(elf_hppa_final_link_relocate) Fix handling of branches.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
6d2ebf8b 2@c Copyright 1988-2000
c906108c
SS
3@c Free Software Foundation, Inc.
4@c
5d161b24 5@c %**start of header
c906108c
SS
6@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
7@c of @set vars. However, you can override filename with makeinfo -o.
8@setfilename gdb.info
9@c
10@include gdb-cfg.texi
11@c
c906108c 12@settitle Debugging with @value{GDBN}
c906108c
SS
13@setchapternewpage odd
14@c %**end of header
15
16@iftex
17@c @smallbook
18@c @cropmarks
19@end iftex
20
21@finalout
22@syncodeindex ky cp
23
41afff9a 24@c readline appendices use @vindex, @findex and @ftable,
48e934c6 25@c annotate.texi and gdbmi use @findex.
c906108c 26@syncodeindex vr cp
41afff9a 27@syncodeindex fn cp
c906108c
SS
28
29@c !!set GDB manual's edition---not the same as GDB version!
6d2ebf8b 30@set EDITION Eighth
c906108c
SS
31
32@c !!set GDB manual's revision date
6d2ebf8b 33@set DATE March 2000
c906108c 34
6d2ebf8b 35@c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
c906108c 36
c906108c 37@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 38@c manuals to an info tree.
96a2c332
SS
39@dircategory Programming & development tools.
40@direntry
c906108c 41* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
42@end direntry
43
c906108c
SS
44@ifinfo
45This file documents the @sc{gnu} debugger @value{GDBN}.
46
47
5d161b24 48This is the @value{EDITION} Edition, @value{DATE},
c906108c
SS
49of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
50for @value{GDBN} Version @value{GDBVN}.
51
6d2ebf8b 52Copyright (C) 1988-2000 Free Software Foundation, Inc.
c906108c
SS
53
54Permission is granted to make and distribute verbatim copies of
55this manual provided the copyright notice and this permission notice
56are preserved on all copies.
57
58@ignore
59Permission is granted to process this file through TeX and print the
60results, provided the printed document carries copying permission
61notice identical to this one except for the removal of this paragraph
62(this paragraph not being relevant to the printed manual).
63
64@end ignore
65Permission is granted to copy and distribute modified versions of this
66manual under the conditions for verbatim copying, provided also that the
67entire resulting derived work is distributed under the terms of a
68permission notice identical to this one.
69
70Permission is granted to copy and distribute translations of this manual
71into another language, under the above conditions for modified versions.
72@end ifinfo
73
74@titlepage
75@title Debugging with @value{GDBN}
76@subtitle The @sc{gnu} Source-Level Debugger
c906108c 77@sp 1
c906108c
SS
78@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
79@subtitle @value{DATE}
9e9c5ae7 80@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 81@page
c906108c
SS
82@tex
83{\parskip=0pt
53a5351d 84\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
85\hfill {\it Debugging with @value{GDBN}}\par
86\hfill \TeX{}info \texinfoversion\par
87}
88@end tex
53a5351d 89
c906108c 90@vskip 0pt plus 1filll
6d2ebf8b 91Copyright @copyright{} 1988-2000 Free Software Foundation, Inc.
c906108c 92@sp 2
c906108c
SS
93Published by the Free Software Foundation @*
9459 Temple Place - Suite 330, @*
95Boston, MA 02111-1307 USA @*
6d2ebf8b
SS
96ISBN 1-882114-77-9 @*
97
c906108c
SS
98Permission is granted to make and distribute verbatim copies of
99this manual provided the copyright notice and this permission notice
100are preserved on all copies.
101
102Permission is granted to copy and distribute modified versions of this
103manual under the conditions for verbatim copying, provided also that the
104entire resulting derived work is distributed under the terms of a
105permission notice identical to this one.
106
107Permission is granted to copy and distribute translations of this manual
108into another language, under the above conditions for modified versions.
109@end titlepage
110@page
111
b9deaee7 112@ifinfo
6d2ebf8b
SS
113@node Top, Summary, (dir), (dir)
114
c906108c
SS
115@top Debugging with @value{GDBN}
116
117This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
118
5d161b24 119This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
c906108c
SS
120@value{GDBVN}.
121
6d2ebf8b
SS
122Copyright (C) 1988-2000 Free Software Foundation, Inc.
123
124@menu
125* Summary:: Summary of @value{GDBN}
126* Sample Session:: A sample @value{GDBN} session
127
128* Invocation:: Getting in and out of @value{GDBN}
129* Commands:: @value{GDBN} commands
130* Running:: Running programs under @value{GDBN}
131* Stopping:: Stopping and continuing
132* Stack:: Examining the stack
133* Source:: Examining source files
134* Data:: Examining data
135
136* Languages:: Using @value{GDBN} with different languages
137
138* Symbols:: Examining the symbol table
139* Altering:: Altering execution
140* GDB Files:: @value{GDBN} files
141* Targets:: Specifying a debugging target
142* Configurations:: Configuration-specific information
143* Controlling GDB:: Controlling @value{GDBN}
144* Sequences:: Canned sequences of commands
145* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
146* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 147* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
148
149* GDB Bugs:: Reporting bugs in @value{GDBN}
150* Formatting Documentation:: How to format and print @value{GDBN} documentation
151
152* Command Line Editing:: Command Line Editing
153* Using History Interactively:: Using History Interactively
154* Installing GDB:: Installing GDB
155* Index:: Index
156@end menu
157
b9deaee7 158@end ifinfo
6d2ebf8b
SS
159
160@c the replication sucks, but this avoids a texinfo 3.12 lameness
161
162@ifhtml
163@node Top
164
165@top Debugging with @value{GDBN}
166
167This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
168
169This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
170@value{GDBVN}.
171
172Copyright (C) 1988-2000 Free Software Foundation, Inc.
173
c906108c
SS
174@menu
175* Summary:: Summary of @value{GDBN}
c906108c 176* Sample Session:: A sample @value{GDBN} session
c906108c
SS
177
178* Invocation:: Getting in and out of @value{GDBN}
179* Commands:: @value{GDBN} commands
180* Running:: Running programs under @value{GDBN}
181* Stopping:: Stopping and continuing
182* Stack:: Examining the stack
183* Source:: Examining source files
184* Data:: Examining data
c906108c 185
7a292a7a 186* Languages:: Using @value{GDBN} with different languages
c906108c
SS
187
188* Symbols:: Examining the symbol table
189* Altering:: Altering execution
190* GDB Files:: @value{GDBN} files
191* Targets:: Specifying a debugging target
104c1213 192* Configurations:: Configuration-specific information
c906108c
SS
193* Controlling GDB:: Controlling @value{GDBN}
194* Sequences:: Canned sequences of commands
c906108c 195* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 196* Annotations:: @value{GDBN}'s annotation interface.
c906108c
SS
197
198* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 199* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
200
201* Command Line Editing:: Command Line Editing
202* Using History Interactively:: Using History Interactively
203* Installing GDB:: Installing GDB
204* Index:: Index
c906108c
SS
205@end menu
206
6d2ebf8b
SS
207@end ifhtml
208
209@node Summary
c906108c
SS
210@unnumbered Summary of @value{GDBN}
211
212The purpose of a debugger such as @value{GDBN} is to allow you to see what is
213going on ``inside'' another program while it executes---or what another
214program was doing at the moment it crashed.
215
216@value{GDBN} can do four main kinds of things (plus other things in support of
217these) to help you catch bugs in the act:
218
219@itemize @bullet
220@item
221Start your program, specifying anything that might affect its behavior.
222
223@item
224Make your program stop on specified conditions.
225
226@item
227Examine what has happened, when your program has stopped.
228
229@item
230Change things in your program, so you can experiment with correcting the
231effects of one bug and go on to learn about another.
232@end itemize
233
cce74817 234You can use @value{GDBN} to debug programs written in C and C++.
c906108c 235For more information, see @ref{Support,,Supported languages}.
c906108c
SS
236For more information, see @ref{C,,C and C++}.
237
cce74817
JM
238@cindex Chill
239@cindex Modula-2
c906108c 240Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 241see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 242
cce74817
JM
243@cindex Pascal
244Debugging Pascal programs which use sets, subranges, file variables, or
245nested functions does not currently work. @value{GDBN} does not support
246entering expressions, printing values, or similar features using Pascal
247syntax.
c906108c 248
c906108c
SS
249@cindex Fortran
250@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 251it may be necessary to refer to some variables with a trailing
cce74817 252underscore.
c906108c 253
c906108c
SS
254@menu
255* Free Software:: Freely redistributable software
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
c906108c
SS
260@unnumberedsec Free software
261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
6d2ebf8b 275@node Contributors
96a2c332
SS
276@unnumberedsec Contributors to @value{GDBN}
277
278Richard Stallman was the original author of @value{GDBN}, and of many
279other @sc{gnu} programs. Many others have contributed to its
280development. This section attempts to credit major contributors. One
281of the virtues of free software is that everyone is free to contribute
282to it; with regret, we cannot actually acknowledge everyone here. The
283file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
284blow-by-blow account.
285
286Changes much prior to version 2.0 are lost in the mists of time.
287
288@quotation
289@emph{Plea:} Additions to this section are particularly welcome. If you
290or your friends (or enemies, to be evenhanded) have been unfairly
291omitted from this list, we would like to add your names!
292@end quotation
293
294So that they may not regard their many labors as thankless, we
295particularly thank those who shepherded @value{GDBN} through major
296releases:
8c70017b 297Andrew Cagney (release 5.0);
c906108c
SS
298Jim Blandy (release 4.18);
299Jason Molenda (release 4.17);
300Stan Shebs (release 4.14);
301Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
302Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
303John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
304Jim Kingdon (releases 3.5, 3.4, and 3.3);
305and Randy Smith (releases 3.2, 3.1, and 3.0).
306
307Richard Stallman, assisted at various times by Peter TerMaat, Chris
308Hanson, and Richard Mlynarik, handled releases through 2.8.
309
96a2c332
SS
310Michael Tiemann is the author of most of the @sc{gnu} C++ support in
311@value{GDBN}, with significant additional contributions from Per
312Bothner. James Clark wrote the @sc{gnu} C++ demangler. Early work on
313C++ was by Peter TerMaat (who also did much general update work leading
314to release 3.0).
c906108c
SS
315
316@value{GDBN} 4 uses the BFD subroutine library to examine multiple
317object-file formats; BFD was a joint project of David V.
318Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
319
320David Johnson wrote the original COFF support; Pace Willison did
321the original support for encapsulated COFF.
322
323Brent Benson of Harris Computer Systems contributed DWARF 2 support.
324
325Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
326Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
327support.
328Jean-Daniel Fekete contributed Sun 386i support.
329Chris Hanson improved the HP9000 support.
330Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
331David Johnson contributed Encore Umax support.
332Jyrki Kuoppala contributed Altos 3068 support.
333Jeff Law contributed HP PA and SOM support.
334Keith Packard contributed NS32K support.
335Doug Rabson contributed Acorn Risc Machine support.
336Bob Rusk contributed Harris Nighthawk CX-UX support.
337Chris Smith contributed Convex support (and Fortran debugging).
338Jonathan Stone contributed Pyramid support.
339Michael Tiemann contributed SPARC support.
340Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
341Pace Willison contributed Intel 386 support.
342Jay Vosburgh contributed Symmetry support.
343
344Andreas Schwab contributed M68K Linux support.
345
346Rich Schaefer and Peter Schauer helped with support of SunOS shared
347libraries.
348
349Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
350about several machine instruction sets.
351
352Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
353remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
354contributed remote debugging modules for the i960, VxWorks, A29K UDI,
355and RDI targets, respectively.
356
357Brian Fox is the author of the readline libraries providing
358command-line editing and command history.
359
7a292a7a
SS
360Andrew Beers of SUNY Buffalo wrote the language-switching code, the
361Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 362
5d161b24 363Fred Fish wrote most of the support for Unix System Vr4.
c906108c
SS
364He also enhanced the command-completion support to cover C++ overloaded
365symbols.
c906108c
SS
366
367Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
368Super-H processors.
369
370NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
371
372Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
373
374Toshiba sponsored the support for the TX39 Mips processor.
375
376Matsushita sponsored the support for the MN10200 and MN10300 processors.
377
96a2c332 378Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
379
380Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
381watchpoints.
382
383Michael Snyder added support for tracepoints.
384
385Stu Grossman wrote gdbserver.
386
387Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 388nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
389
390The following people at the Hewlett-Packard Company contributed
391support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
392(narrow mode), HP's implementation of kernel threads, HP's aC++
393compiler, and the terminal user interface: Ben Krepp, Richard Title,
394John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
395Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
396information in this manual.
397
96a2c332
SS
398Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
399development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
400fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
401Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
402Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
403Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
404Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
405addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
406JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
407Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
408Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
409Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
410Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
411Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
412Zuhn have made contributions both large and small.
c906108c
SS
413
414
6d2ebf8b 415@node Sample Session
c906108c
SS
416@chapter A Sample @value{GDBN} Session
417
418You can use this manual at your leisure to read all about @value{GDBN}.
419However, a handful of commands are enough to get started using the
420debugger. This chapter illustrates those commands.
421
422@iftex
423In this sample session, we emphasize user input like this: @b{input},
424to make it easier to pick out from the surrounding output.
425@end iftex
426
427@c FIXME: this example may not be appropriate for some configs, where
428@c FIXME...primary interest is in remote use.
429
430One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
431processor) exhibits the following bug: sometimes, when we change its
432quote strings from the default, the commands used to capture one macro
433definition within another stop working. In the following short @code{m4}
434session, we define a macro @code{foo} which expands to @code{0000}; we
435then use the @code{m4} built-in @code{defn} to define @code{bar} as the
436same thing. However, when we change the open quote string to
437@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
438procedure fails to define a new synonym @code{baz}:
439
440@smallexample
441$ @b{cd gnu/m4}
442$ @b{./m4}
443@b{define(foo,0000)}
444
445@b{foo}
4460000
447@b{define(bar,defn(`foo'))}
448
449@b{bar}
4500000
451@b{changequote(<QUOTE>,<UNQUOTE>)}
452
453@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
454@b{baz}
455@b{C-d}
456m4: End of input: 0: fatal error: EOF in string
457@end smallexample
458
459@noindent
460Let us use @value{GDBN} to try to see what is going on.
461
c906108c
SS
462@smallexample
463$ @b{@value{GDBP} m4}
464@c FIXME: this falsifies the exact text played out, to permit smallbook
465@c FIXME... format to come out better.
466@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 467 of it under certain conditions; type "show copying" to see
c906108c 468 the conditions.
5d161b24 469There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
470 for details.
471
472@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
473(@value{GDBP})
474@end smallexample
c906108c
SS
475
476@noindent
477@value{GDBN} reads only enough symbol data to know where to find the
478rest when needed; as a result, the first prompt comes up very quickly.
479We now tell @value{GDBN} to use a narrower display width than usual, so
480that examples fit in this manual.
481
482@smallexample
483(@value{GDBP}) @b{set width 70}
484@end smallexample
485
486@noindent
487We need to see how the @code{m4} built-in @code{changequote} works.
488Having looked at the source, we know the relevant subroutine is
489@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
490@code{break} command.
491
492@smallexample
493(@value{GDBP}) @b{break m4_changequote}
494Breakpoint 1 at 0x62f4: file builtin.c, line 879.
495@end smallexample
496
497@noindent
498Using the @code{run} command, we start @code{m4} running under @value{GDBN}
499control; as long as control does not reach the @code{m4_changequote}
500subroutine, the program runs as usual:
501
502@smallexample
503(@value{GDBP}) @b{run}
504Starting program: /work/Editorial/gdb/gnu/m4/m4
505@b{define(foo,0000)}
506
507@b{foo}
5080000
509@end smallexample
510
511@noindent
512To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
513suspends execution of @code{m4}, displaying information about the
514context where it stops.
515
516@smallexample
517@b{changequote(<QUOTE>,<UNQUOTE>)}
518
5d161b24 519Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
520 at builtin.c:879
521879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
522@end smallexample
523
524@noindent
525Now we use the command @code{n} (@code{next}) to advance execution to
526the next line of the current function.
527
528@smallexample
529(@value{GDBP}) @b{n}
530882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
531 : nil,
532@end smallexample
533
534@noindent
535@code{set_quotes} looks like a promising subroutine. We can go into it
536by using the command @code{s} (@code{step}) instead of @code{next}.
537@code{step} goes to the next line to be executed in @emph{any}
538subroutine, so it steps into @code{set_quotes}.
539
540@smallexample
541(@value{GDBP}) @b{s}
542set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
543 at input.c:530
544530 if (lquote != def_lquote)
545@end smallexample
546
547@noindent
548The display that shows the subroutine where @code{m4} is now
549suspended (and its arguments) is called a stack frame display. It
550shows a summary of the stack. We can use the @code{backtrace}
551command (which can also be spelled @code{bt}), to see where we are
552in the stack as a whole: the @code{backtrace} command displays a
553stack frame for each active subroutine.
554
555@smallexample
556(@value{GDBP}) @b{bt}
557#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
558 at input.c:530
5d161b24 559#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
560 at builtin.c:882
561#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
562#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
563 at macro.c:71
564#4 0x79dc in expand_input () at macro.c:40
565#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
566@end smallexample
567
568@noindent
569We step through a few more lines to see what happens. The first two
570times, we can use @samp{s}; the next two times we use @code{n} to avoid
571falling into the @code{xstrdup} subroutine.
572
573@smallexample
574(@value{GDBP}) @b{s}
5750x3b5c 532 if (rquote != def_rquote)
576(@value{GDBP}) @b{s}
5770x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
578def_lquote : xstrdup(lq);
579(@value{GDBP}) @b{n}
580536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
581 : xstrdup(rq);
582(@value{GDBP}) @b{n}
583538 len_lquote = strlen(rquote);
584@end smallexample
585
586@noindent
587The last line displayed looks a little odd; we can examine the variables
588@code{lquote} and @code{rquote} to see if they are in fact the new left
589and right quotes we specified. We use the command @code{p}
590(@code{print}) to see their values.
591
592@smallexample
593(@value{GDBP}) @b{p lquote}
594$1 = 0x35d40 "<QUOTE>"
595(@value{GDBP}) @b{p rquote}
596$2 = 0x35d50 "<UNQUOTE>"
597@end smallexample
598
599@noindent
600@code{lquote} and @code{rquote} are indeed the new left and right quotes.
601To look at some context, we can display ten lines of source
602surrounding the current line with the @code{l} (@code{list}) command.
603
604@smallexample
605(@value{GDBP}) @b{l}
606533 xfree(rquote);
607534
608535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
609 : xstrdup (lq);
610536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
611 : xstrdup (rq);
612537
613538 len_lquote = strlen(rquote);
614539 len_rquote = strlen(lquote);
615540 @}
616541
617542 void
618@end smallexample
619
620@noindent
621Let us step past the two lines that set @code{len_lquote} and
622@code{len_rquote}, and then examine the values of those variables.
623
624@smallexample
625(@value{GDBP}) @b{n}
626539 len_rquote = strlen(lquote);
627(@value{GDBP}) @b{n}
628540 @}
629(@value{GDBP}) @b{p len_lquote}
630$3 = 9
631(@value{GDBP}) @b{p len_rquote}
632$4 = 7
633@end smallexample
634
635@noindent
636That certainly looks wrong, assuming @code{len_lquote} and
637@code{len_rquote} are meant to be the lengths of @code{lquote} and
638@code{rquote} respectively. We can set them to better values using
639the @code{p} command, since it can print the value of
640any expression---and that expression can include subroutine calls and
641assignments.
642
643@smallexample
644(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
645$5 = 7
646(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
647$6 = 9
648@end smallexample
649
650@noindent
651Is that enough to fix the problem of using the new quotes with the
652@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
653executing with the @code{c} (@code{continue}) command, and then try the
654example that caused trouble initially:
655
656@smallexample
657(@value{GDBP}) @b{c}
658Continuing.
659
660@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
661
662baz
6630000
664@end smallexample
665
666@noindent
667Success! The new quotes now work just as well as the default ones. The
668problem seems to have been just the two typos defining the wrong
669lengths. We allow @code{m4} exit by giving it an EOF as input:
670
671@smallexample
672@b{C-d}
673Program exited normally.
674@end smallexample
675
676@noindent
677The message @samp{Program exited normally.} is from @value{GDBN}; it
678indicates @code{m4} has finished executing. We can end our @value{GDBN}
679session with the @value{GDBN} @code{quit} command.
680
681@smallexample
682(@value{GDBP}) @b{quit}
683@end smallexample
c906108c 684
6d2ebf8b 685@node Invocation
c906108c
SS
686@chapter Getting In and Out of @value{GDBN}
687
688This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 689The essentials are:
c906108c 690@itemize @bullet
5d161b24 691@item
53a5351d 692type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 693@item
c906108c
SS
694type @kbd{quit} or @kbd{C-d} to exit.
695@end itemize
696
697@menu
698* Invoking GDB:: How to start @value{GDBN}
699* Quitting GDB:: How to quit @value{GDBN}
700* Shell Commands:: How to use shell commands inside @value{GDBN}
701@end menu
702
6d2ebf8b 703@node Invoking GDB
c906108c
SS
704@section Invoking @value{GDBN}
705
c906108c
SS
706Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
707@value{GDBN} reads commands from the terminal until you tell it to exit.
708
709You can also run @code{@value{GDBP}} with a variety of arguments and options,
710to specify more of your debugging environment at the outset.
711
c906108c
SS
712The command-line options described here are designed
713to cover a variety of situations; in some environments, some of these
5d161b24 714options may effectively be unavailable.
c906108c
SS
715
716The most usual way to start @value{GDBN} is with one argument,
717specifying an executable program:
718
719@example
720@value{GDBP} @var{program}
721@end example
722
c906108c
SS
723@noindent
724You can also start with both an executable program and a core file
725specified:
726
727@example
728@value{GDBP} @var{program} @var{core}
729@end example
730
731You can, instead, specify a process ID as a second argument, if you want
732to debug a running process:
733
734@example
735@value{GDBP} @var{program} 1234
736@end example
737
738@noindent
739would attach @value{GDBN} to process @code{1234} (unless you also have a file
740named @file{1234}; @value{GDBN} does check for a core file first).
741
c906108c 742Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
743complete operating system; when you use @value{GDBN} as a remote
744debugger attached to a bare board, there may not be any notion of
745``process'', and there is often no way to get a core dump. @value{GDBN}
746will warn you if it is unable to attach or to read core dumps.
c906108c 747
96a2c332 748You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
749@value{GDBN}'s non-warranty, by specifying @code{-silent}:
750
751@smallexample
752@value{GDBP} -silent
753@end smallexample
754
755@noindent
756You can further control how @value{GDBN} starts up by using command-line
757options. @value{GDBN} itself can remind you of the options available.
758
759@noindent
760Type
761
762@example
763@value{GDBP} -help
764@end example
765
766@noindent
767to display all available options and briefly describe their use
768(@samp{@value{GDBP} -h} is a shorter equivalent).
769
770All options and command line arguments you give are processed
771in sequential order. The order makes a difference when the
772@samp{-x} option is used.
773
774
775@menu
c906108c
SS
776* File Options:: Choosing files
777* Mode Options:: Choosing modes
778@end menu
779
6d2ebf8b 780@node File Options
c906108c
SS
781@subsection Choosing files
782
2df3850c 783When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
784specifying an executable file and core file (or process ID). This is
785the same as if the arguments were specified by the @samp{-se} and
786@samp{-c} options respectively. (@value{GDBN} reads the first argument
787that does not have an associated option flag as equivalent to the
788@samp{-se} option followed by that argument; and the second argument
789that does not have an associated option flag, if any, as equivalent to
790the @samp{-c} option followed by that argument.)
7a292a7a
SS
791
792If @value{GDBN} has not been configured to included core file support,
793such as for most embedded targets, then it will complain about a second
794argument and ignore it.
c906108c
SS
795
796Many options have both long and short forms; both are shown in the
797following list. @value{GDBN} also recognizes the long forms if you truncate
798them, so long as enough of the option is present to be unambiguous.
799(If you prefer, you can flag option arguments with @samp{--} rather
800than @samp{-}, though we illustrate the more usual convention.)
801
d700128c
EZ
802@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
803@c way, both those who look for -foo and --foo in the index, will find
804@c it.
805
c906108c
SS
806@table @code
807@item -symbols @var{file}
808@itemx -s @var{file}
d700128c
EZ
809@cindex @code{--symbols}
810@cindex @code{-s}
c906108c
SS
811Read symbol table from file @var{file}.
812
813@item -exec @var{file}
814@itemx -e @var{file}
d700128c
EZ
815@cindex @code{--exec}
816@cindex @code{-e}
7a292a7a
SS
817Use file @var{file} as the executable file to execute when appropriate,
818and for examining pure data in conjunction with a core dump.
c906108c
SS
819
820@item -se @var{file}
d700128c 821@cindex @code{--se}
c906108c
SS
822Read symbol table from file @var{file} and use it as the executable
823file.
824
c906108c
SS
825@item -core @var{file}
826@itemx -c @var{file}
d700128c
EZ
827@cindex @code{--core}
828@cindex @code{-c}
c906108c
SS
829Use file @var{file} as a core dump to examine.
830
831@item -c @var{number}
832Connect to process ID @var{number}, as with the @code{attach} command
833(unless there is a file in core-dump format named @var{number}, in which
834case @samp{-c} specifies that file as a core dump to read).
c906108c
SS
835
836@item -command @var{file}
837@itemx -x @var{file}
d700128c
EZ
838@cindex @code{--command}
839@cindex @code{-x}
c906108c
SS
840Execute @value{GDBN} commands from file @var{file}. @xref{Command
841Files,, Command files}.
842
843@item -directory @var{directory}
844@itemx -d @var{directory}
d700128c
EZ
845@cindex @code{--directory}
846@cindex @code{-d}
c906108c
SS
847Add @var{directory} to the path to search for source files.
848
c906108c
SS
849@item -m
850@itemx -mapped
d700128c
EZ
851@cindex @code{--mapped}
852@cindex @code{-m}
c906108c
SS
853@emph{Warning: this option depends on operating system facilities that are not
854supported on all systems.}@*
855If memory-mapped files are available on your system through the @code{mmap}
5d161b24 856system call, you can use this option
c906108c
SS
857to have @value{GDBN} write the symbols from your
858program into a reusable file in the current directory. If the program you are debugging is
96a2c332 859called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
860Future @value{GDBN} debugging sessions notice the presence of this file,
861and can quickly map in symbol information from it, rather than reading
862the symbol table from the executable program.
863
864The @file{.syms} file is specific to the host machine where @value{GDBN}
865is run. It holds an exact image of the internal @value{GDBN} symbol
866table. It cannot be shared across multiple host platforms.
c906108c 867
c906108c
SS
868@item -r
869@itemx -readnow
d700128c
EZ
870@cindex @code{--readnow}
871@cindex @code{-r}
c906108c
SS
872Read each symbol file's entire symbol table immediately, rather than
873the default, which is to read it incrementally as it is needed.
874This makes startup slower, but makes future operations faster.
53a5351d 875
c906108c
SS
876@end table
877
2df3850c 878You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 879order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
880information. (@xref{Files,,Commands to specify files}, for information
881on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
882but build a @file{.syms} file for future use is:
c906108c
SS
883
884@example
2df3850c 885gdb -batch -nx -mapped -readnow programname
c906108c 886@end example
c906108c 887
6d2ebf8b 888@node Mode Options
c906108c
SS
889@subsection Choosing modes
890
891You can run @value{GDBN} in various alternative modes---for example, in
892batch mode or quiet mode.
893
894@table @code
895@item -nx
896@itemx -n
d700128c
EZ
897@cindex @code{--nx}
898@cindex @code{-n}
2df3850c
JM
899Do not execute commands found in any initialization files (normally
900called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
901@value{GDBN} executes the commands in these files after all the command
902options and arguments have been processed. @xref{Command Files,,Command
903files}.
c906108c
SS
904
905@item -quiet
d700128c 906@itemx -silent
c906108c 907@itemx -q
d700128c
EZ
908@cindex @code{--quiet}
909@cindex @code{--silent}
910@cindex @code{-q}
c906108c
SS
911``Quiet''. Do not print the introductory and copyright messages. These
912messages are also suppressed in batch mode.
913
914@item -batch
d700128c 915@cindex @code{--batch}
c906108c
SS
916Run in batch mode. Exit with status @code{0} after processing all the
917command files specified with @samp{-x} (and all commands from
918initialization files, if not inhibited with @samp{-n}). Exit with
919nonzero status if an error occurs in executing the @value{GDBN} commands
920in the command files.
921
2df3850c
JM
922Batch mode may be useful for running @value{GDBN} as a filter, for
923example to download and run a program on another computer; in order to
924make this more useful, the message
c906108c
SS
925
926@example
927Program exited normally.
928@end example
929
930@noindent
2df3850c
JM
931(which is ordinarily issued whenever a program running under
932@value{GDBN} control terminates) is not issued when running in batch
933mode.
934
935@item -nowindows
936@itemx -nw
d700128c
EZ
937@cindex @code{--nowindows}
938@cindex @code{-nw}
2df3850c 939``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 940(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
941interface. If no GUI is available, this option has no effect.
942
943@item -windows
944@itemx -w
d700128c
EZ
945@cindex @code{--windows}
946@cindex @code{-w}
2df3850c
JM
947If @value{GDBN} includes a GUI, then this option requires it to be
948used if possible.
c906108c
SS
949
950@item -cd @var{directory}
d700128c 951@cindex @code{--cd}
c906108c
SS
952Run @value{GDBN} using @var{directory} as its working directory,
953instead of the current directory.
954
c906108c
SS
955@item -fullname
956@itemx -f
d700128c
EZ
957@cindex @code{--fullname}
958@cindex @code{-f}
7a292a7a
SS
959@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
960subprocess. It tells @value{GDBN} to output the full file name and line
961number in a standard, recognizable fashion each time a stack frame is
962displayed (which includes each time your program stops). This
963recognizable format looks like two @samp{\032} characters, followed by
964the file name, line number and character position separated by colons,
965and a newline. The Emacs-to-@value{GDBN} interface program uses the two
966@samp{\032} characters as a signal to display the source code for the
967frame.
c906108c 968
d700128c
EZ
969@item -epoch
970@cindex @code{--epoch}
971The Epoch Emacs-@value{GDBN} interface sets this option when it runs
972@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
973routines so as to allow Epoch to display values of expressions in a
974separate window.
975
976@item -annotate @var{level}
977@cindex @code{--annotate}
978This option sets the @dfn{annotation level} inside @value{GDBN}. Its
979effect is identical to using @samp{set annotate @var{level}}
980(@pxref{Annotations}).
981Annotation level controls how much information does @value{GDBN} print
982together with its prompt, values of expressions, source lines, and other
983types of output. Level 0 is the normal, level 1 is for use when
984@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
985maximum annotation suitable for programs that control @value{GDBN}.
986
987@item -async
988@cindex @code{--async}
989Use the asynchronous event loop for the command-line interface.
990@value{GDBN} processes all events, such as user keyboard input, via a
991special event loop. This allows @value{GDBN} to accept and process user
992commands in parallel with the debugged process being
993run@footnote{@value{GDBN} built with @sc{djgpp} tools for
994MS-DOS/MS-Windows supports this mode of operation, but the event loop is
995suspended when the debuggee runs.}, so you don't need to wait for
996control to return to @value{GDBN} before you type the next command.
997(@emph{Note:} as of version 5.0, the target side of the asynchronous
998operation is not yet in place, so @samp{-async} does not work fully
999yet.)
1000@c FIXME: when the target side of the event loop is done, the above NOTE
1001@c should be removed.
1002
1003When the standard input is connected to a terminal device, @value{GDBN}
1004uses the asynchronous event loop by default, unless disabled by the
1005@samp{-noasync} option.
1006
1007@item -noasync
1008@cindex @code{--noasync}
1009Disable the asynchronous event loop for the command-line interface.
1010
2df3850c
JM
1011@item -baud @var{bps}
1012@itemx -b @var{bps}
d700128c
EZ
1013@cindex @code{--baud}
1014@cindex @code{-b}
c906108c
SS
1015Set the line speed (baud rate or bits per second) of any serial
1016interface used by @value{GDBN} for remote debugging.
c906108c
SS
1017
1018@item -tty @var{device}
d700128c
EZ
1019@itemx -t @var{device}
1020@cindex @code{--tty}
1021@cindex @code{-t}
c906108c
SS
1022Run using @var{device} for your program's standard input and output.
1023@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1024
53a5351d
JM
1025@c resolve the situation of these eventually
1026@c @item -tui
d700128c 1027@c @cindex @code{--tui}
53a5351d
JM
1028@c Use a Terminal User Interface. For information, use your Web browser to
1029@c read the file @file{TUI.html}, which is usually installed in the
1030@c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
1031@c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
1032@c @value{GDBN} under @sc{gnu} Emacs}).
1033
1034@c @item -xdb
d700128c 1035@c @cindex @code{--xdb}
53a5351d
JM
1036@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1037@c For information, see the file @file{xdb_trans.html}, which is usually
1038@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1039@c systems.
1040
d700128c
EZ
1041@item -interpreter @var{interp}
1042@cindex @code{--interpreter}
1043Use the interpreter @var{interp} for interface with the controlling
1044program or device. This option is meant to be set by programs which
1045communicate with @value{GDBN} using it as a back end. For example,
1046@samp{--interpreter=mi} causes @value{GDBN} to use the @dfn{gdbmi
7162c0ca 1047interface} (@pxref{GDB/MI, , The @sc{gdb/mi} Interface}).
d700128c
EZ
1048
1049@item -write
1050@cindex @code{--write}
1051Open the executable and core files for both reading and writing. This
1052is equivalent to the @samp{set write on} command inside @value{GDBN}
1053(@pxref{Patching}).
1054
1055@item -statistics
1056@cindex @code{--statistics}
1057This option causes @value{GDBN} to print statistics about time and
1058memory usage after it completes each command and returns to the prompt.
1059
1060@item -version
1061@cindex @code{--version}
1062This option causes @value{GDBN} to print its version number and
1063no-warranty blurb, and exit.
1064
c906108c
SS
1065@end table
1066
6d2ebf8b 1067@node Quitting GDB
c906108c
SS
1068@section Quitting @value{GDBN}
1069@cindex exiting @value{GDBN}
1070@cindex leaving @value{GDBN}
1071
1072@table @code
1073@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1074@kindex q @r{(@code{quit})}
96a2c332
SS
1075@item quit @r{[}@var{expression}@r{]}
1076@itemx q
1077To exit @value{GDBN}, use the @code{quit} command (abbreviated
1078@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1079do not supply @var{expression}, @value{GDBN} will terminate normally;
1080otherwise it will terminate using the result of @var{expression} as the
1081error code.
c906108c
SS
1082@end table
1083
1084@cindex interrupt
1085An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1086terminates the action of any @value{GDBN} command that is in progress and
1087returns to @value{GDBN} command level. It is safe to type the interrupt
1088character at any time because @value{GDBN} does not allow it to take effect
1089until a time when it is safe.
1090
c906108c
SS
1091If you have been using @value{GDBN} to control an attached process or
1092device, you can release it with the @code{detach} command
1093(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1094
6d2ebf8b 1095@node Shell Commands
c906108c
SS
1096@section Shell commands
1097
1098If you need to execute occasional shell commands during your
1099debugging session, there is no need to leave or suspend @value{GDBN}; you can
1100just use the @code{shell} command.
1101
1102@table @code
1103@kindex shell
1104@cindex shell escape
1105@item shell @var{command string}
1106Invoke a standard shell to execute @var{command string}.
c906108c 1107If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1108shell to run. Otherwise @value{GDBN} uses the default shell
1109(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1110@end table
1111
1112The utility @code{make} is often needed in development environments.
1113You do not have to use the @code{shell} command for this purpose in
1114@value{GDBN}:
1115
1116@table @code
1117@kindex make
1118@cindex calling make
1119@item make @var{make-args}
1120Execute the @code{make} program with the specified
1121arguments. This is equivalent to @samp{shell make @var{make-args}}.
1122@end table
1123
6d2ebf8b 1124@node Commands
c906108c
SS
1125@chapter @value{GDBN} Commands
1126
1127You can abbreviate a @value{GDBN} command to the first few letters of the command
1128name, if that abbreviation is unambiguous; and you can repeat certain
1129@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1130key to get @value{GDBN} to fill out the rest of a word in a command (or to
1131show you the alternatives available, if there is more than one possibility).
1132
1133@menu
1134* Command Syntax:: How to give commands to @value{GDBN}
1135* Completion:: Command completion
1136* Help:: How to ask @value{GDBN} for help
1137@end menu
1138
6d2ebf8b 1139@node Command Syntax
c906108c
SS
1140@section Command syntax
1141
1142A @value{GDBN} command is a single line of input. There is no limit on
1143how long it can be. It starts with a command name, which is followed by
1144arguments whose meaning depends on the command name. For example, the
1145command @code{step} accepts an argument which is the number of times to
1146step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1147with no arguments. Some commands do not allow any arguments.
c906108c
SS
1148
1149@cindex abbreviation
1150@value{GDBN} command names may always be truncated if that abbreviation is
1151unambiguous. Other possible command abbreviations are listed in the
1152documentation for individual commands. In some cases, even ambiguous
1153abbreviations are allowed; for example, @code{s} is specially defined as
1154equivalent to @code{step} even though there are other commands whose
1155names start with @code{s}. You can test abbreviations by using them as
1156arguments to the @code{help} command.
1157
1158@cindex repeating commands
41afff9a 1159@kindex RET @r{(repeat last command)}
c906108c 1160A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1161repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1162will not repeat this way; these are commands whose unintentional
1163repetition might cause trouble and which you are unlikely to want to
1164repeat.
1165
1166The @code{list} and @code{x} commands, when you repeat them with
1167@key{RET}, construct new arguments rather than repeating
1168exactly as typed. This permits easy scanning of source or memory.
1169
1170@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1171output, in a way similar to the common utility @code{more}
1172(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1173@key{RET} too many in this situation, @value{GDBN} disables command
1174repetition after any command that generates this sort of display.
1175
41afff9a 1176@kindex # @r{(a comment)}
c906108c
SS
1177@cindex comment
1178Any text from a @kbd{#} to the end of the line is a comment; it does
1179nothing. This is useful mainly in command files (@pxref{Command
1180Files,,Command files}).
1181
6d2ebf8b 1182@node Completion
c906108c
SS
1183@section Command completion
1184
1185@cindex completion
1186@cindex word completion
1187@value{GDBN} can fill in the rest of a word in a command for you, if there is
1188only one possibility; it can also show you what the valid possibilities
1189are for the next word in a command, at any time. This works for @value{GDBN}
1190commands, @value{GDBN} subcommands, and the names of symbols in your program.
1191
1192Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1193of a word. If there is only one possibility, @value{GDBN} fills in the
1194word, and waits for you to finish the command (or press @key{RET} to
1195enter it). For example, if you type
1196
1197@c FIXME "@key" does not distinguish its argument sufficiently to permit
1198@c complete accuracy in these examples; space introduced for clarity.
1199@c If texinfo enhancements make it unnecessary, it would be nice to
1200@c replace " @key" by "@key" in the following...
1201@example
1202(@value{GDBP}) info bre @key{TAB}
1203@end example
1204
1205@noindent
1206@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1207the only @code{info} subcommand beginning with @samp{bre}:
1208
1209@example
1210(@value{GDBP}) info breakpoints
1211@end example
1212
1213@noindent
1214You can either press @key{RET} at this point, to run the @code{info
1215breakpoints} command, or backspace and enter something else, if
1216@samp{breakpoints} does not look like the command you expected. (If you
1217were sure you wanted @code{info breakpoints} in the first place, you
1218might as well just type @key{RET} immediately after @samp{info bre},
1219to exploit command abbreviations rather than command completion).
1220
1221If there is more than one possibility for the next word when you press
1222@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1223characters and try again, or just press @key{TAB} a second time;
1224@value{GDBN} displays all the possible completions for that word. For
1225example, you might want to set a breakpoint on a subroutine whose name
1226begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1227just sounds the bell. Typing @key{TAB} again displays all the
1228function names in your program that begin with those characters, for
1229example:
1230
1231@example
1232(@value{GDBP}) b make_ @key{TAB}
1233@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1234make_a_section_from_file make_environ
1235make_abs_section make_function_type
1236make_blockvector make_pointer_type
1237make_cleanup make_reference_type
c906108c
SS
1238make_command make_symbol_completion_list
1239(@value{GDBP}) b make_
1240@end example
1241
1242@noindent
1243After displaying the available possibilities, @value{GDBN} copies your
1244partial input (@samp{b make_} in the example) so you can finish the
1245command.
1246
1247If you just want to see the list of alternatives in the first place, you
1248can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1249means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1250key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1251one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1252
1253@cindex quotes in commands
1254@cindex completion of quoted strings
1255Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1256parentheses or other characters that @value{GDBN} normally excludes from
1257its notion of a word. To permit word completion to work in this
1258situation, you may enclose words in @code{'} (single quote marks) in
1259@value{GDBN} commands.
c906108c 1260
c906108c
SS
1261The most likely situation where you might need this is in typing the
1262name of a C++ function. This is because C++ allows function overloading
1263(multiple definitions of the same function, distinguished by argument
1264type). For example, when you want to set a breakpoint you may need to
1265distinguish whether you mean the version of @code{name} that takes an
1266@code{int} parameter, @code{name(int)}, or the version that takes a
1267@code{float} parameter, @code{name(float)}. To use the word-completion
1268facilities in this situation, type a single quote @code{'} at the
1269beginning of the function name. This alerts @value{GDBN} that it may need to
1270consider more information than usual when you press @key{TAB} or
1271@kbd{M-?} to request word completion:
1272
1273@example
96a2c332 1274(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1275bubble(double,double) bubble(int,int)
1276(@value{GDBP}) b 'bubble(
1277@end example
1278
1279In some cases, @value{GDBN} can tell that completing a name requires using
1280quotes. When this happens, @value{GDBN} inserts the quote for you (while
1281completing as much as it can) if you do not type the quote in the first
1282place:
1283
1284@example
1285(@value{GDBP}) b bub @key{TAB}
1286@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1287(@value{GDBP}) b 'bubble(
1288@end example
1289
1290@noindent
1291In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1292you have not yet started typing the argument list when you ask for
1293completion on an overloaded symbol.
1294
d4f3574e 1295For more information about overloaded functions, see @ref{C plus plus
c906108c
SS
1296expressions, ,C++ expressions}. You can use the command @code{set
1297overload-resolution off} to disable overload resolution;
d4f3574e 1298see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
c906108c
SS
1299
1300
6d2ebf8b 1301@node Help
c906108c
SS
1302@section Getting help
1303@cindex online documentation
1304@kindex help
1305
5d161b24 1306You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1307using the command @code{help}.
1308
1309@table @code
41afff9a 1310@kindex h @r{(@code{help})}
c906108c
SS
1311@item help
1312@itemx h
1313You can use @code{help} (abbreviated @code{h}) with no arguments to
1314display a short list of named classes of commands:
1315
1316@smallexample
1317(@value{GDBP}) help
1318List of classes of commands:
1319
2df3850c 1320aliases -- Aliases of other commands
c906108c 1321breakpoints -- Making program stop at certain points
2df3850c 1322data -- Examining data
c906108c 1323files -- Specifying and examining files
2df3850c
JM
1324internals -- Maintenance commands
1325obscure -- Obscure features
1326running -- Running the program
1327stack -- Examining the stack
c906108c
SS
1328status -- Status inquiries
1329support -- Support facilities
96a2c332
SS
1330tracepoints -- Tracing of program execution without@*
1331 stopping the program
c906108c 1332user-defined -- User-defined commands
c906108c 1333
5d161b24 1334Type "help" followed by a class name for a list of
c906108c 1335commands in that class.
5d161b24 1336Type "help" followed by command name for full
c906108c
SS
1337documentation.
1338Command name abbreviations are allowed if unambiguous.
1339(@value{GDBP})
1340@end smallexample
96a2c332 1341@c the above line break eliminates huge line overfull...
c906108c
SS
1342
1343@item help @var{class}
1344Using one of the general help classes as an argument, you can get a
1345list of the individual commands in that class. For example, here is the
1346help display for the class @code{status}:
1347
1348@smallexample
1349(@value{GDBP}) help status
1350Status inquiries.
1351
1352List of commands:
1353
1354@c Line break in "show" line falsifies real output, but needed
1355@c to fit in smallbook page size.
2df3850c
JM
1356info -- Generic command for showing things
1357 about the program being debugged
1358show -- Generic command for showing things
1359 about the debugger
c906108c 1360
5d161b24 1361Type "help" followed by command name for full
c906108c
SS
1362documentation.
1363Command name abbreviations are allowed if unambiguous.
1364(@value{GDBP})
1365@end smallexample
1366
1367@item help @var{command}
1368With a command name as @code{help} argument, @value{GDBN} displays a
1369short paragraph on how to use that command.
1370
6837a0a2
DB
1371@kindex apropos
1372@item apropos @var{args}
1373The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1374commands, and their documentation, for the regular expression specified in
1375@var{args}. It prints out all matches found. For example:
1376
1377@smallexample
1378apropos reload
1379@end smallexample
1380
1381@noindent results in:
1382
1383@smallexample
6d2ebf8b
SS
1384@c @group
1385set symbol-reloading -- Set dynamic symbol table reloading
1386 multiple times in one run
1387show symbol-reloading -- Show dynamic symbol table reloading
1388 multiple times in one run
1389@c @end group
6837a0a2
DB
1390@end smallexample
1391
c906108c
SS
1392@kindex complete
1393@item complete @var{args}
1394The @code{complete @var{args}} command lists all the possible completions
1395for the beginning of a command. Use @var{args} to specify the beginning of the
1396command you want completed. For example:
1397
1398@smallexample
1399complete i
1400@end smallexample
1401
1402@noindent results in:
1403
1404@smallexample
1405@group
2df3850c
JM
1406if
1407ignore
c906108c
SS
1408info
1409inspect
c906108c
SS
1410@end group
1411@end smallexample
1412
1413@noindent This is intended for use by @sc{gnu} Emacs.
1414@end table
1415
1416In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1417and @code{show} to inquire about the state of your program, or the state
1418of @value{GDBN} itself. Each command supports many topics of inquiry; this
1419manual introduces each of them in the appropriate context. The listings
1420under @code{info} and under @code{show} in the Index point to
1421all the sub-commands. @xref{Index}.
1422
1423@c @group
1424@table @code
1425@kindex info
41afff9a 1426@kindex i @r{(@code{info})}
c906108c
SS
1427@item info
1428This command (abbreviated @code{i}) is for describing the state of your
1429program. For example, you can list the arguments given to your program
1430with @code{info args}, list the registers currently in use with @code{info
1431registers}, or list the breakpoints you have set with @code{info breakpoints}.
1432You can get a complete list of the @code{info} sub-commands with
1433@w{@code{help info}}.
1434
1435@kindex set
1436@item set
5d161b24 1437You can assign the result of an expression to an environment variable with
c906108c
SS
1438@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1439@code{set prompt $}.
1440
1441@kindex show
1442@item show
5d161b24 1443In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1444@value{GDBN} itself.
1445You can change most of the things you can @code{show}, by using the
1446related command @code{set}; for example, you can control what number
1447system is used for displays with @code{set radix}, or simply inquire
1448which is currently in use with @code{show radix}.
1449
1450@kindex info set
1451To display all the settable parameters and their current
1452values, you can use @code{show} with no arguments; you may also use
1453@code{info set}. Both commands produce the same display.
1454@c FIXME: "info set" violates the rule that "info" is for state of
1455@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1456@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1457@end table
1458@c @end group
1459
1460Here are three miscellaneous @code{show} subcommands, all of which are
1461exceptional in lacking corresponding @code{set} commands:
1462
1463@table @code
1464@kindex show version
1465@cindex version number
1466@item show version
1467Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1468information in @value{GDBN} bug-reports. If multiple versions of
1469@value{GDBN} are in use at your site, you may need to determine which
1470version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1471commands are introduced, and old ones may wither away. Also, many
1472system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1473variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1474The version number is the same as the one announced when you start
1475@value{GDBN}.
c906108c
SS
1476
1477@kindex show copying
1478@item show copying
1479Display information about permission for copying @value{GDBN}.
1480
1481@kindex show warranty
1482@item show warranty
2df3850c 1483Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1484if your version of @value{GDBN} comes with one.
2df3850c 1485
c906108c
SS
1486@end table
1487
6d2ebf8b 1488@node Running
c906108c
SS
1489@chapter Running Programs Under @value{GDBN}
1490
1491When you run a program under @value{GDBN}, you must first generate
1492debugging information when you compile it.
7a292a7a
SS
1493
1494You may start @value{GDBN} with its arguments, if any, in an environment
1495of your choice. If you are doing native debugging, you may redirect
1496your program's input and output, debug an already running process, or
1497kill a child process.
c906108c
SS
1498
1499@menu
1500* Compilation:: Compiling for debugging
1501* Starting:: Starting your program
c906108c
SS
1502* Arguments:: Your program's arguments
1503* Environment:: Your program's environment
c906108c
SS
1504
1505* Working Directory:: Your program's working directory
1506* Input/Output:: Your program's input and output
1507* Attach:: Debugging an already-running process
1508* Kill Process:: Killing the child process
c906108c
SS
1509
1510* Threads:: Debugging programs with multiple threads
1511* Processes:: Debugging programs with multiple processes
1512@end menu
1513
6d2ebf8b 1514@node Compilation
c906108c
SS
1515@section Compiling for debugging
1516
1517In order to debug a program effectively, you need to generate
1518debugging information when you compile it. This debugging information
1519is stored in the object file; it describes the data type of each
1520variable or function and the correspondence between source line numbers
1521and addresses in the executable code.
1522
1523To request debugging information, specify the @samp{-g} option when you run
1524the compiler.
1525
1526Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1527options together. Using those compilers, you cannot generate optimized
1528executables containing debugging information.
1529
53a5351d
JM
1530@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1531without @samp{-O}, making it possible to debug optimized code. We
1532recommend that you @emph{always} use @samp{-g} whenever you compile a
1533program. You may think your program is correct, but there is no sense
1534in pushing your luck.
c906108c
SS
1535
1536@cindex optimized code, debugging
1537@cindex debugging optimized code
1538When you debug a program compiled with @samp{-g -O}, remember that the
1539optimizer is rearranging your code; the debugger shows you what is
1540really there. Do not be too surprised when the execution path does not
1541exactly match your source file! An extreme example: if you define a
1542variable, but never use it, @value{GDBN} never sees that
1543variable---because the compiler optimizes it out of existence.
1544
1545Some things do not work as well with @samp{-g -O} as with just
1546@samp{-g}, particularly on machines with instruction scheduling. If in
1547doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1548please report it to us as a bug (including a test case!).
1549
1550Older versions of the @sc{gnu} C compiler permitted a variant option
1551@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1552format; if your @sc{gnu} C compiler has this option, do not use it.
1553
1554@need 2000
6d2ebf8b 1555@node Starting
c906108c
SS
1556@section Starting your program
1557@cindex starting
1558@cindex running
1559
1560@table @code
1561@kindex run
41afff9a 1562@kindex r @r{(@code{run})}
c906108c
SS
1563@item run
1564@itemx r
7a292a7a
SS
1565Use the @code{run} command to start your program under @value{GDBN}.
1566You must first specify the program name (except on VxWorks) with an
1567argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1568@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1569(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1570
1571@end table
1572
c906108c
SS
1573If you are running your program in an execution environment that
1574supports processes, @code{run} creates an inferior process and makes
1575that process run your program. (In environments without processes,
1576@code{run} jumps to the start of your program.)
1577
1578The execution of a program is affected by certain information it
1579receives from its superior. @value{GDBN} provides ways to specify this
1580information, which you must do @emph{before} starting your program. (You
1581can change it after starting your program, but such changes only affect
1582your program the next time you start it.) This information may be
1583divided into four categories:
1584
1585@table @asis
1586@item The @emph{arguments.}
1587Specify the arguments to give your program as the arguments of the
1588@code{run} command. If a shell is available on your target, the shell
1589is used to pass the arguments, so that you may use normal conventions
1590(such as wildcard expansion or variable substitution) in describing
1591the arguments.
1592In Unix systems, you can control which shell is used with the
1593@code{SHELL} environment variable.
1594@xref{Arguments, ,Your program's arguments}.
1595
1596@item The @emph{environment.}
1597Your program normally inherits its environment from @value{GDBN}, but you can
1598use the @value{GDBN} commands @code{set environment} and @code{unset
1599environment} to change parts of the environment that affect
1600your program. @xref{Environment, ,Your program's environment}.
1601
1602@item The @emph{working directory.}
1603Your program inherits its working directory from @value{GDBN}. You can set
1604the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1605@xref{Working Directory, ,Your program's working directory}.
1606
1607@item The @emph{standard input and output.}
1608Your program normally uses the same device for standard input and
1609standard output as @value{GDBN} is using. You can redirect input and output
1610in the @code{run} command line, or you can use the @code{tty} command to
1611set a different device for your program.
1612@xref{Input/Output, ,Your program's input and output}.
1613
1614@cindex pipes
1615@emph{Warning:} While input and output redirection work, you cannot use
1616pipes to pass the output of the program you are debugging to another
1617program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1618wrong program.
1619@end table
c906108c
SS
1620
1621When you issue the @code{run} command, your program begins to execute
1622immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1623of how to arrange for your program to stop. Once your program has
1624stopped, you may call functions in your program, using the @code{print}
1625or @code{call} commands. @xref{Data, ,Examining Data}.
1626
1627If the modification time of your symbol file has changed since the last
1628time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1629table, and reads it again. When it does this, @value{GDBN} tries to retain
1630your current breakpoints.
1631
6d2ebf8b 1632@node Arguments
c906108c
SS
1633@section Your program's arguments
1634
1635@cindex arguments (to your program)
1636The arguments to your program can be specified by the arguments of the
5d161b24 1637@code{run} command.
c906108c
SS
1638They are passed to a shell, which expands wildcard characters and
1639performs redirection of I/O, and thence to your program. Your
1640@code{SHELL} environment variable (if it exists) specifies what shell
1641@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1642the default shell (@file{/bin/sh} on Unix).
1643
1644On non-Unix systems, the program is usually invoked directly by
1645@value{GDBN}, which emulates I/O redirection via the appropriate system
1646calls, and the wildcard characters are expanded by the startup code of
1647the program, not by the shell.
c906108c
SS
1648
1649@code{run} with no arguments uses the same arguments used by the previous
1650@code{run}, or those set by the @code{set args} command.
1651
c906108c 1652@table @code
41afff9a 1653@kindex set args
c906108c
SS
1654@item set args
1655Specify the arguments to be used the next time your program is run. If
1656@code{set args} has no arguments, @code{run} executes your program
1657with no arguments. Once you have run your program with arguments,
1658using @code{set args} before the next @code{run} is the only way to run
1659it again without arguments.
1660
1661@kindex show args
1662@item show args
1663Show the arguments to give your program when it is started.
1664@end table
1665
6d2ebf8b 1666@node Environment
c906108c
SS
1667@section Your program's environment
1668
1669@cindex environment (of your program)
1670The @dfn{environment} consists of a set of environment variables and
1671their values. Environment variables conventionally record such things as
1672your user name, your home directory, your terminal type, and your search
1673path for programs to run. Usually you set up environment variables with
1674the shell and they are inherited by all the other programs you run. When
1675debugging, it can be useful to try running your program with a modified
1676environment without having to start @value{GDBN} over again.
1677
1678@table @code
1679@kindex path
1680@item path @var{directory}
1681Add @var{directory} to the front of the @code{PATH} environment variable
1682(the search path for executables), for both @value{GDBN} and your program.
d4f3574e
SS
1683You may specify several directory names, separated by whitespace or by a
1684system-dependent separator character (@samp{:} on Unix, @samp{;} on
1685MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1686is moved to the front, so it is searched sooner.
c906108c
SS
1687
1688You can use the string @samp{$cwd} to refer to whatever is the current
1689working directory at the time @value{GDBN} searches the path. If you
1690use @samp{.} instead, it refers to the directory where you executed the
1691@code{path} command. @value{GDBN} replaces @samp{.} in the
1692@var{directory} argument (with the current path) before adding
1693@var{directory} to the search path.
1694@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1695@c document that, since repeating it would be a no-op.
1696
1697@kindex show paths
1698@item show paths
1699Display the list of search paths for executables (the @code{PATH}
1700environment variable).
1701
1702@kindex show environment
1703@item show environment @r{[}@var{varname}@r{]}
1704Print the value of environment variable @var{varname} to be given to
1705your program when it starts. If you do not supply @var{varname},
1706print the names and values of all environment variables to be given to
1707your program. You can abbreviate @code{environment} as @code{env}.
1708
1709@kindex set environment
53a5351d 1710@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1711Set environment variable @var{varname} to @var{value}. The value
1712changes for your program only, not for @value{GDBN} itself. @var{value} may
1713be any string; the values of environment variables are just strings, and
1714any interpretation is supplied by your program itself. The @var{value}
1715parameter is optional; if it is eliminated, the variable is set to a
1716null value.
1717@c "any string" here does not include leading, trailing
1718@c blanks. Gnu asks: does anyone care?
1719
1720For example, this command:
1721
1722@example
1723set env USER = foo
1724@end example
1725
1726@noindent
d4f3574e 1727tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1728@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1729are not actually required.)
1730
1731@kindex unset environment
1732@item unset environment @var{varname}
1733Remove variable @var{varname} from the environment to be passed to your
1734program. This is different from @samp{set env @var{varname} =};
1735@code{unset environment} removes the variable from the environment,
1736rather than assigning it an empty value.
1737@end table
1738
d4f3574e
SS
1739@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1740the shell indicated
c906108c
SS
1741by your @code{SHELL} environment variable if it exists (or
1742@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1743that runs an initialization file---such as @file{.cshrc} for C-shell, or
1744@file{.bashrc} for BASH---any variables you set in that file affect
1745your program. You may wish to move setting of environment variables to
1746files that are only run when you sign on, such as @file{.login} or
1747@file{.profile}.
1748
6d2ebf8b 1749@node Working Directory
c906108c
SS
1750@section Your program's working directory
1751
1752@cindex working directory (of your program)
1753Each time you start your program with @code{run}, it inherits its
1754working directory from the current working directory of @value{GDBN}.
1755The @value{GDBN} working directory is initially whatever it inherited
1756from its parent process (typically the shell), but you can specify a new
1757working directory in @value{GDBN} with the @code{cd} command.
1758
1759The @value{GDBN} working directory also serves as a default for the commands
1760that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1761specify files}.
1762
1763@table @code
1764@kindex cd
1765@item cd @var{directory}
1766Set the @value{GDBN} working directory to @var{directory}.
1767
1768@kindex pwd
1769@item pwd
1770Print the @value{GDBN} working directory.
1771@end table
1772
6d2ebf8b 1773@node Input/Output
c906108c
SS
1774@section Your program's input and output
1775
1776@cindex redirection
1777@cindex i/o
1778@cindex terminal
1779By default, the program you run under @value{GDBN} does input and output to
5d161b24 1780the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1781to its own terminal modes to interact with you, but it records the terminal
1782modes your program was using and switches back to them when you continue
1783running your program.
1784
1785@table @code
1786@kindex info terminal
1787@item info terminal
1788Displays information recorded by @value{GDBN} about the terminal modes your
1789program is using.
1790@end table
1791
1792You can redirect your program's input and/or output using shell
1793redirection with the @code{run} command. For example,
1794
1795@example
1796run > outfile
1797@end example
1798
1799@noindent
1800starts your program, diverting its output to the file @file{outfile}.
1801
1802@kindex tty
1803@cindex controlling terminal
1804Another way to specify where your program should do input and output is
1805with the @code{tty} command. This command accepts a file name as
1806argument, and causes this file to be the default for future @code{run}
1807commands. It also resets the controlling terminal for the child
1808process, for future @code{run} commands. For example,
1809
1810@example
1811tty /dev/ttyb
1812@end example
1813
1814@noindent
1815directs that processes started with subsequent @code{run} commands
1816default to do input and output on the terminal @file{/dev/ttyb} and have
1817that as their controlling terminal.
1818
1819An explicit redirection in @code{run} overrides the @code{tty} command's
1820effect on the input/output device, but not its effect on the controlling
1821terminal.
1822
1823When you use the @code{tty} command or redirect input in the @code{run}
1824command, only the input @emph{for your program} is affected. The input
1825for @value{GDBN} still comes from your terminal.
1826
6d2ebf8b 1827@node Attach
c906108c
SS
1828@section Debugging an already-running process
1829@kindex attach
1830@cindex attach
1831
1832@table @code
1833@item attach @var{process-id}
1834This command attaches to a running process---one that was started
1835outside @value{GDBN}. (@code{info files} shows your active
1836targets.) The command takes as argument a process ID. The usual way to
1837find out the process-id of a Unix process is with the @code{ps} utility,
1838or with the @samp{jobs -l} shell command.
1839
1840@code{attach} does not repeat if you press @key{RET} a second time after
1841executing the command.
1842@end table
1843
1844To use @code{attach}, your program must be running in an environment
1845which supports processes; for example, @code{attach} does not work for
1846programs on bare-board targets that lack an operating system. You must
1847also have permission to send the process a signal.
1848
1849When you use @code{attach}, the debugger finds the program running in
1850the process first by looking in the current working directory, then (if
1851the program is not found) by using the source file search path
1852(@pxref{Source Path, ,Specifying source directories}). You can also use
1853the @code{file} command to load the program. @xref{Files, ,Commands to
1854Specify Files}.
1855
1856The first thing @value{GDBN} does after arranging to debug the specified
1857process is to stop it. You can examine and modify an attached process
53a5351d
JM
1858with all the @value{GDBN} commands that are ordinarily available when
1859you start processes with @code{run}. You can insert breakpoints; you
1860can step and continue; you can modify storage. If you would rather the
1861process continue running, you may use the @code{continue} command after
c906108c
SS
1862attaching @value{GDBN} to the process.
1863
1864@table @code
1865@kindex detach
1866@item detach
1867When you have finished debugging the attached process, you can use the
1868@code{detach} command to release it from @value{GDBN} control. Detaching
1869the process continues its execution. After the @code{detach} command,
1870that process and @value{GDBN} become completely independent once more, and you
1871are ready to @code{attach} another process or start one with @code{run}.
1872@code{detach} does not repeat if you press @key{RET} again after
1873executing the command.
1874@end table
1875
1876If you exit @value{GDBN} or use the @code{run} command while you have an
1877attached process, you kill that process. By default, @value{GDBN} asks
1878for confirmation if you try to do either of these things; you can
1879control whether or not you need to confirm by using the @code{set
1880confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1881messages}).
1882
6d2ebf8b 1883@node Kill Process
c906108c 1884@section Killing the child process
c906108c
SS
1885
1886@table @code
1887@kindex kill
1888@item kill
1889Kill the child process in which your program is running under @value{GDBN}.
1890@end table
1891
1892This command is useful if you wish to debug a core dump instead of a
1893running process. @value{GDBN} ignores any core dump file while your program
1894is running.
1895
1896On some operating systems, a program cannot be executed outside @value{GDBN}
1897while you have breakpoints set on it inside @value{GDBN}. You can use the
1898@code{kill} command in this situation to permit running your program
1899outside the debugger.
1900
1901The @code{kill} command is also useful if you wish to recompile and
1902relink your program, since on many systems it is impossible to modify an
1903executable file while it is running in a process. In this case, when you
1904next type @code{run}, @value{GDBN} notices that the file has changed, and
1905reads the symbol table again (while trying to preserve your current
1906breakpoint settings).
1907
6d2ebf8b 1908@node Threads
c906108c 1909@section Debugging programs with multiple threads
c906108c
SS
1910
1911@cindex threads of execution
1912@cindex multiple threads
1913@cindex switching threads
1914In some operating systems, such as HP-UX and Solaris, a single program
1915may have more than one @dfn{thread} of execution. The precise semantics
1916of threads differ from one operating system to another, but in general
1917the threads of a single program are akin to multiple processes---except
1918that they share one address space (that is, they can all examine and
1919modify the same variables). On the other hand, each thread has its own
1920registers and execution stack, and perhaps private memory.
1921
1922@value{GDBN} provides these facilities for debugging multi-thread
1923programs:
1924
1925@itemize @bullet
1926@item automatic notification of new threads
1927@item @samp{thread @var{threadno}}, a command to switch among threads
1928@item @samp{info threads}, a command to inquire about existing threads
5d161b24 1929@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
1930a command to apply a command to a list of threads
1931@item thread-specific breakpoints
1932@end itemize
1933
c906108c
SS
1934@quotation
1935@emph{Warning:} These facilities are not yet available on every
1936@value{GDBN} configuration where the operating system supports threads.
1937If your @value{GDBN} does not support threads, these commands have no
1938effect. For example, a system without thread support shows no output
1939from @samp{info threads}, and always rejects the @code{thread} command,
1940like this:
1941
1942@smallexample
1943(@value{GDBP}) info threads
1944(@value{GDBP}) thread 1
1945Thread ID 1 not known. Use the "info threads" command to
1946see the IDs of currently known threads.
1947@end smallexample
1948@c FIXME to implementors: how hard would it be to say "sorry, this GDB
1949@c doesn't support threads"?
1950@end quotation
c906108c
SS
1951
1952@cindex focus of debugging
1953@cindex current thread
1954The @value{GDBN} thread debugging facility allows you to observe all
1955threads while your program runs---but whenever @value{GDBN} takes
1956control, one thread in particular is always the focus of debugging.
1957This thread is called the @dfn{current thread}. Debugging commands show
1958program information from the perspective of the current thread.
1959
41afff9a 1960@cindex @code{New} @var{systag} message
c906108c
SS
1961@cindex thread identifier (system)
1962@c FIXME-implementors!! It would be more helpful if the [New...] message
1963@c included GDB's numeric thread handle, so you could just go to that
1964@c thread without first checking `info threads'.
1965Whenever @value{GDBN} detects a new thread in your program, it displays
1966the target system's identification for the thread with a message in the
1967form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1968whose form varies depending on the particular system. For example, on
1969LynxOS, you might see
1970
1971@example
1972[New process 35 thread 27]
1973@end example
1974
1975@noindent
1976when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1977the @var{systag} is simply something like @samp{process 368}, with no
1978further qualifier.
1979
1980@c FIXME!! (1) Does the [New...] message appear even for the very first
1981@c thread of a program, or does it only appear for the
1982@c second---i.e., when it becomes obvious we have a multithread
1983@c program?
1984@c (2) *Is* there necessarily a first thread always? Or do some
1985@c multithread systems permit starting a program with multiple
5d161b24 1986@c threads ab initio?
c906108c
SS
1987
1988@cindex thread number
1989@cindex thread identifier (GDB)
1990For debugging purposes, @value{GDBN} associates its own thread
1991number---always a single integer---with each thread in your program.
1992
1993@table @code
1994@kindex info threads
1995@item info threads
1996Display a summary of all threads currently in your
1997program. @value{GDBN} displays for each thread (in this order):
1998
1999@enumerate
2000@item the thread number assigned by @value{GDBN}
2001
2002@item the target system's thread identifier (@var{systag})
2003
2004@item the current stack frame summary for that thread
2005@end enumerate
2006
2007@noindent
2008An asterisk @samp{*} to the left of the @value{GDBN} thread number
2009indicates the current thread.
2010
5d161b24 2011For example,
c906108c
SS
2012@end table
2013@c end table here to get a little more width for example
2014
2015@smallexample
2016(@value{GDBP}) info threads
2017 3 process 35 thread 27 0x34e5 in sigpause ()
2018 2 process 35 thread 23 0x34e5 in sigpause ()
2019* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2020 at threadtest.c:68
2021@end smallexample
53a5351d
JM
2022
2023On HP-UX systems:
c906108c
SS
2024
2025@cindex thread number
2026@cindex thread identifier (GDB)
2027For debugging purposes, @value{GDBN} associates its own thread
2028number---a small integer assigned in thread-creation order---with each
2029thread in your program.
2030
41afff9a
EZ
2031@cindex @code{New} @var{systag} message, on HP-UX
2032@cindex thread identifier (system), on HP-UX
c906108c
SS
2033@c FIXME-implementors!! It would be more helpful if the [New...] message
2034@c included GDB's numeric thread handle, so you could just go to that
2035@c thread without first checking `info threads'.
2036Whenever @value{GDBN} detects a new thread in your program, it displays
2037both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2038form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2039whose form varies depending on the particular system. For example, on
2040HP-UX, you see
2041
2042@example
2043[New thread 2 (system thread 26594)]
2044@end example
2045
2046@noindent
5d161b24 2047when @value{GDBN} notices a new thread.
c906108c
SS
2048
2049@table @code
2050@kindex info threads
2051@item info threads
2052Display a summary of all threads currently in your
2053program. @value{GDBN} displays for each thread (in this order):
2054
2055@enumerate
2056@item the thread number assigned by @value{GDBN}
2057
2058@item the target system's thread identifier (@var{systag})
2059
2060@item the current stack frame summary for that thread
2061@end enumerate
2062
2063@noindent
2064An asterisk @samp{*} to the left of the @value{GDBN} thread number
2065indicates the current thread.
2066
5d161b24 2067For example,
c906108c
SS
2068@end table
2069@c end table here to get a little more width for example
2070
2071@example
2072(@value{GDBP}) info threads
6d2ebf8b
SS
2073 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2074 at quicksort.c:137
2075 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2076 from /usr/lib/libc.2
2077 1 system thread 27905 0x7b003498 in _brk () \@*
2078 from /usr/lib/libc.2
c906108c 2079@end example
c906108c
SS
2080
2081@table @code
2082@kindex thread @var{threadno}
2083@item thread @var{threadno}
2084Make thread number @var{threadno} the current thread. The command
2085argument @var{threadno} is the internal @value{GDBN} thread number, as
2086shown in the first field of the @samp{info threads} display.
2087@value{GDBN} responds by displaying the system identifier of the thread
2088you selected, and its current stack frame summary:
2089
2090@smallexample
2091@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2092(@value{GDBP}) thread 2
c906108c 2093[Switching to process 35 thread 23]
c906108c
SS
20940x34e5 in sigpause ()
2095@end smallexample
2096
2097@noindent
2098As with the @samp{[New @dots{}]} message, the form of the text after
2099@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2100threads.
c906108c
SS
2101
2102@kindex thread apply
2103@item thread apply [@var{threadno}] [@var{all}] @var{args}
2104The @code{thread apply} command allows you to apply a command to one or
2105more threads. Specify the numbers of the threads that you want affected
2106with the command argument @var{threadno}. @var{threadno} is the internal
2107@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2108threads} display. To apply a command to all threads, use
2109@code{thread apply all} @var{args}.
c906108c
SS
2110@end table
2111
2112@cindex automatic thread selection
2113@cindex switching threads automatically
2114@cindex threads, automatic switching
2115Whenever @value{GDBN} stops your program, due to a breakpoint or a
2116signal, it automatically selects the thread where that breakpoint or
2117signal happened. @value{GDBN} alerts you to the context switch with a
2118message of the form @samp{[Switching to @var{systag}]} to identify the
2119thread.
2120
2121@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2122more information about how @value{GDBN} behaves when you stop and start
2123programs with multiple threads.
2124
2125@xref{Set Watchpoints,,Setting watchpoints}, for information about
2126watchpoints in programs with multiple threads.
c906108c 2127
6d2ebf8b 2128@node Processes
c906108c
SS
2129@section Debugging programs with multiple processes
2130
2131@cindex fork, debugging programs which call
2132@cindex multiple processes
2133@cindex processes, multiple
53a5351d
JM
2134On most systems, @value{GDBN} has no special support for debugging
2135programs which create additional processes using the @code{fork}
2136function. When a program forks, @value{GDBN} will continue to debug the
2137parent process and the child process will run unimpeded. If you have
2138set a breakpoint in any code which the child then executes, the child
2139will get a @code{SIGTRAP} signal which (unless it catches the signal)
2140will cause it to terminate.
c906108c
SS
2141
2142However, if you want to debug the child process there is a workaround
2143which isn't too painful. Put a call to @code{sleep} in the code which
2144the child process executes after the fork. It may be useful to sleep
2145only if a certain environment variable is set, or a certain file exists,
2146so that the delay need not occur when you don't want to run @value{GDBN}
2147on the child. While the child is sleeping, use the @code{ps} program to
2148get its process ID. Then tell @value{GDBN} (a new invocation of
2149@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2150the child process (@pxref{Attach}). From that point on you can debug
c906108c 2151the child process just like any other process which you attached to.
c906108c 2152
53a5351d
JM
2153On HP-UX (11.x and later only?), @value{GDBN} provides support for
2154debugging programs that create additional processes using the
2155@code{fork} or @code{vfork} function.
c906108c
SS
2156
2157By default, when a program forks, @value{GDBN} will continue to debug
2158the parent process and the child process will run unimpeded.
2159
2160If you want to follow the child process instead of the parent process,
2161use the command @w{@code{set follow-fork-mode}}.
2162
2163@table @code
2164@kindex set follow-fork-mode
2165@item set follow-fork-mode @var{mode}
2166Set the debugger response to a program call of @code{fork} or
2167@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2168process. The @var{mode} can be:
2169
2170@table @code
2171@item parent
2172The original process is debugged after a fork. The child process runs
2df3850c 2173unimpeded. This is the default.
c906108c
SS
2174
2175@item child
2176The new process is debugged after a fork. The parent process runs
2177unimpeded.
2178
2179@item ask
2180The debugger will ask for one of the above choices.
2181@end table
2182
2183@item show follow-fork-mode
2df3850c 2184Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2185@end table
2186
2187If you ask to debug a child process and a @code{vfork} is followed by an
2188@code{exec}, @value{GDBN} executes the new target up to the first
2189breakpoint in the new target. If you have a breakpoint set on
2190@code{main} in your original program, the breakpoint will also be set on
2191the child process's @code{main}.
2192
2193When a child process is spawned by @code{vfork}, you cannot debug the
2194child or parent until an @code{exec} call completes.
2195
2196If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2197call executes, the new target restarts. To restart the parent process,
2198use the @code{file} command with the parent executable name as its
2199argument.
2200
2201You can use the @code{catch} command to make @value{GDBN} stop whenever
2202a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2203Catchpoints, ,Setting catchpoints}.
c906108c 2204
6d2ebf8b 2205@node Stopping
c906108c
SS
2206@chapter Stopping and Continuing
2207
2208The principal purposes of using a debugger are so that you can stop your
2209program before it terminates; or so that, if your program runs into
2210trouble, you can investigate and find out why.
2211
7a292a7a
SS
2212Inside @value{GDBN}, your program may stop for any of several reasons,
2213such as a signal, a breakpoint, or reaching a new line after a
2214@value{GDBN} command such as @code{step}. You may then examine and
2215change variables, set new breakpoints or remove old ones, and then
2216continue execution. Usually, the messages shown by @value{GDBN} provide
2217ample explanation of the status of your program---but you can also
2218explicitly request this information at any time.
c906108c
SS
2219
2220@table @code
2221@kindex info program
2222@item info program
2223Display information about the status of your program: whether it is
7a292a7a 2224running or not, what process it is, and why it stopped.
c906108c
SS
2225@end table
2226
2227@menu
2228* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2229* Continuing and Stepping:: Resuming execution
c906108c 2230* Signals:: Signals
c906108c 2231* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2232@end menu
2233
6d2ebf8b 2234@node Breakpoints
c906108c
SS
2235@section Breakpoints, watchpoints, and catchpoints
2236
2237@cindex breakpoints
2238A @dfn{breakpoint} makes your program stop whenever a certain point in
2239the program is reached. For each breakpoint, you can add conditions to
2240control in finer detail whether your program stops. You can set
2241breakpoints with the @code{break} command and its variants (@pxref{Set
2242Breaks, ,Setting breakpoints}), to specify the place where your program
2243should stop by line number, function name or exact address in the
2244program.
2245
2246In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2247breakpoints in shared libraries before the executable is run. There is
2248a minor limitation on HP-UX systems: you must wait until the executable
2249is run in order to set breakpoints in shared library routines that are
2250not called directly by the program (for example, routines that are
2251arguments in a @code{pthread_create} call).
2252
2253@cindex watchpoints
2254@cindex memory tracing
2255@cindex breakpoint on memory address
2256@cindex breakpoint on variable modification
2257A @dfn{watchpoint} is a special breakpoint that stops your program
2258when the value of an expression changes. You must use a different
2259command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2260watchpoints}), but aside from that, you can manage a watchpoint like
2261any other breakpoint: you enable, disable, and delete both breakpoints
2262and watchpoints using the same commands.
2263
2264You can arrange to have values from your program displayed automatically
2265whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2266Automatic display}.
2267
2268@cindex catchpoints
2269@cindex breakpoint on events
2270A @dfn{catchpoint} is another special breakpoint that stops your program
2271when a certain kind of event occurs, such as the throwing of a C++
2272exception or the loading of a library. As with watchpoints, you use a
2273different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2274catchpoints}), but aside from that, you can manage a catchpoint like any
2275other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2276@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2277
2278@cindex breakpoint numbers
2279@cindex numbers for breakpoints
2280@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2281catchpoint when you create it; these numbers are successive integers
2282starting with one. In many of the commands for controlling various
2283features of breakpoints you use the breakpoint number to say which
2284breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2285@dfn{disabled}; if disabled, it has no effect on your program until you
2286enable it again.
2287
c5394b80
JM
2288@cindex breakpoint ranges
2289@cindex ranges of breakpoints
2290Some @value{GDBN} commands accept a range of breakpoints on which to
2291operate. A breakpoint range is either a single breakpoint number, like
2292@samp{5}, or two such numbers, in increasing order, separated by a
2293hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2294all breakpoint in that range are operated on.
2295
c906108c
SS
2296@menu
2297* Set Breaks:: Setting breakpoints
2298* Set Watchpoints:: Setting watchpoints
2299* Set Catchpoints:: Setting catchpoints
2300* Delete Breaks:: Deleting breakpoints
2301* Disabling:: Disabling breakpoints
2302* Conditions:: Break conditions
2303* Break Commands:: Breakpoint command lists
c906108c 2304* Breakpoint Menus:: Breakpoint menus
d4f3574e 2305* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2306@end menu
2307
6d2ebf8b 2308@node Set Breaks
c906108c
SS
2309@subsection Setting breakpoints
2310
5d161b24 2311@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2312@c consider in particular declaration with/without initialization.
2313@c
2314@c FIXME 2 is there stuff on this already? break at fun start, already init?
2315
2316@kindex break
41afff9a
EZ
2317@kindex b @r{(@code{break})}
2318@vindex $bpnum@r{, convenience variable}
c906108c
SS
2319@cindex latest breakpoint
2320Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2321@code{b}). The debugger convenience variable @samp{$bpnum} records the
c906108c
SS
2322number of the breakpoints you've set most recently; see @ref{Convenience
2323Vars,, Convenience variables}, for a discussion of what you can do with
2324convenience variables.
2325
2326You have several ways to say where the breakpoint should go.
2327
2328@table @code
2329@item break @var{function}
5d161b24 2330Set a breakpoint at entry to function @var{function}.
c906108c
SS
2331When using source languages that permit overloading of symbols, such as
2332C++, @var{function} may refer to more than one possible place to break.
2333@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2334
2335@item break +@var{offset}
2336@itemx break -@var{offset}
2337Set a breakpoint some number of lines forward or back from the position
d4f3574e 2338at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2339(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2340
2341@item break @var{linenum}
2342Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2343The current source file is the last file whose source text was printed.
2344The breakpoint will stop your program just before it executes any of the
c906108c
SS
2345code on that line.
2346
2347@item break @var{filename}:@var{linenum}
2348Set a breakpoint at line @var{linenum} in source file @var{filename}.
2349
2350@item break @var{filename}:@var{function}
2351Set a breakpoint at entry to function @var{function} found in file
2352@var{filename}. Specifying a file name as well as a function name is
2353superfluous except when multiple files contain similarly named
2354functions.
2355
2356@item break *@var{address}
2357Set a breakpoint at address @var{address}. You can use this to set
2358breakpoints in parts of your program which do not have debugging
2359information or source files.
2360
2361@item break
2362When called without any arguments, @code{break} sets a breakpoint at
2363the next instruction to be executed in the selected stack frame
2364(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2365innermost, this makes your program stop as soon as control
2366returns to that frame. This is similar to the effect of a
2367@code{finish} command in the frame inside the selected frame---except
2368that @code{finish} does not leave an active breakpoint. If you use
2369@code{break} without an argument in the innermost frame, @value{GDBN} stops
2370the next time it reaches the current location; this may be useful
2371inside loops.
2372
2373@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2374least one instruction has been executed. If it did not do this, you
2375would be unable to proceed past a breakpoint without first disabling the
2376breakpoint. This rule applies whether or not the breakpoint already
2377existed when your program stopped.
2378
2379@item break @dots{} if @var{cond}
2380Set a breakpoint with condition @var{cond}; evaluate the expression
2381@var{cond} each time the breakpoint is reached, and stop only if the
2382value is nonzero---that is, if @var{cond} evaluates as true.
2383@samp{@dots{}} stands for one of the possible arguments described
2384above (or no argument) specifying where to break. @xref{Conditions,
2385,Break conditions}, for more information on breakpoint conditions.
2386
2387@kindex tbreak
2388@item tbreak @var{args}
2389Set a breakpoint enabled only for one stop. @var{args} are the
2390same as for the @code{break} command, and the breakpoint is set in the same
2391way, but the breakpoint is automatically deleted after the first time your
2392program stops there. @xref{Disabling, ,Disabling breakpoints}.
2393
c906108c
SS
2394@kindex hbreak
2395@item hbreak @var{args}
d4f3574e
SS
2396Set a hardware-assisted breakpoint. @var{args} are the same as for the
2397@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2398breakpoint requires hardware support and some target hardware may not
2399have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2400debugging, so you can set a breakpoint at an instruction without
2401changing the instruction. This can be used with the new trap-generation
2402provided by SPARClite DSU and some x86-based targets. These targets
2403will generate traps when a program accesses some data or instruction
2404address that is assigned to the debug registers. However the hardware
2405breakpoint registers can take a limited number of breakpoints. For
2406example, on the DSU, only two data breakpoints can be set at a time, and
2407@value{GDBN} will reject this command if more than two are used. Delete
2408or disable unused hardware breakpoints before setting new ones
2409(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2410
2411@kindex thbreak
2412@item thbreak @var{args}
2413Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2414are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2415the same way. However, like the @code{tbreak} command,
c906108c
SS
2416the breakpoint is automatically deleted after the
2417first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2418command, the breakpoint requires hardware support and some target hardware
2419may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2420See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2421
2422@kindex rbreak
2423@cindex regular expression
2424@item rbreak @var{regex}
c906108c 2425Set breakpoints on all functions matching the regular expression
11cf8741
JM
2426@var{regex}. This command sets an unconditional breakpoint on all
2427matches, printing a list of all breakpoints it set. Once these
2428breakpoints are set, they are treated just like the breakpoints set with
2429the @code{break} command. You can delete them, disable them, or make
2430them conditional the same way as any other breakpoint.
2431
2432The syntax of the regular expression is the standard one used with tools
2433like @file{grep}. Note that this is different from the syntax used by
2434shells, so for instance @code{foo*} matches all functions that include
2435an @code{fo} followed by zero or more @code{o}s. There is an implicit
2436@code{.*} leading and trailing the regular expression you supply, so to
2437match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2438
c906108c
SS
2439When debugging C++ programs, @code{rbreak} is useful for setting
2440breakpoints on overloaded functions that are not members of any special
2441classes.
c906108c
SS
2442
2443@kindex info breakpoints
2444@cindex @code{$_} and @code{info breakpoints}
2445@item info breakpoints @r{[}@var{n}@r{]}
2446@itemx info break @r{[}@var{n}@r{]}
2447@itemx info watchpoints @r{[}@var{n}@r{]}
2448Print a table of all breakpoints, watchpoints, and catchpoints set and
2449not deleted, with the following columns for each breakpoint:
2450
2451@table @emph
2452@item Breakpoint Numbers
2453@item Type
2454Breakpoint, watchpoint, or catchpoint.
2455@item Disposition
2456Whether the breakpoint is marked to be disabled or deleted when hit.
2457@item Enabled or Disabled
2458Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2459that are not enabled.
2460@item Address
2df3850c 2461Where the breakpoint is in your program, as a memory address.
c906108c
SS
2462@item What
2463Where the breakpoint is in the source for your program, as a file and
2464line number.
2465@end table
2466
2467@noindent
2468If a breakpoint is conditional, @code{info break} shows the condition on
2469the line following the affected breakpoint; breakpoint commands, if any,
2470are listed after that.
2471
2472@noindent
2473@code{info break} with a breakpoint
2474number @var{n} as argument lists only that breakpoint. The
2475convenience variable @code{$_} and the default examining-address for
2476the @code{x} command are set to the address of the last breakpoint
5d161b24 2477listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2478
2479@noindent
2480@code{info break} displays a count of the number of times the breakpoint
2481has been hit. This is especially useful in conjunction with the
2482@code{ignore} command. You can ignore a large number of breakpoint
2483hits, look at the breakpoint info to see how many times the breakpoint
2484was hit, and then run again, ignoring one less than that number. This
2485will get you quickly to the last hit of that breakpoint.
2486@end table
2487
2488@value{GDBN} allows you to set any number of breakpoints at the same place in
2489your program. There is nothing silly or meaningless about this. When
2490the breakpoints are conditional, this is even useful
2491(@pxref{Conditions, ,Break conditions}).
2492
2493@cindex negative breakpoint numbers
2494@cindex internal @value{GDBN} breakpoints
2495@value{GDBN} itself sometimes sets breakpoints in your program for special
2496purposes, such as proper handling of @code{longjmp} (in C programs).
2497These internal breakpoints are assigned negative numbers, starting with
2498@code{-1}; @samp{info breakpoints} does not display them.
2499
2500You can see these breakpoints with the @value{GDBN} maintenance command
2501@samp{maint info breakpoints}.
2502
2503@table @code
2504@kindex maint info breakpoints
2505@item maint info breakpoints
2506Using the same format as @samp{info breakpoints}, display both the
2507breakpoints you've set explicitly, and those @value{GDBN} is using for
2508internal purposes. Internal breakpoints are shown with negative
2509breakpoint numbers. The type column identifies what kind of breakpoint
2510is shown:
2511
2512@table @code
2513@item breakpoint
2514Normal, explicitly set breakpoint.
2515
2516@item watchpoint
2517Normal, explicitly set watchpoint.
2518
2519@item longjmp
2520Internal breakpoint, used to handle correctly stepping through
2521@code{longjmp} calls.
2522
2523@item longjmp resume
2524Internal breakpoint at the target of a @code{longjmp}.
2525
2526@item until
2527Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2528
2529@item finish
2530Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2531
c906108c
SS
2532@item shlib events
2533Shared library events.
53a5351d 2534
c906108c 2535@end table
53a5351d 2536
c906108c
SS
2537@end table
2538
2539
6d2ebf8b 2540@node Set Watchpoints
c906108c
SS
2541@subsection Setting watchpoints
2542
2543@cindex setting watchpoints
2544@cindex software watchpoints
2545@cindex hardware watchpoints
2546You can use a watchpoint to stop execution whenever the value of an
2547expression changes, without having to predict a particular place where
2548this may happen.
2549
2550Depending on your system, watchpoints may be implemented in software or
2df3850c 2551hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2552program and testing the variable's value each time, which is hundreds of
2553times slower than normal execution. (But this may still be worth it, to
2554catch errors where you have no clue what part of your program is the
2555culprit.)
2556
d4f3574e 2557On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2558@value{GDBN} includes support for
c906108c
SS
2559hardware watchpoints, which do not slow down the running of your
2560program.
2561
2562@table @code
2563@kindex watch
2564@item watch @var{expr}
2565Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2566is written into by the program and its value changes.
2567
2568@kindex rwatch
2569@item rwatch @var{expr}
2570Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2571
2572@kindex awatch
2573@item awatch @var{expr}
2df3850c 2574Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2575by the program.
c906108c
SS
2576
2577@kindex info watchpoints
2578@item info watchpoints
2579This command prints a list of watchpoints, breakpoints, and catchpoints;
2580it is the same as @code{info break}.
2581@end table
2582
2583@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2584watchpoints execute very quickly, and the debugger reports a change in
2585value at the exact instruction where the change occurs. If @value{GDBN}
2586cannot set a hardware watchpoint, it sets a software watchpoint, which
2587executes more slowly and reports the change in value at the next
2588statement, not the instruction, after the change occurs.
2589
2590When you issue the @code{watch} command, @value{GDBN} reports
2591
2592@example
2593Hardware watchpoint @var{num}: @var{expr}
2594@end example
2595
2596@noindent
2597if it was able to set a hardware watchpoint.
2598
7be570e7
JM
2599Currently, the @code{awatch} and @code{rwatch} commands can only set
2600hardware watchpoints, because accesses to data that don't change the
2601value of the watched expression cannot be detected without examining
2602every instruction as it is being executed, and @value{GDBN} does not do
2603that currently. If @value{GDBN} finds that it is unable to set a
2604hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2605will print a message like this:
2606
2607@smallexample
2608Expression cannot be implemented with read/access watchpoint.
2609@end smallexample
2610
2611Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2612data type of the watched expression is wider than what a hardware
2613watchpoint on the target machine can handle. For example, some systems
2614can only watch regions that are up to 4 bytes wide; on such systems you
2615cannot set hardware watchpoints for an expression that yields a
2616double-precision floating-point number (which is typically 8 bytes
2617wide). As a work-around, it might be possible to break the large region
2618into a series of smaller ones and watch them with separate watchpoints.
2619
2620If you set too many hardware watchpoints, @value{GDBN} might be unable
2621to insert all of them when you resume the execution of your program.
2622Since the precise number of active watchpoints is unknown until such
2623time as the program is about to be resumed, @value{GDBN} might not be
2624able to warn you about this when you set the watchpoints, and the
2625warning will be printed only when the program is resumed:
2626
2627@smallexample
2628Hardware watchpoint @var{num}: Could not insert watchpoint
2629@end smallexample
2630
2631@noindent
2632If this happens, delete or disable some of the watchpoints.
2633
2634The SPARClite DSU will generate traps when a program accesses some data
2635or instruction address that is assigned to the debug registers. For the
2636data addresses, DSU facilitates the @code{watch} command. However the
2637hardware breakpoint registers can only take two data watchpoints, and
2638both watchpoints must be the same kind. For example, you can set two
2639watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2640@strong{or} two with @code{awatch} commands, but you cannot set one
2641watchpoint with one command and the other with a different command.
c906108c
SS
2642@value{GDBN} will reject the command if you try to mix watchpoints.
2643Delete or disable unused watchpoint commands before setting new ones.
2644
2645If you call a function interactively using @code{print} or @code{call},
2df3850c 2646any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2647kind of breakpoint or the call completes.
2648
7be570e7
JM
2649@value{GDBN} automatically deletes watchpoints that watch local
2650(automatic) variables, or expressions that involve such variables, when
2651they go out of scope, that is, when the execution leaves the block in
2652which these variables were defined. In particular, when the program
2653being debugged terminates, @emph{all} local variables go out of scope,
2654and so only watchpoints that watch global variables remain set. If you
2655rerun the program, you will need to set all such watchpoints again. One
2656way of doing that would be to set a code breakpoint at the entry to the
2657@code{main} function and when it breaks, set all the watchpoints.
2658
c906108c
SS
2659@quotation
2660@cindex watchpoints and threads
2661@cindex threads and watchpoints
c906108c
SS
2662@emph{Warning:} In multi-thread programs, watchpoints have only limited
2663usefulness. With the current watchpoint implementation, @value{GDBN}
2664can only watch the value of an expression @emph{in a single thread}. If
2665you are confident that the expression can only change due to the current
2666thread's activity (and if you are also confident that no other thread
2667can become current), then you can use watchpoints as usual. However,
2668@value{GDBN} may not notice when a non-current thread's activity changes
2669the expression.
53a5351d 2670
d4f3574e 2671@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2672@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2673have only limited usefulness. If @value{GDBN} creates a software
2674watchpoint, it can only watch the value of an expression @emph{in a
2675single thread}. If you are confident that the expression can only
2676change due to the current thread's activity (and if you are also
2677confident that no other thread can become current), then you can use
2678software watchpoints as usual. However, @value{GDBN} may not notice
2679when a non-current thread's activity changes the expression. (Hardware
2680watchpoints, in contrast, watch an expression in all threads.)
c906108c 2681@end quotation
c906108c 2682
6d2ebf8b 2683@node Set Catchpoints
c906108c 2684@subsection Setting catchpoints
d4f3574e 2685@cindex catchpoints, setting
c906108c
SS
2686@cindex exception handlers
2687@cindex event handling
2688
2689You can use @dfn{catchpoints} to cause the debugger to stop for certain
2690kinds of program events, such as C++ exceptions or the loading of a
2691shared library. Use the @code{catch} command to set a catchpoint.
2692
2693@table @code
2694@kindex catch
2695@item catch @var{event}
2696Stop when @var{event} occurs. @var{event} can be any of the following:
2697@table @code
2698@item throw
2699@kindex catch throw
2700The throwing of a C++ exception.
2701
2702@item catch
2703@kindex catch catch
2704The catching of a C++ exception.
2705
2706@item exec
2707@kindex catch exec
2708A call to @code{exec}. This is currently only available for HP-UX.
2709
2710@item fork
2711@kindex catch fork
2712A call to @code{fork}. This is currently only available for HP-UX.
2713
2714@item vfork
2715@kindex catch vfork
2716A call to @code{vfork}. This is currently only available for HP-UX.
2717
2718@item load
2719@itemx load @var{libname}
2720@kindex catch load
2721The dynamic loading of any shared library, or the loading of the library
2722@var{libname}. This is currently only available for HP-UX.
2723
2724@item unload
2725@itemx unload @var{libname}
2726@kindex catch unload
2727The unloading of any dynamically loaded shared library, or the unloading
2728of the library @var{libname}. This is currently only available for HP-UX.
2729@end table
2730
2731@item tcatch @var{event}
2732Set a catchpoint that is enabled only for one stop. The catchpoint is
2733automatically deleted after the first time the event is caught.
2734
2735@end table
2736
2737Use the @code{info break} command to list the current catchpoints.
2738
2739There are currently some limitations to C++ exception handling
2740(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2741
2742@itemize @bullet
2743@item
2744If you call a function interactively, @value{GDBN} normally returns
2745control to you when the function has finished executing. If the call
2746raises an exception, however, the call may bypass the mechanism that
2747returns control to you and cause your program either to abort or to
2748simply continue running until it hits a breakpoint, catches a signal
2749that @value{GDBN} is listening for, or exits. This is the case even if
2750you set a catchpoint for the exception; catchpoints on exceptions are
2751disabled within interactive calls.
2752
2753@item
2754You cannot raise an exception interactively.
2755
2756@item
2757You cannot install an exception handler interactively.
2758@end itemize
2759
2760@cindex raise exceptions
2761Sometimes @code{catch} is not the best way to debug exception handling:
2762if you need to know exactly where an exception is raised, it is better to
2763stop @emph{before} the exception handler is called, since that way you
2764can see the stack before any unwinding takes place. If you set a
2765breakpoint in an exception handler instead, it may not be easy to find
2766out where the exception was raised.
2767
2768To stop just before an exception handler is called, you need some
2769knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2770raised by calling a library function named @code{__raise_exception}
2771which has the following ANSI C interface:
2772
2773@example
2774 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2775 @var{id} is the exception identifier. */
2776 void __raise_exception (void **addr, void *id);
c906108c
SS
2777@end example
2778
2779@noindent
2780To make the debugger catch all exceptions before any stack
2781unwinding takes place, set a breakpoint on @code{__raise_exception}
2782(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2783
2784With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2785that depends on the value of @var{id}, you can stop your program when
2786a specific exception is raised. You can use multiple conditional
2787breakpoints to stop your program when any of a number of exceptions are
2788raised.
2789
2790
6d2ebf8b 2791@node Delete Breaks
c906108c
SS
2792@subsection Deleting breakpoints
2793
2794@cindex clearing breakpoints, watchpoints, catchpoints
2795@cindex deleting breakpoints, watchpoints, catchpoints
2796It is often necessary to eliminate a breakpoint, watchpoint, or
2797catchpoint once it has done its job and you no longer want your program
2798to stop there. This is called @dfn{deleting} the breakpoint. A
2799breakpoint that has been deleted no longer exists; it is forgotten.
2800
2801With the @code{clear} command you can delete breakpoints according to
2802where they are in your program. With the @code{delete} command you can
2803delete individual breakpoints, watchpoints, or catchpoints by specifying
2804their breakpoint numbers.
2805
2806It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2807automatically ignores breakpoints on the first instruction to be executed
2808when you continue execution without changing the execution address.
2809
2810@table @code
2811@kindex clear
2812@item clear
2813Delete any breakpoints at the next instruction to be executed in the
2814selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2815the innermost frame is selected, this is a good way to delete a
2816breakpoint where your program just stopped.
2817
2818@item clear @var{function}
2819@itemx clear @var{filename}:@var{function}
2820Delete any breakpoints set at entry to the function @var{function}.
2821
2822@item clear @var{linenum}
2823@itemx clear @var{filename}:@var{linenum}
2824Delete any breakpoints set at or within the code of the specified line.
2825
2826@cindex delete breakpoints
2827@kindex delete
41afff9a 2828@kindex d @r{(@code{delete})}
c5394b80
JM
2829@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2830Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2831ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2832breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2833confirm off}). You can abbreviate this command as @code{d}.
2834@end table
2835
6d2ebf8b 2836@node Disabling
c906108c
SS
2837@subsection Disabling breakpoints
2838
2839@kindex disable breakpoints
2840@kindex enable breakpoints
2841Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2842prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2843it had been deleted, but remembers the information on the breakpoint so
2844that you can @dfn{enable} it again later.
2845
2846You disable and enable breakpoints, watchpoints, and catchpoints with
2847the @code{enable} and @code{disable} commands, optionally specifying one
2848or more breakpoint numbers as arguments. Use @code{info break} or
2849@code{info watch} to print a list of breakpoints, watchpoints, and
2850catchpoints if you do not know which numbers to use.
2851
2852A breakpoint, watchpoint, or catchpoint can have any of four different
2853states of enablement:
2854
2855@itemize @bullet
2856@item
2857Enabled. The breakpoint stops your program. A breakpoint set
2858with the @code{break} command starts out in this state.
2859@item
2860Disabled. The breakpoint has no effect on your program.
2861@item
2862Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2863disabled.
c906108c
SS
2864@item
2865Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2866immediately after it does so it is deleted permanently. A breakpoint
2867set with the @code{tbreak} command starts out in this state.
c906108c
SS
2868@end itemize
2869
2870You can use the following commands to enable or disable breakpoints,
2871watchpoints, and catchpoints:
2872
2873@table @code
2874@kindex disable breakpoints
2875@kindex disable
41afff9a 2876@kindex dis @r{(@code{disable})}
c5394b80 2877@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2878Disable the specified breakpoints---or all breakpoints, if none are
2879listed. A disabled breakpoint has no effect but is not forgotten. All
2880options such as ignore-counts, conditions and commands are remembered in
2881case the breakpoint is enabled again later. You may abbreviate
2882@code{disable} as @code{dis}.
2883
2884@kindex enable breakpoints
2885@kindex enable
c5394b80 2886@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2887Enable the specified breakpoints (or all defined breakpoints). They
2888become effective once again in stopping your program.
2889
c5394b80 2890@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2891Enable the specified breakpoints temporarily. @value{GDBN} disables any
2892of these breakpoints immediately after stopping your program.
2893
c5394b80 2894@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
2895Enable the specified breakpoints to work once, then die. @value{GDBN}
2896deletes any of these breakpoints as soon as your program stops there.
2897@end table
2898
d4f3574e
SS
2899@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2900@c confusing: tbreak is also initially enabled.
c906108c
SS
2901Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2902,Setting breakpoints}), breakpoints that you set are initially enabled;
2903subsequently, they become disabled or enabled only when you use one of
2904the commands above. (The command @code{until} can set and delete a
2905breakpoint of its own, but it does not change the state of your other
2906breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2907stepping}.)
2908
6d2ebf8b 2909@node Conditions
c906108c
SS
2910@subsection Break conditions
2911@cindex conditional breakpoints
2912@cindex breakpoint conditions
2913
2914@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 2915@c in particular for a watchpoint?
c906108c
SS
2916The simplest sort of breakpoint breaks every time your program reaches a
2917specified place. You can also specify a @dfn{condition} for a
2918breakpoint. A condition is just a Boolean expression in your
2919programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2920a condition evaluates the expression each time your program reaches it,
2921and your program stops only if the condition is @emph{true}.
2922
2923This is the converse of using assertions for program validation; in that
2924situation, you want to stop when the assertion is violated---that is,
2925when the condition is false. In C, if you want to test an assertion expressed
2926by the condition @var{assert}, you should set the condition
2927@samp{! @var{assert}} on the appropriate breakpoint.
2928
2929Conditions are also accepted for watchpoints; you may not need them,
2930since a watchpoint is inspecting the value of an expression anyhow---but
2931it might be simpler, say, to just set a watchpoint on a variable name,
2932and specify a condition that tests whether the new value is an interesting
2933one.
2934
2935Break conditions can have side effects, and may even call functions in
2936your program. This can be useful, for example, to activate functions
2937that log program progress, or to use your own print functions to
2938format special data structures. The effects are completely predictable
2939unless there is another enabled breakpoint at the same address. (In
2940that case, @value{GDBN} might see the other breakpoint first and stop your
2941program without checking the condition of this one.) Note that
d4f3574e
SS
2942breakpoint commands are usually more convenient and flexible than break
2943conditions for the
c906108c
SS
2944purpose of performing side effects when a breakpoint is reached
2945(@pxref{Break Commands, ,Breakpoint command lists}).
2946
2947Break conditions can be specified when a breakpoint is set, by using
2948@samp{if} in the arguments to the @code{break} command. @xref{Set
2949Breaks, ,Setting breakpoints}. They can also be changed at any time
2950with the @code{condition} command.
53a5351d 2951
c906108c
SS
2952You can also use the @code{if} keyword with the @code{watch} command.
2953The @code{catch} command does not recognize the @code{if} keyword;
2954@code{condition} is the only way to impose a further condition on a
2955catchpoint.
c906108c
SS
2956
2957@table @code
2958@kindex condition
2959@item condition @var{bnum} @var{expression}
2960Specify @var{expression} as the break condition for breakpoint,
2961watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2962breakpoint @var{bnum} stops your program only if the value of
2963@var{expression} is true (nonzero, in C). When you use
2964@code{condition}, @value{GDBN} checks @var{expression} immediately for
2965syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
2966referents in the context of your breakpoint. If @var{expression} uses
2967symbols not referenced in the context of the breakpoint, @value{GDBN}
2968prints an error message:
2969
2970@example
2971No symbol "foo" in current context.
2972@end example
2973
2974@noindent
c906108c
SS
2975@value{GDBN} does
2976not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
2977command (or a command that sets a breakpoint with a condition, like
2978@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
2979
2980@item condition @var{bnum}
2981Remove the condition from breakpoint number @var{bnum}. It becomes
2982an ordinary unconditional breakpoint.
2983@end table
2984
2985@cindex ignore count (of breakpoint)
2986A special case of a breakpoint condition is to stop only when the
2987breakpoint has been reached a certain number of times. This is so
2988useful that there is a special way to do it, using the @dfn{ignore
2989count} of the breakpoint. Every breakpoint has an ignore count, which
2990is an integer. Most of the time, the ignore count is zero, and
2991therefore has no effect. But if your program reaches a breakpoint whose
2992ignore count is positive, then instead of stopping, it just decrements
2993the ignore count by one and continues. As a result, if the ignore count
2994value is @var{n}, the breakpoint does not stop the next @var{n} times
2995your program reaches it.
2996
2997@table @code
2998@kindex ignore
2999@item ignore @var{bnum} @var{count}
3000Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3001The next @var{count} times the breakpoint is reached, your program's
3002execution does not stop; other than to decrement the ignore count, @value{GDBN}
3003takes no action.
3004
3005To make the breakpoint stop the next time it is reached, specify
3006a count of zero.
3007
3008When you use @code{continue} to resume execution of your program from a
3009breakpoint, you can specify an ignore count directly as an argument to
3010@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3011Stepping,,Continuing and stepping}.
3012
3013If a breakpoint has a positive ignore count and a condition, the
3014condition is not checked. Once the ignore count reaches zero,
3015@value{GDBN} resumes checking the condition.
3016
3017You could achieve the effect of the ignore count with a condition such
3018as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3019is decremented each time. @xref{Convenience Vars, ,Convenience
3020variables}.
3021@end table
3022
3023Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3024
3025
6d2ebf8b 3026@node Break Commands
c906108c
SS
3027@subsection Breakpoint command lists
3028
3029@cindex breakpoint commands
3030You can give any breakpoint (or watchpoint or catchpoint) a series of
3031commands to execute when your program stops due to that breakpoint. For
3032example, you might want to print the values of certain expressions, or
3033enable other breakpoints.
3034
3035@table @code
3036@kindex commands
3037@kindex end
3038@item commands @r{[}@var{bnum}@r{]}
3039@itemx @dots{} @var{command-list} @dots{}
3040@itemx end
3041Specify a list of commands for breakpoint number @var{bnum}. The commands
3042themselves appear on the following lines. Type a line containing just
3043@code{end} to terminate the commands.
3044
3045To remove all commands from a breakpoint, type @code{commands} and
3046follow it immediately with @code{end}; that is, give no commands.
3047
3048With no @var{bnum} argument, @code{commands} refers to the last
3049breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3050recently encountered).
3051@end table
3052
3053Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3054disabled within a @var{command-list}.
3055
3056You can use breakpoint commands to start your program up again. Simply
3057use the @code{continue} command, or @code{step}, or any other command
3058that resumes execution.
3059
3060Any other commands in the command list, after a command that resumes
3061execution, are ignored. This is because any time you resume execution
3062(even with a simple @code{next} or @code{step}), you may encounter
3063another breakpoint---which could have its own command list, leading to
3064ambiguities about which list to execute.
3065
3066@kindex silent
3067If the first command you specify in a command list is @code{silent}, the
3068usual message about stopping at a breakpoint is not printed. This may
3069be desirable for breakpoints that are to print a specific message and
3070then continue. If none of the remaining commands print anything, you
3071see no sign that the breakpoint was reached. @code{silent} is
3072meaningful only at the beginning of a breakpoint command list.
3073
3074The commands @code{echo}, @code{output}, and @code{printf} allow you to
3075print precisely controlled output, and are often useful in silent
3076breakpoints. @xref{Output, ,Commands for controlled output}.
3077
3078For example, here is how you could use breakpoint commands to print the
3079value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3080
3081@example
3082break foo if x>0
3083commands
3084silent
3085printf "x is %d\n",x
3086cont
3087end
3088@end example
3089
3090One application for breakpoint commands is to compensate for one bug so
3091you can test for another. Put a breakpoint just after the erroneous line
3092of code, give it a condition to detect the case in which something
3093erroneous has been done, and give it commands to assign correct values
3094to any variables that need them. End with the @code{continue} command
3095so that your program does not stop, and start with the @code{silent}
3096command so that no output is produced. Here is an example:
3097
3098@example
3099break 403
3100commands
3101silent
3102set x = y + 4
3103cont
3104end
3105@end example
3106
6d2ebf8b 3107@node Breakpoint Menus
c906108c
SS
3108@subsection Breakpoint menus
3109@cindex overloading
3110@cindex symbol overloading
3111
3112Some programming languages (notably C++) permit a single function name
3113to be defined several times, for application in different contexts.
3114This is called @dfn{overloading}. When a function name is overloaded,
3115@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3116a breakpoint. If you realize this is a problem, you can use
3117something like @samp{break @var{function}(@var{types})} to specify which
3118particular version of the function you want. Otherwise, @value{GDBN} offers
3119you a menu of numbered choices for different possible breakpoints, and
3120waits for your selection with the prompt @samp{>}. The first two
3121options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3122sets a breakpoint at each definition of @var{function}, and typing
3123@kbd{0} aborts the @code{break} command without setting any new
3124breakpoints.
3125
3126For example, the following session excerpt shows an attempt to set a
3127breakpoint at the overloaded symbol @code{String::after}.
3128We choose three particular definitions of that function name:
3129
3130@c FIXME! This is likely to change to show arg type lists, at least
3131@smallexample
3132@group
3133(@value{GDBP}) b String::after
3134[0] cancel
3135[1] all
3136[2] file:String.cc; line number:867
3137[3] file:String.cc; line number:860
3138[4] file:String.cc; line number:875
3139[5] file:String.cc; line number:853
3140[6] file:String.cc; line number:846
3141[7] file:String.cc; line number:735
3142> 2 4 6
3143Breakpoint 1 at 0xb26c: file String.cc, line 867.
3144Breakpoint 2 at 0xb344: file String.cc, line 875.
3145Breakpoint 3 at 0xafcc: file String.cc, line 846.
3146Multiple breakpoints were set.
3147Use the "delete" command to delete unwanted
3148 breakpoints.
3149(@value{GDBP})
3150@end group
3151@end smallexample
c906108c
SS
3152
3153@c @ifclear BARETARGET
6d2ebf8b 3154@node Error in Breakpoints
d4f3574e 3155@subsection ``Cannot insert breakpoints''
c906108c
SS
3156@c
3157@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3158@c
d4f3574e
SS
3159Under some operating systems, breakpoints cannot be used in a program if
3160any other process is running that program. In this situation,
5d161b24 3161attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3162@value{GDBN} to print an error message:
3163
3164@example
3165Cannot insert breakpoints.
3166The same program may be running in another process.
3167@end example
3168
3169When this happens, you have three ways to proceed:
3170
3171@enumerate
3172@item
3173Remove or disable the breakpoints, then continue.
3174
3175@item
5d161b24 3176Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3177name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3178that @value{GDBN} should run your program under that name.
d4f3574e
SS
3179Then start your program again.
3180
3181@item
3182Relink your program so that the text segment is nonsharable, using the
3183linker option @samp{-N}. The operating system limitation may not apply
3184to nonsharable executables.
3185@end enumerate
c906108c
SS
3186@c @end ifclear
3187
d4f3574e
SS
3188A similar message can be printed if you request too many active
3189hardware-assisted breakpoints and watchpoints:
3190
3191@c FIXME: the precise wording of this message may change; the relevant
3192@c source change is not committed yet (Sep 3, 1999).
3193@smallexample
3194Stopped; cannot insert breakpoints.
3195You may have requested too many hardware breakpoints and watchpoints.
3196@end smallexample
3197
3198@noindent
3199This message is printed when you attempt to resume the program, since
3200only then @value{GDBN} knows exactly how many hardware breakpoints and
3201watchpoints it needs to insert.
3202
3203When this message is printed, you need to disable or remove some of the
3204hardware-assisted breakpoints and watchpoints, and then continue.
3205
3206
6d2ebf8b 3207@node Continuing and Stepping
c906108c
SS
3208@section Continuing and stepping
3209
3210@cindex stepping
3211@cindex continuing
3212@cindex resuming execution
3213@dfn{Continuing} means resuming program execution until your program
3214completes normally. In contrast, @dfn{stepping} means executing just
3215one more ``step'' of your program, where ``step'' may mean either one
3216line of source code, or one machine instruction (depending on what
7a292a7a
SS
3217particular command you use). Either when continuing or when stepping,
3218your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3219it stops due to a signal, you may want to use @code{handle}, or use
3220@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3221
3222@table @code
3223@kindex continue
41afff9a
EZ
3224@kindex c @r{(@code{continue})}
3225@kindex fg @r{(resume foreground execution)}
c906108c
SS
3226@item continue @r{[}@var{ignore-count}@r{]}
3227@itemx c @r{[}@var{ignore-count}@r{]}
3228@itemx fg @r{[}@var{ignore-count}@r{]}
3229Resume program execution, at the address where your program last stopped;
3230any breakpoints set at that address are bypassed. The optional argument
3231@var{ignore-count} allows you to specify a further number of times to
3232ignore a breakpoint at this location; its effect is like that of
3233@code{ignore} (@pxref{Conditions, ,Break conditions}).
3234
3235The argument @var{ignore-count} is meaningful only when your program
3236stopped due to a breakpoint. At other times, the argument to
3237@code{continue} is ignored.
3238
d4f3574e
SS
3239The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3240debugged program is deemed to be the foreground program) are provided
3241purely for convenience, and have exactly the same behavior as
3242@code{continue}.
c906108c
SS
3243@end table
3244
3245To resume execution at a different place, you can use @code{return}
3246(@pxref{Returning, ,Returning from a function}) to go back to the
3247calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3248different address}) to go to an arbitrary location in your program.
3249
3250A typical technique for using stepping is to set a breakpoint
3251(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3252beginning of the function or the section of your program where a problem
3253is believed to lie, run your program until it stops at that breakpoint,
3254and then step through the suspect area, examining the variables that are
3255interesting, until you see the problem happen.
3256
3257@table @code
3258@kindex step
41afff9a 3259@kindex s @r{(@code{step})}
c906108c
SS
3260@item step
3261Continue running your program until control reaches a different source
3262line, then stop it and return control to @value{GDBN}. This command is
3263abbreviated @code{s}.
3264
3265@quotation
3266@c "without debugging information" is imprecise; actually "without line
3267@c numbers in the debugging information". (gcc -g1 has debugging info but
3268@c not line numbers). But it seems complex to try to make that
3269@c distinction here.
3270@emph{Warning:} If you use the @code{step} command while control is
3271within a function that was compiled without debugging information,
3272execution proceeds until control reaches a function that does have
3273debugging information. Likewise, it will not step into a function which
3274is compiled without debugging information. To step through functions
3275without debugging information, use the @code{stepi} command, described
3276below.
3277@end quotation
3278
d4f3574e
SS
3279The @code{step} command only stops at the first instruction of a
3280source line. This prevents the multiple stops that could otherwise occur in
c906108c
SS
3281switch statements, for loops, etc. @code{step} continues to stop if a
3282function that has debugging information is called within the line.
d4f3574e
SS
3283In other words, @code{step} @emph{steps inside} any functions called
3284within the line.
c906108c 3285
d4f3574e
SS
3286Also, the @code{step} command only enters a function if there is line
3287number information for the function. Otherwise it acts like the
5d161b24 3288@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3289on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3290was any debugging information about the routine.
c906108c
SS
3291
3292@item step @var{count}
3293Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3294breakpoint is reached, or a signal not related to stepping occurs before
3295@var{count} steps, stepping stops right away.
c906108c
SS
3296
3297@kindex next
41afff9a 3298@kindex n @r{(@code{next})}
c906108c
SS
3299@item next @r{[}@var{count}@r{]}
3300Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3301This is similar to @code{step}, but function calls that appear within
3302the line of code are executed without stopping. Execution stops when
3303control reaches a different line of code at the original stack level
3304that was executing when you gave the @code{next} command. This command
3305is abbreviated @code{n}.
c906108c
SS
3306
3307An argument @var{count} is a repeat count, as for @code{step}.
3308
3309
3310@c FIX ME!! Do we delete this, or is there a way it fits in with
3311@c the following paragraph? --- Vctoria
3312@c
3313@c @code{next} within a function that lacks debugging information acts like
3314@c @code{step}, but any function calls appearing within the code of the
3315@c function are executed without stopping.
3316
d4f3574e
SS
3317The @code{next} command only stops at the first instruction of a
3318source line. This prevents multiple stops that could otherwise occur in
5d161b24 3319switch statements, for loops, etc.
c906108c
SS
3320
3321@kindex finish
3322@item finish
3323Continue running until just after function in the selected stack frame
3324returns. Print the returned value (if any).
3325
3326Contrast this with the @code{return} command (@pxref{Returning,
3327,Returning from a function}).
3328
3329@kindex until
41afff9a 3330@kindex u @r{(@code{until})}
c906108c
SS
3331@item until
3332@itemx u
3333Continue running until a source line past the current line, in the
3334current stack frame, is reached. This command is used to avoid single
3335stepping through a loop more than once. It is like the @code{next}
3336command, except that when @code{until} encounters a jump, it
3337automatically continues execution until the program counter is greater
3338than the address of the jump.
3339
3340This means that when you reach the end of a loop after single stepping
3341though it, @code{until} makes your program continue execution until it
3342exits the loop. In contrast, a @code{next} command at the end of a loop
3343simply steps back to the beginning of the loop, which forces you to step
3344through the next iteration.
3345
3346@code{until} always stops your program if it attempts to exit the current
3347stack frame.
3348
3349@code{until} may produce somewhat counterintuitive results if the order
3350of machine code does not match the order of the source lines. For
3351example, in the following excerpt from a debugging session, the @code{f}
3352(@code{frame}) command shows that execution is stopped at line
3353@code{206}; yet when we use @code{until}, we get to line @code{195}:
3354
3355@example
3356(@value{GDBP}) f
3357#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3358206 expand_input();
3359(@value{GDBP}) until
3360195 for ( ; argc > 0; NEXTARG) @{
3361@end example
3362
3363This happened because, for execution efficiency, the compiler had
3364generated code for the loop closure test at the end, rather than the
3365start, of the loop---even though the test in a C @code{for}-loop is
3366written before the body of the loop. The @code{until} command appeared
3367to step back to the beginning of the loop when it advanced to this
3368expression; however, it has not really gone to an earlier
3369statement---not in terms of the actual machine code.
3370
3371@code{until} with no argument works by means of single
3372instruction stepping, and hence is slower than @code{until} with an
3373argument.
3374
3375@item until @var{location}
3376@itemx u @var{location}
3377Continue running your program until either the specified location is
3378reached, or the current stack frame returns. @var{location} is any of
3379the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3380,Setting breakpoints}). This form of the command uses breakpoints,
3381and hence is quicker than @code{until} without an argument.
3382
3383@kindex stepi
41afff9a 3384@kindex si @r{(@code{stepi})}
c906108c 3385@item stepi
96a2c332 3386@itemx stepi @var{arg}
c906108c
SS
3387@itemx si
3388Execute one machine instruction, then stop and return to the debugger.
3389
3390It is often useful to do @samp{display/i $pc} when stepping by machine
3391instructions. This makes @value{GDBN} automatically display the next
3392instruction to be executed, each time your program stops. @xref{Auto
3393Display,, Automatic display}.
3394
3395An argument is a repeat count, as in @code{step}.
3396
3397@need 750
3398@kindex nexti
41afff9a 3399@kindex ni @r{(@code{nexti})}
c906108c 3400@item nexti
96a2c332 3401@itemx nexti @var{arg}
c906108c
SS
3402@itemx ni
3403Execute one machine instruction, but if it is a function call,
3404proceed until the function returns.
3405
3406An argument is a repeat count, as in @code{next}.
3407@end table
3408
6d2ebf8b 3409@node Signals
c906108c
SS
3410@section Signals
3411@cindex signals
3412
3413A signal is an asynchronous event that can happen in a program. The
3414operating system defines the possible kinds of signals, and gives each
3415kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3416signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3417@code{SIGSEGV} is the signal a program gets from referencing a place in
3418memory far away from all the areas in use; @code{SIGALRM} occurs when
3419the alarm clock timer goes off (which happens only if your program has
3420requested an alarm).
3421
3422@cindex fatal signals
3423Some signals, including @code{SIGALRM}, are a normal part of the
3424functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3425errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3426program has not specified in advance some other way to handle the signal.
3427@code{SIGINT} does not indicate an error in your program, but it is normally
3428fatal so it can carry out the purpose of the interrupt: to kill the program.
3429
3430@value{GDBN} has the ability to detect any occurrence of a signal in your
3431program. You can tell @value{GDBN} in advance what to do for each kind of
3432signal.
3433
3434@cindex handling signals
3435Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3436(so as not to interfere with their role in the functioning of your program)
3437but to stop your program immediately whenever an error signal happens.
3438You can change these settings with the @code{handle} command.
3439
3440@table @code
3441@kindex info signals
3442@item info signals
96a2c332 3443@itemx info handle
c906108c
SS
3444Print a table of all the kinds of signals and how @value{GDBN} has been told to
3445handle each one. You can use this to see the signal numbers of all
3446the defined types of signals.
3447
d4f3574e 3448@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3449
3450@kindex handle
3451@item handle @var{signal} @var{keywords}@dots{}
5d161b24 3452Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
c906108c
SS
3453be the number of a signal or its name (with or without the @samp{SIG} at the
3454beginning). The @var{keywords} say what change to make.
3455@end table
3456
3457@c @group
3458The keywords allowed by the @code{handle} command can be abbreviated.
3459Their full names are:
3460
3461@table @code
3462@item nostop
3463@value{GDBN} should not stop your program when this signal happens. It may
3464still print a message telling you that the signal has come in.
3465
3466@item stop
3467@value{GDBN} should stop your program when this signal happens. This implies
3468the @code{print} keyword as well.
3469
3470@item print
3471@value{GDBN} should print a message when this signal happens.
3472
3473@item noprint
3474@value{GDBN} should not mention the occurrence of the signal at all. This
3475implies the @code{nostop} keyword as well.
3476
3477@item pass
3478@value{GDBN} should allow your program to see this signal; your program
3479can handle the signal, or else it may terminate if the signal is fatal
3480and not handled.
3481
3482@item nopass
3483@value{GDBN} should not allow your program to see this signal.
3484@end table
3485@c @end group
3486
d4f3574e
SS
3487When a signal stops your program, the signal is not visible to the
3488program until you
c906108c
SS
3489continue. Your program sees the signal then, if @code{pass} is in
3490effect for the signal in question @emph{at that time}. In other words,
3491after @value{GDBN} reports a signal, you can use the @code{handle}
3492command with @code{pass} or @code{nopass} to control whether your
3493program sees that signal when you continue.
3494
3495You can also use the @code{signal} command to prevent your program from
3496seeing a signal, or cause it to see a signal it normally would not see,
3497or to give it any signal at any time. For example, if your program stopped
3498due to some sort of memory reference error, you might store correct
3499values into the erroneous variables and continue, hoping to see more
3500execution; but your program would probably terminate immediately as
3501a result of the fatal signal once it saw the signal. To prevent this,
3502you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3503program a signal}.
c906108c 3504
6d2ebf8b 3505@node Thread Stops
c906108c
SS
3506@section Stopping and starting multi-thread programs
3507
3508When your program has multiple threads (@pxref{Threads,, Debugging
3509programs with multiple threads}), you can choose whether to set
3510breakpoints on all threads, or on a particular thread.
3511
3512@table @code
3513@cindex breakpoints and threads
3514@cindex thread breakpoints
3515@kindex break @dots{} thread @var{threadno}
3516@item break @var{linespec} thread @var{threadno}
3517@itemx break @var{linespec} thread @var{threadno} if @dots{}
3518@var{linespec} specifies source lines; there are several ways of
3519writing them, but the effect is always to specify some source line.
3520
3521Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3522to specify that you only want @value{GDBN} to stop the program when a
3523particular thread reaches this breakpoint. @var{threadno} is one of the
3524numeric thread identifiers assigned by @value{GDBN}, shown in the first
3525column of the @samp{info threads} display.
3526
3527If you do not specify @samp{thread @var{threadno}} when you set a
3528breakpoint, the breakpoint applies to @emph{all} threads of your
3529program.
3530
3531You can use the @code{thread} qualifier on conditional breakpoints as
3532well; in this case, place @samp{thread @var{threadno}} before the
3533breakpoint condition, like this:
3534
3535@smallexample
2df3850c 3536(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3537@end smallexample
3538
3539@end table
3540
3541@cindex stopped threads
3542@cindex threads, stopped
3543Whenever your program stops under @value{GDBN} for any reason,
3544@emph{all} threads of execution stop, not just the current thread. This
3545allows you to examine the overall state of the program, including
3546switching between threads, without worrying that things may change
3547underfoot.
3548
3549@cindex continuing threads
3550@cindex threads, continuing
3551Conversely, whenever you restart the program, @emph{all} threads start
3552executing. @emph{This is true even when single-stepping} with commands
5d161b24 3553like @code{step} or @code{next}.
c906108c
SS
3554
3555In particular, @value{GDBN} cannot single-step all threads in lockstep.
3556Since thread scheduling is up to your debugging target's operating
3557system (not controlled by @value{GDBN}), other threads may
3558execute more than one statement while the current thread completes a
3559single step. Moreover, in general other threads stop in the middle of a
3560statement, rather than at a clean statement boundary, when the program
3561stops.
3562
3563You might even find your program stopped in another thread after
3564continuing or even single-stepping. This happens whenever some other
3565thread runs into a breakpoint, a signal, or an exception before the
3566first thread completes whatever you requested.
3567
3568On some OSes, you can lock the OS scheduler and thus allow only a single
3569thread to run.
3570
3571@table @code
3572@item set scheduler-locking @var{mode}
3573Set the scheduler locking mode. If it is @code{off}, then there is no
3574locking and any thread may run at any time. If @code{on}, then only the
3575current thread may run when the inferior is resumed. The @code{step}
3576mode optimizes for single-stepping. It stops other threads from
3577``seizing the prompt'' by preempting the current thread while you are
3578stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3579when you step. They are more likely to run when you @samp{next} over a
c906108c 3580function call, and they are completely free to run when you use commands
d4f3574e 3581like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3582thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3583@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3584
3585@item show scheduler-locking
3586Display the current scheduler locking mode.
3587@end table
3588
c906108c 3589
6d2ebf8b 3590@node Stack
c906108c
SS
3591@chapter Examining the Stack
3592
3593When your program has stopped, the first thing you need to know is where it
3594stopped and how it got there.
3595
3596@cindex call stack
5d161b24
DB
3597Each time your program performs a function call, information about the call
3598is generated.
3599That information includes the location of the call in your program,
3600the arguments of the call,
c906108c 3601and the local variables of the function being called.
5d161b24 3602The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3603The stack frames are allocated in a region of memory called the @dfn{call
3604stack}.
3605
3606When your program stops, the @value{GDBN} commands for examining the
3607stack allow you to see all of this information.
3608
3609@cindex selected frame
3610One of the stack frames is @dfn{selected} by @value{GDBN} and many
3611@value{GDBN} commands refer implicitly to the selected frame. In
3612particular, whenever you ask @value{GDBN} for the value of a variable in
3613your program, the value is found in the selected frame. There are
3614special @value{GDBN} commands to select whichever frame you are
3615interested in. @xref{Selection, ,Selecting a frame}.
3616
3617When your program stops, @value{GDBN} automatically selects the
5d161b24 3618currently executing frame and describes it briefly, similar to the
c906108c
SS
3619@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3620
3621@menu
3622* Frames:: Stack frames
3623* Backtrace:: Backtraces
3624* Selection:: Selecting a frame
3625* Frame Info:: Information on a frame
c906108c
SS
3626
3627@end menu
3628
6d2ebf8b 3629@node Frames
c906108c
SS
3630@section Stack frames
3631
d4f3574e 3632@cindex frame, definition
c906108c
SS
3633@cindex stack frame
3634The call stack is divided up into contiguous pieces called @dfn{stack
3635frames}, or @dfn{frames} for short; each frame is the data associated
3636with one call to one function. The frame contains the arguments given
3637to the function, the function's local variables, and the address at
3638which the function is executing.
3639
3640@cindex initial frame
3641@cindex outermost frame
3642@cindex innermost frame
3643When your program is started, the stack has only one frame, that of the
3644function @code{main}. This is called the @dfn{initial} frame or the
3645@dfn{outermost} frame. Each time a function is called, a new frame is
3646made. Each time a function returns, the frame for that function invocation
3647is eliminated. If a function is recursive, there can be many frames for
3648the same function. The frame for the function in which execution is
3649actually occurring is called the @dfn{innermost} frame. This is the most
3650recently created of all the stack frames that still exist.
3651
3652@cindex frame pointer
3653Inside your program, stack frames are identified by their addresses. A
3654stack frame consists of many bytes, each of which has its own address; each
3655kind of computer has a convention for choosing one byte whose
3656address serves as the address of the frame. Usually this address is kept
3657in a register called the @dfn{frame pointer register} while execution is
3658going on in that frame.
3659
3660@cindex frame number
3661@value{GDBN} assigns numbers to all existing stack frames, starting with
3662zero for the innermost frame, one for the frame that called it,
3663and so on upward. These numbers do not really exist in your program;
3664they are assigned by @value{GDBN} to give you a way of designating stack
3665frames in @value{GDBN} commands.
3666
6d2ebf8b
SS
3667@c The -fomit-frame-pointer below perennially causes hbox overflow
3668@c underflow problems.
c906108c
SS
3669@cindex frameless execution
3670Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3671without stack frames. (For example, the @value{GCC} option
3672@example
3673@samp{-fomit-frame-pointer}
3674@end example
3675generates functions without a frame.)
c906108c
SS
3676This is occasionally done with heavily used library functions to save
3677the frame setup time. @value{GDBN} has limited facilities for dealing
3678with these function invocations. If the innermost function invocation
3679has no stack frame, @value{GDBN} nevertheless regards it as though
3680it had a separate frame, which is numbered zero as usual, allowing
3681correct tracing of the function call chain. However, @value{GDBN} has
3682no provision for frameless functions elsewhere in the stack.
3683
3684@table @code
d4f3574e 3685@kindex frame@r{, command}
41afff9a 3686@cindex current stack frame
c906108c 3687@item frame @var{args}
5d161b24 3688The @code{frame} command allows you to move from one stack frame to another,
c906108c 3689and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3690address of the frame or the stack frame number. Without an argument,
3691@code{frame} prints the current stack frame.
c906108c
SS
3692
3693@kindex select-frame
41afff9a 3694@cindex selecting frame silently
c906108c
SS
3695@item select-frame
3696The @code{select-frame} command allows you to move from one stack frame
3697to another without printing the frame. This is the silent version of
3698@code{frame}.
3699@end table
3700
6d2ebf8b 3701@node Backtrace
c906108c
SS
3702@section Backtraces
3703
3704@cindex backtraces
3705@cindex tracebacks
3706@cindex stack traces
3707A backtrace is a summary of how your program got where it is. It shows one
3708line per frame, for many frames, starting with the currently executing
3709frame (frame zero), followed by its caller (frame one), and on up the
3710stack.
3711
3712@table @code
3713@kindex backtrace
41afff9a 3714@kindex bt @r{(@code{backtrace})}
c906108c
SS
3715@item backtrace
3716@itemx bt
3717Print a backtrace of the entire stack: one line per frame for all
3718frames in the stack.
3719
3720You can stop the backtrace at any time by typing the system interrupt
3721character, normally @kbd{C-c}.
3722
3723@item backtrace @var{n}
3724@itemx bt @var{n}
3725Similar, but print only the innermost @var{n} frames.
3726
3727@item backtrace -@var{n}
3728@itemx bt -@var{n}
3729Similar, but print only the outermost @var{n} frames.
3730@end table
3731
3732@kindex where
3733@kindex info stack
41afff9a 3734@kindex info s @r{(@code{info stack})}
c906108c
SS
3735The names @code{where} and @code{info stack} (abbreviated @code{info s})
3736are additional aliases for @code{backtrace}.
3737
3738Each line in the backtrace shows the frame number and the function name.
3739The program counter value is also shown---unless you use @code{set
3740print address off}. The backtrace also shows the source file name and
3741line number, as well as the arguments to the function. The program
3742counter value is omitted if it is at the beginning of the code for that
3743line number.
3744
3745Here is an example of a backtrace. It was made with the command
3746@samp{bt 3}, so it shows the innermost three frames.
3747
3748@smallexample
3749@group
5d161b24 3750#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3751 at builtin.c:993
3752#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3753#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3754 at macro.c:71
3755(More stack frames follow...)
3756@end group
3757@end smallexample
3758
3759@noindent
3760The display for frame zero does not begin with a program counter
3761value, indicating that your program has stopped at the beginning of the
3762code for line @code{993} of @code{builtin.c}.
3763
6d2ebf8b 3764@node Selection
c906108c
SS
3765@section Selecting a frame
3766
3767Most commands for examining the stack and other data in your program work on
3768whichever stack frame is selected at the moment. Here are the commands for
3769selecting a stack frame; all of them finish by printing a brief description
3770of the stack frame just selected.
3771
3772@table @code
d4f3574e 3773@kindex frame@r{, selecting}
41afff9a 3774@kindex f @r{(@code{frame})}
c906108c
SS
3775@item frame @var{n}
3776@itemx f @var{n}
3777Select frame number @var{n}. Recall that frame zero is the innermost
3778(currently executing) frame, frame one is the frame that called the
3779innermost one, and so on. The highest-numbered frame is the one for
3780@code{main}.
3781
3782@item frame @var{addr}
3783@itemx f @var{addr}
3784Select the frame at address @var{addr}. This is useful mainly if the
3785chaining of stack frames has been damaged by a bug, making it
3786impossible for @value{GDBN} to assign numbers properly to all frames. In
3787addition, this can be useful when your program has multiple stacks and
3788switches between them.
3789
c906108c
SS
3790On the SPARC architecture, @code{frame} needs two addresses to
3791select an arbitrary frame: a frame pointer and a stack pointer.
3792
3793On the MIPS and Alpha architecture, it needs two addresses: a stack
3794pointer and a program counter.
3795
3796On the 29k architecture, it needs three addresses: a register stack
3797pointer, a program counter, and a memory stack pointer.
3798@c note to future updaters: this is conditioned on a flag
3799@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3800@c as of 27 Jan 1994.
c906108c
SS
3801
3802@kindex up
3803@item up @var{n}
3804Move @var{n} frames up the stack. For positive numbers @var{n}, this
3805advances toward the outermost frame, to higher frame numbers, to frames
3806that have existed longer. @var{n} defaults to one.
3807
3808@kindex down
41afff9a 3809@kindex do @r{(@code{down})}
c906108c
SS
3810@item down @var{n}
3811Move @var{n} frames down the stack. For positive numbers @var{n}, this
3812advances toward the innermost frame, to lower frame numbers, to frames
3813that were created more recently. @var{n} defaults to one. You may
3814abbreviate @code{down} as @code{do}.
3815@end table
3816
3817All of these commands end by printing two lines of output describing the
3818frame. The first line shows the frame number, the function name, the
3819arguments, and the source file and line number of execution in that
5d161b24 3820frame. The second line shows the text of that source line.
c906108c
SS
3821
3822@need 1000
3823For example:
3824
3825@smallexample
3826@group
3827(@value{GDBP}) up
3828#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3829 at env.c:10
383010 read_input_file (argv[i]);
3831@end group
3832@end smallexample
3833
3834After such a printout, the @code{list} command with no arguments
3835prints ten lines centered on the point of execution in the frame.
3836@xref{List, ,Printing source lines}.
3837
3838@table @code
3839@kindex down-silently
3840@kindex up-silently
3841@item up-silently @var{n}
3842@itemx down-silently @var{n}
3843These two commands are variants of @code{up} and @code{down},
3844respectively; they differ in that they do their work silently, without
3845causing display of the new frame. They are intended primarily for use
3846in @value{GDBN} command scripts, where the output might be unnecessary and
3847distracting.
3848@end table
3849
6d2ebf8b 3850@node Frame Info
c906108c
SS
3851@section Information about a frame
3852
3853There are several other commands to print information about the selected
3854stack frame.
3855
3856@table @code
3857@item frame
3858@itemx f
3859When used without any argument, this command does not change which
3860frame is selected, but prints a brief description of the currently
3861selected stack frame. It can be abbreviated @code{f}. With an
3862argument, this command is used to select a stack frame.
3863@xref{Selection, ,Selecting a frame}.
3864
3865@kindex info frame
41afff9a 3866@kindex info f @r{(@code{info frame})}
c906108c
SS
3867@item info frame
3868@itemx info f
3869This command prints a verbose description of the selected stack frame,
3870including:
3871
3872@itemize @bullet
5d161b24
DB
3873@item
3874the address of the frame
c906108c
SS
3875@item
3876the address of the next frame down (called by this frame)
3877@item
3878the address of the next frame up (caller of this frame)
3879@item
3880the language in which the source code corresponding to this frame is written
3881@item
3882the address of the frame's arguments
3883@item
d4f3574e
SS
3884the address of the frame's local variables
3885@item
c906108c
SS
3886the program counter saved in it (the address of execution in the caller frame)
3887@item
3888which registers were saved in the frame
3889@end itemize
3890
3891@noindent The verbose description is useful when
3892something has gone wrong that has made the stack format fail to fit
3893the usual conventions.
3894
3895@item info frame @var{addr}
3896@itemx info f @var{addr}
3897Print a verbose description of the frame at address @var{addr}, without
3898selecting that frame. The selected frame remains unchanged by this
3899command. This requires the same kind of address (more than one for some
3900architectures) that you specify in the @code{frame} command.
3901@xref{Selection, ,Selecting a frame}.
3902
3903@kindex info args
3904@item info args
3905Print the arguments of the selected frame, each on a separate line.
3906
3907@item info locals
3908@kindex info locals
3909Print the local variables of the selected frame, each on a separate
3910line. These are all variables (declared either static or automatic)
3911accessible at the point of execution of the selected frame.
3912
c906108c 3913@kindex info catch
d4f3574e
SS
3914@cindex catch exceptions, list active handlers
3915@cindex exception handlers, how to list
c906108c
SS
3916@item info catch
3917Print a list of all the exception handlers that are active in the
3918current stack frame at the current point of execution. To see other
3919exception handlers, visit the associated frame (using the @code{up},
3920@code{down}, or @code{frame} commands); then type @code{info catch}.
3921@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 3922
c906108c
SS
3923@end table
3924
c906108c 3925
6d2ebf8b 3926@node Source
c906108c
SS
3927@chapter Examining Source Files
3928
3929@value{GDBN} can print parts of your program's source, since the debugging
3930information recorded in the program tells @value{GDBN} what source files were
3931used to build it. When your program stops, @value{GDBN} spontaneously prints
3932the line where it stopped. Likewise, when you select a stack frame
3933(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3934execution in that frame has stopped. You can print other portions of
3935source files by explicit command.
3936
7a292a7a 3937If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 3938prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 3939@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
3940
3941@menu
3942* List:: Printing source lines
c906108c 3943* Search:: Searching source files
c906108c
SS
3944* Source Path:: Specifying source directories
3945* Machine Code:: Source and machine code
3946@end menu
3947
6d2ebf8b 3948@node List
c906108c
SS
3949@section Printing source lines
3950
3951@kindex list
41afff9a 3952@kindex l @r{(@code{list})}
c906108c 3953To print lines from a source file, use the @code{list} command
5d161b24 3954(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
3955There are several ways to specify what part of the file you want to print.
3956
3957Here are the forms of the @code{list} command most commonly used:
3958
3959@table @code
3960@item list @var{linenum}
3961Print lines centered around line number @var{linenum} in the
3962current source file.
3963
3964@item list @var{function}
3965Print lines centered around the beginning of function
3966@var{function}.
3967
3968@item list
3969Print more lines. If the last lines printed were printed with a
3970@code{list} command, this prints lines following the last lines
3971printed; however, if the last line printed was a solitary line printed
3972as part of displaying a stack frame (@pxref{Stack, ,Examining the
3973Stack}), this prints lines centered around that line.
3974
3975@item list -
3976Print lines just before the lines last printed.
3977@end table
3978
3979By default, @value{GDBN} prints ten source lines with any of these forms of
3980the @code{list} command. You can change this using @code{set listsize}:
3981
3982@table @code
3983@kindex set listsize
3984@item set listsize @var{count}
3985Make the @code{list} command display @var{count} source lines (unless
3986the @code{list} argument explicitly specifies some other number).
3987
3988@kindex show listsize
3989@item show listsize
3990Display the number of lines that @code{list} prints.
3991@end table
3992
3993Repeating a @code{list} command with @key{RET} discards the argument,
3994so it is equivalent to typing just @code{list}. This is more useful
3995than listing the same lines again. An exception is made for an
3996argument of @samp{-}; that argument is preserved in repetition so that
3997each repetition moves up in the source file.
3998
3999@cindex linespec
4000In general, the @code{list} command expects you to supply zero, one or two
4001@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4002of writing them, but the effect is always to specify some source line.
c906108c
SS
4003Here is a complete description of the possible arguments for @code{list}:
4004
4005@table @code
4006@item list @var{linespec}
4007Print lines centered around the line specified by @var{linespec}.
4008
4009@item list @var{first},@var{last}
4010Print lines from @var{first} to @var{last}. Both arguments are
4011linespecs.
4012
4013@item list ,@var{last}
4014Print lines ending with @var{last}.
4015
4016@item list @var{first},
4017Print lines starting with @var{first}.
4018
4019@item list +
4020Print lines just after the lines last printed.
4021
4022@item list -
4023Print lines just before the lines last printed.
4024
4025@item list
4026As described in the preceding table.
4027@end table
4028
4029Here are the ways of specifying a single source line---all the
4030kinds of linespec.
4031
4032@table @code
4033@item @var{number}
4034Specifies line @var{number} of the current source file.
4035When a @code{list} command has two linespecs, this refers to
4036the same source file as the first linespec.
4037
4038@item +@var{offset}
4039Specifies the line @var{offset} lines after the last line printed.
4040When used as the second linespec in a @code{list} command that has
4041two, this specifies the line @var{offset} lines down from the
4042first linespec.
4043
4044@item -@var{offset}
4045Specifies the line @var{offset} lines before the last line printed.
4046
4047@item @var{filename}:@var{number}
4048Specifies line @var{number} in the source file @var{filename}.
4049
4050@item @var{function}
4051Specifies the line that begins the body of the function @var{function}.
4052For example: in C, this is the line with the open brace.
4053
4054@item @var{filename}:@var{function}
4055Specifies the line of the open-brace that begins the body of the
4056function @var{function} in the file @var{filename}. You only need the
4057file name with a function name to avoid ambiguity when there are
4058identically named functions in different source files.
4059
4060@item *@var{address}
4061Specifies the line containing the program address @var{address}.
4062@var{address} may be any expression.
4063@end table
4064
6d2ebf8b 4065@node Search
c906108c
SS
4066@section Searching source files
4067@cindex searching
4068@kindex reverse-search
4069
4070There are two commands for searching through the current source file for a
4071regular expression.
4072
4073@table @code
4074@kindex search
4075@kindex forward-search
4076@item forward-search @var{regexp}
4077@itemx search @var{regexp}
4078The command @samp{forward-search @var{regexp}} checks each line,
4079starting with the one following the last line listed, for a match for
5d161b24 4080@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4081synonym @samp{search @var{regexp}} or abbreviate the command name as
4082@code{fo}.
4083
4084@item reverse-search @var{regexp}
4085The command @samp{reverse-search @var{regexp}} checks each line, starting
4086with the one before the last line listed and going backward, for a match
4087for @var{regexp}. It lists the line that is found. You can abbreviate
4088this command as @code{rev}.
4089@end table
c906108c 4090
6d2ebf8b 4091@node Source Path
c906108c
SS
4092@section Specifying source directories
4093
4094@cindex source path
4095@cindex directories for source files
4096Executable programs sometimes do not record the directories of the source
4097files from which they were compiled, just the names. Even when they do,
4098the directories could be moved between the compilation and your debugging
4099session. @value{GDBN} has a list of directories to search for source files;
4100this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4101it tries all the directories in the list, in the order they are present
4102in the list, until it finds a file with the desired name. Note that
4103the executable search path is @emph{not} used for this purpose. Neither is
4104the current working directory, unless it happens to be in the source
4105path.
4106
4107If @value{GDBN} cannot find a source file in the source path, and the
4108object program records a directory, @value{GDBN} tries that directory
4109too. If the source path is empty, and there is no record of the
4110compilation directory, @value{GDBN} looks in the current directory as a
4111last resort.
4112
4113Whenever you reset or rearrange the source path, @value{GDBN} clears out
4114any information it has cached about where source files are found and where
4115each line is in the file.
4116
4117@kindex directory
4118@kindex dir
d4f3574e
SS
4119When you start @value{GDBN}, its source path includes only @samp{cdir}
4120and @samp{cwd}, in that order.
c906108c
SS
4121To add other directories, use the @code{directory} command.
4122
4123@table @code
4124@item directory @var{dirname} @dots{}
4125@item dir @var{dirname} @dots{}
4126Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4127directory names may be given to this command, separated by @samp{:}
4128(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4129part of absolute file names) or
c906108c
SS
4130whitespace. You may specify a directory that is already in the source
4131path; this moves it forward, so @value{GDBN} searches it sooner.
4132
4133@kindex cdir
4134@kindex cwd
41afff9a
EZ
4135@vindex $cdir@r{, convenience variable}
4136@vindex $cwdr@r{, convenience variable}
c906108c
SS
4137@cindex compilation directory
4138@cindex current directory
4139@cindex working directory
4140@cindex directory, current
4141@cindex directory, compilation
4142You can use the string @samp{$cdir} to refer to the compilation
4143directory (if one is recorded), and @samp{$cwd} to refer to the current
4144working directory. @samp{$cwd} is not the same as @samp{.}---the former
4145tracks the current working directory as it changes during your @value{GDBN}
4146session, while the latter is immediately expanded to the current
4147directory at the time you add an entry to the source path.
4148
4149@item directory
4150Reset the source path to empty again. This requires confirmation.
4151
4152@c RET-repeat for @code{directory} is explicitly disabled, but since
4153@c repeating it would be a no-op we do not say that. (thanks to RMS)
4154
4155@item show directories
4156@kindex show directories
4157Print the source path: show which directories it contains.
4158@end table
4159
4160If your source path is cluttered with directories that are no longer of
4161interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4162versions of source. You can correct the situation as follows:
4163
4164@enumerate
4165@item
4166Use @code{directory} with no argument to reset the source path to empty.
4167
4168@item
4169Use @code{directory} with suitable arguments to reinstall the
4170directories you want in the source path. You can add all the
4171directories in one command.
4172@end enumerate
4173
6d2ebf8b 4174@node Machine Code
c906108c
SS
4175@section Source and machine code
4176
4177You can use the command @code{info line} to map source lines to program
4178addresses (and vice versa), and the command @code{disassemble} to display
4179a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4180mode, the @code{info line} command causes the arrow to point to the
5d161b24 4181line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4182well as hex.
4183
4184@table @code
4185@kindex info line
4186@item info line @var{linespec}
4187Print the starting and ending addresses of the compiled code for
4188source line @var{linespec}. You can specify source lines in any of
4189the ways understood by the @code{list} command (@pxref{List, ,Printing
4190source lines}).
4191@end table
4192
4193For example, we can use @code{info line} to discover the location of
4194the object code for the first line of function
4195@code{m4_changequote}:
4196
d4f3574e
SS
4197@c FIXME: I think this example should also show the addresses in
4198@c symbolic form, as they usually would be displayed.
c906108c 4199@smallexample
96a2c332 4200(@value{GDBP}) info line m4_changequote
c906108c
SS
4201Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4202@end smallexample
4203
4204@noindent
4205We can also inquire (using @code{*@var{addr}} as the form for
4206@var{linespec}) what source line covers a particular address:
4207@smallexample
4208(@value{GDBP}) info line *0x63ff
4209Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4210@end smallexample
4211
4212@cindex @code{$_} and @code{info line}
41afff9a 4213@kindex x@r{(examine), and} info line
c906108c
SS
4214After @code{info line}, the default address for the @code{x} command
4215is changed to the starting address of the line, so that @samp{x/i} is
4216sufficient to begin examining the machine code (@pxref{Memory,
4217,Examining memory}). Also, this address is saved as the value of the
4218convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4219variables}).
4220
4221@table @code
4222@kindex disassemble
4223@cindex assembly instructions
4224@cindex instructions, assembly
4225@cindex machine instructions
4226@cindex listing machine instructions
4227@item disassemble
4228This specialized command dumps a range of memory as machine
4229instructions. The default memory range is the function surrounding the
4230program counter of the selected frame. A single argument to this
4231command is a program counter value; @value{GDBN} dumps the function
4232surrounding this value. Two arguments specify a range of addresses
4233(first inclusive, second exclusive) to dump.
4234@end table
4235
c906108c
SS
4236The following example shows the disassembly of a range of addresses of
4237HP PA-RISC 2.0 code:
4238
4239@smallexample
4240(@value{GDBP}) disas 0x32c4 0x32e4
4241Dump of assembler code from 0x32c4 to 0x32e4:
42420x32c4 <main+204>: addil 0,dp
42430x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
42440x32cc <main+212>: ldil 0x3000,r31
42450x32d0 <main+216>: ble 0x3f8(sr4,r31)
42460x32d4 <main+220>: ldo 0(r31),rp
42470x32d8 <main+224>: addil -0x800,dp
42480x32dc <main+228>: ldo 0x588(r1),r26
42490x32e0 <main+232>: ldil 0x3000,r31
4250End of assembler dump.
4251@end smallexample
c906108c
SS
4252
4253Some architectures have more than one commonly-used set of instruction
4254mnemonics or other syntax.
4255
4256@table @code
d4f3574e 4257@kindex set disassembly-flavor
c906108c
SS
4258@cindex assembly instructions
4259@cindex instructions, assembly
4260@cindex machine instructions
4261@cindex listing machine instructions
d4f3574e
SS
4262@cindex Intel disassembly flavor
4263@cindex AT&T disassembly flavor
4264@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4265Select the instruction set to use when disassembling the
4266program via the @code{disassemble} or @code{x/i} commands.
4267
4268Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4269can set @var{instruction-set} to either @code{intel} or @code{att}.
4270The default is @code{att}, the AT&T flavor used by default by Unix
4271assemblers for x86-based targets.
c906108c
SS
4272@end table
4273
4274
6d2ebf8b 4275@node Data
c906108c
SS
4276@chapter Examining Data
4277
4278@cindex printing data
4279@cindex examining data
4280@kindex print
4281@kindex inspect
4282@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4283@c document because it is nonstandard... Under Epoch it displays in a
4284@c different window or something like that.
4285The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4286command (abbreviated @code{p}), or its synonym @code{inspect}. It
4287evaluates and prints the value of an expression of the language your
4288program is written in (@pxref{Languages, ,Using @value{GDBN} with
4289Different Languages}).
c906108c
SS
4290
4291@table @code
d4f3574e
SS
4292@item print @var{expr}
4293@itemx print /@var{f} @var{expr}
4294@var{expr} is an expression (in the source language). By default the
4295value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4296you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4297@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4298formats}.
4299
4300@item print
4301@itemx print /@var{f}
d4f3574e 4302If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4303@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4304conveniently inspect the same value in an alternative format.
4305@end table
4306
4307A more low-level way of examining data is with the @code{x} command.
4308It examines data in memory at a specified address and prints it in a
4309specified format. @xref{Memory, ,Examining memory}.
4310
7a292a7a 4311If you are interested in information about types, or about how the
d4f3574e
SS
4312fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4313command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4314Table}.
c906108c
SS
4315
4316@menu
4317* Expressions:: Expressions
4318* Variables:: Program variables
4319* Arrays:: Artificial arrays
4320* Output Formats:: Output formats
4321* Memory:: Examining memory
4322* Auto Display:: Automatic display
4323* Print Settings:: Print settings
4324* Value History:: Value history
4325* Convenience Vars:: Convenience variables
4326* Registers:: Registers
c906108c 4327* Floating Point Hardware:: Floating point hardware
c906108c
SS
4328@end menu
4329
6d2ebf8b 4330@node Expressions
c906108c
SS
4331@section Expressions
4332
4333@cindex expressions
4334@code{print} and many other @value{GDBN} commands accept an expression and
4335compute its value. Any kind of constant, variable or operator defined
4336by the programming language you are using is valid in an expression in
4337@value{GDBN}. This includes conditional expressions, function calls, casts
4338and string constants. It unfortunately does not include symbols defined
4339by preprocessor @code{#define} commands.
4340
d4f3574e
SS
4341@value{GDBN} supports array constants in expressions input by
4342the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4343you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4344memory that is @code{malloc}ed in the target program.
c906108c 4345
c906108c
SS
4346Because C is so widespread, most of the expressions shown in examples in
4347this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4348Languages}, for information on how to use expressions in other
4349languages.
4350
4351In this section, we discuss operators that you can use in @value{GDBN}
4352expressions regardless of your programming language.
4353
4354Casts are supported in all languages, not just in C, because it is so
4355useful to cast a number into a pointer in order to examine a structure
4356at that address in memory.
4357@c FIXME: casts supported---Mod2 true?
c906108c
SS
4358
4359@value{GDBN} supports these operators, in addition to those common
4360to programming languages:
4361
4362@table @code
4363@item @@
4364@samp{@@} is a binary operator for treating parts of memory as arrays.
4365@xref{Arrays, ,Artificial arrays}, for more information.
4366
4367@item ::
4368@samp{::} allows you to specify a variable in terms of the file or
4369function where it is defined. @xref{Variables, ,Program variables}.
4370
4371@cindex @{@var{type}@}
4372@cindex type casting memory
4373@cindex memory, viewing as typed object
4374@cindex casts, to view memory
4375@item @{@var{type}@} @var{addr}
4376Refers to an object of type @var{type} stored at address @var{addr} in
4377memory. @var{addr} may be any expression whose value is an integer or
4378pointer (but parentheses are required around binary operators, just as in
4379a cast). This construct is allowed regardless of what kind of data is
4380normally supposed to reside at @var{addr}.
4381@end table
4382
6d2ebf8b 4383@node Variables
c906108c
SS
4384@section Program variables
4385
4386The most common kind of expression to use is the name of a variable
4387in your program.
4388
4389Variables in expressions are understood in the selected stack frame
4390(@pxref{Selection, ,Selecting a frame}); they must be either:
4391
4392@itemize @bullet
4393@item
4394global (or file-static)
4395@end itemize
4396
5d161b24 4397@noindent or
c906108c
SS
4398
4399@itemize @bullet
4400@item
4401visible according to the scope rules of the
4402programming language from the point of execution in that frame
5d161b24 4403@end itemize
c906108c
SS
4404
4405@noindent This means that in the function
4406
4407@example
4408foo (a)
4409 int a;
4410@{
4411 bar (a);
4412 @{
4413 int b = test ();
4414 bar (b);
4415 @}
4416@}
4417@end example
4418
4419@noindent
4420you can examine and use the variable @code{a} whenever your program is
4421executing within the function @code{foo}, but you can only use or
4422examine the variable @code{b} while your program is executing inside
4423the block where @code{b} is declared.
4424
4425@cindex variable name conflict
4426There is an exception: you can refer to a variable or function whose
4427scope is a single source file even if the current execution point is not
4428in this file. But it is possible to have more than one such variable or
4429function with the same name (in different source files). If that
4430happens, referring to that name has unpredictable effects. If you wish,
4431you can specify a static variable in a particular function or file,
4432using the colon-colon notation:
4433
d4f3574e 4434@cindex colon-colon, context for variables/functions
c906108c
SS
4435@iftex
4436@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4437@cindex @code{::}, context for variables/functions
c906108c
SS
4438@end iftex
4439@example
4440@var{file}::@var{variable}
4441@var{function}::@var{variable}
4442@end example
4443
4444@noindent
4445Here @var{file} or @var{function} is the name of the context for the
4446static @var{variable}. In the case of file names, you can use quotes to
4447make sure @value{GDBN} parses the file name as a single word---for example,
4448to print a global value of @code{x} defined in @file{f2.c}:
4449
4450@example
4451(@value{GDBP}) p 'f2.c'::x
4452@end example
4453
c906108c
SS
4454@cindex C++ scope resolution
4455This use of @samp{::} is very rarely in conflict with the very similar
4456use of the same notation in C++. @value{GDBN} also supports use of the C++
4457scope resolution operator in @value{GDBN} expressions.
4458@c FIXME: Um, so what happens in one of those rare cases where it's in
4459@c conflict?? --mew
c906108c
SS
4460
4461@cindex wrong values
4462@cindex variable values, wrong
4463@quotation
4464@emph{Warning:} Occasionally, a local variable may appear to have the
4465wrong value at certain points in a function---just after entry to a new
4466scope, and just before exit.
4467@end quotation
4468You may see this problem when you are stepping by machine instructions.
4469This is because, on most machines, it takes more than one instruction to
4470set up a stack frame (including local variable definitions); if you are
4471stepping by machine instructions, variables may appear to have the wrong
4472values until the stack frame is completely built. On exit, it usually
4473also takes more than one machine instruction to destroy a stack frame;
4474after you begin stepping through that group of instructions, local
4475variable definitions may be gone.
4476
4477This may also happen when the compiler does significant optimizations.
4478To be sure of always seeing accurate values, turn off all optimization
4479when compiling.
4480
d4f3574e
SS
4481@cindex ``No symbol "foo" in current context''
4482Another possible effect of compiler optimizations is to optimize
4483unused variables out of existence, or assign variables to registers (as
4484opposed to memory addresses). Depending on the support for such cases
4485offered by the debug info format used by the compiler, @value{GDBN}
4486might not be able to display values for such local variables. If that
4487happens, @value{GDBN} will print a message like this:
4488
4489@example
4490No symbol "foo" in current context.
4491@end example
4492
4493To solve such problems, either recompile without optimizations, or use a
4494different debug info format, if the compiler supports several such
4495formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4496supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4497in a format that is superior to formats such as COFF. You may be able
4498to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4499debug info. See @ref{Debugging Options,,Options for Debugging Your
4500Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4501information.
4502
4503
6d2ebf8b 4504@node Arrays
c906108c
SS
4505@section Artificial arrays
4506
4507@cindex artificial array
41afff9a 4508@kindex @@@r{, referencing memory as an array}
c906108c
SS
4509It is often useful to print out several successive objects of the
4510same type in memory; a section of an array, or an array of
4511dynamically determined size for which only a pointer exists in the
4512program.
4513
4514You can do this by referring to a contiguous span of memory as an
4515@dfn{artificial array}, using the binary operator @samp{@@}. The left
4516operand of @samp{@@} should be the first element of the desired array
4517and be an individual object. The right operand should be the desired length
4518of the array. The result is an array value whose elements are all of
4519the type of the left argument. The first element is actually the left
4520argument; the second element comes from bytes of memory immediately
4521following those that hold the first element, and so on. Here is an
4522example. If a program says
4523
4524@example
4525int *array = (int *) malloc (len * sizeof (int));
4526@end example
4527
4528@noindent
4529you can print the contents of @code{array} with
4530
4531@example
4532p *array@@len
4533@end example
4534
4535The left operand of @samp{@@} must reside in memory. Array values made
4536with @samp{@@} in this way behave just like other arrays in terms of
4537subscripting, and are coerced to pointers when used in expressions.
4538Artificial arrays most often appear in expressions via the value history
4539(@pxref{Value History, ,Value history}), after printing one out.
4540
4541Another way to create an artificial array is to use a cast.
4542This re-interprets a value as if it were an array.
4543The value need not be in memory:
4544@example
4545(@value{GDBP}) p/x (short[2])0x12345678
4546$1 = @{0x1234, 0x5678@}
4547@end example
4548
4549As a convenience, if you leave the array length out (as in
c3f6f71d 4550@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4551the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4552@example
4553(@value{GDBP}) p/x (short[])0x12345678
4554$2 = @{0x1234, 0x5678@}
4555@end example
4556
4557Sometimes the artificial array mechanism is not quite enough; in
4558moderately complex data structures, the elements of interest may not
4559actually be adjacent---for example, if you are interested in the values
4560of pointers in an array. One useful work-around in this situation is
4561to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4562variables}) as a counter in an expression that prints the first
4563interesting value, and then repeat that expression via @key{RET}. For
4564instance, suppose you have an array @code{dtab} of pointers to
4565structures, and you are interested in the values of a field @code{fv}
4566in each structure. Here is an example of what you might type:
4567
4568@example
4569set $i = 0
4570p dtab[$i++]->fv
4571@key{RET}
4572@key{RET}
4573@dots{}
4574@end example
4575
6d2ebf8b 4576@node Output Formats
c906108c
SS
4577@section Output formats
4578
4579@cindex formatted output
4580@cindex output formats
4581By default, @value{GDBN} prints a value according to its data type. Sometimes
4582this is not what you want. For example, you might want to print a number
4583in hex, or a pointer in decimal. Or you might want to view data in memory
4584at a certain address as a character string or as an instruction. To do
4585these things, specify an @dfn{output format} when you print a value.
4586
4587The simplest use of output formats is to say how to print a value
4588already computed. This is done by starting the arguments of the
4589@code{print} command with a slash and a format letter. The format
4590letters supported are:
4591
4592@table @code
4593@item x
4594Regard the bits of the value as an integer, and print the integer in
4595hexadecimal.
4596
4597@item d
4598Print as integer in signed decimal.
4599
4600@item u
4601Print as integer in unsigned decimal.
4602
4603@item o
4604Print as integer in octal.
4605
4606@item t
4607Print as integer in binary. The letter @samp{t} stands for ``two''.
4608@footnote{@samp{b} cannot be used because these format letters are also
4609used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4610see @ref{Memory,,Examining memory}.}
c906108c
SS
4611
4612@item a
4613@cindex unknown address, locating
4614Print as an address, both absolute in hexadecimal and as an offset from
4615the nearest preceding symbol. You can use this format used to discover
4616where (in what function) an unknown address is located:
4617
4618@example
4619(@value{GDBP}) p/a 0x54320
4620$3 = 0x54320 <_initialize_vx+396>
4621@end example
4622
4623@item c
4624Regard as an integer and print it as a character constant.
4625
4626@item f
4627Regard the bits of the value as a floating point number and print
4628using typical floating point syntax.
4629@end table
4630
4631For example, to print the program counter in hex (@pxref{Registers}), type
4632
4633@example
4634p/x $pc
4635@end example
4636
4637@noindent
4638Note that no space is required before the slash; this is because command
4639names in @value{GDBN} cannot contain a slash.
4640
4641To reprint the last value in the value history with a different format,
4642you can use the @code{print} command with just a format and no
4643expression. For example, @samp{p/x} reprints the last value in hex.
4644
6d2ebf8b 4645@node Memory
c906108c
SS
4646@section Examining memory
4647
4648You can use the command @code{x} (for ``examine'') to examine memory in
4649any of several formats, independently of your program's data types.
4650
4651@cindex examining memory
4652@table @code
41afff9a 4653@kindex x @r{(examine memory)}
c906108c
SS
4654@item x/@var{nfu} @var{addr}
4655@itemx x @var{addr}
4656@itemx x
4657Use the @code{x} command to examine memory.
4658@end table
4659
4660@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4661much memory to display and how to format it; @var{addr} is an
4662expression giving the address where you want to start displaying memory.
4663If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4664Several commands set convenient defaults for @var{addr}.
4665
4666@table @r
4667@item @var{n}, the repeat count
4668The repeat count is a decimal integer; the default is 1. It specifies
4669how much memory (counting by units @var{u}) to display.
4670@c This really is **decimal**; unaffected by 'set radix' as of GDB
4671@c 4.1.2.
4672
4673@item @var{f}, the display format
4674The display format is one of the formats used by @code{print},
4675@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4676The default is @samp{x} (hexadecimal) initially.
4677The default changes each time you use either @code{x} or @code{print}.
4678
4679@item @var{u}, the unit size
4680The unit size is any of
4681
4682@table @code
4683@item b
4684Bytes.
4685@item h
4686Halfwords (two bytes).
4687@item w
4688Words (four bytes). This is the initial default.
4689@item g
4690Giant words (eight bytes).
4691@end table
4692
4693Each time you specify a unit size with @code{x}, that size becomes the
4694default unit the next time you use @code{x}. (For the @samp{s} and
4695@samp{i} formats, the unit size is ignored and is normally not written.)
4696
4697@item @var{addr}, starting display address
4698@var{addr} is the address where you want @value{GDBN} to begin displaying
4699memory. The expression need not have a pointer value (though it may);
4700it is always interpreted as an integer address of a byte of memory.
4701@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4702@var{addr} is usually just after the last address examined---but several
4703other commands also set the default address: @code{info breakpoints} (to
4704the address of the last breakpoint listed), @code{info line} (to the
4705starting address of a line), and @code{print} (if you use it to display
4706a value from memory).
4707@end table
4708
4709For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4710(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4711starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4712words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4713@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4714
4715Since the letters indicating unit sizes are all distinct from the
4716letters specifying output formats, you do not have to remember whether
4717unit size or format comes first; either order works. The output
4718specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4719(However, the count @var{n} must come first; @samp{wx4} does not work.)
4720
4721Even though the unit size @var{u} is ignored for the formats @samp{s}
4722and @samp{i}, you might still want to use a count @var{n}; for example,
4723@samp{3i} specifies that you want to see three machine instructions,
4724including any operands. The command @code{disassemble} gives an
d4f3574e 4725alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4726Code,,Source and machine code}.
4727
4728All the defaults for the arguments to @code{x} are designed to make it
4729easy to continue scanning memory with minimal specifications each time
4730you use @code{x}. For example, after you have inspected three machine
4731instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4732with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4733the repeat count @var{n} is used again; the other arguments default as
4734for successive uses of @code{x}.
4735
4736@cindex @code{$_}, @code{$__}, and value history
4737The addresses and contents printed by the @code{x} command are not saved
4738in the value history because there is often too much of them and they
4739would get in the way. Instead, @value{GDBN} makes these values available for
4740subsequent use in expressions as values of the convenience variables
4741@code{$_} and @code{$__}. After an @code{x} command, the last address
4742examined is available for use in expressions in the convenience variable
4743@code{$_}. The contents of that address, as examined, are available in
4744the convenience variable @code{$__}.
4745
4746If the @code{x} command has a repeat count, the address and contents saved
4747are from the last memory unit printed; this is not the same as the last
4748address printed if several units were printed on the last line of output.
4749
6d2ebf8b 4750@node Auto Display
c906108c
SS
4751@section Automatic display
4752@cindex automatic display
4753@cindex display of expressions
4754
4755If you find that you want to print the value of an expression frequently
4756(to see how it changes), you might want to add it to the @dfn{automatic
4757display list} so that @value{GDBN} prints its value each time your program stops.
4758Each expression added to the list is given a number to identify it;
4759to remove an expression from the list, you specify that number.
4760The automatic display looks like this:
4761
4762@example
47632: foo = 38
47643: bar[5] = (struct hack *) 0x3804
4765@end example
4766
4767@noindent
4768This display shows item numbers, expressions and their current values. As with
4769displays you request manually using @code{x} or @code{print}, you can
4770specify the output format you prefer; in fact, @code{display} decides
4771whether to use @code{print} or @code{x} depending on how elaborate your
4772format specification is---it uses @code{x} if you specify a unit size,
4773or one of the two formats (@samp{i} and @samp{s}) that are only
4774supported by @code{x}; otherwise it uses @code{print}.
4775
4776@table @code
4777@kindex display
d4f3574e
SS
4778@item display @var{expr}
4779Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4780each time your program stops. @xref{Expressions, ,Expressions}.
4781
4782@code{display} does not repeat if you press @key{RET} again after using it.
4783
d4f3574e 4784@item display/@var{fmt} @var{expr}
c906108c 4785For @var{fmt} specifying only a display format and not a size or
d4f3574e 4786count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4787arrange to display it each time in the specified format @var{fmt}.
4788@xref{Output Formats,,Output formats}.
4789
4790@item display/@var{fmt} @var{addr}
4791For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4792number of units, add the expression @var{addr} as a memory address to
4793be examined each time your program stops. Examining means in effect
4794doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4795@end table
4796
4797For example, @samp{display/i $pc} can be helpful, to see the machine
4798instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4799is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4800
4801@table @code
4802@kindex delete display
4803@kindex undisplay
4804@item undisplay @var{dnums}@dots{}
4805@itemx delete display @var{dnums}@dots{}
4806Remove item numbers @var{dnums} from the list of expressions to display.
4807
4808@code{undisplay} does not repeat if you press @key{RET} after using it.
4809(Otherwise you would just get the error @samp{No display number @dots{}}.)
4810
4811@kindex disable display
4812@item disable display @var{dnums}@dots{}
4813Disable the display of item numbers @var{dnums}. A disabled display
4814item is not printed automatically, but is not forgotten. It may be
4815enabled again later.
4816
4817@kindex enable display
4818@item enable display @var{dnums}@dots{}
4819Enable display of item numbers @var{dnums}. It becomes effective once
4820again in auto display of its expression, until you specify otherwise.
4821
4822@item display
4823Display the current values of the expressions on the list, just as is
4824done when your program stops.
4825
4826@kindex info display
4827@item info display
4828Print the list of expressions previously set up to display
4829automatically, each one with its item number, but without showing the
4830values. This includes disabled expressions, which are marked as such.
4831It also includes expressions which would not be displayed right now
4832because they refer to automatic variables not currently available.
4833@end table
4834
4835If a display expression refers to local variables, then it does not make
4836sense outside the lexical context for which it was set up. Such an
4837expression is disabled when execution enters a context where one of its
4838variables is not defined. For example, if you give the command
4839@code{display last_char} while inside a function with an argument
4840@code{last_char}, @value{GDBN} displays this argument while your program
4841continues to stop inside that function. When it stops elsewhere---where
4842there is no variable @code{last_char}---the display is disabled
4843automatically. The next time your program stops where @code{last_char}
4844is meaningful, you can enable the display expression once again.
4845
6d2ebf8b 4846@node Print Settings
c906108c
SS
4847@section Print settings
4848
4849@cindex format options
4850@cindex print settings
4851@value{GDBN} provides the following ways to control how arrays, structures,
4852and symbols are printed.
4853
4854@noindent
4855These settings are useful for debugging programs in any language:
4856
4857@table @code
4858@kindex set print address
4859@item set print address
4860@itemx set print address on
4861@value{GDBN} prints memory addresses showing the location of stack
4862traces, structure values, pointer values, breakpoints, and so forth,
4863even when it also displays the contents of those addresses. The default
4864is @code{on}. For example, this is what a stack frame display looks like with
4865@code{set print address on}:
4866
4867@smallexample
4868@group
4869(@value{GDBP}) f
4870#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4871 at input.c:530
4872530 if (lquote != def_lquote)
4873@end group
4874@end smallexample
4875
4876@item set print address off
4877Do not print addresses when displaying their contents. For example,
4878this is the same stack frame displayed with @code{set print address off}:
4879
4880@smallexample
4881@group
4882(@value{GDBP}) set print addr off
4883(@value{GDBP}) f
4884#0 set_quotes (lq="<<", rq=">>") at input.c:530
4885530 if (lquote != def_lquote)
4886@end group
4887@end smallexample
4888
4889You can use @samp{set print address off} to eliminate all machine
4890dependent displays from the @value{GDBN} interface. For example, with
4891@code{print address off}, you should get the same text for backtraces on
4892all machines---whether or not they involve pointer arguments.
4893
4894@kindex show print address
4895@item show print address
4896Show whether or not addresses are to be printed.
4897@end table
4898
4899When @value{GDBN} prints a symbolic address, it normally prints the
4900closest earlier symbol plus an offset. If that symbol does not uniquely
4901identify the address (for example, it is a name whose scope is a single
4902source file), you may need to clarify. One way to do this is with
4903@code{info line}, for example @samp{info line *0x4537}. Alternately,
4904you can set @value{GDBN} to print the source file and line number when
4905it prints a symbolic address:
4906
4907@table @code
4908@kindex set print symbol-filename
4909@item set print symbol-filename on
4910Tell @value{GDBN} to print the source file name and line number of a
4911symbol in the symbolic form of an address.
4912
4913@item set print symbol-filename off
4914Do not print source file name and line number of a symbol. This is the
4915default.
4916
4917@kindex show print symbol-filename
4918@item show print symbol-filename
4919Show whether or not @value{GDBN} will print the source file name and
4920line number of a symbol in the symbolic form of an address.
4921@end table
4922
4923Another situation where it is helpful to show symbol filenames and line
4924numbers is when disassembling code; @value{GDBN} shows you the line
4925number and source file that corresponds to each instruction.
4926
4927Also, you may wish to see the symbolic form only if the address being
4928printed is reasonably close to the closest earlier symbol:
4929
4930@table @code
4931@kindex set print max-symbolic-offset
4932@item set print max-symbolic-offset @var{max-offset}
4933Tell @value{GDBN} to only display the symbolic form of an address if the
4934offset between the closest earlier symbol and the address is less than
5d161b24 4935@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
4936to always print the symbolic form of an address if any symbol precedes it.
4937
4938@kindex show print max-symbolic-offset
4939@item show print max-symbolic-offset
4940Ask how large the maximum offset is that @value{GDBN} prints in a
4941symbolic address.
4942@end table
4943
4944@cindex wild pointer, interpreting
4945@cindex pointer, finding referent
4946If you have a pointer and you are not sure where it points, try
4947@samp{set print symbol-filename on}. Then you can determine the name
4948and source file location of the variable where it points, using
4949@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4950For example, here @value{GDBN} shows that a variable @code{ptt} points
4951at another variable @code{t}, defined in @file{hi2.c}:
4952
4953@example
4954(@value{GDBP}) set print symbol-filename on
4955(@value{GDBP}) p/a ptt
4956$4 = 0xe008 <t in hi2.c>
4957@end example
4958
4959@quotation
4960@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4961does not show the symbol name and filename of the referent, even with
4962the appropriate @code{set print} options turned on.
4963@end quotation
4964
4965Other settings control how different kinds of objects are printed:
4966
4967@table @code
4968@kindex set print array
4969@item set print array
4970@itemx set print array on
4971Pretty print arrays. This format is more convenient to read,
4972but uses more space. The default is off.
4973
4974@item set print array off
4975Return to compressed format for arrays.
4976
4977@kindex show print array
4978@item show print array
4979Show whether compressed or pretty format is selected for displaying
4980arrays.
4981
4982@kindex set print elements
4983@item set print elements @var{number-of-elements}
4984Set a limit on how many elements of an array @value{GDBN} will print.
4985If @value{GDBN} is printing a large array, it stops printing after it has
4986printed the number of elements set by the @code{set print elements} command.
4987This limit also applies to the display of strings.
d4f3574e 4988When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
4989Setting @var{number-of-elements} to zero means that the printing is unlimited.
4990
4991@kindex show print elements
4992@item show print elements
4993Display the number of elements of a large array that @value{GDBN} will print.
4994If the number is 0, then the printing is unlimited.
4995
4996@kindex set print null-stop
4997@item set print null-stop
4998Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 4999@sc{null} is encountered. This is useful when large arrays actually
c906108c 5000contain only short strings.
d4f3574e 5001The default is off.
c906108c
SS
5002
5003@kindex set print pretty
5004@item set print pretty on
5d161b24 5005Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5006per line, like this:
5007
5008@smallexample
5009@group
5010$1 = @{
5011 next = 0x0,
5012 flags = @{
5013 sweet = 1,
5014 sour = 1
5015 @},
5016 meat = 0x54 "Pork"
5017@}
5018@end group
5019@end smallexample
5020
5021@item set print pretty off
5022Cause @value{GDBN} to print structures in a compact format, like this:
5023
5024@smallexample
5025@group
5026$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5027meat = 0x54 "Pork"@}
5028@end group
5029@end smallexample
5030
5031@noindent
5032This is the default format.
5033
5034@kindex show print pretty
5035@item show print pretty
5036Show which format @value{GDBN} is using to print structures.
5037
5038@kindex set print sevenbit-strings
5039@item set print sevenbit-strings on
5040Print using only seven-bit characters; if this option is set,
5041@value{GDBN} displays any eight-bit characters (in strings or
5042character values) using the notation @code{\}@var{nnn}. This setting is
5043best if you are working in English (@sc{ascii}) and you use the
5044high-order bit of characters as a marker or ``meta'' bit.
5045
5046@item set print sevenbit-strings off
5047Print full eight-bit characters. This allows the use of more
5048international character sets, and is the default.
5049
5050@kindex show print sevenbit-strings
5051@item show print sevenbit-strings
5052Show whether or not @value{GDBN} is printing only seven-bit characters.
5053
5054@kindex set print union
5055@item set print union on
5d161b24 5056Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5057is the default setting.
5058
5059@item set print union off
5060Tell @value{GDBN} not to print unions which are contained in structures.
5061
5062@kindex show print union
5063@item show print union
5064Ask @value{GDBN} whether or not it will print unions which are contained in
5065structures.
5066
5067For example, given the declarations
5068
5069@smallexample
5070typedef enum @{Tree, Bug@} Species;
5071typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5072typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5073 Bug_forms;
5074
5075struct thing @{
5076 Species it;
5077 union @{
5078 Tree_forms tree;
5079 Bug_forms bug;
5080 @} form;
5081@};
5082
5083struct thing foo = @{Tree, @{Acorn@}@};
5084@end smallexample
5085
5086@noindent
5087with @code{set print union on} in effect @samp{p foo} would print
5088
5089@smallexample
5090$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5091@end smallexample
5092
5093@noindent
5094and with @code{set print union off} in effect it would print
5095
5096@smallexample
5097$1 = @{it = Tree, form = @{...@}@}
5098@end smallexample
5099@end table
5100
c906108c
SS
5101@need 1000
5102@noindent
5103These settings are of interest when debugging C++ programs:
5104
5105@table @code
5106@cindex demangling
5107@kindex set print demangle
5108@item set print demangle
5109@itemx set print demangle on
5110Print C++ names in their source form rather than in the encoded
5111(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5112linkage. The default is on.
c906108c
SS
5113
5114@kindex show print demangle
5115@item show print demangle
5116Show whether C++ names are printed in mangled or demangled form.
5117
5118@kindex set print asm-demangle
5119@item set print asm-demangle
5120@itemx set print asm-demangle on
5121Print C++ names in their source form rather than their mangled form, even
5122in assembler code printouts such as instruction disassemblies.
5123The default is off.
5124
5125@kindex show print asm-demangle
5126@item show print asm-demangle
5127Show whether C++ names in assembly listings are printed in mangled
5128or demangled form.
5129
5130@kindex set demangle-style
5131@cindex C++ symbol decoding style
5132@cindex symbol decoding style, C++
5133@item set demangle-style @var{style}
5134Choose among several encoding schemes used by different compilers to
5135represent C++ names. The choices for @var{style} are currently:
5136
5137@table @code
5138@item auto
5139Allow @value{GDBN} to choose a decoding style by inspecting your program.
5140
5141@item gnu
5d161b24 5142Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
c906108c 5143This is the default.
c906108c
SS
5144
5145@item hp
5146Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5147
5148@item lucid
5149Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5150
5151@item arm
5152Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5153@strong{Warning:} this setting alone is not sufficient to allow
5154debugging @code{cfront}-generated executables. @value{GDBN} would
5155require further enhancement to permit that.
5156
5157@end table
5158If you omit @var{style}, you will see a list of possible formats.
5159
5160@kindex show demangle-style
5161@item show demangle-style
5162Display the encoding style currently in use for decoding C++ symbols.
5163
5164@kindex set print object
5165@item set print object
5166@itemx set print object on
5167When displaying a pointer to an object, identify the @emph{actual}
5168(derived) type of the object rather than the @emph{declared} type, using
5169the virtual function table.
5170
5171@item set print object off
5172Display only the declared type of objects, without reference to the
5173virtual function table. This is the default setting.
5174
5175@kindex show print object
5176@item show print object
5177Show whether actual, or declared, object types are displayed.
5178
5179@kindex set print static-members
5180@item set print static-members
5181@itemx set print static-members on
5182Print static members when displaying a C++ object. The default is on.
5183
5184@item set print static-members off
5185Do not print static members when displaying a C++ object.
5186
5187@kindex show print static-members
5188@item show print static-members
5189Show whether C++ static members are printed, or not.
5190
5191@c These don't work with HP ANSI C++ yet.
5192@kindex set print vtbl
5193@item set print vtbl
5194@itemx set print vtbl on
5195Pretty print C++ virtual function tables. The default is off.
c906108c
SS
5196(The @code{vtbl} commands do not work on programs compiled with the HP
5197ANSI C++ compiler (@code{aCC}).)
c906108c
SS
5198
5199@item set print vtbl off
5200Do not pretty print C++ virtual function tables.
5201
5202@kindex show print vtbl
5203@item show print vtbl
5204Show whether C++ virtual function tables are pretty printed, or not.
5205@end table
c906108c 5206
6d2ebf8b 5207@node Value History
c906108c
SS
5208@section Value history
5209
5210@cindex value history
5d161b24
DB
5211Values printed by the @code{print} command are saved in the @value{GDBN}
5212@dfn{value history}. This allows you to refer to them in other expressions.
5213Values are kept until the symbol table is re-read or discarded
5214(for example with the @code{file} or @code{symbol-file} commands).
5215When the symbol table changes, the value history is discarded,
5216since the values may contain pointers back to the types defined in the
c906108c
SS
5217symbol table.
5218
5219@cindex @code{$}
5220@cindex @code{$$}
5221@cindex history number
5222The values printed are given @dfn{history numbers} by which you can
5223refer to them. These are successive integers starting with one.
5224@code{print} shows you the history number assigned to a value by
5225printing @samp{$@var{num} = } before the value; here @var{num} is the
5226history number.
5227
5228To refer to any previous value, use @samp{$} followed by the value's
5229history number. The way @code{print} labels its output is designed to
5230remind you of this. Just @code{$} refers to the most recent value in
5231the history, and @code{$$} refers to the value before that.
5232@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5233is the value just prior to @code{$$}, @code{$$1} is equivalent to
5234@code{$$}, and @code{$$0} is equivalent to @code{$}.
5235
5236For example, suppose you have just printed a pointer to a structure and
5237want to see the contents of the structure. It suffices to type
5238
5239@example
5240p *$
5241@end example
5242
5243If you have a chain of structures where the component @code{next} points
5244to the next one, you can print the contents of the next one with this:
5245
5246@example
5247p *$.next
5248@end example
5249
5250@noindent
5251You can print successive links in the chain by repeating this
5252command---which you can do by just typing @key{RET}.
5253
5254Note that the history records values, not expressions. If the value of
5255@code{x} is 4 and you type these commands:
5256
5257@example
5258print x
5259set x=5
5260@end example
5261
5262@noindent
5263then the value recorded in the value history by the @code{print} command
5264remains 4 even though the value of @code{x} has changed.
5265
5266@table @code
5267@kindex show values
5268@item show values
5269Print the last ten values in the value history, with their item numbers.
5270This is like @samp{p@ $$9} repeated ten times, except that @code{show
5271values} does not change the history.
5272
5273@item show values @var{n}
5274Print ten history values centered on history item number @var{n}.
5275
5276@item show values +
5277Print ten history values just after the values last printed. If no more
5278values are available, @code{show values +} produces no display.
5279@end table
5280
5281Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5282same effect as @samp{show values +}.
5283
6d2ebf8b 5284@node Convenience Vars
c906108c
SS
5285@section Convenience variables
5286
5287@cindex convenience variables
5288@value{GDBN} provides @dfn{convenience variables} that you can use within
5289@value{GDBN} to hold on to a value and refer to it later. These variables
5290exist entirely within @value{GDBN}; they are not part of your program, and
5291setting a convenience variable has no direct effect on further execution
5292of your program. That is why you can use them freely.
5293
5294Convenience variables are prefixed with @samp{$}. Any name preceded by
5295@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5296the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5297(Value history references, in contrast, are @emph{numbers} preceded
5298by @samp{$}. @xref{Value History, ,Value history}.)
5299
5300You can save a value in a convenience variable with an assignment
5301expression, just as you would set a variable in your program.
5302For example:
5303
5304@example
5305set $foo = *object_ptr
5306@end example
5307
5308@noindent
5309would save in @code{$foo} the value contained in the object pointed to by
5310@code{object_ptr}.
5311
5312Using a convenience variable for the first time creates it, but its
5313value is @code{void} until you assign a new value. You can alter the
5314value with another assignment at any time.
5315
5316Convenience variables have no fixed types. You can assign a convenience
5317variable any type of value, including structures and arrays, even if
5318that variable already has a value of a different type. The convenience
5319variable, when used as an expression, has the type of its current value.
5320
5321@table @code
5322@kindex show convenience
5323@item show convenience
5324Print a list of convenience variables used so far, and their values.
d4f3574e 5325Abbreviated @code{show conv}.
c906108c
SS
5326@end table
5327
5328One of the ways to use a convenience variable is as a counter to be
5329incremented or a pointer to be advanced. For example, to print
5330a field from successive elements of an array of structures:
5331
5332@example
5333set $i = 0
5334print bar[$i++]->contents
5335@end example
5336
d4f3574e
SS
5337@noindent
5338Repeat that command by typing @key{RET}.
c906108c
SS
5339
5340Some convenience variables are created automatically by @value{GDBN} and given
5341values likely to be useful.
5342
5343@table @code
41afff9a 5344@vindex $_@r{, convenience variable}
c906108c
SS
5345@item $_
5346The variable @code{$_} is automatically set by the @code{x} command to
5347the last address examined (@pxref{Memory, ,Examining memory}). Other
5348commands which provide a default address for @code{x} to examine also
5349set @code{$_} to that address; these commands include @code{info line}
5350and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5351except when set by the @code{x} command, in which case it is a pointer
5352to the type of @code{$__}.
5353
41afff9a 5354@vindex $__@r{, convenience variable}
c906108c
SS
5355@item $__
5356The variable @code{$__} is automatically set by the @code{x} command
5357to the value found in the last address examined. Its type is chosen
5358to match the format in which the data was printed.
5359
5360@item $_exitcode
41afff9a 5361@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5362The variable @code{$_exitcode} is automatically set to the exit code when
5363the program being debugged terminates.
5364@end table
5365
53a5351d
JM
5366On HP-UX systems, if you refer to a function or variable name that
5367begins with a dollar sign, @value{GDBN} searches for a user or system
5368name first, before it searches for a convenience variable.
c906108c 5369
6d2ebf8b 5370@node Registers
c906108c
SS
5371@section Registers
5372
5373@cindex registers
5374You can refer to machine register contents, in expressions, as variables
5375with names starting with @samp{$}. The names of registers are different
5376for each machine; use @code{info registers} to see the names used on
5377your machine.
5378
5379@table @code
5380@kindex info registers
5381@item info registers
5382Print the names and values of all registers except floating-point
5383registers (in the selected stack frame).
5384
5385@kindex info all-registers
5386@cindex floating point registers
5387@item info all-registers
5388Print the names and values of all registers, including floating-point
5389registers.
5390
5391@item info registers @var{regname} @dots{}
5392Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5393As discussed in detail below, register values are normally relative to
5394the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5395the machine you are using, with or without the initial @samp{$}.
5396@end table
5397
5398@value{GDBN} has four ``standard'' register names that are available (in
5399expressions) on most machines---whenever they do not conflict with an
5400architecture's canonical mnemonics for registers. The register names
5401@code{$pc} and @code{$sp} are used for the program counter register and
5402the stack pointer. @code{$fp} is used for a register that contains a
5403pointer to the current stack frame, and @code{$ps} is used for a
5404register that contains the processor status. For example,
5405you could print the program counter in hex with
5406
5407@example
5408p/x $pc
5409@end example
5410
5411@noindent
5412or print the instruction to be executed next with
5413
5414@example
5415x/i $pc
5416@end example
5417
5418@noindent
5419or add four to the stack pointer@footnote{This is a way of removing
5420one word from the stack, on machines where stacks grow downward in
5421memory (most machines, nowadays). This assumes that the innermost
5422stack frame is selected; setting @code{$sp} is not allowed when other
5423stack frames are selected. To pop entire frames off the stack,
5424regardless of machine architecture, use @code{return};
d4f3574e 5425see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5426
5427@example
5428set $sp += 4
5429@end example
5430
5431Whenever possible, these four standard register names are available on
5432your machine even though the machine has different canonical mnemonics,
5433so long as there is no conflict. The @code{info registers} command
5434shows the canonical names. For example, on the SPARC, @code{info
5435registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5436can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5437is an alias for the @sc{eflags} register.
c906108c
SS
5438
5439@value{GDBN} always considers the contents of an ordinary register as an
5440integer when the register is examined in this way. Some machines have
5441special registers which can hold nothing but floating point; these
5442registers are considered to have floating point values. There is no way
5443to refer to the contents of an ordinary register as floating point value
5444(although you can @emph{print} it as a floating point value with
5445@samp{print/f $@var{regname}}).
5446
5447Some registers have distinct ``raw'' and ``virtual'' data formats. This
5448means that the data format in which the register contents are saved by
5449the operating system is not the same one that your program normally
5450sees. For example, the registers of the 68881 floating point
5451coprocessor are always saved in ``extended'' (raw) format, but all C
5452programs expect to work with ``double'' (virtual) format. In such
5d161b24 5453cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5454that makes sense for your program), but the @code{info registers} command
5455prints the data in both formats.
5456
5457Normally, register values are relative to the selected stack frame
5458(@pxref{Selection, ,Selecting a frame}). This means that you get the
5459value that the register would contain if all stack frames farther in
5460were exited and their saved registers restored. In order to see the
5461true contents of hardware registers, you must select the innermost
5462frame (with @samp{frame 0}).
5463
5464However, @value{GDBN} must deduce where registers are saved, from the machine
5465code generated by your compiler. If some registers are not saved, or if
5466@value{GDBN} is unable to locate the saved registers, the selected stack
5467frame makes no difference.
5468
6d2ebf8b 5469@node Floating Point Hardware
c906108c
SS
5470@section Floating point hardware
5471@cindex floating point
5472
5473Depending on the configuration, @value{GDBN} may be able to give
5474you more information about the status of the floating point hardware.
5475
5476@table @code
5477@kindex info float
5478@item info float
5479Display hardware-dependent information about the floating
5480point unit. The exact contents and layout vary depending on the
5481floating point chip. Currently, @samp{info float} is supported on
5482the ARM and x86 machines.
5483@end table
c906108c 5484
6d2ebf8b 5485@node Languages
c906108c
SS
5486@chapter Using @value{GDBN} with Different Languages
5487@cindex languages
5488
c906108c
SS
5489Although programming languages generally have common aspects, they are
5490rarely expressed in the same manner. For instance, in ANSI C,
5491dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5492Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 5493represented (and displayed) differently. Hex numbers in C appear as
c906108c 5494@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
5495
5496@cindex working language
5497Language-specific information is built into @value{GDBN} for some languages,
5498allowing you to express operations like the above in your program's
5499native language, and allowing @value{GDBN} to output values in a manner
5500consistent with the syntax of your program's native language. The
5501language you use to build expressions is called the @dfn{working
5502language}.
5503
5504@menu
5505* Setting:: Switching between source languages
5506* Show:: Displaying the language
c906108c 5507* Checks:: Type and range checks
c906108c
SS
5508* Support:: Supported languages
5509@end menu
5510
6d2ebf8b 5511@node Setting
c906108c
SS
5512@section Switching between source languages
5513
5514There are two ways to control the working language---either have @value{GDBN}
5515set it automatically, or select it manually yourself. You can use the
5516@code{set language} command for either purpose. On startup, @value{GDBN}
5517defaults to setting the language automatically. The working language is
5518used to determine how expressions you type are interpreted, how values
5519are printed, etc.
5520
5521In addition to the working language, every source file that
5522@value{GDBN} knows about has its own working language. For some object
5523file formats, the compiler might indicate which language a particular
5524source file is in. However, most of the time @value{GDBN} infers the
5525language from the name of the file. The language of a source file
5526controls whether C++ names are demangled---this way @code{backtrace} can
5527show each frame appropriately for its own language. There is no way to
d4f3574e
SS
5528set the language of a source file from within @value{GDBN}, but you can
5529set the language associated with a filename extension. @xref{Show, ,
5530Displaying the language}.
c906108c
SS
5531
5532This is most commonly a problem when you use a program, such
5d161b24 5533as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
5534another language. In that case, make the
5535program use @code{#line} directives in its C output; that way
5536@value{GDBN} will know the correct language of the source code of the original
5537program, and will display that source code, not the generated C code.
5538
5539@menu
5540* Filenames:: Filename extensions and languages.
5541* Manually:: Setting the working language manually
5542* Automatically:: Having @value{GDBN} infer the source language
5543@end menu
5544
6d2ebf8b 5545@node Filenames
c906108c
SS
5546@subsection List of filename extensions and languages
5547
5548If a source file name ends in one of the following extensions, then
5549@value{GDBN} infers that its language is the one indicated.
5550
5551@table @file
5552
5553@item .c
5554C source file
5555
5556@item .C
5557@itemx .cc
5558@itemx .cp
5559@itemx .cpp
5560@itemx .cxx
5561@itemx .c++
5562C++ source file
5563
5564@item .f
5565@itemx .F
5566Fortran source file
5567
c906108c
SS
5568@item .ch
5569@itemx .c186
5570@itemx .c286
96a2c332 5571CHILL source file
c906108c 5572
c906108c
SS
5573@item .mod
5574Modula-2 source file
c906108c
SS
5575
5576@item .s
5577@itemx .S
5578Assembler source file. This actually behaves almost like C, but
5579@value{GDBN} does not skip over function prologues when stepping.
5580@end table
5581
5582In addition, you may set the language associated with a filename
5583extension. @xref{Show, , Displaying the language}.
5584
6d2ebf8b 5585@node Manually
c906108c
SS
5586@subsection Setting the working language
5587
5588If you allow @value{GDBN} to set the language automatically,
5589expressions are interpreted the same way in your debugging session and
5590your program.
5591
5592@kindex set language
5593If you wish, you may set the language manually. To do this, issue the
5594command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 5595a language, such as
c906108c 5596@code{c} or @code{modula-2}.
c906108c
SS
5597For a list of the supported languages, type @samp{set language}.
5598
c906108c
SS
5599Setting the language manually prevents @value{GDBN} from updating the working
5600language automatically. This can lead to confusion if you try
5601to debug a program when the working language is not the same as the
5602source language, when an expression is acceptable to both
5603languages---but means different things. For instance, if the current
5604source file were written in C, and @value{GDBN} was parsing Modula-2, a
5605command such as:
5606
5607@example
5608print a = b + c
5609@end example
5610
5611@noindent
5612might not have the effect you intended. In C, this means to add
5613@code{b} and @code{c} and place the result in @code{a}. The result
5614printed would be the value of @code{a}. In Modula-2, this means to compare
5615@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 5616
6d2ebf8b 5617@node Automatically
c906108c
SS
5618@subsection Having @value{GDBN} infer the source language
5619
5620To have @value{GDBN} set the working language automatically, use
5621@samp{set language local} or @samp{set language auto}. @value{GDBN}
5622then infers the working language. That is, when your program stops in a
5623frame (usually by encountering a breakpoint), @value{GDBN} sets the
5624working language to the language recorded for the function in that
5625frame. If the language for a frame is unknown (that is, if the function
5626or block corresponding to the frame was defined in a source file that
5627does not have a recognized extension), the current working language is
5628not changed, and @value{GDBN} issues a warning.
5629
5630This may not seem necessary for most programs, which are written
5631entirely in one source language. However, program modules and libraries
5632written in one source language can be used by a main program written in
5633a different source language. Using @samp{set language auto} in this
5634case frees you from having to set the working language manually.
5635
6d2ebf8b 5636@node Show
c906108c 5637@section Displaying the language
c906108c
SS
5638
5639The following commands help you find out which language is the
5640working language, and also what language source files were written in.
5641
5642@kindex show language
d4f3574e
SS
5643@kindex info frame@r{, show the source language}
5644@kindex info source@r{, show the source language}
c906108c
SS
5645@table @code
5646@item show language
5647Display the current working language. This is the
5648language you can use with commands such as @code{print} to
5649build and compute expressions that may involve variables in your program.
5650
5651@item info frame
5d161b24 5652Display the source language for this frame. This language becomes the
c906108c 5653working language if you use an identifier from this frame.
5d161b24 5654@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
5655information listed here.
5656
5657@item info source
5658Display the source language of this source file.
5d161b24 5659@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
5660information listed here.
5661@end table
5662
5663In unusual circumstances, you may have source files with extensions
5664not in the standard list. You can then set the extension associated
5665with a language explicitly:
5666
5667@kindex set extension-language
5668@kindex info extensions
5669@table @code
5670@item set extension-language @var{.ext} @var{language}
5671Set source files with extension @var{.ext} to be assumed to be in
5672the source language @var{language}.
5673
5674@item info extensions
5675List all the filename extensions and the associated languages.
5676@end table
5677
6d2ebf8b 5678@node Checks
c906108c
SS
5679@section Type and range checking
5680
5681@quotation
5682@emph{Warning:} In this release, the @value{GDBN} commands for type and range
5683checking are included, but they do not yet have any effect. This
5684section documents the intended facilities.
5685@end quotation
5686@c FIXME remove warning when type/range code added
5687
5688Some languages are designed to guard you against making seemingly common
5689errors through a series of compile- and run-time checks. These include
5690checking the type of arguments to functions and operators, and making
5691sure mathematical overflows are caught at run time. Checks such as
5692these help to ensure a program's correctness once it has been compiled
5693by eliminating type mismatches, and providing active checks for range
5694errors when your program is running.
5695
5696@value{GDBN} can check for conditions like the above if you wish.
5697Although @value{GDBN} does not check the statements in your program, it
5698can check expressions entered directly into @value{GDBN} for evaluation via
5699the @code{print} command, for example. As with the working language,
5700@value{GDBN} can also decide whether or not to check automatically based on
5701your program's source language. @xref{Support, ,Supported languages},
5702for the default settings of supported languages.
5703
5704@menu
5705* Type Checking:: An overview of type checking
5706* Range Checking:: An overview of range checking
5707@end menu
5708
5709@cindex type checking
5710@cindex checks, type
6d2ebf8b 5711@node Type Checking
c906108c
SS
5712@subsection An overview of type checking
5713
5714Some languages, such as Modula-2, are strongly typed, meaning that the
5715arguments to operators and functions have to be of the correct type,
5716otherwise an error occurs. These checks prevent type mismatch
5717errors from ever causing any run-time problems. For example,
5718
5719@smallexample
57201 + 2 @result{} 3
5721@exdent but
5722@error{} 1 + 2.3
5723@end smallexample
5724
5725The second example fails because the @code{CARDINAL} 1 is not
5726type-compatible with the @code{REAL} 2.3.
5727
5d161b24
DB
5728For the expressions you use in @value{GDBN} commands, you can tell the
5729@value{GDBN} type checker to skip checking;
5730to treat any mismatches as errors and abandon the expression;
5731or to only issue warnings when type mismatches occur,
c906108c
SS
5732but evaluate the expression anyway. When you choose the last of
5733these, @value{GDBN} evaluates expressions like the second example above, but
5734also issues a warning.
5735
5d161b24
DB
5736Even if you turn type checking off, there may be other reasons
5737related to type that prevent @value{GDBN} from evaluating an expression.
5738For instance, @value{GDBN} does not know how to add an @code{int} and
5739a @code{struct foo}. These particular type errors have nothing to do
5740with the language in use, and usually arise from expressions, such as
c906108c
SS
5741the one described above, which make little sense to evaluate anyway.
5742
5743Each language defines to what degree it is strict about type. For
5744instance, both Modula-2 and C require the arguments to arithmetical
5745operators to be numbers. In C, enumerated types and pointers can be
5746represented as numbers, so that they are valid arguments to mathematical
5747operators. @xref{Support, ,Supported languages}, for further
5748details on specific languages.
5749
5750@value{GDBN} provides some additional commands for controlling the type checker:
5751
d4f3574e 5752@kindex set check@r{, type}
c906108c
SS
5753@kindex set check type
5754@kindex show check type
5755@table @code
5756@item set check type auto
5757Set type checking on or off based on the current working language.
5758@xref{Support, ,Supported languages}, for the default settings for
5759each language.
5760
5761@item set check type on
5762@itemx set check type off
5763Set type checking on or off, overriding the default setting for the
5764current working language. Issue a warning if the setting does not
5765match the language default. If any type mismatches occur in
d4f3574e 5766evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
5767message and aborts evaluation of the expression.
5768
5769@item set check type warn
5770Cause the type checker to issue warnings, but to always attempt to
5771evaluate the expression. Evaluating the expression may still
5772be impossible for other reasons. For example, @value{GDBN} cannot add
5773numbers and structures.
5774
5775@item show type
5d161b24 5776Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
5777is setting it automatically.
5778@end table
5779
5780@cindex range checking
5781@cindex checks, range
6d2ebf8b 5782@node Range Checking
c906108c
SS
5783@subsection An overview of range checking
5784
5785In some languages (such as Modula-2), it is an error to exceed the
5786bounds of a type; this is enforced with run-time checks. Such range
5787checking is meant to ensure program correctness by making sure
5788computations do not overflow, or indices on an array element access do
5789not exceed the bounds of the array.
5790
5791For expressions you use in @value{GDBN} commands, you can tell
5792@value{GDBN} to treat range errors in one of three ways: ignore them,
5793always treat them as errors and abandon the expression, or issue
5794warnings but evaluate the expression anyway.
5795
5796A range error can result from numerical overflow, from exceeding an
5797array index bound, or when you type a constant that is not a member
5798of any type. Some languages, however, do not treat overflows as an
5799error. In many implementations of C, mathematical overflow causes the
5800result to ``wrap around'' to lower values---for example, if @var{m} is
5801the largest integer value, and @var{s} is the smallest, then
5802
5803@example
5804@var{m} + 1 @result{} @var{s}
5805@end example
5806
5807This, too, is specific to individual languages, and in some cases
5808specific to individual compilers or machines. @xref{Support, ,
5809Supported languages}, for further details on specific languages.
5810
5811@value{GDBN} provides some additional commands for controlling the range checker:
5812
d4f3574e 5813@kindex set check@r{, range}
c906108c
SS
5814@kindex set check range
5815@kindex show check range
5816@table @code
5817@item set check range auto
5818Set range checking on or off based on the current working language.
5819@xref{Support, ,Supported languages}, for the default settings for
5820each language.
5821
5822@item set check range on
5823@itemx set check range off
5824Set range checking on or off, overriding the default setting for the
5825current working language. A warning is issued if the setting does not
c3f6f71d
JM
5826match the language default. If a range error occurs and range checking is on,
5827then a message is printed and evaluation of the expression is aborted.
c906108c
SS
5828
5829@item set check range warn
5830Output messages when the @value{GDBN} range checker detects a range error,
5831but attempt to evaluate the expression anyway. Evaluating the
5832expression may still be impossible for other reasons, such as accessing
5833memory that the process does not own (a typical example from many Unix
5834systems).
5835
5836@item show range
5837Show the current setting of the range checker, and whether or not it is
5838being set automatically by @value{GDBN}.
5839@end table
c906108c 5840
6d2ebf8b 5841@node Support
c906108c 5842@section Supported languages
c906108c 5843
cce74817
JM
5844@value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5845@c This is false ...
c906108c
SS
5846Some @value{GDBN} features may be used in expressions regardless of the
5847language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5848and the @samp{@{type@}addr} construct (@pxref{Expressions,
5849,Expressions}) can be used with the constructs of any supported
5850language.
5851
5852The following sections detail to what degree each source language is
5853supported by @value{GDBN}. These sections are not meant to be language
5854tutorials or references, but serve only as a reference guide to what the
5855@value{GDBN} expression parser accepts, and what input and output
5856formats should look like for different languages. There are many good
5857books written on each of these languages; please look to these for a
5858language reference or tutorial.
5859
c906108c 5860@menu
7a292a7a 5861* C:: C and C++
cce74817 5862* Modula-2:: Modula-2
104c1213 5863* Chill:: Chill
c906108c
SS
5864@end menu
5865
6d2ebf8b 5866@node C
c906108c 5867@subsection C and C++
7a292a7a 5868
c906108c
SS
5869@cindex C and C++
5870@cindex expressions in C or C++
c906108c
SS
5871
5872Since C and C++ are so closely related, many features of @value{GDBN} apply
5873to both languages. Whenever this is the case, we discuss those languages
5874together.
5875
41afff9a
EZ
5876@cindex C@t{++}
5877@cindex @code{g++}, @sc{gnu} C@t{++} compiler
c906108c
SS
5878@cindex @sc{gnu} C++
5879The C++ debugging facilities are jointly implemented by the C++
5880compiler and @value{GDBN}. Therefore, to debug your C++ code
5881effectively, you must compile your C++ programs with a supported
5882C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5883compiler (@code{aCC}).
5884
5885For best results when using @sc{gnu} C++, use the stabs debugging
5886format. You can select that format explicitly with the @code{g++}
5887command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5888@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5889CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 5890
c906108c
SS
5891@menu
5892* C Operators:: C and C++ operators
5893* C Constants:: C and C++ constants
7a292a7a 5894* C plus plus expressions:: C++ expressions
c906108c 5895* C Defaults:: Default settings for C and C++
c906108c 5896* C Checks:: C and C++ type and range checks
c906108c
SS
5897* Debugging C:: @value{GDBN} and C
5898* Debugging C plus plus:: @value{GDBN} features for C++
5899@end menu
c906108c 5900
6d2ebf8b 5901@node C Operators
c906108c 5902@subsubsection C and C++ operators
7a292a7a
SS
5903
5904@cindex C and C++ operators
c906108c
SS
5905
5906Operators must be defined on values of specific types. For instance,
5907@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 5908often defined on groups of types.
c906108c 5909
c906108c 5910For the purposes of C and C++, the following definitions hold:
c906108c
SS
5911
5912@itemize @bullet
53a5351d 5913
c906108c 5914@item
c906108c
SS
5915@emph{Integral types} include @code{int} with any of its storage-class
5916specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
c906108c
SS
5917
5918@item
d4f3574e
SS
5919@emph{Floating-point types} include @code{float}, @code{double}, and
5920@code{long double} (if supported by the target platform).
c906108c
SS
5921
5922@item
53a5351d 5923@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
5924
5925@item
5926@emph{Scalar types} include all of the above.
53a5351d 5927
c906108c
SS
5928@end itemize
5929
5930@noindent
5931The following operators are supported. They are listed here
5932in order of increasing precedence:
5933
5934@table @code
5935@item ,
5936The comma or sequencing operator. Expressions in a comma-separated list
5937are evaluated from left to right, with the result of the entire
5938expression being the last expression evaluated.
5939
5940@item =
5941Assignment. The value of an assignment expression is the value
5942assigned. Defined on scalar types.
5943
5944@item @var{op}=
5945Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5946and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 5947@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
5948@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5949@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5950
5951@item ?:
5952The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5953of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5954integral type.
5955
5956@item ||
5957Logical @sc{or}. Defined on integral types.
5958
5959@item &&
5960Logical @sc{and}. Defined on integral types.
5961
5962@item |
5963Bitwise @sc{or}. Defined on integral types.
5964
5965@item ^
5966Bitwise exclusive-@sc{or}. Defined on integral types.
5967
5968@item &
5969Bitwise @sc{and}. Defined on integral types.
5970
5971@item ==@r{, }!=
5972Equality and inequality. Defined on scalar types. The value of these
5973expressions is 0 for false and non-zero for true.
5974
5975@item <@r{, }>@r{, }<=@r{, }>=
5976Less than, greater than, less than or equal, greater than or equal.
5977Defined on scalar types. The value of these expressions is 0 for false
5978and non-zero for true.
5979
5980@item <<@r{, }>>
5981left shift, and right shift. Defined on integral types.
5982
5983@item @@
5984The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5985
5986@item +@r{, }-
5987Addition and subtraction. Defined on integral types, floating-point types and
5988pointer types.
5989
5990@item *@r{, }/@r{, }%
5991Multiplication, division, and modulus. Multiplication and division are
5992defined on integral and floating-point types. Modulus is defined on
5993integral types.
5994
5995@item ++@r{, }--
5996Increment and decrement. When appearing before a variable, the
5997operation is performed before the variable is used in an expression;
5998when appearing after it, the variable's value is used before the
5999operation takes place.
6000
6001@item *
6002Pointer dereferencing. Defined on pointer types. Same precedence as
6003@code{++}.
6004
6005@item &
6006Address operator. Defined on variables. Same precedence as @code{++}.
6007
c906108c
SS
6008For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6009allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6010(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6011where a C++ reference variable (declared with @samp{&@var{ref}}) is
6012stored.
c906108c
SS
6013
6014@item -
6015Negative. Defined on integral and floating-point types. Same
6016precedence as @code{++}.
6017
6018@item !
6019Logical negation. Defined on integral types. Same precedence as
6020@code{++}.
6021
6022@item ~
6023Bitwise complement operator. Defined on integral types. Same precedence as
6024@code{++}.
6025
6026
6027@item .@r{, }->
6028Structure member, and pointer-to-structure member. For convenience,
6029@value{GDBN} regards the two as equivalent, choosing whether to dereference a
6030pointer based on the stored type information.
6031Defined on @code{struct} and @code{union} data.
6032
c906108c
SS
6033@item .*@r{, }->*
6034Dereferences of pointers to members.
c906108c
SS
6035
6036@item []
6037Array indexing. @code{@var{a}[@var{i}]} is defined as
6038@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6039
6040@item ()
6041Function parameter list. Same precedence as @code{->}.
6042
c906108c 6043@item ::
7a292a7a
SS
6044C++ scope resolution operator. Defined on @code{struct}, @code{union},
6045and @code{class} types.
c906108c
SS
6046
6047@item ::
7a292a7a
SS
6048Doubled colons also represent the @value{GDBN} scope operator
6049(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6050above.
c906108c
SS
6051@end table
6052
c906108c
SS
6053If an operator is redefined in the user code, @value{GDBN} usually
6054attempts to invoke the redefined version instead of using the operator's
6055predefined meaning.
c906108c 6056
c906108c 6057@menu
5d161b24 6058* C Constants::
c906108c
SS
6059@end menu
6060
6d2ebf8b 6061@node C Constants
c906108c 6062@subsubsection C and C++ constants
c906108c
SS
6063
6064@cindex C and C++ constants
c906108c 6065
7a292a7a 6066@value{GDBN} allows you to express the constants of C and C++ in the
c906108c 6067following ways:
c906108c
SS
6068
6069@itemize @bullet
6070@item
6071Integer constants are a sequence of digits. Octal constants are
6072specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6073a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6074@samp{l}, specifying that the constant should be treated as a
6075@code{long} value.
6076
6077@item
6078Floating point constants are a sequence of digits, followed by a decimal
6079point, followed by a sequence of digits, and optionally followed by an
6080exponent. An exponent is of the form:
6081@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6082sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
6083A floating-point constant may also end with a letter @samp{f} or
6084@samp{F}, specifying that the constant should be treated as being of
6085the @code{float} (as opposed to the default @code{double}) type; or with
6086a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6087constant.
c906108c
SS
6088
6089@item
6090Enumerated constants consist of enumerated identifiers, or their
6091integral equivalents.
6092
6093@item
6094Character constants are a single character surrounded by single quotes
6095(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 6096(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
6097be represented by a letter or by @dfn{escape sequences}, which are of
6098the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6099of the character's ordinal value; or of the form @samp{\@var{x}}, where
6100@samp{@var{x}} is a predefined special character---for example,
6101@samp{\n} for newline.
6102
6103@item
96a2c332
SS
6104String constants are a sequence of character constants surrounded by
6105double quotes (@code{"}). Any valid character constant (as described
6106above) may appear. Double quotes within the string must be preceded by
6107a backslash, so for instance @samp{"a\"b'c"} is a string of five
6108characters.
c906108c
SS
6109
6110@item
6111Pointer constants are an integral value. You can also write pointers
6112to constants using the C operator @samp{&}.
6113
6114@item
6115Array constants are comma-separated lists surrounded by braces @samp{@{}
6116and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6117integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6118and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6119@end itemize
6120
c906108c 6121@menu
5d161b24
DB
6122* C plus plus expressions::
6123* C Defaults::
6124* C Checks::
c906108c 6125
5d161b24 6126* Debugging C::
c906108c
SS
6127@end menu
6128
6d2ebf8b 6129@node C plus plus expressions
c906108c 6130@subsubsection C++ expressions
c906108c
SS
6131
6132@cindex expressions in C++
6133@value{GDBN} expression handling can interpret most C++ expressions.
6134
c906108c
SS
6135@cindex C++ support, not in @sc{coff}
6136@cindex @sc{coff} versus C++
6137@cindex C++ and object formats
6138@cindex object formats and C++
6139@cindex a.out and C++
6140@cindex @sc{ecoff} and C++
6141@cindex @sc{xcoff} and C++
6142@cindex @sc{elf}/stabs and C++
6143@cindex @sc{elf}/@sc{dwarf} and C++
6144@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6145@c periodically whether this has happened...
6146@quotation
6147@emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6148proper compiler. Typically, C++ debugging depends on the use of
6149additional debugging information in the symbol table, and thus requires
6150special support. In particular, if your compiler generates a.out, MIPS
6151@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6152symbol table, these facilities are all available. (With @sc{gnu} CC,
6153you can use the @samp{-gstabs} option to request stabs debugging
6154extensions explicitly.) Where the object code format is standard
6155@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6156support in @value{GDBN} does @emph{not} work.
6157@end quotation
c906108c
SS
6158
6159@enumerate
6160
6161@cindex member functions
6162@item
6163Member function calls are allowed; you can use expressions like
6164
6165@example
6166count = aml->GetOriginal(x, y)
6167@end example
6168
41afff9a 6169@vindex this@r{, inside C@t{++} member functions}
c906108c
SS
6170@cindex namespace in C++
6171@item
6172While a member function is active (in the selected stack frame), your
6173expressions have the same namespace available as the member function;
6174that is, @value{GDBN} allows implicit references to the class instance
6175pointer @code{this} following the same rules as C++.
6176
c906108c 6177@cindex call overloaded functions
d4f3574e 6178@cindex overloaded functions, calling
c906108c
SS
6179@cindex type conversions in C++
6180@item
6181You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 6182call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
6183perform overload resolution involving user-defined type conversions,
6184calls to constructors, or instantiations of templates that do not exist
6185in the program. It also cannot handle ellipsis argument lists or
6186default arguments.
6187
6188It does perform integral conversions and promotions, floating-point
6189promotions, arithmetic conversions, pointer conversions, conversions of
6190class objects to base classes, and standard conversions such as those of
6191functions or arrays to pointers; it requires an exact match on the
6192number of function arguments.
6193
6194Overload resolution is always performed, unless you have specified
6195@code{set overload-resolution off}. @xref{Debugging C plus plus,
6196,@value{GDBN} features for C++}.
6197
d4f3574e 6198You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
6199explicit function signature to call an overloaded function, as in
6200@smallexample
6201p 'foo(char,int)'('x', 13)
6202@end smallexample
d4f3574e 6203
c906108c 6204The @value{GDBN} command-completion facility can simplify this;
d4f3574e 6205see @ref{Completion, ,Command completion}.
c906108c 6206
c906108c
SS
6207@cindex reference declarations
6208@item
5d161b24 6209@value{GDBN} understands variables declared as C++ references; you can use
c906108c
SS
6210them in expressions just as you do in C++ source---they are automatically
6211dereferenced.
6212
6213In the parameter list shown when @value{GDBN} displays a frame, the values of
6214reference variables are not displayed (unlike other variables); this
6215avoids clutter, since references are often used for large structures.
6216The @emph{address} of a reference variable is always shown, unless
6217you have specified @samp{set print address off}.
6218
6219@item
6220@value{GDBN} supports the C++ name resolution operator @code{::}---your
6221expressions can use it just as expressions in your program do. Since
6222one scope may be defined in another, you can use @code{::} repeatedly if
6223necessary, for example in an expression like
6224@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6225resolving name scope by reference to source files, in both C and C++
6226debugging (@pxref{Variables, ,Program variables}).
6227@end enumerate
6228
53a5351d
JM
6229In addition, when used with HP's C++ compiler, @value{GDBN} supports
6230calling virtual functions correctly, printing out virtual bases of
6231objects, calling functions in a base subobject, casting objects, and
6232invoking user-defined operators.
c906108c 6233
6d2ebf8b 6234@node C Defaults
c906108c 6235@subsubsection C and C++ defaults
7a292a7a 6236
c906108c
SS
6237@cindex C and C++ defaults
6238
c906108c
SS
6239If you allow @value{GDBN} to set type and range checking automatically, they
6240both default to @code{off} whenever the working language changes to
6241C or C++. This happens regardless of whether you or @value{GDBN}
6242selects the working language.
c906108c
SS
6243
6244If you allow @value{GDBN} to set the language automatically, it
6245recognizes source files whose names end with @file{.c}, @file{.C}, or
6246@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6247these files, it sets the working language to C or C++.
6248@xref{Automatically, ,Having @value{GDBN} infer the source language},
6249for further details.
6250
c906108c
SS
6251@c Type checking is (a) primarily motivated by Modula-2, and (b)
6252@c unimplemented. If (b) changes, it might make sense to let this node
6253@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 6254
6d2ebf8b 6255@node C Checks
c906108c 6256@subsubsection C and C++ type and range checks
7a292a7a 6257
c906108c
SS
6258@cindex C and C++ checks
6259
6260By default, when @value{GDBN} parses C or C++ expressions, type checking
6261is not used. However, if you turn type checking on, @value{GDBN}
6262considers two variables type equivalent if:
6263
6264@itemize @bullet
6265@item
6266The two variables are structured and have the same structure, union, or
6267enumerated tag.
6268
6269@item
6270The two variables have the same type name, or types that have been
6271declared equivalent through @code{typedef}.
6272
6273@ignore
6274@c leaving this out because neither J Gilmore nor R Pesch understand it.
6275@c FIXME--beers?
6276@item
6277The two @code{struct}, @code{union}, or @code{enum} variables are
6278declared in the same declaration. (Note: this may not be true for all C
6279compilers.)
6280@end ignore
6281@end itemize
6282
6283Range checking, if turned on, is done on mathematical operations. Array
6284indices are not checked, since they are often used to index a pointer
6285that is not itself an array.
c906108c 6286
6d2ebf8b 6287@node Debugging C
c906108c 6288@subsubsection @value{GDBN} and C
c906108c
SS
6289
6290The @code{set print union} and @code{show print union} commands apply to
6291the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
6292inside a @code{struct} or @code{class} is also printed. Otherwise, it
6293appears as @samp{@{...@}}.
c906108c
SS
6294
6295The @code{@@} operator aids in the debugging of dynamic arrays, formed
6296with pointers and a memory allocation function. @xref{Expressions,
6297,Expressions}.
6298
c906108c 6299@menu
5d161b24 6300* Debugging C plus plus::
c906108c
SS
6301@end menu
6302
6d2ebf8b 6303@node Debugging C plus plus
c906108c 6304@subsubsection @value{GDBN} features for C++
c906108c
SS
6305
6306@cindex commands for C++
7a292a7a 6307
c906108c
SS
6308Some @value{GDBN} commands are particularly useful with C++, and some are
6309designed specifically for use with C++. Here is a summary:
6310
6311@table @code
6312@cindex break in overloaded functions
6313@item @r{breakpoint menus}
6314When you want a breakpoint in a function whose name is overloaded,
6315@value{GDBN} breakpoint menus help you specify which function definition
6316you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6317
6318@cindex overloading in C++
6319@item rbreak @var{regex}
6320Setting breakpoints using regular expressions is helpful for setting
6321breakpoints on overloaded functions that are not members of any special
6322classes.
6323@xref{Set Breaks, ,Setting breakpoints}.
6324
6325@cindex C++ exception handling
6326@item catch throw
6327@itemx catch catch
6328Debug C++ exception handling using these commands. @xref{Set
6329Catchpoints, , Setting catchpoints}.
6330
6331@cindex inheritance
6332@item ptype @var{typename}
6333Print inheritance relationships as well as other information for type
6334@var{typename}.
6335@xref{Symbols, ,Examining the Symbol Table}.
6336
6337@cindex C++ symbol display
6338@item set print demangle
6339@itemx show print demangle
6340@itemx set print asm-demangle
6341@itemx show print asm-demangle
6342Control whether C++ symbols display in their source form, both when
6343displaying code as C++ source and when displaying disassemblies.
6344@xref{Print Settings, ,Print settings}.
6345
6346@item set print object
6347@itemx show print object
6348Choose whether to print derived (actual) or declared types of objects.
6349@xref{Print Settings, ,Print settings}.
6350
6351@item set print vtbl
6352@itemx show print vtbl
6353Control the format for printing virtual function tables.
6354@xref{Print Settings, ,Print settings}.
c906108c
SS
6355(The @code{vtbl} commands do not work on programs compiled with the HP
6356ANSI C++ compiler (@code{aCC}).)
6357
6358@kindex set overload-resolution
d4f3574e 6359@cindex overloaded functions, overload resolution
c906108c
SS
6360@item set overload-resolution on
6361Enable overload resolution for C++ expression evaluation. The default
6362is on. For overloaded functions, @value{GDBN} evaluates the arguments
6363and searches for a function whose signature matches the argument types,
d4f3574e
SS
6364using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6365expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
6366message.
6367
6368@item set overload-resolution off
6369Disable overload resolution for C++ expression evaluation. For
6370overloaded functions that are not class member functions, @value{GDBN}
6371chooses the first function of the specified name that it finds in the
6372symbol table, whether or not its arguments are of the correct type. For
6373overloaded functions that are class member functions, @value{GDBN}
6374searches for a function whose signature @emph{exactly} matches the
6375argument types.
c906108c
SS
6376
6377@item @r{Overloaded symbol names}
6378You can specify a particular definition of an overloaded symbol, using
6379the same notation that is used to declare such symbols in C++: type
6380@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6381also use the @value{GDBN} command-line word completion facilities to list the
6382available choices, or to finish the type list for you.
6383@xref{Completion,, Command completion}, for details on how to do this.
6384@end table
c906108c 6385
6d2ebf8b 6386@node Modula-2
c906108c 6387@subsection Modula-2
7a292a7a 6388
d4f3574e 6389@cindex Modula-2, @value{GDBN} support
c906108c
SS
6390
6391The extensions made to @value{GDBN} to support Modula-2 only support
6392output from the @sc{gnu} Modula-2 compiler (which is currently being
6393developed). Other Modula-2 compilers are not currently supported, and
6394attempting to debug executables produced by them is most likely
6395to give an error as @value{GDBN} reads in the executable's symbol
6396table.
6397
6398@cindex expressions in Modula-2
6399@menu
6400* M2 Operators:: Built-in operators
6401* Built-In Func/Proc:: Built-in functions and procedures
6402* M2 Constants:: Modula-2 constants
6403* M2 Defaults:: Default settings for Modula-2
6404* Deviations:: Deviations from standard Modula-2
6405* M2 Checks:: Modula-2 type and range checks
6406* M2 Scope:: The scope operators @code{::} and @code{.}
6407* GDB/M2:: @value{GDBN} and Modula-2
6408@end menu
6409
6d2ebf8b 6410@node M2 Operators
c906108c
SS
6411@subsubsection Operators
6412@cindex Modula-2 operators
6413
6414Operators must be defined on values of specific types. For instance,
6415@code{+} is defined on numbers, but not on structures. Operators are
6416often defined on groups of types. For the purposes of Modula-2, the
6417following definitions hold:
6418
6419@itemize @bullet
6420
6421@item
6422@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6423their subranges.
6424
6425@item
6426@emph{Character types} consist of @code{CHAR} and its subranges.
6427
6428@item
6429@emph{Floating-point types} consist of @code{REAL}.
6430
6431@item
6432@emph{Pointer types} consist of anything declared as @code{POINTER TO
6433@var{type}}.
6434
6435@item
6436@emph{Scalar types} consist of all of the above.
6437
6438@item
6439@emph{Set types} consist of @code{SET} and @code{BITSET} types.
6440
6441@item
6442@emph{Boolean types} consist of @code{BOOLEAN}.
6443@end itemize
6444
6445@noindent
6446The following operators are supported, and appear in order of
6447increasing precedence:
6448
6449@table @code
6450@item ,
6451Function argument or array index separator.
6452
6453@item :=
6454Assignment. The value of @var{var} @code{:=} @var{value} is
6455@var{value}.
6456
6457@item <@r{, }>
6458Less than, greater than on integral, floating-point, or enumerated
6459types.
6460
6461@item <=@r{, }>=
96a2c332 6462Less than or equal to, greater than or equal to
c906108c
SS
6463on integral, floating-point and enumerated types, or set inclusion on
6464set types. Same precedence as @code{<}.
6465
6466@item =@r{, }<>@r{, }#
6467Equality and two ways of expressing inequality, valid on scalar types.
6468Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6469available for inequality, since @code{#} conflicts with the script
6470comment character.
6471
6472@item IN
6473Set membership. Defined on set types and the types of their members.
6474Same precedence as @code{<}.
6475
6476@item OR
6477Boolean disjunction. Defined on boolean types.
6478
6479@item AND@r{, }&
d4f3574e 6480Boolean conjunction. Defined on boolean types.
c906108c
SS
6481
6482@item @@
6483The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6484
6485@item +@r{, }-
6486Addition and subtraction on integral and floating-point types, or union
6487and difference on set types.
6488
6489@item *
6490Multiplication on integral and floating-point types, or set intersection
6491on set types.
6492
6493@item /
6494Division on floating-point types, or symmetric set difference on set
6495types. Same precedence as @code{*}.
6496
6497@item DIV@r{, }MOD
6498Integer division and remainder. Defined on integral types. Same
6499precedence as @code{*}.
6500
6501@item -
6502Negative. Defined on @code{INTEGER} and @code{REAL} data.
6503
6504@item ^
6505Pointer dereferencing. Defined on pointer types.
6506
6507@item NOT
6508Boolean negation. Defined on boolean types. Same precedence as
6509@code{^}.
6510
6511@item .
6512@code{RECORD} field selector. Defined on @code{RECORD} data. Same
6513precedence as @code{^}.
6514
6515@item []
6516Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6517
6518@item ()
6519Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6520as @code{^}.
6521
6522@item ::@r{, }.
6523@value{GDBN} and Modula-2 scope operators.
6524@end table
6525
6526@quotation
6527@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6528treats the use of the operator @code{IN}, or the use of operators
6529@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6530@code{<=}, and @code{>=} on sets as an error.
6531@end quotation
6532
6533@cindex Modula-2 built-ins
6d2ebf8b 6534@node Built-In Func/Proc
c906108c
SS
6535@subsubsection Built-in functions and procedures
6536
6537Modula-2 also makes available several built-in procedures and functions.
6538In describing these, the following metavariables are used:
6539
6540@table @var
6541
6542@item a
6543represents an @code{ARRAY} variable.
6544
6545@item c
6546represents a @code{CHAR} constant or variable.
6547
6548@item i
6549represents a variable or constant of integral type.
6550
6551@item m
6552represents an identifier that belongs to a set. Generally used in the
6553same function with the metavariable @var{s}. The type of @var{s} should
6554be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6555
6556@item n
6557represents a variable or constant of integral or floating-point type.
6558
6559@item r
6560represents a variable or constant of floating-point type.
6561
6562@item t
6563represents a type.
6564
6565@item v
6566represents a variable.
6567
6568@item x
6569represents a variable or constant of one of many types. See the
6570explanation of the function for details.
6571@end table
6572
6573All Modula-2 built-in procedures also return a result, described below.
6574
6575@table @code
6576@item ABS(@var{n})
6577Returns the absolute value of @var{n}.
6578
6579@item CAP(@var{c})
6580If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 6581equivalent, otherwise it returns its argument.
c906108c
SS
6582
6583@item CHR(@var{i})
6584Returns the character whose ordinal value is @var{i}.
6585
6586@item DEC(@var{v})
c3f6f71d 6587Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6588
6589@item DEC(@var{v},@var{i})
6590Decrements the value in the variable @var{v} by @var{i}. Returns the
6591new value.
6592
6593@item EXCL(@var{m},@var{s})
6594Removes the element @var{m} from the set @var{s}. Returns the new
6595set.
6596
6597@item FLOAT(@var{i})
6598Returns the floating point equivalent of the integer @var{i}.
6599
6600@item HIGH(@var{a})
6601Returns the index of the last member of @var{a}.
6602
6603@item INC(@var{v})
c3f6f71d 6604Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6605
6606@item INC(@var{v},@var{i})
6607Increments the value in the variable @var{v} by @var{i}. Returns the
6608new value.
6609
6610@item INCL(@var{m},@var{s})
6611Adds the element @var{m} to the set @var{s} if it is not already
6612there. Returns the new set.
6613
6614@item MAX(@var{t})
6615Returns the maximum value of the type @var{t}.
6616
6617@item MIN(@var{t})
6618Returns the minimum value of the type @var{t}.
6619
6620@item ODD(@var{i})
6621Returns boolean TRUE if @var{i} is an odd number.
6622
6623@item ORD(@var{x})
6624Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
6625value of a character is its @sc{ascii} value (on machines supporting the
6626@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
6627integral, character and enumerated types.
6628
6629@item SIZE(@var{x})
6630Returns the size of its argument. @var{x} can be a variable or a type.
6631
6632@item TRUNC(@var{r})
6633Returns the integral part of @var{r}.
6634
6635@item VAL(@var{t},@var{i})
6636Returns the member of the type @var{t} whose ordinal value is @var{i}.
6637@end table
6638
6639@quotation
6640@emph{Warning:} Sets and their operations are not yet supported, so
6641@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6642an error.
6643@end quotation
6644
6645@cindex Modula-2 constants
6d2ebf8b 6646@node M2 Constants
c906108c
SS
6647@subsubsection Constants
6648
6649@value{GDBN} allows you to express the constants of Modula-2 in the following
6650ways:
6651
6652@itemize @bullet
6653
6654@item
6655Integer constants are simply a sequence of digits. When used in an
6656expression, a constant is interpreted to be type-compatible with the
6657rest of the expression. Hexadecimal integers are specified by a
6658trailing @samp{H}, and octal integers by a trailing @samp{B}.
6659
6660@item
6661Floating point constants appear as a sequence of digits, followed by a
6662decimal point and another sequence of digits. An optional exponent can
6663then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6664@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6665digits of the floating point constant must be valid decimal (base 10)
6666digits.
6667
6668@item
6669Character constants consist of a single character enclosed by a pair of
6670like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 6671also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
6672followed by a @samp{C}.
6673
6674@item
6675String constants consist of a sequence of characters enclosed by a
6676pair of like quotes, either single (@code{'}) or double (@code{"}).
6677Escape sequences in the style of C are also allowed. @xref{C
6678Constants, ,C and C++ constants}, for a brief explanation of escape
6679sequences.
6680
6681@item
6682Enumerated constants consist of an enumerated identifier.
6683
6684@item
6685Boolean constants consist of the identifiers @code{TRUE} and
6686@code{FALSE}.
6687
6688@item
6689Pointer constants consist of integral values only.
6690
6691@item
6692Set constants are not yet supported.
6693@end itemize
6694
6d2ebf8b 6695@node M2 Defaults
c906108c
SS
6696@subsubsection Modula-2 defaults
6697@cindex Modula-2 defaults
6698
6699If type and range checking are set automatically by @value{GDBN}, they
6700both default to @code{on} whenever the working language changes to
d4f3574e 6701Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
6702selected the working language.
6703
6704If you allow @value{GDBN} to set the language automatically, then entering
6705code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 6706working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
6707the language automatically}, for further details.
6708
6d2ebf8b 6709@node Deviations
c906108c
SS
6710@subsubsection Deviations from standard Modula-2
6711@cindex Modula-2, deviations from
6712
6713A few changes have been made to make Modula-2 programs easier to debug.
6714This is done primarily via loosening its type strictness:
6715
6716@itemize @bullet
6717@item
6718Unlike in standard Modula-2, pointer constants can be formed by
6719integers. This allows you to modify pointer variables during
6720debugging. (In standard Modula-2, the actual address contained in a
6721pointer variable is hidden from you; it can only be modified
6722through direct assignment to another pointer variable or expression that
6723returned a pointer.)
6724
6725@item
6726C escape sequences can be used in strings and characters to represent
6727non-printable characters. @value{GDBN} prints out strings with these
6728escape sequences embedded. Single non-printable characters are
6729printed using the @samp{CHR(@var{nnn})} format.
6730
6731@item
6732The assignment operator (@code{:=}) returns the value of its right-hand
6733argument.
6734
6735@item
6736All built-in procedures both modify @emph{and} return their argument.
6737@end itemize
6738
6d2ebf8b 6739@node M2 Checks
c906108c
SS
6740@subsubsection Modula-2 type and range checks
6741@cindex Modula-2 checks
6742
6743@quotation
6744@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6745range checking.
6746@end quotation
6747@c FIXME remove warning when type/range checks added
6748
6749@value{GDBN} considers two Modula-2 variables type equivalent if:
6750
6751@itemize @bullet
6752@item
6753They are of types that have been declared equivalent via a @code{TYPE
6754@var{t1} = @var{t2}} statement
6755
6756@item
6757They have been declared on the same line. (Note: This is true of the
6758@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6759@end itemize
6760
6761As long as type checking is enabled, any attempt to combine variables
6762whose types are not equivalent is an error.
6763
6764Range checking is done on all mathematical operations, assignment, array
6765index bounds, and all built-in functions and procedures.
6766
6d2ebf8b 6767@node M2 Scope
c906108c
SS
6768@subsubsection The scope operators @code{::} and @code{.}
6769@cindex scope
41afff9a 6770@cindex @code{.}, Modula-2 scope operator
c906108c
SS
6771@cindex colon, doubled as scope operator
6772@ifinfo
41afff9a 6773@vindex colon-colon@r{, in Modula-2}
c906108c
SS
6774@c Info cannot handle :: but TeX can.
6775@end ifinfo
6776@iftex
41afff9a 6777@vindex ::@r{, in Modula-2}
c906108c
SS
6778@end iftex
6779
6780There are a few subtle differences between the Modula-2 scope operator
6781(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6782similar syntax:
6783
6784@example
6785
6786@var{module} . @var{id}
6787@var{scope} :: @var{id}
6788@end example
6789
6790@noindent
6791where @var{scope} is the name of a module or a procedure,
6792@var{module} the name of a module, and @var{id} is any declared
6793identifier within your program, except another module.
6794
6795Using the @code{::} operator makes @value{GDBN} search the scope
6796specified by @var{scope} for the identifier @var{id}. If it is not
6797found in the specified scope, then @value{GDBN} searches all scopes
6798enclosing the one specified by @var{scope}.
6799
6800Using the @code{.} operator makes @value{GDBN} search the current scope for
6801the identifier specified by @var{id} that was imported from the
6802definition module specified by @var{module}. With this operator, it is
6803an error if the identifier @var{id} was not imported from definition
6804module @var{module}, or if @var{id} is not an identifier in
6805@var{module}.
6806
6d2ebf8b 6807@node GDB/M2
c906108c
SS
6808@subsubsection @value{GDBN} and Modula-2
6809
6810Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6811Five subcommands of @code{set print} and @code{show print} apply
6812specifically to C and C++: @samp{vtbl}, @samp{demangle},
6813@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6814apply to C++, and the last to the C @code{union} type, which has no direct
6815analogue in Modula-2.
6816
6817The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 6818with any language, is not useful with Modula-2. Its
c906108c
SS
6819intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6820created in Modula-2 as they can in C or C++. However, because an
6821address can be specified by an integral constant, the construct
d4f3574e 6822@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
6823
6824@cindex @code{#} in Modula-2
6825In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6826interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 6827
6d2ebf8b 6828@node Chill
cce74817
JM
6829@subsection Chill
6830
6831The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 6832from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
6833supported, and attempting to debug executables produced by them is most
6834likely to give an error as @value{GDBN} reads in the executable's symbol
6835table.
6836
d4f3574e
SS
6837@c This used to say "... following Chill related topics ...", but since
6838@c menus are not shown in the printed manual, it would look awkward.
6839This section covers the Chill related topics and the features
cce74817
JM
6840of @value{GDBN} which support these topics.
6841
6842@menu
104c1213
JM
6843* How modes are displayed:: How modes are displayed
6844* Locations:: Locations and their accesses
cce74817 6845* Values and their Operations:: Values and their Operations
5d161b24 6846* Chill type and range checks::
53a5351d 6847* Chill defaults::
cce74817
JM
6848@end menu
6849
6d2ebf8b 6850@node How modes are displayed
cce74817
JM
6851@subsubsection How modes are displayed
6852
6853The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 6854with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
6855slightly from the standard specification of the Chill language. The
6856provided modes are:
d4f3574e
SS
6857
6858@c FIXME: this @table's contents effectively disable @code by using @r
6859@c on every @item. So why does it need @code?
cce74817
JM
6860@table @code
6861@item @r{@emph{Discrete modes:}}
6862@itemize @bullet
6863@item
6864@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6865UINT, LONG, ULONG},
6866@item
5d161b24 6867@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 6868@item
5d161b24 6869@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
6870@item
6871@emph{Set Mode} which is displayed by the keyword @code{SET}.
6872@smallexample
6873(@value{GDBP}) ptype x
6874type = SET (karli = 10, susi = 20, fritzi = 100)
6875@end smallexample
6876If the type is an unnumbered set the set element values are omitted.
6877@item
6d2ebf8b
SS
6878@emph{Range Mode} which is displayed by
6879@smallexample
6880@code{type = <basemode>(<lower bound> : <upper bound>)}
6881@end smallexample
6882where @code{<lower bound>, <upper bound>} can be of any discrete literal
6883expression (e.g. set element names).
cce74817
JM
6884@end itemize
6885
6886@item @r{@emph{Powerset Mode:}}
6887A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 6888the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
6889@smallexample
6890(@value{GDBP}) ptype x
6891type = POWERSET SET (egon, hugo, otto)
6892@end smallexample
6893
6894@item @r{@emph{Reference Modes:}}
6895@itemize @bullet
6896@item
d4f3574e 6897@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
6898followed by the mode name to which the reference is bound.
6899@item
6900@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6901@end itemize
6902
6903@item @r{@emph{Procedure mode}}
6904The procedure mode is displayed by @code{type = PROC(<parameter list>)
6905<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
6906list>} is a list of the parameter modes. @code{<return mode>} indicates
6907the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
6908all possible exceptions which can be raised by the procedure.
6909
6910@ignore
6911@item @r{@emph{Instance mode}}
6912The instance mode is represented by a structure, which has a static
5d161b24 6913type, and is therefore not really of interest.
cce74817
JM
6914@end ignore
6915
5d161b24 6916@item @r{@emph{Synchronization Modes:}}
cce74817
JM
6917@itemize @bullet
6918@item
6d2ebf8b
SS
6919@emph{Event Mode} which is displayed by
6920@smallexample
6921@code{EVENT (<event length>)}
6922@end smallexample
cce74817
JM
6923where @code{(<event length>)} is optional.
6924@item
6d2ebf8b
SS
6925@emph{Buffer Mode} which is displayed by
6926@smallexample
6927@code{BUFFER (<buffer length>)<buffer element mode>}
6928@end smallexample
6929where @code{(<buffer length>)} is optional.
cce74817
JM
6930@end itemize
6931
5d161b24 6932@item @r{@emph{Timing Modes:}}
cce74817
JM
6933@itemize @bullet
6934@item
6935@emph{Duration Mode} which is predefined by @code{DURATION}
6936@item
6937@emph{Absolute Time Mode} which is predefined by @code{TIME}
6938@end itemize
6939
6940@item @r{@emph{Real Modes:}}
6941Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6942
6943@item @r{@emph{String Modes:}}
6944@itemize @bullet
6945@item
6d2ebf8b
SS
6946@emph{Character String Mode} which is displayed by
6947@smallexample
6948@code{CHARS(<string length>)}
6949@end smallexample
6950followed by the keyword @code{VARYING} if the String Mode is a varying
6951mode
cce74817 6952@item
6d2ebf8b
SS
6953@emph{Bit String Mode} which is displayed by
6954@smallexample
6955@code{BOOLS(<string
6956length>)}
6957@end smallexample
cce74817
JM
6958@end itemize
6959
6960@item @r{@emph{Array Mode:}}
6961The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6962followed by the element mode (which may in turn be an array mode).
6963@smallexample
6964(@value{GDBP}) ptype x
5d161b24
DB
6965type = ARRAY (1:42)
6966 ARRAY (1:20)
cce74817
JM
6967 SET (karli = 10, susi = 20, fritzi = 100)
6968@end smallexample
6969
5d161b24 6970@item @r{@emph{Structure Mode}}
cce74817 6971The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
6972list>)}. The @code{<field list>} consists of names and modes of fields
6973of the structure. Variant structures have the keyword @code{CASE <field>
6974OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
6975of the GNU Chill compiler doesn't implement tag processing (no runtime
6976checks of variant fields, and therefore no debugging info), the output
6977always displays all variant fields.
6978@smallexample
6979(@value{GDBP}) ptype str
6980type = STRUCT (
6981 as x,
6982 bs x,
6983 CASE bs OF
6984 (karli):
6985 cs a
6986 (ott):
6987 ds x
6988 ESAC
6989)
6990@end smallexample
6991@end table
6992
6d2ebf8b 6993@node Locations
cce74817
JM
6994@subsubsection Locations and their accesses
6995
6996A location in Chill is an object which can contain values.
6997
6998A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
6999the location. The output conforms to the specification of values in
7000Chill programs. How values are specified
7001is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
7002
7003The pseudo-location @code{RESULT} (or @code{result}) can be used to
7004display or change the result of a currently-active procedure:
d4f3574e 7005
cce74817
JM
7006@smallexample
7007set result := EXPR
7008@end smallexample
d4f3574e
SS
7009
7010@noindent
7011This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 7012is not available in @value{GDBN}).
cce74817
JM
7013
7014Values of reference mode locations are printed by @code{PTR(<hex
7015value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 7016mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
7017represents the address where the reference points to. To access the
7018value of the location referenced by the pointer, use the dereference
d4f3574e 7019operator @samp{->}.
cce74817 7020
6d2ebf8b
SS
7021Values of procedure mode locations are displayed by
7022@smallexample
7023@code{@{ PROC
cce74817 7024(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
7025location>}
7026@end smallexample
7027@code{<argument modes>} is a list of modes according to the parameter
7028specification of the procedure and @code{<address>} shows the address of
7029the entry point.
cce74817
JM
7030
7031@ignore
7032Locations of instance modes are displayed just like a structure with two
7033fields specifying the @emph{process type} and the @emph{copy number} of
7034the investigated instance location@footnote{This comes from the current
d4f3574e
SS
7035implementation of instances. They are implemented as a structure (no
7036na). The output should be something like @code{[<name of the process>;
7037<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
7038@code{__proc_copy}.
7039
7040Locations of synchronization modes are displayed like a structure with
7041the field name @code{__event_data} in case of a event mode location, and
7042like a structure with the field @code{__buffer_data} in case of a buffer
7043mode location (refer to previous paragraph).
7044
7045Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 7046...]}. The @code{<field name>} corresponds to the structure mode
cce74817 7047definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
7048of the field. If the investigated structure mode location is of variant
7049structure mode, the variant parts of the structure are enclosed in curled
7050braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 7051on the same memory location and represent the current values of the
d4f3574e 7052memory location in their specific modes. Since no tag processing is done
cce74817 7053all variants are displayed. A variant field is printed by
d4f3574e 7054@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
7055stuff ???)
7056@smallexample
7057(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7058[.cs: []], (susi) = [.ds: susi]}]
7059@end smallexample
7060@end ignore
7061
7062Substructures of string mode-, array mode- or structure mode-values
7063(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
7064certain operations which are described in the next section, @ref{Values
7065and their Operations}.
cce74817
JM
7066
7067A location value may be interpreted as having a different mode using the
d4f3574e
SS
7068location conversion. This mode conversion is written as @code{<mode
7069name>(<location>)}. The user has to consider that the sizes of the modes
7070have to be equal otherwise an error occurs. Furthermore, no range
7071checking of the location against the destination mode is performed, and
cce74817 7072therefore the result can be quite confusing.
d4f3574e 7073
cce74817
JM
7074@smallexample
7075(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7076@end smallexample
7077
6d2ebf8b 7078@node Values and their Operations
cce74817
JM
7079@subsubsection Values and their Operations
7080
7081Values are used to alter locations, to investigate complex structures in
7082more detail or to filter relevant information out of a large amount of
d4f3574e
SS
7083data. There are several (mode dependent) operations defined which enable
7084such investigations. These operations are not only applicable to
cce74817 7085constant values but also to locations, which can become quite useful
d4f3574e 7086when debugging complex structures. During parsing the command line
cce74817
JM
7087(e.g. evaluating an expression) @value{GDBN} treats location names as
7088the values behind these locations.
7089
d4f3574e 7090This section describes how values have to be specified and which
cce74817
JM
7091operations are legal to be used with such values.
7092
7093@table @code
7094@item Literal Values
d4f3574e
SS
7095Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7096For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 7097chapter 1.5.
d4f3574e
SS
7098@c FIXME: if the Chill Manual is a Texinfo documents, the above should
7099@c be converted to a @ref.
cce74817 7100
5d161b24 7101@ignore
cce74817
JM
7102@itemize @bullet
7103@item
7104@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 7105programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
7106@item
7107@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7108@item
7109@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7110@code{'M'})
7111@item
7112@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e
SS
7113mode. The value delivered by a Set Literal is the set value. This is
7114comparable to an enumeration in C/C++ language.
cce74817 7115@item
d4f3574e 7116@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 7117emptiness literal delivers either the empty reference value, the empty
5d161b24 7118procedure value or the empty instance value.
cce74817
JM
7119
7120@item
7121@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 7122enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
7123to be part of the string literal it has to be stuffed (specified twice).
7124@item
7125@emph{Bitstring Literals} are specified in the same manner as in Chill
7126programs (refer z200/88 chpt 5.2.4.8).
7127@item
7128@emph{Floating point literals} are specified in the same manner as in
d4f3574e 7129(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
7130@end itemize
7131@end ignore
7132
7133@item Tuple Values
7134A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 7135name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
7136unambiguity is derived from the context of a evaluated expression.
7137@code{<tuple>} can be one of the following:
d4f3574e 7138
cce74817
JM
7139@itemize @bullet
7140@item @emph{Powerset Tuple}
7141@item @emph{Array Tuple}
7142@item @emph{Structure Tuple}
7143Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 7144same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
7145@end itemize
7146
7147@item String Element Value
6d2ebf8b
SS
7148A string element value is specified by
7149@smallexample
7150@code{<string value>(<index>)}
7151@end smallexample
d4f3574e 7152where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
7153value which is equivalent to the character indexed by @code{<index>} in
7154the string.
7155
7156@item String Slice Value
7157A string slice value is specified by @code{<string value>(<slice
7158spec>)}, where @code{<slice spec>} can be either a range of integer
7159expressions or specified by @code{<start expr> up <size>}.
7160@code{<size>} denotes the number of elements which the slice contains.
7161The delivered value is a string value, which is part of the specified
7162string.
7163
7164@item Array Element Values
7165An array element value is specified by @code{<array value>(<expr>)} and
7166delivers a array element value of the mode of the specified array.
7167
7168@item Array Slice Values
7169An array slice is specified by @code{<array value>(<slice spec>)}, where
7170@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
7171@code{<start expr> up <size>}. @code{<size>} denotes the number of
7172arrayelements the slice contains. The delivered value is an array value
cce74817
JM
7173which is part of the specified array.
7174
7175@item Structure Field Values
7176A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
7177name>}, where @code{<field name>} indicates the name of a field specified
7178in the mode definition of the structure. The mode of the delivered value
cce74817
JM
7179corresponds to this mode definition in the structure definition.
7180
7181@item Procedure Call Value
7182The procedure call value is derived from the return value of the
7183procedure@footnote{If a procedure call is used for instance in an
7184expression, then this procedure is called with all its side
d4f3574e 7185effects. This can lead to confusing results if used carelessly.}.
cce74817 7186
d4f3574e 7187Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 7188
6d2ebf8b
SS
7189Values of time mode locations appear as
7190@smallexample
7191@code{TIME(<secs>:<nsecs>)}
7192@end smallexample
7193
cce74817
JM
7194
7195@ignore
7196This is not implemented yet:
7197@item Built-in Value
7198@noindent
7199The following built in functions are provided:
d4f3574e 7200
cce74817
JM
7201@table @code
7202@item @code{ADDR()}
7203@item @code{NUM()}
7204@item @code{PRED()}
7205@item @code{SUCC()}
7206@item @code{ABS()}
7207@item @code{CARD()}
7208@item @code{MAX()}
7209@item @code{MIN()}
7210@item @code{SIZE()}
7211@item @code{UPPER()}
7212@item @code{LOWER()}
7213@item @code{LENGTH()}
7214@item @code{SIN()}
7215@item @code{COS()}
7216@item @code{TAN()}
7217@item @code{ARCSIN()}
7218@item @code{ARCCOS()}
7219@item @code{ARCTAN()}
7220@item @code{EXP()}
7221@item @code{LN()}
7222@item @code{LOG()}
7223@item @code{SQRT()}
7224@end table
7225
7226For a detailed description refer to the GNU Chill implementation manual
7227chapter 1.6.
7228@end ignore
7229
7230@item Zero-adic Operator Value
7231The zero-adic operator value is derived from the instance value for the
7232current active process.
7233
7234@item Expression Values
7235The value delivered by an expression is the result of the evaluation of
d4f3574e 7236the specified expression. If there are error conditions (mode
cce74817 7237incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 7238corresponding error message. Expressions may be parenthesised which
cce74817 7239causes the evaluation of this expression before any other expression
d4f3574e 7240which uses the result of the parenthesised expression. The following
cce74817 7241operators are supported by @value{GDBN}:
d4f3574e 7242
cce74817
JM
7243@table @code
7244@item @code{OR, ORIF, XOR}
d4f3574e
SS
7245@itemx @code{AND, ANDIF}
7246@itemx @code{NOT}
cce74817 7247Logical operators defined over operands of boolean mode.
d4f3574e 7248
cce74817
JM
7249@item @code{=, /=}
7250Equality and inequality operators defined over all modes.
d4f3574e 7251
cce74817 7252@item @code{>, >=}
d4f3574e 7253@itemx @code{<, <=}
cce74817 7254Relational operators defined over predefined modes.
d4f3574e 7255
cce74817 7256@item @code{+, -}
d4f3574e 7257@itemx @code{*, /, MOD, REM}
cce74817 7258Arithmetic operators defined over predefined modes.
d4f3574e 7259
cce74817
JM
7260@item @code{-}
7261Change sign operator.
d4f3574e 7262
cce74817
JM
7263@item @code{//}
7264String concatenation operator.
d4f3574e 7265
cce74817
JM
7266@item @code{()}
7267String repetition operator.
d4f3574e 7268
cce74817
JM
7269@item @code{->}
7270Referenced location operator which can be used either to take the
7271address of a location (@code{->loc}), or to dereference a reference
7272location (@code{loc->}).
d4f3574e 7273
cce74817 7274@item @code{OR, XOR}
d4f3574e
SS
7275@itemx @code{AND}
7276@itemx @code{NOT}
cce74817 7277Powerset and bitstring operators.
d4f3574e 7278
cce74817 7279@item @code{>, >=}
d4f3574e 7280@itemx @code{<, <=}
cce74817 7281Powerset inclusion operators.
d4f3574e 7282
cce74817
JM
7283@item @code{IN}
7284Membership operator.
7285@end table
7286@end table
7287
6d2ebf8b 7288@node Chill type and range checks
cce74817
JM
7289@subsubsection Chill type and range checks
7290
7291@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 7292of the two modes are equal. This rule applies recursively to more
cce74817 7293complex datatypes which means that complex modes are treated
d4f3574e 7294equivalent if all element modes (which also can be complex modes like
cce74817
JM
7295structures, arrays, etc.) have the same size.
7296
7297Range checking is done on all mathematical operations, assignment, array
7298index bounds and all built in procedures.
7299
7300Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 7301check strong}. This enforces strong type and range checks on all
cce74817
JM
7302operations where Chill constructs are used (expressions, built in
7303functions, etc.) in respect to the semantics as defined in the z.200
7304language specification.
7305
cce74817
JM
7306All checks can be disabled by the @value{GDBN} command @code{set check
7307off}.
7308
5d161b24 7309@ignore
53a5351d 7310@c Deviations from the Chill Standard Z200/88
cce74817
JM
7311see last paragraph ?
7312@end ignore
7313
6d2ebf8b 7314@node Chill defaults
cce74817
JM
7315@subsubsection Chill defaults
7316
7317If type and range checking are set automatically by @value{GDBN}, they
7318both default to @code{on} whenever the working language changes to
d4f3574e 7319Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
7320selected the working language.
7321
7322If you allow @value{GDBN} to set the language automatically, then entering
7323code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 7324working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
7325the language automatically}, for further details.
7326
6d2ebf8b 7327@node Symbols
c906108c
SS
7328@chapter Examining the Symbol Table
7329
d4f3574e 7330The commands described in this chapter allow you to inquire about the
c906108c
SS
7331symbols (names of variables, functions and types) defined in your
7332program. This information is inherent in the text of your program and
7333does not change as your program executes. @value{GDBN} finds it in your
7334program's symbol table, in the file indicated when you started @value{GDBN}
7335(@pxref{File Options, ,Choosing files}), or by one of the
7336file-management commands (@pxref{Files, ,Commands to specify files}).
7337
7338@cindex symbol names
7339@cindex names of symbols
7340@cindex quoting names
7341Occasionally, you may need to refer to symbols that contain unusual
7342characters, which @value{GDBN} ordinarily treats as word delimiters. The
7343most frequent case is in referring to static variables in other
7344source files (@pxref{Variables,,Program variables}). File names
7345are recorded in object files as debugging symbols, but @value{GDBN} would
7346ordinarily parse a typical file name, like @file{foo.c}, as the three words
7347@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7348@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7349
7350@example
7351p 'foo.c'::x
7352@end example
7353
7354@noindent
7355looks up the value of @code{x} in the scope of the file @file{foo.c}.
7356
7357@table @code
7358@kindex info address
7359@item info address @var{symbol}
7360Describe where the data for @var{symbol} is stored. For a register
7361variable, this says which register it is kept in. For a non-register
7362local variable, this prints the stack-frame offset at which the variable
7363is always stored.
7364
7365Note the contrast with @samp{print &@var{symbol}}, which does not work
7366at all for a register variable, and for a stack local variable prints
7367the exact address of the current instantiation of the variable.
7368
7369@kindex whatis
d4f3574e
SS
7370@item whatis @var{expr}
7371Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
7372actually evaluated, and any side-effecting operations (such as
7373assignments or function calls) inside it do not take place.
7374@xref{Expressions, ,Expressions}.
7375
7376@item whatis
7377Print the data type of @code{$}, the last value in the value history.
7378
7379@kindex ptype
7380@item ptype @var{typename}
7381Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
7382the name of a type, or for C code it may have the form @samp{class
7383@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7384@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 7385
d4f3574e 7386@item ptype @var{expr}
c906108c 7387@itemx ptype
d4f3574e 7388Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
7389differs from @code{whatis} by printing a detailed description, instead
7390of just the name of the type.
7391
7392For example, for this variable declaration:
7393
7394@example
7395struct complex @{double real; double imag;@} v;
7396@end example
7397
7398@noindent
7399the two commands give this output:
7400
7401@example
7402@group
7403(@value{GDBP}) whatis v
7404type = struct complex
7405(@value{GDBP}) ptype v
7406type = struct complex @{
7407 double real;
7408 double imag;
7409@}
7410@end group
7411@end example
7412
7413@noindent
7414As with @code{whatis}, using @code{ptype} without an argument refers to
7415the type of @code{$}, the last value in the value history.
7416
7417@kindex info types
7418@item info types @var{regexp}
7419@itemx info types
d4f3574e 7420Print a brief description of all types whose names match @var{regexp}
c906108c
SS
7421(or all types in your program, if you supply no argument). Each
7422complete typename is matched as though it were a complete line; thus,
7423@samp{i type value} gives information on all types in your program whose
d4f3574e 7424names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
7425information only on types whose complete name is @code{value}.
7426
7427This command differs from @code{ptype} in two ways: first, like
7428@code{whatis}, it does not print a detailed description; second, it
7429lists all source files where a type is defined.
7430
7431@kindex info source
7432@item info source
7433Show the name of the current source file---that is, the source file for
7434the function containing the current point of execution---and the language
7435it was written in.
7436
7437@kindex info sources
7438@item info sources
7439Print the names of all source files in your program for which there is
7440debugging information, organized into two lists: files whose symbols
7441have already been read, and files whose symbols will be read when needed.
7442
7443@kindex info functions
7444@item info functions
7445Print the names and data types of all defined functions.
7446
7447@item info functions @var{regexp}
7448Print the names and data types of all defined functions
7449whose names contain a match for regular expression @var{regexp}.
7450Thus, @samp{info fun step} finds all functions whose names
7451include @code{step}; @samp{info fun ^step} finds those whose names
7452start with @code{step}.
7453
7454@kindex info variables
7455@item info variables
7456Print the names and data types of all variables that are declared
7457outside of functions (i.e., excluding local variables).
7458
7459@item info variables @var{regexp}
7460Print the names and data types of all variables (except for local
7461variables) whose names contain a match for regular expression
7462@var{regexp}.
7463
7464@ignore
7465This was never implemented.
7466@kindex info methods
7467@item info methods
7468@itemx info methods @var{regexp}
7469The @code{info methods} command permits the user to examine all defined
7470methods within C++ program, or (with the @var{regexp} argument) a
7471specific set of methods found in the various C++ classes. Many
7472C++ classes provide a large number of methods. Thus, the output
7473from the @code{ptype} command can be overwhelming and hard to use. The
7474@code{info-methods} command filters the methods, printing only those
7475which match the regular-expression @var{regexp}.
7476@end ignore
7477
c906108c
SS
7478@cindex reloading symbols
7479Some systems allow individual object files that make up your program to
7a292a7a
SS
7480be replaced without stopping and restarting your program. For example,
7481in VxWorks you can simply recompile a defective object file and keep on
7482running. If you are running on one of these systems, you can allow
7483@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
7484
7485@table @code
7486@kindex set symbol-reloading
7487@item set symbol-reloading on
7488Replace symbol definitions for the corresponding source file when an
7489object file with a particular name is seen again.
7490
7491@item set symbol-reloading off
6d2ebf8b
SS
7492Do not replace symbol definitions when encountering object files of the
7493same name more than once. This is the default state; if you are not
7494running on a system that permits automatic relinking of modules, you
7495should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
7496may discard symbols when linking large programs, that may contain
7497several modules (from different directories or libraries) with the same
7498name.
c906108c
SS
7499
7500@kindex show symbol-reloading
7501@item show symbol-reloading
7502Show the current @code{on} or @code{off} setting.
7503@end table
c906108c 7504
c906108c
SS
7505@kindex set opaque-type-resolution
7506@item set opaque-type-resolution on
7507Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7508declared as a pointer to a @code{struct}, @code{class}, or
7509@code{union}---for example, @code{struct MyType *}---that is used in one
7510source file although the full declaration of @code{struct MyType} is in
7511another source file. The default is on.
7512
7513A change in the setting of this subcommand will not take effect until
7514the next time symbols for a file are loaded.
7515
7516@item set opaque-type-resolution off
7517Tell @value{GDBN} not to resolve opaque types. In this case, the type
7518is printed as follows:
7519@smallexample
7520@{<no data fields>@}
7521@end smallexample
7522
7523@kindex show opaque-type-resolution
7524@item show opaque-type-resolution
7525Show whether opaque types are resolved or not.
c906108c
SS
7526
7527@kindex maint print symbols
7528@cindex symbol dump
7529@kindex maint print psymbols
7530@cindex partial symbol dump
7531@item maint print symbols @var{filename}
7532@itemx maint print psymbols @var{filename}
7533@itemx maint print msymbols @var{filename}
7534Write a dump of debugging symbol data into the file @var{filename}.
7535These commands are used to debug the @value{GDBN} symbol-reading code. Only
7536symbols with debugging data are included. If you use @samp{maint print
7537symbols}, @value{GDBN} includes all the symbols for which it has already
7538collected full details: that is, @var{filename} reflects symbols for
7539only those files whose symbols @value{GDBN} has read. You can use the
7540command @code{info sources} to find out which files these are. If you
7541use @samp{maint print psymbols} instead, the dump shows information about
7542symbols that @value{GDBN} only knows partially---that is, symbols defined in
7543files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7544@samp{maint print msymbols} dumps just the minimal symbol information
7545required for each object file from which @value{GDBN} has read some symbols.
7546@xref{Files, ,Commands to specify files}, for a discussion of how
7547@value{GDBN} reads symbols (in the description of @code{symbol-file}).
7548@end table
7549
6d2ebf8b 7550@node Altering
c906108c
SS
7551@chapter Altering Execution
7552
7553Once you think you have found an error in your program, you might want to
7554find out for certain whether correcting the apparent error would lead to
7555correct results in the rest of the run. You can find the answer by
7556experiment, using the @value{GDBN} features for altering execution of the
7557program.
7558
7559For example, you can store new values into variables or memory
7a292a7a
SS
7560locations, give your program a signal, restart it at a different
7561address, or even return prematurely from a function.
c906108c
SS
7562
7563@menu
7564* Assignment:: Assignment to variables
7565* Jumping:: Continuing at a different address
c906108c 7566* Signaling:: Giving your program a signal
c906108c
SS
7567* Returning:: Returning from a function
7568* Calling:: Calling your program's functions
7569* Patching:: Patching your program
7570@end menu
7571
6d2ebf8b 7572@node Assignment
c906108c
SS
7573@section Assignment to variables
7574
7575@cindex assignment
7576@cindex setting variables
7577To alter the value of a variable, evaluate an assignment expression.
7578@xref{Expressions, ,Expressions}. For example,
7579
7580@example
7581print x=4
7582@end example
7583
7584@noindent
7585stores the value 4 into the variable @code{x}, and then prints the
5d161b24 7586value of the assignment expression (which is 4).
c906108c
SS
7587@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7588information on operators in supported languages.
c906108c
SS
7589
7590@kindex set variable
7591@cindex variables, setting
7592If you are not interested in seeing the value of the assignment, use the
7593@code{set} command instead of the @code{print} command. @code{set} is
7594really the same as @code{print} except that the expression's value is
7595not printed and is not put in the value history (@pxref{Value History,
7596,Value history}). The expression is evaluated only for its effects.
7597
c906108c
SS
7598If the beginning of the argument string of the @code{set} command
7599appears identical to a @code{set} subcommand, use the @code{set
7600variable} command instead of just @code{set}. This command is identical
7601to @code{set} except for its lack of subcommands. For example, if your
7602program has a variable @code{width}, you get an error if you try to set
7603a new value with just @samp{set width=13}, because @value{GDBN} has the
7604command @code{set width}:
7605
7606@example
7607(@value{GDBP}) whatis width
7608type = double
7609(@value{GDBP}) p width
7610$4 = 13
7611(@value{GDBP}) set width=47
7612Invalid syntax in expression.
7613@end example
7614
7615@noindent
7616The invalid expression, of course, is @samp{=47}. In
7617order to actually set the program's variable @code{width}, use
7618
7619@example
7620(@value{GDBP}) set var width=47
7621@end example
53a5351d 7622
c906108c
SS
7623Because the @code{set} command has many subcommands that can conflict
7624with the names of program variables, it is a good idea to use the
7625@code{set variable} command instead of just @code{set}. For example, if
7626your program has a variable @code{g}, you run into problems if you try
7627to set a new value with just @samp{set g=4}, because @value{GDBN} has
7628the command @code{set gnutarget}, abbreviated @code{set g}:
7629
7630@example
7631@group
7632(@value{GDBP}) whatis g
7633type = double
7634(@value{GDBP}) p g
7635$1 = 1
7636(@value{GDBP}) set g=4
2df3850c 7637(@value{GDBP}) p g
c906108c
SS
7638$2 = 1
7639(@value{GDBP}) r
7640The program being debugged has been started already.
7641Start it from the beginning? (y or n) y
7642Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
7643"/home/smith/cc_progs/a.out": can't open to read symbols:
7644 Invalid bfd target.
c906108c
SS
7645(@value{GDBP}) show g
7646The current BFD target is "=4".
7647@end group
7648@end example
7649
7650@noindent
7651The program variable @code{g} did not change, and you silently set the
7652@code{gnutarget} to an invalid value. In order to set the variable
7653@code{g}, use
7654
7655@example
7656(@value{GDBP}) set var g=4
7657@end example
c906108c
SS
7658
7659@value{GDBN} allows more implicit conversions in assignments than C; you can
7660freely store an integer value into a pointer variable or vice versa,
7661and you can convert any structure to any other structure that is the
7662same length or shorter.
7663@comment FIXME: how do structs align/pad in these conversions?
7664@comment /doc@cygnus.com 18dec1990
7665
7666To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7667construct to generate a value of specified type at a specified address
7668(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7669to memory location @code{0x83040} as an integer (which implies a certain size
7670and representation in memory), and
7671
7672@example
7673set @{int@}0x83040 = 4
7674@end example
7675
7676@noindent
7677stores the value 4 into that memory location.
7678
6d2ebf8b 7679@node Jumping
c906108c
SS
7680@section Continuing at a different address
7681
7682Ordinarily, when you continue your program, you do so at the place where
7683it stopped, with the @code{continue} command. You can instead continue at
7684an address of your own choosing, with the following commands:
7685
7686@table @code
7687@kindex jump
7688@item jump @var{linespec}
7689Resume execution at line @var{linespec}. Execution stops again
7690immediately if there is a breakpoint there. @xref{List, ,Printing
7691source lines}, for a description of the different forms of
7692@var{linespec}. It is common practice to use the @code{tbreak} command
7693in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7694breakpoints}.
7695
7696The @code{jump} command does not change the current stack frame, or
7697the stack pointer, or the contents of any memory location or any
7698register other than the program counter. If line @var{linespec} is in
7699a different function from the one currently executing, the results may
7700be bizarre if the two functions expect different patterns of arguments or
7701of local variables. For this reason, the @code{jump} command requests
7702confirmation if the specified line is not in the function currently
7703executing. However, even bizarre results are predictable if you are
7704well acquainted with the machine-language code of your program.
7705
7706@item jump *@var{address}
7707Resume execution at the instruction at address @var{address}.
7708@end table
7709
c906108c 7710@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
7711On many systems, you can get much the same effect as the @code{jump}
7712command by storing a new value into the register @code{$pc}. The
7713difference is that this does not start your program running; it only
7714changes the address of where it @emph{will} run when you continue. For
7715example,
c906108c
SS
7716
7717@example
7718set $pc = 0x485
7719@end example
7720
7721@noindent
7722makes the next @code{continue} command or stepping command execute at
7723address @code{0x485}, rather than at the address where your program stopped.
7724@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
7725
7726The most common occasion to use the @code{jump} command is to back
7727up---perhaps with more breakpoints set---over a portion of a program
7728that has already executed, in order to examine its execution in more
7729detail.
7730
c906108c 7731@c @group
6d2ebf8b 7732@node Signaling
c906108c
SS
7733@section Giving your program a signal
7734
7735@table @code
7736@kindex signal
7737@item signal @var{signal}
7738Resume execution where your program stopped, but immediately give it the
7739signal @var{signal}. @var{signal} can be the name or the number of a
7740signal. For example, on many systems @code{signal 2} and @code{signal
7741SIGINT} are both ways of sending an interrupt signal.
7742
7743Alternatively, if @var{signal} is zero, continue execution without
7744giving a signal. This is useful when your program stopped on account of
7745a signal and would ordinary see the signal when resumed with the
7746@code{continue} command; @samp{signal 0} causes it to resume without a
7747signal.
7748
7749@code{signal} does not repeat when you press @key{RET} a second time
7750after executing the command.
7751@end table
7752@c @end group
7753
7754Invoking the @code{signal} command is not the same as invoking the
7755@code{kill} utility from the shell. Sending a signal with @code{kill}
7756causes @value{GDBN} to decide what to do with the signal depending on
7757the signal handling tables (@pxref{Signals}). The @code{signal} command
7758passes the signal directly to your program.
7759
c906108c 7760
6d2ebf8b 7761@node Returning
c906108c
SS
7762@section Returning from a function
7763
7764@table @code
7765@cindex returning from a function
7766@kindex return
7767@item return
7768@itemx return @var{expression}
7769You can cancel execution of a function call with the @code{return}
7770command. If you give an
7771@var{expression} argument, its value is used as the function's return
7772value.
7773@end table
7774
7775When you use @code{return}, @value{GDBN} discards the selected stack frame
7776(and all frames within it). You can think of this as making the
7777discarded frame return prematurely. If you wish to specify a value to
7778be returned, give that value as the argument to @code{return}.
7779
7780This pops the selected stack frame (@pxref{Selection, ,Selecting a
7781frame}), and any other frames inside of it, leaving its caller as the
7782innermost remaining frame. That frame becomes selected. The
7783specified value is stored in the registers used for returning values
7784of functions.
7785
7786The @code{return} command does not resume execution; it leaves the
7787program stopped in the state that would exist if the function had just
7788returned. In contrast, the @code{finish} command (@pxref{Continuing
7789and Stepping, ,Continuing and stepping}) resumes execution until the
7790selected stack frame returns naturally.
7791
6d2ebf8b 7792@node Calling
c906108c
SS
7793@section Calling program functions
7794
7795@cindex calling functions
7796@kindex call
7797@table @code
7798@item call @var{expr}
7799Evaluate the expression @var{expr} without displaying @code{void}
7800returned values.
7801@end table
7802
7803You can use this variant of the @code{print} command if you want to
7804execute a function from your program, but without cluttering the output
5d161b24
DB
7805with @code{void} returned values. If the result is not void, it
7806is printed and saved in the value history.
c906108c 7807
c906108c
SS
7808For the A29K, a user-controlled variable @code{call_scratch_address},
7809specifies the location of a scratch area to be used when @value{GDBN}
7810calls a function in the target. This is necessary because the usual
7811method of putting the scratch area on the stack does not work in systems
7812that have separate instruction and data spaces.
c906108c 7813
6d2ebf8b 7814@node Patching
c906108c 7815@section Patching programs
7a292a7a 7816
c906108c
SS
7817@cindex patching binaries
7818@cindex writing into executables
c906108c 7819@cindex writing into corefiles
c906108c 7820
7a292a7a
SS
7821By default, @value{GDBN} opens the file containing your program's
7822executable code (or the corefile) read-only. This prevents accidental
7823alterations to machine code; but it also prevents you from intentionally
7824patching your program's binary.
c906108c
SS
7825
7826If you'd like to be able to patch the binary, you can specify that
7827explicitly with the @code{set write} command. For example, you might
7828want to turn on internal debugging flags, or even to make emergency
7829repairs.
7830
7831@table @code
7832@kindex set write
7833@item set write on
7834@itemx set write off
7a292a7a
SS
7835If you specify @samp{set write on}, @value{GDBN} opens executable and
7836core files for both reading and writing; if you specify @samp{set write
c906108c
SS
7837off} (the default), @value{GDBN} opens them read-only.
7838
7839If you have already loaded a file, you must load it again (using the
7a292a7a
SS
7840@code{exec-file} or @code{core-file} command) after changing @code{set
7841write}, for your new setting to take effect.
c906108c
SS
7842
7843@item show write
7844@kindex show write
7a292a7a
SS
7845Display whether executable files and core files are opened for writing
7846as well as reading.
c906108c
SS
7847@end table
7848
6d2ebf8b 7849@node GDB Files
c906108c
SS
7850@chapter @value{GDBN} Files
7851
7a292a7a
SS
7852@value{GDBN} needs to know the file name of the program to be debugged,
7853both in order to read its symbol table and in order to start your
7854program. To debug a core dump of a previous run, you must also tell
7855@value{GDBN} the name of the core dump file.
c906108c
SS
7856
7857@menu
7858* Files:: Commands to specify files
7859* Symbol Errors:: Errors reading symbol files
7860@end menu
7861
6d2ebf8b 7862@node Files
c906108c 7863@section Commands to specify files
c906108c 7864
7a292a7a 7865@cindex symbol table
c906108c 7866@cindex core dump file
7a292a7a
SS
7867
7868You may want to specify executable and core dump file names. The usual
7869way to do this is at start-up time, using the arguments to
7870@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7871Out of @value{GDBN}}).
c906108c
SS
7872
7873Occasionally it is necessary to change to a different file during a
7874@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7875a file you want to use. In these situations the @value{GDBN} commands
7876to specify new files are useful.
7877
7878@table @code
7879@cindex executable file
7880@kindex file
7881@item file @var{filename}
7882Use @var{filename} as the program to be debugged. It is read for its
7883symbols and for the contents of pure memory. It is also the program
7884executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
7885directory and the file is not found in the @value{GDBN} working directory,
7886@value{GDBN} uses the environment variable @code{PATH} as a list of
7887directories to search, just as the shell does when looking for a program
7888to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
7889and your program, using the @code{path} command.
7890
6d2ebf8b 7891On systems with memory-mapped files, an auxiliary file named
c906108c
SS
7892@file{@var{filename}.syms} may hold symbol table information for
7893@var{filename}. If so, @value{GDBN} maps in the symbol table from
7894@file{@var{filename}.syms}, starting up more quickly. See the
7895descriptions of the file options @samp{-mapped} and @samp{-readnow}
7896(available on the command line, and with the commands @code{file},
5d161b24 7897@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 7898for more information.
c906108c
SS
7899
7900@item file
7901@code{file} with no argument makes @value{GDBN} discard any information it
7902has on both executable file and the symbol table.
7903
7904@kindex exec-file
7905@item exec-file @r{[} @var{filename} @r{]}
7906Specify that the program to be run (but not the symbol table) is found
7907in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7908if necessary to locate your program. Omitting @var{filename} means to
7909discard information on the executable file.
7910
7911@kindex symbol-file
7912@item symbol-file @r{[} @var{filename} @r{]}
7913Read symbol table information from file @var{filename}. @code{PATH} is
7914searched when necessary. Use the @code{file} command to get both symbol
7915table and program to run from the same file.
7916
7917@code{symbol-file} with no argument clears out @value{GDBN} information on your
7918program's symbol table.
7919
5d161b24 7920The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
7921of its convenience variables, the value history, and all breakpoints and
7922auto-display expressions. This is because they may contain pointers to
7923the internal data recording symbols and data types, which are part of
7924the old symbol table data being discarded inside @value{GDBN}.
7925
7926@code{symbol-file} does not repeat if you press @key{RET} again after
7927executing it once.
7928
7929When @value{GDBN} is configured for a particular environment, it
7930understands debugging information in whatever format is the standard
7931generated for that environment; you may use either a @sc{gnu} compiler, or
7932other compilers that adhere to the local conventions.
c906108c
SS
7933Best results are usually obtained from @sc{gnu} compilers; for example,
7934using @code{@value{GCC}} you can generate debugging information for
7935optimized code.
c906108c
SS
7936
7937For most kinds of object files, with the exception of old SVR3 systems
7938using COFF, the @code{symbol-file} command does not normally read the
7939symbol table in full right away. Instead, it scans the symbol table
7940quickly to find which source files and which symbols are present. The
7941details are read later, one source file at a time, as they are needed.
7942
7943The purpose of this two-stage reading strategy is to make @value{GDBN}
7944start up faster. For the most part, it is invisible except for
7945occasional pauses while the symbol table details for a particular source
7946file are being read. (The @code{set verbose} command can turn these
7947pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7948warnings and messages}.)
7949
c906108c
SS
7950We have not implemented the two-stage strategy for COFF yet. When the
7951symbol table is stored in COFF format, @code{symbol-file} reads the
7952symbol table data in full right away. Note that ``stabs-in-COFF''
7953still does the two-stage strategy, since the debug info is actually
7954in stabs format.
7955
7956@kindex readnow
7957@cindex reading symbols immediately
7958@cindex symbols, reading immediately
7959@kindex mapped
7960@cindex memory-mapped symbol file
7961@cindex saving symbol table
7962@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7963@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7964You can override the @value{GDBN} two-stage strategy for reading symbol
7965tables by using the @samp{-readnow} option with any of the commands that
7966load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 7967entire symbol table available.
c906108c 7968
c906108c
SS
7969If memory-mapped files are available on your system through the
7970@code{mmap} system call, you can use another option, @samp{-mapped}, to
7971cause @value{GDBN} to write the symbols for your program into a reusable
7972file. Future @value{GDBN} debugging sessions map in symbol information
7973from this auxiliary symbol file (if the program has not changed), rather
7974than spending time reading the symbol table from the executable
7975program. Using the @samp{-mapped} option has the same effect as
7976starting @value{GDBN} with the @samp{-mapped} command-line option.
7977
7978You can use both options together, to make sure the auxiliary symbol
7979file has all the symbol information for your program.
7980
7981The auxiliary symbol file for a program called @var{myprog} is called
7982@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7983than the corresponding executable), @value{GDBN} always attempts to use
7984it when you debug @var{myprog}; no special options or commands are
7985needed.
7986
7987The @file{.syms} file is specific to the host machine where you run
7988@value{GDBN}. It holds an exact image of the internal @value{GDBN}
7989symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
7990
7991@c FIXME: for now no mention of directories, since this seems to be in
7992@c flux. 13mar1992 status is that in theory GDB would look either in
7993@c current dir or in same dir as myprog; but issues like competing
7994@c GDB's, or clutter in system dirs, mean that in practice right now
7995@c only current dir is used. FFish says maybe a special GDB hierarchy
7996@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7997@c files.
7998
7999@kindex core
8000@kindex core-file
8001@item core-file @r{[} @var{filename} @r{]}
8002Specify the whereabouts of a core dump file to be used as the ``contents
8003of memory''. Traditionally, core files contain only some parts of the
8004address space of the process that generated them; @value{GDBN} can access the
8005executable file itself for other parts.
8006
8007@code{core-file} with no argument specifies that no core file is
8008to be used.
8009
8010Note that the core file is ignored when your program is actually running
7a292a7a
SS
8011under @value{GDBN}. So, if you have been running your program and you
8012wish to debug a core file instead, you must kill the subprocess in which
8013the program is running. To do this, use the @code{kill} command
c906108c 8014(@pxref{Kill Process, ,Killing the child process}).
c906108c 8015
c906108c
SS
8016@kindex add-symbol-file
8017@cindex dynamic linking
8018@item add-symbol-file @var{filename} @var{address}
8019@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
d167840f 8020@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address}
96a2c332
SS
8021The @code{add-symbol-file} command reads additional symbol table
8022information from the file @var{filename}. You would use this command
8023when @var{filename} has been dynamically loaded (by some other means)
8024into the program that is running. @var{address} should be the memory
8025address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
8026this out for itself. You can additionally specify an arbitrary number
8027of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
8028section name and base address for that section. You can specify any
8029@var{address} as an expression.
c906108c
SS
8030
8031The symbol table of the file @var{filename} is added to the symbol table
8032originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
8033@code{add-symbol-file} command any number of times; the new symbol data
8034thus read keeps adding to the old. To discard all old symbol data
8035instead, use the @code{symbol-file} command without any arguments.
c906108c
SS
8036
8037@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8038
8039You can use the @samp{-mapped} and @samp{-readnow} options just as with
8040the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8041table information for @var{filename}.
8042
8043@kindex add-shared-symbol-file
8044@item add-shared-symbol-file
8045The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
8046operating system for the Motorola 88k. @value{GDBN} automatically looks for
8047shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 8048@code{add-shared-symbol-file}. It takes no arguments.
c906108c 8049
c906108c
SS
8050@kindex section
8051@item section
5d161b24
DB
8052The @code{section} command changes the base address of section SECTION of
8053the exec file to ADDR. This can be used if the exec file does not contain
8054section addresses, (such as in the a.out format), or when the addresses
8055specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
8056separately. The @code{info files} command, described below, lists all
8057the sections and their addresses.
c906108c
SS
8058
8059@kindex info files
8060@kindex info target
8061@item info files
8062@itemx info target
7a292a7a
SS
8063@code{info files} and @code{info target} are synonymous; both print the
8064current target (@pxref{Targets, ,Specifying a Debugging Target}),
8065including the names of the executable and core dump files currently in
8066use by @value{GDBN}, and the files from which symbols were loaded. The
8067command @code{help target} lists all possible targets rather than
8068current ones.
8069
c906108c
SS
8070@end table
8071
8072All file-specifying commands allow both absolute and relative file names
8073as arguments. @value{GDBN} always converts the file name to an absolute file
8074name and remembers it that way.
8075
c906108c 8076@cindex shared libraries
c906108c
SS
8077@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8078libraries.
53a5351d 8079
c906108c
SS
8080@value{GDBN} automatically loads symbol definitions from shared libraries
8081when you use the @code{run} command, or when you examine a core file.
8082(Before you issue the @code{run} command, @value{GDBN} does not understand
8083references to a function in a shared library, however---unless you are
8084debugging a core file).
53a5351d
JM
8085
8086On HP-UX, if the program loads a library explicitly, @value{GDBN}
8087automatically loads the symbols at the time of the @code{shl_load} call.
8088
c906108c
SS
8089@c FIXME: some @value{GDBN} release may permit some refs to undef
8090@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8091@c FIXME...lib; check this from time to time when updating manual
8092
8093@table @code
8094@kindex info sharedlibrary
8095@kindex info share
8096@item info share
8097@itemx info sharedlibrary
8098Print the names of the shared libraries which are currently loaded.
8099
8100@kindex sharedlibrary
8101@kindex share
8102@item sharedlibrary @var{regex}
8103@itemx share @var{regex}
c906108c
SS
8104Load shared object library symbols for files matching a
8105Unix regular expression.
8106As with files loaded automatically, it only loads shared libraries
8107required by your program for a core file or after typing @code{run}. If
8108@var{regex} is omitted all shared libraries required by your program are
8109loaded.
8110@end table
8111
53a5351d
JM
8112On HP-UX systems, @value{GDBN} detects the loading of a shared library
8113and automatically reads in symbols from the newly loaded library, up to
8114a threshold that is initially set but that you can modify if you wish.
c906108c
SS
8115
8116Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
8117loaded. To load these symbols, use the command @code{sharedlibrary
8118@var{filename}}. The base address of the shared library is determined
c906108c
SS
8119automatically by @value{GDBN} and need not be specified.
8120
8121To display or set the threshold, use the commands:
8122
8123@table @code
8124@kindex set auto-solib-add
8125@item set auto-solib-add @var{threshold}
8126Set the autoloading size threshold, in megabytes. If @var{threshold} is
8127nonzero, symbols from all shared object libraries will be loaded
8128automatically when the inferior begins execution or when the dynamic
8129linker informs @value{GDBN} that a new library has been loaded, until
8130the symbol table of the program and libraries exceeds this threshold.
8131Otherwise, symbols must be loaded manually, using the
8132@code{sharedlibrary} command. The default threshold is 100 megabytes.
8133
8134@kindex show auto-solib-add
8135@item show auto-solib-add
8136Display the current autoloading size threshold, in megabytes.
8137@end table
c906108c 8138
6d2ebf8b 8139@node Symbol Errors
c906108c
SS
8140@section Errors reading symbol files
8141
8142While reading a symbol file, @value{GDBN} occasionally encounters problems,
8143such as symbol types it does not recognize, or known bugs in compiler
8144output. By default, @value{GDBN} does not notify you of such problems, since
8145they are relatively common and primarily of interest to people
8146debugging compilers. If you are interested in seeing information
8147about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8148only one message about each such type of problem, no matter how many
8149times the problem occurs; or you can ask @value{GDBN} to print more messages,
8150to see how many times the problems occur, with the @code{set
8151complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8152messages}).
8153
8154The messages currently printed, and their meanings, include:
8155
8156@table @code
8157@item inner block not inside outer block in @var{symbol}
8158
8159The symbol information shows where symbol scopes begin and end
8160(such as at the start of a function or a block of statements). This
8161error indicates that an inner scope block is not fully contained
8162in its outer scope blocks.
8163
8164@value{GDBN} circumvents the problem by treating the inner block as if it had
8165the same scope as the outer block. In the error message, @var{symbol}
8166may be shown as ``@code{(don't know)}'' if the outer block is not a
8167function.
8168
8169@item block at @var{address} out of order
8170
8171The symbol information for symbol scope blocks should occur in
8172order of increasing addresses. This error indicates that it does not
8173do so.
8174
8175@value{GDBN} does not circumvent this problem, and has trouble
8176locating symbols in the source file whose symbols it is reading. (You
8177can often determine what source file is affected by specifying
8178@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8179messages}.)
8180
8181@item bad block start address patched
8182
8183The symbol information for a symbol scope block has a start address
8184smaller than the address of the preceding source line. This is known
8185to occur in the SunOS 4.1.1 (and earlier) C compiler.
8186
8187@value{GDBN} circumvents the problem by treating the symbol scope block as
8188starting on the previous source line.
8189
8190@item bad string table offset in symbol @var{n}
8191
8192@cindex foo
8193Symbol number @var{n} contains a pointer into the string table which is
8194larger than the size of the string table.
8195
8196@value{GDBN} circumvents the problem by considering the symbol to have the
8197name @code{foo}, which may cause other problems if many symbols end up
8198with this name.
8199
8200@item unknown symbol type @code{0x@var{nn}}
8201
7a292a7a
SS
8202The symbol information contains new data types that @value{GDBN} does
8203not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 8204uncomprehended information, in hexadecimal.
c906108c 8205
7a292a7a
SS
8206@value{GDBN} circumvents the error by ignoring this symbol information.
8207This usually allows you to debug your program, though certain symbols
c906108c 8208are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
8209debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8210on @code{complain}, then go up to the function @code{read_dbx_symtab}
8211and examine @code{*bufp} to see the symbol.
c906108c
SS
8212
8213@item stub type has NULL name
c906108c 8214
7a292a7a 8215@value{GDBN} could not find the full definition for a struct or class.
c906108c 8216
7a292a7a 8217@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
c906108c 8218The symbol information for a C++ member function is missing some
7a292a7a
SS
8219information that recent versions of the compiler should have output for
8220it.
c906108c
SS
8221
8222@item info mismatch between compiler and debugger
8223
8224@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 8225
c906108c
SS
8226@end table
8227
6d2ebf8b 8228@node Targets
c906108c 8229@chapter Specifying a Debugging Target
7a292a7a 8230
c906108c
SS
8231@cindex debugging target
8232@kindex target
8233
8234A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
8235
8236Often, @value{GDBN} runs in the same host environment as your program;
8237in that case, the debugging target is specified as a side effect when
8238you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
8239flexibility---for example, running @value{GDBN} on a physically separate
8240host, or controlling a standalone system over a serial port or a
53a5351d
JM
8241realtime system over a TCP/IP connection---you can use the @code{target}
8242command to specify one of the target types configured for @value{GDBN}
8243(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
8244
8245@menu
8246* Active Targets:: Active targets
8247* Target Commands:: Commands for managing targets
c906108c
SS
8248* Byte Order:: Choosing target byte order
8249* Remote:: Remote debugging
96baa820 8250* KOD:: Kernel Object Display
c906108c
SS
8251
8252@end menu
8253
6d2ebf8b 8254@node Active Targets
c906108c 8255@section Active targets
7a292a7a 8256
c906108c
SS
8257@cindex stacking targets
8258@cindex active targets
8259@cindex multiple targets
8260
c906108c 8261There are three classes of targets: processes, core files, and
7a292a7a
SS
8262executable files. @value{GDBN} can work concurrently on up to three
8263active targets, one in each class. This allows you to (for example)
8264start a process and inspect its activity without abandoning your work on
8265a core file.
c906108c
SS
8266
8267For example, if you execute @samp{gdb a.out}, then the executable file
8268@code{a.out} is the only active target. If you designate a core file as
8269well---presumably from a prior run that crashed and coredumped---then
8270@value{GDBN} has two active targets and uses them in tandem, looking
8271first in the corefile target, then in the executable file, to satisfy
8272requests for memory addresses. (Typically, these two classes of target
8273are complementary, since core files contain only a program's
8274read-write memory---variables and so on---plus machine status, while
8275executable files contain only the program text and initialized data.)
c906108c
SS
8276
8277When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
8278target as well. When a process target is active, all @value{GDBN}
8279commands requesting memory addresses refer to that target; addresses in
8280an active core file or executable file target are obscured while the
8281process target is active.
c906108c 8282
7a292a7a
SS
8283Use the @code{core-file} and @code{exec-file} commands to select a new
8284core file or executable target (@pxref{Files, ,Commands to specify
c906108c 8285files}). To specify as a target a process that is already running, use
7a292a7a
SS
8286the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8287process}).
c906108c 8288
6d2ebf8b 8289@node Target Commands
c906108c
SS
8290@section Commands for managing targets
8291
8292@table @code
8293@item target @var{type} @var{parameters}
7a292a7a
SS
8294Connects the @value{GDBN} host environment to a target machine or
8295process. A target is typically a protocol for talking to debugging
8296facilities. You use the argument @var{type} to specify the type or
8297protocol of the target machine.
c906108c
SS
8298
8299Further @var{parameters} are interpreted by the target protocol, but
8300typically include things like device names or host names to connect
8301with, process numbers, and baud rates.
c906108c
SS
8302
8303The @code{target} command does not repeat if you press @key{RET} again
8304after executing the command.
8305
8306@kindex help target
8307@item help target
8308Displays the names of all targets available. To display targets
8309currently selected, use either @code{info target} or @code{info files}
8310(@pxref{Files, ,Commands to specify files}).
8311
8312@item help target @var{name}
8313Describe a particular target, including any parameters necessary to
8314select it.
8315
8316@kindex set gnutarget
8317@item set gnutarget @var{args}
5d161b24 8318@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 8319knows whether it is reading an @dfn{executable},
5d161b24
DB
8320a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8321with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
8322with @code{gnutarget} the @code{target} refers to a program, not a machine.
8323
d4f3574e 8324@quotation
c906108c
SS
8325@emph{Warning:} To specify a file format with @code{set gnutarget},
8326you must know the actual BFD name.
d4f3574e 8327@end quotation
c906108c 8328
d4f3574e
SS
8329@noindent
8330@xref{Files, , Commands to specify files}.
c906108c 8331
5d161b24 8332@kindex show gnutarget
c906108c
SS
8333@item show gnutarget
8334Use the @code{show gnutarget} command to display what file format
8335@code{gnutarget} is set to read. If you have not set @code{gnutarget},
8336@value{GDBN} will determine the file format for each file automatically,
8337and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8338@end table
8339
c906108c
SS
8340Here are some common targets (available, or not, depending on the GDB
8341configuration):
c906108c
SS
8342
8343@table @code
8344@kindex target exec
8345@item target exec @var{program}
8346An executable file. @samp{target exec @var{program}} is the same as
8347@samp{exec-file @var{program}}.
8348
c906108c
SS
8349@kindex target core
8350@item target core @var{filename}
8351A core dump file. @samp{target core @var{filename}} is the same as
8352@samp{core-file @var{filename}}.
c906108c
SS
8353
8354@kindex target remote
8355@item target remote @var{dev}
8356Remote serial target in GDB-specific protocol. The argument @var{dev}
8357specifies what serial device to use for the connection (e.g.
8358@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 8359supports the @code{load} command. This is only useful if you have
c906108c
SS
8360some other way of getting the stub to the target system, and you can put
8361it somewhere in memory where it won't get clobbered by the download.
8362
c906108c
SS
8363@kindex target sim
8364@item target sim
2df3850c 8365Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
8366In general,
8367@example
8368 target sim
8369 load
8370 run
8371@end example
d4f3574e 8372@noindent
104c1213 8373works; however, you cannot assume that a specific memory map, device
d4f3574e 8374drivers, or even basic I/O is available, although some simulators do
104c1213
JM
8375provide these. For info about any processor-specific simulator details,
8376see the appropriate section in @ref{Embedded Processors, ,Embedded
8377Processors}.
8378
c906108c
SS
8379@end table
8380
104c1213 8381Some configurations may include these targets as well:
c906108c
SS
8382
8383@table @code
8384
c906108c
SS
8385@kindex target nrom
8386@item target nrom @var{dev}
8387NetROM ROM emulator. This target only supports downloading.
8388
c906108c
SS
8389@end table
8390
5d161b24 8391Different targets are available on different configurations of @value{GDBN};
c906108c 8392your configuration may have more or fewer targets.
c906108c
SS
8393
8394Many remote targets require you to download the executable's code
8395once you've successfully established a connection.
8396
8397@table @code
8398
8399@kindex load @var{filename}
8400@item load @var{filename}
c906108c
SS
8401Depending on what remote debugging facilities are configured into
8402@value{GDBN}, the @code{load} command may be available. Where it exists, it
8403is meant to make @var{filename} (an executable) available for debugging
8404on the remote system---by downloading, or dynamic linking, for example.
8405@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8406the @code{add-symbol-file} command.
8407
8408If your @value{GDBN} does not have a @code{load} command, attempting to
8409execute it gets the error message ``@code{You can't do that when your
8410target is @dots{}}''
c906108c
SS
8411
8412The file is loaded at whatever address is specified in the executable.
8413For some object file formats, you can specify the load address when you
8414link the program; for other formats, like a.out, the object file format
8415specifies a fixed address.
8416@c FIXME! This would be a good place for an xref to the GNU linker doc.
8417
c906108c
SS
8418@code{load} does not repeat if you press @key{RET} again after using it.
8419@end table
8420
6d2ebf8b 8421@node Byte Order
c906108c 8422@section Choosing target byte order
7a292a7a 8423
c906108c
SS
8424@cindex choosing target byte order
8425@cindex target byte order
c906108c
SS
8426
8427Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8428offer the ability to run either big-endian or little-endian byte
8429orders. Usually the executable or symbol will include a bit to
8430designate the endian-ness, and you will not need to worry about
8431which to use. However, you may still find it useful to adjust
d4f3574e 8432@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
8433
8434@table @code
8435@kindex set endian big
8436@item set endian big
8437Instruct @value{GDBN} to assume the target is big-endian.
8438
8439@kindex set endian little
8440@item set endian little
8441Instruct @value{GDBN} to assume the target is little-endian.
8442
8443@kindex set endian auto
8444@item set endian auto
8445Instruct @value{GDBN} to use the byte order associated with the
8446executable.
8447
8448@item show endian
8449Display @value{GDBN}'s current idea of the target byte order.
8450
8451@end table
8452
8453Note that these commands merely adjust interpretation of symbolic
8454data on the host, and that they have absolutely no effect on the
8455target system.
8456
6d2ebf8b 8457@node Remote
c906108c
SS
8458@section Remote debugging
8459@cindex remote debugging
8460
8461If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
8462@value{GDBN} in the usual way, it is often useful to use remote debugging.
8463For example, you might use remote debugging on an operating system kernel,
c906108c
SS
8464or on a small system which does not have a general purpose operating system
8465powerful enough to run a full-featured debugger.
8466
8467Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8468to make this work with particular debugging targets. In addition,
5d161b24 8469@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
8470but not specific to any particular target system) which you can use if you
8471write the remote stubs---the code that runs on the remote system to
8472communicate with @value{GDBN}.
8473
8474Other remote targets may be available in your
8475configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 8476
c906108c 8477@menu
c906108c 8478* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
8479@end menu
8480
6d2ebf8b 8481@node Remote Serial
104c1213 8482@subsection The @value{GDBN} remote serial protocol
7a292a7a 8483
104c1213
JM
8484@cindex remote serial debugging, overview
8485To debug a program running on another machine (the debugging
8486@dfn{target} machine), you must first arrange for all the usual
8487prerequisites for the program to run by itself. For example, for a C
8488program, you need:
c906108c 8489
104c1213
JM
8490@enumerate
8491@item
8492A startup routine to set up the C runtime environment; these usually
8493have a name like @file{crt0}. The startup routine may be supplied by
8494your hardware supplier, or you may have to write your own.
96baa820 8495
5d161b24 8496@item
d4f3574e 8497A C subroutine library to support your program's
104c1213 8498subroutine calls, notably managing input and output.
96baa820 8499
104c1213
JM
8500@item
8501A way of getting your program to the other machine---for example, a
8502download program. These are often supplied by the hardware
8503manufacturer, but you may have to write your own from hardware
8504documentation.
8505@end enumerate
96baa820 8506
104c1213
JM
8507The next step is to arrange for your program to use a serial port to
8508communicate with the machine where @value{GDBN} is running (the @dfn{host}
8509machine). In general terms, the scheme looks like this:
96baa820 8510
104c1213
JM
8511@table @emph
8512@item On the host,
8513@value{GDBN} already understands how to use this protocol; when everything
8514else is set up, you can simply use the @samp{target remote} command
8515(@pxref{Targets,,Specifying a Debugging Target}).
8516
8517@item On the target,
8518you must link with your program a few special-purpose subroutines that
8519implement the @value{GDBN} remote serial protocol. The file containing these
8520subroutines is called a @dfn{debugging stub}.
8521
8522On certain remote targets, you can use an auxiliary program
8523@code{gdbserver} instead of linking a stub into your program.
8524@xref{Server,,Using the @code{gdbserver} program}, for details.
8525@end table
96baa820 8526
104c1213
JM
8527The debugging stub is specific to the architecture of the remote
8528machine; for example, use @file{sparc-stub.c} to debug programs on
8529@sc{sparc} boards.
96baa820 8530
104c1213
JM
8531@cindex remote serial stub list
8532These working remote stubs are distributed with @value{GDBN}:
96baa820 8533
104c1213
JM
8534@table @code
8535
8536@item i386-stub.c
41afff9a 8537@cindex @file{i386-stub.c}
104c1213
JM
8538@cindex Intel
8539@cindex i386
8540For Intel 386 and compatible architectures.
8541
8542@item m68k-stub.c
41afff9a 8543@cindex @file{m68k-stub.c}
104c1213
JM
8544@cindex Motorola 680x0
8545@cindex m680x0
8546For Motorola 680x0 architectures.
8547
8548@item sh-stub.c
41afff9a 8549@cindex @file{sh-stub.c}
104c1213
JM
8550@cindex Hitachi
8551@cindex SH
8552For Hitachi SH architectures.
8553
8554@item sparc-stub.c
41afff9a 8555@cindex @file{sparc-stub.c}
104c1213
JM
8556@cindex Sparc
8557For @sc{sparc} architectures.
8558
8559@item sparcl-stub.c
41afff9a 8560@cindex @file{sparcl-stub.c}
104c1213
JM
8561@cindex Fujitsu
8562@cindex SparcLite
8563For Fujitsu @sc{sparclite} architectures.
8564
8565@end table
8566
8567The @file{README} file in the @value{GDBN} distribution may list other
8568recently added stubs.
8569
8570@menu
8571* Stub Contents:: What the stub can do for you
8572* Bootstrapping:: What you must do for the stub
8573* Debug Session:: Putting it all together
8574* Protocol:: Definition of the communication protocol
8575* Server:: Using the `gdbserver' program
8576* NetWare:: Using the `gdbserve.nlm' program
8577@end menu
8578
6d2ebf8b 8579@node Stub Contents
104c1213
JM
8580@subsubsection What the stub can do for you
8581
8582@cindex remote serial stub
8583The debugging stub for your architecture supplies these three
8584subroutines:
8585
8586@table @code
8587@item set_debug_traps
8588@kindex set_debug_traps
8589@cindex remote serial stub, initialization
8590This routine arranges for @code{handle_exception} to run when your
8591program stops. You must call this subroutine explicitly near the
8592beginning of your program.
8593
8594@item handle_exception
8595@kindex handle_exception
8596@cindex remote serial stub, main routine
8597This is the central workhorse, but your program never calls it
8598explicitly---the setup code arranges for @code{handle_exception} to
8599run when a trap is triggered.
8600
8601@code{handle_exception} takes control when your program stops during
8602execution (for example, on a breakpoint), and mediates communications
8603with @value{GDBN} on the host machine. This is where the communications
8604protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 8605representative on the target machine. It begins by sending summary
104c1213
JM
8606information on the state of your program, then continues to execute,
8607retrieving and transmitting any information @value{GDBN} needs, until you
8608execute a @value{GDBN} command that makes your program resume; at that point,
8609@code{handle_exception} returns control to your own code on the target
5d161b24 8610machine.
104c1213
JM
8611
8612@item breakpoint
8613@cindex @code{breakpoint} subroutine, remote
8614Use this auxiliary subroutine to make your program contain a
8615breakpoint. Depending on the particular situation, this may be the only
8616way for @value{GDBN} to get control. For instance, if your target
8617machine has some sort of interrupt button, you won't need to call this;
8618pressing the interrupt button transfers control to
8619@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8620simply receiving characters on the serial port may also trigger a trap;
8621again, in that situation, you don't need to call @code{breakpoint} from
8622your own program---simply running @samp{target remote} from the host
5d161b24 8623@value{GDBN} session gets control.
104c1213
JM
8624
8625Call @code{breakpoint} if none of these is true, or if you simply want
8626to make certain your program stops at a predetermined point for the
8627start of your debugging session.
8628@end table
8629
6d2ebf8b 8630@node Bootstrapping
104c1213
JM
8631@subsubsection What you must do for the stub
8632
8633@cindex remote stub, support routines
8634The debugging stubs that come with @value{GDBN} are set up for a particular
8635chip architecture, but they have no information about the rest of your
8636debugging target machine.
8637
8638First of all you need to tell the stub how to communicate with the
8639serial port.
8640
8641@table @code
8642@item int getDebugChar()
8643@kindex getDebugChar
8644Write this subroutine to read a single character from the serial port.
8645It may be identical to @code{getchar} for your target system; a
8646different name is used to allow you to distinguish the two if you wish.
8647
8648@item void putDebugChar(int)
8649@kindex putDebugChar
8650Write this subroutine to write a single character to the serial port.
5d161b24 8651It may be identical to @code{putchar} for your target system; a
104c1213
JM
8652different name is used to allow you to distinguish the two if you wish.
8653@end table
8654
8655@cindex control C, and remote debugging
8656@cindex interrupting remote targets
8657If you want @value{GDBN} to be able to stop your program while it is
8658running, you need to use an interrupt-driven serial driver, and arrange
8659for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8660character). That is the character which @value{GDBN} uses to tell the
8661remote system to stop.
8662
8663Getting the debugging target to return the proper status to @value{GDBN}
8664probably requires changes to the standard stub; one quick and dirty way
8665is to just execute a breakpoint instruction (the ``dirty'' part is that
8666@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8667
8668Other routines you need to supply are:
8669
8670@table @code
8671@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8672@kindex exceptionHandler
8673Write this function to install @var{exception_address} in the exception
8674handling tables. You need to do this because the stub does not have any
8675way of knowing what the exception handling tables on your target system
8676are like (for example, the processor's table might be in @sc{rom},
8677containing entries which point to a table in @sc{ram}).
8678@var{exception_number} is the exception number which should be changed;
8679its meaning is architecture-dependent (for example, different numbers
8680might represent divide by zero, misaligned access, etc). When this
8681exception occurs, control should be transferred directly to
8682@var{exception_address}, and the processor state (stack, registers,
8683and so on) should be just as it is when a processor exception occurs. So if
8684you want to use a jump instruction to reach @var{exception_address}, it
8685should be a simple jump, not a jump to subroutine.
8686
8687For the 386, @var{exception_address} should be installed as an interrupt
8688gate so that interrupts are masked while the handler runs. The gate
8689should be at privilege level 0 (the most privileged level). The
8690@sc{sparc} and 68k stubs are able to mask interrupts themselves without
8691help from @code{exceptionHandler}.
8692
8693@item void flush_i_cache()
8694@kindex flush_i_cache
d4f3574e 8695On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
8696instruction cache, if any, on your target machine. If there is no
8697instruction cache, this subroutine may be a no-op.
8698
8699On target machines that have instruction caches, @value{GDBN} requires this
8700function to make certain that the state of your program is stable.
8701@end table
8702
8703@noindent
8704You must also make sure this library routine is available:
8705
8706@table @code
8707@item void *memset(void *, int, int)
8708@kindex memset
8709This is the standard library function @code{memset} that sets an area of
8710memory to a known value. If you have one of the free versions of
8711@code{libc.a}, @code{memset} can be found there; otherwise, you must
8712either obtain it from your hardware manufacturer, or write your own.
8713@end table
8714
8715If you do not use the GNU C compiler, you may need other standard
8716library subroutines as well; this varies from one stub to another,
8717but in general the stubs are likely to use any of the common library
d4f3574e 8718subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
8719
8720
6d2ebf8b 8721@node Debug Session
104c1213
JM
8722@subsubsection Putting it all together
8723
8724@cindex remote serial debugging summary
8725In summary, when your program is ready to debug, you must follow these
8726steps.
8727
8728@enumerate
8729@item
6d2ebf8b 8730Make sure you have defined the supporting low-level routines
104c1213
JM
8731(@pxref{Bootstrapping,,What you must do for the stub}):
8732@display
8733@code{getDebugChar}, @code{putDebugChar},
8734@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8735@end display
8736
8737@item
8738Insert these lines near the top of your program:
8739
8740@example
8741set_debug_traps();
8742breakpoint();
8743@end example
8744
8745@item
8746For the 680x0 stub only, you need to provide a variable called
8747@code{exceptionHook}. Normally you just use:
8748
8749@example
8750void (*exceptionHook)() = 0;
8751@end example
8752
d4f3574e 8753@noindent
104c1213 8754but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 8755function in your program, that function is called when
104c1213
JM
8756@code{@value{GDBN}} continues after stopping on a trap (for example, bus
8757error). The function indicated by @code{exceptionHook} is called with
8758one parameter: an @code{int} which is the exception number.
8759
8760@item
8761Compile and link together: your program, the @value{GDBN} debugging stub for
8762your target architecture, and the supporting subroutines.
8763
8764@item
8765Make sure you have a serial connection between your target machine and
8766the @value{GDBN} host, and identify the serial port on the host.
8767
8768@item
8769@c The "remote" target now provides a `load' command, so we should
8770@c document that. FIXME.
8771Download your program to your target machine (or get it there by
8772whatever means the manufacturer provides), and start it.
8773
8774@item
8775To start remote debugging, run @value{GDBN} on the host machine, and specify
8776as an executable file the program that is running in the remote machine.
8777This tells @value{GDBN} how to find your program's symbols and the contents
8778of its pure text.
8779
d4f3574e 8780@item
104c1213 8781@cindex serial line, @code{target remote}
d4f3574e 8782Establish communication using the @code{target remote} command.
104c1213
JM
8783Its argument specifies how to communicate with the target
8784machine---either via a devicename attached to a direct serial line, or a
8785TCP port (usually to a terminal server which in turn has a serial line
8786to the target). For example, to use a serial line connected to the
8787device named @file{/dev/ttyb}:
8788
8789@example
8790target remote /dev/ttyb
8791@end example
8792
8793@cindex TCP port, @code{target remote}
8794To use a TCP connection, use an argument of the form
8795@code{@var{host}:port}. For example, to connect to port 2828 on a
8796terminal server named @code{manyfarms}:
8797
8798@example
8799target remote manyfarms:2828
8800@end example
8801@end enumerate
8802
8803Now you can use all the usual commands to examine and change data and to
8804step and continue the remote program.
8805
8806To resume the remote program and stop debugging it, use the @code{detach}
8807command.
8808
8809@cindex interrupting remote programs
8810@cindex remote programs, interrupting
8811Whenever @value{GDBN} is waiting for the remote program, if you type the
8812interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8813program. This may or may not succeed, depending in part on the hardware
8814and the serial drivers the remote system uses. If you type the
8815interrupt character once again, @value{GDBN} displays this prompt:
8816
8817@example
8818Interrupted while waiting for the program.
8819Give up (and stop debugging it)? (y or n)
8820@end example
8821
8822If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8823(If you decide you want to try again later, you can use @samp{target
8824remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8825goes back to waiting.
8826
6d2ebf8b 8827@node Protocol
104c1213
JM
8828@subsubsection Communication protocol
8829
8830@cindex debugging stub, example
8831@cindex remote stub, example
8832@cindex stub example, remote debugging
8833The stub files provided with @value{GDBN} implement the target side of the
8834communication protocol, and the @value{GDBN} side is implemented in the
8835@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8836these subroutines to communicate, and ignore the details. (If you're
8837implementing your own stub file, you can still ignore the details: start
8838with one of the existing stub files. @file{sparc-stub.c} is the best
8839organized, and therefore the easiest to read.)
8840
8841However, there may be occasions when you need to know something about
8842the protocol---for example, if there is only one serial port to your
8843target machine, you might want your program to do something special if
8844it recognizes a packet meant for @value{GDBN}.
8845
8846In the examples below, @samp{<-} and @samp{->} are used to indicate
8847transmitted and received data respectfully.
8848
8849@cindex protocol, @value{GDBN} remote serial
8850@cindex serial protocol, @value{GDBN} remote
8851@cindex remote serial protocol
6cf7e474
AC
8852All @value{GDBN} commands and responses (other than acknowledgments) are
8853sent as a @var{packet}. A @var{packet} is introduced with the character
8854@samp{$}, the actual @var{packet-data}, and the terminating character
8855@samp{#} followed by a two-digit @var{checksum}:
104c1213
JM
8856
8857@example
8858@code{$}@var{packet-data}@code{#}@var{checksum}
8859@end example
8860@noindent
104c1213
JM
8861
8862@cindex checksum, for @value{GDBN} remote
8863@noindent
8864The two-digit @var{checksum} is computed as the modulo 256 sum of all
6cf7e474
AC
8865characters between the leading @samp{$} and the trailing @samp{#} (an
8866eight bit unsigned checksum).
8867
8868Implementors should note that prior to @value{GDBN} 5.0 the protocol
8869specification also included an optional two-digit @var{sequence-id}:
8870
8871@example
8872@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8873@end example
104c1213
JM
8874
8875@cindex sequence-id, for @value{GDBN} remote
8876@noindent
6cf7e474
AC
8877That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
8878has never output @var{sequence-id}s. Stubs that handle packets added
8879since @value{GDBN} 5.0 must not accept @var{sequence-id}.
104c1213 8880
6cf7e474 8881@cindex acknowledgment, for @value{GDBN} remote
104c1213
JM
8882When either the host or the target machine receives a packet, the first
8883response expected is an acknowledgment: either @samp{+} (to indicate
8884the package was received correctly) or @samp{-} (to request
8885retransmission):
8886
8887@example
8888<- @code{$}@var{packet-data}@code{#}@var{checksum}
8889-> @code{+}
8890@end example
8891@noindent
104c1213
JM
8892
8893The host (@value{GDBN}) sends @var{command}s, and the target (the
8894debugging stub incorporated in your program) sends a @var{response}. In
8895the case of step and continue @var{command}s, the response is only sent
8896when the operation has completed (the target has again stopped).
8897
8898@var{packet-data} consists of a sequence of characters with the
6cf7e474
AC
8899exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
8900exceptions).
8901
8902Fields within the packet should be separated using @samp{,} @samp{;} or
8903@samp{:}. Except where otherwise noted all numbers are represented in
8904HEX with leading zeros suppressed.
8905
8906Implementors should note that prior to @value{GDBN} 5.0, the character
8907@samp{:} could not appear as the third character in a packet (as it
8908would potentially conflict with the @var{sequence-id}).
104c1213
JM
8909
8910Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 8911means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
8912which stands for that many repetitions of the character preceding the
8913@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
8914where @code{n >=3} (which is where rle starts to win). The printable
8915characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8916value greater than 126 should not be used.
8917
8918Some remote systems have used a different run-length encoding mechanism
8919loosely refered to as the cisco encoding. Following the @samp{*}
8920character are two hex digits that indicate the size of the packet.
104c1213
JM
8921
8922So:
8923@example
8924"@code{0* }"
8925@end example
8926@noindent
8927means the same as "0000".
8928
598ca718 8929The error response returned for some packets includes a two character
104c1213
JM
8930error number. That number is not well defined.
8931
8932For any @var{command} not supported by the stub, an empty response
8933(@samp{$#00}) should be returned. That way it is possible to extend the
8934protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 8935on that response.
104c1213 8936
f1251bdd
C
8937A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
8938@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8939optional.
8940
104c1213
JM
8941Below is a complete list of all currently defined @var{command}s and
8942their corresponding response @var{data}:
598ca718 8943@page
104c1213
JM
8944@multitable @columnfractions .30 .30 .40
8945@item Packet
8946@tab Request
8947@tab Description
8948
f1251bdd 8949@item extended ops
104c1213
JM
8950@tab @code{!}
8951@tab
d4f3574e 8952Use the extended remote protocol. Sticky---only needs to be set once.
598ca718 8953The extended remote protocol supports the @samp{R} packet.
104c1213
JM
8954@item
8955@tab reply @samp{}
8956@tab
8957Stubs that support the extended remote protocol return @samp{} which,
8958unfortunately, is identical to the response returned by stubs that do not
8959support protocol extensions.
8960
8961@item last signal
8962@tab @code{?}
8963@tab
d4f3574e
SS
8964Indicate the reason the target halted. The reply is the same as for step
8965and continue.
8966@item
8967@tab reply
8968@tab see below
8969
104c1213
JM
8970
8971@item reserved
8972@tab @code{a}
5d161b24 8973@tab Reserved for future use
104c1213 8974
f1251bdd 8975@item set program arguments @strong{(reserved)}
104c1213
JM
8976@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8977@tab
598ca718
EZ
8978@item
8979@tab
8980@tab
104c1213
JM
8981Initialized @samp{argv[]} array passed into program. @var{arglen}
8982specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 8983See @file{gdbserver} for more details.
104c1213
JM
8984@item
8985@tab reply @code{OK}
8986@item
8987@tab reply @code{E}@var{NN}
8988
8989@item set baud @strong{(deprecated)}
8990@tab @code{b}@var{baud}
8991@tab
8992Change the serial line speed to @var{baud}. JTC: @emph{When does the
8993transport layer state change? When it's received, or after the ACK is
8994transmitted. In either case, there are problems if the command or the
8995acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8996to add something like this, and get it working for the first time, they
8997ought to modify ser-unix.c to send some kind of out-of-band message to a
8998specially-setup stub and have the switch happen "in between" packets, so
8999that from remote protocol's point of view, nothing actually
9000happened.}
9001
9002@item set breakpoint @strong{(deprecated)}
9003@tab @code{B}@var{addr},@var{mode}
9004@tab
9005Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9006breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9007@samp{z} packets.}
9008
9009@item continue
9010@tab @code{c}@var{addr}
9011@tab
9012@var{addr} is address to resume. If @var{addr} is omitted, resume at
9013current address.
9014@item
9015@tab reply
9016@tab see below
9017
f1251bdd 9018@item continue with signal
104c1213
JM
9019@tab @code{C}@var{sig}@code{;}@var{addr}
9020@tab
9021Continue with signal @var{sig} (hex signal number). If
9022@code{;}@var{addr} is omitted, resume at same address.
9023@item
9024@tab reply
9025@tab see below
9026
598ca718 9027@item toggle debug @strong{(deprecated)}
104c1213
JM
9028@tab @code{d}
9029@tab
d4f3574e 9030toggle debug flag.
104c1213 9031
f1251bdd 9032@item detach
104c1213 9033@tab @code{D}
d4f3574e 9034@tab
2df3850c
JM
9035Detach @value{GDBN} from the remote system. Sent to the remote target before
9036@value{GDBN} disconnects.
d4f3574e
SS
9037@item
9038@tab reply @emph{no response}
9039@tab
598ca718 9040@value{GDBN} does not check for any response after sending this packet.
104c1213
JM
9041
9042@item reserved
9043@tab @code{e}
5d161b24 9044@tab Reserved for future use
104c1213
JM
9045
9046@item reserved
9047@tab @code{E}
5d161b24 9048@tab Reserved for future use
104c1213
JM
9049
9050@item reserved
9051@tab @code{f}
5d161b24 9052@tab Reserved for future use
104c1213
JM
9053
9054@item reserved
9055@tab @code{F}
5d161b24 9056@tab Reserved for future use
104c1213
JM
9057
9058@item read registers
9059@tab @code{g}
9060@tab Read general registers.
9061@item
9062@tab reply @var{XX...}
9063@tab
9064Each byte of register data is described by two hex digits. The bytes
9065with the register are transmitted in target byte order. The size of
d4f3574e 9066each register and their position within the @samp{g} @var{packet} are
2df3850c 9067determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
9068@var{REGISTER_NAME} macros. The specification of several standard
9069@code{g} packets is specified below.
104c1213
JM
9070@item
9071@tab @code{E}@var{NN}
9072@tab for an error.
9073
9074@item write regs
9075@tab @code{G}@var{XX...}
9076@tab
9077See @samp{g} for a description of the @var{XX...} data.
9078@item
9079@tab reply @code{OK}
9080@tab for success
9081@item
9082@tab reply @code{E}@var{NN}
9083@tab for an error
9084
9085@item reserved
9086@tab @code{h}
5d161b24 9087@tab Reserved for future use
104c1213 9088
f1251bdd 9089@item set thread
104c1213
JM
9090@tab @code{H}@var{c}@var{t...}
9091@tab
d4f3574e
SS
9092Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9093@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9094continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9095thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
9096@item
9097@tab reply @code{OK}
9098@tab for success
9099@item
9100@tab reply @code{E}@var{NN}
9101@tab for an error
9102
d4f3574e
SS
9103@c FIXME: JTC:
9104@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 9105@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
9106@c to continue to execute? As I mentioned above, I think the
9107@c semantics of each command when a thread is selected must be
9108@c described. For example:
9109@c
9110@c 'g': If the stub supports threads and a specific thread is
9111@c selected, returns the register block from that thread;
9112@c otherwise returns current registers.
9113@c
9114@c 'G' If the stub supports threads and a specific thread is
9115@c selected, sets the registers of the register block of
9116@c that thread; otherwise sets current registers.
9117
f1251bdd 9118@item cycle step @strong{(draft)}
104c1213
JM
9119@tab @code{i}@var{addr}@code{,}@var{nnn}
9120@tab
9121Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9122present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9123step starting at that address.
9124
f1251bdd 9125@item signal then cycle step @strong{(reserved)}
104c1213
JM
9126@tab @code{I}
9127@tab
9128See @samp{i} and @samp{S} for likely syntax and semantics.
9129
9130@item reserved
9131@tab @code{j}
9132@tab Reserved for future use
9133
9134@item reserved
9135@tab @code{J}
5d161b24 9136@tab Reserved for future use
104c1213 9137
f1251bdd 9138@item kill request
104c1213
JM
9139@tab @code{k}
9140@tab
d4f3574e
SS
9141FIXME: @emph{There is no description of how operate when a specific
9142thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
9143
9144@item reserved
9145@tab @code{l}
5d161b24 9146@tab Reserved for future use
104c1213
JM
9147
9148@item reserved
9149@tab @code{L}
5d161b24 9150@tab Reserved for future use
104c1213
JM
9151
9152@item read memory
9153@tab @code{m}@var{addr}@code{,}@var{length}
9154@tab
9155Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 9156Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
9157using word alligned accesses. FIXME: @emph{A word aligned memory
9158transfer mechanism is needed.}
104c1213
JM
9159@item
9160@tab reply @var{XX...}
9161@tab
d4f3574e 9162@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 9163to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
9164sized memory transfers are assumed using word alligned accesses. FIXME:
9165@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
9166@item
9167@tab reply @code{E}@var{NN}
9168@tab @var{NN} is errno
9169
9170@item write mem
9171@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
9172@tab
9173Write @var{length} bytes of memory starting at address @var{addr}.
9174@var{XX...} is the data.
9175@item
9176@tab reply @code{OK}
9177@tab for success
9178@item
9179@tab reply @code{E}@var{NN}
9180@tab
9181for an error (this includes the case where only part of the data was
9182written).
9183
9184@item reserved
9185@tab @code{n}
5d161b24 9186@tab Reserved for future use
104c1213
JM
9187
9188@item reserved
9189@tab @code{N}
5d161b24 9190@tab Reserved for future use
104c1213
JM
9191
9192@item reserved
9193@tab @code{o}
5d161b24 9194@tab Reserved for future use
104c1213
JM
9195
9196@item reserved
9197@tab @code{O}
5d161b24 9198@tab Reserved for future use
104c1213
JM
9199
9200@item read reg @strong{(reserved)}
9201@tab @code{p}@var{n...}
9202@tab
9203See write register.
9204@item
9205@tab return @var{r....}
9206@tab The hex encoded value of the register in target byte order.
9207
f1251bdd 9208@item write reg
104c1213
JM
9209@tab @code{P}@var{n...}@code{=}@var{r...}
9210@tab
9211Write register @var{n...} with value @var{r...}, which contains two hex
9212digits for each byte in the register (target byte order).
9213@item
9214@tab reply @code{OK}
9215@tab for success
9216@item
9217@tab reply @code{E}@var{NN}
9218@tab for an error
9219
f1251bdd 9220@item general query
104c1213
JM
9221@tab @code{q}@var{query}
9222@tab
598ca718 9223Request info about @var{query}. In general @value{GDBN} queries
104c1213 9224have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
9225company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
9226optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
9227must ensure that they match the full @var{query} name.
104c1213
JM
9228@item
9229@tab reply @code{XX...}
d4f3574e 9230@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
9231@item
9232@tab reply @code{E}@var{NN}
9233@tab error reply
9234@item
9235@tab reply @samp{}
9236@tab Indicating an unrecognized @var{query}.
9237
f1251bdd 9238@item general set
104c1213
JM
9239@tab @code{Q}@var{var}@code{=}@var{val}
9240@tab
9241Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9242naming conventions.
9243
598ca718 9244@item reset @strong{(deprecated)}
d4f3574e
SS
9245@tab @code{r}
9246@tab
9247Reset the entire system.
104c1213 9248
f1251bdd 9249@item remote restart
104c1213
JM
9250@tab @code{R}@var{XX}
9251@tab
d4f3574e
SS
9252Restart the remote server. @var{XX} while needed has no clear
9253definition. FIXME: @emph{An example interaction explaining how this
9254packet is used in extended-remote mode is needed}.
104c1213 9255
f1251bdd 9256@item step
104c1213
JM
9257@tab @code{s}@var{addr}
9258@tab
9259@var{addr} is address to resume. If @var{addr} is omitted, resume at
9260same address.
9261@item
9262@tab reply
9263@tab see below
9264
f1251bdd 9265@item step with signal
104c1213
JM
9266@tab @code{S}@var{sig}@code{;}@var{addr}
9267@tab
9268Like @samp{C} but step not continue.
9269@item
9270@tab reply
9271@tab see below
9272
f1251bdd 9273@item search
104c1213
JM
9274@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9275@tab
9276Search backwards starting at address @var{addr} for a match with pattern
9277@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 9278bytes. @var{addr} must be at least 3 digits.
104c1213 9279
f1251bdd 9280@item thread alive
104c1213
JM
9281@tab @code{T}@var{XX}
9282@tab Find out if the thread XX is alive.
9283@item
9284@tab reply @code{OK}
9285@tab thread is still alive
9286@item
9287@tab reply @code{E}@var{NN}
9288@tab thread is dead
5d161b24 9289
104c1213
JM
9290@item reserved
9291@tab @code{u}
5d161b24 9292@tab Reserved for future use
104c1213
JM
9293
9294@item reserved
9295@tab @code{U}
5d161b24 9296@tab Reserved for future use
104c1213
JM
9297
9298@item reserved
9299@tab @code{v}
5d161b24 9300@tab Reserved for future use
104c1213
JM
9301
9302@item reserved
9303@tab @code{V}
5d161b24 9304@tab Reserved for future use
104c1213
JM
9305
9306@item reserved
9307@tab @code{w}
5d161b24 9308@tab Reserved for future use
104c1213
JM
9309
9310@item reserved
9311@tab @code{W}
5d161b24 9312@tab Reserved for future use
104c1213
JM
9313
9314@item reserved
9315@tab @code{x}
5d161b24 9316@tab Reserved for future use
104c1213 9317
f1251bdd 9318@item write mem (binary)
104c1213
JM
9319@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9320@tab
9321@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
9322binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9323escaped using @code{0x7d}.
104c1213
JM
9324@item
9325@tab reply @code{OK}
9326@tab for success
9327@item
9328@tab reply @code{E}@var{NN}
9329@tab for an error
9330
9331@item reserved
9332@tab @code{y}
5d161b24 9333@tab Reserved for future use
104c1213
JM
9334
9335@item reserved
9336@tab @code{Y}
5d161b24 9337@tab Reserved for future use
104c1213 9338
f1251bdd 9339@item remove break or watchpoint @strong{(draft)}
104c1213
JM
9340@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9341@tab
9342See @samp{Z}.
9343
f1251bdd 9344@item insert break or watchpoint @strong{(draft)}
104c1213
JM
9345@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9346@tab
9347@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9348breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9349@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9350bytes. For a software breakpoint, @var{length} specifies the size of
9351the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
9352@var{length} specifies the memory region to be monitored. To avoid
9353potential problems with duplicate packets, the operations should be
6d2ebf8b 9354implemented in an idempotent way.
104c1213
JM
9355@item
9356@tab reply @code{E}@var{NN}
9357@tab for an error
9358@item
9359@tab reply @code{OK}
9360@tab for success
9361@item
9362@tab @samp{}
9363@tab If not supported.
9364
9365@item reserved
9366@tab <other>
5d161b24 9367@tab Reserved for future use
104c1213
JM
9368
9369@end multitable
9370
d4f3574e
SS
9371The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9372receive any of the below as a reply. In the case of the @samp{C},
9373@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9374when the target halts. In the below the exact meaning of @samp{signal
9375number} is poorly defined. In general one of the UNIX signal numbering
9376conventions is used.
104c1213
JM
9377
9378@multitable @columnfractions .4 .6
9379
9380@item @code{S}@var{AA}
9381@tab @var{AA} is the signal number
9382
9383@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9384@tab
9385@var{AA} = two hex digit signal number; @var{n...} = register number
9386(hex), @var{r...} = target byte ordered register contents, size defined
9387by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9388thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 9389starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
9390@var{n...}, @var{r...} pair and go on to the next. This way we can
9391extend the protocol.
9392
9393@item @code{W}@var{AA}
9394@tab
9395The process exited, and @var{AA} is the exit status. This is only
9396applicable for certains sorts of targets.
9397
9398@item @code{X}@var{AA}
9399@tab
9400The process terminated with signal @var{AA}.
9401
6d2ebf8b 9402@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 9403@tab
6d2ebf8b
SS
9404@var{AA} = signal number; @var{t...} = address of symbol "_start";
9405@var{d...} = base of data section; @var{b...} = base of bss section.
9406@emph{Note: only used by Cisco Systems targets. The difference between
9407this reply and the "qOffsets" query is that the 'N' packet may arrive
9408spontaneously whereas the 'qOffsets' is a query initiated by the host
9409debugger.}
104c1213
JM
9410
9411@item @code{O}@var{XX...}
9412@tab
c3f6f71d 9413@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
9414while the program is running and the debugger should continue to wait
9415for 'W', 'T', etc.
9416
9417@end multitable
9418
d4f3574e
SS
9419The following set and query packets have already been defined.
9420
9421@multitable @columnfractions .2 .2 .6
9422
9423@item current thread
9424@tab @code{q}@code{C}
9425@tab Return the current thread id.
9426@item
9427@tab reply @code{QC}@var{pid}
9428@tab
9429Where @var{pid} is a HEX encoded 16 bit process id.
9430@item
9431@tab reply *
9432@tab Any other reply implies the old pid.
9433
bba2971c
MS
9434@item all thread ids
9435@tab @code{q}@code{fThreadInfo}
9436@item
9437@tab @code{q}@code{sThreadInfo}
d4f3574e 9438@tab
bba2971c
MS
9439Obtain a list of active thread ids from the target (OS). Since there
9440may be too many active threads to fit into one reply packet, this query
9441works iteratively: it may require more than one query/reply sequence to
9442obtain the entire list of threads. The first query of the sequence will
5d161b24 9443be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 9444sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 9445@item
bba2971c
MS
9446@tab
9447@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 9448@item
5d161b24 9449@tab reply @code{m}@var{<id>}
bba2971c
MS
9450@tab A single thread id
9451@item
00e4a2e4 9452@tab reply @code{m}@var{<id>},@var{<id>...}
bba2971c
MS
9453@tab a comma-separated list of thread ids
9454@item
9455@tab reply @code{l}
9456@tab (lower case 'el') denotes end of list.
9457@item
9458@tab
9459@tab
9460In response to each query, the target will reply with a list of one
9461or more thread ids, in big-endian hex, separated by commas. GDB will
9462respond to each reply with a request for more thread ids (using the
9463@code{qs} form of the query), until the target responds with @code{l}
9464(lower-case el, for @code{'last'}).
9465
9466@item extra thread info
480ff1fb 9467@tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
bba2971c
MS
9468@tab
9469@item
9470@tab
9471@tab
9472Where @var{<id>} is a thread-id in big-endian hex.
9473Obtain a printable string description of a thread's attributes from
9474the target OS. This string may contain anything that the target OS
9475thinks is interesting for @value{GDBN} to tell the user about the thread.
9476The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 9477Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
9478"Blocked on Mutex".
9479@item
9480@tab reply @var{XX...}
9481@tab
9482Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
9483printable string containing the extra information about the thread's
9484attributes.
d4f3574e
SS
9485
9486@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9487@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9488@tab
2b628194
MS
9489@item
9490@tab
9491@tab
d4f3574e
SS
9492Obtain thread information from RTOS. Where: @var{startflag} (one hex
9493digit) is one to indicate the first query and zero to indicate a
9494subsequent query; @var{threadcount} (two hex digits) is the maximum
9495number of threads the response packet can contain; and @var{nextthread}
9496(eight hex digits), for subsequent queries (@var{startflag} is zero), is
9497returned in the response as @var{argthread}.
9498@item
bba2971c
MS
9499@tab
9500@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
9501query (see above).
9502@item
d4f3574e
SS
9503@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9504@tab
2b628194
MS
9505@item
9506@tab
9507@tab
d4f3574e
SS
9508Where: @var{count} (two hex digits) is the number of threads being
9509returned; @var{done} (one hex digit) is zero to indicate more threads
9510and one indicates no further threads; @var{argthreadid} (eight hex
9511digits) is @var{nextthread} from the request packet; @var{thread...} is
9512a sequence of thread IDs from the target. @var{threadid} (eight hex
9513digits). See @code{remote.c:parse_threadlist_response()}.
9514
bba2971c
MS
9515@item compute CRC of memory block
9516@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9517@tab
9518@item
9519@tab reply @code{E}@var{NN}
9520@tab An error (such as memory fault)
9521@item
9522@tab reply @code{C}@var{CRC32}
9523@tab A 32 bit cyclic redundancy check of the specified memory region.
9524
d4f3574e
SS
9525@item query sect offs
9526@tab @code{q}@code{Offsets}
917317f4
JM
9527@tab
9528Get section offsets that the target used when re-locating the downloaded
9529image. @emph{Note: while a @code{Bss} offset is included in the
9530response, @value{GDBN} ignores this and instead applies the @code{Data}
9531offset to the @code{Bss} section.}
d4f3574e
SS
9532@item
9533@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9534
9535@item thread info request
9536@tab @code{q}@code{P}@var{mode}@var{threadid}
9537@tab
598ca718
EZ
9538@item
9539@tab
9540@tab
d4f3574e
SS
9541Returns information on @var{threadid}. Where: @var{mode} is a hex
9542encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9543@item
9544@tab reply *
9545@tab
9546See @code{remote.c:remote_unpack_thread_info_response()}.
9547
9548@item remote command
9549@tab @code{q}@code{Rcmd,}@var{COMMAND}
9550@tab
598ca718
EZ
9551@item
9552@tab
9553@tab
d4f3574e
SS
9554@var{COMMAND} (hex encoded) is passed to the local interpreter for
9555execution. Invalid commands should be reported using the output string.
9556Before the final result packet, the target may also respond with a
9557number of intermediate @code{O}@var{OUTPUT} console output
9558packets. @emph{Implementors should note that providing access to a
9559stubs's interpreter may have security implications}.
9560@item
9561@tab reply @code{OK}
9562@tab
9563A command response with no output.
9564@item
9565@tab reply @var{OUTPUT}
9566@tab
9567A command response with the hex encoded output string @var{OUTPUT}.
9568@item
9569@tab reply @code{E}@var{NN}
9570@tab
9571Indicate a badly formed request.
9572
9573@item
9574@tab reply @samp{}
9575@tab
9576When @samp{q}@samp{Rcmd} is not recognized.
9577
9578@end multitable
9579
9580The following @samp{g}/@samp{G} packets have previously been defined.
9581In the below, some thirty-two bit registers are transferred as sixty-four
9582bits. Those registers should be zero/sign extended (which?) to fill the
9583space allocated. Register bytes are transfered in target byte order.
9584The two nibbles within a register byte are transfered most-significant -
9585least-significant.
9586
9587@multitable @columnfractions .5 .5
9588
9589@item MIPS32
9590@tab
9591All registers are transfered as thirty-two bit quantities in the order:
959232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9593registers; fsr; fir; fp.
9594
9595@item MIPS64
9596@tab
9597All registers are transfered as sixty-four bit quantities (including
9598thirty-two bit registers such as @code{sr}). The ordering is the same
9599as @code{MIPS32}.
9600
9601@end multitable
9602
104c1213
JM
9603Example sequence of a target being re-started. Notice how the restart
9604does not get any direct output:
9605
9606@example
9607<- @code{R00}
9608-> @code{+}
9609@emph{target restarts}
9610<- @code{?}
9611-> @code{+}
9612-> @code{T001:1234123412341234}
9613<- @code{+}
9614@end example
9615
9616Example sequence of a target being stepped by a single instruction:
9617
9618@example
9619<- @code{G1445...}
9620-> @code{+}
9621<- @code{s}
9622-> @code{+}
9623@emph{time passes}
9624-> @code{T001:1234123412341234}
9625<- @code{+}
9626<- @code{g}
9627-> @code{+}
9628-> @code{1455...}
9629<- @code{+}
9630@end example
9631
6d2ebf8b 9632@node Server
104c1213
JM
9633@subsubsection Using the @code{gdbserver} program
9634
9635@kindex gdbserver
9636@cindex remote connection without stubs
9637@code{gdbserver} is a control program for Unix-like systems, which
9638allows you to connect your program with a remote @value{GDBN} via
9639@code{target remote}---but without linking in the usual debugging stub.
9640
9641@code{gdbserver} is not a complete replacement for the debugging stubs,
9642because it requires essentially the same operating-system facilities
9643that @value{GDBN} itself does. In fact, a system that can run
9644@code{gdbserver} to connect to a remote @value{GDBN} could also run
9645@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9646because it is a much smaller program than @value{GDBN} itself. It is
9647also easier to port than all of @value{GDBN}, so you may be able to get
9648started more quickly on a new system by using @code{gdbserver}.
9649Finally, if you develop code for real-time systems, you may find that
9650the tradeoffs involved in real-time operation make it more convenient to
9651do as much development work as possible on another system, for example
9652by cross-compiling. You can use @code{gdbserver} to make a similar
9653choice for debugging.
9654
9655@value{GDBN} and @code{gdbserver} communicate via either a serial line
9656or a TCP connection, using the standard @value{GDBN} remote serial
9657protocol.
9658
9659@table @emph
9660@item On the target machine,
9661you need to have a copy of the program you want to debug.
9662@code{gdbserver} does not need your program's symbol table, so you can
9663strip the program if necessary to save space. @value{GDBN} on the host
9664system does all the symbol handling.
9665
9666To use the server, you must tell it how to communicate with @value{GDBN};
9667the name of your program; and the arguments for your program. The
9668syntax is:
9669
9670@smallexample
9671target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9672@end smallexample
9673
9674@var{comm} is either a device name (to use a serial line) or a TCP
9675hostname and portnumber. For example, to debug Emacs with the argument
9676@samp{foo.txt} and communicate with @value{GDBN} over the serial port
9677@file{/dev/com1}:
9678
9679@smallexample
9680target> gdbserver /dev/com1 emacs foo.txt
9681@end smallexample
9682
9683@code{gdbserver} waits passively for the host @value{GDBN} to communicate
9684with it.
9685
9686To use a TCP connection instead of a serial line:
9687
9688@smallexample
9689target> gdbserver host:2345 emacs foo.txt
9690@end smallexample
9691
9692The only difference from the previous example is the first argument,
9693specifying that you are communicating with the host @value{GDBN} via
9694TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9695expect a TCP connection from machine @samp{host} to local TCP port 2345.
9696(Currently, the @samp{host} part is ignored.) You can choose any number
9697you want for the port number as long as it does not conflict with any
9698TCP ports already in use on the target system (for example, @code{23} is
9699reserved for @code{telnet}).@footnote{If you choose a port number that
9700conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 9701and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
9702@code{target remote} command.
9703
9704@item On the @value{GDBN} host machine,
9705you need an unstripped copy of your program, since @value{GDBN} needs
9706symbols and debugging information. Start up @value{GDBN} as usual,
9707using the name of the local copy of your program as the first argument.
9708(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9709running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
9710remote} to establish communications with @code{gdbserver}. Its argument
9711is either a device name (usually a serial device, like
9712@file{/dev/ttyb}), or a TCP port descriptor in the form
9713@code{@var{host}:@var{PORT}}. For example:
9714
9715@smallexample
9716(@value{GDBP}) target remote /dev/ttyb
9717@end smallexample
9718
9719@noindent
9720communicates with the server via serial line @file{/dev/ttyb}, and
9721
9722@smallexample
9723(@value{GDBP}) target remote the-target:2345
9724@end smallexample
9725
9726@noindent
9727communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9728For TCP connections, you must start up @code{gdbserver} prior to using
9729the @code{target remote} command. Otherwise you may get an error whose
9730text depends on the host system, but which usually looks something like
9731@samp{Connection refused}.
9732@end table
9733
6d2ebf8b 9734@node NetWare
104c1213
JM
9735@subsubsection Using the @code{gdbserve.nlm} program
9736
9737@kindex gdbserve.nlm
9738@code{gdbserve.nlm} is a control program for NetWare systems, which
9739allows you to connect your program with a remote @value{GDBN} via
9740@code{target remote}.
9741
9742@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9743using the standard @value{GDBN} remote serial protocol.
9744
9745@table @emph
9746@item On the target machine,
9747you need to have a copy of the program you want to debug.
9748@code{gdbserve.nlm} does not need your program's symbol table, so you
9749can strip the program if necessary to save space. @value{GDBN} on the
9750host system does all the symbol handling.
9751
9752To use the server, you must tell it how to communicate with
9753@value{GDBN}; the name of your program; and the arguments for your
9754program. The syntax is:
9755
5d161b24 9756@smallexample
104c1213
JM
9757load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9758 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9759@end smallexample
9760
9761@var{board} and @var{port} specify the serial line; @var{baud} specifies
9762the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 9763to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
9764
9765For example, to debug Emacs with the argument @samp{foo.txt}and
5d161b24 9766communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 9767using a 19200@dmn{bps} connection:
104c1213
JM
9768
9769@smallexample
9770load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9771@end smallexample
9772
9773@item On the @value{GDBN} host machine,
9774you need an unstripped copy of your program, since @value{GDBN} needs
9775symbols and debugging information. Start up @value{GDBN} as usual,
9776using the name of the local copy of your program as the first argument.
9777(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9778running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
9779remote} to establish communications with @code{gdbserve.nlm}. Its
9780argument is a device name (usually a serial device, like
9781@file{/dev/ttyb}). For example:
9782
9783@smallexample
9784(@value{GDBP}) target remote /dev/ttyb
9785@end smallexample
9786
9787@noindent
9788communications with the server via serial line @file{/dev/ttyb}.
9789@end table
9790
6d2ebf8b 9791@node KOD
104c1213
JM
9792@section Kernel Object Display
9793
9794@cindex kernel object display
9795@cindex kernel object
9796@cindex KOD
9797
9798Some targets support kernel object display. Using this facility,
9799@value{GDBN} communicates specially with the underlying operating system
9800and can display information about operating system-level objects such as
9801mutexes and other synchronization objects. Exactly which objects can be
9802displayed is determined on a per-OS basis.
9803
9804Use the @code{set os} command to set the operating system. This tells
9805@value{GDBN} which kernel object display module to initialize:
9806
9807@example
2df3850c 9808(@value{GDBP}) set os cisco
104c1213
JM
9809@end example
9810
9811If @code{set os} succeeds, @value{GDBN} will display some information
9812about the operating system, and will create a new @code{info} command
9813which can be used to query the target. The @code{info} command is named
9814after the operating system:
9815
9816@example
2df3850c 9817(@value{GDBP}) info cisco
104c1213
JM
9818List of Cisco Kernel Objects
9819Object Description
9820any Any and all objects
9821@end example
9822
9823Further subcommands can be used to query about particular objects known
9824by the kernel.
9825
9826There is currently no way to determine whether a given operating system
96baa820
JM
9827is supported other than to try it.
9828
9829
6d2ebf8b 9830@node Configurations
104c1213
JM
9831@chapter Configuration-Specific Information
9832
9833While nearly all @value{GDBN} commands are available for all native and
9834cross versions of the debugger, there are some exceptions. This chapter
9835describes things that are only available in certain configurations.
9836
9837There are three major categories of configurations: native
9838configurations, where the host and target are the same, embedded
9839operating system configurations, which are usually the same for several
9840different processor architectures, and bare embedded processors, which
9841are quite different from each other.
9842
9843@menu
9844* Native::
9845* Embedded OS::
9846* Embedded Processors::
9847* Architectures::
9848@end menu
9849
6d2ebf8b 9850@node Native
104c1213
JM
9851@section Native
9852
9853This section describes details specific to particular native
9854configurations.
9855
9856@menu
9857* HP-UX:: HP-UX
9858* SVR4 Process Information:: SVR4 process information
9859@end menu
9860
6d2ebf8b 9861@node HP-UX
104c1213
JM
9862@subsection HP-UX
9863
9864On HP-UX systems, if you refer to a function or variable name that
9865begins with a dollar sign, @value{GDBN} searches for a user or system
9866name first, before it searches for a convenience variable.
9867
6d2ebf8b 9868@node SVR4 Process Information
104c1213
JM
9869@subsection SVR4 process information
9870
9871@kindex /proc
9872@cindex process image
9873
9874Many versions of SVR4 provide a facility called @samp{/proc} that can be
9875used to examine the image of a running process using file-system
9876subroutines. If @value{GDBN} is configured for an operating system with
9877this facility, the command @code{info proc} is available to report on
9878several kinds of information about the process running your program.
9879@code{info proc} works only on SVR4 systems that include the
9880@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9881and Unixware, but not HP-UX or Linux, for example.
9882
9883@table @code
9884@kindex info proc
9885@item info proc
9886Summarize available information about the process.
9887
9888@kindex info proc mappings
9889@item info proc mappings
9890Report on the address ranges accessible in the program, with information
9891on whether your program may read, write, or execute each range.
9892
9893@kindex info proc times
9894@item info proc times
9895Starting time, user CPU time, and system CPU time for your program and
9896its children.
9897
9898@kindex info proc id
9899@item info proc id
9900Report on the process IDs related to your program: its own process ID,
9901the ID of its parent, the process group ID, and the session ID.
9902
9903@kindex info proc status
9904@item info proc status
9905General information on the state of the process. If the process is
9906stopped, this report includes the reason for stopping, and any signal
9907received.
9908
9909@item info proc all
9910Show all the above information about the process.
9911@end table
9912
6d2ebf8b 9913@node Embedded OS
104c1213
JM
9914@section Embedded Operating Systems
9915
9916This section describes configurations involving the debugging of
9917embedded operating systems that are available for several different
9918architectures.
9919
9920@menu
9921* VxWorks:: Using @value{GDBN} with VxWorks
9922@end menu
9923
9924@value{GDBN} includes the ability to debug programs running on
9925various real-time operating systems.
9926
6d2ebf8b 9927@node VxWorks
104c1213
JM
9928@subsection Using @value{GDBN} with VxWorks
9929
9930@cindex VxWorks
9931
9932@table @code
9933
9934@kindex target vxworks
9935@item target vxworks @var{machinename}
9936A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9937is the target system's machine name or IP address.
9938
9939@end table
9940
9941On VxWorks, @code{load} links @var{filename} dynamically on the
9942current target system as well as adding its symbols in @value{GDBN}.
9943
9944@value{GDBN} enables developers to spawn and debug tasks running on networked
9945VxWorks targets from a Unix host. Already-running tasks spawned from
9946the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9947both the Unix host and on the VxWorks target. The program
d4f3574e 9948@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 9949installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 9950@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
9951
9952@table @code
9953@item VxWorks-timeout @var{args}
9954@kindex vxworks-timeout
5d161b24
DB
9955All VxWorks-based targets now support the option @code{vxworks-timeout}.
9956This option is set by the user, and @var{args} represents the number of
9957seconds @value{GDBN} waits for responses to rpc's. You might use this if
9958your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
9959of a thin network line.
9960@end table
9961
9962The following information on connecting to VxWorks was current when
9963this manual was produced; newer releases of VxWorks may use revised
9964procedures.
9965
9966@kindex INCLUDE_RDB
9967To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9968to include the remote debugging interface routines in the VxWorks
9969library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9970VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9971kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9972source debugging task @code{tRdbTask} when VxWorks is booted. For more
9973information on configuring and remaking VxWorks, see the manufacturer's
9974manual.
9975@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9976
9977Once you have included @file{rdb.a} in your VxWorks system image and set
9978your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
9979run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
9980@code{vxgdb}, depending on your installation).
104c1213
JM
9981
9982@value{GDBN} comes up showing the prompt:
9983
9984@example
9985(vxgdb)
9986@end example
9987
9988@menu
9989* VxWorks Connection:: Connecting to VxWorks
9990* VxWorks Download:: VxWorks download
9991* VxWorks Attach:: Running tasks
9992@end menu
9993
6d2ebf8b 9994@node VxWorks Connection
104c1213
JM
9995@subsubsection Connecting to VxWorks
9996
9997The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9998network. To connect to a target whose host name is ``@code{tt}'', type:
9999
10000@example
10001(vxgdb) target vxworks tt
10002@end example
10003
10004@need 750
10005@value{GDBN} displays messages like these:
10006
10007@smallexample
5d161b24 10008Attaching remote machine across net...
104c1213
JM
10009Connected to tt.
10010@end smallexample
10011
10012@need 1000
10013@value{GDBN} then attempts to read the symbol tables of any object modules
10014loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10015these files by searching the directories listed in the command search
10016path (@pxref{Environment, ,Your program's environment}); if it fails
10017to find an object file, it displays a message such as:
10018
10019@example
10020prog.o: No such file or directory.
10021@end example
10022
10023When this happens, add the appropriate directory to the search path with
10024the @value{GDBN} command @code{path}, and execute the @code{target}
10025command again.
10026
6d2ebf8b 10027@node VxWorks Download
104c1213
JM
10028@subsubsection VxWorks download
10029
10030@cindex download to VxWorks
10031If you have connected to the VxWorks target and you want to debug an
10032object that has not yet been loaded, you can use the @value{GDBN}
10033@code{load} command to download a file from Unix to VxWorks
10034incrementally. The object file given as an argument to the @code{load}
10035command is actually opened twice: first by the VxWorks target in order
10036to download the code, then by @value{GDBN} in order to read the symbol
10037table. This can lead to problems if the current working directories on
10038the two systems differ. If both systems have NFS mounted the same
10039filesystems, you can avoid these problems by using absolute paths.
10040Otherwise, it is simplest to set the working directory on both systems
10041to the directory in which the object file resides, and then to reference
10042the file by its name, without any path. For instance, a program
10043@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10044and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10045program, type this on VxWorks:
10046
10047@example
10048-> cd "@var{vxpath}/vw/demo/rdb"
10049@end example
d4f3574e
SS
10050
10051@noindent
104c1213
JM
10052Then, in @value{GDBN}, type:
10053
10054@example
5d161b24 10055(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
10056(vxgdb) load prog.o
10057@end example
10058
10059@value{GDBN} displays a response similar to this:
10060
10061@smallexample
10062Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10063@end smallexample
10064
10065You can also use the @code{load} command to reload an object module
10066after editing and recompiling the corresponding source file. Note that
10067this makes @value{GDBN} delete all currently-defined breakpoints,
10068auto-displays, and convenience variables, and to clear the value
10069history. (This is necessary in order to preserve the integrity of
d4f3574e 10070debugger's data structures that reference the target system's symbol
104c1213
JM
10071table.)
10072
6d2ebf8b 10073@node VxWorks Attach
104c1213
JM
10074@subsubsection Running tasks
10075
10076@cindex running VxWorks tasks
10077You can also attach to an existing task using the @code{attach} command as
10078follows:
10079
10080@example
10081(vxgdb) attach @var{task}
10082@end example
10083
10084@noindent
10085where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10086or suspended when you attach to it. Running tasks are suspended at
10087the time of attachment.
10088
6d2ebf8b 10089@node Embedded Processors
104c1213
JM
10090@section Embedded Processors
10091
10092This section goes into details specific to particular embedded
10093configurations.
10094
10095@menu
10096* A29K Embedded:: AMD A29K Embedded
10097* ARM:: ARM
10098* H8/300:: Hitachi H8/300
10099* H8/500:: Hitachi H8/500
10100* i960:: Intel i960
10101* M32R/D:: Mitsubishi M32R/D
10102* M68K:: Motorola M68K
10103* M88K:: Motorola M88K
10104* MIPS Embedded:: MIPS Embedded
10105* PA:: HP PA Embedded
10106* PowerPC: PowerPC
10107* SH:: Hitachi SH
10108* Sparclet:: Tsqware Sparclet
10109* Sparclite:: Fujitsu Sparclite
10110* ST2000:: Tandem ST2000
10111* Z8000:: Zilog Z8000
10112@end menu
10113
6d2ebf8b 10114@node A29K Embedded
104c1213
JM
10115@subsection AMD A29K Embedded
10116
10117@menu
10118* A29K UDI::
10119* A29K EB29K::
10120* Comms (EB29K):: Communications setup
10121* gdb-EB29K:: EB29K cross-debugging
10122* Remote Log:: Remote log
10123@end menu
10124
10125@table @code
10126
10127@kindex target adapt
10128@item target adapt @var{dev}
10129Adapt monitor for A29K.
10130
10131@kindex target amd-eb
10132@item target amd-eb @var{dev} @var{speed} @var{PROG}
10133@cindex AMD EB29K
10134Remote PC-resident AMD EB29K board, attached over serial lines.
10135@var{dev} is the serial device, as for @code{target remote};
10136@var{speed} allows you to specify the linespeed; and @var{PROG} is the
10137name of the program to be debugged, as it appears to DOS on the PC.
10138@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
10139
10140@end table
10141
6d2ebf8b 10142@node A29K UDI
104c1213
JM
10143@subsubsection A29K UDI
10144
10145@cindex UDI
10146@cindex AMD29K via UDI
10147
10148@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
10149protocol for debugging the a29k processor family. To use this
10150configuration with AMD targets running the MiniMON monitor, you need the
10151program @code{MONTIP}, available from AMD at no charge. You can also
10152use @value{GDBN} with the UDI-conformant a29k simulator program
10153@code{ISSTIP}, also available from AMD.
10154
10155@table @code
10156@item target udi @var{keyword}
10157@kindex udi
10158Select the UDI interface to a remote a29k board or simulator, where
10159@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
10160This file contains keyword entries which specify parameters used to
10161connect to a29k targets. If the @file{udi_soc} file is not in your
10162working directory, you must set the environment variable @samp{UDICONF}
10163to its pathname.
10164@end table
10165
6d2ebf8b 10166@node A29K EB29K
104c1213
JM
10167@subsubsection EBMON protocol for AMD29K
10168
10169@cindex EB29K board
10170@cindex running 29K programs
10171
10172AMD distributes a 29K development board meant to fit in a PC, together
10173with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
10174term, this development system is called the ``EB29K''. To use
10175@value{GDBN} from a Unix system to run programs on the EB29K board, you
10176must first connect a serial cable between the PC (which hosts the EB29K
10177board) and a serial port on the Unix system. In the following, we
10178assume you've hooked the cable between the PC's @file{COM1} port and
10179@file{/dev/ttya} on the Unix system.
10180
6d2ebf8b 10181@node Comms (EB29K)
104c1213
JM
10182@subsubsection Communications setup
10183
10184The next step is to set up the PC's port, by doing something like this
10185in DOS on the PC:
10186
10187@example
10188C:\> MODE com1:9600,n,8,1,none
10189@end example
10190
10191@noindent
10192This example---run on an MS DOS 4.0 system---sets the PC port to 9600
10193bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
10194you must match the communications parameters when establishing the Unix
10195end of the connection as well.
10196@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
5d161b24 10197@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
10198@c
10199@c It's optional, but it's unwise to omit it: who knows what is the
10200@c default value set when the DOS machines boots? "No retry" means that
10201@c the DOS serial device driver won't retry the operation if it fails;
10202@c I understand that this is needed because the GDB serial protocol
10203@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
10204
10205To give control of the PC to the Unix side of the serial line, type
10206the following at the DOS console:
10207
10208@example
10209C:\> CTTY com1
10210@end example
10211
10212@noindent
10213(Later, if you wish to return control to the DOS console, you can use
10214the command @code{CTTY con}---but you must send it over the device that
96a2c332 10215had control, in our example over the @file{COM1} serial line.)
104c1213
JM
10216
10217From the Unix host, use a communications program such as @code{tip} or
10218@code{cu} to communicate with the PC; for example,
10219
10220@example
10221cu -s 9600 -l /dev/ttya
10222@end example
10223
10224@noindent
10225The @code{cu} options shown specify, respectively, the linespeed and the
10226serial port to use. If you use @code{tip} instead, your command line
10227may look something like the following:
10228
10229@example
10230tip -9600 /dev/ttya
10231@end example
10232
10233@noindent
10234Your system may require a different name where we show
10235@file{/dev/ttya} as the argument to @code{tip}. The communications
10236parameters, including which port to use, are associated with the
10237@code{tip} argument in the ``remote'' descriptions file---normally the
10238system table @file{/etc/remote}.
10239@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
10240@c the DOS side's comms setup? cu can support -o (odd
10241@c parity), -e (even parity)---apparently no settings for no parity or
10242@c for character size. Taken from stty maybe...? John points out tip
10243@c can set these as internal variables, eg ~s parity=none; man stty
10244@c suggests that it *might* work to stty these options with stdin or
10245@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
10246@c
10247@c There's nothing to be done for the "none" part of the DOS MODE
10248@c command. The rest of the parameters should be matched by the
10249@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
10250
10251@kindex EBMON
10252Using the @code{tip} or @code{cu} connection, change the DOS working
10253directory to the directory containing a copy of your 29K program, then
10254start the PC program @code{EBMON} (an EB29K control program supplied
10255with your board by AMD). You should see an initial display from
10256@code{EBMON} similar to the one that follows, ending with the
10257@code{EBMON} prompt @samp{#}---
10258
10259@example
10260C:\> G:
10261
10262G:\> CD \usr\joe\work29k
10263
10264G:\USR\JOE\WORK29K> EBMON
10265Am29000 PC Coprocessor Board Monitor, version 3.0-18
10266Copyright 1990 Advanced Micro Devices, Inc.
10267Written by Gibbons and Associates, Inc.
10268
10269Enter '?' or 'H' for help
10270
10271PC Coprocessor Type = EB29K
10272I/O Base = 0x208
10273Memory Base = 0xd0000
10274
10275Data Memory Size = 2048KB
10276Available I-RAM Range = 0x8000 to 0x1fffff
10277Available D-RAM Range = 0x80002000 to 0x801fffff
10278
10279PageSize = 0x400
10280Register Stack Size = 0x800
10281Memory Stack Size = 0x1800
10282
10283CPU PRL = 0x3
10284Am29027 Available = No
10285Byte Write Available = Yes
10286
10287# ~.
10288@end example
10289
10290Then exit the @code{cu} or @code{tip} program (done in the example by
10291typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10292running, ready for @value{GDBN} to take over.
10293
10294For this example, we've assumed what is probably the most convenient
10295way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 10296system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
10297PC as a file system on the Unix host. If you do not have PC/NFS or
10298something similar connecting the two systems, you must arrange some
10299other way---perhaps floppy-disk transfer---of getting the 29K program
10300from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10301serial line.
10302
6d2ebf8b 10303@node gdb-EB29K
104c1213
JM
10304@subsubsection EB29K cross-debugging
10305
10306Finally, @code{cd} to the directory containing an image of your 29K
10307program on the Unix system, and start @value{GDBN}---specifying as argument the
10308name of your 29K program:
10309
10310@example
10311cd /usr/joe/work29k
10312@value{GDBP} myfoo
10313@end example
10314
10315@need 500
10316Now you can use the @code{target} command:
10317
10318@example
10319target amd-eb /dev/ttya 9600 MYFOO
10320@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10321@c emphasize that this is the name as seen by DOS (since I think DOS is
10322@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10323@end example
10324
10325@noindent
10326In this example, we've assumed your program is in a file called
10327@file{myfoo}. Note that the filename given as the last argument to
10328@code{target amd-eb} should be the name of the program as it appears to DOS.
10329In our example this is simply @code{MYFOO}, but in general it can include
10330a DOS path, and depending on your transfer mechanism may not resemble
10331the name on the Unix side.
10332
10333At this point, you can set any breakpoints you wish; when you are ready
10334to see your program run on the 29K board, use the @value{GDBN} command
10335@code{run}.
10336
10337To stop debugging the remote program, use the @value{GDBN} @code{detach}
10338command.
10339
10340To return control of the PC to its console, use @code{tip} or @code{cu}
10341once again, after your @value{GDBN} session has concluded, to attach to
10342@code{EBMON}. You can then type the command @code{q} to shut down
10343@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 10344Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
10345and type @kbd{~.} to leave @code{tip} or @code{cu}.
10346
6d2ebf8b 10347@node Remote Log
104c1213 10348@subsubsection Remote log
41afff9a 10349@cindex @file{eb.log}, a log file for EB29K
104c1213
JM
10350@cindex log file for EB29K
10351
10352The @code{target amd-eb} command creates a file @file{eb.log} in the
10353current working directory, to help debug problems with the connection.
10354@file{eb.log} records all the output from @code{EBMON}, including echoes
10355of the commands sent to it. Running @samp{tail -f} on this file in
10356another window often helps to understand trouble with @code{EBMON}, or
10357unexpected events on the PC side of the connection.
10358
6d2ebf8b 10359@node ARM
104c1213
JM
10360@subsection ARM
10361
10362@table @code
10363
10364@kindex target rdi
10365@item target rdi @var{dev}
10366ARM Angel monitor, via RDI library interface to ADP protocol. You may
10367use this target to communicate with both boards running the Angel
10368monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 10369
104c1213
JM
10370@kindex target rdp
10371@item target rdp @var{dev}
10372ARM Demon monitor.
10373
10374@end table
10375
6d2ebf8b 10376@node H8/300
104c1213
JM
10377@subsection Hitachi H8/300
10378
10379@table @code
10380
d4f3574e 10381@kindex target hms@r{, with H8/300}
104c1213
JM
10382@item target hms @var{dev}
10383A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10384Use special commands @code{device} and @code{speed} to control the serial
10385line and the communications speed used.
10386
d4f3574e 10387@kindex target e7000@r{, with H8/300}
104c1213
JM
10388@item target e7000 @var{dev}
10389E7000 emulator for Hitachi H8 and SH.
10390
d4f3574e
SS
10391@kindex target sh3@r{, with H8/300}
10392@kindex target sh3e@r{, with H8/300}
104c1213 10393@item target sh3 @var{dev}
96a2c332 10394@itemx target sh3e @var{dev}
104c1213
JM
10395Hitachi SH-3 and SH-3E target systems.
10396
10397@end table
10398
10399@cindex download to H8/300 or H8/500
10400@cindex H8/300 or H8/500 download
10401@cindex download to Hitachi SH
10402@cindex Hitachi SH download
10403When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10404board, the @code{load} command downloads your program to the Hitachi
10405board and also opens it as the current executable target for
10406@value{GDBN} on your host (like the @code{file} command).
10407
10408@value{GDBN} needs to know these things to talk to your
5d161b24 10409Hitachi SH, H8/300, or H8/500:
104c1213
JM
10410
10411@enumerate
10412@item
10413that you want to use @samp{target hms}, the remote debugging interface
10414for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10415emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 10416the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
10417H8/300, or H8/500.)
10418
10419@item
10420what serial device connects your host to your Hitachi board (the first
10421serial device available on your host is the default).
10422
10423@item
10424what speed to use over the serial device.
10425@end enumerate
10426
10427@menu
10428* Hitachi Boards:: Connecting to Hitachi boards.
10429* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10430* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10431@end menu
10432
6d2ebf8b 10433@node Hitachi Boards
104c1213
JM
10434@subsubsection Connecting to Hitachi boards
10435
10436@c only for Unix hosts
10437@kindex device
10438@cindex serial device, Hitachi micros
96a2c332 10439Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
10440need to explicitly set the serial device. The default @var{port} is the
10441first available port on your host. This is only necessary on Unix
10442hosts, where it is typically something like @file{/dev/ttya}.
10443
10444@kindex speed
10445@cindex serial line speed, Hitachi micros
96a2c332 10446@code{@value{GDBN}} has another special command to set the communications
104c1213 10447speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 10448hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
10449the DOS @code{mode} command (for instance,
10450@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
10451
10452The @samp{device} and @samp{speed} commands are available only when you
10453use a Unix host to debug your Hitachi microprocessor programs. If you
10454use a DOS host,
10455@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10456called @code{asynctsr} to communicate with the development board
10457through a PC serial port. You must also use the DOS @code{mode} command
10458to set up the serial port on the DOS side.
10459
10460The following sample session illustrates the steps needed to start a
10461program under @value{GDBN} control on an H8/300. The example uses a
10462sample H8/300 program called @file{t.x}. The procedure is the same for
10463the Hitachi SH and the H8/500.
10464
10465First hook up your development board. In this example, we use a
10466board attached to serial port @code{COM2}; if you use a different serial
10467port, substitute its name in the argument of the @code{mode} command.
10468When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 10469debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
10470for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10471@code{COM2}.
10472
10473@example
10474C:\H8300\TEST> asynctsr 2
10475C:\H8300\TEST> mode com2:9600,n,8,1,p
10476
10477Resident portion of MODE loaded
10478
10479COM2: 9600, n, 8, 1, p
10480
10481@end example
10482
10483@quotation
10484@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10485@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10486disable it, or even boot without it, to use @code{asynctsr} to control
10487your development board.
10488@end quotation
10489
d4f3574e 10490@kindex target hms@r{, and serial protocol}
104c1213
JM
10491Now that serial communications are set up, and the development board is
10492connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 10493the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
10494you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10495commands to begin your debugging session: @samp{target hms} to specify
10496cross-debugging to the Hitachi board, and the @code{load} command to
10497download your program to the board. @code{load} displays the names of
10498the program's sections, and a @samp{*} for each 2K of data downloaded.
10499(If you want to refresh @value{GDBN} data on symbols or on the
10500executable file without downloading, use the @value{GDBN} commands
10501@code{file} or @code{symbol-file}. These commands, and @code{load}
10502itself, are described in @ref{Files,,Commands to specify files}.)
10503
10504@smallexample
10505(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 10506@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 10507 of it under certain conditions; type "show copying" to see
104c1213 10508 the conditions.
5d161b24 10509There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 10510for details.
2df3850c
JM
10511@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10512(@value{GDBP}) target hms
104c1213 10513Connected to remote H8/300 HMS system.
2df3850c 10514(@value{GDBP}) load t.x
104c1213
JM
10515.text : 0x8000 .. 0xabde ***********
10516.data : 0xabde .. 0xad30 *
10517.stack : 0xf000 .. 0xf014 *
10518@end smallexample
10519
10520At this point, you're ready to run or debug your program. From here on,
10521you can use all the usual @value{GDBN} commands. The @code{break} command
10522sets breakpoints; the @code{run} command starts your program;
10523@code{print} or @code{x} display data; the @code{continue} command
10524resumes execution after stopping at a breakpoint. You can use the
10525@code{help} command at any time to find out more about @value{GDBN} commands.
10526
10527Remember, however, that @emph{operating system} facilities aren't
10528available on your development board; for example, if your program hangs,
10529you can't send an interrupt---but you can press the @sc{reset} switch!
10530
10531Use the @sc{reset} button on the development board
10532@itemize @bullet
10533@item
10534to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10535no way to pass an interrupt signal to the development board); and
10536
10537@item
10538to return to the @value{GDBN} command prompt after your program finishes
10539normally. The communications protocol provides no other way for @value{GDBN}
10540to detect program completion.
10541@end itemize
10542
10543In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10544development board as a ``normal exit'' of your program.
10545
6d2ebf8b 10546@node Hitachi ICE
104c1213
JM
10547@subsubsection Using the E7000 in-circuit emulator
10548
d4f3574e 10549@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
10550You can use the E7000 in-circuit emulator to develop code for either the
10551Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10552e7000} command to connect @value{GDBN} to your E7000:
10553
10554@table @code
10555@item target e7000 @var{port} @var{speed}
10556Use this form if your E7000 is connected to a serial port. The
10557@var{port} argument identifies what serial port to use (for example,
10558@samp{com2}). The third argument is the line speed in bits per second
10559(for example, @samp{9600}).
10560
10561@item target e7000 @var{hostname}
10562If your E7000 is installed as a host on a TCP/IP network, you can just
10563specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10564@end table
10565
6d2ebf8b 10566@node Hitachi Special
104c1213
JM
10567@subsubsection Special @value{GDBN} commands for Hitachi micros
10568
10569Some @value{GDBN} commands are available only for the H8/300:
10570
10571@table @code
10572
10573@kindex set machine
10574@kindex show machine
10575@item set machine h8300
10576@itemx set machine h8300h
10577Condition @value{GDBN} for one of the two variants of the H8/300
10578architecture with @samp{set machine}. You can use @samp{show machine}
10579to check which variant is currently in effect.
10580
10581@end table
10582
6d2ebf8b 10583@node H8/500
104c1213
JM
10584@subsection H8/500
10585
10586@table @code
10587
10588@kindex set memory @var{mod}
10589@cindex memory models, H8/500
10590@item set memory @var{mod}
10591@itemx show memory
10592Specify which H8/500 memory model (@var{mod}) you are using with
10593@samp{set memory}; check which memory model is in effect with @samp{show
10594memory}. The accepted values for @var{mod} are @code{small},
10595@code{big}, @code{medium}, and @code{compact}.
10596
10597@end table
10598
6d2ebf8b 10599@node i960
104c1213
JM
10600@subsection Intel i960
10601
10602@table @code
10603
10604@kindex target mon960
10605@item target mon960 @var{dev}
10606MON960 monitor for Intel i960.
10607
f0ca3dce 10608@kindex target nindy
104c1213
JM
10609@item target nindy @var{devicename}
10610An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10611the name of the serial device to use for the connection, e.g.
10612@file{/dev/ttya}.
10613
10614@end table
10615
10616@cindex Nindy
10617@cindex i960
10618@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10619@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10620tell @value{GDBN} how to connect to the 960 in several ways:
10621
10622@itemize @bullet
10623@item
10624Through command line options specifying serial port, version of the
10625Nindy protocol, and communications speed;
10626
10627@item
10628By responding to a prompt on startup;
10629
10630@item
10631By using the @code{target} command at any point during your @value{GDBN}
10632session. @xref{Target Commands, ,Commands for managing targets}.
10633
104c1213
JM
10634@end itemize
10635
10636@cindex download to Nindy-960
10637With the Nindy interface to an Intel 960 board, @code{load}
10638downloads @var{filename} to the 960 as well as adding its symbols in
10639@value{GDBN}.
10640
10641@menu
10642* Nindy Startup:: Startup with Nindy
10643* Nindy Options:: Options for Nindy
10644* Nindy Reset:: Nindy reset command
10645@end menu
10646
6d2ebf8b 10647@node Nindy Startup
104c1213
JM
10648@subsubsection Startup with Nindy
10649
10650If you simply start @code{@value{GDBP}} without using any command-line
10651options, you are prompted for what serial port to use, @emph{before} you
10652reach the ordinary @value{GDBN} prompt:
10653
10654@example
5d161b24 10655Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
10656@end example
10657
10658@noindent
10659Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10660identifies the serial port you want to use. You can, if you choose,
10661simply start up with no Nindy connection by responding to the prompt
10662with an empty line. If you do this and later wish to attach to Nindy,
10663use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10664
6d2ebf8b 10665@node Nindy Options
104c1213
JM
10666@subsubsection Options for Nindy
10667
10668These are the startup options for beginning your @value{GDBN} session with a
10669Nindy-960 board attached:
10670
10671@table @code
10672@item -r @var{port}
10673Specify the serial port name of a serial interface to be used to connect
10674to the target system. This option is only available when @value{GDBN} is
10675configured for the Intel 960 target architecture. You may specify
10676@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10677device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10678suffix for a specific @code{tty} (e.g. @samp{-r a}).
10679
10680@item -O
10681(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10682the ``old'' Nindy monitor protocol to connect to the target system.
10683This option is only available when @value{GDBN} is configured for the Intel 960
10684target architecture.
10685
10686@quotation
10687@emph{Warning:} if you specify @samp{-O}, but are actually trying to
10688connect to a target system that expects the newer protocol, the connection
10689fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10690attempts to reconnect at several different line speeds. You can abort
10691this process with an interrupt.
10692@end quotation
10693
10694@item -brk
10695Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10696system, in an attempt to reset it, before connecting to a Nindy target.
10697
10698@quotation
10699@emph{Warning:} Many target systems do not have the hardware that this
10700requires; it only works with a few boards.
10701@end quotation
10702@end table
10703
10704The standard @samp{-b} option controls the line speed used on the serial
10705port.
10706
10707@c @group
6d2ebf8b 10708@node Nindy Reset
104c1213
JM
10709@subsubsection Nindy reset command
10710
10711@table @code
10712@item reset
10713@kindex reset
10714For a Nindy target, this command sends a ``break'' to the remote target
10715system; this is only useful if the target has been equipped with a
10716circuit to perform a hard reset (or some other interesting action) when
10717a break is detected.
10718@end table
10719@c @end group
10720
6d2ebf8b 10721@node M32R/D
104c1213
JM
10722@subsection Mitsubishi M32R/D
10723
10724@table @code
10725
10726@kindex target m32r
10727@item target m32r @var{dev}
10728Mitsubishi M32R/D ROM monitor.
10729
10730@end table
10731
6d2ebf8b 10732@node M68K
104c1213
JM
10733@subsection M68k
10734
10735The Motorola m68k configuration includes ColdFire support, and
10736target command for the following ROM monitors.
10737
10738@table @code
10739
10740@kindex target abug
10741@item target abug @var{dev}
10742ABug ROM monitor for M68K.
10743
10744@kindex target cpu32bug
10745@item target cpu32bug @var{dev}
10746CPU32BUG monitor, running on a CPU32 (M68K) board.
10747
10748@kindex target dbug
10749@item target dbug @var{dev}
10750dBUG ROM monitor for Motorola ColdFire.
10751
10752@kindex target est
10753@item target est @var{dev}
10754EST-300 ICE monitor, running on a CPU32 (M68K) board.
10755
10756@kindex target rom68k
10757@item target rom68k @var{dev}
10758ROM 68K monitor, running on an M68K IDP board.
10759
10760@end table
10761
10762If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10763instead have only a single special target command:
10764
10765@table @code
10766
10767@kindex target es1800
10768@item target es1800 @var{dev}
10769ES-1800 emulator for M68K.
10770
10771@end table
10772
10773[context?]
10774
10775@table @code
10776
10777@kindex target rombug
10778@item target rombug @var{dev}
10779ROMBUG ROM monitor for OS/9000.
10780
10781@end table
10782
6d2ebf8b 10783@node M88K
104c1213
JM
10784@subsection M88K
10785
10786@table @code
10787
10788@kindex target bug
10789@item target bug @var{dev}
10790BUG monitor, running on a MVME187 (m88k) board.
10791
10792@end table
10793
6d2ebf8b 10794@node MIPS Embedded
104c1213
JM
10795@subsection MIPS Embedded
10796
10797@cindex MIPS boards
10798@value{GDBN} can use the MIPS remote debugging protocol to talk to a
10799MIPS board attached to a serial line. This is available when
10800you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10801
10802@need 1000
10803Use these @value{GDBN} commands to specify the connection to your target board:
10804
10805@table @code
10806@item target mips @var{port}
10807@kindex target mips @var{port}
10808To run a program on the board, start up @code{@value{GDBP}} with the
10809name of your program as the argument. To connect to the board, use the
10810command @samp{target mips @var{port}}, where @var{port} is the name of
10811the serial port connected to the board. If the program has not already
10812been downloaded to the board, you may use the @code{load} command to
10813download it. You can then use all the usual @value{GDBN} commands.
10814
10815For example, this sequence connects to the target board through a serial
10816port, and loads and runs a program called @var{prog} through the
10817debugger:
10818
10819@example
10820host$ @value{GDBP} @var{prog}
2df3850c
JM
10821@value{GDBN} is free software and @dots{}
10822(@value{GDBP}) target mips /dev/ttyb
10823(@value{GDBP}) load @var{prog}
10824(@value{GDBP}) run
104c1213
JM
10825@end example
10826
10827@item target mips @var{hostname}:@var{portnumber}
10828On some @value{GDBN} host configurations, you can specify a TCP
10829connection (for instance, to a serial line managed by a terminal
10830concentrator) instead of a serial port, using the syntax
10831@samp{@var{hostname}:@var{portnumber}}.
10832
10833@item target pmon @var{port}
10834@kindex target pmon @var{port}
10835PMON ROM monitor.
10836
10837@item target ddb @var{port}
10838@kindex target ddb @var{port}
10839NEC's DDB variant of PMON for Vr4300.
10840
10841@item target lsi @var{port}
10842@kindex target lsi @var{port}
10843LSI variant of PMON.
10844
10845@kindex target r3900
10846@item target r3900 @var{dev}
10847Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10848
10849@kindex target array
10850@item target array @var{dev}
10851Array Tech LSI33K RAID controller board.
10852
10853@end table
10854
10855
10856@noindent
10857@value{GDBN} also supports these special commands for MIPS targets:
10858
10859@table @code
10860@item set processor @var{args}
10861@itemx show processor
10862@kindex set processor @var{args}
10863@kindex show processor
10864Use the @code{set processor} command to set the type of MIPS
10865processor when you want to access processor-type-specific registers.
5d161b24 10866For example, @code{set processor @var{r3041}} tells @value{GDBN}
104c1213 10867to use the CPO registers appropriate for the 3041 chip.
5d161b24 10868Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 10869is using. Use the @code{info reg} command to see what registers
5d161b24 10870@value{GDBN} is using.
104c1213
JM
10871
10872@item set mipsfpu double
10873@itemx set mipsfpu single
10874@itemx set mipsfpu none
10875@itemx show mipsfpu
10876@kindex set mipsfpu
10877@kindex show mipsfpu
10878@cindex MIPS remote floating point
10879@cindex floating point, MIPS remote
10880If your target board does not support the MIPS floating point
10881coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 10882need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
10883file). This tells @value{GDBN} how to find the return value of
10884functions which return floating point values. It also allows
10885@value{GDBN} to avoid saving the floating point registers when calling
10886functions on the board. If you are using a floating point coprocessor
10887with only single precision floating point support, as on the @sc{r4650}
10888processor, use the command @samp{set mipsfpu single}. The default
10889double precision floating point coprocessor may be selected using
10890@samp{set mipsfpu double}.
10891
10892In previous versions the only choices were double precision or no
10893floating point, so @samp{set mipsfpu on} will select double precision
10894and @samp{set mipsfpu off} will select no floating point.
10895
10896As usual, you can inquire about the @code{mipsfpu} variable with
10897@samp{show mipsfpu}.
10898
10899@item set remotedebug @var{n}
10900@itemx show remotedebug
d4f3574e
SS
10901@kindex set remotedebug@r{, MIPS protocol}
10902@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
10903@cindex @code{remotedebug}, MIPS protocol
10904@cindex MIPS @code{remotedebug} protocol
10905@c FIXME! For this to be useful, you must know something about the MIPS
10906@c FIXME...protocol. Where is it described?
10907You can see some debugging information about communications with the board
10908by setting the @code{remotedebug} variable. If you set it to @code{1} using
10909@samp{set remotedebug 1}, every packet is displayed. If you set it
10910to @code{2}, every character is displayed. You can check the current value
10911at any time with the command @samp{show remotedebug}.
10912
10913@item set timeout @var{seconds}
10914@itemx set retransmit-timeout @var{seconds}
10915@itemx show timeout
10916@itemx show retransmit-timeout
10917@cindex @code{timeout}, MIPS protocol
10918@cindex @code{retransmit-timeout}, MIPS protocol
10919@kindex set timeout
10920@kindex show timeout
10921@kindex set retransmit-timeout
10922@kindex show retransmit-timeout
10923You can control the timeout used while waiting for a packet, in the MIPS
10924remote protocol, with the @code{set timeout @var{seconds}} command. The
10925default is 5 seconds. Similarly, you can control the timeout used while
10926waiting for an acknowledgement of a packet with the @code{set
10927retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10928You can inspect both values with @code{show timeout} and @code{show
10929retransmit-timeout}. (These commands are @emph{only} available when
10930@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10931
10932The timeout set by @code{set timeout} does not apply when @value{GDBN}
10933is waiting for your program to stop. In that case, @value{GDBN} waits
10934forever because it has no way of knowing how long the program is going
10935to run before stopping.
10936@end table
10937
6d2ebf8b 10938@node PowerPC
104c1213
JM
10939@subsection PowerPC
10940
10941@table @code
10942
10943@kindex target dink32
10944@item target dink32 @var{dev}
10945DINK32 ROM monitor.
10946
10947@kindex target ppcbug
10948@item target ppcbug @var{dev}
10949@kindex target ppcbug1
10950@item target ppcbug1 @var{dev}
10951PPCBUG ROM monitor for PowerPC.
10952
10953@kindex target sds
10954@item target sds @var{dev}
10955SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10956
10957@end table
10958
6d2ebf8b 10959@node PA
104c1213
JM
10960@subsection HP PA Embedded
10961
10962@table @code
10963
10964@kindex target op50n
10965@item target op50n @var{dev}
10966OP50N monitor, running on an OKI HPPA board.
10967
10968@kindex target w89k
10969@item target w89k @var{dev}
10970W89K monitor, running on a Winbond HPPA board.
10971
10972@end table
10973
6d2ebf8b 10974@node SH
104c1213
JM
10975@subsection Hitachi SH
10976
10977@table @code
10978
d4f3574e 10979@kindex target hms@r{, with Hitachi SH}
104c1213
JM
10980@item target hms @var{dev}
10981A Hitachi SH board attached via serial line to your host. Use special
10982commands @code{device} and @code{speed} to control the serial line and
10983the communications speed used.
10984
d4f3574e 10985@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
10986@item target e7000 @var{dev}
10987E7000 emulator for Hitachi SH.
10988
d4f3574e
SS
10989@kindex target sh3@r{, with SH}
10990@kindex target sh3e@r{, with SH}
104c1213
JM
10991@item target sh3 @var{dev}
10992@item target sh3e @var{dev}
10993Hitachi SH-3 and SH-3E target systems.
10994
10995@end table
10996
6d2ebf8b 10997@node Sparclet
104c1213
JM
10998@subsection Tsqware Sparclet
10999
11000@cindex Sparclet
11001
5d161b24
DB
11002@value{GDBN} enables developers to debug tasks running on
11003Sparclet targets from a Unix host.
104c1213
JM
11004@value{GDBN} uses code that runs on
11005both the Unix host and on the Sparclet target. The program
5d161b24 11006@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
11007
11008@table @code
f0ca3dce 11009@item remotetimeout @var{args}
104c1213 11010@kindex remotetimeout
5d161b24
DB
11011@value{GDBN} supports the option @code{remotetimeout}.
11012This option is set by the user, and @var{args} represents the number of
11013seconds @value{GDBN} waits for responses.
104c1213
JM
11014@end table
11015
41afff9a 11016@cindex compiling, on Sparclet
5d161b24 11017When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 11018information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 11019load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 11020@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
11021
11022@example
11023sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11024@end example
11025
d4f3574e 11026You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
11027
11028@example
11029sparclet-aout-objdump --headers --syms prog
11030@end example
11031
41afff9a 11032@cindex running, on Sparclet
104c1213
JM
11033Once you have set
11034your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 11035run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
11036(or @code{sparclet-aout-gdb}, depending on your installation).
11037
11038@value{GDBN} comes up showing the prompt:
11039
11040@example
11041(gdbslet)
11042@end example
11043
11044@menu
11045* Sparclet File:: Setting the file to debug
11046* Sparclet Connection:: Connecting to Sparclet
11047* Sparclet Download:: Sparclet download
5d161b24 11048* Sparclet Execution:: Running and debugging
104c1213
JM
11049@end menu
11050
6d2ebf8b 11051@node Sparclet File
104c1213
JM
11052@subsubsection Setting file to debug
11053
11054The @value{GDBN} command @code{file} lets you choose with program to debug.
11055
11056@example
11057(gdbslet) file prog
11058@end example
11059
11060@need 1000
11061@value{GDBN} then attempts to read the symbol table of @file{prog}.
11062@value{GDBN} locates
11063the file by searching the directories listed in the command search
11064path.
11065If the file was compiled with debug information (option "-g"), source
11066files will be searched as well.
11067@value{GDBN} locates
11068the source files by searching the directories listed in the directory search
11069path (@pxref{Environment, ,Your program's environment}).
11070If it fails
11071to find a file, it displays a message such as:
11072
11073@example
11074prog: No such file or directory.
11075@end example
11076
11077When this happens, add the appropriate directories to the search paths with
5d161b24 11078the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
11079@code{target} command again.
11080
6d2ebf8b 11081@node Sparclet Connection
104c1213
JM
11082@subsubsection Connecting to Sparclet
11083
11084The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11085To connect to a target on serial port ``@code{ttya}'', type:
11086
11087@example
11088(gdbslet) target sparclet /dev/ttya
11089Remote target sparclet connected to /dev/ttya
5d161b24 11090main () at ../prog.c:3
104c1213
JM
11091@end example
11092
11093@need 750
11094@value{GDBN} displays messages like these:
11095
d4f3574e 11096@example
104c1213 11097Connected to ttya.
d4f3574e 11098@end example
104c1213 11099
6d2ebf8b 11100@node Sparclet Download
104c1213
JM
11101@subsubsection Sparclet download
11102
11103@cindex download to Sparclet
5d161b24 11104Once connected to the Sparclet target,
104c1213
JM
11105you can use the @value{GDBN}
11106@code{load} command to download the file from the host to the target.
11107The file name and load offset should be given as arguments to the @code{load}
11108command.
5d161b24 11109Since the file format is aout, the program must be loaded to the starting
d4f3574e 11110address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
11111offset is an offset which is added to the VMA (virtual memory address)
11112of each of the file's sections.
11113For instance, if the program
11114@file{prog} was linked to text address 0x1201000, with data at 0x12010160
11115and bss at 0x12010170, in @value{GDBN}, type:
11116
11117@example
11118(gdbslet) load prog 0x12010000
11119Loading section .text, size 0xdb0 vma 0x12010000
11120@end example
11121
5d161b24
DB
11122If the code is loaded at a different address then what the program was linked
11123to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
11124to tell @value{GDBN} where to map the symbol table.
11125
6d2ebf8b 11126@node Sparclet Execution
104c1213
JM
11127@subsubsection Running and debugging
11128
11129@cindex running and debugging Sparclet programs
11130You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 11131commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
11132manual for the list of commands.
11133
11134@example
11135(gdbslet) b main
11136Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 11137(gdbslet) run
104c1213
JM
11138Starting program: prog
11139Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
111403 char *symarg = 0;
11141(gdbslet) step
111424 char *execarg = "hello!";
5d161b24 11143(gdbslet)
104c1213
JM
11144@end example
11145
6d2ebf8b 11146@node Sparclite
104c1213
JM
11147@subsection Fujitsu Sparclite
11148
11149@table @code
11150
11151@kindex target sparclite
11152@item target sparclite @var{dev}
5d161b24
DB
11153Fujitsu sparclite boards, used only for the purpose of loading.
11154You must use an additional command to debug the program.
11155For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
11156remote protocol.
11157
11158@end table
11159
6d2ebf8b 11160@node ST2000
104c1213
JM
11161@subsection Tandem ST2000
11162
2df3850c 11163@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
11164STDBUG protocol.
11165
11166To connect your ST2000 to the host system, see the manufacturer's
11167manual. Once the ST2000 is physically attached, you can run:
11168
11169@example
11170target st2000 @var{dev} @var{speed}
11171@end example
11172
11173@noindent
11174to establish it as your debugging environment. @var{dev} is normally
11175the name of a serial device, such as @file{/dev/ttya}, connected to the
11176ST2000 via a serial line. You can instead specify @var{dev} as a TCP
11177connection (for example, to a serial line attached via a terminal
11178concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
11179
11180The @code{load} and @code{attach} commands are @emph{not} defined for
11181this target; you must load your program into the ST2000 as you normally
11182would for standalone operation. @value{GDBN} reads debugging information
11183(such as symbols) from a separate, debugging version of the program
11184available on your host computer.
11185@c FIXME!! This is terribly vague; what little content is here is
11186@c basically hearsay.
11187
11188@cindex ST2000 auxiliary commands
11189These auxiliary @value{GDBN} commands are available to help you with the ST2000
11190environment:
11191
11192@table @code
11193@item st2000 @var{command}
11194@kindex st2000 @var{cmd}
11195@cindex STDBUG commands (ST2000)
11196@cindex commands to STDBUG (ST2000)
11197Send a @var{command} to the STDBUG monitor. See the manufacturer's
11198manual for available commands.
11199
11200@item connect
11201@cindex connect (to STDBUG)
11202Connect the controlling terminal to the STDBUG command monitor. When
11203you are done interacting with STDBUG, typing either of two character
11204sequences gets you back to the @value{GDBN} command prompt:
11205@kbd{@key{RET}~.} (Return, followed by tilde and period) or
11206@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
11207@end table
11208
6d2ebf8b 11209@node Z8000
104c1213
JM
11210@subsection Zilog Z8000
11211
11212@cindex Z8000
11213@cindex simulator, Z8000
11214@cindex Zilog Z8000 simulator
11215
11216When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
11217a Z8000 simulator.
11218
11219For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
11220unsegmented variant of the Z8000 architecture) or the Z8001 (the
11221segmented variant). The simulator recognizes which architecture is
11222appropriate by inspecting the object code.
11223
11224@table @code
11225@item target sim @var{args}
11226@kindex sim
d4f3574e 11227@kindex target sim@r{, with Z8000}
104c1213
JM
11228Debug programs on a simulated CPU. If the simulator supports setup
11229options, specify them via @var{args}.
11230@end table
11231
11232@noindent
11233After specifying this target, you can debug programs for the simulated
11234CPU in the same style as programs for your host computer; use the
11235@code{file} command to load a new program image, the @code{run} command
11236to run your program, and so on.
11237
d4f3574e
SS
11238As well as making available all the usual machine registers
11239(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
11240additional items of information as specially named registers:
104c1213
JM
11241
11242@table @code
11243
11244@item cycles
11245Counts clock-ticks in the simulator.
11246
11247@item insts
11248Counts instructions run in the simulator.
11249
11250@item time
11251Execution time in 60ths of a second.
11252
11253@end table
11254
11255You can refer to these values in @value{GDBN} expressions with the usual
11256conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
11257conditional breakpoint that suspends only after at least 5000
11258simulated clock ticks.
11259
6d2ebf8b 11260@node Architectures
104c1213
JM
11261@section Architectures
11262
11263This section describes characteristics of architectures that affect
2df3850c 11264all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
11265
11266@menu
11267* A29K::
11268* Alpha::
11269* MIPS::
11270@end menu
11271
6d2ebf8b 11272@node A29K
104c1213
JM
11273@subsection A29K
11274
11275@table @code
11276
11277@kindex set rstack_high_address
11278@cindex AMD 29K register stack
11279@cindex register stack, AMD29K
11280@item set rstack_high_address @var{address}
11281On AMD 29000 family processors, registers are saved in a separate
d4f3574e 11282@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
11283extent of this stack. Normally, @value{GDBN} just assumes that the
11284stack is ``large enough''. This may result in @value{GDBN} referencing
11285memory locations that do not exist. If necessary, you can get around
11286this problem by specifying the ending address of the register stack with
11287the @code{set rstack_high_address} command. The argument should be an
11288address, which you probably want to precede with @samp{0x} to specify in
11289hexadecimal.
11290
11291@kindex show rstack_high_address
11292@item show rstack_high_address
11293Display the current limit of the register stack, on AMD 29000 family
11294processors.
11295
11296@end table
11297
6d2ebf8b 11298@node Alpha
104c1213
JM
11299@subsection Alpha
11300
11301See the following section.
11302
6d2ebf8b 11303@node MIPS
104c1213
JM
11304@subsection MIPS
11305
11306@cindex stack on Alpha
11307@cindex stack on MIPS
11308@cindex Alpha stack
11309@cindex MIPS stack
11310Alpha- and MIPS-based computers use an unusual stack frame, which
11311sometimes requires @value{GDBN} to search backward in the object code to
11312find the beginning of a function.
11313
11314@cindex response time, MIPS debugging
11315To improve response time (especially for embedded applications, where
11316@value{GDBN} may be restricted to a slow serial line for this search)
11317you may want to limit the size of this search, using one of these
11318commands:
11319
11320@table @code
00e4a2e4 11321@cindex @code{heuristic-fence-post} (Alpha, MIPS)
104c1213
JM
11322@item set heuristic-fence-post @var{limit}
11323Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11324search for the beginning of a function. A value of @var{0} (the
11325default) means there is no limit. However, except for @var{0}, the
11326larger the limit the more bytes @code{heuristic-fence-post} must search
11327and therefore the longer it takes to run.
11328
11329@item show heuristic-fence-post
11330Display the current limit.
11331@end table
11332
11333@noindent
11334These commands are available @emph{only} when @value{GDBN} is configured
11335for debugging programs on Alpha or MIPS processors.
11336
11337
6d2ebf8b 11338@node Controlling GDB
c906108c
SS
11339@chapter Controlling @value{GDBN}
11340
53a5351d
JM
11341You can alter the way @value{GDBN} interacts with you by using the
11342@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 11343data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 11344described here.
c906108c
SS
11345
11346@menu
11347* Prompt:: Prompt
11348* Editing:: Command editing
11349* History:: Command history
11350* Screen Size:: Screen size
11351* Numbers:: Numbers
11352* Messages/Warnings:: Optional warnings and messages
5d161b24 11353* Debugging Output:: Optional messages about internal happenings
c906108c
SS
11354@end menu
11355
6d2ebf8b 11356@node Prompt
c906108c
SS
11357@section Prompt
11358
11359@cindex prompt
11360
11361@value{GDBN} indicates its readiness to read a command by printing a string
11362called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11363can change the prompt string with the @code{set prompt} command. For
11364instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 11365the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
11366which one you are talking to.
11367
d4f3574e 11368@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
11369prompt you set. This allows you to set a prompt which ends in a space
11370or a prompt that does not.
11371
11372@table @code
11373@kindex set prompt
11374@item set prompt @var{newprompt}
11375Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11376
11377@kindex show prompt
11378@item show prompt
11379Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11380@end table
11381
6d2ebf8b 11382@node Editing
c906108c
SS
11383@section Command editing
11384@cindex readline
11385@cindex command line editing
11386
11387@value{GDBN} reads its input commands via the @dfn{readline} interface. This
11388@sc{gnu} library provides consistent behavior for programs which provide a
11389command line interface to the user. Advantages are @sc{gnu} Emacs-style
11390or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11391substitution, and a storage and recall of command history across
11392debugging sessions.
11393
11394You may control the behavior of command line editing in @value{GDBN} with the
11395command @code{set}.
11396
11397@table @code
11398@kindex set editing
11399@cindex editing
11400@item set editing
11401@itemx set editing on
11402Enable command line editing (enabled by default).
11403
11404@item set editing off
11405Disable command line editing.
11406
11407@kindex show editing
11408@item show editing
11409Show whether command line editing is enabled.
11410@end table
11411
6d2ebf8b 11412@node History
c906108c
SS
11413@section Command history
11414
11415@value{GDBN} can keep track of the commands you type during your
11416debugging sessions, so that you can be certain of precisely what
11417happened. Use these commands to manage the @value{GDBN} command
11418history facility.
11419
11420@table @code
11421@cindex history substitution
11422@cindex history file
11423@kindex set history filename
11424@kindex GDBHISTFILE
11425@item set history filename @var{fname}
11426Set the name of the @value{GDBN} command history file to @var{fname}.
11427This is the file where @value{GDBN} reads an initial command history
11428list, and where it writes the command history from this session when it
11429exits. You can access this list through history expansion or through
11430the history command editing characters listed below. This file defaults
11431to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
11432@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11433is not set.
c906108c
SS
11434
11435@cindex history save
11436@kindex set history save
11437@item set history save
11438@itemx set history save on
11439Record command history in a file, whose name may be specified with the
11440@code{set history filename} command. By default, this option is disabled.
11441
11442@item set history save off
11443Stop recording command history in a file.
11444
11445@cindex history size
11446@kindex set history size
11447@item set history size @var{size}
11448Set the number of commands which @value{GDBN} keeps in its history list.
11449This defaults to the value of the environment variable
11450@code{HISTSIZE}, or to 256 if this variable is not set.
11451@end table
11452
11453@cindex history expansion
11454History expansion assigns special meaning to the character @kbd{!}.
11455@ifset have-readline-appendices
11456@xref{Event Designators}.
11457@end ifset
11458
11459Since @kbd{!} is also the logical not operator in C, history expansion
11460is off by default. If you decide to enable history expansion with the
11461@code{set history expansion on} command, you may sometimes need to
11462follow @kbd{!} (when it is used as logical not, in an expression) with
11463a space or a tab to prevent it from being expanded. The readline
11464history facilities do not attempt substitution on the strings
11465@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11466
11467The commands to control history expansion are:
11468
11469@table @code
11470@kindex set history expansion
11471@item set history expansion on
11472@itemx set history expansion
11473Enable history expansion. History expansion is off by default.
11474
11475@item set history expansion off
11476Disable history expansion.
11477
11478The readline code comes with more complete documentation of
11479editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11480or @code{vi} may wish to read it.
11481@ifset have-readline-appendices
11482@xref{Command Line Editing}.
11483@end ifset
11484
11485@c @group
11486@kindex show history
11487@item show history
11488@itemx show history filename
11489@itemx show history save
11490@itemx show history size
11491@itemx show history expansion
11492These commands display the state of the @value{GDBN} history parameters.
11493@code{show history} by itself displays all four states.
11494@c @end group
11495@end table
11496
11497@table @code
41afff9a 11498@kindex shows
c906108c
SS
11499@item show commands
11500Display the last ten commands in the command history.
11501
11502@item show commands @var{n}
11503Print ten commands centered on command number @var{n}.
11504
11505@item show commands +
11506Print ten commands just after the commands last printed.
11507@end table
11508
6d2ebf8b 11509@node Screen Size
c906108c
SS
11510@section Screen size
11511@cindex size of screen
11512@cindex pauses in output
11513
11514Certain commands to @value{GDBN} may produce large amounts of
11515information output to the screen. To help you read all of it,
11516@value{GDBN} pauses and asks you for input at the end of each page of
11517output. Type @key{RET} when you want to continue the output, or @kbd{q}
11518to discard the remaining output. Also, the screen width setting
11519determines when to wrap lines of output. Depending on what is being
11520printed, @value{GDBN} tries to break the line at a readable place,
11521rather than simply letting it overflow onto the following line.
11522
d4f3574e
SS
11523Normally @value{GDBN} knows the size of the screen from the terminal
11524driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 11525together with the value of the @code{TERM} environment variable and the
d4f3574e 11526@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
11527you can override it with the @code{set height} and @code{set
11528width} commands:
11529
11530@table @code
11531@kindex set height
11532@kindex set width
11533@kindex show width
11534@kindex show height
11535@item set height @var{lpp}
11536@itemx show height
11537@itemx set width @var{cpl}
11538@itemx show width
11539These @code{set} commands specify a screen height of @var{lpp} lines and
11540a screen width of @var{cpl} characters. The associated @code{show}
11541commands display the current settings.
11542
5d161b24
DB
11543If you specify a height of zero lines, @value{GDBN} does not pause during
11544output no matter how long the output is. This is useful if output is to a
c906108c
SS
11545file or to an editor buffer.
11546
11547Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11548from wrapping its output.
11549@end table
11550
6d2ebf8b 11551@node Numbers
c906108c
SS
11552@section Numbers
11553@cindex number representation
11554@cindex entering numbers
11555
2df3850c
JM
11556You can always enter numbers in octal, decimal, or hexadecimal in
11557@value{GDBN} by the usual conventions: octal numbers begin with
11558@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11559begin with @samp{0x}. Numbers that begin with none of these are, by
11560default, entered in base 10; likewise, the default display for
11561numbers---when no particular format is specified---is base 10. You can
11562change the default base for both input and output with the @code{set
11563radix} command.
c906108c
SS
11564
11565@table @code
11566@kindex set input-radix
11567@item set input-radix @var{base}
11568Set the default base for numeric input. Supported choices
11569for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11570specified either unambiguously or using the current default radix; for
11571example, any of
11572
11573@smallexample
11574set radix 012
11575set radix 10.
11576set radix 0xa
11577@end smallexample
11578
11579@noindent
11580sets the base to decimal. On the other hand, @samp{set radix 10}
11581leaves the radix unchanged no matter what it was.
11582
11583@kindex set output-radix
11584@item set output-radix @var{base}
11585Set the default base for numeric display. Supported choices
11586for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11587specified either unambiguously or using the current default radix.
11588
11589@kindex show input-radix
11590@item show input-radix
11591Display the current default base for numeric input.
11592
11593@kindex show output-radix
11594@item show output-radix
11595Display the current default base for numeric display.
11596@end table
11597
6d2ebf8b 11598@node Messages/Warnings
c906108c
SS
11599@section Optional warnings and messages
11600
2df3850c
JM
11601By default, @value{GDBN} is silent about its inner workings. If you are
11602running on a slow machine, you may want to use the @code{set verbose}
11603command. This makes @value{GDBN} tell you when it does a lengthy
11604internal operation, so you will not think it has crashed.
c906108c
SS
11605
11606Currently, the messages controlled by @code{set verbose} are those
11607which announce that the symbol table for a source file is being read;
11608see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11609
11610@table @code
11611@kindex set verbose
11612@item set verbose on
11613Enables @value{GDBN} output of certain informational messages.
11614
11615@item set verbose off
11616Disables @value{GDBN} output of certain informational messages.
11617
11618@kindex show verbose
11619@item show verbose
11620Displays whether @code{set verbose} is on or off.
11621@end table
11622
2df3850c
JM
11623By default, if @value{GDBN} encounters bugs in the symbol table of an
11624object file, it is silent; but if you are debugging a compiler, you may
11625find this information useful (@pxref{Symbol Errors, ,Errors reading
11626symbol files}).
c906108c
SS
11627
11628@table @code
2df3850c 11629
c906108c
SS
11630@kindex set complaints
11631@item set complaints @var{limit}
2df3850c
JM
11632Permits @value{GDBN} to output @var{limit} complaints about each type of
11633unusual symbols before becoming silent about the problem. Set
11634@var{limit} to zero to suppress all complaints; set it to a large number
11635to prevent complaints from being suppressed.
c906108c
SS
11636
11637@kindex show complaints
11638@item show complaints
11639Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 11640
c906108c
SS
11641@end table
11642
11643By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11644lot of stupid questions to confirm certain commands. For example, if
11645you try to run a program which is already running:
11646
11647@example
11648(@value{GDBP}) run
11649The program being debugged has been started already.
11650Start it from the beginning? (y or n)
11651@end example
11652
11653If you are willing to unflinchingly face the consequences of your own
11654commands, you can disable this ``feature'':
11655
11656@table @code
2df3850c 11657
c906108c
SS
11658@kindex set confirm
11659@cindex flinching
11660@cindex confirmation
11661@cindex stupid questions
11662@item set confirm off
11663Disables confirmation requests.
11664
11665@item set confirm on
11666Enables confirmation requests (the default).
11667
11668@kindex show confirm
11669@item show confirm
11670Displays state of confirmation requests.
2df3850c 11671
c906108c
SS
11672@end table
11673
6d2ebf8b 11674@node Debugging Output
5d161b24
DB
11675@section Optional messages about internal happenings
11676@table @code
11677@kindex set debug arch
11678@item set debug arch
11679Turns on or off display of gdbarch debugging info. The default is off
11680@kindex show debug arch
11681@item show debug arch
11682Displays the current state of displaying gdbarch debugging info.
11683@kindex set debug event
11684@item set debug event
11685Turns on or off display of @value{GDBN} event debugging info. The
11686default is off.
11687@kindex show debug event
11688@item show debug event
11689Displays the current state of displaying @value{GDBN} event debugging
11690info.
11691@kindex set debug expression
11692@item set debug expression
11693Turns on or off display of @value{GDBN} expression debugging info. The
11694default is off.
11695@kindex show debug expression
11696@item show debug expression
11697Displays the current state of displaying @value{GDBN} expression
11698debugging info.
11699@kindex set debug overload
11700@item set debug overload
11701Turns on or off display of @value{GDBN} C++ overload debugging
11702info. This includes info such as ranking of functions, etc. The default
11703is off.
11704@kindex show debug overload
11705@item show debug overload
11706Displays the current state of displaying @value{GDBN} C++ overload
11707debugging info.
11708@kindex set debug remote
11709@cindex packets, reporting on stdout
11710@cindex serial connections, debugging
11711@item set debug remote
11712Turns on or off display of reports on all packets sent back and forth across
11713the serial line to the remote machine. The info is printed on the
11714@value{GDBN} standard output stream. The default is off.
11715@kindex show debug remote
11716@item show debug remote
11717Displays the state of display of remote packets.
11718@kindex set debug serial
11719@item set debug serial
11720Turns on or off display of @value{GDBN} serial debugging info. The
11721default is off.
11722@kindex show debug serial
11723@item show debug serial
11724Displays the current state of displaying @value{GDBN} serial debugging
11725info.
11726@kindex set debug target
11727@item set debug target
11728Turns on or off display of @value{GDBN} target debugging info. This info
11729includes what is going on at the target level of GDB, as it happens. The
11730default is off.
11731@kindex show debug target
11732@item show debug target
11733Displays the current state of displaying @value{GDBN} target debugging
11734info.
11735@kindex set debug varobj
11736@item set debug varobj
11737Turns on or off display of @value{GDBN} variable object debugging
11738info. The default is off.
11739@kindex show debug varobj
11740@item show debug varobj
11741Displays the current state of displaying @value{GDBN} variable object
11742debugging info.
11743@end table
11744
6d2ebf8b 11745@node Sequences
c906108c
SS
11746@chapter Canned Sequences of Commands
11747
11748Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
11749command lists}), @value{GDBN} provides two ways to store sequences of
11750commands for execution as a unit: user-defined commands and command
11751files.
c906108c
SS
11752
11753@menu
11754* Define:: User-defined commands
11755* Hooks:: User-defined command hooks
11756* Command Files:: Command files
11757* Output:: Commands for controlled output
11758@end menu
11759
6d2ebf8b 11760@node Define
c906108c
SS
11761@section User-defined commands
11762
11763@cindex user-defined command
2df3850c
JM
11764A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11765which you assign a new name as a command. This is done with the
11766@code{define} command. User commands may accept up to 10 arguments
11767separated by whitespace. Arguments are accessed within the user command
11768via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
11769
11770@smallexample
11771define adder
11772 print $arg0 + $arg1 + $arg2
11773@end smallexample
11774
d4f3574e
SS
11775@noindent
11776To execute the command use:
c906108c
SS
11777
11778@smallexample
11779adder 1 2 3
11780@end smallexample
11781
d4f3574e
SS
11782@noindent
11783This defines the command @code{adder}, which prints the sum of
5d161b24 11784its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
11785reference variables, use complex expressions, or even perform inferior
11786functions calls.
11787
11788@table @code
2df3850c 11789
c906108c
SS
11790@kindex define
11791@item define @var{commandname}
11792Define a command named @var{commandname}. If there is already a command
11793by that name, you are asked to confirm that you want to redefine it.
11794
11795The definition of the command is made up of other @value{GDBN} command lines,
11796which are given following the @code{define} command. The end of these
11797commands is marked by a line containing @code{end}.
11798
11799@kindex if
11800@kindex else
11801@item if
11802Takes a single argument, which is an expression to evaluate.
11803It is followed by a series of commands that are executed
11804only if the expression is true (nonzero).
11805There can then optionally be a line @code{else}, followed
11806by a series of commands that are only executed if the expression
11807was false. The end of the list is marked by a line containing @code{end}.
11808
11809@kindex while
11810@item while
11811The syntax is similar to @code{if}: the command takes a single argument,
11812which is an expression to evaluate, and must be followed by the commands to
11813execute, one per line, terminated by an @code{end}.
11814The commands are executed repeatedly as long as the expression
11815evaluates to true.
11816
11817@kindex document
11818@item document @var{commandname}
11819Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
11820accessed by @code{help}. The command @var{commandname} must already be
11821defined. This command reads lines of documentation just as @code{define}
11822reads the lines of the command definition, ending with @code{end}.
11823After the @code{document} command is finished, @code{help} on command
c906108c
SS
11824@var{commandname} displays the documentation you have written.
11825
11826You may use the @code{document} command again to change the
11827documentation of a command. Redefining the command with @code{define}
11828does not change the documentation.
11829
11830@kindex help user-defined
11831@item help user-defined
11832List all user-defined commands, with the first line of the documentation
11833(if any) for each.
11834
11835@kindex show user
11836@item show user
11837@itemx show user @var{commandname}
2df3850c
JM
11838Display the @value{GDBN} commands used to define @var{commandname} (but
11839not its documentation). If no @var{commandname} is given, display the
c906108c 11840definitions for all user-defined commands.
2df3850c 11841
c906108c
SS
11842@end table
11843
11844When user-defined commands are executed, the
11845commands of the definition are not printed. An error in any command
11846stops execution of the user-defined command.
11847
11848If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
11849without asking when used inside a user-defined command. Many @value{GDBN}
11850commands that normally print messages to say what they are doing omit the
c906108c
SS
11851messages when used in a user-defined command.
11852
6d2ebf8b 11853@node Hooks
c906108c 11854@section User-defined command hooks
d4f3574e
SS
11855@cindex command hooks
11856@cindex hooks, for commands
c906108c
SS
11857
11858You may define @emph{hooks}, which are a special kind of user-defined
11859command. Whenever you run the command @samp{foo}, if the user-defined
11860command @samp{hook-foo} exists, it is executed (with no arguments)
11861before that command.
11862
d4f3574e 11863@kindex stop@r{, a pseudo-command}
c906108c
SS
11864In addition, a pseudo-command, @samp{stop} exists. Defining
11865(@samp{hook-stop}) makes the associated commands execute every time
11866execution stops in your program: before breakpoint commands are run,
11867displays are printed, or the stack frame is printed.
11868
c906108c
SS
11869For example, to ignore @code{SIGALRM} signals while
11870single-stepping, but treat them normally during normal execution,
11871you could define:
11872
11873@example
11874define hook-stop
11875handle SIGALRM nopass
11876end
11877
11878define hook-run
11879handle SIGALRM pass
11880end
11881
11882define hook-continue
11883handle SIGLARM pass
11884end
11885@end example
c906108c
SS
11886
11887You can define a hook for any single-word command in @value{GDBN}, but
11888not for command aliases; you should define a hook for the basic command
11889name, e.g. @code{backtrace} rather than @code{bt}.
11890@c FIXME! So how does Joe User discover whether a command is an alias
11891@c or not?
11892If an error occurs during the execution of your hook, execution of
11893@value{GDBN} commands stops and @value{GDBN} issues a prompt
11894(before the command that you actually typed had a chance to run).
11895
11896If you try to define a hook which does not match any known command, you
11897get a warning from the @code{define} command.
11898
6d2ebf8b 11899@node Command Files
c906108c
SS
11900@section Command files
11901
11902@cindex command files
5d161b24
DB
11903A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11904commands. Comments (lines starting with @kbd{#}) may also be included.
11905An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
11906the last command, as it would from the terminal.
11907
11908@cindex init file
11909@cindex @file{.gdbinit}
d4f3574e 11910@cindex @file{gdb.ini}
c906108c 11911When you start @value{GDBN}, it automatically executes commands from its
bf0184be
ND
11912@dfn{init files}. These are files named @file{.gdbinit} on Unix and
11913@file{gdb.ini} on DOS/Windows. During startup, @value{GDBN} does the
11914following:
11915
11916@enumerate
11917@item
11918Reads the init file (if any) in your home directory@footnote{On
11919DOS/Windows systems, the home directory is the one pointed to by the
11920@code{HOME} environment variable.}.
11921
11922@item
11923Processes command line options and operands.
11924
11925@item
11926Reads the init file (if any) in the current working directory.
11927
11928@item
11929Reads command files specified by the @samp{-x} option.
11930@end enumerate
11931
11932The init file in your home directory can set options (such as @samp{set
11933complaints}) that affect subsequent processing of command line options
11934and operands. Init files are not executed if you use the @samp{-nx}
11935option (@pxref{Mode Options, ,Choosing modes}).
c906108c 11936
c906108c
SS
11937@cindex init file name
11938On some configurations of @value{GDBN}, the init file is known by a
11939different name (these are typically environments where a specialized
11940form of @value{GDBN} may need to coexist with other forms, hence a
11941different name for the specialized version's init file). These are the
11942environments with special init file names:
11943
00e4a2e4 11944@cindex @file{.vxgdbinit}
c906108c
SS
11945@itemize @bullet
11946@item
00e4a2e4 11947VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 11948
00e4a2e4 11949@cindex @file{.os68gdbinit}
c906108c 11950@item
00e4a2e4 11951OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 11952
00e4a2e4 11953@cindex @file{.esgdbinit}
c906108c 11954@item
00e4a2e4 11955ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
c906108c 11956@end itemize
c906108c
SS
11957
11958You can also request the execution of a command file with the
11959@code{source} command:
11960
11961@table @code
11962@kindex source
11963@item source @var{filename}
11964Execute the command file @var{filename}.
11965@end table
11966
11967The lines in a command file are executed sequentially. They are not
11968printed as they are executed. An error in any command terminates execution
11969of the command file.
11970
11971Commands that would ask for confirmation if used interactively proceed
11972without asking when used in a command file. Many @value{GDBN} commands that
11973normally print messages to say what they are doing omit the messages
11974when called from command files.
11975
6d2ebf8b 11976@node Output
c906108c
SS
11977@section Commands for controlled output
11978
11979During the execution of a command file or a user-defined command, normal
11980@value{GDBN} output is suppressed; the only output that appears is what is
11981explicitly printed by the commands in the definition. This section
11982describes three commands useful for generating exactly the output you
11983want.
11984
11985@table @code
11986@kindex echo
11987@item echo @var{text}
11988@c I do not consider backslash-space a standard C escape sequence
11989@c because it is not in ANSI.
11990Print @var{text}. Nonprinting characters can be included in
11991@var{text} using C escape sequences, such as @samp{\n} to print a
11992newline. @strong{No newline is printed unless you specify one.}
11993In addition to the standard C escape sequences, a backslash followed
11994by a space stands for a space. This is useful for displaying a
11995string with spaces at the beginning or the end, since leading and
5d161b24 11996trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
11997To print @samp{@w{ }and foo =@w{ }}, use the command
11998@samp{echo \@w{ }and foo = \@w{ }}.
11999
12000A backslash at the end of @var{text} can be used, as in C, to continue
12001the command onto subsequent lines. For example,
12002
12003@example
12004echo This is some text\n\
12005which is continued\n\
12006onto several lines.\n
12007@end example
12008
12009produces the same output as
12010
12011@example
12012echo This is some text\n
12013echo which is continued\n
12014echo onto several lines.\n
12015@end example
12016
12017@kindex output
12018@item output @var{expression}
12019Print the value of @var{expression} and nothing but that value: no
12020newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 12021value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
12022on expressions.
12023
12024@item output/@var{fmt} @var{expression}
12025Print the value of @var{expression} in format @var{fmt}. You can use
12026the same formats as for @code{print}. @xref{Output Formats,,Output
12027formats}, for more information.
12028
12029@kindex printf
12030@item printf @var{string}, @var{expressions}@dots{}
12031Print the values of the @var{expressions} under the control of
12032@var{string}. The @var{expressions} are separated by commas and may be
12033either numbers or pointers. Their values are printed as specified by
12034@var{string}, exactly as if your program were to execute the C
12035subroutine
d4f3574e
SS
12036@c FIXME: the above implies that at least all ANSI C formats are
12037@c supported, but it isn't true: %E and %G don't work (or so it seems).
12038@c Either this is a bug, or the manual should document what formats are
12039@c supported.
c906108c
SS
12040
12041@example
12042printf (@var{string}, @var{expressions}@dots{});
12043@end example
12044
12045For example, you can print two values in hex like this:
12046
12047@smallexample
12048printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12049@end smallexample
12050
12051The only backslash-escape sequences that you can use in the format
12052string are the simple ones that consist of backslash followed by a
12053letter.
12054@end table
12055
6d2ebf8b 12056@node Emacs
c906108c
SS
12057@chapter Using @value{GDBN} under @sc{gnu} Emacs
12058
12059@cindex Emacs
12060@cindex @sc{gnu} Emacs
12061A special interface allows you to use @sc{gnu} Emacs to view (and
12062edit) the source files for the program you are debugging with
12063@value{GDBN}.
12064
12065To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
12066executable file you want to debug as an argument. This command starts
12067@value{GDBN} as a subprocess of Emacs, with input and output through a newly
12068created Emacs buffer.
53a5351d 12069@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
12070
12071Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
12072things:
12073
12074@itemize @bullet
12075@item
12076All ``terminal'' input and output goes through the Emacs buffer.
12077@end itemize
12078
12079This applies both to @value{GDBN} commands and their output, and to the input
12080and output done by the program you are debugging.
12081
12082This is useful because it means that you can copy the text of previous
12083commands and input them again; you can even use parts of the output
12084in this way.
12085
12086All the facilities of Emacs' Shell mode are available for interacting
12087with your program. In particular, you can send signals the usual
12088way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
12089stop.
12090
12091@itemize @bullet
12092@item
12093@value{GDBN} displays source code through Emacs.
12094@end itemize
12095
12096Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
12097source file for that frame and puts an arrow (@samp{=>}) at the
12098left margin of the current line. Emacs uses a separate buffer for
12099source display, and splits the screen to show both your @value{GDBN} session
12100and the source.
12101
12102Explicit @value{GDBN} @code{list} or search commands still produce output as
12103usual, but you probably have no reason to use them from Emacs.
12104
12105@quotation
12106@emph{Warning:} If the directory where your program resides is not your
12107current directory, it can be easy to confuse Emacs about the location of
12108the source files, in which case the auxiliary display buffer does not
12109appear to show your source. @value{GDBN} can find programs by searching your
12110environment's @code{PATH} variable, so the @value{GDBN} input and output
12111session proceeds normally; but Emacs does not get enough information
12112back from @value{GDBN} to locate the source files in this situation. To
12113avoid this problem, either start @value{GDBN} mode from the directory where
12114your program resides, or specify an absolute file name when prompted for the
12115@kbd{M-x gdb} argument.
12116
12117A similar confusion can result if you use the @value{GDBN} @code{file} command to
12118switch to debugging a program in some other location, from an existing
12119@value{GDBN} buffer in Emacs.
12120@end quotation
12121
12122By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
12123you need to call @value{GDBN} by a different name (for example, if you keep
12124several configurations around, with different names) you can set the
12125Emacs variable @code{gdb-command-name}; for example,
12126
12127@example
12128(setq gdb-command-name "mygdb")
12129@end example
12130
12131@noindent
d4f3574e 12132(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
12133in your @file{.emacs} file) makes Emacs call the program named
12134``@code{mygdb}'' instead.
12135
12136In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
12137addition to the standard Shell mode commands:
12138
12139@table @kbd
12140@item C-h m
12141Describe the features of Emacs' @value{GDBN} Mode.
12142
12143@item M-s
12144Execute to another source line, like the @value{GDBN} @code{step} command; also
12145update the display window to show the current file and location.
12146
12147@item M-n
12148Execute to next source line in this function, skipping all function
12149calls, like the @value{GDBN} @code{next} command. Then update the display window
12150to show the current file and location.
12151
12152@item M-i
12153Execute one instruction, like the @value{GDBN} @code{stepi} command; update
12154display window accordingly.
12155
12156@item M-x gdb-nexti
12157Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
12158display window accordingly.
12159
12160@item C-c C-f
12161Execute until exit from the selected stack frame, like the @value{GDBN}
12162@code{finish} command.
12163
12164@item M-c
12165Continue execution of your program, like the @value{GDBN} @code{continue}
12166command.
12167
12168@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
12169
12170@item M-u
12171Go up the number of frames indicated by the numeric argument
12172(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
12173like the @value{GDBN} @code{up} command.
12174
12175@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
12176
12177@item M-d
12178Go down the number of frames indicated by the numeric argument, like the
12179@value{GDBN} @code{down} command.
12180
12181@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
12182
12183@item C-x &
12184Read the number where the cursor is positioned, and insert it at the end
12185of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
12186around an address that was displayed earlier, type @kbd{disassemble};
12187then move the cursor to the address display, and pick up the
12188argument for @code{disassemble} by typing @kbd{C-x &}.
12189
12190You can customize this further by defining elements of the list
12191@code{gdb-print-command}; once it is defined, you can format or
12192otherwise process numbers picked up by @kbd{C-x &} before they are
12193inserted. A numeric argument to @kbd{C-x &} indicates that you
12194wish special formatting, and also acts as an index to pick an element of the
12195list. If the list element is a string, the number to be inserted is
12196formatted using the Emacs function @code{format}; otherwise the number
12197is passed as an argument to the corresponding list element.
12198@end table
12199
12200In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
12201tells @value{GDBN} to set a breakpoint on the source line point is on.
12202
12203If you accidentally delete the source-display buffer, an easy way to get
12204it back is to type the command @code{f} in the @value{GDBN} buffer, to
12205request a frame display; when you run under Emacs, this recreates
12206the source buffer if necessary to show you the context of the current
12207frame.
12208
12209The source files displayed in Emacs are in ordinary Emacs buffers
12210which are visiting the source files in the usual way. You can edit
12211the files with these buffers if you wish; but keep in mind that @value{GDBN}
12212communicates with Emacs in terms of line numbers. If you add or
12213delete lines from the text, the line numbers that @value{GDBN} knows cease
12214to correspond properly with the code.
12215
12216@c The following dropped because Epoch is nonstandard. Reactivate
12217@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
12218@ignore
12219@kindex Emacs Epoch environment
12220@kindex Epoch
12221@kindex inspect
12222
5d161b24 12223Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
12224called the @code{epoch}
12225environment. Users of this environment can use a new command,
12226@code{inspect} which performs identically to @code{print} except that
12227each value is printed in its own window.
12228@end ignore
c906108c 12229
d700128c 12230@include annotate.texi
7162c0ca 12231@include gdbmi.texinfo
d700128c 12232
6d2ebf8b 12233@node GDB Bugs
c906108c
SS
12234@chapter Reporting Bugs in @value{GDBN}
12235@cindex bugs in @value{GDBN}
12236@cindex reporting bugs in @value{GDBN}
12237
12238Your bug reports play an essential role in making @value{GDBN} reliable.
12239
12240Reporting a bug may help you by bringing a solution to your problem, or it
12241may not. But in any case the principal function of a bug report is to help
12242the entire community by making the next version of @value{GDBN} work better. Bug
12243reports are your contribution to the maintenance of @value{GDBN}.
12244
12245In order for a bug report to serve its purpose, you must include the
12246information that enables us to fix the bug.
12247
12248@menu
12249* Bug Criteria:: Have you found a bug?
12250* Bug Reporting:: How to report bugs
12251@end menu
12252
6d2ebf8b 12253@node Bug Criteria
c906108c
SS
12254@section Have you found a bug?
12255@cindex bug criteria
12256
12257If you are not sure whether you have found a bug, here are some guidelines:
12258
12259@itemize @bullet
12260@cindex fatal signal
12261@cindex debugger crash
12262@cindex crash of debugger
12263@item
12264If the debugger gets a fatal signal, for any input whatever, that is a
12265@value{GDBN} bug. Reliable debuggers never crash.
12266
12267@cindex error on valid input
12268@item
12269If @value{GDBN} produces an error message for valid input, that is a
12270bug. (Note that if you're cross debugging, the problem may also be
12271somewhere in the connection to the target.)
12272
12273@cindex invalid input
12274@item
12275If @value{GDBN} does not produce an error message for invalid input,
12276that is a bug. However, you should note that your idea of
12277``invalid input'' might be our idea of ``an extension'' or ``support
12278for traditional practice''.
12279
12280@item
12281If you are an experienced user of debugging tools, your suggestions
12282for improvement of @value{GDBN} are welcome in any case.
12283@end itemize
12284
6d2ebf8b 12285@node Bug Reporting
c906108c
SS
12286@section How to report bugs
12287@cindex bug reports
12288@cindex @value{GDBN} bugs, reporting
12289
c906108c
SS
12290A number of companies and individuals offer support for @sc{gnu} products.
12291If you obtained @value{GDBN} from a support organization, we recommend you
12292contact that organization first.
12293
12294You can find contact information for many support companies and
12295individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
12296distribution.
12297@c should add a web page ref...
12298
12299In any event, we also recommend that you send bug reports for
12300@value{GDBN} to this addresses:
12301
12302@example
d4f3574e 12303bug-gdb@@gnu.org
c906108c
SS
12304@end example
12305
12306@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 12307@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
12308not want to receive bug reports. Those that do have arranged to receive
12309@samp{bug-gdb}.
12310
12311The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
12312serves as a repeater. The mailing list and the newsgroup carry exactly
12313the same messages. Often people think of posting bug reports to the
12314newsgroup instead of mailing them. This appears to work, but it has one
12315problem which can be crucial: a newsgroup posting often lacks a mail
12316path back to the sender. Thus, if we need to ask for more information,
12317we may be unable to reach you. For this reason, it is better to send
12318bug reports to the mailing list.
12319
12320As a last resort, send bug reports on paper to:
12321
12322@example
12323@sc{gnu} Debugger Bugs
12324Free Software Foundation Inc.
1232559 Temple Place - Suite 330
12326Boston, MA 02111-1307
12327USA
12328@end example
c906108c
SS
12329
12330The fundamental principle of reporting bugs usefully is this:
12331@strong{report all the facts}. If you are not sure whether to state a
12332fact or leave it out, state it!
12333
12334Often people omit facts because they think they know what causes the
12335problem and assume that some details do not matter. Thus, you might
12336assume that the name of the variable you use in an example does not matter.
12337Well, probably it does not, but one cannot be sure. Perhaps the bug is a
12338stray memory reference which happens to fetch from the location where that
12339name is stored in memory; perhaps, if the name were different, the contents
12340of that location would fool the debugger into doing the right thing despite
12341the bug. Play it safe and give a specific, complete example. That is the
12342easiest thing for you to do, and the most helpful.
12343
12344Keep in mind that the purpose of a bug report is to enable us to fix the
12345bug. It may be that the bug has been reported previously, but neither
12346you nor we can know that unless your bug report is complete and
12347self-contained.
12348
12349Sometimes people give a few sketchy facts and ask, ``Does this ring a
12350bell?'' Those bug reports are useless, and we urge everyone to
12351@emph{refuse to respond to them} except to chide the sender to report
12352bugs properly.
12353
12354To enable us to fix the bug, you should include all these things:
12355
12356@itemize @bullet
12357@item
12358The version of @value{GDBN}. @value{GDBN} announces it if you start
12359with no arguments; you can also print it at any time using @code{show
12360version}.
12361
12362Without this, we will not know whether there is any point in looking for
12363the bug in the current version of @value{GDBN}.
12364
12365@item
12366The type of machine you are using, and the operating system name and
12367version number.
12368
c906108c
SS
12369@item
12370What compiler (and its version) was used to compile @value{GDBN}---e.g.
12371``@value{GCC}--2.8.1''.
c906108c
SS
12372
12373@item
12374What compiler (and its version) was used to compile the program you are
12375debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12376C Compiler''. For GCC, you can say @code{gcc --version} to get this
12377information; for other compilers, see the documentation for those
12378compilers.
12379
12380@item
12381The command arguments you gave the compiler to compile your example and
12382observe the bug. For example, did you use @samp{-O}? To guarantee
12383you will not omit something important, list them all. A copy of the
12384Makefile (or the output from make) is sufficient.
12385
12386If we were to try to guess the arguments, we would probably guess wrong
12387and then we might not encounter the bug.
12388
12389@item
12390A complete input script, and all necessary source files, that will
12391reproduce the bug.
12392
12393@item
12394A description of what behavior you observe that you believe is
12395incorrect. For example, ``It gets a fatal signal.''
12396
12397Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12398will certainly notice it. But if the bug is incorrect output, we might
12399not notice unless it is glaringly wrong. You might as well not give us
12400a chance to make a mistake.
12401
12402Even if the problem you experience is a fatal signal, you should still
12403say so explicitly. Suppose something strange is going on, such as, your
12404copy of @value{GDBN} is out of synch, or you have encountered a bug in
12405the C library on your system. (This has happened!) Your copy might
12406crash and ours would not. If you told us to expect a crash, then when
12407ours fails to crash, we would know that the bug was not happening for
12408us. If you had not told us to expect a crash, then we would not be able
12409to draw any conclusion from our observations.
12410
c906108c
SS
12411@item
12412If you wish to suggest changes to the @value{GDBN} source, send us context
12413diffs. If you even discuss something in the @value{GDBN} source, refer to
12414it by context, not by line number.
12415
12416The line numbers in our development sources will not match those in your
12417sources. Your line numbers would convey no useful information to us.
53a5351d 12418
c906108c
SS
12419@end itemize
12420
12421Here are some things that are not necessary:
12422
12423@itemize @bullet
12424@item
12425A description of the envelope of the bug.
12426
12427Often people who encounter a bug spend a lot of time investigating
12428which changes to the input file will make the bug go away and which
12429changes will not affect it.
12430
12431This is often time consuming and not very useful, because the way we
12432will find the bug is by running a single example under the debugger
12433with breakpoints, not by pure deduction from a series of examples.
12434We recommend that you save your time for something else.
12435
12436Of course, if you can find a simpler example to report @emph{instead}
12437of the original one, that is a convenience for us. Errors in the
12438output will be easier to spot, running under the debugger will take
12439less time, and so on.
12440
12441However, simplification is not vital; if you do not want to do this,
12442report the bug anyway and send us the entire test case you used.
12443
12444@item
12445A patch for the bug.
12446
12447A patch for the bug does help us if it is a good one. But do not omit
12448the necessary information, such as the test case, on the assumption that
12449a patch is all we need. We might see problems with your patch and decide
12450to fix the problem another way, or we might not understand it at all.
12451
12452Sometimes with a program as complicated as @value{GDBN} it is very hard to
12453construct an example that will make the program follow a certain path
12454through the code. If you do not send us the example, we will not be able
12455to construct one, so we will not be able to verify that the bug is fixed.
12456
12457And if we cannot understand what bug you are trying to fix, or why your
12458patch should be an improvement, we will not install it. A test case will
12459help us to understand.
12460
12461@item
12462A guess about what the bug is or what it depends on.
12463
12464Such guesses are usually wrong. Even we cannot guess right about such
12465things without first using the debugger to find the facts.
12466@end itemize
12467
5d161b24 12468@c The readline documentation is distributed with the readline code
c906108c
SS
12469@c and consists of the two following files:
12470@c rluser.texinfo
7be570e7 12471@c inc-hist.texinfo
c906108c
SS
12472@c Use -I with makeinfo to point to the appropriate directory,
12473@c environment var TEXINPUTS with TeX.
12474@include rluser.texinfo
7be570e7 12475@include inc-hist.texinfo
c906108c
SS
12476
12477
6d2ebf8b 12478@node Formatting Documentation
c906108c
SS
12479@appendix Formatting Documentation
12480
12481@cindex @value{GDBN} reference card
12482@cindex reference card
12483The @value{GDBN} 4 release includes an already-formatted reference card, ready
12484for printing with PostScript or Ghostscript, in the @file{gdb}
12485subdirectory of the main source directory@footnote{In
12486@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12487release.}. If you can use PostScript or Ghostscript with your printer,
12488you can print the reference card immediately with @file{refcard.ps}.
12489
12490The release also includes the source for the reference card. You
12491can format it, using @TeX{}, by typing:
12492
12493@example
12494make refcard.dvi
12495@end example
12496
5d161b24
DB
12497The @value{GDBN} reference card is designed to print in @dfn{landscape}
12498mode on US ``letter'' size paper;
c906108c
SS
12499that is, on a sheet 11 inches wide by 8.5 inches
12500high. You will need to specify this form of printing as an option to
12501your @sc{dvi} output program.
12502
12503@cindex documentation
12504
12505All the documentation for @value{GDBN} comes as part of the machine-readable
12506distribution. The documentation is written in Texinfo format, which is
12507a documentation system that uses a single source file to produce both
12508on-line information and a printed manual. You can use one of the Info
12509formatting commands to create the on-line version of the documentation
12510and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12511
12512@value{GDBN} includes an already formatted copy of the on-line Info
12513version of this manual in the @file{gdb} subdirectory. The main Info
12514file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12515subordinate files matching @samp{gdb.info*} in the same directory. If
12516necessary, you can print out these files, or read them with any editor;
12517but they are easier to read using the @code{info} subsystem in @sc{gnu}
12518Emacs or the standalone @code{info} program, available as part of the
12519@sc{gnu} Texinfo distribution.
12520
12521If you want to format these Info files yourself, you need one of the
12522Info formatting programs, such as @code{texinfo-format-buffer} or
12523@code{makeinfo}.
12524
12525If you have @code{makeinfo} installed, and are in the top level
12526@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12527version @value{GDBVN}), you can make the Info file by typing:
12528
12529@example
12530cd gdb
12531make gdb.info
12532@end example
12533
12534If you want to typeset and print copies of this manual, you need @TeX{},
12535a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12536Texinfo definitions file.
12537
12538@TeX{} is a typesetting program; it does not print files directly, but
12539produces output files called @sc{dvi} files. To print a typeset
12540document, you need a program to print @sc{dvi} files. If your system
12541has @TeX{} installed, chances are it has such a program. The precise
12542command to use depends on your system; @kbd{lpr -d} is common; another
12543(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12544require a file name without any extension or a @samp{.dvi} extension.
12545
12546@TeX{} also requires a macro definitions file called
12547@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12548written in Texinfo format. On its own, @TeX{} cannot either read or
12549typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12550and is located in the @file{gdb-@var{version-number}/texinfo}
12551directory.
12552
12553If you have @TeX{} and a @sc{dvi} printer program installed, you can
12554typeset and print this manual. First switch to the the @file{gdb}
12555subdirectory of the main source directory (for example, to
12556@file{gdb-@value{GDBVN}/gdb}) and type:
12557
12558@example
12559make gdb.dvi
12560@end example
12561
12562Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 12563
6d2ebf8b 12564@node Installing GDB
c906108c
SS
12565@appendix Installing @value{GDBN}
12566@cindex configuring @value{GDBN}
12567@cindex installation
12568
c906108c
SS
12569@value{GDBN} comes with a @code{configure} script that automates the process
12570of preparing @value{GDBN} for installation; you can then use @code{make} to
12571build the @code{gdb} program.
12572@iftex
12573@c irrelevant in info file; it's as current as the code it lives with.
12574@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12575look at the @file{README} file in the sources; we may have improved the
12576installation procedures since publishing this manual.}
12577@end iftex
12578
5d161b24
DB
12579The @value{GDBN} distribution includes all the source code you need for
12580@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
12581appending the version number to @samp{gdb}.
12582
12583For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12584@file{gdb-@value{GDBVN}} directory. That directory contains:
12585
12586@table @code
12587@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12588script for configuring @value{GDBN} and all its supporting libraries
12589
12590@item gdb-@value{GDBVN}/gdb
12591the source specific to @value{GDBN} itself
12592
12593@item gdb-@value{GDBVN}/bfd
12594source for the Binary File Descriptor library
12595
12596@item gdb-@value{GDBVN}/include
12597@sc{gnu} include files
12598
12599@item gdb-@value{GDBVN}/libiberty
12600source for the @samp{-liberty} free software library
12601
12602@item gdb-@value{GDBVN}/opcodes
12603source for the library of opcode tables and disassemblers
12604
12605@item gdb-@value{GDBVN}/readline
12606source for the @sc{gnu} command-line interface
12607
12608@item gdb-@value{GDBVN}/glob
12609source for the @sc{gnu} filename pattern-matching subroutine
12610
12611@item gdb-@value{GDBVN}/mmalloc
12612source for the @sc{gnu} memory-mapped malloc package
12613@end table
12614
12615The simplest way to configure and build @value{GDBN} is to run @code{configure}
12616from the @file{gdb-@var{version-number}} source directory, which in
12617this example is the @file{gdb-@value{GDBVN}} directory.
12618
12619First switch to the @file{gdb-@var{version-number}} source directory
12620if you are not already in it; then run @code{configure}. Pass the
12621identifier for the platform on which @value{GDBN} will run as an
12622argument.
12623
12624For example:
12625
12626@example
12627cd gdb-@value{GDBVN}
12628./configure @var{host}
12629make
12630@end example
12631
12632@noindent
12633where @var{host} is an identifier such as @samp{sun4} or
12634@samp{decstation}, that identifies the platform where @value{GDBN} will run.
12635(You can often leave off @var{host}; @code{configure} tries to guess the
12636correct value by examining your system.)
12637
12638Running @samp{configure @var{host}} and then running @code{make} builds the
12639@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12640libraries, then @code{gdb} itself. The configured source files, and the
12641binaries, are left in the corresponding source directories.
12642
12643@need 750
12644@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12645system does not recognize this automatically when you run a different
12646shell, you may need to run @code{sh} on it explicitly:
12647
12648@example
12649sh configure @var{host}
12650@end example
12651
12652If you run @code{configure} from a directory that contains source
12653directories for multiple libraries or programs, such as the
12654@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12655creates configuration files for every directory level underneath (unless
12656you tell it not to, with the @samp{--norecursion} option).
12657
12658You can run the @code{configure} script from any of the
12659subordinate directories in the @value{GDBN} distribution if you only want to
12660configure that subdirectory, but be sure to specify a path to it.
12661
12662For example, with version @value{GDBVN}, type the following to configure only
12663the @code{bfd} subdirectory:
12664
12665@example
12666@group
12667cd gdb-@value{GDBVN}/bfd
12668../configure @var{host}
12669@end group
12670@end example
12671
12672You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12673However, you should make sure that the shell on your path (named by
12674the @samp{SHELL} environment variable) is publicly readable. Remember
12675that @value{GDBN} uses the shell to start your program---some systems refuse to
12676let @value{GDBN} debug child processes whose programs are not readable.
12677
12678@menu
12679* Separate Objdir:: Compiling @value{GDBN} in another directory
12680* Config Names:: Specifying names for hosts and targets
12681* Configure Options:: Summary of options for configure
12682@end menu
12683
6d2ebf8b 12684@node Separate Objdir
c906108c
SS
12685@section Compiling @value{GDBN} in another directory
12686
12687If you want to run @value{GDBN} versions for several host or target machines,
12688you need a different @code{gdb} compiled for each combination of
12689host and target. @code{configure} is designed to make this easy by
12690allowing you to generate each configuration in a separate subdirectory,
12691rather than in the source directory. If your @code{make} program
12692handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12693@code{make} in each of these directories builds the @code{gdb}
12694program specified there.
12695
12696To build @code{gdb} in a separate directory, run @code{configure}
12697with the @samp{--srcdir} option to specify where to find the source.
12698(You also need to specify a path to find @code{configure}
12699itself from your working directory. If the path to @code{configure}
12700would be the same as the argument to @samp{--srcdir}, you can leave out
12701the @samp{--srcdir} option; it is assumed.)
12702
5d161b24 12703For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
12704separate directory for a Sun 4 like this:
12705
12706@example
12707@group
12708cd gdb-@value{GDBVN}
12709mkdir ../gdb-sun4
12710cd ../gdb-sun4
12711../gdb-@value{GDBVN}/configure sun4
12712make
12713@end group
12714@end example
12715
12716When @code{configure} builds a configuration using a remote source
12717directory, it creates a tree for the binaries with the same structure
12718(and using the same names) as the tree under the source directory. In
12719the example, you'd find the Sun 4 library @file{libiberty.a} in the
12720directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12721@file{gdb-sun4/gdb}.
12722
12723One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
12724directories is to configure @value{GDBN} for cross-compiling (where
12725@value{GDBN} runs on one machine---the @dfn{host}---while debugging
12726programs that run on another machine---the @dfn{target}).
c906108c
SS
12727You specify a cross-debugging target by
12728giving the @samp{--target=@var{target}} option to @code{configure}.
12729
12730When you run @code{make} to build a program or library, you must run
12731it in a configured directory---whatever directory you were in when you
12732called @code{configure} (or one of its subdirectories).
12733
12734The @code{Makefile} that @code{configure} generates in each source
12735directory also runs recursively. If you type @code{make} in a source
12736directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12737directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12738will build all the required libraries, and then build GDB.
12739
12740When you have multiple hosts or targets configured in separate
12741directories, you can run @code{make} on them in parallel (for example,
12742if they are NFS-mounted on each of the hosts); they will not interfere
12743with each other.
12744
6d2ebf8b 12745@node Config Names
c906108c
SS
12746@section Specifying names for hosts and targets
12747
12748The specifications used for hosts and targets in the @code{configure}
12749script are based on a three-part naming scheme, but some short predefined
12750aliases are also supported. The full naming scheme encodes three pieces
12751of information in the following pattern:
12752
12753@example
12754@var{architecture}-@var{vendor}-@var{os}
12755@end example
12756
12757For example, you can use the alias @code{sun4} as a @var{host} argument,
12758or as the value for @var{target} in a @code{--target=@var{target}}
12759option. The equivalent full name is @samp{sparc-sun-sunos4}.
12760
12761The @code{configure} script accompanying @value{GDBN} does not provide
12762any query facility to list all supported host and target names or
12763aliases. @code{configure} calls the Bourne shell script
12764@code{config.sub} to map abbreviations to full names; you can read the
12765script, if you wish, or you can use it to test your guesses on
12766abbreviations---for example:
12767
12768@smallexample
12769% sh config.sub i386-linux
12770i386-pc-linux-gnu
12771% sh config.sub alpha-linux
12772alpha-unknown-linux-gnu
12773% sh config.sub hp9k700
12774hppa1.1-hp-hpux
12775% sh config.sub sun4
12776sparc-sun-sunos4.1.1
12777% sh config.sub sun3
12778m68k-sun-sunos4.1.1
12779% sh config.sub i986v
12780Invalid configuration `i986v': machine `i986v' not recognized
12781@end smallexample
12782
12783@noindent
12784@code{config.sub} is also distributed in the @value{GDBN} source
12785directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12786
6d2ebf8b 12787@node Configure Options
c906108c
SS
12788@section @code{configure} options
12789
12790Here is a summary of the @code{configure} options and arguments that
12791are most often useful for building @value{GDBN}. @code{configure} also has
12792several other options not listed here. @inforef{What Configure
12793Does,,configure.info}, for a full explanation of @code{configure}.
12794
12795@example
12796configure @r{[}--help@r{]}
12797 @r{[}--prefix=@var{dir}@r{]}
12798 @r{[}--exec-prefix=@var{dir}@r{]}
12799 @r{[}--srcdir=@var{dirname}@r{]}
12800 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12801 @r{[}--target=@var{target}@r{]}
12802 @var{host}
12803@end example
12804
12805@noindent
12806You may introduce options with a single @samp{-} rather than
12807@samp{--} if you prefer; but you may abbreviate option names if you use
12808@samp{--}.
12809
12810@table @code
12811@item --help
12812Display a quick summary of how to invoke @code{configure}.
12813
12814@item --prefix=@var{dir}
12815Configure the source to install programs and files under directory
12816@file{@var{dir}}.
12817
12818@item --exec-prefix=@var{dir}
12819Configure the source to install programs under directory
12820@file{@var{dir}}.
12821
12822@c avoid splitting the warning from the explanation:
12823@need 2000
12824@item --srcdir=@var{dirname}
12825@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12826@code{make} that implements the @code{VPATH} feature.}@*
12827Use this option to make configurations in directories separate from the
12828@value{GDBN} source directories. Among other things, you can use this to
12829build (or maintain) several configurations simultaneously, in separate
12830directories. @code{configure} writes configuration specific files in
12831the current directory, but arranges for them to use the source in the
12832directory @var{dirname}. @code{configure} creates directories under
12833the working directory in parallel to the source directories below
12834@var{dirname}.
12835
12836@item --norecursion
12837Configure only the directory level where @code{configure} is executed; do not
12838propagate configuration to subdirectories.
12839
12840@item --target=@var{target}
12841Configure @value{GDBN} for cross-debugging programs running on the specified
12842@var{target}. Without this option, @value{GDBN} is configured to debug
12843programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12844
12845There is no convenient way to generate a list of all available targets.
12846
12847@item @var{host} @dots{}
12848Configure @value{GDBN} to run on the specified @var{host}.
12849
12850There is no convenient way to generate a list of all available hosts.
12851@end table
12852
12853There are many other options available as well, but they are generally
12854needed for special purposes only.
5d161b24 12855
6d2ebf8b 12856@node Index
c906108c
SS
12857@unnumbered Index
12858
12859@printindex cp
12860
12861@tex
12862% I think something like @colophon should be in texinfo. In the
12863% meantime:
12864\long\def\colophon{\hbox to0pt{}\vfill
12865\centerline{The body of this manual is set in}
12866\centerline{\fontname\tenrm,}
12867\centerline{with headings in {\bf\fontname\tenbf}}
12868\centerline{and examples in {\tt\fontname\tentt}.}
12869\centerline{{\it\fontname\tenit\/},}
12870\centerline{{\bf\fontname\tenbf}, and}
12871\centerline{{\sl\fontname\tensl\/}}
12872\centerline{are used for emphasis.}\vfill}
12873\page\colophon
12874% Blame: doc@cygnus.com, 1991.
12875@end tex
12876
12877@contents
12878@bye
This page took 0.625383 seconds and 4 git commands to generate.