* elf64-ppc.c (struct ppc_link_hash_entry): Add "fake".
[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,
c552b3bb 3@c 1999, 2000, 2001, 2002, 2003, 2004
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
c552b3bb 55 1999, 2000, 2001, 2002, 2003, 2004 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,
b51970ac 871996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 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
c552b3bb 118Copyright (C) 1988-2004 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
49efadf5 195You can use @value{GDBN} to debug programs written in C and C@t{++}.
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:
faae5abe 350Andrew Cagney (releases 6.1, 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{++}
d0d5df6f
AC
448compiler, and the Text User Interface (nee Terminal User Interface):
449Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
450Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
451provided HP-specific information in this manual.
c906108c 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
b383017d 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}
b383017d 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 1067
aa26fa3a
TT
1068@item --args
1069@cindex @code{--args}
1070Change interpretation of command line so that arguments following the
1071executable file are passed as command line arguments to the inferior.
1072This option stops option processing.
1073
2df3850c
JM
1074@item -baud @var{bps}
1075@itemx -b @var{bps}
d700128c
EZ
1076@cindex @code{--baud}
1077@cindex @code{-b}
c906108c
SS
1078Set the line speed (baud rate or bits per second) of any serial
1079interface used by @value{GDBN} for remote debugging.
c906108c 1080
f47b1503
AS
1081@item -l @var{timeout}
1082@cindex @code{-l}
1083Set the timeout (in seconds) of any communication used by @value{GDBN}
1084for remote debugging.
1085
c906108c 1086@item -tty @var{device}
d700128c
EZ
1087@itemx -t @var{device}
1088@cindex @code{--tty}
1089@cindex @code{-t}
c906108c
SS
1090Run using @var{device} for your program's standard input and output.
1091@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1092
53a5351d 1093@c resolve the situation of these eventually
c4555f82
SC
1094@item -tui
1095@cindex @code{--tui}
d0d5df6f
AC
1096Activate the @dfn{Text User Interface} when starting. The Text User
1097Interface manages several text windows on the terminal, showing
1098source, assembly, registers and @value{GDBN} command outputs
1099(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1100Text User Interface can be enabled by invoking the program
1101@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1102Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1103
1104@c @item -xdb
d700128c 1105@c @cindex @code{--xdb}
53a5351d
JM
1106@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1107@c For information, see the file @file{xdb_trans.html}, which is usually
1108@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1109@c systems.
1110
d700128c
EZ
1111@item -interpreter @var{interp}
1112@cindex @code{--interpreter}
1113Use the interpreter @var{interp} for interface with the controlling
1114program or device. This option is meant to be set by programs which
94bbb2c0 1115communicate with @value{GDBN} using it as a back end.
21c294e6 1116@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1117
da0f9dcd 1118@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1119@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6c74ac8b
AC
1120The @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0. The
1121previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1122selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1123@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1124
1125@item -write
1126@cindex @code{--write}
1127Open the executable and core files for both reading and writing. This
1128is equivalent to the @samp{set write on} command inside @value{GDBN}
1129(@pxref{Patching}).
1130
1131@item -statistics
1132@cindex @code{--statistics}
1133This option causes @value{GDBN} to print statistics about time and
1134memory usage after it completes each command and returns to the prompt.
1135
1136@item -version
1137@cindex @code{--version}
1138This option causes @value{GDBN} to print its version number and
1139no-warranty blurb, and exit.
1140
c906108c
SS
1141@end table
1142
6d2ebf8b 1143@node Quitting GDB
c906108c
SS
1144@section Quitting @value{GDBN}
1145@cindex exiting @value{GDBN}
1146@cindex leaving @value{GDBN}
1147
1148@table @code
1149@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1150@kindex q @r{(@code{quit})}
96a2c332
SS
1151@item quit @r{[}@var{expression}@r{]}
1152@itemx q
1153To exit @value{GDBN}, use the @code{quit} command (abbreviated
1154@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1155do not supply @var{expression}, @value{GDBN} will terminate normally;
1156otherwise it will terminate using the result of @var{expression} as the
1157error code.
c906108c
SS
1158@end table
1159
1160@cindex interrupt
1161An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1162terminates the action of any @value{GDBN} command that is in progress and
1163returns to @value{GDBN} command level. It is safe to type the interrupt
1164character at any time because @value{GDBN} does not allow it to take effect
1165until a time when it is safe.
1166
c906108c
SS
1167If you have been using @value{GDBN} to control an attached process or
1168device, you can release it with the @code{detach} command
1169(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1170
6d2ebf8b 1171@node Shell Commands
c906108c
SS
1172@section Shell commands
1173
1174If you need to execute occasional shell commands during your
1175debugging session, there is no need to leave or suspend @value{GDBN}; you can
1176just use the @code{shell} command.
1177
1178@table @code
1179@kindex shell
1180@cindex shell escape
1181@item shell @var{command string}
1182Invoke a standard shell to execute @var{command string}.
c906108c 1183If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1184shell to run. Otherwise @value{GDBN} uses the default shell
1185(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1186@end table
1187
1188The utility @code{make} is often needed in development environments.
1189You do not have to use the @code{shell} command for this purpose in
1190@value{GDBN}:
1191
1192@table @code
1193@kindex make
1194@cindex calling make
1195@item make @var{make-args}
1196Execute the @code{make} program with the specified
1197arguments. This is equivalent to @samp{shell make @var{make-args}}.
1198@end table
1199
0fac0b41
DJ
1200@node Logging output
1201@section Logging output
1202@cindex logging @value{GDBN} output
1203
1204You may want to save the output of @value{GDBN} commands to a file.
1205There are several commands to control @value{GDBN}'s logging.
1206
1207@table @code
1208@kindex set logging
1209@item set logging on
1210Enable logging.
1211@item set logging off
1212Disable logging.
1213@item set logging file @var{file}
1214Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1215@item set logging overwrite [on|off]
1216By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1217you want @code{set logging on} to overwrite the logfile instead.
1218@item set logging redirect [on|off]
1219By default, @value{GDBN} output will go to both the terminal and the logfile.
1220Set @code{redirect} if you want output to go only to the log file.
1221@kindex show logging
1222@item show logging
1223Show the current values of the logging settings.
1224@end table
1225
6d2ebf8b 1226@node Commands
c906108c
SS
1227@chapter @value{GDBN} Commands
1228
1229You can abbreviate a @value{GDBN} command to the first few letters of the command
1230name, if that abbreviation is unambiguous; and you can repeat certain
1231@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1232key to get @value{GDBN} to fill out the rest of a word in a command (or to
1233show you the alternatives available, if there is more than one possibility).
1234
1235@menu
1236* Command Syntax:: How to give commands to @value{GDBN}
1237* Completion:: Command completion
1238* Help:: How to ask @value{GDBN} for help
1239@end menu
1240
6d2ebf8b 1241@node Command Syntax
c906108c
SS
1242@section Command syntax
1243
1244A @value{GDBN} command is a single line of input. There is no limit on
1245how long it can be. It starts with a command name, which is followed by
1246arguments whose meaning depends on the command name. For example, the
1247command @code{step} accepts an argument which is the number of times to
1248step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1249with no arguments. Some commands do not allow any arguments.
c906108c
SS
1250
1251@cindex abbreviation
1252@value{GDBN} command names may always be truncated if that abbreviation is
1253unambiguous. Other possible command abbreviations are listed in the
1254documentation for individual commands. In some cases, even ambiguous
1255abbreviations are allowed; for example, @code{s} is specially defined as
1256equivalent to @code{step} even though there are other commands whose
1257names start with @code{s}. You can test abbreviations by using them as
1258arguments to the @code{help} command.
1259
1260@cindex repeating commands
41afff9a 1261@kindex RET @r{(repeat last command)}
c906108c 1262A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1263repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1264will not repeat this way; these are commands whose unintentional
1265repetition might cause trouble and which you are unlikely to want to
1266repeat.
1267
1268The @code{list} and @code{x} commands, when you repeat them with
1269@key{RET}, construct new arguments rather than repeating
1270exactly as typed. This permits easy scanning of source or memory.
1271
1272@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1273output, in a way similar to the common utility @code{more}
1274(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1275@key{RET} too many in this situation, @value{GDBN} disables command
1276repetition after any command that generates this sort of display.
1277
41afff9a 1278@kindex # @r{(a comment)}
c906108c
SS
1279@cindex comment
1280Any text from a @kbd{#} to the end of the line is a comment; it does
1281nothing. This is useful mainly in command files (@pxref{Command
1282Files,,Command files}).
1283
88118b3a
TT
1284@cindex repeating command sequences
1285@kindex C-o @r{(operate-and-get-next)}
1286The @kbd{C-o} binding is useful for repeating a complex sequence of
1287commands. This command accepts the current line, like @kbd{RET}, and
1288then fetches the next line relative to the current line from the history
1289for editing.
1290
6d2ebf8b 1291@node Completion
c906108c
SS
1292@section Command completion
1293
1294@cindex completion
1295@cindex word completion
1296@value{GDBN} can fill in the rest of a word in a command for you, if there is
1297only one possibility; it can also show you what the valid possibilities
1298are for the next word in a command, at any time. This works for @value{GDBN}
1299commands, @value{GDBN} subcommands, and the names of symbols in your program.
1300
1301Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1302of a word. If there is only one possibility, @value{GDBN} fills in the
1303word, and waits for you to finish the command (or press @key{RET} to
1304enter it). For example, if you type
1305
1306@c FIXME "@key" does not distinguish its argument sufficiently to permit
1307@c complete accuracy in these examples; space introduced for clarity.
1308@c If texinfo enhancements make it unnecessary, it would be nice to
1309@c replace " @key" by "@key" in the following...
474c8240 1310@smallexample
c906108c 1311(@value{GDBP}) info bre @key{TAB}
474c8240 1312@end smallexample
c906108c
SS
1313
1314@noindent
1315@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1316the only @code{info} subcommand beginning with @samp{bre}:
1317
474c8240 1318@smallexample
c906108c 1319(@value{GDBP}) info breakpoints
474c8240 1320@end smallexample
c906108c
SS
1321
1322@noindent
1323You can either press @key{RET} at this point, to run the @code{info
1324breakpoints} command, or backspace and enter something else, if
1325@samp{breakpoints} does not look like the command you expected. (If you
1326were sure you wanted @code{info breakpoints} in the first place, you
1327might as well just type @key{RET} immediately after @samp{info bre},
1328to exploit command abbreviations rather than command completion).
1329
1330If there is more than one possibility for the next word when you press
1331@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1332characters and try again, or just press @key{TAB} a second time;
1333@value{GDBN} displays all the possible completions for that word. For
1334example, you might want to set a breakpoint on a subroutine whose name
1335begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1336just sounds the bell. Typing @key{TAB} again displays all the
1337function names in your program that begin with those characters, for
1338example:
1339
474c8240 1340@smallexample
c906108c
SS
1341(@value{GDBP}) b make_ @key{TAB}
1342@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1343make_a_section_from_file make_environ
1344make_abs_section make_function_type
1345make_blockvector make_pointer_type
1346make_cleanup make_reference_type
c906108c
SS
1347make_command make_symbol_completion_list
1348(@value{GDBP}) b make_
474c8240 1349@end smallexample
c906108c
SS
1350
1351@noindent
1352After displaying the available possibilities, @value{GDBN} copies your
1353partial input (@samp{b make_} in the example) so you can finish the
1354command.
1355
1356If you just want to see the list of alternatives in the first place, you
b37052ae 1357can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1358means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1359key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1360one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1361
1362@cindex quotes in commands
1363@cindex completion of quoted strings
1364Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1365parentheses or other characters that @value{GDBN} normally excludes from
1366its notion of a word. To permit word completion to work in this
1367situation, you may enclose words in @code{'} (single quote marks) in
1368@value{GDBN} commands.
c906108c 1369
c906108c 1370The most likely situation where you might need this is in typing the
b37052ae
EZ
1371name of a C@t{++} function. This is because C@t{++} allows function
1372overloading (multiple definitions of the same function, distinguished
1373by argument type). For example, when you want to set a breakpoint you
1374may need to distinguish whether you mean the version of @code{name}
1375that takes an @code{int} parameter, @code{name(int)}, or the version
1376that takes a @code{float} parameter, @code{name(float)}. To use the
1377word-completion facilities in this situation, type a single quote
1378@code{'} at the beginning of the function name. This alerts
1379@value{GDBN} that it may need to consider more information than usual
1380when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1381
474c8240 1382@smallexample
96a2c332 1383(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1384bubble(double,double) bubble(int,int)
1385(@value{GDBP}) b 'bubble(
474c8240 1386@end smallexample
c906108c
SS
1387
1388In some cases, @value{GDBN} can tell that completing a name requires using
1389quotes. When this happens, @value{GDBN} inserts the quote for you (while
1390completing as much as it can) if you do not type the quote in the first
1391place:
1392
474c8240 1393@smallexample
c906108c
SS
1394(@value{GDBP}) b bub @key{TAB}
1395@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1396(@value{GDBP}) b 'bubble(
474c8240 1397@end smallexample
c906108c
SS
1398
1399@noindent
1400In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1401you have not yet started typing the argument list when you ask for
1402completion on an overloaded symbol.
1403
d4f3574e 1404For more information about overloaded functions, see @ref{C plus plus
b37052ae 1405expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1406overload-resolution off} to disable overload resolution;
b37052ae 1407see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1408
1409
6d2ebf8b 1410@node Help
c906108c
SS
1411@section Getting help
1412@cindex online documentation
1413@kindex help
1414
5d161b24 1415You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1416using the command @code{help}.
1417
1418@table @code
41afff9a 1419@kindex h @r{(@code{help})}
c906108c
SS
1420@item help
1421@itemx h
1422You can use @code{help} (abbreviated @code{h}) with no arguments to
1423display a short list of named classes of commands:
1424
1425@smallexample
1426(@value{GDBP}) help
1427List of classes of commands:
1428
2df3850c 1429aliases -- Aliases of other commands
c906108c 1430breakpoints -- Making program stop at certain points
2df3850c 1431data -- Examining data
c906108c 1432files -- Specifying and examining files
2df3850c
JM
1433internals -- Maintenance commands
1434obscure -- Obscure features
1435running -- Running the program
1436stack -- Examining the stack
c906108c
SS
1437status -- Status inquiries
1438support -- Support facilities
96a2c332
SS
1439tracepoints -- Tracing of program execution without@*
1440 stopping the program
c906108c 1441user-defined -- User-defined commands
c906108c 1442
5d161b24 1443Type "help" followed by a class name for a list of
c906108c 1444commands in that class.
5d161b24 1445Type "help" followed by command name for full
c906108c
SS
1446documentation.
1447Command name abbreviations are allowed if unambiguous.
1448(@value{GDBP})
1449@end smallexample
96a2c332 1450@c the above line break eliminates huge line overfull...
c906108c
SS
1451
1452@item help @var{class}
1453Using one of the general help classes as an argument, you can get a
1454list of the individual commands in that class. For example, here is the
1455help display for the class @code{status}:
1456
1457@smallexample
1458(@value{GDBP}) help status
1459Status inquiries.
1460
1461List of commands:
1462
1463@c Line break in "show" line falsifies real output, but needed
1464@c to fit in smallbook page size.
2df3850c
JM
1465info -- Generic command for showing things
1466 about the program being debugged
1467show -- Generic command for showing things
1468 about the debugger
c906108c 1469
5d161b24 1470Type "help" followed by command name for full
c906108c
SS
1471documentation.
1472Command name abbreviations are allowed if unambiguous.
1473(@value{GDBP})
1474@end smallexample
1475
1476@item help @var{command}
1477With a command name as @code{help} argument, @value{GDBN} displays a
1478short paragraph on how to use that command.
1479
6837a0a2
DB
1480@kindex apropos
1481@item apropos @var{args}
1482The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1483commands, and their documentation, for the regular expression specified in
1484@var{args}. It prints out all matches found. For example:
1485
1486@smallexample
1487apropos reload
1488@end smallexample
1489
b37052ae
EZ
1490@noindent
1491results in:
6837a0a2
DB
1492
1493@smallexample
6d2ebf8b
SS
1494@c @group
1495set symbol-reloading -- Set dynamic symbol table reloading
1496 multiple times in one run
1497show symbol-reloading -- Show dynamic symbol table reloading
1498 multiple times in one run
1499@c @end group
6837a0a2
DB
1500@end smallexample
1501
c906108c
SS
1502@kindex complete
1503@item complete @var{args}
1504The @code{complete @var{args}} command lists all the possible completions
1505for the beginning of a command. Use @var{args} to specify the beginning of the
1506command you want completed. For example:
1507
1508@smallexample
1509complete i
1510@end smallexample
1511
1512@noindent results in:
1513
1514@smallexample
1515@group
2df3850c
JM
1516if
1517ignore
c906108c
SS
1518info
1519inspect
c906108c
SS
1520@end group
1521@end smallexample
1522
1523@noindent This is intended for use by @sc{gnu} Emacs.
1524@end table
1525
1526In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1527and @code{show} to inquire about the state of your program, or the state
1528of @value{GDBN} itself. Each command supports many topics of inquiry; this
1529manual introduces each of them in the appropriate context. The listings
1530under @code{info} and under @code{show} in the Index point to
1531all the sub-commands. @xref{Index}.
1532
1533@c @group
1534@table @code
1535@kindex info
41afff9a 1536@kindex i @r{(@code{info})}
c906108c
SS
1537@item info
1538This command (abbreviated @code{i}) is for describing the state of your
1539program. For example, you can list the arguments given to your program
1540with @code{info args}, list the registers currently in use with @code{info
1541registers}, or list the breakpoints you have set with @code{info breakpoints}.
1542You can get a complete list of the @code{info} sub-commands with
1543@w{@code{help info}}.
1544
1545@kindex set
1546@item set
5d161b24 1547You can assign the result of an expression to an environment variable with
c906108c
SS
1548@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1549@code{set prompt $}.
1550
1551@kindex show
1552@item show
5d161b24 1553In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1554@value{GDBN} itself.
1555You can change most of the things you can @code{show}, by using the
1556related command @code{set}; for example, you can control what number
1557system is used for displays with @code{set radix}, or simply inquire
1558which is currently in use with @code{show radix}.
1559
1560@kindex info set
1561To display all the settable parameters and their current
1562values, you can use @code{show} with no arguments; you may also use
1563@code{info set}. Both commands produce the same display.
1564@c FIXME: "info set" violates the rule that "info" is for state of
1565@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1566@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1567@end table
1568@c @end group
1569
1570Here are three miscellaneous @code{show} subcommands, all of which are
1571exceptional in lacking corresponding @code{set} commands:
1572
1573@table @code
1574@kindex show version
1575@cindex version number
1576@item show version
1577Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1578information in @value{GDBN} bug-reports. If multiple versions of
1579@value{GDBN} are in use at your site, you may need to determine which
1580version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1581commands are introduced, and old ones may wither away. Also, many
1582system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1583variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1584The version number is the same as the one announced when you start
1585@value{GDBN}.
c906108c
SS
1586
1587@kindex show copying
1588@item show copying
1589Display information about permission for copying @value{GDBN}.
1590
1591@kindex show warranty
1592@item show warranty
2df3850c 1593Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1594if your version of @value{GDBN} comes with one.
2df3850c 1595
c906108c
SS
1596@end table
1597
6d2ebf8b 1598@node Running
c906108c
SS
1599@chapter Running Programs Under @value{GDBN}
1600
1601When you run a program under @value{GDBN}, you must first generate
1602debugging information when you compile it.
7a292a7a
SS
1603
1604You may start @value{GDBN} with its arguments, if any, in an environment
1605of your choice. If you are doing native debugging, you may redirect
1606your program's input and output, debug an already running process, or
1607kill a child process.
c906108c
SS
1608
1609@menu
1610* Compilation:: Compiling for debugging
1611* Starting:: Starting your program
c906108c
SS
1612* Arguments:: Your program's arguments
1613* Environment:: Your program's environment
c906108c
SS
1614
1615* Working Directory:: Your program's working directory
1616* Input/Output:: Your program's input and output
1617* Attach:: Debugging an already-running process
1618* Kill Process:: Killing the child process
c906108c
SS
1619
1620* Threads:: Debugging programs with multiple threads
1621* Processes:: Debugging programs with multiple processes
1622@end menu
1623
6d2ebf8b 1624@node Compilation
c906108c
SS
1625@section Compiling for debugging
1626
1627In order to debug a program effectively, you need to generate
1628debugging information when you compile it. This debugging information
1629is stored in the object file; it describes the data type of each
1630variable or function and the correspondence between source line numbers
1631and addresses in the executable code.
1632
1633To request debugging information, specify the @samp{-g} option when you run
1634the compiler.
1635
e2e0bcd1
JB
1636Most compilers do not include information about preprocessor macros in
1637the debugging information if you specify the @option{-g} flag alone,
1638because this information is rather large. Version 3.1 of @value{NGCC},
1639the @sc{gnu} C compiler, provides macro information if you specify the
1640options @option{-gdwarf-2} and @option{-g3}; the former option requests
1641debugging information in the Dwarf 2 format, and the latter requests
1642``extra information''. In the future, we hope to find more compact ways
1643to represent macro information, so that it can be included with
1644@option{-g} alone.
1645
c906108c
SS
1646Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1647options together. Using those compilers, you cannot generate optimized
1648executables containing debugging information.
1649
53a5351d
JM
1650@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1651without @samp{-O}, making it possible to debug optimized code. We
1652recommend that you @emph{always} use @samp{-g} whenever you compile a
1653program. You may think your program is correct, but there is no sense
1654in pushing your luck.
c906108c
SS
1655
1656@cindex optimized code, debugging
1657@cindex debugging optimized code
1658When you debug a program compiled with @samp{-g -O}, remember that the
1659optimizer is rearranging your code; the debugger shows you what is
1660really there. Do not be too surprised when the execution path does not
1661exactly match your source file! An extreme example: if you define a
1662variable, but never use it, @value{GDBN} never sees that
1663variable---because the compiler optimizes it out of existence.
1664
1665Some things do not work as well with @samp{-g -O} as with just
1666@samp{-g}, particularly on machines with instruction scheduling. If in
1667doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1668please report it to us as a bug (including a test case!).
15387254 1669@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1670
1671Older versions of the @sc{gnu} C compiler permitted a variant option
1672@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1673format; if your @sc{gnu} C compiler has this option, do not use it.
1674
1675@need 2000
6d2ebf8b 1676@node Starting
c906108c
SS
1677@section Starting your program
1678@cindex starting
1679@cindex running
1680
1681@table @code
1682@kindex run
41afff9a 1683@kindex r @r{(@code{run})}
c906108c
SS
1684@item run
1685@itemx r
7a292a7a
SS
1686Use the @code{run} command to start your program under @value{GDBN}.
1687You must first specify the program name (except on VxWorks) with an
1688argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1689@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1690(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1691
1692@end table
1693
c906108c
SS
1694If you are running your program in an execution environment that
1695supports processes, @code{run} creates an inferior process and makes
1696that process run your program. (In environments without processes,
1697@code{run} jumps to the start of your program.)
1698
1699The execution of a program is affected by certain information it
1700receives from its superior. @value{GDBN} provides ways to specify this
1701information, which you must do @emph{before} starting your program. (You
1702can change it after starting your program, but such changes only affect
1703your program the next time you start it.) This information may be
1704divided into four categories:
1705
1706@table @asis
1707@item The @emph{arguments.}
1708Specify the arguments to give your program as the arguments of the
1709@code{run} command. If a shell is available on your target, the shell
1710is used to pass the arguments, so that you may use normal conventions
1711(such as wildcard expansion or variable substitution) in describing
1712the arguments.
1713In Unix systems, you can control which shell is used with the
1714@code{SHELL} environment variable.
1715@xref{Arguments, ,Your program's arguments}.
1716
1717@item The @emph{environment.}
1718Your program normally inherits its environment from @value{GDBN}, but you can
1719use the @value{GDBN} commands @code{set environment} and @code{unset
1720environment} to change parts of the environment that affect
1721your program. @xref{Environment, ,Your program's environment}.
1722
1723@item The @emph{working directory.}
1724Your program inherits its working directory from @value{GDBN}. You can set
1725the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1726@xref{Working Directory, ,Your program's working directory}.
1727
1728@item The @emph{standard input and output.}
1729Your program normally uses the same device for standard input and
1730standard output as @value{GDBN} is using. You can redirect input and output
1731in the @code{run} command line, or you can use the @code{tty} command to
1732set a different device for your program.
1733@xref{Input/Output, ,Your program's input and output}.
1734
1735@cindex pipes
1736@emph{Warning:} While input and output redirection work, you cannot use
1737pipes to pass the output of the program you are debugging to another
1738program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1739wrong program.
1740@end table
c906108c
SS
1741
1742When you issue the @code{run} command, your program begins to execute
1743immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1744of how to arrange for your program to stop. Once your program has
1745stopped, you may call functions in your program, using the @code{print}
1746or @code{call} commands. @xref{Data, ,Examining Data}.
1747
1748If the modification time of your symbol file has changed since the last
1749time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1750table, and reads it again. When it does this, @value{GDBN} tries to retain
1751your current breakpoints.
1752
4e8b0763
JB
1753@table @code
1754@kindex start
1755@item start
1756@cindex run to main procedure
1757The name of the main procedure can vary from language to language.
1758With C or C@t{++}, the main procedure name is always @code{main}, but
1759other languages such as Ada do not require a specific name for their
1760main procedure. The debugger provides a convenient way to start the
1761execution of the program and to stop at the beginning of the main
1762procedure, depending on the language used.
1763
1764The @samp{start} command does the equivalent of setting a temporary
1765breakpoint at the beginning of the main procedure and then invoking
1766the @samp{run} command.
1767
f018e82f
EZ
1768@cindex elaboration phase
1769Some programs contain an @dfn{elaboration} phase where some startup code is
1770executed before the main procedure is called. This depends on the
1771languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1772constructors for static and global objects are executed before
1773@code{main} is called. It is therefore possible that the debugger stops
1774before reaching the main procedure. However, the temporary breakpoint
1775will remain to halt execution.
1776
1777Specify the arguments to give to your program as arguments to the
1778@samp{start} command. These arguments will be given verbatim to the
1779underlying @samp{run} command. Note that the same arguments will be
1780reused if no argument is provided during subsequent calls to
1781@samp{start} or @samp{run}.
1782
1783It is sometimes necessary to debug the program during elaboration. In
1784these cases, using the @code{start} command would stop the execution of
1785your program too late, as the program would have already completed the
1786elaboration phase. Under these circumstances, insert breakpoints in your
1787elaboration code before running your program.
1788@end table
1789
6d2ebf8b 1790@node Arguments
c906108c
SS
1791@section Your program's arguments
1792
1793@cindex arguments (to your program)
1794The arguments to your program can be specified by the arguments of the
5d161b24 1795@code{run} command.
c906108c
SS
1796They are passed to a shell, which expands wildcard characters and
1797performs redirection of I/O, and thence to your program. Your
1798@code{SHELL} environment variable (if it exists) specifies what shell
1799@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1800the default shell (@file{/bin/sh} on Unix).
1801
1802On non-Unix systems, the program is usually invoked directly by
1803@value{GDBN}, which emulates I/O redirection via the appropriate system
1804calls, and the wildcard characters are expanded by the startup code of
1805the program, not by the shell.
c906108c
SS
1806
1807@code{run} with no arguments uses the same arguments used by the previous
1808@code{run}, or those set by the @code{set args} command.
1809
c906108c 1810@table @code
41afff9a 1811@kindex set args
c906108c
SS
1812@item set args
1813Specify the arguments to be used the next time your program is run. If
1814@code{set args} has no arguments, @code{run} executes your program
1815with no arguments. Once you have run your program with arguments,
1816using @code{set args} before the next @code{run} is the only way to run
1817it again without arguments.
1818
1819@kindex show args
1820@item show args
1821Show the arguments to give your program when it is started.
1822@end table
1823
6d2ebf8b 1824@node Environment
c906108c
SS
1825@section Your program's environment
1826
1827@cindex environment (of your program)
1828The @dfn{environment} consists of a set of environment variables and
1829their values. Environment variables conventionally record such things as
1830your user name, your home directory, your terminal type, and your search
1831path for programs to run. Usually you set up environment variables with
1832the shell and they are inherited by all the other programs you run. When
1833debugging, it can be useful to try running your program with a modified
1834environment without having to start @value{GDBN} over again.
1835
1836@table @code
1837@kindex path
1838@item path @var{directory}
1839Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1840(the search path for executables) that will be passed to your program.
1841The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1842You may specify several directory names, separated by whitespace or by a
1843system-dependent separator character (@samp{:} on Unix, @samp{;} on
1844MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1845is moved to the front, so it is searched sooner.
c906108c
SS
1846
1847You can use the string @samp{$cwd} to refer to whatever is the current
1848working directory at the time @value{GDBN} searches the path. If you
1849use @samp{.} instead, it refers to the directory where you executed the
1850@code{path} command. @value{GDBN} replaces @samp{.} in the
1851@var{directory} argument (with the current path) before adding
1852@var{directory} to the search path.
1853@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1854@c document that, since repeating it would be a no-op.
1855
1856@kindex show paths
1857@item show paths
1858Display the list of search paths for executables (the @code{PATH}
1859environment variable).
1860
1861@kindex show environment
1862@item show environment @r{[}@var{varname}@r{]}
1863Print the value of environment variable @var{varname} to be given to
1864your program when it starts. If you do not supply @var{varname},
1865print the names and values of all environment variables to be given to
1866your program. You can abbreviate @code{environment} as @code{env}.
1867
1868@kindex set environment
53a5351d 1869@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1870Set environment variable @var{varname} to @var{value}. The value
1871changes for your program only, not for @value{GDBN} itself. @var{value} may
1872be any string; the values of environment variables are just strings, and
1873any interpretation is supplied by your program itself. The @var{value}
1874parameter is optional; if it is eliminated, the variable is set to a
1875null value.
1876@c "any string" here does not include leading, trailing
1877@c blanks. Gnu asks: does anyone care?
1878
1879For example, this command:
1880
474c8240 1881@smallexample
c906108c 1882set env USER = foo
474c8240 1883@end smallexample
c906108c
SS
1884
1885@noindent
d4f3574e 1886tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1887@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1888are not actually required.)
1889
1890@kindex unset environment
1891@item unset environment @var{varname}
1892Remove variable @var{varname} from the environment to be passed to your
1893program. This is different from @samp{set env @var{varname} =};
1894@code{unset environment} removes the variable from the environment,
1895rather than assigning it an empty value.
1896@end table
1897
d4f3574e
SS
1898@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1899the shell indicated
c906108c
SS
1900by your @code{SHELL} environment variable if it exists (or
1901@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1902that runs an initialization file---such as @file{.cshrc} for C-shell, or
1903@file{.bashrc} for BASH---any variables you set in that file affect
1904your program. You may wish to move setting of environment variables to
1905files that are only run when you sign on, such as @file{.login} or
1906@file{.profile}.
1907
6d2ebf8b 1908@node Working Directory
c906108c
SS
1909@section Your program's working directory
1910
1911@cindex working directory (of your program)
1912Each time you start your program with @code{run}, it inherits its
1913working directory from the current working directory of @value{GDBN}.
1914The @value{GDBN} working directory is initially whatever it inherited
1915from its parent process (typically the shell), but you can specify a new
1916working directory in @value{GDBN} with the @code{cd} command.
1917
1918The @value{GDBN} working directory also serves as a default for the commands
1919that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1920specify files}.
1921
1922@table @code
1923@kindex cd
1924@item cd @var{directory}
1925Set the @value{GDBN} working directory to @var{directory}.
1926
1927@kindex pwd
1928@item pwd
1929Print the @value{GDBN} working directory.
1930@end table
1931
60bf7e09
EZ
1932It is generally impossible to find the current working directory of
1933the process being debugged (since a program can change its directory
1934during its run). If you work on a system where @value{GDBN} is
1935configured with the @file{/proc} support, you can use the @code{info
1936proc} command (@pxref{SVR4 Process Information}) to find out the
1937current working directory of the debuggee.
1938
6d2ebf8b 1939@node Input/Output
c906108c
SS
1940@section Your program's input and output
1941
1942@cindex redirection
1943@cindex i/o
1944@cindex terminal
1945By default, the program you run under @value{GDBN} does input and output to
5d161b24 1946the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1947to its own terminal modes to interact with you, but it records the terminal
1948modes your program was using and switches back to them when you continue
1949running your program.
1950
1951@table @code
1952@kindex info terminal
1953@item info terminal
1954Displays information recorded by @value{GDBN} about the terminal modes your
1955program is using.
1956@end table
1957
1958You can redirect your program's input and/or output using shell
1959redirection with the @code{run} command. For example,
1960
474c8240 1961@smallexample
c906108c 1962run > outfile
474c8240 1963@end smallexample
c906108c
SS
1964
1965@noindent
1966starts your program, diverting its output to the file @file{outfile}.
1967
1968@kindex tty
1969@cindex controlling terminal
1970Another way to specify where your program should do input and output is
1971with the @code{tty} command. This command accepts a file name as
1972argument, and causes this file to be the default for future @code{run}
1973commands. It also resets the controlling terminal for the child
1974process, for future @code{run} commands. For example,
1975
474c8240 1976@smallexample
c906108c 1977tty /dev/ttyb
474c8240 1978@end smallexample
c906108c
SS
1979
1980@noindent
1981directs that processes started with subsequent @code{run} commands
1982default to do input and output on the terminal @file{/dev/ttyb} and have
1983that as their controlling terminal.
1984
1985An explicit redirection in @code{run} overrides the @code{tty} command's
1986effect on the input/output device, but not its effect on the controlling
1987terminal.
1988
1989When you use the @code{tty} command or redirect input in the @code{run}
1990command, only the input @emph{for your program} is affected. The input
1991for @value{GDBN} still comes from your terminal.
1992
6d2ebf8b 1993@node Attach
c906108c
SS
1994@section Debugging an already-running process
1995@kindex attach
1996@cindex attach
1997
1998@table @code
1999@item attach @var{process-id}
2000This command attaches to a running process---one that was started
2001outside @value{GDBN}. (@code{info files} shows your active
2002targets.) The command takes as argument a process ID. The usual way to
2003find out the process-id of a Unix process is with the @code{ps} utility,
2004or with the @samp{jobs -l} shell command.
2005
2006@code{attach} does not repeat if you press @key{RET} a second time after
2007executing the command.
2008@end table
2009
2010To use @code{attach}, your program must be running in an environment
2011which supports processes; for example, @code{attach} does not work for
2012programs on bare-board targets that lack an operating system. You must
2013also have permission to send the process a signal.
2014
2015When you use @code{attach}, the debugger finds the program running in
2016the process first by looking in the current working directory, then (if
2017the program is not found) by using the source file search path
2018(@pxref{Source Path, ,Specifying source directories}). You can also use
2019the @code{file} command to load the program. @xref{Files, ,Commands to
2020Specify Files}.
2021
2022The first thing @value{GDBN} does after arranging to debug the specified
2023process is to stop it. You can examine and modify an attached process
53a5351d
JM
2024with all the @value{GDBN} commands that are ordinarily available when
2025you start processes with @code{run}. You can insert breakpoints; you
2026can step and continue; you can modify storage. If you would rather the
2027process continue running, you may use the @code{continue} command after
c906108c
SS
2028attaching @value{GDBN} to the process.
2029
2030@table @code
2031@kindex detach
2032@item detach
2033When you have finished debugging the attached process, you can use the
2034@code{detach} command to release it from @value{GDBN} control. Detaching
2035the process continues its execution. After the @code{detach} command,
2036that process and @value{GDBN} become completely independent once more, and you
2037are ready to @code{attach} another process or start one with @code{run}.
2038@code{detach} does not repeat if you press @key{RET} again after
2039executing the command.
2040@end table
2041
2042If you exit @value{GDBN} or use the @code{run} command while you have an
2043attached process, you kill that process. By default, @value{GDBN} asks
2044for confirmation if you try to do either of these things; you can
2045control whether or not you need to confirm by using the @code{set
2046confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2047messages}).
2048
6d2ebf8b 2049@node Kill Process
c906108c 2050@section Killing the child process
c906108c
SS
2051
2052@table @code
2053@kindex kill
2054@item kill
2055Kill the child process in which your program is running under @value{GDBN}.
2056@end table
2057
2058This command is useful if you wish to debug a core dump instead of a
2059running process. @value{GDBN} ignores any core dump file while your program
2060is running.
2061
2062On some operating systems, a program cannot be executed outside @value{GDBN}
2063while you have breakpoints set on it inside @value{GDBN}. You can use the
2064@code{kill} command in this situation to permit running your program
2065outside the debugger.
2066
2067The @code{kill} command is also useful if you wish to recompile and
2068relink your program, since on many systems it is impossible to modify an
2069executable file while it is running in a process. In this case, when you
2070next type @code{run}, @value{GDBN} notices that the file has changed, and
2071reads the symbol table again (while trying to preserve your current
2072breakpoint settings).
2073
6d2ebf8b 2074@node Threads
c906108c 2075@section Debugging programs with multiple threads
c906108c
SS
2076
2077@cindex threads of execution
2078@cindex multiple threads
2079@cindex switching threads
2080In some operating systems, such as HP-UX and Solaris, a single program
2081may have more than one @dfn{thread} of execution. The precise semantics
2082of threads differ from one operating system to another, but in general
2083the threads of a single program are akin to multiple processes---except
2084that they share one address space (that is, they can all examine and
2085modify the same variables). On the other hand, each thread has its own
2086registers and execution stack, and perhaps private memory.
2087
2088@value{GDBN} provides these facilities for debugging multi-thread
2089programs:
2090
2091@itemize @bullet
2092@item automatic notification of new threads
2093@item @samp{thread @var{threadno}}, a command to switch among threads
2094@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2095@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2096a command to apply a command to a list of threads
2097@item thread-specific breakpoints
2098@end itemize
2099
c906108c
SS
2100@quotation
2101@emph{Warning:} These facilities are not yet available on every
2102@value{GDBN} configuration where the operating system supports threads.
2103If your @value{GDBN} does not support threads, these commands have no
2104effect. For example, a system without thread support shows no output
2105from @samp{info threads}, and always rejects the @code{thread} command,
2106like this:
2107
2108@smallexample
2109(@value{GDBP}) info threads
2110(@value{GDBP}) thread 1
2111Thread ID 1 not known. Use the "info threads" command to
2112see the IDs of currently known threads.
2113@end smallexample
2114@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2115@c doesn't support threads"?
2116@end quotation
c906108c
SS
2117
2118@cindex focus of debugging
2119@cindex current thread
2120The @value{GDBN} thread debugging facility allows you to observe all
2121threads while your program runs---but whenever @value{GDBN} takes
2122control, one thread in particular is always the focus of debugging.
2123This thread is called the @dfn{current thread}. Debugging commands show
2124program information from the perspective of the current thread.
2125
41afff9a 2126@cindex @code{New} @var{systag} message
c906108c
SS
2127@cindex thread identifier (system)
2128@c FIXME-implementors!! It would be more helpful if the [New...] message
2129@c included GDB's numeric thread handle, so you could just go to that
2130@c thread without first checking `info threads'.
2131Whenever @value{GDBN} detects a new thread in your program, it displays
2132the target system's identification for the thread with a message in the
2133form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2134whose form varies depending on the particular system. For example, on
2135LynxOS, you might see
2136
474c8240 2137@smallexample
c906108c 2138[New process 35 thread 27]
474c8240 2139@end smallexample
c906108c
SS
2140
2141@noindent
2142when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2143the @var{systag} is simply something like @samp{process 368}, with no
2144further qualifier.
2145
2146@c FIXME!! (1) Does the [New...] message appear even for the very first
2147@c thread of a program, or does it only appear for the
6ca652b0 2148@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2149@c program?
2150@c (2) *Is* there necessarily a first thread always? Or do some
2151@c multithread systems permit starting a program with multiple
5d161b24 2152@c threads ab initio?
c906108c
SS
2153
2154@cindex thread number
2155@cindex thread identifier (GDB)
2156For debugging purposes, @value{GDBN} associates its own thread
2157number---always a single integer---with each thread in your program.
2158
2159@table @code
2160@kindex info threads
2161@item info threads
2162Display a summary of all threads currently in your
2163program. @value{GDBN} displays for each thread (in this order):
2164
2165@enumerate
2166@item the thread number assigned by @value{GDBN}
2167
2168@item the target system's thread identifier (@var{systag})
2169
2170@item the current stack frame summary for that thread
2171@end enumerate
2172
2173@noindent
2174An asterisk @samp{*} to the left of the @value{GDBN} thread number
2175indicates the current thread.
2176
5d161b24 2177For example,
c906108c
SS
2178@end table
2179@c end table here to get a little more width for example
2180
2181@smallexample
2182(@value{GDBP}) info threads
2183 3 process 35 thread 27 0x34e5 in sigpause ()
2184 2 process 35 thread 23 0x34e5 in sigpause ()
2185* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2186 at threadtest.c:68
2187@end smallexample
53a5351d
JM
2188
2189On HP-UX systems:
c906108c 2190
4644b6e3
EZ
2191@cindex debugging multithreaded programs (on HP-UX)
2192@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2193For debugging purposes, @value{GDBN} associates its own thread
2194number---a small integer assigned in thread-creation order---with each
2195thread in your program.
2196
41afff9a
EZ
2197@cindex @code{New} @var{systag} message, on HP-UX
2198@cindex thread identifier (system), on HP-UX
c906108c
SS
2199@c FIXME-implementors!! It would be more helpful if the [New...] message
2200@c included GDB's numeric thread handle, so you could just go to that
2201@c thread without first checking `info threads'.
2202Whenever @value{GDBN} detects a new thread in your program, it displays
2203both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2204form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2205whose form varies depending on the particular system. For example, on
2206HP-UX, you see
2207
474c8240 2208@smallexample
c906108c 2209[New thread 2 (system thread 26594)]
474c8240 2210@end smallexample
c906108c
SS
2211
2212@noindent
5d161b24 2213when @value{GDBN} notices a new thread.
c906108c
SS
2214
2215@table @code
4644b6e3 2216@kindex info threads (HP-UX)
c906108c
SS
2217@item info threads
2218Display a summary of all threads currently in your
2219program. @value{GDBN} displays for each thread (in this order):
2220
2221@enumerate
2222@item the thread number assigned by @value{GDBN}
2223
2224@item the target system's thread identifier (@var{systag})
2225
2226@item the current stack frame summary for that thread
2227@end enumerate
2228
2229@noindent
2230An asterisk @samp{*} to the left of the @value{GDBN} thread number
2231indicates the current thread.
2232
5d161b24 2233For example,
c906108c
SS
2234@end table
2235@c end table here to get a little more width for example
2236
474c8240 2237@smallexample
c906108c 2238(@value{GDBP}) info threads
6d2ebf8b
SS
2239 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2240 at quicksort.c:137
2241 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2242 from /usr/lib/libc.2
2243 1 system thread 27905 0x7b003498 in _brk () \@*
2244 from /usr/lib/libc.2
474c8240 2245@end smallexample
c906108c
SS
2246
2247@table @code
2248@kindex thread @var{threadno}
2249@item thread @var{threadno}
2250Make thread number @var{threadno} the current thread. The command
2251argument @var{threadno} is the internal @value{GDBN} thread number, as
2252shown in the first field of the @samp{info threads} display.
2253@value{GDBN} responds by displaying the system identifier of the thread
2254you selected, and its current stack frame summary:
2255
2256@smallexample
2257@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2258(@value{GDBP}) thread 2
c906108c 2259[Switching to process 35 thread 23]
c906108c
SS
22600x34e5 in sigpause ()
2261@end smallexample
2262
2263@noindent
2264As with the @samp{[New @dots{}]} message, the form of the text after
2265@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2266threads.
c906108c 2267
c906108c
SS
2268@item thread apply [@var{threadno}] [@var{all}] @var{args}
2269The @code{thread apply} command allows you to apply a command to one or
2270more threads. Specify the numbers of the threads that you want affected
2271with the command argument @var{threadno}. @var{threadno} is the internal
2272@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2273threads} display. To apply a command to all threads, use
2274@code{thread apply all} @var{args}.
c906108c
SS
2275@end table
2276
2277@cindex automatic thread selection
2278@cindex switching threads automatically
2279@cindex threads, automatic switching
2280Whenever @value{GDBN} stops your program, due to a breakpoint or a
2281signal, it automatically selects the thread where that breakpoint or
2282signal happened. @value{GDBN} alerts you to the context switch with a
2283message of the form @samp{[Switching to @var{systag}]} to identify the
2284thread.
2285
2286@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2287more information about how @value{GDBN} behaves when you stop and start
2288programs with multiple threads.
2289
2290@xref{Set Watchpoints,,Setting watchpoints}, for information about
2291watchpoints in programs with multiple threads.
c906108c 2292
6d2ebf8b 2293@node Processes
c906108c
SS
2294@section Debugging programs with multiple processes
2295
2296@cindex fork, debugging programs which call
2297@cindex multiple processes
2298@cindex processes, multiple
53a5351d
JM
2299On most systems, @value{GDBN} has no special support for debugging
2300programs which create additional processes using the @code{fork}
2301function. When a program forks, @value{GDBN} will continue to debug the
2302parent process and the child process will run unimpeded. If you have
2303set a breakpoint in any code which the child then executes, the child
2304will get a @code{SIGTRAP} signal which (unless it catches the signal)
2305will cause it to terminate.
c906108c
SS
2306
2307However, if you want to debug the child process there is a workaround
2308which isn't too painful. Put a call to @code{sleep} in the code which
2309the child process executes after the fork. It may be useful to sleep
2310only if a certain environment variable is set, or a certain file exists,
2311so that the delay need not occur when you don't want to run @value{GDBN}
2312on the child. While the child is sleeping, use the @code{ps} program to
2313get its process ID. Then tell @value{GDBN} (a new invocation of
2314@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2315the child process (@pxref{Attach}). From that point on you can debug
c906108c 2316the child process just like any other process which you attached to.
c906108c 2317
b51970ac
DJ
2318On some systems, @value{GDBN} provides support for debugging programs that
2319create additional processes using the @code{fork} or @code{vfork} functions.
2320Currently, the only platforms with this feature are HP-UX (11.x and later
2321only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2322
2323By default, when a program forks, @value{GDBN} will continue to debug
2324the parent process and the child process will run unimpeded.
2325
2326If you want to follow the child process instead of the parent process,
2327use the command @w{@code{set follow-fork-mode}}.
2328
2329@table @code
2330@kindex set follow-fork-mode
2331@item set follow-fork-mode @var{mode}
2332Set the debugger response to a program call of @code{fork} or
2333@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2334process. The @var{mode} can be:
2335
2336@table @code
2337@item parent
2338The original process is debugged after a fork. The child process runs
2df3850c 2339unimpeded. This is the default.
c906108c
SS
2340
2341@item child
2342The new process is debugged after a fork. The parent process runs
2343unimpeded.
2344
c906108c
SS
2345@end table
2346
2347@item show follow-fork-mode
2df3850c 2348Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2349@end table
2350
2351If you ask to debug a child process and a @code{vfork} is followed by an
2352@code{exec}, @value{GDBN} executes the new target up to the first
2353breakpoint in the new target. If you have a breakpoint set on
2354@code{main} in your original program, the breakpoint will also be set on
2355the child process's @code{main}.
2356
2357When a child process is spawned by @code{vfork}, you cannot debug the
2358child or parent until an @code{exec} call completes.
2359
2360If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2361call executes, the new target restarts. To restart the parent process,
2362use the @code{file} command with the parent executable name as its
2363argument.
2364
2365You can use the @code{catch} command to make @value{GDBN} stop whenever
2366a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2367Catchpoints, ,Setting catchpoints}.
c906108c 2368
6d2ebf8b 2369@node Stopping
c906108c
SS
2370@chapter Stopping and Continuing
2371
2372The principal purposes of using a debugger are so that you can stop your
2373program before it terminates; or so that, if your program runs into
2374trouble, you can investigate and find out why.
2375
7a292a7a
SS
2376Inside @value{GDBN}, your program may stop for any of several reasons,
2377such as a signal, a breakpoint, or reaching a new line after a
2378@value{GDBN} command such as @code{step}. You may then examine and
2379change variables, set new breakpoints or remove old ones, and then
2380continue execution. Usually, the messages shown by @value{GDBN} provide
2381ample explanation of the status of your program---but you can also
2382explicitly request this information at any time.
c906108c
SS
2383
2384@table @code
2385@kindex info program
2386@item info program
2387Display information about the status of your program: whether it is
7a292a7a 2388running or not, what process it is, and why it stopped.
c906108c
SS
2389@end table
2390
2391@menu
2392* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2393* Continuing and Stepping:: Resuming execution
c906108c 2394* Signals:: Signals
c906108c 2395* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2396@end menu
2397
6d2ebf8b 2398@node Breakpoints
c906108c
SS
2399@section Breakpoints, watchpoints, and catchpoints
2400
2401@cindex breakpoints
2402A @dfn{breakpoint} makes your program stop whenever a certain point in
2403the program is reached. For each breakpoint, you can add conditions to
2404control in finer detail whether your program stops. You can set
2405breakpoints with the @code{break} command and its variants (@pxref{Set
2406Breaks, ,Setting breakpoints}), to specify the place where your program
2407should stop by line number, function name or exact address in the
2408program.
2409
2410In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2411breakpoints in shared libraries before the executable is run. There is
2412a minor limitation on HP-UX systems: you must wait until the executable
2413is run in order to set breakpoints in shared library routines that are
2414not called directly by the program (for example, routines that are
2415arguments in a @code{pthread_create} call).
2416
2417@cindex watchpoints
2418@cindex memory tracing
2419@cindex breakpoint on memory address
2420@cindex breakpoint on variable modification
2421A @dfn{watchpoint} is a special breakpoint that stops your program
2422when the value of an expression changes. You must use a different
2423command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2424watchpoints}), but aside from that, you can manage a watchpoint like
2425any other breakpoint: you enable, disable, and delete both breakpoints
2426and watchpoints using the same commands.
2427
2428You can arrange to have values from your program displayed automatically
2429whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2430Automatic display}.
2431
2432@cindex catchpoints
2433@cindex breakpoint on events
2434A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2435when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2436exception or the loading of a library. As with watchpoints, you use a
2437different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2438catchpoints}), but aside from that, you can manage a catchpoint like any
2439other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2440@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2441
2442@cindex breakpoint numbers
2443@cindex numbers for breakpoints
2444@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2445catchpoint when you create it; these numbers are successive integers
2446starting with one. In many of the commands for controlling various
2447features of breakpoints you use the breakpoint number to say which
2448breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2449@dfn{disabled}; if disabled, it has no effect on your program until you
2450enable it again.
2451
c5394b80
JM
2452@cindex breakpoint ranges
2453@cindex ranges of breakpoints
2454Some @value{GDBN} commands accept a range of breakpoints on which to
2455operate. A breakpoint range is either a single breakpoint number, like
2456@samp{5}, or two such numbers, in increasing order, separated by a
2457hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2458all breakpoint in that range are operated on.
2459
c906108c
SS
2460@menu
2461* Set Breaks:: Setting breakpoints
2462* Set Watchpoints:: Setting watchpoints
2463* Set Catchpoints:: Setting catchpoints
2464* Delete Breaks:: Deleting breakpoints
2465* Disabling:: Disabling breakpoints
2466* Conditions:: Break conditions
2467* Break Commands:: Breakpoint command lists
c906108c 2468* Breakpoint Menus:: Breakpoint menus
d4f3574e 2469* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2470* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2471@end menu
2472
6d2ebf8b 2473@node Set Breaks
c906108c
SS
2474@subsection Setting breakpoints
2475
5d161b24 2476@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2477@c consider in particular declaration with/without initialization.
2478@c
2479@c FIXME 2 is there stuff on this already? break at fun start, already init?
2480
2481@kindex break
41afff9a
EZ
2482@kindex b @r{(@code{break})}
2483@vindex $bpnum@r{, convenience variable}
c906108c
SS
2484@cindex latest breakpoint
2485Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2486@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2487number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2488Vars,, Convenience variables}, for a discussion of what you can do with
2489convenience variables.
2490
2491You have several ways to say where the breakpoint should go.
2492
2493@table @code
2494@item break @var{function}
5d161b24 2495Set a breakpoint at entry to function @var{function}.
c906108c 2496When using source languages that permit overloading of symbols, such as
b37052ae 2497C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2498@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2499
2500@item break +@var{offset}
2501@itemx break -@var{offset}
2502Set a breakpoint some number of lines forward or back from the position
d4f3574e 2503at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2504(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2505
2506@item break @var{linenum}
2507Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2508The current source file is the last file whose source text was printed.
2509The breakpoint will stop your program just before it executes any of the
c906108c
SS
2510code on that line.
2511
2512@item break @var{filename}:@var{linenum}
2513Set a breakpoint at line @var{linenum} in source file @var{filename}.
2514
2515@item break @var{filename}:@var{function}
2516Set a breakpoint at entry to function @var{function} found in file
2517@var{filename}. Specifying a file name as well as a function name is
2518superfluous except when multiple files contain similarly named
2519functions.
2520
2521@item break *@var{address}
2522Set a breakpoint at address @var{address}. You can use this to set
2523breakpoints in parts of your program which do not have debugging
2524information or source files.
2525
2526@item break
2527When called without any arguments, @code{break} sets a breakpoint at
2528the next instruction to be executed in the selected stack frame
2529(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2530innermost, this makes your program stop as soon as control
2531returns to that frame. This is similar to the effect of a
2532@code{finish} command in the frame inside the selected frame---except
2533that @code{finish} does not leave an active breakpoint. If you use
2534@code{break} without an argument in the innermost frame, @value{GDBN} stops
2535the next time it reaches the current location; this may be useful
2536inside loops.
2537
2538@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2539least one instruction has been executed. If it did not do this, you
2540would be unable to proceed past a breakpoint without first disabling the
2541breakpoint. This rule applies whether or not the breakpoint already
2542existed when your program stopped.
2543
2544@item break @dots{} if @var{cond}
2545Set a breakpoint with condition @var{cond}; evaluate the expression
2546@var{cond} each time the breakpoint is reached, and stop only if the
2547value is nonzero---that is, if @var{cond} evaluates as true.
2548@samp{@dots{}} stands for one of the possible arguments described
2549above (or no argument) specifying where to break. @xref{Conditions,
2550,Break conditions}, for more information on breakpoint conditions.
2551
2552@kindex tbreak
2553@item tbreak @var{args}
2554Set a breakpoint enabled only for one stop. @var{args} are the
2555same as for the @code{break} command, and the breakpoint is set in the same
2556way, but the breakpoint is automatically deleted after the first time your
2557program stops there. @xref{Disabling, ,Disabling breakpoints}.
2558
c906108c
SS
2559@kindex hbreak
2560@item hbreak @var{args}
d4f3574e
SS
2561Set a hardware-assisted breakpoint. @var{args} are the same as for the
2562@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2563breakpoint requires hardware support and some target hardware may not
2564have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2565debugging, so you can set a breakpoint at an instruction without
2566changing the instruction. This can be used with the new trap-generation
2567provided by SPARClite DSU and some x86-based targets. These targets
2568will generate traps when a program accesses some data or instruction
2569address that is assigned to the debug registers. However the hardware
2570breakpoint registers can take a limited number of breakpoints. For
2571example, on the DSU, only two data breakpoints can be set at a time, and
2572@value{GDBN} will reject this command if more than two are used. Delete
2573or disable unused hardware breakpoints before setting new ones
2574(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2575@xref{set remote hardware-breakpoint-limit}.
2576
c906108c
SS
2577
2578@kindex thbreak
2579@item thbreak @var{args}
2580Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2581are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2582the same way. However, like the @code{tbreak} command,
c906108c
SS
2583the breakpoint is automatically deleted after the
2584first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2585command, the breakpoint requires hardware support and some target hardware
2586may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2587See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2588
2589@kindex rbreak
2590@cindex regular expression
2591@item rbreak @var{regex}
c906108c 2592Set breakpoints on all functions matching the regular expression
11cf8741
JM
2593@var{regex}. This command sets an unconditional breakpoint on all
2594matches, printing a list of all breakpoints it set. Once these
2595breakpoints are set, they are treated just like the breakpoints set with
2596the @code{break} command. You can delete them, disable them, or make
2597them conditional the same way as any other breakpoint.
2598
2599The syntax of the regular expression is the standard one used with tools
2600like @file{grep}. Note that this is different from the syntax used by
2601shells, so for instance @code{foo*} matches all functions that include
2602an @code{fo} followed by zero or more @code{o}s. There is an implicit
2603@code{.*} leading and trailing the regular expression you supply, so to
2604match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2605
f7dc1244 2606@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2607When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2608breakpoints on overloaded functions that are not members of any special
2609classes.
c906108c 2610
f7dc1244
EZ
2611@cindex set breakpoints on all functions
2612The @code{rbreak} command can be used to set breakpoints in
2613@strong{all} the functions in a program, like this:
2614
2615@smallexample
2616(@value{GDBP}) rbreak .
2617@end smallexample
2618
c906108c
SS
2619@kindex info breakpoints
2620@cindex @code{$_} and @code{info breakpoints}
2621@item info breakpoints @r{[}@var{n}@r{]}
2622@itemx info break @r{[}@var{n}@r{]}
2623@itemx info watchpoints @r{[}@var{n}@r{]}
2624Print a table of all breakpoints, watchpoints, and catchpoints set and
2625not deleted, with the following columns for each breakpoint:
2626
2627@table @emph
2628@item Breakpoint Numbers
2629@item Type
2630Breakpoint, watchpoint, or catchpoint.
2631@item Disposition
2632Whether the breakpoint is marked to be disabled or deleted when hit.
2633@item Enabled or Disabled
2634Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2635that are not enabled.
2636@item Address
2650777c
JJ
2637Where the breakpoint is in your program, as a memory address. If the
2638breakpoint is pending (see below for details) on a future load of a shared library, the address
2639will be listed as @samp{<PENDING>}.
c906108c
SS
2640@item What
2641Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2642line number. For a pending breakpoint, the original string passed to
2643the breakpoint command will be listed as it cannot be resolved until
2644the appropriate shared library is loaded in the future.
c906108c
SS
2645@end table
2646
2647@noindent
2648If a breakpoint is conditional, @code{info break} shows the condition on
2649the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2650are listed after that. A pending breakpoint is allowed to have a condition
2651specified for it. The condition is not parsed for validity until a shared
2652library is loaded that allows the pending breakpoint to resolve to a
2653valid location.
c906108c
SS
2654
2655@noindent
2656@code{info break} with a breakpoint
2657number @var{n} as argument lists only that breakpoint. The
2658convenience variable @code{$_} and the default examining-address for
2659the @code{x} command are set to the address of the last breakpoint
5d161b24 2660listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2661
2662@noindent
2663@code{info break} displays a count of the number of times the breakpoint
2664has been hit. This is especially useful in conjunction with the
2665@code{ignore} command. You can ignore a large number of breakpoint
2666hits, look at the breakpoint info to see how many times the breakpoint
2667was hit, and then run again, ignoring one less than that number. This
2668will get you quickly to the last hit of that breakpoint.
2669@end table
2670
2671@value{GDBN} allows you to set any number of breakpoints at the same place in
2672your program. There is nothing silly or meaningless about this. When
2673the breakpoints are conditional, this is even useful
2674(@pxref{Conditions, ,Break conditions}).
2675
2650777c 2676@cindex pending breakpoints
dd79a6cf
JJ
2677If a specified breakpoint location cannot be found, it may be due to the fact
2678that the location is in a shared library that is yet to be loaded. In such
2679a case, you may want @value{GDBN} to create a special breakpoint (known as
2680a @dfn{pending breakpoint}) that
2681attempts to resolve itself in the future when an appropriate shared library
2682gets loaded.
2683
2684Pending breakpoints are useful to set at the start of your
2650777c
JJ
2685@value{GDBN} session for locations that you know will be dynamically loaded
2686later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2687a check is made to see if the load resolves any pending breakpoint locations.
2688If a pending breakpoint location gets resolved,
2689a regular breakpoint is created and the original pending breakpoint is removed.
2690
2691@value{GDBN} provides some additional commands for controlling pending
2692breakpoint support:
2693
2694@kindex set breakpoint pending
2695@kindex show breakpoint pending
2696@table @code
2697@item set breakpoint pending auto
2698This is the default behavior. When @value{GDBN} cannot find the breakpoint
2699location, it queries you whether a pending breakpoint should be created.
2700
2701@item set breakpoint pending on
2702This indicates that an unrecognized breakpoint location should automatically
2703result in a pending breakpoint being created.
2704
2705@item set breakpoint pending off
2706This indicates that pending breakpoints are not to be created. Any
2707unrecognized breakpoint location results in an error. This setting does
2708not affect any pending breakpoints previously created.
2709
2710@item show breakpoint pending
2711Show the current behavior setting for creating pending breakpoints.
2712@end table
2650777c 2713
649e03f6
RM
2714@cindex operations allowed on pending breakpoints
2715Normal breakpoint operations apply to pending breakpoints as well. You may
2716specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2717breakpoint is reached. You can also enable or disable
2718the pending breakpoint. When you specify a condition for a pending breakpoint,
2719the parsing of the condition will be deferred until the point where the
2720pending breakpoint location is resolved. Disabling a pending breakpoint
2721tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2722shared library load. When a pending breakpoint is re-enabled,
649e03f6 2723@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2724This is done because any number of shared library loads could have
2725occurred since the time the breakpoint was disabled and one or more
2726of these loads could resolve the location.
2727
c906108c
SS
2728@cindex negative breakpoint numbers
2729@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2730@value{GDBN} itself sometimes sets breakpoints in your program for
2731special purposes, such as proper handling of @code{longjmp} (in C
2732programs). These internal breakpoints are assigned negative numbers,
2733starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2734You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2735@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2736
2737
6d2ebf8b 2738@node Set Watchpoints
c906108c
SS
2739@subsection Setting watchpoints
2740
2741@cindex setting watchpoints
2742@cindex software watchpoints
2743@cindex hardware watchpoints
2744You can use a watchpoint to stop execution whenever the value of an
2745expression changes, without having to predict a particular place where
2746this may happen.
2747
2748Depending on your system, watchpoints may be implemented in software or
2df3850c 2749hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2750program and testing the variable's value each time, which is hundreds of
2751times slower than normal execution. (But this may still be worth it, to
2752catch errors where you have no clue what part of your program is the
2753culprit.)
2754
1104b9e7 2755On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2756@value{GDBN} includes support for
c906108c
SS
2757hardware watchpoints, which do not slow down the running of your
2758program.
2759
2760@table @code
2761@kindex watch
2762@item watch @var{expr}
2763Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2764is written into by the program and its value changes.
2765
2766@kindex rwatch
2767@item rwatch @var{expr}
2768Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2769
2770@kindex awatch
2771@item awatch @var{expr}
2df3850c 2772Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2773by the program.
c906108c
SS
2774
2775@kindex info watchpoints
2776@item info watchpoints
2777This command prints a list of watchpoints, breakpoints, and catchpoints;
2778it is the same as @code{info break}.
2779@end table
2780
2781@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2782watchpoints execute very quickly, and the debugger reports a change in
2783value at the exact instruction where the change occurs. If @value{GDBN}
2784cannot set a hardware watchpoint, it sets a software watchpoint, which
2785executes more slowly and reports the change in value at the next
2786statement, not the instruction, after the change occurs.
2787
2788When you issue the @code{watch} command, @value{GDBN} reports
2789
474c8240 2790@smallexample
c906108c 2791Hardware watchpoint @var{num}: @var{expr}
474c8240 2792@end smallexample
c906108c
SS
2793
2794@noindent
2795if it was able to set a hardware watchpoint.
2796
7be570e7
JM
2797Currently, the @code{awatch} and @code{rwatch} commands can only set
2798hardware watchpoints, because accesses to data that don't change the
2799value of the watched expression cannot be detected without examining
2800every instruction as it is being executed, and @value{GDBN} does not do
2801that currently. If @value{GDBN} finds that it is unable to set a
2802hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2803will print a message like this:
2804
2805@smallexample
2806Expression cannot be implemented with read/access watchpoint.
2807@end smallexample
2808
2809Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2810data type of the watched expression is wider than what a hardware
2811watchpoint on the target machine can handle. For example, some systems
2812can only watch regions that are up to 4 bytes wide; on such systems you
2813cannot set hardware watchpoints for an expression that yields a
2814double-precision floating-point number (which is typically 8 bytes
2815wide). As a work-around, it might be possible to break the large region
2816into a series of smaller ones and watch them with separate watchpoints.
2817
2818If you set too many hardware watchpoints, @value{GDBN} might be unable
2819to insert all of them when you resume the execution of your program.
2820Since the precise number of active watchpoints is unknown until such
2821time as the program is about to be resumed, @value{GDBN} might not be
2822able to warn you about this when you set the watchpoints, and the
2823warning will be printed only when the program is resumed:
2824
2825@smallexample
2826Hardware watchpoint @var{num}: Could not insert watchpoint
2827@end smallexample
2828
2829@noindent
2830If this happens, delete or disable some of the watchpoints.
2831
2832The SPARClite DSU will generate traps when a program accesses some data
2833or instruction address that is assigned to the debug registers. For the
2834data addresses, DSU facilitates the @code{watch} command. However the
2835hardware breakpoint registers can only take two data watchpoints, and
2836both watchpoints must be the same kind. For example, you can set two
2837watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2838@strong{or} two with @code{awatch} commands, but you cannot set one
2839watchpoint with one command and the other with a different command.
c906108c
SS
2840@value{GDBN} will reject the command if you try to mix watchpoints.
2841Delete or disable unused watchpoint commands before setting new ones.
2842
2843If you call a function interactively using @code{print} or @code{call},
2df3850c 2844any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2845kind of breakpoint or the call completes.
2846
7be570e7
JM
2847@value{GDBN} automatically deletes watchpoints that watch local
2848(automatic) variables, or expressions that involve such variables, when
2849they go out of scope, that is, when the execution leaves the block in
2850which these variables were defined. In particular, when the program
2851being debugged terminates, @emph{all} local variables go out of scope,
2852and so only watchpoints that watch global variables remain set. If you
2853rerun the program, you will need to set all such watchpoints again. One
2854way of doing that would be to set a code breakpoint at the entry to the
2855@code{main} function and when it breaks, set all the watchpoints.
2856
c906108c
SS
2857@quotation
2858@cindex watchpoints and threads
2859@cindex threads and watchpoints
c906108c
SS
2860@emph{Warning:} In multi-thread programs, watchpoints have only limited
2861usefulness. With the current watchpoint implementation, @value{GDBN}
2862can only watch the value of an expression @emph{in a single thread}. If
2863you are confident that the expression can only change due to the current
2864thread's activity (and if you are also confident that no other thread
2865can become current), then you can use watchpoints as usual. However,
2866@value{GDBN} may not notice when a non-current thread's activity changes
2867the expression.
53a5351d 2868
d4f3574e 2869@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2870@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2871have only limited usefulness. If @value{GDBN} creates a software
2872watchpoint, it can only watch the value of an expression @emph{in a
2873single thread}. If you are confident that the expression can only
2874change due to the current thread's activity (and if you are also
2875confident that no other thread can become current), then you can use
2876software watchpoints as usual. However, @value{GDBN} may not notice
2877when a non-current thread's activity changes the expression. (Hardware
2878watchpoints, in contrast, watch an expression in all threads.)
c906108c 2879@end quotation
c906108c 2880
501eef12
AC
2881@xref{set remote hardware-watchpoint-limit}.
2882
6d2ebf8b 2883@node Set Catchpoints
c906108c 2884@subsection Setting catchpoints
d4f3574e 2885@cindex catchpoints, setting
c906108c
SS
2886@cindex exception handlers
2887@cindex event handling
2888
2889You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2890kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2891shared library. Use the @code{catch} command to set a catchpoint.
2892
2893@table @code
2894@kindex catch
2895@item catch @var{event}
2896Stop when @var{event} occurs. @var{event} can be any of the following:
2897@table @code
2898@item throw
4644b6e3 2899@cindex stop on C@t{++} exceptions
b37052ae 2900The throwing of a C@t{++} exception.
c906108c
SS
2901
2902@item catch
b37052ae 2903The catching of a C@t{++} exception.
c906108c
SS
2904
2905@item exec
4644b6e3 2906@cindex break on fork/exec
c906108c
SS
2907A call to @code{exec}. This is currently only available for HP-UX.
2908
2909@item fork
c906108c
SS
2910A call to @code{fork}. This is currently only available for HP-UX.
2911
2912@item vfork
c906108c
SS
2913A call to @code{vfork}. This is currently only available for HP-UX.
2914
2915@item load
2916@itemx load @var{libname}
4644b6e3 2917@cindex break on load/unload of shared library
c906108c
SS
2918The dynamic loading of any shared library, or the loading of the library
2919@var{libname}. This is currently only available for HP-UX.
2920
2921@item unload
2922@itemx unload @var{libname}
c906108c
SS
2923The unloading of any dynamically loaded shared library, or the unloading
2924of the library @var{libname}. This is currently only available for HP-UX.
2925@end table
2926
2927@item tcatch @var{event}
2928Set a catchpoint that is enabled only for one stop. The catchpoint is
2929automatically deleted after the first time the event is caught.
2930
2931@end table
2932
2933Use the @code{info break} command to list the current catchpoints.
2934
b37052ae 2935There are currently some limitations to C@t{++} exception handling
c906108c
SS
2936(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2937
2938@itemize @bullet
2939@item
2940If you call a function interactively, @value{GDBN} normally returns
2941control to you when the function has finished executing. If the call
2942raises an exception, however, the call may bypass the mechanism that
2943returns control to you and cause your program either to abort or to
2944simply continue running until it hits a breakpoint, catches a signal
2945that @value{GDBN} is listening for, or exits. This is the case even if
2946you set a catchpoint for the exception; catchpoints on exceptions are
2947disabled within interactive calls.
2948
2949@item
2950You cannot raise an exception interactively.
2951
2952@item
2953You cannot install an exception handler interactively.
2954@end itemize
2955
2956@cindex raise exceptions
2957Sometimes @code{catch} is not the best way to debug exception handling:
2958if you need to know exactly where an exception is raised, it is better to
2959stop @emph{before} the exception handler is called, since that way you
2960can see the stack before any unwinding takes place. If you set a
2961breakpoint in an exception handler instead, it may not be easy to find
2962out where the exception was raised.
2963
2964To stop just before an exception handler is called, you need some
b37052ae 2965knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2966raised by calling a library function named @code{__raise_exception}
2967which has the following ANSI C interface:
2968
474c8240 2969@smallexample
c906108c 2970 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2971 @var{id} is the exception identifier. */
2972 void __raise_exception (void **addr, void *id);
474c8240 2973@end smallexample
c906108c
SS
2974
2975@noindent
2976To make the debugger catch all exceptions before any stack
2977unwinding takes place, set a breakpoint on @code{__raise_exception}
2978(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2979
2980With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2981that depends on the value of @var{id}, you can stop your program when
2982a specific exception is raised. You can use multiple conditional
2983breakpoints to stop your program when any of a number of exceptions are
2984raised.
2985
2986
6d2ebf8b 2987@node Delete Breaks
c906108c
SS
2988@subsection Deleting breakpoints
2989
2990@cindex clearing breakpoints, watchpoints, catchpoints
2991@cindex deleting breakpoints, watchpoints, catchpoints
2992It is often necessary to eliminate a breakpoint, watchpoint, or
2993catchpoint once it has done its job and you no longer want your program
2994to stop there. This is called @dfn{deleting} the breakpoint. A
2995breakpoint that has been deleted no longer exists; it is forgotten.
2996
2997With the @code{clear} command you can delete breakpoints according to
2998where they are in your program. With the @code{delete} command you can
2999delete individual breakpoints, watchpoints, or catchpoints by specifying
3000their breakpoint numbers.
3001
3002It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3003automatically ignores breakpoints on the first instruction to be executed
3004when you continue execution without changing the execution address.
3005
3006@table @code
3007@kindex clear
3008@item clear
3009Delete any breakpoints at the next instruction to be executed in the
3010selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3011the innermost frame is selected, this is a good way to delete a
3012breakpoint where your program just stopped.
3013
3014@item clear @var{function}
3015@itemx clear @var{filename}:@var{function}
3016Delete any breakpoints set at entry to the function @var{function}.
3017
3018@item clear @var{linenum}
3019@itemx clear @var{filename}:@var{linenum}
3020Delete any breakpoints set at or within the code of the specified line.
3021
3022@cindex delete breakpoints
3023@kindex delete
41afff9a 3024@kindex d @r{(@code{delete})}
c5394b80
JM
3025@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3026Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3027ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3028breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3029confirm off}). You can abbreviate this command as @code{d}.
3030@end table
3031
6d2ebf8b 3032@node Disabling
c906108c
SS
3033@subsection Disabling breakpoints
3034
4644b6e3 3035@cindex enable/disable a breakpoint
c906108c
SS
3036Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3037prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3038it had been deleted, but remembers the information on the breakpoint so
3039that you can @dfn{enable} it again later.
3040
3041You disable and enable breakpoints, watchpoints, and catchpoints with
3042the @code{enable} and @code{disable} commands, optionally specifying one
3043or more breakpoint numbers as arguments. Use @code{info break} or
3044@code{info watch} to print a list of breakpoints, watchpoints, and
3045catchpoints if you do not know which numbers to use.
3046
3047A breakpoint, watchpoint, or catchpoint can have any of four different
3048states of enablement:
3049
3050@itemize @bullet
3051@item
3052Enabled. The breakpoint stops your program. A breakpoint set
3053with the @code{break} command starts out in this state.
3054@item
3055Disabled. The breakpoint has no effect on your program.
3056@item
3057Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3058disabled.
c906108c
SS
3059@item
3060Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3061immediately after it does so it is deleted permanently. A breakpoint
3062set with the @code{tbreak} command starts out in this state.
c906108c
SS
3063@end itemize
3064
3065You can use the following commands to enable or disable breakpoints,
3066watchpoints, and catchpoints:
3067
3068@table @code
c906108c 3069@kindex disable
41afff9a 3070@kindex dis @r{(@code{disable})}
c5394b80 3071@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3072Disable the specified breakpoints---or all breakpoints, if none are
3073listed. A disabled breakpoint has no effect but is not forgotten. All
3074options such as ignore-counts, conditions and commands are remembered in
3075case the breakpoint is enabled again later. You may abbreviate
3076@code{disable} as @code{dis}.
3077
c906108c 3078@kindex enable
c5394b80 3079@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3080Enable the specified breakpoints (or all defined breakpoints). They
3081become effective once again in stopping your program.
3082
c5394b80 3083@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3084Enable the specified breakpoints temporarily. @value{GDBN} disables any
3085of these breakpoints immediately after stopping your program.
3086
c5394b80 3087@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3088Enable the specified breakpoints to work once, then die. @value{GDBN}
3089deletes any of these breakpoints as soon as your program stops there.
3090@end table
3091
d4f3574e
SS
3092@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3093@c confusing: tbreak is also initially enabled.
c906108c
SS
3094Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3095,Setting breakpoints}), breakpoints that you set are initially enabled;
3096subsequently, they become disabled or enabled only when you use one of
3097the commands above. (The command @code{until} can set and delete a
3098breakpoint of its own, but it does not change the state of your other
3099breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3100stepping}.)
3101
6d2ebf8b 3102@node Conditions
c906108c
SS
3103@subsection Break conditions
3104@cindex conditional breakpoints
3105@cindex breakpoint conditions
3106
3107@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3108@c in particular for a watchpoint?
c906108c
SS
3109The simplest sort of breakpoint breaks every time your program reaches a
3110specified place. You can also specify a @dfn{condition} for a
3111breakpoint. A condition is just a Boolean expression in your
3112programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3113a condition evaluates the expression each time your program reaches it,
3114and your program stops only if the condition is @emph{true}.
3115
3116This is the converse of using assertions for program validation; in that
3117situation, you want to stop when the assertion is violated---that is,
3118when the condition is false. In C, if you want to test an assertion expressed
3119by the condition @var{assert}, you should set the condition
3120@samp{! @var{assert}} on the appropriate breakpoint.
3121
3122Conditions are also accepted for watchpoints; you may not need them,
3123since a watchpoint is inspecting the value of an expression anyhow---but
3124it might be simpler, say, to just set a watchpoint on a variable name,
3125and specify a condition that tests whether the new value is an interesting
3126one.
3127
3128Break conditions can have side effects, and may even call functions in
3129your program. This can be useful, for example, to activate functions
3130that log program progress, or to use your own print functions to
3131format special data structures. The effects are completely predictable
3132unless there is another enabled breakpoint at the same address. (In
3133that case, @value{GDBN} might see the other breakpoint first and stop your
3134program without checking the condition of this one.) Note that
d4f3574e
SS
3135breakpoint commands are usually more convenient and flexible than break
3136conditions for the
c906108c
SS
3137purpose of performing side effects when a breakpoint is reached
3138(@pxref{Break Commands, ,Breakpoint command lists}).
3139
3140Break conditions can be specified when a breakpoint is set, by using
3141@samp{if} in the arguments to the @code{break} command. @xref{Set
3142Breaks, ,Setting breakpoints}. They can also be changed at any time
3143with the @code{condition} command.
53a5351d 3144
c906108c
SS
3145You can also use the @code{if} keyword with the @code{watch} command.
3146The @code{catch} command does not recognize the @code{if} keyword;
3147@code{condition} is the only way to impose a further condition on a
3148catchpoint.
c906108c
SS
3149
3150@table @code
3151@kindex condition
3152@item condition @var{bnum} @var{expression}
3153Specify @var{expression} as the break condition for breakpoint,
3154watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3155breakpoint @var{bnum} stops your program only if the value of
3156@var{expression} is true (nonzero, in C). When you use
3157@code{condition}, @value{GDBN} checks @var{expression} immediately for
3158syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3159referents in the context of your breakpoint. If @var{expression} uses
3160symbols not referenced in the context of the breakpoint, @value{GDBN}
3161prints an error message:
3162
474c8240 3163@smallexample
d4f3574e 3164No symbol "foo" in current context.
474c8240 3165@end smallexample
d4f3574e
SS
3166
3167@noindent
c906108c
SS
3168@value{GDBN} does
3169not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3170command (or a command that sets a breakpoint with a condition, like
3171@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3172
3173@item condition @var{bnum}
3174Remove the condition from breakpoint number @var{bnum}. It becomes
3175an ordinary unconditional breakpoint.
3176@end table
3177
3178@cindex ignore count (of breakpoint)
3179A special case of a breakpoint condition is to stop only when the
3180breakpoint has been reached a certain number of times. This is so
3181useful that there is a special way to do it, using the @dfn{ignore
3182count} of the breakpoint. Every breakpoint has an ignore count, which
3183is an integer. Most of the time, the ignore count is zero, and
3184therefore has no effect. But if your program reaches a breakpoint whose
3185ignore count is positive, then instead of stopping, it just decrements
3186the ignore count by one and continues. As a result, if the ignore count
3187value is @var{n}, the breakpoint does not stop the next @var{n} times
3188your program reaches it.
3189
3190@table @code
3191@kindex ignore
3192@item ignore @var{bnum} @var{count}
3193Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3194The next @var{count} times the breakpoint is reached, your program's
3195execution does not stop; other than to decrement the ignore count, @value{GDBN}
3196takes no action.
3197
3198To make the breakpoint stop the next time it is reached, specify
3199a count of zero.
3200
3201When you use @code{continue} to resume execution of your program from a
3202breakpoint, you can specify an ignore count directly as an argument to
3203@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3204Stepping,,Continuing and stepping}.
3205
3206If a breakpoint has a positive ignore count and a condition, the
3207condition is not checked. Once the ignore count reaches zero,
3208@value{GDBN} resumes checking the condition.
3209
3210You could achieve the effect of the ignore count with a condition such
3211as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3212is decremented each time. @xref{Convenience Vars, ,Convenience
3213variables}.
3214@end table
3215
3216Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3217
3218
6d2ebf8b 3219@node Break Commands
c906108c
SS
3220@subsection Breakpoint command lists
3221
3222@cindex breakpoint commands
3223You can give any breakpoint (or watchpoint or catchpoint) a series of
3224commands to execute when your program stops due to that breakpoint. For
3225example, you might want to print the values of certain expressions, or
3226enable other breakpoints.
3227
3228@table @code
3229@kindex commands
3230@kindex end
3231@item commands @r{[}@var{bnum}@r{]}
3232@itemx @dots{} @var{command-list} @dots{}
3233@itemx end
3234Specify a list of commands for breakpoint number @var{bnum}. The commands
3235themselves appear on the following lines. Type a line containing just
3236@code{end} to terminate the commands.
3237
3238To remove all commands from a breakpoint, type @code{commands} and
3239follow it immediately with @code{end}; that is, give no commands.
3240
3241With no @var{bnum} argument, @code{commands} refers to the last
3242breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3243recently encountered).
3244@end table
3245
3246Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3247disabled within a @var{command-list}.
3248
3249You can use breakpoint commands to start your program up again. Simply
3250use the @code{continue} command, or @code{step}, or any other command
3251that resumes execution.
3252
3253Any other commands in the command list, after a command that resumes
3254execution, are ignored. This is because any time you resume execution
3255(even with a simple @code{next} or @code{step}), you may encounter
3256another breakpoint---which could have its own command list, leading to
3257ambiguities about which list to execute.
3258
3259@kindex silent
3260If the first command you specify in a command list is @code{silent}, the
3261usual message about stopping at a breakpoint is not printed. This may
3262be desirable for breakpoints that are to print a specific message and
3263then continue. If none of the remaining commands print anything, you
3264see no sign that the breakpoint was reached. @code{silent} is
3265meaningful only at the beginning of a breakpoint command list.
3266
3267The commands @code{echo}, @code{output}, and @code{printf} allow you to
3268print precisely controlled output, and are often useful in silent
3269breakpoints. @xref{Output, ,Commands for controlled output}.
3270
3271For example, here is how you could use breakpoint commands to print the
3272value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3273
474c8240 3274@smallexample
c906108c
SS
3275break foo if x>0
3276commands
3277silent
3278printf "x is %d\n",x
3279cont
3280end
474c8240 3281@end smallexample
c906108c
SS
3282
3283One application for breakpoint commands is to compensate for one bug so
3284you can test for another. Put a breakpoint just after the erroneous line
3285of code, give it a condition to detect the case in which something
3286erroneous has been done, and give it commands to assign correct values
3287to any variables that need them. End with the @code{continue} command
3288so that your program does not stop, and start with the @code{silent}
3289command so that no output is produced. Here is an example:
3290
474c8240 3291@smallexample
c906108c
SS
3292break 403
3293commands
3294silent
3295set x = y + 4
3296cont
3297end
474c8240 3298@end smallexample
c906108c 3299
6d2ebf8b 3300@node Breakpoint Menus
c906108c
SS
3301@subsection Breakpoint menus
3302@cindex overloading
3303@cindex symbol overloading
3304
b383017d 3305Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3306single function name
c906108c
SS
3307to be defined several times, for application in different contexts.
3308This is called @dfn{overloading}. When a function name is overloaded,
3309@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3310a breakpoint. If you realize this is a problem, you can use
3311something like @samp{break @var{function}(@var{types})} to specify which
3312particular version of the function you want. Otherwise, @value{GDBN} offers
3313you a menu of numbered choices for different possible breakpoints, and
3314waits for your selection with the prompt @samp{>}. The first two
3315options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3316sets a breakpoint at each definition of @var{function}, and typing
3317@kbd{0} aborts the @code{break} command without setting any new
3318breakpoints.
3319
3320For example, the following session excerpt shows an attempt to set a
3321breakpoint at the overloaded symbol @code{String::after}.
3322We choose three particular definitions of that function name:
3323
3324@c FIXME! This is likely to change to show arg type lists, at least
3325@smallexample
3326@group
3327(@value{GDBP}) b String::after
3328[0] cancel
3329[1] all
3330[2] file:String.cc; line number:867
3331[3] file:String.cc; line number:860
3332[4] file:String.cc; line number:875
3333[5] file:String.cc; line number:853
3334[6] file:String.cc; line number:846
3335[7] file:String.cc; line number:735
3336> 2 4 6
3337Breakpoint 1 at 0xb26c: file String.cc, line 867.
3338Breakpoint 2 at 0xb344: file String.cc, line 875.
3339Breakpoint 3 at 0xafcc: file String.cc, line 846.
3340Multiple breakpoints were set.
3341Use the "delete" command to delete unwanted
3342 breakpoints.
3343(@value{GDBP})
3344@end group
3345@end smallexample
c906108c
SS
3346
3347@c @ifclear BARETARGET
6d2ebf8b 3348@node Error in Breakpoints
d4f3574e 3349@subsection ``Cannot insert breakpoints''
c906108c
SS
3350@c
3351@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3352@c
d4f3574e
SS
3353Under some operating systems, breakpoints cannot be used in a program if
3354any other process is running that program. In this situation,
5d161b24 3355attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3356@value{GDBN} to print an error message:
3357
474c8240 3358@smallexample
d4f3574e
SS
3359Cannot insert breakpoints.
3360The same program may be running in another process.
474c8240 3361@end smallexample
d4f3574e
SS
3362
3363When this happens, you have three ways to proceed:
3364
3365@enumerate
3366@item
3367Remove or disable the breakpoints, then continue.
3368
3369@item
5d161b24 3370Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3371name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3372that @value{GDBN} should run your program under that name.
d4f3574e
SS
3373Then start your program again.
3374
3375@item
3376Relink your program so that the text segment is nonsharable, using the
3377linker option @samp{-N}. The operating system limitation may not apply
3378to nonsharable executables.
3379@end enumerate
c906108c
SS
3380@c @end ifclear
3381
d4f3574e
SS
3382A similar message can be printed if you request too many active
3383hardware-assisted breakpoints and watchpoints:
3384
3385@c FIXME: the precise wording of this message may change; the relevant
3386@c source change is not committed yet (Sep 3, 1999).
3387@smallexample
3388Stopped; cannot insert breakpoints.
3389You may have requested too many hardware breakpoints and watchpoints.
3390@end smallexample
3391
3392@noindent
3393This message is printed when you attempt to resume the program, since
3394only then @value{GDBN} knows exactly how many hardware breakpoints and
3395watchpoints it needs to insert.
3396
3397When this message is printed, you need to disable or remove some of the
3398hardware-assisted breakpoints and watchpoints, and then continue.
3399
1485d690
KB
3400@node Breakpoint related warnings
3401@subsection ``Breakpoint address adjusted...''
3402@cindex breakpoint address adjusted
3403
3404Some processor architectures place constraints on the addresses at
3405which breakpoints may be placed. For architectures thus constrained,
3406@value{GDBN} will attempt to adjust the breakpoint's address to comply
3407with the constraints dictated by the architecture.
3408
3409One example of such an architecture is the Fujitsu FR-V. The FR-V is
3410a VLIW architecture in which a number of RISC-like instructions may be
3411bundled together for parallel execution. The FR-V architecture
3412constrains the location of a breakpoint instruction within such a
3413bundle to the instruction with the lowest address. @value{GDBN}
3414honors this constraint by adjusting a breakpoint's address to the
3415first in the bundle.
3416
3417It is not uncommon for optimized code to have bundles which contain
3418instructions from different source statements, thus it may happen that
3419a breakpoint's address will be adjusted from one source statement to
3420another. Since this adjustment may significantly alter @value{GDBN}'s
3421breakpoint related behavior from what the user expects, a warning is
3422printed when the breakpoint is first set and also when the breakpoint
3423is hit.
3424
3425A warning like the one below is printed when setting a breakpoint
3426that's been subject to address adjustment:
3427
3428@smallexample
3429warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3430@end smallexample
3431
3432Such warnings are printed both for user settable and @value{GDBN}'s
3433internal breakpoints. If you see one of these warnings, you should
3434verify that a breakpoint set at the adjusted address will have the
3435desired affect. If not, the breakpoint in question may be removed and
b383017d 3436other breakpoints may be set which will have the desired behavior.
1485d690
KB
3437E.g., it may be sufficient to place the breakpoint at a later
3438instruction. A conditional breakpoint may also be useful in some
3439cases to prevent the breakpoint from triggering too often.
3440
3441@value{GDBN} will also issue a warning when stopping at one of these
3442adjusted breakpoints:
3443
3444@smallexample
3445warning: Breakpoint 1 address previously adjusted from 0x00010414
3446to 0x00010410.
3447@end smallexample
3448
3449When this warning is encountered, it may be too late to take remedial
3450action except in cases where the breakpoint is hit earlier or more
3451frequently than expected.
d4f3574e 3452
6d2ebf8b 3453@node Continuing and Stepping
c906108c
SS
3454@section Continuing and stepping
3455
3456@cindex stepping
3457@cindex continuing
3458@cindex resuming execution
3459@dfn{Continuing} means resuming program execution until your program
3460completes normally. In contrast, @dfn{stepping} means executing just
3461one more ``step'' of your program, where ``step'' may mean either one
3462line of source code, or one machine instruction (depending on what
7a292a7a
SS
3463particular command you use). Either when continuing or when stepping,
3464your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3465it stops due to a signal, you may want to use @code{handle}, or use
3466@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3467
3468@table @code
3469@kindex continue
41afff9a
EZ
3470@kindex c @r{(@code{continue})}
3471@kindex fg @r{(resume foreground execution)}
c906108c
SS
3472@item continue @r{[}@var{ignore-count}@r{]}
3473@itemx c @r{[}@var{ignore-count}@r{]}
3474@itemx fg @r{[}@var{ignore-count}@r{]}
3475Resume program execution, at the address where your program last stopped;
3476any breakpoints set at that address are bypassed. The optional argument
3477@var{ignore-count} allows you to specify a further number of times to
3478ignore a breakpoint at this location; its effect is like that of
3479@code{ignore} (@pxref{Conditions, ,Break conditions}).
3480
3481The argument @var{ignore-count} is meaningful only when your program
3482stopped due to a breakpoint. At other times, the argument to
3483@code{continue} is ignored.
3484
d4f3574e
SS
3485The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3486debugged program is deemed to be the foreground program) are provided
3487purely for convenience, and have exactly the same behavior as
3488@code{continue}.
c906108c
SS
3489@end table
3490
3491To resume execution at a different place, you can use @code{return}
3492(@pxref{Returning, ,Returning from a function}) to go back to the
3493calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3494different address}) to go to an arbitrary location in your program.
3495
3496A typical technique for using stepping is to set a breakpoint
3497(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3498beginning of the function or the section of your program where a problem
3499is believed to lie, run your program until it stops at that breakpoint,
3500and then step through the suspect area, examining the variables that are
3501interesting, until you see the problem happen.
3502
3503@table @code
3504@kindex step
41afff9a 3505@kindex s @r{(@code{step})}
c906108c
SS
3506@item step
3507Continue running your program until control reaches a different source
3508line, then stop it and return control to @value{GDBN}. This command is
3509abbreviated @code{s}.
3510
3511@quotation
3512@c "without debugging information" is imprecise; actually "without line
3513@c numbers in the debugging information". (gcc -g1 has debugging info but
3514@c not line numbers). But it seems complex to try to make that
3515@c distinction here.
3516@emph{Warning:} If you use the @code{step} command while control is
3517within a function that was compiled without debugging information,
3518execution proceeds until control reaches a function that does have
3519debugging information. Likewise, it will not step into a function which
3520is compiled without debugging information. To step through functions
3521without debugging information, use the @code{stepi} command, described
3522below.
3523@end quotation
3524
4a92d011
EZ
3525The @code{step} command only stops at the first instruction of a source
3526line. This prevents the multiple stops that could otherwise occur in
3527@code{switch} statements, @code{for} loops, etc. @code{step} continues
3528to stop if a function that has debugging information is called within
3529the line. In other words, @code{step} @emph{steps inside} any functions
3530called within the line.
c906108c 3531
d4f3574e
SS
3532Also, the @code{step} command only enters a function if there is line
3533number information for the function. Otherwise it acts like the
5d161b24 3534@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3535on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3536was any debugging information about the routine.
c906108c
SS
3537
3538@item step @var{count}
3539Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3540breakpoint is reached, or a signal not related to stepping occurs before
3541@var{count} steps, stepping stops right away.
c906108c
SS
3542
3543@kindex next
41afff9a 3544@kindex n @r{(@code{next})}
c906108c
SS
3545@item next @r{[}@var{count}@r{]}
3546Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3547This is similar to @code{step}, but function calls that appear within
3548the line of code are executed without stopping. Execution stops when
3549control reaches a different line of code at the original stack level
3550that was executing when you gave the @code{next} command. This command
3551is abbreviated @code{n}.
c906108c
SS
3552
3553An argument @var{count} is a repeat count, as for @code{step}.
3554
3555
3556@c FIX ME!! Do we delete this, or is there a way it fits in with
3557@c the following paragraph? --- Vctoria
3558@c
3559@c @code{next} within a function that lacks debugging information acts like
3560@c @code{step}, but any function calls appearing within the code of the
3561@c function are executed without stopping.
3562
d4f3574e
SS
3563The @code{next} command only stops at the first instruction of a
3564source line. This prevents multiple stops that could otherwise occur in
4a92d011 3565@code{switch} statements, @code{for} loops, etc.
c906108c 3566
b90a5f51
CF
3567@kindex set step-mode
3568@item set step-mode
3569@cindex functions without line info, and stepping
3570@cindex stepping into functions with no line info
3571@itemx set step-mode on
4a92d011 3572The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3573stop at the first instruction of a function which contains no debug line
3574information rather than stepping over it.
3575
4a92d011
EZ
3576This is useful in cases where you may be interested in inspecting the
3577machine instructions of a function which has no symbolic info and do not
3578want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3579
3580@item set step-mode off
4a92d011 3581Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3582debug information. This is the default.
3583
c906108c
SS
3584@kindex finish
3585@item finish
3586Continue running until just after function in the selected stack frame
3587returns. Print the returned value (if any).
3588
3589Contrast this with the @code{return} command (@pxref{Returning,
3590,Returning from a function}).
3591
3592@kindex until
41afff9a 3593@kindex u @r{(@code{until})}
c906108c
SS
3594@item until
3595@itemx u
3596Continue running until a source line past the current line, in the
3597current stack frame, is reached. This command is used to avoid single
3598stepping through a loop more than once. It is like the @code{next}
3599command, except that when @code{until} encounters a jump, it
3600automatically continues execution until the program counter is greater
3601than the address of the jump.
3602
3603This means that when you reach the end of a loop after single stepping
3604though it, @code{until} makes your program continue execution until it
3605exits the loop. In contrast, a @code{next} command at the end of a loop
3606simply steps back to the beginning of the loop, which forces you to step
3607through the next iteration.
3608
3609@code{until} always stops your program if it attempts to exit the current
3610stack frame.
3611
3612@code{until} may produce somewhat counterintuitive results if the order
3613of machine code does not match the order of the source lines. For
3614example, in the following excerpt from a debugging session, the @code{f}
3615(@code{frame}) command shows that execution is stopped at line
3616@code{206}; yet when we use @code{until}, we get to line @code{195}:
3617
474c8240 3618@smallexample
c906108c
SS
3619(@value{GDBP}) f
3620#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3621206 expand_input();
3622(@value{GDBP}) until
3623195 for ( ; argc > 0; NEXTARG) @{
474c8240 3624@end smallexample
c906108c
SS
3625
3626This happened because, for execution efficiency, the compiler had
3627generated code for the loop closure test at the end, rather than the
3628start, of the loop---even though the test in a C @code{for}-loop is
3629written before the body of the loop. The @code{until} command appeared
3630to step back to the beginning of the loop when it advanced to this
3631expression; however, it has not really gone to an earlier
3632statement---not in terms of the actual machine code.
3633
3634@code{until} with no argument works by means of single
3635instruction stepping, and hence is slower than @code{until} with an
3636argument.
3637
3638@item until @var{location}
3639@itemx u @var{location}
3640Continue running your program until either the specified location is
3641reached, or the current stack frame returns. @var{location} is any of
3642the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3643,Setting breakpoints}). This form of the command uses breakpoints, and
3644hence is quicker than @code{until} without an argument. The specified
3645location is actually reached only if it is in the current frame. This
3646implies that @code{until} can be used to skip over recursive function
3647invocations. For instance in the code below, if the current location is
3648line @code{96}, issuing @code{until 99} will execute the program up to
3649line @code{99} in the same invocation of factorial, i.e. after the inner
3650invocations have returned.
3651
3652@smallexample
365394 int factorial (int value)
365495 @{
365596 if (value > 1) @{
365697 value *= factorial (value - 1);
365798 @}
365899 return (value);
3659100 @}
3660@end smallexample
3661
3662
3663@kindex advance @var{location}
3664@itemx advance @var{location}
3665Continue running the program up to the given location. An argument is
3666required, anything of the same form as arguments for the @code{break}
3667command. Execution will also stop upon exit from the current stack
3668frame. This command is similar to @code{until}, but @code{advance} will
3669not skip over recursive function calls, and the target location doesn't
3670have to be in the same frame as the current one.
3671
c906108c
SS
3672
3673@kindex stepi
41afff9a 3674@kindex si @r{(@code{stepi})}
c906108c 3675@item stepi
96a2c332 3676@itemx stepi @var{arg}
c906108c
SS
3677@itemx si
3678Execute one machine instruction, then stop and return to the debugger.
3679
3680It is often useful to do @samp{display/i $pc} when stepping by machine
3681instructions. This makes @value{GDBN} automatically display the next
3682instruction to be executed, each time your program stops. @xref{Auto
3683Display,, Automatic display}.
3684
3685An argument is a repeat count, as in @code{step}.
3686
3687@need 750
3688@kindex nexti
41afff9a 3689@kindex ni @r{(@code{nexti})}
c906108c 3690@item nexti
96a2c332 3691@itemx nexti @var{arg}
c906108c
SS
3692@itemx ni
3693Execute one machine instruction, but if it is a function call,
3694proceed until the function returns.
3695
3696An argument is a repeat count, as in @code{next}.
3697@end table
3698
6d2ebf8b 3699@node Signals
c906108c
SS
3700@section Signals
3701@cindex signals
3702
3703A signal is an asynchronous event that can happen in a program. The
3704operating system defines the possible kinds of signals, and gives each
3705kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3706signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3707@code{SIGSEGV} is the signal a program gets from referencing a place in
3708memory far away from all the areas in use; @code{SIGALRM} occurs when
3709the alarm clock timer goes off (which happens only if your program has
3710requested an alarm).
3711
3712@cindex fatal signals
3713Some signals, including @code{SIGALRM}, are a normal part of the
3714functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3715errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3716program has not specified in advance some other way to handle the signal.
3717@code{SIGINT} does not indicate an error in your program, but it is normally
3718fatal so it can carry out the purpose of the interrupt: to kill the program.
3719
3720@value{GDBN} has the ability to detect any occurrence of a signal in your
3721program. You can tell @value{GDBN} in advance what to do for each kind of
3722signal.
3723
3724@cindex handling signals
24f93129
EZ
3725Normally, @value{GDBN} is set up to let the non-erroneous signals like
3726@code{SIGALRM} be silently passed to your program
3727(so as not to interfere with their role in the program's functioning)
c906108c
SS
3728but to stop your program immediately whenever an error signal happens.
3729You can change these settings with the @code{handle} command.
3730
3731@table @code
3732@kindex info signals
3733@item info signals
96a2c332 3734@itemx info handle
c906108c
SS
3735Print a table of all the kinds of signals and how @value{GDBN} has been told to
3736handle each one. You can use this to see the signal numbers of all
3737the defined types of signals.
3738
d4f3574e 3739@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3740
3741@kindex handle
3742@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3743Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3744can be the number of a signal or its name (with or without the
24f93129 3745@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3746@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3747known signals. The @var{keywords} say what change to make.
c906108c
SS
3748@end table
3749
3750@c @group
3751The keywords allowed by the @code{handle} command can be abbreviated.
3752Their full names are:
3753
3754@table @code
3755@item nostop
3756@value{GDBN} should not stop your program when this signal happens. It may
3757still print a message telling you that the signal has come in.
3758
3759@item stop
3760@value{GDBN} should stop your program when this signal happens. This implies
3761the @code{print} keyword as well.
3762
3763@item print
3764@value{GDBN} should print a message when this signal happens.
3765
3766@item noprint
3767@value{GDBN} should not mention the occurrence of the signal at all. This
3768implies the @code{nostop} keyword as well.
3769
3770@item pass
5ece1a18 3771@itemx noignore
c906108c
SS
3772@value{GDBN} should allow your program to see this signal; your program
3773can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3774and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3775
3776@item nopass
5ece1a18 3777@itemx ignore
c906108c 3778@value{GDBN} should not allow your program to see this signal.
5ece1a18 3779@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3780@end table
3781@c @end group
3782
d4f3574e
SS
3783When a signal stops your program, the signal is not visible to the
3784program until you
c906108c
SS
3785continue. Your program sees the signal then, if @code{pass} is in
3786effect for the signal in question @emph{at that time}. In other words,
3787after @value{GDBN} reports a signal, you can use the @code{handle}
3788command with @code{pass} or @code{nopass} to control whether your
3789program sees that signal when you continue.
3790
24f93129
EZ
3791The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3792non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3793@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3794erroneous signals.
3795
c906108c
SS
3796You can also use the @code{signal} command to prevent your program from
3797seeing a signal, or cause it to see a signal it normally would not see,
3798or to give it any signal at any time. For example, if your program stopped
3799due to some sort of memory reference error, you might store correct
3800values into the erroneous variables and continue, hoping to see more
3801execution; but your program would probably terminate immediately as
3802a result of the fatal signal once it saw the signal. To prevent this,
3803you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3804program a signal}.
c906108c 3805
6d2ebf8b 3806@node Thread Stops
c906108c
SS
3807@section Stopping and starting multi-thread programs
3808
3809When your program has multiple threads (@pxref{Threads,, Debugging
3810programs with multiple threads}), you can choose whether to set
3811breakpoints on all threads, or on a particular thread.
3812
3813@table @code
3814@cindex breakpoints and threads
3815@cindex thread breakpoints
3816@kindex break @dots{} thread @var{threadno}
3817@item break @var{linespec} thread @var{threadno}
3818@itemx break @var{linespec} thread @var{threadno} if @dots{}
3819@var{linespec} specifies source lines; there are several ways of
3820writing them, but the effect is always to specify some source line.
3821
3822Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3823to specify that you only want @value{GDBN} to stop the program when a
3824particular thread reaches this breakpoint. @var{threadno} is one of the
3825numeric thread identifiers assigned by @value{GDBN}, shown in the first
3826column of the @samp{info threads} display.
3827
3828If you do not specify @samp{thread @var{threadno}} when you set a
3829breakpoint, the breakpoint applies to @emph{all} threads of your
3830program.
3831
3832You can use the @code{thread} qualifier on conditional breakpoints as
3833well; in this case, place @samp{thread @var{threadno}} before the
3834breakpoint condition, like this:
3835
3836@smallexample
2df3850c 3837(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3838@end smallexample
3839
3840@end table
3841
3842@cindex stopped threads
3843@cindex threads, stopped
3844Whenever your program stops under @value{GDBN} for any reason,
3845@emph{all} threads of execution stop, not just the current thread. This
3846allows you to examine the overall state of the program, including
3847switching between threads, without worrying that things may change
3848underfoot.
3849
36d86913
MC
3850@cindex thread breakpoints and system calls
3851@cindex system calls and thread breakpoints
3852@cindex premature return from system calls
3853There is an unfortunate side effect. If one thread stops for a
3854breakpoint, or for some other reason, and another thread is blocked in a
3855system call, then the system call may return prematurely. This is a
3856consequence of the interaction between multiple threads and the signals
3857that @value{GDBN} uses to implement breakpoints and other events that
3858stop execution.
3859
3860To handle this problem, your program should check the return value of
3861each system call and react appropriately. This is good programming
3862style anyways.
3863
3864For example, do not write code like this:
3865
3866@smallexample
3867 sleep (10);
3868@end smallexample
3869
3870The call to @code{sleep} will return early if a different thread stops
3871at a breakpoint or for some other reason.
3872
3873Instead, write this:
3874
3875@smallexample
3876 int unslept = 10;
3877 while (unslept > 0)
3878 unslept = sleep (unslept);
3879@end smallexample
3880
3881A system call is allowed to return early, so the system is still
3882conforming to its specification. But @value{GDBN} does cause your
3883multi-threaded program to behave differently than it would without
3884@value{GDBN}.
3885
3886Also, @value{GDBN} uses internal breakpoints in the thread library to
3887monitor certain events such as thread creation and thread destruction.
3888When such an event happens, a system call in another thread may return
3889prematurely, even though your program does not appear to stop.
3890
c906108c
SS
3891@cindex continuing threads
3892@cindex threads, continuing
3893Conversely, whenever you restart the program, @emph{all} threads start
3894executing. @emph{This is true even when single-stepping} with commands
5d161b24 3895like @code{step} or @code{next}.
c906108c
SS
3896
3897In particular, @value{GDBN} cannot single-step all threads in lockstep.
3898Since thread scheduling is up to your debugging target's operating
3899system (not controlled by @value{GDBN}), other threads may
3900execute more than one statement while the current thread completes a
3901single step. Moreover, in general other threads stop in the middle of a
3902statement, rather than at a clean statement boundary, when the program
3903stops.
3904
3905You might even find your program stopped in another thread after
3906continuing or even single-stepping. This happens whenever some other
3907thread runs into a breakpoint, a signal, or an exception before the
3908first thread completes whatever you requested.
3909
3910On some OSes, you can lock the OS scheduler and thus allow only a single
3911thread to run.
3912
3913@table @code
3914@item set scheduler-locking @var{mode}
3915Set the scheduler locking mode. If it is @code{off}, then there is no
3916locking and any thread may run at any time. If @code{on}, then only the
3917current thread may run when the inferior is resumed. The @code{step}
3918mode optimizes for single-stepping. It stops other threads from
3919``seizing the prompt'' by preempting the current thread while you are
3920stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3921when you step. They are more likely to run when you @samp{next} over a
c906108c 3922function call, and they are completely free to run when you use commands
d4f3574e 3923like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3924thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3925@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3926
3927@item show scheduler-locking
3928Display the current scheduler locking mode.
3929@end table
3930
c906108c 3931
6d2ebf8b 3932@node Stack
c906108c
SS
3933@chapter Examining the Stack
3934
3935When your program has stopped, the first thing you need to know is where it
3936stopped and how it got there.
3937
3938@cindex call stack
5d161b24
DB
3939Each time your program performs a function call, information about the call
3940is generated.
3941That information includes the location of the call in your program,
3942the arguments of the call,
c906108c 3943and the local variables of the function being called.
5d161b24 3944The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3945The stack frames are allocated in a region of memory called the @dfn{call
3946stack}.
3947
3948When your program stops, the @value{GDBN} commands for examining the
3949stack allow you to see all of this information.
3950
3951@cindex selected frame
3952One of the stack frames is @dfn{selected} by @value{GDBN} and many
3953@value{GDBN} commands refer implicitly to the selected frame. In
3954particular, whenever you ask @value{GDBN} for the value of a variable in
3955your program, the value is found in the selected frame. There are
3956special @value{GDBN} commands to select whichever frame you are
3957interested in. @xref{Selection, ,Selecting a frame}.
3958
3959When your program stops, @value{GDBN} automatically selects the
5d161b24 3960currently executing frame and describes it briefly, similar to the
c906108c
SS
3961@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3962
3963@menu
3964* Frames:: Stack frames
3965* Backtrace:: Backtraces
3966* Selection:: Selecting a frame
3967* Frame Info:: Information on a frame
c906108c
SS
3968
3969@end menu
3970
6d2ebf8b 3971@node Frames
c906108c
SS
3972@section Stack frames
3973
d4f3574e 3974@cindex frame, definition
c906108c
SS
3975@cindex stack frame
3976The call stack is divided up into contiguous pieces called @dfn{stack
3977frames}, or @dfn{frames} for short; each frame is the data associated
3978with one call to one function. The frame contains the arguments given
3979to the function, the function's local variables, and the address at
3980which the function is executing.
3981
3982@cindex initial frame
3983@cindex outermost frame
3984@cindex innermost frame
3985When your program is started, the stack has only one frame, that of the
3986function @code{main}. This is called the @dfn{initial} frame or the
3987@dfn{outermost} frame. Each time a function is called, a new frame is
3988made. Each time a function returns, the frame for that function invocation
3989is eliminated. If a function is recursive, there can be many frames for
3990the same function. The frame for the function in which execution is
3991actually occurring is called the @dfn{innermost} frame. This is the most
3992recently created of all the stack frames that still exist.
3993
3994@cindex frame pointer
3995Inside your program, stack frames are identified by their addresses. A
3996stack frame consists of many bytes, each of which has its own address; each
3997kind of computer has a convention for choosing one byte whose
3998address serves as the address of the frame. Usually this address is kept
3999in a register called the @dfn{frame pointer register} while execution is
4000going on in that frame.
4001
4002@cindex frame number
4003@value{GDBN} assigns numbers to all existing stack frames, starting with
4004zero for the innermost frame, one for the frame that called it,
4005and so on upward. These numbers do not really exist in your program;
4006they are assigned by @value{GDBN} to give you a way of designating stack
4007frames in @value{GDBN} commands.
4008
6d2ebf8b
SS
4009@c The -fomit-frame-pointer below perennially causes hbox overflow
4010@c underflow problems.
c906108c
SS
4011@cindex frameless execution
4012Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4013without stack frames. (For example, the @value{GCC} option
474c8240 4014@smallexample
6d2ebf8b 4015@samp{-fomit-frame-pointer}
474c8240 4016@end smallexample
6d2ebf8b 4017generates functions without a frame.)
c906108c
SS
4018This is occasionally done with heavily used library functions to save
4019the frame setup time. @value{GDBN} has limited facilities for dealing
4020with these function invocations. If the innermost function invocation
4021has no stack frame, @value{GDBN} nevertheless regards it as though
4022it had a separate frame, which is numbered zero as usual, allowing
4023correct tracing of the function call chain. However, @value{GDBN} has
4024no provision for frameless functions elsewhere in the stack.
4025
4026@table @code
d4f3574e 4027@kindex frame@r{, command}
41afff9a 4028@cindex current stack frame
c906108c 4029@item frame @var{args}
5d161b24 4030The @code{frame} command allows you to move from one stack frame to another,
c906108c 4031and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4032address of the frame or the stack frame number. Without an argument,
4033@code{frame} prints the current stack frame.
c906108c
SS
4034
4035@kindex select-frame
41afff9a 4036@cindex selecting frame silently
c906108c
SS
4037@item select-frame
4038The @code{select-frame} command allows you to move from one stack frame
4039to another without printing the frame. This is the silent version of
4040@code{frame}.
4041@end table
4042
6d2ebf8b 4043@node Backtrace
c906108c
SS
4044@section Backtraces
4045
4046@cindex backtraces
4047@cindex tracebacks
4048@cindex stack traces
4049A backtrace is a summary of how your program got where it is. It shows one
4050line per frame, for many frames, starting with the currently executing
4051frame (frame zero), followed by its caller (frame one), and on up the
4052stack.
4053
4054@table @code
4055@kindex backtrace
41afff9a 4056@kindex bt @r{(@code{backtrace})}
c906108c
SS
4057@item backtrace
4058@itemx bt
4059Print a backtrace of the entire stack: one line per frame for all
4060frames in the stack.
4061
4062You can stop the backtrace at any time by typing the system interrupt
4063character, normally @kbd{C-c}.
4064
4065@item backtrace @var{n}
4066@itemx bt @var{n}
4067Similar, but print only the innermost @var{n} frames.
4068
4069@item backtrace -@var{n}
4070@itemx bt -@var{n}
4071Similar, but print only the outermost @var{n} frames.
4072@end table
4073
4074@kindex where
4075@kindex info stack
c906108c
SS
4076The names @code{where} and @code{info stack} (abbreviated @code{info s})
4077are additional aliases for @code{backtrace}.
4078
4079Each line in the backtrace shows the frame number and the function name.
4080The program counter value is also shown---unless you use @code{set
4081print address off}. The backtrace also shows the source file name and
4082line number, as well as the arguments to the function. The program
4083counter value is omitted if it is at the beginning of the code for that
4084line number.
4085
4086Here is an example of a backtrace. It was made with the command
4087@samp{bt 3}, so it shows the innermost three frames.
4088
4089@smallexample
4090@group
5d161b24 4091#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4092 at builtin.c:993
4093#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4094#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4095 at macro.c:71
4096(More stack frames follow...)
4097@end group
4098@end smallexample
4099
4100@noindent
4101The display for frame zero does not begin with a program counter
4102value, indicating that your program has stopped at the beginning of the
4103code for line @code{993} of @code{builtin.c}.
4104
25d29d70
AC
4105Most programs have a standard user entry point---a place where system
4106libraries and startup code transition into user code. For C this is
4107@code{main}. When @value{GDBN} finds the entry function in a backtrace
4108it will terminate the backtrace, to avoid tracing into highly
4109system-specific (and generally uninteresting) code.
4110
4111If you need to examine the startup code, or limit the number of levels
4112in a backtrace, you can change this behavior:
95f90d25
DJ
4113
4114@table @code
25d29d70
AC
4115@item set backtrace past-main
4116@itemx set backtrace past-main on
4644b6e3 4117@kindex set backtrace
25d29d70
AC
4118Backtraces will continue past the user entry point.
4119
4120@item set backtrace past-main off
95f90d25
DJ
4121Backtraces will stop when they encounter the user entry point. This is the
4122default.
4123
25d29d70 4124@item show backtrace past-main
4644b6e3 4125@kindex show backtrace
25d29d70
AC
4126Display the current user entry point backtrace policy.
4127
2315ffec
RC
4128@item set backtrace past-entry
4129@itemx set backtrace past-entry on
4130Backtraces will continue past the internal entry point of an application.
4131This entry point is encoded by the linker when the application is built,
4132and is likely before the user entry point @code{main} (or equivalent) is called.
4133
4134@item set backtrace past-entry off
4135Backtraces will stop when they encouter the internal entry point of an
4136application. This is the default.
4137
4138@item show backtrace past-entry
4139Display the current internal entry point backtrace policy.
4140
25d29d70
AC
4141@item set backtrace limit @var{n}
4142@itemx set backtrace limit 0
4143@cindex backtrace limit
4144Limit the backtrace to @var{n} levels. A value of zero means
4145unlimited.
95f90d25 4146
25d29d70
AC
4147@item show backtrace limit
4148Display the current limit on backtrace levels.
95f90d25
DJ
4149@end table
4150
6d2ebf8b 4151@node Selection
c906108c
SS
4152@section Selecting a frame
4153
4154Most commands for examining the stack and other data in your program work on
4155whichever stack frame is selected at the moment. Here are the commands for
4156selecting a stack frame; all of them finish by printing a brief description
4157of the stack frame just selected.
4158
4159@table @code
d4f3574e 4160@kindex frame@r{, selecting}
41afff9a 4161@kindex f @r{(@code{frame})}
c906108c
SS
4162@item frame @var{n}
4163@itemx f @var{n}
4164Select frame number @var{n}. Recall that frame zero is the innermost
4165(currently executing) frame, frame one is the frame that called the
4166innermost one, and so on. The highest-numbered frame is the one for
4167@code{main}.
4168
4169@item frame @var{addr}
4170@itemx f @var{addr}
4171Select the frame at address @var{addr}. This is useful mainly if the
4172chaining of stack frames has been damaged by a bug, making it
4173impossible for @value{GDBN} to assign numbers properly to all frames. In
4174addition, this can be useful when your program has multiple stacks and
4175switches between them.
4176
c906108c
SS
4177On the SPARC architecture, @code{frame} needs two addresses to
4178select an arbitrary frame: a frame pointer and a stack pointer.
4179
4180On the MIPS and Alpha architecture, it needs two addresses: a stack
4181pointer and a program counter.
4182
4183On the 29k architecture, it needs three addresses: a register stack
4184pointer, a program counter, and a memory stack pointer.
4185@c note to future updaters: this is conditioned on a flag
4186@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4187@c as of 27 Jan 1994.
c906108c
SS
4188
4189@kindex up
4190@item up @var{n}
4191Move @var{n} frames up the stack. For positive numbers @var{n}, this
4192advances toward the outermost frame, to higher frame numbers, to frames
4193that have existed longer. @var{n} defaults to one.
4194
4195@kindex down
41afff9a 4196@kindex do @r{(@code{down})}
c906108c
SS
4197@item down @var{n}
4198Move @var{n} frames down the stack. For positive numbers @var{n}, this
4199advances toward the innermost frame, to lower frame numbers, to frames
4200that were created more recently. @var{n} defaults to one. You may
4201abbreviate @code{down} as @code{do}.
4202@end table
4203
4204All of these commands end by printing two lines of output describing the
4205frame. The first line shows the frame number, the function name, the
4206arguments, and the source file and line number of execution in that
5d161b24 4207frame. The second line shows the text of that source line.
c906108c
SS
4208
4209@need 1000
4210For example:
4211
4212@smallexample
4213@group
4214(@value{GDBP}) up
4215#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4216 at env.c:10
421710 read_input_file (argv[i]);
4218@end group
4219@end smallexample
4220
4221After such a printout, the @code{list} command with no arguments
4222prints ten lines centered on the point of execution in the frame.
87885426
FN
4223You can also edit the program at the point of execution with your favorite
4224editing program by typing @code{edit}.
4225@xref{List, ,Printing source lines},
4226for details.
c906108c
SS
4227
4228@table @code
4229@kindex down-silently
4230@kindex up-silently
4231@item up-silently @var{n}
4232@itemx down-silently @var{n}
4233These two commands are variants of @code{up} and @code{down},
4234respectively; they differ in that they do their work silently, without
4235causing display of the new frame. They are intended primarily for use
4236in @value{GDBN} command scripts, where the output might be unnecessary and
4237distracting.
4238@end table
4239
6d2ebf8b 4240@node Frame Info
c906108c
SS
4241@section Information about a frame
4242
4243There are several other commands to print information about the selected
4244stack frame.
4245
4246@table @code
4247@item frame
4248@itemx f
4249When used without any argument, this command does not change which
4250frame is selected, but prints a brief description of the currently
4251selected stack frame. It can be abbreviated @code{f}. With an
4252argument, this command is used to select a stack frame.
4253@xref{Selection, ,Selecting a frame}.
4254
4255@kindex info frame
41afff9a 4256@kindex info f @r{(@code{info frame})}
c906108c
SS
4257@item info frame
4258@itemx info f
4259This command prints a verbose description of the selected stack frame,
4260including:
4261
4262@itemize @bullet
5d161b24
DB
4263@item
4264the address of the frame
c906108c
SS
4265@item
4266the address of the next frame down (called by this frame)
4267@item
4268the address of the next frame up (caller of this frame)
4269@item
4270the language in which the source code corresponding to this frame is written
4271@item
4272the address of the frame's arguments
4273@item
d4f3574e
SS
4274the address of the frame's local variables
4275@item
c906108c
SS
4276the program counter saved in it (the address of execution in the caller frame)
4277@item
4278which registers were saved in the frame
4279@end itemize
4280
4281@noindent The verbose description is useful when
4282something has gone wrong that has made the stack format fail to fit
4283the usual conventions.
4284
4285@item info frame @var{addr}
4286@itemx info f @var{addr}
4287Print a verbose description of the frame at address @var{addr}, without
4288selecting that frame. The selected frame remains unchanged by this
4289command. This requires the same kind of address (more than one for some
4290architectures) that you specify in the @code{frame} command.
4291@xref{Selection, ,Selecting a frame}.
4292
4293@kindex info args
4294@item info args
4295Print the arguments of the selected frame, each on a separate line.
4296
4297@item info locals
4298@kindex info locals
4299Print the local variables of the selected frame, each on a separate
4300line. These are all variables (declared either static or automatic)
4301accessible at the point of execution of the selected frame.
4302
c906108c 4303@kindex info catch
d4f3574e
SS
4304@cindex catch exceptions, list active handlers
4305@cindex exception handlers, how to list
c906108c
SS
4306@item info catch
4307Print a list of all the exception handlers that are active in the
4308current stack frame at the current point of execution. To see other
4309exception handlers, visit the associated frame (using the @code{up},
4310@code{down}, or @code{frame} commands); then type @code{info catch}.
4311@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4312
c906108c
SS
4313@end table
4314
c906108c 4315
6d2ebf8b 4316@node Source
c906108c
SS
4317@chapter Examining Source Files
4318
4319@value{GDBN} can print parts of your program's source, since the debugging
4320information recorded in the program tells @value{GDBN} what source files were
4321used to build it. When your program stops, @value{GDBN} spontaneously prints
4322the line where it stopped. Likewise, when you select a stack frame
4323(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4324execution in that frame has stopped. You can print other portions of
4325source files by explicit command.
4326
7a292a7a 4327If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4328prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4329@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4330
4331@menu
4332* List:: Printing source lines
87885426 4333* Edit:: Editing source files
c906108c 4334* Search:: Searching source files
c906108c
SS
4335* Source Path:: Specifying source directories
4336* Machine Code:: Source and machine code
4337@end menu
4338
6d2ebf8b 4339@node List
c906108c
SS
4340@section Printing source lines
4341
4342@kindex list
41afff9a 4343@kindex l @r{(@code{list})}
c906108c 4344To print lines from a source file, use the @code{list} command
5d161b24 4345(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4346There are several ways to specify what part of the file you want to print.
4347
4348Here are the forms of the @code{list} command most commonly used:
4349
4350@table @code
4351@item list @var{linenum}
4352Print lines centered around line number @var{linenum} in the
4353current source file.
4354
4355@item list @var{function}
4356Print lines centered around the beginning of function
4357@var{function}.
4358
4359@item list
4360Print more lines. If the last lines printed were printed with a
4361@code{list} command, this prints lines following the last lines
4362printed; however, if the last line printed was a solitary line printed
4363as part of displaying a stack frame (@pxref{Stack, ,Examining the
4364Stack}), this prints lines centered around that line.
4365
4366@item list -
4367Print lines just before the lines last printed.
4368@end table
4369
4370By default, @value{GDBN} prints ten source lines with any of these forms of
4371the @code{list} command. You can change this using @code{set listsize}:
4372
4373@table @code
4374@kindex set listsize
4375@item set listsize @var{count}
4376Make the @code{list} command display @var{count} source lines (unless
4377the @code{list} argument explicitly specifies some other number).
4378
4379@kindex show listsize
4380@item show listsize
4381Display the number of lines that @code{list} prints.
4382@end table
4383
4384Repeating a @code{list} command with @key{RET} discards the argument,
4385so it is equivalent to typing just @code{list}. This is more useful
4386than listing the same lines again. An exception is made for an
4387argument of @samp{-}; that argument is preserved in repetition so that
4388each repetition moves up in the source file.
4389
4390@cindex linespec
4391In general, the @code{list} command expects you to supply zero, one or two
4392@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4393of writing them, but the effect is always to specify some source line.
c906108c
SS
4394Here is a complete description of the possible arguments for @code{list}:
4395
4396@table @code
4397@item list @var{linespec}
4398Print lines centered around the line specified by @var{linespec}.
4399
4400@item list @var{first},@var{last}
4401Print lines from @var{first} to @var{last}. Both arguments are
4402linespecs.
4403
4404@item list ,@var{last}
4405Print lines ending with @var{last}.
4406
4407@item list @var{first},
4408Print lines starting with @var{first}.
4409
4410@item list +
4411Print lines just after the lines last printed.
4412
4413@item list -
4414Print lines just before the lines last printed.
4415
4416@item list
4417As described in the preceding table.
4418@end table
4419
4420Here are the ways of specifying a single source line---all the
4421kinds of linespec.
4422
4423@table @code
4424@item @var{number}
4425Specifies line @var{number} of the current source file.
4426When a @code{list} command has two linespecs, this refers to
4427the same source file as the first linespec.
4428
4429@item +@var{offset}
4430Specifies the line @var{offset} lines after the last line printed.
4431When used as the second linespec in a @code{list} command that has
4432two, this specifies the line @var{offset} lines down from the
4433first linespec.
4434
4435@item -@var{offset}
4436Specifies the line @var{offset} lines before the last line printed.
4437
4438@item @var{filename}:@var{number}
4439Specifies line @var{number} in the source file @var{filename}.
4440
4441@item @var{function}
4442Specifies the line that begins the body of the function @var{function}.
4443For example: in C, this is the line with the open brace.
4444
4445@item @var{filename}:@var{function}
4446Specifies the line of the open-brace that begins the body of the
4447function @var{function} in the file @var{filename}. You only need the
4448file name with a function name to avoid ambiguity when there are
4449identically named functions in different source files.
4450
4451@item *@var{address}
4452Specifies the line containing the program address @var{address}.
4453@var{address} may be any expression.
4454@end table
4455
87885426
FN
4456@node Edit
4457@section Editing source files
4458@cindex editing source files
4459
4460@kindex edit
4461@kindex e @r{(@code{edit})}
4462To edit the lines in a source file, use the @code{edit} command.
4463The editing program of your choice
4464is invoked with the current line set to
4465the active line in the program.
4466Alternatively, there are several ways to specify what part of the file you
4467want to print if you want to see other parts of the program.
4468
4469Here are the forms of the @code{edit} command most commonly used:
4470
4471@table @code
4472@item edit
4473Edit the current source file at the active line number in the program.
4474
4475@item edit @var{number}
4476Edit the current source file with @var{number} as the active line number.
4477
4478@item edit @var{function}
4479Edit the file containing @var{function} at the beginning of its definition.
4480
4481@item edit @var{filename}:@var{number}
4482Specifies line @var{number} in the source file @var{filename}.
4483
4484@item edit @var{filename}:@var{function}
4485Specifies the line that begins the body of the
4486function @var{function} in the file @var{filename}. You only need the
4487file name with a function name to avoid ambiguity when there are
4488identically named functions in different source files.
4489
4490@item edit *@var{address}
4491Specifies the line containing the program address @var{address}.
4492@var{address} may be any expression.
4493@end table
4494
4495@subsection Choosing your editor
4496You can customize @value{GDBN} to use any editor you want
4497@footnote{
4498The only restriction is that your editor (say @code{ex}), recognizes the
4499following command-line syntax:
10998722 4500@smallexample
87885426 4501ex +@var{number} file
10998722 4502@end smallexample
15387254
EZ
4503The optional numeric value +@var{number} specifies the number of the line in
4504the file where to start editing.}.
4505By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4506by setting the environment variable @code{EDITOR} before using
4507@value{GDBN}. For example, to configure @value{GDBN} to use the
4508@code{vi} editor, you could use these commands with the @code{sh} shell:
4509@smallexample
87885426
FN
4510EDITOR=/usr/bin/vi
4511export EDITOR
15387254 4512gdb @dots{}
10998722 4513@end smallexample
87885426 4514or in the @code{csh} shell,
10998722 4515@smallexample
87885426 4516setenv EDITOR /usr/bin/vi
15387254 4517gdb @dots{}
10998722 4518@end smallexample
87885426 4519
6d2ebf8b 4520@node Search
c906108c 4521@section Searching source files
15387254 4522@cindex searching source files
c906108c
SS
4523@kindex reverse-search
4524
4525There are two commands for searching through the current source file for a
4526regular expression.
4527
4528@table @code
4529@kindex search
4530@kindex forward-search
4531@item forward-search @var{regexp}
4532@itemx search @var{regexp}
4533The command @samp{forward-search @var{regexp}} checks each line,
4534starting with the one following the last line listed, for a match for
5d161b24 4535@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4536synonym @samp{search @var{regexp}} or abbreviate the command name as
4537@code{fo}.
4538
4539@item reverse-search @var{regexp}
4540The command @samp{reverse-search @var{regexp}} checks each line, starting
4541with the one before the last line listed and going backward, for a match
4542for @var{regexp}. It lists the line that is found. You can abbreviate
4543this command as @code{rev}.
4544@end table
c906108c 4545
6d2ebf8b 4546@node Source Path
c906108c
SS
4547@section Specifying source directories
4548
4549@cindex source path
4550@cindex directories for source files
4551Executable programs sometimes do not record the directories of the source
4552files from which they were compiled, just the names. Even when they do,
4553the directories could be moved between the compilation and your debugging
4554session. @value{GDBN} has a list of directories to search for source files;
4555this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4556it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4557in the list, until it finds a file with the desired name.
4558
4559For example, suppose an executable references the file
4560@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4561@file{/mnt/cross}. The file is first looked up literally; if this
4562fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4563fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4564message is printed. @value{GDBN} does not look up the parts of the
4565source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4566Likewise, the subdirectories of the source path are not searched: if
4567the source path is @file{/mnt/cross}, and the binary refers to
4568@file{foo.c}, @value{GDBN} would not find it under
4569@file{/mnt/cross/usr/src/foo-1.0/lib}.
4570
4571Plain file names, relative file names with leading directories, file
4572names containing dots, etc.@: are all treated as described above; for
4573instance, if the source path is @file{/mnt/cross}, and the source file
4574is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4575@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4576that---@file{/mnt/cross/foo.c}.
4577
4578Note that the executable search path is @emph{not} used to locate the
4579source files. Neither is the current working directory, unless it
4580happens to be in the source path.
c906108c
SS
4581
4582Whenever you reset or rearrange the source path, @value{GDBN} clears out
4583any information it has cached about where source files are found and where
4584each line is in the file.
4585
4586@kindex directory
4587@kindex dir
d4f3574e
SS
4588When you start @value{GDBN}, its source path includes only @samp{cdir}
4589and @samp{cwd}, in that order.
c906108c
SS
4590To add other directories, use the @code{directory} command.
4591
4592@table @code
4593@item directory @var{dirname} @dots{}
4594@item dir @var{dirname} @dots{}
4595Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4596directory names may be given to this command, separated by @samp{:}
4597(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4598part of absolute file names) or
c906108c
SS
4599whitespace. You may specify a directory that is already in the source
4600path; this moves it forward, so @value{GDBN} searches it sooner.
4601
4602@kindex cdir
4603@kindex cwd
41afff9a
EZ
4604@vindex $cdir@r{, convenience variable}
4605@vindex $cwdr@r{, convenience variable}
c906108c
SS
4606@cindex compilation directory
4607@cindex current directory
4608@cindex working directory
4609@cindex directory, current
4610@cindex directory, compilation
4611You can use the string @samp{$cdir} to refer to the compilation
4612directory (if one is recorded), and @samp{$cwd} to refer to the current
4613working directory. @samp{$cwd} is not the same as @samp{.}---the former
4614tracks the current working directory as it changes during your @value{GDBN}
4615session, while the latter is immediately expanded to the current
4616directory at the time you add an entry to the source path.
4617
4618@item directory
4619Reset the source path to empty again. This requires confirmation.
4620
4621@c RET-repeat for @code{directory} is explicitly disabled, but since
4622@c repeating it would be a no-op we do not say that. (thanks to RMS)
4623
4624@item show directories
4625@kindex show directories
4626Print the source path: show which directories it contains.
4627@end table
4628
4629If your source path is cluttered with directories that are no longer of
4630interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4631versions of source. You can correct the situation as follows:
4632
4633@enumerate
4634@item
4635Use @code{directory} with no argument to reset the source path to empty.
4636
4637@item
4638Use @code{directory} with suitable arguments to reinstall the
4639directories you want in the source path. You can add all the
4640directories in one command.
4641@end enumerate
4642
6d2ebf8b 4643@node Machine Code
c906108c 4644@section Source and machine code
15387254 4645@cindex source line and its code address
c906108c
SS
4646
4647You can use the command @code{info line} to map source lines to program
4648addresses (and vice versa), and the command @code{disassemble} to display
4649a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4650mode, the @code{info line} command causes the arrow to point to the
5d161b24 4651line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4652well as hex.
4653
4654@table @code
4655@kindex info line
4656@item info line @var{linespec}
4657Print the starting and ending addresses of the compiled code for
4658source line @var{linespec}. You can specify source lines in any of
4659the ways understood by the @code{list} command (@pxref{List, ,Printing
4660source lines}).
4661@end table
4662
4663For example, we can use @code{info line} to discover the location of
4664the object code for the first line of function
4665@code{m4_changequote}:
4666
d4f3574e
SS
4667@c FIXME: I think this example should also show the addresses in
4668@c symbolic form, as they usually would be displayed.
c906108c 4669@smallexample
96a2c332 4670(@value{GDBP}) info line m4_changequote
c906108c
SS
4671Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4672@end smallexample
4673
4674@noindent
15387254 4675@cindex code address and its source line
c906108c
SS
4676We can also inquire (using @code{*@var{addr}} as the form for
4677@var{linespec}) what source line covers a particular address:
4678@smallexample
4679(@value{GDBP}) info line *0x63ff
4680Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4681@end smallexample
4682
4683@cindex @code{$_} and @code{info line}
15387254 4684@cindex @code{x} command, default address
41afff9a 4685@kindex x@r{(examine), and} info line
c906108c
SS
4686After @code{info line}, the default address for the @code{x} command
4687is changed to the starting address of the line, so that @samp{x/i} is
4688sufficient to begin examining the machine code (@pxref{Memory,
4689,Examining memory}). Also, this address is saved as the value of the
4690convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4691variables}).
4692
4693@table @code
4694@kindex disassemble
4695@cindex assembly instructions
4696@cindex instructions, assembly
4697@cindex machine instructions
4698@cindex listing machine instructions
4699@item disassemble
4700This specialized command dumps a range of memory as machine
4701instructions. The default memory range is the function surrounding the
4702program counter of the selected frame. A single argument to this
4703command is a program counter value; @value{GDBN} dumps the function
4704surrounding this value. Two arguments specify a range of addresses
4705(first inclusive, second exclusive) to dump.
4706@end table
4707
c906108c
SS
4708The following example shows the disassembly of a range of addresses of
4709HP PA-RISC 2.0 code:
4710
4711@smallexample
4712(@value{GDBP}) disas 0x32c4 0x32e4
4713Dump of assembler code from 0x32c4 to 0x32e4:
47140x32c4 <main+204>: addil 0,dp
47150x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
47160x32cc <main+212>: ldil 0x3000,r31
47170x32d0 <main+216>: ble 0x3f8(sr4,r31)
47180x32d4 <main+220>: ldo 0(r31),rp
47190x32d8 <main+224>: addil -0x800,dp
47200x32dc <main+228>: ldo 0x588(r1),r26
47210x32e0 <main+232>: ldil 0x3000,r31
4722End of assembler dump.
4723@end smallexample
c906108c
SS
4724
4725Some architectures have more than one commonly-used set of instruction
4726mnemonics or other syntax.
4727
4728@table @code
d4f3574e 4729@kindex set disassembly-flavor
d4f3574e
SS
4730@cindex Intel disassembly flavor
4731@cindex AT&T disassembly flavor
4732@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4733Select the instruction set to use when disassembling the
4734program via the @code{disassemble} or @code{x/i} commands.
4735
4736Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4737can set @var{instruction-set} to either @code{intel} or @code{att}.
4738The default is @code{att}, the AT&T flavor used by default by Unix
4739assemblers for x86-based targets.
c906108c
SS
4740@end table
4741
4742
6d2ebf8b 4743@node Data
c906108c
SS
4744@chapter Examining Data
4745
4746@cindex printing data
4747@cindex examining data
4748@kindex print
4749@kindex inspect
4750@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4751@c document because it is nonstandard... Under Epoch it displays in a
4752@c different window or something like that.
4753The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4754command (abbreviated @code{p}), or its synonym @code{inspect}. It
4755evaluates and prints the value of an expression of the language your
4756program is written in (@pxref{Languages, ,Using @value{GDBN} with
4757Different Languages}).
c906108c
SS
4758
4759@table @code
d4f3574e
SS
4760@item print @var{expr}
4761@itemx print /@var{f} @var{expr}
4762@var{expr} is an expression (in the source language). By default the
4763value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4764you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4765@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4766formats}.
4767
4768@item print
4769@itemx print /@var{f}
15387254 4770@cindex reprint the last value
d4f3574e 4771If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4772@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4773conveniently inspect the same value in an alternative format.
4774@end table
4775
4776A more low-level way of examining data is with the @code{x} command.
4777It examines data in memory at a specified address and prints it in a
4778specified format. @xref{Memory, ,Examining memory}.
4779
7a292a7a 4780If you are interested in information about types, or about how the
d4f3574e
SS
4781fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4782command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4783Table}.
c906108c
SS
4784
4785@menu
4786* Expressions:: Expressions
4787* Variables:: Program variables
4788* Arrays:: Artificial arrays
4789* Output Formats:: Output formats
4790* Memory:: Examining memory
4791* Auto Display:: Automatic display
4792* Print Settings:: Print settings
4793* Value History:: Value history
4794* Convenience Vars:: Convenience variables
4795* Registers:: Registers
c906108c 4796* Floating Point Hardware:: Floating point hardware
53c69bd7 4797* Vector Unit:: Vector Unit
b383017d 4798* Auxiliary Vector:: Auxiliary data provided by operating system
29e57380 4799* Memory Region Attributes:: Memory region attributes
16d9dec6 4800* Dump/Restore Files:: Copy between memory and a file
384ee23f 4801* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4802* Character Sets:: Debugging programs that use a different
4803 character set than GDB does
c906108c
SS
4804@end menu
4805
6d2ebf8b 4806@node Expressions
c906108c
SS
4807@section Expressions
4808
4809@cindex expressions
4810@code{print} and many other @value{GDBN} commands accept an expression and
4811compute its value. Any kind of constant, variable or operator defined
4812by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4813@value{GDBN}. This includes conditional expressions, function calls,
4814casts, and string constants. It also includes preprocessor macros, if
4815you compiled your program to include this information; see
4816@ref{Compilation}.
c906108c 4817
15387254 4818@cindex arrays in expressions
d4f3574e
SS
4819@value{GDBN} supports array constants in expressions input by
4820the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4821you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4822memory that is @code{malloc}ed in the target program.
c906108c 4823
c906108c
SS
4824Because C is so widespread, most of the expressions shown in examples in
4825this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4826Languages}, for information on how to use expressions in other
4827languages.
4828
4829In this section, we discuss operators that you can use in @value{GDBN}
4830expressions regardless of your programming language.
4831
15387254 4832@cindex casts, in expressions
c906108c
SS
4833Casts are supported in all languages, not just in C, because it is so
4834useful to cast a number into a pointer in order to examine a structure
4835at that address in memory.
4836@c FIXME: casts supported---Mod2 true?
c906108c
SS
4837
4838@value{GDBN} supports these operators, in addition to those common
4839to programming languages:
4840
4841@table @code
4842@item @@
4843@samp{@@} is a binary operator for treating parts of memory as arrays.
4844@xref{Arrays, ,Artificial arrays}, for more information.
4845
4846@item ::
4847@samp{::} allows you to specify a variable in terms of the file or
4848function where it is defined. @xref{Variables, ,Program variables}.
4849
4850@cindex @{@var{type}@}
4851@cindex type casting memory
4852@cindex memory, viewing as typed object
4853@cindex casts, to view memory
4854@item @{@var{type}@} @var{addr}
4855Refers to an object of type @var{type} stored at address @var{addr} in
4856memory. @var{addr} may be any expression whose value is an integer or
4857pointer (but parentheses are required around binary operators, just as in
4858a cast). This construct is allowed regardless of what kind of data is
4859normally supposed to reside at @var{addr}.
4860@end table
4861
6d2ebf8b 4862@node Variables
c906108c
SS
4863@section Program variables
4864
4865The most common kind of expression to use is the name of a variable
4866in your program.
4867
4868Variables in expressions are understood in the selected stack frame
4869(@pxref{Selection, ,Selecting a frame}); they must be either:
4870
4871@itemize @bullet
4872@item
4873global (or file-static)
4874@end itemize
4875
5d161b24 4876@noindent or
c906108c
SS
4877
4878@itemize @bullet
4879@item
4880visible according to the scope rules of the
4881programming language from the point of execution in that frame
5d161b24 4882@end itemize
c906108c
SS
4883
4884@noindent This means that in the function
4885
474c8240 4886@smallexample
c906108c
SS
4887foo (a)
4888 int a;
4889@{
4890 bar (a);
4891 @{
4892 int b = test ();
4893 bar (b);
4894 @}
4895@}
474c8240 4896@end smallexample
c906108c
SS
4897
4898@noindent
4899you can examine and use the variable @code{a} whenever your program is
4900executing within the function @code{foo}, but you can only use or
4901examine the variable @code{b} while your program is executing inside
4902the block where @code{b} is declared.
4903
4904@cindex variable name conflict
4905There is an exception: you can refer to a variable or function whose
4906scope is a single source file even if the current execution point is not
4907in this file. But it is possible to have more than one such variable or
4908function with the same name (in different source files). If that
4909happens, referring to that name has unpredictable effects. If you wish,
4910you can specify a static variable in a particular function or file,
15387254 4911using the colon-colon (@code{::}) notation:
c906108c 4912
d4f3574e 4913@cindex colon-colon, context for variables/functions
c906108c
SS
4914@iftex
4915@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4916@cindex @code{::}, context for variables/functions
c906108c 4917@end iftex
474c8240 4918@smallexample
c906108c
SS
4919@var{file}::@var{variable}
4920@var{function}::@var{variable}
474c8240 4921@end smallexample
c906108c
SS
4922
4923@noindent
4924Here @var{file} or @var{function} is the name of the context for the
4925static @var{variable}. In the case of file names, you can use quotes to
4926make sure @value{GDBN} parses the file name as a single word---for example,
4927to print a global value of @code{x} defined in @file{f2.c}:
4928
474c8240 4929@smallexample
c906108c 4930(@value{GDBP}) p 'f2.c'::x
474c8240 4931@end smallexample
c906108c 4932
b37052ae 4933@cindex C@t{++} scope resolution
c906108c 4934This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4935use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4936scope resolution operator in @value{GDBN} expressions.
4937@c FIXME: Um, so what happens in one of those rare cases where it's in
4938@c conflict?? --mew
c906108c
SS
4939
4940@cindex wrong values
4941@cindex variable values, wrong
15387254
EZ
4942@cindex function entry/exit, wrong values of variables
4943@cindex optimized code, wrong values of variables
c906108c
SS
4944@quotation
4945@emph{Warning:} Occasionally, a local variable may appear to have the
4946wrong value at certain points in a function---just after entry to a new
4947scope, and just before exit.
4948@end quotation
4949You may see this problem when you are stepping by machine instructions.
4950This is because, on most machines, it takes more than one instruction to
4951set up a stack frame (including local variable definitions); if you are
4952stepping by machine instructions, variables may appear to have the wrong
4953values until the stack frame is completely built. On exit, it usually
4954also takes more than one machine instruction to destroy a stack frame;
4955after you begin stepping through that group of instructions, local
4956variable definitions may be gone.
4957
4958This may also happen when the compiler does significant optimizations.
4959To be sure of always seeing accurate values, turn off all optimization
4960when compiling.
4961
d4f3574e
SS
4962@cindex ``No symbol "foo" in current context''
4963Another possible effect of compiler optimizations is to optimize
4964unused variables out of existence, or assign variables to registers (as
4965opposed to memory addresses). Depending on the support for such cases
4966offered by the debug info format used by the compiler, @value{GDBN}
4967might not be able to display values for such local variables. If that
4968happens, @value{GDBN} will print a message like this:
4969
474c8240 4970@smallexample
d4f3574e 4971No symbol "foo" in current context.
474c8240 4972@end smallexample
d4f3574e
SS
4973
4974To solve such problems, either recompile without optimizations, or use a
4975different debug info format, if the compiler supports several such
15387254 4976formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
4977usually supports the @option{-gstabs+} option. @option{-gstabs+}
4978produces debug info in a format that is superior to formats such as
4979COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4980an effective form for debug info. @xref{Debugging Options,,Options
4981for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
4982@xref{C, , Debugging C++}, for more info about debug info formats
4983that are best suited to C@t{++} programs.
d4f3574e 4984
6d2ebf8b 4985@node Arrays
c906108c
SS
4986@section Artificial arrays
4987
4988@cindex artificial array
15387254 4989@cindex arrays
41afff9a 4990@kindex @@@r{, referencing memory as an array}
c906108c
SS
4991It is often useful to print out several successive objects of the
4992same type in memory; a section of an array, or an array of
4993dynamically determined size for which only a pointer exists in the
4994program.
4995
4996You can do this by referring to a contiguous span of memory as an
4997@dfn{artificial array}, using the binary operator @samp{@@}. The left
4998operand of @samp{@@} should be the first element of the desired array
4999and be an individual object. The right operand should be the desired length
5000of the array. The result is an array value whose elements are all of
5001the type of the left argument. The first element is actually the left
5002argument; the second element comes from bytes of memory immediately
5003following those that hold the first element, and so on. Here is an
5004example. If a program says
5005
474c8240 5006@smallexample
c906108c 5007int *array = (int *) malloc (len * sizeof (int));
474c8240 5008@end smallexample
c906108c
SS
5009
5010@noindent
5011you can print the contents of @code{array} with
5012
474c8240 5013@smallexample
c906108c 5014p *array@@len
474c8240 5015@end smallexample
c906108c
SS
5016
5017The left operand of @samp{@@} must reside in memory. Array values made
5018with @samp{@@} in this way behave just like other arrays in terms of
5019subscripting, and are coerced to pointers when used in expressions.
5020Artificial arrays most often appear in expressions via the value history
5021(@pxref{Value History, ,Value history}), after printing one out.
5022
5023Another way to create an artificial array is to use a cast.
5024This re-interprets a value as if it were an array.
5025The value need not be in memory:
474c8240 5026@smallexample
c906108c
SS
5027(@value{GDBP}) p/x (short[2])0x12345678
5028$1 = @{0x1234, 0x5678@}
474c8240 5029@end smallexample
c906108c
SS
5030
5031As a convenience, if you leave the array length out (as in
c3f6f71d 5032@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5033the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5034@smallexample
c906108c
SS
5035(@value{GDBP}) p/x (short[])0x12345678
5036$2 = @{0x1234, 0x5678@}
474c8240 5037@end smallexample
c906108c
SS
5038
5039Sometimes the artificial array mechanism is not quite enough; in
5040moderately complex data structures, the elements of interest may not
5041actually be adjacent---for example, if you are interested in the values
5042of pointers in an array. One useful work-around in this situation is
5043to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5044variables}) as a counter in an expression that prints the first
5045interesting value, and then repeat that expression via @key{RET}. For
5046instance, suppose you have an array @code{dtab} of pointers to
5047structures, and you are interested in the values of a field @code{fv}
5048in each structure. Here is an example of what you might type:
5049
474c8240 5050@smallexample
c906108c
SS
5051set $i = 0
5052p dtab[$i++]->fv
5053@key{RET}
5054@key{RET}
5055@dots{}
474c8240 5056@end smallexample
c906108c 5057
6d2ebf8b 5058@node Output Formats
c906108c
SS
5059@section Output formats
5060
5061@cindex formatted output
5062@cindex output formats
5063By default, @value{GDBN} prints a value according to its data type. Sometimes
5064this is not what you want. For example, you might want to print a number
5065in hex, or a pointer in decimal. Or you might want to view data in memory
5066at a certain address as a character string or as an instruction. To do
5067these things, specify an @dfn{output format} when you print a value.
5068
5069The simplest use of output formats is to say how to print a value
5070already computed. This is done by starting the arguments of the
5071@code{print} command with a slash and a format letter. The format
5072letters supported are:
5073
5074@table @code
5075@item x
5076Regard the bits of the value as an integer, and print the integer in
5077hexadecimal.
5078
5079@item d
5080Print as integer in signed decimal.
5081
5082@item u
5083Print as integer in unsigned decimal.
5084
5085@item o
5086Print as integer in octal.
5087
5088@item t
5089Print as integer in binary. The letter @samp{t} stands for ``two''.
5090@footnote{@samp{b} cannot be used because these format letters are also
5091used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5092see @ref{Memory,,Examining memory}.}
c906108c
SS
5093
5094@item a
5095@cindex unknown address, locating
3d67e040 5096@cindex locate address
c906108c
SS
5097Print as an address, both absolute in hexadecimal and as an offset from
5098the nearest preceding symbol. You can use this format used to discover
5099where (in what function) an unknown address is located:
5100
474c8240 5101@smallexample
c906108c
SS
5102(@value{GDBP}) p/a 0x54320
5103$3 = 0x54320 <_initialize_vx+396>
474c8240 5104@end smallexample
c906108c 5105
3d67e040
EZ
5106@noindent
5107The command @code{info symbol 0x54320} yields similar results.
5108@xref{Symbols, info symbol}.
5109
c906108c
SS
5110@item c
5111Regard as an integer and print it as a character constant.
5112
5113@item f
5114Regard the bits of the value as a floating point number and print
5115using typical floating point syntax.
5116@end table
5117
5118For example, to print the program counter in hex (@pxref{Registers}), type
5119
474c8240 5120@smallexample
c906108c 5121p/x $pc
474c8240 5122@end smallexample
c906108c
SS
5123
5124@noindent
5125Note that no space is required before the slash; this is because command
5126names in @value{GDBN} cannot contain a slash.
5127
5128To reprint the last value in the value history with a different format,
5129you can use the @code{print} command with just a format and no
5130expression. For example, @samp{p/x} reprints the last value in hex.
5131
6d2ebf8b 5132@node Memory
c906108c
SS
5133@section Examining memory
5134
5135You can use the command @code{x} (for ``examine'') to examine memory in
5136any of several formats, independently of your program's data types.
5137
5138@cindex examining memory
5139@table @code
41afff9a 5140@kindex x @r{(examine memory)}
c906108c
SS
5141@item x/@var{nfu} @var{addr}
5142@itemx x @var{addr}
5143@itemx x
5144Use the @code{x} command to examine memory.
5145@end table
5146
5147@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5148much memory to display and how to format it; @var{addr} is an
5149expression giving the address where you want to start displaying memory.
5150If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5151Several commands set convenient defaults for @var{addr}.
5152
5153@table @r
5154@item @var{n}, the repeat count
5155The repeat count is a decimal integer; the default is 1. It specifies
5156how much memory (counting by units @var{u}) to display.
5157@c This really is **decimal**; unaffected by 'set radix' as of GDB
5158@c 4.1.2.
5159
5160@item @var{f}, the display format
5161The display format is one of the formats used by @code{print},
5162@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5163The default is @samp{x} (hexadecimal) initially.
5164The default changes each time you use either @code{x} or @code{print}.
5165
5166@item @var{u}, the unit size
5167The unit size is any of
5168
5169@table @code
5170@item b
5171Bytes.
5172@item h
5173Halfwords (two bytes).
5174@item w
5175Words (four bytes). This is the initial default.
5176@item g
5177Giant words (eight bytes).
5178@end table
5179
5180Each time you specify a unit size with @code{x}, that size becomes the
5181default unit the next time you use @code{x}. (For the @samp{s} and
5182@samp{i} formats, the unit size is ignored and is normally not written.)
5183
5184@item @var{addr}, starting display address
5185@var{addr} is the address where you want @value{GDBN} to begin displaying
5186memory. The expression need not have a pointer value (though it may);
5187it is always interpreted as an integer address of a byte of memory.
5188@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5189@var{addr} is usually just after the last address examined---but several
5190other commands also set the default address: @code{info breakpoints} (to
5191the address of the last breakpoint listed), @code{info line} (to the
5192starting address of a line), and @code{print} (if you use it to display
5193a value from memory).
5194@end table
5195
5196For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5197(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5198starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5199words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5200@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5201
5202Since the letters indicating unit sizes are all distinct from the
5203letters specifying output formats, you do not have to remember whether
5204unit size or format comes first; either order works. The output
5205specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5206(However, the count @var{n} must come first; @samp{wx4} does not work.)
5207
5208Even though the unit size @var{u} is ignored for the formats @samp{s}
5209and @samp{i}, you might still want to use a count @var{n}; for example,
5210@samp{3i} specifies that you want to see three machine instructions,
5211including any operands. The command @code{disassemble} gives an
d4f3574e 5212alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5213Code,,Source and machine code}.
5214
5215All the defaults for the arguments to @code{x} are designed to make it
5216easy to continue scanning memory with minimal specifications each time
5217you use @code{x}. For example, after you have inspected three machine
5218instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5219with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5220the repeat count @var{n} is used again; the other arguments default as
5221for successive uses of @code{x}.
5222
5223@cindex @code{$_}, @code{$__}, and value history
5224The addresses and contents printed by the @code{x} command are not saved
5225in the value history because there is often too much of them and they
5226would get in the way. Instead, @value{GDBN} makes these values available for
5227subsequent use in expressions as values of the convenience variables
5228@code{$_} and @code{$__}. After an @code{x} command, the last address
5229examined is available for use in expressions in the convenience variable
5230@code{$_}. The contents of that address, as examined, are available in
5231the convenience variable @code{$__}.
5232
5233If the @code{x} command has a repeat count, the address and contents saved
5234are from the last memory unit printed; this is not the same as the last
5235address printed if several units were printed on the last line of output.
5236
6d2ebf8b 5237@node Auto Display
c906108c
SS
5238@section Automatic display
5239@cindex automatic display
5240@cindex display of expressions
5241
5242If you find that you want to print the value of an expression frequently
5243(to see how it changes), you might want to add it to the @dfn{automatic
5244display list} so that @value{GDBN} prints its value each time your program stops.
5245Each expression added to the list is given a number to identify it;
5246to remove an expression from the list, you specify that number.
5247The automatic display looks like this:
5248
474c8240 5249@smallexample
c906108c
SS
52502: foo = 38
52513: bar[5] = (struct hack *) 0x3804
474c8240 5252@end smallexample
c906108c
SS
5253
5254@noindent
5255This display shows item numbers, expressions and their current values. As with
5256displays you request manually using @code{x} or @code{print}, you can
5257specify the output format you prefer; in fact, @code{display} decides
5258whether to use @code{print} or @code{x} depending on how elaborate your
5259format specification is---it uses @code{x} if you specify a unit size,
5260or one of the two formats (@samp{i} and @samp{s}) that are only
5261supported by @code{x}; otherwise it uses @code{print}.
5262
5263@table @code
5264@kindex display
d4f3574e
SS
5265@item display @var{expr}
5266Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5267each time your program stops. @xref{Expressions, ,Expressions}.
5268
5269@code{display} does not repeat if you press @key{RET} again after using it.
5270
d4f3574e 5271@item display/@var{fmt} @var{expr}
c906108c 5272For @var{fmt} specifying only a display format and not a size or
d4f3574e 5273count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5274arrange to display it each time in the specified format @var{fmt}.
5275@xref{Output Formats,,Output formats}.
5276
5277@item display/@var{fmt} @var{addr}
5278For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5279number of units, add the expression @var{addr} as a memory address to
5280be examined each time your program stops. Examining means in effect
5281doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5282@end table
5283
5284For example, @samp{display/i $pc} can be helpful, to see the machine
5285instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5286is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5287
5288@table @code
5289@kindex delete display
5290@kindex undisplay
5291@item undisplay @var{dnums}@dots{}
5292@itemx delete display @var{dnums}@dots{}
5293Remove item numbers @var{dnums} from the list of expressions to display.
5294
5295@code{undisplay} does not repeat if you press @key{RET} after using it.
5296(Otherwise you would just get the error @samp{No display number @dots{}}.)
5297
5298@kindex disable display
5299@item disable display @var{dnums}@dots{}
5300Disable the display of item numbers @var{dnums}. A disabled display
5301item is not printed automatically, but is not forgotten. It may be
5302enabled again later.
5303
5304@kindex enable display
5305@item enable display @var{dnums}@dots{}
5306Enable display of item numbers @var{dnums}. It becomes effective once
5307again in auto display of its expression, until you specify otherwise.
5308
5309@item display
5310Display the current values of the expressions on the list, just as is
5311done when your program stops.
5312
5313@kindex info display
5314@item info display
5315Print the list of expressions previously set up to display
5316automatically, each one with its item number, but without showing the
5317values. This includes disabled expressions, which are marked as such.
5318It also includes expressions which would not be displayed right now
5319because they refer to automatic variables not currently available.
5320@end table
5321
15387254 5322@cindex display disabled out of scope
c906108c
SS
5323If a display expression refers to local variables, then it does not make
5324sense outside the lexical context for which it was set up. Such an
5325expression is disabled when execution enters a context where one of its
5326variables is not defined. For example, if you give the command
5327@code{display last_char} while inside a function with an argument
5328@code{last_char}, @value{GDBN} displays this argument while your program
5329continues to stop inside that function. When it stops elsewhere---where
5330there is no variable @code{last_char}---the display is disabled
5331automatically. The next time your program stops where @code{last_char}
5332is meaningful, you can enable the display expression once again.
5333
6d2ebf8b 5334@node Print Settings
c906108c
SS
5335@section Print settings
5336
5337@cindex format options
5338@cindex print settings
5339@value{GDBN} provides the following ways to control how arrays, structures,
5340and symbols are printed.
5341
5342@noindent
5343These settings are useful for debugging programs in any language:
5344
5345@table @code
4644b6e3 5346@kindex set print
c906108c
SS
5347@item set print address
5348@itemx set print address on
4644b6e3 5349@cindex print/don't print memory addresses
c906108c
SS
5350@value{GDBN} prints memory addresses showing the location of stack
5351traces, structure values, pointer values, breakpoints, and so forth,
5352even when it also displays the contents of those addresses. The default
5353is @code{on}. For example, this is what a stack frame display looks like with
5354@code{set print address on}:
5355
5356@smallexample
5357@group
5358(@value{GDBP}) f
5359#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5360 at input.c:530
5361530 if (lquote != def_lquote)
5362@end group
5363@end smallexample
5364
5365@item set print address off
5366Do not print addresses when displaying their contents. For example,
5367this is the same stack frame displayed with @code{set print address off}:
5368
5369@smallexample
5370@group
5371(@value{GDBP}) set print addr off
5372(@value{GDBP}) f
5373#0 set_quotes (lq="<<", rq=">>") at input.c:530
5374530 if (lquote != def_lquote)
5375@end group
5376@end smallexample
5377
5378You can use @samp{set print address off} to eliminate all machine
5379dependent displays from the @value{GDBN} interface. For example, with
5380@code{print address off}, you should get the same text for backtraces on
5381all machines---whether or not they involve pointer arguments.
5382
4644b6e3 5383@kindex show print
c906108c
SS
5384@item show print address
5385Show whether or not addresses are to be printed.
5386@end table
5387
5388When @value{GDBN} prints a symbolic address, it normally prints the
5389closest earlier symbol plus an offset. If that symbol does not uniquely
5390identify the address (for example, it is a name whose scope is a single
5391source file), you may need to clarify. One way to do this is with
5392@code{info line}, for example @samp{info line *0x4537}. Alternately,
5393you can set @value{GDBN} to print the source file and line number when
5394it prints a symbolic address:
5395
5396@table @code
c906108c 5397@item set print symbol-filename on
4644b6e3 5398@cindex closest symbol and offset for an address
c906108c
SS
5399Tell @value{GDBN} to print the source file name and line number of a
5400symbol in the symbolic form of an address.
5401
5402@item set print symbol-filename off
5403Do not print source file name and line number of a symbol. This is the
5404default.
5405
c906108c
SS
5406@item show print symbol-filename
5407Show whether or not @value{GDBN} will print the source file name and
5408line number of a symbol in the symbolic form of an address.
5409@end table
5410
5411Another situation where it is helpful to show symbol filenames and line
5412numbers is when disassembling code; @value{GDBN} shows you the line
5413number and source file that corresponds to each instruction.
5414
5415Also, you may wish to see the symbolic form only if the address being
5416printed is reasonably close to the closest earlier symbol:
5417
5418@table @code
c906108c 5419@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5420@cindex maximum value for offset of closest symbol
c906108c
SS
5421Tell @value{GDBN} to only display the symbolic form of an address if the
5422offset between the closest earlier symbol and the address is less than
5d161b24 5423@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5424to always print the symbolic form of an address if any symbol precedes it.
5425
c906108c
SS
5426@item show print max-symbolic-offset
5427Ask how large the maximum offset is that @value{GDBN} prints in a
5428symbolic address.
5429@end table
5430
5431@cindex wild pointer, interpreting
5432@cindex pointer, finding referent
5433If you have a pointer and you are not sure where it points, try
5434@samp{set print symbol-filename on}. Then you can determine the name
5435and source file location of the variable where it points, using
5436@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5437For example, here @value{GDBN} shows that a variable @code{ptt} points
5438at another variable @code{t}, defined in @file{hi2.c}:
5439
474c8240 5440@smallexample
c906108c
SS
5441(@value{GDBP}) set print symbol-filename on
5442(@value{GDBP}) p/a ptt
5443$4 = 0xe008 <t in hi2.c>
474c8240 5444@end smallexample
c906108c
SS
5445
5446@quotation
5447@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5448does not show the symbol name and filename of the referent, even with
5449the appropriate @code{set print} options turned on.
5450@end quotation
5451
5452Other settings control how different kinds of objects are printed:
5453
5454@table @code
c906108c
SS
5455@item set print array
5456@itemx set print array on
4644b6e3 5457@cindex pretty print arrays
c906108c
SS
5458Pretty print arrays. This format is more convenient to read,
5459but uses more space. The default is off.
5460
5461@item set print array off
5462Return to compressed format for arrays.
5463
c906108c
SS
5464@item show print array
5465Show whether compressed or pretty format is selected for displaying
5466arrays.
5467
c906108c 5468@item set print elements @var{number-of-elements}
4644b6e3 5469@cindex number of array elements to print
c906108c
SS
5470Set a limit on how many elements of an array @value{GDBN} will print.
5471If @value{GDBN} is printing a large array, it stops printing after it has
5472printed the number of elements set by the @code{set print elements} command.
5473This limit also applies to the display of strings.
d4f3574e 5474When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5475Setting @var{number-of-elements} to zero means that the printing is unlimited.
5476
c906108c
SS
5477@item show print elements
5478Display the number of elements of a large array that @value{GDBN} will print.
5479If the number is 0, then the printing is unlimited.
5480
c906108c 5481@item set print null-stop
4644b6e3 5482@cindex @sc{null} elements in arrays
c906108c 5483Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5484@sc{null} is encountered. This is useful when large arrays actually
c906108c 5485contain only short strings.
d4f3574e 5486The default is off.
c906108c 5487
c906108c 5488@item set print pretty on
5d161b24 5489Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5490per line, like this:
5491
5492@smallexample
5493@group
5494$1 = @{
5495 next = 0x0,
5496 flags = @{
5497 sweet = 1,
5498 sour = 1
5499 @},
5500 meat = 0x54 "Pork"
5501@}
5502@end group
5503@end smallexample
5504
5505@item set print pretty off
5506Cause @value{GDBN} to print structures in a compact format, like this:
5507
5508@smallexample
5509@group
5510$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5511meat = 0x54 "Pork"@}
5512@end group
5513@end smallexample
5514
5515@noindent
5516This is the default format.
5517
c906108c
SS
5518@item show print pretty
5519Show which format @value{GDBN} is using to print structures.
5520
c906108c 5521@item set print sevenbit-strings on
4644b6e3
EZ
5522@cindex eight-bit characters in strings
5523@cindex octal escapes in strings
c906108c
SS
5524Print using only seven-bit characters; if this option is set,
5525@value{GDBN} displays any eight-bit characters (in strings or
5526character values) using the notation @code{\}@var{nnn}. This setting is
5527best if you are working in English (@sc{ascii}) and you use the
5528high-order bit of characters as a marker or ``meta'' bit.
5529
5530@item set print sevenbit-strings off
5531Print full eight-bit characters. This allows the use of more
5532international character sets, and is the default.
5533
c906108c
SS
5534@item show print sevenbit-strings
5535Show whether or not @value{GDBN} is printing only seven-bit characters.
5536
c906108c 5537@item set print union on
4644b6e3 5538@cindex unions in structures, printing
5d161b24 5539Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5540is the default setting.
5541
5542@item set print union off
5543Tell @value{GDBN} not to print unions which are contained in structures.
5544
c906108c
SS
5545@item show print union
5546Ask @value{GDBN} whether or not it will print unions which are contained in
5547structures.
5548
5549For example, given the declarations
5550
5551@smallexample
5552typedef enum @{Tree, Bug@} Species;
5553typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5554typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5555 Bug_forms;
5556
5557struct thing @{
5558 Species it;
5559 union @{
5560 Tree_forms tree;
5561 Bug_forms bug;
5562 @} form;
5563@};
5564
5565struct thing foo = @{Tree, @{Acorn@}@};
5566@end smallexample
5567
5568@noindent
5569with @code{set print union on} in effect @samp{p foo} would print
5570
5571@smallexample
5572$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5573@end smallexample
5574
5575@noindent
5576and with @code{set print union off} in effect it would print
5577
5578@smallexample
5579$1 = @{it = Tree, form = @{...@}@}
5580@end smallexample
5581@end table
5582
c906108c
SS
5583@need 1000
5584@noindent
b37052ae 5585These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5586
5587@table @code
4644b6e3 5588@cindex demangling C@t{++} names
c906108c
SS
5589@item set print demangle
5590@itemx set print demangle on
b37052ae 5591Print C@t{++} names in their source form rather than in the encoded
c906108c 5592(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5593linkage. The default is on.
c906108c 5594
c906108c 5595@item show print demangle
b37052ae 5596Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5597
c906108c
SS
5598@item set print asm-demangle
5599@itemx set print asm-demangle on
b37052ae 5600Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5601in assembler code printouts such as instruction disassemblies.
5602The default is off.
5603
c906108c 5604@item show print asm-demangle
b37052ae 5605Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5606or demangled form.
5607
b37052ae
EZ
5608@cindex C@t{++} symbol decoding style
5609@cindex symbol decoding style, C@t{++}
c906108c
SS
5610@item set demangle-style @var{style}
5611Choose among several encoding schemes used by different compilers to
b37052ae 5612represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5613
5614@table @code
5615@item auto
5616Allow @value{GDBN} to choose a decoding style by inspecting your program.
5617
5618@item gnu
b37052ae 5619Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5620This is the default.
c906108c
SS
5621
5622@item hp
b37052ae 5623Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5624
5625@item lucid
b37052ae 5626Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5627
5628@item arm
b37052ae 5629Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5630@strong{Warning:} this setting alone is not sufficient to allow
5631debugging @code{cfront}-generated executables. @value{GDBN} would
5632require further enhancement to permit that.
5633
5634@end table
5635If you omit @var{style}, you will see a list of possible formats.
5636
c906108c 5637@item show demangle-style
b37052ae 5638Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5639
c906108c
SS
5640@item set print object
5641@itemx set print object on
4644b6e3 5642@cindex derived type of an object, printing
c906108c
SS
5643When displaying a pointer to an object, identify the @emph{actual}
5644(derived) type of the object rather than the @emph{declared} type, using
5645the virtual function table.
5646
5647@item set print object off
5648Display only the declared type of objects, without reference to the
5649virtual function table. This is the default setting.
5650
c906108c
SS
5651@item show print object
5652Show whether actual, or declared, object types are displayed.
5653
c906108c
SS
5654@item set print static-members
5655@itemx set print static-members on
4644b6e3 5656@cindex static members of C@t{++} objects
b37052ae 5657Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5658
5659@item set print static-members off
b37052ae 5660Do not print static members when displaying a C@t{++} object.
c906108c 5661
c906108c 5662@item show print static-members
b37052ae 5663Show whether C@t{++} static members are printed, or not.
c906108c
SS
5664
5665@c These don't work with HP ANSI C++ yet.
c906108c
SS
5666@item set print vtbl
5667@itemx set print vtbl on
4644b6e3 5668@cindex pretty print C@t{++} virtual function tables
b37052ae 5669Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5670(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5671ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5672
5673@item set print vtbl off
b37052ae 5674Do not pretty print C@t{++} virtual function tables.
c906108c 5675
c906108c 5676@item show print vtbl
b37052ae 5677Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5678@end table
c906108c 5679
6d2ebf8b 5680@node Value History
c906108c
SS
5681@section Value history
5682
5683@cindex value history
5d161b24
DB
5684Values printed by the @code{print} command are saved in the @value{GDBN}
5685@dfn{value history}. This allows you to refer to them in other expressions.
5686Values are kept until the symbol table is re-read or discarded
5687(for example with the @code{file} or @code{symbol-file} commands).
5688When the symbol table changes, the value history is discarded,
5689since the values may contain pointers back to the types defined in the
c906108c
SS
5690symbol table.
5691
5692@cindex @code{$}
5693@cindex @code{$$}
5694@cindex history number
5695The values printed are given @dfn{history numbers} by which you can
5696refer to them. These are successive integers starting with one.
5697@code{print} shows you the history number assigned to a value by
5698printing @samp{$@var{num} = } before the value; here @var{num} is the
5699history number.
5700
5701To refer to any previous value, use @samp{$} followed by the value's
5702history number. The way @code{print} labels its output is designed to
5703remind you of this. Just @code{$} refers to the most recent value in
5704the history, and @code{$$} refers to the value before that.
5705@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5706is the value just prior to @code{$$}, @code{$$1} is equivalent to
5707@code{$$}, and @code{$$0} is equivalent to @code{$}.
5708
5709For example, suppose you have just printed a pointer to a structure and
5710want to see the contents of the structure. It suffices to type
5711
474c8240 5712@smallexample
c906108c 5713p *$
474c8240 5714@end smallexample
c906108c
SS
5715
5716If you have a chain of structures where the component @code{next} points
5717to the next one, you can print the contents of the next one with this:
5718
474c8240 5719@smallexample
c906108c 5720p *$.next
474c8240 5721@end smallexample
c906108c
SS
5722
5723@noindent
5724You can print successive links in the chain by repeating this
5725command---which you can do by just typing @key{RET}.
5726
5727Note that the history records values, not expressions. If the value of
5728@code{x} is 4 and you type these commands:
5729
474c8240 5730@smallexample
c906108c
SS
5731print x
5732set x=5
474c8240 5733@end smallexample
c906108c
SS
5734
5735@noindent
5736then the value recorded in the value history by the @code{print} command
5737remains 4 even though the value of @code{x} has changed.
5738
5739@table @code
5740@kindex show values
5741@item show values
5742Print the last ten values in the value history, with their item numbers.
5743This is like @samp{p@ $$9} repeated ten times, except that @code{show
5744values} does not change the history.
5745
5746@item show values @var{n}
5747Print ten history values centered on history item number @var{n}.
5748
5749@item show values +
5750Print ten history values just after the values last printed. If no more
5751values are available, @code{show values +} produces no display.
5752@end table
5753
5754Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5755same effect as @samp{show values +}.
5756
6d2ebf8b 5757@node Convenience Vars
c906108c
SS
5758@section Convenience variables
5759
5760@cindex convenience variables
5761@value{GDBN} provides @dfn{convenience variables} that you can use within
5762@value{GDBN} to hold on to a value and refer to it later. These variables
5763exist entirely within @value{GDBN}; they are not part of your program, and
5764setting a convenience variable has no direct effect on further execution
5765of your program. That is why you can use them freely.
5766
5767Convenience variables are prefixed with @samp{$}. Any name preceded by
5768@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5769the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5770(Value history references, in contrast, are @emph{numbers} preceded
5771by @samp{$}. @xref{Value History, ,Value history}.)
5772
5773You can save a value in a convenience variable with an assignment
5774expression, just as you would set a variable in your program.
5775For example:
5776
474c8240 5777@smallexample
c906108c 5778set $foo = *object_ptr
474c8240 5779@end smallexample
c906108c
SS
5780
5781@noindent
5782would save in @code{$foo} the value contained in the object pointed to by
5783@code{object_ptr}.
5784
5785Using a convenience variable for the first time creates it, but its
5786value is @code{void} until you assign a new value. You can alter the
5787value with another assignment at any time.
5788
5789Convenience variables have no fixed types. You can assign a convenience
5790variable any type of value, including structures and arrays, even if
5791that variable already has a value of a different type. The convenience
5792variable, when used as an expression, has the type of its current value.
5793
5794@table @code
5795@kindex show convenience
5796@item show convenience
5797Print a list of convenience variables used so far, and their values.
d4f3574e 5798Abbreviated @code{show conv}.
c906108c
SS
5799@end table
5800
5801One of the ways to use a convenience variable is as a counter to be
5802incremented or a pointer to be advanced. For example, to print
5803a field from successive elements of an array of structures:
5804
474c8240 5805@smallexample
c906108c
SS
5806set $i = 0
5807print bar[$i++]->contents
474c8240 5808@end smallexample
c906108c 5809
d4f3574e
SS
5810@noindent
5811Repeat that command by typing @key{RET}.
c906108c
SS
5812
5813Some convenience variables are created automatically by @value{GDBN} and given
5814values likely to be useful.
5815
5816@table @code
41afff9a 5817@vindex $_@r{, convenience variable}
c906108c
SS
5818@item $_
5819The variable @code{$_} is automatically set by the @code{x} command to
5820the last address examined (@pxref{Memory, ,Examining memory}). Other
5821commands which provide a default address for @code{x} to examine also
5822set @code{$_} to that address; these commands include @code{info line}
5823and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5824except when set by the @code{x} command, in which case it is a pointer
5825to the type of @code{$__}.
5826
41afff9a 5827@vindex $__@r{, convenience variable}
c906108c
SS
5828@item $__
5829The variable @code{$__} is automatically set by the @code{x} command
5830to the value found in the last address examined. Its type is chosen
5831to match the format in which the data was printed.
5832
5833@item $_exitcode
41afff9a 5834@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5835The variable @code{$_exitcode} is automatically set to the exit code when
5836the program being debugged terminates.
5837@end table
5838
53a5351d
JM
5839On HP-UX systems, if you refer to a function or variable name that
5840begins with a dollar sign, @value{GDBN} searches for a user or system
5841name first, before it searches for a convenience variable.
c906108c 5842
6d2ebf8b 5843@node Registers
c906108c
SS
5844@section Registers
5845
5846@cindex registers
5847You can refer to machine register contents, in expressions, as variables
5848with names starting with @samp{$}. The names of registers are different
5849for each machine; use @code{info registers} to see the names used on
5850your machine.
5851
5852@table @code
5853@kindex info registers
5854@item info registers
5855Print the names and values of all registers except floating-point
c85508ee 5856and vector registers (in the selected stack frame).
c906108c
SS
5857
5858@kindex info all-registers
5859@cindex floating point registers
5860@item info all-registers
5861Print the names and values of all registers, including floating-point
c85508ee 5862and vector registers (in the selected stack frame).
c906108c
SS
5863
5864@item info registers @var{regname} @dots{}
5865Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5866As discussed in detail below, register values are normally relative to
5867the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5868the machine you are using, with or without the initial @samp{$}.
5869@end table
5870
5871@value{GDBN} has four ``standard'' register names that are available (in
5872expressions) on most machines---whenever they do not conflict with an
5873architecture's canonical mnemonics for registers. The register names
5874@code{$pc} and @code{$sp} are used for the program counter register and
5875the stack pointer. @code{$fp} is used for a register that contains a
5876pointer to the current stack frame, and @code{$ps} is used for a
5877register that contains the processor status. For example,
5878you could print the program counter in hex with
5879
474c8240 5880@smallexample
c906108c 5881p/x $pc
474c8240 5882@end smallexample
c906108c
SS
5883
5884@noindent
5885or print the instruction to be executed next with
5886
474c8240 5887@smallexample
c906108c 5888x/i $pc
474c8240 5889@end smallexample
c906108c
SS
5890
5891@noindent
5892or add four to the stack pointer@footnote{This is a way of removing
5893one word from the stack, on machines where stacks grow downward in
5894memory (most machines, nowadays). This assumes that the innermost
5895stack frame is selected; setting @code{$sp} is not allowed when other
5896stack frames are selected. To pop entire frames off the stack,
5897regardless of machine architecture, use @code{return};
d4f3574e 5898see @ref{Returning, ,Returning from a function}.} with
c906108c 5899
474c8240 5900@smallexample
c906108c 5901set $sp += 4
474c8240 5902@end smallexample
c906108c
SS
5903
5904Whenever possible, these four standard register names are available on
5905your machine even though the machine has different canonical mnemonics,
5906so long as there is no conflict. The @code{info registers} command
5907shows the canonical names. For example, on the SPARC, @code{info
5908registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5909can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5910is an alias for the @sc{eflags} register.
c906108c
SS
5911
5912@value{GDBN} always considers the contents of an ordinary register as an
5913integer when the register is examined in this way. Some machines have
5914special registers which can hold nothing but floating point; these
5915registers are considered to have floating point values. There is no way
5916to refer to the contents of an ordinary register as floating point value
5917(although you can @emph{print} it as a floating point value with
5918@samp{print/f $@var{regname}}).
5919
5920Some registers have distinct ``raw'' and ``virtual'' data formats. This
5921means that the data format in which the register contents are saved by
5922the operating system is not the same one that your program normally
5923sees. For example, the registers of the 68881 floating point
5924coprocessor are always saved in ``extended'' (raw) format, but all C
5925programs expect to work with ``double'' (virtual) format. In such
5d161b24 5926cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5927that makes sense for your program), but the @code{info registers} command
5928prints the data in both formats.
5929
5930Normally, register values are relative to the selected stack frame
5931(@pxref{Selection, ,Selecting a frame}). This means that you get the
5932value that the register would contain if all stack frames farther in
5933were exited and their saved registers restored. In order to see the
5934true contents of hardware registers, you must select the innermost
5935frame (with @samp{frame 0}).
5936
5937However, @value{GDBN} must deduce where registers are saved, from the machine
5938code generated by your compiler. If some registers are not saved, or if
5939@value{GDBN} is unable to locate the saved registers, the selected stack
5940frame makes no difference.
5941
6d2ebf8b 5942@node Floating Point Hardware
c906108c
SS
5943@section Floating point hardware
5944@cindex floating point
5945
5946Depending on the configuration, @value{GDBN} may be able to give
5947you more information about the status of the floating point hardware.
5948
5949@table @code
5950@kindex info float
5951@item info float
5952Display hardware-dependent information about the floating
5953point unit. The exact contents and layout vary depending on the
5954floating point chip. Currently, @samp{info float} is supported on
5955the ARM and x86 machines.
5956@end table
c906108c 5957
e76f1f2e
AC
5958@node Vector Unit
5959@section Vector Unit
5960@cindex vector unit
5961
5962Depending on the configuration, @value{GDBN} may be able to give you
5963more information about the status of the vector unit.
5964
5965@table @code
5966@kindex info vector
5967@item info vector
5968Display information about the vector unit. The exact contents and
5969layout vary depending on the hardware.
5970@end table
5971
b383017d
RM
5972@node Auxiliary Vector
5973@section Operating system auxiliary vector
5974@cindex auxiliary vector
5975@cindex vector, auxiliary
5976
5977Some operating systems supply an @dfn{auxiliary vector} to programs at
5978startup. This is akin to the arguments and environment that you
5979specify for a program, but contains a system-dependent variety of
5980binary values that tell system libraries important details about the
5981hardware, operating system, and process. Each value's purpose is
5982identified by an integer tag; the meanings are well-known but system-specific.
5983Depending on the configuration and operating system facilities,
5984@value{GDBN} may be able to show you this information.
5985
5986@table @code
5987@kindex info auxv
5988@item info auxv
5989Display the auxiliary vector of the inferior, which can be either a
e4937fc1 5990live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
5991numerically, and also shows names and text descriptions for recognized
5992tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 5993pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
5994most appropriate form for a recognized tag, and in hexadecimal for
5995an unrecognized tag.
5996@end table
5997
29e57380 5998@node Memory Region Attributes
b383017d 5999@section Memory region attributes
29e57380
C
6000@cindex memory region attributes
6001
b383017d
RM
6002@dfn{Memory region attributes} allow you to describe special handling
6003required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6004to determine whether to allow certain types of memory accesses; whether to
6005use specific width accesses; and whether to cache target memory.
6006
6007Defined memory regions can be individually enabled and disabled. When a
6008memory region is disabled, @value{GDBN} uses the default attributes when
6009accessing memory in that region. Similarly, if no memory regions have
6010been defined, @value{GDBN} uses the default attributes when accessing
6011all memory.
6012
b383017d 6013When a memory region is defined, it is given a number to identify it;
29e57380
C
6014to enable, disable, or remove a memory region, you specify that number.
6015
6016@table @code
6017@kindex mem
bfac230e
DH
6018@item mem @var{lower} @var{upper} @var{attributes}@dots{}
6019Define memory region bounded by @var{lower} and @var{upper} with
6020attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
6021special case: it is treated as the the target's maximum memory address.
6022(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6023
6024@kindex delete mem
6025@item delete mem @var{nums}@dots{}
59649f2e 6026Remove memory regions @var{nums}@dots{}.
29e57380
C
6027
6028@kindex disable mem
6029@item disable mem @var{nums}@dots{}
59649f2e 6030Disable memory regions @var{nums}@dots{}.
b383017d 6031A disabled memory region is not forgotten.
29e57380
C
6032It may be enabled again later.
6033
6034@kindex enable mem
6035@item enable mem @var{nums}@dots{}
59649f2e 6036Enable memory regions @var{nums}@dots{}.
29e57380
C
6037
6038@kindex info mem
6039@item info mem
6040Print a table of all defined memory regions, with the following columns
6041for each region.
6042
6043@table @emph
6044@item Memory Region Number
6045@item Enabled or Disabled.
b383017d 6046Enabled memory regions are marked with @samp{y}.
29e57380
C
6047Disabled memory regions are marked with @samp{n}.
6048
6049@item Lo Address
6050The address defining the inclusive lower bound of the memory region.
6051
6052@item Hi Address
6053The address defining the exclusive upper bound of the memory region.
6054
6055@item Attributes
6056The list of attributes set for this memory region.
6057@end table
6058@end table
6059
6060
6061@subsection Attributes
6062
b383017d 6063@subsubsection Memory Access Mode
29e57380
C
6064The access mode attributes set whether @value{GDBN} may make read or
6065write accesses to a memory region.
6066
6067While these attributes prevent @value{GDBN} from performing invalid
6068memory accesses, they do nothing to prevent the target system, I/O DMA,
6069etc. from accessing memory.
6070
6071@table @code
6072@item ro
6073Memory is read only.
6074@item wo
6075Memory is write only.
6076@item rw
6ca652b0 6077Memory is read/write. This is the default.
29e57380
C
6078@end table
6079
6080@subsubsection Memory Access Size
6081The acccess size attributes tells @value{GDBN} to use specific sized
6082accesses in the memory region. Often memory mapped device registers
6083require specific sized accesses. If no access size attribute is
6084specified, @value{GDBN} may use accesses of any size.
6085
6086@table @code
6087@item 8
6088Use 8 bit memory accesses.
6089@item 16
6090Use 16 bit memory accesses.
6091@item 32
6092Use 32 bit memory accesses.
6093@item 64
6094Use 64 bit memory accesses.
6095@end table
6096
6097@c @subsubsection Hardware/Software Breakpoints
6098@c The hardware/software breakpoint attributes set whether @value{GDBN}
6099@c will use hardware or software breakpoints for the internal breakpoints
6100@c used by the step, next, finish, until, etc. commands.
6101@c
6102@c @table @code
6103@c @item hwbreak
b383017d 6104@c Always use hardware breakpoints
29e57380
C
6105@c @item swbreak (default)
6106@c @end table
6107
6108@subsubsection Data Cache
6109The data cache attributes set whether @value{GDBN} will cache target
6110memory. While this generally improves performance by reducing debug
6111protocol overhead, it can lead to incorrect results because @value{GDBN}
6112does not know about volatile variables or memory mapped device
6113registers.
6114
6115@table @code
6116@item cache
b383017d 6117Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6118@item nocache
6119Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6120@end table
6121
6122@c @subsubsection Memory Write Verification
b383017d 6123@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6124@c will re-reads data after each write to verify the write was successful.
6125@c
6126@c @table @code
6127@c @item verify
6128@c @item noverify (default)
6129@c @end table
6130
16d9dec6
MS
6131@node Dump/Restore Files
6132@section Copy between memory and a file
6133@cindex dump/restore files
6134@cindex append data to a file
6135@cindex dump data to a file
6136@cindex restore data from a file
16d9dec6 6137
df5215a6
JB
6138You can use the commands @code{dump}, @code{append}, and
6139@code{restore} to copy data between target memory and a file. The
6140@code{dump} and @code{append} commands write data to a file, and the
6141@code{restore} command reads data from a file back into the inferior's
6142memory. Files may be in binary, Motorola S-record, Intel hex, or
6143Tektronix Hex format; however, @value{GDBN} can only append to binary
6144files.
6145
6146@table @code
6147
6148@kindex dump
6149@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6150@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6151Dump the contents of memory from @var{start_addr} to @var{end_addr},
6152or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6153
df5215a6 6154The @var{format} parameter may be any one of:
16d9dec6 6155@table @code
df5215a6
JB
6156@item binary
6157Raw binary form.
6158@item ihex
6159Intel hex format.
6160@item srec
6161Motorola S-record format.
6162@item tekhex
6163Tektronix Hex format.
6164@end table
6165
6166@value{GDBN} uses the same definitions of these formats as the
6167@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6168@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6169form.
6170
6171@kindex append
6172@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6173@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6174Append the contents of memory from @var{start_addr} to @var{end_addr},
6175or the value of @var{expr}, to @var{filename}, in raw binary form.
6176(@value{GDBN} can only append data to files in raw binary form.)
6177
6178@kindex restore
6179@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6180Restore the contents of file @var{filename} into memory. The
6181@code{restore} command can automatically recognize any known @sc{bfd}
6182file format, except for raw binary. To restore a raw binary file you
6183must specify the optional keyword @code{binary} after the filename.
16d9dec6 6184
b383017d 6185If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6186contained in the file. Binary files always start at address zero, so
6187they will be restored at address @var{bias}. Other bfd files have
6188a built-in location; they will be restored at offset @var{bias}
6189from that location.
6190
6191If @var{start} and/or @var{end} are non-zero, then only data between
6192file offset @var{start} and file offset @var{end} will be restored.
b383017d 6193These offsets are relative to the addresses in the file, before
16d9dec6
MS
6194the @var{bias} argument is applied.
6195
6196@end table
6197
384ee23f
EZ
6198@node Core File Generation
6199@section How to Produce a Core File from Your Program
6200@cindex dump core from inferior
6201
6202A @dfn{core file} or @dfn{core dump} is a file that records the memory
6203image of a running process and its process status (register values
6204etc.). Its primary use is post-mortem debugging of a program that
6205crashed while it ran outside a debugger. A program that crashes
6206automatically produces a core file, unless this feature is disabled by
6207the user. @xref{Files}, for information on invoking @value{GDBN} in
6208the post-mortem debugging mode.
6209
6210Occasionally, you may wish to produce a core file of the program you
6211are debugging in order to preserve a snapshot of its state.
6212@value{GDBN} has a special command for that.
6213
6214@table @code
6215@kindex gcore
6216@kindex generate-core-file
6217@item generate-core-file [@var{file}]
6218@itemx gcore [@var{file}]
6219Produce a core dump of the inferior process. The optional argument
6220@var{file} specifies the file name where to put the core dump. If not
6221specified, the file name defaults to @file{core.@var{pid}}, where
6222@var{pid} is the inferior process ID.
6223
6224Note that this command is implemented only for some systems (as of
6225this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6226@end table
6227
a0eb71c5
KB
6228@node Character Sets
6229@section Character Sets
6230@cindex character sets
6231@cindex charset
6232@cindex translating between character sets
6233@cindex host character set
6234@cindex target character set
6235
6236If the program you are debugging uses a different character set to
6237represent characters and strings than the one @value{GDBN} uses itself,
6238@value{GDBN} can automatically translate between the character sets for
6239you. The character set @value{GDBN} uses we call the @dfn{host
6240character set}; the one the inferior program uses we call the
6241@dfn{target character set}.
6242
6243For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6244uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6245remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6246running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6247then the host character set is Latin-1, and the target character set is
6248@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6249target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6250@sc{ebcdic} and Latin 1 as you print character or string values, or use
6251character and string literals in expressions.
6252
6253@value{GDBN} has no way to automatically recognize which character set
6254the inferior program uses; you must tell it, using the @code{set
6255target-charset} command, described below.
6256
6257Here are the commands for controlling @value{GDBN}'s character set
6258support:
6259
6260@table @code
6261@item set target-charset @var{charset}
6262@kindex set target-charset
6263Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6264character set names @value{GDBN} recognizes below, but if you type
6265@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6266list the target character sets it supports.
a0eb71c5
KB
6267@end table
6268
6269@table @code
6270@item set host-charset @var{charset}
6271@kindex set host-charset
6272Set the current host character set to @var{charset}.
6273
6274By default, @value{GDBN} uses a host character set appropriate to the
6275system it is running on; you can override that default using the
6276@code{set host-charset} command.
6277
6278@value{GDBN} can only use certain character sets as its host character
6279set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6280indicate which can be host character sets, but if you type
6281@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6282list the host character sets it supports.
a0eb71c5
KB
6283
6284@item set charset @var{charset}
6285@kindex set charset
e33d66ec
EZ
6286Set the current host and target character sets to @var{charset}. As
6287above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6288@value{GDBN} will list the name of the character sets that can be used
6289for both host and target.
6290
a0eb71c5
KB
6291
6292@item show charset
a0eb71c5 6293@kindex show charset
b383017d 6294Show the names of the current host and target charsets.
e33d66ec
EZ
6295
6296@itemx show host-charset
a0eb71c5 6297@kindex show host-charset
b383017d 6298Show the name of the current host charset.
e33d66ec
EZ
6299
6300@itemx show target-charset
a0eb71c5 6301@kindex show target-charset
b383017d 6302Show the name of the current target charset.
a0eb71c5
KB
6303
6304@end table
6305
6306@value{GDBN} currently includes support for the following character
6307sets:
6308
6309@table @code
6310
6311@item ASCII
6312@cindex ASCII character set
6313Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6314character set.
6315
6316@item ISO-8859-1
6317@cindex ISO 8859-1 character set
6318@cindex ISO Latin 1 character set
e33d66ec 6319The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6320characters needed for French, German, and Spanish. @value{GDBN} can use
6321this as its host character set.
6322
6323@item EBCDIC-US
6324@itemx IBM1047
6325@cindex EBCDIC character set
6326@cindex IBM1047 character set
6327Variants of the @sc{ebcdic} character set, used on some of IBM's
6328mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6329@value{GDBN} cannot use these as its host character set.
6330
6331@end table
6332
6333Note that these are all single-byte character sets. More work inside
6334GDB is needed to support multi-byte or variable-width character
6335encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6336
6337Here is an example of @value{GDBN}'s character set support in action.
6338Assume that the following source code has been placed in the file
6339@file{charset-test.c}:
6340
6341@smallexample
6342#include <stdio.h>
6343
6344char ascii_hello[]
6345 = @{72, 101, 108, 108, 111, 44, 32, 119,
6346 111, 114, 108, 100, 33, 10, 0@};
6347char ibm1047_hello[]
6348 = @{200, 133, 147, 147, 150, 107, 64, 166,
6349 150, 153, 147, 132, 90, 37, 0@};
6350
6351main ()
6352@{
6353 printf ("Hello, world!\n");
6354@}
10998722 6355@end smallexample
a0eb71c5
KB
6356
6357In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6358containing the string @samp{Hello, world!} followed by a newline,
6359encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6360
6361We compile the program, and invoke the debugger on it:
6362
6363@smallexample
6364$ gcc -g charset-test.c -o charset-test
6365$ gdb -nw charset-test
6366GNU gdb 2001-12-19-cvs
6367Copyright 2001 Free Software Foundation, Inc.
6368@dots{}
f7dc1244 6369(@value{GDBP})
10998722 6370@end smallexample
a0eb71c5
KB
6371
6372We can use the @code{show charset} command to see what character sets
6373@value{GDBN} is currently using to interpret and display characters and
6374strings:
6375
6376@smallexample
f7dc1244 6377(@value{GDBP}) show charset
e33d66ec 6378The current host and target character set is `ISO-8859-1'.
f7dc1244 6379(@value{GDBP})
10998722 6380@end smallexample
a0eb71c5
KB
6381
6382For the sake of printing this manual, let's use @sc{ascii} as our
6383initial character set:
6384@smallexample
f7dc1244
EZ
6385(@value{GDBP}) set charset ASCII
6386(@value{GDBP}) show charset
e33d66ec 6387The current host and target character set is `ASCII'.
f7dc1244 6388(@value{GDBP})
10998722 6389@end smallexample
a0eb71c5
KB
6390
6391Let's assume that @sc{ascii} is indeed the correct character set for our
6392host system --- in other words, let's assume that if @value{GDBN} prints
6393characters using the @sc{ascii} character set, our terminal will display
6394them properly. Since our current target character set is also
6395@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6396
6397@smallexample
f7dc1244 6398(@value{GDBP}) print ascii_hello
a0eb71c5 6399$1 = 0x401698 "Hello, world!\n"
f7dc1244 6400(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6401$2 = 72 'H'
f7dc1244 6402(@value{GDBP})
10998722 6403@end smallexample
a0eb71c5
KB
6404
6405@value{GDBN} uses the target character set for character and string
6406literals you use in expressions:
6407
6408@smallexample
f7dc1244 6409(@value{GDBP}) print '+'
a0eb71c5 6410$3 = 43 '+'
f7dc1244 6411(@value{GDBP})
10998722 6412@end smallexample
a0eb71c5
KB
6413
6414The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6415character.
6416
6417@value{GDBN} relies on the user to tell it which character set the
6418target program uses. If we print @code{ibm1047_hello} while our target
6419character set is still @sc{ascii}, we get jibberish:
6420
6421@smallexample
f7dc1244 6422(@value{GDBP}) print ibm1047_hello
a0eb71c5 6423$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6424(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6425$5 = 200 '\310'
f7dc1244 6426(@value{GDBP})
10998722 6427@end smallexample
a0eb71c5 6428
e33d66ec 6429If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6430@value{GDBN} tells us the character sets it supports:
6431
6432@smallexample
f7dc1244 6433(@value{GDBP}) set target-charset
b383017d 6434ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6435(@value{GDBP}) set target-charset
10998722 6436@end smallexample
a0eb71c5
KB
6437
6438We can select @sc{ibm1047} as our target character set, and examine the
6439program's strings again. Now the @sc{ascii} string is wrong, but
6440@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6441target character set, @sc{ibm1047}, to the host character set,
6442@sc{ascii}, and they display correctly:
6443
6444@smallexample
f7dc1244
EZ
6445(@value{GDBP}) set target-charset IBM1047
6446(@value{GDBP}) show charset
e33d66ec
EZ
6447The current host character set is `ASCII'.
6448The current target character set is `IBM1047'.
f7dc1244 6449(@value{GDBP}) print ascii_hello
a0eb71c5 6450$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6451(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6452$7 = 72 '\110'
f7dc1244 6453(@value{GDBP}) print ibm1047_hello
a0eb71c5 6454$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6455(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6456$9 = 200 'H'
f7dc1244 6457(@value{GDBP})
10998722 6458@end smallexample
a0eb71c5
KB
6459
6460As above, @value{GDBN} uses the target character set for character and
6461string literals you use in expressions:
6462
6463@smallexample
f7dc1244 6464(@value{GDBP}) print '+'
a0eb71c5 6465$10 = 78 '+'
f7dc1244 6466(@value{GDBP})
10998722 6467@end smallexample
a0eb71c5 6468
e33d66ec 6469The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6470character.
6471
6472
e2e0bcd1
JB
6473@node Macros
6474@chapter C Preprocessor Macros
6475
49efadf5 6476Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6477``preprocessor macros'' which expand into strings of tokens.
6478@value{GDBN} can evaluate expressions containing macro invocations, show
6479the result of macro expansion, and show a macro's definition, including
6480where it was defined.
6481
6482You may need to compile your program specially to provide @value{GDBN}
6483with information about preprocessor macros. Most compilers do not
6484include macros in their debugging information, even when you compile
6485with the @option{-g} flag. @xref{Compilation}.
6486
6487A program may define a macro at one point, remove that definition later,
6488and then provide a different definition after that. Thus, at different
6489points in the program, a macro may have different definitions, or have
6490no definition at all. If there is a current stack frame, @value{GDBN}
6491uses the macros in scope at that frame's source code line. Otherwise,
6492@value{GDBN} uses the macros in scope at the current listing location;
6493see @ref{List}.
6494
6495At the moment, @value{GDBN} does not support the @code{##}
6496token-splicing operator, the @code{#} stringification operator, or
6497variable-arity macros.
6498
6499Whenever @value{GDBN} evaluates an expression, it always expands any
6500macro invocations present in the expression. @value{GDBN} also provides
6501the following commands for working with macros explicitly.
6502
6503@table @code
6504
6505@kindex macro expand
6506@cindex macro expansion, showing the results of preprocessor
6507@cindex preprocessor macro expansion, showing the results of
6508@cindex expanding preprocessor macros
6509@item macro expand @var{expression}
6510@itemx macro exp @var{expression}
6511Show the results of expanding all preprocessor macro invocations in
6512@var{expression}. Since @value{GDBN} simply expands macros, but does
6513not parse the result, @var{expression} need not be a valid expression;
6514it can be any string of tokens.
6515
e2e0bcd1
JB
6516@item macro expand-once @var{expression}
6517@itemx macro exp1 @var{expression}
4644b6e3 6518@cindex expand macro once
e2e0bcd1
JB
6519@i{(This command is not yet implemented.)} Show the results of
6520expanding those preprocessor macro invocations that appear explicitly in
6521@var{expression}. Macro invocations appearing in that expansion are
6522left unchanged. This command allows you to see the effect of a
6523particular macro more clearly, without being confused by further
6524expansions. Since @value{GDBN} simply expands macros, but does not
6525parse the result, @var{expression} need not be a valid expression; it
6526can be any string of tokens.
6527
475b0867 6528@kindex info macro
e2e0bcd1
JB
6529@cindex macro definition, showing
6530@cindex definition, showing a macro's
475b0867 6531@item info macro @var{macro}
e2e0bcd1
JB
6532Show the definition of the macro named @var{macro}, and describe the
6533source location where that definition was established.
6534
6535@kindex macro define
6536@cindex user-defined macros
6537@cindex defining macros interactively
6538@cindex macros, user-defined
6539@item macro define @var{macro} @var{replacement-list}
6540@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6541@i{(This command is not yet implemented.)} Introduce a definition for a
6542preprocessor macro named @var{macro}, invocations of which are replaced
6543by the tokens given in @var{replacement-list}. The first form of this
6544command defines an ``object-like'' macro, which takes no arguments; the
6545second form defines a ``function-like'' macro, which takes the arguments
6546given in @var{arglist}.
6547
6548A definition introduced by this command is in scope in every expression
6549evaluated in @value{GDBN}, until it is removed with the @command{macro
6550undef} command, described below. The definition overrides all
6551definitions for @var{macro} present in the program being debugged, as
6552well as any previous user-supplied definition.
6553
6554@kindex macro undef
6555@item macro undef @var{macro}
6556@i{(This command is not yet implemented.)} Remove any user-supplied
6557definition for the macro named @var{macro}. This command only affects
6558definitions provided with the @command{macro define} command, described
6559above; it cannot remove definitions present in the program being
6560debugged.
6561
6562@end table
6563
6564@cindex macros, example of debugging with
6565Here is a transcript showing the above commands in action. First, we
6566show our source files:
6567
6568@smallexample
6569$ cat sample.c
6570#include <stdio.h>
6571#include "sample.h"
6572
6573#define M 42
6574#define ADD(x) (M + x)
6575
6576main ()
6577@{
6578#define N 28
6579 printf ("Hello, world!\n");
6580#undef N
6581 printf ("We're so creative.\n");
6582#define N 1729
6583 printf ("Goodbye, world!\n");
6584@}
6585$ cat sample.h
6586#define Q <
6587$
6588@end smallexample
6589
6590Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6591We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6592compiler includes information about preprocessor macros in the debugging
6593information.
6594
6595@smallexample
6596$ gcc -gdwarf-2 -g3 sample.c -o sample
6597$
6598@end smallexample
6599
6600Now, we start @value{GDBN} on our sample program:
6601
6602@smallexample
6603$ gdb -nw sample
6604GNU gdb 2002-05-06-cvs
6605Copyright 2002 Free Software Foundation, Inc.
6606GDB is free software, @dots{}
f7dc1244 6607(@value{GDBP})
e2e0bcd1
JB
6608@end smallexample
6609
6610We can expand macros and examine their definitions, even when the
6611program is not running. @value{GDBN} uses the current listing position
6612to decide which macro definitions are in scope:
6613
6614@smallexample
f7dc1244 6615(@value{GDBP}) list main
e2e0bcd1
JB
66163
66174 #define M 42
66185 #define ADD(x) (M + x)
66196
66207 main ()
66218 @{
66229 #define N 28
662310 printf ("Hello, world!\n");
662411 #undef N
662512 printf ("We're so creative.\n");
f7dc1244 6626(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6627Defined at /home/jimb/gdb/macros/play/sample.c:5
6628#define ADD(x) (M + x)
f7dc1244 6629(@value{GDBP}) info macro Q
e2e0bcd1
JB
6630Defined at /home/jimb/gdb/macros/play/sample.h:1
6631 included at /home/jimb/gdb/macros/play/sample.c:2
6632#define Q <
f7dc1244 6633(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6634expands to: (42 + 1)
f7dc1244 6635(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6636expands to: once (M + 1)
f7dc1244 6637(@value{GDBP})
e2e0bcd1
JB
6638@end smallexample
6639
6640In the example above, note that @command{macro expand-once} expands only
6641the macro invocation explicit in the original text --- the invocation of
6642@code{ADD} --- but does not expand the invocation of the macro @code{M},
6643which was introduced by @code{ADD}.
6644
6645Once the program is running, GDB uses the macro definitions in force at
6646the source line of the current stack frame:
6647
6648@smallexample
f7dc1244 6649(@value{GDBP}) break main
e2e0bcd1 6650Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6651(@value{GDBP}) run
b383017d 6652Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6653
6654Breakpoint 1, main () at sample.c:10
665510 printf ("Hello, world!\n");
f7dc1244 6656(@value{GDBP})
e2e0bcd1
JB
6657@end smallexample
6658
6659At line 10, the definition of the macro @code{N} at line 9 is in force:
6660
6661@smallexample
f7dc1244 6662(@value{GDBP}) info macro N
e2e0bcd1
JB
6663Defined at /home/jimb/gdb/macros/play/sample.c:9
6664#define N 28
f7dc1244 6665(@value{GDBP}) macro expand N Q M
e2e0bcd1 6666expands to: 28 < 42
f7dc1244 6667(@value{GDBP}) print N Q M
e2e0bcd1 6668$1 = 1
f7dc1244 6669(@value{GDBP})
e2e0bcd1
JB
6670@end smallexample
6671
6672As we step over directives that remove @code{N}'s definition, and then
6673give it a new definition, @value{GDBN} finds the definition (or lack
6674thereof) in force at each point:
6675
6676@smallexample
f7dc1244 6677(@value{GDBP}) next
e2e0bcd1
JB
6678Hello, world!
667912 printf ("We're so creative.\n");
f7dc1244 6680(@value{GDBP}) info macro N
e2e0bcd1
JB
6681The symbol `N' has no definition as a C/C++ preprocessor macro
6682at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 6683(@value{GDBP}) next
e2e0bcd1
JB
6684We're so creative.
668514 printf ("Goodbye, world!\n");
f7dc1244 6686(@value{GDBP}) info macro N
e2e0bcd1
JB
6687Defined at /home/jimb/gdb/macros/play/sample.c:13
6688#define N 1729
f7dc1244 6689(@value{GDBP}) macro expand N Q M
e2e0bcd1 6690expands to: 1729 < 42
f7dc1244 6691(@value{GDBP}) print N Q M
e2e0bcd1 6692$2 = 0
f7dc1244 6693(@value{GDBP})
e2e0bcd1
JB
6694@end smallexample
6695
6696
b37052ae
EZ
6697@node Tracepoints
6698@chapter Tracepoints
6699@c This chapter is based on the documentation written by Michael
6700@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6701
6702@cindex tracepoints
6703In some applications, it is not feasible for the debugger to interrupt
6704the program's execution long enough for the developer to learn
6705anything helpful about its behavior. If the program's correctness
6706depends on its real-time behavior, delays introduced by a debugger
6707might cause the program to change its behavior drastically, or perhaps
6708fail, even when the code itself is correct. It is useful to be able
6709to observe the program's behavior without interrupting it.
6710
6711Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6712specify locations in the program, called @dfn{tracepoints}, and
6713arbitrary expressions to evaluate when those tracepoints are reached.
6714Later, using the @code{tfind} command, you can examine the values
6715those expressions had when the program hit the tracepoints. The
6716expressions may also denote objects in memory---structures or arrays,
6717for example---whose values @value{GDBN} should record; while visiting
6718a particular tracepoint, you may inspect those objects as if they were
6719in memory at that moment. However, because @value{GDBN} records these
6720values without interacting with you, it can do so quickly and
6721unobtrusively, hopefully not disturbing the program's behavior.
6722
6723The tracepoint facility is currently available only for remote
2c0069bb
EZ
6724targets. @xref{Targets}. In addition, your remote target must know how
6725to collect trace data. This functionality is implemented in the remote
6726stub; however, none of the stubs distributed with @value{GDBN} support
6727tracepoints as of this writing.
b37052ae
EZ
6728
6729This chapter describes the tracepoint commands and features.
6730
6731@menu
b383017d
RM
6732* Set Tracepoints::
6733* Analyze Collected Data::
6734* Tracepoint Variables::
b37052ae
EZ
6735@end menu
6736
6737@node Set Tracepoints
6738@section Commands to Set Tracepoints
6739
6740Before running such a @dfn{trace experiment}, an arbitrary number of
6741tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6742tracepoint has a number assigned to it by @value{GDBN}. Like with
6743breakpoints, tracepoint numbers are successive integers starting from
6744one. Many of the commands associated with tracepoints take the
6745tracepoint number as their argument, to identify which tracepoint to
6746work on.
6747
6748For each tracepoint, you can specify, in advance, some arbitrary set
6749of data that you want the target to collect in the trace buffer when
6750it hits that tracepoint. The collected data can include registers,
6751local variables, or global data. Later, you can use @value{GDBN}
6752commands to examine the values these data had at the time the
6753tracepoint was hit.
6754
6755This section describes commands to set tracepoints and associated
6756conditions and actions.
6757
6758@menu
b383017d
RM
6759* Create and Delete Tracepoints::
6760* Enable and Disable Tracepoints::
6761* Tracepoint Passcounts::
6762* Tracepoint Actions::
6763* Listing Tracepoints::
6764* Starting and Stopping Trace Experiment::
b37052ae
EZ
6765@end menu
6766
6767@node Create and Delete Tracepoints
6768@subsection Create and Delete Tracepoints
6769
6770@table @code
6771@cindex set tracepoint
6772@kindex trace
6773@item trace
6774The @code{trace} command is very similar to the @code{break} command.
6775Its argument can be a source line, a function name, or an address in
6776the target program. @xref{Set Breaks}. The @code{trace} command
6777defines a tracepoint, which is a point in the target program where the
6778debugger will briefly stop, collect some data, and then allow the
6779program to continue. Setting a tracepoint or changing its commands
6780doesn't take effect until the next @code{tstart} command; thus, you
6781cannot change the tracepoint attributes once a trace experiment is
6782running.
6783
6784Here are some examples of using the @code{trace} command:
6785
6786@smallexample
6787(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6788
6789(@value{GDBP}) @b{trace +2} // 2 lines forward
6790
6791(@value{GDBP}) @b{trace my_function} // first source line of function
6792
6793(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6794
6795(@value{GDBP}) @b{trace *0x2117c4} // an address
6796@end smallexample
6797
6798@noindent
6799You can abbreviate @code{trace} as @code{tr}.
6800
6801@vindex $tpnum
6802@cindex last tracepoint number
6803@cindex recent tracepoint number
6804@cindex tracepoint number
6805The convenience variable @code{$tpnum} records the tracepoint number
6806of the most recently set tracepoint.
6807
6808@kindex delete tracepoint
6809@cindex tracepoint deletion
6810@item delete tracepoint @r{[}@var{num}@r{]}
6811Permanently delete one or more tracepoints. With no argument, the
6812default is to delete all tracepoints.
6813
6814Examples:
6815
6816@smallexample
6817(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6818
6819(@value{GDBP}) @b{delete trace} // remove all tracepoints
6820@end smallexample
6821
6822@noindent
6823You can abbreviate this command as @code{del tr}.
6824@end table
6825
6826@node Enable and Disable Tracepoints
6827@subsection Enable and Disable Tracepoints
6828
6829@table @code
6830@kindex disable tracepoint
6831@item disable tracepoint @r{[}@var{num}@r{]}
6832Disable tracepoint @var{num}, or all tracepoints if no argument
6833@var{num} is given. A disabled tracepoint will have no effect during
6834the next trace experiment, but it is not forgotten. You can re-enable
6835a disabled tracepoint using the @code{enable tracepoint} command.
6836
6837@kindex enable tracepoint
6838@item enable tracepoint @r{[}@var{num}@r{]}
6839Enable tracepoint @var{num}, or all tracepoints. The enabled
6840tracepoints will become effective the next time a trace experiment is
6841run.
6842@end table
6843
6844@node Tracepoint Passcounts
6845@subsection Tracepoint Passcounts
6846
6847@table @code
6848@kindex passcount
6849@cindex tracepoint pass count
6850@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6851Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6852automatically stop a trace experiment. If a tracepoint's passcount is
6853@var{n}, then the trace experiment will be automatically stopped on
6854the @var{n}'th time that tracepoint is hit. If the tracepoint number
6855@var{num} is not specified, the @code{passcount} command sets the
6856passcount of the most recently defined tracepoint. If no passcount is
6857given, the trace experiment will run until stopped explicitly by the
6858user.
6859
6860Examples:
6861
6862@smallexample
b383017d 6863(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 6864@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6865
6866(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6867@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6868(@value{GDBP}) @b{trace foo}
6869(@value{GDBP}) @b{pass 3}
6870(@value{GDBP}) @b{trace bar}
6871(@value{GDBP}) @b{pass 2}
6872(@value{GDBP}) @b{trace baz}
6873(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6874@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6875@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6876@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6877@end smallexample
6878@end table
6879
6880@node Tracepoint Actions
6881@subsection Tracepoint Action Lists
6882
6883@table @code
6884@kindex actions
6885@cindex tracepoint actions
6886@item actions @r{[}@var{num}@r{]}
6887This command will prompt for a list of actions to be taken when the
6888tracepoint is hit. If the tracepoint number @var{num} is not
6889specified, this command sets the actions for the one that was most
6890recently defined (so that you can define a tracepoint and then say
6891@code{actions} without bothering about its number). You specify the
6892actions themselves on the following lines, one action at a time, and
6893terminate the actions list with a line containing just @code{end}. So
6894far, the only defined actions are @code{collect} and
6895@code{while-stepping}.
6896
6897@cindex remove actions from a tracepoint
6898To remove all actions from a tracepoint, type @samp{actions @var{num}}
6899and follow it immediately with @samp{end}.
6900
6901@smallexample
6902(@value{GDBP}) @b{collect @var{data}} // collect some data
6903
6826cf00 6904(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6905
6826cf00 6906(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6907@end smallexample
6908
6909In the following example, the action list begins with @code{collect}
6910commands indicating the things to be collected when the tracepoint is
6911hit. Then, in order to single-step and collect additional data
6912following the tracepoint, a @code{while-stepping} command is used,
6913followed by the list of things to be collected while stepping. The
6914@code{while-stepping} command is terminated by its own separate
6915@code{end} command. Lastly, the action list is terminated by an
6916@code{end} command.
6917
6918@smallexample
6919(@value{GDBP}) @b{trace foo}
6920(@value{GDBP}) @b{actions}
6921Enter actions for tracepoint 1, one per line:
6922> collect bar,baz
6923> collect $regs
6924> while-stepping 12
6925 > collect $fp, $sp
6926 > end
6927end
6928@end smallexample
6929
6930@kindex collect @r{(tracepoints)}
6931@item collect @var{expr1}, @var{expr2}, @dots{}
6932Collect values of the given expressions when the tracepoint is hit.
6933This command accepts a comma-separated list of any valid expressions.
6934In addition to global, static, or local variables, the following
6935special arguments are supported:
6936
6937@table @code
6938@item $regs
6939collect all registers
6940
6941@item $args
6942collect all function arguments
6943
6944@item $locals
6945collect all local variables.
6946@end table
6947
6948You can give several consecutive @code{collect} commands, each one
6949with a single argument, or one @code{collect} command with several
6950arguments separated by commas: the effect is the same.
6951
f5c37c66
EZ
6952The command @code{info scope} (@pxref{Symbols, info scope}) is
6953particularly useful for figuring out what data to collect.
6954
b37052ae
EZ
6955@kindex while-stepping @r{(tracepoints)}
6956@item while-stepping @var{n}
6957Perform @var{n} single-step traces after the tracepoint, collecting
6958new data at each step. The @code{while-stepping} command is
6959followed by the list of what to collect while stepping (followed by
6960its own @code{end} command):
6961
6962@smallexample
6963> while-stepping 12
6964 > collect $regs, myglobal
6965 > end
6966>
6967@end smallexample
6968
6969@noindent
6970You may abbreviate @code{while-stepping} as @code{ws} or
6971@code{stepping}.
6972@end table
6973
6974@node Listing Tracepoints
6975@subsection Listing Tracepoints
6976
6977@table @code
6978@kindex info tracepoints
6979@cindex information about tracepoints
6980@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6981Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6982a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6983defined so far. For each tracepoint, the following information is
6984shown:
6985
6986@itemize @bullet
6987@item
6988its number
6989@item
6990whether it is enabled or disabled
6991@item
6992its address
6993@item
6994its passcount as given by the @code{passcount @var{n}} command
6995@item
6996its step count as given by the @code{while-stepping @var{n}} command
6997@item
6998where in the source files is the tracepoint set
6999@item
7000its action list as given by the @code{actions} command
7001@end itemize
7002
7003@smallexample
7004(@value{GDBP}) @b{info trace}
7005Num Enb Address PassC StepC What
70061 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
70072 y 0x0020dc64 0 0 in g_test at g_test.c:1375
70083 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7009(@value{GDBP})
7010@end smallexample
7011
7012@noindent
7013This command can be abbreviated @code{info tp}.
7014@end table
7015
7016@node Starting and Stopping Trace Experiment
7017@subsection Starting and Stopping Trace Experiment
7018
7019@table @code
7020@kindex tstart
7021@cindex start a new trace experiment
7022@cindex collected data discarded
7023@item tstart
7024This command takes no arguments. It starts the trace experiment, and
7025begins collecting data. This has the side effect of discarding all
7026the data collected in the trace buffer during the previous trace
7027experiment.
7028
7029@kindex tstop
7030@cindex stop a running trace experiment
7031@item tstop
7032This command takes no arguments. It ends the trace experiment, and
7033stops collecting data.
7034
7035@strong{Note:} a trace experiment and data collection may stop
7036automatically if any tracepoint's passcount is reached
7037(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7038
7039@kindex tstatus
7040@cindex status of trace data collection
7041@cindex trace experiment, status of
7042@item tstatus
7043This command displays the status of the current trace data
7044collection.
7045@end table
7046
7047Here is an example of the commands we described so far:
7048
7049@smallexample
7050(@value{GDBP}) @b{trace gdb_c_test}
7051(@value{GDBP}) @b{actions}
7052Enter actions for tracepoint #1, one per line.
7053> collect $regs,$locals,$args
7054> while-stepping 11
7055 > collect $regs
7056 > end
7057> end
7058(@value{GDBP}) @b{tstart}
7059 [time passes @dots{}]
7060(@value{GDBP}) @b{tstop}
7061@end smallexample
7062
7063
7064@node Analyze Collected Data
7065@section Using the collected data
7066
7067After the tracepoint experiment ends, you use @value{GDBN} commands
7068for examining the trace data. The basic idea is that each tracepoint
7069collects a trace @dfn{snapshot} every time it is hit and another
7070snapshot every time it single-steps. All these snapshots are
7071consecutively numbered from zero and go into a buffer, and you can
7072examine them later. The way you examine them is to @dfn{focus} on a
7073specific trace snapshot. When the remote stub is focused on a trace
7074snapshot, it will respond to all @value{GDBN} requests for memory and
7075registers by reading from the buffer which belongs to that snapshot,
7076rather than from @emph{real} memory or registers of the program being
7077debugged. This means that @strong{all} @value{GDBN} commands
7078(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7079behave as if we were currently debugging the program state as it was
7080when the tracepoint occurred. Any requests for data that are not in
7081the buffer will fail.
7082
7083@menu
7084* tfind:: How to select a trace snapshot
7085* tdump:: How to display all data for a snapshot
7086* save-tracepoints:: How to save tracepoints for a future run
7087@end menu
7088
7089@node tfind
7090@subsection @code{tfind @var{n}}
7091
7092@kindex tfind
7093@cindex select trace snapshot
7094@cindex find trace snapshot
7095The basic command for selecting a trace snapshot from the buffer is
7096@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7097counting from zero. If no argument @var{n} is given, the next
7098snapshot is selected.
7099
7100Here are the various forms of using the @code{tfind} command.
7101
7102@table @code
7103@item tfind start
7104Find the first snapshot in the buffer. This is a synonym for
7105@code{tfind 0} (since 0 is the number of the first snapshot).
7106
7107@item tfind none
7108Stop debugging trace snapshots, resume @emph{live} debugging.
7109
7110@item tfind end
7111Same as @samp{tfind none}.
7112
7113@item tfind
7114No argument means find the next trace snapshot.
7115
7116@item tfind -
7117Find the previous trace snapshot before the current one. This permits
7118retracing earlier steps.
7119
7120@item tfind tracepoint @var{num}
7121Find the next snapshot associated with tracepoint @var{num}. Search
7122proceeds forward from the last examined trace snapshot. If no
7123argument @var{num} is given, it means find the next snapshot collected
7124for the same tracepoint as the current snapshot.
7125
7126@item tfind pc @var{addr}
7127Find the next snapshot associated with the value @var{addr} of the
7128program counter. Search proceeds forward from the last examined trace
7129snapshot. If no argument @var{addr} is given, it means find the next
7130snapshot with the same value of PC as the current snapshot.
7131
7132@item tfind outside @var{addr1}, @var{addr2}
7133Find the next snapshot whose PC is outside the given range of
7134addresses.
7135
7136@item tfind range @var{addr1}, @var{addr2}
7137Find the next snapshot whose PC is between @var{addr1} and
7138@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7139
7140@item tfind line @r{[}@var{file}:@r{]}@var{n}
7141Find the next snapshot associated with the source line @var{n}. If
7142the optional argument @var{file} is given, refer to line @var{n} in
7143that source file. Search proceeds forward from the last examined
7144trace snapshot. If no argument @var{n} is given, it means find the
7145next line other than the one currently being examined; thus saying
7146@code{tfind line} repeatedly can appear to have the same effect as
7147stepping from line to line in a @emph{live} debugging session.
7148@end table
7149
7150The default arguments for the @code{tfind} commands are specifically
7151designed to make it easy to scan through the trace buffer. For
7152instance, @code{tfind} with no argument selects the next trace
7153snapshot, and @code{tfind -} with no argument selects the previous
7154trace snapshot. So, by giving one @code{tfind} command, and then
7155simply hitting @key{RET} repeatedly you can examine all the trace
7156snapshots in order. Or, by saying @code{tfind -} and then hitting
7157@key{RET} repeatedly you can examine the snapshots in reverse order.
7158The @code{tfind line} command with no argument selects the snapshot
7159for the next source line executed. The @code{tfind pc} command with
7160no argument selects the next snapshot with the same program counter
7161(PC) as the current frame. The @code{tfind tracepoint} command with
7162no argument selects the next trace snapshot collected by the same
7163tracepoint as the current one.
7164
7165In addition to letting you scan through the trace buffer manually,
7166these commands make it easy to construct @value{GDBN} scripts that
7167scan through the trace buffer and print out whatever collected data
7168you are interested in. Thus, if we want to examine the PC, FP, and SP
7169registers from each trace frame in the buffer, we can say this:
7170
7171@smallexample
7172(@value{GDBP}) @b{tfind start}
7173(@value{GDBP}) @b{while ($trace_frame != -1)}
7174> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7175 $trace_frame, $pc, $sp, $fp
7176> tfind
7177> end
7178
7179Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7180Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7181Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7182Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7183Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7184Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7185Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7186Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7187Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7188Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7189Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7190@end smallexample
7191
7192Or, if we want to examine the variable @code{X} at each source line in
7193the buffer:
7194
7195@smallexample
7196(@value{GDBP}) @b{tfind start}
7197(@value{GDBP}) @b{while ($trace_frame != -1)}
7198> printf "Frame %d, X == %d\n", $trace_frame, X
7199> tfind line
7200> end
7201
7202Frame 0, X = 1
7203Frame 7, X = 2
7204Frame 13, X = 255
7205@end smallexample
7206
7207@node tdump
7208@subsection @code{tdump}
7209@kindex tdump
7210@cindex dump all data collected at tracepoint
7211@cindex tracepoint data, display
7212
7213This command takes no arguments. It prints all the data collected at
7214the current trace snapshot.
7215
7216@smallexample
7217(@value{GDBP}) @b{trace 444}
7218(@value{GDBP}) @b{actions}
7219Enter actions for tracepoint #2, one per line:
7220> collect $regs, $locals, $args, gdb_long_test
7221> end
7222
7223(@value{GDBP}) @b{tstart}
7224
7225(@value{GDBP}) @b{tfind line 444}
7226#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7227at gdb_test.c:444
7228444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7229
7230(@value{GDBP}) @b{tdump}
7231Data collected at tracepoint 2, trace frame 1:
7232d0 0xc4aa0085 -995491707
7233d1 0x18 24
7234d2 0x80 128
7235d3 0x33 51
7236d4 0x71aea3d 119204413
7237d5 0x22 34
7238d6 0xe0 224
7239d7 0x380035 3670069
7240a0 0x19e24a 1696330
7241a1 0x3000668 50333288
7242a2 0x100 256
7243a3 0x322000 3284992
7244a4 0x3000698 50333336
7245a5 0x1ad3cc 1758156
7246fp 0x30bf3c 0x30bf3c
7247sp 0x30bf34 0x30bf34
7248ps 0x0 0
7249pc 0x20b2c8 0x20b2c8
7250fpcontrol 0x0 0
7251fpstatus 0x0 0
7252fpiaddr 0x0 0
7253p = 0x20e5b4 "gdb-test"
7254p1 = (void *) 0x11
7255p2 = (void *) 0x22
7256p3 = (void *) 0x33
7257p4 = (void *) 0x44
7258p5 = (void *) 0x55
7259p6 = (void *) 0x66
7260gdb_long_test = 17 '\021'
7261
7262(@value{GDBP})
7263@end smallexample
7264
7265@node save-tracepoints
7266@subsection @code{save-tracepoints @var{filename}}
7267@kindex save-tracepoints
7268@cindex save tracepoints for future sessions
7269
7270This command saves all current tracepoint definitions together with
7271their actions and passcounts, into a file @file{@var{filename}}
7272suitable for use in a later debugging session. To read the saved
7273tracepoint definitions, use the @code{source} command (@pxref{Command
7274Files}).
7275
7276@node Tracepoint Variables
7277@section Convenience Variables for Tracepoints
7278@cindex tracepoint variables
7279@cindex convenience variables for tracepoints
7280
7281@table @code
7282@vindex $trace_frame
7283@item (int) $trace_frame
7284The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7285snapshot is selected.
7286
7287@vindex $tracepoint
7288@item (int) $tracepoint
7289The tracepoint for the current trace snapshot.
7290
7291@vindex $trace_line
7292@item (int) $trace_line
7293The line number for the current trace snapshot.
7294
7295@vindex $trace_file
7296@item (char []) $trace_file
7297The source file for the current trace snapshot.
7298
7299@vindex $trace_func
7300@item (char []) $trace_func
7301The name of the function containing @code{$tracepoint}.
7302@end table
7303
7304Note: @code{$trace_file} is not suitable for use in @code{printf},
7305use @code{output} instead.
7306
7307Here's a simple example of using these convenience variables for
7308stepping through all the trace snapshots and printing some of their
7309data.
7310
7311@smallexample
7312(@value{GDBP}) @b{tfind start}
7313
7314(@value{GDBP}) @b{while $trace_frame != -1}
7315> output $trace_file
7316> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7317> tfind
7318> end
7319@end smallexample
7320
df0cd8c5
JB
7321@node Overlays
7322@chapter Debugging Programs That Use Overlays
7323@cindex overlays
7324
7325If your program is too large to fit completely in your target system's
7326memory, you can sometimes use @dfn{overlays} to work around this
7327problem. @value{GDBN} provides some support for debugging programs that
7328use overlays.
7329
7330@menu
7331* How Overlays Work:: A general explanation of overlays.
7332* Overlay Commands:: Managing overlays in @value{GDBN}.
7333* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7334 mapped by asking the inferior.
7335* Overlay Sample Program:: A sample program using overlays.
7336@end menu
7337
7338@node How Overlays Work
7339@section How Overlays Work
7340@cindex mapped overlays
7341@cindex unmapped overlays
7342@cindex load address, overlay's
7343@cindex mapped address
7344@cindex overlay area
7345
7346Suppose you have a computer whose instruction address space is only 64
7347kilobytes long, but which has much more memory which can be accessed by
7348other means: special instructions, segment registers, or memory
7349management hardware, for example. Suppose further that you want to
7350adapt a program which is larger than 64 kilobytes to run on this system.
7351
7352One solution is to identify modules of your program which are relatively
7353independent, and need not call each other directly; call these modules
7354@dfn{overlays}. Separate the overlays from the main program, and place
7355their machine code in the larger memory. Place your main program in
7356instruction memory, but leave at least enough space there to hold the
7357largest overlay as well.
7358
7359Now, to call a function located in an overlay, you must first copy that
7360overlay's machine code from the large memory into the space set aside
7361for it in the instruction memory, and then jump to its entry point
7362there.
7363
c928edc0
AC
7364@c NB: In the below the mapped area's size is greater or equal to the
7365@c size of all overlays. This is intentional to remind the developer
7366@c that overlays don't necessarily need to be the same size.
7367
474c8240 7368@smallexample
df0cd8c5 7369@group
c928edc0
AC
7370 Data Instruction Larger
7371Address Space Address Space Address Space
7372+-----------+ +-----------+ +-----------+
7373| | | | | |
7374+-----------+ +-----------+ +-----------+<-- overlay 1
7375| program | | main | .----| overlay 1 | load address
7376| variables | | program | | +-----------+
7377| and heap | | | | | |
7378+-----------+ | | | +-----------+<-- overlay 2
7379| | +-----------+ | | | load address
7380+-----------+ | | | .-| overlay 2 |
7381 | | | | | |
7382 mapped --->+-----------+ | | +-----------+
7383 address | | | | | |
7384 | overlay | <-' | | |
7385 | area | <---' +-----------+<-- overlay 3
7386 | | <---. | | load address
7387 +-----------+ `--| overlay 3 |
7388 | | | |
7389 +-----------+ | |
7390 +-----------+
7391 | |
7392 +-----------+
7393
7394 @anchor{A code overlay}A code overlay
df0cd8c5 7395@end group
474c8240 7396@end smallexample
df0cd8c5 7397
c928edc0
AC
7398The diagram (@pxref{A code overlay}) shows a system with separate data
7399and instruction address spaces. To map an overlay, the program copies
7400its code from the larger address space to the instruction address space.
7401Since the overlays shown here all use the same mapped address, only one
7402may be mapped at a time. For a system with a single address space for
7403data and instructions, the diagram would be similar, except that the
7404program variables and heap would share an address space with the main
7405program and the overlay area.
df0cd8c5
JB
7406
7407An overlay loaded into instruction memory and ready for use is called a
7408@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7409instruction memory. An overlay not present (or only partially present)
7410in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7411is its address in the larger memory. The mapped address is also called
7412the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7413called the @dfn{load memory address}, or @dfn{LMA}.
7414
7415Unfortunately, overlays are not a completely transparent way to adapt a
7416program to limited instruction memory. They introduce a new set of
7417global constraints you must keep in mind as you design your program:
7418
7419@itemize @bullet
7420
7421@item
7422Before calling or returning to a function in an overlay, your program
7423must make sure that overlay is actually mapped. Otherwise, the call or
7424return will transfer control to the right address, but in the wrong
7425overlay, and your program will probably crash.
7426
7427@item
7428If the process of mapping an overlay is expensive on your system, you
7429will need to choose your overlays carefully to minimize their effect on
7430your program's performance.
7431
7432@item
7433The executable file you load onto your system must contain each
7434overlay's instructions, appearing at the overlay's load address, not its
7435mapped address. However, each overlay's instructions must be relocated
7436and its symbols defined as if the overlay were at its mapped address.
7437You can use GNU linker scripts to specify different load and relocation
7438addresses for pieces of your program; see @ref{Overlay Description,,,
7439ld.info, Using ld: the GNU linker}.
7440
7441@item
7442The procedure for loading executable files onto your system must be able
7443to load their contents into the larger address space as well as the
7444instruction and data spaces.
7445
7446@end itemize
7447
7448The overlay system described above is rather simple, and could be
7449improved in many ways:
7450
7451@itemize @bullet
7452
7453@item
7454If your system has suitable bank switch registers or memory management
7455hardware, you could use those facilities to make an overlay's load area
7456contents simply appear at their mapped address in instruction space.
7457This would probably be faster than copying the overlay to its mapped
7458area in the usual way.
7459
7460@item
7461If your overlays are small enough, you could set aside more than one
7462overlay area, and have more than one overlay mapped at a time.
7463
7464@item
7465You can use overlays to manage data, as well as instructions. In
7466general, data overlays are even less transparent to your design than
7467code overlays: whereas code overlays only require care when you call or
7468return to functions, data overlays require care every time you access
7469the data. Also, if you change the contents of a data overlay, you
7470must copy its contents back out to its load address before you can copy a
7471different data overlay into the same mapped area.
7472
7473@end itemize
7474
7475
7476@node Overlay Commands
7477@section Overlay Commands
7478
7479To use @value{GDBN}'s overlay support, each overlay in your program must
7480correspond to a separate section of the executable file. The section's
7481virtual memory address and load memory address must be the overlay's
7482mapped and load addresses. Identifying overlays with sections allows
7483@value{GDBN} to determine the appropriate address of a function or
7484variable, depending on whether the overlay is mapped or not.
7485
7486@value{GDBN}'s overlay commands all start with the word @code{overlay};
7487you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7488
7489@table @code
7490@item overlay off
4644b6e3 7491@kindex overlay
df0cd8c5
JB
7492Disable @value{GDBN}'s overlay support. When overlay support is
7493disabled, @value{GDBN} assumes that all functions and variables are
7494always present at their mapped addresses. By default, @value{GDBN}'s
7495overlay support is disabled.
7496
7497@item overlay manual
df0cd8c5
JB
7498@cindex manual overlay debugging
7499Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7500relies on you to tell it which overlays are mapped, and which are not,
7501using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7502commands described below.
7503
7504@item overlay map-overlay @var{overlay}
7505@itemx overlay map @var{overlay}
df0cd8c5
JB
7506@cindex map an overlay
7507Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7508be the name of the object file section containing the overlay. When an
7509overlay is mapped, @value{GDBN} assumes it can find the overlay's
7510functions and variables at their mapped addresses. @value{GDBN} assumes
7511that any other overlays whose mapped ranges overlap that of
7512@var{overlay} are now unmapped.
7513
7514@item overlay unmap-overlay @var{overlay}
7515@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7516@cindex unmap an overlay
7517Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7518must be the name of the object file section containing the overlay.
7519When an overlay is unmapped, @value{GDBN} assumes it can find the
7520overlay's functions and variables at their load addresses.
7521
7522@item overlay auto
df0cd8c5
JB
7523Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7524consults a data structure the overlay manager maintains in the inferior
7525to see which overlays are mapped. For details, see @ref{Automatic
7526Overlay Debugging}.
7527
7528@item overlay load-target
7529@itemx overlay load
df0cd8c5
JB
7530@cindex reloading the overlay table
7531Re-read the overlay table from the inferior. Normally, @value{GDBN}
7532re-reads the table @value{GDBN} automatically each time the inferior
7533stops, so this command should only be necessary if you have changed the
7534overlay mapping yourself using @value{GDBN}. This command is only
7535useful when using automatic overlay debugging.
7536
7537@item overlay list-overlays
7538@itemx overlay list
7539@cindex listing mapped overlays
7540Display a list of the overlays currently mapped, along with their mapped
7541addresses, load addresses, and sizes.
7542
7543@end table
7544
7545Normally, when @value{GDBN} prints a code address, it includes the name
7546of the function the address falls in:
7547
474c8240 7548@smallexample
f7dc1244 7549(@value{GDBP}) print main
df0cd8c5 7550$3 = @{int ()@} 0x11a0 <main>
474c8240 7551@end smallexample
df0cd8c5
JB
7552@noindent
7553When overlay debugging is enabled, @value{GDBN} recognizes code in
7554unmapped overlays, and prints the names of unmapped functions with
7555asterisks around them. For example, if @code{foo} is a function in an
7556unmapped overlay, @value{GDBN} prints it this way:
7557
474c8240 7558@smallexample
f7dc1244 7559(@value{GDBP}) overlay list
df0cd8c5 7560No sections are mapped.
f7dc1244 7561(@value{GDBP}) print foo
df0cd8c5 7562$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7563@end smallexample
df0cd8c5
JB
7564@noindent
7565When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7566name normally:
7567
474c8240 7568@smallexample
f7dc1244 7569(@value{GDBP}) overlay list
b383017d 7570Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7571 mapped at 0x1016 - 0x104a
f7dc1244 7572(@value{GDBP}) print foo
df0cd8c5 7573$6 = @{int (int)@} 0x1016 <foo>
474c8240 7574@end smallexample
df0cd8c5
JB
7575
7576When overlay debugging is enabled, @value{GDBN} can find the correct
7577address for functions and variables in an overlay, whether or not the
7578overlay is mapped. This allows most @value{GDBN} commands, like
7579@code{break} and @code{disassemble}, to work normally, even on unmapped
7580code. However, @value{GDBN}'s breakpoint support has some limitations:
7581
7582@itemize @bullet
7583@item
7584@cindex breakpoints in overlays
7585@cindex overlays, setting breakpoints in
7586You can set breakpoints in functions in unmapped overlays, as long as
7587@value{GDBN} can write to the overlay at its load address.
7588@item
7589@value{GDBN} can not set hardware or simulator-based breakpoints in
7590unmapped overlays. However, if you set a breakpoint at the end of your
7591overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7592you are using manual overlay management), @value{GDBN} will re-set its
7593breakpoints properly.
7594@end itemize
7595
7596
7597@node Automatic Overlay Debugging
7598@section Automatic Overlay Debugging
7599@cindex automatic overlay debugging
7600
7601@value{GDBN} can automatically track which overlays are mapped and which
7602are not, given some simple co-operation from the overlay manager in the
7603inferior. If you enable automatic overlay debugging with the
7604@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7605looks in the inferior's memory for certain variables describing the
7606current state of the overlays.
7607
7608Here are the variables your overlay manager must define to support
7609@value{GDBN}'s automatic overlay debugging:
7610
7611@table @asis
7612
7613@item @code{_ovly_table}:
7614This variable must be an array of the following structures:
7615
474c8240 7616@smallexample
df0cd8c5
JB
7617struct
7618@{
7619 /* The overlay's mapped address. */
7620 unsigned long vma;
7621
7622 /* The size of the overlay, in bytes. */
7623 unsigned long size;
7624
7625 /* The overlay's load address. */
7626 unsigned long lma;
7627
7628 /* Non-zero if the overlay is currently mapped;
7629 zero otherwise. */
7630 unsigned long mapped;
7631@}
474c8240 7632@end smallexample
df0cd8c5
JB
7633
7634@item @code{_novlys}:
7635This variable must be a four-byte signed integer, holding the total
7636number of elements in @code{_ovly_table}.
7637
7638@end table
7639
7640To decide whether a particular overlay is mapped or not, @value{GDBN}
7641looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7642@code{lma} members equal the VMA and LMA of the overlay's section in the
7643executable file. When @value{GDBN} finds a matching entry, it consults
7644the entry's @code{mapped} member to determine whether the overlay is
7645currently mapped.
7646
81d46470 7647In addition, your overlay manager may define a function called
def71bfa 7648@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7649will silently set a breakpoint there. If the overlay manager then
7650calls this function whenever it has changed the overlay table, this
7651will enable @value{GDBN} to accurately keep track of which overlays
7652are in program memory, and update any breakpoints that may be set
b383017d 7653in overlays. This will allow breakpoints to work even if the
81d46470
MS
7654overlays are kept in ROM or other non-writable memory while they
7655are not being executed.
df0cd8c5
JB
7656
7657@node Overlay Sample Program
7658@section Overlay Sample Program
7659@cindex overlay example program
7660
7661When linking a program which uses overlays, you must place the overlays
7662at their load addresses, while relocating them to run at their mapped
7663addresses. To do this, you must write a linker script (@pxref{Overlay
7664Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7665since linker scripts are specific to a particular host system, target
7666architecture, and target memory layout, this manual cannot provide
7667portable sample code demonstrating @value{GDBN}'s overlay support.
7668
7669However, the @value{GDBN} source distribution does contain an overlaid
7670program, with linker scripts for a few systems, as part of its test
7671suite. The program consists of the following files from
7672@file{gdb/testsuite/gdb.base}:
7673
7674@table @file
7675@item overlays.c
7676The main program file.
7677@item ovlymgr.c
7678A simple overlay manager, used by @file{overlays.c}.
7679@item foo.c
7680@itemx bar.c
7681@itemx baz.c
7682@itemx grbx.c
7683Overlay modules, loaded and used by @file{overlays.c}.
7684@item d10v.ld
7685@itemx m32r.ld
7686Linker scripts for linking the test program on the @code{d10v-elf}
7687and @code{m32r-elf} targets.
7688@end table
7689
7690You can build the test program using the @code{d10v-elf} GCC
7691cross-compiler like this:
7692
474c8240 7693@smallexample
df0cd8c5
JB
7694$ d10v-elf-gcc -g -c overlays.c
7695$ d10v-elf-gcc -g -c ovlymgr.c
7696$ d10v-elf-gcc -g -c foo.c
7697$ d10v-elf-gcc -g -c bar.c
7698$ d10v-elf-gcc -g -c baz.c
7699$ d10v-elf-gcc -g -c grbx.c
7700$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7701 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7702@end smallexample
df0cd8c5
JB
7703
7704The build process is identical for any other architecture, except that
7705you must substitute the appropriate compiler and linker script for the
7706target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7707
7708
6d2ebf8b 7709@node Languages
c906108c
SS
7710@chapter Using @value{GDBN} with Different Languages
7711@cindex languages
7712
c906108c
SS
7713Although programming languages generally have common aspects, they are
7714rarely expressed in the same manner. For instance, in ANSI C,
7715dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7716Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7717represented (and displayed) differently. Hex numbers in C appear as
c906108c 7718@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7719
7720@cindex working language
7721Language-specific information is built into @value{GDBN} for some languages,
7722allowing you to express operations like the above in your program's
7723native language, and allowing @value{GDBN} to output values in a manner
7724consistent with the syntax of your program's native language. The
7725language you use to build expressions is called the @dfn{working
7726language}.
7727
7728@menu
7729* Setting:: Switching between source languages
7730* Show:: Displaying the language
c906108c 7731* Checks:: Type and range checks
c906108c 7732* Support:: Supported languages
4e562065 7733* Unsupported languages:: Unsupported languages
c906108c
SS
7734@end menu
7735
6d2ebf8b 7736@node Setting
c906108c
SS
7737@section Switching between source languages
7738
7739There are two ways to control the working language---either have @value{GDBN}
7740set it automatically, or select it manually yourself. You can use the
7741@code{set language} command for either purpose. On startup, @value{GDBN}
7742defaults to setting the language automatically. The working language is
7743used to determine how expressions you type are interpreted, how values
7744are printed, etc.
7745
7746In addition to the working language, every source file that
7747@value{GDBN} knows about has its own working language. For some object
7748file formats, the compiler might indicate which language a particular
7749source file is in. However, most of the time @value{GDBN} infers the
7750language from the name of the file. The language of a source file
b37052ae 7751controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7752show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7753set the language of a source file from within @value{GDBN}, but you can
7754set the language associated with a filename extension. @xref{Show, ,
7755Displaying the language}.
c906108c
SS
7756
7757This is most commonly a problem when you use a program, such
5d161b24 7758as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7759another language. In that case, make the
7760program use @code{#line} directives in its C output; that way
7761@value{GDBN} will know the correct language of the source code of the original
7762program, and will display that source code, not the generated C code.
7763
7764@menu
7765* Filenames:: Filename extensions and languages.
7766* Manually:: Setting the working language manually
7767* Automatically:: Having @value{GDBN} infer the source language
7768@end menu
7769
6d2ebf8b 7770@node Filenames
c906108c
SS
7771@subsection List of filename extensions and languages
7772
7773If a source file name ends in one of the following extensions, then
7774@value{GDBN} infers that its language is the one indicated.
7775
7776@table @file
e07c999f
PH
7777@item .ada
7778@itemx .ads
7779@itemx .adb
7780@itemx .a
7781Ada source file.
c906108c
SS
7782
7783@item .c
7784C source file
7785
7786@item .C
7787@itemx .cc
7788@itemx .cp
7789@itemx .cpp
7790@itemx .cxx
7791@itemx .c++
b37052ae 7792C@t{++} source file
c906108c 7793
b37303ee
AF
7794@item .m
7795Objective-C source file
7796
c906108c
SS
7797@item .f
7798@itemx .F
7799Fortran source file
7800
c906108c
SS
7801@item .mod
7802Modula-2 source file
c906108c
SS
7803
7804@item .s
7805@itemx .S
7806Assembler source file. This actually behaves almost like C, but
7807@value{GDBN} does not skip over function prologues when stepping.
7808@end table
7809
7810In addition, you may set the language associated with a filename
7811extension. @xref{Show, , Displaying the language}.
7812
6d2ebf8b 7813@node Manually
c906108c
SS
7814@subsection Setting the working language
7815
7816If you allow @value{GDBN} to set the language automatically,
7817expressions are interpreted the same way in your debugging session and
7818your program.
7819
7820@kindex set language
7821If you wish, you may set the language manually. To do this, issue the
7822command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7823a language, such as
c906108c 7824@code{c} or @code{modula-2}.
c906108c
SS
7825For a list of the supported languages, type @samp{set language}.
7826
c906108c
SS
7827Setting the language manually prevents @value{GDBN} from updating the working
7828language automatically. This can lead to confusion if you try
7829to debug a program when the working language is not the same as the
7830source language, when an expression is acceptable to both
7831languages---but means different things. For instance, if the current
7832source file were written in C, and @value{GDBN} was parsing Modula-2, a
7833command such as:
7834
474c8240 7835@smallexample
c906108c 7836print a = b + c
474c8240 7837@end smallexample
c906108c
SS
7838
7839@noindent
7840might not have the effect you intended. In C, this means to add
7841@code{b} and @code{c} and place the result in @code{a}. The result
7842printed would be the value of @code{a}. In Modula-2, this means to compare
7843@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7844
6d2ebf8b 7845@node Automatically
c906108c
SS
7846@subsection Having @value{GDBN} infer the source language
7847
7848To have @value{GDBN} set the working language automatically, use
7849@samp{set language local} or @samp{set language auto}. @value{GDBN}
7850then infers the working language. That is, when your program stops in a
7851frame (usually by encountering a breakpoint), @value{GDBN} sets the
7852working language to the language recorded for the function in that
7853frame. If the language for a frame is unknown (that is, if the function
7854or block corresponding to the frame was defined in a source file that
7855does not have a recognized extension), the current working language is
7856not changed, and @value{GDBN} issues a warning.
7857
7858This may not seem necessary for most programs, which are written
7859entirely in one source language. However, program modules and libraries
7860written in one source language can be used by a main program written in
7861a different source language. Using @samp{set language auto} in this
7862case frees you from having to set the working language manually.
7863
6d2ebf8b 7864@node Show
c906108c 7865@section Displaying the language
c906108c
SS
7866
7867The following commands help you find out which language is the
7868working language, and also what language source files were written in.
7869
7870@kindex show language
c906108c
SS
7871@table @code
7872@item show language
7873Display the current working language. This is the
7874language you can use with commands such as @code{print} to
7875build and compute expressions that may involve variables in your program.
7876
7877@item info frame
4644b6e3 7878@kindex info frame@r{, show the source language}
5d161b24 7879Display the source language for this frame. This language becomes the
c906108c 7880working language if you use an identifier from this frame.
5d161b24 7881@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7882information listed here.
7883
7884@item info source
4644b6e3 7885@kindex info source@r{, show the source language}
c906108c 7886Display the source language of this source file.
5d161b24 7887@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7888information listed here.
7889@end table
7890
7891In unusual circumstances, you may have source files with extensions
7892not in the standard list. You can then set the extension associated
7893with a language explicitly:
7894
7895@kindex set extension-language
7896@kindex info extensions
7897@table @code
7898@item set extension-language @var{.ext} @var{language}
7899Set source files with extension @var{.ext} to be assumed to be in
7900the source language @var{language}.
7901
7902@item info extensions
7903List all the filename extensions and the associated languages.
7904@end table
7905
6d2ebf8b 7906@node Checks
c906108c
SS
7907@section Type and range checking
7908
7909@quotation
7910@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7911checking are included, but they do not yet have any effect. This
7912section documents the intended facilities.
7913@end quotation
7914@c FIXME remove warning when type/range code added
7915
7916Some languages are designed to guard you against making seemingly common
7917errors through a series of compile- and run-time checks. These include
7918checking the type of arguments to functions and operators, and making
7919sure mathematical overflows are caught at run time. Checks such as
7920these help to ensure a program's correctness once it has been compiled
7921by eliminating type mismatches, and providing active checks for range
7922errors when your program is running.
7923
7924@value{GDBN} can check for conditions like the above if you wish.
7925Although @value{GDBN} does not check the statements in your program, it
7926can check expressions entered directly into @value{GDBN} for evaluation via
7927the @code{print} command, for example. As with the working language,
7928@value{GDBN} can also decide whether or not to check automatically based on
7929your program's source language. @xref{Support, ,Supported languages},
7930for the default settings of supported languages.
7931
7932@menu
7933* Type Checking:: An overview of type checking
7934* Range Checking:: An overview of range checking
7935@end menu
7936
7937@cindex type checking
7938@cindex checks, type
6d2ebf8b 7939@node Type Checking
c906108c
SS
7940@subsection An overview of type checking
7941
7942Some languages, such as Modula-2, are strongly typed, meaning that the
7943arguments to operators and functions have to be of the correct type,
7944otherwise an error occurs. These checks prevent type mismatch
7945errors from ever causing any run-time problems. For example,
7946
7947@smallexample
79481 + 2 @result{} 3
7949@exdent but
7950@error{} 1 + 2.3
7951@end smallexample
7952
7953The second example fails because the @code{CARDINAL} 1 is not
7954type-compatible with the @code{REAL} 2.3.
7955
5d161b24
DB
7956For the expressions you use in @value{GDBN} commands, you can tell the
7957@value{GDBN} type checker to skip checking;
7958to treat any mismatches as errors and abandon the expression;
7959or to only issue warnings when type mismatches occur,
c906108c
SS
7960but evaluate the expression anyway. When you choose the last of
7961these, @value{GDBN} evaluates expressions like the second example above, but
7962also issues a warning.
7963
5d161b24
DB
7964Even if you turn type checking off, there may be other reasons
7965related to type that prevent @value{GDBN} from evaluating an expression.
7966For instance, @value{GDBN} does not know how to add an @code{int} and
7967a @code{struct foo}. These particular type errors have nothing to do
7968with the language in use, and usually arise from expressions, such as
c906108c
SS
7969the one described above, which make little sense to evaluate anyway.
7970
7971Each language defines to what degree it is strict about type. For
7972instance, both Modula-2 and C require the arguments to arithmetical
7973operators to be numbers. In C, enumerated types and pointers can be
7974represented as numbers, so that they are valid arguments to mathematical
7975operators. @xref{Support, ,Supported languages}, for further
7976details on specific languages.
7977
7978@value{GDBN} provides some additional commands for controlling the type checker:
7979
c906108c
SS
7980@kindex set check type
7981@kindex show check type
7982@table @code
7983@item set check type auto
7984Set type checking on or off based on the current working language.
7985@xref{Support, ,Supported languages}, for the default settings for
7986each language.
7987
7988@item set check type on
7989@itemx set check type off
7990Set type checking on or off, overriding the default setting for the
7991current working language. Issue a warning if the setting does not
7992match the language default. If any type mismatches occur in
d4f3574e 7993evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7994message and aborts evaluation of the expression.
7995
7996@item set check type warn
7997Cause the type checker to issue warnings, but to always attempt to
7998evaluate the expression. Evaluating the expression may still
7999be impossible for other reasons. For example, @value{GDBN} cannot add
8000numbers and structures.
8001
8002@item show type
5d161b24 8003Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8004is setting it automatically.
8005@end table
8006
8007@cindex range checking
8008@cindex checks, range
6d2ebf8b 8009@node Range Checking
c906108c
SS
8010@subsection An overview of range checking
8011
8012In some languages (such as Modula-2), it is an error to exceed the
8013bounds of a type; this is enforced with run-time checks. Such range
8014checking is meant to ensure program correctness by making sure
8015computations do not overflow, or indices on an array element access do
8016not exceed the bounds of the array.
8017
8018For expressions you use in @value{GDBN} commands, you can tell
8019@value{GDBN} to treat range errors in one of three ways: ignore them,
8020always treat them as errors and abandon the expression, or issue
8021warnings but evaluate the expression anyway.
8022
8023A range error can result from numerical overflow, from exceeding an
8024array index bound, or when you type a constant that is not a member
8025of any type. Some languages, however, do not treat overflows as an
8026error. In many implementations of C, mathematical overflow causes the
8027result to ``wrap around'' to lower values---for example, if @var{m} is
8028the largest integer value, and @var{s} is the smallest, then
8029
474c8240 8030@smallexample
c906108c 8031@var{m} + 1 @result{} @var{s}
474c8240 8032@end smallexample
c906108c
SS
8033
8034This, too, is specific to individual languages, and in some cases
8035specific to individual compilers or machines. @xref{Support, ,
8036Supported languages}, for further details on specific languages.
8037
8038@value{GDBN} provides some additional commands for controlling the range checker:
8039
c906108c
SS
8040@kindex set check range
8041@kindex show check range
8042@table @code
8043@item set check range auto
8044Set range checking on or off based on the current working language.
8045@xref{Support, ,Supported languages}, for the default settings for
8046each language.
8047
8048@item set check range on
8049@itemx set check range off
8050Set range checking on or off, overriding the default setting for the
8051current working language. A warning is issued if the setting does not
c3f6f71d
JM
8052match the language default. If a range error occurs and range checking is on,
8053then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8054
8055@item set check range warn
8056Output messages when the @value{GDBN} range checker detects a range error,
8057but attempt to evaluate the expression anyway. Evaluating the
8058expression may still be impossible for other reasons, such as accessing
8059memory that the process does not own (a typical example from many Unix
8060systems).
8061
8062@item show range
8063Show the current setting of the range checker, and whether or not it is
8064being set automatically by @value{GDBN}.
8065@end table
c906108c 8066
6d2ebf8b 8067@node Support
c906108c 8068@section Supported languages
c906108c 8069
e07c999f 8070@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, Modula-2, and Ada.
cce74817 8071@c This is false ...
c906108c
SS
8072Some @value{GDBN} features may be used in expressions regardless of the
8073language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8074and the @samp{@{type@}addr} construct (@pxref{Expressions,
8075,Expressions}) can be used with the constructs of any supported
8076language.
8077
8078The following sections detail to what degree each source language is
8079supported by @value{GDBN}. These sections are not meant to be language
8080tutorials or references, but serve only as a reference guide to what the
8081@value{GDBN} expression parser accepts, and what input and output
8082formats should look like for different languages. There are many good
8083books written on each of these languages; please look to these for a
8084language reference or tutorial.
8085
c906108c 8086@menu
b37303ee 8087* C:: C and C@t{++}
b383017d 8088* Objective-C:: Objective-C
b37303ee 8089* Modula-2:: Modula-2
e07c999f 8090* Ada:: Ada
c906108c
SS
8091@end menu
8092
6d2ebf8b 8093@node C
b37052ae 8094@subsection C and C@t{++}
7a292a7a 8095
b37052ae
EZ
8096@cindex C and C@t{++}
8097@cindex expressions in C or C@t{++}
c906108c 8098
b37052ae 8099Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8100to both languages. Whenever this is the case, we discuss those languages
8101together.
8102
41afff9a
EZ
8103@cindex C@t{++}
8104@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8105@cindex @sc{gnu} C@t{++}
8106The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8107compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8108effectively, you must compile your C@t{++} programs with a supported
8109C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8110compiler (@code{aCC}).
8111
0179ffac
DC
8112For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8113format; if it doesn't work on your system, try the stabs+ debugging
8114format. You can select those formats explicitly with the @code{g++}
8115command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8116@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8117CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8118
c906108c 8119@menu
b37052ae
EZ
8120* C Operators:: C and C@t{++} operators
8121* C Constants:: C and C@t{++} constants
8122* C plus plus expressions:: C@t{++} expressions
8123* C Defaults:: Default settings for C and C@t{++}
8124* C Checks:: C and C@t{++} type and range checks
c906108c 8125* Debugging C:: @value{GDBN} and C
b37052ae 8126* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8127@end menu
c906108c 8128
6d2ebf8b 8129@node C Operators
b37052ae 8130@subsubsection C and C@t{++} operators
7a292a7a 8131
b37052ae 8132@cindex C and C@t{++} operators
c906108c
SS
8133
8134Operators must be defined on values of specific types. For instance,
8135@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8136often defined on groups of types.
c906108c 8137
b37052ae 8138For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8139
8140@itemize @bullet
53a5351d 8141
c906108c 8142@item
c906108c 8143@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8144specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8145
8146@item
d4f3574e
SS
8147@emph{Floating-point types} include @code{float}, @code{double}, and
8148@code{long double} (if supported by the target platform).
c906108c
SS
8149
8150@item
53a5351d 8151@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8152
8153@item
8154@emph{Scalar types} include all of the above.
53a5351d 8155
c906108c
SS
8156@end itemize
8157
8158@noindent
8159The following operators are supported. They are listed here
8160in order of increasing precedence:
8161
8162@table @code
8163@item ,
8164The comma or sequencing operator. Expressions in a comma-separated list
8165are evaluated from left to right, with the result of the entire
8166expression being the last expression evaluated.
8167
8168@item =
8169Assignment. The value of an assignment expression is the value
8170assigned. Defined on scalar types.
8171
8172@item @var{op}=
8173Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8174and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8175@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8176@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8177@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8178
8179@item ?:
8180The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8181of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8182integral type.
8183
8184@item ||
8185Logical @sc{or}. Defined on integral types.
8186
8187@item &&
8188Logical @sc{and}. Defined on integral types.
8189
8190@item |
8191Bitwise @sc{or}. Defined on integral types.
8192
8193@item ^
8194Bitwise exclusive-@sc{or}. Defined on integral types.
8195
8196@item &
8197Bitwise @sc{and}. Defined on integral types.
8198
8199@item ==@r{, }!=
8200Equality and inequality. Defined on scalar types. The value of these
8201expressions is 0 for false and non-zero for true.
8202
8203@item <@r{, }>@r{, }<=@r{, }>=
8204Less than, greater than, less than or equal, greater than or equal.
8205Defined on scalar types. The value of these expressions is 0 for false
8206and non-zero for true.
8207
8208@item <<@r{, }>>
8209left shift, and right shift. Defined on integral types.
8210
8211@item @@
8212The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8213
8214@item +@r{, }-
8215Addition and subtraction. Defined on integral types, floating-point types and
8216pointer types.
8217
8218@item *@r{, }/@r{, }%
8219Multiplication, division, and modulus. Multiplication and division are
8220defined on integral and floating-point types. Modulus is defined on
8221integral types.
8222
8223@item ++@r{, }--
8224Increment and decrement. When appearing before a variable, the
8225operation is performed before the variable is used in an expression;
8226when appearing after it, the variable's value is used before the
8227operation takes place.
8228
8229@item *
8230Pointer dereferencing. Defined on pointer types. Same precedence as
8231@code{++}.
8232
8233@item &
8234Address operator. Defined on variables. Same precedence as @code{++}.
8235
b37052ae
EZ
8236For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8237allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8238(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8239where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8240stored.
c906108c
SS
8241
8242@item -
8243Negative. Defined on integral and floating-point types. Same
8244precedence as @code{++}.
8245
8246@item !
8247Logical negation. Defined on integral types. Same precedence as
8248@code{++}.
8249
8250@item ~
8251Bitwise complement operator. Defined on integral types. Same precedence as
8252@code{++}.
8253
8254
8255@item .@r{, }->
8256Structure member, and pointer-to-structure member. For convenience,
8257@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8258pointer based on the stored type information.
8259Defined on @code{struct} and @code{union} data.
8260
c906108c
SS
8261@item .*@r{, }->*
8262Dereferences of pointers to members.
c906108c
SS
8263
8264@item []
8265Array indexing. @code{@var{a}[@var{i}]} is defined as
8266@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8267
8268@item ()
8269Function parameter list. Same precedence as @code{->}.
8270
c906108c 8271@item ::
b37052ae 8272C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8273and @code{class} types.
c906108c
SS
8274
8275@item ::
7a292a7a
SS
8276Doubled colons also represent the @value{GDBN} scope operator
8277(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8278above.
c906108c
SS
8279@end table
8280
c906108c
SS
8281If an operator is redefined in the user code, @value{GDBN} usually
8282attempts to invoke the redefined version instead of using the operator's
8283predefined meaning.
c906108c 8284
c906108c 8285@menu
5d161b24 8286* C Constants::
c906108c
SS
8287@end menu
8288
6d2ebf8b 8289@node C Constants
b37052ae 8290@subsubsection C and C@t{++} constants
c906108c 8291
b37052ae 8292@cindex C and C@t{++} constants
c906108c 8293
b37052ae 8294@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8295following ways:
c906108c
SS
8296
8297@itemize @bullet
8298@item
8299Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8300specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8301by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8302@samp{l}, specifying that the constant should be treated as a
8303@code{long} value.
8304
8305@item
8306Floating point constants are a sequence of digits, followed by a decimal
8307point, followed by a sequence of digits, and optionally followed by an
8308exponent. An exponent is of the form:
8309@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8310sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8311A floating-point constant may also end with a letter @samp{f} or
8312@samp{F}, specifying that the constant should be treated as being of
8313the @code{float} (as opposed to the default @code{double}) type; or with
8314a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8315constant.
c906108c
SS
8316
8317@item
8318Enumerated constants consist of enumerated identifiers, or their
8319integral equivalents.
8320
8321@item
8322Character constants are a single character surrounded by single quotes
8323(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8324(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8325be represented by a letter or by @dfn{escape sequences}, which are of
8326the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8327of the character's ordinal value; or of the form @samp{\@var{x}}, where
8328@samp{@var{x}} is a predefined special character---for example,
8329@samp{\n} for newline.
8330
8331@item
96a2c332
SS
8332String constants are a sequence of character constants surrounded by
8333double quotes (@code{"}). Any valid character constant (as described
8334above) may appear. Double quotes within the string must be preceded by
8335a backslash, so for instance @samp{"a\"b'c"} is a string of five
8336characters.
c906108c
SS
8337
8338@item
8339Pointer constants are an integral value. You can also write pointers
8340to constants using the C operator @samp{&}.
8341
8342@item
8343Array constants are comma-separated lists surrounded by braces @samp{@{}
8344and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8345integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8346and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8347@end itemize
8348
c906108c 8349@menu
5d161b24
DB
8350* C plus plus expressions::
8351* C Defaults::
8352* C Checks::
c906108c 8353
5d161b24 8354* Debugging C::
c906108c
SS
8355@end menu
8356
6d2ebf8b 8357@node C plus plus expressions
b37052ae
EZ
8358@subsubsection C@t{++} expressions
8359
8360@cindex expressions in C@t{++}
8361@value{GDBN} expression handling can interpret most C@t{++} expressions.
8362
0179ffac
DC
8363@cindex debugging C@t{++} programs
8364@cindex C@t{++} compilers
8365@cindex debug formats and C@t{++}
8366@cindex @value{NGCC} and C@t{++}
c906108c 8367@quotation
b37052ae 8368@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8369proper compiler and the proper debug format. Currently, @value{GDBN}
8370works best when debugging C@t{++} code that is compiled with
8371@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8372@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8373stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8374stabs+ as their default debug format, so you usually don't need to
8375specify a debug format explicitly. Other compilers and/or debug formats
8376are likely to work badly or not at all when using @value{GDBN} to debug
8377C@t{++} code.
c906108c 8378@end quotation
c906108c
SS
8379
8380@enumerate
8381
8382@cindex member functions
8383@item
8384Member function calls are allowed; you can use expressions like
8385
474c8240 8386@smallexample
c906108c 8387count = aml->GetOriginal(x, y)
474c8240 8388@end smallexample
c906108c 8389
41afff9a 8390@vindex this@r{, inside C@t{++} member functions}
b37052ae 8391@cindex namespace in C@t{++}
c906108c
SS
8392@item
8393While a member function is active (in the selected stack frame), your
8394expressions have the same namespace available as the member function;
8395that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8396pointer @code{this} following the same rules as C@t{++}.
c906108c 8397
c906108c 8398@cindex call overloaded functions
d4f3574e 8399@cindex overloaded functions, calling
b37052ae 8400@cindex type conversions in C@t{++}
c906108c
SS
8401@item
8402You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8403call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8404perform overload resolution involving user-defined type conversions,
8405calls to constructors, or instantiations of templates that do not exist
8406in the program. It also cannot handle ellipsis argument lists or
8407default arguments.
8408
8409It does perform integral conversions and promotions, floating-point
8410promotions, arithmetic conversions, pointer conversions, conversions of
8411class objects to base classes, and standard conversions such as those of
8412functions or arrays to pointers; it requires an exact match on the
8413number of function arguments.
8414
8415Overload resolution is always performed, unless you have specified
8416@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8417,@value{GDBN} features for C@t{++}}.
c906108c 8418
d4f3574e 8419You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8420explicit function signature to call an overloaded function, as in
8421@smallexample
8422p 'foo(char,int)'('x', 13)
8423@end smallexample
d4f3574e 8424
c906108c 8425The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8426see @ref{Completion, ,Command completion}.
c906108c 8427
c906108c
SS
8428@cindex reference declarations
8429@item
b37052ae
EZ
8430@value{GDBN} understands variables declared as C@t{++} references; you can use
8431them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8432dereferenced.
8433
8434In the parameter list shown when @value{GDBN} displays a frame, the values of
8435reference variables are not displayed (unlike other variables); this
8436avoids clutter, since references are often used for large structures.
8437The @emph{address} of a reference variable is always shown, unless
8438you have specified @samp{set print address off}.
8439
8440@item
b37052ae 8441@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8442expressions can use it just as expressions in your program do. Since
8443one scope may be defined in another, you can use @code{::} repeatedly if
8444necessary, for example in an expression like
8445@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8446resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8447debugging (@pxref{Variables, ,Program variables}).
8448@end enumerate
8449
b37052ae 8450In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8451calling virtual functions correctly, printing out virtual bases of
8452objects, calling functions in a base subobject, casting objects, and
8453invoking user-defined operators.
c906108c 8454
6d2ebf8b 8455@node C Defaults
b37052ae 8456@subsubsection C and C@t{++} defaults
7a292a7a 8457
b37052ae 8458@cindex C and C@t{++} defaults
c906108c 8459
c906108c
SS
8460If you allow @value{GDBN} to set type and range checking automatically, they
8461both default to @code{off} whenever the working language changes to
b37052ae 8462C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8463selects the working language.
c906108c
SS
8464
8465If you allow @value{GDBN} to set the language automatically, it
8466recognizes source files whose names end with @file{.c}, @file{.C}, or
8467@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8468these files, it sets the working language to C or C@t{++}.
c906108c
SS
8469@xref{Automatically, ,Having @value{GDBN} infer the source language},
8470for further details.
8471
c906108c
SS
8472@c Type checking is (a) primarily motivated by Modula-2, and (b)
8473@c unimplemented. If (b) changes, it might make sense to let this node
8474@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8475
6d2ebf8b 8476@node C Checks
b37052ae 8477@subsubsection C and C@t{++} type and range checks
7a292a7a 8478
b37052ae 8479@cindex C and C@t{++} checks
c906108c 8480
b37052ae 8481By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8482is not used. However, if you turn type checking on, @value{GDBN}
8483considers two variables type equivalent if:
8484
8485@itemize @bullet
8486@item
8487The two variables are structured and have the same structure, union, or
8488enumerated tag.
8489
8490@item
8491The two variables have the same type name, or types that have been
8492declared equivalent through @code{typedef}.
8493
8494@ignore
8495@c leaving this out because neither J Gilmore nor R Pesch understand it.
8496@c FIXME--beers?
8497@item
8498The two @code{struct}, @code{union}, or @code{enum} variables are
8499declared in the same declaration. (Note: this may not be true for all C
8500compilers.)
8501@end ignore
8502@end itemize
8503
8504Range checking, if turned on, is done on mathematical operations. Array
8505indices are not checked, since they are often used to index a pointer
8506that is not itself an array.
c906108c 8507
6d2ebf8b 8508@node Debugging C
c906108c 8509@subsubsection @value{GDBN} and C
c906108c
SS
8510
8511The @code{set print union} and @code{show print union} commands apply to
8512the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8513inside a @code{struct} or @code{class} is also printed. Otherwise, it
8514appears as @samp{@{...@}}.
c906108c
SS
8515
8516The @code{@@} operator aids in the debugging of dynamic arrays, formed
8517with pointers and a memory allocation function. @xref{Expressions,
8518,Expressions}.
8519
c906108c 8520@menu
5d161b24 8521* Debugging C plus plus::
c906108c
SS
8522@end menu
8523
6d2ebf8b 8524@node Debugging C plus plus
b37052ae 8525@subsubsection @value{GDBN} features for C@t{++}
c906108c 8526
b37052ae 8527@cindex commands for C@t{++}
7a292a7a 8528
b37052ae
EZ
8529Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8530designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8531
8532@table @code
8533@cindex break in overloaded functions
8534@item @r{breakpoint menus}
8535When you want a breakpoint in a function whose name is overloaded,
8536@value{GDBN} breakpoint menus help you specify which function definition
8537you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8538
b37052ae 8539@cindex overloading in C@t{++}
c906108c
SS
8540@item rbreak @var{regex}
8541Setting breakpoints using regular expressions is helpful for setting
8542breakpoints on overloaded functions that are not members of any special
8543classes.
8544@xref{Set Breaks, ,Setting breakpoints}.
8545
b37052ae 8546@cindex C@t{++} exception handling
c906108c
SS
8547@item catch throw
8548@itemx catch catch
b37052ae 8549Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8550Catchpoints, , Setting catchpoints}.
8551
8552@cindex inheritance
8553@item ptype @var{typename}
8554Print inheritance relationships as well as other information for type
8555@var{typename}.
8556@xref{Symbols, ,Examining the Symbol Table}.
8557
b37052ae 8558@cindex C@t{++} symbol display
c906108c
SS
8559@item set print demangle
8560@itemx show print demangle
8561@itemx set print asm-demangle
8562@itemx show print asm-demangle
b37052ae
EZ
8563Control whether C@t{++} symbols display in their source form, both when
8564displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8565@xref{Print Settings, ,Print settings}.
8566
8567@item set print object
8568@itemx show print object
8569Choose whether to print derived (actual) or declared types of objects.
8570@xref{Print Settings, ,Print settings}.
8571
8572@item set print vtbl
8573@itemx show print vtbl
8574Control the format for printing virtual function tables.
8575@xref{Print Settings, ,Print settings}.
c906108c 8576(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8577ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8578
8579@kindex set overload-resolution
d4f3574e 8580@cindex overloaded functions, overload resolution
c906108c 8581@item set overload-resolution on
b37052ae 8582Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8583is on. For overloaded functions, @value{GDBN} evaluates the arguments
8584and searches for a function whose signature matches the argument types,
b37052ae 8585using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8586expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8587message.
8588
8589@item set overload-resolution off
b37052ae 8590Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8591overloaded functions that are not class member functions, @value{GDBN}
8592chooses the first function of the specified name that it finds in the
8593symbol table, whether or not its arguments are of the correct type. For
8594overloaded functions that are class member functions, @value{GDBN}
8595searches for a function whose signature @emph{exactly} matches the
8596argument types.
c906108c
SS
8597
8598@item @r{Overloaded symbol names}
8599You can specify a particular definition of an overloaded symbol, using
b37052ae 8600the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8601@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8602also use the @value{GDBN} command-line word completion facilities to list the
8603available choices, or to finish the type list for you.
8604@xref{Completion,, Command completion}, for details on how to do this.
8605@end table
c906108c 8606
b37303ee
AF
8607@node Objective-C
8608@subsection Objective-C
8609
8610@cindex Objective-C
8611This section provides information about some commands and command
8612options that are useful for debugging Objective-C code.
8613
8614@menu
b383017d
RM
8615* Method Names in Commands::
8616* The Print Command with Objective-C::
b37303ee
AF
8617@end menu
8618
8619@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8620@subsubsection Method Names in Commands
8621
8622The following commands have been extended to accept Objective-C method
8623names as line specifications:
8624
8625@kindex clear@r{, and Objective-C}
8626@kindex break@r{, and Objective-C}
8627@kindex info line@r{, and Objective-C}
8628@kindex jump@r{, and Objective-C}
8629@kindex list@r{, and Objective-C}
8630@itemize
8631@item @code{clear}
8632@item @code{break}
8633@item @code{info line}
8634@item @code{jump}
8635@item @code{list}
8636@end itemize
8637
8638A fully qualified Objective-C method name is specified as
8639
8640@smallexample
8641-[@var{Class} @var{methodName}]
8642@end smallexample
8643
c552b3bb
JM
8644where the minus sign is used to indicate an instance method and a
8645plus sign (not shown) is used to indicate a class method. The class
8646name @var{Class} and method name @var{methodName} are enclosed in
8647brackets, similar to the way messages are specified in Objective-C
8648source code. For example, to set a breakpoint at the @code{create}
8649instance method of class @code{Fruit} in the program currently being
8650debugged, enter:
b37303ee
AF
8651
8652@smallexample
8653break -[Fruit create]
8654@end smallexample
8655
8656To list ten program lines around the @code{initialize} class method,
8657enter:
8658
8659@smallexample
8660list +[NSText initialize]
8661@end smallexample
8662
c552b3bb
JM
8663In the current version of @value{GDBN}, the plus or minus sign is
8664required. In future versions of @value{GDBN}, the plus or minus
8665sign will be optional, but you can use it to narrow the search. It
8666is also possible to specify just a method name:
b37303ee
AF
8667
8668@smallexample
8669break create
8670@end smallexample
8671
8672You must specify the complete method name, including any colons. If
8673your program's source files contain more than one @code{create} method,
8674you'll be presented with a numbered list of classes that implement that
8675method. Indicate your choice by number, or type @samp{0} to exit if
8676none apply.
8677
8678As another example, to clear a breakpoint established at the
8679@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8680
8681@smallexample
8682clear -[NSWindow makeKeyAndOrderFront:]
8683@end smallexample
8684
8685@node The Print Command with Objective-C
8686@subsubsection The Print Command With Objective-C
c552b3bb
JM
8687@kindex print-object
8688@kindex po @r{(@code{print-object})}
b37303ee 8689
c552b3bb 8690The print command has also been extended to accept methods. For example:
b37303ee
AF
8691
8692@smallexample
c552b3bb 8693print -[@var{object} hash]
b37303ee
AF
8694@end smallexample
8695
8696@cindex print an Objective-C object description
c552b3bb
JM
8697@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8698@noindent
8699will tell @value{GDBN} to send the @code{hash} message to @var{object}
8700and print the result. Also, an additional command has been added,
8701@code{print-object} or @code{po} for short, which is meant to print
8702the description of an object. However, this command may only work
8703with certain Objective-C libraries that have a particular hook
8704function, @code{_NSPrintForDebugger}, defined.
b37303ee 8705
e07c999f 8706@node Modula-2, Ada, Objective-C, Support
c906108c 8707@subsection Modula-2
7a292a7a 8708
d4f3574e 8709@cindex Modula-2, @value{GDBN} support
c906108c
SS
8710
8711The extensions made to @value{GDBN} to support Modula-2 only support
8712output from the @sc{gnu} Modula-2 compiler (which is currently being
8713developed). Other Modula-2 compilers are not currently supported, and
8714attempting to debug executables produced by them is most likely
8715to give an error as @value{GDBN} reads in the executable's symbol
8716table.
8717
8718@cindex expressions in Modula-2
8719@menu
8720* M2 Operators:: Built-in operators
8721* Built-In Func/Proc:: Built-in functions and procedures
8722* M2 Constants:: Modula-2 constants
8723* M2 Defaults:: Default settings for Modula-2
8724* Deviations:: Deviations from standard Modula-2
8725* M2 Checks:: Modula-2 type and range checks
8726* M2 Scope:: The scope operators @code{::} and @code{.}
8727* GDB/M2:: @value{GDBN} and Modula-2
8728@end menu
8729
6d2ebf8b 8730@node M2 Operators
c906108c
SS
8731@subsubsection Operators
8732@cindex Modula-2 operators
8733
8734Operators must be defined on values of specific types. For instance,
8735@code{+} is defined on numbers, but not on structures. Operators are
8736often defined on groups of types. For the purposes of Modula-2, the
8737following definitions hold:
8738
8739@itemize @bullet
8740
8741@item
8742@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8743their subranges.
8744
8745@item
8746@emph{Character types} consist of @code{CHAR} and its subranges.
8747
8748@item
8749@emph{Floating-point types} consist of @code{REAL}.
8750
8751@item
8752@emph{Pointer types} consist of anything declared as @code{POINTER TO
8753@var{type}}.
8754
8755@item
8756@emph{Scalar types} consist of all of the above.
8757
8758@item
8759@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8760
8761@item
8762@emph{Boolean types} consist of @code{BOOLEAN}.
8763@end itemize
8764
8765@noindent
8766The following operators are supported, and appear in order of
8767increasing precedence:
8768
8769@table @code
8770@item ,
8771Function argument or array index separator.
8772
8773@item :=
8774Assignment. The value of @var{var} @code{:=} @var{value} is
8775@var{value}.
8776
8777@item <@r{, }>
8778Less than, greater than on integral, floating-point, or enumerated
8779types.
8780
8781@item <=@r{, }>=
96a2c332 8782Less than or equal to, greater than or equal to
c906108c
SS
8783on integral, floating-point and enumerated types, or set inclusion on
8784set types. Same precedence as @code{<}.
8785
8786@item =@r{, }<>@r{, }#
8787Equality and two ways of expressing inequality, valid on scalar types.
8788Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8789available for inequality, since @code{#} conflicts with the script
8790comment character.
8791
8792@item IN
8793Set membership. Defined on set types and the types of their members.
8794Same precedence as @code{<}.
8795
8796@item OR
8797Boolean disjunction. Defined on boolean types.
8798
8799@item AND@r{, }&
d4f3574e 8800Boolean conjunction. Defined on boolean types.
c906108c
SS
8801
8802@item @@
8803The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8804
8805@item +@r{, }-
8806Addition and subtraction on integral and floating-point types, or union
8807and difference on set types.
8808
8809@item *
8810Multiplication on integral and floating-point types, or set intersection
8811on set types.
8812
8813@item /
8814Division on floating-point types, or symmetric set difference on set
8815types. Same precedence as @code{*}.
8816
8817@item DIV@r{, }MOD
8818Integer division and remainder. Defined on integral types. Same
8819precedence as @code{*}.
8820
8821@item -
8822Negative. Defined on @code{INTEGER} and @code{REAL} data.
8823
8824@item ^
8825Pointer dereferencing. Defined on pointer types.
8826
8827@item NOT
8828Boolean negation. Defined on boolean types. Same precedence as
8829@code{^}.
8830
8831@item .
8832@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8833precedence as @code{^}.
8834
8835@item []
8836Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8837
8838@item ()
8839Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8840as @code{^}.
8841
8842@item ::@r{, }.
8843@value{GDBN} and Modula-2 scope operators.
8844@end table
8845
8846@quotation
8847@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8848treats the use of the operator @code{IN}, or the use of operators
8849@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8850@code{<=}, and @code{>=} on sets as an error.
8851@end quotation
8852
cb51c4e0 8853
6d2ebf8b 8854@node Built-In Func/Proc
c906108c 8855@subsubsection Built-in functions and procedures
cb51c4e0 8856@cindex Modula-2 built-ins
c906108c
SS
8857
8858Modula-2 also makes available several built-in procedures and functions.
8859In describing these, the following metavariables are used:
8860
8861@table @var
8862
8863@item a
8864represents an @code{ARRAY} variable.
8865
8866@item c
8867represents a @code{CHAR} constant or variable.
8868
8869@item i
8870represents a variable or constant of integral type.
8871
8872@item m
8873represents an identifier that belongs to a set. Generally used in the
8874same function with the metavariable @var{s}. The type of @var{s} should
8875be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8876
8877@item n
8878represents a variable or constant of integral or floating-point type.
8879
8880@item r
8881represents a variable or constant of floating-point type.
8882
8883@item t
8884represents a type.
8885
8886@item v
8887represents a variable.
8888
8889@item x
8890represents a variable or constant of one of many types. See the
8891explanation of the function for details.
8892@end table
8893
8894All Modula-2 built-in procedures also return a result, described below.
8895
8896@table @code
8897@item ABS(@var{n})
8898Returns the absolute value of @var{n}.
8899
8900@item CAP(@var{c})
8901If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8902equivalent, otherwise it returns its argument.
c906108c
SS
8903
8904@item CHR(@var{i})
8905Returns the character whose ordinal value is @var{i}.
8906
8907@item DEC(@var{v})
c3f6f71d 8908Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8909
8910@item DEC(@var{v},@var{i})
8911Decrements the value in the variable @var{v} by @var{i}. Returns the
8912new value.
8913
8914@item EXCL(@var{m},@var{s})
8915Removes the element @var{m} from the set @var{s}. Returns the new
8916set.
8917
8918@item FLOAT(@var{i})
8919Returns the floating point equivalent of the integer @var{i}.
8920
8921@item HIGH(@var{a})
8922Returns the index of the last member of @var{a}.
8923
8924@item INC(@var{v})
c3f6f71d 8925Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8926
8927@item INC(@var{v},@var{i})
8928Increments the value in the variable @var{v} by @var{i}. Returns the
8929new value.
8930
8931@item INCL(@var{m},@var{s})
8932Adds the element @var{m} to the set @var{s} if it is not already
8933there. Returns the new set.
8934
8935@item MAX(@var{t})
8936Returns the maximum value of the type @var{t}.
8937
8938@item MIN(@var{t})
8939Returns the minimum value of the type @var{t}.
8940
8941@item ODD(@var{i})
8942Returns boolean TRUE if @var{i} is an odd number.
8943
8944@item ORD(@var{x})
8945Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8946value of a character is its @sc{ascii} value (on machines supporting the
8947@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8948integral, character and enumerated types.
8949
8950@item SIZE(@var{x})
8951Returns the size of its argument. @var{x} can be a variable or a type.
8952
8953@item TRUNC(@var{r})
8954Returns the integral part of @var{r}.
8955
8956@item VAL(@var{t},@var{i})
8957Returns the member of the type @var{t} whose ordinal value is @var{i}.
8958@end table
8959
8960@quotation
8961@emph{Warning:} Sets and their operations are not yet supported, so
8962@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8963an error.
8964@end quotation
8965
8966@cindex Modula-2 constants
6d2ebf8b 8967@node M2 Constants
c906108c
SS
8968@subsubsection Constants
8969
8970@value{GDBN} allows you to express the constants of Modula-2 in the following
8971ways:
8972
8973@itemize @bullet
8974
8975@item
8976Integer constants are simply a sequence of digits. When used in an
8977expression, a constant is interpreted to be type-compatible with the
8978rest of the expression. Hexadecimal integers are specified by a
8979trailing @samp{H}, and octal integers by a trailing @samp{B}.
8980
8981@item
8982Floating point constants appear as a sequence of digits, followed by a
8983decimal point and another sequence of digits. An optional exponent can
8984then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8985@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8986digits of the floating point constant must be valid decimal (base 10)
8987digits.
8988
8989@item
8990Character constants consist of a single character enclosed by a pair of
8991like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8992also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8993followed by a @samp{C}.
8994
8995@item
8996String constants consist of a sequence of characters enclosed by a
8997pair of like quotes, either single (@code{'}) or double (@code{"}).
8998Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8999Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9000sequences.
9001
9002@item
9003Enumerated constants consist of an enumerated identifier.
9004
9005@item
9006Boolean constants consist of the identifiers @code{TRUE} and
9007@code{FALSE}.
9008
9009@item
9010Pointer constants consist of integral values only.
9011
9012@item
9013Set constants are not yet supported.
9014@end itemize
9015
6d2ebf8b 9016@node M2 Defaults
c906108c
SS
9017@subsubsection Modula-2 defaults
9018@cindex Modula-2 defaults
9019
9020If type and range checking are set automatically by @value{GDBN}, they
9021both default to @code{on} whenever the working language changes to
d4f3574e 9022Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9023selected the working language.
9024
9025If you allow @value{GDBN} to set the language automatically, then entering
9026code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9027working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9028the language automatically}, for further details.
9029
6d2ebf8b 9030@node Deviations
c906108c
SS
9031@subsubsection Deviations from standard Modula-2
9032@cindex Modula-2, deviations from
9033
9034A few changes have been made to make Modula-2 programs easier to debug.
9035This is done primarily via loosening its type strictness:
9036
9037@itemize @bullet
9038@item
9039Unlike in standard Modula-2, pointer constants can be formed by
9040integers. This allows you to modify pointer variables during
9041debugging. (In standard Modula-2, the actual address contained in a
9042pointer variable is hidden from you; it can only be modified
9043through direct assignment to another pointer variable or expression that
9044returned a pointer.)
9045
9046@item
9047C escape sequences can be used in strings and characters to represent
9048non-printable characters. @value{GDBN} prints out strings with these
9049escape sequences embedded. Single non-printable characters are
9050printed using the @samp{CHR(@var{nnn})} format.
9051
9052@item
9053The assignment operator (@code{:=}) returns the value of its right-hand
9054argument.
9055
9056@item
9057All built-in procedures both modify @emph{and} return their argument.
9058@end itemize
9059
6d2ebf8b 9060@node M2 Checks
c906108c
SS
9061@subsubsection Modula-2 type and range checks
9062@cindex Modula-2 checks
9063
9064@quotation
9065@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9066range checking.
9067@end quotation
9068@c FIXME remove warning when type/range checks added
9069
9070@value{GDBN} considers two Modula-2 variables type equivalent if:
9071
9072@itemize @bullet
9073@item
9074They are of types that have been declared equivalent via a @code{TYPE
9075@var{t1} = @var{t2}} statement
9076
9077@item
9078They have been declared on the same line. (Note: This is true of the
9079@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9080@end itemize
9081
9082As long as type checking is enabled, any attempt to combine variables
9083whose types are not equivalent is an error.
9084
9085Range checking is done on all mathematical operations, assignment, array
9086index bounds, and all built-in functions and procedures.
9087
6d2ebf8b 9088@node M2 Scope
c906108c
SS
9089@subsubsection The scope operators @code{::} and @code{.}
9090@cindex scope
41afff9a 9091@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9092@cindex colon, doubled as scope operator
9093@ifinfo
41afff9a 9094@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9095@c Info cannot handle :: but TeX can.
9096@end ifinfo
9097@iftex
41afff9a 9098@vindex ::@r{, in Modula-2}
c906108c
SS
9099@end iftex
9100
9101There are a few subtle differences between the Modula-2 scope operator
9102(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9103similar syntax:
9104
474c8240 9105@smallexample
c906108c
SS
9106
9107@var{module} . @var{id}
9108@var{scope} :: @var{id}
474c8240 9109@end smallexample
c906108c
SS
9110
9111@noindent
9112where @var{scope} is the name of a module or a procedure,
9113@var{module} the name of a module, and @var{id} is any declared
9114identifier within your program, except another module.
9115
9116Using the @code{::} operator makes @value{GDBN} search the scope
9117specified by @var{scope} for the identifier @var{id}. If it is not
9118found in the specified scope, then @value{GDBN} searches all scopes
9119enclosing the one specified by @var{scope}.
9120
9121Using the @code{.} operator makes @value{GDBN} search the current scope for
9122the identifier specified by @var{id} that was imported from the
9123definition module specified by @var{module}. With this operator, it is
9124an error if the identifier @var{id} was not imported from definition
9125module @var{module}, or if @var{id} is not an identifier in
9126@var{module}.
9127
6d2ebf8b 9128@node GDB/M2
c906108c
SS
9129@subsubsection @value{GDBN} and Modula-2
9130
9131Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9132Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9133specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9134@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9135apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9136analogue in Modula-2.
9137
9138The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9139with any language, is not useful with Modula-2. Its
c906108c 9140intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9141created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9142address can be specified by an integral constant, the construct
d4f3574e 9143@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9144
9145@cindex @code{#} in Modula-2
9146In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9147interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9148
e07c999f
PH
9149@node Ada
9150@subsection Ada
9151@cindex Ada
9152
9153The extensions made to @value{GDBN} for Ada only support
9154output from the @sc{gnu} Ada (GNAT) compiler.
9155Other Ada compilers are not currently supported, and
9156attempting to debug executables produced by them is most likely
9157to be difficult.
9158
9159
9160@cindex expressions in Ada
9161@menu
9162* Ada Mode Intro:: General remarks on the Ada syntax
9163 and semantics supported by Ada mode
9164 in @value{GDBN}.
9165* Omissions from Ada:: Restrictions on the Ada expression syntax.
9166* Additions to Ada:: Extensions of the Ada expression syntax.
9167* Stopping Before Main Program:: Debugging the program during elaboration.
9168* Ada Glitches:: Known peculiarities of Ada mode.
9169@end menu
9170
9171@node Ada Mode Intro
9172@subsubsection Introduction
9173@cindex Ada mode, general
9174
9175The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9176syntax, with some extensions.
9177The philosophy behind the design of this subset is
9178
9179@itemize @bullet
9180@item
9181That @value{GDBN} should provide basic literals and access to operations for
9182arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9183leaving more sophisticated computations to subprograms written into the
9184program (which therefore may be called from @value{GDBN}).
9185
9186@item
9187That type safety and strict adherence to Ada language restrictions
9188are not particularly important to the @value{GDBN} user.
9189
9190@item
9191That brevity is important to the @value{GDBN} user.
9192@end itemize
9193
9194Thus, for brevity, the debugger acts as if there were
9195implicit @code{with} and @code{use} clauses in effect for all user-written
9196packages, making it unnecessary to fully qualify most names with
9197their packages, regardless of context. Where this causes ambiguity,
9198@value{GDBN} asks the user's intent.
9199
9200The debugger will start in Ada mode if it detects an Ada main program.
9201As for other languages, it will enter Ada mode when stopped in a program that
9202was translated from an Ada source file.
9203
9204While in Ada mode, you may use `@t{--}' for comments. This is useful
9205mostly for documenting command files. The standard @value{GDBN} comment
9206(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9207middle (to allow based literals).
9208
9209The debugger supports limited overloading. Given a subprogram call in which
9210the function symbol has multiple definitions, it will use the number of
9211actual parameters and some information about their types to attempt to narrow
9212the set of definitions. It also makes very limited use of context, preferring
9213procedures to functions in the context of the @code{call} command, and
9214functions to procedures elsewhere.
9215
9216@node Omissions from Ada
9217@subsubsection Omissions from Ada
9218@cindex Ada, omissions from
9219
9220Here are the notable omissions from the subset:
9221
9222@itemize @bullet
9223@item
9224Only a subset of the attributes are supported:
9225
9226@itemize @minus
9227@item
9228@t{'First}, @t{'Last}, and @t{'Length}
9229 on array objects (not on types and subtypes).
9230
9231@item
9232@t{'Min} and @t{'Max}.
9233
9234@item
9235@t{'Pos} and @t{'Val}.
9236
9237@item
9238@t{'Tag}.
9239
9240@item
9241@t{'Range} on array objects (not subtypes), but only as the right
9242operand of the membership (@code{in}) operator.
9243
9244@item
9245@t{'Access}, @t{'Unchecked_Access}, and
9246@t{'Unrestricted_Access} (a GNAT extension).
9247
9248@item
9249@t{'Address}.
9250@end itemize
9251
9252@item
9253The names in
9254@code{Characters.Latin_1} are not available and
9255concatenation is not implemented. Thus, escape characters in strings are
9256not currently available.
9257
9258@item
9259Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9260equality of representations. They will generally work correctly
9261for strings and arrays whose elements have integer or enumeration types.
9262They may not work correctly for arrays whose element
9263types have user-defined equality, for arrays of real values
9264(in particular, IEEE-conformant floating point, because of negative
9265zeroes and NaNs), and for arrays whose elements contain unused bits with
9266indeterminate values.
9267
9268@item
9269The other component-by-component array operations (@code{and}, @code{or},
9270@code{xor}, @code{not}, and relational tests other than equality)
9271are not implemented.
9272
9273@item
9274There are no record or array aggregates.
9275
9276@item
9277Calls to dispatching subprograms are not implemented.
9278
9279@item
9280The overloading algorithm is much more limited (i.e., less selective)
9281than that of real Ada. It makes only limited use of the context in which a subexpression
9282appears to resolve its meaning, and it is much looser in its rules for allowing
9283type matches. As a result, some function calls will be ambiguous, and the user
9284will be asked to choose the proper resolution.
9285
9286@item
9287The @code{new} operator is not implemented.
9288
9289@item
9290Entry calls are not implemented.
9291
9292@item
9293Aside from printing, arithmetic operations on the native VAX floating-point
9294formats are not supported.
9295
9296@item
9297It is not possible to slice a packed array.
9298@end itemize
9299
9300@node Additions to Ada
9301@subsubsection Additions to Ada
9302@cindex Ada, deviations from
9303
9304As it does for other languages, @value{GDBN} makes certain generic
9305extensions to Ada (@pxref{Expressions}):
9306
9307@itemize @bullet
9308@item
9309If the expression @var{E} is a variable residing in memory
9310(typically a local variable or array element) and @var{N} is
9311a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9312@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9313In Ada, this operator is generally not necessary, since its prime use
9314is in displaying parts of an array, and slicing will usually do this in Ada.
9315However, there are occasional uses when debugging programs
9316in which certain debugging information has been optimized away.
9317
9318@item
9319@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9320in function or file @var{B}.'' When @var{B} is a file name, you must typically
9321surround it in single quotes.
9322
9323@item
9324The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9325@var{type} that appears at address @var{addr}.''
9326
9327@item
9328A name starting with @samp{$} is a convenience variable
9329(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9330@end itemize
9331
9332In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9333to Ada:
9334
9335@itemize @bullet
9336@item
9337The assignment statement is allowed as an expression, returning
9338its right-hand operand as its value. Thus, you may enter
9339
9340@smallexample
9341set x := y + 3
9342print A(tmp := y + 1)
9343@end smallexample
9344
9345@item
9346The semicolon is allowed as an ``operator,'' returning as its value
9347the value of its right-hand operand.
9348This allows, for example,
9349complex conditional breaks:
9350
9351@smallexample
9352break f
9353condition 1 (report(i); k += 1; A(k) > 100)
9354@end smallexample
9355
9356@item
9357Rather than use catenation and symbolic character names to introduce special
9358characters into strings, one may instead use a special bracket notation,
9359which is also used to print strings. A sequence of characters of the form
9360@samp{["@var{XX}"]} within a string or character literal denotes the
9361(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9362sequence of characters @samp{["""]} also denotes a single quotation mark
9363in strings. For example,
9364@smallexample
9365 "One line.["0a"]Next line.["0a"]"
9366@end smallexample
9367@noindent
9368contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9369period.
9370
9371@item
9372The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9373@t{'Max} is optional (and is ignored in any case). For example, it is valid
9374to write
9375
9376@smallexample
9377print 'max(x, y)
9378@end smallexample
9379
9380@item
9381When printing arrays, @value{GDBN} uses positional notation when the
9382array has a lower bound of 1, and uses a modified named notation otherwise.
9383For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9384
9385@smallexample
9386(3 => 10, 17, 1)
9387@end smallexample
9388
9389@noindent
9390That is, in contrast to valid Ada, only the first component has a @code{=>}
9391clause.
9392
9393@item
9394You may abbreviate attributes in expressions with any unique,
9395multi-character subsequence of
9396their names (an exact match gets preference).
9397For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9398in place of @t{a'length}.
9399
9400@item
9401@cindex quoting Ada internal identifiers
9402Since Ada is case-insensitive, the debugger normally maps identifiers you type
9403to lower case. The GNAT compiler uses upper-case characters for
9404some of its internal identifiers, which are normally of no interest to users.
9405For the rare occasions when you actually have to look at them,
9406enclose them in angle brackets to avoid the lower-case mapping.
9407For example,
9408@smallexample
9409@value{GDBP} print <JMPBUF_SAVE>[0]
9410@end smallexample
9411
9412@item
9413Printing an object of class-wide type or dereferencing an
9414access-to-class-wide value will display all the components of the object's
9415specific type (as indicated by its run-time tag). Likewise, component
9416selection on such a value will operate on the specific type of the
9417object.
9418
9419@end itemize
9420
9421@node Stopping Before Main Program
9422@subsubsection Stopping at the Very Beginning
9423
9424@cindex breakpointing Ada elaboration code
9425It is sometimes necessary to debug the program during elaboration, and
9426before reaching the main procedure.
9427As defined in the Ada Reference
9428Manual, the elaboration code is invoked from a procedure called
9429@code{adainit}. To run your program up to the beginning of
9430elaboration, simply use the following two commands:
9431@code{tbreak adainit} and @code{run}.
9432
9433@node Ada Glitches
9434@subsubsection Known Peculiarities of Ada Mode
9435@cindex Ada, problems
9436
9437Besides the omissions listed previously (@pxref{Omissions from Ada}),
9438we know of several problems with and limitations of Ada mode in
9439@value{GDBN},
9440some of which will be fixed with planned future releases of the debugger
9441and the GNU Ada compiler.
9442
9443@itemize @bullet
9444@item
9445Currently, the debugger
9446has insufficient information to determine whether certain pointers represent
9447pointers to objects or the objects themselves.
9448Thus, the user may have to tack an extra @code{.all} after an expression
9449to get it printed properly.
9450
9451@item
9452Static constants that the compiler chooses not to materialize as objects in
9453storage are invisible to the debugger.
9454
9455@item
9456Named parameter associations in function argument lists are ignored (the
9457argument lists are treated as positional).
9458
9459@item
9460Many useful library packages are currently invisible to the debugger.
9461
9462@item
9463Fixed-point arithmetic, conversions, input, and output is carried out using
9464floating-point arithmetic, and may give results that only approximate those on
9465the host machine.
9466
9467@item
9468The type of the @t{'Address} attribute may not be @code{System.Address}.
9469
9470@item
9471The GNAT compiler never generates the prefix @code{Standard} for any of
9472the standard symbols defined by the Ada language. @value{GDBN} knows about
9473this: it will strip the prefix from names when you use it, and will never
9474look for a name you have so qualified among local symbols, nor match against
9475symbols in other packages or subprograms. If you have
9476defined entities anywhere in your program other than parameters and
9477local variables whose simple names match names in @code{Standard},
9478GNAT's lack of qualification here can cause confusion. When this happens,
9479you can usually resolve the confusion
9480by qualifying the problematic names with package
9481@code{Standard} explicitly.
9482@end itemize
9483
4e562065
JB
9484@node Unsupported languages
9485@section Unsupported languages
9486
9487@cindex unsupported languages
9488@cindex minimal language
9489In addition to the other fully-supported programming languages,
9490@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9491It does not represent a real programming language, but provides a set
9492of capabilities close to what the C or assembly languages provide.
9493This should allow most simple operations to be performed while debugging
9494an application that uses a language currently not supported by @value{GDBN}.
9495
9496If the language is set to @code{auto}, @value{GDBN} will automatically
9497select this language if the current frame corresponds to an unsupported
9498language.
9499
6d2ebf8b 9500@node Symbols
c906108c
SS
9501@chapter Examining the Symbol Table
9502
d4f3574e 9503The commands described in this chapter allow you to inquire about the
c906108c
SS
9504symbols (names of variables, functions and types) defined in your
9505program. This information is inherent in the text of your program and
9506does not change as your program executes. @value{GDBN} finds it in your
9507program's symbol table, in the file indicated when you started @value{GDBN}
9508(@pxref{File Options, ,Choosing files}), or by one of the
9509file-management commands (@pxref{Files, ,Commands to specify files}).
9510
9511@cindex symbol names
9512@cindex names of symbols
9513@cindex quoting names
9514Occasionally, you may need to refer to symbols that contain unusual
9515characters, which @value{GDBN} ordinarily treats as word delimiters. The
9516most frequent case is in referring to static variables in other
9517source files (@pxref{Variables,,Program variables}). File names
9518are recorded in object files as debugging symbols, but @value{GDBN} would
9519ordinarily parse a typical file name, like @file{foo.c}, as the three words
9520@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9521@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9522
474c8240 9523@smallexample
c906108c 9524p 'foo.c'::x
474c8240 9525@end smallexample
c906108c
SS
9526
9527@noindent
9528looks up the value of @code{x} in the scope of the file @file{foo.c}.
9529
9530@table @code
9531@kindex info address
b37052ae 9532@cindex address of a symbol
c906108c
SS
9533@item info address @var{symbol}
9534Describe where the data for @var{symbol} is stored. For a register
9535variable, this says which register it is kept in. For a non-register
9536local variable, this prints the stack-frame offset at which the variable
9537is always stored.
9538
9539Note the contrast with @samp{print &@var{symbol}}, which does not work
9540at all for a register variable, and for a stack local variable prints
9541the exact address of the current instantiation of the variable.
9542
3d67e040 9543@kindex info symbol
b37052ae 9544@cindex symbol from address
3d67e040
EZ
9545@item info symbol @var{addr}
9546Print the name of a symbol which is stored at the address @var{addr}.
9547If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9548nearest symbol and an offset from it:
9549
474c8240 9550@smallexample
3d67e040
EZ
9551(@value{GDBP}) info symbol 0x54320
9552_initialize_vx + 396 in section .text
474c8240 9553@end smallexample
3d67e040
EZ
9554
9555@noindent
9556This is the opposite of the @code{info address} command. You can use
9557it to find out the name of a variable or a function given its address.
9558
c906108c 9559@kindex whatis
d4f3574e
SS
9560@item whatis @var{expr}
9561Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9562actually evaluated, and any side-effecting operations (such as
9563assignments or function calls) inside it do not take place.
9564@xref{Expressions, ,Expressions}.
9565
9566@item whatis
9567Print the data type of @code{$}, the last value in the value history.
9568
9569@kindex ptype
9570@item ptype @var{typename}
9571Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9572the name of a type, or for C code it may have the form @samp{class
9573@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9574@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9575
d4f3574e 9576@item ptype @var{expr}
c906108c 9577@itemx ptype
d4f3574e 9578Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9579differs from @code{whatis} by printing a detailed description, instead
9580of just the name of the type.
9581
9582For example, for this variable declaration:
9583
474c8240 9584@smallexample
c906108c 9585struct complex @{double real; double imag;@} v;
474c8240 9586@end smallexample
c906108c
SS
9587
9588@noindent
9589the two commands give this output:
9590
474c8240 9591@smallexample
c906108c
SS
9592@group
9593(@value{GDBP}) whatis v
9594type = struct complex
9595(@value{GDBP}) ptype v
9596type = struct complex @{
9597 double real;
9598 double imag;
9599@}
9600@end group
474c8240 9601@end smallexample
c906108c
SS
9602
9603@noindent
9604As with @code{whatis}, using @code{ptype} without an argument refers to
9605the type of @code{$}, the last value in the value history.
9606
9607@kindex info types
9608@item info types @var{regexp}
9609@itemx info types
d4f3574e 9610Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9611(or all types in your program, if you supply no argument). Each
9612complete typename is matched as though it were a complete line; thus,
9613@samp{i type value} gives information on all types in your program whose
d4f3574e 9614names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9615information only on types whose complete name is @code{value}.
9616
9617This command differs from @code{ptype} in two ways: first, like
9618@code{whatis}, it does not print a detailed description; second, it
9619lists all source files where a type is defined.
9620
b37052ae
EZ
9621@kindex info scope
9622@cindex local variables
9623@item info scope @var{addr}
9624List all the variables local to a particular scope. This command
9625accepts a location---a function name, a source line, or an address
9626preceded by a @samp{*}, and prints all the variables local to the
9627scope defined by that location. For example:
9628
9629@smallexample
9630(@value{GDBP}) @b{info scope command_line_handler}
9631Scope for command_line_handler:
9632Symbol rl is an argument at stack/frame offset 8, length 4.
9633Symbol linebuffer is in static storage at address 0x150a18, length 4.
9634Symbol linelength is in static storage at address 0x150a1c, length 4.
9635Symbol p is a local variable in register $esi, length 4.
9636Symbol p1 is a local variable in register $ebx, length 4.
9637Symbol nline is a local variable in register $edx, length 4.
9638Symbol repeat is a local variable at frame offset -8, length 4.
9639@end smallexample
9640
f5c37c66
EZ
9641@noindent
9642This command is especially useful for determining what data to collect
9643during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9644collect}.
9645
c906108c
SS
9646@kindex info source
9647@item info source
919d772c
JB
9648Show information about the current source file---that is, the source file for
9649the function containing the current point of execution:
9650@itemize @bullet
9651@item
9652the name of the source file, and the directory containing it,
9653@item
9654the directory it was compiled in,
9655@item
9656its length, in lines,
9657@item
9658which programming language it is written in,
9659@item
9660whether the executable includes debugging information for that file, and
9661if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9662@item
9663whether the debugging information includes information about
9664preprocessor macros.
9665@end itemize
9666
c906108c
SS
9667
9668@kindex info sources
9669@item info sources
9670Print the names of all source files in your program for which there is
9671debugging information, organized into two lists: files whose symbols
9672have already been read, and files whose symbols will be read when needed.
9673
9674@kindex info functions
9675@item info functions
9676Print the names and data types of all defined functions.
9677
9678@item info functions @var{regexp}
9679Print the names and data types of all defined functions
9680whose names contain a match for regular expression @var{regexp}.
9681Thus, @samp{info fun step} finds all functions whose names
9682include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
9683start with @code{step}. If a function name contains characters
9684that conflict with the regular expression language (eg.
1c5dfdad 9685@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9686
9687@kindex info variables
9688@item info variables
9689Print the names and data types of all variables that are declared
6ca652b0 9690outside of functions (i.e.@: excluding local variables).
c906108c
SS
9691
9692@item info variables @var{regexp}
9693Print the names and data types of all variables (except for local
9694variables) whose names contain a match for regular expression
9695@var{regexp}.
9696
b37303ee
AF
9697@kindex info classes
9698@item info classes
9699@itemx info classes @var{regexp}
9700Display all Objective-C classes in your program, or
9701(with the @var{regexp} argument) all those matching a particular regular
9702expression.
9703
9704@kindex info selectors
9705@item info selectors
9706@itemx info selectors @var{regexp}
9707Display all Objective-C selectors in your program, or
9708(with the @var{regexp} argument) all those matching a particular regular
9709expression.
9710
c906108c
SS
9711@ignore
9712This was never implemented.
9713@kindex info methods
9714@item info methods
9715@itemx info methods @var{regexp}
9716The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9717methods within C@t{++} program, or (with the @var{regexp} argument) a
9718specific set of methods found in the various C@t{++} classes. Many
9719C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9720from the @code{ptype} command can be overwhelming and hard to use. The
9721@code{info-methods} command filters the methods, printing only those
9722which match the regular-expression @var{regexp}.
9723@end ignore
9724
c906108c
SS
9725@cindex reloading symbols
9726Some systems allow individual object files that make up your program to
7a292a7a
SS
9727be replaced without stopping and restarting your program. For example,
9728in VxWorks you can simply recompile a defective object file and keep on
9729running. If you are running on one of these systems, you can allow
9730@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9731
9732@table @code
9733@kindex set symbol-reloading
9734@item set symbol-reloading on
9735Replace symbol definitions for the corresponding source file when an
9736object file with a particular name is seen again.
9737
9738@item set symbol-reloading off
6d2ebf8b
SS
9739Do not replace symbol definitions when encountering object files of the
9740same name more than once. This is the default state; if you are not
9741running on a system that permits automatic relinking of modules, you
9742should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9743may discard symbols when linking large programs, that may contain
9744several modules (from different directories or libraries) with the same
9745name.
c906108c
SS
9746
9747@kindex show symbol-reloading
9748@item show symbol-reloading
9749Show the current @code{on} or @code{off} setting.
9750@end table
c906108c 9751
c906108c
SS
9752@kindex set opaque-type-resolution
9753@item set opaque-type-resolution on
9754Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9755declared as a pointer to a @code{struct}, @code{class}, or
9756@code{union}---for example, @code{struct MyType *}---that is used in one
9757source file although the full declaration of @code{struct MyType} is in
9758another source file. The default is on.
9759
9760A change in the setting of this subcommand will not take effect until
9761the next time symbols for a file are loaded.
9762
9763@item set opaque-type-resolution off
9764Tell @value{GDBN} not to resolve opaque types. In this case, the type
9765is printed as follows:
9766@smallexample
9767@{<no data fields>@}
9768@end smallexample
9769
9770@kindex show opaque-type-resolution
9771@item show opaque-type-resolution
9772Show whether opaque types are resolved or not.
c906108c
SS
9773
9774@kindex maint print symbols
9775@cindex symbol dump
9776@kindex maint print psymbols
9777@cindex partial symbol dump
9778@item maint print symbols @var{filename}
9779@itemx maint print psymbols @var{filename}
9780@itemx maint print msymbols @var{filename}
9781Write a dump of debugging symbol data into the file @var{filename}.
9782These commands are used to debug the @value{GDBN} symbol-reading code. Only
9783symbols with debugging data are included. If you use @samp{maint print
9784symbols}, @value{GDBN} includes all the symbols for which it has already
9785collected full details: that is, @var{filename} reflects symbols for
9786only those files whose symbols @value{GDBN} has read. You can use the
9787command @code{info sources} to find out which files these are. If you
9788use @samp{maint print psymbols} instead, the dump shows information about
9789symbols that @value{GDBN} only knows partially---that is, symbols defined in
9790files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9791@samp{maint print msymbols} dumps just the minimal symbol information
9792required for each object file from which @value{GDBN} has read some symbols.
9793@xref{Files, ,Commands to specify files}, for a discussion of how
9794@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9795
5e7b2f39
JB
9796@kindex maint info symtabs
9797@kindex maint info psymtabs
44ea7b70
JB
9798@cindex listing @value{GDBN}'s internal symbol tables
9799@cindex symbol tables, listing @value{GDBN}'s internal
9800@cindex full symbol tables, listing @value{GDBN}'s internal
9801@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9802@item maint info symtabs @r{[} @var{regexp} @r{]}
9803@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9804
9805List the @code{struct symtab} or @code{struct partial_symtab}
9806structures whose names match @var{regexp}. If @var{regexp} is not
9807given, list them all. The output includes expressions which you can
9808copy into a @value{GDBN} debugging this one to examine a particular
9809structure in more detail. For example:
9810
9811@smallexample
5e7b2f39 9812(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9813@{ objfile /home/gnu/build/gdb/gdb
9814 ((struct objfile *) 0x82e69d0)
b383017d 9815 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9816 ((struct partial_symtab *) 0x8474b10)
9817 readin no
9818 fullname (null)
9819 text addresses 0x814d3c8 -- 0x8158074
9820 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9821 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9822 dependencies (none)
9823 @}
9824@}
5e7b2f39 9825(@value{GDBP}) maint info symtabs
44ea7b70
JB
9826(@value{GDBP})
9827@end smallexample
9828@noindent
9829We see that there is one partial symbol table whose filename contains
9830the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9831and we see that @value{GDBN} has not read in any symtabs yet at all.
9832If we set a breakpoint on a function, that will cause @value{GDBN} to
9833read the symtab for the compilation unit containing that function:
9834
9835@smallexample
9836(@value{GDBP}) break dwarf2_psymtab_to_symtab
9837Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9838line 1574.
5e7b2f39 9839(@value{GDBP}) maint info symtabs
b383017d 9840@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 9841 ((struct objfile *) 0x82e69d0)
b383017d 9842 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9843 ((struct symtab *) 0x86c1f38)
9844 dirname (null)
9845 fullname (null)
9846 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9847 debugformat DWARF 2
9848 @}
9849@}
b383017d 9850(@value{GDBP})
44ea7b70 9851@end smallexample
c906108c
SS
9852@end table
9853
44ea7b70 9854
6d2ebf8b 9855@node Altering
c906108c
SS
9856@chapter Altering Execution
9857
9858Once you think you have found an error in your program, you might want to
9859find out for certain whether correcting the apparent error would lead to
9860correct results in the rest of the run. You can find the answer by
9861experiment, using the @value{GDBN} features for altering execution of the
9862program.
9863
9864For example, you can store new values into variables or memory
7a292a7a
SS
9865locations, give your program a signal, restart it at a different
9866address, or even return prematurely from a function.
c906108c
SS
9867
9868@menu
9869* Assignment:: Assignment to variables
9870* Jumping:: Continuing at a different address
c906108c 9871* Signaling:: Giving your program a signal
c906108c
SS
9872* Returning:: Returning from a function
9873* Calling:: Calling your program's functions
9874* Patching:: Patching your program
9875@end menu
9876
6d2ebf8b 9877@node Assignment
c906108c
SS
9878@section Assignment to variables
9879
9880@cindex assignment
9881@cindex setting variables
9882To alter the value of a variable, evaluate an assignment expression.
9883@xref{Expressions, ,Expressions}. For example,
9884
474c8240 9885@smallexample
c906108c 9886print x=4
474c8240 9887@end smallexample
c906108c
SS
9888
9889@noindent
9890stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9891value of the assignment expression (which is 4).
c906108c
SS
9892@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9893information on operators in supported languages.
c906108c
SS
9894
9895@kindex set variable
9896@cindex variables, setting
9897If you are not interested in seeing the value of the assignment, use the
9898@code{set} command instead of the @code{print} command. @code{set} is
9899really the same as @code{print} except that the expression's value is
9900not printed and is not put in the value history (@pxref{Value History,
9901,Value history}). The expression is evaluated only for its effects.
9902
c906108c
SS
9903If the beginning of the argument string of the @code{set} command
9904appears identical to a @code{set} subcommand, use the @code{set
9905variable} command instead of just @code{set}. This command is identical
9906to @code{set} except for its lack of subcommands. For example, if your
9907program has a variable @code{width}, you get an error if you try to set
9908a new value with just @samp{set width=13}, because @value{GDBN} has the
9909command @code{set width}:
9910
474c8240 9911@smallexample
c906108c
SS
9912(@value{GDBP}) whatis width
9913type = double
9914(@value{GDBP}) p width
9915$4 = 13
9916(@value{GDBP}) set width=47
9917Invalid syntax in expression.
474c8240 9918@end smallexample
c906108c
SS
9919
9920@noindent
9921The invalid expression, of course, is @samp{=47}. In
9922order to actually set the program's variable @code{width}, use
9923
474c8240 9924@smallexample
c906108c 9925(@value{GDBP}) set var width=47
474c8240 9926@end smallexample
53a5351d 9927
c906108c
SS
9928Because the @code{set} command has many subcommands that can conflict
9929with the names of program variables, it is a good idea to use the
9930@code{set variable} command instead of just @code{set}. For example, if
9931your program has a variable @code{g}, you run into problems if you try
9932to set a new value with just @samp{set g=4}, because @value{GDBN} has
9933the command @code{set gnutarget}, abbreviated @code{set g}:
9934
474c8240 9935@smallexample
c906108c
SS
9936@group
9937(@value{GDBP}) whatis g
9938type = double
9939(@value{GDBP}) p g
9940$1 = 1
9941(@value{GDBP}) set g=4
2df3850c 9942(@value{GDBP}) p g
c906108c
SS
9943$2 = 1
9944(@value{GDBP}) r
9945The program being debugged has been started already.
9946Start it from the beginning? (y or n) y
9947Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9948"/home/smith/cc_progs/a.out": can't open to read symbols:
9949 Invalid bfd target.
c906108c
SS
9950(@value{GDBP}) show g
9951The current BFD target is "=4".
9952@end group
474c8240 9953@end smallexample
c906108c
SS
9954
9955@noindent
9956The program variable @code{g} did not change, and you silently set the
9957@code{gnutarget} to an invalid value. In order to set the variable
9958@code{g}, use
9959
474c8240 9960@smallexample
c906108c 9961(@value{GDBP}) set var g=4
474c8240 9962@end smallexample
c906108c
SS
9963
9964@value{GDBN} allows more implicit conversions in assignments than C; you can
9965freely store an integer value into a pointer variable or vice versa,
9966and you can convert any structure to any other structure that is the
9967same length or shorter.
9968@comment FIXME: how do structs align/pad in these conversions?
9969@comment /doc@cygnus.com 18dec1990
9970
9971To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9972construct to generate a value of specified type at a specified address
9973(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9974to memory location @code{0x83040} as an integer (which implies a certain size
9975and representation in memory), and
9976
474c8240 9977@smallexample
c906108c 9978set @{int@}0x83040 = 4
474c8240 9979@end smallexample
c906108c
SS
9980
9981@noindent
9982stores the value 4 into that memory location.
9983
6d2ebf8b 9984@node Jumping
c906108c
SS
9985@section Continuing at a different address
9986
9987Ordinarily, when you continue your program, you do so at the place where
9988it stopped, with the @code{continue} command. You can instead continue at
9989an address of your own choosing, with the following commands:
9990
9991@table @code
9992@kindex jump
9993@item jump @var{linespec}
9994Resume execution at line @var{linespec}. Execution stops again
9995immediately if there is a breakpoint there. @xref{List, ,Printing
9996source lines}, for a description of the different forms of
9997@var{linespec}. It is common practice to use the @code{tbreak} command
9998in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9999breakpoints}.
10000
10001The @code{jump} command does not change the current stack frame, or
10002the stack pointer, or the contents of any memory location or any
10003register other than the program counter. If line @var{linespec} is in
10004a different function from the one currently executing, the results may
10005be bizarre if the two functions expect different patterns of arguments or
10006of local variables. For this reason, the @code{jump} command requests
10007confirmation if the specified line is not in the function currently
10008executing. However, even bizarre results are predictable if you are
10009well acquainted with the machine-language code of your program.
10010
10011@item jump *@var{address}
10012Resume execution at the instruction at address @var{address}.
10013@end table
10014
c906108c 10015@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10016On many systems, you can get much the same effect as the @code{jump}
10017command by storing a new value into the register @code{$pc}. The
10018difference is that this does not start your program running; it only
10019changes the address of where it @emph{will} run when you continue. For
10020example,
c906108c 10021
474c8240 10022@smallexample
c906108c 10023set $pc = 0x485
474c8240 10024@end smallexample
c906108c
SS
10025
10026@noindent
10027makes the next @code{continue} command or stepping command execute at
10028address @code{0x485}, rather than at the address where your program stopped.
10029@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10030
10031The most common occasion to use the @code{jump} command is to back
10032up---perhaps with more breakpoints set---over a portion of a program
10033that has already executed, in order to examine its execution in more
10034detail.
10035
c906108c 10036@c @group
6d2ebf8b 10037@node Signaling
c906108c
SS
10038@section Giving your program a signal
10039
10040@table @code
10041@kindex signal
10042@item signal @var{signal}
10043Resume execution where your program stopped, but immediately give it the
10044signal @var{signal}. @var{signal} can be the name or the number of a
10045signal. For example, on many systems @code{signal 2} and @code{signal
10046SIGINT} are both ways of sending an interrupt signal.
10047
10048Alternatively, if @var{signal} is zero, continue execution without
10049giving a signal. This is useful when your program stopped on account of
10050a signal and would ordinary see the signal when resumed with the
10051@code{continue} command; @samp{signal 0} causes it to resume without a
10052signal.
10053
10054@code{signal} does not repeat when you press @key{RET} a second time
10055after executing the command.
10056@end table
10057@c @end group
10058
10059Invoking the @code{signal} command is not the same as invoking the
10060@code{kill} utility from the shell. Sending a signal with @code{kill}
10061causes @value{GDBN} to decide what to do with the signal depending on
10062the signal handling tables (@pxref{Signals}). The @code{signal} command
10063passes the signal directly to your program.
10064
c906108c 10065
6d2ebf8b 10066@node Returning
c906108c
SS
10067@section Returning from a function
10068
10069@table @code
10070@cindex returning from a function
10071@kindex return
10072@item return
10073@itemx return @var{expression}
10074You can cancel execution of a function call with the @code{return}
10075command. If you give an
10076@var{expression} argument, its value is used as the function's return
10077value.
10078@end table
10079
10080When you use @code{return}, @value{GDBN} discards the selected stack frame
10081(and all frames within it). You can think of this as making the
10082discarded frame return prematurely. If you wish to specify a value to
10083be returned, give that value as the argument to @code{return}.
10084
10085This pops the selected stack frame (@pxref{Selection, ,Selecting a
10086frame}), and any other frames inside of it, leaving its caller as the
10087innermost remaining frame. That frame becomes selected. The
10088specified value is stored in the registers used for returning values
10089of functions.
10090
10091The @code{return} command does not resume execution; it leaves the
10092program stopped in the state that would exist if the function had just
10093returned. In contrast, the @code{finish} command (@pxref{Continuing
10094and Stepping, ,Continuing and stepping}) resumes execution until the
10095selected stack frame returns naturally.
10096
6d2ebf8b 10097@node Calling
c906108c
SS
10098@section Calling program functions
10099
f8568604 10100@table @code
c906108c 10101@cindex calling functions
f8568604
EZ
10102@cindex inferior functions, calling
10103@item print @var{expr}
10104Evaluate the expression @var{expr} and displaying the resuling value.
10105@var{expr} may include calls to functions in the program being
10106debugged.
10107
c906108c 10108@kindex call
c906108c
SS
10109@item call @var{expr}
10110Evaluate the expression @var{expr} without displaying @code{void}
10111returned values.
c906108c
SS
10112
10113You can use this variant of the @code{print} command if you want to
f8568604
EZ
10114execute a function from your program that does not return anything
10115(a.k.a.@: @dfn{a void function}), but without cluttering the output
10116with @code{void} returned values that @value{GDBN} will otherwise
10117print. If the result is not void, it is printed and saved in the
10118value history.
10119@end table
10120
10121@cindex weak alias functions
10122Sometimes, a function you wish to call is actually a @dfn{weak alias}
10123for another function. In such case, @value{GDBN} might not pick up
10124the type information, including the types of the function arguments,
10125which causes @value{GDBN} to call the inferior function incorrectly.
10126As a result, the called function will function erroneously and may
10127even crash. A solution to that is to use the name of the aliased
10128function instead.
c906108c 10129
6d2ebf8b 10130@node Patching
c906108c 10131@section Patching programs
7a292a7a 10132
c906108c
SS
10133@cindex patching binaries
10134@cindex writing into executables
c906108c 10135@cindex writing into corefiles
c906108c 10136
7a292a7a
SS
10137By default, @value{GDBN} opens the file containing your program's
10138executable code (or the corefile) read-only. This prevents accidental
10139alterations to machine code; but it also prevents you from intentionally
10140patching your program's binary.
c906108c
SS
10141
10142If you'd like to be able to patch the binary, you can specify that
10143explicitly with the @code{set write} command. For example, you might
10144want to turn on internal debugging flags, or even to make emergency
10145repairs.
10146
10147@table @code
10148@kindex set write
10149@item set write on
10150@itemx set write off
7a292a7a
SS
10151If you specify @samp{set write on}, @value{GDBN} opens executable and
10152core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10153off} (the default), @value{GDBN} opens them read-only.
10154
10155If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10156@code{exec-file} or @code{core-file} command) after changing @code{set
10157write}, for your new setting to take effect.
c906108c
SS
10158
10159@item show write
10160@kindex show write
7a292a7a
SS
10161Display whether executable files and core files are opened for writing
10162as well as reading.
c906108c
SS
10163@end table
10164
6d2ebf8b 10165@node GDB Files
c906108c
SS
10166@chapter @value{GDBN} Files
10167
7a292a7a
SS
10168@value{GDBN} needs to know the file name of the program to be debugged,
10169both in order to read its symbol table and in order to start your
10170program. To debug a core dump of a previous run, you must also tell
10171@value{GDBN} the name of the core dump file.
c906108c
SS
10172
10173@menu
10174* Files:: Commands to specify files
5b5d99cf 10175* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10176* Symbol Errors:: Errors reading symbol files
10177@end menu
10178
6d2ebf8b 10179@node Files
c906108c 10180@section Commands to specify files
c906108c 10181
7a292a7a 10182@cindex symbol table
c906108c 10183@cindex core dump file
7a292a7a
SS
10184
10185You may want to specify executable and core dump file names. The usual
10186way to do this is at start-up time, using the arguments to
10187@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10188Out of @value{GDBN}}).
c906108c
SS
10189
10190Occasionally it is necessary to change to a different file during a
10191@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10192a file you want to use. In these situations the @value{GDBN} commands
10193to specify new files are useful.
10194
10195@table @code
10196@cindex executable file
10197@kindex file
10198@item file @var{filename}
10199Use @var{filename} as the program to be debugged. It is read for its
10200symbols and for the contents of pure memory. It is also the program
10201executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10202directory and the file is not found in the @value{GDBN} working directory,
10203@value{GDBN} uses the environment variable @code{PATH} as a list of
10204directories to search, just as the shell does when looking for a program
10205to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10206and your program, using the @code{path} command.
10207
6d2ebf8b 10208On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10209@file{@var{filename}.syms} may hold symbol table information for
10210@var{filename}. If so, @value{GDBN} maps in the symbol table from
10211@file{@var{filename}.syms}, starting up more quickly. See the
10212descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10213(available on the command line, see @ref{File Options, , -readnow},
10214and with the commands @code{file}, @code{symbol-file}, or
10215@code{add-symbol-file}, described below), for more information.
c906108c
SS
10216
10217@item file
10218@code{file} with no argument makes @value{GDBN} discard any information it
10219has on both executable file and the symbol table.
10220
10221@kindex exec-file
10222@item exec-file @r{[} @var{filename} @r{]}
10223Specify that the program to be run (but not the symbol table) is found
10224in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10225if necessary to locate your program. Omitting @var{filename} means to
10226discard information on the executable file.
10227
10228@kindex symbol-file
10229@item symbol-file @r{[} @var{filename} @r{]}
10230Read symbol table information from file @var{filename}. @code{PATH} is
10231searched when necessary. Use the @code{file} command to get both symbol
10232table and program to run from the same file.
10233
10234@code{symbol-file} with no argument clears out @value{GDBN} information on your
10235program's symbol table.
10236
5d161b24 10237The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10238of its convenience variables, the value history, and all breakpoints and
10239auto-display expressions. This is because they may contain pointers to
10240the internal data recording symbols and data types, which are part of
10241the old symbol table data being discarded inside @value{GDBN}.
10242
10243@code{symbol-file} does not repeat if you press @key{RET} again after
10244executing it once.
10245
10246When @value{GDBN} is configured for a particular environment, it
10247understands debugging information in whatever format is the standard
10248generated for that environment; you may use either a @sc{gnu} compiler, or
10249other compilers that adhere to the local conventions.
c906108c
SS
10250Best results are usually obtained from @sc{gnu} compilers; for example,
10251using @code{@value{GCC}} you can generate debugging information for
10252optimized code.
c906108c
SS
10253
10254For most kinds of object files, with the exception of old SVR3 systems
10255using COFF, the @code{symbol-file} command does not normally read the
10256symbol table in full right away. Instead, it scans the symbol table
10257quickly to find which source files and which symbols are present. The
10258details are read later, one source file at a time, as they are needed.
10259
10260The purpose of this two-stage reading strategy is to make @value{GDBN}
10261start up faster. For the most part, it is invisible except for
10262occasional pauses while the symbol table details for a particular source
10263file are being read. (The @code{set verbose} command can turn these
10264pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10265warnings and messages}.)
10266
c906108c
SS
10267We have not implemented the two-stage strategy for COFF yet. When the
10268symbol table is stored in COFF format, @code{symbol-file} reads the
10269symbol table data in full right away. Note that ``stabs-in-COFF''
10270still does the two-stage strategy, since the debug info is actually
10271in stabs format.
10272
10273@kindex readnow
10274@cindex reading symbols immediately
10275@cindex symbols, reading immediately
10276@kindex mapped
10277@cindex memory-mapped symbol file
10278@cindex saving symbol table
10279@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10280@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10281You can override the @value{GDBN} two-stage strategy for reading symbol
10282tables by using the @samp{-readnow} option with any of the commands that
10283load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10284entire symbol table available.
c906108c 10285
c906108c
SS
10286If memory-mapped files are available on your system through the
10287@code{mmap} system call, you can use another option, @samp{-mapped}, to
10288cause @value{GDBN} to write the symbols for your program into a reusable
10289file. Future @value{GDBN} debugging sessions map in symbol information
10290from this auxiliary symbol file (if the program has not changed), rather
10291than spending time reading the symbol table from the executable
10292program. Using the @samp{-mapped} option has the same effect as
10293starting @value{GDBN} with the @samp{-mapped} command-line option.
10294
10295You can use both options together, to make sure the auxiliary symbol
10296file has all the symbol information for your program.
10297
10298The auxiliary symbol file for a program called @var{myprog} is called
10299@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10300than the corresponding executable), @value{GDBN} always attempts to use
10301it when you debug @var{myprog}; no special options or commands are
10302needed.
10303
10304The @file{.syms} file is specific to the host machine where you run
10305@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10306symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10307
10308@c FIXME: for now no mention of directories, since this seems to be in
10309@c flux. 13mar1992 status is that in theory GDB would look either in
10310@c current dir or in same dir as myprog; but issues like competing
10311@c GDB's, or clutter in system dirs, mean that in practice right now
10312@c only current dir is used. FFish says maybe a special GDB hierarchy
10313@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10314@c files.
10315
c906108c
SS
10316@kindex core-file
10317@item core-file @r{[} @var{filename} @r{]}
4644b6e3 10318@itemx core
c906108c
SS
10319Specify the whereabouts of a core dump file to be used as the ``contents
10320of memory''. Traditionally, core files contain only some parts of the
10321address space of the process that generated them; @value{GDBN} can access the
10322executable file itself for other parts.
10323
10324@code{core-file} with no argument specifies that no core file is
10325to be used.
10326
10327Note that the core file is ignored when your program is actually running
7a292a7a
SS
10328under @value{GDBN}. So, if you have been running your program and you
10329wish to debug a core file instead, you must kill the subprocess in which
10330the program is running. To do this, use the @code{kill} command
c906108c 10331(@pxref{Kill Process, ,Killing the child process}).
c906108c 10332
c906108c
SS
10333@kindex add-symbol-file
10334@cindex dynamic linking
10335@item add-symbol-file @var{filename} @var{address}
10336@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10337@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10338The @code{add-symbol-file} command reads additional symbol table
10339information from the file @var{filename}. You would use this command
10340when @var{filename} has been dynamically loaded (by some other means)
10341into the program that is running. @var{address} should be the memory
10342address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10343this out for itself. You can additionally specify an arbitrary number
10344of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10345section name and base address for that section. You can specify any
10346@var{address} as an expression.
c906108c
SS
10347
10348The symbol table of the file @var{filename} is added to the symbol table
10349originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10350@code{add-symbol-file} command any number of times; the new symbol data
10351thus read keeps adding to the old. To discard all old symbol data
10352instead, use the @code{symbol-file} command without any arguments.
c906108c 10353
17d9d558
JB
10354@cindex relocatable object files, reading symbols from
10355@cindex object files, relocatable, reading symbols from
10356@cindex reading symbols from relocatable object files
10357@cindex symbols, reading from relocatable object files
10358@cindex @file{.o} files, reading symbols from
10359Although @var{filename} is typically a shared library file, an
10360executable file, or some other object file which has been fully
10361relocated for loading into a process, you can also load symbolic
10362information from relocatable @file{.o} files, as long as:
10363
10364@itemize @bullet
10365@item
10366the file's symbolic information refers only to linker symbols defined in
10367that file, not to symbols defined by other object files,
10368@item
10369every section the file's symbolic information refers to has actually
10370been loaded into the inferior, as it appears in the file, and
10371@item
10372you can determine the address at which every section was loaded, and
10373provide these to the @code{add-symbol-file} command.
10374@end itemize
10375
10376@noindent
10377Some embedded operating systems, like Sun Chorus and VxWorks, can load
10378relocatable files into an already running program; such systems
10379typically make the requirements above easy to meet. However, it's
10380important to recognize that many native systems use complex link
49efadf5 10381procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10382assembly, for example) that make the requirements difficult to meet. In
10383general, one cannot assume that using @code{add-symbol-file} to read a
10384relocatable object file's symbolic information will have the same effect
10385as linking the relocatable object file into the program in the normal
10386way.
10387
c906108c
SS
10388@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10389
10390You can use the @samp{-mapped} and @samp{-readnow} options just as with
10391the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10392table information for @var{filename}.
10393
10394@kindex add-shared-symbol-file
10395@item add-shared-symbol-file
10396The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
10397operating system for the Motorola 88k. @value{GDBN} automatically looks for
10398shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 10399@code{add-shared-symbol-file}. It takes no arguments.
c906108c 10400
c906108c
SS
10401@kindex section
10402@item section
5d161b24
DB
10403The @code{section} command changes the base address of section SECTION of
10404the exec file to ADDR. This can be used if the exec file does not contain
10405section addresses, (such as in the a.out format), or when the addresses
10406specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
10407separately. The @code{info files} command, described below, lists all
10408the sections and their addresses.
c906108c
SS
10409
10410@kindex info files
10411@kindex info target
10412@item info files
10413@itemx info target
7a292a7a
SS
10414@code{info files} and @code{info target} are synonymous; both print the
10415current target (@pxref{Targets, ,Specifying a Debugging Target}),
10416including the names of the executable and core dump files currently in
10417use by @value{GDBN}, and the files from which symbols were loaded. The
10418command @code{help target} lists all possible targets rather than
10419current ones.
10420
fe95c787
MS
10421@kindex maint info sections
10422@item maint info sections
10423Another command that can give you extra information about program sections
10424is @code{maint info sections}. In addition to the section information
10425displayed by @code{info files}, this command displays the flags and file
10426offset of each section in the executable and core dump files. In addition,
10427@code{maint info sections} provides the following command options (which
10428may be arbitrarily combined):
10429
10430@table @code
10431@item ALLOBJ
10432Display sections for all loaded object files, including shared libraries.
10433@item @var{sections}
6600abed 10434Display info only for named @var{sections}.
fe95c787
MS
10435@item @var{section-flags}
10436Display info only for sections for which @var{section-flags} are true.
10437The section flags that @value{GDBN} currently knows about are:
10438@table @code
10439@item ALLOC
10440Section will have space allocated in the process when loaded.
10441Set for all sections except those containing debug information.
10442@item LOAD
10443Section will be loaded from the file into the child process memory.
10444Set for pre-initialized code and data, clear for @code{.bss} sections.
10445@item RELOC
10446Section needs to be relocated before loading.
10447@item READONLY
10448Section cannot be modified by the child process.
10449@item CODE
10450Section contains executable code only.
6600abed 10451@item DATA
fe95c787
MS
10452Section contains data only (no executable code).
10453@item ROM
10454Section will reside in ROM.
10455@item CONSTRUCTOR
10456Section contains data for constructor/destructor lists.
10457@item HAS_CONTENTS
10458Section is not empty.
10459@item NEVER_LOAD
10460An instruction to the linker to not output the section.
10461@item COFF_SHARED_LIBRARY
10462A notification to the linker that the section contains
10463COFF shared library information.
10464@item IS_COMMON
10465Section contains common symbols.
10466@end table
10467@end table
6763aef9
MS
10468@kindex set trust-readonly-sections
10469@item set trust-readonly-sections on
10470Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10471really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10472In that case, @value{GDBN} can fetch values from these sections
10473out of the object file, rather than from the target program.
10474For some targets (notably embedded ones), this can be a significant
10475enhancement to debugging performance.
10476
10477The default is off.
10478
10479@item set trust-readonly-sections off
15110bc3 10480Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10481the contents of the section might change while the program is running,
10482and must therefore be fetched from the target when needed.
c906108c
SS
10483@end table
10484
10485All file-specifying commands allow both absolute and relative file names
10486as arguments. @value{GDBN} always converts the file name to an absolute file
10487name and remembers it that way.
10488
c906108c 10489@cindex shared libraries
c906108c
SS
10490@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
10491libraries.
53a5351d 10492
c906108c
SS
10493@value{GDBN} automatically loads symbol definitions from shared libraries
10494when you use the @code{run} command, or when you examine a core file.
10495(Before you issue the @code{run} command, @value{GDBN} does not understand
10496references to a function in a shared library, however---unless you are
10497debugging a core file).
53a5351d
JM
10498
10499On HP-UX, if the program loads a library explicitly, @value{GDBN}
10500automatically loads the symbols at the time of the @code{shl_load} call.
10501
c906108c
SS
10502@c FIXME: some @value{GDBN} release may permit some refs to undef
10503@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10504@c FIXME...lib; check this from time to time when updating manual
10505
b7209cb4
FF
10506There are times, however, when you may wish to not automatically load
10507symbol definitions from shared libraries, such as when they are
10508particularly large or there are many of them.
10509
10510To control the automatic loading of shared library symbols, use the
10511commands:
10512
10513@table @code
10514@kindex set auto-solib-add
10515@item set auto-solib-add @var{mode}
10516If @var{mode} is @code{on}, symbols from all shared object libraries
10517will be loaded automatically when the inferior begins execution, you
10518attach to an independently started inferior, or when the dynamic linker
10519informs @value{GDBN} that a new library has been loaded. If @var{mode}
10520is @code{off}, symbols must be loaded manually, using the
10521@code{sharedlibrary} command. The default value is @code{on}.
10522
dcaf7c2c
EZ
10523@cindex memory used for symbol tables
10524If your program uses lots of shared libraries with debug info that
10525takes large amounts of memory, you can decrease the @value{GDBN}
10526memory footprint by preventing it from automatically loading the
10527symbols from shared libraries. To that end, type @kbd{set
10528auto-solib-add off} before running the inferior, then load each
10529library whose debug symbols you do need with @kbd{sharedlibrary
10530@var{regexp}}, where @var{regexp} is a regular expresion that matches
10531the libraries whose symbols you want to be loaded.
10532
b7209cb4
FF
10533@kindex show auto-solib-add
10534@item show auto-solib-add
10535Display the current autoloading mode.
10536@end table
10537
10538To explicitly load shared library symbols, use the @code{sharedlibrary}
10539command:
10540
c906108c
SS
10541@table @code
10542@kindex info sharedlibrary
10543@kindex info share
10544@item info share
10545@itemx info sharedlibrary
10546Print the names of the shared libraries which are currently loaded.
10547
10548@kindex sharedlibrary
10549@kindex share
10550@item sharedlibrary @var{regex}
10551@itemx share @var{regex}
c906108c
SS
10552Load shared object library symbols for files matching a
10553Unix regular expression.
10554As with files loaded automatically, it only loads shared libraries
10555required by your program for a core file or after typing @code{run}. If
10556@var{regex} is omitted all shared libraries required by your program are
10557loaded.
10558@end table
10559
b7209cb4
FF
10560On some systems, such as HP-UX systems, @value{GDBN} supports
10561autoloading shared library symbols until a limiting threshold size is
10562reached. This provides the benefit of allowing autoloading to remain on
10563by default, but avoids autoloading excessively large shared libraries,
10564up to a threshold that is initially set, but which you can modify if you
10565wish.
c906108c
SS
10566
10567Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10568loaded. To load these symbols, use the command @code{sharedlibrary
10569@var{filename}}. The base address of the shared library is determined
c906108c
SS
10570automatically by @value{GDBN} and need not be specified.
10571
10572To display or set the threshold, use the commands:
10573
10574@table @code
b7209cb4
FF
10575@kindex set auto-solib-limit
10576@item set auto-solib-limit @var{threshold}
10577Set the autoloading size threshold, in an integral number of megabytes.
10578If @var{threshold} is nonzero and shared library autoloading is enabled,
10579symbols from all shared object libraries will be loaded until the total
10580size of the loaded shared library symbols exceeds this threshold.
c906108c 10581Otherwise, symbols must be loaded manually, using the
6ca652b0 10582@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10583Mb).
c906108c 10584
b7209cb4
FF
10585@kindex show auto-solib-limit
10586@item show auto-solib-limit
c906108c
SS
10587Display the current autoloading size threshold, in megabytes.
10588@end table
c906108c 10589
f5ebfba0
DJ
10590Shared libraries are also supported in many cross or remote debugging
10591configurations. A copy of the target's libraries need to be present on the
10592host system; they need to be the same as the target libraries, although the
10593copies on the target can be stripped as long as the copies on the host are
10594not.
10595
10596You need to tell @value{GDBN} where the target libraries are, so that it can
10597load the correct copies---otherwise, it may try to load the host's libraries.
10598@value{GDBN} has two variables to specify the search directories for target
10599libraries.
10600
10601@table @code
10602@kindex set solib-absolute-prefix
10603@item set solib-absolute-prefix @var{path}
10604If this variable is set, @var{path} will be used as a prefix for any
10605absolute shared library paths; many runtime loaders store the absolute
10606paths to the shared library in the target program's memory. If you use
10607@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10608out in the same way that they are on the target, with e.g.@: a
10609@file{/usr/lib} hierarchy under @var{path}.
10610
10611You can set the default value of @samp{solib-absolute-prefix} by using the
10612configure-time @samp{--with-sysroot} option.
10613
10614@kindex show solib-absolute-prefix
10615@item show solib-absolute-prefix
10616Display the current shared library prefix.
10617
10618@kindex set solib-search-path
10619@item set solib-search-path @var{path}
10620If this variable is set, @var{path} is a colon-separated list of directories
10621to search for shared libraries. @samp{solib-search-path} is used after
10622@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10623the library is relative instead of absolute. If you want to use
10624@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10625set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10626@value{GDBN} from finding your host's libraries.
10627
10628@kindex show solib-search-path
10629@item show solib-search-path
10630Display the current shared library search path.
10631@end table
10632
5b5d99cf
JB
10633
10634@node Separate Debug Files
10635@section Debugging Information in Separate Files
10636@cindex separate debugging information files
10637@cindex debugging information in separate files
10638@cindex @file{.debug} subdirectories
10639@cindex debugging information directory, global
10640@cindex global debugging information directory
10641
10642@value{GDBN} allows you to put a program's debugging information in a
10643file separate from the executable itself, in a way that allows
10644@value{GDBN} to find and load the debugging information automatically.
10645Since debugging information can be very large --- sometimes larger
10646than the executable code itself --- some systems distribute debugging
10647information for their executables in separate files, which users can
10648install only when they need to debug a problem.
10649
10650If an executable's debugging information has been extracted to a
10651separate file, the executable should contain a @dfn{debug link} giving
10652the name of the debugging information file (with no directory
10653components), and a checksum of its contents. (The exact form of a
10654debug link is described below.) If the full name of the directory
10655containing the executable is @var{execdir}, and the executable has a
10656debug link that specifies the name @var{debugfile}, then @value{GDBN}
10657will automatically search for the debugging information file in three
10658places:
10659
10660@itemize @bullet
10661@item
10662the directory containing the executable file (that is, it will look
10663for a file named @file{@var{execdir}/@var{debugfile}},
10664@item
10665a subdirectory of that directory named @file{.debug} (that is, the
10666file @file{@var{execdir}/.debug/@var{debugfile}}, and
10667@item
10668a subdirectory of the global debug file directory that includes the
10669executable's full path, and the name from the link (that is, the file
10670@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10671@var{globaldebugdir} is the global debug file directory, and
10672@var{execdir} has been turned into a relative path).
10673@end itemize
10674@noindent
10675@value{GDBN} checks under each of these names for a debugging
10676information file whose checksum matches that given in the link, and
10677reads the debugging information from the first one it finds.
10678
10679So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10680which has a link containing the name @file{ls.debug}, and the global
10681debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10682for debug information in @file{/usr/bin/ls.debug},
10683@file{/usr/bin/.debug/ls.debug}, and
10684@file{/usr/lib/debug/usr/bin/ls.debug}.
10685
10686You can set the global debugging info directory's name, and view the
10687name @value{GDBN} is currently using.
10688
10689@table @code
10690
10691@kindex set debug-file-directory
10692@item set debug-file-directory @var{directory}
10693Set the directory which @value{GDBN} searches for separate debugging
10694information files to @var{directory}.
10695
10696@kindex show debug-file-directory
10697@item show debug-file-directory
10698Show the directory @value{GDBN} searches for separate debugging
10699information files.
10700
10701@end table
10702
10703@cindex @code{.gnu_debuglink} sections
10704@cindex debug links
10705A debug link is a special section of the executable file named
10706@code{.gnu_debuglink}. The section must contain:
10707
10708@itemize
10709@item
10710A filename, with any leading directory components removed, followed by
10711a zero byte,
10712@item
10713zero to three bytes of padding, as needed to reach the next four-byte
10714boundary within the section, and
10715@item
10716a four-byte CRC checksum, stored in the same endianness used for the
10717executable file itself. The checksum is computed on the debugging
10718information file's full contents by the function given below, passing
10719zero as the @var{crc} argument.
10720@end itemize
10721
10722Any executable file format can carry a debug link, as long as it can
10723contain a section named @code{.gnu_debuglink} with the contents
10724described above.
10725
10726The debugging information file itself should be an ordinary
10727executable, containing a full set of linker symbols, sections, and
10728debugging information. The sections of the debugging information file
10729should have the same names, addresses and sizes as the original file,
10730but they need not contain any data --- much like a @code{.bss} section
10731in an ordinary executable.
10732
10733As of December 2002, there is no standard GNU utility to produce
10734separated executable / debugging information file pairs. Ulrich
10735Drepper's @file{elfutils} package, starting with version 0.53,
10736contains a version of the @code{strip} command such that the command
10737@kbd{strip foo -f foo.debug} removes the debugging information from
10738the executable file @file{foo}, places it in the file
10739@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10740
10741Since there are many different ways to compute CRC's (different
10742polynomials, reversals, byte ordering, etc.), the simplest way to
10743describe the CRC used in @code{.gnu_debuglink} sections is to give the
10744complete code for a function that computes it:
10745
4644b6e3 10746@kindex gnu_debuglink_crc32
5b5d99cf
JB
10747@smallexample
10748unsigned long
10749gnu_debuglink_crc32 (unsigned long crc,
10750 unsigned char *buf, size_t len)
10751@{
10752 static const unsigned long crc32_table[256] =
10753 @{
10754 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10755 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10756 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10757 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10758 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10759 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10760 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10761 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10762 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10763 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10764 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10765 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10766 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10767 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10768 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10769 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10770 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10771 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10772 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10773 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10774 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10775 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10776 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10777 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10778 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10779 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10780 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10781 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10782 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10783 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10784 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10785 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10786 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10787 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10788 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10789 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10790 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10791 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10792 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10793 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10794 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10795 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10796 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10797 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10798 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10799 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10800 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10801 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10802 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10803 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10804 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10805 0x2d02ef8d
10806 @};
10807 unsigned char *end;
10808
10809 crc = ~crc & 0xffffffff;
10810 for (end = buf + len; buf < end; ++buf)
10811 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10812 return ~crc & 0xffffffff;
5b5d99cf
JB
10813@}
10814@end smallexample
10815
10816
6d2ebf8b 10817@node Symbol Errors
c906108c
SS
10818@section Errors reading symbol files
10819
10820While reading a symbol file, @value{GDBN} occasionally encounters problems,
10821such as symbol types it does not recognize, or known bugs in compiler
10822output. By default, @value{GDBN} does not notify you of such problems, since
10823they are relatively common and primarily of interest to people
10824debugging compilers. If you are interested in seeing information
10825about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10826only one message about each such type of problem, no matter how many
10827times the problem occurs; or you can ask @value{GDBN} to print more messages,
10828to see how many times the problems occur, with the @code{set
10829complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10830messages}).
10831
10832The messages currently printed, and their meanings, include:
10833
10834@table @code
10835@item inner block not inside outer block in @var{symbol}
10836
10837The symbol information shows where symbol scopes begin and end
10838(such as at the start of a function or a block of statements). This
10839error indicates that an inner scope block is not fully contained
10840in its outer scope blocks.
10841
10842@value{GDBN} circumvents the problem by treating the inner block as if it had
10843the same scope as the outer block. In the error message, @var{symbol}
10844may be shown as ``@code{(don't know)}'' if the outer block is not a
10845function.
10846
10847@item block at @var{address} out of order
10848
10849The symbol information for symbol scope blocks should occur in
10850order of increasing addresses. This error indicates that it does not
10851do so.
10852
10853@value{GDBN} does not circumvent this problem, and has trouble
10854locating symbols in the source file whose symbols it is reading. (You
10855can often determine what source file is affected by specifying
10856@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10857messages}.)
10858
10859@item bad block start address patched
10860
10861The symbol information for a symbol scope block has a start address
10862smaller than the address of the preceding source line. This is known
10863to occur in the SunOS 4.1.1 (and earlier) C compiler.
10864
10865@value{GDBN} circumvents the problem by treating the symbol scope block as
10866starting on the previous source line.
10867
10868@item bad string table offset in symbol @var{n}
10869
10870@cindex foo
10871Symbol number @var{n} contains a pointer into the string table which is
10872larger than the size of the string table.
10873
10874@value{GDBN} circumvents the problem by considering the symbol to have the
10875name @code{foo}, which may cause other problems if many symbols end up
10876with this name.
10877
10878@item unknown symbol type @code{0x@var{nn}}
10879
7a292a7a
SS
10880The symbol information contains new data types that @value{GDBN} does
10881not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10882uncomprehended information, in hexadecimal.
c906108c 10883
7a292a7a
SS
10884@value{GDBN} circumvents the error by ignoring this symbol information.
10885This usually allows you to debug your program, though certain symbols
c906108c 10886are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10887debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10888on @code{complain}, then go up to the function @code{read_dbx_symtab}
10889and examine @code{*bufp} to see the symbol.
c906108c
SS
10890
10891@item stub type has NULL name
c906108c 10892
7a292a7a 10893@value{GDBN} could not find the full definition for a struct or class.
c906108c 10894
7a292a7a 10895@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10896The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10897information that recent versions of the compiler should have output for
10898it.
c906108c
SS
10899
10900@item info mismatch between compiler and debugger
10901
10902@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10903
c906108c
SS
10904@end table
10905
6d2ebf8b 10906@node Targets
c906108c 10907@chapter Specifying a Debugging Target
7a292a7a 10908
c906108c
SS
10909@cindex debugging target
10910@kindex target
10911
10912A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10913
10914Often, @value{GDBN} runs in the same host environment as your program;
10915in that case, the debugging target is specified as a side effect when
10916you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10917flexibility---for example, running @value{GDBN} on a physically separate
10918host, or controlling a standalone system over a serial port or a
53a5351d
JM
10919realtime system over a TCP/IP connection---you can use the @code{target}
10920command to specify one of the target types configured for @value{GDBN}
10921(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10922
10923@menu
10924* Active Targets:: Active targets
10925* Target Commands:: Commands for managing targets
c906108c
SS
10926* Byte Order:: Choosing target byte order
10927* Remote:: Remote debugging
96baa820 10928* KOD:: Kernel Object Display
c906108c
SS
10929
10930@end menu
10931
6d2ebf8b 10932@node Active Targets
c906108c 10933@section Active targets
7a292a7a 10934
c906108c
SS
10935@cindex stacking targets
10936@cindex active targets
10937@cindex multiple targets
10938
c906108c 10939There are three classes of targets: processes, core files, and
7a292a7a
SS
10940executable files. @value{GDBN} can work concurrently on up to three
10941active targets, one in each class. This allows you to (for example)
10942start a process and inspect its activity without abandoning your work on
10943a core file.
c906108c
SS
10944
10945For example, if you execute @samp{gdb a.out}, then the executable file
10946@code{a.out} is the only active target. If you designate a core file as
10947well---presumably from a prior run that crashed and coredumped---then
10948@value{GDBN} has two active targets and uses them in tandem, looking
10949first in the corefile target, then in the executable file, to satisfy
10950requests for memory addresses. (Typically, these two classes of target
10951are complementary, since core files contain only a program's
10952read-write memory---variables and so on---plus machine status, while
10953executable files contain only the program text and initialized data.)
c906108c
SS
10954
10955When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10956target as well. When a process target is active, all @value{GDBN}
10957commands requesting memory addresses refer to that target; addresses in
10958an active core file or executable file target are obscured while the
10959process target is active.
c906108c 10960
7a292a7a
SS
10961Use the @code{core-file} and @code{exec-file} commands to select a new
10962core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10963files}). To specify as a target a process that is already running, use
7a292a7a
SS
10964the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10965process}).
c906108c 10966
6d2ebf8b 10967@node Target Commands
c906108c
SS
10968@section Commands for managing targets
10969
10970@table @code
10971@item target @var{type} @var{parameters}
7a292a7a
SS
10972Connects the @value{GDBN} host environment to a target machine or
10973process. A target is typically a protocol for talking to debugging
10974facilities. You use the argument @var{type} to specify the type or
10975protocol of the target machine.
c906108c
SS
10976
10977Further @var{parameters} are interpreted by the target protocol, but
10978typically include things like device names or host names to connect
10979with, process numbers, and baud rates.
c906108c
SS
10980
10981The @code{target} command does not repeat if you press @key{RET} again
10982after executing the command.
10983
10984@kindex help target
10985@item help target
10986Displays the names of all targets available. To display targets
10987currently selected, use either @code{info target} or @code{info files}
10988(@pxref{Files, ,Commands to specify files}).
10989
10990@item help target @var{name}
10991Describe a particular target, including any parameters necessary to
10992select it.
10993
10994@kindex set gnutarget
10995@item set gnutarget @var{args}
5d161b24 10996@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10997knows whether it is reading an @dfn{executable},
5d161b24
DB
10998a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10999with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11000with @code{gnutarget} the @code{target} refers to a program, not a machine.
11001
d4f3574e 11002@quotation
c906108c
SS
11003@emph{Warning:} To specify a file format with @code{set gnutarget},
11004you must know the actual BFD name.
d4f3574e 11005@end quotation
c906108c 11006
d4f3574e
SS
11007@noindent
11008@xref{Files, , Commands to specify files}.
c906108c 11009
5d161b24 11010@kindex show gnutarget
c906108c
SS
11011@item show gnutarget
11012Use the @code{show gnutarget} command to display what file format
11013@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11014@value{GDBN} will determine the file format for each file automatically,
11015and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11016@end table
11017
4644b6e3 11018@cindex common targets
c906108c
SS
11019Here are some common targets (available, or not, depending on the GDB
11020configuration):
c906108c
SS
11021
11022@table @code
4644b6e3 11023@kindex target
c906108c 11024@item target exec @var{program}
4644b6e3 11025@cindex executable file target
c906108c
SS
11026An executable file. @samp{target exec @var{program}} is the same as
11027@samp{exec-file @var{program}}.
11028
c906108c 11029@item target core @var{filename}
4644b6e3 11030@cindex core dump file target
c906108c
SS
11031A core dump file. @samp{target core @var{filename}} is the same as
11032@samp{core-file @var{filename}}.
c906108c 11033
c906108c 11034@item target remote @var{dev}
4644b6e3 11035@cindex remote target
c906108c
SS
11036Remote serial target in GDB-specific protocol. The argument @var{dev}
11037specifies what serial device to use for the connection (e.g.
11038@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11039supports the @code{load} command. This is only useful if you have
c906108c
SS
11040some other way of getting the stub to the target system, and you can put
11041it somewhere in memory where it won't get clobbered by the download.
11042
c906108c 11043@item target sim
4644b6e3 11044@cindex built-in simulator target
2df3850c 11045Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11046In general,
474c8240 11047@smallexample
104c1213
JM
11048 target sim
11049 load
11050 run
474c8240 11051@end smallexample
d4f3574e 11052@noindent
104c1213 11053works; however, you cannot assume that a specific memory map, device
d4f3574e 11054drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11055provide these. For info about any processor-specific simulator details,
11056see the appropriate section in @ref{Embedded Processors, ,Embedded
11057Processors}.
11058
c906108c
SS
11059@end table
11060
104c1213 11061Some configurations may include these targets as well:
c906108c
SS
11062
11063@table @code
11064
c906108c 11065@item target nrom @var{dev}
4644b6e3 11066@cindex NetROM ROM emulator target
c906108c
SS
11067NetROM ROM emulator. This target only supports downloading.
11068
c906108c
SS
11069@end table
11070
5d161b24 11071Different targets are available on different configurations of @value{GDBN};
c906108c 11072your configuration may have more or fewer targets.
c906108c
SS
11073
11074Many remote targets require you to download the executable's code
11075once you've successfully established a connection.
11076
11077@table @code
11078
11079@kindex load @var{filename}
11080@item load @var{filename}
c906108c
SS
11081Depending on what remote debugging facilities are configured into
11082@value{GDBN}, the @code{load} command may be available. Where it exists, it
11083is meant to make @var{filename} (an executable) available for debugging
11084on the remote system---by downloading, or dynamic linking, for example.
11085@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11086the @code{add-symbol-file} command.
11087
11088If your @value{GDBN} does not have a @code{load} command, attempting to
11089execute it gets the error message ``@code{You can't do that when your
11090target is @dots{}}''
c906108c
SS
11091
11092The file is loaded at whatever address is specified in the executable.
11093For some object file formats, you can specify the load address when you
11094link the program; for other formats, like a.out, the object file format
11095specifies a fixed address.
11096@c FIXME! This would be a good place for an xref to the GNU linker doc.
11097
c906108c
SS
11098@code{load} does not repeat if you press @key{RET} again after using it.
11099@end table
11100
6d2ebf8b 11101@node Byte Order
c906108c 11102@section Choosing target byte order
7a292a7a 11103
c906108c
SS
11104@cindex choosing target byte order
11105@cindex target byte order
c906108c 11106
172c2a43 11107Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11108offer the ability to run either big-endian or little-endian byte
11109orders. Usually the executable or symbol will include a bit to
11110designate the endian-ness, and you will not need to worry about
11111which to use. However, you may still find it useful to adjust
d4f3574e 11112@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11113
11114@table @code
4644b6e3 11115@kindex set endian
c906108c
SS
11116@item set endian big
11117Instruct @value{GDBN} to assume the target is big-endian.
11118
c906108c
SS
11119@item set endian little
11120Instruct @value{GDBN} to assume the target is little-endian.
11121
c906108c
SS
11122@item set endian auto
11123Instruct @value{GDBN} to use the byte order associated with the
11124executable.
11125
11126@item show endian
11127Display @value{GDBN}'s current idea of the target byte order.
11128
11129@end table
11130
11131Note that these commands merely adjust interpretation of symbolic
11132data on the host, and that they have absolutely no effect on the
11133target system.
11134
6d2ebf8b 11135@node Remote
c906108c
SS
11136@section Remote debugging
11137@cindex remote debugging
11138
11139If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11140@value{GDBN} in the usual way, it is often useful to use remote debugging.
11141For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11142or on a small system which does not have a general purpose operating system
11143powerful enough to run a full-featured debugger.
11144
11145Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11146to make this work with particular debugging targets. In addition,
5d161b24 11147@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11148but not specific to any particular target system) which you can use if you
11149write the remote stubs---the code that runs on the remote system to
11150communicate with @value{GDBN}.
11151
11152Other remote targets may be available in your
11153configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11154
6f05cf9f
AC
11155@node KOD
11156@section Kernel Object Display
6f05cf9f 11157@cindex kernel object display
6f05cf9f
AC
11158@cindex KOD
11159
11160Some targets support kernel object display. Using this facility,
11161@value{GDBN} communicates specially with the underlying operating system
11162and can display information about operating system-level objects such as
11163mutexes and other synchronization objects. Exactly which objects can be
11164displayed is determined on a per-OS basis.
11165
3bbe9696 11166@kindex set os
6f05cf9f
AC
11167Use the @code{set os} command to set the operating system. This tells
11168@value{GDBN} which kernel object display module to initialize:
11169
474c8240 11170@smallexample
6f05cf9f 11171(@value{GDBP}) set os cisco
474c8240 11172@end smallexample
6f05cf9f 11173
3bbe9696
EZ
11174@kindex show os
11175The associated command @code{show os} displays the operating system
11176set with the @code{set os} command; if no operating system has been
11177set, @code{show os} will display an empty string @samp{""}.
11178
6f05cf9f
AC
11179If @code{set os} succeeds, @value{GDBN} will display some information
11180about the operating system, and will create a new @code{info} command
11181which can be used to query the target. The @code{info} command is named
11182after the operating system:
c906108c 11183
3bbe9696 11184@kindex info cisco
474c8240 11185@smallexample
6f05cf9f
AC
11186(@value{GDBP}) info cisco
11187List of Cisco Kernel Objects
11188Object Description
11189any Any and all objects
474c8240 11190@end smallexample
6f05cf9f
AC
11191
11192Further subcommands can be used to query about particular objects known
11193by the kernel.
11194
3bbe9696
EZ
11195There is currently no way to determine whether a given operating
11196system is supported other than to try setting it with @kbd{set os
11197@var{name}}, where @var{name} is the name of the operating system you
11198want to try.
6f05cf9f
AC
11199
11200
11201@node Remote Debugging
11202@chapter Debugging remote programs
11203
6b2f586d 11204@menu
07f31aa6 11205* Connecting:: Connecting to a remote target
6b2f586d
AC
11206* Server:: Using the gdbserver program
11207* NetWare:: Using the gdbserve.nlm program
501eef12 11208* Remote configuration:: Remote configuration
6b2f586d 11209* remote stub:: Implementing a remote stub
6b2f586d
AC
11210@end menu
11211
07f31aa6
DJ
11212@node Connecting
11213@section Connecting to a remote target
11214
11215On the @value{GDBN} host machine, you will need an unstripped copy of
11216your program, since @value{GDBN} needs symobl and debugging information.
11217Start up @value{GDBN} as usual, using the name of the local copy of your
11218program as the first argument.
11219
11220@cindex serial line, @code{target remote}
11221If you're using a serial line, you may want to give @value{GDBN} the
11222@w{@samp{--baud}} option, or use the @code{set remotebaud} command
11223before the @code{target} command.
11224
11225After that, use @code{target remote} to establish communications with
11226the target machine. Its argument specifies how to communicate---either
11227via a devicename attached to a direct serial line, or a TCP or UDP port
11228(possibly to a terminal server which in turn has a serial line to the
11229target). For example, to use a serial line connected to the device
11230named @file{/dev/ttyb}:
11231
11232@smallexample
11233target remote /dev/ttyb
11234@end smallexample
11235
11236@cindex TCP port, @code{target remote}
11237To use a TCP connection, use an argument of the form
11238@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11239For example, to connect to port 2828 on a
11240terminal server named @code{manyfarms}:
11241
11242@smallexample
11243target remote manyfarms:2828
11244@end smallexample
11245
11246If your remote target is actually running on the same machine as
11247your debugger session (e.g.@: a simulator of your target running on
11248the same host), you can omit the hostname. For example, to connect
11249to port 1234 on your local machine:
11250
11251@smallexample
11252target remote :1234
11253@end smallexample
11254@noindent
11255
11256Note that the colon is still required here.
11257
11258@cindex UDP port, @code{target remote}
11259To use a UDP connection, use an argument of the form
11260@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11261on a terminal server named @code{manyfarms}:
11262
11263@smallexample
11264target remote udp:manyfarms:2828
11265@end smallexample
11266
11267When using a UDP connection for remote debugging, you should keep in mind
11268that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11269busy or unreliable networks, which will cause havoc with your debugging
11270session.
11271
11272Now you can use all the usual commands to examine and change data and to
11273step and continue the remote program.
11274
11275@cindex interrupting remote programs
11276@cindex remote programs, interrupting
11277Whenever @value{GDBN} is waiting for the remote program, if you type the
11278interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11279program. This may or may not succeed, depending in part on the hardware
11280and the serial drivers the remote system uses. If you type the
11281interrupt character once again, @value{GDBN} displays this prompt:
11282
11283@smallexample
11284Interrupted while waiting for the program.
11285Give up (and stop debugging it)? (y or n)
11286@end smallexample
11287
11288If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11289(If you decide you want to try again later, you can use @samp{target
11290remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11291goes back to waiting.
11292
11293@table @code
11294@kindex detach (remote)
11295@item detach
11296When you have finished debugging the remote program, you can use the
11297@code{detach} command to release it from @value{GDBN} control.
11298Detaching from the target normally resumes its execution, but the results
11299will depend on your particular remote stub. After the @code{detach}
11300command, @value{GDBN} is free to connect to another target.
11301
11302@kindex disconnect
11303@item disconnect
11304The @code{disconnect} command behaves like @code{detach}, except that
11305the target is generally not resumed. It will wait for @value{GDBN}
11306(this instance or another one) to connect and continue debugging. After
11307the @code{disconnect} command, @value{GDBN} is again free to connect to
11308another target.
11309@end table
11310
6f05cf9f
AC
11311@node Server
11312@section Using the @code{gdbserver} program
11313
11314@kindex gdbserver
11315@cindex remote connection without stubs
11316@code{gdbserver} is a control program for Unix-like systems, which
11317allows you to connect your program with a remote @value{GDBN} via
11318@code{target remote}---but without linking in the usual debugging stub.
11319
11320@code{gdbserver} is not a complete replacement for the debugging stubs,
11321because it requires essentially the same operating-system facilities
11322that @value{GDBN} itself does. In fact, a system that can run
11323@code{gdbserver} to connect to a remote @value{GDBN} could also run
11324@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11325because it is a much smaller program than @value{GDBN} itself. It is
11326also easier to port than all of @value{GDBN}, so you may be able to get
11327started more quickly on a new system by using @code{gdbserver}.
11328Finally, if you develop code for real-time systems, you may find that
11329the tradeoffs involved in real-time operation make it more convenient to
11330do as much development work as possible on another system, for example
11331by cross-compiling. You can use @code{gdbserver} to make a similar
11332choice for debugging.
11333
11334@value{GDBN} and @code{gdbserver} communicate via either a serial line
11335or a TCP connection, using the standard @value{GDBN} remote serial
11336protocol.
11337
11338@table @emph
11339@item On the target machine,
11340you need to have a copy of the program you want to debug.
11341@code{gdbserver} does not need your program's symbol table, so you can
11342strip the program if necessary to save space. @value{GDBN} on the host
11343system does all the symbol handling.
11344
11345To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11346the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11347syntax is:
11348
11349@smallexample
11350target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11351@end smallexample
11352
11353@var{comm} is either a device name (to use a serial line) or a TCP
11354hostname and portnumber. For example, to debug Emacs with the argument
11355@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11356@file{/dev/com1}:
11357
11358@smallexample
11359target> gdbserver /dev/com1 emacs foo.txt
11360@end smallexample
11361
11362@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11363with it.
11364
11365To use a TCP connection instead of a serial line:
11366
11367@smallexample
11368target> gdbserver host:2345 emacs foo.txt
11369@end smallexample
11370
11371The only difference from the previous example is the first argument,
11372specifying that you are communicating with the host @value{GDBN} via
11373TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11374expect a TCP connection from machine @samp{host} to local TCP port 2345.
11375(Currently, the @samp{host} part is ignored.) You can choose any number
11376you want for the port number as long as it does not conflict with any
11377TCP ports already in use on the target system (for example, @code{23} is
11378reserved for @code{telnet}).@footnote{If you choose a port number that
11379conflicts with another service, @code{gdbserver} prints an error message
11380and exits.} You must use the same port number with the host @value{GDBN}
11381@code{target remote} command.
11382
56460a61
DJ
11383On some targets, @code{gdbserver} can also attach to running programs.
11384This is accomplished via the @code{--attach} argument. The syntax is:
11385
11386@smallexample
11387target> gdbserver @var{comm} --attach @var{pid}
11388@end smallexample
11389
11390@var{pid} is the process ID of a currently running process. It isn't necessary
11391to point @code{gdbserver} at a binary for the running process.
11392
b1fe9455
DJ
11393@pindex pidof
11394@cindex attach to a program by name
11395You can debug processes by name instead of process ID if your target has the
11396@code{pidof} utility:
11397
11398@smallexample
11399target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11400@end smallexample
11401
11402In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11403has multiple threads, most versions of @code{pidof} support the
11404@code{-s} option to only return the first process ID.
11405
07f31aa6
DJ
11406@item On the host machine,
11407connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11408For TCP connections, you must start up @code{gdbserver} prior to using
11409the @code{target remote} command. Otherwise you may get an error whose
11410text depends on the host system, but which usually looks something like
07f31aa6
DJ
11411@samp{Connection refused}. You don't need to use the @code{load}
11412command in @value{GDBN} when using gdbserver, since the program is
11413already on the target.
11414
6f05cf9f
AC
11415@end table
11416
11417@node NetWare
11418@section Using the @code{gdbserve.nlm} program
11419
11420@kindex gdbserve.nlm
11421@code{gdbserve.nlm} is a control program for NetWare systems, which
11422allows you to connect your program with a remote @value{GDBN} via
11423@code{target remote}.
11424
11425@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11426using the standard @value{GDBN} remote serial protocol.
11427
11428@table @emph
11429@item On the target machine,
11430you need to have a copy of the program you want to debug.
11431@code{gdbserve.nlm} does not need your program's symbol table, so you
11432can strip the program if necessary to save space. @value{GDBN} on the
11433host system does all the symbol handling.
11434
11435To use the server, you must tell it how to communicate with
11436@value{GDBN}; the name of your program; and the arguments for your
11437program. The syntax is:
11438
11439@smallexample
11440load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11441 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11442@end smallexample
11443
11444@var{board} and @var{port} specify the serial line; @var{baud} specifies
11445the baud rate used by the connection. @var{port} and @var{node} default
11446to 0, @var{baud} defaults to 9600@dmn{bps}.
11447
11448For example, to debug Emacs with the argument @samp{foo.txt}and
11449communicate with @value{GDBN} over serial port number 2 or board 1
11450using a 19200@dmn{bps} connection:
11451
11452@smallexample
11453load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11454@end smallexample
11455
07f31aa6
DJ
11456@item
11457On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11458Connecting to a remote target}).
6f05cf9f 11459
6f05cf9f
AC
11460@end table
11461
501eef12
AC
11462@node Remote configuration
11463@section Remote configuration
11464
11465The following configuration options are available when debugging remote
11466programs:
11467
11468@table @code
11469@kindex set remote hardware-watchpoint-limit
11470@kindex set remote hardware-breakpoint-limit
11471@anchor{set remote hardware-watchpoint-limit}
11472@anchor{set remote hardware-breakpoint-limit}
11473@item set remote hardware-watchpoint-limit @var{limit}
11474@itemx set remote hardware-breakpoint-limit @var{limit}
11475Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11476watchpoints. A limit of -1, the default, is treated as unlimited.
11477@end table
11478
6f05cf9f
AC
11479@node remote stub
11480@section Implementing a remote stub
7a292a7a 11481
8e04817f
AC
11482@cindex debugging stub, example
11483@cindex remote stub, example
11484@cindex stub example, remote debugging
11485The stub files provided with @value{GDBN} implement the target side of the
11486communication protocol, and the @value{GDBN} side is implemented in the
11487@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
11488these subroutines to communicate, and ignore the details. (If you're
11489implementing your own stub file, you can still ignore the details: start
11490with one of the existing stub files. @file{sparc-stub.c} is the best
11491organized, and therefore the easiest to read.)
11492
104c1213
JM
11493@cindex remote serial debugging, overview
11494To debug a program running on another machine (the debugging
11495@dfn{target} machine), you must first arrange for all the usual
11496prerequisites for the program to run by itself. For example, for a C
11497program, you need:
c906108c 11498
104c1213
JM
11499@enumerate
11500@item
11501A startup routine to set up the C runtime environment; these usually
11502have a name like @file{crt0}. The startup routine may be supplied by
11503your hardware supplier, or you may have to write your own.
96baa820 11504
5d161b24 11505@item
d4f3574e 11506A C subroutine library to support your program's
104c1213 11507subroutine calls, notably managing input and output.
96baa820 11508
104c1213
JM
11509@item
11510A way of getting your program to the other machine---for example, a
11511download program. These are often supplied by the hardware
11512manufacturer, but you may have to write your own from hardware
11513documentation.
11514@end enumerate
96baa820 11515
104c1213
JM
11516The next step is to arrange for your program to use a serial port to
11517communicate with the machine where @value{GDBN} is running (the @dfn{host}
11518machine). In general terms, the scheme looks like this:
96baa820 11519
104c1213
JM
11520@table @emph
11521@item On the host,
11522@value{GDBN} already understands how to use this protocol; when everything
11523else is set up, you can simply use the @samp{target remote} command
11524(@pxref{Targets,,Specifying a Debugging Target}).
11525
11526@item On the target,
11527you must link with your program a few special-purpose subroutines that
11528implement the @value{GDBN} remote serial protocol. The file containing these
11529subroutines is called a @dfn{debugging stub}.
11530
11531On certain remote targets, you can use an auxiliary program
11532@code{gdbserver} instead of linking a stub into your program.
11533@xref{Server,,Using the @code{gdbserver} program}, for details.
11534@end table
96baa820 11535
104c1213
JM
11536The debugging stub is specific to the architecture of the remote
11537machine; for example, use @file{sparc-stub.c} to debug programs on
11538@sc{sparc} boards.
96baa820 11539
104c1213
JM
11540@cindex remote serial stub list
11541These working remote stubs are distributed with @value{GDBN}:
96baa820 11542
104c1213
JM
11543@table @code
11544
11545@item i386-stub.c
41afff9a 11546@cindex @file{i386-stub.c}
104c1213
JM
11547@cindex Intel
11548@cindex i386
11549For Intel 386 and compatible architectures.
11550
11551@item m68k-stub.c
41afff9a 11552@cindex @file{m68k-stub.c}
104c1213
JM
11553@cindex Motorola 680x0
11554@cindex m680x0
11555For Motorola 680x0 architectures.
11556
11557@item sh-stub.c
41afff9a 11558@cindex @file{sh-stub.c}
172c2a43 11559@cindex Renesas
104c1213 11560@cindex SH
172c2a43 11561For Renesas SH architectures.
104c1213
JM
11562
11563@item sparc-stub.c
41afff9a 11564@cindex @file{sparc-stub.c}
104c1213
JM
11565@cindex Sparc
11566For @sc{sparc} architectures.
11567
11568@item sparcl-stub.c
41afff9a 11569@cindex @file{sparcl-stub.c}
104c1213
JM
11570@cindex Fujitsu
11571@cindex SparcLite
11572For Fujitsu @sc{sparclite} architectures.
11573
11574@end table
11575
11576The @file{README} file in the @value{GDBN} distribution may list other
11577recently added stubs.
11578
11579@menu
11580* Stub Contents:: What the stub can do for you
11581* Bootstrapping:: What you must do for the stub
11582* Debug Session:: Putting it all together
104c1213
JM
11583@end menu
11584
6d2ebf8b 11585@node Stub Contents
6f05cf9f 11586@subsection What the stub can do for you
104c1213
JM
11587
11588@cindex remote serial stub
11589The debugging stub for your architecture supplies these three
11590subroutines:
11591
11592@table @code
11593@item set_debug_traps
4644b6e3 11594@findex set_debug_traps
104c1213
JM
11595@cindex remote serial stub, initialization
11596This routine arranges for @code{handle_exception} to run when your
11597program stops. You must call this subroutine explicitly near the
11598beginning of your program.
11599
11600@item handle_exception
4644b6e3 11601@findex handle_exception
104c1213
JM
11602@cindex remote serial stub, main routine
11603This is the central workhorse, but your program never calls it
11604explicitly---the setup code arranges for @code{handle_exception} to
11605run when a trap is triggered.
11606
11607@code{handle_exception} takes control when your program stops during
11608execution (for example, on a breakpoint), and mediates communications
11609with @value{GDBN} on the host machine. This is where the communications
11610protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11611representative on the target machine. It begins by sending summary
104c1213
JM
11612information on the state of your program, then continues to execute,
11613retrieving and transmitting any information @value{GDBN} needs, until you
11614execute a @value{GDBN} command that makes your program resume; at that point,
11615@code{handle_exception} returns control to your own code on the target
5d161b24 11616machine.
104c1213
JM
11617
11618@item breakpoint
11619@cindex @code{breakpoint} subroutine, remote
11620Use this auxiliary subroutine to make your program contain a
11621breakpoint. Depending on the particular situation, this may be the only
11622way for @value{GDBN} to get control. For instance, if your target
11623machine has some sort of interrupt button, you won't need to call this;
11624pressing the interrupt button transfers control to
11625@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11626simply receiving characters on the serial port may also trigger a trap;
11627again, in that situation, you don't need to call @code{breakpoint} from
11628your own program---simply running @samp{target remote} from the host
5d161b24 11629@value{GDBN} session gets control.
104c1213
JM
11630
11631Call @code{breakpoint} if none of these is true, or if you simply want
11632to make certain your program stops at a predetermined point for the
11633start of your debugging session.
11634@end table
11635
6d2ebf8b 11636@node Bootstrapping
6f05cf9f 11637@subsection What you must do for the stub
104c1213
JM
11638
11639@cindex remote stub, support routines
11640The debugging stubs that come with @value{GDBN} are set up for a particular
11641chip architecture, but they have no information about the rest of your
11642debugging target machine.
11643
11644First of all you need to tell the stub how to communicate with the
11645serial port.
11646
11647@table @code
11648@item int getDebugChar()
4644b6e3 11649@findex getDebugChar
104c1213
JM
11650Write this subroutine to read a single character from the serial port.
11651It may be identical to @code{getchar} for your target system; a
11652different name is used to allow you to distinguish the two if you wish.
11653
11654@item void putDebugChar(int)
4644b6e3 11655@findex putDebugChar
104c1213 11656Write this subroutine to write a single character to the serial port.
5d161b24 11657It may be identical to @code{putchar} for your target system; a
104c1213
JM
11658different name is used to allow you to distinguish the two if you wish.
11659@end table
11660
11661@cindex control C, and remote debugging
11662@cindex interrupting remote targets
11663If you want @value{GDBN} to be able to stop your program while it is
11664running, you need to use an interrupt-driven serial driver, and arrange
11665for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11666character). That is the character which @value{GDBN} uses to tell the
11667remote system to stop.
11668
11669Getting the debugging target to return the proper status to @value{GDBN}
11670probably requires changes to the standard stub; one quick and dirty way
11671is to just execute a breakpoint instruction (the ``dirty'' part is that
11672@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11673
11674Other routines you need to supply are:
11675
11676@table @code
11677@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 11678@findex exceptionHandler
104c1213
JM
11679Write this function to install @var{exception_address} in the exception
11680handling tables. You need to do this because the stub does not have any
11681way of knowing what the exception handling tables on your target system
11682are like (for example, the processor's table might be in @sc{rom},
11683containing entries which point to a table in @sc{ram}).
11684@var{exception_number} is the exception number which should be changed;
11685its meaning is architecture-dependent (for example, different numbers
11686might represent divide by zero, misaligned access, etc). When this
11687exception occurs, control should be transferred directly to
11688@var{exception_address}, and the processor state (stack, registers,
11689and so on) should be just as it is when a processor exception occurs. So if
11690you want to use a jump instruction to reach @var{exception_address}, it
11691should be a simple jump, not a jump to subroutine.
11692
11693For the 386, @var{exception_address} should be installed as an interrupt
11694gate so that interrupts are masked while the handler runs. The gate
11695should be at privilege level 0 (the most privileged level). The
11696@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11697help from @code{exceptionHandler}.
11698
11699@item void flush_i_cache()
4644b6e3 11700@findex flush_i_cache
d4f3574e 11701On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11702instruction cache, if any, on your target machine. If there is no
11703instruction cache, this subroutine may be a no-op.
11704
11705On target machines that have instruction caches, @value{GDBN} requires this
11706function to make certain that the state of your program is stable.
11707@end table
11708
11709@noindent
11710You must also make sure this library routine is available:
11711
11712@table @code
11713@item void *memset(void *, int, int)
4644b6e3 11714@findex memset
104c1213
JM
11715This is the standard library function @code{memset} that sets an area of
11716memory to a known value. If you have one of the free versions of
11717@code{libc.a}, @code{memset} can be found there; otherwise, you must
11718either obtain it from your hardware manufacturer, or write your own.
11719@end table
11720
11721If you do not use the GNU C compiler, you may need other standard
11722library subroutines as well; this varies from one stub to another,
11723but in general the stubs are likely to use any of the common library
d4f3574e 11724subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11725
11726
6d2ebf8b 11727@node Debug Session
6f05cf9f 11728@subsection Putting it all together
104c1213
JM
11729
11730@cindex remote serial debugging summary
11731In summary, when your program is ready to debug, you must follow these
11732steps.
11733
11734@enumerate
11735@item
6d2ebf8b 11736Make sure you have defined the supporting low-level routines
104c1213
JM
11737(@pxref{Bootstrapping,,What you must do for the stub}):
11738@display
11739@code{getDebugChar}, @code{putDebugChar},
11740@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11741@end display
11742
11743@item
11744Insert these lines near the top of your program:
11745
474c8240 11746@smallexample
104c1213
JM
11747set_debug_traps();
11748breakpoint();
474c8240 11749@end smallexample
104c1213
JM
11750
11751@item
11752For the 680x0 stub only, you need to provide a variable called
11753@code{exceptionHook}. Normally you just use:
11754
474c8240 11755@smallexample
104c1213 11756void (*exceptionHook)() = 0;
474c8240 11757@end smallexample
104c1213 11758
d4f3574e 11759@noindent
104c1213 11760but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11761function in your program, that function is called when
104c1213
JM
11762@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11763error). The function indicated by @code{exceptionHook} is called with
11764one parameter: an @code{int} which is the exception number.
11765
11766@item
11767Compile and link together: your program, the @value{GDBN} debugging stub for
11768your target architecture, and the supporting subroutines.
11769
11770@item
11771Make sure you have a serial connection between your target machine and
11772the @value{GDBN} host, and identify the serial port on the host.
11773
11774@item
11775@c The "remote" target now provides a `load' command, so we should
11776@c document that. FIXME.
11777Download your program to your target machine (or get it there by
11778whatever means the manufacturer provides), and start it.
11779
11780@item
07f31aa6
DJ
11781Start @value{GDBN} on the host, and connect to the target
11782(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11783
104c1213
JM
11784@end enumerate
11785
8e04817f
AC
11786@node Configurations
11787@chapter Configuration-Specific Information
104c1213 11788
8e04817f
AC
11789While nearly all @value{GDBN} commands are available for all native and
11790cross versions of the debugger, there are some exceptions. This chapter
11791describes things that are only available in certain configurations.
104c1213 11792
8e04817f
AC
11793There are three major categories of configurations: native
11794configurations, where the host and target are the same, embedded
11795operating system configurations, which are usually the same for several
11796different processor architectures, and bare embedded processors, which
11797are quite different from each other.
104c1213 11798
8e04817f
AC
11799@menu
11800* Native::
11801* Embedded OS::
11802* Embedded Processors::
11803* Architectures::
11804@end menu
104c1213 11805
8e04817f
AC
11806@node Native
11807@section Native
104c1213 11808
8e04817f
AC
11809This section describes details specific to particular native
11810configurations.
6cf7e474 11811
8e04817f
AC
11812@menu
11813* HP-UX:: HP-UX
7561d450 11814* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
11815* SVR4 Process Information:: SVR4 process information
11816* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11817* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11818@end menu
6cf7e474 11819
8e04817f
AC
11820@node HP-UX
11821@subsection HP-UX
104c1213 11822
8e04817f
AC
11823On HP-UX systems, if you refer to a function or variable name that
11824begins with a dollar sign, @value{GDBN} searches for a user or system
11825name first, before it searches for a convenience variable.
104c1213 11826
7561d450
MK
11827@node BSD libkvm Interface
11828@subsection BSD libkvm Interface
11829
11830@cindex libkvm
11831@cindex kernel memory image
11832@cindex kernel crash dump
11833
11834BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
11835interface that provides a uniform interface for accessing kernel virtual
11836memory images, including live systems and crash dumps. @value{GDBN}
11837uses this interface to allow you to debug live kernels and kernel crash
11838dumps on many native BSD configurations. This is implemented as a
11839special @code{kvm} debugging target. For debugging a live system, load
11840the currently running kernel into @value{GDBN} and connect to the
11841@code{kvm} target:
11842
11843@smallexample
11844(@value{GDBP}) @b{target kvm}
11845@end smallexample
11846
11847For debugging crash dumps, provide the file name of the crash dump as an
11848argument:
11849
11850@smallexample
11851(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
11852@end smallexample
11853
11854Once connected to the @code{kvm} target, the following commands are
11855available:
11856
11857@table @code
11858@kindex kvm
11859@item kvm pcb
11860Set current context from pcb address.
11861
11862@item kvm proc
11863Set current context from proc address. This command isn't available on
11864modern FreeBSD systems.
11865@end table
11866
8e04817f
AC
11867@node SVR4 Process Information
11868@subsection SVR4 process information
60bf7e09
EZ
11869@cindex /proc
11870@cindex examine process image
11871@cindex process info via @file{/proc}
104c1213 11872
60bf7e09
EZ
11873Many versions of SVR4 and compatible systems provide a facility called
11874@samp{/proc} that can be used to examine the image of a running
11875process using file-system subroutines. If @value{GDBN} is configured
11876for an operating system with this facility, the command @code{info
11877proc} is available to report information about the process running
11878your program, or about any process running on your system. @code{info
11879proc} works only on SVR4 systems that include the @code{procfs} code.
11880This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
11881Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 11882
8e04817f
AC
11883@table @code
11884@kindex info proc
60bf7e09 11885@cindex process ID
8e04817f 11886@item info proc
60bf7e09
EZ
11887@itemx info proc @var{process-id}
11888Summarize available information about any running process. If a
11889process ID is specified by @var{process-id}, display information about
11890that process; otherwise display information about the program being
11891debugged. The summary includes the debugged process ID, the command
11892line used to invoke it, its current working directory, and its
11893executable file's absolute file name.
11894
11895On some systems, @var{process-id} can be of the form
11896@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
11897within a process. If the optional @var{pid} part is missing, it means
11898a thread from the process being debugged (the leading @samp{/} still
11899needs to be present, or else @value{GDBN} will interpret the number as
11900a process ID rather than a thread ID).
6cf7e474 11901
8e04817f 11902@item info proc mappings
60bf7e09
EZ
11903@cindex memory address space mappings
11904Report the memory address space ranges accessible in the program, with
11905information on whether the process has read, write, or execute access
11906rights to each range. On @sc{gnu}/Linux systems, each memory range
11907includes the object file which is mapped to that range, instead of the
11908memory access rights to that range.
11909
11910@item info proc stat
11911@itemx info proc status
11912@cindex process detailed status information
11913These subcommands are specific to @sc{gnu}/Linux systems. They show
11914the process-related information, including the user ID and group ID;
11915how many threads are there in the process; its virtual memory usage;
11916the signals that are pending, blocked, and ignored; its TTY; its
11917consumption of system and user time; its stack size; its @samp{nice}
11918value; etc. For more information, see the @samp{proc(5)} man page
11919(type @kbd{man 5 proc} from your shell prompt).
11920
11921@item info proc all
11922Show all the information about the process described under all of the
11923above @code{info proc} subcommands.
11924
8e04817f
AC
11925@ignore
11926@comment These sub-options of 'info proc' were not included when
11927@comment procfs.c was re-written. Keep their descriptions around
11928@comment against the day when someone finds the time to put them back in.
11929@kindex info proc times
11930@item info proc times
11931Starting time, user CPU time, and system CPU time for your program and
11932its children.
6cf7e474 11933
8e04817f
AC
11934@kindex info proc id
11935@item info proc id
11936Report on the process IDs related to your program: its own process ID,
11937the ID of its parent, the process group ID, and the session ID.
8e04817f
AC
11938@end ignore
11939@end table
104c1213 11940
8e04817f
AC
11941@node DJGPP Native
11942@subsection Features for Debugging @sc{djgpp} Programs
11943@cindex @sc{djgpp} debugging
11944@cindex native @sc{djgpp} debugging
11945@cindex MS-DOS-specific commands
104c1213 11946
8e04817f
AC
11947@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11948MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11949that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11950top of real-mode DOS systems and their emulations.
104c1213 11951
8e04817f
AC
11952@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11953defines a few commands specific to the @sc{djgpp} port. This
11954subsection describes those commands.
104c1213 11955
8e04817f
AC
11956@table @code
11957@kindex info dos
11958@item info dos
11959This is a prefix of @sc{djgpp}-specific commands which print
11960information about the target system and important OS structures.
f1251bdd 11961
8e04817f
AC
11962@kindex sysinfo
11963@cindex MS-DOS system info
11964@cindex free memory information (MS-DOS)
11965@item info dos sysinfo
11966This command displays assorted information about the underlying
11967platform: the CPU type and features, the OS version and flavor, the
11968DPMI version, and the available conventional and DPMI memory.
104c1213 11969
8e04817f
AC
11970@cindex GDT
11971@cindex LDT
11972@cindex IDT
11973@cindex segment descriptor tables
11974@cindex descriptor tables display
11975@item info dos gdt
11976@itemx info dos ldt
11977@itemx info dos idt
11978These 3 commands display entries from, respectively, Global, Local,
11979and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11980tables are data structures which store a descriptor for each segment
11981that is currently in use. The segment's selector is an index into a
11982descriptor table; the table entry for that index holds the
11983descriptor's base address and limit, and its attributes and access
11984rights.
104c1213 11985
8e04817f
AC
11986A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11987segment (used for both data and the stack), and a DOS segment (which
11988allows access to DOS/BIOS data structures and absolute addresses in
11989conventional memory). However, the DPMI host will usually define
11990additional segments in order to support the DPMI environment.
d4f3574e 11991
8e04817f
AC
11992@cindex garbled pointers
11993These commands allow to display entries from the descriptor tables.
11994Without an argument, all entries from the specified table are
11995displayed. An argument, which should be an integer expression, means
11996display a single entry whose index is given by the argument. For
11997example, here's a convenient way to display information about the
11998debugged program's data segment:
104c1213 11999
8e04817f
AC
12000@smallexample
12001@exdent @code{(@value{GDBP}) info dos ldt $ds}
12002@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12003@end smallexample
104c1213 12004
8e04817f
AC
12005@noindent
12006This comes in handy when you want to see whether a pointer is outside
12007the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12008
8e04817f
AC
12009@cindex page tables display (MS-DOS)
12010@item info dos pde
12011@itemx info dos pte
12012These two commands display entries from, respectively, the Page
12013Directory and the Page Tables. Page Directories and Page Tables are
12014data structures which control how virtual memory addresses are mapped
12015into physical addresses. A Page Table includes an entry for every
12016page of memory that is mapped into the program's address space; there
12017may be several Page Tables, each one holding up to 4096 entries. A
12018Page Directory has up to 4096 entries, one each for every Page Table
12019that is currently in use.
104c1213 12020
8e04817f
AC
12021Without an argument, @kbd{info dos pde} displays the entire Page
12022Directory, and @kbd{info dos pte} displays all the entries in all of
12023the Page Tables. An argument, an integer expression, given to the
12024@kbd{info dos pde} command means display only that entry from the Page
12025Directory table. An argument given to the @kbd{info dos pte} command
12026means display entries from a single Page Table, the one pointed to by
12027the specified entry in the Page Directory.
104c1213 12028
8e04817f
AC
12029@cindex direct memory access (DMA) on MS-DOS
12030These commands are useful when your program uses @dfn{DMA} (Direct
12031Memory Access), which needs physical addresses to program the DMA
12032controller.
104c1213 12033
8e04817f 12034These commands are supported only with some DPMI servers.
104c1213 12035
8e04817f
AC
12036@cindex physical address from linear address
12037@item info dos address-pte @var{addr}
12038This command displays the Page Table entry for a specified linear
12039address. The argument linear address @var{addr} should already have the
12040appropriate segment's base address added to it, because this command
12041accepts addresses which may belong to @emph{any} segment. For
12042example, here's how to display the Page Table entry for the page where
12043the variable @code{i} is stored:
104c1213 12044
b383017d 12045@smallexample
8e04817f
AC
12046@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12047@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12048@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12049@end smallexample
104c1213 12050
8e04817f
AC
12051@noindent
12052This says that @code{i} is stored at offset @code{0xd30} from the page
12053whose physical base address is @code{0x02698000}, and prints all the
12054attributes of that page.
104c1213 12055
8e04817f
AC
12056Note that you must cast the addresses of variables to a @code{char *},
12057since otherwise the value of @code{__djgpp_base_address}, the base
12058address of all variables and functions in a @sc{djgpp} program, will
12059be added using the rules of C pointer arithmetics: if @code{i} is
12060declared an @code{int}, @value{GDBN} will add 4 times the value of
12061@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12062
8e04817f
AC
12063Here's another example, it displays the Page Table entry for the
12064transfer buffer:
104c1213 12065
8e04817f
AC
12066@smallexample
12067@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12068@exdent @code{Page Table entry for address 0x29110:}
12069@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12070@end smallexample
104c1213 12071
8e04817f
AC
12072@noindent
12073(The @code{+ 3} offset is because the transfer buffer's address is the
120743rd member of the @code{_go32_info_block} structure.) The output of
12075this command clearly shows that addresses in conventional memory are
12076mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 12077
8e04817f
AC
12078This command is supported only with some DPMI servers.
12079@end table
104c1213 12080
78c47bea
PM
12081@node Cygwin Native
12082@subsection Features for Debugging MS Windows PE executables
12083@cindex MS Windows debugging
12084@cindex native Cygwin debugging
12085@cindex Cygwin-specific commands
12086
be448670
CF
12087@value{GDBN} supports native debugging of MS Windows programs, including
12088DLLs with and without symbolic debugging information. There are various
12089additional Cygwin-specific commands, described in this subsection. The
12090subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12091that have no debugging symbols.
12092
78c47bea
PM
12093
12094@table @code
12095@kindex info w32
12096@item info w32
12097This is a prefix of MS Windows specific commands which print
12098information about the target system and important OS structures.
12099
12100@item info w32 selector
12101This command displays information returned by
12102the Win32 API @code{GetThreadSelectorEntry} function.
12103It takes an optional argument that is evaluated to
12104a long value to give the information about this given selector.
12105Without argument, this command displays information
12106about the the six segment registers.
12107
12108@kindex info dll
12109@item info dll
12110This is a Cygwin specific alias of info shared.
12111
12112@kindex dll-symbols
12113@item dll-symbols
12114This command loads symbols from a dll similarly to
12115add-sym command but without the need to specify a base address.
12116
b383017d 12117@kindex set new-console
78c47bea 12118@item set new-console @var{mode}
b383017d 12119If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12120be started in a new console on next start.
12121If @var{mode} is @code{off}i, the debuggee will
12122be started in the same console as the debugger.
12123
12124@kindex show new-console
12125@item show new-console
12126Displays whether a new console is used
12127when the debuggee is started.
12128
12129@kindex set new-group
12130@item set new-group @var{mode}
12131This boolean value controls whether the debuggee should
12132start a new group or stay in the same group as the debugger.
12133This affects the way the Windows OS handles
12134Ctrl-C.
12135
12136@kindex show new-group
12137@item show new-group
12138Displays current value of new-group boolean.
12139
12140@kindex set debugevents
12141@item set debugevents
12142This boolean value adds debug output concerning events seen by the debugger.
12143
12144@kindex set debugexec
12145@item set debugexec
b383017d 12146This boolean value adds debug output concerning execute events
78c47bea
PM
12147seen by the debugger.
12148
12149@kindex set debugexceptions
12150@item set debugexceptions
b383017d 12151This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12152seen by the debugger.
12153
12154@kindex set debugmemory
12155@item set debugmemory
b383017d 12156This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12157seen by the debugger.
12158
12159@kindex set shell
12160@item set shell
12161This boolean values specifies whether the debuggee is called
12162via a shell or directly (default value is on).
12163
12164@kindex show shell
12165@item show shell
12166Displays if the debuggee will be started with a shell.
12167
12168@end table
12169
be448670
CF
12170@menu
12171* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12172@end menu
12173
12174@node Non-debug DLL symbols
12175@subsubsection Support for DLLs without debugging symbols
12176@cindex DLLs with no debugging symbols
12177@cindex Minimal symbols and DLLs
12178
12179Very often on windows, some of the DLLs that your program relies on do
12180not include symbolic debugging information (for example,
12181@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
12182symbols in a DLL, it relies on the minimal amount of symbolic
12183information contained in the DLL's export table. This subsubsection
12184describes working with such symbols, known internally to @value{GDBN} as
12185``minimal symbols''.
12186
12187Note that before the debugged program has started execution, no DLLs
12188will have been loaded. The easiest way around this problem is simply to
12189start the program --- either by setting a breakpoint or letting the
12190program run once to completion. It is also possible to force
12191@value{GDBN} to load a particular DLL before starting the executable ---
12192see the shared library information in @pxref{Files} or the
12193@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
12194explicitly loading symbols from a DLL with no debugging information will
12195cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
12196which may adversely affect symbol lookup performance.
12197
12198@subsubsection DLL name prefixes
12199
12200In keeping with the naming conventions used by the Microsoft debugging
12201tools, DLL export symbols are made available with a prefix based on the
12202DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
12203also entered into the symbol table, so @code{CreateFileA} is often
12204sufficient. In some cases there will be name clashes within a program
12205(particularly if the executable itself includes full debugging symbols)
12206necessitating the use of the fully qualified name when referring to the
12207contents of the DLL. Use single-quotes around the name to avoid the
12208exclamation mark (``!'') being interpreted as a language operator.
12209
12210Note that the internal name of the DLL may be all upper-case, even
12211though the file name of the DLL is lower-case, or vice-versa. Since
12212symbols within @value{GDBN} are @emph{case-sensitive} this may cause
12213some confusion. If in doubt, try the @code{info functions} and
12214@code{info variables} commands or even @code{maint print msymbols} (see
12215@pxref{Symbols}). Here's an example:
12216
12217@smallexample
f7dc1244 12218(@value{GDBP}) info function CreateFileA
be448670
CF
12219All functions matching regular expression "CreateFileA":
12220
12221Non-debugging symbols:
122220x77e885f4 CreateFileA
122230x77e885f4 KERNEL32!CreateFileA
12224@end smallexample
12225
12226@smallexample
f7dc1244 12227(@value{GDBP}) info function !
be448670
CF
12228All functions matching regular expression "!":
12229
12230Non-debugging symbols:
122310x6100114c cygwin1!__assert
122320x61004034 cygwin1!_dll_crt0@@0
122330x61004240 cygwin1!dll_crt0(per_process *)
12234[etc...]
12235@end smallexample
12236
12237@subsubsection Working with minimal symbols
12238
12239Symbols extracted from a DLL's export table do not contain very much
12240type information. All that @value{GDBN} can do is guess whether a symbol
12241refers to a function or variable depending on the linker section that
12242contains the symbol. Also note that the actual contents of the memory
12243contained in a DLL are not available unless the program is running. This
12244means that you cannot examine the contents of a variable or disassemble
12245a function within a DLL without a running program.
12246
12247Variables are generally treated as pointers and dereferenced
12248automatically. For this reason, it is often necessary to prefix a
12249variable name with the address-of operator (``&'') and provide explicit
12250type information in the command. Here's an example of the type of
12251problem:
12252
12253@smallexample
f7dc1244 12254(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
12255$1 = 268572168
12256@end smallexample
12257
12258@smallexample
f7dc1244 12259(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
122600x10021610: "\230y\""
12261@end smallexample
12262
12263And two possible solutions:
12264
12265@smallexample
f7dc1244 12266(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
12267$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
12268@end smallexample
12269
12270@smallexample
f7dc1244 12271(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 122720x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 12273(@value{GDBP}) x/x 0x10021608
be448670 122740x10021608: 0x0022fd98
f7dc1244 12275(@value{GDBP}) x/s 0x0022fd98
be448670
CF
122760x22fd98: "/cygdrive/c/mydirectory/myprogram"
12277@end smallexample
12278
12279Setting a break point within a DLL is possible even before the program
12280starts execution. However, under these circumstances, @value{GDBN} can't
12281examine the initial instructions of the function in order to skip the
12282function's frame set-up code. You can work around this by using ``*&''
12283to set the breakpoint at a raw memory address:
12284
12285@smallexample
f7dc1244 12286(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
12287Breakpoint 1 at 0x1e04eff0
12288@end smallexample
12289
12290The author of these extensions is not entirely convinced that setting a
12291break point within a shared DLL like @file{kernel32.dll} is completely
12292safe.
12293
8e04817f
AC
12294@node Embedded OS
12295@section Embedded Operating Systems
104c1213 12296
8e04817f
AC
12297This section describes configurations involving the debugging of
12298embedded operating systems that are available for several different
12299architectures.
d4f3574e 12300
8e04817f
AC
12301@menu
12302* VxWorks:: Using @value{GDBN} with VxWorks
12303@end menu
104c1213 12304
8e04817f
AC
12305@value{GDBN} includes the ability to debug programs running on
12306various real-time operating systems.
104c1213 12307
8e04817f
AC
12308@node VxWorks
12309@subsection Using @value{GDBN} with VxWorks
104c1213 12310
8e04817f 12311@cindex VxWorks
104c1213 12312
8e04817f 12313@table @code
104c1213 12314
8e04817f
AC
12315@kindex target vxworks
12316@item target vxworks @var{machinename}
12317A VxWorks system, attached via TCP/IP. The argument @var{machinename}
12318is the target system's machine name or IP address.
104c1213 12319
8e04817f 12320@end table
104c1213 12321
8e04817f
AC
12322On VxWorks, @code{load} links @var{filename} dynamically on the
12323current target system as well as adding its symbols in @value{GDBN}.
104c1213 12324
8e04817f
AC
12325@value{GDBN} enables developers to spawn and debug tasks running on networked
12326VxWorks targets from a Unix host. Already-running tasks spawned from
12327the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
12328both the Unix host and on the VxWorks target. The program
12329@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
12330installed with the name @code{vxgdb}, to distinguish it from a
12331@value{GDBN} for debugging programs on the host itself.)
104c1213 12332
8e04817f
AC
12333@table @code
12334@item VxWorks-timeout @var{args}
12335@kindex vxworks-timeout
12336All VxWorks-based targets now support the option @code{vxworks-timeout}.
12337This option is set by the user, and @var{args} represents the number of
12338seconds @value{GDBN} waits for responses to rpc's. You might use this if
12339your VxWorks target is a slow software simulator or is on the far side
12340of a thin network line.
12341@end table
104c1213 12342
8e04817f
AC
12343The following information on connecting to VxWorks was current when
12344this manual was produced; newer releases of VxWorks may use revised
12345procedures.
104c1213 12346
4644b6e3 12347@findex INCLUDE_RDB
8e04817f
AC
12348To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
12349to include the remote debugging interface routines in the VxWorks
12350library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
12351VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
12352kernel. The resulting kernel contains @file{rdb.a}, and spawns the
12353source debugging task @code{tRdbTask} when VxWorks is booted. For more
12354information on configuring and remaking VxWorks, see the manufacturer's
12355manual.
12356@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 12357
8e04817f
AC
12358Once you have included @file{rdb.a} in your VxWorks system image and set
12359your Unix execution search path to find @value{GDBN}, you are ready to
12360run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
12361@code{vxgdb}, depending on your installation).
104c1213 12362
8e04817f 12363@value{GDBN} comes up showing the prompt:
104c1213 12364
474c8240 12365@smallexample
8e04817f 12366(vxgdb)
474c8240 12367@end smallexample
104c1213 12368
8e04817f
AC
12369@menu
12370* VxWorks Connection:: Connecting to VxWorks
12371* VxWorks Download:: VxWorks download
12372* VxWorks Attach:: Running tasks
12373@end menu
104c1213 12374
8e04817f
AC
12375@node VxWorks Connection
12376@subsubsection Connecting to VxWorks
104c1213 12377
8e04817f
AC
12378The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
12379network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 12380
474c8240 12381@smallexample
8e04817f 12382(vxgdb) target vxworks tt
474c8240 12383@end smallexample
104c1213 12384
8e04817f
AC
12385@need 750
12386@value{GDBN} displays messages like these:
104c1213 12387
8e04817f
AC
12388@smallexample
12389Attaching remote machine across net...
12390Connected to tt.
12391@end smallexample
104c1213 12392
8e04817f
AC
12393@need 1000
12394@value{GDBN} then attempts to read the symbol tables of any object modules
12395loaded into the VxWorks target since it was last booted. @value{GDBN} locates
12396these files by searching the directories listed in the command search
12397path (@pxref{Environment, ,Your program's environment}); if it fails
12398to find an object file, it displays a message such as:
5d161b24 12399
474c8240 12400@smallexample
8e04817f 12401prog.o: No such file or directory.
474c8240 12402@end smallexample
104c1213 12403
8e04817f
AC
12404When this happens, add the appropriate directory to the search path with
12405the @value{GDBN} command @code{path}, and execute the @code{target}
12406command again.
104c1213 12407
8e04817f
AC
12408@node VxWorks Download
12409@subsubsection VxWorks download
104c1213 12410
8e04817f
AC
12411@cindex download to VxWorks
12412If you have connected to the VxWorks target and you want to debug an
12413object that has not yet been loaded, you can use the @value{GDBN}
12414@code{load} command to download a file from Unix to VxWorks
12415incrementally. The object file given as an argument to the @code{load}
12416command is actually opened twice: first by the VxWorks target in order
12417to download the code, then by @value{GDBN} in order to read the symbol
12418table. This can lead to problems if the current working directories on
12419the two systems differ. If both systems have NFS mounted the same
12420filesystems, you can avoid these problems by using absolute paths.
12421Otherwise, it is simplest to set the working directory on both systems
12422to the directory in which the object file resides, and then to reference
12423the file by its name, without any path. For instance, a program
12424@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
12425and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
12426program, type this on VxWorks:
104c1213 12427
474c8240 12428@smallexample
8e04817f 12429-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 12430@end smallexample
104c1213 12431
8e04817f
AC
12432@noindent
12433Then, in @value{GDBN}, type:
104c1213 12434
474c8240 12435@smallexample
8e04817f
AC
12436(vxgdb) cd @var{hostpath}/vw/demo/rdb
12437(vxgdb) load prog.o
474c8240 12438@end smallexample
104c1213 12439
8e04817f 12440@value{GDBN} displays a response similar to this:
104c1213 12441
8e04817f
AC
12442@smallexample
12443Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
12444@end smallexample
104c1213 12445
8e04817f
AC
12446You can also use the @code{load} command to reload an object module
12447after editing and recompiling the corresponding source file. Note that
12448this makes @value{GDBN} delete all currently-defined breakpoints,
12449auto-displays, and convenience variables, and to clear the value
12450history. (This is necessary in order to preserve the integrity of
12451debugger's data structures that reference the target system's symbol
12452table.)
104c1213 12453
8e04817f
AC
12454@node VxWorks Attach
12455@subsubsection Running tasks
104c1213
JM
12456
12457@cindex running VxWorks tasks
12458You can also attach to an existing task using the @code{attach} command as
12459follows:
12460
474c8240 12461@smallexample
104c1213 12462(vxgdb) attach @var{task}
474c8240 12463@end smallexample
104c1213
JM
12464
12465@noindent
12466where @var{task} is the VxWorks hexadecimal task ID. The task can be running
12467or suspended when you attach to it. Running tasks are suspended at
12468the time of attachment.
12469
6d2ebf8b 12470@node Embedded Processors
104c1213
JM
12471@section Embedded Processors
12472
12473This section goes into details specific to particular embedded
12474configurations.
12475
7d86b5d5 12476
104c1213 12477@menu
104c1213 12478* ARM:: ARM
172c2a43
KI
12479* H8/300:: Renesas H8/300
12480* H8/500:: Renesas H8/500
12481* M32R/D:: Renesas M32R/D
104c1213 12482* M68K:: Motorola M68K
104c1213 12483* MIPS Embedded:: MIPS Embedded
a37295f9 12484* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
12485* PA:: HP PA Embedded
12486* PowerPC: PowerPC
172c2a43 12487* SH:: Renesas SH
104c1213
JM
12488* Sparclet:: Tsqware Sparclet
12489* Sparclite:: Fujitsu Sparclite
12490* ST2000:: Tandem ST2000
12491* Z8000:: Zilog Z8000
12492@end menu
12493
6d2ebf8b 12494@node ARM
104c1213
JM
12495@subsection ARM
12496
12497@table @code
12498
8e04817f
AC
12499@kindex target rdi
12500@item target rdi @var{dev}
12501ARM Angel monitor, via RDI library interface to ADP protocol. You may
12502use this target to communicate with both boards running the Angel
12503monitor, or with the EmbeddedICE JTAG debug device.
12504
12505@kindex target rdp
12506@item target rdp @var{dev}
12507ARM Demon monitor.
12508
12509@end table
12510
12511@node H8/300
172c2a43 12512@subsection Renesas H8/300
8e04817f
AC
12513
12514@table @code
12515
12516@kindex target hms@r{, with H8/300}
12517@item target hms @var{dev}
172c2a43 12518A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
12519Use special commands @code{device} and @code{speed} to control the serial
12520line and the communications speed used.
12521
12522@kindex target e7000@r{, with H8/300}
12523@item target e7000 @var{dev}
172c2a43 12524E7000 emulator for Renesas H8 and SH.
8e04817f
AC
12525
12526@kindex target sh3@r{, with H8/300}
12527@kindex target sh3e@r{, with H8/300}
12528@item target sh3 @var{dev}
12529@itemx target sh3e @var{dev}
172c2a43 12530Renesas SH-3 and SH-3E target systems.
8e04817f
AC
12531
12532@end table
12533
12534@cindex download to H8/300 or H8/500
12535@cindex H8/300 or H8/500 download
172c2a43
KI
12536@cindex download to Renesas SH
12537@cindex Renesas SH download
12538When you select remote debugging to a Renesas SH, H8/300, or H8/500
12539board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
12540board and also opens it as the current executable target for
12541@value{GDBN} on your host (like the @code{file} command).
12542
12543@value{GDBN} needs to know these things to talk to your
172c2a43 12544Renesas SH, H8/300, or H8/500:
8e04817f
AC
12545
12546@enumerate
12547@item
12548that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
12549for Renesas microprocessors, or @samp{target e7000}, the in-circuit
12550emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
12551the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
12552H8/300, or H8/500.)
12553
12554@item
172c2a43 12555what serial device connects your host to your Renesas board (the first
8e04817f
AC
12556serial device available on your host is the default).
12557
12558@item
12559what speed to use over the serial device.
12560@end enumerate
12561
12562@menu
172c2a43
KI
12563* Renesas Boards:: Connecting to Renesas boards.
12564* Renesas ICE:: Using the E7000 In-Circuit Emulator.
12565* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
12566@end menu
12567
172c2a43
KI
12568@node Renesas Boards
12569@subsubsection Connecting to Renesas boards
8e04817f
AC
12570
12571@c only for Unix hosts
12572@kindex device
172c2a43 12573@cindex serial device, Renesas micros
8e04817f
AC
12574Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
12575need to explicitly set the serial device. The default @var{port} is the
12576first available port on your host. This is only necessary on Unix
12577hosts, where it is typically something like @file{/dev/ttya}.
12578
12579@kindex speed
172c2a43 12580@cindex serial line speed, Renesas micros
8e04817f
AC
12581@code{@value{GDBN}} has another special command to set the communications
12582speed: @samp{speed @var{bps}}. This command also is only used from Unix
12583hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
12584the DOS @code{mode} command (for instance,
12585@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
12586
12587The @samp{device} and @samp{speed} commands are available only when you
172c2a43 12588use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
12589use a DOS host,
12590@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12591called @code{asynctsr} to communicate with the development board
12592through a PC serial port. You must also use the DOS @code{mode} command
12593to set up the serial port on the DOS side.
12594
12595The following sample session illustrates the steps needed to start a
12596program under @value{GDBN} control on an H8/300. The example uses a
12597sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 12598the Renesas SH and the H8/500.
8e04817f
AC
12599
12600First hook up your development board. In this example, we use a
12601board attached to serial port @code{COM2}; if you use a different serial
12602port, substitute its name in the argument of the @code{mode} command.
12603When you call @code{asynctsr}, the auxiliary comms program used by the
12604debugger, you give it just the numeric part of the serial port's name;
12605for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12606@code{COM2}.
12607
474c8240 12608@smallexample
8e04817f
AC
12609C:\H8300\TEST> asynctsr 2
12610C:\H8300\TEST> mode com2:9600,n,8,1,p
12611
12612Resident portion of MODE loaded
12613
12614COM2: 9600, n, 8, 1, p
12615
474c8240 12616@end smallexample
8e04817f
AC
12617
12618@quotation
12619@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12620@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12621disable it, or even boot without it, to use @code{asynctsr} to control
12622your development board.
12623@end quotation
12624
12625@kindex target hms@r{, and serial protocol}
12626Now that serial communications are set up, and the development board is
12627connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
12628the name of your program as the argument. @code{@value{GDBN}} prompts
12629you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12630commands to begin your debugging session: @samp{target hms} to specify
172c2a43 12631cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
12632download your program to the board. @code{load} displays the names of
12633the program's sections, and a @samp{*} for each 2K of data downloaded.
12634(If you want to refresh @value{GDBN} data on symbols or on the
12635executable file without downloading, use the @value{GDBN} commands
12636@code{file} or @code{symbol-file}. These commands, and @code{load}
12637itself, are described in @ref{Files,,Commands to specify files}.)
12638
12639@smallexample
12640(eg-C:\H8300\TEST) @value{GDBP} t.x
12641@value{GDBN} is free software and you are welcome to distribute copies
12642 of it under certain conditions; type "show copying" to see
12643 the conditions.
12644There is absolutely no warranty for @value{GDBN}; type "show warranty"
12645for details.
12646@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12647(@value{GDBP}) target hms
12648Connected to remote H8/300 HMS system.
12649(@value{GDBP}) load t.x
12650.text : 0x8000 .. 0xabde ***********
12651.data : 0xabde .. 0xad30 *
12652.stack : 0xf000 .. 0xf014 *
12653@end smallexample
12654
12655At this point, you're ready to run or debug your program. From here on,
12656you can use all the usual @value{GDBN} commands. The @code{break} command
12657sets breakpoints; the @code{run} command starts your program;
12658@code{print} or @code{x} display data; the @code{continue} command
12659resumes execution after stopping at a breakpoint. You can use the
12660@code{help} command at any time to find out more about @value{GDBN} commands.
12661
12662Remember, however, that @emph{operating system} facilities aren't
12663available on your development board; for example, if your program hangs,
12664you can't send an interrupt---but you can press the @sc{reset} switch!
12665
12666Use the @sc{reset} button on the development board
12667@itemize @bullet
12668@item
12669to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12670no way to pass an interrupt signal to the development board); and
12671
12672@item
12673to return to the @value{GDBN} command prompt after your program finishes
12674normally. The communications protocol provides no other way for @value{GDBN}
12675to detect program completion.
12676@end itemize
12677
12678In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12679development board as a ``normal exit'' of your program.
12680
172c2a43 12681@node Renesas ICE
8e04817f
AC
12682@subsubsection Using the E7000 in-circuit emulator
12683
172c2a43 12684@kindex target e7000@r{, with Renesas ICE}
8e04817f 12685You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12686Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12687e7000} command to connect @value{GDBN} to your E7000:
12688
12689@table @code
12690@item target e7000 @var{port} @var{speed}
12691Use this form if your E7000 is connected to a serial port. The
12692@var{port} argument identifies what serial port to use (for example,
12693@samp{com2}). The third argument is the line speed in bits per second
12694(for example, @samp{9600}).
12695
12696@item target e7000 @var{hostname}
12697If your E7000 is installed as a host on a TCP/IP network, you can just
12698specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12699@end table
12700
172c2a43
KI
12701@node Renesas Special
12702@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12703
12704Some @value{GDBN} commands are available only for the H8/300:
12705
12706@table @code
12707
12708@kindex set machine
12709@kindex show machine
12710@item set machine h8300
12711@itemx set machine h8300h
12712Condition @value{GDBN} for one of the two variants of the H8/300
12713architecture with @samp{set machine}. You can use @samp{show machine}
12714to check which variant is currently in effect.
104c1213
JM
12715
12716@end table
12717
8e04817f
AC
12718@node H8/500
12719@subsection H8/500
104c1213
JM
12720
12721@table @code
12722
8e04817f
AC
12723@kindex set memory @var{mod}
12724@cindex memory models, H8/500
12725@item set memory @var{mod}
12726@itemx show memory
12727Specify which H8/500 memory model (@var{mod}) you are using with
12728@samp{set memory}; check which memory model is in effect with @samp{show
12729memory}. The accepted values for @var{mod} are @code{small},
12730@code{big}, @code{medium}, and @code{compact}.
104c1213 12731
8e04817f 12732@end table
104c1213 12733
8e04817f 12734@node M32R/D
172c2a43 12735@subsection Renesas M32R/D
8e04817f
AC
12736
12737@table @code
12738
12739@kindex target m32r
12740@item target m32r @var{dev}
172c2a43 12741Renesas M32R/D ROM monitor.
8e04817f 12742
fb3e19c0
KI
12743@kindex target m32rsdi
12744@item target m32rsdi @var{dev}
12745Renesas M32R SDI server, connected via parallel port to the board.
12746
8e04817f
AC
12747@end table
12748
12749@node M68K
12750@subsection M68k
12751
12752The Motorola m68k configuration includes ColdFire support, and
12753target command for the following ROM monitors.
12754
12755@table @code
12756
12757@kindex target abug
12758@item target abug @var{dev}
12759ABug ROM monitor for M68K.
12760
12761@kindex target cpu32bug
12762@item target cpu32bug @var{dev}
12763CPU32BUG monitor, running on a CPU32 (M68K) board.
12764
12765@kindex target dbug
12766@item target dbug @var{dev}
12767dBUG ROM monitor for Motorola ColdFire.
12768
12769@kindex target est
12770@item target est @var{dev}
12771EST-300 ICE monitor, running on a CPU32 (M68K) board.
12772
12773@kindex target rom68k
12774@item target rom68k @var{dev}
12775ROM 68K monitor, running on an M68K IDP board.
12776
12777@end table
12778
8e04817f
AC
12779@table @code
12780
12781@kindex target rombug
12782@item target rombug @var{dev}
12783ROMBUG ROM monitor for OS/9000.
12784
12785@end table
12786
8e04817f
AC
12787@node MIPS Embedded
12788@subsection MIPS Embedded
12789
12790@cindex MIPS boards
12791@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12792MIPS board attached to a serial line. This is available when
12793you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12794
8e04817f
AC
12795@need 1000
12796Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12797
8e04817f
AC
12798@table @code
12799@item target mips @var{port}
12800@kindex target mips @var{port}
12801To run a program on the board, start up @code{@value{GDBP}} with the
12802name of your program as the argument. To connect to the board, use the
12803command @samp{target mips @var{port}}, where @var{port} is the name of
12804the serial port connected to the board. If the program has not already
12805been downloaded to the board, you may use the @code{load} command to
12806download it. You can then use all the usual @value{GDBN} commands.
104c1213 12807
8e04817f
AC
12808For example, this sequence connects to the target board through a serial
12809port, and loads and runs a program called @var{prog} through the
12810debugger:
104c1213 12811
474c8240 12812@smallexample
8e04817f
AC
12813host$ @value{GDBP} @var{prog}
12814@value{GDBN} is free software and @dots{}
12815(@value{GDBP}) target mips /dev/ttyb
12816(@value{GDBP}) load @var{prog}
12817(@value{GDBP}) run
474c8240 12818@end smallexample
104c1213 12819
8e04817f
AC
12820@item target mips @var{hostname}:@var{portnumber}
12821On some @value{GDBN} host configurations, you can specify a TCP
12822connection (for instance, to a serial line managed by a terminal
12823concentrator) instead of a serial port, using the syntax
12824@samp{@var{hostname}:@var{portnumber}}.
104c1213 12825
8e04817f
AC
12826@item target pmon @var{port}
12827@kindex target pmon @var{port}
12828PMON ROM monitor.
104c1213 12829
8e04817f
AC
12830@item target ddb @var{port}
12831@kindex target ddb @var{port}
12832NEC's DDB variant of PMON for Vr4300.
104c1213 12833
8e04817f
AC
12834@item target lsi @var{port}
12835@kindex target lsi @var{port}
12836LSI variant of PMON.
104c1213 12837
8e04817f
AC
12838@kindex target r3900
12839@item target r3900 @var{dev}
12840Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12841
8e04817f
AC
12842@kindex target array
12843@item target array @var{dev}
12844Array Tech LSI33K RAID controller board.
104c1213 12845
8e04817f 12846@end table
104c1213 12847
104c1213 12848
8e04817f
AC
12849@noindent
12850@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12851
8e04817f
AC
12852@table @code
12853@item set processor @var{args}
12854@itemx show processor
12855@kindex set processor @var{args}
12856@kindex show processor
12857Use the @code{set processor} command to set the type of MIPS
12858processor when you want to access processor-type-specific registers.
12859For example, @code{set processor @var{r3041}} tells @value{GDBN}
12860to use the CPU registers appropriate for the 3041 chip.
12861Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12862is using. Use the @code{info reg} command to see what registers
12863@value{GDBN} is using.
104c1213 12864
8e04817f
AC
12865@item set mipsfpu double
12866@itemx set mipsfpu single
12867@itemx set mipsfpu none
12868@itemx show mipsfpu
12869@kindex set mipsfpu
12870@kindex show mipsfpu
12871@cindex MIPS remote floating point
12872@cindex floating point, MIPS remote
12873If your target board does not support the MIPS floating point
12874coprocessor, you should use the command @samp{set mipsfpu none} (if you
12875need this, you may wish to put the command in your @value{GDBN} init
12876file). This tells @value{GDBN} how to find the return value of
12877functions which return floating point values. It also allows
12878@value{GDBN} to avoid saving the floating point registers when calling
12879functions on the board. If you are using a floating point coprocessor
12880with only single precision floating point support, as on the @sc{r4650}
12881processor, use the command @samp{set mipsfpu single}. The default
12882double precision floating point coprocessor may be selected using
12883@samp{set mipsfpu double}.
104c1213 12884
8e04817f
AC
12885In previous versions the only choices were double precision or no
12886floating point, so @samp{set mipsfpu on} will select double precision
12887and @samp{set mipsfpu off} will select no floating point.
104c1213 12888
8e04817f
AC
12889As usual, you can inquire about the @code{mipsfpu} variable with
12890@samp{show mipsfpu}.
104c1213 12891
8e04817f
AC
12892@item set remotedebug @var{n}
12893@itemx show remotedebug
12894@kindex set remotedebug@r{, MIPS protocol}
12895@kindex show remotedebug@r{, MIPS protocol}
12896@cindex @code{remotedebug}, MIPS protocol
12897@cindex MIPS @code{remotedebug} protocol
12898@c FIXME! For this to be useful, you must know something about the MIPS
12899@c FIXME...protocol. Where is it described?
12900You can see some debugging information about communications with the board
12901by setting the @code{remotedebug} variable. If you set it to @code{1} using
12902@samp{set remotedebug 1}, every packet is displayed. If you set it
12903to @code{2}, every character is displayed. You can check the current value
12904at any time with the command @samp{show remotedebug}.
104c1213 12905
8e04817f
AC
12906@item set timeout @var{seconds}
12907@itemx set retransmit-timeout @var{seconds}
12908@itemx show timeout
12909@itemx show retransmit-timeout
12910@cindex @code{timeout}, MIPS protocol
12911@cindex @code{retransmit-timeout}, MIPS protocol
12912@kindex set timeout
12913@kindex show timeout
12914@kindex set retransmit-timeout
12915@kindex show retransmit-timeout
12916You can control the timeout used while waiting for a packet, in the MIPS
12917remote protocol, with the @code{set timeout @var{seconds}} command. The
12918default is 5 seconds. Similarly, you can control the timeout used while
12919waiting for an acknowledgement of a packet with the @code{set
12920retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12921You can inspect both values with @code{show timeout} and @code{show
12922retransmit-timeout}. (These commands are @emph{only} available when
12923@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12924
8e04817f
AC
12925The timeout set by @code{set timeout} does not apply when @value{GDBN}
12926is waiting for your program to stop. In that case, @value{GDBN} waits
12927forever because it has no way of knowing how long the program is going
12928to run before stopping.
12929@end table
104c1213 12930
a37295f9
MM
12931@node OpenRISC 1000
12932@subsection OpenRISC 1000
12933@cindex OpenRISC 1000
12934
12935@cindex or1k boards
12936See OR1k Architecture document (@uref{www.opencores.org}) for more information
12937about platform and commands.
12938
12939@table @code
12940
12941@kindex target jtag
12942@item target jtag jtag://@var{host}:@var{port}
12943
12944Connects to remote JTAG server.
12945JTAG remote server can be either an or1ksim or JTAG server,
12946connected via parallel port to the board.
12947
12948Example: @code{target jtag jtag://localhost:9999}
12949
12950@kindex or1ksim
12951@item or1ksim @var{command}
12952If connected to @code{or1ksim} OpenRISC 1000 Architectural
12953Simulator, proprietary commands can be executed.
12954
12955@kindex info or1k spr
12956@item info or1k spr
12957Displays spr groups.
12958
12959@item info or1k spr @var{group}
12960@itemx info or1k spr @var{groupno}
12961Displays register names in selected group.
12962
12963@item info or1k spr @var{group} @var{register}
12964@itemx info or1k spr @var{register}
12965@itemx info or1k spr @var{groupno} @var{registerno}
12966@itemx info or1k spr @var{registerno}
12967Shows information about specified spr register.
12968
12969@kindex spr
12970@item spr @var{group} @var{register} @var{value}
12971@itemx spr @var{register @var{value}}
12972@itemx spr @var{groupno} @var{registerno @var{value}}
12973@itemx spr @var{registerno @var{value}}
12974Writes @var{value} to specified spr register.
12975@end table
12976
12977Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12978It is very similar to @value{GDBN} trace, except it does not interfere with normal
12979program execution and is thus much faster. Hardware breakpoints/watchpoint
12980triggers can be set using:
12981@table @code
12982@item $LEA/$LDATA
12983Load effective address/data
12984@item $SEA/$SDATA
12985Store effective address/data
12986@item $AEA/$ADATA
12987Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12988@item $FETCH
12989Fetch data
12990@end table
12991
12992When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12993@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12994
12995@code{htrace} commands:
12996@cindex OpenRISC 1000 htrace
12997@table @code
12998@kindex hwatch
12999@item hwatch @var{conditional}
13000Set hardware watchpoint on combination of Load/Store Effecive Address(es)
13001or Data. For example:
13002
13003@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
13004
13005@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
13006
4644b6e3 13007@kindex htrace
a37295f9
MM
13008@item htrace info
13009Display information about current HW trace configuration.
13010
a37295f9
MM
13011@item htrace trigger @var{conditional}
13012Set starting criteria for HW trace.
13013
a37295f9
MM
13014@item htrace qualifier @var{conditional}
13015Set acquisition qualifier for HW trace.
13016
a37295f9
MM
13017@item htrace stop @var{conditional}
13018Set HW trace stopping criteria.
13019
f153cc92 13020@item htrace record [@var{data}]*
a37295f9
MM
13021Selects the data to be recorded, when qualifier is met and HW trace was
13022triggered.
13023
a37295f9 13024@item htrace enable
a37295f9
MM
13025@itemx htrace disable
13026Enables/disables the HW trace.
13027
f153cc92 13028@item htrace rewind [@var{filename}]
a37295f9
MM
13029Clears currently recorded trace data.
13030
13031If filename is specified, new trace file is made and any newly collected data
13032will be written there.
13033
f153cc92 13034@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
13035Prints trace buffer, using current record configuration.
13036
a37295f9
MM
13037@item htrace mode continuous
13038Set continuous trace mode.
13039
a37295f9
MM
13040@item htrace mode suspend
13041Set suspend trace mode.
13042
13043@end table
13044
8e04817f
AC
13045@node PowerPC
13046@subsection PowerPC
104c1213
JM
13047
13048@table @code
104c1213 13049
8e04817f
AC
13050@kindex target dink32
13051@item target dink32 @var{dev}
13052DINK32 ROM monitor.
104c1213 13053
8e04817f
AC
13054@kindex target ppcbug
13055@item target ppcbug @var{dev}
13056@kindex target ppcbug1
13057@item target ppcbug1 @var{dev}
13058PPCBUG ROM monitor for PowerPC.
104c1213 13059
8e04817f
AC
13060@kindex target sds
13061@item target sds @var{dev}
13062SDS monitor, running on a PowerPC board (such as Motorola's ADS).
13063
13064@end table
13065
13066@node PA
13067@subsection HP PA Embedded
104c1213
JM
13068
13069@table @code
13070
8e04817f
AC
13071@kindex target op50n
13072@item target op50n @var{dev}
13073OP50N monitor, running on an OKI HPPA board.
13074
13075@kindex target w89k
13076@item target w89k @var{dev}
13077W89K monitor, running on a Winbond HPPA board.
104c1213
JM
13078
13079@end table
13080
8e04817f 13081@node SH
172c2a43 13082@subsection Renesas SH
104c1213
JM
13083
13084@table @code
13085
172c2a43 13086@kindex target hms@r{, with Renesas SH}
8e04817f 13087@item target hms @var{dev}
172c2a43 13088A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
13089commands @code{device} and @code{speed} to control the serial line and
13090the communications speed used.
104c1213 13091
172c2a43 13092@kindex target e7000@r{, with Renesas SH}
8e04817f 13093@item target e7000 @var{dev}
172c2a43 13094E7000 emulator for Renesas SH.
104c1213 13095
8e04817f
AC
13096@kindex target sh3@r{, with SH}
13097@kindex target sh3e@r{, with SH}
13098@item target sh3 @var{dev}
13099@item target sh3e @var{dev}
172c2a43 13100Renesas SH-3 and SH-3E target systems.
104c1213 13101
8e04817f 13102@end table
104c1213 13103
8e04817f
AC
13104@node Sparclet
13105@subsection Tsqware Sparclet
104c1213 13106
8e04817f
AC
13107@cindex Sparclet
13108
13109@value{GDBN} enables developers to debug tasks running on
13110Sparclet targets from a Unix host.
13111@value{GDBN} uses code that runs on
13112both the Unix host and on the Sparclet target. The program
13113@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 13114
8e04817f
AC
13115@table @code
13116@item remotetimeout @var{args}
13117@kindex remotetimeout
13118@value{GDBN} supports the option @code{remotetimeout}.
13119This option is set by the user, and @var{args} represents the number of
13120seconds @value{GDBN} waits for responses.
104c1213
JM
13121@end table
13122
8e04817f
AC
13123@cindex compiling, on Sparclet
13124When compiling for debugging, include the options @samp{-g} to get debug
13125information and @samp{-Ttext} to relocate the program to where you wish to
13126load it on the target. You may also want to add the options @samp{-n} or
13127@samp{-N} in order to reduce the size of the sections. Example:
104c1213 13128
474c8240 13129@smallexample
8e04817f 13130sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 13131@end smallexample
104c1213 13132
8e04817f 13133You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 13134
474c8240 13135@smallexample
8e04817f 13136sparclet-aout-objdump --headers --syms prog
474c8240 13137@end smallexample
104c1213 13138
8e04817f
AC
13139@cindex running, on Sparclet
13140Once you have set
13141your Unix execution search path to find @value{GDBN}, you are ready to
13142run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
13143(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 13144
8e04817f
AC
13145@value{GDBN} comes up showing the prompt:
13146
474c8240 13147@smallexample
8e04817f 13148(gdbslet)
474c8240 13149@end smallexample
104c1213
JM
13150
13151@menu
8e04817f
AC
13152* Sparclet File:: Setting the file to debug
13153* Sparclet Connection:: Connecting to Sparclet
13154* Sparclet Download:: Sparclet download
13155* Sparclet Execution:: Running and debugging
104c1213
JM
13156@end menu
13157
8e04817f
AC
13158@node Sparclet File
13159@subsubsection Setting file to debug
104c1213 13160
8e04817f 13161The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 13162
474c8240 13163@smallexample
8e04817f 13164(gdbslet) file prog
474c8240 13165@end smallexample
104c1213 13166
8e04817f
AC
13167@need 1000
13168@value{GDBN} then attempts to read the symbol table of @file{prog}.
13169@value{GDBN} locates
13170the file by searching the directories listed in the command search
13171path.
13172If the file was compiled with debug information (option "-g"), source
13173files will be searched as well.
13174@value{GDBN} locates
13175the source files by searching the directories listed in the directory search
13176path (@pxref{Environment, ,Your program's environment}).
13177If it fails
13178to find a file, it displays a message such as:
104c1213 13179
474c8240 13180@smallexample
8e04817f 13181prog: No such file or directory.
474c8240 13182@end smallexample
104c1213 13183
8e04817f
AC
13184When this happens, add the appropriate directories to the search paths with
13185the @value{GDBN} commands @code{path} and @code{dir}, and execute the
13186@code{target} command again.
104c1213 13187
8e04817f
AC
13188@node Sparclet Connection
13189@subsubsection Connecting to Sparclet
104c1213 13190
8e04817f
AC
13191The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
13192To connect to a target on serial port ``@code{ttya}'', type:
104c1213 13193
474c8240 13194@smallexample
8e04817f
AC
13195(gdbslet) target sparclet /dev/ttya
13196Remote target sparclet connected to /dev/ttya
13197main () at ../prog.c:3
474c8240 13198@end smallexample
104c1213 13199
8e04817f
AC
13200@need 750
13201@value{GDBN} displays messages like these:
104c1213 13202
474c8240 13203@smallexample
8e04817f 13204Connected to ttya.
474c8240 13205@end smallexample
104c1213 13206
8e04817f
AC
13207@node Sparclet Download
13208@subsubsection Sparclet download
104c1213 13209
8e04817f
AC
13210@cindex download to Sparclet
13211Once connected to the Sparclet target,
13212you can use the @value{GDBN}
13213@code{load} command to download the file from the host to the target.
13214The file name and load offset should be given as arguments to the @code{load}
13215command.
13216Since the file format is aout, the program must be loaded to the starting
13217address. You can use @code{objdump} to find out what this value is. The load
13218offset is an offset which is added to the VMA (virtual memory address)
13219of each of the file's sections.
13220For instance, if the program
13221@file{prog} was linked to text address 0x1201000, with data at 0x12010160
13222and bss at 0x12010170, in @value{GDBN}, type:
104c1213 13223
474c8240 13224@smallexample
8e04817f
AC
13225(gdbslet) load prog 0x12010000
13226Loading section .text, size 0xdb0 vma 0x12010000
474c8240 13227@end smallexample
104c1213 13228
8e04817f
AC
13229If the code is loaded at a different address then what the program was linked
13230to, you may need to use the @code{section} and @code{add-symbol-file} commands
13231to tell @value{GDBN} where to map the symbol table.
13232
13233@node Sparclet Execution
13234@subsubsection Running and debugging
13235
13236@cindex running and debugging Sparclet programs
13237You can now begin debugging the task using @value{GDBN}'s execution control
13238commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
13239manual for the list of commands.
13240
474c8240 13241@smallexample
8e04817f
AC
13242(gdbslet) b main
13243Breakpoint 1 at 0x12010000: file prog.c, line 3.
13244(gdbslet) run
13245Starting program: prog
13246Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
132473 char *symarg = 0;
13248(gdbslet) step
132494 char *execarg = "hello!";
13250(gdbslet)
474c8240 13251@end smallexample
8e04817f
AC
13252
13253@node Sparclite
13254@subsection Fujitsu Sparclite
104c1213
JM
13255
13256@table @code
13257
8e04817f
AC
13258@kindex target sparclite
13259@item target sparclite @var{dev}
13260Fujitsu sparclite boards, used only for the purpose of loading.
13261You must use an additional command to debug the program.
13262For example: target remote @var{dev} using @value{GDBN} standard
13263remote protocol.
104c1213
JM
13264
13265@end table
13266
8e04817f
AC
13267@node ST2000
13268@subsection Tandem ST2000
104c1213 13269
8e04817f
AC
13270@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
13271STDBUG protocol.
104c1213 13272
8e04817f
AC
13273To connect your ST2000 to the host system, see the manufacturer's
13274manual. Once the ST2000 is physically attached, you can run:
104c1213 13275
474c8240 13276@smallexample
8e04817f 13277target st2000 @var{dev} @var{speed}
474c8240 13278@end smallexample
104c1213 13279
8e04817f
AC
13280@noindent
13281to establish it as your debugging environment. @var{dev} is normally
13282the name of a serial device, such as @file{/dev/ttya}, connected to the
13283ST2000 via a serial line. You can instead specify @var{dev} as a TCP
13284connection (for example, to a serial line attached via a terminal
13285concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 13286
8e04817f
AC
13287The @code{load} and @code{attach} commands are @emph{not} defined for
13288this target; you must load your program into the ST2000 as you normally
13289would for standalone operation. @value{GDBN} reads debugging information
13290(such as symbols) from a separate, debugging version of the program
13291available on your host computer.
13292@c FIXME!! This is terribly vague; what little content is here is
13293@c basically hearsay.
104c1213 13294
8e04817f
AC
13295@cindex ST2000 auxiliary commands
13296These auxiliary @value{GDBN} commands are available to help you with the ST2000
13297environment:
104c1213 13298
8e04817f
AC
13299@table @code
13300@item st2000 @var{command}
13301@kindex st2000 @var{cmd}
13302@cindex STDBUG commands (ST2000)
13303@cindex commands to STDBUG (ST2000)
13304Send a @var{command} to the STDBUG monitor. See the manufacturer's
13305manual for available commands.
104c1213 13306
8e04817f
AC
13307@item connect
13308@cindex connect (to STDBUG)
13309Connect the controlling terminal to the STDBUG command monitor. When
13310you are done interacting with STDBUG, typing either of two character
13311sequences gets you back to the @value{GDBN} command prompt:
13312@kbd{@key{RET}~.} (Return, followed by tilde and period) or
13313@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
13314@end table
13315
8e04817f
AC
13316@node Z8000
13317@subsection Zilog Z8000
104c1213 13318
8e04817f
AC
13319@cindex Z8000
13320@cindex simulator, Z8000
13321@cindex Zilog Z8000 simulator
104c1213 13322
8e04817f
AC
13323When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
13324a Z8000 simulator.
13325
13326For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
13327unsegmented variant of the Z8000 architecture) or the Z8001 (the
13328segmented variant). The simulator recognizes which architecture is
13329appropriate by inspecting the object code.
104c1213 13330
8e04817f
AC
13331@table @code
13332@item target sim @var{args}
13333@kindex sim
13334@kindex target sim@r{, with Z8000}
13335Debug programs on a simulated CPU. If the simulator supports setup
13336options, specify them via @var{args}.
104c1213
JM
13337@end table
13338
8e04817f
AC
13339@noindent
13340After specifying this target, you can debug programs for the simulated
13341CPU in the same style as programs for your host computer; use the
13342@code{file} command to load a new program image, the @code{run} command
13343to run your program, and so on.
13344
13345As well as making available all the usual machine registers
13346(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
13347additional items of information as specially named registers:
104c1213
JM
13348
13349@table @code
13350
8e04817f
AC
13351@item cycles
13352Counts clock-ticks in the simulator.
104c1213 13353
8e04817f
AC
13354@item insts
13355Counts instructions run in the simulator.
104c1213 13356
8e04817f
AC
13357@item time
13358Execution time in 60ths of a second.
104c1213 13359
8e04817f 13360@end table
104c1213 13361
8e04817f
AC
13362You can refer to these values in @value{GDBN} expressions with the usual
13363conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
13364conditional breakpoint that suspends only after at least 5000
13365simulated clock ticks.
104c1213 13366
8e04817f
AC
13367@node Architectures
13368@section Architectures
104c1213 13369
8e04817f
AC
13370This section describes characteristics of architectures that affect
13371all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 13372
8e04817f
AC
13373@menu
13374* A29K::
13375* Alpha::
13376* MIPS::
13377@end menu
104c1213 13378
8e04817f
AC
13379@node A29K
13380@subsection A29K
104c1213
JM
13381
13382@table @code
104c1213 13383
8e04817f
AC
13384@kindex set rstack_high_address
13385@cindex AMD 29K register stack
13386@cindex register stack, AMD29K
13387@item set rstack_high_address @var{address}
13388On AMD 29000 family processors, registers are saved in a separate
13389@dfn{register stack}. There is no way for @value{GDBN} to determine the
13390extent of this stack. Normally, @value{GDBN} just assumes that the
13391stack is ``large enough''. This may result in @value{GDBN} referencing
13392memory locations that do not exist. If necessary, you can get around
13393this problem by specifying the ending address of the register stack with
13394the @code{set rstack_high_address} command. The argument should be an
13395address, which you probably want to precede with @samp{0x} to specify in
13396hexadecimal.
104c1213 13397
8e04817f
AC
13398@kindex show rstack_high_address
13399@item show rstack_high_address
13400Display the current limit of the register stack, on AMD 29000 family
13401processors.
104c1213 13402
8e04817f 13403@end table
104c1213 13404
8e04817f
AC
13405@node Alpha
13406@subsection Alpha
104c1213 13407
8e04817f 13408See the following section.
104c1213 13409
8e04817f
AC
13410@node MIPS
13411@subsection MIPS
104c1213 13412
8e04817f
AC
13413@cindex stack on Alpha
13414@cindex stack on MIPS
13415@cindex Alpha stack
13416@cindex MIPS stack
13417Alpha- and MIPS-based computers use an unusual stack frame, which
13418sometimes requires @value{GDBN} to search backward in the object code to
13419find the beginning of a function.
104c1213 13420
8e04817f
AC
13421@cindex response time, MIPS debugging
13422To improve response time (especially for embedded applications, where
13423@value{GDBN} may be restricted to a slow serial line for this search)
13424you may want to limit the size of this search, using one of these
13425commands:
104c1213 13426
8e04817f
AC
13427@table @code
13428@cindex @code{heuristic-fence-post} (Alpha, MIPS)
13429@item set heuristic-fence-post @var{limit}
13430Restrict @value{GDBN} to examining at most @var{limit} bytes in its
13431search for the beginning of a function. A value of @var{0} (the
13432default) means there is no limit. However, except for @var{0}, the
13433larger the limit the more bytes @code{heuristic-fence-post} must search
13434and therefore the longer it takes to run.
104c1213 13435
8e04817f
AC
13436@item show heuristic-fence-post
13437Display the current limit.
13438@end table
104c1213
JM
13439
13440@noindent
8e04817f
AC
13441These commands are available @emph{only} when @value{GDBN} is configured
13442for debugging programs on Alpha or MIPS processors.
104c1213 13443
104c1213 13444
8e04817f
AC
13445@node Controlling GDB
13446@chapter Controlling @value{GDBN}
13447
13448You can alter the way @value{GDBN} interacts with you by using the
13449@code{set} command. For commands controlling how @value{GDBN} displays
13450data, see @ref{Print Settings, ,Print settings}. Other settings are
13451described here.
13452
13453@menu
13454* Prompt:: Prompt
13455* Editing:: Command editing
13456* History:: Command history
13457* Screen Size:: Screen size
13458* Numbers:: Numbers
1e698235 13459* ABI:: Configuring the current ABI
8e04817f
AC
13460* Messages/Warnings:: Optional warnings and messages
13461* Debugging Output:: Optional messages about internal happenings
13462@end menu
13463
13464@node Prompt
13465@section Prompt
104c1213 13466
8e04817f 13467@cindex prompt
104c1213 13468
8e04817f
AC
13469@value{GDBN} indicates its readiness to read a command by printing a string
13470called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13471can change the prompt string with the @code{set prompt} command. For
13472instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
13473the prompt in one of the @value{GDBN} sessions so that you can always tell
13474which one you are talking to.
104c1213 13475
8e04817f
AC
13476@emph{Note:} @code{set prompt} does not add a space for you after the
13477prompt you set. This allows you to set a prompt which ends in a space
13478or a prompt that does not.
104c1213 13479
8e04817f
AC
13480@table @code
13481@kindex set prompt
13482@item set prompt @var{newprompt}
13483Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 13484
8e04817f
AC
13485@kindex show prompt
13486@item show prompt
13487Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
13488@end table
13489
8e04817f
AC
13490@node Editing
13491@section Command editing
13492@cindex readline
13493@cindex command line editing
104c1213 13494
703663ab 13495@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
13496@sc{gnu} library provides consistent behavior for programs which provide a
13497command line interface to the user. Advantages are @sc{gnu} Emacs-style
13498or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13499substitution, and a storage and recall of command history across
13500debugging sessions.
104c1213 13501
8e04817f
AC
13502You may control the behavior of command line editing in @value{GDBN} with the
13503command @code{set}.
104c1213 13504
8e04817f
AC
13505@table @code
13506@kindex set editing
13507@cindex editing
13508@item set editing
13509@itemx set editing on
13510Enable command line editing (enabled by default).
104c1213 13511
8e04817f
AC
13512@item set editing off
13513Disable command line editing.
104c1213 13514
8e04817f
AC
13515@kindex show editing
13516@item show editing
13517Show whether command line editing is enabled.
104c1213
JM
13518@end table
13519
703663ab
EZ
13520@xref{Command Line Editing}, for more details about the Readline
13521interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
13522encouraged to read that chapter.
13523
8e04817f
AC
13524@node History
13525@section Command history
703663ab 13526@cindex command history
8e04817f
AC
13527
13528@value{GDBN} can keep track of the commands you type during your
13529debugging sessions, so that you can be certain of precisely what
13530happened. Use these commands to manage the @value{GDBN} command
13531history facility.
104c1213 13532
703663ab
EZ
13533@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
13534package, to provide the history facility. @xref{Using History
13535Interactively}, for the detailed description of the History library.
13536
13537Here is the description of @value{GDBN} commands related to command
13538history.
13539
104c1213 13540@table @code
8e04817f
AC
13541@cindex history substitution
13542@cindex history file
13543@kindex set history filename
4644b6e3 13544@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
13545@item set history filename @var{fname}
13546Set the name of the @value{GDBN} command history file to @var{fname}.
13547This is the file where @value{GDBN} reads an initial command history
13548list, and where it writes the command history from this session when it
13549exits. You can access this list through history expansion or through
13550the history command editing characters listed below. This file defaults
13551to the value of the environment variable @code{GDBHISTFILE}, or to
13552@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13553is not set.
104c1213 13554
8e04817f 13555@cindex history save
4644b6e3 13556@kindex set history
8e04817f
AC
13557@item set history save
13558@itemx set history save on
13559Record command history in a file, whose name may be specified with the
13560@code{set history filename} command. By default, this option is disabled.
104c1213 13561
8e04817f
AC
13562@item set history save off
13563Stop recording command history in a file.
104c1213 13564
8e04817f 13565@cindex history size
8e04817f
AC
13566@item set history size @var{size}
13567Set the number of commands which @value{GDBN} keeps in its history list.
13568This defaults to the value of the environment variable
13569@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
13570@end table
13571
8e04817f 13572History expansion assigns special meaning to the character @kbd{!}.
703663ab 13573@xref{Event Designators}, for more details.
8e04817f 13574
703663ab 13575@cindex history expansion, turn on/off
8e04817f
AC
13576Since @kbd{!} is also the logical not operator in C, history expansion
13577is off by default. If you decide to enable history expansion with the
13578@code{set history expansion on} command, you may sometimes need to
13579follow @kbd{!} (when it is used as logical not, in an expression) with
13580a space or a tab to prevent it from being expanded. The readline
13581history facilities do not attempt substitution on the strings
13582@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13583
13584The commands to control history expansion are:
104c1213
JM
13585
13586@table @code
8e04817f
AC
13587@item set history expansion on
13588@itemx set history expansion
703663ab 13589@kindex set history expansion
8e04817f 13590Enable history expansion. History expansion is off by default.
104c1213 13591
8e04817f
AC
13592@item set history expansion off
13593Disable history expansion.
104c1213 13594
8e04817f
AC
13595@c @group
13596@kindex show history
13597@item show history
13598@itemx show history filename
13599@itemx show history save
13600@itemx show history size
13601@itemx show history expansion
13602These commands display the state of the @value{GDBN} history parameters.
13603@code{show history} by itself displays all four states.
13604@c @end group
13605@end table
13606
13607@table @code
13608@kindex shows
13609@item show commands
13610Display the last ten commands in the command history.
104c1213 13611
8e04817f
AC
13612@item show commands @var{n}
13613Print ten commands centered on command number @var{n}.
13614
13615@item show commands +
13616Print ten commands just after the commands last printed.
104c1213
JM
13617@end table
13618
8e04817f
AC
13619@node Screen Size
13620@section Screen size
13621@cindex size of screen
13622@cindex pauses in output
104c1213 13623
8e04817f
AC
13624Certain commands to @value{GDBN} may produce large amounts of
13625information output to the screen. To help you read all of it,
13626@value{GDBN} pauses and asks you for input at the end of each page of
13627output. Type @key{RET} when you want to continue the output, or @kbd{q}
13628to discard the remaining output. Also, the screen width setting
13629determines when to wrap lines of output. Depending on what is being
13630printed, @value{GDBN} tries to break the line at a readable place,
13631rather than simply letting it overflow onto the following line.
13632
13633Normally @value{GDBN} knows the size of the screen from the terminal
13634driver software. For example, on Unix @value{GDBN} uses the termcap data base
13635together with the value of the @code{TERM} environment variable and the
13636@code{stty rows} and @code{stty cols} settings. If this is not correct,
13637you can override it with the @code{set height} and @code{set
13638width} commands:
13639
13640@table @code
13641@kindex set height
13642@kindex set width
13643@kindex show width
13644@kindex show height
13645@item set height @var{lpp}
13646@itemx show height
13647@itemx set width @var{cpl}
13648@itemx show width
13649These @code{set} commands specify a screen height of @var{lpp} lines and
13650a screen width of @var{cpl} characters. The associated @code{show}
13651commands display the current settings.
104c1213 13652
8e04817f
AC
13653If you specify a height of zero lines, @value{GDBN} does not pause during
13654output no matter how long the output is. This is useful if output is to a
13655file or to an editor buffer.
104c1213 13656
8e04817f
AC
13657Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13658from wrapping its output.
104c1213
JM
13659@end table
13660
8e04817f
AC
13661@node Numbers
13662@section Numbers
13663@cindex number representation
13664@cindex entering numbers
104c1213 13665
8e04817f
AC
13666You can always enter numbers in octal, decimal, or hexadecimal in
13667@value{GDBN} by the usual conventions: octal numbers begin with
13668@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13669begin with @samp{0x}. Numbers that begin with none of these are, by
13670default, entered in base 10; likewise, the default display for
13671numbers---when no particular format is specified---is base 10. You can
13672change the default base for both input and output with the @code{set
13673radix} command.
104c1213 13674
8e04817f
AC
13675@table @code
13676@kindex set input-radix
13677@item set input-radix @var{base}
13678Set the default base for numeric input. Supported choices
13679for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13680specified either unambiguously or using the current default radix; for
13681example, any of
104c1213 13682
8e04817f
AC
13683@smallexample
13684set radix 012
13685set radix 10.
13686set radix 0xa
13687@end smallexample
104c1213 13688
8e04817f
AC
13689@noindent
13690sets the base to decimal. On the other hand, @samp{set radix 10}
13691leaves the radix unchanged no matter what it was.
104c1213 13692
8e04817f
AC
13693@kindex set output-radix
13694@item set output-radix @var{base}
13695Set the default base for numeric display. Supported choices
13696for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13697specified either unambiguously or using the current default radix.
104c1213 13698
8e04817f
AC
13699@kindex show input-radix
13700@item show input-radix
13701Display the current default base for numeric input.
104c1213 13702
8e04817f
AC
13703@kindex show output-radix
13704@item show output-radix
13705Display the current default base for numeric display.
13706@end table
104c1213 13707
1e698235
DJ
13708@node ABI
13709@section Configuring the current ABI
13710
13711@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13712application automatically. However, sometimes you need to override its
13713conclusions. Use these commands to manage @value{GDBN}'s view of the
13714current ABI.
13715
98b45e30
DJ
13716@cindex OS ABI
13717@kindex set osabi
b4e9345d 13718@kindex show osabi
98b45e30
DJ
13719
13720One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 13721system targets, either via remote debugging or native emulation.
98b45e30
DJ
13722@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13723but you can override its conclusion using the @code{set osabi} command.
13724One example where this is useful is in debugging of binaries which use
13725an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13726not have the same identifying marks that the standard C library for your
13727platform provides.
13728
13729@table @code
13730@item show osabi
13731Show the OS ABI currently in use.
13732
13733@item set osabi
13734With no argument, show the list of registered available OS ABI's.
13735
13736@item set osabi @var{abi}
13737Set the current OS ABI to @var{abi}.
13738@end table
13739
1e698235
DJ
13740@cindex float promotion
13741@kindex set coerce-float-to-double
13742
13743Generally, the way that an argument of type @code{float} is passed to a
13744function depends on whether the function is prototyped. For a prototyped
13745(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13746according to the architecture's convention for @code{float}. For unprototyped
13747(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13748@code{double} and then passed.
13749
13750Unfortunately, some forms of debug information do not reliably indicate whether
13751a function is prototyped. If @value{GDBN} calls a function that is not marked
13752as prototyped, it consults @kbd{set coerce-float-to-double}.
13753
13754@table @code
13755@item set coerce-float-to-double
13756@itemx set coerce-float-to-double on
13757Arguments of type @code{float} will be promoted to @code{double} when passed
13758to an unprototyped function. This is the default setting.
13759
13760@item set coerce-float-to-double off
13761Arguments of type @code{float} will be passed directly to unprototyped
13762functions.
13763@end table
13764
f1212245
DJ
13765@kindex set cp-abi
13766@kindex show cp-abi
13767@value{GDBN} needs to know the ABI used for your program's C@t{++}
13768objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13769used to build your application. @value{GDBN} only fully supports
13770programs with a single C@t{++} ABI; if your program contains code using
13771multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13772program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13773Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13774before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13775``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13776use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13777``auto''.
13778
13779@table @code
13780@item show cp-abi
13781Show the C@t{++} ABI currently in use.
13782
13783@item set cp-abi
13784With no argument, show the list of supported C@t{++} ABI's.
13785
13786@item set cp-abi @var{abi}
13787@itemx set cp-abi auto
13788Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13789@end table
13790
8e04817f
AC
13791@node Messages/Warnings
13792@section Optional warnings and messages
104c1213 13793
8e04817f
AC
13794By default, @value{GDBN} is silent about its inner workings. If you are
13795running on a slow machine, you may want to use the @code{set verbose}
13796command. This makes @value{GDBN} tell you when it does a lengthy
13797internal operation, so you will not think it has crashed.
104c1213 13798
8e04817f
AC
13799Currently, the messages controlled by @code{set verbose} are those
13800which announce that the symbol table for a source file is being read;
13801see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13802
8e04817f
AC
13803@table @code
13804@kindex set verbose
13805@item set verbose on
13806Enables @value{GDBN} output of certain informational messages.
104c1213 13807
8e04817f
AC
13808@item set verbose off
13809Disables @value{GDBN} output of certain informational messages.
104c1213 13810
8e04817f
AC
13811@kindex show verbose
13812@item show verbose
13813Displays whether @code{set verbose} is on or off.
13814@end table
104c1213 13815
8e04817f
AC
13816By default, if @value{GDBN} encounters bugs in the symbol table of an
13817object file, it is silent; but if you are debugging a compiler, you may
13818find this information useful (@pxref{Symbol Errors, ,Errors reading
13819symbol files}).
104c1213 13820
8e04817f 13821@table @code
104c1213 13822
8e04817f
AC
13823@kindex set complaints
13824@item set complaints @var{limit}
13825Permits @value{GDBN} to output @var{limit} complaints about each type of
13826unusual symbols before becoming silent about the problem. Set
13827@var{limit} to zero to suppress all complaints; set it to a large number
13828to prevent complaints from being suppressed.
104c1213 13829
8e04817f
AC
13830@kindex show complaints
13831@item show complaints
13832Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13833
8e04817f 13834@end table
104c1213 13835
8e04817f
AC
13836By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13837lot of stupid questions to confirm certain commands. For example, if
13838you try to run a program which is already running:
104c1213 13839
474c8240 13840@smallexample
8e04817f
AC
13841(@value{GDBP}) run
13842The program being debugged has been started already.
13843Start it from the beginning? (y or n)
474c8240 13844@end smallexample
104c1213 13845
8e04817f
AC
13846If you are willing to unflinchingly face the consequences of your own
13847commands, you can disable this ``feature'':
104c1213 13848
8e04817f 13849@table @code
104c1213 13850
8e04817f
AC
13851@kindex set confirm
13852@cindex flinching
13853@cindex confirmation
13854@cindex stupid questions
13855@item set confirm off
13856Disables confirmation requests.
104c1213 13857
8e04817f
AC
13858@item set confirm on
13859Enables confirmation requests (the default).
104c1213 13860
8e04817f
AC
13861@kindex show confirm
13862@item show confirm
13863Displays state of confirmation requests.
13864
13865@end table
104c1213 13866
8e04817f
AC
13867@node Debugging Output
13868@section Optional messages about internal happenings
4644b6e3
EZ
13869@cindex optional debugging messages
13870
104c1213 13871@table @code
4644b6e3
EZ
13872@kindex set debug
13873@cindex gdbarch debugging info
8e04817f
AC
13874@item set debug arch
13875Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 13876@kindex show debug
8e04817f
AC
13877@item show debug arch
13878Displays the current state of displaying gdbarch debugging info.
8e04817f 13879@item set debug event
4644b6e3 13880@cindex event debugging info
8e04817f
AC
13881Turns on or off display of @value{GDBN} event debugging info. The
13882default is off.
8e04817f
AC
13883@item show debug event
13884Displays the current state of displaying @value{GDBN} event debugging
13885info.
8e04817f 13886@item set debug expression
4644b6e3 13887@cindex expression debugging info
8e04817f
AC
13888Turns on or off display of @value{GDBN} expression debugging info. The
13889default is off.
8e04817f
AC
13890@item show debug expression
13891Displays the current state of displaying @value{GDBN} expression
13892debugging info.
7453dc06 13893@item set debug frame
4644b6e3 13894@cindex frame debugging info
7453dc06
AC
13895Turns on or off display of @value{GDBN} frame debugging info. The
13896default is off.
7453dc06
AC
13897@item show debug frame
13898Displays the current state of displaying @value{GDBN} frame debugging
13899info.
30e91e0b
RC
13900@item set debug infrun
13901@cindex inferior debugging info
13902Turns on or off display of @value{GDBN} debugging info for running the inferior.
13903The default is off. @file{infrun.c} contains GDB's runtime state machine used
13904for implementing operations such as single-stepping the inferior.
13905@item show debug infrun
13906Displays the current state of @value{GDBN} inferior debugging.
2b4855ab 13907@item set debug observer
4644b6e3 13908@cindex observer debugging info
2b4855ab
AC
13909Turns on or off display of @value{GDBN} observer debugging. This
13910includes info such as the notification of observable events.
2b4855ab
AC
13911@item show debug observer
13912Displays the current state of observer debugging.
8e04817f 13913@item set debug overload
4644b6e3 13914@cindex C@t{++} overload debugging info
8e04817f
AC
13915Turns on or off display of @value{GDBN} C@t{++} overload debugging
13916info. This includes info such as ranking of functions, etc. The default
13917is off.
8e04817f
AC
13918@item show debug overload
13919Displays the current state of displaying @value{GDBN} C@t{++} overload
13920debugging info.
8e04817f
AC
13921@cindex packets, reporting on stdout
13922@cindex serial connections, debugging
13923@item set debug remote
13924Turns on or off display of reports on all packets sent back and forth across
13925the serial line to the remote machine. The info is printed on the
13926@value{GDBN} standard output stream. The default is off.
8e04817f
AC
13927@item show debug remote
13928Displays the state of display of remote packets.
8e04817f
AC
13929@item set debug serial
13930Turns on or off display of @value{GDBN} serial debugging info. The
13931default is off.
8e04817f
AC
13932@item show debug serial
13933Displays the current state of displaying @value{GDBN} serial debugging
13934info.
8e04817f 13935@item set debug target
4644b6e3 13936@cindex target debugging info
8e04817f
AC
13937Turns on or off display of @value{GDBN} target debugging info. This info
13938includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
13939default is 0. Set it to 1 to track events, and to 2 to also track the
13940value of large memory transfers. Changes to this flag do not take effect
13941until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
13942@item show debug target
13943Displays the current state of displaying @value{GDBN} target debugging
13944info.
8e04817f 13945@item set debug varobj
4644b6e3 13946@cindex variable object debugging info
8e04817f
AC
13947Turns on or off display of @value{GDBN} variable object debugging
13948info. The default is off.
8e04817f
AC
13949@item show debug varobj
13950Displays the current state of displaying @value{GDBN} variable object
13951debugging info.
13952@end table
104c1213 13953
8e04817f
AC
13954@node Sequences
13955@chapter Canned Sequences of Commands
104c1213 13956
8e04817f
AC
13957Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13958command lists}), @value{GDBN} provides two ways to store sequences of
13959commands for execution as a unit: user-defined commands and command
13960files.
104c1213 13961
8e04817f
AC
13962@menu
13963* Define:: User-defined commands
13964* Hooks:: User-defined command hooks
13965* Command Files:: Command files
13966* Output:: Commands for controlled output
13967@end menu
104c1213 13968
8e04817f
AC
13969@node Define
13970@section User-defined commands
104c1213 13971
8e04817f
AC
13972@cindex user-defined command
13973A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13974which you assign a new name as a command. This is done with the
13975@code{define} command. User commands may accept up to 10 arguments
13976separated by whitespace. Arguments are accessed within the user command
13977via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13978
8e04817f
AC
13979@smallexample
13980define adder
13981 print $arg0 + $arg1 + $arg2
13982@end smallexample
104c1213
JM
13983
13984@noindent
8e04817f 13985To execute the command use:
104c1213 13986
8e04817f
AC
13987@smallexample
13988adder 1 2 3
13989@end smallexample
104c1213 13990
8e04817f
AC
13991@noindent
13992This defines the command @code{adder}, which prints the sum of
13993its three arguments. Note the arguments are text substitutions, so they may
13994reference variables, use complex expressions, or even perform inferior
13995functions calls.
104c1213
JM
13996
13997@table @code
104c1213 13998
8e04817f
AC
13999@kindex define
14000@item define @var{commandname}
14001Define a command named @var{commandname}. If there is already a command
14002by that name, you are asked to confirm that you want to redefine it.
104c1213 14003
8e04817f
AC
14004The definition of the command is made up of other @value{GDBN} command lines,
14005which are given following the @code{define} command. The end of these
14006commands is marked by a line containing @code{end}.
104c1213 14007
8e04817f
AC
14008@kindex if
14009@kindex else
14010@item if
14011Takes a single argument, which is an expression to evaluate.
14012It is followed by a series of commands that are executed
14013only if the expression is true (nonzero).
14014There can then optionally be a line @code{else}, followed
14015by a series of commands that are only executed if the expression
14016was false. The end of the list is marked by a line containing @code{end}.
104c1213 14017
8e04817f
AC
14018@kindex while
14019@item while
14020The syntax is similar to @code{if}: the command takes a single argument,
14021which is an expression to evaluate, and must be followed by the commands to
14022execute, one per line, terminated by an @code{end}.
14023The commands are executed repeatedly as long as the expression
14024evaluates to true.
104c1213 14025
8e04817f
AC
14026@kindex document
14027@item document @var{commandname}
14028Document the user-defined command @var{commandname}, so that it can be
14029accessed by @code{help}. The command @var{commandname} must already be
14030defined. This command reads lines of documentation just as @code{define}
14031reads the lines of the command definition, ending with @code{end}.
14032After the @code{document} command is finished, @code{help} on command
14033@var{commandname} displays the documentation you have written.
104c1213 14034
8e04817f
AC
14035You may use the @code{document} command again to change the
14036documentation of a command. Redefining the command with @code{define}
14037does not change the documentation.
104c1213 14038
8e04817f
AC
14039@kindex help user-defined
14040@item help user-defined
14041List all user-defined commands, with the first line of the documentation
14042(if any) for each.
104c1213 14043
8e04817f
AC
14044@kindex show user
14045@item show user
14046@itemx show user @var{commandname}
14047Display the @value{GDBN} commands used to define @var{commandname} (but
14048not its documentation). If no @var{commandname} is given, display the
14049definitions for all user-defined commands.
104c1213 14050
20f01a46
DH
14051@kindex show max-user-call-depth
14052@kindex set max-user-call-depth
14053@item show max-user-call-depth
5ca0cb28
DH
14054@itemx set max-user-call-depth
14055The value of @code{max-user-call-depth} controls how many recursion
14056levels are allowed in user-defined commands before GDB suspects an
14057infinite recursion and aborts the command.
20f01a46 14058
104c1213
JM
14059@end table
14060
8e04817f
AC
14061When user-defined commands are executed, the
14062commands of the definition are not printed. An error in any command
14063stops execution of the user-defined command.
104c1213 14064
8e04817f
AC
14065If used interactively, commands that would ask for confirmation proceed
14066without asking when used inside a user-defined command. Many @value{GDBN}
14067commands that normally print messages to say what they are doing omit the
14068messages when used in a user-defined command.
104c1213 14069
8e04817f
AC
14070@node Hooks
14071@section User-defined command hooks
14072@cindex command hooks
14073@cindex hooks, for commands
14074@cindex hooks, pre-command
104c1213 14075
8e04817f 14076@kindex hook
8e04817f
AC
14077You may define @dfn{hooks}, which are a special kind of user-defined
14078command. Whenever you run the command @samp{foo}, if the user-defined
14079command @samp{hook-foo} exists, it is executed (with no arguments)
14080before that command.
104c1213 14081
8e04817f
AC
14082@cindex hooks, post-command
14083@kindex hookpost
8e04817f
AC
14084A hook may also be defined which is run after the command you executed.
14085Whenever you run the command @samp{foo}, if the user-defined command
14086@samp{hookpost-foo} exists, it is executed (with no arguments) after
14087that command. Post-execution hooks may exist simultaneously with
14088pre-execution hooks, for the same command.
104c1213 14089
8e04817f 14090It is valid for a hook to call the command which it hooks. If this
9f1c6395 14091occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 14092
8e04817f
AC
14093@c It would be nice if hookpost could be passed a parameter indicating
14094@c if the command it hooks executed properly or not. FIXME!
104c1213 14095
8e04817f
AC
14096@kindex stop@r{, a pseudo-command}
14097In addition, a pseudo-command, @samp{stop} exists. Defining
14098(@samp{hook-stop}) makes the associated commands execute every time
14099execution stops in your program: before breakpoint commands are run,
14100displays are printed, or the stack frame is printed.
104c1213 14101
8e04817f
AC
14102For example, to ignore @code{SIGALRM} signals while
14103single-stepping, but treat them normally during normal execution,
14104you could define:
104c1213 14105
474c8240 14106@smallexample
8e04817f
AC
14107define hook-stop
14108handle SIGALRM nopass
14109end
104c1213 14110
8e04817f
AC
14111define hook-run
14112handle SIGALRM pass
14113end
104c1213 14114
8e04817f
AC
14115define hook-continue
14116handle SIGLARM pass
14117end
474c8240 14118@end smallexample
104c1213 14119
8e04817f 14120As a further example, to hook at the begining and end of the @code{echo}
b383017d 14121command, and to add extra text to the beginning and end of the message,
8e04817f 14122you could define:
104c1213 14123
474c8240 14124@smallexample
8e04817f
AC
14125define hook-echo
14126echo <<<---
14127end
104c1213 14128
8e04817f
AC
14129define hookpost-echo
14130echo --->>>\n
14131end
104c1213 14132
8e04817f
AC
14133(@value{GDBP}) echo Hello World
14134<<<---Hello World--->>>
14135(@value{GDBP})
104c1213 14136
474c8240 14137@end smallexample
104c1213 14138
8e04817f
AC
14139You can define a hook for any single-word command in @value{GDBN}, but
14140not for command aliases; you should define a hook for the basic command
14141name, e.g. @code{backtrace} rather than @code{bt}.
14142@c FIXME! So how does Joe User discover whether a command is an alias
14143@c or not?
14144If an error occurs during the execution of your hook, execution of
14145@value{GDBN} commands stops and @value{GDBN} issues a prompt
14146(before the command that you actually typed had a chance to run).
104c1213 14147
8e04817f
AC
14148If you try to define a hook which does not match any known command, you
14149get a warning from the @code{define} command.
c906108c 14150
8e04817f
AC
14151@node Command Files
14152@section Command files
c906108c 14153
8e04817f
AC
14154@cindex command files
14155A command file for @value{GDBN} is a file of lines that are @value{GDBN}
14156commands. Comments (lines starting with @kbd{#}) may also be included.
14157An empty line in a command file does nothing; it does not mean to repeat
14158the last command, as it would from the terminal.
c906108c 14159
8e04817f
AC
14160@cindex init file
14161@cindex @file{.gdbinit}
14162@cindex @file{gdb.ini}
14163When you start @value{GDBN}, it automatically executes commands from its
14164@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
14165port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
14166limitations of file names imposed by DOS filesystems.}.
14167During startup, @value{GDBN} does the following:
c906108c 14168
8e04817f
AC
14169@enumerate
14170@item
14171Reads the init file (if any) in your home directory@footnote{On
14172DOS/Windows systems, the home directory is the one pointed to by the
14173@code{HOME} environment variable.}.
c906108c 14174
8e04817f
AC
14175@item
14176Processes command line options and operands.
c906108c 14177
8e04817f
AC
14178@item
14179Reads the init file (if any) in the current working directory.
c906108c 14180
8e04817f
AC
14181@item
14182Reads command files specified by the @samp{-x} option.
14183@end enumerate
c906108c 14184
8e04817f
AC
14185The init file in your home directory can set options (such as @samp{set
14186complaints}) that affect subsequent processing of command line options
14187and operands. Init files are not executed if you use the @samp{-nx}
14188option (@pxref{Mode Options, ,Choosing modes}).
c906108c 14189
8e04817f
AC
14190@cindex init file name
14191On some configurations of @value{GDBN}, the init file is known by a
14192different name (these are typically environments where a specialized
14193form of @value{GDBN} may need to coexist with other forms, hence a
14194different name for the specialized version's init file). These are the
14195environments with special init file names:
c906108c 14196
8e04817f
AC
14197@cindex @file{.vxgdbinit}
14198@itemize @bullet
14199@item
14200VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 14201
8e04817f
AC
14202@cindex @file{.os68gdbinit}
14203@item
14204OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 14205
8e04817f
AC
14206@cindex @file{.esgdbinit}
14207@item
14208ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
14209@end itemize
c906108c 14210
8e04817f
AC
14211You can also request the execution of a command file with the
14212@code{source} command:
c906108c 14213
8e04817f
AC
14214@table @code
14215@kindex source
14216@item source @var{filename}
14217Execute the command file @var{filename}.
c906108c
SS
14218@end table
14219
8e04817f 14220The lines in a command file are executed sequentially. They are not
a71ec265
DH
14221printed as they are executed. An error in any command terminates
14222execution of the command file and control is returned to the console.
c906108c 14223
8e04817f
AC
14224Commands that would ask for confirmation if used interactively proceed
14225without asking when used in a command file. Many @value{GDBN} commands that
14226normally print messages to say what they are doing omit the messages
14227when called from command files.
c906108c 14228
8e04817f
AC
14229@value{GDBN} also accepts command input from standard input. In this
14230mode, normal output goes to standard output and error output goes to
14231standard error. Errors in a command file supplied on standard input do
14232not terminate execution of the command file --- execution continues with
14233the next command.
c906108c 14234
474c8240 14235@smallexample
8e04817f 14236gdb < cmds > log 2>&1
474c8240 14237@end smallexample
c906108c 14238
8e04817f
AC
14239(The syntax above will vary depending on the shell used.) This example
14240will execute commands from the file @file{cmds}. All output and errors
14241would be directed to @file{log}.
c906108c 14242
8e04817f
AC
14243@node Output
14244@section Commands for controlled output
c906108c 14245
8e04817f
AC
14246During the execution of a command file or a user-defined command, normal
14247@value{GDBN} output is suppressed; the only output that appears is what is
14248explicitly printed by the commands in the definition. This section
14249describes three commands useful for generating exactly the output you
14250want.
c906108c
SS
14251
14252@table @code
8e04817f
AC
14253@kindex echo
14254@item echo @var{text}
14255@c I do not consider backslash-space a standard C escape sequence
14256@c because it is not in ANSI.
14257Print @var{text}. Nonprinting characters can be included in
14258@var{text} using C escape sequences, such as @samp{\n} to print a
14259newline. @strong{No newline is printed unless you specify one.}
14260In addition to the standard C escape sequences, a backslash followed
14261by a space stands for a space. This is useful for displaying a
14262string with spaces at the beginning or the end, since leading and
14263trailing spaces are otherwise trimmed from all arguments.
14264To print @samp{@w{ }and foo =@w{ }}, use the command
14265@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 14266
8e04817f
AC
14267A backslash at the end of @var{text} can be used, as in C, to continue
14268the command onto subsequent lines. For example,
c906108c 14269
474c8240 14270@smallexample
8e04817f
AC
14271echo This is some text\n\
14272which is continued\n\
14273onto several lines.\n
474c8240 14274@end smallexample
c906108c 14275
8e04817f 14276produces the same output as
c906108c 14277
474c8240 14278@smallexample
8e04817f
AC
14279echo This is some text\n
14280echo which is continued\n
14281echo onto several lines.\n
474c8240 14282@end smallexample
c906108c 14283
8e04817f
AC
14284@kindex output
14285@item output @var{expression}
14286Print the value of @var{expression} and nothing but that value: no
14287newlines, no @samp{$@var{nn} = }. The value is not entered in the
14288value history either. @xref{Expressions, ,Expressions}, for more information
14289on expressions.
c906108c 14290
8e04817f
AC
14291@item output/@var{fmt} @var{expression}
14292Print the value of @var{expression} in format @var{fmt}. You can use
14293the same formats as for @code{print}. @xref{Output Formats,,Output
14294formats}, for more information.
c906108c 14295
8e04817f
AC
14296@kindex printf
14297@item printf @var{string}, @var{expressions}@dots{}
14298Print the values of the @var{expressions} under the control of
14299@var{string}. The @var{expressions} are separated by commas and may be
14300either numbers or pointers. Their values are printed as specified by
14301@var{string}, exactly as if your program were to execute the C
14302subroutine
14303@c FIXME: the above implies that at least all ANSI C formats are
14304@c supported, but it isn't true: %E and %G don't work (or so it seems).
14305@c Either this is a bug, or the manual should document what formats are
14306@c supported.
c906108c 14307
474c8240 14308@smallexample
8e04817f 14309printf (@var{string}, @var{expressions}@dots{});
474c8240 14310@end smallexample
c906108c 14311
8e04817f 14312For example, you can print two values in hex like this:
c906108c 14313
8e04817f
AC
14314@smallexample
14315printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
14316@end smallexample
c906108c 14317
8e04817f
AC
14318The only backslash-escape sequences that you can use in the format
14319string are the simple ones that consist of backslash followed by a
14320letter.
c906108c
SS
14321@end table
14322
21c294e6
AC
14323@node Interpreters
14324@chapter Command Interpreters
14325@cindex command interpreters
14326
14327@value{GDBN} supports multiple command interpreters, and some command
14328infrastructure to allow users or user interface writers to switch
14329between interpreters or run commands in other interpreters.
14330
14331@value{GDBN} currently supports two command interpreters, the console
14332interpreter (sometimes called the command-line interpreter or @sc{cli})
14333and the machine interface interpreter (or @sc{gdb/mi}). This manual
14334describes both of these interfaces in great detail.
14335
14336By default, @value{GDBN} will start with the console interpreter.
14337However, the user may choose to start @value{GDBN} with another
14338interpreter by specifying the @option{-i} or @option{--interpreter}
14339startup options. Defined interpreters include:
14340
14341@table @code
14342@item console
14343@cindex console interpreter
14344The traditional console or command-line interpreter. This is the most often
14345used interpreter with @value{GDBN}. With no interpreter specified at runtime,
14346@value{GDBN} will use this interpreter.
14347
14348@item mi
14349@cindex mi interpreter
14350The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
14351by programs wishing to use @value{GDBN} as a backend for a debugger GUI
14352or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
14353Interface}.
14354
14355@item mi2
14356@cindex mi2 interpreter
14357The current @sc{gdb/mi} interface.
14358
14359@item mi1
14360@cindex mi1 interpreter
14361The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
14362
14363@end table
14364
14365@cindex invoke another interpreter
14366The interpreter being used by @value{GDBN} may not be dynamically
14367switched at runtime. Although possible, this could lead to a very
14368precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
14369enters the command "interpreter-set console" in a console view,
14370@value{GDBN} would switch to using the console interpreter, rendering
14371the IDE inoperable!
14372
14373@kindex interpreter-exec
14374Although you may only choose a single interpreter at startup, you may execute
14375commands in any interpreter from the current interpreter using the appropriate
14376command. If you are running the console interpreter, simply use the
14377@code{interpreter-exec} command:
14378
14379@smallexample
14380interpreter-exec mi "-data-list-register-names"
14381@end smallexample
14382
14383@sc{gdb/mi} has a similar command, although it is only available in versions of
14384@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
14385
8e04817f
AC
14386@node TUI
14387@chapter @value{GDBN} Text User Interface
14388@cindex TUI
d0d5df6f 14389@cindex Text User Interface
c906108c 14390
8e04817f
AC
14391@menu
14392* TUI Overview:: TUI overview
14393* TUI Keys:: TUI key bindings
7cf36c78 14394* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
14395* TUI Commands:: TUI specific commands
14396* TUI Configuration:: TUI configuration variables
14397@end menu
c906108c 14398
d0d5df6f
AC
14399The @value{GDBN} Text User Interface, TUI in short, is a terminal
14400interface which uses the @code{curses} library to show the source
14401file, the assembly output, the program registers and @value{GDBN}
14402commands in separate text windows.
14403
14404The TUI is enabled by invoking @value{GDBN} using either
14405@pindex gdbtui
14406@samp{gdbtui} or @samp{gdb -tui}.
c906108c 14407
8e04817f
AC
14408@node TUI Overview
14409@section TUI overview
c906108c 14410
8e04817f
AC
14411The TUI has two display modes that can be switched while
14412@value{GDBN} runs:
c906108c 14413
8e04817f
AC
14414@itemize @bullet
14415@item
14416A curses (or TUI) mode in which it displays several text
14417windows on the terminal.
c906108c 14418
8e04817f
AC
14419@item
14420A standard mode which corresponds to the @value{GDBN} configured without
14421the TUI.
14422@end itemize
c906108c 14423
8e04817f
AC
14424In the TUI mode, @value{GDBN} can display several text window
14425on the terminal:
c906108c 14426
8e04817f
AC
14427@table @emph
14428@item command
14429This window is the @value{GDBN} command window with the @value{GDBN}
14430prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
14431managed using readline but through the TUI. The @emph{command}
14432window is always visible.
c906108c 14433
8e04817f
AC
14434@item source
14435The source window shows the source file of the program. The current
14436line as well as active breakpoints are displayed in this window.
c906108c 14437
8e04817f
AC
14438@item assembly
14439The assembly window shows the disassembly output of the program.
c906108c 14440
8e04817f
AC
14441@item register
14442This window shows the processor registers. It detects when
14443a register is changed and when this is the case, registers that have
6a1b180d 14444changed are highlighted.
c906108c 14445
c906108c
SS
14446@end table
14447
269c21fe
SC
14448The source and assembly windows show the current program position
14449by highlighting the current line and marking them with the @samp{>} marker.
14450Breakpoints are also indicated with two markers. A first one
14451indicates the breakpoint type:
14452
14453@table @code
14454@item B
14455Breakpoint which was hit at least once.
14456
14457@item b
14458Breakpoint which was never hit.
14459
14460@item H
14461Hardware breakpoint which was hit at least once.
14462
14463@item h
14464Hardware breakpoint which was never hit.
14465
14466@end table
14467
14468The second marker indicates whether the breakpoint is enabled or not:
14469
14470@table @code
14471@item +
14472Breakpoint is enabled.
14473
14474@item -
14475Breakpoint is disabled.
14476
14477@end table
14478
8e04817f
AC
14479The source, assembly and register windows are attached to the thread
14480and the frame position. They are updated when the current thread
14481changes, when the frame changes or when the program counter changes.
14482These three windows are arranged by the TUI according to several
14483layouts. The layout defines which of these three windows are visible.
14484The following layouts are available:
c906108c 14485
8e04817f
AC
14486@itemize @bullet
14487@item
14488source
2df3850c 14489
8e04817f
AC
14490@item
14491assembly
14492
14493@item
14494source and assembly
14495
14496@item
14497source and registers
c906108c 14498
8e04817f
AC
14499@item
14500assembly and registers
2df3850c 14501
8e04817f 14502@end itemize
c906108c 14503
b7bb15bc
SC
14504On top of the command window a status line gives various information
14505concerning the current process begin debugged. The status line is
14506updated when the information it shows changes. The following fields
14507are displayed:
14508
14509@table @emph
14510@item target
14511Indicates the current gdb target
14512(@pxref{Targets, ,Specifying a Debugging Target}).
14513
14514@item process
14515Gives information about the current process or thread number.
14516When no process is being debugged, this field is set to @code{No process}.
14517
14518@item function
14519Gives the current function name for the selected frame.
14520The name is demangled if demangling is turned on (@pxref{Print Settings}).
14521When there is no symbol corresponding to the current program counter
14522the string @code{??} is displayed.
14523
14524@item line
14525Indicates the current line number for the selected frame.
14526When the current line number is not known the string @code{??} is displayed.
14527
14528@item pc
14529Indicates the current program counter address.
14530
14531@end table
14532
8e04817f
AC
14533@node TUI Keys
14534@section TUI Key Bindings
14535@cindex TUI key bindings
c906108c 14536
8e04817f
AC
14537The TUI installs several key bindings in the readline keymaps
14538(@pxref{Command Line Editing}).
14539They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
14540directly on the TUI layout and windows. The TUI also provides
14541a @emph{SingleKey} keymap which binds several keys directly to
14542@value{GDBN} commands. The following key bindings
8e04817f 14543are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 14544
8e04817f
AC
14545@table @kbd
14546@kindex C-x C-a
14547@item C-x C-a
14548@kindex C-x a
14549@itemx C-x a
14550@kindex C-x A
14551@itemx C-x A
14552Enter or leave the TUI mode. When the TUI mode is left,
14553the curses window management is left and @value{GDBN} operates using
14554its standard mode writing on the terminal directly. When the TUI
14555mode is entered, the control is given back to the curses windows.
14556The screen is then refreshed.
c906108c 14557
8e04817f
AC
14558@kindex C-x 1
14559@item C-x 1
14560Use a TUI layout with only one window. The layout will
14561either be @samp{source} or @samp{assembly}. When the TUI mode
14562is not active, it will switch to the TUI mode.
2df3850c 14563
8e04817f 14564Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 14565
8e04817f
AC
14566@kindex C-x 2
14567@item C-x 2
14568Use a TUI layout with at least two windows. When the current
14569layout shows already two windows, a next layout with two windows is used.
14570When a new layout is chosen, one window will always be common to the
14571previous layout and the new one.
c906108c 14572
8e04817f 14573Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 14574
72ffddc9
SC
14575@kindex C-x o
14576@item C-x o
14577Change the active window. The TUI associates several key bindings
14578(like scrolling and arrow keys) to the active window. This command
14579gives the focus to the next TUI window.
14580
14581Think of it as the Emacs @kbd{C-x o} binding.
14582
7cf36c78
SC
14583@kindex C-x s
14584@item C-x s
14585Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
14586(@pxref{TUI Single Key Mode}).
14587
c906108c
SS
14588@end table
14589
8e04817f 14590The following key bindings are handled only by the TUI mode:
5d161b24 14591
8e04817f
AC
14592@table @key
14593@kindex PgUp
14594@item PgUp
14595Scroll the active window one page up.
c906108c 14596
8e04817f
AC
14597@kindex PgDn
14598@item PgDn
14599Scroll the active window one page down.
c906108c 14600
8e04817f
AC
14601@kindex Up
14602@item Up
14603Scroll the active window one line up.
c906108c 14604
8e04817f
AC
14605@kindex Down
14606@item Down
14607Scroll the active window one line down.
c906108c 14608
8e04817f
AC
14609@kindex Left
14610@item Left
14611Scroll the active window one column left.
c906108c 14612
8e04817f
AC
14613@kindex Right
14614@item Right
14615Scroll the active window one column right.
c906108c 14616
8e04817f
AC
14617@kindex C-L
14618@item C-L
14619Refresh the screen.
c906108c 14620
8e04817f 14621@end table
c906108c 14622
8e04817f 14623In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
14624for scrolling. This means they are available for readline when the
14625active window is the command window. When the command window
14626does not have the focus, it is necessary to use other readline
14627key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 14628
7cf36c78
SC
14629@node TUI Single Key Mode
14630@section TUI Single Key Mode
14631@cindex TUI single key mode
14632
14633The TUI provides a @emph{SingleKey} mode in which it installs a particular
14634key binding in the readline keymaps to connect single keys to
b383017d 14635some gdb commands.
7cf36c78
SC
14636
14637@table @kbd
14638@kindex c @r{(SingleKey TUI key)}
14639@item c
14640continue
14641
14642@kindex d @r{(SingleKey TUI key)}
14643@item d
14644down
14645
14646@kindex f @r{(SingleKey TUI key)}
14647@item f
14648finish
14649
14650@kindex n @r{(SingleKey TUI key)}
14651@item n
14652next
14653
14654@kindex q @r{(SingleKey TUI key)}
14655@item q
14656exit the @emph{SingleKey} mode.
14657
14658@kindex r @r{(SingleKey TUI key)}
14659@item r
14660run
14661
14662@kindex s @r{(SingleKey TUI key)}
14663@item s
14664step
14665
14666@kindex u @r{(SingleKey TUI key)}
14667@item u
14668up
14669
14670@kindex v @r{(SingleKey TUI key)}
14671@item v
14672info locals
14673
14674@kindex w @r{(SingleKey TUI key)}
14675@item w
14676where
14677
14678@end table
14679
14680Other keys temporarily switch to the @value{GDBN} command prompt.
14681The key that was pressed is inserted in the editing buffer so that
14682it is possible to type most @value{GDBN} commands without interaction
14683with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14684@emph{SingleKey} mode is restored. The only way to permanently leave
14685this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14686
14687
8e04817f
AC
14688@node TUI Commands
14689@section TUI specific commands
14690@cindex TUI commands
14691
14692The TUI has specific commands to control the text windows.
14693These commands are always available, that is they do not depend on
14694the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14695is in the standard mode, using these commands will automatically switch
14696in the TUI mode.
c906108c
SS
14697
14698@table @code
3d757584
SC
14699@item info win
14700@kindex info win
14701List and give the size of all displayed windows.
14702
8e04817f 14703@item layout next
4644b6e3 14704@kindex layout
8e04817f 14705Display the next layout.
2df3850c 14706
8e04817f 14707@item layout prev
8e04817f 14708Display the previous layout.
c906108c 14709
8e04817f 14710@item layout src
8e04817f 14711Display the source window only.
c906108c 14712
8e04817f 14713@item layout asm
8e04817f 14714Display the assembly window only.
c906108c 14715
8e04817f 14716@item layout split
8e04817f 14717Display the source and assembly window.
c906108c 14718
8e04817f 14719@item layout regs
8e04817f
AC
14720Display the register window together with the source or assembly window.
14721
14722@item focus next | prev | src | asm | regs | split
14723@kindex focus
14724Set the focus to the named window.
14725This command allows to change the active window so that scrolling keys
14726can be affected to another window.
c906108c 14727
8e04817f
AC
14728@item refresh
14729@kindex refresh
14730Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14731
6a1b180d
SC
14732@item tui reg float
14733@kindex tui reg
14734Show the floating point registers in the register window.
14735
14736@item tui reg general
14737Show the general registers in the register window.
14738
14739@item tui reg next
14740Show the next register group. The list of register groups as well as
14741their order is target specific. The predefined register groups are the
14742following: @code{general}, @code{float}, @code{system}, @code{vector},
14743@code{all}, @code{save}, @code{restore}.
14744
14745@item tui reg system
14746Show the system registers in the register window.
14747
8e04817f
AC
14748@item update
14749@kindex update
14750Update the source window and the current execution point.
c906108c 14751
8e04817f
AC
14752@item winheight @var{name} +@var{count}
14753@itemx winheight @var{name} -@var{count}
14754@kindex winheight
14755Change the height of the window @var{name} by @var{count}
14756lines. Positive counts increase the height, while negative counts
14757decrease it.
2df3850c 14758
c906108c
SS
14759@end table
14760
8e04817f
AC
14761@node TUI Configuration
14762@section TUI configuration variables
14763@cindex TUI configuration variables
c906108c 14764
8e04817f
AC
14765The TUI has several configuration variables that control the
14766appearance of windows on the terminal.
c906108c 14767
8e04817f
AC
14768@table @code
14769@item set tui border-kind @var{kind}
14770@kindex set tui border-kind
14771Select the border appearance for the source, assembly and register windows.
14772The possible values are the following:
14773@table @code
14774@item space
14775Use a space character to draw the border.
c906108c 14776
8e04817f
AC
14777@item ascii
14778Use ascii characters + - and | to draw the border.
c906108c 14779
8e04817f
AC
14780@item acs
14781Use the Alternate Character Set to draw the border. The border is
14782drawn using character line graphics if the terminal supports them.
c78b4128 14783
8e04817f 14784@end table
c78b4128 14785
8e04817f
AC
14786@item set tui active-border-mode @var{mode}
14787@kindex set tui active-border-mode
14788Select the attributes to display the border of the active window.
14789The possible values are @code{normal}, @code{standout}, @code{reverse},
14790@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14791
8e04817f
AC
14792@item set tui border-mode @var{mode}
14793@kindex set tui border-mode
14794Select the attributes to display the border of other windows.
14795The @var{mode} can be one of the following:
14796@table @code
14797@item normal
14798Use normal attributes to display the border.
c906108c 14799
8e04817f
AC
14800@item standout
14801Use standout mode.
c906108c 14802
8e04817f
AC
14803@item reverse
14804Use reverse video mode.
c906108c 14805
8e04817f
AC
14806@item half
14807Use half bright mode.
c906108c 14808
8e04817f
AC
14809@item half-standout
14810Use half bright and standout mode.
c906108c 14811
8e04817f
AC
14812@item bold
14813Use extra bright or bold mode.
c78b4128 14814
8e04817f
AC
14815@item bold-standout
14816Use extra bright or bold and standout mode.
c78b4128 14817
8e04817f 14818@end table
c78b4128 14819
8e04817f 14820@end table
c78b4128 14821
8e04817f
AC
14822@node Emacs
14823@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14824
8e04817f
AC
14825@cindex Emacs
14826@cindex @sc{gnu} Emacs
14827A special interface allows you to use @sc{gnu} Emacs to view (and
14828edit) the source files for the program you are debugging with
14829@value{GDBN}.
c906108c 14830
8e04817f
AC
14831To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14832executable file you want to debug as an argument. This command starts
14833@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14834created Emacs buffer.
14835@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14836
8e04817f
AC
14837Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14838things:
c906108c 14839
8e04817f
AC
14840@itemize @bullet
14841@item
14842All ``terminal'' input and output goes through the Emacs buffer.
14843@end itemize
c906108c 14844
8e04817f
AC
14845This applies both to @value{GDBN} commands and their output, and to the input
14846and output done by the program you are debugging.
bf0184be 14847
8e04817f
AC
14848This is useful because it means that you can copy the text of previous
14849commands and input them again; you can even use parts of the output
14850in this way.
bf0184be 14851
8e04817f
AC
14852All the facilities of Emacs' Shell mode are available for interacting
14853with your program. In particular, you can send signals the usual
14854way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14855stop.
bf0184be 14856
8e04817f 14857@itemize @bullet
bf0184be 14858@item
8e04817f
AC
14859@value{GDBN} displays source code through Emacs.
14860@end itemize
bf0184be 14861
8e04817f
AC
14862Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14863source file for that frame and puts an arrow (@samp{=>}) at the
14864left margin of the current line. Emacs uses a separate buffer for
14865source display, and splits the screen to show both your @value{GDBN} session
14866and the source.
bf0184be 14867
8e04817f
AC
14868Explicit @value{GDBN} @code{list} or search commands still produce output as
14869usual, but you probably have no reason to use them from Emacs.
c906108c 14870
64fabec2
AC
14871If you specify an absolute file name when prompted for the @kbd{M-x
14872gdb} argument, then Emacs sets your current working directory to where
14873your program resides. If you only specify the file name, then Emacs
14874sets your current working directory to to the directory associated
14875with the previous buffer. In this case, @value{GDBN} may find your
14876program by searching your environment's @code{PATH} variable, but on
14877some operating systems it might not find the source. So, although the
14878@value{GDBN} input and output session proceeds normally, the auxiliary
14879buffer does not display the current source and line of execution.
14880
14881The initial working directory of @value{GDBN} is printed on the top
14882line of the @value{GDBN} I/O buffer and this serves as a default for
14883the commands that specify files for @value{GDBN} to operate
14884on. @xref{Files, ,Commands to specify files}.
14885
14886By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14887need to call @value{GDBN} by a different name (for example, if you
14888keep several configurations around, with different names) you can
14889customize the Emacs variable @code{gud-gdb-command-name} to run the
14890one you want.
8e04817f
AC
14891
14892In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14893addition to the standard Shell mode commands:
c906108c 14894
8e04817f
AC
14895@table @kbd
14896@item C-h m
14897Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14898
64fabec2 14899@item C-c C-s
8e04817f
AC
14900Execute to another source line, like the @value{GDBN} @code{step} command; also
14901update the display window to show the current file and location.
c906108c 14902
64fabec2 14903@item C-c C-n
8e04817f
AC
14904Execute to next source line in this function, skipping all function
14905calls, like the @value{GDBN} @code{next} command. Then update the display window
14906to show the current file and location.
c906108c 14907
64fabec2 14908@item C-c C-i
8e04817f
AC
14909Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14910display window accordingly.
c906108c 14911
8e04817f
AC
14912@item C-c C-f
14913Execute until exit from the selected stack frame, like the @value{GDBN}
14914@code{finish} command.
c906108c 14915
64fabec2 14916@item C-c C-r
8e04817f
AC
14917Continue execution of your program, like the @value{GDBN} @code{continue}
14918command.
b433d00b 14919
64fabec2 14920@item C-c <
8e04817f
AC
14921Go up the number of frames indicated by the numeric argument
14922(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14923like the @value{GDBN} @code{up} command.
b433d00b 14924
64fabec2 14925@item C-c >
8e04817f
AC
14926Go down the number of frames indicated by the numeric argument, like the
14927@value{GDBN} @code{down} command.
8e04817f 14928@end table
c906108c 14929
64fabec2 14930In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14931tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14932
64fabec2
AC
14933If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14934shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14935point to any frame in the stack and type @key{RET} to make it become the
14936current frame and display the associated source in the source buffer.
14937Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14938current one.
14939
8e04817f
AC
14940If you accidentally delete the source-display buffer, an easy way to get
14941it back is to type the command @code{f} in the @value{GDBN} buffer, to
14942request a frame display; when you run under Emacs, this recreates
14943the source buffer if necessary to show you the context of the current
14944frame.
c906108c 14945
8e04817f
AC
14946The source files displayed in Emacs are in ordinary Emacs buffers
14947which are visiting the source files in the usual way. You can edit
14948the files with these buffers if you wish; but keep in mind that @value{GDBN}
14949communicates with Emacs in terms of line numbers. If you add or
14950delete lines from the text, the line numbers that @value{GDBN} knows cease
14951to correspond properly with the code.
b383017d 14952
64fabec2
AC
14953The description given here is for GNU Emacs version 21.3 and a more
14954detailed description of its interaction with @value{GDBN} is given in
14955the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14956
8e04817f
AC
14957@c The following dropped because Epoch is nonstandard. Reactivate
14958@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14959@ignore
14960@kindex Emacs Epoch environment
14961@kindex Epoch
14962@kindex inspect
c906108c 14963
8e04817f
AC
14964Version 18 of @sc{gnu} Emacs has a built-in window system
14965called the @code{epoch}
14966environment. Users of this environment can use a new command,
14967@code{inspect} which performs identically to @code{print} except that
14968each value is printed in its own window.
14969@end ignore
c906108c 14970
922fbb7b
AC
14971
14972@node GDB/MI
14973@chapter The @sc{gdb/mi} Interface
14974
14975@unnumberedsec Function and Purpose
14976
14977@cindex @sc{gdb/mi}, its purpose
14978@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14979specifically intended to support the development of systems which use
14980the debugger as just one small component of a larger system.
14981
14982This chapter is a specification of the @sc{gdb/mi} interface. It is written
14983in the form of a reference manual.
14984
14985Note that @sc{gdb/mi} is still under construction, so some of the
14986features described below are incomplete and subject to change.
14987
14988@unnumberedsec Notation and Terminology
14989
14990@cindex notational conventions, for @sc{gdb/mi}
14991This chapter uses the following notation:
14992
14993@itemize @bullet
14994@item
14995@code{|} separates two alternatives.
14996
14997@item
14998@code{[ @var{something} ]} indicates that @var{something} is optional:
14999it may or may not be given.
15000
15001@item
15002@code{( @var{group} )*} means that @var{group} inside the parentheses
15003may repeat zero or more times.
15004
15005@item
15006@code{( @var{group} )+} means that @var{group} inside the parentheses
15007may repeat one or more times.
15008
15009@item
15010@code{"@var{string}"} means a literal @var{string}.
15011@end itemize
15012
15013@ignore
15014@heading Dependencies
15015@end ignore
15016
15017@heading Acknowledgments
15018
15019In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
15020Elena Zannoni.
15021
15022@menu
15023* GDB/MI Command Syntax::
15024* GDB/MI Compatibility with CLI::
15025* GDB/MI Output Records::
15026* GDB/MI Command Description Format::
15027* GDB/MI Breakpoint Table Commands::
15028* GDB/MI Data Manipulation::
15029* GDB/MI Program Control::
15030* GDB/MI Miscellaneous Commands::
15031@ignore
15032* GDB/MI Kod Commands::
15033* GDB/MI Memory Overlay Commands::
15034* GDB/MI Signal Handling Commands::
15035@end ignore
15036* GDB/MI Stack Manipulation::
15037* GDB/MI Symbol Query::
15038* GDB/MI Target Manipulation::
15039* GDB/MI Thread Commands::
15040* GDB/MI Tracepoint Commands::
15041* GDB/MI Variable Objects::
15042@end menu
15043
15044@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15045@node GDB/MI Command Syntax
15046@section @sc{gdb/mi} Command Syntax
15047
15048@menu
15049* GDB/MI Input Syntax::
15050* GDB/MI Output Syntax::
15051* GDB/MI Simple Examples::
15052@end menu
15053
15054@node GDB/MI Input Syntax
15055@subsection @sc{gdb/mi} Input Syntax
15056
15057@cindex input syntax for @sc{gdb/mi}
15058@cindex @sc{gdb/mi}, input syntax
15059@table @code
15060@item @var{command} @expansion{}
15061@code{@var{cli-command} | @var{mi-command}}
15062
15063@item @var{cli-command} @expansion{}
15064@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
15065@var{cli-command} is any existing @value{GDBN} CLI command.
15066
15067@item @var{mi-command} @expansion{}
15068@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
15069@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
15070
15071@item @var{token} @expansion{}
15072"any sequence of digits"
15073
15074@item @var{option} @expansion{}
15075@code{"-" @var{parameter} [ " " @var{parameter} ]}
15076
15077@item @var{parameter} @expansion{}
15078@code{@var{non-blank-sequence} | @var{c-string}}
15079
15080@item @var{operation} @expansion{}
15081@emph{any of the operations described in this chapter}
15082
15083@item @var{non-blank-sequence} @expansion{}
15084@emph{anything, provided it doesn't contain special characters such as
15085"-", @var{nl}, """ and of course " "}
15086
15087@item @var{c-string} @expansion{}
15088@code{""" @var{seven-bit-iso-c-string-content} """}
15089
15090@item @var{nl} @expansion{}
15091@code{CR | CR-LF}
15092@end table
15093
15094@noindent
15095Notes:
15096
15097@itemize @bullet
15098@item
15099The CLI commands are still handled by the @sc{mi} interpreter; their
15100output is described below.
15101
15102@item
15103The @code{@var{token}}, when present, is passed back when the command
15104finishes.
15105
15106@item
15107Some @sc{mi} commands accept optional arguments as part of the parameter
15108list. Each option is identified by a leading @samp{-} (dash) and may be
15109followed by an optional argument parameter. Options occur first in the
15110parameter list and can be delimited from normal parameters using
15111@samp{--} (this is useful when some parameters begin with a dash).
15112@end itemize
15113
15114Pragmatics:
15115
15116@itemize @bullet
15117@item
15118We want easy access to the existing CLI syntax (for debugging).
15119
15120@item
15121We want it to be easy to spot a @sc{mi} operation.
15122@end itemize
15123
15124@node GDB/MI Output Syntax
15125@subsection @sc{gdb/mi} Output Syntax
15126
15127@cindex output syntax of @sc{gdb/mi}
15128@cindex @sc{gdb/mi}, output syntax
15129The output from @sc{gdb/mi} consists of zero or more out-of-band records
15130followed, optionally, by a single result record. This result record
15131is for the most recent command. The sequence of output records is
15132terminated by @samp{(@value{GDBP})}.
15133
15134If an input command was prefixed with a @code{@var{token}} then the
15135corresponding output for that command will also be prefixed by that same
15136@var{token}.
15137
15138@table @code
15139@item @var{output} @expansion{}
f7dc1244 15140@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
15141
15142@item @var{result-record} @expansion{}
15143@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
15144
15145@item @var{out-of-band-record} @expansion{}
15146@code{@var{async-record} | @var{stream-record}}
15147
15148@item @var{async-record} @expansion{}
15149@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
15150
15151@item @var{exec-async-output} @expansion{}
15152@code{[ @var{token} ] "*" @var{async-output}}
15153
15154@item @var{status-async-output} @expansion{}
15155@code{[ @var{token} ] "+" @var{async-output}}
15156
15157@item @var{notify-async-output} @expansion{}
15158@code{[ @var{token} ] "=" @var{async-output}}
15159
15160@item @var{async-output} @expansion{}
15161@code{@var{async-class} ( "," @var{result} )* @var{nl}}
15162
15163@item @var{result-class} @expansion{}
15164@code{"done" | "running" | "connected" | "error" | "exit"}
15165
15166@item @var{async-class} @expansion{}
15167@code{"stopped" | @var{others}} (where @var{others} will be added
15168depending on the needs---this is still in development).
15169
15170@item @var{result} @expansion{}
15171@code{ @var{variable} "=" @var{value}}
15172
15173@item @var{variable} @expansion{}
15174@code{ @var{string} }
15175
15176@item @var{value} @expansion{}
15177@code{ @var{const} | @var{tuple} | @var{list} }
15178
15179@item @var{const} @expansion{}
15180@code{@var{c-string}}
15181
15182@item @var{tuple} @expansion{}
15183@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
15184
15185@item @var{list} @expansion{}
15186@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
15187@var{result} ( "," @var{result} )* "]" }
15188
15189@item @var{stream-record} @expansion{}
15190@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
15191
15192@item @var{console-stream-output} @expansion{}
15193@code{"~" @var{c-string}}
15194
15195@item @var{target-stream-output} @expansion{}
15196@code{"@@" @var{c-string}}
15197
15198@item @var{log-stream-output} @expansion{}
15199@code{"&" @var{c-string}}
15200
15201@item @var{nl} @expansion{}
15202@code{CR | CR-LF}
15203
15204@item @var{token} @expansion{}
15205@emph{any sequence of digits}.
15206@end table
15207
15208@noindent
15209Notes:
15210
15211@itemize @bullet
15212@item
15213All output sequences end in a single line containing a period.
15214
15215@item
15216The @code{@var{token}} is from the corresponding request. If an execution
15217command is interrupted by the @samp{-exec-interrupt} command, the
15218@var{token} associated with the @samp{*stopped} message is the one of the
15219original execution command, not the one of the interrupt command.
15220
15221@item
15222@cindex status output in @sc{gdb/mi}
15223@var{status-async-output} contains on-going status information about the
15224progress of a slow operation. It can be discarded. All status output is
15225prefixed by @samp{+}.
15226
15227@item
15228@cindex async output in @sc{gdb/mi}
15229@var{exec-async-output} contains asynchronous state change on the target
15230(stopped, started, disappeared). All async output is prefixed by
15231@samp{*}.
15232
15233@item
15234@cindex notify output in @sc{gdb/mi}
15235@var{notify-async-output} contains supplementary information that the
15236client should handle (e.g., a new breakpoint information). All notify
15237output is prefixed by @samp{=}.
15238
15239@item
15240@cindex console output in @sc{gdb/mi}
15241@var{console-stream-output} is output that should be displayed as is in the
15242console. It is the textual response to a CLI command. All the console
15243output is prefixed by @samp{~}.
15244
15245@item
15246@cindex target output in @sc{gdb/mi}
15247@var{target-stream-output} is the output produced by the target program.
15248All the target output is prefixed by @samp{@@}.
15249
15250@item
15251@cindex log output in @sc{gdb/mi}
15252@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
15253instance messages that should be displayed as part of an error log. All
15254the log output is prefixed by @samp{&}.
15255
15256@item
15257@cindex list output in @sc{gdb/mi}
15258New @sc{gdb/mi} commands should only output @var{lists} containing
15259@var{values}.
15260
15261
15262@end itemize
15263
15264@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
15265details about the various output records.
15266
15267@node GDB/MI Simple Examples
15268@subsection Simple Examples of @sc{gdb/mi} Interaction
15269@cindex @sc{gdb/mi}, simple examples
15270
15271This subsection presents several simple examples of interaction using
15272the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
15273following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
15274the output received from @sc{gdb/mi}.
15275
15276@subsubheading Target Stop
15277@c Ummm... There is no "-stop" command. This assumes async, no?
15278Here's an example of stopping the inferior process:
15279
15280@smallexample
15281-> -stop
15282<- (@value{GDBP})
15283@end smallexample
15284
15285@noindent
15286and later:
15287
15288@smallexample
15289<- *stop,reason="stop",address="0x123",source="a.c:123"
15290<- (@value{GDBP})
15291@end smallexample
15292
15293@subsubheading Simple CLI Command
15294
15295Here's an example of a simple CLI command being passed through
15296@sc{gdb/mi} and on to the CLI.
15297
15298@smallexample
15299-> print 1+2
15300<- &"print 1+2\n"
15301<- ~"$1 = 3\n"
15302<- ^done
15303<- (@value{GDBP})
15304@end smallexample
15305
15306@subsubheading Command With Side Effects
15307
15308@smallexample
15309-> -symbol-file xyz.exe
15310<- *breakpoint,nr="3",address="0x123",source="a.c:123"
15311<- (@value{GDBP})
15312@end smallexample
15313
15314@subsubheading A Bad Command
15315
15316Here's what happens if you pass a non-existent command:
15317
15318@smallexample
15319-> -rubbish
15320<- ^error,msg="Undefined MI command: rubbish"
15321<- (@value{GDBP})
15322@end smallexample
15323
15324@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15325@node GDB/MI Compatibility with CLI
15326@section @sc{gdb/mi} Compatibility with CLI
15327
15328@cindex compatibility, @sc{gdb/mi} and CLI
15329@cindex @sc{gdb/mi}, compatibility with CLI
15330To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
15331accepts existing CLI commands. As specified by the syntax, such
15332commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
15333respond.
15334
15335This mechanism is provided as an aid to developers of @sc{gdb/mi}
15336clients and not as a reliable interface into the CLI. Since the command
15337is being interpreteted in an environment that assumes @sc{gdb/mi}
15338behaviour, the exact output of such commands is likely to end up being
15339an un-supported hybrid of @sc{gdb/mi} and CLI output.
15340
15341@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15342@node GDB/MI Output Records
15343@section @sc{gdb/mi} Output Records
15344
15345@menu
15346* GDB/MI Result Records::
15347* GDB/MI Stream Records::
15348* GDB/MI Out-of-band Records::
15349@end menu
15350
15351@node GDB/MI Result Records
15352@subsection @sc{gdb/mi} Result Records
15353
15354@cindex result records in @sc{gdb/mi}
15355@cindex @sc{gdb/mi}, result records
15356In addition to a number of out-of-band notifications, the response to a
15357@sc{gdb/mi} command includes one of the following result indications:
15358
15359@table @code
15360@findex ^done
15361@item "^done" [ "," @var{results} ]
15362The synchronous operation was successful, @code{@var{results}} are the return
15363values.
15364
15365@item "^running"
15366@findex ^running
15367@c Is this one correct? Should it be an out-of-band notification?
15368The asynchronous operation was successfully started. The target is
15369running.
15370
15371@item "^error" "," @var{c-string}
15372@findex ^error
15373The operation failed. The @code{@var{c-string}} contains the corresponding
15374error message.
15375@end table
15376
15377@node GDB/MI Stream Records
15378@subsection @sc{gdb/mi} Stream Records
15379
15380@cindex @sc{gdb/mi}, stream records
15381@cindex stream records in @sc{gdb/mi}
15382@value{GDBN} internally maintains a number of output streams: the console, the
15383target, and the log. The output intended for each of these streams is
15384funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
15385
15386Each stream record begins with a unique @dfn{prefix character} which
15387identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
15388Syntax}). In addition to the prefix, each stream record contains a
15389@code{@var{string-output}}. This is either raw text (with an implicit new
15390line) or a quoted C string (which does not contain an implicit newline).
15391
15392@table @code
15393@item "~" @var{string-output}
15394The console output stream contains text that should be displayed in the
15395CLI console window. It contains the textual responses to CLI commands.
15396
15397@item "@@" @var{string-output}
15398The target output stream contains any textual output from the running
15399target.
15400
15401@item "&" @var{string-output}
15402The log stream contains debugging messages being produced by @value{GDBN}'s
15403internals.
15404@end table
15405
15406@node GDB/MI Out-of-band Records
15407@subsection @sc{gdb/mi} Out-of-band Records
15408
15409@cindex out-of-band records in @sc{gdb/mi}
15410@cindex @sc{gdb/mi}, out-of-band records
15411@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
15412additional changes that have occurred. Those changes can either be a
15413consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
15414target activity (e.g., target stopped).
15415
15416The following is a preliminary list of possible out-of-band records.
15417
15418@table @code
15419@item "*" "stop"
15420@end table
15421
15422
15423@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15424@node GDB/MI Command Description Format
15425@section @sc{gdb/mi} Command Description Format
15426
15427The remaining sections describe blocks of commands. Each block of
15428commands is laid out in a fashion similar to this section.
15429
15430Note the the line breaks shown in the examples are here only for
15431readability. They don't appear in the real output.
15432Also note that the commands with a non-available example (N.A.@:) are
15433not yet implemented.
15434
15435@subheading Motivation
15436
15437The motivation for this collection of commands.
15438
15439@subheading Introduction
15440
15441A brief introduction to this collection of commands as a whole.
15442
15443@subheading Commands
15444
15445For each command in the block, the following is described:
15446
15447@subsubheading Synopsis
15448
15449@smallexample
15450 -command @var{args}@dots{}
15451@end smallexample
15452
15453@subsubheading @value{GDBN} Command
15454
15455The corresponding @value{GDBN} CLI command.
15456
15457@subsubheading Result
15458
15459@subsubheading Out-of-band
15460
15461@subsubheading Notes
15462
15463@subsubheading Example
15464
15465
15466@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15467@node GDB/MI Breakpoint Table Commands
15468@section @sc{gdb/mi} Breakpoint table commands
15469
15470@cindex breakpoint commands for @sc{gdb/mi}
15471@cindex @sc{gdb/mi}, breakpoint commands
15472This section documents @sc{gdb/mi} commands for manipulating
15473breakpoints.
15474
15475@subheading The @code{-break-after} Command
15476@findex -break-after
15477
15478@subsubheading Synopsis
15479
15480@smallexample
15481 -break-after @var{number} @var{count}
15482@end smallexample
15483
15484The breakpoint number @var{number} is not in effect until it has been
15485hit @var{count} times. To see how this is reflected in the output of
15486the @samp{-break-list} command, see the description of the
15487@samp{-break-list} command below.
15488
15489@subsubheading @value{GDBN} Command
15490
15491The corresponding @value{GDBN} command is @samp{ignore}.
15492
15493@subsubheading Example
15494
15495@smallexample
15496(@value{GDBP})
15497-break-insert main
15498^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
15499(@value{GDBP})
15500-break-after 1 3
15501~
15502^done
15503(@value{GDBP})
15504-break-list
15505^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15506hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15507@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15508@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15509@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15510@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15511@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15512body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15513addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
15514ignore="3"@}]@}
15515(@value{GDBP})
15516@end smallexample
15517
15518@ignore
15519@subheading The @code{-break-catch} Command
15520@findex -break-catch
15521
15522@subheading The @code{-break-commands} Command
15523@findex -break-commands
15524@end ignore
15525
15526
15527@subheading The @code{-break-condition} Command
15528@findex -break-condition
15529
15530@subsubheading Synopsis
15531
15532@smallexample
15533 -break-condition @var{number} @var{expr}
15534@end smallexample
15535
15536Breakpoint @var{number} will stop the program only if the condition in
15537@var{expr} is true. The condition becomes part of the
15538@samp{-break-list} output (see the description of the @samp{-break-list}
15539command below).
15540
15541@subsubheading @value{GDBN} Command
15542
15543The corresponding @value{GDBN} command is @samp{condition}.
15544
15545@subsubheading Example
15546
15547@smallexample
15548(@value{GDBP})
15549-break-condition 1 1
15550^done
15551(@value{GDBP})
15552-break-list
15553^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15554hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15555@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15556@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15557@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15558@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15559@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15560body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15561addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
15562times="0",ignore="3"@}]@}
15563(@value{GDBP})
15564@end smallexample
15565
15566@subheading The @code{-break-delete} Command
15567@findex -break-delete
15568
15569@subsubheading Synopsis
15570
15571@smallexample
15572 -break-delete ( @var{breakpoint} )+
15573@end smallexample
15574
15575Delete the breakpoint(s) whose number(s) are specified in the argument
15576list. This is obviously reflected in the breakpoint list.
15577
15578@subsubheading @value{GDBN} command
15579
15580The corresponding @value{GDBN} command is @samp{delete}.
15581
15582@subsubheading Example
15583
15584@smallexample
15585(@value{GDBP})
15586-break-delete 1
15587^done
15588(@value{GDBP})
15589-break-list
15590^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15591hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15592@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15593@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15594@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15595@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15596@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15597body=[]@}
15598(@value{GDBP})
15599@end smallexample
15600
15601@subheading The @code{-break-disable} Command
15602@findex -break-disable
15603
15604@subsubheading Synopsis
15605
15606@smallexample
15607 -break-disable ( @var{breakpoint} )+
15608@end smallexample
15609
15610Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
15611break list is now set to @samp{n} for the named @var{breakpoint}(s).
15612
15613@subsubheading @value{GDBN} Command
15614
15615The corresponding @value{GDBN} command is @samp{disable}.
15616
15617@subsubheading Example
15618
15619@smallexample
15620(@value{GDBP})
15621-break-disable 2
15622^done
15623(@value{GDBP})
15624-break-list
15625^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15626hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15627@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15628@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15629@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15630@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15631@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15632body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15633addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15634(@value{GDBP})
15635@end smallexample
15636
15637@subheading The @code{-break-enable} Command
15638@findex -break-enable
15639
15640@subsubheading Synopsis
15641
15642@smallexample
15643 -break-enable ( @var{breakpoint} )+
15644@end smallexample
15645
15646Enable (previously disabled) @var{breakpoint}(s).
15647
15648@subsubheading @value{GDBN} Command
15649
15650The corresponding @value{GDBN} command is @samp{enable}.
15651
15652@subsubheading Example
15653
15654@smallexample
15655(@value{GDBP})
15656-break-enable 2
15657^done
15658(@value{GDBP})
15659-break-list
15660^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15661hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15662@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15663@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15664@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15665@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15666@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15667body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15668addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15669(@value{GDBP})
15670@end smallexample
15671
15672@subheading The @code{-break-info} Command
15673@findex -break-info
15674
15675@subsubheading Synopsis
15676
15677@smallexample
15678 -break-info @var{breakpoint}
15679@end smallexample
15680
15681@c REDUNDANT???
15682Get information about a single breakpoint.
15683
15684@subsubheading @value{GDBN} command
15685
15686The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15687
15688@subsubheading Example
15689N.A.
15690
15691@subheading The @code{-break-insert} Command
15692@findex -break-insert
15693
15694@subsubheading Synopsis
15695
15696@smallexample
15697 -break-insert [ -t ] [ -h ] [ -r ]
15698 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15699 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15700@end smallexample
15701
15702@noindent
15703If specified, @var{line}, can be one of:
15704
15705@itemize @bullet
15706@item function
15707@c @item +offset
15708@c @item -offset
15709@c @item linenum
15710@item filename:linenum
15711@item filename:function
15712@item *address
15713@end itemize
15714
15715The possible optional parameters of this command are:
15716
15717@table @samp
15718@item -t
15719Insert a tempoary breakpoint.
15720@item -h
15721Insert a hardware breakpoint.
15722@item -c @var{condition}
15723Make the breakpoint conditional on @var{condition}.
15724@item -i @var{ignore-count}
15725Initialize the @var{ignore-count}.
15726@item -r
15727Insert a regular breakpoint in all the functions whose names match the
15728given regular expression. Other flags are not applicable to regular
15729expresson.
15730@end table
15731
15732@subsubheading Result
15733
15734The result is in the form:
15735
15736@smallexample
15737 ^done,bkptno="@var{number}",func="@var{funcname}",
15738 file="@var{filename}",line="@var{lineno}"
15739@end smallexample
15740
15741@noindent
15742where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15743is the name of the function where the breakpoint was inserted,
15744@var{filename} is the name of the source file which contains this
15745function, and @var{lineno} is the source line number within that file.
15746
15747Note: this format is open to change.
15748@c An out-of-band breakpoint instead of part of the result?
15749
15750@subsubheading @value{GDBN} Command
15751
15752The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15753@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15754
15755@subsubheading Example
15756
15757@smallexample
15758(@value{GDBP})
15759-break-insert main
15760^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15761(@value{GDBP})
15762-break-insert -t foo
15763^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15764(@value{GDBP})
15765-break-list
15766^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15767hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15768@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15769@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15770@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15771@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15772@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15773body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15774addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15775bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15776addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15777(@value{GDBP})
15778-break-insert -r foo.*
15779~int foo(int, int);
15780^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15781(@value{GDBP})
15782@end smallexample
15783
15784@subheading The @code{-break-list} Command
15785@findex -break-list
15786
15787@subsubheading Synopsis
15788
15789@smallexample
15790 -break-list
15791@end smallexample
15792
15793Displays the list of inserted breakpoints, showing the following fields:
15794
15795@table @samp
15796@item Number
15797number of the breakpoint
15798@item Type
15799type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15800@item Disposition
15801should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15802or @samp{nokeep}
15803@item Enabled
15804is the breakpoint enabled or no: @samp{y} or @samp{n}
15805@item Address
15806memory location at which the breakpoint is set
15807@item What
15808logical location of the breakpoint, expressed by function name, file
15809name, line number
15810@item Times
15811number of times the breakpoint has been hit
15812@end table
15813
15814If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15815@code{body} field is an empty list.
15816
15817@subsubheading @value{GDBN} Command
15818
15819The corresponding @value{GDBN} command is @samp{info break}.
15820
15821@subsubheading Example
15822
15823@smallexample
15824(@value{GDBP})
15825-break-list
15826^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15827hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15828@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15829@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15830@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15831@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15832@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15833body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15834addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15835bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15836addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15837(@value{GDBP})
15838@end smallexample
15839
15840Here's an example of the result when there are no breakpoints:
15841
15842@smallexample
15843(@value{GDBP})
15844-break-list
15845^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15846hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15847@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15848@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15849@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15850@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15851@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15852body=[]@}
15853(@value{GDBP})
15854@end smallexample
15855
15856@subheading The @code{-break-watch} Command
15857@findex -break-watch
15858
15859@subsubheading Synopsis
15860
15861@smallexample
15862 -break-watch [ -a | -r ]
15863@end smallexample
15864
15865Create a watchpoint. With the @samp{-a} option it will create an
15866@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15867read from or on a write to the memory location. With the @samp{-r}
15868option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15869trigger only when the memory location is accessed for reading. Without
15870either of the options, the watchpoint created is a regular watchpoint,
15871i.e. it will trigger when the memory location is accessed for writing.
15872@xref{Set Watchpoints, , Setting watchpoints}.
15873
15874Note that @samp{-break-list} will report a single list of watchpoints and
15875breakpoints inserted.
15876
15877@subsubheading @value{GDBN} Command
15878
15879The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15880@samp{rwatch}.
15881
15882@subsubheading Example
15883
15884Setting a watchpoint on a variable in the @code{main} function:
15885
15886@smallexample
15887(@value{GDBP})
15888-break-watch x
15889^done,wpt=@{number="2",exp="x"@}
15890(@value{GDBP})
15891-exec-continue
15892^running
15893^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15894value=@{old="-268439212",new="55"@},
15895frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15896(@value{GDBP})
15897@end smallexample
15898
15899Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15900the program execution twice: first for the variable changing value, then
15901for the watchpoint going out of scope.
15902
15903@smallexample
15904(@value{GDBP})
15905-break-watch C
15906^done,wpt=@{number="5",exp="C"@}
15907(@value{GDBP})
15908-exec-continue
15909^running
15910^done,reason="watchpoint-trigger",
15911wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15912frame=@{func="callee4",args=[],
15913file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15914(@value{GDBP})
15915-exec-continue
15916^running
15917^done,reason="watchpoint-scope",wpnum="5",
15918frame=@{func="callee3",args=[@{name="strarg",
15919value="0x11940 \"A string argument.\""@}],
15920file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15921(@value{GDBP})
15922@end smallexample
15923
15924Listing breakpoints and watchpoints, at different points in the program
15925execution. Note that once the watchpoint goes out of scope, it is
15926deleted.
15927
15928@smallexample
15929(@value{GDBP})
15930-break-watch C
15931^done,wpt=@{number="2",exp="C"@}
15932(@value{GDBP})
15933-break-list
15934^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15935hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15936@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15937@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15938@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15939@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15940@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15941body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15942addr="0x00010734",func="callee4",
15943file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15944bkpt=@{number="2",type="watchpoint",disp="keep",
15945enabled="y",addr="",what="C",times="0"@}]@}
15946(@value{GDBP})
15947-exec-continue
15948^running
15949^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15950value=@{old="-276895068",new="3"@},
15951frame=@{func="callee4",args=[],
15952file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15953(@value{GDBP})
15954-break-list
15955^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15956hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15957@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15958@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15959@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15960@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15961@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15962body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15963addr="0x00010734",func="callee4",
15964file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15965bkpt=@{number="2",type="watchpoint",disp="keep",
15966enabled="y",addr="",what="C",times="-5"@}]@}
15967(@value{GDBP})
15968-exec-continue
15969^running
15970^done,reason="watchpoint-scope",wpnum="2",
15971frame=@{func="callee3",args=[@{name="strarg",
15972value="0x11940 \"A string argument.\""@}],
15973file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15974(@value{GDBP})
15975-break-list
15976^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15977hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15978@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15979@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15980@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15981@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15982@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15983body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15984addr="0x00010734",func="callee4",
15985file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15986(@value{GDBP})
15987@end smallexample
15988
15989@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15990@node GDB/MI Data Manipulation
15991@section @sc{gdb/mi} Data Manipulation
15992
15993@cindex data manipulation, in @sc{gdb/mi}
15994@cindex @sc{gdb/mi}, data manipulation
15995This section describes the @sc{gdb/mi} commands that manipulate data:
15996examine memory and registers, evaluate expressions, etc.
15997
15998@c REMOVED FROM THE INTERFACE.
15999@c @subheading -data-assign
16000@c Change the value of a program variable. Plenty of side effects.
16001@c @subsubheading GDB command
16002@c set variable
16003@c @subsubheading Example
16004@c N.A.
16005
16006@subheading The @code{-data-disassemble} Command
16007@findex -data-disassemble
16008
16009@subsubheading Synopsis
16010
16011@smallexample
16012 -data-disassemble
16013 [ -s @var{start-addr} -e @var{end-addr} ]
16014 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
16015 -- @var{mode}
16016@end smallexample
16017
16018@noindent
16019Where:
16020
16021@table @samp
16022@item @var{start-addr}
16023is the beginning address (or @code{$pc})
16024@item @var{end-addr}
16025is the end address
16026@item @var{filename}
16027is the name of the file to disassemble
16028@item @var{linenum}
16029is the line number to disassemble around
16030@item @var{lines}
16031is the the number of disassembly lines to be produced. If it is -1,
16032the whole function will be disassembled, in case no @var{end-addr} is
16033specified. If @var{end-addr} is specified as a non-zero value, and
16034@var{lines} is lower than the number of disassembly lines between
16035@var{start-addr} and @var{end-addr}, only @var{lines} lines are
16036displayed; if @var{lines} is higher than the number of lines between
16037@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
16038are displayed.
16039@item @var{mode}
16040is either 0 (meaning only disassembly) or 1 (meaning mixed source and
16041disassembly).
16042@end table
16043
16044@subsubheading Result
16045
16046The output for each instruction is composed of four fields:
16047
16048@itemize @bullet
16049@item Address
16050@item Func-name
16051@item Offset
16052@item Instruction
16053@end itemize
16054
16055Note that whatever included in the instruction field, is not manipulated
16056directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
16057
16058@subsubheading @value{GDBN} Command
16059
16060There's no direct mapping from this command to the CLI.
16061
16062@subsubheading Example
16063
16064Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
16065
16066@smallexample
16067(@value{GDBP})
16068-data-disassemble -s $pc -e "$pc + 20" -- 0
16069^done,
16070asm_insns=[
16071@{address="0x000107c0",func-name="main",offset="4",
16072inst="mov 2, %o0"@},
16073@{address="0x000107c4",func-name="main",offset="8",
16074inst="sethi %hi(0x11800), %o2"@},
16075@{address="0x000107c8",func-name="main",offset="12",
16076inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
16077@{address="0x000107cc",func-name="main",offset="16",
16078inst="sethi %hi(0x11800), %o2"@},
16079@{address="0x000107d0",func-name="main",offset="20",
16080inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
16081(@value{GDBP})
16082@end smallexample
16083
16084Disassemble the whole @code{main} function. Line 32 is part of
16085@code{main}.
16086
16087@smallexample
16088-data-disassemble -f basics.c -l 32 -- 0
16089^done,asm_insns=[
16090@{address="0x000107bc",func-name="main",offset="0",
16091inst="save %sp, -112, %sp"@},
16092@{address="0x000107c0",func-name="main",offset="4",
16093inst="mov 2, %o0"@},
16094@{address="0x000107c4",func-name="main",offset="8",
16095inst="sethi %hi(0x11800), %o2"@},
16096[@dots{}]
16097@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
16098@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
16099(@value{GDBP})
16100@end smallexample
16101
16102Disassemble 3 instructions from the start of @code{main}:
16103
16104@smallexample
16105(@value{GDBP})
16106-data-disassemble -f basics.c -l 32 -n 3 -- 0
16107^done,asm_insns=[
16108@{address="0x000107bc",func-name="main",offset="0",
16109inst="save %sp, -112, %sp"@},
16110@{address="0x000107c0",func-name="main",offset="4",
16111inst="mov 2, %o0"@},
16112@{address="0x000107c4",func-name="main",offset="8",
16113inst="sethi %hi(0x11800), %o2"@}]
16114(@value{GDBP})
16115@end smallexample
16116
16117Disassemble 3 instructions from the start of @code{main} in mixed mode:
16118
16119@smallexample
16120(@value{GDBP})
16121-data-disassemble -f basics.c -l 32 -n 3 -- 1
16122^done,asm_insns=[
16123src_and_asm_line=@{line="31",
16124file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16125 testsuite/gdb.mi/basics.c",line_asm_insn=[
16126@{address="0x000107bc",func-name="main",offset="0",
16127inst="save %sp, -112, %sp"@}]@},
16128src_and_asm_line=@{line="32",
16129file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16130 testsuite/gdb.mi/basics.c",line_asm_insn=[
16131@{address="0x000107c0",func-name="main",offset="4",
16132inst="mov 2, %o0"@},
16133@{address="0x000107c4",func-name="main",offset="8",
16134inst="sethi %hi(0x11800), %o2"@}]@}]
16135(@value{GDBP})
16136@end smallexample
16137
16138
16139@subheading The @code{-data-evaluate-expression} Command
16140@findex -data-evaluate-expression
16141
16142@subsubheading Synopsis
16143
16144@smallexample
16145 -data-evaluate-expression @var{expr}
16146@end smallexample
16147
16148Evaluate @var{expr} as an expression. The expression could contain an
16149inferior function call. The function call will execute synchronously.
16150If the expression contains spaces, it must be enclosed in double quotes.
16151
16152@subsubheading @value{GDBN} Command
16153
16154The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
16155@samp{call}. In @code{gdbtk} only, there's a corresponding
16156@samp{gdb_eval} command.
16157
16158@subsubheading Example
16159
16160In the following example, the numbers that precede the commands are the
16161@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
16162Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
16163output.
16164
16165@smallexample
16166211-data-evaluate-expression A
16167211^done,value="1"
16168(@value{GDBP})
16169311-data-evaluate-expression &A
16170311^done,value="0xefffeb7c"
16171(@value{GDBP})
16172411-data-evaluate-expression A+3
16173411^done,value="4"
16174(@value{GDBP})
16175511-data-evaluate-expression "A + 3"
16176511^done,value="4"
16177(@value{GDBP})
16178@end smallexample
16179
16180
16181@subheading The @code{-data-list-changed-registers} Command
16182@findex -data-list-changed-registers
16183
16184@subsubheading Synopsis
16185
16186@smallexample
16187 -data-list-changed-registers
16188@end smallexample
16189
16190Display a list of the registers that have changed.
16191
16192@subsubheading @value{GDBN} Command
16193
16194@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
16195has the corresponding command @samp{gdb_changed_register_list}.
16196
16197@subsubheading Example
16198
16199On a PPC MBX board:
16200
16201@smallexample
16202(@value{GDBP})
16203-exec-continue
16204^running
16205
16206(@value{GDBP})
16207*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
16208args=[],file="try.c",line="5"@}
16209(@value{GDBP})
16210-data-list-changed-registers
16211^done,changed-registers=["0","1","2","4","5","6","7","8","9",
16212"10","11","13","14","15","16","17","18","19","20","21","22","23",
16213"24","25","26","27","28","30","31","64","65","66","67","69"]
16214(@value{GDBP})
16215@end smallexample
16216
16217
16218@subheading The @code{-data-list-register-names} Command
16219@findex -data-list-register-names
16220
16221@subsubheading Synopsis
16222
16223@smallexample
16224 -data-list-register-names [ ( @var{regno} )+ ]
16225@end smallexample
16226
16227Show a list of register names for the current target. If no arguments
16228are given, it shows a list of the names of all the registers. If
16229integer numbers are given as arguments, it will print a list of the
16230names of the registers corresponding to the arguments. To ensure
16231consistency between a register name and its number, the output list may
16232include empty register names.
16233
16234@subsubheading @value{GDBN} Command
16235
16236@value{GDBN} does not have a command which corresponds to
16237@samp{-data-list-register-names}. In @code{gdbtk} there is a
16238corresponding command @samp{gdb_regnames}.
16239
16240@subsubheading Example
16241
16242For the PPC MBX board:
16243@smallexample
16244(@value{GDBP})
16245-data-list-register-names
16246^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
16247"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
16248"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
16249"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
16250"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
16251"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
16252"", "pc","ps","cr","lr","ctr","xer"]
16253(@value{GDBP})
16254-data-list-register-names 1 2 3
16255^done,register-names=["r1","r2","r3"]
16256(@value{GDBP})
16257@end smallexample
16258
16259@subheading The @code{-data-list-register-values} Command
16260@findex -data-list-register-values
16261
16262@subsubheading Synopsis
16263
16264@smallexample
16265 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
16266@end smallexample
16267
16268Display the registers' contents. @var{fmt} is the format according to
16269which the registers' contents are to be returned, followed by an optional
16270list of numbers specifying the registers to display. A missing list of
16271numbers indicates that the contents of all the registers must be returned.
16272
16273Allowed formats for @var{fmt} are:
16274
16275@table @code
16276@item x
16277Hexadecimal
16278@item o
16279Octal
16280@item t
16281Binary
16282@item d
16283Decimal
16284@item r
16285Raw
16286@item N
16287Natural
16288@end table
16289
16290@subsubheading @value{GDBN} Command
16291
16292The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
16293all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
16294
16295@subsubheading Example
16296
16297For a PPC MBX board (note: line breaks are for readability only, they
16298don't appear in the actual output):
16299
16300@smallexample
16301(@value{GDBP})
16302-data-list-register-values r 64 65
16303^done,register-values=[@{number="64",value="0xfe00a300"@},
16304@{number="65",value="0x00029002"@}]
16305(@value{GDBP})
16306-data-list-register-values x
16307^done,register-values=[@{number="0",value="0xfe0043c8"@},
16308@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
16309@{number="3",value="0x0"@},@{number="4",value="0xa"@},
16310@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
16311@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
16312@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
16313@{number="11",value="0x1"@},@{number="12",value="0x0"@},
16314@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
16315@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
16316@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
16317@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
16318@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
16319@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
16320@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
16321@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
16322@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
16323@{number="31",value="0x0"@},@{number="32",value="0x0"@},
16324@{number="33",value="0x0"@},@{number="34",value="0x0"@},
16325@{number="35",value="0x0"@},@{number="36",value="0x0"@},
16326@{number="37",value="0x0"@},@{number="38",value="0x0"@},
16327@{number="39",value="0x0"@},@{number="40",value="0x0"@},
16328@{number="41",value="0x0"@},@{number="42",value="0x0"@},
16329@{number="43",value="0x0"@},@{number="44",value="0x0"@},
16330@{number="45",value="0x0"@},@{number="46",value="0x0"@},
16331@{number="47",value="0x0"@},@{number="48",value="0x0"@},
16332@{number="49",value="0x0"@},@{number="50",value="0x0"@},
16333@{number="51",value="0x0"@},@{number="52",value="0x0"@},
16334@{number="53",value="0x0"@},@{number="54",value="0x0"@},
16335@{number="55",value="0x0"@},@{number="56",value="0x0"@},
16336@{number="57",value="0x0"@},@{number="58",value="0x0"@},
16337@{number="59",value="0x0"@},@{number="60",value="0x0"@},
16338@{number="61",value="0x0"@},@{number="62",value="0x0"@},
16339@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
16340@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
16341@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
16342@{number="69",value="0x20002b03"@}]
16343(@value{GDBP})
16344@end smallexample
16345
16346
16347@subheading The @code{-data-read-memory} Command
16348@findex -data-read-memory
16349
16350@subsubheading Synopsis
16351
16352@smallexample
16353 -data-read-memory [ -o @var{byte-offset} ]
16354 @var{address} @var{word-format} @var{word-size}
16355 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
16356@end smallexample
16357
16358@noindent
16359where:
16360
16361@table @samp
16362@item @var{address}
16363An expression specifying the address of the first memory word to be
16364read. Complex expressions containing embedded white space should be
16365quoted using the C convention.
16366
16367@item @var{word-format}
16368The format to be used to print the memory words. The notation is the
16369same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
16370,Output formats}).
16371
16372@item @var{word-size}
16373The size of each memory word in bytes.
16374
16375@item @var{nr-rows}
16376The number of rows in the output table.
16377
16378@item @var{nr-cols}
16379The number of columns in the output table.
16380
16381@item @var{aschar}
16382If present, indicates that each row should include an @sc{ascii} dump. The
16383value of @var{aschar} is used as a padding character when a byte is not a
16384member of the printable @sc{ascii} character set (printable @sc{ascii}
16385characters are those whose code is between 32 and 126, inclusively).
16386
16387@item @var{byte-offset}
16388An offset to add to the @var{address} before fetching memory.
16389@end table
16390
16391This command displays memory contents as a table of @var{nr-rows} by
16392@var{nr-cols} words, each word being @var{word-size} bytes. In total,
16393@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
16394(returned as @samp{total-bytes}). Should less than the requested number
16395of bytes be returned by the target, the missing words are identified
16396using @samp{N/A}. The number of bytes read from the target is returned
16397in @samp{nr-bytes} and the starting address used to read memory in
16398@samp{addr}.
16399
16400The address of the next/previous row or page is available in
16401@samp{next-row} and @samp{prev-row}, @samp{next-page} and
16402@samp{prev-page}.
16403
16404@subsubheading @value{GDBN} Command
16405
16406The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
16407@samp{gdb_get_mem} memory read command.
16408
16409@subsubheading Example
16410
16411Read six bytes of memory starting at @code{bytes+6} but then offset by
16412@code{-6} bytes. Format as three rows of two columns. One byte per
16413word. Display each word in hex.
16414
16415@smallexample
16416(@value{GDBP})
164179-data-read-memory -o -6 -- bytes+6 x 1 3 2
164189^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
16419next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
16420prev-page="0x0000138a",memory=[
16421@{addr="0x00001390",data=["0x00","0x01"]@},
16422@{addr="0x00001392",data=["0x02","0x03"]@},
16423@{addr="0x00001394",data=["0x04","0x05"]@}]
16424(@value{GDBP})
16425@end smallexample
16426
16427Read two bytes of memory starting at address @code{shorts + 64} and
16428display as a single word formatted in decimal.
16429
16430@smallexample
16431(@value{GDBP})
164325-data-read-memory shorts+64 d 2 1 1
164335^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
16434next-row="0x00001512",prev-row="0x0000150e",
16435next-page="0x00001512",prev-page="0x0000150e",memory=[
16436@{addr="0x00001510",data=["128"]@}]
16437(@value{GDBP})
16438@end smallexample
16439
16440Read thirty two bytes of memory starting at @code{bytes+16} and format
16441as eight rows of four columns. Include a string encoding with @samp{x}
16442used as the non-printable character.
16443
16444@smallexample
16445(@value{GDBP})
164464-data-read-memory bytes+16 x 1 8 4 x
164474^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
16448next-row="0x000013c0",prev-row="0x0000139c",
16449next-page="0x000013c0",prev-page="0x00001380",memory=[
16450@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
16451@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
16452@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
16453@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
16454@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
16455@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
16456@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
16457@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
16458(@value{GDBP})
16459@end smallexample
16460
16461@subheading The @code{-display-delete} Command
16462@findex -display-delete
16463
16464@subsubheading Synopsis
16465
16466@smallexample
16467 -display-delete @var{number}
16468@end smallexample
16469
16470Delete the display @var{number}.
16471
16472@subsubheading @value{GDBN} Command
16473
16474The corresponding @value{GDBN} command is @samp{delete display}.
16475
16476@subsubheading Example
16477N.A.
16478
16479
16480@subheading The @code{-display-disable} Command
16481@findex -display-disable
16482
16483@subsubheading Synopsis
16484
16485@smallexample
16486 -display-disable @var{number}
16487@end smallexample
16488
16489Disable display @var{number}.
16490
16491@subsubheading @value{GDBN} Command
16492
16493The corresponding @value{GDBN} command is @samp{disable display}.
16494
16495@subsubheading Example
16496N.A.
16497
16498
16499@subheading The @code{-display-enable} Command
16500@findex -display-enable
16501
16502@subsubheading Synopsis
16503
16504@smallexample
16505 -display-enable @var{number}
16506@end smallexample
16507
16508Enable display @var{number}.
16509
16510@subsubheading @value{GDBN} Command
16511
16512The corresponding @value{GDBN} command is @samp{enable display}.
16513
16514@subsubheading Example
16515N.A.
16516
16517
16518@subheading The @code{-display-insert} Command
16519@findex -display-insert
16520
16521@subsubheading Synopsis
16522
16523@smallexample
16524 -display-insert @var{expression}
16525@end smallexample
16526
16527Display @var{expression} every time the program stops.
16528
16529@subsubheading @value{GDBN} Command
16530
16531The corresponding @value{GDBN} command is @samp{display}.
16532
16533@subsubheading Example
16534N.A.
16535
16536
16537@subheading The @code{-display-list} Command
16538@findex -display-list
16539
16540@subsubheading Synopsis
16541
16542@smallexample
16543 -display-list
16544@end smallexample
16545
16546List the displays. Do not show the current values.
16547
16548@subsubheading @value{GDBN} Command
16549
16550The corresponding @value{GDBN} command is @samp{info display}.
16551
16552@subsubheading Example
16553N.A.
16554
16555
16556@subheading The @code{-environment-cd} Command
16557@findex -environment-cd
16558
16559@subsubheading Synopsis
16560
16561@smallexample
16562 -environment-cd @var{pathdir}
16563@end smallexample
16564
16565Set @value{GDBN}'s working directory.
16566
16567@subsubheading @value{GDBN} Command
16568
16569The corresponding @value{GDBN} command is @samp{cd}.
16570
16571@subsubheading Example
16572
16573@smallexample
16574(@value{GDBP})
16575-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16576^done
16577(@value{GDBP})
16578@end smallexample
16579
16580
16581@subheading The @code{-environment-directory} Command
16582@findex -environment-directory
16583
16584@subsubheading Synopsis
16585
16586@smallexample
16587 -environment-directory [ -r ] [ @var{pathdir} ]+
16588@end smallexample
16589
16590Add directories @var{pathdir} to beginning of search path for source files.
16591If the @samp{-r} option is used, the search path is reset to the default
b383017d 16592search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
16593@samp{-r} option, the search path is first reset and then addition
16594occurs as normal.
b383017d 16595Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16596multiple directories in a single command
16597results in the directories added to the beginning of the
16598search path in the same order they were presented in the command.
16599If blanks are needed as
16600part of a directory name, double-quotes should be used around
16601the name. In the command output, the path will show up separated
b383017d 16602by the system directory-separator character. The directory-seperator
922fbb7b
AC
16603character must not be used
16604in any directory name.
16605If no directories are specified, the current search path is displayed.
16606
16607@subsubheading @value{GDBN} Command
16608
16609The corresponding @value{GDBN} command is @samp{dir}.
16610
16611@subsubheading Example
16612
16613@smallexample
16614(@value{GDBP})
16615-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16616^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16617(@value{GDBP})
16618-environment-directory ""
16619^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16620(@value{GDBP})
16621-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16622^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16623(@value{GDBP})
16624-environment-directory -r
16625^done,source-path="$cdir:$cwd"
16626(@value{GDBP})
16627@end smallexample
16628
16629
16630@subheading The @code{-environment-path} Command
16631@findex -environment-path
16632
16633@subsubheading Synopsis
16634
16635@smallexample
16636 -environment-path [ -r ] [ @var{pathdir} ]+
16637@end smallexample
16638
16639Add directories @var{pathdir} to beginning of search path for object files.
16640If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
16641search path that existed at gdb start-up. If directories @var{pathdir} are
16642supplied in addition to the
922fbb7b
AC
16643@samp{-r} option, the search path is first reset and then addition
16644occurs as normal.
b383017d 16645Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16646multiple directories in a single command
16647results in the directories added to the beginning of the
16648search path in the same order they were presented in the command.
16649If blanks are needed as
16650part of a directory name, double-quotes should be used around
16651the name. In the command output, the path will show up separated
b383017d 16652by the system directory-separator character. The directory-seperator
922fbb7b
AC
16653character must not be used
16654in any directory name.
16655If no directories are specified, the current path is displayed.
16656
16657
16658@subsubheading @value{GDBN} Command
16659
16660The corresponding @value{GDBN} command is @samp{path}.
16661
16662@subsubheading Example
16663
16664@smallexample
16665(@value{GDBP})
b383017d 16666-environment-path
922fbb7b
AC
16667^done,path="/usr/bin"
16668(@value{GDBP})
16669-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16670^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16671(@value{GDBP})
16672-environment-path -r /usr/local/bin
16673^done,path="/usr/local/bin:/usr/bin"
16674(@value{GDBP})
16675@end smallexample
16676
16677
16678@subheading The @code{-environment-pwd} Command
16679@findex -environment-pwd
16680
16681@subsubheading Synopsis
16682
16683@smallexample
16684 -environment-pwd
16685@end smallexample
16686
16687Show the current working directory.
16688
16689@subsubheading @value{GDBN} command
16690
16691The corresponding @value{GDBN} command is @samp{pwd}.
16692
16693@subsubheading Example
16694
16695@smallexample
16696(@value{GDBP})
16697-environment-pwd
16698^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16699(@value{GDBP})
16700@end smallexample
16701
16702@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16703@node GDB/MI Program Control
16704@section @sc{gdb/mi} Program control
16705
16706@subsubheading Program termination
16707
16708As a result of execution, the inferior program can run to completion, if
16709it doesn't encounter any breakpoints. In this case the output will
16710include an exit code, if the program has exited exceptionally.
16711
16712@subsubheading Examples
16713
16714@noindent
16715Program exited normally:
16716
16717@smallexample
16718(@value{GDBP})
16719-exec-run
16720^running
16721(@value{GDBP})
16722x = 55
16723*stopped,reason="exited-normally"
16724(@value{GDBP})
16725@end smallexample
16726
16727@noindent
16728Program exited exceptionally:
16729
16730@smallexample
16731(@value{GDBP})
16732-exec-run
16733^running
16734(@value{GDBP})
16735x = 55
16736*stopped,reason="exited",exit-code="01"
16737(@value{GDBP})
16738@end smallexample
16739
16740Another way the program can terminate is if it receives a signal such as
16741@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16742
16743@smallexample
16744(@value{GDBP})
16745*stopped,reason="exited-signalled",signal-name="SIGINT",
16746signal-meaning="Interrupt"
16747@end smallexample
16748
16749
16750@subheading The @code{-exec-abort} Command
16751@findex -exec-abort
16752
16753@subsubheading Synopsis
16754
16755@smallexample
16756 -exec-abort
16757@end smallexample
16758
16759Kill the inferior running program.
16760
16761@subsubheading @value{GDBN} Command
16762
16763The corresponding @value{GDBN} command is @samp{kill}.
16764
16765@subsubheading Example
16766N.A.
16767
16768
16769@subheading The @code{-exec-arguments} Command
16770@findex -exec-arguments
16771
16772@subsubheading Synopsis
16773
16774@smallexample
16775 -exec-arguments @var{args}
16776@end smallexample
16777
16778Set the inferior program arguments, to be used in the next
16779@samp{-exec-run}.
16780
16781@subsubheading @value{GDBN} Command
16782
16783The corresponding @value{GDBN} command is @samp{set args}.
16784
16785@subsubheading Example
16786
16787@c FIXME!
16788Don't have one around.
16789
16790
16791@subheading The @code{-exec-continue} Command
16792@findex -exec-continue
16793
16794@subsubheading Synopsis
16795
16796@smallexample
16797 -exec-continue
16798@end smallexample
16799
16800Asynchronous command. Resumes the execution of the inferior program
16801until a breakpoint is encountered, or until the inferior exits.
16802
16803@subsubheading @value{GDBN} Command
16804
16805The corresponding @value{GDBN} corresponding is @samp{continue}.
16806
16807@subsubheading Example
16808
16809@smallexample
16810-exec-continue
16811^running
16812(@value{GDBP})
16813@@Hello world
16814*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16815file="hello.c",line="13"@}
16816(@value{GDBP})
16817@end smallexample
16818
16819
16820@subheading The @code{-exec-finish} Command
16821@findex -exec-finish
16822
16823@subsubheading Synopsis
16824
16825@smallexample
16826 -exec-finish
16827@end smallexample
16828
16829Asynchronous command. Resumes the execution of the inferior program
16830until the current function is exited. Displays the results returned by
16831the function.
16832
16833@subsubheading @value{GDBN} Command
16834
16835The corresponding @value{GDBN} command is @samp{finish}.
16836
16837@subsubheading Example
16838
16839Function returning @code{void}.
16840
16841@smallexample
16842-exec-finish
16843^running
16844(@value{GDBP})
16845@@hello from foo
16846*stopped,reason="function-finished",frame=@{func="main",args=[],
16847file="hello.c",line="7"@}
16848(@value{GDBP})
16849@end smallexample
16850
16851Function returning other than @code{void}. The name of the internal
16852@value{GDBN} variable storing the result is printed, together with the
16853value itself.
16854
16855@smallexample
16856-exec-finish
16857^running
16858(@value{GDBP})
16859*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16860args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16861file="recursive2.c",line="14"@},
16862gdb-result-var="$1",return-value="0"
16863(@value{GDBP})
16864@end smallexample
16865
16866
16867@subheading The @code{-exec-interrupt} Command
16868@findex -exec-interrupt
16869
16870@subsubheading Synopsis
16871
16872@smallexample
16873 -exec-interrupt
16874@end smallexample
16875
16876Asynchronous command. Interrupts the background execution of the target.
16877Note how the token associated with the stop message is the one for the
16878execution command that has been interrupted. The token for the interrupt
16879itself only appears in the @samp{^done} output. If the user is trying to
16880interrupt a non-running program, an error message will be printed.
16881
16882@subsubheading @value{GDBN} Command
16883
16884The corresponding @value{GDBN} command is @samp{interrupt}.
16885
16886@subsubheading Example
16887
16888@smallexample
16889(@value{GDBP})
16890111-exec-continue
16891111^running
16892
16893(@value{GDBP})
16894222-exec-interrupt
16895222^done
16896(@value{GDBP})
16897111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16898frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16899(@value{GDBP})
16900
16901(@value{GDBP})
16902-exec-interrupt
16903^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16904(@value{GDBP})
16905@end smallexample
16906
16907
16908@subheading The @code{-exec-next} Command
16909@findex -exec-next
16910
16911@subsubheading Synopsis
16912
16913@smallexample
16914 -exec-next
16915@end smallexample
16916
16917Asynchronous command. Resumes execution of the inferior program, stopping
16918when the beginning of the next source line is reached.
16919
16920@subsubheading @value{GDBN} Command
16921
16922The corresponding @value{GDBN} command is @samp{next}.
16923
16924@subsubheading Example
16925
16926@smallexample
16927-exec-next
16928^running
16929(@value{GDBP})
16930*stopped,reason="end-stepping-range",line="8",file="hello.c"
16931(@value{GDBP})
16932@end smallexample
16933
16934
16935@subheading The @code{-exec-next-instruction} Command
16936@findex -exec-next-instruction
16937
16938@subsubheading Synopsis
16939
16940@smallexample
16941 -exec-next-instruction
16942@end smallexample
16943
16944Asynchronous command. Executes one machine instruction. If the
16945instruction is a function call continues until the function returns. If
16946the program stops at an instruction in the middle of a source line, the
16947address will be printed as well.
16948
16949@subsubheading @value{GDBN} Command
16950
16951The corresponding @value{GDBN} command is @samp{nexti}.
16952
16953@subsubheading Example
16954
16955@smallexample
16956(@value{GDBP})
16957-exec-next-instruction
16958^running
16959
16960(@value{GDBP})
16961*stopped,reason="end-stepping-range",
16962addr="0x000100d4",line="5",file="hello.c"
16963(@value{GDBP})
16964@end smallexample
16965
16966
16967@subheading The @code{-exec-return} Command
16968@findex -exec-return
16969
16970@subsubheading Synopsis
16971
16972@smallexample
16973 -exec-return
16974@end smallexample
16975
16976Makes current function return immediately. Doesn't execute the inferior.
16977Displays the new current frame.
16978
16979@subsubheading @value{GDBN} Command
16980
16981The corresponding @value{GDBN} command is @samp{return}.
16982
16983@subsubheading Example
16984
16985@smallexample
16986(@value{GDBP})
16987200-break-insert callee4
16988200^done,bkpt=@{number="1",addr="0x00010734",
16989file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16990(@value{GDBP})
16991000-exec-run
16992000^running
16993(@value{GDBP})
16994000*stopped,reason="breakpoint-hit",bkptno="1",
16995frame=@{func="callee4",args=[],
16996file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16997(@value{GDBP})
16998205-break-delete
16999205^done
17000(@value{GDBP})
17001111-exec-return
17002111^done,frame=@{level="0",func="callee3",
17003args=[@{name="strarg",
17004value="0x11940 \"A string argument.\""@}],
17005file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17006(@value{GDBP})
17007@end smallexample
17008
17009
17010@subheading The @code{-exec-run} Command
17011@findex -exec-run
17012
17013@subsubheading Synopsis
17014
17015@smallexample
17016 -exec-run
17017@end smallexample
17018
17019Asynchronous command. Starts execution of the inferior from the
17020beginning. The inferior executes until either a breakpoint is
17021encountered or the program exits.
17022
17023@subsubheading @value{GDBN} Command
17024
17025The corresponding @value{GDBN} command is @samp{run}.
17026
17027@subsubheading Example
17028
17029@smallexample
17030(@value{GDBP})
17031-break-insert main
17032^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17033(@value{GDBP})
17034-exec-run
17035^running
17036(@value{GDBP})
17037*stopped,reason="breakpoint-hit",bkptno="1",
17038frame=@{func="main",args=[],file="recursive2.c",line="4"@}
17039(@value{GDBP})
17040@end smallexample
17041
17042
17043@subheading The @code{-exec-show-arguments} Command
17044@findex -exec-show-arguments
17045
17046@subsubheading Synopsis
17047
17048@smallexample
17049 -exec-show-arguments
17050@end smallexample
17051
17052Print the arguments of the program.
17053
17054@subsubheading @value{GDBN} Command
17055
17056The corresponding @value{GDBN} command is @samp{show args}.
17057
17058@subsubheading Example
17059N.A.
17060
17061@c @subheading -exec-signal
17062
17063@subheading The @code{-exec-step} Command
17064@findex -exec-step
17065
17066@subsubheading Synopsis
17067
17068@smallexample
17069 -exec-step
17070@end smallexample
17071
17072Asynchronous command. Resumes execution of the inferior program, stopping
17073when the beginning of the next source line is reached, if the next
17074source line is not a function call. If it is, stop at the first
17075instruction of the called function.
17076
17077@subsubheading @value{GDBN} Command
17078
17079The corresponding @value{GDBN} command is @samp{step}.
17080
17081@subsubheading Example
17082
17083Stepping into a function:
17084
17085@smallexample
17086-exec-step
17087^running
17088(@value{GDBP})
17089*stopped,reason="end-stepping-range",
17090frame=@{func="foo",args=[@{name="a",value="10"@},
17091@{name="b",value="0"@}],file="recursive2.c",line="11"@}
17092(@value{GDBP})
17093@end smallexample
17094
17095Regular stepping:
17096
17097@smallexample
17098-exec-step
17099^running
17100(@value{GDBP})
17101*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
17102(@value{GDBP})
17103@end smallexample
17104
17105
17106@subheading The @code{-exec-step-instruction} Command
17107@findex -exec-step-instruction
17108
17109@subsubheading Synopsis
17110
17111@smallexample
17112 -exec-step-instruction
17113@end smallexample
17114
17115Asynchronous command. Resumes the inferior which executes one machine
17116instruction. The output, once @value{GDBN} has stopped, will vary depending on
17117whether we have stopped in the middle of a source line or not. In the
17118former case, the address at which the program stopped will be printed as
17119well.
17120
17121@subsubheading @value{GDBN} Command
17122
17123The corresponding @value{GDBN} command is @samp{stepi}.
17124
17125@subsubheading Example
17126
17127@smallexample
17128(@value{GDBP})
17129-exec-step-instruction
17130^running
17131
17132(@value{GDBP})
17133*stopped,reason="end-stepping-range",
17134frame=@{func="foo",args=[],file="try.c",line="10"@}
17135(@value{GDBP})
17136-exec-step-instruction
17137^running
17138
17139(@value{GDBP})
17140*stopped,reason="end-stepping-range",
17141frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
17142(@value{GDBP})
17143@end smallexample
17144
17145
17146@subheading The @code{-exec-until} Command
17147@findex -exec-until
17148
17149@subsubheading Synopsis
17150
17151@smallexample
17152 -exec-until [ @var{location} ]
17153@end smallexample
17154
17155Asynchronous command. Executes the inferior until the @var{location}
17156specified in the argument is reached. If there is no argument, the inferior
17157executes until a source line greater than the current one is reached.
17158The reason for stopping in this case will be @samp{location-reached}.
17159
17160@subsubheading @value{GDBN} Command
17161
17162The corresponding @value{GDBN} command is @samp{until}.
17163
17164@subsubheading Example
17165
17166@smallexample
17167(@value{GDBP})
17168-exec-until recursive2.c:6
17169^running
17170(@value{GDBP})
17171x = 55
17172*stopped,reason="location-reached",frame=@{func="main",args=[],
17173file="recursive2.c",line="6"@}
17174(@value{GDBP})
17175@end smallexample
17176
17177@ignore
17178@subheading -file-clear
17179Is this going away????
17180@end ignore
17181
17182
17183@subheading The @code{-file-exec-and-symbols} Command
17184@findex -file-exec-and-symbols
17185
17186@subsubheading Synopsis
17187
17188@smallexample
17189 -file-exec-and-symbols @var{file}
17190@end smallexample
17191
17192Specify the executable file to be debugged. This file is the one from
17193which the symbol table is also read. If no file is specified, the
17194command clears the executable and symbol information. If breakpoints
17195are set when using this command with no arguments, @value{GDBN} will produce
17196error messages. Otherwise, no output is produced, except a completion
17197notification.
17198
17199@subsubheading @value{GDBN} Command
17200
17201The corresponding @value{GDBN} command is @samp{file}.
17202
17203@subsubheading Example
17204
17205@smallexample
17206(@value{GDBP})
17207-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17208^done
17209(@value{GDBP})
17210@end smallexample
17211
17212
17213@subheading The @code{-file-exec-file} Command
17214@findex -file-exec-file
17215
17216@subsubheading Synopsis
17217
17218@smallexample
17219 -file-exec-file @var{file}
17220@end smallexample
17221
17222Specify the executable file to be debugged. Unlike
17223@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
17224from this file. If used without argument, @value{GDBN} clears the information
17225about the executable file. No output is produced, except a completion
17226notification.
17227
17228@subsubheading @value{GDBN} Command
17229
17230The corresponding @value{GDBN} command is @samp{exec-file}.
17231
17232@subsubheading Example
17233
17234@smallexample
17235(@value{GDBP})
17236-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17237^done
17238(@value{GDBP})
17239@end smallexample
17240
17241
17242@subheading The @code{-file-list-exec-sections} Command
17243@findex -file-list-exec-sections
17244
17245@subsubheading Synopsis
17246
17247@smallexample
17248 -file-list-exec-sections
17249@end smallexample
17250
17251List the sections of the current executable file.
17252
17253@subsubheading @value{GDBN} Command
17254
17255The @value{GDBN} command @samp{info file} shows, among the rest, the same
17256information as this command. @code{gdbtk} has a corresponding command
17257@samp{gdb_load_info}.
17258
17259@subsubheading Example
17260N.A.
17261
17262
1abaf70c
BR
17263@subheading The @code{-file-list-exec-source-file} Command
17264@findex -file-list-exec-source-file
17265
17266@subsubheading Synopsis
17267
17268@smallexample
17269 -file-list-exec-source-file
17270@end smallexample
17271
b383017d 17272List the line number, the current source file, and the absolute path
1abaf70c
BR
17273to the current source file for the current executable.
17274
17275@subsubheading @value{GDBN} Command
17276
17277There's no @value{GDBN} command which directly corresponds to this one.
17278
17279@subsubheading Example
17280
17281@smallexample
17282(@value{GDBP})
17283123-file-list-exec-source-file
17284123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
17285(@value{GDBP})
17286@end smallexample
17287
17288
922fbb7b
AC
17289@subheading The @code{-file-list-exec-source-files} Command
17290@findex -file-list-exec-source-files
17291
17292@subsubheading Synopsis
17293
17294@smallexample
17295 -file-list-exec-source-files
17296@end smallexample
17297
17298List the source files for the current executable.
17299
57c22c6c
BR
17300It will always output the filename, but only when GDB can find the absolute
17301file name of a source file, will it output the fullname.
17302
922fbb7b
AC
17303@subsubheading @value{GDBN} Command
17304
17305There's no @value{GDBN} command which directly corresponds to this one.
17306@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
17307
17308@subsubheading Example
57c22c6c
BR
17309@smallexample
17310(@value{GDBP})
17311-file-list-exec-source-files
17312^done,files=[
17313@{file=foo.c,fullname=/home/foo.c@},
17314@{file=/home/bar.c,fullname=/home/bar.c@},
17315@{file=gdb_could_not_find_fullpath.c@}]
17316(@value{GDBP})
17317@end smallexample
922fbb7b
AC
17318
17319@subheading The @code{-file-list-shared-libraries} Command
17320@findex -file-list-shared-libraries
17321
17322@subsubheading Synopsis
17323
17324@smallexample
17325 -file-list-shared-libraries
17326@end smallexample
17327
17328List the shared libraries in the program.
17329
17330@subsubheading @value{GDBN} Command
17331
17332The corresponding @value{GDBN} command is @samp{info shared}.
17333
17334@subsubheading Example
17335N.A.
17336
17337
17338@subheading The @code{-file-list-symbol-files} Command
17339@findex -file-list-symbol-files
17340
17341@subsubheading Synopsis
17342
17343@smallexample
17344 -file-list-symbol-files
17345@end smallexample
17346
17347List symbol files.
17348
17349@subsubheading @value{GDBN} Command
17350
17351The corresponding @value{GDBN} command is @samp{info file} (part of it).
17352
17353@subsubheading Example
17354N.A.
17355
17356
17357@subheading The @code{-file-symbol-file} Command
17358@findex -file-symbol-file
17359
17360@subsubheading Synopsis
17361
17362@smallexample
17363 -file-symbol-file @var{file}
17364@end smallexample
17365
17366Read symbol table info from the specified @var{file} argument. When
17367used without arguments, clears @value{GDBN}'s symbol table info. No output is
17368produced, except for a completion notification.
17369
17370@subsubheading @value{GDBN} Command
17371
17372The corresponding @value{GDBN} command is @samp{symbol-file}.
17373
17374@subsubheading Example
17375
17376@smallexample
17377(@value{GDBP})
17378-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17379^done
17380(@value{GDBP})
17381@end smallexample
17382
17383@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17384@node GDB/MI Miscellaneous Commands
17385@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
17386
17387@c @subheading -gdb-complete
17388
17389@subheading The @code{-gdb-exit} Command
17390@findex -gdb-exit
17391
17392@subsubheading Synopsis
17393
17394@smallexample
17395 -gdb-exit
17396@end smallexample
17397
17398Exit @value{GDBN} immediately.
17399
17400@subsubheading @value{GDBN} Command
17401
17402Approximately corresponds to @samp{quit}.
17403
17404@subsubheading Example
17405
17406@smallexample
17407(@value{GDBP})
17408-gdb-exit
17409@end smallexample
17410
17411@subheading The @code{-gdb-set} Command
17412@findex -gdb-set
17413
17414@subsubheading Synopsis
17415
17416@smallexample
17417 -gdb-set
17418@end smallexample
17419
17420Set an internal @value{GDBN} variable.
17421@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
17422
17423@subsubheading @value{GDBN} Command
17424
17425The corresponding @value{GDBN} command is @samp{set}.
17426
17427@subsubheading Example
17428
17429@smallexample
17430(@value{GDBP})
17431-gdb-set $foo=3
17432^done
17433(@value{GDBP})
17434@end smallexample
17435
17436
17437@subheading The @code{-gdb-show} Command
17438@findex -gdb-show
17439
17440@subsubheading Synopsis
17441
17442@smallexample
17443 -gdb-show
17444@end smallexample
17445
17446Show the current value of a @value{GDBN} variable.
17447
17448@subsubheading @value{GDBN} command
17449
17450The corresponding @value{GDBN} command is @samp{show}.
17451
17452@subsubheading Example
17453
17454@smallexample
17455(@value{GDBP})
17456-gdb-show annotate
17457^done,value="0"
17458(@value{GDBP})
17459@end smallexample
17460
17461@c @subheading -gdb-source
17462
17463
17464@subheading The @code{-gdb-version} Command
17465@findex -gdb-version
17466
17467@subsubheading Synopsis
17468
17469@smallexample
17470 -gdb-version
17471@end smallexample
17472
17473Show version information for @value{GDBN}. Used mostly in testing.
17474
17475@subsubheading @value{GDBN} Command
17476
17477There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
17478information when you start an interactive session.
17479
17480@subsubheading Example
17481
17482@c This example modifies the actual output from GDB to avoid overfull
17483@c box in TeX.
17484@smallexample
17485(@value{GDBP})
17486-gdb-version
17487~GNU gdb 5.2.1
17488~Copyright 2000 Free Software Foundation, Inc.
17489~GDB is free software, covered by the GNU General Public License, and
17490~you are welcome to change it and/or distribute copies of it under
17491~ certain conditions.
17492~Type "show copying" to see the conditions.
17493~There is absolutely no warranty for GDB. Type "show warranty" for
17494~ details.
b383017d 17495~This GDB was configured as
922fbb7b
AC
17496 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
17497^done
17498(@value{GDBP})
17499@end smallexample
17500
17501@subheading The @code{-interpreter-exec} Command
17502@findex -interpreter-exec
17503
17504@subheading Synopsis
17505
17506@smallexample
17507-interpreter-exec @var{interpreter} @var{command}
17508@end smallexample
17509
17510Execute the specified @var{command} in the given @var{interpreter}.
17511
17512@subheading @value{GDBN} Command
17513
17514The corresponding @value{GDBN} command is @samp{interpreter-exec}.
17515
17516@subheading Example
17517
17518@smallexample
17519(@value{GDBP})
17520-interpreter-exec console "break main"
17521&"During symbol reading, couldn't parse type; debugger out of date?.\n"
17522&"During symbol reading, bad structure-type format.\n"
17523~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
17524^done
17525(@value{GDBP})
17526@end smallexample
17527
17528@ignore
17529@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17530@node GDB/MI Kod Commands
17531@section @sc{gdb/mi} Kod Commands
17532
17533The Kod commands are not implemented.
17534
17535@c @subheading -kod-info
17536
17537@c @subheading -kod-list
17538
17539@c @subheading -kod-list-object-types
17540
17541@c @subheading -kod-show
17542
17543@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17544@node GDB/MI Memory Overlay Commands
17545@section @sc{gdb/mi} Memory Overlay Commands
17546
17547The memory overlay commands are not implemented.
17548
17549@c @subheading -overlay-auto
17550
17551@c @subheading -overlay-list-mapping-state
17552
17553@c @subheading -overlay-list-overlays
17554
17555@c @subheading -overlay-map
17556
17557@c @subheading -overlay-off
17558
17559@c @subheading -overlay-on
17560
17561@c @subheading -overlay-unmap
17562
17563@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17564@node GDB/MI Signal Handling Commands
17565@section @sc{gdb/mi} Signal Handling Commands
17566
17567Signal handling commands are not implemented.
17568
17569@c @subheading -signal-handle
17570
17571@c @subheading -signal-list-handle-actions
17572
17573@c @subheading -signal-list-signal-types
17574@end ignore
17575
17576
17577@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17578@node GDB/MI Stack Manipulation
17579@section @sc{gdb/mi} Stack Manipulation Commands
17580
17581
17582@subheading The @code{-stack-info-frame} Command
17583@findex -stack-info-frame
17584
17585@subsubheading Synopsis
17586
17587@smallexample
17588 -stack-info-frame
17589@end smallexample
17590
17591Get info on the current frame.
17592
17593@subsubheading @value{GDBN} Command
17594
17595The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
17596(without arguments).
17597
17598@subsubheading Example
17599N.A.
17600
17601@subheading The @code{-stack-info-depth} Command
17602@findex -stack-info-depth
17603
17604@subsubheading Synopsis
17605
17606@smallexample
17607 -stack-info-depth [ @var{max-depth} ]
17608@end smallexample
17609
17610Return the depth of the stack. If the integer argument @var{max-depth}
17611is specified, do not count beyond @var{max-depth} frames.
17612
17613@subsubheading @value{GDBN} Command
17614
17615There's no equivalent @value{GDBN} command.
17616
17617@subsubheading Example
17618
17619For a stack with frame levels 0 through 11:
17620
17621@smallexample
17622(@value{GDBP})
17623-stack-info-depth
17624^done,depth="12"
17625(@value{GDBP})
17626-stack-info-depth 4
17627^done,depth="4"
17628(@value{GDBP})
17629-stack-info-depth 12
17630^done,depth="12"
17631(@value{GDBP})
17632-stack-info-depth 11
17633^done,depth="11"
17634(@value{GDBP})
17635-stack-info-depth 13
17636^done,depth="12"
17637(@value{GDBP})
17638@end smallexample
17639
17640@subheading The @code{-stack-list-arguments} Command
17641@findex -stack-list-arguments
17642
17643@subsubheading Synopsis
17644
17645@smallexample
17646 -stack-list-arguments @var{show-values}
17647 [ @var{low-frame} @var{high-frame} ]
17648@end smallexample
17649
17650Display a list of the arguments for the frames between @var{low-frame}
17651and @var{high-frame} (inclusive). If @var{low-frame} and
17652@var{high-frame} are not provided, list the arguments for the whole call
17653stack.
17654
17655The @var{show-values} argument must have a value of 0 or 1. A value of
176560 means that only the names of the arguments are listed, a value of 1
17657means that both names and values of the arguments are printed.
17658
17659@subsubheading @value{GDBN} Command
17660
17661@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17662@samp{gdb_get_args} command which partially overlaps with the
17663functionality of @samp{-stack-list-arguments}.
17664
17665@subsubheading Example
17666
17667@smallexample
17668(@value{GDBP})
17669-stack-list-frames
17670^done,
17671stack=[
17672frame=@{level="0",addr="0x00010734",func="callee4",
17673file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17674frame=@{level="1",addr="0x0001076c",func="callee3",
17675file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17676frame=@{level="2",addr="0x0001078c",func="callee2",
17677file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17678frame=@{level="3",addr="0x000107b4",func="callee1",
17679file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17680frame=@{level="4",addr="0x000107e0",func="main",
17681file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17682(@value{GDBP})
17683-stack-list-arguments 0
17684^done,
17685stack-args=[
17686frame=@{level="0",args=[]@},
17687frame=@{level="1",args=[name="strarg"]@},
17688frame=@{level="2",args=[name="intarg",name="strarg"]@},
17689frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17690frame=@{level="4",args=[]@}]
17691(@value{GDBP})
17692-stack-list-arguments 1
17693^done,
17694stack-args=[
17695frame=@{level="0",args=[]@},
17696frame=@{level="1",
17697 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17698frame=@{level="2",args=[
17699@{name="intarg",value="2"@},
17700@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17701@{frame=@{level="3",args=[
17702@{name="intarg",value="2"@},
17703@{name="strarg",value="0x11940 \"A string argument.\""@},
17704@{name="fltarg",value="3.5"@}]@},
17705frame=@{level="4",args=[]@}]
17706(@value{GDBP})
17707-stack-list-arguments 0 2 2
17708^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17709(@value{GDBP})
17710-stack-list-arguments 1 2 2
17711^done,stack-args=[frame=@{level="2",
17712args=[@{name="intarg",value="2"@},
17713@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17714(@value{GDBP})
17715@end smallexample
17716
17717@c @subheading -stack-list-exception-handlers
17718
17719
17720@subheading The @code{-stack-list-frames} Command
17721@findex -stack-list-frames
17722
17723@subsubheading Synopsis
17724
17725@smallexample
17726 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17727@end smallexample
17728
17729List the frames currently on the stack. For each frame it displays the
17730following info:
17731
17732@table @samp
17733@item @var{level}
17734The frame number, 0 being the topmost frame, i.e. the innermost function.
17735@item @var{addr}
17736The @code{$pc} value for that frame.
17737@item @var{func}
17738Function name.
17739@item @var{file}
17740File name of the source file where the function lives.
17741@item @var{line}
17742Line number corresponding to the @code{$pc}.
17743@end table
17744
17745If invoked without arguments, this command prints a backtrace for the
17746whole stack. If given two integer arguments, it shows the frames whose
17747levels are between the two arguments (inclusive). If the two arguments
17748are equal, it shows the single frame at the corresponding level.
17749
17750@subsubheading @value{GDBN} Command
17751
17752The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17753
17754@subsubheading Example
17755
17756Full stack backtrace:
17757
17758@smallexample
17759(@value{GDBP})
17760-stack-list-frames
17761^done,stack=
17762[frame=@{level="0",addr="0x0001076c",func="foo",
17763 file="recursive2.c",line="11"@},
17764frame=@{level="1",addr="0x000107a4",func="foo",
17765 file="recursive2.c",line="14"@},
17766frame=@{level="2",addr="0x000107a4",func="foo",
17767 file="recursive2.c",line="14"@},
17768frame=@{level="3",addr="0x000107a4",func="foo",
17769 file="recursive2.c",line="14"@},
17770frame=@{level="4",addr="0x000107a4",func="foo",
17771 file="recursive2.c",line="14"@},
17772frame=@{level="5",addr="0x000107a4",func="foo",
17773 file="recursive2.c",line="14"@},
17774frame=@{level="6",addr="0x000107a4",func="foo",
17775 file="recursive2.c",line="14"@},
17776frame=@{level="7",addr="0x000107a4",func="foo",
17777 file="recursive2.c",line="14"@},
17778frame=@{level="8",addr="0x000107a4",func="foo",
17779 file="recursive2.c",line="14"@},
17780frame=@{level="9",addr="0x000107a4",func="foo",
17781 file="recursive2.c",line="14"@},
17782frame=@{level="10",addr="0x000107a4",func="foo",
17783 file="recursive2.c",line="14"@},
17784frame=@{level="11",addr="0x00010738",func="main",
17785 file="recursive2.c",line="4"@}]
17786(@value{GDBP})
17787@end smallexample
17788
17789Show frames between @var{low_frame} and @var{high_frame}:
17790
17791@smallexample
17792(@value{GDBP})
17793-stack-list-frames 3 5
17794^done,stack=
17795[frame=@{level="3",addr="0x000107a4",func="foo",
17796 file="recursive2.c",line="14"@},
17797frame=@{level="4",addr="0x000107a4",func="foo",
17798 file="recursive2.c",line="14"@},
17799frame=@{level="5",addr="0x000107a4",func="foo",
17800 file="recursive2.c",line="14"@}]
17801(@value{GDBP})
17802@end smallexample
17803
17804Show a single frame:
17805
17806@smallexample
17807(@value{GDBP})
17808-stack-list-frames 3 3
17809^done,stack=
17810[frame=@{level="3",addr="0x000107a4",func="foo",
17811 file="recursive2.c",line="14"@}]
17812(@value{GDBP})
17813@end smallexample
17814
17815
17816@subheading The @code{-stack-list-locals} Command
17817@findex -stack-list-locals
17818
17819@subsubheading Synopsis
17820
17821@smallexample
17822 -stack-list-locals @var{print-values}
17823@end smallexample
17824
17825Display the local variable names for the current frame. With an
bc8ced35
NR
17826argument of 0 or @code{--no-values}, prints only the names of the variables.
17827With argument of 1 or @code{--all-values}, prints also their values. With
17828argument of 2 or @code{--simple-values}, prints the name, type and value for
17829simple data types and the name and type for arrays, structures and
17830unions. In this last case, the idea is that the user can see the
17831value of simple data types immediately and he can create variable
17832objects for other data types if he wishes to explore their values in
17833more detail.
922fbb7b
AC
17834
17835@subsubheading @value{GDBN} Command
17836
17837@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17838
17839@subsubheading Example
17840
17841@smallexample
17842(@value{GDBP})
17843-stack-list-locals 0
17844^done,locals=[name="A",name="B",name="C"]
17845(@value{GDBP})
bc8ced35 17846-stack-list-locals --all-values
922fbb7b 17847^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
17848 @{name="C",value="@{1, 2, 3@}"@}]
17849-stack-list-locals --simple-values
17850^done,locals=[@{name="A",type="int",value="1"@},
17851 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
17852(@value{GDBP})
17853@end smallexample
17854
17855
17856@subheading The @code{-stack-select-frame} Command
17857@findex -stack-select-frame
17858
17859@subsubheading Synopsis
17860
17861@smallexample
17862 -stack-select-frame @var{framenum}
17863@end smallexample
17864
17865Change the current frame. Select a different frame @var{framenum} on
17866the stack.
17867
17868@subsubheading @value{GDBN} Command
17869
17870The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17871@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17872
17873@subsubheading Example
17874
17875@smallexample
17876(@value{GDBP})
17877-stack-select-frame 2
17878^done
17879(@value{GDBP})
17880@end smallexample
17881
17882@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17883@node GDB/MI Symbol Query
17884@section @sc{gdb/mi} Symbol Query Commands
17885
17886
17887@subheading The @code{-symbol-info-address} Command
17888@findex -symbol-info-address
17889
17890@subsubheading Synopsis
17891
17892@smallexample
17893 -symbol-info-address @var{symbol}
17894@end smallexample
17895
17896Describe where @var{symbol} is stored.
17897
17898@subsubheading @value{GDBN} Command
17899
17900The corresponding @value{GDBN} command is @samp{info address}.
17901
17902@subsubheading Example
17903N.A.
17904
17905
17906@subheading The @code{-symbol-info-file} Command
17907@findex -symbol-info-file
17908
17909@subsubheading Synopsis
17910
17911@smallexample
17912 -symbol-info-file
17913@end smallexample
17914
17915Show the file for the symbol.
17916
17917@subsubheading @value{GDBN} Command
17918
17919There's no equivalent @value{GDBN} command. @code{gdbtk} has
17920@samp{gdb_find_file}.
17921
17922@subsubheading Example
17923N.A.
17924
17925
17926@subheading The @code{-symbol-info-function} Command
17927@findex -symbol-info-function
17928
17929@subsubheading Synopsis
17930
17931@smallexample
17932 -symbol-info-function
17933@end smallexample
17934
17935Show which function the symbol lives in.
17936
17937@subsubheading @value{GDBN} Command
17938
17939@samp{gdb_get_function} in @code{gdbtk}.
17940
17941@subsubheading Example
17942N.A.
17943
17944
17945@subheading The @code{-symbol-info-line} Command
17946@findex -symbol-info-line
17947
17948@subsubheading Synopsis
17949
17950@smallexample
17951 -symbol-info-line
17952@end smallexample
17953
17954Show the core addresses of the code for a source line.
17955
17956@subsubheading @value{GDBN} Command
17957
71952f4c 17958The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17959@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17960
17961@subsubheading Example
17962N.A.
17963
17964
17965@subheading The @code{-symbol-info-symbol} Command
17966@findex -symbol-info-symbol
17967
17968@subsubheading Synopsis
17969
17970@smallexample
17971 -symbol-info-symbol @var{addr}
17972@end smallexample
17973
17974Describe what symbol is at location @var{addr}.
17975
17976@subsubheading @value{GDBN} Command
17977
17978The corresponding @value{GDBN} command is @samp{info symbol}.
17979
17980@subsubheading Example
17981N.A.
17982
17983
17984@subheading The @code{-symbol-list-functions} Command
17985@findex -symbol-list-functions
17986
17987@subsubheading Synopsis
17988
17989@smallexample
17990 -symbol-list-functions
17991@end smallexample
17992
17993List the functions in the executable.
17994
17995@subsubheading @value{GDBN} Command
17996
17997@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17998@samp{gdb_search} in @code{gdbtk}.
17999
18000@subsubheading Example
18001N.A.
18002
18003
32e7087d
JB
18004@subheading The @code{-symbol-list-lines} Command
18005@findex -symbol-list-lines
18006
18007@subsubheading Synopsis
18008
18009@smallexample
18010 -symbol-list-lines @var{filename}
18011@end smallexample
18012
18013Print the list of lines that contain code and their associated program
18014addresses for the given source filename. The entries are sorted in
18015ascending PC order.
18016
18017@subsubheading @value{GDBN} Command
18018
18019There is no corresponding @value{GDBN} command.
18020
18021@subsubheading Example
18022@smallexample
18023(@value{GDBP})
18024-symbol-list-lines basics.c
54ff5908 18025^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
18026(@value{GDBP})
18027@end smallexample
18028
18029
922fbb7b
AC
18030@subheading The @code{-symbol-list-types} Command
18031@findex -symbol-list-types
18032
18033@subsubheading Synopsis
18034
18035@smallexample
18036 -symbol-list-types
18037@end smallexample
18038
18039List all the type names.
18040
18041@subsubheading @value{GDBN} Command
18042
18043The corresponding commands are @samp{info types} in @value{GDBN},
18044@samp{gdb_search} in @code{gdbtk}.
18045
18046@subsubheading Example
18047N.A.
18048
18049
18050@subheading The @code{-symbol-list-variables} Command
18051@findex -symbol-list-variables
18052
18053@subsubheading Synopsis
18054
18055@smallexample
18056 -symbol-list-variables
18057@end smallexample
18058
18059List all the global and static variable names.
18060
18061@subsubheading @value{GDBN} Command
18062
18063@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
18064
18065@subsubheading Example
18066N.A.
18067
18068
18069@subheading The @code{-symbol-locate} Command
18070@findex -symbol-locate
18071
18072@subsubheading Synopsis
18073
18074@smallexample
18075 -symbol-locate
18076@end smallexample
18077
18078@subsubheading @value{GDBN} Command
18079
18080@samp{gdb_loc} in @code{gdbtk}.
18081
18082@subsubheading Example
18083N.A.
18084
18085
18086@subheading The @code{-symbol-type} Command
18087@findex -symbol-type
18088
18089@subsubheading Synopsis
18090
18091@smallexample
18092 -symbol-type @var{variable}
18093@end smallexample
18094
18095Show type of @var{variable}.
18096
18097@subsubheading @value{GDBN} Command
18098
18099The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
18100@samp{gdb_obj_variable}.
18101
18102@subsubheading Example
18103N.A.
18104
18105
18106@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18107@node GDB/MI Target Manipulation
18108@section @sc{gdb/mi} Target Manipulation Commands
18109
18110
18111@subheading The @code{-target-attach} Command
18112@findex -target-attach
18113
18114@subsubheading Synopsis
18115
18116@smallexample
18117 -target-attach @var{pid} | @var{file}
18118@end smallexample
18119
18120Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
18121
18122@subsubheading @value{GDBN} command
18123
18124The corresponding @value{GDBN} command is @samp{attach}.
18125
18126@subsubheading Example
18127N.A.
18128
18129
18130@subheading The @code{-target-compare-sections} Command
18131@findex -target-compare-sections
18132
18133@subsubheading Synopsis
18134
18135@smallexample
18136 -target-compare-sections [ @var{section} ]
18137@end smallexample
18138
18139Compare data of section @var{section} on target to the exec file.
18140Without the argument, all sections are compared.
18141
18142@subsubheading @value{GDBN} Command
18143
18144The @value{GDBN} equivalent is @samp{compare-sections}.
18145
18146@subsubheading Example
18147N.A.
18148
18149
18150@subheading The @code{-target-detach} Command
18151@findex -target-detach
18152
18153@subsubheading Synopsis
18154
18155@smallexample
18156 -target-detach
18157@end smallexample
18158
18159Disconnect from the remote target. There's no output.
18160
18161@subsubheading @value{GDBN} command
18162
18163The corresponding @value{GDBN} command is @samp{detach}.
18164
18165@subsubheading Example
18166
18167@smallexample
18168(@value{GDBP})
18169-target-detach
18170^done
18171(@value{GDBP})
18172@end smallexample
18173
18174
07f31aa6
DJ
18175@subheading The @code{-target-disconnect} Command
18176@findex -target-disconnect
18177
18178@subsubheading Synopsis
18179
18180@example
18181 -target-disconnect
18182@end example
18183
18184Disconnect from the remote target. There's no output.
18185
18186@subsubheading @value{GDBN} command
18187
18188The corresponding @value{GDBN} command is @samp{disconnect}.
18189
18190@subsubheading Example
18191
18192@smallexample
18193(@value{GDBP})
18194-target-disconnect
18195^done
18196(@value{GDBP})
18197@end smallexample
18198
18199
922fbb7b
AC
18200@subheading The @code{-target-download} Command
18201@findex -target-download
18202
18203@subsubheading Synopsis
18204
18205@smallexample
18206 -target-download
18207@end smallexample
18208
18209Loads the executable onto the remote target.
18210It prints out an update message every half second, which includes the fields:
18211
18212@table @samp
18213@item section
18214The name of the section.
18215@item section-sent
18216The size of what has been sent so far for that section.
18217@item section-size
18218The size of the section.
18219@item total-sent
18220The total size of what was sent so far (the current and the previous sections).
18221@item total-size
18222The size of the overall executable to download.
18223@end table
18224
18225@noindent
18226Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
18227@sc{gdb/mi} Output Syntax}).
18228
18229In addition, it prints the name and size of the sections, as they are
18230downloaded. These messages include the following fields:
18231
18232@table @samp
18233@item section
18234The name of the section.
18235@item section-size
18236The size of the section.
18237@item total-size
18238The size of the overall executable to download.
18239@end table
18240
18241@noindent
18242At the end, a summary is printed.
18243
18244@subsubheading @value{GDBN} Command
18245
18246The corresponding @value{GDBN} command is @samp{load}.
18247
18248@subsubheading Example
18249
18250Note: each status message appears on a single line. Here the messages
18251have been broken down so that they can fit onto a page.
18252
18253@smallexample
18254(@value{GDBP})
18255-target-download
18256+download,@{section=".text",section-size="6668",total-size="9880"@}
18257+download,@{section=".text",section-sent="512",section-size="6668",
18258total-sent="512",total-size="9880"@}
18259+download,@{section=".text",section-sent="1024",section-size="6668",
18260total-sent="1024",total-size="9880"@}
18261+download,@{section=".text",section-sent="1536",section-size="6668",
18262total-sent="1536",total-size="9880"@}
18263+download,@{section=".text",section-sent="2048",section-size="6668",
18264total-sent="2048",total-size="9880"@}
18265+download,@{section=".text",section-sent="2560",section-size="6668",
18266total-sent="2560",total-size="9880"@}
18267+download,@{section=".text",section-sent="3072",section-size="6668",
18268total-sent="3072",total-size="9880"@}
18269+download,@{section=".text",section-sent="3584",section-size="6668",
18270total-sent="3584",total-size="9880"@}
18271+download,@{section=".text",section-sent="4096",section-size="6668",
18272total-sent="4096",total-size="9880"@}
18273+download,@{section=".text",section-sent="4608",section-size="6668",
18274total-sent="4608",total-size="9880"@}
18275+download,@{section=".text",section-sent="5120",section-size="6668",
18276total-sent="5120",total-size="9880"@}
18277+download,@{section=".text",section-sent="5632",section-size="6668",
18278total-sent="5632",total-size="9880"@}
18279+download,@{section=".text",section-sent="6144",section-size="6668",
18280total-sent="6144",total-size="9880"@}
18281+download,@{section=".text",section-sent="6656",section-size="6668",
18282total-sent="6656",total-size="9880"@}
18283+download,@{section=".init",section-size="28",total-size="9880"@}
18284+download,@{section=".fini",section-size="28",total-size="9880"@}
18285+download,@{section=".data",section-size="3156",total-size="9880"@}
18286+download,@{section=".data",section-sent="512",section-size="3156",
18287total-sent="7236",total-size="9880"@}
18288+download,@{section=".data",section-sent="1024",section-size="3156",
18289total-sent="7748",total-size="9880"@}
18290+download,@{section=".data",section-sent="1536",section-size="3156",
18291total-sent="8260",total-size="9880"@}
18292+download,@{section=".data",section-sent="2048",section-size="3156",
18293total-sent="8772",total-size="9880"@}
18294+download,@{section=".data",section-sent="2560",section-size="3156",
18295total-sent="9284",total-size="9880"@}
18296+download,@{section=".data",section-sent="3072",section-size="3156",
18297total-sent="9796",total-size="9880"@}
18298^done,address="0x10004",load-size="9880",transfer-rate="6586",
18299write-rate="429"
18300(@value{GDBP})
18301@end smallexample
18302
18303
18304@subheading The @code{-target-exec-status} Command
18305@findex -target-exec-status
18306
18307@subsubheading Synopsis
18308
18309@smallexample
18310 -target-exec-status
18311@end smallexample
18312
18313Provide information on the state of the target (whether it is running or
18314not, for instance).
18315
18316@subsubheading @value{GDBN} Command
18317
18318There's no equivalent @value{GDBN} command.
18319
18320@subsubheading Example
18321N.A.
18322
18323
18324@subheading The @code{-target-list-available-targets} Command
18325@findex -target-list-available-targets
18326
18327@subsubheading Synopsis
18328
18329@smallexample
18330 -target-list-available-targets
18331@end smallexample
18332
18333List the possible targets to connect to.
18334
18335@subsubheading @value{GDBN} Command
18336
18337The corresponding @value{GDBN} command is @samp{help target}.
18338
18339@subsubheading Example
18340N.A.
18341
18342
18343@subheading The @code{-target-list-current-targets} Command
18344@findex -target-list-current-targets
18345
18346@subsubheading Synopsis
18347
18348@smallexample
18349 -target-list-current-targets
18350@end smallexample
18351
18352Describe the current target.
18353
18354@subsubheading @value{GDBN} Command
18355
18356The corresponding information is printed by @samp{info file} (among
18357other things).
18358
18359@subsubheading Example
18360N.A.
18361
18362
18363@subheading The @code{-target-list-parameters} Command
18364@findex -target-list-parameters
18365
18366@subsubheading Synopsis
18367
18368@smallexample
18369 -target-list-parameters
18370@end smallexample
18371
18372@c ????
18373
18374@subsubheading @value{GDBN} Command
18375
18376No equivalent.
18377
18378@subsubheading Example
18379N.A.
18380
18381
18382@subheading The @code{-target-select} Command
18383@findex -target-select
18384
18385@subsubheading Synopsis
18386
18387@smallexample
18388 -target-select @var{type} @var{parameters @dots{}}
18389@end smallexample
18390
18391Connect @value{GDBN} to the remote target. This command takes two args:
18392
18393@table @samp
18394@item @var{type}
18395The type of target, for instance @samp{async}, @samp{remote}, etc.
18396@item @var{parameters}
18397Device names, host names and the like. @xref{Target Commands, ,
18398Commands for managing targets}, for more details.
18399@end table
18400
18401The output is a connection notification, followed by the address at
18402which the target program is, in the following form:
18403
18404@smallexample
18405^connected,addr="@var{address}",func="@var{function name}",
18406 args=[@var{arg list}]
18407@end smallexample
18408
18409@subsubheading @value{GDBN} Command
18410
18411The corresponding @value{GDBN} command is @samp{target}.
18412
18413@subsubheading Example
18414
18415@smallexample
18416(@value{GDBP})
18417-target-select async /dev/ttya
18418^connected,addr="0xfe00a300",func="??",args=[]
18419(@value{GDBP})
18420@end smallexample
18421
18422@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18423@node GDB/MI Thread Commands
18424@section @sc{gdb/mi} Thread Commands
18425
18426
18427@subheading The @code{-thread-info} Command
18428@findex -thread-info
18429
18430@subsubheading Synopsis
18431
18432@smallexample
18433 -thread-info
18434@end smallexample
18435
18436@subsubheading @value{GDBN} command
18437
18438No equivalent.
18439
18440@subsubheading Example
18441N.A.
18442
18443
18444@subheading The @code{-thread-list-all-threads} Command
18445@findex -thread-list-all-threads
18446
18447@subsubheading Synopsis
18448
18449@smallexample
18450 -thread-list-all-threads
18451@end smallexample
18452
18453@subsubheading @value{GDBN} Command
18454
18455The equivalent @value{GDBN} command is @samp{info threads}.
18456
18457@subsubheading Example
18458N.A.
18459
18460
18461@subheading The @code{-thread-list-ids} Command
18462@findex -thread-list-ids
18463
18464@subsubheading Synopsis
18465
18466@smallexample
18467 -thread-list-ids
18468@end smallexample
18469
18470Produces a list of the currently known @value{GDBN} thread ids. At the
18471end of the list it also prints the total number of such threads.
18472
18473@subsubheading @value{GDBN} Command
18474
18475Part of @samp{info threads} supplies the same information.
18476
18477@subsubheading Example
18478
18479No threads present, besides the main process:
18480
18481@smallexample
18482(@value{GDBP})
18483-thread-list-ids
18484^done,thread-ids=@{@},number-of-threads="0"
18485(@value{GDBP})
18486@end smallexample
18487
18488
18489Several threads:
18490
18491@smallexample
18492(@value{GDBP})
18493-thread-list-ids
18494^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18495number-of-threads="3"
18496(@value{GDBP})
18497@end smallexample
18498
18499
18500@subheading The @code{-thread-select} Command
18501@findex -thread-select
18502
18503@subsubheading Synopsis
18504
18505@smallexample
18506 -thread-select @var{threadnum}
18507@end smallexample
18508
18509Make @var{threadnum} the current thread. It prints the number of the new
18510current thread, and the topmost frame for that thread.
18511
18512@subsubheading @value{GDBN} Command
18513
18514The corresponding @value{GDBN} command is @samp{thread}.
18515
18516@subsubheading Example
18517
18518@smallexample
18519(@value{GDBP})
18520-exec-next
18521^running
18522(@value{GDBP})
18523*stopped,reason="end-stepping-range",thread-id="2",line="187",
18524file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18525(@value{GDBP})
18526-thread-list-ids
18527^done,
18528thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18529number-of-threads="3"
18530(@value{GDBP})
18531-thread-select 3
18532^done,new-thread-id="3",
18533frame=@{level="0",func="vprintf",
18534args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18535@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18536(@value{GDBP})
18537@end smallexample
18538
18539@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18540@node GDB/MI Tracepoint Commands
18541@section @sc{gdb/mi} Tracepoint Commands
18542
18543The tracepoint commands are not yet implemented.
18544
18545@c @subheading -trace-actions
18546
18547@c @subheading -trace-delete
18548
18549@c @subheading -trace-disable
18550
18551@c @subheading -trace-dump
18552
18553@c @subheading -trace-enable
18554
18555@c @subheading -trace-exists
18556
18557@c @subheading -trace-find
18558
18559@c @subheading -trace-frame-number
18560
18561@c @subheading -trace-info
18562
18563@c @subheading -trace-insert
18564
18565@c @subheading -trace-list
18566
18567@c @subheading -trace-pass-count
18568
18569@c @subheading -trace-save
18570
18571@c @subheading -trace-start
18572
18573@c @subheading -trace-stop
18574
18575
18576@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18577@node GDB/MI Variable Objects
18578@section @sc{gdb/mi} Variable Objects
18579
18580
18581@subheading Motivation for Variable Objects in @sc{gdb/mi}
18582
18583For the implementation of a variable debugger window (locals, watched
18584expressions, etc.), we are proposing the adaptation of the existing code
18585used by @code{Insight}.
18586
18587The two main reasons for that are:
18588
18589@enumerate 1
18590@item
18591It has been proven in practice (it is already on its second generation).
18592
18593@item
18594It will shorten development time (needless to say how important it is
18595now).
18596@end enumerate
18597
18598The original interface was designed to be used by Tcl code, so it was
18599slightly changed so it could be used through @sc{gdb/mi}. This section
18600describes the @sc{gdb/mi} operations that will be available and gives some
18601hints about their use.
18602
18603@emph{Note}: In addition to the set of operations described here, we
18604expect the @sc{gui} implementation of a variable window to require, at
18605least, the following operations:
18606
18607@itemize @bullet
18608@item @code{-gdb-show} @code{output-radix}
18609@item @code{-stack-list-arguments}
18610@item @code{-stack-list-locals}
18611@item @code{-stack-select-frame}
18612@end itemize
18613
18614@subheading Introduction to Variable Objects in @sc{gdb/mi}
18615
18616@cindex variable objects in @sc{gdb/mi}
18617The basic idea behind variable objects is the creation of a named object
18618to represent a variable, an expression, a memory location or even a CPU
18619register. For each object created, a set of operations is available for
18620examining or changing its properties.
18621
18622Furthermore, complex data types, such as C structures, are represented
18623in a tree format. For instance, the @code{struct} type variable is the
18624root and the children will represent the struct members. If a child
18625is itself of a complex type, it will also have children of its own.
18626Appropriate language differences are handled for C, C@t{++} and Java.
18627
18628When returning the actual values of the objects, this facility allows
18629for the individual selection of the display format used in the result
18630creation. It can be chosen among: binary, decimal, hexadecimal, octal
18631and natural. Natural refers to a default format automatically
18632chosen based on the variable type (like decimal for an @code{int}, hex
18633for pointers, etc.).
18634
18635The following is the complete set of @sc{gdb/mi} operations defined to
18636access this functionality:
18637
18638@multitable @columnfractions .4 .6
18639@item @strong{Operation}
18640@tab @strong{Description}
18641
18642@item @code{-var-create}
18643@tab create a variable object
18644@item @code{-var-delete}
18645@tab delete the variable object and its children
18646@item @code{-var-set-format}
18647@tab set the display format of this variable
18648@item @code{-var-show-format}
18649@tab show the display format of this variable
18650@item @code{-var-info-num-children}
18651@tab tells how many children this object has
18652@item @code{-var-list-children}
18653@tab return a list of the object's children
18654@item @code{-var-info-type}
18655@tab show the type of this variable object
18656@item @code{-var-info-expression}
18657@tab print what this variable object represents
18658@item @code{-var-show-attributes}
18659@tab is this variable editable? does it exist here?
18660@item @code{-var-evaluate-expression}
18661@tab get the value of this variable
18662@item @code{-var-assign}
18663@tab set the value of this variable
18664@item @code{-var-update}
18665@tab update the variable and its children
18666@end multitable
18667
18668In the next subsection we describe each operation in detail and suggest
18669how it can be used.
18670
18671@subheading Description And Use of Operations on Variable Objects
18672
18673@subheading The @code{-var-create} Command
18674@findex -var-create
18675
18676@subsubheading Synopsis
18677
18678@smallexample
18679 -var-create @{@var{name} | "-"@}
18680 @{@var{frame-addr} | "*"@} @var{expression}
18681@end smallexample
18682
18683This operation creates a variable object, which allows the monitoring of
18684a variable, the result of an expression, a memory cell or a CPU
18685register.
18686
18687The @var{name} parameter is the string by which the object can be
18688referenced. It must be unique. If @samp{-} is specified, the varobj
18689system will generate a string ``varNNNNNN'' automatically. It will be
18690unique provided that one does not specify @var{name} on that format.
18691The command fails if a duplicate name is found.
18692
18693The frame under which the expression should be evaluated can be
18694specified by @var{frame-addr}. A @samp{*} indicates that the current
18695frame should be used.
18696
18697@var{expression} is any expression valid on the current language set (must not
18698begin with a @samp{*}), or one of the following:
18699
18700@itemize @bullet
18701@item
18702@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18703
18704@item
18705@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18706
18707@item
18708@samp{$@var{regname}} --- a CPU register name
18709@end itemize
18710
18711@subsubheading Result
18712
18713This operation returns the name, number of children and the type of the
18714object created. Type is returned as a string as the ones generated by
18715the @value{GDBN} CLI:
18716
18717@smallexample
18718 name="@var{name}",numchild="N",type="@var{type}"
18719@end smallexample
18720
18721
18722@subheading The @code{-var-delete} Command
18723@findex -var-delete
18724
18725@subsubheading Synopsis
18726
18727@smallexample
18728 -var-delete @var{name}
18729@end smallexample
18730
18731Deletes a previously created variable object and all of its children.
18732
18733Returns an error if the object @var{name} is not found.
18734
18735
18736@subheading The @code{-var-set-format} Command
18737@findex -var-set-format
18738
18739@subsubheading Synopsis
18740
18741@smallexample
18742 -var-set-format @var{name} @var{format-spec}
18743@end smallexample
18744
18745Sets the output format for the value of the object @var{name} to be
18746@var{format-spec}.
18747
18748The syntax for the @var{format-spec} is as follows:
18749
18750@smallexample
18751 @var{format-spec} @expansion{}
18752 @{binary | decimal | hexadecimal | octal | natural@}
18753@end smallexample
18754
18755
18756@subheading The @code{-var-show-format} Command
18757@findex -var-show-format
18758
18759@subsubheading Synopsis
18760
18761@smallexample
18762 -var-show-format @var{name}
18763@end smallexample
18764
18765Returns the format used to display the value of the object @var{name}.
18766
18767@smallexample
18768 @var{format} @expansion{}
18769 @var{format-spec}
18770@end smallexample
18771
18772
18773@subheading The @code{-var-info-num-children} Command
18774@findex -var-info-num-children
18775
18776@subsubheading Synopsis
18777
18778@smallexample
18779 -var-info-num-children @var{name}
18780@end smallexample
18781
18782Returns the number of children of a variable object @var{name}:
18783
18784@smallexample
18785 numchild=@var{n}
18786@end smallexample
18787
18788
18789@subheading The @code{-var-list-children} Command
18790@findex -var-list-children
18791
18792@subsubheading Synopsis
18793
18794@smallexample
bc8ced35 18795 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
18796@end smallexample
18797
bc8ced35
NR
18798Returns a list of the children of the specified variable object. With
18799just the variable object name as an argument or with an optional
18800preceding argument of 0 or @code{--no-values}, prints only the names of the
18801variables. With an optional preceding argument of 1 or @code{--all-values},
18802also prints their values.
18803
18804@subsubheading Example
922fbb7b
AC
18805
18806@smallexample
bc8ced35
NR
18807(@value{GDBP})
18808 -var-list-children n
922fbb7b
AC
18809 numchild=@var{n},children=[@{name=@var{name},
18810 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
18811(@value{GDBP})
18812 -var-list-children --all-values n
18813 numchild=@var{n},children=[@{name=@var{name},
18814 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
18815@end smallexample
18816
18817
18818@subheading The @code{-var-info-type} Command
18819@findex -var-info-type
18820
18821@subsubheading Synopsis
18822
18823@smallexample
18824 -var-info-type @var{name}
18825@end smallexample
18826
18827Returns the type of the specified variable @var{name}. The type is
18828returned as a string in the same format as it is output by the
18829@value{GDBN} CLI:
18830
18831@smallexample
18832 type=@var{typename}
18833@end smallexample
18834
18835
18836@subheading The @code{-var-info-expression} Command
18837@findex -var-info-expression
18838
18839@subsubheading Synopsis
18840
18841@smallexample
18842 -var-info-expression @var{name}
18843@end smallexample
18844
18845Returns what is represented by the variable object @var{name}:
18846
18847@smallexample
18848 lang=@var{lang-spec},exp=@var{expression}
18849@end smallexample
18850
18851@noindent
18852where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18853
18854@subheading The @code{-var-show-attributes} Command
18855@findex -var-show-attributes
18856
18857@subsubheading Synopsis
18858
18859@smallexample
18860 -var-show-attributes @var{name}
18861@end smallexample
18862
18863List attributes of the specified variable object @var{name}:
18864
18865@smallexample
18866 status=@var{attr} [ ( ,@var{attr} )* ]
18867@end smallexample
18868
18869@noindent
18870where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18871
18872@subheading The @code{-var-evaluate-expression} Command
18873@findex -var-evaluate-expression
18874
18875@subsubheading Synopsis
18876
18877@smallexample
18878 -var-evaluate-expression @var{name}
18879@end smallexample
18880
18881Evaluates the expression that is represented by the specified variable
18882object and returns its value as a string in the current format specified
18883for the object:
18884
18885@smallexample
18886 value=@var{value}
18887@end smallexample
18888
18889Note that one must invoke @code{-var-list-children} for a variable
18890before the value of a child variable can be evaluated.
18891
18892@subheading The @code{-var-assign} Command
18893@findex -var-assign
18894
18895@subsubheading Synopsis
18896
18897@smallexample
18898 -var-assign @var{name} @var{expression}
18899@end smallexample
18900
18901Assigns the value of @var{expression} to the variable object specified
18902by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 18903value is altered by the assign, the variable will show up in any
922fbb7b
AC
18904subsequent @code{-var-update} list.
18905
18906@subsubheading Example
18907
18908@smallexample
18909(@value{GDBP})
18910-var-assign var1 3
18911^done,value="3"
18912(@value{GDBP})
18913-var-update *
18914^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18915(@value{GDBP})
18916@end smallexample
18917
18918@subheading The @code{-var-update} Command
18919@findex -var-update
18920
18921@subsubheading Synopsis
18922
18923@smallexample
18924 -var-update @{@var{name} | "*"@}
18925@end smallexample
18926
18927Update the value of the variable object @var{name} by evaluating its
18928expression after fetching all the new values from memory or registers.
18929A @samp{*} causes all existing variable objects to be updated.
18930
18931
18932@node Annotations
18933@chapter @value{GDBN} Annotations
18934
086432e2
AC
18935This chapter describes annotations in @value{GDBN}. Annotations were
18936designed to interface @value{GDBN} to graphical user interfaces or other
18937similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18938relatively high level.
18939
086432e2
AC
18940The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18941(@pxref{GDB/MI}).
18942
922fbb7b
AC
18943@ignore
18944This is Edition @value{EDITION}, @value{DATE}.
18945@end ignore
18946
18947@menu
18948* Annotations Overview:: What annotations are; the general syntax.
18949* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18950* Prompting:: Annotations marking @value{GDBN}'s need for input.
18951* Errors:: Annotations for error messages.
922fbb7b
AC
18952* Invalidation:: Some annotations describe things now invalid.
18953* Annotations for Running::
18954 Whether the program is running, how it stopped, etc.
18955* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18956@end menu
18957
18958@node Annotations Overview
18959@section What is an Annotation?
18960@cindex annotations
18961
922fbb7b
AC
18962Annotations start with a newline character, two @samp{control-z}
18963characters, and the name of the annotation. If there is no additional
18964information associated with this annotation, the name of the annotation
18965is followed immediately by a newline. If there is additional
18966information, the name of the annotation is followed by a space, the
18967additional information, and a newline. The additional information
18968cannot contain newline characters.
18969
18970Any output not beginning with a newline and two @samp{control-z}
18971characters denotes literal output from @value{GDBN}. Currently there is
18972no need for @value{GDBN} to output a newline followed by two
18973@samp{control-z} characters, but if there was such a need, the
18974annotations could be extended with an @samp{escape} annotation which
18975means those three characters as output.
18976
086432e2
AC
18977The annotation @var{level}, which is specified using the
18978@option{--annotate} command line option (@pxref{Mode Options}), controls
18979how much information @value{GDBN} prints together with its prompt,
18980values of expressions, source lines, and other types of output. Level 0
18981is for no anntations, level 1 is for use when @value{GDBN} is run as a
18982subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18983for programs that control @value{GDBN}, and level 2 annotations have
18984been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18985Interface, annotate, GDB's Obsolete Annotations}). This chapter
18986describes level 3 annotations.
18987
922fbb7b
AC
18988A simple example of starting up @value{GDBN} with annotations is:
18989
18990@smallexample
086432e2
AC
18991$ @kbd{gdb --annotate=3}
18992GNU gdb 6.0
18993Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18994GDB is free software, covered by the GNU General Public License,
18995and you are welcome to change it and/or distribute copies of it
18996under certain conditions.
18997Type "show copying" to see the conditions.
18998There is absolutely no warranty for GDB. Type "show warranty"
18999for details.
086432e2 19000This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
19001
19002^Z^Zpre-prompt
f7dc1244 19003(@value{GDBP})
922fbb7b 19004^Z^Zprompt
086432e2 19005@kbd{quit}
922fbb7b
AC
19006
19007^Z^Zpost-prompt
b383017d 19008$
922fbb7b
AC
19009@end smallexample
19010
19011Here @samp{quit} is input to @value{GDBN}; the rest is output from
19012@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
19013denotes a @samp{control-z} character) are annotations; the rest is
19014output from @value{GDBN}.
19015
19016@node Server Prefix
19017@section The Server Prefix
19018@cindex server prefix for annotations
19019
19020To issue a command to @value{GDBN} without affecting certain aspects of
19021the state which is seen by users, prefix it with @samp{server }. This
19022means that this command will not affect the command history, nor will it
19023affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
19024pressed on a line by itself.
19025
19026The server prefix does not affect the recording of values into the value
19027history; to print a value without recording it into the value history,
19028use the @code{output} command instead of the @code{print} command.
19029
922fbb7b
AC
19030@node Prompting
19031@section Annotation for @value{GDBN} Input
19032
19033@cindex annotations for prompts
19034When @value{GDBN} prompts for input, it annotates this fact so it is possible
19035to know when to send output, when the output from a given command is
19036over, etc.
19037
19038Different kinds of input each have a different @dfn{input type}. Each
19039input type has three annotations: a @code{pre-} annotation, which
19040denotes the beginning of any prompt which is being output, a plain
19041annotation, which denotes the end of the prompt, and then a @code{post-}
19042annotation which denotes the end of any echo which may (or may not) be
19043associated with the input. For example, the @code{prompt} input type
19044features the following annotations:
19045
19046@smallexample
19047^Z^Zpre-prompt
19048^Z^Zprompt
19049^Z^Zpost-prompt
19050@end smallexample
19051
19052The input types are
19053
19054@table @code
19055@findex pre-prompt
19056@findex prompt
19057@findex post-prompt
19058@item prompt
19059When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
19060
19061@findex pre-commands
19062@findex commands
19063@findex post-commands
19064@item commands
19065When @value{GDBN} prompts for a set of commands, like in the @code{commands}
19066command. The annotations are repeated for each command which is input.
19067
19068@findex pre-overload-choice
19069@findex overload-choice
19070@findex post-overload-choice
19071@item overload-choice
19072When @value{GDBN} wants the user to select between various overloaded functions.
19073
19074@findex pre-query
19075@findex query
19076@findex post-query
19077@item query
19078When @value{GDBN} wants the user to confirm a potentially dangerous operation.
19079
19080@findex pre-prompt-for-continue
19081@findex prompt-for-continue
19082@findex post-prompt-for-continue
19083@item prompt-for-continue
19084When @value{GDBN} is asking the user to press return to continue. Note: Don't
19085expect this to work well; instead use @code{set height 0} to disable
19086prompting. This is because the counting of lines is buggy in the
19087presence of annotations.
19088@end table
19089
19090@node Errors
19091@section Errors
19092@cindex annotations for errors, warnings and interrupts
19093
19094@findex quit
19095@smallexample
19096^Z^Zquit
19097@end smallexample
19098
19099This annotation occurs right before @value{GDBN} responds to an interrupt.
19100
19101@findex error
19102@smallexample
19103^Z^Zerror
19104@end smallexample
19105
19106This annotation occurs right before @value{GDBN} responds to an error.
19107
19108Quit and error annotations indicate that any annotations which @value{GDBN} was
19109in the middle of may end abruptly. For example, if a
19110@code{value-history-begin} annotation is followed by a @code{error}, one
19111cannot expect to receive the matching @code{value-history-end}. One
19112cannot expect not to receive it either, however; an error annotation
19113does not necessarily mean that @value{GDBN} is immediately returning all the way
19114to the top level.
19115
19116@findex error-begin
19117A quit or error annotation may be preceded by
19118
19119@smallexample
19120^Z^Zerror-begin
19121@end smallexample
19122
19123Any output between that and the quit or error annotation is the error
19124message.
19125
19126Warning messages are not yet annotated.
19127@c If we want to change that, need to fix warning(), type_error(),
19128@c range_error(), and possibly other places.
19129
922fbb7b
AC
19130@node Invalidation
19131@section Invalidation Notices
19132
19133@cindex annotations for invalidation messages
19134The following annotations say that certain pieces of state may have
19135changed.
19136
19137@table @code
19138@findex frames-invalid
19139@item ^Z^Zframes-invalid
19140
19141The frames (for example, output from the @code{backtrace} command) may
19142have changed.
19143
19144@findex breakpoints-invalid
19145@item ^Z^Zbreakpoints-invalid
19146
19147The breakpoints may have changed. For example, the user just added or
19148deleted a breakpoint.
19149@end table
19150
19151@node Annotations for Running
19152@section Running the Program
19153@cindex annotations for running programs
19154
19155@findex starting
19156@findex stopping
19157When the program starts executing due to a @value{GDBN} command such as
b383017d 19158@code{step} or @code{continue},
922fbb7b
AC
19159
19160@smallexample
19161^Z^Zstarting
19162@end smallexample
19163
b383017d 19164is output. When the program stops,
922fbb7b
AC
19165
19166@smallexample
19167^Z^Zstopped
19168@end smallexample
19169
19170is output. Before the @code{stopped} annotation, a variety of
19171annotations describe how the program stopped.
19172
19173@table @code
19174@findex exited
19175@item ^Z^Zexited @var{exit-status}
19176The program exited, and @var{exit-status} is the exit status (zero for
19177successful exit, otherwise nonzero).
19178
19179@findex signalled
19180@findex signal-name
19181@findex signal-name-end
19182@findex signal-string
19183@findex signal-string-end
19184@item ^Z^Zsignalled
19185The program exited with a signal. After the @code{^Z^Zsignalled}, the
19186annotation continues:
19187
19188@smallexample
19189@var{intro-text}
19190^Z^Zsignal-name
19191@var{name}
19192^Z^Zsignal-name-end
19193@var{middle-text}
19194^Z^Zsignal-string
19195@var{string}
19196^Z^Zsignal-string-end
19197@var{end-text}
19198@end smallexample
19199
19200@noindent
19201where @var{name} is the name of the signal, such as @code{SIGILL} or
19202@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
19203as @code{Illegal Instruction} or @code{Segmentation fault}.
19204@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
19205user's benefit and have no particular format.
19206
19207@findex signal
19208@item ^Z^Zsignal
19209The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
19210just saying that the program received the signal, not that it was
19211terminated with it.
19212
19213@findex breakpoint
19214@item ^Z^Zbreakpoint @var{number}
19215The program hit breakpoint number @var{number}.
19216
19217@findex watchpoint
19218@item ^Z^Zwatchpoint @var{number}
19219The program hit watchpoint number @var{number}.
19220@end table
19221
19222@node Source Annotations
19223@section Displaying Source
19224@cindex annotations for source display
19225
19226@findex source
19227The following annotation is used instead of displaying source code:
19228
19229@smallexample
19230^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
19231@end smallexample
19232
19233where @var{filename} is an absolute file name indicating which source
19234file, @var{line} is the line number within that file (where 1 is the
19235first line in the file), @var{character} is the character position
19236within the file (where 0 is the first character in the file) (for most
19237debug formats this will necessarily point to the beginning of a line),
19238@var{middle} is @samp{middle} if @var{addr} is in the middle of the
19239line, or @samp{beg} if @var{addr} is at the beginning of the line, and
19240@var{addr} is the address in the target program associated with the
19241source which is being displayed. @var{addr} is in the form @samp{0x}
19242followed by one or more lowercase hex digits (note that this does not
19243depend on the language).
19244
8e04817f
AC
19245@node GDB Bugs
19246@chapter Reporting Bugs in @value{GDBN}
19247@cindex bugs in @value{GDBN}
19248@cindex reporting bugs in @value{GDBN}
c906108c 19249
8e04817f 19250Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 19251
8e04817f
AC
19252Reporting a bug may help you by bringing a solution to your problem, or it
19253may not. But in any case the principal function of a bug report is to help
19254the entire community by making the next version of @value{GDBN} work better. Bug
19255reports are your contribution to the maintenance of @value{GDBN}.
c906108c 19256
8e04817f
AC
19257In order for a bug report to serve its purpose, you must include the
19258information that enables us to fix the bug.
c4555f82
SC
19259
19260@menu
8e04817f
AC
19261* Bug Criteria:: Have you found a bug?
19262* Bug Reporting:: How to report bugs
c4555f82
SC
19263@end menu
19264
8e04817f
AC
19265@node Bug Criteria
19266@section Have you found a bug?
19267@cindex bug criteria
c4555f82 19268
8e04817f 19269If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
19270
19271@itemize @bullet
8e04817f
AC
19272@cindex fatal signal
19273@cindex debugger crash
19274@cindex crash of debugger
c4555f82 19275@item
8e04817f
AC
19276If the debugger gets a fatal signal, for any input whatever, that is a
19277@value{GDBN} bug. Reliable debuggers never crash.
19278
19279@cindex error on valid input
19280@item
19281If @value{GDBN} produces an error message for valid input, that is a
19282bug. (Note that if you're cross debugging, the problem may also be
19283somewhere in the connection to the target.)
c4555f82 19284
8e04817f 19285@cindex invalid input
c4555f82 19286@item
8e04817f
AC
19287If @value{GDBN} does not produce an error message for invalid input,
19288that is a bug. However, you should note that your idea of
19289``invalid input'' might be our idea of ``an extension'' or ``support
19290for traditional practice''.
19291
19292@item
19293If you are an experienced user of debugging tools, your suggestions
19294for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
19295@end itemize
19296
8e04817f
AC
19297@node Bug Reporting
19298@section How to report bugs
19299@cindex bug reports
19300@cindex @value{GDBN} bugs, reporting
19301
19302A number of companies and individuals offer support for @sc{gnu} products.
19303If you obtained @value{GDBN} from a support organization, we recommend you
19304contact that organization first.
19305
19306You can find contact information for many support companies and
19307individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
19308distribution.
19309@c should add a web page ref...
19310
129188f6
AC
19311In any event, we also recommend that you submit bug reports for
19312@value{GDBN}. The prefered method is to submit them directly using
19313@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
19314page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
19315be used.
8e04817f
AC
19316
19317@strong{Do not send bug reports to @samp{info-gdb}, or to
19318@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
19319not want to receive bug reports. Those that do have arranged to receive
19320@samp{bug-gdb}.
19321
19322The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
19323serves as a repeater. The mailing list and the newsgroup carry exactly
19324the same messages. Often people think of posting bug reports to the
19325newsgroup instead of mailing them. This appears to work, but it has one
19326problem which can be crucial: a newsgroup posting often lacks a mail
19327path back to the sender. Thus, if we need to ask for more information,
19328we may be unable to reach you. For this reason, it is better to send
19329bug reports to the mailing list.
c4555f82 19330
8e04817f
AC
19331The fundamental principle of reporting bugs usefully is this:
19332@strong{report all the facts}. If you are not sure whether to state a
19333fact or leave it out, state it!
c4555f82 19334
8e04817f
AC
19335Often people omit facts because they think they know what causes the
19336problem and assume that some details do not matter. Thus, you might
19337assume that the name of the variable you use in an example does not matter.
19338Well, probably it does not, but one cannot be sure. Perhaps the bug is a
19339stray memory reference which happens to fetch from the location where that
19340name is stored in memory; perhaps, if the name were different, the contents
19341of that location would fool the debugger into doing the right thing despite
19342the bug. Play it safe and give a specific, complete example. That is the
19343easiest thing for you to do, and the most helpful.
c4555f82 19344
8e04817f
AC
19345Keep in mind that the purpose of a bug report is to enable us to fix the
19346bug. It may be that the bug has been reported previously, but neither
19347you nor we can know that unless your bug report is complete and
19348self-contained.
c4555f82 19349
8e04817f
AC
19350Sometimes people give a few sketchy facts and ask, ``Does this ring a
19351bell?'' Those bug reports are useless, and we urge everyone to
19352@emph{refuse to respond to them} except to chide the sender to report
19353bugs properly.
19354
19355To enable us to fix the bug, you should include all these things:
c4555f82
SC
19356
19357@itemize @bullet
19358@item
8e04817f
AC
19359The version of @value{GDBN}. @value{GDBN} announces it if you start
19360with no arguments; you can also print it at any time using @code{show
19361version}.
c4555f82 19362
8e04817f
AC
19363Without this, we will not know whether there is any point in looking for
19364the bug in the current version of @value{GDBN}.
c4555f82
SC
19365
19366@item
8e04817f
AC
19367The type of machine you are using, and the operating system name and
19368version number.
c4555f82
SC
19369
19370@item
8e04817f
AC
19371What compiler (and its version) was used to compile @value{GDBN}---e.g.
19372``@value{GCC}--2.8.1''.
c4555f82
SC
19373
19374@item
8e04817f
AC
19375What compiler (and its version) was used to compile the program you are
19376debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
19377C Compiler''. For GCC, you can say @code{gcc --version} to get this
19378information; for other compilers, see the documentation for those
19379compilers.
c4555f82 19380
8e04817f
AC
19381@item
19382The command arguments you gave the compiler to compile your example and
19383observe the bug. For example, did you use @samp{-O}? To guarantee
19384you will not omit something important, list them all. A copy of the
19385Makefile (or the output from make) is sufficient.
c4555f82 19386
8e04817f
AC
19387If we were to try to guess the arguments, we would probably guess wrong
19388and then we might not encounter the bug.
c4555f82 19389
8e04817f
AC
19390@item
19391A complete input script, and all necessary source files, that will
19392reproduce the bug.
c4555f82 19393
8e04817f
AC
19394@item
19395A description of what behavior you observe that you believe is
19396incorrect. For example, ``It gets a fatal signal.''
c4555f82 19397
8e04817f
AC
19398Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
19399will certainly notice it. But if the bug is incorrect output, we might
19400not notice unless it is glaringly wrong. You might as well not give us
19401a chance to make a mistake.
c4555f82 19402
8e04817f
AC
19403Even if the problem you experience is a fatal signal, you should still
19404say so explicitly. Suppose something strange is going on, such as, your
19405copy of @value{GDBN} is out of synch, or you have encountered a bug in
19406the C library on your system. (This has happened!) Your copy might
19407crash and ours would not. If you told us to expect a crash, then when
19408ours fails to crash, we would know that the bug was not happening for
19409us. If you had not told us to expect a crash, then we would not be able
19410to draw any conclusion from our observations.
c4555f82 19411
e0c07bf0
MC
19412@pindex script
19413@cindex recording a session script
19414To collect all this information, you can use a session recording program
19415such as @command{script}, which is available on many Unix systems.
19416Just run your @value{GDBN} session inside @command{script} and then
19417include the @file{typescript} file with your bug report.
19418
19419Another way to record a @value{GDBN} session is to run @value{GDBN}
19420inside Emacs and then save the entire buffer to a file.
19421
8e04817f
AC
19422@item
19423If you wish to suggest changes to the @value{GDBN} source, send us context
19424diffs. If you even discuss something in the @value{GDBN} source, refer to
19425it by context, not by line number.
c4555f82 19426
8e04817f
AC
19427The line numbers in our development sources will not match those in your
19428sources. Your line numbers would convey no useful information to us.
c4555f82 19429
8e04817f 19430@end itemize
c4555f82 19431
8e04817f 19432Here are some things that are not necessary:
c4555f82 19433
8e04817f
AC
19434@itemize @bullet
19435@item
19436A description of the envelope of the bug.
c4555f82 19437
8e04817f
AC
19438Often people who encounter a bug spend a lot of time investigating
19439which changes to the input file will make the bug go away and which
19440changes will not affect it.
c4555f82 19441
8e04817f
AC
19442This is often time consuming and not very useful, because the way we
19443will find the bug is by running a single example under the debugger
19444with breakpoints, not by pure deduction from a series of examples.
19445We recommend that you save your time for something else.
c4555f82 19446
8e04817f
AC
19447Of course, if you can find a simpler example to report @emph{instead}
19448of the original one, that is a convenience for us. Errors in the
19449output will be easier to spot, running under the debugger will take
19450less time, and so on.
c4555f82 19451
8e04817f
AC
19452However, simplification is not vital; if you do not want to do this,
19453report the bug anyway and send us the entire test case you used.
c4555f82 19454
8e04817f
AC
19455@item
19456A patch for the bug.
c4555f82 19457
8e04817f
AC
19458A patch for the bug does help us if it is a good one. But do not omit
19459the necessary information, such as the test case, on the assumption that
19460a patch is all we need. We might see problems with your patch and decide
19461to fix the problem another way, or we might not understand it at all.
c4555f82 19462
8e04817f
AC
19463Sometimes with a program as complicated as @value{GDBN} it is very hard to
19464construct an example that will make the program follow a certain path
19465through the code. If you do not send us the example, we will not be able
19466to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 19467
8e04817f
AC
19468And if we cannot understand what bug you are trying to fix, or why your
19469patch should be an improvement, we will not install it. A test case will
19470help us to understand.
c4555f82 19471
8e04817f
AC
19472@item
19473A guess about what the bug is or what it depends on.
c4555f82 19474
8e04817f
AC
19475Such guesses are usually wrong. Even we cannot guess right about such
19476things without first using the debugger to find the facts.
19477@end itemize
c4555f82 19478
8e04817f
AC
19479@c The readline documentation is distributed with the readline code
19480@c and consists of the two following files:
19481@c rluser.texinfo
19482@c inc-hist.texinfo
19483@c Use -I with makeinfo to point to the appropriate directory,
19484@c environment var TEXINPUTS with TeX.
19485@include rluser.texinfo
19486@include inc-hist.texinfo
c4555f82 19487
c4555f82 19488
8e04817f
AC
19489@node Formatting Documentation
19490@appendix Formatting Documentation
c4555f82 19491
8e04817f
AC
19492@cindex @value{GDBN} reference card
19493@cindex reference card
19494The @value{GDBN} 4 release includes an already-formatted reference card, ready
19495for printing with PostScript or Ghostscript, in the @file{gdb}
19496subdirectory of the main source directory@footnote{In
19497@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
19498release.}. If you can use PostScript or Ghostscript with your printer,
19499you can print the reference card immediately with @file{refcard.ps}.
c4555f82 19500
8e04817f
AC
19501The release also includes the source for the reference card. You
19502can format it, using @TeX{}, by typing:
c4555f82 19503
474c8240 19504@smallexample
8e04817f 19505make refcard.dvi
474c8240 19506@end smallexample
c4555f82 19507
8e04817f
AC
19508The @value{GDBN} reference card is designed to print in @dfn{landscape}
19509mode on US ``letter'' size paper;
19510that is, on a sheet 11 inches wide by 8.5 inches
19511high. You will need to specify this form of printing as an option to
19512your @sc{dvi} output program.
c4555f82 19513
8e04817f 19514@cindex documentation
c4555f82 19515
8e04817f
AC
19516All the documentation for @value{GDBN} comes as part of the machine-readable
19517distribution. The documentation is written in Texinfo format, which is
19518a documentation system that uses a single source file to produce both
19519on-line information and a printed manual. You can use one of the Info
19520formatting commands to create the on-line version of the documentation
19521and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 19522
8e04817f
AC
19523@value{GDBN} includes an already formatted copy of the on-line Info
19524version of this manual in the @file{gdb} subdirectory. The main Info
19525file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
19526subordinate files matching @samp{gdb.info*} in the same directory. If
19527necessary, you can print out these files, or read them with any editor;
19528but they are easier to read using the @code{info} subsystem in @sc{gnu}
19529Emacs or the standalone @code{info} program, available as part of the
19530@sc{gnu} Texinfo distribution.
c4555f82 19531
8e04817f
AC
19532If you want to format these Info files yourself, you need one of the
19533Info formatting programs, such as @code{texinfo-format-buffer} or
19534@code{makeinfo}.
c4555f82 19535
8e04817f
AC
19536If you have @code{makeinfo} installed, and are in the top level
19537@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
19538version @value{GDBVN}), you can make the Info file by typing:
c4555f82 19539
474c8240 19540@smallexample
8e04817f
AC
19541cd gdb
19542make gdb.info
474c8240 19543@end smallexample
c4555f82 19544
8e04817f
AC
19545If you want to typeset and print copies of this manual, you need @TeX{},
19546a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
19547Texinfo definitions file.
c4555f82 19548
8e04817f
AC
19549@TeX{} is a typesetting program; it does not print files directly, but
19550produces output files called @sc{dvi} files. To print a typeset
19551document, you need a program to print @sc{dvi} files. If your system
19552has @TeX{} installed, chances are it has such a program. The precise
19553command to use depends on your system; @kbd{lpr -d} is common; another
19554(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
19555require a file name without any extension or a @samp{.dvi} extension.
c4555f82 19556
8e04817f
AC
19557@TeX{} also requires a macro definitions file called
19558@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
19559written in Texinfo format. On its own, @TeX{} cannot either read or
19560typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
19561and is located in the @file{gdb-@var{version-number}/texinfo}
19562directory.
c4555f82 19563
8e04817f
AC
19564If you have @TeX{} and a @sc{dvi} printer program installed, you can
19565typeset and print this manual. First switch to the the @file{gdb}
19566subdirectory of the main source directory (for example, to
19567@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 19568
474c8240 19569@smallexample
8e04817f 19570make gdb.dvi
474c8240 19571@end smallexample
c4555f82 19572
8e04817f 19573Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 19574
8e04817f
AC
19575@node Installing GDB
19576@appendix Installing @value{GDBN}
19577@cindex configuring @value{GDBN}
19578@cindex installation
94e91d6d 19579@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 19580
8e04817f
AC
19581@value{GDBN} comes with a @code{configure} script that automates the process
19582of preparing @value{GDBN} for installation; you can then use @code{make} to
19583build the @code{gdb} program.
19584@iftex
19585@c irrelevant in info file; it's as current as the code it lives with.
19586@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
19587look at the @file{README} file in the sources; we may have improved the
19588installation procedures since publishing this manual.}
19589@end iftex
c4555f82 19590
8e04817f
AC
19591The @value{GDBN} distribution includes all the source code you need for
19592@value{GDBN} in a single directory, whose name is usually composed by
19593appending the version number to @samp{gdb}.
c4555f82 19594
8e04817f
AC
19595For example, the @value{GDBN} version @value{GDBVN} distribution is in the
19596@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 19597
8e04817f
AC
19598@table @code
19599@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
19600script for configuring @value{GDBN} and all its supporting libraries
c4555f82 19601
8e04817f
AC
19602@item gdb-@value{GDBVN}/gdb
19603the source specific to @value{GDBN} itself
c4555f82 19604
8e04817f
AC
19605@item gdb-@value{GDBVN}/bfd
19606source for the Binary File Descriptor library
c906108c 19607
8e04817f
AC
19608@item gdb-@value{GDBVN}/include
19609@sc{gnu} include files
c906108c 19610
8e04817f
AC
19611@item gdb-@value{GDBVN}/libiberty
19612source for the @samp{-liberty} free software library
c906108c 19613
8e04817f
AC
19614@item gdb-@value{GDBVN}/opcodes
19615source for the library of opcode tables and disassemblers
c906108c 19616
8e04817f
AC
19617@item gdb-@value{GDBVN}/readline
19618source for the @sc{gnu} command-line interface
c906108c 19619
8e04817f
AC
19620@item gdb-@value{GDBVN}/glob
19621source for the @sc{gnu} filename pattern-matching subroutine
c906108c 19622
8e04817f
AC
19623@item gdb-@value{GDBVN}/mmalloc
19624source for the @sc{gnu} memory-mapped malloc package
19625@end table
c906108c 19626
8e04817f
AC
19627The simplest way to configure and build @value{GDBN} is to run @code{configure}
19628from the @file{gdb-@var{version-number}} source directory, which in
19629this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 19630
8e04817f
AC
19631First switch to the @file{gdb-@var{version-number}} source directory
19632if you are not already in it; then run @code{configure}. Pass the
19633identifier for the platform on which @value{GDBN} will run as an
19634argument.
c906108c 19635
8e04817f 19636For example:
c906108c 19637
474c8240 19638@smallexample
8e04817f
AC
19639cd gdb-@value{GDBVN}
19640./configure @var{host}
19641make
474c8240 19642@end smallexample
c906108c 19643
8e04817f
AC
19644@noindent
19645where @var{host} is an identifier such as @samp{sun4} or
19646@samp{decstation}, that identifies the platform where @value{GDBN} will run.
19647(You can often leave off @var{host}; @code{configure} tries to guess the
19648correct value by examining your system.)
c906108c 19649
8e04817f
AC
19650Running @samp{configure @var{host}} and then running @code{make} builds the
19651@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
19652libraries, then @code{gdb} itself. The configured source files, and the
19653binaries, are left in the corresponding source directories.
c906108c 19654
8e04817f
AC
19655@need 750
19656@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
19657system does not recognize this automatically when you run a different
19658shell, you may need to run @code{sh} on it explicitly:
c906108c 19659
474c8240 19660@smallexample
8e04817f 19661sh configure @var{host}
474c8240 19662@end smallexample
c906108c 19663
8e04817f
AC
19664If you run @code{configure} from a directory that contains source
19665directories for multiple libraries or programs, such as the
19666@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
19667creates configuration files for every directory level underneath (unless
19668you tell it not to, with the @samp{--norecursion} option).
19669
94e91d6d
MC
19670You should run the @code{configure} script from the top directory in the
19671source tree, the @file{gdb-@var{version-number}} directory. If you run
19672@code{configure} from one of the subdirectories, you will configure only
19673that subdirectory. That is usually not what you want. In particular,
19674if you run the first @code{configure} from the @file{gdb} subdirectory
19675of the @file{gdb-@var{version-number}} directory, you will omit the
19676configuration of @file{bfd}, @file{readline}, and other sibling
19677directories of the @file{gdb} subdirectory. This leads to build errors
19678about missing include files such as @file{bfd/bfd.h}.
c906108c 19679
8e04817f
AC
19680You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
19681However, you should make sure that the shell on your path (named by
19682the @samp{SHELL} environment variable) is publicly readable. Remember
19683that @value{GDBN} uses the shell to start your program---some systems refuse to
19684let @value{GDBN} debug child processes whose programs are not readable.
c906108c 19685
8e04817f
AC
19686@menu
19687* Separate Objdir:: Compiling @value{GDBN} in another directory
19688* Config Names:: Specifying names for hosts and targets
19689* Configure Options:: Summary of options for configure
19690@end menu
c906108c 19691
8e04817f
AC
19692@node Separate Objdir
19693@section Compiling @value{GDBN} in another directory
c906108c 19694
8e04817f
AC
19695If you want to run @value{GDBN} versions for several host or target machines,
19696you need a different @code{gdb} compiled for each combination of
19697host and target. @code{configure} is designed to make this easy by
19698allowing you to generate each configuration in a separate subdirectory,
19699rather than in the source directory. If your @code{make} program
19700handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19701@code{make} in each of these directories builds the @code{gdb}
19702program specified there.
c906108c 19703
8e04817f
AC
19704To build @code{gdb} in a separate directory, run @code{configure}
19705with the @samp{--srcdir} option to specify where to find the source.
19706(You also need to specify a path to find @code{configure}
19707itself from your working directory. If the path to @code{configure}
19708would be the same as the argument to @samp{--srcdir}, you can leave out
19709the @samp{--srcdir} option; it is assumed.)
c906108c 19710
8e04817f
AC
19711For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19712separate directory for a Sun 4 like this:
c906108c 19713
474c8240 19714@smallexample
8e04817f
AC
19715@group
19716cd gdb-@value{GDBVN}
19717mkdir ../gdb-sun4
19718cd ../gdb-sun4
19719../gdb-@value{GDBVN}/configure sun4
19720make
19721@end group
474c8240 19722@end smallexample
c906108c 19723
8e04817f
AC
19724When @code{configure} builds a configuration using a remote source
19725directory, it creates a tree for the binaries with the same structure
19726(and using the same names) as the tree under the source directory. In
19727the example, you'd find the Sun 4 library @file{libiberty.a} in the
19728directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19729@file{gdb-sun4/gdb}.
c906108c 19730
94e91d6d
MC
19731Make sure that your path to the @file{configure} script has just one
19732instance of @file{gdb} in it. If your path to @file{configure} looks
19733like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19734one subdirectory of @value{GDBN}, not the whole package. This leads to
19735build errors about missing include files such as @file{bfd/bfd.h}.
19736
8e04817f
AC
19737One popular reason to build several @value{GDBN} configurations in separate
19738directories is to configure @value{GDBN} for cross-compiling (where
19739@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19740programs that run on another machine---the @dfn{target}).
19741You specify a cross-debugging target by
19742giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19743
8e04817f
AC
19744When you run @code{make} to build a program or library, you must run
19745it in a configured directory---whatever directory you were in when you
19746called @code{configure} (or one of its subdirectories).
c906108c 19747
8e04817f
AC
19748The @code{Makefile} that @code{configure} generates in each source
19749directory also runs recursively. If you type @code{make} in a source
19750directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19751directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19752will build all the required libraries, and then build GDB.
c906108c 19753
8e04817f
AC
19754When you have multiple hosts or targets configured in separate
19755directories, you can run @code{make} on them in parallel (for example,
19756if they are NFS-mounted on each of the hosts); they will not interfere
19757with each other.
c906108c 19758
8e04817f
AC
19759@node Config Names
19760@section Specifying names for hosts and targets
c906108c 19761
8e04817f
AC
19762The specifications used for hosts and targets in the @code{configure}
19763script are based on a three-part naming scheme, but some short predefined
19764aliases are also supported. The full naming scheme encodes three pieces
19765of information in the following pattern:
c906108c 19766
474c8240 19767@smallexample
8e04817f 19768@var{architecture}-@var{vendor}-@var{os}
474c8240 19769@end smallexample
c906108c 19770
8e04817f
AC
19771For example, you can use the alias @code{sun4} as a @var{host} argument,
19772or as the value for @var{target} in a @code{--target=@var{target}}
19773option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19774
8e04817f
AC
19775The @code{configure} script accompanying @value{GDBN} does not provide
19776any query facility to list all supported host and target names or
19777aliases. @code{configure} calls the Bourne shell script
19778@code{config.sub} to map abbreviations to full names; you can read the
19779script, if you wish, or you can use it to test your guesses on
19780abbreviations---for example:
c906108c 19781
8e04817f
AC
19782@smallexample
19783% sh config.sub i386-linux
19784i386-pc-linux-gnu
19785% sh config.sub alpha-linux
19786alpha-unknown-linux-gnu
19787% sh config.sub hp9k700
19788hppa1.1-hp-hpux
19789% sh config.sub sun4
19790sparc-sun-sunos4.1.1
19791% sh config.sub sun3
19792m68k-sun-sunos4.1.1
19793% sh config.sub i986v
19794Invalid configuration `i986v': machine `i986v' not recognized
19795@end smallexample
c906108c 19796
8e04817f
AC
19797@noindent
19798@code{config.sub} is also distributed in the @value{GDBN} source
19799directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19800
8e04817f
AC
19801@node Configure Options
19802@section @code{configure} options
c906108c 19803
8e04817f
AC
19804Here is a summary of the @code{configure} options and arguments that
19805are most often useful for building @value{GDBN}. @code{configure} also has
19806several other options not listed here. @inforef{What Configure
19807Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19808
474c8240 19809@smallexample
8e04817f
AC
19810configure @r{[}--help@r{]}
19811 @r{[}--prefix=@var{dir}@r{]}
19812 @r{[}--exec-prefix=@var{dir}@r{]}
19813 @r{[}--srcdir=@var{dirname}@r{]}
19814 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19815 @r{[}--target=@var{target}@r{]}
19816 @var{host}
474c8240 19817@end smallexample
c906108c 19818
8e04817f
AC
19819@noindent
19820You may introduce options with a single @samp{-} rather than
19821@samp{--} if you prefer; but you may abbreviate option names if you use
19822@samp{--}.
c906108c 19823
8e04817f
AC
19824@table @code
19825@item --help
19826Display a quick summary of how to invoke @code{configure}.
c906108c 19827
8e04817f
AC
19828@item --prefix=@var{dir}
19829Configure the source to install programs and files under directory
19830@file{@var{dir}}.
c906108c 19831
8e04817f
AC
19832@item --exec-prefix=@var{dir}
19833Configure the source to install programs under directory
19834@file{@var{dir}}.
c906108c 19835
8e04817f
AC
19836@c avoid splitting the warning from the explanation:
19837@need 2000
19838@item --srcdir=@var{dirname}
19839@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19840@code{make} that implements the @code{VPATH} feature.}@*
19841Use this option to make configurations in directories separate from the
19842@value{GDBN} source directories. Among other things, you can use this to
19843build (or maintain) several configurations simultaneously, in separate
19844directories. @code{configure} writes configuration specific files in
19845the current directory, but arranges for them to use the source in the
19846directory @var{dirname}. @code{configure} creates directories under
19847the working directory in parallel to the source directories below
19848@var{dirname}.
c906108c 19849
8e04817f
AC
19850@item --norecursion
19851Configure only the directory level where @code{configure} is executed; do not
19852propagate configuration to subdirectories.
c906108c 19853
8e04817f
AC
19854@item --target=@var{target}
19855Configure @value{GDBN} for cross-debugging programs running on the specified
19856@var{target}. Without this option, @value{GDBN} is configured to debug
19857programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19858
8e04817f 19859There is no convenient way to generate a list of all available targets.
c906108c 19860
8e04817f
AC
19861@item @var{host} @dots{}
19862Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19863
8e04817f
AC
19864There is no convenient way to generate a list of all available hosts.
19865@end table
c906108c 19866
8e04817f
AC
19867There are many other options available as well, but they are generally
19868needed for special purposes only.
c906108c 19869
8e04817f
AC
19870@node Maintenance Commands
19871@appendix Maintenance Commands
19872@cindex maintenance commands
19873@cindex internal commands
c906108c 19874
8e04817f
AC
19875In addition to commands intended for @value{GDBN} users, @value{GDBN}
19876includes a number of commands intended for @value{GDBN} developers.
19877These commands are provided here for reference.
c906108c 19878
8e04817f
AC
19879@table @code
19880@kindex maint info breakpoints
19881@item @anchor{maint info breakpoints}maint info breakpoints
19882Using the same format as @samp{info breakpoints}, display both the
19883breakpoints you've set explicitly, and those @value{GDBN} is using for
19884internal purposes. Internal breakpoints are shown with negative
19885breakpoint numbers. The type column identifies what kind of breakpoint
19886is shown:
c906108c 19887
8e04817f
AC
19888@table @code
19889@item breakpoint
19890Normal, explicitly set breakpoint.
c906108c 19891
8e04817f
AC
19892@item watchpoint
19893Normal, explicitly set watchpoint.
c906108c 19894
8e04817f
AC
19895@item longjmp
19896Internal breakpoint, used to handle correctly stepping through
19897@code{longjmp} calls.
c906108c 19898
8e04817f
AC
19899@item longjmp resume
19900Internal breakpoint at the target of a @code{longjmp}.
c906108c 19901
8e04817f
AC
19902@item until
19903Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19904
8e04817f
AC
19905@item finish
19906Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19907
8e04817f
AC
19908@item shlib events
19909Shared library events.
c906108c 19910
8e04817f 19911@end table
c906108c 19912
8d30a00d
AC
19913@kindex maint internal-error
19914@kindex maint internal-warning
19915@item maint internal-error
19916@itemx maint internal-warning
19917Cause @value{GDBN} to call the internal function @code{internal_error}
19918or @code{internal_warning} and hence behave as though an internal error
19919or internal warning has been detected. In addition to reporting the
19920internal problem, these functions give the user the opportunity to
19921either quit @value{GDBN} or create a core file of the current
19922@value{GDBN} session.
19923
19924@smallexample
f7dc1244 19925(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
19926@dots{}/maint.c:121: internal-error: testing, 1, 2
19927A problem internal to GDB has been detected. Further
19928debugging may prove unreliable.
19929Quit this debugging session? (y or n) @kbd{n}
19930Create a core file? (y or n) @kbd{n}
f7dc1244 19931(@value{GDBP})
8d30a00d
AC
19932@end smallexample
19933
19934Takes an optional parameter that is used as the text of the error or
19935warning message.
19936
00905d52
AC
19937@kindex maint print dummy-frames
19938@item maint print dummy-frames
19939
19940Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19941
19942@smallexample
f7dc1244 19943(@value{GDBP}) @kbd{b add}
00905d52 19944@dots{}
f7dc1244 19945(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
19946Breakpoint 2, add (a=2, b=3) at @dots{}
1994758 return (a + b);
19948The program being debugged stopped while in a function called from GDB.
19949@dots{}
f7dc1244 19950(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
199510x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19952 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19953 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 19954(@value{GDBP})
00905d52
AC
19955@end smallexample
19956
19957Takes an optional file parameter.
19958
0680b120
AC
19959@kindex maint print registers
19960@kindex maint print raw-registers
19961@kindex maint print cooked-registers
617073a9 19962@kindex maint print register-groups
0680b120
AC
19963@item maint print registers
19964@itemx maint print raw-registers
19965@itemx maint print cooked-registers
617073a9 19966@itemx maint print register-groups
0680b120
AC
19967Print @value{GDBN}'s internal register data structures.
19968
617073a9
AC
19969The command @code{maint print raw-registers} includes the contents of
19970the raw register cache; the command @code{maint print cooked-registers}
19971includes the (cooked) value of all registers; and the command
19972@code{maint print register-groups} includes the groups that each
19973register is a member of. @xref{Registers,, Registers, gdbint,
19974@value{GDBN} Internals}.
0680b120
AC
19975
19976Takes an optional file parameter.
19977
617073a9
AC
19978@kindex maint print reggroups
19979@item maint print reggroups
19980Print @value{GDBN}'s internal register group data structures.
19981
19982Takes an optional file parameter.
19983
19984@smallexample
f7dc1244 19985(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
19986 Group Type
19987 general user
19988 float user
19989 all user
19990 vector user
19991 system user
19992 save internal
19993 restore internal
617073a9
AC
19994@end smallexample
19995
e7ba9c65
DJ
19996@kindex maint set profile
19997@kindex maint show profile
19998@cindex profiling GDB
19999@item maint set profile
20000@itemx maint show profile
20001Control profiling of @value{GDBN}.
20002
20003Profiling will be disabled until you use the @samp{maint set profile}
20004command to enable it. When you enable profiling, the system will begin
20005collecting timing and execution count data; when you disable profiling or
20006exit @value{GDBN}, the results will be written to a log file. Remember that
20007if you use profiling, @value{GDBN} will overwrite the profiling log file
20008(often called @file{gmon.out}). If you have a record of important profiling
20009data in a @file{gmon.out} file, be sure to move it to a safe location.
20010
20011Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 20012compiled with the @samp{-pg} compiler option.
e7ba9c65 20013
ae038cb0
DJ
20014@kindex maint set dwarf2 max-cache-age
20015@kindex maint show dwarf2 max-cache-age
20016@item maint set dwarf2 max-cache-age
20017@itemx maint show dwarf2 max-cache-age
20018Control the DWARF 2 compilation unit cache.
20019
20020In object files with inter-compilation-unit references, such as those
20021produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
20022reader needs to frequently refer to previously read compilation units.
20023This setting controls how long a compilation unit will remain in the cache
20024if it is not referenced. Setting it to zero disables caching, which will
20025slow down @value{GDBN} startup but reduce memory consumption.
20026
8e04817f 20027@end table
c906108c 20028
c906108c 20029
e0ce93ac 20030@node Remote Protocol
8e04817f 20031@appendix @value{GDBN} Remote Serial Protocol
c906108c 20032
ee2d5c50
AC
20033@menu
20034* Overview::
20035* Packets::
20036* Stop Reply Packets::
20037* General Query Packets::
20038* Register Packet Format::
20039* Examples::
0ce1b118 20040* File-I/O remote protocol extension::
ee2d5c50
AC
20041@end menu
20042
20043@node Overview
20044@section Overview
20045
8e04817f
AC
20046There may be occasions when you need to know something about the
20047protocol---for example, if there is only one serial port to your target
20048machine, you might want your program to do something special if it
20049recognizes a packet meant for @value{GDBN}.
c906108c 20050
d2c6833e 20051In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 20052transmitted and received data respectfully.
c906108c 20053
8e04817f
AC
20054@cindex protocol, @value{GDBN} remote serial
20055@cindex serial protocol, @value{GDBN} remote
20056@cindex remote serial protocol
20057All @value{GDBN} commands and responses (other than acknowledgments) are
20058sent as a @var{packet}. A @var{packet} is introduced with the character
20059@samp{$}, the actual @var{packet-data}, and the terminating character
20060@samp{#} followed by a two-digit @var{checksum}:
c906108c 20061
474c8240 20062@smallexample
8e04817f 20063@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 20064@end smallexample
8e04817f 20065@noindent
c906108c 20066
8e04817f
AC
20067@cindex checksum, for @value{GDBN} remote
20068@noindent
20069The two-digit @var{checksum} is computed as the modulo 256 sum of all
20070characters between the leading @samp{$} and the trailing @samp{#} (an
20071eight bit unsigned checksum).
c906108c 20072
8e04817f
AC
20073Implementors should note that prior to @value{GDBN} 5.0 the protocol
20074specification also included an optional two-digit @var{sequence-id}:
c906108c 20075
474c8240 20076@smallexample
8e04817f 20077@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 20078@end smallexample
c906108c 20079
8e04817f
AC
20080@cindex sequence-id, for @value{GDBN} remote
20081@noindent
20082That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
20083has never output @var{sequence-id}s. Stubs that handle packets added
20084since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 20085
8e04817f
AC
20086@cindex acknowledgment, for @value{GDBN} remote
20087When either the host or the target machine receives a packet, the first
20088response expected is an acknowledgment: either @samp{+} (to indicate
20089the package was received correctly) or @samp{-} (to request
20090retransmission):
c906108c 20091
474c8240 20092@smallexample
d2c6833e
AC
20093-> @code{$}@var{packet-data}@code{#}@var{checksum}
20094<- @code{+}
474c8240 20095@end smallexample
8e04817f 20096@noindent
53a5351d 20097
8e04817f
AC
20098The host (@value{GDBN}) sends @var{command}s, and the target (the
20099debugging stub incorporated in your program) sends a @var{response}. In
20100the case of step and continue @var{command}s, the response is only sent
20101when the operation has completed (the target has again stopped).
c906108c 20102
8e04817f
AC
20103@var{packet-data} consists of a sequence of characters with the
20104exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
20105exceptions).
c906108c 20106
8e04817f 20107Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 20108@cindex remote protocol, field separator
8e04817f 20109@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 20110@sc{hex} with leading zeros suppressed.
c906108c 20111
8e04817f
AC
20112Implementors should note that prior to @value{GDBN} 5.0, the character
20113@samp{:} could not appear as the third character in a packet (as it
20114would potentially conflict with the @var{sequence-id}).
c906108c 20115
8e04817f
AC
20116Response @var{data} can be run-length encoded to save space. A @samp{*}
20117means that the next character is an @sc{ascii} encoding giving a repeat count
20118which stands for that many repetitions of the character preceding the
20119@samp{*}. The encoding is @code{n+29}, yielding a printable character
20120where @code{n >=3} (which is where rle starts to win). The printable
20121characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
20122value greater than 126 should not be used.
c906108c 20123
8e04817f 20124So:
474c8240 20125@smallexample
8e04817f 20126"@code{0* }"
474c8240 20127@end smallexample
8e04817f
AC
20128@noindent
20129means the same as "0000".
c906108c 20130
8e04817f
AC
20131The error response returned for some packets includes a two character
20132error number. That number is not well defined.
c906108c 20133
8e04817f
AC
20134For any @var{command} not supported by the stub, an empty response
20135(@samp{$#00}) should be returned. That way it is possible to extend the
20136protocol. A newer @value{GDBN} can tell if a packet is supported based
20137on that response.
c906108c 20138
b383017d
RM
20139A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
20140@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 20141optional.
c906108c 20142
ee2d5c50
AC
20143@node Packets
20144@section Packets
20145
20146The following table provides a complete list of all currently defined
20147@var{command}s and their corresponding response @var{data}.
20148
20149@table @r
20150
20151@item @code{!} --- extended mode
20152@cindex @code{!} packet
20153
8e04817f
AC
20154Enable extended mode. In extended mode, the remote server is made
20155persistent. The @samp{R} packet is used to restart the program being
20156debugged.
ee2d5c50
AC
20157
20158Reply:
20159@table @samp
20160@item OK
8e04817f 20161The remote target both supports and has enabled extended mode.
ee2d5c50 20162@end table
c906108c 20163
ee2d5c50
AC
20164@item @code{?} --- last signal
20165@cindex @code{?} packet
c906108c 20166
ee2d5c50
AC
20167Indicate the reason the target halted. The reply is the same as for
20168step and continue.
c906108c 20169
ee2d5c50
AC
20170Reply:
20171@xref{Stop Reply Packets}, for the reply specifications.
20172
20173@item @code{a} --- reserved
20174
20175Reserved for future use.
20176
20177@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
20178@cindex @code{A} packet
c906108c 20179
8e04817f
AC
20180Initialized @samp{argv[]} array passed into program. @var{arglen}
20181specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
20182See @code{gdbserver} for more details.
20183
20184Reply:
20185@table @samp
20186@item OK
20187@item E@var{NN}
20188@end table
20189
20190@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
20191@cindex @code{b} packet
20192
20193Change the serial line speed to @var{baud}.
20194
20195JTC: @emph{When does the transport layer state change? When it's
20196received, or after the ACK is transmitted. In either case, there are
20197problems if the command or the acknowledgment packet is dropped.}
20198
20199Stan: @emph{If people really wanted to add something like this, and get
20200it working for the first time, they ought to modify ser-unix.c to send
20201some kind of out-of-band message to a specially-setup stub and have the
20202switch happen "in between" packets, so that from remote protocol's point
20203of view, nothing actually happened.}
20204
20205@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
20206@cindex @code{B} packet
20207
8e04817f 20208Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
20209breakpoint at @var{addr}.
20210
20211This packet has been replaced by the @samp{Z} and @samp{z} packets
20212(@pxref{insert breakpoint or watchpoint packet}).
c906108c 20213
ee2d5c50
AC
20214@item @code{c}@var{addr} --- continue
20215@cindex @code{c} packet
20216
20217@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 20218current address.
c906108c 20219
ee2d5c50
AC
20220Reply:
20221@xref{Stop Reply Packets}, for the reply specifications.
20222
20223@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
20224@cindex @code{C} packet
20225
8e04817f
AC
20226Continue with signal @var{sig} (hex signal number). If
20227@code{;}@var{addr} is omitted, resume at same address.
c906108c 20228
ee2d5c50
AC
20229Reply:
20230@xref{Stop Reply Packets}, for the reply specifications.
c906108c 20231
ee2d5c50
AC
20232@item @code{d} --- toggle debug @strong{(deprecated)}
20233@cindex @code{d} packet
20234
20235Toggle debug flag.
20236
20237@item @code{D} --- detach
20238@cindex @code{D} packet
20239
20240Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 20241before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
20242
20243Reply:
20244@table @samp
20245@item @emph{no response}
8e04817f 20246@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 20247@end table
c906108c 20248
ee2d5c50 20249@item @code{e} --- reserved
c906108c 20250
ee2d5c50 20251Reserved for future use.
c906108c 20252
ee2d5c50 20253@item @code{E} --- reserved
c906108c 20254
ee2d5c50 20255Reserved for future use.
c906108c 20256
ee2d5c50
AC
20257@item @code{f} --- reserved
20258
20259Reserved for future use.
20260
0ce1b118
CV
20261@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
20262@cindex @code{F} packet
ee2d5c50 20263
0ce1b118
CV
20264This packet is send by @value{GDBN} as reply to a @code{F} request packet
20265sent by the target. This is part of the File-I/O protocol extension.
20266@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
20267
20268@item @code{g} --- read registers
20269@anchor{read registers packet}
20270@cindex @code{g} packet
20271
20272Read general registers.
20273
20274Reply:
20275@table @samp
20276@item @var{XX@dots{}}
8e04817f
AC
20277Each byte of register data is described by two hex digits. The bytes
20278with the register are transmitted in target byte order. The size of
20279each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
20280determined by the @value{GDBN} internal macros
20281@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
20282specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
20283@item E@var{NN}
20284for an error.
20285@end table
c906108c 20286
ee2d5c50
AC
20287@item @code{G}@var{XX@dots{}} --- write regs
20288@cindex @code{G} packet
c906108c 20289
ee2d5c50
AC
20290@xref{read registers packet}, for a description of the @var{XX@dots{}}
20291data.
20292
20293Reply:
20294@table @samp
20295@item OK
20296for success
20297@item E@var{NN}
20298for an error
20299@end table
20300
20301@item @code{h} --- reserved
20302
20303Reserved for future use.
20304
b383017d 20305@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 20306@cindex @code{H} packet
c906108c 20307
8e04817f 20308Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
20309@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
20310should be @samp{c} for step and continue operations, @samp{g} for other
20311operations. The thread designator @var{t@dots{}} may be -1, meaning all
20312the threads, a thread number, or zero which means pick any thread.
20313
20314Reply:
20315@table @samp
20316@item OK
20317for success
20318@item E@var{NN}
20319for an error
20320@end table
c906108c 20321
8e04817f
AC
20322@c FIXME: JTC:
20323@c 'H': How restrictive (or permissive) is the thread model. If a
20324@c thread is selected and stopped, are other threads allowed
20325@c to continue to execute? As I mentioned above, I think the
20326@c semantics of each command when a thread is selected must be
20327@c described. For example:
20328@c
20329@c 'g': If the stub supports threads and a specific thread is
20330@c selected, returns the register block from that thread;
20331@c otherwise returns current registers.
20332@c
20333@c 'G' If the stub supports threads and a specific thread is
20334@c selected, sets the registers of the register block of
20335@c that thread; otherwise sets current registers.
c906108c 20336
ee2d5c50
AC
20337@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
20338@anchor{cycle step packet}
20339@cindex @code{i} packet
20340
8e04817f
AC
20341Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
20342present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
20343step starting at that address.
c906108c 20344
ee2d5c50
AC
20345@item @code{I} --- signal then cycle step @strong{(reserved)}
20346@cindex @code{I} packet
20347
20348@xref{step with signal packet}. @xref{cycle step packet}.
20349
20350@item @code{j} --- reserved
20351
20352Reserved for future use.
20353
20354@item @code{J} --- reserved
c906108c 20355
ee2d5c50 20356Reserved for future use.
c906108c 20357
ee2d5c50
AC
20358@item @code{k} --- kill request
20359@cindex @code{k} packet
c906108c 20360
ac282366 20361FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
20362thread context has been selected (i.e.@: does 'k' kill only that
20363thread?)}.
c906108c 20364
ee2d5c50 20365@item @code{K} --- reserved
c906108c 20366
ee2d5c50
AC
20367Reserved for future use.
20368
20369@item @code{l} --- reserved
20370
20371Reserved for future use.
20372
20373@item @code{L} --- reserved
20374
20375Reserved for future use.
20376
20377@item @code{m}@var{addr}@code{,}@var{length} --- read memory
20378@cindex @code{m} packet
c906108c 20379
8e04817f 20380Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 20381Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 20382assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 20383transfer mechanism is needed.}
c906108c 20384
ee2d5c50
AC
20385Reply:
20386@table @samp
20387@item @var{XX@dots{}}
20388@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
20389to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 20390that sized memory transfers are assumed using word aligned
ee2d5c50
AC
20391accesses. FIXME: @emph{A word aligned memory transfer mechanism is
20392needed.}
20393@item E@var{NN}
20394@var{NN} is errno
20395@end table
20396
20397@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
20398@cindex @code{M} packet
20399
8e04817f 20400Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
20401@var{XX@dots{}} is the data.
20402
20403Reply:
20404@table @samp
20405@item OK
20406for success
20407@item E@var{NN}
8e04817f
AC
20408for an error (this includes the case where only part of the data was
20409written).
ee2d5c50 20410@end table
c906108c 20411
ee2d5c50 20412@item @code{n} --- reserved
c906108c 20413
ee2d5c50 20414Reserved for future use.
c906108c 20415
ee2d5c50 20416@item @code{N} --- reserved
c906108c 20417
ee2d5c50 20418Reserved for future use.
c906108c 20419
ee2d5c50
AC
20420@item @code{o} --- reserved
20421
20422Reserved for future use.
20423
20424@item @code{O} --- reserved
20425
2e868123 20426@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
20427@cindex @code{p} packet
20428
2e868123
AC
20429@xref{read registers packet}, for a description of how the returned
20430register value is encoded.
ee2d5c50
AC
20431
20432Reply:
20433@table @samp
2e868123
AC
20434@item @var{XX@dots{}}
20435the register's value
20436@item E@var{NN}
20437for an error
20438@item
20439Indicating an unrecognized @var{query}.
ee2d5c50
AC
20440@end table
20441
20442@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
20443@anchor{write register packet}
20444@cindex @code{P} packet
20445
20446Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 20447digits for each byte in the register (target byte order).
c906108c 20448
ee2d5c50
AC
20449Reply:
20450@table @samp
20451@item OK
20452for success
20453@item E@var{NN}
20454for an error
20455@end table
20456
20457@item @code{q}@var{query} --- general query
20458@anchor{general query packet}
20459@cindex @code{q} packet
20460
20461Request info about @var{query}. In general @value{GDBN} queries have a
20462leading upper case letter. Custom vendor queries should use a company
20463prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
20464be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
20465that they match the full @var{query} name.
20466
20467Reply:
20468@table @samp
20469@item @var{XX@dots{}}
20470Hex encoded data from query. The reply can not be empty.
20471@item E@var{NN}
20472error reply
8e04817f 20473@item
ee2d5c50
AC
20474Indicating an unrecognized @var{query}.
20475@end table
20476
20477@item @code{Q}@var{var}@code{=}@var{val} --- general set
20478@cindex @code{Q} packet
20479
20480Set value of @var{var} to @var{val}.
20481
20482@xref{general query packet}, for a discussion of naming conventions.
c906108c 20483
ee2d5c50
AC
20484@item @code{r} --- reset @strong{(deprecated)}
20485@cindex @code{r} packet
c906108c 20486
8e04817f 20487Reset the entire system.
c906108c 20488
ee2d5c50
AC
20489@item @code{R}@var{XX} --- remote restart
20490@cindex @code{R} packet
20491
8e04817f
AC
20492Restart the program being debugged. @var{XX}, while needed, is ignored.
20493This packet is only available in extended mode.
ee2d5c50
AC
20494
20495Reply:
20496@table @samp
20497@item @emph{no reply}
8e04817f 20498The @samp{R} packet has no reply.
ee2d5c50
AC
20499@end table
20500
20501@item @code{s}@var{addr} --- step
20502@cindex @code{s} packet
c906108c 20503
8e04817f
AC
20504@var{addr} is address to resume. If @var{addr} is omitted, resume at
20505same address.
c906108c 20506
ee2d5c50
AC
20507Reply:
20508@xref{Stop Reply Packets}, for the reply specifications.
20509
20510@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
20511@anchor{step with signal packet}
20512@cindex @code{S} packet
20513
8e04817f 20514Like @samp{C} but step not continue.
c906108c 20515
ee2d5c50
AC
20516Reply:
20517@xref{Stop Reply Packets}, for the reply specifications.
20518
b383017d 20519@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
20520@cindex @code{t} packet
20521
8e04817f 20522Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
20523@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
20524@var{addr} must be at least 3 digits.
c906108c 20525
ee2d5c50
AC
20526@item @code{T}@var{XX} --- thread alive
20527@cindex @code{T} packet
c906108c 20528
ee2d5c50 20529Find out if the thread XX is alive.
c906108c 20530
ee2d5c50
AC
20531Reply:
20532@table @samp
20533@item OK
20534thread is still alive
20535@item E@var{NN}
20536thread is dead
20537@end table
20538
20539@item @code{u} --- reserved
20540
20541Reserved for future use.
20542
20543@item @code{U} --- reserved
20544
20545Reserved for future use.
20546
86d30acc 20547@item @code{v} --- verbose packet prefix
ee2d5c50 20548
86d30acc
DJ
20549Packets starting with @code{v} are identified by a multi-letter name,
20550up to the first @code{;} or @code{?} (or the end of the packet).
20551
20552@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
20553@cindex @code{vCont} packet
20554
20555Resume the inferior. Different actions may be specified for each thread.
20556If an action is specified with no @var{tid}, then it is applied to any
20557threads that don't have a specific action specified; if no default action is
20558specified then other threads should remain stopped. Specifying multiple
20559default actions is an error; specifying no actions is also an error.
20560Thread IDs are specified in hexadecimal. Currently supported actions are:
20561
20562@table @code
20563@item c
20564Continue.
20565@item C@var{sig}
20566Continue with signal @var{sig}. @var{sig} should be two hex digits.
20567@item s
20568Step.
20569@item S@var{sig}
20570Step with signal @var{sig}. @var{sig} should be two hex digits.
20571@end table
20572
20573The optional @var{addr} argument normally associated with these packets is
20574not supported in @code{vCont}.
20575
20576Reply:
20577@xref{Stop Reply Packets}, for the reply specifications.
20578
20579@item @code{vCont?} --- extended resume query
20580@cindex @code{vCont?} packet
20581
20582Query support for the @code{vCont} packet.
20583
20584Reply:
20585@table @samp
20586@item @code{vCont}[;@var{action}]...
20587The @code{vCont} packet is supported. Each @var{action} is a supported
20588command in the @code{vCont} packet.
20589@item
20590The @code{vCont} packet is not supported.
20591@end table
ee2d5c50
AC
20592
20593@item @code{V} --- reserved
c906108c 20594
ee2d5c50 20595Reserved for future use.
c906108c 20596
ee2d5c50 20597@item @code{w} --- reserved
c906108c 20598
ee2d5c50 20599Reserved for future use.
c906108c 20600
ee2d5c50 20601@item @code{W} --- reserved
c906108c 20602
ee2d5c50 20603Reserved for future use.
c906108c 20604
ee2d5c50
AC
20605@item @code{x} --- reserved
20606
20607Reserved for future use.
20608
20609@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
20610@cindex @code{X} packet
20611
20612@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
20613is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
20614escaped using @code{0x7d}, and then XORed with @code{0x20}.
20615For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 20616
ee2d5c50
AC
20617Reply:
20618@table @samp
20619@item OK
20620for success
20621@item E@var{NN}
20622for an error
20623@end table
20624
20625@item @code{y} --- reserved
c906108c 20626
ee2d5c50 20627Reserved for future use.
c906108c 20628
ee2d5c50
AC
20629@item @code{Y} reserved
20630
20631Reserved for future use.
20632
2f870471
AC
20633@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
20634@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
20635@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 20636@cindex @code{z} packet
2f870471 20637@cindex @code{Z} packets
ee2d5c50 20638
2f870471
AC
20639Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
20640watchpoint starting at address @var{address} and covering the next
20641@var{length} bytes.
ee2d5c50 20642
2f870471
AC
20643Each breakpoint and watchpoint packet @var{type} is documented
20644separately.
20645
512217c7
AC
20646@emph{Implementation notes: A remote target shall return an empty string
20647for an unrecognized breakpoint or watchpoint packet @var{type}. A
20648remote target shall support either both or neither of a given
2f870471
AC
20649@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
20650avoid potential problems with duplicate packets, the operations should
20651be implemented in an idempotent way.}
20652
20653@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
20654@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
20655@cindex @code{z0} packet
20656@cindex @code{Z0} packet
20657
20658Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
20659@code{addr} of size @code{length}.
20660
20661A memory breakpoint is implemented by replacing the instruction at
20662@var{addr} with a software breakpoint or trap instruction. The
20663@code{length} is used by targets that indicates the size of the
20664breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20665@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 20666
2f870471
AC
20667@emph{Implementation note: It is possible for a target to copy or move
20668code that contains memory breakpoints (e.g., when implementing
20669overlays). The behavior of this packet, in the presence of such a
20670target, is not defined.}
c906108c 20671
ee2d5c50
AC
20672Reply:
20673@table @samp
2f870471
AC
20674@item OK
20675success
20676@item
20677not supported
ee2d5c50
AC
20678@item E@var{NN}
20679for an error
2f870471
AC
20680@end table
20681
20682@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20683@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20684@cindex @code{z1} packet
20685@cindex @code{Z1} packet
20686
20687Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20688address @code{addr} of size @code{length}.
20689
20690A hardware breakpoint is implemented using a mechanism that is not
20691dependant on being able to modify the target's memory.
20692
20693@emph{Implementation note: A hardware breakpoint is not affected by code
20694movement.}
20695
20696Reply:
20697@table @samp
ee2d5c50 20698@item OK
2f870471
AC
20699success
20700@item
20701not supported
20702@item E@var{NN}
20703for an error
20704@end table
20705
20706@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20707@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20708@cindex @code{z2} packet
20709@cindex @code{Z2} packet
20710
20711Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20712
20713Reply:
20714@table @samp
20715@item OK
20716success
20717@item
20718not supported
20719@item E@var{NN}
20720for an error
20721@end table
20722
20723@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20724@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20725@cindex @code{z3} packet
20726@cindex @code{Z3} packet
20727
2e834e49 20728Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20729
20730Reply:
20731@table @samp
20732@item OK
20733success
20734@item
20735not supported
20736@item E@var{NN}
20737for an error
20738@end table
20739
2e834e49
HPN
20740@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20741@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20742@cindex @code{z4} packet
20743@cindex @code{Z4} packet
20744
20745Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20746
20747Reply:
20748@table @samp
20749@item OK
20750success
20751@item
20752not supported
20753@item E@var{NN}
20754for an error
ee2d5c50
AC
20755@end table
20756
20757@end table
c906108c 20758
ee2d5c50
AC
20759@node Stop Reply Packets
20760@section Stop Reply Packets
20761@cindex stop reply packets
c906108c 20762
8e04817f
AC
20763The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20764receive any of the below as a reply. In the case of the @samp{C},
20765@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20766when the target halts. In the below the exact meaning of @samp{signal
20767number} is poorly defined. In general one of the UNIX signal numbering
20768conventions is used.
c906108c 20769
ee2d5c50 20770@table @samp
c906108c 20771
ee2d5c50
AC
20772@item S@var{AA}
20773@var{AA} is the signal number
c906108c 20774
8e04817f 20775@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
20776@cindex @code{T} packet reply
20777
8e04817f
AC
20778@var{AA} = two hex digit signal number; @var{n...} = register number
20779(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20780by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20781@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20782(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20783address, this is a hex integer; @var{n...} = other string not starting
20784with valid hex digit. @value{GDBN} should ignore this @var{n...},
20785@var{r...} pair and go on to the next. This way we can extend the
20786protocol.
c906108c 20787
ee2d5c50
AC
20788@item W@var{AA}
20789
8e04817f 20790The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20791applicable to certain targets.
20792
20793@item X@var{AA}
c906108c 20794
8e04817f 20795The process terminated with signal @var{AA}.
c906108c 20796
ee2d5c50 20797@item O@var{XX@dots{}}
c906108c 20798
ee2d5c50
AC
20799@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20800any time while the program is running and the debugger should continue
20801to wait for @samp{W}, @samp{T}, etc.
20802
0ce1b118
CV
20803@item F@var{call-id}@code{,}@var{parameter@dots{}}
20804
20805@var{call-id} is the identifier which says which host system call should
20806be called. This is just the name of the function. Translation into the
20807correct system call is only applicable as it's defined in @value{GDBN}.
20808@xref{File-I/O remote protocol extension}, for a list of implemented
20809system calls.
20810
20811@var{parameter@dots{}} is a list of parameters as defined for this very
20812system call.
20813
20814The target replies with this packet when it expects @value{GDBN} to call
20815a host system call on behalf of the target. @value{GDBN} replies with
20816an appropriate @code{F} packet and keeps up waiting for the next reply
20817packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20818@samp{s} action is expected to be continued.
20819@xref{File-I/O remote protocol extension}, for more details.
20820
ee2d5c50
AC
20821@end table
20822
20823@node General Query Packets
20824@section General Query Packets
c906108c 20825
8e04817f 20826The following set and query packets have already been defined.
c906108c 20827
ee2d5c50 20828@table @r
c906108c 20829
ee2d5c50
AC
20830@item @code{q}@code{C} --- current thread
20831
20832Return the current thread id.
20833
20834Reply:
20835@table @samp
20836@item @code{QC}@var{pid}
e1aac25b 20837Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
20838@item *
20839Any other reply implies the old pid.
20840@end table
20841
20842@item @code{q}@code{fThreadInfo} -- all thread ids
20843
20844@code{q}@code{sThreadInfo}
c906108c 20845
8e04817f
AC
20846Obtain a list of active thread ids from the target (OS). Since there
20847may be too many active threads to fit into one reply packet, this query
20848works iteratively: it may require more than one query/reply sequence to
20849obtain the entire list of threads. The first query of the sequence will
20850be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20851sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20852
20853NOTE: replaces the @code{qL} query (see below).
20854
20855Reply:
20856@table @samp
20857@item @code{m}@var{id}
20858A single thread id
20859@item @code{m}@var{id},@var{id}@dots{}
20860a comma-separated list of thread ids
20861@item @code{l}
20862(lower case 'el') denotes end of list.
20863@end table
20864
20865In response to each query, the target will reply with a list of one or
e1aac25b
JB
20866more thread ids, in big-endian unsigned hex, separated by commas.
20867@value{GDBN} will respond to each reply with a request for more thread
20868ids (using the @code{qs} form of the query), until the target responds
20869with @code{l} (lower-case el, for @code{'last'}).
c906108c 20870
ee2d5c50
AC
20871@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20872
20873Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20874string description of a thread's attributes from the target OS. This
20875string may contain anything that the target OS thinks is interesting for
20876@value{GDBN} to tell the user about the thread. The string is displayed
20877in @value{GDBN}'s @samp{info threads} display. Some examples of
20878possible thread extra info strings are ``Runnable'', or ``Blocked on
20879Mutex''.
20880
20881Reply:
20882@table @samp
20883@item @var{XX@dots{}}
20884Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20885the printable string containing the extra information about the thread's
8e04817f 20886attributes.
ee2d5c50
AC
20887@end table
20888
20889@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20890
8e04817f
AC
20891Obtain thread information from RTOS. Where: @var{startflag} (one hex
20892digit) is one to indicate the first query and zero to indicate a
20893subsequent query; @var{threadcount} (two hex digits) is the maximum
20894number of threads the response packet can contain; and @var{nextthread}
20895(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20896returned in the response as @var{argthread}.
ee2d5c50
AC
20897
20898NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20899(see above).
20900
20901Reply:
20902@table @samp
20903@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20904Where: @var{count} (two hex digits) is the number of threads being
20905returned; @var{done} (one hex digit) is zero to indicate more threads
20906and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20907digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20908is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20909digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20910@end table
c906108c 20911
ee2d5c50
AC
20912@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20913
20914Reply:
20915@table @samp
20916@item @code{E}@var{NN}
20917An error (such as memory fault)
20918@item @code{C}@var{CRC32}
20919A 32 bit cyclic redundancy check of the specified memory region.
20920@end table
20921
20922@item @code{q}@code{Offsets} --- query sect offs
c906108c 20923
8e04817f
AC
20924Get section offsets that the target used when re-locating the downloaded
20925image. @emph{Note: while a @code{Bss} offset is included in the
20926response, @value{GDBN} ignores this and instead applies the @code{Data}
20927offset to the @code{Bss} section.}
c906108c 20928
ee2d5c50
AC
20929Reply:
20930@table @samp
20931@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20932@end table
20933
20934@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20935
8e04817f
AC
20936Returns information on @var{threadid}. Where: @var{mode} is a hex
20937encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20938
20939Reply:
20940@table @samp
20941@item *
20942@end table
20943
8e04817f 20944See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20945
ee2d5c50
AC
20946@item @code{q}@code{Rcmd,}@var{command} --- remote command
20947
20948@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20949execution. Invalid commands should be reported using the output string.
20950Before the final result packet, the target may also respond with a
ee2d5c50
AC
20951number of intermediate @code{O}@var{output} console output packets.
20952@emph{Implementors should note that providing access to a stubs's
20953interpreter may have security implications}.
20954
20955Reply:
20956@table @samp
20957@item OK
8e04817f 20958A command response with no output.
ee2d5c50 20959@item @var{OUTPUT}
8e04817f 20960A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20961@item @code{E}@var{NN}
8e04817f 20962Indicate a badly formed request.
ee2d5c50 20963@item @samp{}
8e04817f 20964When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20965@end table
20966
20967@item @code{qSymbol::} --- symbol lookup
c906108c 20968
8e04817f
AC
20969Notify the target that @value{GDBN} is prepared to serve symbol lookup
20970requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20971
20972Reply:
20973@table @samp
20974@item @code{OK}
8e04817f 20975The target does not need to look up any (more) symbols.
ee2d5c50
AC
20976@item @code{qSymbol:}@var{sym_name}
20977The target requests the value of symbol @var{sym_name} (hex encoded).
20978@value{GDBN} may provide the value by using the
20979@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20980@end table
20981
20982@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20983
20984Set the value of @var{sym_name} to @var{sym_value}.
20985
20986@var{sym_name} (hex encoded) is the name of a symbol whose value the
20987target has previously requested.
20988
20989@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20990@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20991will be empty.
20992
20993Reply:
20994@table @samp
20995@item @code{OK}
8e04817f 20996The target does not need to look up any (more) symbols.
ee2d5c50
AC
20997@item @code{qSymbol:}@var{sym_name}
20998The target requests the value of a new symbol @var{sym_name} (hex
20999encoded). @value{GDBN} will continue to supply the values of symbols
21000(if available), until the target ceases to request them.
21001@end table
eb12ee30 21002
649e03f6
RM
21003@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
21004
21005Read uninterpreted bytes from the target's special data area
21006identified by the keyword @code{object}.
21007Request @var{length} bytes starting at @var{offset} bytes into the data.
21008The content and encoding of @var{annex} is specific to the object;
21009it can supply additional details about what data to access.
21010
21011Here are the specific requests of this form defined so far.
21012All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
21013requests use the same reply formats, listed below.
21014
21015@table @asis
21016@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
21017Access the target's @dfn{auxiliary vector}. @xref{Auxiliary Vector}.
21018Note @var{annex} must be empty.
21019@end table
21020
21021Reply:
21022@table @asis
21023@item @code{OK}
21024The @var{offset} in the request is at the end of the data.
21025There is no more data to be read.
21026
21027@item @var{XX@dots{}}
21028Hex encoded data bytes read.
21029This may be fewer bytes than the @var{length} in the request.
21030
21031@item @code{E00}
21032The request was malformed, or @var{annex} was invalid.
21033
21034@item @code{E}@var{nn}
21035The offset was invalid, or there was an error encountered reading the data.
21036@var{nn} is a hex-encoded @code{errno} value.
21037
21038@item @code{""} (empty)
21039An empty reply indicates the @var{object} or @var{annex} string was not
21040recognized by the stub.
21041@end table
21042
21043@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
21044
21045Write uninterpreted bytes into the target's special data area
21046identified by the keyword @code{object},
21047starting at @var{offset} bytes into the data.
21048@var{data@dots{}} is the hex-encoded data to be written.
21049The content and encoding of @var{annex} is specific to the object;
21050it can supply additional details about what data to access.
21051
21052No requests of this form are presently in use. This specification
21053serves as a placeholder to document the common format that new
21054specific request specifications ought to use.
21055
21056Reply:
21057@table @asis
21058@item @var{nn}
21059@var{nn} (hex encoded) is the number of bytes written.
21060This may be fewer bytes than supplied in the request.
21061
21062@item @code{E00}
21063The request was malformed, or @var{annex} was invalid.
21064
21065@item @code{E}@var{nn}
21066The offset was invalid, or there was an error encountered writing the data.
21067@var{nn} is a hex-encoded @code{errno} value.
21068
21069@item @code{""} (empty)
21070An empty reply indicates the @var{object} or @var{annex} string was not
21071recognized by the stub, or that the object does not support writing.
21072@end table
21073
21074@item @code{qPart}:@var{object}:@var{operation}:@dots{}
21075Requests of this form may be added in the future. When a stub does
21076not recognize the @var{object} keyword, or its support for
21077@var{object} does not recognize the @var{operation} keyword,
21078the stub must respond with an empty packet.
ee2d5c50
AC
21079@end table
21080
21081@node Register Packet Format
21082@section Register Packet Format
eb12ee30 21083
8e04817f 21084The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
21085In the below, some thirty-two bit registers are transferred as
21086sixty-four bits. Those registers should be zero/sign extended (which?)
21087to fill the space allocated. Register bytes are transfered in target
21088byte order. The two nibbles within a register byte are transfered
21089most-significant - least-significant.
eb12ee30 21090
ee2d5c50 21091@table @r
eb12ee30 21092
8e04817f 21093@item MIPS32
ee2d5c50 21094
8e04817f
AC
21095All registers are transfered as thirty-two bit quantities in the order:
2109632 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
21097registers; fsr; fir; fp.
eb12ee30 21098
8e04817f 21099@item MIPS64
ee2d5c50 21100
8e04817f
AC
21101All registers are transfered as sixty-four bit quantities (including
21102thirty-two bit registers such as @code{sr}). The ordering is the same
21103as @code{MIPS32}.
eb12ee30 21104
ee2d5c50
AC
21105@end table
21106
21107@node Examples
21108@section Examples
eb12ee30 21109
8e04817f
AC
21110Example sequence of a target being re-started. Notice how the restart
21111does not get any direct output:
eb12ee30 21112
474c8240 21113@smallexample
d2c6833e
AC
21114-> @code{R00}
21115<- @code{+}
8e04817f 21116@emph{target restarts}
d2c6833e 21117-> @code{?}
8e04817f 21118<- @code{+}
d2c6833e
AC
21119<- @code{T001:1234123412341234}
21120-> @code{+}
474c8240 21121@end smallexample
eb12ee30 21122
8e04817f 21123Example sequence of a target being stepped by a single instruction:
eb12ee30 21124
474c8240 21125@smallexample
d2c6833e 21126-> @code{G1445@dots{}}
8e04817f 21127<- @code{+}
d2c6833e
AC
21128-> @code{s}
21129<- @code{+}
21130@emph{time passes}
21131<- @code{T001:1234123412341234}
8e04817f 21132-> @code{+}
d2c6833e 21133-> @code{g}
8e04817f 21134<- @code{+}
d2c6833e
AC
21135<- @code{1455@dots{}}
21136-> @code{+}
474c8240 21137@end smallexample
eb12ee30 21138
0ce1b118
CV
21139@node File-I/O remote protocol extension
21140@section File-I/O remote protocol extension
21141@cindex File-I/O remote protocol extension
21142
21143@menu
21144* File-I/O Overview::
21145* Protocol basics::
1d8b2f28
JB
21146* The F request packet::
21147* The F reply packet::
0ce1b118
CV
21148* Memory transfer::
21149* The Ctrl-C message::
21150* Console I/O::
21151* The isatty call::
21152* The system call::
21153* List of supported calls::
21154* Protocol specific representation of datatypes::
21155* Constants::
21156* File-I/O Examples::
21157@end menu
21158
21159@node File-I/O Overview
21160@subsection File-I/O Overview
21161@cindex file-i/o overview
21162
21163The File I/O remote protocol extension (short: File-I/O) allows the
21164target to use the hosts file system and console I/O when calling various
21165system calls. System calls on the target system are translated into a
21166remote protocol packet to the host system which then performs the needed
21167actions and returns with an adequate response packet to the target system.
21168This simulates file system operations even on targets that lack file systems.
21169
21170The protocol is defined host- and target-system independent. It uses
21171it's own independent representation of datatypes and values. Both,
21172@value{GDBN} and the target's @value{GDBN} stub are responsible for
21173translating the system dependent values into the unified protocol values
21174when data is transmitted.
21175
21176The communication is synchronous. A system call is possible only
21177when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
21178packets. While @value{GDBN} handles the request for a system call,
21179the target is stopped to allow deterministic access to the target's
21180memory. Therefore File-I/O is not interuptible by target signals. It
21181is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
21182
21183The target's request to perform a host system call does not finish
21184the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
21185after finishing the system call, the target returns to continuing the
21186previous activity (continue, step). No additional continue or step
21187request from @value{GDBN} is required.
21188
21189@smallexample
f7dc1244 21190(@value{GDBP}) continue
0ce1b118
CV
21191 <- target requests 'system call X'
21192 target is stopped, @value{GDBN} executes system call
21193 -> GDB returns result
21194 ... target continues, GDB returns to wait for the target
21195 <- target hits breakpoint and sends a Txx packet
21196@end smallexample
21197
21198The protocol is only used for files on the host file system and
21199for I/O on the console. Character or block special devices, pipes,
21200named pipes or sockets or any other communication method on the host
21201system are not supported by this protocol.
21202
21203@node Protocol basics
21204@subsection Protocol basics
21205@cindex protocol basics, file-i/o
21206
21207The File-I/O protocol uses the @code{F} packet, as request as well
21208as as reply packet. Since a File-I/O system call can only occur when
b383017d 21209@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
21210File-I/O request is a reply that @value{GDBN} has to expect as a result
21211of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
21212This @code{F} packet contains all information needed to allow @value{GDBN}
21213to call the appropriate host system call:
21214
21215@itemize @bullet
b383017d 21216@item
0ce1b118
CV
21217A unique identifier for the requested system call.
21218
21219@item
21220All parameters to the system call. Pointers are given as addresses
21221in the target memory address space. Pointers to strings are given as
b383017d 21222pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
21223Numerical control values are given in a protocol specific representation.
21224
21225@end itemize
21226
21227At that point @value{GDBN} has to perform the following actions.
21228
21229@itemize @bullet
b383017d 21230@item
0ce1b118
CV
21231If parameter pointer values are given, which point to data needed as input
21232to a system call, @value{GDBN} requests this data from the target with a
21233standard @code{m} packet request. This additional communication has to be
21234expected by the target implementation and is handled as any other @code{m}
21235packet.
21236
21237@item
21238@value{GDBN} translates all value from protocol representation to host
21239representation as needed. Datatypes are coerced into the host types.
21240
21241@item
21242@value{GDBN} calls the system call
21243
21244@item
21245It then coerces datatypes back to protocol representation.
21246
21247@item
21248If pointer parameters in the request packet point to buffer space in which
21249a system call is expected to copy data to, the data is transmitted to the
21250target using a @code{M} or @code{X} packet. This packet has to be expected
21251by the target implementation and is handled as any other @code{M} or @code{X}
21252packet.
21253
21254@end itemize
21255
21256Eventually @value{GDBN} replies with another @code{F} packet which contains all
21257necessary information for the target to continue. This at least contains
21258
21259@itemize @bullet
21260@item
21261Return value.
21262
21263@item
21264@code{errno}, if has been changed by the system call.
21265
21266@item
21267``Ctrl-C'' flag.
21268
21269@end itemize
21270
21271After having done the needed type and value coercion, the target continues
21272the latest continue or step action.
21273
1d8b2f28 21274@node The F request packet
0ce1b118
CV
21275@subsection The @code{F} request packet
21276@cindex file-i/o request packet
21277@cindex @code{F} request packet
21278
21279The @code{F} request packet has the following format:
21280
21281@table @samp
21282
21283@smallexample
21284@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
21285@end smallexample
21286
21287@var{call-id} is the identifier to indicate the host system call to be called.
21288This is just the name of the function.
21289
21290@var{parameter@dots{}} are the parameters to the system call.
21291
b383017d 21292@end table
0ce1b118
CV
21293
21294Parameters are hexadecimal integer values, either the real values in case
21295of scalar datatypes, as pointers to target buffer space in case of compound
21296datatypes and unspecified memory areas or as pointer/length pairs in case
21297of string parameters. These are appended to the call-id, each separated
21298from its predecessor by a comma. All values are transmitted in ASCII
21299string representation, pointer/length pairs separated by a slash.
21300
1d8b2f28 21301@node The F reply packet
0ce1b118
CV
21302@subsection The @code{F} reply packet
21303@cindex file-i/o reply packet
21304@cindex @code{F} reply packet
21305
21306The @code{F} reply packet has the following format:
21307
21308@table @samp
21309
21310@smallexample
21311@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
21312@end smallexample
21313
21314@var{retcode} is the return code of the system call as hexadecimal value.
21315
21316@var{errno} is the errno set by the call, in protocol specific representation.
21317This parameter can be omitted if the call was successful.
21318
21319@var{Ctrl-C flag} is only send if the user requested a break. In this
21320case, @var{errno} must be send as well, even if the call was successful.
21321The @var{Ctrl-C flag} itself consists of the character 'C':
21322
21323@smallexample
21324F0,0,C
21325@end smallexample
21326
21327@noindent
21328or, if the call was interupted before the host call has been performed:
21329
21330@smallexample
21331F-1,4,C
21332@end smallexample
21333
21334@noindent
21335assuming 4 is the protocol specific representation of @code{EINTR}.
21336
21337@end table
21338
21339@node Memory transfer
21340@subsection Memory transfer
21341@cindex memory transfer, in file-i/o protocol
21342
21343Structured data which is transferred using a memory read or write as e.g.@:
21344a @code{struct stat} is expected to be in a protocol specific format with
21345all scalar multibyte datatypes being big endian. This should be done by
21346the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
21347it transfers memory to the target. Transferred pointers to structured
21348data should point to the already coerced data at any time.
21349
21350@node The Ctrl-C message
21351@subsection The Ctrl-C message
21352@cindex ctrl-c message, in file-i/o protocol
21353
21354A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
21355reply packet. In this case the target should behave, as if it had
21356gotten a break message. The meaning for the target is ``system call
21357interupted by @code{SIGINT}''. Consequentially, the target should actually stop
21358(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 21359packet. In this case, it's important for the target to know, in which
0ce1b118
CV
21360state the system call was interrupted. Since this action is by design
21361not an atomic operation, we have to differ between two cases:
21362
21363@itemize @bullet
21364@item
21365The system call hasn't been performed on the host yet.
21366
21367@item
21368The system call on the host has been finished.
21369
21370@end itemize
21371
21372These two states can be distinguished by the target by the value of the
21373returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
21374call hasn't been performed. This is equivalent to the @code{EINTR} handling
21375on POSIX systems. In any other case, the target may presume that the
21376system call has been finished --- successful or not --- and should behave
21377as if the break message arrived right after the system call.
21378
21379@value{GDBN} must behave reliable. If the system call has not been called
21380yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
21381@code{errno} in the packet. If the system call on the host has been finished
21382before the user requests a break, the full action must be finshed by
21383@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
21384The @code{F} packet may only be send when either nothing has happened
21385or the full action has been completed.
21386
21387@node Console I/O
21388@subsection Console I/O
21389@cindex console i/o as part of file-i/o
21390
21391By default and if not explicitely closed by the target system, the file
21392descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
21393on the @value{GDBN} console is handled as any other file output operation
21394(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
21395by @value{GDBN} so that after the target read request from file descriptor
213960 all following typing is buffered until either one of the following
21397conditions is met:
21398
21399@itemize @bullet
21400@item
21401The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
21402@code{read}
21403system call is treated as finished.
21404
21405@item
21406The user presses @kbd{Enter}. This is treated as end of input with a trailing
21407line feed.
21408
21409@item
21410The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
21411character, especially no Ctrl-D is appended to the input.
21412
21413@end itemize
21414
21415If the user has typed more characters as fit in the buffer given to
21416the read call, the trailing characters are buffered in @value{GDBN} until
21417either another @code{read(0, @dots{})} is requested by the target or debugging
21418is stopped on users request.
21419
21420@node The isatty call
21421@subsection The isatty(3) call
21422@cindex isatty call, file-i/o protocol
21423
21424A special case in this protocol is the library call @code{isatty} which
21425is implemented as it's own call inside of this protocol. It returns
214261 to the target if the file descriptor given as parameter is attached
21427to the @value{GDBN} console, 0 otherwise. Implementing through system calls
21428would require implementing @code{ioctl} and would be more complex than
21429needed.
21430
21431@node The system call
21432@subsection The system(3) call
21433@cindex system call, file-i/o protocol
21434
21435The other special case in this protocol is the @code{system} call which
21436is implemented as it's own call, too. @value{GDBN} is taking over the full
21437task of calling the necessary host calls to perform the @code{system}
21438call. The return value of @code{system} is simplified before it's returned
21439to the target. Basically, the only signal transmitted back is @code{EINTR}
21440in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
21441entirely of the exit status of the called command.
21442
21443Due to security concerns, the @code{system} call is refused to be called
b383017d 21444by @value{GDBN} by default. The user has to allow this call explicitly by
0ce1b118
CV
21445entering
21446
21447@table @samp
21448@kindex set remote system-call-allowed 1
21449@item @code{set remote system-call-allowed 1}
21450@end table
21451
21452Disabling the @code{system} call is done by
21453
21454@table @samp
21455@kindex set remote system-call-allowed 0
21456@item @code{set remote system-call-allowed 0}
21457@end table
21458
21459The current setting is shown by typing
21460
21461@table @samp
21462@kindex show remote system-call-allowed
21463@item @code{show remote system-call-allowed}
21464@end table
21465
21466@node List of supported calls
21467@subsection List of supported calls
21468@cindex list of supported file-i/o calls
21469
21470@menu
21471* open::
21472* close::
21473* read::
21474* write::
21475* lseek::
21476* rename::
21477* unlink::
21478* stat/fstat::
21479* gettimeofday::
21480* isatty::
21481* system::
21482@end menu
21483
21484@node open
21485@unnumberedsubsubsec open
21486@cindex open, file-i/o system call
21487
21488@smallexample
21489@exdent Synopsis:
21490int open(const char *pathname, int flags);
21491int open(const char *pathname, int flags, mode_t mode);
21492
b383017d 21493@exdent Request:
0ce1b118
CV
21494Fopen,pathptr/len,flags,mode
21495@end smallexample
21496
21497@noindent
21498@code{flags} is the bitwise or of the following values:
21499
21500@table @code
b383017d 21501@item O_CREAT
0ce1b118
CV
21502If the file does not exist it will be created. The host
21503rules apply as far as file ownership and time stamps
21504are concerned.
21505
b383017d 21506@item O_EXCL
0ce1b118
CV
21507When used with O_CREAT, if the file already exists it is
21508an error and open() fails.
21509
b383017d 21510@item O_TRUNC
0ce1b118
CV
21511If the file already exists and the open mode allows
21512writing (O_RDWR or O_WRONLY is given) it will be
21513truncated to length 0.
21514
b383017d 21515@item O_APPEND
0ce1b118
CV
21516The file is opened in append mode.
21517
b383017d 21518@item O_RDONLY
0ce1b118
CV
21519The file is opened for reading only.
21520
b383017d 21521@item O_WRONLY
0ce1b118
CV
21522The file is opened for writing only.
21523
b383017d 21524@item O_RDWR
0ce1b118
CV
21525The file is opened for reading and writing.
21526
21527@noindent
21528Each other bit is silently ignored.
21529
21530@end table
21531
21532@noindent
21533@code{mode} is the bitwise or of the following values:
21534
21535@table @code
b383017d 21536@item S_IRUSR
0ce1b118
CV
21537User has read permission.
21538
b383017d 21539@item S_IWUSR
0ce1b118
CV
21540User has write permission.
21541
b383017d 21542@item S_IRGRP
0ce1b118
CV
21543Group has read permission.
21544
b383017d 21545@item S_IWGRP
0ce1b118
CV
21546Group has write permission.
21547
b383017d 21548@item S_IROTH
0ce1b118
CV
21549Others have read permission.
21550
b383017d 21551@item S_IWOTH
0ce1b118
CV
21552Others have write permission.
21553
21554@noindent
21555Each other bit is silently ignored.
21556
21557@end table
21558
21559@smallexample
21560@exdent Return value:
21561open returns the new file descriptor or -1 if an error
21562occured.
21563
21564@exdent Errors:
21565@end smallexample
21566
21567@table @code
b383017d 21568@item EEXIST
0ce1b118
CV
21569pathname already exists and O_CREAT and O_EXCL were used.
21570
b383017d 21571@item EISDIR
0ce1b118
CV
21572pathname refers to a directory.
21573
b383017d 21574@item EACCES
0ce1b118
CV
21575The requested access is not allowed.
21576
21577@item ENAMETOOLONG
21578pathname was too long.
21579
b383017d 21580@item ENOENT
0ce1b118
CV
21581A directory component in pathname does not exist.
21582
b383017d 21583@item ENODEV
0ce1b118
CV
21584pathname refers to a device, pipe, named pipe or socket.
21585
b383017d 21586@item EROFS
0ce1b118
CV
21587pathname refers to a file on a read-only filesystem and
21588write access was requested.
21589
b383017d 21590@item EFAULT
0ce1b118
CV
21591pathname is an invalid pointer value.
21592
b383017d 21593@item ENOSPC
0ce1b118
CV
21594No space on device to create the file.
21595
b383017d 21596@item EMFILE
0ce1b118
CV
21597The process already has the maximum number of files open.
21598
b383017d 21599@item ENFILE
0ce1b118
CV
21600The limit on the total number of files open on the system
21601has been reached.
21602
b383017d 21603@item EINTR
0ce1b118
CV
21604The call was interrupted by the user.
21605@end table
21606
21607@node close
21608@unnumberedsubsubsec close
21609@cindex close, file-i/o system call
21610
21611@smallexample
b383017d 21612@exdent Synopsis:
0ce1b118
CV
21613int close(int fd);
21614
b383017d 21615@exdent Request:
0ce1b118
CV
21616Fclose,fd
21617
21618@exdent Return value:
21619close returns zero on success, or -1 if an error occurred.
21620
21621@exdent Errors:
21622@end smallexample
21623
21624@table @code
b383017d 21625@item EBADF
0ce1b118
CV
21626fd isn't a valid open file descriptor.
21627
b383017d 21628@item EINTR
0ce1b118
CV
21629The call was interrupted by the user.
21630@end table
21631
21632@node read
21633@unnumberedsubsubsec read
21634@cindex read, file-i/o system call
21635
21636@smallexample
b383017d 21637@exdent Synopsis:
0ce1b118
CV
21638int read(int fd, void *buf, unsigned int count);
21639
b383017d 21640@exdent Request:
0ce1b118
CV
21641Fread,fd,bufptr,count
21642
21643@exdent Return value:
21644On success, the number of bytes read is returned.
21645Zero indicates end of file. If count is zero, read
b383017d 21646returns zero as well. On error, -1 is returned.
0ce1b118
CV
21647
21648@exdent Errors:
21649@end smallexample
21650
21651@table @code
b383017d 21652@item EBADF
0ce1b118
CV
21653fd is not a valid file descriptor or is not open for
21654reading.
21655
b383017d 21656@item EFAULT
0ce1b118
CV
21657buf is an invalid pointer value.
21658
b383017d 21659@item EINTR
0ce1b118
CV
21660The call was interrupted by the user.
21661@end table
21662
21663@node write
21664@unnumberedsubsubsec write
21665@cindex write, file-i/o system call
21666
21667@smallexample
b383017d 21668@exdent Synopsis:
0ce1b118
CV
21669int write(int fd, const void *buf, unsigned int count);
21670
b383017d 21671@exdent Request:
0ce1b118
CV
21672Fwrite,fd,bufptr,count
21673
21674@exdent Return value:
21675On success, the number of bytes written are returned.
21676Zero indicates nothing was written. On error, -1
21677is returned.
21678
21679@exdent Errors:
21680@end smallexample
21681
21682@table @code
b383017d 21683@item EBADF
0ce1b118
CV
21684fd is not a valid file descriptor or is not open for
21685writing.
21686
b383017d 21687@item EFAULT
0ce1b118
CV
21688buf is an invalid pointer value.
21689
b383017d 21690@item EFBIG
0ce1b118
CV
21691An attempt was made to write a file that exceeds the
21692host specific maximum file size allowed.
21693
b383017d 21694@item ENOSPC
0ce1b118
CV
21695No space on device to write the data.
21696
b383017d 21697@item EINTR
0ce1b118
CV
21698The call was interrupted by the user.
21699@end table
21700
21701@node lseek
21702@unnumberedsubsubsec lseek
21703@cindex lseek, file-i/o system call
21704
21705@smallexample
b383017d 21706@exdent Synopsis:
0ce1b118
CV
21707long lseek (int fd, long offset, int flag);
21708
b383017d 21709@exdent Request:
0ce1b118
CV
21710Flseek,fd,offset,flag
21711@end smallexample
21712
21713@code{flag} is one of:
21714
21715@table @code
b383017d 21716@item SEEK_SET
0ce1b118
CV
21717The offset is set to offset bytes.
21718
b383017d 21719@item SEEK_CUR
0ce1b118
CV
21720The offset is set to its current location plus offset
21721bytes.
21722
b383017d 21723@item SEEK_END
0ce1b118
CV
21724The offset is set to the size of the file plus offset
21725bytes.
21726@end table
21727
21728@smallexample
21729@exdent Return value:
21730On success, the resulting unsigned offset in bytes from
21731the beginning of the file is returned. Otherwise, a
21732value of -1 is returned.
21733
21734@exdent Errors:
21735@end smallexample
21736
21737@table @code
b383017d 21738@item EBADF
0ce1b118
CV
21739fd is not a valid open file descriptor.
21740
b383017d 21741@item ESPIPE
0ce1b118
CV
21742fd is associated with the @value{GDBN} console.
21743
b383017d 21744@item EINVAL
0ce1b118
CV
21745flag is not a proper value.
21746
b383017d 21747@item EINTR
0ce1b118
CV
21748The call was interrupted by the user.
21749@end table
21750
21751@node rename
21752@unnumberedsubsubsec rename
21753@cindex rename, file-i/o system call
21754
21755@smallexample
b383017d 21756@exdent Synopsis:
0ce1b118
CV
21757int rename(const char *oldpath, const char *newpath);
21758
b383017d 21759@exdent Request:
0ce1b118
CV
21760Frename,oldpathptr/len,newpathptr/len
21761
21762@exdent Return value:
21763On success, zero is returned. On error, -1 is returned.
21764
21765@exdent Errors:
21766@end smallexample
21767
21768@table @code
b383017d 21769@item EISDIR
0ce1b118
CV
21770newpath is an existing directory, but oldpath is not a
21771directory.
21772
b383017d 21773@item EEXIST
0ce1b118
CV
21774newpath is a non-empty directory.
21775
b383017d 21776@item EBUSY
0ce1b118
CV
21777oldpath or newpath is a directory that is in use by some
21778process.
21779
b383017d 21780@item EINVAL
0ce1b118
CV
21781An attempt was made to make a directory a subdirectory
21782of itself.
21783
b383017d 21784@item ENOTDIR
0ce1b118
CV
21785A component used as a directory in oldpath or new
21786path is not a directory. Or oldpath is a directory
21787and newpath exists but is not a directory.
21788
b383017d 21789@item EFAULT
0ce1b118
CV
21790oldpathptr or newpathptr are invalid pointer values.
21791
b383017d 21792@item EACCES
0ce1b118
CV
21793No access to the file or the path of the file.
21794
21795@item ENAMETOOLONG
b383017d 21796
0ce1b118
CV
21797oldpath or newpath was too long.
21798
b383017d 21799@item ENOENT
0ce1b118
CV
21800A directory component in oldpath or newpath does not exist.
21801
b383017d 21802@item EROFS
0ce1b118
CV
21803The file is on a read-only filesystem.
21804
b383017d 21805@item ENOSPC
0ce1b118
CV
21806The device containing the file has no room for the new
21807directory entry.
21808
b383017d 21809@item EINTR
0ce1b118
CV
21810The call was interrupted by the user.
21811@end table
21812
21813@node unlink
21814@unnumberedsubsubsec unlink
21815@cindex unlink, file-i/o system call
21816
21817@smallexample
b383017d 21818@exdent Synopsis:
0ce1b118
CV
21819int unlink(const char *pathname);
21820
b383017d 21821@exdent Request:
0ce1b118
CV
21822Funlink,pathnameptr/len
21823
21824@exdent Return value:
21825On success, zero is returned. On error, -1 is returned.
21826
21827@exdent Errors:
21828@end smallexample
21829
21830@table @code
b383017d 21831@item EACCES
0ce1b118
CV
21832No access to the file or the path of the file.
21833
b383017d 21834@item EPERM
0ce1b118
CV
21835The system does not allow unlinking of directories.
21836
b383017d 21837@item EBUSY
0ce1b118
CV
21838The file pathname cannot be unlinked because it's
21839being used by another process.
21840
b383017d 21841@item EFAULT
0ce1b118
CV
21842pathnameptr is an invalid pointer value.
21843
21844@item ENAMETOOLONG
21845pathname was too long.
21846
b383017d 21847@item ENOENT
0ce1b118
CV
21848A directory component in pathname does not exist.
21849
b383017d 21850@item ENOTDIR
0ce1b118
CV
21851A component of the path is not a directory.
21852
b383017d 21853@item EROFS
0ce1b118
CV
21854The file is on a read-only filesystem.
21855
b383017d 21856@item EINTR
0ce1b118
CV
21857The call was interrupted by the user.
21858@end table
21859
21860@node stat/fstat
21861@unnumberedsubsubsec stat/fstat
21862@cindex fstat, file-i/o system call
21863@cindex stat, file-i/o system call
21864
21865@smallexample
b383017d 21866@exdent Synopsis:
0ce1b118
CV
21867int stat(const char *pathname, struct stat *buf);
21868int fstat(int fd, struct stat *buf);
21869
b383017d 21870@exdent Request:
0ce1b118
CV
21871Fstat,pathnameptr/len,bufptr
21872Ffstat,fd,bufptr
21873
21874@exdent Return value:
21875On success, zero is returned. On error, -1 is returned.
21876
21877@exdent Errors:
21878@end smallexample
21879
21880@table @code
b383017d 21881@item EBADF
0ce1b118
CV
21882fd is not a valid open file.
21883
b383017d 21884@item ENOENT
0ce1b118
CV
21885A directory component in pathname does not exist or the
21886path is an empty string.
21887
b383017d 21888@item ENOTDIR
0ce1b118
CV
21889A component of the path is not a directory.
21890
b383017d 21891@item EFAULT
0ce1b118
CV
21892pathnameptr is an invalid pointer value.
21893
b383017d 21894@item EACCES
0ce1b118
CV
21895No access to the file or the path of the file.
21896
21897@item ENAMETOOLONG
21898pathname was too long.
21899
b383017d 21900@item EINTR
0ce1b118
CV
21901The call was interrupted by the user.
21902@end table
21903
21904@node gettimeofday
21905@unnumberedsubsubsec gettimeofday
21906@cindex gettimeofday, file-i/o system call
21907
21908@smallexample
b383017d 21909@exdent Synopsis:
0ce1b118
CV
21910int gettimeofday(struct timeval *tv, void *tz);
21911
b383017d 21912@exdent Request:
0ce1b118
CV
21913Fgettimeofday,tvptr,tzptr
21914
21915@exdent Return value:
21916On success, 0 is returned, -1 otherwise.
21917
21918@exdent Errors:
21919@end smallexample
21920
21921@table @code
b383017d 21922@item EINVAL
0ce1b118
CV
21923tz is a non-NULL pointer.
21924
b383017d 21925@item EFAULT
0ce1b118
CV
21926tvptr and/or tzptr is an invalid pointer value.
21927@end table
21928
21929@node isatty
21930@unnumberedsubsubsec isatty
21931@cindex isatty, file-i/o system call
21932
21933@smallexample
b383017d 21934@exdent Synopsis:
0ce1b118
CV
21935int isatty(int fd);
21936
b383017d 21937@exdent Request:
0ce1b118
CV
21938Fisatty,fd
21939
21940@exdent Return value:
21941Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21942
21943@exdent Errors:
21944@end smallexample
21945
21946@table @code
b383017d 21947@item EINTR
0ce1b118
CV
21948The call was interrupted by the user.
21949@end table
21950
21951@node system
21952@unnumberedsubsubsec system
21953@cindex system, file-i/o system call
21954
21955@smallexample
b383017d 21956@exdent Synopsis:
0ce1b118
CV
21957int system(const char *command);
21958
b383017d 21959@exdent Request:
0ce1b118
CV
21960Fsystem,commandptr/len
21961
21962@exdent Return value:
21963The value returned is -1 on error and the return status
21964of the command otherwise. Only the exit status of the
21965command is returned, which is extracted from the hosts
21966system return value by calling WEXITSTATUS(retval).
21967In case /bin/sh could not be executed, 127 is returned.
21968
21969@exdent Errors:
21970@end smallexample
21971
21972@table @code
b383017d 21973@item EINTR
0ce1b118
CV
21974The call was interrupted by the user.
21975@end table
21976
21977@node Protocol specific representation of datatypes
21978@subsection Protocol specific representation of datatypes
21979@cindex protocol specific representation of datatypes, in file-i/o protocol
21980
21981@menu
21982* Integral datatypes::
21983* Pointer values::
21984* struct stat::
21985* struct timeval::
21986@end menu
21987
21988@node Integral datatypes
21989@unnumberedsubsubsec Integral datatypes
21990@cindex integral datatypes, in file-i/o protocol
21991
21992The integral datatypes used in the system calls are
21993
21994@smallexample
21995int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21996@end smallexample
21997
21998@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21999implemented as 32 bit values in this protocol.
22000
b383017d
RM
22001@code{Long} and @code{unsigned long} are implemented as 64 bit types.
22002
0ce1b118
CV
22003@xref{Limits}, for corresponding MIN and MAX values (similar to those
22004in @file{limits.h}) to allow range checking on host and target.
22005
22006@code{time_t} datatypes are defined as seconds since the Epoch.
22007
22008All integral datatypes transferred as part of a memory read or write of a
22009structured datatype e.g.@: a @code{struct stat} have to be given in big endian
22010byte order.
22011
22012@node Pointer values
22013@unnumberedsubsubsec Pointer values
22014@cindex pointer values, in file-i/o protocol
22015
22016Pointers to target data are transmitted as they are. An exception
22017is made for pointers to buffers for which the length isn't
22018transmitted as part of the function call, namely strings. Strings
22019are transmitted as a pointer/length pair, both as hex values, e.g.@:
22020
22021@smallexample
22022@code{1aaf/12}
22023@end smallexample
22024
22025@noindent
22026which is a pointer to data of length 18 bytes at position 0x1aaf.
22027The length is defined as the full string length in bytes, including
22028the trailing null byte. Example:
22029
22030@smallexample
22031``hello, world'' at address 0x123456
22032@end smallexample
22033
22034@noindent
22035is transmitted as
22036
22037@smallexample
22038@code{123456/d}
22039@end smallexample
22040
22041@node struct stat
22042@unnumberedsubsubsec struct stat
22043@cindex struct stat, in file-i/o protocol
22044
22045The buffer of type struct stat used by the target and @value{GDBN} is defined
22046as follows:
22047
22048@smallexample
22049struct stat @{
22050 unsigned int st_dev; /* device */
22051 unsigned int st_ino; /* inode */
22052 mode_t st_mode; /* protection */
22053 unsigned int st_nlink; /* number of hard links */
22054 unsigned int st_uid; /* user ID of owner */
22055 unsigned int st_gid; /* group ID of owner */
22056 unsigned int st_rdev; /* device type (if inode device) */
22057 unsigned long st_size; /* total size, in bytes */
22058 unsigned long st_blksize; /* blocksize for filesystem I/O */
22059 unsigned long st_blocks; /* number of blocks allocated */
22060 time_t st_atime; /* time of last access */
22061 time_t st_mtime; /* time of last modification */
22062 time_t st_ctime; /* time of last change */
22063@};
22064@end smallexample
22065
22066The integral datatypes are conforming to the definitions given in the
22067approriate section (see @ref{Integral datatypes}, for details) so this
22068structure is of size 64 bytes.
22069
22070The values of several fields have a restricted meaning and/or
22071range of values.
22072
22073@smallexample
22074st_dev: 0 file
22075 1 console
22076
22077st_ino: No valid meaning for the target. Transmitted unchanged.
22078
22079st_mode: Valid mode bits are described in Appendix C. Any other
22080 bits have currently no meaning for the target.
22081
22082st_uid: No valid meaning for the target. Transmitted unchanged.
22083
22084st_gid: No valid meaning for the target. Transmitted unchanged.
22085
22086st_rdev: No valid meaning for the target. Transmitted unchanged.
22087
22088st_atime, st_mtime, st_ctime:
22089 These values have a host and file system dependent
22090 accuracy. Especially on Windows hosts the file systems
22091 don't support exact timing values.
22092@end smallexample
22093
22094The target gets a struct stat of the above representation and is
22095responsible to coerce it to the target representation before
22096continuing.
22097
22098Note that due to size differences between the host and target
22099representation of stat members, these members could eventually
22100get truncated on the target.
22101
22102@node struct timeval
22103@unnumberedsubsubsec struct timeval
22104@cindex struct timeval, in file-i/o protocol
22105
22106The buffer of type struct timeval used by the target and @value{GDBN}
22107is defined as follows:
22108
22109@smallexample
b383017d 22110struct timeval @{
0ce1b118
CV
22111 time_t tv_sec; /* second */
22112 long tv_usec; /* microsecond */
22113@};
22114@end smallexample
22115
22116The integral datatypes are conforming to the definitions given in the
22117approriate section (see @ref{Integral datatypes}, for details) so this
22118structure is of size 8 bytes.
22119
22120@node Constants
22121@subsection Constants
22122@cindex constants, in file-i/o protocol
22123
22124The following values are used for the constants inside of the
22125protocol. @value{GDBN} and target are resposible to translate these
22126values before and after the call as needed.
22127
22128@menu
22129* Open flags::
22130* mode_t values::
22131* Errno values::
22132* Lseek flags::
22133* Limits::
22134@end menu
22135
22136@node Open flags
22137@unnumberedsubsubsec Open flags
22138@cindex open flags, in file-i/o protocol
22139
22140All values are given in hexadecimal representation.
22141
22142@smallexample
22143 O_RDONLY 0x0
22144 O_WRONLY 0x1
22145 O_RDWR 0x2
22146 O_APPEND 0x8
22147 O_CREAT 0x200
22148 O_TRUNC 0x400
22149 O_EXCL 0x800
22150@end smallexample
22151
22152@node mode_t values
22153@unnumberedsubsubsec mode_t values
22154@cindex mode_t values, in file-i/o protocol
22155
22156All values are given in octal representation.
22157
22158@smallexample
22159 S_IFREG 0100000
22160 S_IFDIR 040000
22161 S_IRUSR 0400
22162 S_IWUSR 0200
22163 S_IXUSR 0100
22164 S_IRGRP 040
22165 S_IWGRP 020
22166 S_IXGRP 010
22167 S_IROTH 04
22168 S_IWOTH 02
22169 S_IXOTH 01
22170@end smallexample
22171
22172@node Errno values
22173@unnumberedsubsubsec Errno values
22174@cindex errno values, in file-i/o protocol
22175
22176All values are given in decimal representation.
22177
22178@smallexample
22179 EPERM 1
22180 ENOENT 2
22181 EINTR 4
22182 EBADF 9
22183 EACCES 13
22184 EFAULT 14
22185 EBUSY 16
22186 EEXIST 17
22187 ENODEV 19
22188 ENOTDIR 20
22189 EISDIR 21
22190 EINVAL 22
22191 ENFILE 23
22192 EMFILE 24
22193 EFBIG 27
22194 ENOSPC 28
22195 ESPIPE 29
22196 EROFS 30
22197 ENAMETOOLONG 91
22198 EUNKNOWN 9999
22199@end smallexample
22200
22201 EUNKNOWN is used as a fallback error value if a host system returns
22202 any error value not in the list of supported error numbers.
22203
22204@node Lseek flags
22205@unnumberedsubsubsec Lseek flags
22206@cindex lseek flags, in file-i/o protocol
22207
22208@smallexample
22209 SEEK_SET 0
22210 SEEK_CUR 1
22211 SEEK_END 2
22212@end smallexample
22213
22214@node Limits
22215@unnumberedsubsubsec Limits
22216@cindex limits, in file-i/o protocol
22217
22218All values are given in decimal representation.
22219
22220@smallexample
22221 INT_MIN -2147483648
22222 INT_MAX 2147483647
22223 UINT_MAX 4294967295
22224 LONG_MIN -9223372036854775808
22225 LONG_MAX 9223372036854775807
22226 ULONG_MAX 18446744073709551615
22227@end smallexample
22228
22229@node File-I/O Examples
22230@subsection File-I/O Examples
22231@cindex file-i/o examples
22232
22233Example sequence of a write call, file descriptor 3, buffer is at target
22234address 0x1234, 6 bytes should be written:
22235
22236@smallexample
22237<- @code{Fwrite,3,1234,6}
22238@emph{request memory read from target}
22239-> @code{m1234,6}
22240<- XXXXXX
22241@emph{return "6 bytes written"}
22242-> @code{F6}
22243@end smallexample
22244
22245Example sequence of a read call, file descriptor 3, buffer is at target
22246address 0x1234, 6 bytes should be read:
22247
22248@smallexample
22249<- @code{Fread,3,1234,6}
22250@emph{request memory write to target}
22251-> @code{X1234,6:XXXXXX}
22252@emph{return "6 bytes read"}
22253-> @code{F6}
22254@end smallexample
22255
22256Example sequence of a read call, call fails on the host due to invalid
22257file descriptor (EBADF):
22258
22259@smallexample
22260<- @code{Fread,3,1234,6}
22261-> @code{F-1,9}
22262@end smallexample
22263
22264Example sequence of a read call, user presses Ctrl-C before syscall on
22265host is called:
22266
22267@smallexample
22268<- @code{Fread,3,1234,6}
22269-> @code{F-1,4,C}
22270<- @code{T02}
22271@end smallexample
22272
22273Example sequence of a read call, user presses Ctrl-C after syscall on
22274host is called:
22275
22276@smallexample
22277<- @code{Fread,3,1234,6}
22278-> @code{X1234,6:XXXXXX}
22279<- @code{T02}
22280@end smallexample
22281
f418dd93
DJ
22282@include agentexpr.texi
22283
aab4e0ec 22284@include gpl.texi
eb12ee30 22285
2154891a 22286@raisesections
6826cf00 22287@include fdl.texi
2154891a 22288@lowersections
6826cf00 22289
6d2ebf8b 22290@node Index
c906108c
SS
22291@unnumbered Index
22292
22293@printindex cp
22294
22295@tex
22296% I think something like @colophon should be in texinfo. In the
22297% meantime:
22298\long\def\colophon{\hbox to0pt{}\vfill
22299\centerline{The body of this manual is set in}
22300\centerline{\fontname\tenrm,}
22301\centerline{with headings in {\bf\fontname\tenbf}}
22302\centerline{and examples in {\tt\fontname\tentt}.}
22303\centerline{{\it\fontname\tenit\/},}
22304\centerline{{\bf\fontname\tenbf}, and}
22305\centerline{{\sl\fontname\tensl\/}}
22306\centerline{are used for emphasis.}\vfill}
22307\page\colophon
22308% Blame: doc@cygnus.com, 1991.
22309@end tex
22310
c906108c 22311@bye
This page took 1.634236 seconds and 4 git commands to generate.