* gdb.texinfo: Refer to file names, not path names, per rms
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 1988 1989 1990 1991 1992 1993 1994 Free Software Foundation, Inc.
3 @c
4 @c %**start of header
5 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6 @c of @set vars. However, you can override filename with makeinfo -o.
7 @setfilename gdb.info
8 @c
9 @include gdb-cfg.texi
10 @c
11 @ifset GENERIC
12 @settitle Debugging with @value{GDBN}
13 @end ifset
14 @ifclear GENERIC
15 @settitle Debugging with @value{GDBN} (@value{TARGET})
16 @end ifclear
17 @setchapternewpage odd
18 @c %**end of header
19
20 @iftex
21 @c @smallbook
22 @c @cropmarks
23 @end iftex
24
25 @finalout
26 @syncodeindex ky cp
27
28 @c readline appendices use @vindex
29 @syncodeindex vr cp
30
31 @c !!set GDB manual's edition---not the same as GDB version!
32 @set EDITION 4.12
33
34 @c !!set GDB manual's revision date
35 @set DATE January 1994
36
37 @c GDB CHANGELOG CONSULTED BETWEEN:
38 @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com)
39 @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
40
41 @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
42
43 @ifinfo
44 @c This is a dir.info fragment to support semi-automated addition of
45 @c manuals to an info tree. zoo@cygnus.com is developing this facility.
46 @format
47 START-INFO-DIR-ENTRY
48 * Gdb: (gdb). The GNU debugger.
49 END-INFO-DIR-ENTRY
50 @end format
51 @end ifinfo
52 @c
53 @c
54 @ifinfo
55 This file documents the GNU debugger @value{GDBN}.
56
57
58 This is Edition @value{EDITION}, @value{DATE},
59 of @cite{Debugging with @value{GDBN}: the GNU Source-Level Debugger}
60 for GDB Version @value{GDBVN}.
61
62 Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software Foundation, Inc.
63
64 Permission is granted to make and distribute verbatim copies of
65 this manual provided the copyright notice and this permission notice
66 are preserved on all copies.
67
68 @ignore
69 Permission is granted to process this file through TeX and print the
70 results, provided the printed document carries copying permission
71 notice identical to this one except for the removal of this paragraph
72 (this paragraph not being relevant to the printed manual).
73
74 @end ignore
75 Permission is granted to copy and distribute modified versions of this
76 manual under the conditions for verbatim copying, provided also that the
77 entire resulting derived work is distributed under the terms of a
78 permission notice identical to this one.
79
80 Permission is granted to copy and distribute translations of this manual
81 into another language, under the above conditions for modified versions.
82 @end ifinfo
83
84 @titlepage
85 @title Debugging with @value{GDBN}
86 @subtitle The GNU Source-Level Debugger
87 @ifclear GENERIC
88 @subtitle (@value{TARGET})
89 @end ifclear
90 @sp 1
91 @subtitle Edition @value{EDITION}, for @value{GDBN} version @value{GDBVN}
92 @subtitle @value{DATE}
93 @author Richard M. Stallman and Roland H. Pesch
94 @page
95 @tex
96 {\parskip=0pt
97 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@prep.ai.mit.edu.)\par
98 \hfill {\it Debugging with @value{GDBN}}\par
99 \hfill \TeX{}info \texinfoversion\par
100 \hfill pesch\@cygnus.com\par
101 }
102 @end tex
103
104 @vskip 0pt plus 1filll
105 Copyright @copyright{} 1988, '89, '90, '91, '92, '93 Free Software
106 Foundation, Inc.
107 @sp 2
108 Published by the Free Software Foundation @*
109 675 Massachusetts Avenue, @*
110 Cambridge, MA 02139 USA @*
111 Printed copies are available for $20 each. @*
112 ISBN 1-882114-11-6 @*
113
114 Permission is granted to make and distribute verbatim copies of
115 this manual provided the copyright notice and this permission notice
116 are preserved on all copies.
117
118 Permission is granted to copy and distribute modified versions of this
119 manual under the conditions for verbatim copying, provided also that the
120 entire resulting derived work is distributed under the terms of a
121 permission notice identical to this one.
122
123 Permission is granted to copy and distribute translations of this manual
124 into another language, under the above conditions for modified versions.
125 @end titlepage
126 @page
127
128 @ifinfo
129 @node Top
130 @top Debugging with @value{GDBN}
131
132 This file describes @value{GDBN}, the GNU symbolic debugger.
133
134 This is Edition @value{EDITION}, @value{DATE}, for GDB Version @value{GDBVN}.
135
136 @menu
137 * Summary:: Summary of @value{GDBN}
138 @ifset NOVEL
139 * New Features:: New features since GDB version 3.5
140 @end ifset
141 @ifclear BARETARGET
142 * Sample Session:: A sample @value{GDBN} session
143 @end ifclear
144
145 * Invocation:: Getting in and out of @value{GDBN}
146 * Commands:: @value{GDBN} commands
147 * Running:: Running programs under @value{GDBN}
148 * Stopping:: Stopping and continuing
149 * Stack:: Examining the stack
150 * Source:: Examining source files
151 * Data:: Examining data
152 @ifclear CONLY
153 * Languages:: Using @value{GDBN} with different languages
154 @end ifclear
155 @ifset CONLY
156 * C:: C language support
157 @end ifset
158 @c remnant makeinfo bug, blank line needed after two end-ifs?
159
160 * Symbols:: Examining the symbol table
161 * Altering:: Altering execution
162 * GDB Files:: @value{GDBN} files
163 * Targets:: Specifying a debugging target
164 * Controlling GDB:: Controlling @value{GDBN}
165 * Sequences:: Canned sequences of commands
166 @ifclear DOSHOST
167 * Emacs:: Using @value{GDBN} under GNU Emacs
168 @end ifclear
169
170 * GDB Bugs:: Reporting bugs in @value{GDBN}
171 * Command Line Editing:: Facilities of the readline library
172 * Using History Interactively::
173 @ifset NOVEL
174 * Renamed Commands::
175 @end ifset
176 @ifclear PRECONFIGURED
177 * Formatting Documentation:: How to format and print GDB documentation
178 * Installing GDB:: Installing GDB
179 @end ifclear
180
181 * Index:: Index
182 @end menu
183 @end ifinfo
184
185 @node Summary
186 @unnumbered Summary of @value{GDBN}
187
188 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
189 going on ``inside'' another program while it executes---or what another
190 program was doing at the moment it crashed.
191
192 @value{GDBN} can do four main kinds of things (plus other things in support of
193 these) to help you catch bugs in the act:
194
195 @itemize @bullet
196 @item
197 Start your program, specifying anything that might affect its behavior.
198
199 @item
200 Make your program stop on specified conditions.
201
202 @item
203 Examine what has happened, when your program has stopped.
204
205 @item
206 Change things in your program, so you can experiment with correcting the
207 effects of one bug and go on to learn about another.
208 @end itemize
209
210 @ifclear CONLY
211 You can use @value{GDBN} to debug programs written in C or C++.
212 @c "MOD2" used as a "miscellaneous languages" flag here.
213 @c This is acceptable while there is no real doc for Chill and Pascal.
214 @ifclear MOD2
215 For more information, see @ref{Support,,Supported languages}.
216 @end ifclear
217 @ifset MOD2
218 For more information, see @ref{C,,C and C++}.
219
220 Support for Modula-2 and Chill is partial. For information on Modula-2,
221 see @ref{Modula-2,,Modula-2}. There is no further documentation on Chill yet.
222
223 Debugging Pascal programs which use sets, subranges, file variables, or nested
224 functions does not currently work. @value{GDBN} does not support
225 entering expressions, printing values, or similar features using Pascal syntax.
226 @end ifset
227 @ifset FORTRAN
228 @cindex Fortran
229 @value{GDBN} can be used to debug programs written in Fortran, although
230 it does not yet support entering expressions, printing values, or
231 similar features using Fortran syntax. It may be necessary to refer to
232 some variables with a trailing underscore.
233 @end ifset
234 @end ifclear
235
236 @menu
237 * Free Software:: Freely redistributable software
238 * Contributors:: Contributors to GDB
239 @end menu
240
241 @node Free Software
242 @unnumberedsec Free software
243
244 @value{GDBN} is @dfn{free software}, protected by the GNU General Public License
245 (GPL). The GPL gives you the freedom to copy or adapt a licensed
246 program---but every person getting a copy also gets with it the
247 freedom to modify that copy (which means that they must get access to
248 the source code), and the freedom to distribute further copies.
249 Typical software companies use copyrights to limit your freedoms; the
250 Free Software Foundation uses the GPL to preserve these freedoms.
251
252 Fundamentally, the General Public License is a license which says that
253 you have these freedoms and that you cannot take these freedoms away
254 from anyone else.
255
256 @node Contributors
257 @unnumberedsec Contributors to GDB
258
259 Richard Stallman was the original author of GDB, and of many other GNU
260 programs. Many others have contributed to its development. This
261 section attempts to credit major contributors. One of the virtues of
262 free software is that everyone is free to contribute to it; with
263 regret, we cannot actually acknowledge everyone here. The file
264 @file{ChangeLog} in the GDB distribution approximates a blow-by-blow
265 account.
266
267 Changes much prior to version 2.0 are lost in the mists of time.
268
269 @quotation
270 @emph{Plea:} Additions to this section are particularly welcome. If you
271 or your friends (or enemies, to be evenhanded) have been unfairly
272 omitted from this list, we would like to add your names!
273 @end quotation
274
275 So that they may not regard their long labor as thankless, we
276 particularly thank those who shepherded GDB through major releases: Fred
277 Fish (releases 4.12, 4.11, 4.10, 4.9), Stu Grossman and John Gilmore (releases
278 4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and
279 3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy Smith (releases
280 3.2, 3.1, 3.0). As major maintainer of GDB for some period, each
281 contributed significantly to the structure, stability, and capabilities
282 of the entire debugger.
283
284 Richard Stallman, assisted at various times by Peter TerMaat, Chris
285 Hanson, and Richard Mlynarik, handled releases through 2.8.
286
287 @ifclear CONLY
288 Michael Tiemann is the author of most of the GNU C++ support in GDB,
289 with significant additional contributions from Per Bothner. James
290 Clark wrote the GNU C++ demangler. Early work on C++ was by Peter
291 TerMaat (who also did much general update work leading to release 3.0).
292 @end ifclear
293
294 GDB 4 uses the BFD subroutine library to examine multiple
295 object-file formats; BFD was a joint project of David V.
296 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
297
298 David Johnson wrote the original COFF support; Pace Willison did
299 the original support for encapsulated COFF.
300
301 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
302 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
303 support. Jean-Daniel Fekete contributed Sun 386i support. Chris
304 Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
305 Hasei contributed Sony/News OS 3 support. David Johnson contributed
306 Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
307 Keith Packard contributed NS32K support. Doug Rabson contributed
308 Acorn Risc Machine support. Chris Smith contributed Convex support
309 (and Fortran debugging). Jonathan Stone contributed Pyramid support.
310 Michael Tiemann contributed SPARC support. Tim Tucker contributed
311 support for the Gould NP1 and Gould Powernode. Pace Willison
312 contributed Intel 386 support. Jay Vosburgh contributed Symmetry
313 support.
314
315 Rich Schaefer and Peter Schauer helped with support of SunOS shared
316 libraries.
317
318 Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
319 several machine instruction sets.
320
321 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
322 develop remote debugging. Intel Corporation and Wind River Systems
323 contributed remote debugging modules for their products.
324
325 Brian Fox is the author of the readline libraries providing
326 command-line editing and command history.
327
328 Andrew Beers of SUNY Buffalo wrote the language-switching code,
329 @ifset MOD2
330 the Modula-2 support,
331 @end ifset
332 and contributed the Languages chapter of this manual.
333
334 Fred Fish wrote most of the support for Unix System Vr4.
335 @ifclear CONLY
336 He also enhanced the command-completion support to cover C++ overloaded
337 symbols.
338 @end ifclear
339
340 Hitachi America, Ltd. sponsored the support for Hitachi microprocessors.
341
342 @ifset NOVEL
343 @node New Features
344 @unnumbered New Features since GDB Version 3.5
345
346 @table @emph
347 @item Targets
348 Using the new command @code{target}, you can select at runtime whether
349 you are debugging local files, local processes, standalone systems over
350 a serial port, or realtime systems over a TCP/IP connection. The
351 command @code{load} can download programs into a remote system. Serial
352 stubs are available for Motorola 680x0, Intel 80386, and Sparc remote
353 systems; GDB also supports debugging realtime processes running under
354 VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a
355 debugger stub on the target system. Internally, GDB now uses a function
356 vector to mediate access to different targets; if you need to add your
357 own support for a remote protocol, this makes it much easier.
358
359 @item Watchpoints
360 GDB now sports watchpoints as well as breakpoints. You can use a
361 watchpoint to stop execution whenever the value of an expression
362 changes, without having to predict a particular place in your program
363 where this may happen.
364
365 @item Wide Output
366 Commands that issue wide output now insert newlines at places designed
367 to make the output more readable.
368
369 @item Object Code Formats
370 GDB uses a new library called the Binary File Descriptor (BFD) Library
371 to permit it to switch dynamically, without reconfiguration or
372 recompilation, between different object-file formats. Formats currently
373 supported are COFF, ELF, a.out, Intel 960 b.out, MIPS ECOFF, HPPA SOM
374 (with stabs debugging), and S-records; files may be read as .o files,
375 archive libraries, or core dumps. BFD is available as a subroutine
376 library so that other programs may take advantage of it, and the other
377 GNU binary utilities are being converted to use it.
378
379 @item Configuration and Ports
380 Compile-time configuration (to select a particular architecture and
381 operating system) is much easier. The script @code{configure} now
382 allows you to configure GDB as either a native debugger or a
383 cross-debugger. @xref{Installing GDB}, for details on how to
384 configure.
385
386 @item Interaction
387 The user interface to the GDB control variables is simpler,
388 and is consolidated in two commands, @code{set} and @code{show}. Output
389 lines are now broken at readable places, rather than overflowing onto
390 the next line. You can suppress output of machine-level addresses,
391 displaying only source language information.
392
393 @item C++
394 GDB now supports C++ multiple inheritance (if used with a GCC
395 version 2 compiler), and also has limited support for C++ exception
396 handling, with the commands @code{catch} and @code{info catch}: GDB
397 can break when an exception is raised, before the stack is peeled back
398 to the exception handler's context.
399
400 @ifset MOD2
401 @item Modula-2
402 GDB now has preliminary support for the GNU Modula-2 compiler, currently
403 under development at the State University of New York at Buffalo.
404 Coordinated development of both GDB and the GNU Modula-2 compiler will
405 continue. Other Modula-2 compilers are currently not supported, and
406 attempting to debug programs compiled with them will likely result in an
407 error as the symbol table of the executable is read in.
408 @end ifset
409
410 @item Command Rationalization
411 Many GDB commands have been renamed to make them easier to remember
412 and use. In particular, the subcommands of @code{info} and
413 @code{show}/@code{set} are grouped to make the former refer to the state
414 of your program, and the latter refer to the state of GDB itself.
415 @xref{Renamed Commands}, for details on what commands were renamed.
416
417 @item Shared Libraries
418 GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000
419 shared libraries.
420
421 @item Threads
422 On some systems, GDB 4 has facilities to debug multi-thread programs.
423
424 @item Reference Card
425 GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting
426 the Documentation}, for instructions about how to print it.
427 @end table
428 @end ifset
429
430 @ifclear BARETARGET
431 @node Sample Session
432 @chapter A Sample @value{GDBN} Session
433
434 You can use this manual at your leisure to read all about @value{GDBN}.
435 However, a handful of commands are enough to get started using the
436 debugger. This chapter illustrates those commands.
437
438 @iftex
439 In this sample session, we emphasize user input like this: @b{input},
440 to make it easier to pick out from the surrounding output.
441 @end iftex
442
443 @c FIXME: this example may not be appropriate for some configs, where
444 @c FIXME...primary interest is in remote use.
445
446 One of the preliminary versions of GNU @code{m4} (a generic macro
447 processor) exhibits the following bug: sometimes, when we change its
448 quote strings from the default, the commands used to capture one macro
449 definition within another stop working. In the following short @code{m4}
450 session, we define a macro @code{foo} which expands to @code{0000}; we
451 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
452 same thing. However, when we change the open quote string to
453 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
454 procedure fails to define a new synonym @code{baz}:
455
456 @smallexample
457 $ @b{cd gnu/m4}
458 $ @b{./m4}
459 @b{define(foo,0000)}
460
461 @b{foo}
462 0000
463 @b{define(bar,defn(`foo'))}
464
465 @b{bar}
466 0000
467 @b{changequote(<QUOTE>,<UNQUOTE>)}
468
469 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
470 @b{baz}
471 @b{C-d}
472 m4: End of input: 0: fatal error: EOF in string
473 @end smallexample
474
475 @noindent
476 Let us use @value{GDBN} to try to see what is going on.
477
478 @smallexample
479 $ @b{@value{GDBP} m4}
480 @c FIXME: this falsifies the exact text played out, to permit smallbook
481 @c FIXME... format to come out better.
482 GDB is free software and you are welcome to distribute copies
483 of it under certain conditions; type "show copying" to see
484 the conditions.
485 There is absolutely no warranty for GDB; type "show warranty"
486 for details.
487 GDB @value{GDBVN}, Copyright 1993 Free Software Foundation, Inc...
488 (@value{GDBP})
489 @end smallexample
490
491 @noindent
492 @value{GDBN} reads only enough symbol data to know where to find the
493 rest when needed; as a result, the first prompt comes up very quickly.
494 We now tell @value{GDBN} to use a narrower display width than usual, so
495 that examples fit in this manual.
496
497 @smallexample
498 (@value{GDBP}) @b{set width 70}
499 @end smallexample
500
501 @noindent
502 We need to see how the @code{m4} built-in @code{changequote} works.
503 Having looked at the source, we know the relevant subroutine is
504 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
505 @code{break} command.
506
507 @smallexample
508 (@value{GDBP}) @b{break m4_changequote}
509 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
510 @end smallexample
511
512 @noindent
513 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
514 control; as long as control does not reach the @code{m4_changequote}
515 subroutine, the program runs as usual:
516
517 @smallexample
518 (@value{GDBP}) @b{run}
519 Starting program: /work/Editorial/gdb/gnu/m4/m4
520 @b{define(foo,0000)}
521
522 @b{foo}
523 0000
524 @end smallexample
525
526 @noindent
527 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
528 suspends execution of @code{m4}, displaying information about the
529 context where it stops.
530
531 @smallexample
532 @b{changequote(<QUOTE>,<UNQUOTE>)}
533
534 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
535 at builtin.c:879
536 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
537 @end smallexample
538
539 @noindent
540 Now we use the command @code{n} (@code{next}) to advance execution to
541 the next line of the current function.
542
543 @smallexample
544 (@value{GDBP}) @b{n}
545 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
546 : nil,
547 @end smallexample
548
549 @noindent
550 @code{set_quotes} looks like a promising subroutine. We can go into it
551 by using the command @code{s} (@code{step}) instead of @code{next}.
552 @code{step} goes to the next line to be executed in @emph{any}
553 subroutine, so it steps into @code{set_quotes}.
554
555 @smallexample
556 (@value{GDBP}) @b{s}
557 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
558 at input.c:530
559 530 if (lquote != def_lquote)
560 @end smallexample
561
562 @noindent
563 The display that shows the subroutine where @code{m4} is now
564 suspended (and its arguments) is called a stack frame display. It
565 shows a summary of the stack. We can use the @code{backtrace}
566 command (which can also be spelled @code{bt}), to see where we are
567 in the stack as a whole: the @code{backtrace} command displays a
568 stack frame for each active subroutine.
569
570 @smallexample
571 (@value{GDBP}) @b{bt}
572 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
573 at input.c:530
574 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
575 at builtin.c:882
576 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
577 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
578 at macro.c:71
579 #4 0x79dc in expand_input () at macro.c:40
580 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
581 @end smallexample
582
583 @noindent
584 We step through a few more lines to see what happens. The first two
585 times, we can use @samp{s}; the next two times we use @code{n} to avoid
586 falling into the @code{xstrdup} subroutine.
587
588 @smallexample
589 (@value{GDBP}) @b{s}
590 0x3b5c 532 if (rquote != def_rquote)
591 (@value{GDBP}) @b{s}
592 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
593 def_lquote : xstrdup(lq);
594 (@value{GDBP}) @b{n}
595 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
596 : xstrdup(rq);
597 (@value{GDBP}) @b{n}
598 538 len_lquote = strlen(rquote);
599 @end smallexample
600
601 @noindent
602 The last line displayed looks a little odd; we can examine the variables
603 @code{lquote} and @code{rquote} to see if they are in fact the new left
604 and right quotes we specified. We use the command @code{p}
605 (@code{print}) to see their values.
606
607 @smallexample
608 (@value{GDBP}) @b{p lquote}
609 $1 = 0x35d40 "<QUOTE>"
610 (@value{GDBP}) @b{p rquote}
611 $2 = 0x35d50 "<UNQUOTE>"
612 @end smallexample
613
614 @noindent
615 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
616 To look at some context, we can display ten lines of source
617 surrounding the current line with the @code{l} (@code{list}) command.
618
619 @smallexample
620 (@value{GDBP}) @b{l}
621 533 xfree(rquote);
622 534
623 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
624 : xstrdup (lq);
625 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
626 : xstrdup (rq);
627 537
628 538 len_lquote = strlen(rquote);
629 539 len_rquote = strlen(lquote);
630 540 @}
631 541
632 542 void
633 @end smallexample
634
635 @noindent
636 Let us step past the two lines that set @code{len_lquote} and
637 @code{len_rquote}, and then examine the values of those variables.
638
639 @smallexample
640 (@value{GDBP}) @b{n}
641 539 len_rquote = strlen(lquote);
642 (@value{GDBP}) @b{n}
643 540 @}
644 (@value{GDBP}) @b{p len_lquote}
645 $3 = 9
646 (@value{GDBP}) @b{p len_rquote}
647 $4 = 7
648 @end smallexample
649
650 @noindent
651 That certainly looks wrong, assuming @code{len_lquote} and
652 @code{len_rquote} are meant to be the lengths of @code{lquote} and
653 @code{rquote} respectively. We can set them to better values using
654 the @code{p} command, since it can print the value of
655 any expression---and that expression can include subroutine calls and
656 assignments.
657
658 @smallexample
659 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
660 $5 = 7
661 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
662 $6 = 9
663 @end smallexample
664
665 @noindent
666 Is that enough to fix the problem of using the new quotes with the
667 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
668 executing with the @code{c} (@code{continue}) command, and then try the
669 example that caused trouble initially:
670
671 @smallexample
672 (@value{GDBP}) @b{c}
673 Continuing.
674
675 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
676
677 baz
678 0000
679 @end smallexample
680
681 @noindent
682 Success! The new quotes now work just as well as the default ones. The
683 problem seems to have been just the two typos defining the wrong
684 lengths. We allow @code{m4} exit by giving it an EOF as input:
685
686 @smallexample
687 @b{C-d}
688 Program exited normally.
689 @end smallexample
690
691 @noindent
692 The message @samp{Program exited normally.} is from @value{GDBN}; it
693 indicates @code{m4} has finished executing. We can end our @value{GDBN}
694 session with the @value{GDBN} @code{quit} command.
695
696 @smallexample
697 (@value{GDBP}) @b{quit}
698 @end smallexample
699 @end ifclear
700
701 @node Invocation
702 @chapter Getting In and Out of @value{GDBN}
703
704 This chapter discusses how to start @value{GDBN}, and how to get out of it.
705 (The essentials: type @samp{@value{GDBP}} to start GDB, and type @kbd{quit}
706 or @kbd{C-d} to exit.)
707
708 @menu
709 * Invoking GDB:: How to start @value{GDBN}
710 * Quitting GDB:: How to quit @value{GDBN}
711 * Shell Commands:: How to use shell commands inside @value{GDBN}
712 @end menu
713
714 @node Invoking GDB
715 @section Invoking @value{GDBN}
716
717 @ifset H8EXCLUSIVE
718 For details on starting up @value{GDBP} as a
719 remote debugger attached to a Hitachi microprocessor, see @ref{Hitachi
720 Remote,,@value{GDBN} and Hitachi Microprocessors}.
721 @end ifset
722
723 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
724 @value{GDBN} reads commands from the terminal until you tell it to exit.
725
726 You can also run @code{@value{GDBP}} with a variety of arguments and options,
727 to specify more of your debugging environment at the outset.
728
729 @ifset GENERIC
730 The command-line options described here are designed
731 to cover a variety of situations; in some environments, some of these
732 options may effectively be unavailable.
733 @end ifset
734
735 The most usual way to start @value{GDBN} is with one argument,
736 specifying an executable program:
737
738 @example
739 @value{GDBP} @var{program}
740 @end example
741
742 @ifclear BARETARGET
743 @noindent
744 You can also start with both an executable program and a core file
745 specified:
746
747 @example
748 @value{GDBP} @var{program} @var{core}
749 @end example
750
751 You can, instead, specify a process ID as a second argument, if you want
752 to debug a running process:
753
754 @example
755 @value{GDBP} @var{program} 1234
756 @end example
757
758 @noindent
759 would attach @value{GDBN} to process @code{1234} (unless you also have a file
760 named @file{1234}; @value{GDBN} does check for a core file first).
761
762 Taking advantage of the second command-line argument requires a fairly
763 complete operating system; when you use @value{GDBN} as a remote debugger
764 attached to a bare board, there may not be any notion of ``process'',
765 and there is often no way to get a core dump.
766 @end ifclear
767
768 @noindent
769 You can further control how @value{GDBN} starts up by using command-line
770 options. @value{GDBN} itself can remind you of the options available.
771
772 @noindent
773 Type
774
775 @example
776 @value{GDBP} -help
777 @end example
778
779 @noindent
780 to display all available options and briefly describe their use
781 (@samp{@value{GDBP} -h} is a shorter equivalent).
782
783 All options and command line arguments you give are processed
784 in sequential order. The order makes a difference when the
785 @samp{-x} option is used.
786
787
788 @menu
789 @ifclear GENERIC
790 @ifset REMOTESTUB
791 * Remote Serial:: @value{GDBN} remote serial protocol
792 @end ifset
793 @ifset I960
794 * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy)
795 @end ifset
796 @ifset AMD29K
797 * UDI29K Remote:: The UDI protocol for AMD29K
798 * EB29K Remote:: The EBMON protocol for AMD29K
799 @end ifset
800 @ifset VXWORKS
801 * VxWorks Remote:: @value{GDBN} and VxWorks
802 @end ifset
803 @ifset ST2000
804 * ST2000 Remote:: @value{GDBN} with a Tandem ST2000
805 @end ifset
806 @ifset H8
807 * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors
808 @end ifset
809 @ifset MIPS
810 * MIPS Remote:: @value{GDBN} and MIPS boards
811 @end ifset
812 @ifset SIMS
813 * Simulator:: Simulated CPU target
814 @end ifset
815 @end ifclear
816 @c remnant makeinfo bug requires this blank line after *two* end-ifblahs:
817
818 * File Options:: Choosing files
819 * Mode Options:: Choosing modes
820 @end menu
821
822 @ifclear GENERIC
823 @include remote.texi
824 @end ifclear
825
826 @node File Options
827 @subsection Choosing files
828
829 @ifclear BARETARGET
830 When @value{GDBN} starts, it reads any arguments other than options as
831 specifying an executable file and core file (or process ID). This is
832 the same as if the arguments were specified by the @samp{-se} and
833 @samp{-c} options respectively. (@value{GDBN} reads the first argument
834 that does not have an associated option flag as equivalent to the
835 @samp{-se} option followed by that argument; and the second argument
836 that does not have an associated option flag, if any, as equivalent to
837 the @samp{-c} option followed by that argument.)
838 @end ifclear
839 @ifset BARETARGET
840 When @value{GDBN} starts, it reads any argument other than options as
841 specifying an executable file. This is the same as if the argument was
842 specified by the @samp{-se} option.
843 @end ifset
844
845 Many options have both long and short forms; both are shown in the
846 following list. @value{GDBN} also recognizes the long forms if you truncate
847 them, so long as enough of the option is present to be unambiguous.
848 (If you prefer, you can flag option arguments with @samp{--} rather
849 than @samp{-}, though we illustrate the more usual convention.)
850
851 @table @code
852 @item -symbols @var{file}
853 @itemx -s @var{file}
854 Read symbol table from file @var{file}.
855
856 @item -exec @var{file}
857 @itemx -e @var{file}
858 Use file @var{file} as the executable file to execute when
859 @ifset BARETARGET
860 appropriate.
861 @end ifset
862 @ifclear BARETARGET
863 appropriate, and for examining pure data in conjunction with a core
864 dump.
865 @end ifclear
866
867 @item -se @var{file}
868 Read symbol table from file @var{file} and use it as the executable
869 file.
870
871 @ifclear BARETARGET
872 @item -core @var{file}
873 @itemx -c @var{file}
874 Use file @var{file} as a core dump to examine.
875
876 @item -c @var{number}
877 Connect to process ID @var{number}, as with the @code{attach} command
878 (unless there is a file in core-dump format named @var{number}, in which
879 case @samp{-c} specifies that file as a core dump to read).
880 @end ifclear
881
882 @item -command @var{file}
883 @itemx -x @var{file}
884 Execute @value{GDBN} commands from file @var{file}. @xref{Command
885 Files,, Command files}.
886
887 @item -directory @var{directory}
888 @itemx -d @var{directory}
889 Add @var{directory} to the path to search for source files.
890
891 @ifclear BARETARGET
892 @item -m
893 @itemx -mapped
894 @emph{Warning: this option depends on operating system facilities that are not
895 supported on all systems.}@*
896 If memory-mapped files are available on your system through the @code{mmap}
897 system call, you can use this option
898 to have @value{GDBN} write the symbols from your
899 program into a reusable file in the current directory. If the program you are debugging is
900 called @file{/tmp/fred}, the mapped symbol file is @file{./fred.syms}.
901 Future @value{GDBN} debugging sessions notice the presence of this file,
902 and can quickly map in symbol information from it, rather than reading
903 the symbol table from the executable program.
904
905 @c FIXME! Really host, not target?
906 The @file{.syms} file is specific to the host machine where @value{GDBN}
907 is run. It holds an exact image of the internal @value{GDBN} symbol
908 table. It cannot be shared across multiple host platforms.
909 @end ifclear
910
911 @item -r
912 @itemx -readnow
913 Read each symbol file's entire symbol table immediately, rather than
914 the default, which is to read it incrementally as it is needed.
915 This makes startup slower, but makes future operations faster.
916 @end table
917
918 @ifclear BARETARGET
919 The @code{-mapped} and @code{-readnow} options are typically combined in
920 order to build a @file{.syms} file that contains complete symbol
921 information. (@xref{Files,,Commands to specify files}, for information
922 on @file{.syms} files.) A simple GDB invocation to do nothing but build
923 a @file{.syms} file for future use is:
924
925 @example
926 gdb -batch -nx -mapped -readnow programname
927 @end example
928 @end ifclear
929
930 @node Mode Options
931 @subsection Choosing modes
932
933 You can run @value{GDBN} in various alternative modes---for example, in
934 batch mode or quiet mode.
935
936 @table @code
937 @item -nx
938 @itemx -n
939 Do not execute commands from any initialization files (normally called
940 @file{@value{GDBINIT}}). Normally, the commands in these files are
941 executed after all the command options and arguments have been
942 processed. @xref{Command Files,,Command files}.
943
944 @item -quiet
945 @itemx -q
946 ``Quiet''. Do not print the introductory and copyright messages. These
947 messages are also suppressed in batch mode.
948
949 @item -batch
950 Run in batch mode. Exit with status @code{0} after processing all the
951 command files specified with @samp{-x} (and all commands from
952 initialization files, if not inhibited with @samp{-n}). Exit with
953 nonzero status if an error occurs in executing the @value{GDBN} commands
954 in the command files.
955
956 Batch mode may be useful for running @value{GDBN} as a filter, for example to
957 download and run a program on another computer; in order to make this
958 more useful, the message
959
960 @example
961 Program exited normally.
962 @end example
963
964 @noindent
965 (which is ordinarily issued whenever a program running under @value{GDBN} control
966 terminates) is not issued when running in batch mode.
967
968 @item -cd @var{directory}
969 Run @value{GDBN} using @var{directory} as its working directory,
970 instead of the current directory.
971
972 @ifset LUCID
973 @item -context @var{authentication}
974 When the Energize programming system starts up @value{GDBN}, it uses this
975 option to trigger an alternate mode of interaction.
976 @var{authentication} is a pair of numeric codes that identify @value{GDBN}
977 as a client in the Energize environment. Avoid this option when you run
978 @value{GDBN} directly from the command line. See @ref{Energize,,Using
979 @value{GDBN} with Energize} for more discussion of using @value{GDBN} with Energize.
980 @end ifset
981
982 @ifclear DOSHOST
983 @item -fullname
984 @itemx -f
985 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells @value{GDBN}
986 to output the full file name and line number in a standard,
987 recognizable fashion each time a stack frame is displayed (which
988 includes each time your program stops). This recognizable format looks
989 like two @samp{\032} characters, followed by the file name, line number
990 and character position separated by colons, and a newline. The
991 Emacs-to-@value{GDBN} interface program uses the two @samp{\032} characters as
992 a signal to display the source code for the frame.
993 @end ifclear
994
995 @ifset SERIAL
996 @item -b @var{bps}
997 Set the line speed (baud rate or bits per second) of any serial
998 interface used by @value{GDBN} for remote debugging.
999
1000 @item -tty @var{device}
1001 Run using @var{device} for your program's standard input and output.
1002 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1003 @end ifset
1004 @end table
1005
1006 @node Quitting GDB
1007 @section Quitting @value{GDBN}
1008 @cindex exiting @value{GDBN}
1009 @cindex leaving @value{GDBN}
1010
1011 @table @code
1012 @item quit
1013 @kindex quit
1014 @kindex q
1015 To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or type
1016 an end-of-file character (usually @kbd{C-d}).
1017 @end table
1018
1019 @cindex interrupt
1020 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1021 terminates the action of any @value{GDBN} command that is in progress and
1022 returns to @value{GDBN} command level. It is safe to type the interrupt
1023 character at any time because @value{GDBN} does not allow it to take effect
1024 until a time when it is safe.
1025
1026 @ifclear BARETARGET
1027 If you have been using @value{GDBN} to control an attached process or
1028 device, you can release it with the @code{detach} command
1029 (@pxref{Attach, ,Debugging an already-running process}).
1030 @end ifclear
1031
1032 @node Shell Commands
1033 @section Shell commands
1034
1035 If you need to execute occasional shell commands during your
1036 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1037 just use the @code{shell} command.
1038
1039 @table @code
1040 @item shell @var{command string}
1041 @kindex shell
1042 @cindex shell escape
1043 Invoke a the standard shell to execute @var{command string}.
1044 @ifclear DOSHOST
1045 If it exists, the environment variable @code{SHELL} determines which
1046 shell to run. Otherwise @value{GDBN} uses @code{/bin/sh}.
1047 @end ifclear
1048 @end table
1049
1050 The utility @code{make} is often needed in development environments.
1051 You do not have to use the @code{shell} command for this purpose in
1052 @value{GDBN}:
1053
1054 @table @code
1055 @item make @var{make-args}
1056 @kindex make
1057 @cindex calling make
1058 Execute the @code{make} program with the specified
1059 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1060 @end table
1061
1062 @node Commands
1063 @chapter @value{GDBN} Commands
1064
1065 You can abbreviate a @value{GDBN} command to the first few letters of the command
1066 name, if that abbreviation is unambiguous; and you can repeat certain
1067 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1068 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1069 show you the alternatives available, if there is more than one possibility).
1070
1071 @menu
1072 * Command Syntax:: How to give commands to @value{GDBN}
1073 * Completion:: Command completion
1074 * Help:: How to ask @value{GDBN} for help
1075 @end menu
1076
1077 @node Command Syntax
1078 @section Command syntax
1079
1080 A @value{GDBN} command is a single line of input. There is no limit on
1081 how long it can be. It starts with a command name, which is followed by
1082 arguments whose meaning depends on the command name. For example, the
1083 command @code{step} accepts an argument which is the number of times to
1084 step, as in @samp{step 5}. You can also use the @code{step} command
1085 with no arguments. Some command names do not allow any arguments.
1086
1087 @cindex abbreviation
1088 @value{GDBN} command names may always be truncated if that abbreviation is
1089 unambiguous. Other possible command abbreviations are listed in the
1090 documentation for individual commands. In some cases, even ambiguous
1091 abbreviations are allowed; for example, @code{s} is specially defined as
1092 equivalent to @code{step} even though there are other commands whose
1093 names start with @code{s}. You can test abbreviations by using them as
1094 arguments to the @code{help} command.
1095
1096 @cindex repeating commands
1097 @kindex RET
1098 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1099 repeat the previous command. Certain commands (for example, @code{run})
1100 will not repeat this way; these are commands whose unintentional
1101 repetition might cause trouble and which you are unlikely to want to
1102 repeat.
1103
1104 The @code{list} and @code{x} commands, when you repeat them with
1105 @key{RET}, construct new arguments rather than repeating
1106 exactly as typed. This permits easy scanning of source or memory.
1107
1108 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1109 output, in a way similar to the common utility @code{more}
1110 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1111 @key{RET} too many in this situation, @value{GDBN} disables command
1112 repetition after any command that generates this sort of display.
1113
1114 @kindex #
1115 @cindex comment
1116 Any text from a @kbd{#} to the end of the line is a comment; it does
1117 nothing. This is useful mainly in command files (@pxref{Command
1118 Files,,Command files}).
1119
1120 @node Completion
1121 @section Command completion
1122
1123 @cindex completion
1124 @cindex word completion
1125 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1126 only one possibility; it can also show you what the valid possibilities
1127 are for the next word in a command, at any time. This works for @value{GDBN}
1128 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1129
1130 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1131 of a word. If there is only one possibility, @value{GDBN} fills in the
1132 word, and waits for you to finish the command (or press @key{RET} to
1133 enter it). For example, if you type
1134
1135 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1136 @c complete accuracy in these examples; space introduced for clarity.
1137 @c If texinfo enhancements make it unnecessary, it would be nice to
1138 @c replace " @key" by "@key" in the following...
1139 @example
1140 (@value{GDBP}) info bre @key{TAB}
1141 @end example
1142
1143 @noindent
1144 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1145 the only @code{info} subcommand beginning with @samp{bre}:
1146
1147 @example
1148 (@value{GDBP}) info breakpoints
1149 @end example
1150
1151 @noindent
1152 You can either press @key{RET} at this point, to run the @code{info
1153 breakpoints} command, or backspace and enter something else, if
1154 @samp{breakpoints} does not look like the command you expected. (If you
1155 were sure you wanted @code{info breakpoints} in the first place, you
1156 might as well just type @key{RET} immediately after @samp{info bre},
1157 to exploit command abbreviations rather than command completion).
1158
1159 If there is more than one possibility for the next word when you press
1160 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1161 characters and try again, or just press @key{TAB} a second time;
1162 @value{GDBN} displays all the possible completions for that word. For
1163 example, you might want to set a breakpoint on a subroutine whose name
1164 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1165 just sounds the bell. Typing @key{TAB} again displays all the
1166 function names in your program that begin with those characters, for
1167 example:
1168
1169 @example
1170 (@value{GDBP}) b make_ @key{TAB}
1171 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1172 make_a_section_from_file make_environ
1173 make_abs_section make_function_type
1174 make_blockvector make_pointer_type
1175 make_cleanup make_reference_type
1176 make_command make_symbol_completion_list
1177 (@value{GDBP}) b make_
1178 @end example
1179
1180 @noindent
1181 After displaying the available possibilities, @value{GDBN} copies your
1182 partial input (@samp{b make_} in the example) so you can finish the
1183 command.
1184
1185 If you just want to see the list of alternatives in the first place, you
1186 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1187 means @kbd{@key{META} ?}. You can type this
1188 @ifclear DOSHOST
1189 either by holding down a
1190 key designated as the @key{META} shift on your keyboard (if there is
1191 one) while typing @kbd{?}, or
1192 @end ifclear
1193 as @key{ESC} followed by @kbd{?}.
1194
1195 @cindex quotes in commands
1196 @cindex completion of quoted strings
1197 Sometimes the string you need, while logically a ``word'', may contain
1198 parentheses or other characters that @value{GDBN} normally excludes from its
1199 notion of a word. To permit word completion to work in this situation,
1200 you may enclose words in @code{'} (single quote marks) in @value{GDBN} commands.
1201
1202 @ifclear CONLY
1203 The most likely situation where you might need this is in typing the
1204 name of a C++ function. This is because C++ allows function overloading
1205 (multiple definitions of the same function, distinguished by argument
1206 type). For example, when you want to set a breakpoint you may need to
1207 distinguish whether you mean the version of @code{name} that takes an
1208 @code{int} parameter, @code{name(int)}, or the version that takes a
1209 @code{float} parameter, @code{name(float)}. To use the word-completion
1210 facilities in this situation, type a single quote @code{'} at the
1211 beginning of the function name. This alerts @value{GDBN} that it may need to
1212 consider more information than usual when you press @key{TAB} or
1213 @kbd{M-?} to request word completion:
1214
1215 @example
1216 (@value{GDBP}) b 'bubble( @key{M-?}
1217 bubble(double,double) bubble(int,int)
1218 (@value{GDBP}) b 'bubble(
1219 @end example
1220
1221 In some cases, @value{GDBN} can tell that completing a name requires using
1222 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1223 completing as much as it can) if you do not type the quote in the first
1224 place:
1225
1226 @example
1227 (@value{GDBP}) b bub @key{TAB}
1228 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1229 (@value{GDBP}) b 'bubble(
1230 @end example
1231
1232 @noindent
1233 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1234 you have not yet started typing the argument list when you ask for
1235 completion on an overloaded symbol.
1236 @end ifclear
1237
1238
1239 @node Help
1240 @section Getting help
1241 @cindex online documentation
1242 @kindex help
1243
1244 You can always ask @value{GDBN} itself for information on its commands, using the
1245 command @code{help}.
1246
1247 @table @code
1248 @item help
1249 @itemx h
1250 @kindex h
1251 You can use @code{help} (abbreviated @code{h}) with no arguments to
1252 display a short list of named classes of commands:
1253
1254 @smallexample
1255 (@value{GDBP}) help
1256 List of classes of commands:
1257
1258 running -- Running the program
1259 stack -- Examining the stack
1260 data -- Examining data
1261 breakpoints -- Making program stop at certain points
1262 files -- Specifying and examining files
1263 status -- Status inquiries
1264 support -- Support facilities
1265 user-defined -- User-defined commands
1266 aliases -- Aliases of other commands
1267 obscure -- Obscure features
1268
1269 Type "help" followed by a class name for a list of
1270 commands in that class.
1271 Type "help" followed by command name for full
1272 documentation.
1273 Command name abbreviations are allowed if unambiguous.
1274 (@value{GDBP})
1275 @end smallexample
1276
1277 @item help @var{class}
1278 Using one of the general help classes as an argument, you can get a
1279 list of the individual commands in that class. For example, here is the
1280 help display for the class @code{status}:
1281
1282 @smallexample
1283 (@value{GDBP}) help status
1284 Status inquiries.
1285
1286 List of commands:
1287
1288 @c Line break in "show" line falsifies real output, but needed
1289 @c to fit in smallbook page size.
1290 show -- Generic command for showing things set
1291 with "set"
1292 info -- Generic command for printing status
1293
1294 Type "help" followed by command name for full
1295 documentation.
1296 Command name abbreviations are allowed if unambiguous.
1297 (@value{GDBP})
1298 @end smallexample
1299
1300 @item help @var{command}
1301 With a command name as @code{help} argument, @value{GDBN} displays a
1302 short paragraph on how to use that command.
1303 @end table
1304
1305 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1306 and @code{show} to inquire about the state of your program, or the state
1307 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1308 manual introduces each of them in the appropriate context. The listings
1309 under @code{info} and under @code{show} in the Index point to
1310 all the sub-commands. @xref{Index}.
1311
1312 @c @group
1313 @table @code
1314 @item info
1315 @kindex info
1316 @kindex i
1317 This command (abbreviated @code{i}) is for describing the state of your
1318 program. For example, you can list the arguments given to your program
1319 with @code{info args}, list the registers currently in use with @code{info
1320 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1321 You can get a complete list of the @code{info} sub-commands with
1322 @w{@code{help info}}.
1323
1324 @kindex show
1325 @item show
1326 In contrast, @code{show} is for describing the state of @value{GDBN} itself.
1327 You can change most of the things you can @code{show}, by using the
1328 related command @code{set}; for example, you can control what number
1329 system is used for displays with @code{set radix}, or simply inquire
1330 which is currently in use with @code{show radix}.
1331
1332 @kindex info set
1333 To display all the settable parameters and their current
1334 values, you can use @code{show} with no arguments; you may also use
1335 @code{info set}. Both commands produce the same display.
1336 @c FIXME: "info set" violates the rule that "info" is for state of
1337 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1338 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1339 @end table
1340 @c @end group
1341
1342 Here are three miscellaneous @code{show} subcommands, all of which are
1343 exceptional in lacking corresponding @code{set} commands:
1344
1345 @table @code
1346 @kindex show version
1347 @cindex version number
1348 @item show version
1349 Show what version of @value{GDBN} is running. You should include this
1350 information in @value{GDBN} bug-reports. If multiple versions of @value{GDBN} are in
1351 use at your site, you may occasionally want to determine which version
1352 of @value{GDBN} you are running; as @value{GDBN} evolves, new commands are introduced,
1353 and old ones may wither away. The version number is also announced
1354 when you start @value{GDBN}.
1355
1356 @kindex show copying
1357 @item show copying
1358 Display information about permission for copying @value{GDBN}.
1359
1360 @kindex show warranty
1361 @item show warranty
1362 Display the GNU ``NO WARRANTY'' statement.
1363 @end table
1364
1365 @node Running
1366 @chapter Running Programs Under @value{GDBN}
1367
1368 When you run a program under @value{GDBN}, you must first generate
1369 debugging information when you compile it.
1370 @ifclear BARETARGET
1371 You may start it with its arguments, if any, in an environment of your
1372 choice. You may redirect your program's input and output, debug an
1373 already running process, or kill a child process.
1374 @end ifclear
1375
1376 @menu
1377 * Compilation:: Compiling for debugging
1378 * Starting:: Starting your program
1379 @ifclear BARETARGET
1380 * Arguments:: Your program's arguments
1381 * Environment:: Your program's environment
1382 * Working Directory:: Your program's working directory
1383 * Input/Output:: Your program's input and output
1384 * Attach:: Debugging an already-running process
1385 * Kill Process:: Killing the child process
1386 * Process Information:: Additional process information
1387 * Threads:: Debugging programs with multiple threads
1388 @end ifclear
1389 @end menu
1390
1391 @node Compilation
1392 @section Compiling for debugging
1393
1394 In order to debug a program effectively, you need to generate
1395 debugging information when you compile it. This debugging information
1396 is stored in the object file; it describes the data type of each
1397 variable or function and the correspondence between source line numbers
1398 and addresses in the executable code.
1399
1400 To request debugging information, specify the @samp{-g} option when you run
1401 the compiler.
1402
1403 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1404 options together. Using those compilers, you cannot generate optimized
1405 executables containing debugging information.
1406
1407 @value{NGCC}, the GNU C compiler, supports @samp{-g} with or without
1408 @samp{-O}, making it possible to debug optimized code. We recommend
1409 that you @emph{always} use @samp{-g} whenever you compile a program.
1410 You may think your program is correct, but there is no sense in pushing
1411 your luck.
1412
1413 @cindex optimized code, debugging
1414 @cindex debugging optimized code
1415 When you debug a program compiled with @samp{-g -O}, remember that the
1416 optimizer is rearranging your code; the debugger shows you what is
1417 really there. Do not be too surprised when the execution path does not
1418 exactly match your source file! An extreme example: if you define a
1419 variable, but never use it, @value{GDBN} never sees that
1420 variable---because the compiler optimizes it out of existence.
1421
1422 Some things do not work as well with @samp{-g -O} as with just
1423 @samp{-g}, particularly on machines with instruction scheduling. If in
1424 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1425 please report it as a bug (including a test case!).
1426
1427 Older versions of the GNU C compiler permitted a variant option
1428 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1429 format; if your GNU C compiler has this option, do not use it.
1430
1431 @need 2000
1432 @node Starting
1433 @section Starting your program
1434 @cindex starting
1435 @cindex running
1436
1437 @table @code
1438 @item run
1439 @itemx r
1440 @kindex run
1441 Use the @code{run} command to start your program under @value{GDBN}. You must
1442 first specify the program name
1443 @ifset VXWORKS
1444 (except on VxWorks)
1445 @end ifset
1446 with an argument to @value{GDBN} (@pxref{Invocation, ,Getting In and
1447 Out of @value{GDBN}}), or by using the @code{file} or @code{exec-file}
1448 command (@pxref{Files, ,Commands to specify files}).
1449
1450 @end table
1451
1452 @ifclear BARETARGET
1453 If you are running your program in an execution environment that
1454 supports processes, @code{run} creates an inferior process and makes
1455 that process run your program. (In environments without processes,
1456 @code{run} jumps to the start of your program.)
1457
1458 The execution of a program is affected by certain information it
1459 receives from its superior. @value{GDBN} provides ways to specify this
1460 information, which you must do @emph{before} starting your program. (You
1461 can change it after starting your program, but such changes only affect
1462 your program the next time you start it.) This information may be
1463 divided into four categories:
1464
1465 @table @asis
1466 @item The @emph{arguments.}
1467 Specify the arguments to give your program as the arguments of the
1468 @code{run} command. If a shell is available on your target, the shell
1469 is used to pass the arguments, so that you may use normal conventions
1470 (such as wildcard expansion or variable substitution) in describing
1471 the arguments. In Unix systems, you can control which shell is used
1472 with the @code{SHELL} environment variable. @xref{Arguments, ,Your
1473 program's arguments}.
1474
1475 @item The @emph{environment.}
1476 Your program normally inherits its environment from @value{GDBN}, but you can
1477 use the @value{GDBN} commands @code{set environment} and @code{unset
1478 environment} to change parts of the environment that affect
1479 your program. @xref{Environment, ,Your program's environment}.
1480
1481 @item The @emph{working directory.}
1482 Your program inherits its working directory from @value{GDBN}. You can set
1483 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1484 @xref{Working Directory, ,Your program's working directory}.
1485
1486 @item The @emph{standard input and output.}
1487 Your program normally uses the same device for standard input and
1488 standard output as @value{GDBN} is using. You can redirect input and output
1489 in the @code{run} command line, or you can use the @code{tty} command to
1490 set a different device for your program.
1491 @xref{Input/Output, ,Your program's input and output}.
1492
1493 @cindex pipes
1494 @emph{Warning:} While input and output redirection work, you cannot use
1495 pipes to pass the output of the program you are debugging to another
1496 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1497 wrong program.
1498 @end table
1499 @end ifclear
1500
1501 When you issue the @code{run} command, your program begins to execute
1502 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1503 of how to arrange for your program to stop. Once your program has
1504 stopped, you may call functions in your program, using the @code{print}
1505 or @code{call} commands. @xref{Data, ,Examining Data}.
1506
1507 If the modification time of your symbol file has changed since the last
1508 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1509 table, and reads it again. When it does this, @value{GDBN} tries to retain
1510 your current breakpoints.
1511
1512 @ifclear BARETARGET
1513 @node Arguments
1514 @section Your program's arguments
1515
1516 @cindex arguments (to your program)
1517 The arguments to your program can be specified by the arguments of the
1518 @code{run} command. They are passed to a shell, which expands wildcard
1519 characters and performs redirection of I/O, and thence to your program.
1520 Your @code{SHELL} environment variable (if it exists) specifies what
1521 shell @value{GDBN} if you do not define @code{SHELL}, @value{GDBN} uses
1522 @code{/bin/sh}.
1523
1524 @code{run} with no arguments uses the same arguments used by the previous
1525 @code{run}, or those set by the @code{set args} command.
1526
1527 @kindex set args
1528 @table @code
1529 @item set args
1530 Specify the arguments to be used the next time your program is run. If
1531 @code{set args} has no arguments, @code{run} executes your program
1532 with no arguments. Once you have run your program with arguments,
1533 using @code{set args} before the next @code{run} is the only way to run
1534 it again without arguments.
1535
1536 @item show args
1537 @kindex show args
1538 Show the arguments to give your program when it is started.
1539 @end table
1540
1541 @node Environment
1542 @section Your program's environment
1543
1544 @cindex environment (of your program)
1545 The @dfn{environment} consists of a set of environment variables and
1546 their values. Environment variables conventionally record such things as
1547 your user name, your home directory, your terminal type, and your search
1548 path for programs to run. Usually you set up environment variables with
1549 the shell and they are inherited by all the other programs you run. When
1550 debugging, it can be useful to try running your program with a modified
1551 environment without having to start @value{GDBN} over again.
1552
1553 @table @code
1554 @item path @var{directory}
1555 @kindex path
1556 Add @var{directory} to the front of the @code{PATH} environment variable
1557 (the search path for executables), for both @value{GDBN} and your program.
1558 You may specify several directory names, separated by @samp{:} or
1559 whitespace. If @var{directory} is already in the path, it is moved to
1560 the front, so it is searched sooner.
1561
1562 You can use the string @samp{$cwd} to refer to whatever is the current
1563 working directory at the time @value{GDBN} searches the path. If you
1564 use @samp{.} instead, it refers to the directory where you executed the
1565 @code{path} command. @value{GDBN} replaces @samp{.} in the
1566 @var{directory} argument (with the current path) before adding
1567 @var{directory} to the search path.
1568 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1569 @c document that, since repeating it would be a no-op.
1570
1571 @item show paths
1572 @kindex show paths
1573 Display the list of search paths for executables (the @code{PATH}
1574 environment variable).
1575
1576 @item show environment @r{[}@var{varname}@r{]}
1577 @kindex show environment
1578 Print the value of environment variable @var{varname} to be given to
1579 your program when it starts. If you do not supply @var{varname},
1580 print the names and values of all environment variables to be given to
1581 your program. You can abbreviate @code{environment} as @code{env}.
1582
1583 @item set environment @var{varname} @r{[}=@r{]} @var{value}
1584 @kindex set environment
1585 Set environment variable @var{varname} to @var{value}. The value
1586 changes for your program only, not for @value{GDBN} itself. @var{value} may
1587 be any string; the values of environment variables are just strings, and
1588 any interpretation is supplied by your program itself. The @var{value}
1589 parameter is optional; if it is eliminated, the variable is set to a
1590 null value.
1591 @c "any string" here does not include leading, trailing
1592 @c blanks. Gnu asks: does anyone care?
1593
1594 For example, this command:
1595
1596 @example
1597 set env USER = foo
1598 @end example
1599
1600 @noindent
1601 tells a Unix program, when subsequently run, that its user is named
1602 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1603 are not actually required.)
1604
1605 @item unset environment @var{varname}
1606 @kindex unset environment
1607 Remove variable @var{varname} from the environment to be passed to your
1608 program. This is different from @samp{set env @var{varname} =};
1609 @code{unset environment} removes the variable from the environment,
1610 rather than assigning it an empty value.
1611 @end table
1612
1613 @emph{Warning:} @value{GDBN} runs your program using the shell indicated
1614 by your @code{SHELL} environment variable if it exists (or
1615 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1616 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1617 @file{.bashrc} for BASH---any variables you set in that file affect
1618 your program. You may wish to move setting of environment variables to
1619 files that are only run when you sign on, such as @file{.login} or
1620 @file{.profile}.
1621
1622 @node Working Directory
1623 @section Your program's working directory
1624
1625 @cindex working directory (of your program)
1626 Each time you start your program with @code{run}, it inherits its
1627 working directory from the current working directory of @value{GDBN}.
1628 The @value{GDBN} working directory is initially whatever it inherited
1629 from its parent process (typically the shell), but you can specify a new
1630 working directory in @value{GDBN} with the @code{cd} command.
1631
1632 The @value{GDBN} working directory also serves as a default for the commands
1633 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1634 specify files}.
1635
1636 @table @code
1637 @item cd @var{directory}
1638 @kindex cd
1639 Set the @value{GDBN} working directory to @var{directory}.
1640
1641 @item pwd
1642 @kindex pwd
1643 Print the @value{GDBN} working directory.
1644 @end table
1645
1646 @node Input/Output
1647 @section Your program's input and output
1648
1649 @cindex redirection
1650 @cindex i/o
1651 @cindex terminal
1652 By default, the program you run under @value{GDBN} does input and output to
1653 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal to
1654 its own terminal modes to interact with you, but it records the terminal
1655 modes your program was using and switches back to them when you continue
1656 running your program.
1657
1658 @table @code
1659 @item info terminal
1660 @kindex info terminal
1661 Displays information recorded by @value{GDBN} about the terminal modes your
1662 program is using.
1663 @end table
1664
1665 You can redirect your program's input and/or output using shell
1666 redirection with the @code{run} command. For example,
1667
1668 @example
1669 run > outfile
1670 @end example
1671
1672 @noindent
1673 starts your program, diverting its output to the file @file{outfile}.
1674
1675 @kindex tty
1676 @cindex controlling terminal
1677 Another way to specify where your program should do input and output is
1678 with the @code{tty} command. This command accepts a file name as
1679 argument, and causes this file to be the default for future @code{run}
1680 commands. It also resets the controlling terminal for the child
1681 process, for future @code{run} commands. For example,
1682
1683 @example
1684 tty /dev/ttyb
1685 @end example
1686
1687 @noindent
1688 directs that processes started with subsequent @code{run} commands
1689 default to do input and output on the terminal @file{/dev/ttyb} and have
1690 that as their controlling terminal.
1691
1692 An explicit redirection in @code{run} overrides the @code{tty} command's
1693 effect on the input/output device, but not its effect on the controlling
1694 terminal.
1695
1696 When you use the @code{tty} command or redirect input in the @code{run}
1697 command, only the input @emph{for your program} is affected. The input
1698 for @value{GDBN} still comes from your terminal.
1699
1700 @node Attach
1701 @section Debugging an already-running process
1702 @kindex attach
1703 @cindex attach
1704
1705 @table @code
1706 @item attach @var{process-id}
1707 This command attaches to a running process---one that was started
1708 outside @value{GDBN}. (@code{info files} shows your active
1709 targets.) The command takes as argument a process ID. The usual way to
1710 find out the process-id of a Unix process is with the @code{ps} utility,
1711 or with the @samp{jobs -l} shell command.
1712
1713 @code{attach} does not repeat if you press @key{RET} a second time after
1714 executing the command.
1715 @end table
1716
1717 To use @code{attach}, your program must be running in an environment
1718 which supports processes; for example, @code{attach} does not work for
1719 programs on bare-board targets that lack an operating system. You must
1720 also have permission to send the process a signal.
1721
1722 When using @code{attach}, you should first use the @code{file} command
1723 to specify the program running in the process and load its symbol table.
1724 @xref{Files, ,Commands to Specify Files}.
1725
1726 The first thing @value{GDBN} does after arranging to debug the specified
1727 process is to stop it. You can examine and modify an attached process
1728 with all the @value{GDBN} commands that are ordinarily available when you start
1729 processes with @code{run}. You can insert breakpoints; you can step and
1730 continue; you can modify storage. If you would rather the process
1731 continue running, you may use the @code{continue} command after
1732 attaching @value{GDBN} to the process.
1733
1734 @table @code
1735 @item detach
1736 @kindex detach
1737 When you have finished debugging the attached process, you can use the
1738 @code{detach} command to release it from @value{GDBN} control. Detaching
1739 the process continues its execution. After the @code{detach} command,
1740 that process and @value{GDBN} become completely independent once more, and you
1741 are ready to @code{attach} another process or start one with @code{run}.
1742 @code{detach} does not repeat if you press @key{RET} again after
1743 executing the command.
1744 @end table
1745
1746 If you exit @value{GDBN} or use the @code{run} command while you have an
1747 attached process, you kill that process. By default, @value{GDBN} asks
1748 for confirmation if you try to do either of these things; you can
1749 control whether or not you need to confirm by using the @code{set
1750 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1751 messages}).
1752
1753 @node Kill Process
1754 @c @group
1755 @section Killing the child process
1756
1757 @table @code
1758 @item kill
1759 @kindex kill
1760 Kill the child process in which your program is running under @value{GDBN}.
1761 @end table
1762
1763 This command is useful if you wish to debug a core dump instead of a
1764 running process. @value{GDBN} ignores any core dump file while your program
1765 is running.
1766 @c @end group
1767
1768 On some operating systems, a program cannot be executed outside @value{GDBN}
1769 while you have breakpoints set on it inside @value{GDBN}. You can use the
1770 @code{kill} command in this situation to permit running your program
1771 outside the debugger.
1772
1773 The @code{kill} command is also useful if you wish to recompile and
1774 relink your program, since on many systems it is impossible to modify an
1775 executable file while it is running in a process. In this case, when you
1776 next type @code{run}, @value{GDBN} notices that the file has changed, and
1777 reads the symbol table again (while trying to preserve your current
1778 breakpoint settings).
1779
1780 @node Process Information
1781 @section Additional process information
1782
1783 @kindex /proc
1784 @cindex process image
1785 Some operating systems provide a facility called @samp{/proc} that can
1786 be used to examine the image of a running process using file-system
1787 subroutines. If @value{GDBN} is configured for an operating system with this
1788 facility, the command @code{info proc} is available to report on several
1789 kinds of information about the process running your program.
1790
1791 @table @code
1792 @item info proc
1793 @kindex info proc
1794 Summarize available information about the process.
1795
1796 @item info proc mappings
1797 @kindex info proc mappings
1798 Report on the address ranges accessible in the program, with information
1799 on whether your program may read, write, or execute each range.
1800
1801 @item info proc times
1802 @kindex info proc times
1803 Starting time, user CPU time, and system CPU time for your program and
1804 its children.
1805
1806 @item info proc id
1807 @kindex info proc id
1808 Report on the process IDs related to your program: its own process ID,
1809 the ID of its parent, the process group ID, and the session ID.
1810
1811 @item info proc status
1812 @kindex info proc status
1813 General information on the state of the process. If the process is
1814 stopped, this report includes the reason for stopping, and any signal
1815 received.
1816
1817 @item info proc all
1818 Show all the above information about the process.
1819 @end table
1820
1821 @node Threads
1822 @section Debugging programs with multiple threads
1823
1824 @cindex threads of execution
1825 @cindex multiple threads
1826 @cindex switching threads
1827 In some operating systems, a single program may have more than one
1828 @dfn{thread} of execution. The precise semantics of threads differ from
1829 one operating system to another, but in general the threads of a single
1830 program are akin to multiple processes---except that they share one
1831 address space (that is, they can all examine and modify the same
1832 variables). On the other hand, each thread has its own registers and
1833 execution stack, and perhaps private memory.
1834
1835 @value{GDBN} provides these facilities for debugging multi-thread
1836 programs:
1837
1838 @itemize @bullet
1839 @item automatic notification of new threads
1840 @item @samp{thread @var{threadno}}, a command to switch among threads
1841 @item @samp{info threads}, a command to inquire about existing threads
1842 @item thread-specific breakpoints
1843 @end itemize
1844
1845 @quotation
1846 @emph{Warning:} These facilities are not yet available on every
1847 @value{GDBN} configuration where the operating system supports threads.
1848 If your @value{GDBN} does not support threads, these commands have no
1849 effect. For example, a system without thread support shows no output
1850 from @samp{info threads}, and always rejects the @code{thread} command,
1851 like this:
1852
1853 @smallexample
1854 (@value{GDBP}) info threads
1855 (@value{GDBP}) thread 1
1856 Thread ID 1 not known. Use the "info threads" command to
1857 see the IDs of currently known threads.
1858 @end smallexample
1859 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
1860 @c doesn't support threads"?
1861 @end quotation
1862
1863 @cindex focus of debugging
1864 @cindex current thread
1865 The @value{GDBN} thread debugging facility allows you to observe all
1866 threads while your program runs---but whenever @value{GDBN} takes
1867 control, one thread in particular is always the focus of debugging.
1868 This thread is called the @dfn{current thread}. Debugging commands show
1869 program information from the perspective of the current thread.
1870
1871 @kindex New @var{systag}
1872 @cindex thread identifier (system)
1873 @c FIXME-implementors!! It would be more helpful if the [New...] message
1874 @c included GDB's numeric thread handle, so you could just go to that
1875 @c thread without first checking `info threads'.
1876 Whenever @value{GDBN} detects a new thread in your program, it displays
1877 the target system's identification for the thread with a message in the
1878 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1879 whose form varies depending on the particular system. For example, on
1880 LynxOS, you might see
1881
1882 @example
1883 [New process 35 thread 27]
1884 @end example
1885
1886 @noindent
1887 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1888 the @var{systag} is simply something like @samp{process 368}, with no
1889 further qualifier.
1890
1891 @c FIXME!! (1) Does the [New...] message appear even for the very first
1892 @c thread of a program, or does it only appear for the
1893 @c second---i.e., when it becomes obvious we have a multithread
1894 @c program?
1895 @c (2) *Is* there necessarily a first thread always? Or do some
1896 @c multithread systems permit starting a program with multiple
1897 @c threads ab initio?
1898
1899 @cindex thread number
1900 @cindex thread identifier (GDB)
1901 For debugging purposes, @value{GDBN} associates its own thread
1902 number---always a single integer---with each thread in your program.
1903
1904 @table @code
1905 @item info threads
1906 @kindex info threads
1907 Display a summary of all threads currently in your
1908 program. @value{GDBN} displays for each thread (in this order):
1909
1910 @enumerate
1911 @item the thread number assigned by @value{GDBN}
1912
1913 @item the target system's thread identifier (@var{systag})
1914
1915 @item the current stack frame summary for that thread
1916 @end enumerate
1917
1918 @noindent
1919 An asterisk @samp{*} to the left of the @value{GDBN} thread number
1920 indicates the current thread.
1921
1922 For example,
1923 @end table
1924 @c end table here to get a little more width for example
1925
1926 @smallexample
1927 (@value{GDBP}) info threads
1928 3 process 35 thread 27 0x34e5 in sigpause ()
1929 2 process 35 thread 23 0x34e5 in sigpause ()
1930 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
1931 at threadtest.c:68
1932 @end smallexample
1933
1934 @table @code
1935 @item thread @var{threadno}
1936 @kindex thread @var{threadno}
1937 Make thread number @var{threadno} the current thread. The command
1938 argument @var{threadno} is the internal @value{GDBN} thread number, as
1939 shown in the first field of the @samp{info threads} display.
1940 @value{GDBN} responds by displaying the system identifier of the thread
1941 you selected, and its current stack frame summary:
1942
1943 @smallexample
1944 @c FIXME!! This example made up; find a GDB w/threads and get real one
1945 (@value{GDBP}) thread 2
1946 [Switching to process 35 thread 23]
1947 0x34e5 in sigpause ()
1948 @end smallexample
1949
1950 @noindent
1951 As with the @samp{[New @dots{}]} message, the form of the text after
1952 @samp{Switching to} depends on your system's conventions for identifying
1953 threads.
1954 @end table
1955
1956 @cindex automatic thread selection
1957 @cindex switching threads automatically
1958 @cindex threads, automatic switching
1959 Whenever @value{GDBN} stops your program, due to a breakpoint or a
1960 signal, it automatically selects the thread where that breakpoint or
1961 signal happened. @value{GDBN} alerts you to the context switch with a
1962 message of the form @samp{[Switching to @var{systag}]} to identify the
1963 thread.
1964
1965 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
1966 more information about how @value{GDBN} behaves when you stop and start
1967 programs with multiple threads.
1968
1969 @xref{Set Watchpoints,,Setting watchpoints}, for information about
1970 watchpoints in programs with multiple threads.
1971 @end ifclear
1972
1973 @node Stopping
1974 @chapter Stopping and Continuing
1975
1976 The principal purposes of using a debugger are so that you can stop your
1977 program before it terminates; or so that, if your program runs into
1978 trouble, you can investigate and find out why.
1979
1980 Inside @value{GDBN}, your program may stop for any of several reasons, such
1981 as
1982 @ifclear BARETARGET
1983 a signal,
1984 @end ifclear
1985 a breakpoint, or reaching a new line after a @value{GDBN}
1986 command such as @code{step}. You may then examine and change
1987 variables, set new breakpoints or remove old ones, and then continue
1988 execution. Usually, the messages shown by @value{GDBN} provide ample
1989 explanation of the status of your program---but you can also explicitly
1990 request this information at any time.
1991
1992 @table @code
1993 @item info program
1994 @kindex info program
1995 Display information about the status of your program: whether it is
1996 running or not,
1997 @ifclear BARETARGET
1998 what process it is,
1999 @end ifclear
2000 and why it stopped.
2001 @end table
2002
2003 @menu
2004 @ifclear CONLY
2005 * Breakpoints:: Breakpoints, watchpoints, and exceptions
2006 @end ifclear
2007 @ifset CONLY
2008 * Breakpoints:: Breakpoints and watchpoints
2009 @end ifset
2010 @c Remnant makeinfo bug requires blank line after *successful* end-if in menu:
2011
2012 * Continuing and Stepping:: Resuming execution
2013 @ifset POSIX
2014 * Signals:: Signals
2015 @end ifset
2016 @ifclear BARETARGET
2017 * Thread Stops:: Stopping and starting multi-thread programs
2018 @end ifclear
2019 @end menu
2020
2021 @c makeinfo node-defaulting requires adjacency of @node and sectioning cmds
2022 @c ...hence distribute @node Breakpoints over two possible @if expansions.
2023 @c
2024 @ifclear CONLY
2025 @node Breakpoints
2026 @section Breakpoints, watchpoints, and exceptions
2027 @end ifclear
2028 @ifset CONLY
2029 @node Breakpoints
2030 @section Breakpoints and watchpoints
2031 @end ifset
2032
2033 @cindex breakpoints
2034 A @dfn{breakpoint} makes your program stop whenever a certain point in
2035 the program is reached. For each breakpoint, you can add
2036 conditions to control in finer detail whether your program stops.
2037 You can set breakpoints with the @code{break} command and its variants
2038 (@pxref{Set Breaks, ,Setting breakpoints}), to specify the place where
2039 your program should stop by line number, function name or exact address
2040 in the program.
2041 @ifclear CONLY
2042 In languages with exception handling (such as GNU C++), you can also set
2043 breakpoints where an exception is raised (@pxref{Exception Handling,,
2044 Breakpoints and exceptions}).
2045 @end ifclear
2046
2047 @cindex watchpoints
2048 @cindex memory tracing
2049 @cindex breakpoint on memory address
2050 @cindex breakpoint on variable modification
2051 A @dfn{watchpoint} is a special breakpoint that stops your program
2052 when the value of an expression changes. You must use a different
2053 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2054 watchpoints}), but aside from that, you can manage a watchpoint like
2055 any other breakpoint: you enable, disable, and delete both breakpoints
2056 and watchpoints using the same commands.
2057
2058 You can arrange to have values from your program displayed automatically
2059 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2060 Automatic display}.
2061
2062 @cindex breakpoint numbers
2063 @cindex numbers for breakpoints
2064 @value{GDBN} assigns a number to each breakpoint or watchpoint when you
2065 create it; these numbers are successive integers starting with one. In
2066 many of the commands for controlling various features of breakpoints you
2067 use the breakpoint number to say which breakpoint you want to change.
2068 Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has
2069 no effect on your program until you enable it again.
2070
2071 @menu
2072 * Set Breaks:: Setting breakpoints
2073 * Set Watchpoints:: Setting watchpoints
2074 @ifclear CONLY
2075 * Exception Handling:: Breakpoints and exceptions
2076 @end ifclear
2077
2078 * Delete Breaks:: Deleting breakpoints
2079 * Disabling:: Disabling breakpoints
2080 * Conditions:: Break conditions
2081 * Break Commands:: Breakpoint command lists
2082 @ifclear CONLY
2083 * Breakpoint Menus:: Breakpoint menus
2084 @end ifclear
2085 @ifclear BARETARGET
2086 * Error in Breakpoints:: ``Cannot insert breakpoints''
2087 @end ifclear
2088 @end menu
2089
2090 @node Set Breaks
2091 @subsection Setting breakpoints
2092
2093 @c FIXME LMB what does GDB do if no code on line of breakpt?
2094 @c consider in particular declaration with/without initialization.
2095 @c
2096 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2097
2098 @kindex break
2099 @kindex b
2100 @kindex $bpnum
2101 @cindex latest breakpoint
2102 Breakpoints are set with the @code{break} command (abbreviated
2103 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2104 number of the beakpoint you've set most recently; see @ref{Convenience
2105 Vars,, Convenience variables}, for a discussion of what you can do with
2106 convenience variables.
2107
2108 You have several ways to say where the breakpoint should go.
2109
2110 @table @code
2111 @item break @var{function}
2112 Set a breakpoint at entry to function @var{function}.
2113 @ifclear CONLY
2114 When using source languages that permit overloading of symbols, such as
2115 C++, @var{function} may refer to more than one possible place to break.
2116 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2117 @end ifclear
2118
2119 @item break +@var{offset}
2120 @itemx break -@var{offset}
2121 Set a breakpoint some number of lines forward or back from the position
2122 at which execution stopped in the currently selected frame.
2123
2124 @item break @var{linenum}
2125 Set a breakpoint at line @var{linenum} in the current source file.
2126 That file is the last file whose source text was printed. This
2127 breakpoint stops your program just before it executes any of the
2128 code on that line.
2129
2130 @item break @var{filename}:@var{linenum}
2131 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2132
2133 @item break @var{filename}:@var{function}
2134 Set a breakpoint at entry to function @var{function} found in file
2135 @var{filename}. Specifying a file name as well as a function name is
2136 superfluous except when multiple files contain similarly named
2137 functions.
2138
2139 @item break *@var{address}
2140 Set a breakpoint at address @var{address}. You can use this to set
2141 breakpoints in parts of your program which do not have debugging
2142 information or source files.
2143
2144 @item break
2145 When called without any arguments, @code{break} sets a breakpoint at
2146 the next instruction to be executed in the selected stack frame
2147 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2148 innermost, this makes your program stop as soon as control
2149 returns to that frame. This is similar to the effect of a
2150 @code{finish} command in the frame inside the selected frame---except
2151 that @code{finish} does not leave an active breakpoint. If you use
2152 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2153 the next time it reaches the current location; this may be useful
2154 inside loops.
2155
2156 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2157 least one instruction has been executed. If it did not do this, you
2158 would be unable to proceed past a breakpoint without first disabling the
2159 breakpoint. This rule applies whether or not the breakpoint already
2160 existed when your program stopped.
2161
2162 @item break @dots{} if @var{cond}
2163 Set a breakpoint with condition @var{cond}; evaluate the expression
2164 @var{cond} each time the breakpoint is reached, and stop only if the
2165 value is nonzero---that is, if @var{cond} evaluates as true.
2166 @samp{@dots{}} stands for one of the possible arguments described
2167 above (or no argument) specifying where to break. @xref{Conditions,
2168 ,Break conditions}, for more information on breakpoint conditions.
2169
2170 @item tbreak @var{args}
2171 @kindex tbreak
2172 Set a breakpoint enabled only for one stop. @var{args} are the
2173 same as for the @code{break} command, and the breakpoint is set in the same
2174 way, but the breakpoint is automatically deleted after the first time your
2175 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2176
2177 @item rbreak @var{regex}
2178 @kindex rbreak
2179 @cindex regular expression
2180 @c FIXME what kind of regexp?
2181 Set breakpoints on all functions matching the regular expression
2182 @var{regex}. This command
2183 sets an unconditional breakpoint on all matches, printing a list of all
2184 breakpoints it set. Once these breakpoints are set, they are treated
2185 just like the breakpoints set with the @code{break} command. You can
2186 delete them, disable them, or make them conditional the same way as any
2187 other breakpoint.
2188
2189 @ifclear CONLY
2190 When debugging C++ programs, @code{rbreak} is useful for setting
2191 breakpoints on overloaded functions that are not members of any special
2192 classes.
2193 @end ifclear
2194
2195 @kindex info breakpoints
2196 @cindex @code{$_} and @code{info breakpoints}
2197 @item info breakpoints @r{[}@var{n}@r{]}
2198 @itemx info break @r{[}@var{n}@r{]}
2199 @itemx info watchpoints @r{[}@var{n}@r{]}
2200 Print a table of all breakpoints and watchpoints set and not
2201 deleted, with the following columns for each breakpoint:
2202
2203 @table @emph
2204 @item Breakpoint Numbers
2205 @item Type
2206 Breakpoint or watchpoint.
2207 @item Disposition
2208 Whether the breakpoint is marked to be disabled or deleted when hit.
2209 @item Enabled or Disabled
2210 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2211 that are not enabled.
2212 @item Address
2213 Where the breakpoint is in your program, as a memory address
2214 @item What
2215 Where the breakpoint is in the source for your program, as a file and
2216 line number.
2217 @end table
2218
2219 @noindent
2220 If a breakpoint is conditional, @code{info break} shows the condition on
2221 the line following the affected breakpoint; breakpoint commands, if any,
2222 are listed after that.
2223
2224 @noindent
2225 @code{info break} with a breakpoint
2226 number @var{n} as argument lists only that breakpoint. The
2227 convenience variable @code{$_} and the default examining-address for
2228 the @code{x} command are set to the address of the last breakpoint
2229 listed (@pxref{Memory, ,Examining memory}).
2230 @end table
2231
2232 @value{GDBN} allows you to set any number of breakpoints at the same place in
2233 your program. There is nothing silly or meaningless about this. When
2234 the breakpoints are conditional, this is even useful
2235 (@pxref{Conditions, ,Break conditions}).
2236
2237 @cindex negative breakpoint numbers
2238 @cindex internal @value{GDBN} breakpoints
2239 @value{GDBN} itself sometimes sets breakpoints in your program for special
2240 purposes, such as proper handling of @code{longjmp} (in C programs).
2241 These internal breakpoints are assigned negative numbers, starting with
2242 @code{-1}; @samp{info breakpoints} does not display them.
2243
2244 You can see these breakpoints with the @value{GDBN} maintenance command
2245 @samp{maint info breakpoints}.
2246
2247 @table @code
2248 @kindex maint info breakpoints
2249 @item maint info breakpoints
2250 Using the same format as @samp{info breakpoints}, display both the
2251 breakpoints you've set explicitly, and those @value{GDBN} is using for
2252 internal purposes. Internal breakpoints are shown with negative
2253 breakpoint numbers. The type column identifies what kind of breakpoint
2254 is shown:
2255
2256 @table @code
2257 @item breakpoint
2258 Normal, explicitly set breakpoint.
2259
2260 @item watchpoint
2261 Normal, explicitly set watchpoint.
2262
2263 @item longjmp
2264 Internal breakpoint, used to handle correctly stepping through
2265 @code{longjmp} calls.
2266
2267 @item longjmp resume
2268 Internal breakpoint at the target of a @code{longjmp}.
2269
2270 @item until
2271 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2272
2273 @item finish
2274 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2275 @end table
2276
2277 @end table
2278
2279
2280 @node Set Watchpoints
2281 @subsection Setting watchpoints
2282 @cindex setting watchpoints
2283
2284 You can use a watchpoint to stop execution whenever the value of an
2285 expression changes, without having to predict a particular place
2286 where this may happen.
2287
2288 Watchpoints currently execute two orders of magnitude more slowly than
2289 other breakpoints, but this can be well worth it to catch errors where
2290 you have no clue what part of your program is the culprit.
2291
2292 @ignore
2293 @c this "future releases" promise has been in too long, is getting
2294 @c embarrassing. But...
2295 @c FIXME: in future updates, check whether hardware watchpoints in on any
2296 @c platforms yet. As of 26jan94, they're very close on HPPA running
2297 @c Berkeley and on Irix 4.
2298 Some processors provide special hardware to support watchpoint
2299 evaluation; future releases of @value{GDBN} will use such hardware if it
2300 is available.
2301 @end ignore
2302
2303 @table @code
2304 @kindex watch
2305 @item watch @var{expr}
2306 Set a watchpoint for an expression.
2307
2308 @kindex info watchpoints
2309 @item info watchpoints
2310 This command prints a list of watchpoints and breakpoints; it is the
2311 same as @code{info break}.
2312 @end table
2313
2314 @ifclear BARETARGET
2315 @quotation
2316 @cindex watchpoints and threads
2317 @cindex threads and watchpoints
2318 @emph{Warning:} in multi-thread programs, watchpoints have only limited
2319 usefulness. With the current watchpoint implementation, @value{GDBN}
2320 can only watch the value of an expression @emph{in a single thread}. If
2321 you are confident that the expression can only change due to the current
2322 thread's activity (and if you are also confident that no other thread
2323 can become current), then you can use watchpoints as usual. However,
2324 @value{GDBN} may not notice when a non-current thread's activity changes
2325 the expression.
2326 @end quotation
2327 @end ifclear
2328
2329 @ifclear CONLY
2330 @node Exception Handling
2331 @subsection Breakpoints and exceptions
2332 @cindex exception handlers
2333
2334 Some languages, such as GNU C++, implement exception handling. You can
2335 use @value{GDBN} to examine what caused your program to raise an exception,
2336 and to list the exceptions your program is prepared to handle at a
2337 given point in time.
2338
2339 @table @code
2340 @item catch @var{exceptions}
2341 @kindex catch
2342 You can set breakpoints at active exception handlers by using the
2343 @code{catch} command. @var{exceptions} is a list of names of exceptions
2344 to catch.
2345 @end table
2346
2347 You can use @code{info catch} to list active exception handlers.
2348 @xref{Frame Info, ,Information about a frame}.
2349
2350 There are currently some limitations to exception handling in @value{GDBN}:
2351
2352 @itemize @bullet
2353 @item
2354 If you call a function interactively, @value{GDBN} normally returns
2355 control to you when the function has finished executing. If the call
2356 raises an exception, however, the call may bypass the mechanism that
2357 returns control to you and cause your program to simply continue
2358 running until it hits a breakpoint, catches a signal that @value{GDBN} is
2359 listening for, or exits.
2360
2361 @item
2362 You cannot raise an exception interactively.
2363
2364 @item
2365 You cannot install an exception handler interactively.
2366 @end itemize
2367
2368 @cindex raise exceptions
2369 Sometimes @code{catch} is not the best way to debug exception handling:
2370 if you need to know exactly where an exception is raised, it is better to
2371 stop @emph{before} the exception handler is called, since that way you
2372 can see the stack before any unwinding takes place. If you set a
2373 breakpoint in an exception handler instead, it may not be easy to find
2374 out where the exception was raised.
2375
2376 To stop just before an exception handler is called, you need some
2377 knowledge of the implementation. In the case of GNU C++, exceptions are
2378 raised by calling a library function named @code{__raise_exception}
2379 which has the following ANSI C interface:
2380
2381 @example
2382 /* @var{addr} is where the exception identifier is stored.
2383 ID is the exception identifier. */
2384 void __raise_exception (void **@var{addr}, void *@var{id});
2385 @end example
2386
2387 @noindent
2388 To make the debugger catch all exceptions before any stack
2389 unwinding takes place, set a breakpoint on @code{__raise_exception}
2390 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2391
2392 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2393 that depends on the value of @var{id}, you can stop your program when
2394 a specific exception is raised. You can use multiple conditional
2395 breakpoints to stop your program when any of a number of exceptions are
2396 raised.
2397 @end ifclear
2398
2399 @node Delete Breaks
2400 @subsection Deleting breakpoints
2401
2402 @cindex clearing breakpoints, watchpoints
2403 @cindex deleting breakpoints, watchpoints
2404 It is often necessary to eliminate a breakpoint or watchpoint once it
2405 has done its job and you no longer want your program to stop there. This
2406 is called @dfn{deleting} the breakpoint. A breakpoint that has been
2407 deleted no longer exists; it is forgotten.
2408
2409 With the @code{clear} command you can delete breakpoints according to
2410 where they are in your program. With the @code{delete} command you can
2411 delete individual breakpoints or watchpoints by specifying their
2412 breakpoint numbers.
2413
2414 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2415 automatically ignores breakpoints on the first instruction to be executed
2416 when you continue execution without changing the execution address.
2417
2418 @table @code
2419 @item clear
2420 @kindex clear
2421 Delete any breakpoints at the next instruction to be executed in the
2422 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2423 the innermost frame is selected, this is a good way to delete a
2424 breakpoint where your program just stopped.
2425
2426 @item clear @var{function}
2427 @itemx clear @var{filename}:@var{function}
2428 Delete any breakpoints set at entry to the function @var{function}.
2429
2430 @item clear @var{linenum}
2431 @itemx clear @var{filename}:@var{linenum}
2432 Delete any breakpoints set at or within the code of the specified line.
2433
2434 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2435 @cindex delete breakpoints
2436 @kindex delete
2437 @kindex d
2438 Delete the breakpoints or watchpoints of the numbers specified as
2439 arguments. If no argument is specified, delete all breakpoints (@value{GDBN}
2440 asks confirmation, unless you have @code{set confirm off}). You
2441 can abbreviate this command as @code{d}.
2442 @end table
2443
2444 @node Disabling
2445 @subsection Disabling breakpoints
2446
2447 @cindex disabled breakpoints
2448 @cindex enabled breakpoints
2449 Rather than deleting a breakpoint or watchpoint, you might prefer to
2450 @dfn{disable} it. This makes the breakpoint inoperative as if it had
2451 been deleted, but remembers the information on the breakpoint so that
2452 you can @dfn{enable} it again later.
2453
2454 You disable and enable breakpoints and watchpoints with the
2455 @code{enable} and @code{disable} commands, optionally specifying one or
2456 more breakpoint numbers as arguments. Use @code{info break} or
2457 @code{info watch} to print a list of breakpoints or watchpoints if you
2458 do not know which numbers to use.
2459
2460 A breakpoint or watchpoint can have any of four different states of
2461 enablement:
2462
2463 @itemize @bullet
2464 @item
2465 Enabled. The breakpoint stops your program. A breakpoint set
2466 with the @code{break} command starts out in this state.
2467 @item
2468 Disabled. The breakpoint has no effect on your program.
2469 @item
2470 Enabled once. The breakpoint stops your program, but then becomes
2471 disabled. A breakpoint set with the @code{tbreak} command starts out in
2472 this state.
2473 @item
2474 Enabled for deletion. The breakpoint stops your program, but
2475 immediately after it does so it is deleted permanently.
2476 @end itemize
2477
2478 You can use the following commands to enable or disable breakpoints and
2479 watchpoints:
2480
2481 @table @code
2482 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2483 @kindex disable breakpoints
2484 @kindex disable
2485 @kindex dis
2486 Disable the specified breakpoints---or all breakpoints, if none are
2487 listed. A disabled breakpoint has no effect but is not forgotten. All
2488 options such as ignore-counts, conditions and commands are remembered in
2489 case the breakpoint is enabled again later. You may abbreviate
2490 @code{disable} as @code{dis}.
2491
2492 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2493 @kindex enable breakpoints
2494 @kindex enable
2495 Enable the specified breakpoints (or all defined breakpoints). They
2496 become effective once again in stopping your program.
2497
2498 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2499 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2500 of these breakpoints immediately after stopping your program.
2501
2502 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2503 Enable the specified breakpoints to work once, then die. @value{GDBN}
2504 deletes any of these breakpoints as soon as your program stops there.
2505 @end table
2506
2507 Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2508 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2509 subsequently, they become disabled or enabled only when you use one of
2510 the commands above. (The command @code{until} can set and delete a
2511 breakpoint of its own, but it does not change the state of your other
2512 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2513 stepping}.)
2514
2515 @node Conditions
2516 @subsection Break conditions
2517 @cindex conditional breakpoints
2518 @cindex breakpoint conditions
2519
2520 @c FIXME what is scope of break condition expr? Context where wanted?
2521 @c in particular for a watchpoint?
2522 The simplest sort of breakpoint breaks every time your program reaches a
2523 specified place. You can also specify a @dfn{condition} for a
2524 breakpoint. A condition is just a Boolean expression in your
2525 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2526 a condition evaluates the expression each time your program reaches it,
2527 and your program stops only if the condition is @emph{true}.
2528
2529 This is the converse of using assertions for program validation; in that
2530 situation, you want to stop when the assertion is violated---that is,
2531 when the condition is false. In C, if you want to test an assertion expressed
2532 by the condition @var{assert}, you should set the condition
2533 @samp{! @var{assert}} on the appropriate breakpoint.
2534
2535 Conditions are also accepted for watchpoints; you may not need them,
2536 since a watchpoint is inspecting the value of an expression anyhow---but
2537 it might be simpler, say, to just set a watchpoint on a variable name,
2538 and specify a condition that tests whether the new value is an interesting
2539 one.
2540
2541 Break conditions can have side effects, and may even call functions in
2542 your program. This can be useful, for example, to activate functions
2543 that log program progress, or to use your own print functions to
2544 format special data structures. The effects are completely predictable
2545 unless there is another enabled breakpoint at the same address. (In
2546 that case, @value{GDBN} might see the other breakpoint first and stop your
2547 program without checking the condition of this one.) Note that
2548 breakpoint commands are usually more convenient and flexible for the
2549 purpose of performing side effects when a breakpoint is reached
2550 (@pxref{Break Commands, ,Breakpoint command lists}).
2551
2552 Break conditions can be specified when a breakpoint is set, by using
2553 @samp{if} in the arguments to the @code{break} command. @xref{Set
2554 Breaks, ,Setting breakpoints}. They can also be changed at any time
2555 with the @code{condition} command. The @code{watch} command does not
2556 recognize the @code{if} keyword; @code{condition} is the only way to
2557 impose a further condition on a watchpoint.
2558
2559 @table @code
2560 @item condition @var{bnum} @var{expression}
2561 @kindex condition
2562 Specify @var{expression} as the break condition for breakpoint or
2563 watchpoint number @var{bnum}. After you set a condition, breakpoint
2564 @var{bnum} stops your program only if the value of @var{expression} is
2565 true (nonzero, in C). When you use @code{condition}, @value{GDBN}
2566 checks @var{expression} immediately for syntactic correctness, and to
2567 determine whether symbols in it have referents in the context of your
2568 breakpoint.
2569 @c FIXME so what does GDB do if there is no referent? Moreover, what
2570 @c about watchpoints?
2571 @value{GDBN} does
2572 not actually evaluate @var{expression} at the time the @code{condition}
2573 command is given, however. @xref{Expressions, ,Expressions}.
2574
2575 @item condition @var{bnum}
2576 Remove the condition from breakpoint number @var{bnum}. It becomes
2577 an ordinary unconditional breakpoint.
2578 @end table
2579
2580 @cindex ignore count (of breakpoint)
2581 A special case of a breakpoint condition is to stop only when the
2582 breakpoint has been reached a certain number of times. This is so
2583 useful that there is a special way to do it, using the @dfn{ignore
2584 count} of the breakpoint. Every breakpoint has an ignore count, which
2585 is an integer. Most of the time, the ignore count is zero, and
2586 therefore has no effect. But if your program reaches a breakpoint whose
2587 ignore count is positive, then instead of stopping, it just decrements
2588 the ignore count by one and continues. As a result, if the ignore count
2589 value is @var{n}, the breakpoint does not stop the next @var{n} times
2590 your program reaches it.
2591
2592 @table @code
2593 @item ignore @var{bnum} @var{count}
2594 @kindex ignore
2595 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2596 The next @var{count} times the breakpoint is reached, your program's
2597 execution does not stop; other than to decrement the ignore count, @value{GDBN}
2598 takes no action.
2599
2600 To make the breakpoint stop the next time it is reached, specify
2601 a count of zero.
2602
2603 When you use @code{continue} to resume execution of your program from a
2604 breakpoint, you can specify an ignore count directly as an argument to
2605 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
2606 Stepping,,Continuing and stepping}.
2607
2608 If a breakpoint has a positive ignore count and a condition, the
2609 condition is not checked. Once the ignore count reaches zero,
2610 @value{GDBN} resumes checking the condition.
2611
2612 You could achieve the effect of the ignore count with a condition such
2613 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2614 is decremented each time. @xref{Convenience Vars, ,Convenience
2615 variables}.
2616 @end table
2617
2618 @node Break Commands
2619 @subsection Breakpoint command lists
2620
2621 @cindex breakpoint commands
2622 You can give any breakpoint (or watchpoint) a series of commands to
2623 execute when your program stops due to that breakpoint. For example, you
2624 might want to print the values of certain expressions, or enable other
2625 breakpoints.
2626
2627 @table @code
2628 @item commands @r{[}@var{bnum}@r{]}
2629 @itemx @dots{} @var{command-list} @dots{}
2630 @itemx end
2631 @kindex commands
2632 @kindex end
2633 Specify a list of commands for breakpoint number @var{bnum}. The commands
2634 themselves appear on the following lines. Type a line containing just
2635 @code{end} to terminate the commands.
2636
2637 To remove all commands from a breakpoint, type @code{commands} and
2638 follow it immediately with @code{end}; that is, give no commands.
2639
2640 With no @var{bnum} argument, @code{commands} refers to the last
2641 breakpoint or watchpoint set (not to the breakpoint most recently
2642 encountered).
2643 @end table
2644
2645 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
2646 disabled within a @var{command-list}.
2647
2648 You can use breakpoint commands to start your program up again. Simply
2649 use the @code{continue} command, or @code{step}, or any other command
2650 that resumes execution.
2651
2652 Any other commands in the command list, after a command that resumes
2653 execution, are ignored. This is because any time you resume execution
2654 (even with a simple @code{next} or @code{step}), you may encounter
2655 another breakpoint---which could have its own command list, leading to
2656 ambiguities about which list to execute.
2657
2658 @kindex silent
2659 If the first command you specify in a command list is @code{silent}, the
2660 usual message about stopping at a breakpoint is not printed. This may
2661 be desirable for breakpoints that are to print a specific message and
2662 then continue. If none of the remaining commands print anything, you
2663 see no sign that the breakpoint was reached. @code{silent} is
2664 meaningful only at the beginning of a breakpoint command list.
2665
2666 The commands @code{echo}, @code{output}, and @code{printf} allow you to
2667 print precisely controlled output, and are often useful in silent
2668 breakpoints. @xref{Output, ,Commands for controlled output}.
2669
2670 For example, here is how you could use breakpoint commands to print the
2671 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2672
2673 @example
2674 break foo if x>0
2675 commands
2676 silent
2677 printf "x is %d\n",x
2678 cont
2679 end
2680 @end example
2681
2682 One application for breakpoint commands is to compensate for one bug so
2683 you can test for another. Put a breakpoint just after the erroneous line
2684 of code, give it a condition to detect the case in which something
2685 erroneous has been done, and give it commands to assign correct values
2686 to any variables that need them. End with the @code{continue} command
2687 so that your program does not stop, and start with the @code{silent}
2688 command so that no output is produced. Here is an example:
2689
2690 @example
2691 break 403
2692 commands
2693 silent
2694 set x = y + 4
2695 cont
2696 end
2697 @end example
2698
2699 @ifclear CONLY
2700 @node Breakpoint Menus
2701 @subsection Breakpoint menus
2702 @cindex overloading
2703 @cindex symbol overloading
2704
2705 Some programming languages (notably C++) permit a single function name
2706 to be defined several times, for application in different contexts.
2707 This is called @dfn{overloading}. When a function name is overloaded,
2708 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
2709 a breakpoint. If you realize this is a problem, you can use
2710 something like @samp{break @var{function}(@var{types})} to specify which
2711 particular version of the function you want. Otherwise, @value{GDBN} offers
2712 you a menu of numbered choices for different possible breakpoints, and
2713 waits for your selection with the prompt @samp{>}. The first two
2714 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2715 sets a breakpoint at each definition of @var{function}, and typing
2716 @kbd{0} aborts the @code{break} command without setting any new
2717 breakpoints.
2718
2719 For example, the following session excerpt shows an attempt to set a
2720 breakpoint at the overloaded symbol @code{String::after}.
2721 We choose three particular definitions of that function name:
2722
2723 @c FIXME! This is likely to change to show arg type lists, at least
2724 @smallexample
2725 (@value{GDBP}) b String::after
2726 [0] cancel
2727 [1] all
2728 [2] file:String.cc; line number:867
2729 [3] file:String.cc; line number:860
2730 [4] file:String.cc; line number:875
2731 [5] file:String.cc; line number:853
2732 [6] file:String.cc; line number:846
2733 [7] file:String.cc; line number:735
2734 > 2 4 6
2735 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2736 Breakpoint 2 at 0xb344: file String.cc, line 875.
2737 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2738 Multiple breakpoints were set.
2739 Use the "delete" command to delete unwanted
2740 breakpoints.
2741 (@value{GDBP})
2742 @end smallexample
2743 @end ifclear
2744
2745 @ifclear BARETARGET
2746 @node Error in Breakpoints
2747 @subsection ``Cannot insert breakpoints''
2748
2749 @c FIXME: "cannot insert breakpoints" error, v unclear.
2750 @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91
2751 @c some light may be shed by looking at instances of
2752 @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise
2753 @c too. pesch, 20sep91
2754 Under some operating systems, breakpoints cannot be used in a program if
2755 any other process is running that program. In this situation,
2756 attempting to run or continue a program with a breakpoint causes @value{GDBN}
2757 to stop the other process.
2758
2759 When this happens, you have three ways to proceed:
2760
2761 @enumerate
2762 @item
2763 Remove or disable the breakpoints, then continue.
2764
2765 @item
2766 Suspend @value{GDBN}, and copy the file containing your program to a new name.
2767 Resume @value{GDBN} and use the @code{exec-file} command to specify that @value{GDBN}
2768 should run your program under that name. Then start your program again.
2769
2770 @c FIXME: RMS commented here "Show example". Maybe when someone
2771 @c explains the first FIXME: in this section...
2772
2773 @item
2774 Relink your program so that the text segment is nonsharable, using the
2775 linker option @samp{-N}. The operating system limitation may not apply
2776 to nonsharable executables.
2777 @end enumerate
2778 @end ifclear
2779
2780 @node Continuing and Stepping
2781 @section Continuing and stepping
2782
2783 @cindex stepping
2784 @cindex continuing
2785 @cindex resuming execution
2786 @dfn{Continuing} means resuming program execution until your program
2787 completes normally. In contrast, @dfn{stepping} means executing just
2788 one more ``step'' of your program, where ``step'' may mean either one
2789 line of source code, or one machine instruction (depending on what
2790 particular command you use). Either when continuing
2791 or when stepping, your program may stop even sooner, due to
2792 @ifset BARETARGET
2793 a breakpoint.
2794 @end ifset
2795 @ifclear BARETARGET
2796 a breakpoint or a signal. (If due to a signal, you may want to use
2797 @code{handle}, or use @samp{signal 0} to resume execution.
2798 @xref{Signals, ,Signals}.)
2799 @end ifclear
2800
2801 @table @code
2802 @item continue @r{[}@var{ignore-count}@r{]}
2803 @itemx c @r{[}@var{ignore-count}@r{]}
2804 @itemx fg @r{[}@var{ignore-count}@r{]}
2805 @kindex continue
2806 @kindex c
2807 @kindex fg
2808 Resume program execution, at the address where your program last stopped;
2809 any breakpoints set at that address are bypassed. The optional argument
2810 @var{ignore-count} allows you to specify a further number of times to
2811 ignore a breakpoint at this location; its effect is like that of
2812 @code{ignore} (@pxref{Conditions, ,Break conditions}).
2813
2814 The argument @var{ignore-count} is meaningful only when your program
2815 stopped due to a breakpoint. At other times, the argument to
2816 @code{continue} is ignored.
2817
2818 The synonyms @code{c} and @code{fg} are provided purely for convenience,
2819 and have exactly the same behavior as @code{continue}.
2820 @end table
2821
2822 To resume execution at a different place, you can use @code{return}
2823 (@pxref{Returning, ,Returning from a function}) to go back to the
2824 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
2825 different address}) to go to an arbitrary location in your program.
2826
2827 A typical technique for using stepping is to set a breakpoint
2828 @ifclear CONLY
2829 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions})
2830 @end ifclear
2831 @ifset CONLY
2832 (@pxref{Breakpoints, ,Breakpoints and watchpoints})
2833 @end ifset
2834 at the
2835 beginning of the function or the section of your program where a
2836 problem is believed to lie, run your program until it stops at that
2837 breakpoint, and then step through the suspect area, examining the
2838 variables that are interesting, until you see the problem happen.
2839
2840 @table @code
2841 @item step
2842 @kindex step
2843 @kindex s
2844 Continue running your program until control reaches a different source
2845 line, then stop it and return control to @value{GDBN}. This command is
2846 abbreviated @code{s}.
2847
2848 @quotation
2849 @c "without debugging information" is imprecise; actually "without line
2850 @c numbers in the debugging information". (gcc -g1 has debugging info but
2851 @c not line numbers). But it seems complex to try to make that
2852 @c distinction here.
2853 @emph{Warning:} If you use the @code{step} command while control is
2854 within a function that was compiled without debugging information,
2855 execution proceeds until control reaches a function that does have
2856 debugging information. Likewise, it will not step into a function which
2857 is compiled without debugging information. To step through functions
2858 without debugging information, use the @code{stepi} command, described
2859 below.
2860 @end quotation
2861
2862 @item step @var{count}
2863 Continue running as in @code{step}, but do so @var{count} times. If a
2864 breakpoint is reached,
2865 @ifclear BARETARGET
2866 or a signal not related to stepping occurs before @var{count} steps,
2867 @end ifclear
2868 stepping stops right away.
2869
2870 @item next @r{[}@var{count}@r{]}
2871 @kindex next
2872 @kindex n
2873 Continue to the next source line in the current (innermost) stack frame.
2874 Similar to @code{step}, but any function calls appearing within the line
2875 of code are executed without stopping. Execution stops when control
2876 reaches a different line of code at the stack level which was executing
2877 when the @code{next} command was given. This command is abbreviated
2878 @code{n}.
2879
2880 An argument @var{count} is a repeat count, as for @code{step}.
2881
2882 @code{next} within a function that lacks debugging information acts like
2883 @code{step}, but any function calls appearing within the code of the
2884 function are executed without stopping.
2885
2886 @item finish
2887 @kindex finish
2888 Continue running until just after function in the selected stack frame
2889 returns. Print the returned value (if any).
2890
2891 Contrast this with the @code{return} command (@pxref{Returning,
2892 ,Returning from a function}).
2893
2894 @item until
2895 @kindex until
2896 @itemx u
2897 @kindex u
2898 Continue running until a source line past the current line, in the
2899 current stack frame, is reached. This command is used to avoid single
2900 stepping through a loop more than once. It is like the @code{next}
2901 command, except that when @code{until} encounters a jump, it
2902 automatically continues execution until the program counter is greater
2903 than the address of the jump.
2904
2905 This means that when you reach the end of a loop after single stepping
2906 though it, @code{until} makes your program continue execution until it
2907 exits the loop. In contrast, a @code{next} command at the end of a loop
2908 simply steps back to the beginning of the loop, which forces you to step
2909 through the next iteration.
2910
2911 @code{until} always stops your program if it attempts to exit the current
2912 stack frame.
2913
2914 @code{until} may produce somewhat counterintuitive results if the order
2915 of machine code does not match the order of the source lines. For
2916 example, in the following excerpt from a debugging session, the @code{f}
2917 (@code{frame}) command shows that execution is stopped at line
2918 @code{206}; yet when we use @code{until}, we get to line @code{195}:
2919
2920 @example
2921 (@value{GDBP}) f
2922 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
2923 206 expand_input();
2924 (@value{GDBP}) until
2925 195 for ( ; argc > 0; NEXTARG) @{
2926 @end example
2927
2928 This happened because, for execution efficiency, the compiler had
2929 generated code for the loop closure test at the end, rather than the
2930 start, of the loop---even though the test in a C @code{for}-loop is
2931 written before the body of the loop. The @code{until} command appeared
2932 to step back to the beginning of the loop when it advanced to this
2933 expression; however, it has not really gone to an earlier
2934 statement---not in terms of the actual machine code.
2935
2936 @code{until} with no argument works by means of single
2937 instruction stepping, and hence is slower than @code{until} with an
2938 argument.
2939
2940 @item until @var{location}
2941 @itemx u @var{location}
2942 Continue running your program until either the specified location is
2943 reached, or the current stack frame returns. @var{location} is any of
2944 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
2945 ,Setting breakpoints}). This form of the command uses breakpoints,
2946 and hence is quicker than @code{until} without an argument.
2947
2948 @item stepi
2949 @itemx si
2950 @kindex stepi
2951 @kindex si
2952 Execute one machine instruction, then stop and return to the debugger.
2953
2954 It is often useful to do @samp{display/i $pc} when stepping by machine
2955 instructions. This makes @value{GDBN} automatically display the next
2956 instruction to be executed, each time your program stops. @xref{Auto
2957 Display,, Automatic display}.
2958
2959 An argument is a repeat count, as in @code{step}.
2960
2961 @need 750
2962 @item nexti
2963 @itemx ni
2964 @kindex nexti
2965 @kindex ni
2966 Execute one machine instruction, but if it is a function call,
2967 proceed until the function returns.
2968
2969 An argument is a repeat count, as in @code{next}.
2970 @end table
2971
2972 @ifset POSIX
2973 @node Signals
2974 @section Signals
2975 @cindex signals
2976
2977 A signal is an asynchronous event that can happen in a program. The
2978 operating system defines the possible kinds of signals, and gives each
2979 kind a name and a number. For example, in Unix @code{SIGINT} is the
2980 signal a program gets when you type an interrupt (often @kbd{C-c});
2981 @code{SIGSEGV} is the signal a program gets from referencing a place in
2982 memory far away from all the areas in use; @code{SIGALRM} occurs when
2983 the alarm clock timer goes off (which happens only if your program has
2984 requested an alarm).
2985
2986 @cindex fatal signals
2987 Some signals, including @code{SIGALRM}, are a normal part of the
2988 functioning of your program. Others, such as @code{SIGSEGV}, indicate
2989 errors; these signals are @dfn{fatal} (kill your program immediately) if the
2990 program has not specified in advance some other way to handle the signal.
2991 @code{SIGINT} does not indicate an error in your program, but it is normally
2992 fatal so it can carry out the purpose of the interrupt: to kill the program.
2993
2994 @value{GDBN} has the ability to detect any occurrence of a signal in your
2995 program. You can tell @value{GDBN} in advance what to do for each kind of
2996 signal.
2997
2998 @cindex handling signals
2999 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3000 (so as not to interfere with their role in the functioning of your program)
3001 but to stop your program immediately whenever an error signal happens.
3002 You can change these settings with the @code{handle} command.
3003
3004 @table @code
3005 @item info signals
3006 @kindex info signals
3007 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3008 handle each one. You can use this to see the signal numbers of all
3009 the defined types of signals.
3010
3011 @item handle @var{signal} @var{keywords}@dots{}
3012 @kindex handle
3013 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can be the
3014 number of a signal or its name (with or without the @samp{SIG} at the
3015 beginning). The @var{keywords} say what change to make.
3016 @end table
3017
3018 @c @group
3019 The keywords allowed by the @code{handle} command can be abbreviated.
3020 Their full names are:
3021
3022 @table @code
3023 @item nostop
3024 @value{GDBN} should not stop your program when this signal happens. It may
3025 still print a message telling you that the signal has come in.
3026
3027 @item stop
3028 @value{GDBN} should stop your program when this signal happens. This implies
3029 the @code{print} keyword as well.
3030
3031 @item print
3032 @value{GDBN} should print a message when this signal happens.
3033
3034 @item noprint
3035 @value{GDBN} should not mention the occurrence of the signal at all. This
3036 implies the @code{nostop} keyword as well.
3037
3038 @item pass
3039 @value{GDBN} should allow your program to see this signal; your program
3040 can handle the signal, or else it may terminate if the signal is fatal
3041 and not handled.
3042
3043 @item nopass
3044 @value{GDBN} should not allow your program to see this signal.
3045 @end table
3046 @c @end group
3047
3048 When a signal stops your program, the signal is not visible until you
3049 continue. Your program sees the signal then, if @code{pass} is in
3050 effect for the signal in question @emph{at that time}. In other words,
3051 after @value{GDBN} reports a signal, you can use the @code{handle}
3052 command with @code{pass} or @code{nopass} to control whether your
3053 program sees that signal when you continue.
3054
3055 You can also use the @code{signal} command to prevent your program from
3056 seeing a signal, or cause it to see a signal it normally would not see,
3057 or to give it any signal at any time. For example, if your program stopped
3058 due to some sort of memory reference error, you might store correct
3059 values into the erroneous variables and continue, hoping to see more
3060 execution; but your program would probably terminate immediately as
3061 a result of the fatal signal once it saw the signal. To prevent this,
3062 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3063 program a signal}.
3064 @end ifset
3065
3066 @ifclear BARETARGET
3067 @node Thread Stops
3068 @section Stopping and starting multi-thread programs
3069
3070 When your program has multiple threads (@pxref{Threads,, Debugging
3071 programs with multiple threads}), you can choose whether to set
3072 breakpoints on all threads, or on a particular thread.
3073
3074 @table @code
3075 @cindex breakpoints and threads
3076 @cindex thread breakpoints
3077 @kindex break @dots{} thread @var{threadno}
3078 @item break @var{linespec} thread @var{threadno}
3079 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3080 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3081 to specify that you only want @value{GDBN} to stop the program when a
3082 particular thread reaches this breakpoint. @var{threadno} is one of the
3083 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3084 column of the @samp{info threads} display.
3085
3086 If you do not specify @samp{thread @var{threadno}} when you set a
3087 breakpoint, the breakpoint applies to @emph{all} threads of your
3088 program.
3089
3090 You can use the @code{thread} qualifier on conditional breakpoints as
3091 well; in this case, place @samp{thread @var{threadno}} before the
3092 breakpoint condition, like this:
3093
3094 @smallexample
3095 (gdb) break frik.c:13 thread 28 if bartab > lim
3096 @end smallexample
3097 @end table
3098
3099 @cindex stopped threads
3100 @cindex threads, stopped
3101 Whenever your program stops under @value{GDBN} for any reason,
3102 @emph{all} threads of execution stop, not just the current thread. This
3103 allows you to examine the overall state of the program, including
3104 switching between threads, without worrying that things may change
3105 underfoot.
3106
3107 @cindex continuing threads
3108 @cindex threads, continuing
3109 Conversely, whenever you restart the program, @emph{all} threads start
3110 executing. @emph{This is true even when single-stepping} with commands
3111 like @code{step} or @code{next}.
3112
3113 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3114 Since thread scheduling is up to your debugging target's operating
3115 system (not controlled by @value{GDBN}), other threads may
3116 execute more than one statement while the current thread completes a
3117 single step. Moreover, in general other threads stop in the middle of a
3118 statement, rather than at a clean statement boundary, when the program
3119 stops.
3120
3121 You might even find your program stopped in another thread after
3122 continuing or even single-stepping. This happens whenever some other
3123 thread runs into a breakpoint, a signal, or an exception before the
3124 first thread completes whatever you requested.
3125 @end ifclear
3126
3127 @node Stack
3128 @chapter Examining the Stack
3129
3130 When your program has stopped, the first thing you need to know is where it
3131 stopped and how it got there.
3132
3133 @cindex call stack
3134 Each time your program performs a function call, the information about
3135 where in your program the call was made from is saved in a block of data
3136 called a @dfn{stack frame}. The frame also contains the arguments of the
3137 call and the local variables of the function that was called. All the
3138 stack frames are allocated in a region of memory called the @dfn{call
3139 stack}.
3140
3141 When your program stops, the @value{GDBN} commands for examining the
3142 stack allow you to see all of this information.
3143
3144 @cindex selected frame
3145 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3146 @value{GDBN} commands refer implicitly to the selected frame. In
3147 particular, whenever you ask @value{GDBN} for the value of a variable in
3148 your program, the value is found in the selected frame. There are
3149 special @value{GDBN} commands to select whichever frame you are
3150 interested in.
3151
3152 When your program stops, @value{GDBN} automatically selects the
3153 currently executing frame and describes it briefly as the @code{frame}
3154 command does (@pxref{Frame Info, ,Information about a frame}).
3155
3156 @menu
3157 * Frames:: Stack frames
3158 * Backtrace:: Backtraces
3159 * Selection:: Selecting a frame
3160 * Frame Info:: Information on a frame
3161 @ifset MIPS
3162 * MIPS Stack:: MIPS machines and the function stack
3163 @end ifset
3164 @end menu
3165
3166 @node Frames
3167 @section Stack frames
3168
3169 @cindex frame
3170 @cindex stack frame
3171 The call stack is divided up into contiguous pieces called @dfn{stack
3172 frames}, or @dfn{frames} for short; each frame is the data associated
3173 with one call to one function. The frame contains the arguments given
3174 to the function, the function's local variables, and the address at
3175 which the function is executing.
3176
3177 @cindex initial frame
3178 @cindex outermost frame
3179 @cindex innermost frame
3180 When your program is started, the stack has only one frame, that of the
3181 function @code{main}. This is called the @dfn{initial} frame or the
3182 @dfn{outermost} frame. Each time a function is called, a new frame is
3183 made. Each time a function returns, the frame for that function invocation
3184 is eliminated. If a function is recursive, there can be many frames for
3185 the same function. The frame for the function in which execution is
3186 actually occurring is called the @dfn{innermost} frame. This is the most
3187 recently created of all the stack frames that still exist.
3188
3189 @cindex frame pointer
3190 Inside your program, stack frames are identified by their addresses. A
3191 stack frame consists of many bytes, each of which has its own address; each
3192 kind of computer has a convention for choosing one of those bytes whose
3193 address serves as the address of the frame. Usually this address is kept
3194 in a register called the @dfn{frame pointer register} while execution is
3195 going on in that frame.
3196
3197 @cindex frame number
3198 @value{GDBN} assigns numbers to all existing stack frames, starting with
3199 zero for the innermost frame, one for the frame that called it,
3200 and so on upward. These numbers do not really exist in your program;
3201 they are assigned by @value{GDBN} to give you a way of designating stack
3202 frames in @value{GDBN} commands.
3203
3204 @c below produces an acceptable overful hbox. --mew 13aug1993
3205 @cindex frameless execution
3206 Some compilers provide a way to compile functions so that they operate
3207 without stack frames. (For example, the @code{@value{GCC}} option
3208 @samp{-fomit-frame-pointer} generates functions without a frame.)
3209 This is occasionally done with heavily used library functions to save
3210 the frame setup time. @value{GDBN} has limited facilities for dealing
3211 with these function invocations. If the innermost function invocation
3212 has no stack frame, @value{GDBN} nevertheless regards it as though
3213 it had a separate frame, which is numbered zero as usual, allowing
3214 correct tracing of the function call chain. However, @value{GDBN} has
3215 no provision for frameless functions elsewhere in the stack.
3216
3217 @node Backtrace
3218 @section Backtraces
3219
3220 A backtrace is a summary of how your program got where it is. It shows one
3221 line per frame, for many frames, starting with the currently executing
3222 frame (frame zero), followed by its caller (frame one), and on up the
3223 stack.
3224
3225 @table @code
3226 @item backtrace
3227 @itemx bt
3228 @kindex backtrace
3229 @kindex bt
3230 Print a backtrace of the entire stack: one line per frame for all
3231 frames in the stack.
3232
3233 You can stop the backtrace at any time by typing the system interrupt
3234 character, normally @kbd{C-c}.
3235
3236 @item backtrace @var{n}
3237 @itemx bt @var{n}
3238 Similar, but print only the innermost @var{n} frames.
3239
3240 @item backtrace -@var{n}
3241 @itemx bt -@var{n}
3242 Similar, but print only the outermost @var{n} frames.
3243 @end table
3244
3245 @kindex where
3246 @kindex info stack
3247 @kindex info s
3248 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3249 are additional aliases for @code{backtrace}.
3250
3251 Each line in the backtrace shows the frame number and the function name.
3252 The program counter value is also shown---unless you use @code{set
3253 print address off}. The backtrace also shows the source file name and
3254 line number, as well as the arguments to the function. The program
3255 counter value is omitted if it is at the beginning of the code for that
3256 line number.
3257
3258 Here is an example of a backtrace. It was made with the command
3259 @samp{bt 3}, so it shows the innermost three frames.
3260
3261 @smallexample
3262 @group
3263 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3264 at builtin.c:993
3265 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3266 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3267 at macro.c:71
3268 (More stack frames follow...)
3269 @end group
3270 @end smallexample
3271
3272 @noindent
3273 The display for frame zero does not begin with a program counter
3274 value, indicating that your program has stopped at the beginning of the
3275 code for line @code{993} of @code{builtin.c}.
3276
3277 @node Selection
3278 @section Selecting a frame
3279
3280 Most commands for examining the stack and other data in your program work on
3281 whichever stack frame is selected at the moment. Here are the commands for
3282 selecting a stack frame; all of them finish by printing a brief description
3283 of the stack frame just selected.
3284
3285 @table @code
3286 @item frame @var{n}
3287 @itemx f @var{n}
3288 @kindex frame
3289 @kindex f
3290 Select frame number @var{n}. Recall that frame zero is the innermost
3291 (currently executing) frame, frame one is the frame that called the
3292 innermost one, and so on. The highest-numbered frame is the one for
3293 @code{main}.
3294
3295 @item frame @var{addr}
3296 @itemx f @var{addr}
3297 Select the frame at address @var{addr}. This is useful mainly if the
3298 chaining of stack frames has been damaged by a bug, making it
3299 impossible for @value{GDBN} to assign numbers properly to all frames. In
3300 addition, this can be useful when your program has multiple stacks and
3301 switches between them.
3302
3303 @ifclear H8EXCLUSIVE
3304 On the SPARC architecture, @code{frame} needs two addresses to
3305 select an arbitrary frame: a frame pointer and a stack pointer.
3306
3307 On the MIPS and Alpha architecture, it needs two addresses: a stack
3308 pointer and a program counter.
3309
3310 On the 29k architecture, it needs three addresses: a register stack
3311 pointer, a program counter, and a memory stack pointer.
3312 @c note to future updaters: this is conditioned on a flag
3313 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3314 @c as of 27 Jan 1994.
3315 @end ifclear
3316
3317 @item up @var{n}
3318 @kindex up
3319 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3320 advances toward the outermost frame, to higher frame numbers, to frames
3321 that have existed longer. @var{n} defaults to one.
3322
3323 @item down @var{n}
3324 @kindex down
3325 @kindex do
3326 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3327 advances toward the innermost frame, to lower frame numbers, to frames
3328 that were created more recently. @var{n} defaults to one. You may
3329 abbreviate @code{down} as @code{do}.
3330 @end table
3331
3332 All of these commands end by printing two lines of output describing the
3333 frame. The first line shows the frame number, the function name, the
3334 arguments, and the source file and line number of execution in that
3335 frame. The second line shows the text of that source line.
3336
3337 @need 1000
3338 For example:
3339
3340 @smallexample
3341 @group
3342 (@value{GDBP}) up
3343 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3344 at env.c:10
3345 10 read_input_file (argv[i]);
3346 @end group
3347 @end smallexample
3348
3349 After such a printout, the @code{list} command with no arguments
3350 prints ten lines centered on the point of execution in the frame.
3351 @xref{List, ,Printing source lines}.
3352
3353 @table @code
3354 @item up-silently @var{n}
3355 @itemx down-silently @var{n}
3356 @kindex down-silently
3357 @kindex up-silently
3358 These two commands are variants of @code{up} and @code{down},
3359 respectively; they differ in that they do their work silently, without
3360 causing display of the new frame. They are intended primarily for use
3361 in @value{GDBN} command scripts, where the output might be unnecessary and
3362 distracting.
3363 @end table
3364
3365 @node Frame Info
3366 @section Information about a frame
3367
3368 There are several other commands to print information about the selected
3369 stack frame.
3370
3371 @table @code
3372 @item frame
3373 @itemx f
3374 When used without any argument, this command does not change which
3375 frame is selected, but prints a brief description of the currently
3376 selected stack frame. It can be abbreviated @code{f}. With an
3377 argument, this command is used to select a stack frame.
3378 @xref{Selection, ,Selecting a frame}.
3379
3380 @item info frame
3381 @itemx info f
3382 @kindex info frame
3383 @kindex info f
3384 This command prints a verbose description of the selected stack frame,
3385 including the address of the frame, the addresses of the next frame down
3386 (called by this frame) and the next frame up (caller of this frame), the
3387 language that the source code corresponding to this frame was written in,
3388 the address of the frame's arguments, the program counter saved in it
3389 (the address of execution in the caller frame), and which registers
3390 were saved in the frame. The verbose description is useful when
3391 something has gone wrong that has made the stack format fail to fit
3392 the usual conventions.
3393
3394 @item info frame @var{addr}
3395 @itemx info f @var{addr}
3396 Print a verbose description of the frame at address @var{addr}, without
3397 selecting that frame. The selected frame remains unchanged by this
3398 command. This requires the same kind of address (more than one for some
3399 architectures) that you specify in the @code{frame} command.
3400 @xref{Selection, ,Selecting a frame}.
3401
3402 @item info args
3403 @kindex info args
3404 Print the arguments of the selected frame, each on a separate line.
3405
3406 @item info locals
3407 @kindex info locals
3408 Print the local variables of the selected frame, each on a separate
3409 line. These are all variables (declared either static or automatic)
3410 accessible at the point of execution of the selected frame.
3411
3412 @ifclear CONLY
3413 @item info catch
3414 @kindex info catch
3415 @cindex catch exceptions
3416 @cindex exception handlers
3417 Print a list of all the exception handlers that are active in the
3418 current stack frame at the current point of execution. To see other
3419 exception handlers, visit the associated frame (using the @code{up},
3420 @code{down}, or @code{frame} commands); then type @code{info catch}.
3421 @xref{Exception Handling, ,Breakpoints and exceptions}.
3422 @end ifclear
3423 @end table
3424
3425 @ifset MIPS
3426 @node MIPS Stack
3427 @section MIPS machines and the function stack
3428
3429 @cindex stack on MIPS
3430 @cindex MIPS stack
3431 MIPS based computers use an unusual stack frame, which sometimes
3432 requires @value{GDBN} to search backward in the object code to find the
3433 beginning of a function.
3434
3435 @cindex response time, MIPS debugging
3436 To improve response time (especially for embedded applications, where
3437 @value{GDBN} may be restricted to a slow serial line for this search)
3438 you may want to limit the size of this search, using one of these
3439 commands:
3440 @c FIXME! So what happens when GDB does *not* find the beginning of a
3441 @c function?
3442
3443 @cindex @code{heuristic-fence-post} (MIPS)
3444 @table @code
3445 @item set heuristic-fence-post @var{limit}
3446 Restrict @value{GDBN} to examining at most @var{limit} bytes in its search
3447 for the beginning of a function. A value of @code{0} (the default)
3448 means there is no limit.
3449
3450 @item show heuristic-fence-post
3451 Display the current limit.
3452 @end table
3453
3454 @noindent
3455 These commands are available @emph{only} when @value{GDBN} is configured
3456 for debugging programs on MIPS processors.
3457 @end ifset
3458
3459 @node Source
3460 @chapter Examining Source Files
3461
3462 @value{GDBN} can print parts of your program's source, since the debugging
3463 information recorded in the program tells @value{GDBN} what source files were
3464 used to build it. When your program stops, @value{GDBN} spontaneously prints
3465 the line where it stopped. Likewise, when you select a stack frame
3466 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3467 execution in that frame has stopped. You can print other portions of
3468 source files by explicit command.
3469
3470 @ifclear DOSHOST
3471 If you use @value{GDBN} through its GNU Emacs interface, you may prefer to use
3472 Emacs facilities to view source; @pxref{Emacs, ,Using @value{GDBN} under GNU
3473 Emacs}.
3474 @end ifclear
3475
3476 @menu
3477 * List:: Printing source lines
3478 @ifclear DOSHOST
3479 * Search:: Searching source files
3480 @end ifclear
3481
3482 * Source Path:: Specifying source directories
3483 * Machine Code:: Source and machine code
3484 @end menu
3485
3486 @node List
3487 @section Printing source lines
3488
3489 @kindex list
3490 @kindex l
3491 To print lines from a source file, use the @code{list} command
3492 (abbreviated @code{l}). There are several ways to specify what part
3493 of the file you want to print.
3494
3495 Here are the forms of the @code{list} command most commonly used:
3496
3497 @table @code
3498 @item list @var{linenum}
3499 Print lines centered around line number @var{linenum} in the
3500 current source file.
3501
3502 @item list @var{function}
3503 Print lines centered around the beginning of function
3504 @var{function}.
3505
3506 @item list
3507 Print more lines. If the last lines printed were printed with a
3508 @code{list} command, this prints lines following the last lines
3509 printed; however, if the last line printed was a solitary line printed
3510 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3511 Stack}), this prints lines centered around that line.
3512
3513 @item list -
3514 Print lines just before the lines last printed.
3515 @end table
3516
3517 By default, @value{GDBN} prints ten source lines with any of these forms of
3518 the @code{list} command. You can change this using @code{set listsize}:
3519
3520 @table @code
3521 @item set listsize @var{count}
3522 @kindex set listsize
3523 Make the @code{list} command display @var{count} source lines (unless
3524 the @code{list} argument explicitly specifies some other number).
3525
3526 @item show listsize
3527 @kindex show listsize
3528 Display the number of lines that @code{list} prints.
3529 @end table
3530
3531 Repeating a @code{list} command with @key{RET} discards the argument,
3532 so it is equivalent to typing just @code{list}. This is more useful
3533 than listing the same lines again. An exception is made for an
3534 argument of @samp{-}; that argument is preserved in repetition so that
3535 each repetition moves up in the source file.
3536
3537 @cindex linespec
3538 In general, the @code{list} command expects you to supply zero, one or two
3539 @dfn{linespecs}. Linespecs specify source lines; there are several ways
3540 of writing them but the effect is always to specify some source line.
3541 Here is a complete description of the possible arguments for @code{list}:
3542
3543 @table @code
3544 @item list @var{linespec}
3545 Print lines centered around the line specified by @var{linespec}.
3546
3547 @item list @var{first},@var{last}
3548 Print lines from @var{first} to @var{last}. Both arguments are
3549 linespecs.
3550
3551 @item list ,@var{last}
3552 Print lines ending with @var{last}.
3553
3554 @item list @var{first},
3555 Print lines starting with @var{first}.
3556
3557 @item list +
3558 Print lines just after the lines last printed.
3559
3560 @item list -
3561 Print lines just before the lines last printed.
3562
3563 @item list
3564 As described in the preceding table.
3565 @end table
3566
3567 Here are the ways of specifying a single source line---all the
3568 kinds of linespec.
3569
3570 @table @code
3571 @item @var{number}
3572 Specifies line @var{number} of the current source file.
3573 When a @code{list} command has two linespecs, this refers to
3574 the same source file as the first linespec.
3575
3576 @item +@var{offset}
3577 Specifies the line @var{offset} lines after the last line printed.
3578 When used as the second linespec in a @code{list} command that has
3579 two, this specifies the line @var{offset} lines down from the
3580 first linespec.
3581
3582 @item -@var{offset}
3583 Specifies the line @var{offset} lines before the last line printed.
3584
3585 @item @var{filename}:@var{number}
3586 Specifies line @var{number} in the source file @var{filename}.
3587
3588 @item @var{function}
3589 @c FIXME: "of the open-brace" is C-centric. When we add other langs...
3590 Specifies the line of the open-brace that begins the body of the
3591 function @var{function}.
3592
3593 @item @var{filename}:@var{function}
3594 Specifies the line of the open-brace that begins the body of the
3595 function @var{function} in the file @var{filename}. You only need the
3596 file name with a function name to avoid ambiguity when there are
3597 identically named functions in different source files.
3598
3599 @item *@var{address}
3600 Specifies the line containing the program address @var{address}.
3601 @var{address} may be any expression.
3602 @end table
3603
3604 @ifclear DOSHOST
3605 @node Search
3606 @section Searching source files
3607 @cindex searching
3608 @kindex reverse-search
3609
3610 There are two commands for searching through the current source file for a
3611 regular expression.
3612
3613 @table @code
3614 @item forward-search @var{regexp}
3615 @itemx search @var{regexp}
3616 @kindex search
3617 @kindex forward-search
3618 The command @samp{forward-search @var{regexp}} checks each line,
3619 starting with the one following the last line listed, for a match for
3620 @var{regexp}. It lists the line that is found. You can use
3621 synonym @samp{search @var{regexp}} or abbreviate the command name as
3622 @code{fo}.
3623
3624 @item reverse-search @var{regexp}
3625 The command @samp{reverse-search @var{regexp}} checks each line, starting
3626 with the one before the last line listed and going backward, for a match
3627 for @var{regexp}. It lists the line that is found. You can abbreviate
3628 this command as @code{rev}.
3629 @end table
3630 @end ifclear
3631
3632 @node Source Path
3633 @section Specifying source directories
3634
3635 @cindex source path
3636 @cindex directories for source files
3637 Executable programs sometimes do not record the directories of the source
3638 files from which they were compiled, just the names. Even when they do,
3639 the directories could be moved between the compilation and your debugging
3640 session. @value{GDBN} has a list of directories to search for source files;
3641 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
3642 it tries all the directories in the list, in the order they are present
3643 in the list, until it finds a file with the desired name. Note that
3644 the executable search path is @emph{not} used for this purpose. Neither is
3645 the current working directory, unless it happens to be in the source
3646 path.
3647
3648 If @value{GDBN} cannot find a source file in the source path, and the
3649 object program records a directory, @value{GDBN} tries that directory
3650 too. If the source path is empty, and there is no record of the
3651 compilation directory, @value{GDBN} looks in the current directory as a
3652 last resort.
3653
3654 Whenever you reset or rearrange the source path, @value{GDBN} clears out
3655 any information it has cached about where source files are found and where
3656 each line is in the file.
3657
3658 @kindex directory
3659 When you start @value{GDBN}, its source path is empty.
3660 To add other directories, use the @code{directory} command.
3661
3662 @table @code
3663 @item directory @var{dirname} @dots{}
3664 Add directory @var{dirname} to the front of the source path. Several
3665 directory names may be given to this command, separated by @samp{:} or
3666 whitespace. You may specify a directory that is already in the source
3667 path; this moves it forward, so @value{GDBN} searches it sooner.
3668
3669 @kindex cdir
3670 @kindex cwd
3671 @kindex $cdir
3672 @kindex $cwd
3673 @cindex compilation directory
3674 @cindex current directory
3675 @cindex working directory
3676 @cindex directory, current
3677 @cindex directory, compilation
3678 You can use the string @samp{$cdir} to refer to the compilation
3679 directory (if one is recorded), and @samp{$cwd} to refer to the current
3680 working directory. @samp{$cwd} is not the same as @samp{.}---the former
3681 tracks the current working directory as it changes during your @value{GDBN}
3682 session, while the latter is immediately expanded to the current
3683 directory at the time you add an entry to the source path.
3684
3685 @item directory
3686 Reset the source path to empty again. This requires confirmation.
3687
3688 @c RET-repeat for @code{directory} is explicitly disabled, but since
3689 @c repeating it would be a no-op we do not say that. (thanks to RMS)
3690
3691 @item show directories
3692 @kindex show directories
3693 Print the source path: show which directories it contains.
3694 @end table
3695
3696 If your source path is cluttered with directories that are no longer of
3697 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
3698 versions of source. You can correct the situation as follows:
3699
3700 @enumerate
3701 @item
3702 Use @code{directory} with no argument to reset the source path to empty.
3703
3704 @item
3705 Use @code{directory} with suitable arguments to reinstall the
3706 directories you want in the source path. You can add all the
3707 directories in one command.
3708 @end enumerate
3709
3710 @node Machine Code
3711 @section Source and machine code
3712
3713 You can use the command @code{info line} to map source lines to program
3714 addresses (and vice versa), and the command @code{disassemble} to display
3715 a range of addresses as machine instructions.
3716
3717 @table @code
3718 @item info line @var{linespec}
3719 @kindex info line
3720 Print the starting and ending addresses of the compiled code for
3721 source line @var{linespec}. You can specify source lines in any of
3722 the ways understood by the @code{list} command (@pxref{List, ,Printing
3723 source lines}).
3724 @end table
3725
3726 For example, we can use @code{info line} to discover the location of
3727 the object code for the first line of function
3728 @code{m4_changequote}:
3729
3730 @smallexample
3731 (@value{GDBP}) info line m4_changecom
3732 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3733 @end smallexample
3734
3735 @noindent
3736 We can also inquire (using @code{*@var{addr}} as the form for
3737 @var{linespec}) what source line covers a particular address:
3738 @smallexample
3739 (@value{GDBP}) info line *0x63ff
3740 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3741 @end smallexample
3742
3743 @cindex @code{$_} and @code{info line}
3744 After @code{info line}, the default address for the @code{x} command
3745 is changed to the starting address of the line, so that @samp{x/i} is
3746 sufficient to begin examining the machine code (@pxref{Memory,
3747 ,Examining memory}). Also, this address is saved as the value of the
3748 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3749 variables}).
3750
3751 @table @code
3752 @kindex disassemble
3753 @item disassemble
3754 @cindex assembly instructions
3755 @cindex instructions, assembly
3756 @cindex machine instructions
3757 @cindex listing machine instructions
3758 This specialized command dumps a range of memory as machine
3759 instructions. The default memory range is the function surrounding the
3760 program counter of the selected frame. A single argument to this
3761 command is a program counter value; @value{GDBN} dumps the function
3762 surrounding this value. Two arguments specify a range of addresses
3763 (first inclusive, second exclusive) to dump.
3764 @end table
3765
3766 @ifclear H8EXCLUSIVE
3767 We can use @code{disassemble} to inspect the object code
3768 range shown in the last @code{info line} example (the example
3769 shows SPARC machine instructions):
3770
3771
3772 @smallexample
3773 (@value{GDBP}) disas 0x63e4 0x6404
3774 Dump of assembler code from 0x63e4 to 0x6404:
3775 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360>
3776 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0
3777 0x63ec <builtin_init+5348>: ld [%i1+4], %o0
3778 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364>
3779 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0
3780 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0
3781 0x63fc <builtin_init+5364>: call 0x9288 <path_search>
3782 0x6400 <builtin_init+5368>: nop
3783 End of assembler dump.
3784 @end smallexample
3785 @end ifclear
3786
3787 @ifset H8EXCLUSIVE
3788 For example, here is the beginning of the output for the
3789 disassembly of a function @code{fact}:
3790
3791
3792 @smallexample
3793 (@value{GDBP}) disas fact
3794 Dump of assembler code for function fact:
3795 to 0x808c:
3796 0x802c <fact>: 6d f2 mov.w r2,@@-r7
3797 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7
3798 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7
3799 0x8032 <fact+6>: 0d 76 mov.w r7,r6
3800 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0
3801 0x8038 <fact+12> 19 11 sub.w r1,r1
3802 .
3803 .
3804 .
3805 @end smallexample
3806 @end ifset
3807
3808 @node Data
3809 @chapter Examining Data
3810
3811 @cindex printing data
3812 @cindex examining data
3813 @kindex print
3814 @kindex inspect
3815 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
3816 @c document because it is nonstandard... Under Epoch it displays in a
3817 @c different window or something like that.
3818 The usual way to examine data in your program is with the @code{print}
3819 command (abbreviated @code{p}), or its synonym @code{inspect}.
3820 @ifclear CONLY
3821 It evaluates and prints the value of an expression of the language your
3822 program is written in (@pxref{Languages, ,Using @value{GDBN} with Different
3823 Languages}).
3824 @end ifclear
3825
3826 @table @code
3827 @item print @var{exp}
3828 @itemx print /@var{f} @var{exp}
3829 @var{exp} is an expression (in the source language). By default the
3830 value of @var{exp} is printed in a format appropriate to its data type;
3831 you can choose a different format by specifying @samp{/@var{f}}, where
3832 @var{f} is a letter specifying the format; @pxref{Output Formats,,Output
3833 formats}.
3834
3835 @item print
3836 @itemx print /@var{f}
3837 If you omit @var{exp}, @value{GDBN} displays the last value again (from the
3838 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
3839 conveniently inspect the same value in an alternative format.
3840 @end table
3841
3842 A more low-level way of examining data is with the @code{x} command.
3843 It examines data in memory at a specified address and prints it in a
3844 specified format. @xref{Memory, ,Examining memory}.
3845
3846 If you are interested in information about types, or about how the fields
3847 of a struct
3848 @ifclear CONLY
3849 or class
3850 @end ifclear
3851 are declared, use the @code{ptype @var{exp}}
3852 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}.
3853
3854 @menu
3855 * Expressions:: Expressions
3856 * Variables:: Program variables
3857 * Arrays:: Artificial arrays
3858 * Output Formats:: Output formats
3859 * Memory:: Examining memory
3860 * Auto Display:: Automatic display
3861 * Print Settings:: Print settings
3862 * Value History:: Value history
3863 * Convenience Vars:: Convenience variables
3864 * Registers:: Registers
3865 @ifclear HAVE-FLOAT
3866 * Floating Point Hardware:: Floating point hardware
3867 @end ifclear
3868 @end menu
3869
3870 @node Expressions
3871 @section Expressions
3872
3873 @cindex expressions
3874 @code{print} and many other @value{GDBN} commands accept an expression and
3875 compute its value. Any kind of constant, variable or operator defined
3876 by the programming language you are using is valid in an expression in
3877 @value{GDBN}. This includes conditional expressions, function calls, casts
3878 and string constants. It unfortunately does not include symbols defined
3879 by preprocessor @code{#define} commands.
3880
3881 @ifclear CONLY
3882 Because C is so widespread, most of the expressions shown in examples in
3883 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
3884 Languages}, for information on how to use expressions in other
3885 languages.
3886
3887 In this section, we discuss operators that you can use in @value{GDBN}
3888 expressions regardless of your programming language.
3889
3890 Casts are supported in all languages, not just in C, because it is so
3891 useful to cast a number into a pointer so as to examine a structure
3892 at that address in memory.
3893 @c FIXME: casts supported---Mod2 true?
3894 @end ifclear
3895
3896 @value{GDBN} supports these operators in addition to those of programming
3897 languages:
3898
3899 @table @code
3900 @item @@
3901 @samp{@@} is a binary operator for treating parts of memory as arrays.
3902 @xref{Arrays, ,Artificial arrays}, for more information.
3903
3904 @item ::
3905 @samp{::} allows you to specify a variable in terms of the file or
3906 function where it is defined. @xref{Variables, ,Program variables}.
3907
3908 @item @{@var{type}@} @var{addr}
3909 @cindex @{@var{type}@}
3910 @cindex type casting memory
3911 @cindex memory, viewing as typed object
3912 @cindex casts, to view memory
3913 Refers to an object of type @var{type} stored at address @var{addr} in
3914 memory. @var{addr} may be any expression whose value is an integer or
3915 pointer (but parentheses are required around binary operators, just as in
3916 a cast). This construct is allowed regardless of what kind of data is
3917 normally supposed to reside at @var{addr}.
3918 @end table
3919
3920 @node Variables
3921 @section Program variables
3922
3923 The most common kind of expression to use is the name of a variable
3924 in your program.
3925
3926 Variables in expressions are understood in the selected stack frame
3927 (@pxref{Selection, ,Selecting a frame}); they must either be global
3928 (or static) or be visible according to the scope rules of the
3929 programming language from the point of execution in that frame. This
3930 means that in the function
3931
3932 @example
3933 foo (a)
3934 int a;
3935 @{
3936 bar (a);
3937 @{
3938 int b = test ();
3939 bar (b);
3940 @}
3941 @}
3942 @end example
3943
3944 @noindent
3945 you can examine and use the variable @code{a} whenever your program is
3946 executing within the function @code{foo}, but you can only use or
3947 examine the variable @code{b} while your program is executing inside
3948 the block where @code{b} is declared.
3949
3950 @cindex variable name conflict
3951 There is an exception: you can refer to a variable or function whose
3952 scope is a single source file even if the current execution point is not
3953 in this file. But it is possible to have more than one such variable or
3954 function with the same name (in different source files). If that
3955 happens, referring to that name has unpredictable effects. If you wish,
3956 you can specify a static variable in a particular function or file,
3957 using the colon-colon notation:
3958
3959 @cindex colon-colon
3960 @iftex
3961 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
3962 @kindex ::
3963 @end iftex
3964 @example
3965 @var{file}::@var{variable}
3966 @var{function}::@var{variable}
3967 @end example
3968
3969 @noindent
3970 Here @var{file} or @var{function} is the name of the context for the
3971 static @var{variable}. In the case of file names, you can use quotes to
3972 make sure @value{GDBN} parses the file name as a single word---for example,
3973 to print a global value of @code{x} defined in @file{f2.c}:
3974
3975 @example
3976 (@value{GDBP}) p 'f2.c'::x
3977 @end example
3978
3979 @ifclear CONLY
3980 @cindex C++ scope resolution
3981 This use of @samp{::} is very rarely in conflict with the very similar
3982 use of the same notation in C++. @value{GDBN} also supports use of the C++
3983 scope resolution operator in @value{GDBN} expressions.
3984 @c FIXME: Um, so what happens in one of those rare cases where it's in
3985 @c conflict?? --mew
3986 @end ifclear
3987
3988 @cindex wrong values
3989 @cindex variable values, wrong
3990 @quotation
3991 @emph{Warning:} Occasionally, a local variable may appear to have the
3992 wrong value at certain points in a function---just after entry to a new
3993 scope, and just before exit.
3994 @end quotation
3995 You may see this problem when you are stepping by machine instructions.
3996 This is because on most machines, it takes more than one instruction to
3997 set up a stack frame (including local variable definitions); if you are
3998 stepping by machine instructions, variables may appear to have the wrong
3999 values until the stack frame is completely built. On exit, it usually
4000 also takes more than one machine instruction to destroy a stack frame;
4001 after you begin stepping through that group of instructions, local
4002 variable definitions may be gone.
4003
4004 @node Arrays
4005 @section Artificial arrays
4006
4007 @cindex artificial array
4008 @kindex @@
4009 It is often useful to print out several successive objects of the
4010 same type in memory; a section of an array, or an array of
4011 dynamically determined size for which only a pointer exists in the
4012 program.
4013
4014 You can do this by referring to a contiguous span of memory as an
4015 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4016 operand of @samp{@@} should be the first element of the desired array,
4017 as an individual object. The right operand should be the desired length
4018 of the array. The result is an array value whose elements are all of
4019 the type of the left argument. The first element is actually the left
4020 argument; the second element comes from bytes of memory immediately
4021 following those that hold the first element, and so on. Here is an
4022 example. If a program says
4023
4024 @example
4025 int *array = (int *) malloc (len * sizeof (int));
4026 @end example
4027
4028 @noindent
4029 you can print the contents of @code{array} with
4030
4031 @example
4032 p *array@@len
4033 @end example
4034
4035 The left operand of @samp{@@} must reside in memory. Array values made
4036 with @samp{@@} in this way behave just like other arrays in terms of
4037 subscripting, and are coerced to pointers when used in expressions.
4038 Artificial arrays most often appear in expressions via the value history
4039 (@pxref{Value History, ,Value history}), after printing one out.
4040
4041 Sometimes the artificial array mechanism is not quite enough; in
4042 moderately complex data structures, the elements of interest may not
4043 actually be adjacent---for example, if you are interested in the values
4044 of pointers in an array. One useful work-around in this situation is
4045 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4046 variables}) as a counter in an expression that prints the first
4047 interesting value, and then repeat that expression via @key{RET}. For
4048 instance, suppose you have an array @code{dtab} of pointers to
4049 structures, and you are interested in the values of a field @code{fv}
4050 in each structure. Here is an example of what you might type:
4051
4052 @example
4053 set $i = 0
4054 p dtab[$i++]->fv
4055 @key{RET}
4056 @key{RET}
4057 @dots{}
4058 @end example
4059
4060 @node Output Formats
4061 @section Output formats
4062
4063 @cindex formatted output
4064 @cindex output formats
4065 By default, @value{GDBN} prints a value according to its data type. Sometimes
4066 this is not what you want. For example, you might want to print a number
4067 in hex, or a pointer in decimal. Or you might want to view data in memory
4068 at a certain address as a character string or as an instruction. To do
4069 these things, specify an @dfn{output format} when you print a value.
4070
4071 The simplest use of output formats is to say how to print a value
4072 already computed. This is done by starting the arguments of the
4073 @code{print} command with a slash and a format letter. The format
4074 letters supported are:
4075
4076 @table @code
4077 @item x
4078 Regard the bits of the value as an integer, and print the integer in
4079 hexadecimal.
4080
4081 @item d
4082 Print as integer in signed decimal.
4083
4084 @item u
4085 Print as integer in unsigned decimal.
4086
4087 @item o
4088 Print as integer in octal.
4089
4090 @item t
4091 Print as integer in binary. The letter @samp{t} stands for ``two''.
4092 @footnote{@samp{b} cannot be used because these format letters are also
4093 used with the @code{x} command, where @samp{b} stands for ``byte'';
4094 @pxref{Memory,,Examining memory}.}
4095
4096 @item a
4097 @cindex unknown address, locating
4098 Print as an address, both absolute in hexadecimal and as an offset from
4099 the nearest preceding symbol. You can use this format used to discover
4100 where (in what function) an unknown address is located:
4101
4102 @example
4103 (@value{GDBP}) p/a 0x54320
4104 $3 = 0x54320 <_initialize_vx+396>
4105 @end example
4106
4107 @item c
4108 Regard as an integer and print it as a character constant.
4109
4110 @item f
4111 Regard the bits of the value as a floating point number and print
4112 using typical floating point syntax.
4113 @end table
4114
4115 For example, to print the program counter in hex (@pxref{Registers}), type
4116
4117 @example
4118 p/x $pc
4119 @end example
4120
4121 @noindent
4122 Note that no space is required before the slash; this is because command
4123 names in @value{GDBN} cannot contain a slash.
4124
4125 To reprint the last value in the value history with a different format,
4126 you can use the @code{print} command with just a format and no
4127 expression. For example, @samp{p/x} reprints the last value in hex.
4128
4129 @node Memory
4130 @section Examining memory
4131
4132 You can use the command @code{x} (for ``examine'') to examine memory in
4133 any of several formats, independently of your program's data types.
4134
4135 @cindex examining memory
4136 @table @code
4137 @kindex x
4138 @item x/@var{nfu} @var{addr}
4139 @itemx x @var{addr}
4140 @itemx x
4141 Use the @code{x} command to examine memory.
4142 @end table
4143
4144 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4145 much memory to display and how to format it; @var{addr} is an
4146 expression giving the address where you want to start displaying memory.
4147 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4148 Several commands set convenient defaults for @var{addr}.
4149
4150 @table @r
4151 @item @var{n}, the repeat count
4152 The repeat count is a decimal integer; the default is 1. It specifies
4153 how much memory (counting by units @var{u}) to display.
4154 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4155 @c 4.1.2.
4156
4157 @item @var{f}, the display format
4158 The display format is one of the formats used by @code{print},
4159 or @samp{s} (null-terminated string) or @samp{i} (machine instruction).
4160 The default is @samp{x} (hexadecimal) initially, or the format from the
4161 last time you used either @code{x} or @code{print}.
4162
4163 @item @var{u}, the unit size
4164 The unit size is any of
4165
4166 @table @code
4167 @item b
4168 Bytes.
4169 @item h
4170 Halfwords (two bytes).
4171 @item w
4172 Words (four bytes). This is the initial default.
4173 @item g
4174 Giant words (eight bytes).
4175 @end table
4176
4177 Each time you specify a unit size with @code{x}, that size becomes the
4178 default unit the next time you use @code{x}. (For the @samp{s} and
4179 @samp{i} formats, the unit size is ignored and is normally not written.)
4180
4181 @item @var{addr}, starting display address
4182 @var{addr} is the address where you want @value{GDBN} to begin displaying
4183 memory. The expression need not have a pointer value (though it may);
4184 it is always interpreted as an integer address of a byte of memory.
4185 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4186 @var{addr} is usually just after the last address examined---but several
4187 other commands also set the default address: @code{info breakpoints} (to
4188 the address of the last breakpoint listed), @code{info line} (to the
4189 starting address of a line), and @code{print} (if you use it to display
4190 a value from memory).
4191 @end table
4192
4193 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4194 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4195 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4196 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4197 @pxref{Registers}) in hexadecimal (@samp{x}).
4198
4199 Since the letters indicating unit sizes are all distinct from the
4200 letters specifying output formats, you do not have to remember whether
4201 unit size or format comes first; either order works. The output
4202 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4203 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4204
4205 Even though the unit size @var{u} is ignored for the formats @samp{s}
4206 and @samp{i}, you might still want to use a count @var{n}; for example,
4207 @samp{3i} specifies that you want to see three machine instructions,
4208 including any operands. The command @code{disassemble} gives an
4209 alternative way of inspecting machine instructions; @pxref{Machine
4210 Code,,Source and machine code}.
4211
4212 All the defaults for the arguments to @code{x} are designed to make it
4213 easy to continue scanning memory with minimal specifications each time
4214 you use @code{x}. For example, after you have inspected three machine
4215 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4216 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4217 the repeat count @var{n} is used again; the other arguments default as
4218 for successive uses of @code{x}.
4219
4220 @cindex @code{$_}, @code{$__}, and value history
4221 The addresses and contents printed by the @code{x} command are not saved
4222 in the value history because there is often too much of them and they
4223 would get in the way. Instead, @value{GDBN} makes these values available for
4224 subsequent use in expressions as values of the convenience variables
4225 @code{$_} and @code{$__}. After an @code{x} command, the last address
4226 examined is available for use in expressions in the convenience variable
4227 @code{$_}. The contents of that address, as examined, are available in
4228 the convenience variable @code{$__}.
4229
4230 If the @code{x} command has a repeat count, the address and contents saved
4231 are from the last memory unit printed; this is not the same as the last
4232 address printed if several units were printed on the last line of output.
4233
4234 @node Auto Display
4235 @section Automatic display
4236 @cindex automatic display
4237 @cindex display of expressions
4238
4239 If you find that you want to print the value of an expression frequently
4240 (to see how it changes), you might want to add it to the @dfn{automatic
4241 display list} so that @value{GDBN} prints its value each time your program stops.
4242 Each expression added to the list is given a number to identify it;
4243 to remove an expression from the list, you specify that number.
4244 The automatic display looks like this:
4245
4246 @example
4247 2: foo = 38
4248 3: bar[5] = (struct hack *) 0x3804
4249 @end example
4250
4251 @noindent
4252 This display shows item numbers, expressions and their current values. As with
4253 displays you request manually using @code{x} or @code{print}, you can
4254 specify the output format you prefer; in fact, @code{display} decides
4255 whether to use @code{print} or @code{x} depending on how elaborate your
4256 format specification is---it uses @code{x} if you specify a unit size,
4257 or one of the two formats (@samp{i} and @samp{s}) that are only
4258 supported by @code{x}; otherwise it uses @code{print}.
4259
4260 @table @code
4261 @item display @var{exp}
4262 @kindex display
4263 Add the expression @var{exp} to the list of expressions to display
4264 each time your program stops. @xref{Expressions, ,Expressions}.
4265
4266 @code{display} does not repeat if you press @key{RET} again after using it.
4267
4268 @item display/@var{fmt} @var{exp}
4269 For @var{fmt} specifying only a display format and not a size or
4270 count, add the expression @var{exp} to the auto-display list but
4271 arrange to display it each time in the specified format @var{fmt}.
4272 @xref{Output Formats,,Output formats}.
4273
4274 @item display/@var{fmt} @var{addr}
4275 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4276 number of units, add the expression @var{addr} as a memory address to
4277 be examined each time your program stops. Examining means in effect
4278 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4279 @end table
4280
4281 For example, @samp{display/i $pc} can be helpful, to see the machine
4282 instruction about to be executed each time execution stops (@samp{$pc}
4283 is a common name for the program counter; @pxref{Registers}).
4284
4285 @table @code
4286 @item undisplay @var{dnums}@dots{}
4287 @itemx delete display @var{dnums}@dots{}
4288 @kindex delete display
4289 @kindex undisplay
4290 Remove item numbers @var{dnums} from the list of expressions to display.
4291
4292 @code{undisplay} does not repeat if you press @key{RET} after using it.
4293 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4294
4295 @item disable display @var{dnums}@dots{}
4296 @kindex disable display
4297 Disable the display of item numbers @var{dnums}. A disabled display
4298 item is not printed automatically, but is not forgotten. It may be
4299 enabled again later.
4300
4301 @item enable display @var{dnums}@dots{}
4302 @kindex enable display
4303 Enable display of item numbers @var{dnums}. It becomes effective once
4304 again in auto display of its expression, until you specify otherwise.
4305
4306 @item display
4307 Display the current values of the expressions on the list, just as is
4308 done when your program stops.
4309
4310 @item info display
4311 @kindex info display
4312 Print the list of expressions previously set up to display
4313 automatically, each one with its item number, but without showing the
4314 values. This includes disabled expressions, which are marked as such.
4315 It also includes expressions which would not be displayed right now
4316 because they refer to automatic variables not currently available.
4317 @end table
4318
4319 If a display expression refers to local variables, then it does not make
4320 sense outside the lexical context for which it was set up. Such an
4321 expression is disabled when execution enters a context where one of its
4322 variables is not defined. For example, if you give the command
4323 @code{display last_char} while inside a function with an argument
4324 @code{last_char}, @value{GDBN} displays this argument while your program
4325 continues to stop inside that function. When it stops elsewhere---where
4326 there is no variable @code{last_char}---the display is disabled
4327 automatically. The next time your program stops where @code{last_char}
4328 is meaningful, you can enable the display expression once again.
4329
4330 @node Print Settings
4331 @section Print settings
4332
4333 @cindex format options
4334 @cindex print settings
4335 @value{GDBN} provides the following ways to control how arrays, structures,
4336 and symbols are printed.
4337
4338 @noindent
4339 These settings are useful for debugging programs in any language:
4340
4341 @table @code
4342 @item set print address
4343 @itemx set print address on
4344 @kindex set print address
4345 @value{GDBN} prints memory addresses showing the location of stack
4346 traces, structure values, pointer values, breakpoints, and so forth,
4347 even when it also displays the contents of those addresses. The default
4348 is @code{on}. For example, this is what a stack frame display looks like, with
4349 @code{set print address on}:
4350
4351 @smallexample
4352 @group
4353 (@value{GDBP}) f
4354 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4355 at input.c:530
4356 530 if (lquote != def_lquote)
4357 @end group
4358 @end smallexample
4359
4360 @item set print address off
4361 Do not print addresses when displaying their contents. For example,
4362 this is the same stack frame displayed with @code{set print address off}:
4363
4364 @smallexample
4365 @group
4366 (@value{GDBP}) set print addr off
4367 (@value{GDBP}) f
4368 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4369 530 if (lquote != def_lquote)
4370 @end group
4371 @end smallexample
4372
4373 You can use @samp{set print address off} to eliminate all machine
4374 dependent displays from the @value{GDBN} interface. For example, with
4375 @code{print address off}, you should get the same text for backtraces on
4376 all machines---whether or not they involve pointer arguments.
4377
4378 @item show print address
4379 @kindex show print address
4380 Show whether or not addresses are to be printed.
4381 @end table
4382
4383 When @value{GDBN} prints a symbolic address, it normally prints the
4384 closest earlier symbol plus an offset. If that symbol does not uniquely
4385 identify the address (for example, it is a name whose scope is a single
4386 source file), you may need to disambiguate. One way to do this is with
4387 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4388 you can set @value{GDBN} to print the source file and line number when
4389 it prints a symbolic address:
4390
4391 @table @code
4392 @item set print symbol-filename on
4393 @kindex set print symbol-filename
4394 Tell @value{GDBN} to print the source file name and line number of a
4395 symbol in the symbolic form of an address.
4396
4397 @item set print symbol-filename off
4398 Do not print source file name and line number of a symbol. This is the
4399 default.
4400
4401 @item show print symbol-filename
4402 @kindex show print symbol-filename
4403 Show whether or not @value{GDBN} will print the source file name and
4404 line number of a symbol in the symbolic form of an address.
4405 @end table
4406
4407 Another situation where it is helpful to show symbol filenames and line
4408 numbers is when disassembling code; @value{GDBN} shows you the line
4409 number and source file that corresponds to each instruction.
4410
4411 Also, you may wish to see the symbolic form only if the address being
4412 printed is reasonably close to the closest earlier symbol:
4413
4414 @table @code
4415 @item set print max-symbolic-offset @var{max-offset}
4416 @kindex set print max-symbolic-offset
4417 Tell @value{GDBN} to only display the symbolic form of an address if the
4418 offset between the closest earlier symbol and the address is less than
4419 @var{max-offset}. The default is 0, which means to always print the
4420 symbolic form of an address, if any symbol precedes it.
4421
4422 @item show print max-symbolic-offset
4423 @kindex show print max-symbolic-offset
4424 Ask how large the maximum offset is that @value{GDBN} prints in a
4425 symbolic address.
4426 @end table
4427
4428 @cindex wild pointer, interpreting
4429 @cindex pointer, finding referent
4430 If you have a pointer and you are not sure where it points, try
4431 @samp{set print symbol-filename on}. Then you can determine the name
4432 and source file location of the variable where it points, using
4433 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4434 For example, here @value{GDBN} shows that a variable @code{ptt} points
4435 at another variable @code{t}, defined in @file{hi2.c}:
4436
4437 @example
4438 (@value{GDBP}) set print symbol-filename on
4439 (@value{GDBP}) p/a ptt
4440 $4 = 0xe008 <t in hi2.c>
4441 @end example
4442
4443 @quotation
4444 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4445 does not show the symbol name and filename of the referent, even with
4446 the appropriate @code{set print} options turned on.
4447 @end quotation
4448
4449 Other settings control how different kinds of objects are printed:
4450
4451 @table @code
4452 @item set print array
4453 @itemx set print array on
4454 @kindex set print array
4455 Pretty-print arrays. This format is more convenient to read,
4456 but uses more space. The default is off.
4457
4458 @item set print array off
4459 Return to compressed format for arrays.
4460
4461 @item show print array
4462 @kindex show print array
4463 Show whether compressed or pretty format is selected for displaying
4464 arrays.
4465
4466 @item set print elements @var{number-of-elements}
4467 @kindex set print elements
4468 If @value{GDBN} is printing a large array, it stops printing after it has
4469 printed the number of elements set by the @code{set print elements} command.
4470 This limit also applies to the display of strings.
4471 Setting the number of elements to zero means that the printing is unlimited.
4472
4473 @item show print elements
4474 @kindex show print elements
4475 Display the number of elements of a large array that @value{GDBN} prints
4476 before losing patience.
4477
4478 @item set print pretty on
4479 @kindex set print pretty
4480 Cause @value{GDBN} to print structures in an indented format with one member per
4481 line, like this:
4482
4483 @smallexample
4484 @group
4485 $1 = @{
4486 next = 0x0,
4487 flags = @{
4488 sweet = 1,
4489 sour = 1
4490 @},
4491 meat = 0x54 "Pork"
4492 @}
4493 @end group
4494 @end smallexample
4495
4496 @item set print pretty off
4497 Cause @value{GDBN} to print structures in a compact format, like this:
4498
4499 @smallexample
4500 @group
4501 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4502 meat = 0x54 "Pork"@}
4503 @end group
4504 @end smallexample
4505
4506 @noindent
4507 This is the default format.
4508
4509 @item show print pretty
4510 @kindex show print pretty
4511 Show which format @value{GDBN} is using to print structures.
4512
4513 @item set print sevenbit-strings on
4514 @kindex set print sevenbit-strings
4515 Print using only seven-bit characters; if this option is set,
4516 @value{GDBN} displays any eight-bit characters (in strings or
4517 character values) using the notation @code{\}@var{nnn}. This setting is
4518 best if you are working in English (@sc{ascii}) and you use the
4519 high-order bit of characters as a marker or ``meta'' bit.
4520
4521 @item set print sevenbit-strings off
4522 Print full eight-bit characters. This allows the use of more
4523 international character sets, and is the default.
4524
4525 @item show print sevenbit-strings
4526 @kindex show print sevenbit-strings
4527 Show whether or not @value{GDBN} is printing only seven-bit characters.
4528
4529 @item set print union on
4530 @kindex set print union
4531 Tell @value{GDBN} to print unions which are contained in structures. This is the
4532 default setting.
4533
4534 @item set print union off
4535 Tell @value{GDBN} not to print unions which are contained in structures.
4536
4537 @item show print union
4538 @kindex show print union
4539 Ask @value{GDBN} whether or not it will print unions which are contained in
4540 structures.
4541
4542 For example, given the declarations
4543
4544 @smallexample
4545 typedef enum @{Tree, Bug@} Species;
4546 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
4547 typedef enum @{Caterpillar, Cocoon, Butterfly@}
4548 Bug_forms;
4549
4550 struct thing @{
4551 Species it;
4552 union @{
4553 Tree_forms tree;
4554 Bug_forms bug;
4555 @} form;
4556 @};
4557
4558 struct thing foo = @{Tree, @{Acorn@}@};
4559 @end smallexample
4560
4561 @noindent
4562 with @code{set print union on} in effect @samp{p foo} would print
4563
4564 @smallexample
4565 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4566 @end smallexample
4567
4568 @noindent
4569 and with @code{set print union off} in effect it would print
4570
4571 @smallexample
4572 $1 = @{it = Tree, form = @{...@}@}
4573 @end smallexample
4574 @end table
4575
4576 @ifclear CONLY
4577 @need 1000
4578 @noindent
4579 These settings are of interest when debugging C++ programs:
4580
4581 @table @code
4582 @item set print demangle
4583 @itemx set print demangle on
4584 @kindex set print demangle
4585 Print C++ names in their source form rather than in the encoded
4586 (``mangled'') form passed to the assembler and linker for type-safe
4587 linkage. The default is @samp{on}.
4588
4589 @item show print demangle
4590 @kindex show print demangle
4591 Show whether C++ names are printed in mangled or demangled form.
4592
4593 @item set print asm-demangle
4594 @itemx set print asm-demangle on
4595 @kindex set print asm-demangle
4596 Print C++ names in their source form rather than their mangled form, even
4597 in assembler code printouts such as instruction disassemblies.
4598 The default is off.
4599
4600 @item show print asm-demangle
4601 @kindex show print asm-demangle
4602 Show whether C++ names in assembly listings are printed in mangled
4603 or demangled form.
4604
4605 @item set demangle-style @var{style}
4606 @kindex set demangle-style
4607 @cindex C++ symbol decoding style
4608 @cindex symbol decoding style, C++
4609 Choose among several encoding schemes used by different compilers to
4610 represent C++ names. The choices for @var{style} are currently:
4611
4612 @table @code
4613 @item auto
4614 Allow @value{GDBN} to choose a decoding style by inspecting your program.
4615
4616 @item gnu
4617 Decode based on the GNU C++ compiler (@code{g++}) encoding algorithm.
4618
4619 @item lucid
4620 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
4621
4622 @item arm
4623 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
4624 @strong{Warning:} this setting alone is not sufficient to allow
4625 debugging @code{cfront}-generated executables. @value{GDBN} would
4626 require further enhancement to permit that.
4627 @end table
4628
4629 @item show demangle-style
4630 @kindex show demangle-style
4631 Display the encoding style currently in use for decoding C++ symbols.
4632
4633 @item set print object
4634 @itemx set print object on
4635 @kindex set print object
4636 When displaying a pointer to an object, identify the @emph{actual}
4637 (derived) type of the object rather than the @emph{declared} type, using
4638 the virtual function table.
4639
4640 @item set print object off
4641 Display only the declared type of objects, without reference to the
4642 virtual function table. This is the default setting.
4643
4644 @item show print object
4645 @kindex show print object
4646 Show whether actual, or declared, object types are displayed.
4647
4648 @item set print vtbl
4649 @itemx set print vtbl on
4650 @kindex set print vtbl
4651 Pretty print C++ virtual function tables. The default is off.
4652
4653 @item set print vtbl off
4654 Do not pretty print C++ virtual function tables.
4655
4656 @item show print vtbl
4657 @kindex show print vtbl
4658 Show whether C++ virtual function tables are pretty printed, or not.
4659 @end table
4660 @end ifclear
4661
4662 @node Value History
4663 @section Value history
4664
4665 @cindex value history
4666 Values printed by the @code{print} command are saved in the @value{GDBN} @dfn{value
4667 history} so that you can refer to them in other expressions. Values are
4668 kept until the symbol table is re-read or discarded (for example with
4669 the @code{file} or @code{symbol-file} commands). When the symbol table
4670 changes, the value history is discarded, since the values may contain
4671 pointers back to the types defined in the symbol table.
4672
4673 @cindex @code{$}
4674 @cindex @code{$$}
4675 @cindex history number
4676 The values printed are given @dfn{history numbers} by which you can
4677 refer to them. These are successive integers starting with one.
4678 @code{print} shows you the history number assigned to a value by
4679 printing @samp{$@var{num} = } before the value; here @var{num} is the
4680 history number.
4681
4682 To refer to any previous value, use @samp{$} followed by the value's
4683 history number. The way @code{print} labels its output is designed to
4684 remind you of this. Just @code{$} refers to the most recent value in
4685 the history, and @code{$$} refers to the value before that.
4686 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
4687 is the value just prior to @code{$$}, @code{$$1} is equivalent to
4688 @code{$$}, and @code{$$0} is equivalent to @code{$}.
4689
4690 For example, suppose you have just printed a pointer to a structure and
4691 want to see the contents of the structure. It suffices to type
4692
4693 @example
4694 p *$
4695 @end example
4696
4697 If you have a chain of structures where the component @code{next} points
4698 to the next one, you can print the contents of the next one with this:
4699
4700 @example
4701 p *$.next
4702 @end example
4703
4704 @noindent
4705 You can print successive links in the chain by repeating this
4706 command---which you can do by just typing @key{RET}.
4707
4708 Note that the history records values, not expressions. If the value of
4709 @code{x} is 4 and you type these commands:
4710
4711 @example
4712 print x
4713 set x=5
4714 @end example
4715
4716 @noindent
4717 then the value recorded in the value history by the @code{print} command
4718 remains 4 even though the value of @code{x} has changed.
4719
4720 @table @code
4721 @kindex show values
4722 @item show values
4723 Print the last ten values in the value history, with their item numbers.
4724 This is like @samp{p@ $$9} repeated ten times, except that @code{show
4725 values} does not change the history.
4726
4727 @item show values @var{n}
4728 Print ten history values centered on history item number @var{n}.
4729
4730 @item show values +
4731 Print ten history values just after the values last printed. If no more
4732 values are available, produces no display.
4733 @end table
4734
4735 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
4736 same effect as @samp{show values +}.
4737
4738 @node Convenience Vars
4739 @section Convenience variables
4740
4741 @cindex convenience variables
4742 @value{GDBN} provides @dfn{convenience variables} that you can use within
4743 @value{GDBN} to hold on to a value and refer to it later. These variables
4744 exist entirely within @value{GDBN}; they are not part of your program, and
4745 setting a convenience variable has no direct effect on further execution
4746 of your program. That is why you can use them freely.
4747
4748 Convenience variables are prefixed with @samp{$}. Any name preceded by
4749 @samp{$} can be used for a convenience variable, unless it is one of
4750 the predefined machine-specific register names (@pxref{Registers}).
4751 (Value history references, in contrast, are @emph{numbers} preceded
4752 by @samp{$}. @xref{Value History, ,Value history}.)
4753
4754 You can save a value in a convenience variable with an assignment
4755 expression, just as you would set a variable in your program.
4756 For example:
4757
4758 @example
4759 set $foo = *object_ptr
4760 @end example
4761
4762 @noindent
4763 would save in @code{$foo} the value contained in the object pointed to by
4764 @code{object_ptr}.
4765
4766 Using a convenience variable for the first time creates it, but its
4767 value is @code{void} until you assign a new value. You can alter the
4768 value with another assignment at any time.
4769
4770 Convenience variables have no fixed types. You can assign a convenience
4771 variable any type of value, including structures and arrays, even if
4772 that variable already has a value of a different type. The convenience
4773 variable, when used as an expression, has the type of its current value.
4774
4775 @table @code
4776 @item show convenience
4777 @kindex show convenience
4778 Print a list of convenience variables used so far, and their values.
4779 Abbreviated @code{show con}.
4780 @end table
4781
4782 One of the ways to use a convenience variable is as a counter to be
4783 incremented or a pointer to be advanced. For example, to print
4784 a field from successive elements of an array of structures:
4785
4786 @example
4787 set $i = 0
4788 print bar[$i++]->contents
4789 @i{@dots{} repeat that command by typing @key{RET}.}
4790 @end example
4791
4792 Some convenience variables are created automatically by @value{GDBN} and given
4793 values likely to be useful.
4794
4795 @table @code
4796 @item $_
4797 @kindex $_
4798 The variable @code{$_} is automatically set by the @code{x} command to
4799 the last address examined (@pxref{Memory, ,Examining memory}). Other
4800 commands which provide a default address for @code{x} to examine also
4801 set @code{$_} to that address; these commands include @code{info line}
4802 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
4803 except when set by the @code{x} command, in which case it is a pointer
4804 to the type of @code{$__}.
4805
4806 @item $__
4807 @kindex $__
4808 The variable @code{$__} is automatically set by the @code{x} command
4809 to the value found in the last address examined. Its type is chosen
4810 to match the format in which the data was printed.
4811 @end table
4812
4813 @node Registers
4814 @section Registers
4815
4816 @cindex registers
4817 You can refer to machine register contents, in expressions, as variables
4818 with names starting with @samp{$}. The names of registers are different
4819 for each machine; use @code{info registers} to see the names used on
4820 your machine.
4821
4822 @table @code
4823 @item info registers
4824 @kindex info registers
4825 Print the names and values of all registers except floating-point
4826 registers (in the selected stack frame).
4827
4828 @item info all-registers
4829 @kindex info all-registers
4830 @cindex floating point registers
4831 Print the names and values of all registers, including floating-point
4832 registers.
4833
4834 @item info registers @var{regname} @dots{}
4835 Print the relativized value of each specified register @var{regname}.
4836 @var{regname} may be any register name valid on the machine you are using, with
4837 or without the initial @samp{$}.
4838 @end table
4839
4840 @value{GDBN} has four ``standard'' register names that are available (in
4841 expressions) on most machines---whenever they do not conflict with an
4842 architecture's canonical mnemonics for registers. The register names
4843 @code{$pc} and @code{$sp} are used for the program counter register and
4844 the stack pointer. @code{$fp} is used for a register that contains a
4845 pointer to the current stack frame, and @code{$ps} is used for a
4846 register that contains the processor status. For example,
4847 you could print the program counter in hex with
4848
4849 @example
4850 p/x $pc
4851 @end example
4852
4853 @noindent
4854 or print the instruction to be executed next with
4855
4856 @example
4857 x/i $pc
4858 @end example
4859
4860 @noindent
4861 or add four to the stack pointer@footnote{This is a way of removing
4862 one word from the stack, on machines where stacks grow downward in
4863 memory (most machines, nowadays). This assumes that the innermost
4864 stack frame is selected; setting @code{$sp} is not allowed when other
4865 stack frames are selected. To pop entire frames off the stack,
4866 regardless of machine architecture, use @code{return};
4867 @pxref{Returning, ,Returning from a function}.} with
4868
4869 @example
4870 set $sp += 4
4871 @end example
4872
4873 Whenever possible, these four standard register names are available on
4874 your machine even though the machine has different canonical mnemonics,
4875 so long as there is no conflict. The @code{info registers} command
4876 shows the canonical names. For example, on the SPARC, @code{info
4877 registers} displays the processor status register as @code{$psr} but you
4878 can also refer to it as @code{$ps}.
4879
4880 @value{GDBN} always considers the contents of an ordinary register as an
4881 integer when the register is examined in this way. Some machines have
4882 special registers which can hold nothing but floating point; these
4883 registers are considered to have floating point values. There is no way
4884 to refer to the contents of an ordinary register as floating point value
4885 (although you can @emph{print} it as a floating point value with
4886 @samp{print/f $@var{regname}}).
4887
4888 Some registers have distinct ``raw'' and ``virtual'' data formats. This
4889 means that the data format in which the register contents are saved by
4890 the operating system is not the same one that your program normally
4891 sees. For example, the registers of the 68881 floating point
4892 coprocessor are always saved in ``extended'' (raw) format, but all C
4893 programs expect to work with ``double'' (virtual) format. In such
4894 cases, @value{GDBN} normally works with the virtual format only (the format that
4895 makes sense for your program), but the @code{info registers} command
4896 prints the data in both formats.
4897
4898 Normally, register values are relative to the selected stack frame
4899 (@pxref{Selection, ,Selecting a frame}). This means that you get the
4900 value that the register would contain if all stack frames farther in
4901 were exited and their saved registers restored. In order to see the
4902 true contents of hardware registers, you must select the innermost
4903 frame (with @samp{frame 0}).
4904
4905 However, @value{GDBN} must deduce where registers are saved, from the machine
4906 code generated by your compiler. If some registers are not saved, or if
4907 @value{GDBN} is unable to locate the saved registers, the selected stack
4908 frame makes no difference.
4909
4910 @ifset AMD29K
4911 @table @code
4912 @item set rstack_high_address @var{address}
4913 @kindex set rstack_high_address
4914 @cindex AMD 29K register stack
4915 @cindex register stack, AMD29K
4916 On AMD 29000 family processors, registers are saved in a separate
4917 ``register stack''. There is no way for @value{GDBN} to determine the extent
4918 of this stack. Normally, @value{GDBN} just assumes that the stack is ``large
4919 enough''. This may result in @value{GDBN} referencing memory locations that
4920 do not exist. If necessary, you can get around this problem by
4921 specifying the ending address of the register stack with the @code{set
4922 rstack_high_address} command. The argument should be an address, which
4923 you probably want to precede with @samp{0x} to specify in
4924 hexadecimal.
4925
4926 @item show rstack_high_address
4927 @kindex show rstack_high_address
4928 Display the current limit of the register stack, on AMD 29000 family
4929 processors.
4930 @end table
4931 @end ifset
4932
4933 @ifclear HAVE-FLOAT
4934 @node Floating Point Hardware
4935 @section Floating point hardware
4936 @cindex floating point
4937
4938 @c FIXME! Really host, not target?
4939 Depending on the host machine architecture, @value{GDBN} may be able to give
4940 you more information about the status of the floating point hardware.
4941
4942 @table @code
4943 @item info float
4944 @kindex info float
4945 Display hardware-dependent information about the floating
4946 point unit. The exact contents and layout vary depending on the
4947 floating point chip; on some platforms, @samp{info float} is not
4948 available at all.
4949 @end table
4950 @c FIXME: this is a cop-out. Try to get examples, explanations. Only
4951 @c FIXME...supported currently on arm's and 386's. Mark properly with
4952 @c FIXME... m4 macros to isolate general statements from hardware-dep,
4953 @c FIXME... at that point.
4954 @end ifclear
4955
4956 @ifclear CONLY
4957 @node Languages
4958 @chapter Using @value{GDBN} with Different Languages
4959 @cindex languages
4960
4961 @ifset MOD2
4962 Although programming languages generally have common aspects, they are
4963 rarely expressed in the same manner. For instance, in ANSI C,
4964 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
4965 Modula-2, it is accomplished by @code{p^}. Values can also be
4966 represented (and displayed) differently. Hex numbers in C are written
4967 like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
4968 @end ifset
4969
4970 @cindex working language
4971 Language-specific information is built into @value{GDBN} for some languages,
4972 allowing you to express operations like the above in your program's
4973 native language, and allowing @value{GDBN} to output values in a manner
4974 consistent with the syntax of your program's native language. The
4975 language you use to build expressions, called the @dfn{working
4976 language}, can be selected manually, or @value{GDBN} can set it
4977 automatically.
4978
4979 @menu
4980 * Setting:: Switching between source languages
4981 * Show:: Displaying the language
4982 @ifset MOD2
4983 * Checks:: Type and range checks
4984 @end ifset
4985
4986 * Support:: Supported languages
4987 @end menu
4988
4989 @node Setting
4990 @section Switching between source languages
4991
4992 There are two ways to control the working language---either have @value{GDBN}
4993 set it automatically, or select it manually yourself. You can use the
4994 @code{set language} command for either purpose. On startup, @value{GDBN}
4995 defaults to setting the language automatically.
4996
4997 @menu
4998 * Manually:: Setting the working language manually
4999 * Automatically:: Having @value{GDBN} infer the source language
5000 @end menu
5001
5002 @node Manually
5003 @subsection Setting the working language
5004
5005 If you allow @value{GDBN} to set the language automatically,
5006 expressions are interpreted the same way in your debugging session and
5007 your program.
5008
5009 @kindex set language
5010 If you wish, you may set the language manually. To do this, issue the
5011 command @samp{set language @var{lang}}, where @var{lang} is the name of
5012 a language, such as
5013 @ifclear MOD2
5014 @code{c}.
5015 @end ifclear
5016 @ifset MOD2
5017 @code{c} or @code{modula-2}.
5018 @end ifset
5019 For a list of the supported languages, type @samp{set language}.
5020 @c FIXME: rms: eventually this command should be "help set language".
5021
5022 @ifset MOD2
5023 Setting the language manually prevents @value{GDBN} from updating the working
5024 language automatically. This can lead to confusion if you try
5025 to debug a program when the working language is not the same as the
5026 source language, when an expression is acceptable to both
5027 languages---but means different things. For instance, if the current
5028 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5029 command such as:
5030
5031 @example
5032 print a = b + c
5033 @end example
5034
5035 @noindent
5036 might not have the effect you intended. In C, this means to add
5037 @code{b} and @code{c} and place the result in @code{a}. The result
5038 printed would be the value of @code{a}. In Modula-2, this means to compare
5039 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5040 @end ifset
5041
5042 @node Automatically
5043 @subsection Having @value{GDBN} infer the source language
5044
5045 To have @value{GDBN} set the working language automatically, use @samp{set
5046 language local} or @samp{set language auto}. @value{GDBN} then infers the
5047 language that a program was written in by looking at the name of its
5048 source files, and examining their extensions:
5049
5050 @table @file
5051 @ifset MOD2
5052 @item *.mod
5053 Modula-2 source file
5054 @end ifset
5055
5056 @item *.c
5057 C source file
5058
5059 @item *.C
5060 @itemx *.cc
5061 C++ source file
5062 @end table
5063
5064 This information is recorded for each function or procedure in a source
5065 file. When your program stops in a frame (usually by encountering a
5066 breakpoint), @value{GDBN} sets the working language to the language recorded
5067 for the function in that frame. If the language for a frame is unknown
5068 (that is, if the function or block corresponding to the frame was
5069 defined in a source file that does not have a recognized extension), the
5070 current working language is not changed, and @value{GDBN} issues a warning.
5071
5072 This may not seem necessary for most programs, which are written
5073 entirely in one source language. However, program modules and libraries
5074 written in one source language can be used by a main program written in
5075 a different source language. Using @samp{set language auto} in this
5076 case frees you from having to set the working language manually.
5077
5078 @node Show
5079 @section Displaying the language
5080
5081 The following commands help you find out which language is the
5082 working language, and also what language source files were written in.
5083
5084 @kindex show language
5085 @kindex info frame
5086 @kindex info source
5087 @table @code
5088 @item show language
5089 Display the current working language. This is the
5090 language you can use with commands such as @code{print} to
5091 build and compute expressions that may involve variables in your program.
5092
5093 @item info frame
5094 Among the other information listed here (@pxref{Frame Info, ,Information
5095 about a frame}) is the source language for this frame. This
5096 language becomes the working language if you use an
5097 identifier from this frame.
5098
5099 @item info source
5100 Among the other information listed here (@pxref{Symbols, ,Examining the
5101 Symbol Table}) is the source language of this source file.
5102 @end table
5103
5104 @ifset MOD2
5105 @node Checks
5106 @section Type and range checking
5107
5108 @quotation
5109 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5110 checking are included, but they do not yet have any effect. This
5111 section documents the intended facilities.
5112 @end quotation
5113 @c FIXME remove warning when type/range code added
5114
5115 Some languages are designed to guard you against making seemingly common
5116 errors through a series of compile- and run-time checks. These include
5117 checking the type of arguments to functions and operators, and making
5118 sure mathematical overflows are caught at run time. Checks such as
5119 these help to ensure a program's correctness once it has been compiled
5120 by eliminating type mismatches, and providing active checks for range
5121 errors when your program is running.
5122
5123 @value{GDBN} can check for conditions like the above if you wish.
5124 Although @value{GDBN} does not check the statements in your program, it
5125 can check expressions entered directly into @value{GDBN} for evaluation via
5126 the @code{print} command, for example. As with the working language,
5127 @value{GDBN} can also decide whether or not to check automatically based on
5128 your program's source language. @xref{Support, ,Supported languages},
5129 for the default settings of supported languages.
5130
5131 @menu
5132 * Type Checking:: An overview of type checking
5133 * Range Checking:: An overview of range checking
5134 @end menu
5135
5136 @cindex type checking
5137 @cindex checks, type
5138 @node Type Checking
5139 @subsection An overview of type checking
5140
5141 Some languages, such as Modula-2, are strongly typed, meaning that the
5142 arguments to operators and functions have to be of the correct type,
5143 otherwise an error occurs. These checks prevent type mismatch
5144 errors from ever causing any run-time problems. For example,
5145
5146 @example
5147 1 + 2 @result{} 3
5148 @exdent but
5149 @error{} 1 + 2.3
5150 @end example
5151
5152 The second example fails because the @code{CARDINAL} 1 is not
5153 type-compatible with the @code{REAL} 2.3.
5154
5155 For expressions you use in @value{GDBN} commands, you can tell the @value{GDBN}
5156 type checker to skip checking; to treat any mismatches as errors and
5157 abandon the expression; or only issue warnings when type mismatches
5158 occur, but evaluate the expression anyway. When you choose the last of
5159 these, @value{GDBN} evaluates expressions like the second example above, but
5160 also issues a warning.
5161
5162 Even though you may turn type checking off, other type-based reasons may
5163 prevent @value{GDBN} from evaluating an expression. For instance, @value{GDBN} does not
5164 know how to add an @code{int} and a @code{struct foo}. These particular
5165 type errors have nothing to do with the language in use, and usually
5166 arise from expressions, such as the one described above, which make
5167 little sense to evaluate anyway.
5168
5169 Each language defines to what degree it is strict about type. For
5170 instance, both Modula-2 and C require the arguments to arithmetical
5171 operators to be numbers. In C, enumerated types and pointers can be
5172 represented as numbers, so that they are valid arguments to mathematical
5173 operators. @xref{Support, ,Supported languages}, for further
5174 details on specific languages.
5175
5176 @value{GDBN} provides some additional commands for controlling the type checker:
5177
5178 @kindex set check
5179 @kindex set check type
5180 @kindex show check type
5181 @table @code
5182 @item set check type auto
5183 Set type checking on or off based on the current working language.
5184 @xref{Support, ,Supported languages}, for the default settings for
5185 each language.
5186
5187 @item set check type on
5188 @itemx set check type off
5189 Set type checking on or off, overriding the default setting for the
5190 current working language. Issue a warning if the setting does not
5191 match the language default. If any type mismatches occur in
5192 evaluating an expression while typechecking is on, @value{GDBN} prints a
5193 message and aborts evaluation of the expression.
5194
5195 @item set check type warn
5196 Cause the type checker to issue warnings, but to always attempt to
5197 evaluate the expression. Evaluating the expression may still
5198 be impossible for other reasons. For example, @value{GDBN} cannot add
5199 numbers and structures.
5200
5201 @item show type
5202 Show the current setting of the type checker, and whether or not @value{GDBN} is
5203 setting it automatically.
5204 @end table
5205
5206 @cindex range checking
5207 @cindex checks, range
5208 @node Range Checking
5209 @subsection An overview of range checking
5210
5211 In some languages (such as Modula-2), it is an error to exceed the
5212 bounds of a type; this is enforced with run-time checks. Such range
5213 checking is meant to ensure program correctness by making sure
5214 computations do not overflow, or indices on an array element access do
5215 not exceed the bounds of the array.
5216
5217 For expressions you use in @value{GDBN} commands, you can tell
5218 @value{GDBN} to treat range errors in one of three ways: ignore them,
5219 always treat them as errors and abandon the expression, or issue
5220 warnings but evaluate the expression anyway.
5221
5222 A range error can result from numerical overflow, from exceeding an
5223 array index bound, or when you type a constant that is not a member
5224 of any type. Some languages, however, do not treat overflows as an
5225 error. In many implementations of C, mathematical overflow causes the
5226 result to ``wrap around'' to lower values---for example, if @var{m} is
5227 the largest integer value, and @var{s} is the smallest, then
5228
5229 @example
5230 @var{m} + 1 @result{} @var{s}
5231 @end example
5232
5233 This, too, is specific to individual languages, and in some cases
5234 specific to individual compilers or machines. @xref{Support, ,
5235 Supported languages}, for further details on specific languages.
5236
5237 @value{GDBN} provides some additional commands for controlling the range checker:
5238
5239 @kindex set check
5240 @kindex set check range
5241 @kindex show check range
5242 @table @code
5243 @item set check range auto
5244 Set range checking on or off based on the current working language.
5245 @xref{Support, ,Supported languages}, for the default settings for
5246 each language.
5247
5248 @item set check range on
5249 @itemx set check range off
5250 Set range checking on or off, overriding the default setting for the
5251 current working language. A warning is issued if the setting does not
5252 match the language default. If a range error occurs, then a message
5253 is printed and evaluation of the expression is aborted.
5254
5255 @item set check range warn
5256 Output messages when the @value{GDBN} range checker detects a range error,
5257 but attempt to evaluate the expression anyway. Evaluating the
5258 expression may still be impossible for other reasons, such as accessing
5259 memory that the process does not own (a typical example from many Unix
5260 systems).
5261
5262 @item show range
5263 Show the current setting of the range checker, and whether or not it is
5264 being set automatically by @value{GDBN}.
5265 @end table
5266 @end ifset
5267
5268 @node Support
5269 @section Supported languages
5270
5271 @ifset MOD2
5272 @value{GDBN} 4 supports C, C++, and Modula-2.
5273 @end ifset
5274 @ifclear MOD2
5275 @value{GDBN} 4 supports C, and C++.
5276 @end ifclear
5277 Some @value{GDBN} features may be used in expressions regardless of the
5278 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5279 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5280 ,Expressions}) can be used with the constructs of any supported
5281 language.
5282
5283 The following sections detail to what degree each source language is
5284 supported by @value{GDBN}. These sections are not meant to be language
5285 tutorials or references, but serve only as a reference guide to what the
5286 @value{GDBN} expression parser accepts, and what input and output
5287 formats should look like for different languages. There are many good
5288 books written on each of these languages; please look to these for a
5289 language reference or tutorial.
5290
5291 @ifset MOD2
5292 @menu
5293 * C:: C and C++
5294 * Modula-2:: Modula-2
5295 @end menu
5296
5297 @node C
5298 @subsection C and C++
5299 @cindex C and C++
5300 @cindex expressions in C or C++
5301
5302 Since C and C++ are so closely related, many features of @value{GDBN} apply
5303 to both languages. Whenever this is the case, we discuss both languages
5304 together.
5305 @end ifset
5306 @ifclear MOD2
5307 @c Cancel this below, under same condition, at end of this chapter!
5308 @raisesections
5309 @end ifclear
5310
5311 @cindex C++
5312 @kindex g++
5313 @cindex GNU C++
5314 The C++ debugging facilities are jointly implemented by the GNU C++
5315 compiler and @value{GDBN}. Therefore, to debug your C++ code
5316 effectively, you must compile your C++ programs with the GNU C++
5317 compiler, @code{g++}.
5318
5319 For best results when debugging C++ programs, use the stabs debugging
5320 format. You can select that format explicitly with the @code{g++}
5321 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5322 @ref{Debugging Options,,Options for Debugging Your Program or GNU CC,
5323 gcc.info, Using GNU CC}, for more information.
5324 @end ifclear
5325 @ifset CONLY
5326 @node C
5327 @chapter C Language Support
5328 @cindex C language
5329 @cindex expressions in C
5330
5331 Information specific to the C language is built into @value{GDBN} so that you
5332 can use C expressions while degugging. This also permits @value{GDBN} to
5333 output values in a manner consistent with C conventions.
5334
5335 @menu
5336 * C Operators:: C operators
5337 * C Constants:: C constants
5338 * Debugging C:: @value{GDBN} and C
5339 @end menu
5340 @end ifset
5341 @ifclear CONLY
5342 @menu
5343 * C Operators:: C and C++ operators
5344 * C Constants:: C and C++ constants
5345 * Cplus expressions:: C++ expressions
5346 * C Defaults:: Default settings for C and C++
5347 @ifset MOD2
5348 * C Checks:: C and C++ type and range checks
5349 @end ifset
5350
5351 * Debugging C:: @value{GDBN} and C
5352 * Debugging C plus plus:: Special features for C++
5353 @end menu
5354 @end ifclear
5355
5356 @ifclear CONLY
5357 @cindex C and C++ operators
5358 @node C Operators
5359 @subsubsection C and C++ operators
5360 @end ifclear
5361 @ifset CONLY
5362 @cindex C operators
5363 @node C Operators
5364 @section C operators
5365 @end ifset
5366
5367 Operators must be defined on values of specific types. For instance,
5368 @code{+} is defined on numbers, but not on structures. Operators are
5369 often defined on groups of types.
5370
5371 @ifclear CONLY
5372 For the purposes of C and C++, the following definitions hold:
5373 @end ifclear
5374
5375 @itemize @bullet
5376 @item
5377 @emph{Integral types} include @code{int} with any of its storage-class
5378 specifiers; @code{char}; and @code{enum}.
5379
5380 @item
5381 @emph{Floating-point types} include @code{float} and @code{double}.
5382
5383 @item
5384 @emph{Pointer types} include all types defined as @code{(@var{type}
5385 *)}.
5386
5387 @item
5388 @emph{Scalar types} include all of the above.
5389 @end itemize
5390
5391 @noindent
5392 The following operators are supported. They are listed here
5393 in order of increasing precedence:
5394
5395 @table @code
5396 @item ,
5397 The comma or sequencing operator. Expressions in a comma-separated list
5398 are evaluated from left to right, with the result of the entire
5399 expression being the last expression evaluated.
5400
5401 @item =
5402 Assignment. The value of an assignment expression is the value
5403 assigned. Defined on scalar types.
5404
5405 @item @var{op}=
5406 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5407 and translated to @w{@code{@var{a} = @var{a op b}}}.
5408 @w{@code{@var{op}=}} and @code{=} have the same precendence.
5409 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5410 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5411
5412 @item ?:
5413 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5414 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5415 integral type.
5416
5417 @item ||
5418 Logical @sc{or}. Defined on integral types.
5419
5420 @item &&
5421 Logical @sc{and}. Defined on integral types.
5422
5423 @item |
5424 Bitwise @sc{or}. Defined on integral types.
5425
5426 @item ^
5427 Bitwise exclusive-@sc{or}. Defined on integral types.
5428
5429 @item &
5430 Bitwise @sc{and}. Defined on integral types.
5431
5432 @item ==@r{, }!=
5433 Equality and inequality. Defined on scalar types. The value of these
5434 expressions is 0 for false and non-zero for true.
5435
5436 @item <@r{, }>@r{, }<=@r{, }>=
5437 Less than, greater than, less than or equal, greater than or equal.
5438 Defined on scalar types. The value of these expressions is 0 for false
5439 and non-zero for true.
5440
5441 @item <<@r{, }>>
5442 left shift, and right shift. Defined on integral types.
5443
5444 @item @@
5445 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5446
5447 @item +@r{, }-
5448 Addition and subtraction. Defined on integral types, floating-point types and
5449 pointer types.
5450
5451 @item *@r{, }/@r{, }%
5452 Multiplication, division, and modulus. Multiplication and division are
5453 defined on integral and floating-point types. Modulus is defined on
5454 integral types.
5455
5456 @item ++@r{, }--
5457 Increment and decrement. When appearing before a variable, the
5458 operation is performed before the variable is used in an expression;
5459 when appearing after it, the variable's value is used before the
5460 operation takes place.
5461
5462 @item *
5463 Pointer dereferencing. Defined on pointer types. Same precedence as
5464 @code{++}.
5465
5466 @item &
5467 Address operator. Defined on variables. Same precedence as @code{++}.
5468
5469 @ifclear CONLY
5470 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
5471 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
5472 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
5473 where a C++ reference variable (declared with @samp{&@var{ref}}) is
5474 stored.
5475 @end ifclear
5476
5477 @item -
5478 Negative. Defined on integral and floating-point types. Same
5479 precedence as @code{++}.
5480
5481 @item !
5482 Logical negation. Defined on integral types. Same precedence as
5483 @code{++}.
5484
5485 @item ~
5486 Bitwise complement operator. Defined on integral types. Same precedence as
5487 @code{++}.
5488
5489
5490 @item .@r{, }->
5491 Structure member, and pointer-to-structure member. For convenience,
5492 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
5493 pointer based on the stored type information.
5494 Defined on @code{struct} and @code{union} data.
5495
5496 @item []
5497 Array indexing. @code{@var{a}[@var{i}]} is defined as
5498 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
5499
5500 @item ()
5501 Function parameter list. Same precedence as @code{->}.
5502
5503 @ifclear CONLY
5504 @item ::
5505 C++ scope resolution operator. Defined on
5506 @code{struct}, @code{union}, and @code{class} types.
5507 @end ifclear
5508
5509 @item ::
5510 Doubled colons
5511 @ifclear CONLY
5512 also
5513 @end ifclear
5514 represent the @value{GDBN} scope operator (@pxref{Expressions,
5515 ,Expressions}).
5516 @ifclear CONLY
5517 Same precedence as @code{::}, above.
5518 @end ifclear
5519 @end table
5520
5521 @ifclear CONLY
5522 @cindex C and C++ constants
5523 @node C Constants
5524 @subsubsection C and C++ constants
5525
5526 @value{GDBN} allows you to express the constants of C and C++ in the
5527 following ways:
5528 @end ifclear
5529 @ifset CONLY
5530 @cindex C constants
5531 @node C Constants
5532 @section C constants
5533
5534 @value{GDBN} allows you to express the constants of C in the
5535 following ways:
5536 @end ifset
5537
5538 @itemize @bullet
5539 @item
5540 Integer constants are a sequence of digits. Octal constants are
5541 specified by a leading @samp{0} (ie. zero), and hexadecimal constants by
5542 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
5543 @samp{l}, specifying that the constant should be treated as a
5544 @code{long} value.
5545
5546 @item
5547 Floating point constants are a sequence of digits, followed by a decimal
5548 point, followed by a sequence of digits, and optionally followed by an
5549 exponent. An exponent is of the form:
5550 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
5551 sequence of digits. The @samp{+} is optional for positive exponents.
5552
5553 @item
5554 Enumerated constants consist of enumerated identifiers, or their
5555 integral equivalents.
5556
5557 @item
5558 Character constants are a single character surrounded by single quotes
5559 (@code{'}), or a number---the ordinal value of the corresponding character
5560 (usually its @sc{ASCII} value). Within quotes, the single character may
5561 be represented by a letter or by @dfn{escape sequences}, which are of
5562 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
5563 of the character's ordinal value; or of the form @samp{\@var{x}}, where
5564 @samp{@var{x}} is a predefined special character---for example,
5565 @samp{\n} for newline.
5566
5567 @item
5568 String constants are a sequence of character constants surrounded
5569 by double quotes (@code{"}).
5570
5571 @item
5572 Pointer constants are an integral value. You can also write pointers
5573 to constants using the C operator @samp{&}.
5574
5575 @item
5576 Array constants are comma-separated lists surrounded by braces @samp{@{}
5577 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
5578 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
5579 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
5580 @end itemize
5581
5582 @ifclear CONLY
5583 @node Cplus expressions
5584 @subsubsection C++ expressions
5585
5586 @cindex expressions in C++
5587 @value{GDBN} expression handling has a number of extensions to
5588 interpret a significant subset of C++ expressions.
5589
5590 @cindex C++ support, not in @sc{coff}
5591 @cindex @sc{coff} versus C++
5592 @cindex C++ and object formats
5593 @cindex object formats and C++
5594 @cindex a.out and C++
5595 @cindex @sc{ecoff} and C++
5596 @cindex @sc{xcoff} and C++
5597 @cindex @sc{elf}/stabs and C++
5598 @cindex @sc{elf}/@sc{dwarf} and C++
5599 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
5600 @c periodically whether this has happened...
5601 @quotation
5602 @emph{Warning:} @value{GDBN} can only debug C++ code if you compile with
5603 the GNU C++ compiler. Moreover, C++ debugging depends on the use of
5604 additional debugging information in the symbol table, and thus requires
5605 special support. @value{GDBN} has this support @emph{only} with the
5606 stabs debug format. In particular, if your compiler generates a.out,
5607 MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions
5608 to the symbol table, these facilities are all available. (With GNU CC,
5609 you can use the @samp{-gstabs} option to request stabs debugging
5610 extensions explicitly.) Where the object code format is standard
5611 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
5612 support in @value{GDBN} does @emph{not} work.
5613 @end quotation
5614
5615 @enumerate
5616
5617 @cindex member functions
5618 @item
5619 Member function calls are allowed; you can use expressions like
5620
5621 @example
5622 count = aml->GetOriginal(x, y)
5623 @end example
5624
5625 @kindex this
5626 @cindex namespace in C++
5627 @item
5628 While a member function is active (in the selected stack frame), your
5629 expressions have the same namespace available as the member function;
5630 that is, @value{GDBN} allows implicit references to the class instance
5631 pointer @code{this} following the same rules as C++.
5632
5633 @cindex call overloaded functions
5634 @cindex type conversions in C++
5635 @item
5636 You can call overloaded functions; @value{GDBN} resolves the function
5637 call to the right definition, with one restriction---you must use
5638 arguments of the type required by the function that you want to call.
5639 @value{GDBN} does not perform conversions requiring constructors or
5640 user-defined type operators.
5641
5642 @cindex reference declarations
5643 @item
5644 @value{GDBN} understands variables declared as C++ references; you can use them in
5645 expressions just as you do in C++ source---they are automatically
5646 dereferenced.
5647
5648 In the parameter list shown when @value{GDBN} displays a frame, the values of
5649 reference variables are not displayed (unlike other variables); this
5650 avoids clutter, since references are often used for large structures.
5651 The @emph{address} of a reference variable is always shown, unless
5652 you have specified @samp{set print address off}.
5653
5654 @item
5655 @value{GDBN} supports the C++ name resolution operator @code{::}---your
5656 expressions can use it just as expressions in your program do. Since
5657 one scope may be defined in another, you can use @code{::} repeatedly if
5658 necessary, for example in an expression like
5659 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
5660 resolving name scope by reference to source files, in both C and C++
5661 debugging (@pxref{Variables, ,Program variables}).
5662 @end enumerate
5663
5664 @node C Defaults
5665 @subsubsection C and C++ defaults
5666 @cindex C and C++ defaults
5667
5668 If you allow @value{GDBN} to set type and range checking automatically, they
5669 both default to @code{off} whenever the working language changes to
5670 C or C++. This happens regardless of whether you, or @value{GDBN},
5671 selected the working language.
5672
5673 If you allow @value{GDBN} to set the language automatically, it sets the
5674 working language to C or C++ on entering code compiled from a source file
5675 whose name ends with @file{.c}, @file{.C}, or @file{.cc}.
5676 @xref{Automatically, ,Having @value{GDBN} infer the source language}, for
5677 further details.
5678
5679 @ifset MOD2
5680 @c Type checking is (a) primarily motivated by Modula-2, and (b)
5681 @c unimplemented. If (b) changes, it might make sense to let this node
5682 @c appear even if Mod-2 does not, but meanwhile ignore it. pesch 16jul93.
5683 @node C Checks
5684 @subsubsection C and C++ type and range checks
5685 @cindex C and C++ checks
5686
5687 By default, when @value{GDBN} parses C or C++ expressions, type checking
5688 is not used. However, if you turn type checking on, @value{GDBN}
5689 considers two variables type equivalent if:
5690
5691 @itemize @bullet
5692 @item
5693 The two variables are structured and have the same structure, union, or
5694 enumerated tag.
5695
5696 @item
5697 Two two variables have the same type name, or types that have been
5698 declared equivalent through @code{typedef}.
5699
5700 @ignore
5701 @c leaving this out because neither J Gilmore nor R Pesch understand it.
5702 @c FIXME--beers?
5703 @item
5704 The two @code{struct}, @code{union}, or @code{enum} variables are
5705 declared in the same declaration. (Note: this may not be true for all C
5706 compilers.)
5707 @end ignore
5708 @end itemize
5709
5710 Range checking, if turned on, is done on mathematical operations. Array
5711 indices are not checked, since they are often used to index a pointer
5712 that is not itself an array.
5713 @end ifset
5714 @end ifclear
5715
5716 @ifclear CONLY
5717 @node Debugging C
5718 @subsubsection @value{GDBN} and C
5719 @end ifclear
5720 @ifset CONLY
5721 @node Debugging C
5722 @section @value{GDBN} and C
5723 @end ifset
5724
5725 The @code{set print union} and @code{show print union} commands apply to
5726 the @code{union} type. When set to @samp{on}, any @code{union} that is
5727 inside a @code{struct}
5728 @ifclear CONLY
5729 or @code{class}
5730 @end ifclear
5731 is also printed.
5732 Otherwise, it appears as @samp{@{...@}}.
5733
5734 The @code{@@} operator aids in the debugging of dynamic arrays, formed
5735 with pointers and a memory allocation function. @xref{Expressions,
5736 ,Expressions}.
5737
5738 @ifclear CONLY
5739 @node Debugging C plus plus
5740 @subsubsection @value{GDBN} features for C++
5741
5742 @cindex commands for C++
5743 Some @value{GDBN} commands are particularly useful with C++, and some are
5744 designed specifically for use with C++. Here is a summary:
5745
5746 @table @code
5747 @cindex break in overloaded functions
5748 @item @r{breakpoint menus}
5749 When you want a breakpoint in a function whose name is overloaded,
5750 @value{GDBN} breakpoint menus help you specify which function definition
5751 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
5752
5753 @cindex overloading in C++
5754 @item rbreak @var{regex}
5755 Setting breakpoints using regular expressions is helpful for setting
5756 breakpoints on overloaded functions that are not members of any special
5757 classes.
5758 @xref{Set Breaks, ,Setting breakpoints}.
5759
5760 @cindex C++ exception handling
5761 @item catch @var{exceptions}
5762 @itemx info catch
5763 Debug C++ exception handling using these commands. @xref{Exception
5764 Handling, ,Breakpoints and exceptions}.
5765
5766 @cindex inheritance
5767 @item ptype @var{typename}
5768 Print inheritance relationships as well as other information for type
5769 @var{typename}.
5770 @xref{Symbols, ,Examining the Symbol Table}.
5771
5772 @cindex C++ symbol display
5773 @item set print demangle
5774 @itemx show print demangle
5775 @itemx set print asm-demangle
5776 @itemx show print asm-demangle
5777 Control whether C++ symbols display in their source form, both when
5778 displaying code as C++ source and when displaying disassemblies.
5779 @xref{Print Settings, ,Print settings}.
5780
5781 @item set print object
5782 @itemx show print object
5783 Choose whether to print derived (actual) or declared types of objects.
5784 @xref{Print Settings, ,Print settings}.
5785
5786 @item set print vtbl
5787 @itemx show print vtbl
5788 Control the format for printing virtual function tables.
5789 @xref{Print Settings, ,Print settings}.
5790
5791 @item @r{Overloaded symbol names}
5792 You can specify a particular definition of an overloaded symbol, using
5793 the same notation that is used to declare such symbols in C++: type
5794 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
5795 also use the @value{GDBN} command-line word completion facilities to list the
5796 available choices, or to finish the type list for you.
5797 @xref{Completion,, Command completion}, for details on how to do this.
5798 @end table
5799 @ifclear MOD2
5800 @c cancels "raisesections" under same conditions near bgn of chapter
5801 @lowersections
5802 @end ifclear
5803
5804 @ifset MOD2
5805 @node Modula-2
5806 @subsection Modula-2
5807 @cindex Modula-2
5808
5809 The extensions made to @value{GDBN} to support Modula-2 only support
5810 output from the GNU Modula-2 compiler (which is currently being
5811 developed). Other Modula-2 compilers are not currently supported, and
5812 attempting to debug executables produced by them is most likely
5813 to give an error as @value{GDBN} reads in the executable's symbol
5814 table.
5815
5816 @cindex expressions in Modula-2
5817 @menu
5818 * M2 Operators:: Built-in operators
5819 * Built-In Func/Proc:: Built-in functions and procedures
5820 * M2 Constants:: Modula-2 constants
5821 * M2 Defaults:: Default settings for Modula-2
5822 * Deviations:: Deviations from standard Modula-2
5823 * M2 Checks:: Modula-2 type and range checks
5824 * M2 Scope:: The scope operators @code{::} and @code{.}
5825 * GDB/M2:: @value{GDBN} and Modula-2
5826 @end menu
5827
5828 @node M2 Operators
5829 @subsubsection Operators
5830 @cindex Modula-2 operators
5831
5832 Operators must be defined on values of specific types. For instance,
5833 @code{+} is defined on numbers, but not on structures. Operators are
5834 often defined on groups of types. For the purposes of Modula-2, the
5835 following definitions hold:
5836
5837 @itemize @bullet
5838
5839 @item
5840 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
5841 their subranges.
5842
5843 @item
5844 @emph{Character types} consist of @code{CHAR} and its subranges.
5845
5846 @item
5847 @emph{Floating-point types} consist of @code{REAL}.
5848
5849 @item
5850 @emph{Pointer types} consist of anything declared as @code{POINTER TO
5851 @var{type}}.
5852
5853 @item
5854 @emph{Scalar types} consist of all of the above.
5855
5856 @item
5857 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
5858
5859 @item
5860 @emph{Boolean types} consist of @code{BOOLEAN}.
5861 @end itemize
5862
5863 @noindent
5864 The following operators are supported, and appear in order of
5865 increasing precedence:
5866
5867 @table @code
5868 @item ,
5869 Function argument or array index separator.
5870
5871 @item :=
5872 Assignment. The value of @var{var} @code{:=} @var{value} is
5873 @var{value}.
5874
5875 @item <@r{, }>
5876 Less than, greater than on integral, floating-point, or enumerated
5877 types.
5878
5879 @item <=@r{, }>=
5880 Less than, greater than, less than or equal to, greater than or equal to
5881 on integral, floating-point and enumerated types, or set inclusion on
5882 set types. Same precedence as @code{<}.
5883
5884 @item =@r{, }<>@r{, }#
5885 Equality and two ways of expressing inequality, valid on scalar types.
5886 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
5887 available for inequality, since @code{#} conflicts with the script
5888 comment character.
5889
5890 @item IN
5891 Set membership. Defined on set types and the types of their members.
5892 Same precedence as @code{<}.
5893
5894 @item OR
5895 Boolean disjunction. Defined on boolean types.
5896
5897 @item AND@r{, }&
5898 Boolean conjuction. Defined on boolean types.
5899
5900 @item @@
5901 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5902
5903 @item +@r{, }-
5904 Addition and subtraction on integral and floating-point types, or union
5905 and difference on set types.
5906
5907 @item *
5908 Multiplication on integral and floating-point types, or set intersection
5909 on set types.
5910
5911 @item /
5912 Division on floating-point types, or symmetric set difference on set
5913 types. Same precedence as @code{*}.
5914
5915 @item DIV@r{, }MOD
5916 Integer division and remainder. Defined on integral types. Same
5917 precedence as @code{*}.
5918
5919 @item -
5920 Negative. Defined on @code{INTEGER} and @code{REAL} data.
5921
5922 @item ^
5923 Pointer dereferencing. Defined on pointer types.
5924
5925 @item NOT
5926 Boolean negation. Defined on boolean types. Same precedence as
5927 @code{^}.
5928
5929 @item .
5930 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
5931 precedence as @code{^}.
5932
5933 @item []
5934 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
5935
5936 @item ()
5937 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
5938 as @code{^}.
5939
5940 @item ::@r{, }.
5941 @value{GDBN} and Modula-2 scope operators.
5942 @end table
5943
5944 @quotation
5945 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
5946 treats the use of the operator @code{IN}, or the use of operators
5947 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
5948 @code{<=}, and @code{>=} on sets as an error.
5949 @end quotation
5950
5951 @cindex Modula-2 built-ins
5952 @node Built-In Func/Proc
5953 @subsubsection Built-in functions and procedures
5954
5955 Modula-2 also makes available several built-in procedures and functions.
5956 In describing these, the following metavariables are used:
5957
5958 @table @var
5959
5960 @item a
5961 represents an @code{ARRAY} variable.
5962
5963 @item c
5964 represents a @code{CHAR} constant or variable.
5965
5966 @item i
5967 represents a variable or constant of integral type.
5968
5969 @item m
5970 represents an identifier that belongs to a set. Generally used in the
5971 same function with the metavariable @var{s}. The type of @var{s} should
5972 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
5973
5974 @item n
5975 represents a variable or constant of integral or floating-point type.
5976
5977 @item r
5978 represents a variable or constant of floating-point type.
5979
5980 @item t
5981 represents a type.
5982
5983 @item v
5984 represents a variable.
5985
5986 @item x
5987 represents a variable or constant of one of many types. See the
5988 explanation of the function for details.
5989 @end table
5990
5991 All Modula-2 built-in procedures also return a result, described below.
5992
5993 @table @code
5994 @item ABS(@var{n})
5995 Returns the absolute value of @var{n}.
5996
5997 @item CAP(@var{c})
5998 If @var{c} is a lower case letter, it returns its upper case
5999 equivalent, otherwise it returns its argument
6000
6001 @item CHR(@var{i})
6002 Returns the character whose ordinal value is @var{i}.
6003
6004 @item DEC(@var{v})
6005 Decrements the value in the variable @var{v}. Returns the new value.
6006
6007 @item DEC(@var{v},@var{i})
6008 Decrements the value in the variable @var{v} by @var{i}. Returns the
6009 new value.
6010
6011 @item EXCL(@var{m},@var{s})
6012 Removes the element @var{m} from the set @var{s}. Returns the new
6013 set.
6014
6015 @item FLOAT(@var{i})
6016 Returns the floating point equivalent of the integer @var{i}.
6017
6018 @item HIGH(@var{a})
6019 Returns the index of the last member of @var{a}.
6020
6021 @item INC(@var{v})
6022 Increments the value in the variable @var{v}. Returns the new value.
6023
6024 @item INC(@var{v},@var{i})
6025 Increments the value in the variable @var{v} by @var{i}. Returns the
6026 new value.
6027
6028 @item INCL(@var{m},@var{s})
6029 Adds the element @var{m} to the set @var{s} if it is not already
6030 there. Returns the new set.
6031
6032 @item MAX(@var{t})
6033 Returns the maximum value of the type @var{t}.
6034
6035 @item MIN(@var{t})
6036 Returns the minimum value of the type @var{t}.
6037
6038 @item ODD(@var{i})
6039 Returns boolean TRUE if @var{i} is an odd number.
6040
6041 @item ORD(@var{x})
6042 Returns the ordinal value of its argument. For example, the ordinal
6043 value of a character is its ASCII value (on machines supporting the
6044 ASCII character set). @var{x} must be of an ordered type, which include
6045 integral, character and enumerated types.
6046
6047 @item SIZE(@var{x})
6048 Returns the size of its argument. @var{x} can be a variable or a type.
6049
6050 @item TRUNC(@var{r})
6051 Returns the integral part of @var{r}.
6052
6053 @item VAL(@var{t},@var{i})
6054 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6055 @end table
6056
6057 @quotation
6058 @emph{Warning:} Sets and their operations are not yet supported, so
6059 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6060 an error.
6061 @end quotation
6062
6063 @cindex Modula-2 constants
6064 @node M2 Constants
6065 @subsubsection Constants
6066
6067 @value{GDBN} allows you to express the constants of Modula-2 in the following
6068 ways:
6069
6070 @itemize @bullet
6071
6072 @item
6073 Integer constants are simply a sequence of digits. When used in an
6074 expression, a constant is interpreted to be type-compatible with the
6075 rest of the expression. Hexadecimal integers are specified by a
6076 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6077
6078 @item
6079 Floating point constants appear as a sequence of digits, followed by a
6080 decimal point and another sequence of digits. An optional exponent can
6081 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6082 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6083 digits of the floating point constant must be valid decimal (base 10)
6084 digits.
6085
6086 @item
6087 Character constants consist of a single character enclosed by a pair of
6088 like quotes, either single (@code{'}) or double (@code{"}). They may
6089 also be expressed by their ordinal value (their ASCII value, usually)
6090 followed by a @samp{C}.
6091
6092 @item
6093 String constants consist of a sequence of characters enclosed by a
6094 pair of like quotes, either single (@code{'}) or double (@code{"}).
6095 Escape sequences in the style of C are also allowed. @xref{C
6096 Constants, ,C and C++ constants}, for a brief explanation of escape
6097 sequences.
6098
6099 @item
6100 Enumerated constants consist of an enumerated identifier.
6101
6102 @item
6103 Boolean constants consist of the identifiers @code{TRUE} and
6104 @code{FALSE}.
6105
6106 @item
6107 Pointer constants consist of integral values only.
6108
6109 @item
6110 Set constants are not yet supported.
6111 @end itemize
6112
6113 @node M2 Defaults
6114 @subsubsection Modula-2 defaults
6115 @cindex Modula-2 defaults
6116
6117 If type and range checking are set automatically by @value{GDBN}, they
6118 both default to @code{on} whenever the working language changes to
6119 Modula-2. This happens regardless of whether you, or @value{GDBN},
6120 selected the working language.
6121
6122 If you allow @value{GDBN} to set the language automatically, then entering
6123 code compiled from a file whose name ends with @file{.mod} sets the
6124 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6125 the language automatically}, for further details.
6126
6127 @node Deviations
6128 @subsubsection Deviations from standard Modula-2
6129 @cindex Modula-2, deviations from
6130
6131 A few changes have been made to make Modula-2 programs easier to debug.
6132 This is done primarily via loosening its type strictness:
6133
6134 @itemize @bullet
6135 @item
6136 Unlike in standard Modula-2, pointer constants can be formed by
6137 integers. This allows you to modify pointer variables during
6138 debugging. (In standard Modula-2, the actual address contained in a
6139 pointer variable is hidden from you; it can only be modified
6140 through direct assignment to another pointer variable or expression that
6141 returned a pointer.)
6142
6143 @item
6144 C escape sequences can be used in strings and characters to represent
6145 non-printable characters. @value{GDBN} prints out strings with these
6146 escape sequences embedded. Single non-printable characters are
6147 printed using the @samp{CHR(@var{nnn})} format.
6148
6149 @item
6150 The assignment operator (@code{:=}) returns the value of its right-hand
6151 argument.
6152
6153 @item
6154 All built-in procedures both modify @emph{and} return their argument.
6155 @end itemize
6156
6157 @node M2 Checks
6158 @subsubsection Modula-2 type and range checks
6159 @cindex Modula-2 checks
6160
6161 @quotation
6162 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6163 range checking.
6164 @end quotation
6165 @c FIXME remove warning when type/range checks added
6166
6167 @value{GDBN} considers two Modula-2 variables type equivalent if:
6168
6169 @itemize @bullet
6170 @item
6171 They are of types that have been declared equivalent via a @code{TYPE
6172 @var{t1} = @var{t2}} statement
6173
6174 @item
6175 They have been declared on the same line. (Note: This is true of the
6176 GNU Modula-2 compiler, but it may not be true of other compilers.)
6177 @end itemize
6178
6179 As long as type checking is enabled, any attempt to combine variables
6180 whose types are not equivalent is an error.
6181
6182 Range checking is done on all mathematical operations, assignment, array
6183 index bounds, and all built-in functions and procedures.
6184
6185 @node M2 Scope
6186 @subsubsection The scope operators @code{::} and @code{.}
6187 @cindex scope
6188 @kindex .
6189 @cindex colon, doubled as scope operator
6190 @ifinfo
6191 @kindex colon-colon
6192 @c Info cannot handle :: but TeX can.
6193 @end ifinfo
6194 @iftex
6195 @kindex ::
6196 @end iftex
6197
6198 There are a few subtle differences between the Modula-2 scope operator
6199 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6200 similar syntax:
6201
6202 @example
6203
6204 @var{module} . @var{id}
6205 @var{scope} :: @var{id}
6206 @end example
6207
6208 @noindent
6209 where @var{scope} is the name of a module or a procedure,
6210 @var{module} the name of a module, and @var{id} is any declared
6211 identifier within your program, except another module.
6212
6213 Using the @code{::} operator makes @value{GDBN} search the scope
6214 specified by @var{scope} for the identifier @var{id}. If it is not
6215 found in the specified scope, then @value{GDBN} searches all scopes
6216 enclosing the one specified by @var{scope}.
6217
6218 Using the @code{.} operator makes @value{GDBN} search the current scope for
6219 the identifier specified by @var{id} that was imported from the
6220 definition module specified by @var{module}. With this operator, it is
6221 an error if the identifier @var{id} was not imported from definition
6222 module @var{module}, or if @var{id} is not an identifier in
6223 @var{module}.
6224
6225 @node GDB/M2
6226 @subsubsection @value{GDBN} and Modula-2
6227
6228 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6229 Five subcommands of @code{set print} and @code{show print} apply
6230 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6231 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6232 apply to C++, and the last to the C @code{union} type, which has no direct
6233 analogue in Modula-2.
6234
6235 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6236 while using any language, is not useful with Modula-2. Its
6237 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6238 created in Modula-2 as they can in C or C++. However, because an
6239 address can be specified by an integral constant, the construct
6240 @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
6241
6242 @cindex @code{#} in Modula-2
6243 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6244 interpreted as the beginning of a comment. Use @code{<>} instead.
6245
6246 @end ifset
6247 @end ifclear
6248
6249 @node Symbols
6250 @chapter Examining the Symbol Table
6251
6252 The commands described in this section allow you to inquire about the
6253 symbols (names of variables, functions and types) defined in your
6254 program. This information is inherent in the text of your program and
6255 does not change as your program executes. @value{GDBN} finds it in your
6256 program's symbol table, in the file indicated when you started @value{GDBN}
6257 (@pxref{File Options, ,Choosing files}), or by one of the
6258 file-management commands (@pxref{Files, ,Commands to specify files}).
6259
6260 @c FIXME! This might be intentionally specific to C and C++; if so, move
6261 @c to someplace in C section of lang chapter.
6262 @cindex symbol names
6263 @cindex names of symbols
6264 @cindex quoting names
6265 Occasionally, you may need to refer to symbols that contain unusual
6266 characters, which @value{GDBN} ordinarily treats as word delimiters. The
6267 most frequent case is in referring to static variables in other
6268 source files (@pxref{Variables,,Program variables}). File names
6269 are recorded in object files as debugging symbols, but @value{GDBN} would
6270 ordinarily parse a typical file name, like @file{foo.c}, as the three words
6271 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
6272 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
6273
6274 @example
6275 p 'foo.c'::x
6276 @end example
6277
6278 @noindent
6279 looks up the value of @code{x} in the scope of the file @file{foo.c}.
6280
6281 @table @code
6282 @item info address @var{symbol}
6283 @kindex info address
6284 Describe where the data for @var{symbol} is stored. For a register
6285 variable, this says which register it is kept in. For a non-register
6286 local variable, this prints the stack-frame offset at which the variable
6287 is always stored.
6288
6289 Note the contrast with @samp{print &@var{symbol}}, which does not work
6290 at all for a register variable, and for a stack local variable prints
6291 the exact address of the current instantiation of the variable.
6292
6293 @item whatis @var{exp}
6294 @kindex whatis
6295 Print the data type of expression @var{exp}. @var{exp} is not
6296 actually evaluated, and any side-effecting operations (such as
6297 assignments or function calls) inside it do not take place.
6298 @xref{Expressions, ,Expressions}.
6299
6300 @item whatis
6301 Print the data type of @code{$}, the last value in the value history.
6302
6303 @item ptype @var{typename}
6304 @kindex ptype
6305 Print a description of data type @var{typename}. @var{typename} may be
6306 the name of a type, or for C code it may have the form
6307 @ifclear CONLY
6308 @samp{class @var{class-name}},
6309 @end ifclear
6310 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
6311 @samp{enum @var{enum-tag}}.
6312
6313 @item ptype @var{exp}
6314 @itemx ptype
6315 Print a description of the type of expression @var{exp}. @code{ptype}
6316 differs from @code{whatis} by printing a detailed description, instead
6317 of just the name of the type.
6318
6319 For example, for this variable declaration:
6320
6321 @example
6322 struct complex @{double real; double imag;@} v;
6323 @end example
6324
6325 @noindent
6326 the two commands give this output:
6327
6328 @example
6329 @group
6330 (@value{GDBP}) whatis v
6331 type = struct complex
6332 (@value{GDBP}) ptype v
6333 type = struct complex @{
6334 double real;
6335 double imag;
6336 @}
6337 @end group
6338 @end example
6339
6340 @noindent
6341 As with @code{whatis}, using @code{ptype} without an argument refers to
6342 the type of @code{$}, the last value in the value history.
6343
6344 @item info types @var{regexp}
6345 @itemx info types
6346 @kindex info types
6347 Print a brief description of all types whose name matches @var{regexp}
6348 (or all types in your program, if you supply no argument). Each
6349 complete typename is matched as though it were a complete line; thus,
6350 @samp{i type value} gives information on all types in your program whose
6351 name includes the string @code{value}, but @samp{i type ^value$} gives
6352 information only on types whose complete name is @code{value}.
6353
6354 This command differs from @code{ptype} in two ways: first, like
6355 @code{whatis}, it does not print a detailed description; second, it
6356 lists all source files where a type is defined.
6357
6358 @item info source
6359 @kindex info source
6360 Show the name of the current source file---that is, the source file for
6361 the function containing the current point of execution---and the language
6362 it was written in.
6363
6364 @item info sources
6365 @kindex info sources
6366 Print the names of all source files in your program for which there is
6367 debugging information, organized into two lists: files whose symbols
6368 have already been read, and files whose symbols will be read when needed.
6369
6370 @item info functions
6371 @kindex info functions
6372 Print the names and data types of all defined functions.
6373
6374 @item info functions @var{regexp}
6375 Print the names and data types of all defined functions
6376 whose names contain a match for regular expression @var{regexp}.
6377 Thus, @samp{info fun step} finds all functions whose names
6378 include @code{step}; @samp{info fun ^step} finds those whose names
6379 start with @code{step}.
6380
6381 @item info variables
6382 @kindex info variables
6383 Print the names and data types of all variables that are declared
6384 outside of functions (i.e., excluding local variables).
6385
6386 @item info variables @var{regexp}
6387 Print the names and data types of all variables (except for local
6388 variables) whose names contain a match for regular expression
6389 @var{regexp}.
6390
6391 @ignore
6392 This was never implemented.
6393 @item info methods
6394 @itemx info methods @var{regexp}
6395 @kindex info methods
6396 The @code{info methods} command permits the user to examine all defined
6397 methods within C++ program, or (with the @var{regexp} argument) a
6398 specific set of methods found in the various C++ classes. Many
6399 C++ classes provide a large number of methods. Thus, the output
6400 from the @code{ptype} command can be overwhelming and hard to use. The
6401 @code{info-methods} command filters the methods, printing only those
6402 which match the regular-expression @var{regexp}.
6403 @end ignore
6404
6405 @item maint print symbols @var{filename}
6406 @itemx maint print psymbols @var{filename}
6407 @itemx maint print msymbols @var{filename}
6408 @kindex maint print symbols
6409 @cindex symbol dump
6410 @kindex maint print psymbols
6411 @cindex partial symbol dump
6412 Write a dump of debugging symbol data into the file @var{filename}.
6413 These commands are used to debug the @value{GDBN} symbol-reading code. Only
6414 symbols with debugging data are included. If you use @samp{maint print
6415 symbols}, @value{GDBN} includes all the symbols for which it has already
6416 collected full details: that is, @var{filename} reflects symbols for
6417 only those files whose symbols @value{GDBN} has read. You can use the
6418 command @code{info sources} to find out which files these are. If you
6419 use @samp{maint print psymbols} instead, the dump shows information about
6420 symbols that @value{GDBN} only knows partially---that is, symbols defined in
6421 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
6422 @samp{maint print msymbols} dumps just the minimal symbol information
6423 required for each object file from which @value{GDBN} has read some symbols.
6424 @xref{Files, ,Commands to specify files}, for a discussion of how
6425 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
6426 @end table
6427
6428 @node Altering
6429 @chapter Altering Execution
6430
6431 Once you think you have found an error in your program, you might want to
6432 find out for certain whether correcting the apparent error would lead to
6433 correct results in the rest of the run. You can find the answer by
6434 experiment, using the @value{GDBN} features for altering execution of the
6435 program.
6436
6437 For example, you can store new values into variables or memory
6438 locations,
6439 @ifclear BARETARGET
6440 give your program a signal, restart it
6441 @end ifclear
6442 @ifset BARETARGET
6443 restart your program
6444 @end ifset
6445 at a different address, or even return prematurely from a function to
6446 its caller.
6447
6448 @menu
6449 * Assignment:: Assignment to variables
6450 * Jumping:: Continuing at a different address
6451 @ifclear BARETARGET
6452 * Signaling:: Giving your program a signal
6453 @end ifclear
6454
6455 * Returning:: Returning from a function
6456 * Calling:: Calling your program's functions
6457 * Patching:: Patching your program
6458 @end menu
6459
6460 @node Assignment
6461 @section Assignment to variables
6462
6463 @cindex assignment
6464 @cindex setting variables
6465 To alter the value of a variable, evaluate an assignment expression.
6466 @xref{Expressions, ,Expressions}. For example,
6467
6468 @example
6469 print x=4
6470 @end example
6471
6472 @noindent
6473 stores the value 4 into the variable @code{x}, and then prints the
6474 value of the assignment expression (which is 4).
6475 @ifclear CONLY
6476 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
6477 information on operators in supported languages.
6478 @end ifclear
6479
6480 @kindex set variable
6481 @cindex variables, setting
6482 If you are not interested in seeing the value of the assignment, use the
6483 @code{set} command instead of the @code{print} command. @code{set} is
6484 really the same as @code{print} except that the expression's value is
6485 not printed and is not put in the value history (@pxref{Value History,
6486 ,Value history}). The expression is evaluated only for its effects.
6487
6488 If the beginning of the argument string of the @code{set} command
6489 appears identical to a @code{set} subcommand, use the @code{set
6490 variable} command instead of just @code{set}. This command is identical
6491 to @code{set} except for its lack of subcommands. For example, if
6492 your program has a variable @code{width}, you get
6493 an error if you try to set a new value with just @samp{set width=13},
6494 because @value{GDBN} has the command @code{set width}:
6495
6496 @example
6497 (@value{GDBP}) whatis width
6498 type = double
6499 (@value{GDBP}) p width
6500 $4 = 13
6501 (@value{GDBP}) set width=47
6502 Invalid syntax in expression.
6503 @end example
6504
6505 @noindent
6506 The invalid expression, of course, is @samp{=47}. In
6507 order to actually set the program's variable @code{width}, use
6508
6509 @example
6510 (@value{GDBP}) set var width=47
6511 @end example
6512
6513 @value{GDBN} allows more implicit conversions in assignments than C; you can
6514 freely store an integer value into a pointer variable or vice versa,
6515 and you can convert any structure to any other structure that is the
6516 same length or shorter.
6517 @comment FIXME: how do structs align/pad in these conversions?
6518 @comment /pesch@cygnus.com 18dec1990
6519
6520 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
6521 construct to generate a value of specified type at a specified address
6522 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
6523 to memory location @code{0x83040} as an integer (which implies a certain size
6524 and representation in memory), and
6525
6526 @example
6527 set @{int@}0x83040 = 4
6528 @end example
6529
6530 @noindent
6531 stores the value 4 into that memory location.
6532
6533 @node Jumping
6534 @section Continuing at a different address
6535
6536 Ordinarily, when you continue your program, you do so at the place where
6537 it stopped, with the @code{continue} command. You can instead continue at
6538 an address of your own choosing, with the following commands:
6539
6540 @table @code
6541 @item jump @var{linespec}
6542 @kindex jump
6543 Resume execution at line @var{linespec}. Execution stops again
6544 immediately if there is a breakpoint there. @xref{List, ,Printing
6545 source lines}, for a description of the different forms of
6546 @var{linespec}.
6547
6548 The @code{jump} command does not change the current stack frame, or
6549 the stack pointer, or the contents of any memory location or any
6550 register other than the program counter. If line @var{linespec} is in
6551 a different function from the one currently executing, the results may
6552 be bizarre if the two functions expect different patterns of arguments or
6553 of local variables. For this reason, the @code{jump} command requests
6554 confirmation if the specified line is not in the function currently
6555 executing. However, even bizarre results are predictable if you are
6556 well acquainted with the machine-language code of your program.
6557
6558 @item jump *@var{address}
6559 Resume execution at the instruction at address @var{address}.
6560 @end table
6561
6562 You can get much the same effect as the @code{jump} command by storing a
6563 new value into the register @code{$pc}. The difference is that this
6564 does not start your program running; it only changes the address where it
6565 @emph{will} run when you continue. For example,
6566
6567 @example
6568 set $pc = 0x485
6569 @end example
6570
6571 @noindent
6572 makes the next @code{continue} command or stepping command execute at
6573 address @code{0x485}, rather than at the address where your program stopped.
6574 @xref{Continuing and Stepping, ,Continuing and stepping}.
6575
6576 The most common occasion to use the @code{jump} command is to back up,
6577 perhaps with more breakpoints set, over a portion of a program that has
6578 already executed, in order to examine its execution in more detail.
6579
6580 @ifclear BARETARGET
6581 @c @group
6582 @node Signaling
6583 @section Giving your program a signal
6584
6585 @table @code
6586 @item signal @var{signal}
6587 @kindex signal
6588 Resume execution where your program stopped, but immediately give it the
6589 signal @var{signal}. @var{signal} can be the name or the number of a
6590 signal. For example, on many systems @code{signal 2} and @code{signal
6591 SIGINT} are both ways of sending an interrupt signal.
6592
6593 Alternatively, if @var{signal} is zero, continue execution without
6594 giving a signal. This is useful when your program stopped on account of
6595 a signal and would ordinary see the signal when resumed with the
6596 @code{continue} command; @samp{signal 0} causes it to resume without a
6597 signal.
6598
6599 @code{signal} does not repeat when you press @key{RET} a second time
6600 after executing the command.
6601 @end table
6602 @c @end group
6603
6604 Invoking the @code{signal} command is not the same as invoking the
6605 @code{kill} utility from the shell. Sending a signal with @code{kill}
6606 causes @value{GDBN} to decide what to do with the signal depending on
6607 the signal handling tables (@pxref{Signals}). The @code{signal} command
6608 passes the signal directly to your program.
6609
6610 @end ifclear
6611
6612 @node Returning
6613 @section Returning from a function
6614
6615 @table @code
6616 @item return
6617 @itemx return @var{expression}
6618 @cindex returning from a function
6619 @kindex return
6620 You can cancel execution of a function call with the @code{return}
6621 command. If you give an
6622 @var{expression} argument, its value is used as the function's return
6623 value.
6624 @end table
6625
6626 When you use @code{return}, @value{GDBN} discards the selected stack frame
6627 (and all frames within it). You can think of this as making the
6628 discarded frame return prematurely. If you wish to specify a value to
6629 be returned, give that value as the argument to @code{return}.
6630
6631 This pops the selected stack frame (@pxref{Selection, ,Selecting a
6632 frame}), and any other frames inside of it, leaving its caller as the
6633 innermost remaining frame. That frame becomes selected. The
6634 specified value is stored in the registers used for returning values
6635 of functions.
6636
6637 The @code{return} command does not resume execution; it leaves the
6638 program stopped in the state that would exist if the function had just
6639 returned. In contrast, the @code{finish} command (@pxref{Continuing
6640 and Stepping, ,Continuing and stepping}) resumes execution until the
6641 selected stack frame returns naturally.
6642
6643 @node Calling
6644 @section Calling program functions
6645
6646 @cindex calling functions
6647 @kindex call
6648 @table @code
6649 @item call @var{expr}
6650 Evaluate the expression @var{expr} without displaying @code{void}
6651 returned values.
6652 @end table
6653
6654 You can use this variant of the @code{print} command if you want to
6655 execute a function from your program, but without cluttering the output
6656 with @code{void} returned values. The result is printed and saved in
6657 the value history, if it is not void.
6658
6659 @node Patching
6660 @section Patching programs
6661 @cindex patching binaries
6662 @cindex writing into executables
6663 @ifclear BARETARGET
6664 @cindex writing into corefiles
6665 @end ifclear
6666
6667 By default, @value{GDBN} opens the file containing your program's executable
6668 code
6669 @ifclear BARETARGET
6670 (or the corefile)
6671 @end ifclear
6672 read-only. This prevents accidental alterations
6673 to machine code; but it also prevents you from intentionally patching
6674 your program's binary.
6675
6676 If you'd like to be able to patch the binary, you can specify that
6677 explicitly with the @code{set write} command. For example, you might
6678 want to turn on internal debugging flags, or even to make emergency
6679 repairs.
6680
6681 @table @code
6682 @item set write on
6683 @itemx set write off
6684 @kindex set write
6685 If you specify @samp{set write on}, @value{GDBN} opens executable
6686 @ifclear BARETARGET
6687 and core
6688 @end ifclear
6689 files for both reading and writing; if you specify @samp{set write
6690 off} (the default), @value{GDBN} opens them read-only.
6691
6692 If you have already loaded a file, you must load it again (using the
6693 @code{exec-file}
6694 @ifclear BARETARGET
6695 or @code{core-file}
6696 @end ifclear
6697 command) after changing @code{set write}, for your new setting to take
6698 effect.
6699
6700 @item show write
6701 @kindex show write
6702 Display whether executable files
6703 @ifclear BARETARGET
6704 and core files
6705 @end ifclear
6706 are opened for writing as well as reading.
6707 @end table
6708
6709 @node GDB Files
6710 @chapter @value{GDBN} Files
6711
6712 @value{GDBN} needs to know the file name of the program to be debugged, both in
6713 order to read its symbol table and in order to start your program.
6714 @ifclear BARETARGET
6715 To debug a core dump of a previous run, you must also tell @value{GDBN}
6716 the name of the core dump file.
6717 @end ifclear
6718
6719 @menu
6720 * Files:: Commands to specify files
6721 * Symbol Errors:: Errors reading symbol files
6722 @end menu
6723
6724 @node Files
6725 @section Commands to specify files
6726 @cindex symbol table
6727
6728 @ifclear BARETARGET
6729 @cindex core dump file
6730 The usual way to specify executable and core dump file names is with
6731 the command arguments given when you start @value{GDBN} (@pxref{Invocation,
6732 ,Getting In and Out of @value{GDBN}}.
6733 @end ifclear
6734 @ifset BARETARGET
6735 The usual way to specify an executable file name is with
6736 the command argument given when you start @value{GDBN}, (@pxref{Invocation,
6737 ,Getting In and Out of @value{GDBN}}.
6738 @end ifset
6739
6740 Occasionally it is necessary to change to a different file during a
6741 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
6742 a file you want to use. In these situations the @value{GDBN} commands
6743 to specify new files are useful.
6744
6745 @table @code
6746 @item file @var{filename}
6747 @cindex executable file
6748 @kindex file
6749 Use @var{filename} as the program to be debugged. It is read for its
6750 symbols and for the contents of pure memory. It is also the program
6751 executed when you use the @code{run} command. If you do not specify a
6752 directory and the file is not found in the @value{GDBN} working directory, @value{GDBN}
6753 uses the environment variable @code{PATH} as a list of directories to
6754 search, just as the shell does when looking for a program to run. You
6755 can change the value of this variable, for both @value{GDBN} and your program,
6756 using the @code{path} command.
6757
6758 On systems with memory-mapped files, an auxiliary file
6759 @file{@var{filename}.syms} may hold symbol table information for
6760 @var{filename}. If so, @value{GDBN} maps in the symbol table from
6761 @file{@var{filename}.syms}, starting up more quickly. See the
6762 descriptions of the options @samp{-mapped} and @samp{-readnow}
6763 (available on the command line, and with the commands @code{file},
6764 @code{symbol-file}, or @code{add-symbol-file}), for more information.
6765
6766 @item file
6767 @code{file} with no argument makes @value{GDBN} discard any information it
6768 has on both executable file and the symbol table.
6769
6770 @item exec-file @r{[} @var{filename} @r{]}
6771 @kindex exec-file
6772 Specify that the program to be run (but not the symbol table) is found
6773 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
6774 if necessary to locate your program. Omitting @var{filename} means to
6775 discard information on the executable file.
6776
6777 @item symbol-file @r{[} @var{filename} @r{]}
6778 @kindex symbol-file
6779 Read symbol table information from file @var{filename}. @code{PATH} is
6780 searched when necessary. Use the @code{file} command to get both symbol
6781 table and program to run from the same file.
6782
6783 @code{symbol-file} with no argument clears out @value{GDBN} information on your
6784 program's symbol table.
6785
6786 The @code{symbol-file} command causes @value{GDBN} to forget the contents of its
6787 convenience variables, the value history, and all breakpoints and
6788 auto-display expressions. This is because they may contain pointers to
6789 the internal data recording symbols and data types, which are part of
6790 the old symbol table data being discarded inside @value{GDBN}.
6791
6792 @code{symbol-file} does not repeat if you press @key{RET} again after
6793 executing it once.
6794
6795 When @value{GDBN} is configured for a particular environment, it
6796 understands debugging information in whatever format is the standard
6797 generated for that environment; you may use either a GNU compiler, or
6798 other compilers that adhere to the local conventions. Best results are
6799 usually obtained from GNU compilers; for example, using @code{@value{GCC}}
6800 you can generate debugging information for optimized code.
6801
6802 On some kinds of object files, the @code{symbol-file} command does not
6803 normally read the symbol table in full right away. Instead, it scans
6804 the symbol table quickly to find which source files and which symbols
6805 are present. The details are read later, one source file at a time,
6806 as they are needed.
6807
6808 The purpose of this two-stage reading strategy is to make @value{GDBN} start up
6809 faster. For the most part, it is invisible except for occasional
6810 pauses while the symbol table details for a particular source file are
6811 being read. (The @code{set verbose} command can turn these pauses
6812 into messages if desired. @xref{Messages/Warnings, ,Optional warnings
6813 and messages}.)
6814
6815 We have not implemented the two-stage strategy for COFF yet. When the
6816 symbol table is stored in COFF format, @code{symbol-file} reads the
6817 symbol table data in full right away.
6818
6819 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6820 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6821 @kindex readnow
6822 @cindex reading symbols immediately
6823 @cindex symbols, reading immediately
6824 @kindex mapped
6825 @cindex memory-mapped symbol file
6826 @cindex saving symbol table
6827 You can override the @value{GDBN} two-stage strategy for reading symbol
6828 tables by using the @samp{-readnow} option with any of the commands that
6829 load symbol table information, if you want to be sure @value{GDBN} has the
6830 entire symbol table available.
6831
6832 @ifclear BARETARGET
6833 If memory-mapped files are available on your system through the
6834 @code{mmap} system call, you can use another option, @samp{-mapped}, to
6835 cause @value{GDBN} to write the symbols for your program into a reusable
6836 file. Future @value{GDBN} debugging sessions map in symbol information
6837 from this auxiliary symbol file (if the program has not changed), rather
6838 than spending time reading the symbol table from the executable
6839 program. Using the @samp{-mapped} option has the same effect as
6840 starting @value{GDBN} with the @samp{-mapped} command-line option.
6841
6842 You can use both options together, to make sure the auxiliary symbol
6843 file has all the symbol information for your program.
6844
6845 The auxiliary symbol file for a program called @var{myprog} is called
6846 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
6847 than the corresponding executable), @value{GDBN} always attempts to use
6848 it when you debug @var{myprog}; no special options or commands are
6849 needed.
6850
6851 The @file{.syms} file is specific to the host machine where you run
6852 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
6853 symbol table. It cannot be shared across multiple host platforms.
6854
6855 @c FIXME: for now no mention of directories, since this seems to be in
6856 @c flux. 13mar1992 status is that in theory GDB would look either in
6857 @c current dir or in same dir as myprog; but issues like competing
6858 @c GDB's, or clutter in system dirs, mean that in practice right now
6859 @c only current dir is used. FFish says maybe a special GDB hierarchy
6860 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
6861 @c files.
6862
6863 @item core-file @r{[} @var{filename} @r{]}
6864 @kindex core
6865 @kindex core-file
6866 Specify the whereabouts of a core dump file to be used as the ``contents
6867 of memory''. Traditionally, core files contain only some parts of the
6868 address space of the process that generated them; @value{GDBN} can access the
6869 executable file itself for other parts.
6870
6871 @code{core-file} with no argument specifies that no core file is
6872 to be used.
6873
6874 Note that the core file is ignored when your program is actually running
6875 under @value{GDBN}. So, if you have been running your program and you wish to
6876 debug a core file instead, you must kill the subprocess in which the
6877 program is running. To do this, use the @code{kill} command
6878 (@pxref{Kill Process, ,Killing the child process}).
6879 @end ifclear
6880
6881 @item load @var{filename}
6882 @kindex load
6883 @ifset GENERIC
6884 Depending on what remote debugging facilities are configured into
6885 @value{GDBN}, the @code{load} command may be available. Where it exists, it
6886 is meant to make @var{filename} (an executable) available for debugging
6887 on the remote system---by downloading, or dynamic linking, for example.
6888 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
6889 the @code{add-symbol-file} command.
6890
6891 If your @value{GDBN} does not have a @code{load} command, attempting to
6892 execute it gets the error message ``@code{You can't do that when your
6893 target is @dots{}}''
6894 @end ifset
6895
6896 The file is loaded at whatever address is specified in the executable.
6897 For some object file formats, you can specify the load address when you
6898 link the program; for other formats, like a.out, the object file format
6899 specifies a fixed address.
6900 @c FIXME! This would be a good place for an xref to the GNU linker doc.
6901
6902 @ifset VXWORKS
6903 On VxWorks, @code{load} links @var{filename} dynamically on the
6904 current target system as well as adding its symbols in @value{GDBN}.
6905 @end ifset
6906
6907 @ifset I960
6908 @cindex download to Nindy-960
6909 With the Nindy interface to an Intel 960 board, @code{load}
6910 downloads @var{filename} to the 960 as well as adding its symbols in
6911 @value{GDBN}.
6912 @end ifset
6913
6914 @ifset H8
6915 @cindex download to H8/300 or H8/500
6916 @cindex H8/300 or H8/500 download
6917 @cindex download to Hitachi SH
6918 @cindex Hitachi SH download
6919 When you select remote debugging to a Hitachi SH, H8/300, or H8/500 board
6920 (@pxref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}),
6921 the @code{load} command downloads your program to the Hitachi board and also
6922 opens it as the current executable target for @value{GDBN} on your host
6923 (like the @code{file} command).
6924 @end ifset
6925
6926 @code{load} does not repeat if you press @key{RET} again after using it.
6927
6928 @ifclear BARETARGET
6929 @item add-symbol-file @var{filename} @var{address}
6930 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6931 @kindex add-symbol-file
6932 @cindex dynamic linking
6933 The @code{add-symbol-file} command reads additional symbol table information
6934 from the file @var{filename}. You would use this command when @var{filename}
6935 has been dynamically loaded (by some other means) into the program that
6936 is running. @var{address} should be the memory address at which the
6937 file has been loaded; @value{GDBN} cannot figure this out for itself.
6938 You can specify @var{address} as an expression.
6939
6940 The symbol table of the file @var{filename} is added to the symbol table
6941 originally read with the @code{symbol-file} command. You can use the
6942 @code{add-symbol-file} command any number of times; the new symbol data thus
6943 read keeps adding to the old. To discard all old symbol data instead,
6944 use the @code{symbol-file} command.
6945
6946 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
6947
6948 You can use the @samp{-mapped} and @samp{-readnow} options just as with
6949 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
6950 table information for @var{filename}.
6951 @end ifclear
6952
6953 @item info files
6954 @itemx info target
6955 @kindex info files
6956 @kindex info target
6957 @code{info files} and @code{info target} are synonymous; both print
6958 the current target (@pxref{Targets, ,Specifying a Debugging Target}),
6959 including the
6960 @ifclear BARETARGET
6961 names of the executable and core dump files
6962 @end ifclear
6963 @ifset BARETARGET
6964 name of the executable file
6965 @end ifset
6966 currently in use by @value{GDBN}, and the files from which symbols were
6967 loaded. The command @code{help targets} lists all possible targets
6968 rather than current ones.
6969 @end table
6970
6971 All file-specifying commands allow both absolute and relative file names
6972 as arguments. @value{GDBN} always converts the file name to an absolute file
6973 name and remembers it that way.
6974
6975 @ifclear BARETARGET
6976 @cindex shared libraries
6977 @value{GDBN} supports SunOS, SVr4, Irix 5, and IBM RS/6000 shared libraries.
6978 @value{GDBN} automatically loads symbol definitions from shared libraries
6979 when you use the @code{run} command, or when you examine a core file.
6980 (Before you issue the @code{run} command, @value{GDBN} does not understand
6981 references to a function in a shared library, however---unless you are
6982 debugging a core file).
6983 @c FIXME: some @value{GDBN} release may permit some refs to undef
6984 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
6985 @c FIXME...lib; check this from time to time when updating manual
6986
6987 @table @code
6988 @item info share
6989 @itemx info sharedlibrary
6990 @kindex info sharedlibrary
6991 @kindex info share
6992 Print the names of the shared libraries which are currently loaded.
6993
6994 @item sharedlibrary @var{regex}
6995 @itemx share @var{regex}
6996 @kindex sharedlibrary
6997 @kindex share
6998 This is an obsolescent command; you can use it to explicitly load shared
6999 object library symbols for files matching a Unix regular expression, but
7000 as with files loaded automatically, it only loads shared libraries
7001 required by your program for a core file or after typing @code{run}. If
7002 @var{regex} is omitted all shared libraries required by your program are
7003 loaded.
7004 @end table
7005 @end ifclear
7006
7007 @node Symbol Errors
7008 @section Errors reading symbol files
7009
7010 While reading a symbol file, @value{GDBN} occasionally encounters problems,
7011 such as symbol types it does not recognize, or known bugs in compiler
7012 output. By default, @value{GDBN} does not notify you of such problems, since
7013 they are relatively common and primarily of interest to people
7014 debugging compilers. If you are interested in seeing information
7015 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
7016 only one message about each such type of problem, no matter how many
7017 times the problem occurs; or you can ask @value{GDBN} to print more messages,
7018 to see how many times the problems occur, with the @code{set
7019 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
7020 messages}).
7021
7022 The messages currently printed, and their meanings, include:
7023
7024 @table @code
7025 @item inner block not inside outer block in @var{symbol}
7026
7027 The symbol information shows where symbol scopes begin and end
7028 (such as at the start of a function or a block of statements). This
7029 error indicates that an inner scope block is not fully contained
7030 in its outer scope blocks.
7031
7032 @value{GDBN} circumvents the problem by treating the inner block as if it had
7033 the same scope as the outer block. In the error message, @var{symbol}
7034 may be shown as ``@code{(don't know)}'' if the outer block is not a
7035 function.
7036
7037 @item block at @var{address} out of order
7038
7039 The symbol information for symbol scope blocks should occur in
7040 order of increasing addresses. This error indicates that it does not
7041 do so.
7042
7043 @value{GDBN} does not circumvent this problem, and has trouble
7044 locating symbols in the source file whose symbols it is reading. (You
7045 can often determine what source file is affected by specifying
7046 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
7047 messages}.)
7048
7049 @item bad block start address patched
7050
7051 The symbol information for a symbol scope block has a start address
7052 smaller than the address of the preceding source line. This is known
7053 to occur in the SunOS 4.1.1 (and earlier) C compiler.
7054
7055 @value{GDBN} circumvents the problem by treating the symbol scope block as
7056 starting on the previous source line.
7057
7058 @item bad string table offset in symbol @var{n}
7059
7060 @cindex foo
7061 Symbol number @var{n} contains a pointer into the string table which is
7062 larger than the size of the string table.
7063
7064 @value{GDBN} circumvents the problem by considering the symbol to have the
7065 name @code{foo}, which may cause other problems if many symbols end up
7066 with this name.
7067
7068 @item unknown symbol type @code{0x@var{nn}}
7069
7070 The symbol information contains new data types that @value{GDBN} does not yet
7071 know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
7072 information, in hexadecimal.
7073
7074 @value{GDBN} circumvents the error by ignoring this symbol information. This
7075 usually allows you to debug your program, though certain symbols
7076 are not accessible. If you encounter such a problem and feel like
7077 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint on
7078 @code{complain}, then go up to the function @code{read_dbx_symtab} and
7079 examine @code{*bufp} to see the symbol.
7080
7081 @item stub type has NULL name
7082 @value{GDBN} could not find the full definition for
7083 @ifclear CONLY
7084 a struct or class.
7085 @end ifclear
7086 @ifset CONLY
7087 a struct.
7088 @end ifset
7089
7090 @ifclear CONLY
7091 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
7092
7093 The symbol information for a C++ member function is missing some
7094 information that recent versions of the compiler should have output
7095 for it.
7096 @end ifclear
7097
7098 @item info mismatch between compiler and debugger
7099
7100 @value{GDBN} could not parse a type specification output by the compiler.
7101 @end table
7102
7103 @node Targets
7104 @chapter Specifying a Debugging Target
7105 @cindex debugging target
7106 @kindex target
7107
7108 A @dfn{target} is the execution environment occupied by your program.
7109 @ifclear BARETARGET
7110 Often, @value{GDBN} runs in the same host environment as your program; in
7111 that case, the debugging target is specified as a side effect when you
7112 use the @code{file} or @code{core} commands. When you need more
7113 flexibility---for example, running @value{GDBN} on a physically separate
7114 host, or controlling a standalone system over a serial port or a
7115 realtime system over a TCP/IP connection---you
7116 @end ifclear
7117 @ifset BARETARGET
7118 You
7119 @end ifset
7120 can use the @code{target} command to specify one of the target types
7121 configured for @value{GDBN} (@pxref{Target Commands, ,Commands for managing
7122 targets}).
7123
7124 @menu
7125 * Active Targets:: Active targets
7126 * Target Commands:: Commands for managing targets
7127 * Remote:: Remote debugging
7128 @end menu
7129
7130 @node Active Targets
7131 @section Active targets
7132 @cindex stacking targets
7133 @cindex active targets
7134 @cindex multiple targets
7135
7136 @ifclear BARETARGET
7137 There are three classes of targets: processes, core files, and
7138 executable files. @value{GDBN} can work concurrently on up to three active
7139 targets, one in each class. This allows you to (for example) start a
7140 process and inspect its activity without abandoning your work on a core
7141 file.
7142
7143 For example, if you execute @samp{gdb a.out}, then the executable file
7144 @code{a.out} is the only active target. If you designate a core file as
7145 well---presumably from a prior run that crashed and coredumped---then
7146 @value{GDBN} has two active targets and uses them in tandem, looking
7147 first in the corefile target, then in the executable file, to satisfy
7148 requests for memory addresses. (Typically, these two classes of target
7149 are complementary, since core files contain only a program's
7150 read-write memory---variables and so on---plus machine status, while
7151 executable files contain only the program text and initialized data.)
7152 @end ifclear
7153
7154 When you type @code{run}, your executable file becomes an active process
7155 target as well. When a process target is active, all @value{GDBN} commands
7156 requesting memory addresses refer to that target; addresses in an
7157 @ifclear BARETARGET
7158 active core file or
7159 @end ifclear
7160 executable file target are obscured while the process
7161 target is active.
7162
7163 @ifset BARETARGET
7164 Use the @code{exec-file} command to select a
7165 new executable target (@pxref{Files, ,Commands to specify
7166 files}).
7167 @end ifset
7168 @ifclear BARETARGET
7169 Use the @code{core-file} and @code{exec-file} commands to select a
7170 new core file or executable target (@pxref{Files, ,Commands to specify
7171 files}). To specify as a target a process that is already running, use
7172 the @code{attach} command (@pxref{Attach, ,Debugging an
7173 already-running process}).
7174 @end ifclear
7175
7176 @node Target Commands
7177 @section Commands for managing targets
7178
7179 @table @code
7180 @item target @var{type} @var{parameters}
7181 Connects the @value{GDBN} host environment to a target
7182 @ifset BARETARGET
7183 machine.
7184 @end ifset
7185 @ifclear BARETARGET
7186 machine or process. A target is typically a protocol for talking to
7187 debugging facilities. You use the argument @var{type} to specify the
7188 type or protocol of the target machine.
7189
7190 Further @var{parameters} are interpreted by the target protocol, but
7191 typically include things like device names or host names to connect
7192 with, process numbers, and baud rates.
7193 @end ifclear
7194
7195 The @code{target} command does not repeat if you press @key{RET} again
7196 after executing the command.
7197
7198 @item help target
7199 @kindex help target
7200 Displays the names of all targets available. To display targets
7201 currently selected, use either @code{info target} or @code{info files}
7202 (@pxref{Files, ,Commands to specify files}).
7203
7204 @item help target @var{name}
7205 Describe a particular target, including any parameters necessary to
7206 select it.
7207 @end table
7208
7209 Here are some common targets (available, or not, depending on the GDB
7210 configuration):
7211
7212 @table @code
7213 @item target exec @var{program}
7214 @kindex target exec
7215 An executable file. @samp{target exec @var{program}} is the same as
7216 @samp{exec-file @var{program}}.
7217
7218 @ifclear BARETARGET
7219 @item target core @var{filename}
7220 @kindex target core
7221 A core dump file. @samp{target core @var{filename}} is the same as
7222 @samp{core-file @var{filename}}.
7223 @end ifclear
7224
7225 @ifset REMOTESTUB
7226 @item target remote @var{dev}
7227 @kindex target remote
7228 Remote serial target in GDB-specific protocol. The argument @var{dev}
7229 specifies what serial device to use for the connection (e.g.
7230 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}.
7231 @end ifset
7232
7233 @ifset SIMS
7234 @item target sim
7235 @kindex target sim
7236 CPU simulator. @xref{Simulator,,Simulated CPU Target}.
7237 @end ifset
7238
7239 @ifset AMD29K
7240 @item target udi @var{keyword}
7241 @kindex target udi
7242 Remote AMD29K target, using the AMD UDI protocol. The @var{keyword}
7243 argument specifies which 29K board or simulator to use. @xref{UDI29K
7244 Remote,,The UDI protocol for AMD29K}.
7245
7246 @item target amd-eb @var{dev} @var{speed} @var{PROG}
7247 @kindex target amd-eb
7248 @cindex AMD EB29K
7249 Remote PC-resident AMD EB29K board, attached over serial lines.
7250 @var{dev} is the serial device, as for @code{target remote};
7251 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
7252 name of the program to be debugged, as it appears to DOS on the PC.
7253 @xref{EB29K Remote, ,The EBMON protocol for AMD29K}.
7254
7255 @end ifset
7256 @ifset H8
7257 @item target hms
7258 @kindex target hms
7259 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
7260 @ifclear H8EXCLUSIVE
7261 @c Unix only, not currently of interest for H8-only manual
7262 Use special commands @code{device} and @code{speed} to control the serial
7263 line and the communications speed used.
7264 @end ifclear
7265 @xref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}.
7266
7267 @end ifset
7268 @ifset I960
7269 @item target nindy @var{devicename}
7270 @kindex target nindy
7271 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
7272 the name of the serial device to use for the connection, e.g.
7273 @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}.
7274
7275 @end ifset
7276 @ifset ST2000
7277 @item target st2000 @var{dev} @var{speed}
7278 @kindex target st2000
7279 A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev}
7280 is the name of the device attached to the ST2000 serial line;
7281 @var{speed} is the communication line speed. The arguments are not used
7282 if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet.
7283 @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}.
7284
7285 @end ifset
7286 @ifset VXWORKS
7287 @item target vxworks @var{machinename}
7288 @kindex target vxworks
7289 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
7290 is the target system's machine name or IP address.
7291 @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}.
7292 @end ifset
7293 @end table
7294
7295 @ifset GENERIC
7296 Different targets are available on different configurations of @value{GDBN}; your
7297 configuration may have more or fewer targets.
7298 @end ifset
7299
7300 @node Remote
7301 @section Remote debugging
7302 @cindex remote debugging
7303
7304 If you are trying to debug a program running on a machine that cannot run
7305 GDB in the usual way, it is often useful to use remote debugging. For
7306 example, you might use remote debugging on an operating system kernel, or on
7307 a small system which does not have a general purpose operating system
7308 powerful enough to run a full-featured debugger.
7309
7310 Some configurations of GDB have special serial or TCP/IP interfaces
7311 to make this work with particular debugging targets. In addition,
7312 GDB comes with a generic serial protocol (specific to GDB, but
7313 not specific to any particular target system) which you can use if you
7314 write the remote stubs---the code that runs on the remote system to
7315 communicate with GDB.
7316
7317 Other remote targets may be available in your
7318 configuration of GDB; use @code{help targets} to list them.
7319
7320 @ifset GENERIC
7321 @c Text on starting up GDB in various specific cases; it goes up front
7322 @c in manuals configured for any of those particular situations, here
7323 @c otherwise.
7324 @menu
7325 @ifset REMOTESTUB
7326 * Remote Serial:: @value{GDBN} remote serial protocol
7327 @end ifset
7328 @ifset I960
7329 * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy)
7330 @end ifset
7331 @ifset AMD29K
7332 * UDI29K Remote:: The UDI protocol for AMD29K
7333 * EB29K Remote:: The EBMON protocol for AMD29K
7334 @end ifset
7335 @ifset VXWORKS
7336 * VxWorks Remote:: @value{GDBN} and VxWorks
7337 @end ifset
7338 @ifset ST2000
7339 * ST2000 Remote:: @value{GDBN} with a Tandem ST2000
7340 @end ifset
7341 @ifset H8
7342 * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors
7343 @end ifset
7344 @ifset MIPS
7345 * MIPS Remote:: @value{GDBN} and MIPS boards
7346 @end ifset
7347 @ifset SIMS
7348 * Simulator:: Simulated CPU target
7349 @end ifset
7350 @end menu
7351
7352 @include remote.texi
7353 @end ifset
7354
7355 @node Controlling GDB
7356 @chapter Controlling @value{GDBN}
7357
7358 You can alter the way @value{GDBN} interacts with you by using
7359 the @code{set} command. For commands controlling how @value{GDBN} displays
7360 data, @pxref{Print Settings, ,Print settings}; other settings are described here.
7361
7362 @menu
7363 * Prompt:: Prompt
7364 * Editing:: Command editing
7365 * History:: Command history
7366 * Screen Size:: Screen size
7367 * Numbers:: Numbers
7368 * Messages/Warnings:: Optional warnings and messages
7369 @end menu
7370
7371 @node Prompt
7372 @section Prompt
7373 @cindex prompt
7374
7375 @value{GDBN} indicates its readiness to read a command by printing a string
7376 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
7377 can change the prompt string with the @code{set prompt} command. For
7378 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
7379 the prompt in one of the @value{GDBN} sessions so that you can always tell which
7380 one you are talking to.
7381
7382 @table @code
7383 @item set prompt @var{newprompt}
7384 @kindex set prompt
7385 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
7386 @kindex show prompt
7387 @item show prompt
7388 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
7389 @end table
7390
7391 @node Editing
7392 @section Command editing
7393 @cindex readline
7394 @cindex command line editing
7395
7396 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
7397 GNU library provides consistent behavior for programs which provide a
7398 command line interface to the user. Advantages are @code{emacs}-style
7399 or @code{vi}-style inline editing of commands, @code{csh}-like history
7400 substitution, and a storage and recall of command history across
7401 debugging sessions.
7402
7403 You may control the behavior of command line editing in @value{GDBN} with the
7404 command @code{set}.
7405
7406 @table @code
7407 @kindex set editing
7408 @cindex editing
7409 @item set editing
7410 @itemx set editing on
7411 Enable command line editing (enabled by default).
7412
7413 @item set editing off
7414 Disable command line editing.
7415
7416 @kindex show editing
7417 @item show editing
7418 Show whether command line editing is enabled.
7419 @end table
7420
7421 @node History
7422 @section Command history
7423
7424 @value{GDBN} can keep track of the commands you type during your
7425 debugging sessions, so that you can be certain of precisely what
7426 happened. Use these commands to manage the @value{GDBN} command
7427 history facility.
7428
7429 @table @code
7430 @cindex history substitution
7431 @cindex history file
7432 @kindex set history filename
7433 @kindex GDBHISTFILE
7434 @item set history filename @var{fname}
7435 Set the name of the @value{GDBN} command history file to @var{fname}.
7436 This is the file where @value{GDBN} reads an initial command history
7437 list, and where it writes the command history from this session when it
7438 exits. You can access this list through history expansion or through
7439 the history command editing characters listed below. This file defaults
7440 to the value of the environment variable @code{GDBHISTFILE}, or to
7441 @file{./.gdb_history} if this variable is not set.
7442
7443 @cindex history save
7444 @kindex set history save
7445 @item set history save
7446 @itemx set history save on
7447 Record command history in a file, whose name may be specified with the
7448 @code{set history filename} command. By default, this option is disabled.
7449
7450 @item set history save off
7451 Stop recording command history in a file.
7452
7453 @cindex history size
7454 @kindex set history size
7455 @item set history size @var{size}
7456 Set the number of commands which @value{GDBN} keeps in its history list.
7457 This defaults to the value of the environment variable
7458 @code{HISTSIZE}, or to 256 if this variable is not set.
7459 @end table
7460
7461 @cindex history expansion
7462 History expansion assigns special meaning to the character @kbd{!}.
7463 @ifset have-readline-appendices
7464 @xref{Event Designators}.
7465 @end ifset
7466
7467 Since @kbd{!} is also the logical not operator in C, history expansion
7468 is off by default. If you decide to enable history expansion with the
7469 @code{set history expansion on} command, you may sometimes need to
7470 follow @kbd{!} (when it is used as logical not, in an expression) with
7471 a space or a tab to prevent it from being expanded. The readline
7472 history facilities do not attempt substitution on the strings
7473 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
7474
7475 The commands to control history expansion are:
7476
7477 @table @code
7478
7479 @kindex set history expansion
7480 @item set history expansion on
7481 @itemx set history expansion
7482 Enable history expansion. History expansion is off by default.
7483
7484 @item set history expansion off
7485 Disable history expansion.
7486
7487 The readline code comes with more complete documentation of
7488 editing and history expansion features. Users unfamiliar with @code{emacs}
7489 or @code{vi} may wish to read it.
7490 @ifset have-readline-appendices
7491 @xref{Command Line Editing}.
7492 @end ifset
7493
7494 @c @group
7495 @kindex show history
7496 @item show history
7497 @itemx show history filename
7498 @itemx show history save
7499 @itemx show history size
7500 @itemx show history expansion
7501 These commands display the state of the @value{GDBN} history parameters.
7502 @code{show history} by itself displays all four states.
7503 @c @end group
7504 @end table
7505
7506 @table @code
7507 @kindex show commands
7508 @item show commands
7509 Display the last ten commands in the command history.
7510
7511 @item show commands @var{n}
7512 Print ten commands centered on command number @var{n}.
7513
7514 @item show commands +
7515 Print ten commands just after the commands last printed.
7516 @end table
7517
7518 @node Screen Size
7519 @section Screen size
7520 @cindex size of screen
7521 @cindex pauses in output
7522
7523 Certain commands to @value{GDBN} may produce large amounts of
7524 information output to the screen. To help you read all of it,
7525 @value{GDBN} pauses and asks you for input at the end of each page of
7526 output. Type @key{RET} when you want to continue the output, or @kbd{q}
7527 to discard the remaining output. Also, the screen width setting
7528 determines when to wrap lines of output. Depending on what is being
7529 printed, @value{GDBN} tries to break the line at a readable place,
7530 rather than simply letting it overflow onto the following line.
7531
7532 Normally @value{GDBN} knows the size of the screen from the termcap data base
7533 together with the value of the @code{TERM} environment variable and the
7534 @code{stty rows} and @code{stty cols} settings. If this is not correct,
7535 you can override it with the @code{set height} and @code{set
7536 width} commands:
7537
7538 @table @code
7539 @item set height @var{lpp}
7540 @itemx show height
7541 @itemx set width @var{cpl}
7542 @itemx show width
7543 @kindex set height
7544 @kindex set width
7545 @kindex show width
7546 @kindex show height
7547 These @code{set} commands specify a screen height of @var{lpp} lines and
7548 a screen width of @var{cpl} characters. The associated @code{show}
7549 commands display the current settings.
7550
7551 If you specify a height of zero lines, @value{GDBN} does not pause during output
7552 no matter how long the output is. This is useful if output is to a file
7553 or to an editor buffer.
7554
7555 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
7556 from wrapping its output.
7557 @end table
7558
7559 @node Numbers
7560 @section Numbers
7561 @cindex number representation
7562 @cindex entering numbers
7563
7564 You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by
7565 the usual conventions: octal numbers begin with @samp{0}, decimal
7566 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
7567 Numbers that begin with none of these are, by default, entered in base
7568 10; likewise, the default display for numbers---when no particular
7569 format is specified---is base 10. You can change the default base for
7570 both input and output with the @code{set radix} command.
7571
7572 @table @code
7573 @kindex set radix
7574 @item set radix @var{base}
7575 Set the default base for numeric input and display. Supported choices
7576 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
7577 specified either unambiguously or using the current default radix; for
7578 example, any of
7579
7580 @example
7581 set radix 012
7582 set radix 10.
7583 set radix 0xa
7584 @end example
7585
7586 @noindent
7587 sets the base to decimal. On the other hand, @samp{set radix 10}
7588 leaves the radix unchanged no matter what it was.
7589
7590 @kindex show radix
7591 @item show radix
7592 Display the current default base for numeric input and display.
7593 @end table
7594
7595 @node Messages/Warnings
7596 @section Optional warnings and messages
7597
7598 By default, @value{GDBN} is silent about its inner workings. If you are running
7599 on a slow machine, you may want to use the @code{set verbose} command.
7600 It makes @value{GDBN} tell you when it does a lengthy internal operation, so
7601 you will not think it has crashed.
7602
7603 Currently, the messages controlled by @code{set verbose} are those
7604 which announce that the symbol table for a source file is being read;
7605 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
7606
7607 @table @code
7608 @kindex set verbose
7609 @item set verbose on
7610 Enables @value{GDBN} output of certain informational messages.
7611
7612 @item set verbose off
7613 Disables @value{GDBN} output of certain informational messages.
7614
7615 @kindex show verbose
7616 @item show verbose
7617 Displays whether @code{set verbose} is on or off.
7618 @end table
7619
7620 By default, if @value{GDBN} encounters bugs in the symbol table of an object
7621 file, it is silent; but if you are debugging a compiler, you may find
7622 this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}).
7623
7624 @table @code
7625 @kindex set complaints
7626 @item set complaints @var{limit}
7627 Permits @value{GDBN} to output @var{limit} complaints about each type of unusual
7628 symbols before becoming silent about the problem. Set @var{limit} to
7629 zero to suppress all complaints; set it to a large number to prevent
7630 complaints from being suppressed.
7631
7632 @kindex show complaints
7633 @item show complaints
7634 Displays how many symbol complaints @value{GDBN} is permitted to produce.
7635 @end table
7636
7637 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
7638 lot of stupid questions to confirm certain commands. For example, if
7639 you try to run a program which is already running:
7640
7641 @example
7642 (@value{GDBP}) run
7643 The program being debugged has been started already.
7644 Start it from the beginning? (y or n)
7645 @end example
7646
7647 If you are willing to unflinchingly face the consequences of your own
7648 commands, you can disable this ``feature'':
7649
7650 @table @code
7651 @kindex set confirm
7652 @cindex flinching
7653 @cindex confirmation
7654 @cindex stupid questions
7655 @item set confirm off
7656 Disables confirmation requests.
7657
7658 @item set confirm on
7659 Enables confirmation requests (the default).
7660
7661 @item show confirm
7662 @kindex show confirm
7663 Displays state of confirmation requests.
7664 @end table
7665
7666 @c FIXME this does not really belong here. But where *does* it belong?
7667 @cindex reloading symbols
7668 Some systems allow individual object files that make up your program to
7669 be replaced without stopping and restarting your program.
7670 @ifset VXWORKS
7671 For example, in VxWorks you can simply recompile a defective object file
7672 and keep on running.
7673 @end ifset
7674 If you are running on one of these systems, you can allow @value{GDBN} to
7675 reload the symbols for automatically relinked modules:
7676
7677 @table @code
7678 @kindex set symbol-reloading
7679 @item set symbol-reloading on
7680 Replace symbol definitions for the corresponding source file when an
7681 object file with a particular name is seen again.
7682
7683 @item set symbol-reloading off
7684 Do not replace symbol definitions when re-encountering object files of
7685 the same name. This is the default state; if you are not running on a
7686 system that permits automatically relinking modules, you should leave
7687 @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7688 when linking large programs, that may contain several modules (from
7689 different directories or libraries) with the same name.
7690
7691 @item show symbol-reloading
7692 Show the current @code{on} or @code{off} setting.
7693 @end table
7694
7695 @node Sequences
7696 @chapter Canned Sequences of Commands
7697
7698 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
7699 command lists}), @value{GDBN} provides two ways to store sequences of commands
7700 for execution as a unit: user-defined commands and command files.
7701
7702 @menu
7703 * Define:: User-defined commands
7704 * Hooks:: User-defined command hooks
7705 * Command Files:: Command files
7706 * Output:: Commands for controlled output
7707 @end menu
7708
7709 @node Define
7710 @section User-defined commands
7711
7712 @cindex user-defined command
7713 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which you
7714 assign a new name as a command. This is done with the @code{define}
7715 command.
7716
7717 @table @code
7718 @item define @var{commandname}
7719 @kindex define
7720 Define a command named @var{commandname}. If there is already a command
7721 by that name, you are asked to confirm that you want to redefine it.
7722
7723 The definition of the command is made up of other @value{GDBN} command lines,
7724 which are given following the @code{define} command. The end of these
7725 commands is marked by a line containing @code{end}.
7726
7727 @item document @var{commandname}
7728 @kindex document
7729 Give documentation to the user-defined command @var{commandname}. The
7730 command @var{commandname} must already be defined. This command reads
7731 lines of documentation just as @code{define} reads the lines of the
7732 command definition, ending with @code{end}. After the @code{document}
7733 command is finished, @code{help} on command @var{commandname} displays
7734 the documentation you have specified.
7735
7736 You may use the @code{document} command again to change the
7737 documentation of a command. Redefining the command with @code{define}
7738 does not change the documentation.
7739
7740 @item help user-defined
7741 @kindex help user-defined
7742 List all user-defined commands, with the first line of the documentation
7743 (if any) for each.
7744
7745 @item show user
7746 @itemx show user @var{commandname}
7747 @kindex show user
7748 Display the @value{GDBN} commands used to define @var{commandname} (but not its
7749 documentation). If no @var{commandname} is given, display the
7750 definitions for all user-defined commands.
7751 @end table
7752
7753 User-defined commands do not take arguments. When they are executed, the
7754 commands of the definition are not printed. An error in any command
7755 stops execution of the user-defined command.
7756
7757 Commands that would ask for confirmation if used interactively proceed
7758 without asking when used inside a user-defined command. Many @value{GDBN} commands
7759 that normally print messages to say what they are doing omit the messages
7760 when used in a user-defined command.
7761
7762 @node Hooks
7763 @section User-defined command hooks
7764 @cindex command files
7765
7766 You may define @emph{hooks}, which are a special kind of user-defined
7767 command. Whenever you run the command @samp{foo}, if the user-defined
7768 command @samp{hook-foo} exists, it is executed (with no arguments)
7769 before that command.
7770
7771 In addition, a pseudo-command, @samp{stop} exists. Defining
7772 (@samp{hook-stop}) makes the associated commands execute every time
7773 execution stops in your program: before breakpoint commands are run,
7774 displays are printed, or the stack frame is printed.
7775
7776 @ifclear BARETARGET
7777 For example, to ignore @code{SIGALRM} signals while
7778 single-stepping, but treat them normally during normal execution,
7779 you could define:
7780
7781 @example
7782 define hook-stop
7783 handle SIGALRM nopass
7784 end
7785
7786 define hook-run
7787 handle SIGALRM pass
7788 end
7789
7790 define hook-continue
7791 handle SIGLARM pass
7792 end
7793 @end example
7794 @end ifclear
7795
7796 You can define a hook for any single-word command in @value{GDBN}, but
7797 not for command aliases; you should define a hook for the basic command
7798 name, e.g. @code{backtrace} rather than @code{bt}.
7799 @c FIXME! So how does Joe User discover whether a command is an alias
7800 @c or not?
7801 If an error occurs during the execution of your hook, execution of
7802 @value{GDBN} commands stops and @value{GDBN} issues a prompt
7803 (before the command that you actually typed had a chance to run).
7804
7805 If you try to define a hook which does not match any known command, you
7806 get a warning from the @code{define} command.
7807
7808 @node Command Files
7809 @section Command files
7810
7811 @cindex command files
7812 A command file for @value{GDBN} is a file of lines that are @value{GDBN} commands. Comments
7813 (lines starting with @kbd{#}) may also be included. An empty line in a
7814 command file does nothing; it does not mean to repeat the last command, as
7815 it would from the terminal.
7816
7817 @cindex init file
7818 @cindex @file{@value{GDBINIT}}
7819 When you start @value{GDBN}, it automatically executes commands from its
7820 @dfn{init files}. These are files named @file{@value{GDBINIT}}.
7821 @value{GDBN} reads the init file (if any) in your home directory, then
7822 processes command line options and operands, and then reads the init
7823 file (if any) in the current working directory. This is so the init
7824 file in your home directory can set options (such as @code{set
7825 complaints}) which affect the processing of the command line options and
7826 operands. The init files are not executed if you use the @samp{-nx}
7827 option; @pxref{Mode Options, ,Choosing modes}.
7828
7829 @ifset GENERIC
7830 @cindex init file name
7831 On some configurations of @value{GDBN}, the init file is known by a
7832 different name (these are typically environments where a specialized
7833 form of GDB may need to coexist with other forms, hence a different name
7834 for the specialized version's init file). These are the environments
7835 with special init file names:
7836
7837 @itemize @bullet
7838 @kindex .vxgdbinit
7839 @item
7840 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
7841
7842 @kindex .os68gdbinit
7843 @item
7844 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
7845
7846 @kindex .esgdbinit
7847 @item
7848 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
7849 @end itemize
7850 @end ifset
7851
7852 You can also request the execution of a command file with the
7853 @code{source} command:
7854
7855 @table @code
7856 @item source @var{filename}
7857 @kindex source
7858 Execute the command file @var{filename}.
7859 @end table
7860
7861 The lines in a command file are executed sequentially. They are not
7862 printed as they are executed. An error in any command terminates execution
7863 of the command file.
7864
7865 Commands that would ask for confirmation if used interactively proceed
7866 without asking when used in a command file. Many @value{GDBN} commands that
7867 normally print messages to say what they are doing omit the messages
7868 when called from command files.
7869
7870 @node Output
7871 @section Commands for controlled output
7872
7873 During the execution of a command file or a user-defined command, normal
7874 @value{GDBN} output is suppressed; the only output that appears is what is
7875 explicitly printed by the commands in the definition. This section
7876 describes three commands useful for generating exactly the output you
7877 want.
7878
7879 @table @code
7880 @item echo @var{text}
7881 @kindex echo
7882 @c I do not consider backslash-space a standard C escape sequence
7883 @c because it is not in ANSI.
7884 Print @var{text}. Nonprinting characters can be included in
7885 @var{text} using C escape sequences, such as @samp{\n} to print a
7886 newline. @strong{No newline is printed unless you specify one.}
7887 In addition to the standard C escape sequences, a backslash followed
7888 by a space stands for a space. This is useful for displaying a
7889 string with spaces at the beginning or the end, since leading and
7890 trailing spaces are otherwise trimmed from all arguments.
7891 To print @samp{@w{ }and foo =@w{ }}, use the command
7892 @samp{echo \@w{ }and foo = \@w{ }}.
7893
7894 A backslash at the end of @var{text} can be used, as in C, to continue
7895 the command onto subsequent lines. For example,
7896
7897 @example
7898 echo This is some text\n\
7899 which is continued\n\
7900 onto several lines.\n
7901 @end example
7902
7903 produces the same output as
7904
7905 @example
7906 echo This is some text\n
7907 echo which is continued\n
7908 echo onto several lines.\n
7909 @end example
7910
7911 @item output @var{expression}
7912 @kindex output
7913 Print the value of @var{expression} and nothing but that value: no
7914 newlines, no @samp{$@var{nn} = }. The value is not entered in the
7915 value history either. @xref{Expressions, ,Expressions}, for more information on
7916 expressions.
7917
7918 @item output/@var{fmt} @var{expression}
7919 Print the value of @var{expression} in format @var{fmt}. You can use
7920 the same formats as for @code{print}. @xref{Output Formats,,Output
7921 formats}, for more information.
7922
7923 @item printf @var{string}, @var{expressions}@dots{}
7924 @kindex printf
7925 Print the values of the @var{expressions} under the control of
7926 @var{string}. The @var{expressions} are separated by commas and may be
7927 either numbers or pointers. Their values are printed as specified by
7928 @var{string}, exactly as if your program were to execute the C
7929 subroutine
7930
7931 @example
7932 printf (@var{string}, @var{expressions}@dots{});
7933 @end example
7934
7935 For example, you can print two values in hex like this:
7936
7937 @smallexample
7938 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
7939 @end smallexample
7940
7941 The only backslash-escape sequences that you can use in the format
7942 string are the simple ones that consist of backslash followed by a
7943 letter.
7944 @end table
7945
7946 @ifclear DOSHOST
7947 @node Emacs
7948 @chapter Using @value{GDBN} under GNU Emacs
7949
7950 @cindex emacs
7951 A special interface allows you to use GNU Emacs to view (and
7952 edit) the source files for the program you are debugging with
7953 @value{GDBN}.
7954
7955 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
7956 executable file you want to debug as an argument. This command starts
7957 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
7958 created Emacs buffer.
7959
7960 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
7961 things:
7962
7963 @itemize @bullet
7964 @item
7965 All ``terminal'' input and output goes through the Emacs buffer.
7966 @end itemize
7967
7968 This applies both to @value{GDBN} commands and their output, and to the input
7969 and output done by the program you are debugging.
7970
7971 This is useful because it means that you can copy the text of previous
7972 commands and input them again; you can even use parts of the output
7973 in this way.
7974
7975 All the facilities of Emacs' Shell mode are available for interacting
7976 with your program. In particular, you can send signals the usual
7977 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
7978 stop.
7979
7980 @itemize @bullet
7981 @item
7982 @value{GDBN} displays source code through Emacs.
7983 @end itemize
7984
7985 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
7986 source file for that frame and puts an arrow (@samp{=>}) at the
7987 left margin of the current line. Emacs uses a separate buffer for
7988 source display, and splits the screen to show both your @value{GDBN} session
7989 and the source.
7990
7991 Explicit @value{GDBN} @code{list} or search commands still produce output as
7992 usual, but you probably have no reason to use them from Emacs.
7993
7994 @quotation
7995 @emph{Warning:} If the directory where your program resides is not your
7996 current directory, it can be easy to confuse Emacs about the location of
7997 the source files, in which case the auxiliary display buffer does not
7998 appear to show your source. @value{GDBN} can find programs by searching your
7999 environment's @code{PATH} variable, so the @value{GDBN} input and output
8000 session proceeds normally; but Emacs does not get enough information
8001 back from @value{GDBN} to locate the source files in this situation. To
8002 avoid this problem, either start @value{GDBN} mode from the directory where
8003 your program resides, or specify an absolute file name when prompted for the
8004 @kbd{M-x gdb} argument.
8005
8006 A similar confusion can result if you use the @value{GDBN} @code{file} command to
8007 switch to debugging a program in some other location, from an existing
8008 @value{GDBN} buffer in Emacs.
8009 @end quotation
8010
8011 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
8012 you need to call @value{GDBN} by a different name (for example, if you keep
8013 several configurations around, with different names) you can set the
8014 Emacs variable @code{gdb-command-name}; for example,
8015
8016 @example
8017 (setq gdb-command-name "mygdb")
8018 @end example
8019
8020 @noindent
8021 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
8022 in your @file{.emacs} file) makes Emacs call the program named
8023 ``@code{mygdb}'' instead.
8024
8025 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
8026 addition to the standard Shell mode commands:
8027
8028 @table @kbd
8029 @item C-h m
8030 Describe the features of Emacs' @value{GDBN} Mode.
8031
8032 @item M-s
8033 Execute to another source line, like the @value{GDBN} @code{step} command; also
8034 update the display window to show the current file and location.
8035
8036 @item M-n
8037 Execute to next source line in this function, skipping all function
8038 calls, like the @value{GDBN} @code{next} command. Then update the display window
8039 to show the current file and location.
8040
8041 @item M-i
8042 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
8043 display window accordingly.
8044
8045 @item M-x gdb-nexti
8046 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
8047 display window accordingly.
8048
8049 @item C-c C-f
8050 Execute until exit from the selected stack frame, like the @value{GDBN}
8051 @code{finish} command.
8052
8053 @item M-c
8054 Continue execution of your program, like the @value{GDBN} @code{continue}
8055 command.
8056
8057 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
8058
8059 @item M-u
8060 Go up the number of frames indicated by the numeric argument
8061 (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
8062 like the @value{GDBN} @code{up} command.
8063
8064 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
8065
8066 @item M-d
8067 Go down the number of frames indicated by the numeric argument, like the
8068 @value{GDBN} @code{down} command.
8069
8070 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
8071
8072 @item C-x &
8073 Read the number where the cursor is positioned, and insert it at the end
8074 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
8075 around an address that was displayed earlier, type @kbd{disassemble};
8076 then move the cursor to the address display, and pick up the
8077 argument for @code{disassemble} by typing @kbd{C-x &}.
8078
8079 You can customize this further by defining elements of the list
8080 @code{gdb-print-command}; once it is defined, you can format or
8081 otherwise process numbers picked up by @kbd{C-x &} before they are
8082 inserted. A numeric argument to @kbd{C-x &} indicates that you
8083 wish special formatting, and also acts as an index to pick an element of the
8084 list. If the list element is a string, the number to be inserted is
8085 formatted using the Emacs function @code{format}; otherwise the number
8086 is passed as an argument to the corresponding list element.
8087 @end table
8088
8089 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
8090 tells @value{GDBN} to set a breakpoint on the source line point is on.
8091
8092 If you accidentally delete the source-display buffer, an easy way to get
8093 it back is to type the command @code{f} in the @value{GDBN} buffer, to
8094 request a frame display; when you run under Emacs, this recreates
8095 the source buffer if necessary to show you the context of the current
8096 frame.
8097
8098 The source files displayed in Emacs are in ordinary Emacs buffers
8099 which are visiting the source files in the usual way. You can edit
8100 the files with these buffers if you wish; but keep in mind that @value{GDBN}
8101 communicates with Emacs in terms of line numbers. If you add or
8102 delete lines from the text, the line numbers that @value{GDBN} knows cease
8103 to correspond properly with the code.
8104
8105 @c The following dropped because Epoch is nonstandard. Reactivate
8106 @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990
8107 @ignore
8108 @kindex emacs epoch environment
8109 @kindex epoch
8110 @kindex inspect
8111
8112 Version 18 of Emacs has a built-in window system called the @code{epoch}
8113 environment. Users of this environment can use a new command,
8114 @code{inspect} which performs identically to @code{print} except that
8115 each value is printed in its own window.
8116 @end ignore
8117 @end ifclear
8118
8119 @ifset LUCID
8120 @node Energize
8121 @chapter Using @value{GDBN} with Energize
8122
8123 @cindex Energize
8124 The Energize Programming System is an integrated development environment
8125 that includes a point-and-click interface to many programming tools.
8126 When you use @value{GDBN} in this environment, you can use the standard
8127 Energize graphical interface to drive @value{GDBN}; you can also, if you
8128 choose, type @value{GDBN} commands as usual in a debugging window. Even if
8129 you use the graphical interface, the debugging window (which uses Emacs,
8130 and resembles the standard Emacs interface to @value{GDBN}) displays the
8131 equivalent commands, so that the history of your debugging session is
8132 properly reflected.
8133
8134 When Energize starts up a @value{GDBN} session, it uses one of the
8135 command-line options @samp{-energize} or @samp{-cadillac} (``cadillac''
8136 is the name of the communications protocol used by the Energize system).
8137 This option makes @value{GDBN} run as one of the tools in the Energize Tool
8138 Set: it sends all output to the Energize kernel, and accept input from
8139 it as well.
8140
8141 See the user manual for the Energize Programming System for
8142 information on how to use the Energize graphical interface and the other
8143 development tools that Energize integrates with @value{GDBN}.
8144
8145 @end ifset
8146
8147 @node GDB Bugs
8148 @chapter Reporting Bugs in @value{GDBN}
8149 @cindex bugs in @value{GDBN}
8150 @cindex reporting bugs in @value{GDBN}
8151
8152 Your bug reports play an essential role in making @value{GDBN} reliable.
8153
8154 Reporting a bug may help you by bringing a solution to your problem, or it
8155 may not. But in any case the principal function of a bug report is to help
8156 the entire community by making the next version of @value{GDBN} work better. Bug
8157 reports are your contribution to the maintenance of @value{GDBN}.
8158
8159 In order for a bug report to serve its purpose, you must include the
8160 information that enables us to fix the bug.
8161
8162 @menu
8163 * Bug Criteria:: Have you found a bug?
8164 * Bug Reporting:: How to report bugs
8165 @end menu
8166
8167 @node Bug Criteria
8168 @section Have you found a bug?
8169 @cindex bug criteria
8170
8171 If you are not sure whether you have found a bug, here are some guidelines:
8172
8173 @itemize @bullet
8174 @item
8175 @cindex fatal signal
8176 @cindex debugger crash
8177 @cindex crash of debugger
8178 If the debugger gets a fatal signal, for any input whatever, that is a
8179 @value{GDBN} bug. Reliable debuggers never crash.
8180
8181 @item
8182 @cindex error on valid input
8183 If @value{GDBN} produces an error message for valid input, that is a bug.
8184
8185 @item
8186 @cindex invalid input
8187 If @value{GDBN} does not produce an error message for invalid input,
8188 that is a bug. However, you should note that your idea of
8189 ``invalid input'' might be our idea of ``an extension'' or ``support
8190 for traditional practice''.
8191
8192 @item
8193 If you are an experienced user of debugging tools, your suggestions
8194 for improvement of @value{GDBN} are welcome in any case.
8195 @end itemize
8196
8197 @node Bug Reporting
8198 @section How to report bugs
8199 @cindex bug reports
8200 @cindex @value{GDBN} bugs, reporting
8201
8202 A number of companies and individuals offer support for GNU products.
8203 If you obtained @value{GDBN} from a support organization, we recommend you
8204 contact that organization first.
8205
8206 You can find contact information for many support companies and
8207 individuals in the file @file{etc/SERVICE} in the GNU Emacs
8208 distribution.
8209
8210 In any event, we also recommend that you send bug reports for @value{GDBN} to one
8211 of these addresses:
8212
8213 @example
8214 bug-gdb@@prep.ai.mit.edu
8215 @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
8216 @end example
8217
8218 @strong{Do not send bug reports to @samp{info-gdb}, or to
8219 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do not want to
8220 receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
8221
8222 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
8223 serves as a repeater. The mailing list and the newsgroup carry exactly
8224 the same messages. Often people think of posting bug reports to the
8225 newsgroup instead of mailing them. This appears to work, but it has one
8226 problem which can be crucial: a newsgroup posting often lacks a mail
8227 path back to the sender. Thus, if we need to ask for more information,
8228 we may be unable to reach you. For this reason, it is better to send
8229 bug reports to the mailing list.
8230
8231 As a last resort, send bug reports on paper to:
8232
8233 @example
8234 GNU Debugger Bugs
8235 Free Software Foundation
8236 545 Tech Square
8237 Cambridge, MA 02139
8238 @end example
8239
8240 The fundamental principle of reporting bugs usefully is this:
8241 @strong{report all the facts}. If you are not sure whether to state a
8242 fact or leave it out, state it!
8243
8244 Often people omit facts because they think they know what causes the
8245 problem and assume that some details do not matter. Thus, you might
8246 assume that the name of the variable you use in an example does not matter.
8247 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
8248 stray memory reference which happens to fetch from the location where that
8249 name is stored in memory; perhaps, if the name were different, the contents
8250 of that location would fool the debugger into doing the right thing despite
8251 the bug. Play it safe and give a specific, complete example. That is the
8252 easiest thing for you to do, and the most helpful.
8253
8254 Keep in mind that the purpose of a bug report is to enable us to fix
8255 the bug if it is new to us. It is not as important as what happens if
8256 the bug is already known. Therefore, always write your bug reports on
8257 the assumption that the bug has not been reported previously.
8258
8259 Sometimes people give a few sketchy facts and ask, ``Does this ring a
8260 bell?'' Those bug reports are useless, and we urge everyone to
8261 @emph{refuse to respond to them} except to chide the sender to report
8262 bugs properly.
8263
8264 To enable us to fix the bug, you should include all these things:
8265
8266 @itemize @bullet
8267 @item
8268 The version of @value{GDBN}. @value{GDBN} announces it if you start with no
8269 arguments; you can also print it at any time using @code{show version}.
8270
8271 Without this, we will not know whether there is any point in looking for
8272 the bug in the current version of @value{GDBN}.
8273
8274 @item
8275 The type of machine you are using, and the operating system name and
8276 version number.
8277
8278 @item
8279 What compiler (and its version) was used to compile @value{GDBN}---e.g.
8280 ``@value{GCC}--2.0''.
8281
8282 @item
8283 What compiler (and its version) was used to compile the program you
8284 are debugging---e.g. ``@value{GCC}--2.0''.
8285
8286 @item
8287 The command arguments you gave the compiler to compile your example and
8288 observe the bug. For example, did you use @samp{-O}? To guarantee
8289 you will not omit something important, list them all. A copy of the
8290 Makefile (or the output from make) is sufficient.
8291
8292 If we were to try to guess the arguments, we would probably guess wrong
8293 and then we might not encounter the bug.
8294
8295 @item
8296 A complete input script, and all necessary source files, that will
8297 reproduce the bug.
8298
8299 @item
8300 A description of what behavior you observe that you believe is
8301 incorrect. For example, ``It gets a fatal signal.''
8302
8303 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we will
8304 certainly notice it. But if the bug is incorrect output, we might not
8305 notice unless it is glaringly wrong. We are human, after all. You
8306 might as well not give us a chance to make a mistake.
8307
8308 Even if the problem you experience is a fatal signal, you should still
8309 say so explicitly. Suppose something strange is going on, such as,
8310 your copy of @value{GDBN} is out of synch, or you have encountered a
8311 bug in the C library on your system. (This has happened!) Your copy
8312 might crash and ours would not. If you told us to expect a crash,
8313 then when ours fails to crash, we would know that the bug was not
8314 happening for us. If you had not told us to expect a crash, then we
8315 would not be able to draw any conclusion from our observations.
8316
8317 @item
8318 If you wish to suggest changes to the @value{GDBN} source, send us context
8319 diffs. If you even discuss something in the @value{GDBN} source, refer to
8320 it by context, not by line number.
8321
8322 The line numbers in our development sources will not match those in your
8323 sources. Your line numbers would convey no useful information to us.
8324 @end itemize
8325
8326 Here are some things that are not necessary:
8327
8328 @itemize @bullet
8329 @item
8330 A description of the envelope of the bug.
8331
8332 Often people who encounter a bug spend a lot of time investigating
8333 which changes to the input file will make the bug go away and which
8334 changes will not affect it.
8335
8336 This is often time consuming and not very useful, because the way we
8337 will find the bug is by running a single example under the debugger
8338 with breakpoints, not by pure deduction from a series of examples.
8339 We recommend that you save your time for something else.
8340
8341 Of course, if you can find a simpler example to report @emph{instead}
8342 of the original one, that is a convenience for us. Errors in the
8343 output will be easier to spot, running under the debugger will take
8344 less time, and so on.
8345
8346 However, simplification is not vital; if you do not want to do this,
8347 report the bug anyway and send us the entire test case you used.
8348
8349 @item
8350 A patch for the bug.
8351
8352 A patch for the bug does help us if it is a good one. But do not omit
8353 the necessary information, such as the test case, on the assumption that
8354 a patch is all we need. We might see problems with your patch and decide
8355 to fix the problem another way, or we might not understand it at all.
8356
8357 Sometimes with a program as complicated as @value{GDBN} it is very hard to
8358 construct an example that will make the program follow a certain path
8359 through the code. If you do not send us the example, we will not be able
8360 to construct one, so we will not be able to verify that the bug is fixed.
8361
8362 And if we cannot understand what bug you are trying to fix, or why your
8363 patch should be an improvement, we will not install it. A test case will
8364 help us to understand.
8365
8366 @item
8367 A guess about what the bug is or what it depends on.
8368
8369 Such guesses are usually wrong. Even we cannot guess right about such
8370 things without first using the debugger to find the facts.
8371 @end itemize
8372
8373 @c The readline documentation is distributed with the readline code
8374 @c and consists of the two following files:
8375 @c rluser.texinfo
8376 @c inc-hist.texi
8377 @c Use -I with makeinfo to point to the appropriate directory,
8378 @c environment var TEXINPUTS with TeX.
8379 @include rluser.texinfo
8380 @include inc-hist.texi
8381
8382 @ifset NOVEL
8383 @node Renamed Commands
8384 @appendix Renamed Commands
8385
8386 The following commands were renamed in GDB 4, in order to make the
8387 command set as a whole more consistent and easier to use and remember:
8388
8389 @kindex add-syms
8390 @kindex delete environment
8391 @kindex info copying
8392 @kindex info convenience
8393 @kindex info directories
8394 @kindex info editing
8395 @kindex info history
8396 @kindex info targets
8397 @kindex info values
8398 @kindex info version
8399 @kindex info warranty
8400 @kindex set addressprint
8401 @kindex set arrayprint
8402 @kindex set prettyprint
8403 @kindex set screen-height
8404 @kindex set screen-width
8405 @kindex set unionprint
8406 @kindex set vtblprint
8407 @kindex set demangle
8408 @kindex set asm-demangle
8409 @kindex set sevenbit-strings
8410 @kindex set array-max
8411 @kindex set caution
8412 @kindex set history write
8413 @kindex show addressprint
8414 @kindex show arrayprint
8415 @kindex show prettyprint
8416 @kindex show screen-height
8417 @kindex show screen-width
8418 @kindex show unionprint
8419 @kindex show vtblprint
8420 @kindex show demangle
8421 @kindex show asm-demangle
8422 @kindex show sevenbit-strings
8423 @kindex show array-max
8424 @kindex show caution
8425 @kindex show history write
8426 @kindex unset
8427
8428 @c TEXI2ROFF-KILL
8429 @ifinfo
8430 @c END TEXI2ROFF-KILL
8431 @example
8432 OLD COMMAND NEW COMMAND
8433 @c TEXI2ROFF-KILL
8434 --------------- -------------------------------
8435 @c END TEXI2ROFF-KILL
8436 add-syms add-symbol-file
8437 delete environment unset environment
8438 info convenience show convenience
8439 info copying show copying
8440 info directories show directories
8441 info editing show commands
8442 info history show values
8443 info targets help target
8444 info values show values
8445 info version show version
8446 info warranty show warranty
8447 set/show addressprint set/show print address
8448 set/show array-max set/show print elements
8449 set/show arrayprint set/show print array
8450 set/show asm-demangle set/show print asm-demangle
8451 set/show caution set/show confirm
8452 set/show demangle set/show print demangle
8453 set/show history write set/show history save
8454 set/show prettyprint set/show print pretty
8455 set/show screen-height set/show height
8456 set/show screen-width set/show width
8457 set/show sevenbit-strings set/show print sevenbit-strings
8458 set/show unionprint set/show print union
8459 set/show vtblprint set/show print vtbl
8460
8461 unset [No longer an alias for delete]
8462 @end example
8463 @c TEXI2ROFF-KILL
8464 @end ifinfo
8465
8466 @tex
8467 \vskip \parskip\vskip \baselineskip
8468 \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
8469 {\bf Old Command} &&{\bf New Command}\cr
8470 add-syms &&add-symbol-file\cr
8471 delete environment &&unset environment\cr
8472 info convenience &&show convenience\cr
8473 info copying &&show copying\cr
8474 info directories &&show directories \cr
8475 info editing &&show commands\cr
8476 info history &&show values\cr
8477 info targets &&help target\cr
8478 info values &&show values\cr
8479 info version &&show version\cr
8480 info warranty &&show warranty\cr
8481 set{\rm / }show addressprint &&set{\rm / }show print address\cr
8482 set{\rm / }show array-max &&set{\rm / }show print elements\cr
8483 set{\rm / }show arrayprint &&set{\rm / }show print array\cr
8484 set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
8485 set{\rm / }show caution &&set{\rm / }show confirm\cr
8486 set{\rm / }show demangle &&set{\rm / }show print demangle\cr
8487 set{\rm / }show history write &&set{\rm / }show history save\cr
8488 set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
8489 set{\rm / }show screen-height &&set{\rm / }show height\cr
8490 set{\rm / }show screen-width &&set{\rm / }show width\cr
8491 set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
8492 set{\rm / }show unionprint &&set{\rm / }show print union\cr
8493 set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
8494 \cr
8495 unset &&\rm(No longer an alias for delete)\cr
8496 }
8497 @end tex
8498 @c END TEXI2ROFF-KILL
8499 @end ifset
8500
8501 @ifclear PRECONFIGURED
8502 @node Formatting Documentation
8503 @appendix Formatting Documentation
8504
8505 @cindex GDB reference card
8506 @cindex reference card
8507 The GDB 4 release includes an already-formatted reference card, ready
8508 for printing with PostScript or Ghostscript, in the @file{gdb}
8509 subdirectory of the main source directory@footnote{In
8510 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
8511 release.}. If you can use PostScript or Ghostscript with your printer,
8512 you can print the reference card immediately with @file{refcard.ps}.
8513
8514 The release also includes the source for the reference card. You
8515 can format it, using @TeX{}, by typing:
8516
8517 @example
8518 make refcard.dvi
8519 @end example
8520
8521 The GDB reference card is designed to print in landscape mode on US
8522 ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches
8523 high. You will need to specify this form of printing as an option to
8524 your @sc{dvi} output program.
8525
8526 @cindex documentation
8527
8528 All the documentation for GDB comes as part of the machine-readable
8529 distribution. The documentation is written in Texinfo format, which is
8530 a documentation system that uses a single source file to produce both
8531 on-line information and a printed manual. You can use one of the Info
8532 formatting commands to create the on-line version of the documentation
8533 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
8534
8535 GDB includes an already formatted copy of the on-line Info version of
8536 this manual in the @file{gdb} subdirectory. The main Info file is
8537 @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to
8538 subordinate files matching @samp{gdb.info*} in the same directory. If
8539 necessary, you can print out these files, or read them with any editor;
8540 but they are easier to read using the @code{info} subsystem in GNU Emacs
8541 or the standalone @code{info} program, available as part of the GNU
8542 Texinfo distribution.
8543
8544 If you want to format these Info files yourself, you need one of the
8545 Info formatting programs, such as @code{texinfo-format-buffer} or
8546 @code{makeinfo}.
8547
8548 If you have @code{makeinfo} installed, and are in the top level GDB
8549 source directory (@file{gdb-@value{GDBVN}}, in the case of version @value{GDBVN}), you can
8550 make the Info file by typing:
8551
8552 @example
8553 cd gdb
8554 make gdb.info
8555 @end example
8556
8557 If you want to typeset and print copies of this manual, you need @TeX{},
8558 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
8559 Texinfo definitions file.
8560
8561 @TeX{} is a typesetting program; it does not print files directly, but
8562 produces output files called @sc{dvi} files. To print a typeset
8563 document, you need a program to print @sc{dvi} files. If your system
8564 has @TeX{} installed, chances are it has such a program. The precise
8565 command to use depends on your system; @kbd{lpr -d} is common; another
8566 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
8567 require a file name without any extension or a @samp{.dvi} extension.
8568
8569 @TeX{} also requires a macro definitions file called
8570 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
8571 written in Texinfo format. On its own, @TeX{} cannot read, much less
8572 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
8573 and is located in the @file{gdb-@var{version-number}/texinfo}
8574 directory.
8575
8576 If you have @TeX{} and a @sc{dvi} printer program installed, you can
8577 typeset and print this manual. First switch to the the @file{gdb}
8578 subdirectory of the main source directory (for example, to
8579 @file{gdb-@value{GDBVN}/gdb}) and then type:
8580
8581 @example
8582 make gdb.dvi
8583 @end example
8584
8585 @node Installing GDB
8586 @appendix Installing GDB
8587 @cindex configuring GDB
8588 @cindex installation
8589
8590 GDB comes with a @code{configure} script that automates the process
8591 of preparing GDB for installation; you can then use @code{make} to
8592 build the @code{gdb} program.
8593 @iftex
8594 @c irrelevant in info file; it's as current as the code it lives with.
8595 @footnote{If you have a more recent version of GDB than @value{GDBVN},
8596 look at the @file{README} file in the sources; we may have improved the
8597 installation procedures since publishing this manual.}
8598 @end iftex
8599
8600 The GDB distribution includes all the source code you need for GDB in
8601 a single directory, whose name is usually composed by appending the
8602 version number to @samp{gdb}.
8603
8604 For example, the GDB version @value{GDBVN} distribution is in the
8605 @file{gdb-@value{GDBVN}} directory. That directory contains:
8606
8607 @table @code
8608 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
8609 script for configuring GDB and all its supporting libraries.
8610
8611 @item gdb-@value{GDBVN}/gdb
8612 the source specific to GDB itself
8613
8614 @item gdb-@value{GDBVN}/bfd
8615 source for the Binary File Descriptor library
8616
8617 @item gdb-@value{GDBVN}/include
8618 GNU include files
8619
8620 @item gdb-@value{GDBVN}/libiberty
8621 source for the @samp{-liberty} free software library
8622
8623 @item gdb-@value{GDBVN}/opcodes
8624 source for the library of opcode tables and disassemblers
8625
8626 @item gdb-@value{GDBVN}/readline
8627 source for the GNU command-line interface
8628
8629 @item gdb-@value{GDBVN}/glob
8630 source for the GNU filename pattern-matching subroutine
8631
8632 @item gdb-@value{GDBVN}/mmalloc
8633 source for the GNU memory-mapped malloc package
8634 @end table
8635
8636 The simplest way to configure and build GDB is to run @code{configure}
8637 from the @file{gdb-@var{version-number}} source directory, which in
8638 this example is the @file{gdb-@value{GDBVN}} directory.
8639
8640 First switch to the @file{gdb-@var{version-number}} source directory
8641 if you are not already in it; then run @code{configure}. Pass the
8642 identifier for the platform on which GDB will run as an
8643 argument.
8644
8645 For example:
8646
8647 @example
8648 cd gdb-@value{GDBVN}
8649 ./configure @var{host}
8650 make
8651 @end example
8652
8653 @noindent
8654 where @var{host} is an identifier such as @samp{sun4} or
8655 @samp{decstation}, that identifies the platform where GDB will run.
8656 (You can often leave off @var{host}; @code{configure} tries to guess the
8657 correct value by examining your system.)
8658
8659 Running @samp{configure @var{host}} and then running @code{make} builds the
8660 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
8661 libraries, then @code{gdb} itself. The configured source files, and the
8662 binaries, are left in the corresponding source directories.
8663
8664 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8665 system does not recognize this automatically when you run a different
8666 shell, you may need to run @code{sh} on it explicitly:
8667
8668 @example
8669 sh configure @var{host}
8670 @end example
8671
8672 If you run @code{configure} from a directory that contains source
8673 directories for multiple libraries or programs, such as the
8674 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
8675 creates configuration files for every directory level underneath (unless
8676 you tell it not to, with the @samp{--norecursion} option).
8677
8678 You can run the @code{configure} script from any of the
8679 subordinate directories in the GDB distribution if you only want to
8680 configure that subdirectory, but be sure to specify a path to it.
8681
8682 For example, with version @value{GDBVN}, type the following to configure only
8683 the @code{bfd} subdirectory:
8684
8685 @example
8686 @group
8687 cd gdb-@value{GDBVN}/bfd
8688 ../configure @var{host}
8689 @end group
8690 @end example
8691
8692 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
8693 However, you should make sure that the shell on your path (named by
8694 the @samp{SHELL} environment variable) is publicly readable. Remember
8695 that GDB uses the shell to start your program---some systems refuse to
8696 let GDB debug child processes whose programs are not readable.
8697
8698 @menu
8699 * Separate Objdir:: Compiling GDB in another directory
8700 * Config Names:: Specifying names for hosts and targets
8701 * configure Options:: Summary of options for configure
8702 @end menu
8703
8704 @node Separate Objdir
8705 @section Compiling GDB in another directory
8706
8707 If you want to run GDB versions for several host or target machines,
8708 you need a different @code{gdb} compiled for each combination of
8709 host and target. @code{configure} is designed to make this easy by
8710 allowing you to generate each configuration in a separate subdirectory,
8711 rather than in the source directory. If your @code{make} program
8712 handles the @samp{VPATH} feature (GNU @code{make} does), running
8713 @code{make} in each of these directories builds the @code{gdb}
8714 program specified there.
8715
8716 To build @code{gdb} in a separate directory, run @code{configure}
8717 with the @samp{--srcdir} option to specify where to find the source.
8718 (You also need to specify a path to find @code{configure}
8719 itself from your working directory. If the path to @code{configure}
8720 would be the same as the argument to @samp{--srcdir}, you can leave out
8721 the @samp{--srcdir} option; it is assumed.)
8722
8723 For example, with version @value{GDBVN}, you can build GDB in a separate
8724 directory for a Sun 4 like this:
8725
8726 @example
8727 @group
8728 cd gdb-@value{GDBVN}
8729 mkdir ../gdb-sun4
8730 cd ../gdb-sun4
8731 ../gdb-@value{GDBVN}/configure sun4
8732 make
8733 @end group
8734 @end example
8735
8736 When @code{configure} builds a configuration using a remote source
8737 directory, it creates a tree for the binaries with the same structure
8738 (and using the same names) as the tree under the source directory. In
8739 the example, you'd find the Sun 4 library @file{libiberty.a} in the
8740 directory @file{gdb-sun4/libiberty}, and GDB itself in
8741 @file{gdb-sun4/gdb}.
8742
8743 One popular reason to build several GDB configurations in separate
8744 directories is to configure GDB for cross-compiling (where GDB
8745 runs on one machine---the host---while debugging programs that run on
8746 another machine---the target). You specify a cross-debugging target by
8747 giving the @samp{--target=@var{target}} option to @code{configure}.
8748
8749 When you run @code{make} to build a program or library, you must run
8750 it in a configured directory---whatever directory you were in when you
8751 called @code{configure} (or one of its subdirectories).
8752
8753 The @code{Makefile} that @code{configure} generates in each source
8754 directory also runs recursively. If you type @code{make} in a source
8755 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
8756 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
8757 will build all the required libraries, and then build GDB.
8758
8759 When you have multiple hosts or targets configured in separate
8760 directories, you can run @code{make} on them in parallel (for example,
8761 if they are NFS-mounted on each of the hosts); they will not interfere
8762 with each other.
8763
8764 @node Config Names
8765 @section Specifying names for hosts and targets
8766
8767 The specifications used for hosts and targets in the @code{configure}
8768 script are based on a three-part naming scheme, but some short predefined
8769 aliases are also supported. The full naming scheme encodes three pieces
8770 of information in the following pattern:
8771
8772 @example
8773 @var{architecture}-@var{vendor}-@var{os}
8774 @end example
8775
8776 For example, you can use the alias @code{sun4} as a @var{host} argument,
8777 or as the value for @var{target} in a @code{--target=@var{target}}
8778 option. The equivalent full name is @samp{sparc-sun-sunos4}.
8779
8780 The @code{configure} script accompanying GDB does not provide
8781 any query facility to list all supported host and target names or
8782 aliases. @code{configure} calls the Bourne shell script
8783 @code{config.sub} to map abbreviations to full names; you can read the
8784 script, if you wish, or you can use it to test your guesses on
8785 abbreviations---for example:
8786
8787 @smallexample
8788 % sh config.sub sun4
8789 sparc-sun-sunos4.1.1
8790 % sh config.sub sun3
8791 m68k-sun-sunos4.1.1
8792 % sh config.sub decstation
8793 mips-dec-ultrix4.2
8794 % sh config.sub hp300bsd
8795 m68k-hp-bsd
8796 % sh config.sub i386v
8797 i386-unknown-sysv
8798 % sh config.sub i786v
8799 Invalid configuration `i786v': machine `i786v' not recognized
8800 @end smallexample
8801
8802 @noindent
8803 @code{config.sub} is also distributed in the GDB source
8804 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
8805
8806 @node configure Options
8807 @section @code{configure} options
8808
8809 Here is a summary of the @code{configure} options and arguments that
8810 are most often useful for building @value{GDBN}. @code{configure} also has
8811 several other options not listed here. @inforef{What Configure
8812 Does,,configure.info}, for a full explanation of @code{configure}.
8813 @c FIXME: Would this be more, or less, useful as an xref (ref to printed
8814 @c manual in the printed manual, ref to info file only from the info file)?
8815
8816 @example
8817 configure @r{[}--help@r{]}
8818 @r{[}--prefix=@var{dir}@r{]}
8819 @r{[}--srcdir=@var{dirname}@r{]}
8820 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
8821 @r{[}--target=@var{target}@r{]} @var{host}
8822 @end example
8823
8824 @noindent
8825 You may introduce options with a single @samp{-} rather than
8826 @samp{--} if you prefer; but you may abbreviate option names if you use
8827 @samp{--}.
8828
8829 @table @code
8830 @item --help
8831 Display a quick summary of how to invoke @code{configure}.
8832
8833 @item -prefix=@var{dir}
8834 Configure the source to install programs and files under directory
8835 @file{@var{dir}}.
8836
8837 @c avoid splitting the warning from the explanation:
8838 @need 2000
8839 @item --srcdir=@var{dirname}
8840 @strong{Warning: using this option requires GNU @code{make}, or another
8841 @code{make} that implements the @code{VPATH} feature.}@*
8842 Use this option to make configurations in directories separate from the
8843 GDB source directories. Among other things, you can use this to
8844 build (or maintain) several configurations simultaneously, in separate
8845 directories. @code{configure} writes configuration specific files in
8846 the current directory, but arranges for them to use the source in the
8847 directory @var{dirname}. @code{configure} creates directories under
8848 the working directory in parallel to the source directories below
8849 @var{dirname}.
8850
8851 @item --norecursion
8852 Configure only the directory level where @code{configure} is executed; do not
8853 propagate configuration to subdirectories.
8854
8855 @item --rm
8856 @emph{Remove} files otherwise built during configuration.
8857
8858 @c This does not work (yet if ever). FIXME.
8859 @c @item --parse=@var{lang} @dots{}
8860 @c Configure the GDB expression parser to parse the listed languages.
8861 @c @samp{all} configures GDB for all supported languages. To get a
8862 @c list of all supported languages, omit the argument. Without this
8863 @c option, GDB is configured to parse all supported languages.
8864
8865 @item --target=@var{target}
8866 Configure GDB for cross-debugging programs running on the specified
8867 @var{target}. Without this option, GDB is configured to debug
8868 programs that run on the same machine (@var{host}) as GDB itself.
8869
8870 There is no convenient way to generate a list of all available targets.
8871
8872 @item @var{host} @dots{}
8873 Configure GDB to run on the specified @var{host}.
8874
8875 There is no convenient way to generate a list of all available hosts.
8876 @end table
8877
8878 @noindent
8879 @code{configure} accepts other options, for compatibility with
8880 configuring other GNU tools recursively; but these are the only
8881 options that affect GDB or its supporting libraries.
8882 @end ifclear
8883
8884 @node Index
8885 @unnumbered Index
8886
8887 @printindex cp
8888
8889 @tex
8890 % I think something like @colophon should be in texinfo. In the
8891 % meantime:
8892 \long\def\colophon{\hbox to0pt{}\vfill
8893 \centerline{The body of this manual is set in}
8894 \centerline{\fontname\tenrm,}
8895 \centerline{with headings in {\bf\fontname\tenbf}}
8896 \centerline{and examples in {\tt\fontname\tentt}.}
8897 \centerline{{\it\fontname\tenit\/},}
8898 \centerline{{\bf\fontname\tenbf}, and}
8899 \centerline{{\sl\fontname\tensl\/}}
8900 \centerline{are used for emphasis.}\vfill}
8901 \page\colophon
8902 % Blame: pesch@cygnus.com, 1991.
8903 @end tex
8904
8905 @contents
8906 @bye