a0ef49f9dfd78677aa1bf21d2cafca51833f8f0f
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo
2 @setfilename _GDBP__.info
3 @c $Id$
4 @c
5 @c NOTE: this manual is marked up for preprocessing with a collection
6 @c of m4 macros called "pretex.m4". If you see <_if__> and <_fi__>
7 @c scattered around the source, you have the full source before
8 @c preprocessing; if you don't, you have the source configured for
9 @c _HOST__ architectures (and you can of course get the full source,
10 @c with all configurations, from wherever you got this).
11 _if__(0)
12
13 THIS IS THE FULL SOURCE. The full source needs to be run through m4
14 before either tex- or info- formatting: for example,
15 _0__
16 m4 pretex.m4 none.m4 m680x0.m4 gdb.texinfo >gdb-680x0.texinfo
17 _1__
18 will produce (assuming your path finds either GNU or SysV m4; Berkeley
19 won't do) a file suitable for formatting. See the text in "pretex.m4"
20 for a fuller explanation (and the macro definitions).
21 To permit maximum flexibility, the full source also does not contain
22 any "info" markup that can be generated automatically; you should first
23 preprocess it as above, then run it through C-u texinfo-master-menu,
24 before actually info-formatting it.
25 _fi__(0)
26 @c
27 @syncodeindex ky cp
28 @c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN:
29 @c Tue Feb 26 01:47:07 1991 Cygnus John Gilmore (cygnus at yuba)
30 @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
31 @ifinfo
32 This file documents the GNU debugger _GDBN__.
33
34 Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
35
36 Permission is granted to make and distribute verbatim copies of
37 this manual provided the copyright notice and this permission notice
38 are preserved on all copies.
39
40 @ignore
41 Permission is granted to process this file through Tex and print the
42 results, provided the printed document carries copying permission
43 notice identical to this one except for the removal of this paragraph
44 (this paragraph not being relevant to the printed manual).
45
46 @end ignore
47 Permission is granted to copy and distribute modified versions of this
48 manual under the conditions for verbatim copying, provided also that the
49 section entitled ``GNU General Public License'' is included exactly as
50 in the original, and provided that the entire resulting derived work is
51 distributed under the terms of a permission notice identical to this
52 one.
53
54 Permission is granted to copy and distribute translations of this manual
55 into another language, under the above conditions for modified versions,
56 except that the section entitled ``GNU General Public License'' may be
57 included in a translation approved by the author instead of in the
58 original English.
59 @end ifinfo
60 @smallbook
61 @setchapternewpage odd
62 _if__(_GENERIC__)
63 @settitle Using _GDBN__ (v4.0)
64 _fi__(_GENERIC__)
65 _if__(!_GENERIC__)
66 @settitle Using _GDBN__ v4.0 (_HOST__)
67 _fi__(!_GENERIC__)
68 @iftex
69 @c @finalout
70 @end iftex
71 @titlepage
72 @title{Using _GDBN__}
73 @subtitle{A Guide to the GNU Source-Level Debugger}
74 _if__(!_GENERIC__)
75 @subtitle{On _HOST__ Systems}
76 _fi__(!_GENERIC__)
77 @sp 1
78 @c Maybe crank this up to "Fourth Edition" when released at FSF
79 @c @subtitle Third Edition---_GDBN__ version 4.0
80 @subtitle _GDBN__ version 4.0
81 @subtitle May 1991
82 @author{Richard M. Stallman @hfill Free Software Foundation}
83 @author{Roland H. Pesch @hfill Cygnus Support}
84 @page
85
86 @tex
87 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
88 \xdef\manvers{\$Revision$} % For use in headers, footers too
89 {\parskip=0pt
90 \hfill Cygnus Support\par
91 \hfill {\it Using _GDBN__}, \manvers\par
92 \hfill \TeX{}info \texinfoversion\par
93 }
94 @end tex
95
96 @vskip 0pt plus 1filll
97 Copyright @copyright{} 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
98
99 Permission is granted to make and distribute verbatim copies of
100 this manual provided the copyright notice and this permission notice
101 are preserved on all copies.
102
103 Permission is granted to copy and distribute modified versions of this
104 manual under the conditions for verbatim copying, provided also that the
105 section entitled ``GNU General Public License'' is included exactly as
106 in the original, and provided that the entire resulting derived work is
107 distributed under the terms of a permission notice identical to this
108 one.
109
110 Permission is granted to copy and distribute translations of this manual
111 into another language, under the above conditions for modified versions,
112 except that the section entitled ``GNU General Public License'' may be
113 included in a translation approved by the author instead of in the
114 original English.
115 @end titlepage
116 @page
117
118 @node Top,,,
119 @unnumbered Summary of _GDBN__
120
121 The purpose of a debugger such as _GDBN__ is to allow you to see what is
122 going on ``inside'' another program while it executes---or what another
123 program was doing at the moment it crashed.
124
125 _GDBN__ can do four main kinds of things (plus other things in support of
126 these) to help you catch bugs in the act:
127
128 @enumerate
129 @item
130 Start your program, specifying anything that might affect its behavior.
131
132 @item
133 Make your program stop on specified conditions.
134
135 @item
136 Examine what has happened, when your program has stopped.
137
138 @item
139 Change things in your program, so you can experiment with correcting the
140 effects of one bug and go on to learn about another.
141 @end enumerate
142
143 _GDBN__ can be used to debug programs written in C and C++. Pascal support
144 is being implemented, and Fortran support will be added when a GNU
145 Fortran compiler is ready.
146
147 @unnumberedsec Free Software
148 _GDBN__ is Free Software, protected by the GNU General Public License (GPL).
149 The GPL gives you the freedom to copy or adapt a licensed
150 program---but every person getting a copy also gets with it the
151 freedom to modify that copy (which means that they must get access to
152 the source code), and the freedom to distribute further copies.
153 Typical software companies use copyrights to limit your freedoms; the
154 Free Software Foundation uses the GPL to preserve these freedoms.
155
156 Fundamentally, the General Public License is a license which says that
157 you have these freedoms and that you can't take these freedoms away
158 from anyone else.
159
160 For full details, @pxref{License}.
161
162 @node New Features,,,
163 @unnumbered New Features in _GDBN__ version 4.0
164
165 @itemize @bullet
166 @item
167 TARGETS: Using the new command @samp{target}, you can select at runtime
168 whether you are debugging local files, local processes, standalone
169 systems over the serial port, realtime systems over a TCP/IP
170 connection, etc. _GDBN__ now uses a function vector to mediate access to
171 all the different possible targets, making it much easier to add
172 support for new remote protocols.
173
174 @item
175 WATCHPOINTS: _GDBN__ now sports watchpoints as well as breakpoints. You can
176 use a watchpoint to stop execution whenever the value of an expression
177 changes, without having to predict a particular place in the inferior
178 process where this may happen.
179
180 @item
181 OBJECT CODE FORMATS: _GDBN__ uses a new scheme called Binary File
182 Descriptors (BFD) to permit it to switch dynamically, without
183 reconfiguration or recompilation, between different object-file
184 formats. Formats currently supported are COFF, a.out, and the new
185 Intel 960 b.out; files may be read as .o's, archive libraries, or core
186 dumps. BFD is available as a subroutine library so that other
187 programs may take advantage of it, and the other GNU binary utilities
188 are being converted to use it.
189
190 @item
191 CONFIGURATION: You must still choose a particular machine architecture
192 and operating system for _GDBN__'s host and target systems when _GDBN__ is built.
193 The script @samp{config.gdb} now handles specification of separate host
194 and target configurations.
195
196 @item
197 INTERACTION: _GDBN__ now uses the GNU readline interface to read its
198 input; this provides inline editing of commands, using the familiar
199 Emacs or @code{vi} keymaps, and command-history support. The user interface
200 to _GDBN__'s control variables has been simplified and consolidated in two
201 commands, @samp{set} and @samp{show}. Output lines are now broken at
202 readable places, rather than overflowing onto the next line.
203
204 @item
205 SOURCE LANGUAGE: _GDBN__ now understands C++ source as well as C. Multiple
206 inheritance is supported when used with G++ 2.0. There is also limited
207 support for C++ exception handling: _GDBN__ can break when an exception is
208 raised, before the stack is peeled back to the exception handler's
209 context. You can suppress output of machine-level addresses,
210 displaying only source language information.
211
212 @item
213 PORTS: _GDBN__ has been ported to the following new architectures:
214 AT&T 3b1, Acorn RISC machine, HP300 running HPUX, big- and little-
215 endian MIPS machines, Motorola 88k, Sun 386i, and Sun 3 running SunOS
216 4. In addition, the following are supported as targets only: AMD
217 29k, Intel 960, and Wind River's VxWorks.
218
219 @item
220 SHARED LIBRARIES: _GDBN__ 4.0 supports SunOS shared libraries.
221
222 @item
223 WORK IN PROGRESS: kernel debugging for BSD and Mach systems; Tahoe and
224 HPPA architecture support.
225
226 @end itemize
227
228 @node Sample Session,,,
229 @chapter A Sample _GDBN__ Session
230
231 You can use this manual at your leisure to read all about _GDBN__.
232 However, a handful of commands are enough to get started using the
233 debugger. This chapter illustrates these commands.
234
235 In this sample session, we emphasize user input like this: @var{input},
236 to make it easier to pick out from the surrounding output.
237
238 @c FIXME: this example may not be appropriate for some configs, where
239 @c FIXME...primary interest is in remote use.
240 We'll be using _GDBN__ to inspect GNU @code{m4} (a generic macro
241 processor).
242
243 _0__@smallexample
244 $ @var{cd gm4/common}
245
246 $ @var{_GDBP__ m4}
247 Reading symbol data from m4...done.
248 (_GDBP__) set width 70
249 @end smallexample
250
251 @noindent
252 _GDBN__ only reads enough symbol data to know where to find the rest
253 when needed; as a result, the first prompt comes up very quickly. We
254 immediately told _GDBN__ to use a narrower display width than usual, so
255 that examples will fit in this manual.
256
257 @smallexample
258 (_GDBP__) @var{break m4_changequote}
259 Breakpoint 1 at 0x59d4: file builtin.c, line 812.
260 @end smallexample
261
262 @noindent
263 We've chosen to see how the @code{m4} builtin @samp{changequote} works.
264 Having looked at the source, we knew the relevant subroutine is
265 @samp{m4_changequote}. We've set a breakpoint there with _GDBN__'s
266 @code{break} command.
267
268 @smallexample
269 (_GDBP__) @var{run}
270 Starting program: /s1/gnu/src/gm4/common/m4
271 @var{`usual' quotes <not these>}
272 usual quotes <not these>
273 @end smallexample
274
275 @noindent
276 Using the @samp{run} command, we've started @code{m4} running under
277 _GDBN__ control; while we don't touch the @samp{m4_changequote}
278 subroutine, the program runs as usual---it filters standard input.
279
280 @smallexample
281 @var{changequote(<,>)}
282
283 Breakpoint 1, m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
284 812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
285 @end smallexample
286 @noindent
287 To trigger the breakpoint, we called @code{changequote}. _GDBN__
288 suspended execution of @code{m4}, displaying information about the
289 context where it stopped.
290
291 @group
292 @smallexample
293 (_GDBP__) @var{s}
294 bad_argc (name=0xf851cfb4<Address 0xf851cfb4 out of bounds>, argc=3,
295 min=1, max=3) at builtin.c:230
296 230 if (min > 0 && argc < min) @{
297 @end smallexample
298 @noindent
299 We've used the command @samp{s} (@code{step}) to advance execution to
300 the next source line; since there was a subroutine call, we've stopped
301 in the first line of that subroutine, not in the next line of
302 @code{m4_changequote}.
303 @end group
304
305 The command @samp{next} would have taken us to the next line of
306 @code{m4_changequote}. To see where we are in the stack, we can use the
307 @samp{backtrace} command (which can also be spelled @samp{bt}).
308
309 @smallexample
310 (_GDBP__) @var{bt}
311 #0 bad_argc (name=0xf851cfb4<Address 0xf851cfb4 out of bounds>,
312 argc=3, min=1, max=3) at builtin.c:230
313 #1 0x59ec in m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
314 #2 0x6e38 in expand_macro (sym=0x2b060) at macro.c:242
315 #3 0x6840 in expand_token (obs=0x0, t=176224, td=0xf7fffb08)
316 at macro.c:71
317 #4 0x6794 in expand_input () at macro.c:40
318 #5 0x28dc in main (argc=0, argv=0xf7fffbf8) at m4.c:174
319 @end smallexample
320
321 @noindent
322 We'll tell _GDBN__ to finish execution of this subroutine, to get back
323 to @code{m4_changequote}.
324
325 @smallexample
326 (_GDBP__) @var{finish}
327 Run till exit from #0 bad_argc (name=0xf851cfb4<Address 0xf851cfb4 out
328 of bounds>,
329 argc=3, min=1, max=3) at builtin.c:230
330 0x59ec in m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
331 812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
332 Value returned is $1 = false
333 @end smallexample
334
335 @noindent
336 We're still in the middle of the first line of @code{m4_changequote};
337 @samp{finish} just allowed the subroutine call to complete.
338 The display beginning ``@code{0x59ec in}@dots{}'', preceding the
339 display of line @code{812}, is a reminder of that situation from
340 _GDBN__.
341
342 Now that we're past the subroutine call, using the @code{step} command
343 again will get us to the next line of @code{m4_changequote}.
344
345 @smallexample
346 (_GDBP__) @var{s}
347 815 lquote = (argc >= 2) ? TOKEN_DATA_TEXT(argv[1])[0] : DEF_LQUOTE;
348 (_GDBP__) @var{whatis lquote}
349 type = char
350 (_GDBP__) @var{p lquote}
351 $2 = 96 '`'
352 @end smallexample
353
354 @noindent
355 When we stepped to another line, @code{m4} was about to set a variable
356 @samp{lquote}; we inspected its type with @samp{whatis} and its value
357 with @samp{p} (the @samp{print} command). We can see some context by
358 displaying the surrounding source code, with the @samp{l} (@code{list})
359 command.
360
361 @smallexample
362 (_GDBP__) @var{l}
363 810 token_data **argv;
364 811 @{
365 812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
366 813 return;
367 814
368 815 lquote = (argc >= 2) ? TOKEN_DATA_TEXT(argv[1])[0] : DEF_LQUOTE;
369 816 rquote = (argc >= 3) ? TOKEN_DATA_TEXT(argv[2])[0] : DEF_RQUOTE;
370 817 @}
371 818
372 819 /*
373 (_GDBP__) @var{s}
374 816 rquote = (argc >= 3) ? TOKEN_DATA_TEXT(argv[2])[0] : DEF_RQUOTE;
375 (_GDBP__) @var{s}
376 817 @}
377 (_GDBP__) @var{p lquote}
378 $3 = 60 '<'
379 (_GDBP__) @var{p rquote}
380 $4 = 62 '>'
381 @end smallexample
382
383 @noindent
384 We proceeded past another line with @samp{s}, and inspected the new
385 values of @code{m4}'s internal variables @code{rquote} and
386 @code{lquote}.
387
388 Since we're done with our inspection of this subroutine, we'll tell
389 _GDBN__ to allow @code{m4} to continue running, with the @samp{c}
390 (@code{continue}) command:
391
392 @smallexample
393 (_GDBP__) @var{c}
394 Continuing.
395
396 @var{`usual' quotes <not these>}
397 `usual' quotes not these
398
399 Program exited normally.
400 (_GDBP__) @var{quit}
401
402 $
403 _1__@end smallexample
404
405 @noindent
406 Finally, when we ended the @code{m4} run, _GDBN__ told us
407 ``@code{Program exited normally.}'' We ended our _GDBN__ session with
408 the _GDBN__ @samp{quit} command.
409
410
411 @node Invocation,,,
412 @chapter Getting In and Out of _GDBN__
413
414 @node Starting _GDBN__,,,
415 @section Starting _GDBN__
416
417 _GDBN__ is invoked with the shell command @samp{_GDBP__}. Once started,
418 it reads commands from the terminal until you tell it to exit.
419
420 You can start by just calling @samp{_GDBP__} with no arguments or
421 options; but the most usual way to start _GDBN__ is with one argument or
422 two, specifying an executable program as the argument:
423 @example
424 _GDBP__ program
425 @end example
426 @noindent
427 You can also start with both an executable program and a core file specified:
428 @example
429 _GDBP__ program core
430 @end example
431
432 You can further control how _GDBN__ starts up by using command-line
433 options.
434
435 _GDBN__ itself can remind you of the options available:
436 @example
437 gdb -help
438 @end example
439 @noindent
440 will display all available options and briefly describe their use
441 (@samp{gdb -h} is a shorter equivalent).
442
443 All options and command line arguments you give are processed
444 in sequential order. The order makes a difference when the
445 @samp{-x} option is used.
446
447 @node File Options,,,
448 @subsection Choosing Files
449
450 As shown above, any arguments other than options specify an executable
451 file and core file; that is, the first argument encountered with no
452 associated option flag is equivalent to a @samp{-se} option, and the
453 second, if any, is equivalent to a @samp{-c} option. Many options have
454 both long and short forms; both are shown here.
455
456 @table @code
457 @item -symbols @var{file}
458 @itemx -s @var{file}
459 Read symbol table from file @var{file}.
460
461 @item -exec @var{file}
462 @itemx -e @var{file}
463 Use file @var{file} as the executable file to execute when
464 appropriate, and for examining pure data in conjunction with a core
465 dump.
466
467 @item -se @var{file}
468 Read symbol table from file @var{file} and use it as the executable
469 file.
470
471 @item -core @var{file}
472 @itemx -c @var{file}
473 Use file @var{file} as a core dump to examine.
474
475 @item -command @var{file}
476 @itemx -x @var{file}
477 Execute _GDBN__ commands from file @var{file}. @xref{Command Files}.
478
479 @item -directory @var{directory}
480 @itemx -d @var{directory}
481 Add @var{directory} to the path to search for source files.
482 @end table
483
484 @node Mode Options,,,
485 @subsection Choosing Modes
486
487 @table @code
488 @item -nx
489 @itemx -n
490 Do not execute commands from any @file{_GDBINIT__} initialization files.
491 Normally, the commands in these files are executed after all the
492 command options and arguments have been processed. @xref{Command
493 Files}.
494
495 @item -quiet
496 @itemx -q
497 ``Quiet''. Do not print the introductory and copyright messages. These
498 messages are also suppressed in batch mode, or if an executable file name is
499 specified on the _GDBN__ command line.
500
501 @item -batch
502 Run in batch mode. Exit with code @code{0} after processing all the command
503 files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited).
504 Exit with nonzero status if an error occurs in executing the _GDBN__
505 commands in the command files.
506
507 Batch mode may be useful for running _GDBN__ as a filter, for example to
508 download and run a program on another computer; in order to make this
509 more useful, the message
510 @example
511 Program exited normally.
512 @end example
513 @noindent
514 (which is ordinarily issued whenever a program running under _GDBN__ control
515 terminates) is not issued when running in batch mode.
516
517 @item -cd @var{directory}
518 Run _GDBN__ using @var{directory} as its working directory,
519 instead of the current directory.
520
521 @item -fullname
522 @itemx -f
523 This option is used when Emacs runs _GDBN__ as a subprocess. It tells _GDBN__
524 to output the full file name and line number in a standard,
525 recognizable fashion each time a stack frame is displayed (which
526 includes each time the program stops). This recognizable format looks
527 like two @samp{\032} characters, followed by the file name, line number
528 and character position separated by colons, and a newline. The
529 Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as
530 a signal to display the source code for the frame.
531
532 @item -b @var{bps}
533 Set the line speed (baud rate or bps) of any serial interface used by
534 _GDBN__ for remote debugging.
535
536 @item -tty @var{device}
537 Run using @code{device} for your program's standard input and output.
538 @end table
539
540 _if__(_I960__)
541 @node i960-Nindy Remote,,,
542 @subsection _GDBN__ with a Remote i960 (Nindy)
543
544 ``Nindy'' is the name of a ROM Monitor program for Intel 960 target
545 systems. When _GDBN__ is configured to control a remote Intel 960 using
546 Nindy, you can tell _GDBN__ how to connect to the 960 in several ways:
547
548 @itemize @bullet
549 @item
550 Through command line options specifying device, baud rate, and protocol;
551
552 @item
553 By responding to a prompt on startup;
554
555 @item
556 By using the @samp{target} command at any point during your _GDBN__ session.
557 @end itemize
558
559 @node Nindy Startup,,,
560 @subsubsection Startup with Nindy
561
562 The command-line options for Nindy are detailed below. If you simply
563 start @code{_GDBP__} without using options to specify a serial port, you are
564 prompted for it, @emph{before} you reach the ordinary _GDBN__ prompt:
565 @example
566 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
567 @end example
568 @noindent
569 You can, if you choose, simply start up with no Nindy connection by
570 responding to the prompt with an empty line. If you do this, and later
571 wish to attach to Nindy, use @samp{target} (@pxref{Target Commands}).
572
573 @node Nindy Options,,,
574 @subsubsection Options for Nindy
575
576 These are the startup options for beginning your _GDBN__ session with a
577 Nindy-960 board attached:
578
579 @table @code
580 @item -r @var{port}
581 Specify the serial port name of a serial interface to be used to connect
582 to the target system. This option is only available when _GDBN__ is
583 configured for the Intel 960 target architecture. You may specify
584 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
585 device name in @samp{/dev} (e.g. @samp{-r ttya}), or simply the unique
586 suffix for a specific @code{tty} (e.g. @samp{-r a}).
587
588 @item -O
589 (An uppercase letter ``O'', not a zero.) Specify that _GDBN__ should use
590 the ``old'' Nindy monitor protocol to connect to the target system.
591 This option is only available when _GDBN__ is configured for the Intel 960
592 target architecture.
593
594 @quotation
595 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
596 connect to a target system that expects the newer protocol, the connection
597 will fail, appearing to be a speed mismatch. _GDBN__ will repeatedly
598 attempt to reconnect at several different line speeds. You can abort
599 this process with an interrupt.
600 @end quotation
601
602 @item -brk
603 Specify that _GDBN__ should first send a @samp{BREAK} signal to the target
604 system, in an attempt to reset it, before connecting to a Nindy target.
605
606 @quotation
607 @emph{Warning:} Many target systems do not have the hardware that this
608 requires; it only works with a few boards.
609 @end quotation
610
611 @end table
612
613 The standard @samp{-b} option controls the line speed used on the serial
614 port.
615
616 @group
617 @node Nindy reset,,,
618 @subsubsection Nindy Reset Command
619 @table @code
620 @item reset
621 @kindex reset
622 For a Nindy target, this command sends a ``break'' to the remote target
623 system; this is only useful if the target has been equipped with a
624 circuit to perform a hard reset (or some other interesting action) when
625 a break is detected.
626 @end table
627 @end group
628 _fi__(_I960__)
629
630 _if__(_AMD29K__)
631 @node EB29K Remote,,,
632 @subsection _GDBN__ with a Remote EB29K
633
634 @cindex EB29K board
635 @cindex running 29K programs
636 @cindex 29K
637
638 To use _GDBN__ from a Unix system to run programs on AMD's EB29K
639 board in a PC, you must first connect a serial cable between the PC
640 and a serial port on the Unix system. In the following, we assume
641 you've hooked the cable between the PC's @samp{COM1} port and
642 @samp{/dev/ttya} on the Unix system.
643
644 @node Comms (EB29K),,,
645 @subsubsection Communications Setup
646 The next step is to set up the PC's port, by doing something like the
647 following in DOS on the PC:
648 _0__@example
649 C:\> MODE com1:9600,n,8,1,none
650 _1__@end example
651 @noindent
652 This example---run on an MS DOS 4.0 system---sets the PC port to 9600
653 bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
654 you must match the communications parameters when establishing the Unix
655 end of the connection as well.
656 @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
657 @c mean? It's optional; leave it out? ---pesch@cygnus.com, 25feb91
658
659 To give control of the PC to the Unix side of the serial line, type
660 the following at the DOS console:
661 _0__@example
662 C:\> CTTY com1
663 _1__@end example
664 @noindent
665 (Later, if you wish to return control to the DOS console, you can use
666 the command @samp{CTTY con}---but you must send it over the device that
667 had control, in our example over the @samp{COM1} serial line).
668
669 From the Unix host, use a communications program such as @code{tip} or
670 @code{cu} to communicate with the PC; for example,
671 @example
672 cu -s 9600 -l /dev/ttya
673 @end example
674 @noindent
675 The @code{cu} options shown specify, respectively, the linespeed and the
676 serial port to use. If you use @code{tip} instead, your command line
677 may look something like the following instead:
678 @example
679 tip -9600 /dev/ttya
680 @end example
681 @noindent
682 Your system may define a different name where our example uses
683 @samp{/dev/ttya} as the argument to @code{tip}. The communications
684 parameters, including what port to use, are associated with the
685 @code{tip} argument in the ``remote'' descriptions file---normally the
686 system table @file{/etc/remote}.
687 @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
688 @c the DOS side's comms setup? cu can support -o (odd
689 @c parity), -e (even parity)---apparently no settings for no parity or
690 @c for character size. Taken from stty maybe...? John points out tip
691 @c can set these as internal variables, eg ~s parity=none; man stty
692 @c suggests that it *might* work to stty these options with stdin or
693 @c stdout redirected... ---pesch@cygnus.com, 25feb91
694
695 @kindex EBMON
696 Using the @samp{tip} or @samp{cu} connection, change the DOS working
697 directory to the directory containing a copy of your 29K program, then
698 start the PC program @samp{EBMON} (an EB29K control program supplied
699 with your board by AMD). You should see an initial display from
700 @code{EBMON} similar to the one that follows, ending with the
701 @code{EBMON} prompt @samp{#}---
702 _0__@example
703 C:\> G:
704
705 G:\> CD \usr\joe\work29k
706
707 G:\USR\JOE\WORK29K> EBMON
708 Am29000 PC Coprocessor Board Monitor, version 3.0-18
709 Copyright 1990 Advanced Micro Devices, Inc.
710 Written by Gibbons and Associates, Inc.
711
712 Enter '?' or 'H' for help
713
714 PC Coprocessor Type = EB29K
715 I/O Base = 0x208
716 Memory Base = 0xd0000
717
718 Data Memory Size = 2048KB
719 Available I-RAM Range = 0x8000 to 0x1fffff
720 Available D-RAM Range = 0x80002000 to 0x801fffff
721
722 PageSize = 0x400
723 Register Stack Size = 0x800
724 Memory Stack Size = 0x1800
725
726 CPU PRL = 0x3
727 Am29027 Available = No
728 Byte Write Available = Yes
729
730 # ~.
731 _1__@end example
732
733 Then exit the @code{cu} or @code{tip} program (done in the example by
734 typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} will keep
735 running, ready for _GDBN__ to take over.
736
737 For this example, we've assumed what is probably the most convenient
738 way to make sure the same 29K program is on both the PC and the Unix
739 system: a PC/NFS connection that establishes ``drive @code{G:}'' on the
740 PC as a file system on the Unix host. If you don't have PC/NFS or
741 something similar connecting the two systems, you must arrange some
742 other way---perhaps floppy-disk transfer---of getting the 29K program
743 from the Unix system to the PC; _GDBN__ will @emph{not} download it over the
744 serial line.
745
746 @node _GDBP__-EB29K,,,
747 @subsubsection EB29K cross-debugging
748 Finally, @code{cd} to the directory containing an image of your 29K
749 program on the Unix system, and start _GDBN__---specifying as argument the
750 name of your 29K program:
751 @example
752 cd /usr/joe/work29k
753 _GDBP__ myfoo
754 @end example
755 Now you can use the @code{target} command:
756 @example
757 target amd-eb /dev/ttya 9600 MYFOO
758 @end example
759 @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
760 @c emphasize that this is the name as seen by DOS (since I think DOS is
761 @c single-minded about case of letters). ---pesch@cygnus.com, 25feb91
762
763 @noindent
764 In this example, we've assumed your program is in a file called
765 @samp{myfoo}. Note that the filename given as the last argument to
766 @samp{target amd-eb} should be the name of the program as it appears to DOS.
767 In our example this is simply @samp{MYFOO}, but in general it can include
768 a DOS path, and depending on your transfer mechanism may not resemble
769 the name on the Unix side.
770
771 At this point, you can set any breakpoints you wish; when you're ready
772 to see your program run on the 29K board, use the _GDBN__ command
773 @example
774 run
775 @end example
776
777 To stop debugging the remote program, use the _GDBN__ @samp{detach}
778 command.
779
780 To return control of the PC to its console, use @code{tip} or @code{cu}
781 once again, after your _GDBN__ session has concluded, to attach to
782 @code{EBMON}. You can then type the command @samp{q} to shut down
783 @code{EBMON}, returning control to the DOS command-line interpreter.
784 Type @samp{CTTY con} to return command input to the main DOS console,
785 and type @samp{~.} to leave @code{tip} or @code{cu}.
786
787 @node Remote Log,,,
788 @subsubsection Remote Log
789 @kindex eb.log
790 @cindex log file for EB29K
791 The @samp{target amd-eb} command creates a file @file{eb.log} in the
792 current working directory, to help debug problems with the connection.
793 @file{eb.log} records all the output from @code{EBMON}, including echoes
794 of the commands sent to it. Running @samp{tail -f} on this file in
795 another window often helps to understand trouble with @code{EBMON}, or
796 unexpected events on the PC side of the connection.
797 _fi__(_AMD29K__)
798
799 _if__(_VXWORKS__)
800 @node VxWorks Remote,,,
801 @subsection _GDBN__ and VxWorks
802 _GDBN__ enables developers to spawn and debug tasks running on networked
803 VxWorks targets from a Unix host. Already-running tasks spawned from
804 the VxWorks shell can also be debugged. _GDBN__ uses code that runs on
805 both the UNIX host and on the VxWorks target. The program
806 @code{_GDBP__} is installed and executed on the UNIX host.
807
808 The remote debugging interface (RDB) routines are installed and executed
809 on the VxWorks target. These routines are included in the VxWorks library
810 @code{rdb.a} and are incorporated into the system image when source-level
811 debugging is enabled in the VxWorks configuration.
812
813 Defining @code{INCLUDE_RDB} in the VxWorks configuration file
814 @code{configAll.h} includes the RDB interface routines and spawns the
815 source debugging task @code{tRdbTask} when VxWorks is booted. For more
816 information on configuring and remaking VxWorks, see the @cite{VxWorks
817 Programmer's Guide}.
818
819 Once you have included the RDB interface in your VxWorks system image
820 and set your Unix execution search path to find _GDBN__, you are ready
821 to run _GDBN__. From your UNIX host, type:
822
823 @smallexample
824 % _GDBP__
825 @end smallexample
826
827 _GDBN__ will come up showing the prompt:
828
829 @smallexample
830 (_GDBP__)
831 @end smallexample
832
833 @node VxWorks connection,,,
834 @subsubsection Connecting to VxWorks
835
836 The _GDBN__ command @samp{target} lets you connect to a VxWorks target on the
837 network. To connect to a target whose host name is ``@code{tt}'', type:
838
839 @smallexample
840 (_GDBP__) target vxworks tt
841 @end smallexample
842
843 _GDBN__ will display a message similar to the following:
844
845 @smallexample
846 Attaching remote machine across net... Success!
847 @end smallexample
848
849 _GDBN__ will then attempt to read the symbol tables of any object
850 modules loaded into the VxWorks target since it was last booted.
851 _GDBN__ locates these files by searching the directories listed in the
852 command search path (@pxref{Environment}); if it fails to find an
853 object file, it will display a message such as:
854
855 @smallexample
856 prog.o: No such file or directory.
857 @end smallexample
858
859 This will cause the @samp{target} command to abort. When this happens,
860 you should add the appropriate directory to the search path, with the
861 _GDBN__ command @samp{path}, and execute the @samp{target} command
862 again.
863
864 @node VxWorks download,,,
865 @subsubsection VxWorks Download
866
867 If you have connected to the VxWorks target and you want to debug an
868 object that has not yet been loaded, you can use the _GDBN__ @samp{load}
869 command to download a file from UNIX to VxWorks incrementally. The
870 object file given as an argument to the @samp{load} command is actually
871 opened twice: first by the VxWorks target in order to download the code,
872 then by _GDBN__ in order to read the symbol table. This can lead to
873 problems if the current working directories on the two systems differ.
874 It is simplest to set the working directory on both systems to the
875 directory in which the object file resides, and then to reference the
876 file by its name, without any path. Thus, to load a program
877 @samp{prog.o}, residing in @code{wherever/vw/demo/rdb}, on VxWorks type:
878
879 @smallexample
880 -> cd "wherever/vw/demo/rdb"
881 @end smallexample
882
883 On _GDBN__ type:
884
885 @smallexample
886 (_GDBP__) cd wherever/vw/demo/rdb
887 (_GDBP__) load prog.o
888 @end smallexample
889
890 _GDBN__ will display a response similar to the following:
891
892 @smallexample
893 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
894 @end smallexample
895
896 You can also use the @samp{load} command to reload an object module
897 after editing and recompiling the corresponding source file. Note that
898 this will cause _GDBN__ to delete all currently-defined breakpoints,
899 auto-displays, and convenience variables, and to clear the value
900 history. (This is necessary in order to preserve the integrity of
901 debugger data structures that reference the target system's symbol
902 table.)
903
904 @node VxWorks attach,,,
905 @subsubsection Running Tasks
906
907 You can also attach to an existing task using the @samp{attach} command as
908 follows:
909
910 @smallexample
911 (_GDBP__) attach @var{taskId}
912 @end smallexample
913
914 where @var{taskId} is the VxWorks hexadecimal task ID. The task can be running
915 or suspended when you attach to it. If running, it will be suspended at
916 the time of attachment.
917
918 _fi__(_VXWORKS__)
919
920 @node Leaving _GDBN__,,,
921 @section Leaving _GDBN__
922 @cindex exiting _GDBN__
923 @table @code
924 @item quit
925 @kindex quit
926 @kindex q
927 To exit _GDBN__, use the @samp{quit} command (abbreviated @samp{q}), or type
928 an end-of-file character (usually @kbd{C-d}).
929 @end table
930
931 @cindex interrupt
932 An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather
933 will terminate the action of any _GDBN__ command that is in progress and
934 return to _GDBN__ command level. It is safe to type the interrupt
935 character at any time because _GDBN__ does not allow it to take effect
936 until a time when it is safe.
937
938 If you've been using _GDBN__ to control an attached process or device,
939 you can release it with the @samp{detach} command; @pxref{Attach}.
940
941 @node Shell Commands,,,
942 @section Shell Commands
943 If you just need to execute occasional shell commands during your
944 debugging session, there's no need to leave or suspend _GDBN__; you can
945 just use the @samp{shell} command.
946
947 @table @code
948 @item shell @var{command string}
949 @kindex shell
950 @cindex shell escape
951 Directs _GDBN__ to invoke an inferior shell to execute @var{command string}.
952 The environment variable @code{SHELL} is used if it exists, otherwise _GDBN__
953 uses @samp{/bin/sh}.
954 @end table
955
956 The utility @samp{make} is often needed in development environments.
957 You don't have to use the @samp{shell} command for this purpose in _GDBN__:
958
959 @table @code
960 @item make @var{make-args}
961 @kindex make
962 @cindex calling make
963 Causes _GDBN__ to execute an inferior @code{make} program with the specified
964 arguments. This is equivalent to @samp{shell make @var{make-args}}.
965 @end table
966
967 @node Commands,,,
968 @chapter _GDBN__ Commands
969
970 @node Command Syntax,,,
971 @section Command Syntax
972 A _GDBN__ command is a single line of input. There is no limit on how long
973 it can be. It starts with a command name, which is followed by arguments
974 whose meaning depends on the command name. For example, the command
975 @samp{step} accepts an argument which is the number of times to step,
976 as in @samp{step 5}. You can also use the @samp{step} command with
977 no arguments. Some command names do not allow any arguments.
978
979 @cindex abbreviation
980 _GDBN__ command names may always be truncated if that abbreviation is
981 unambiguous. Other possible command abbreviations are listed in the
982 documentation for individual commands. Sometimes even ambiguous
983 abbreviations are allowed; for example, @samp{s} is specially defined as
984 equivalent to @samp{step} even though there are other commands whose
985 names start with @samp{s}.
986
987 @cindex repeating commands
988 A blank line as input to _GDBN__ means to repeat the previous command.
989 Certain commands (for example, @samp{run}) will not repeat this way;
990 these are commands for which unintentional repetition might cause
991 trouble and which you are unlikely to want to repeat.
992
993 The @samp{list} and @samp{x} commands construct new arguments when
994 repeated, rather than repeating exactly as typed, to permit easy
995 scanning of source or memory.
996
997 @kindex #
998 @cindex comment
999 A line of input starting with @samp{#} is a comment; it does nothing.
1000 This is useful mainly in command files (@xref{Command Files}).
1001
1002 @node Help,,,
1003 @section Getting Help
1004 @cindex online documentation
1005 @kindex help
1006 You can always ask _GDBN__ itself for information on its commands, using the
1007 command @samp{help}.
1008
1009 @table @code
1010 @item help
1011 @itemx h
1012 @kindex h
1013 You can use @code{help} (abbreviated @code{h}) with no arguments to
1014 display a short list of named categories of commands:
1015 @smallexample
1016 (_GDBP__) help
1017 List of classes of commands:
1018
1019 running -- Running the program
1020 stack -- Examining the stack
1021 data -- Examining data
1022 breakpoints -- Making program stop at certain points
1023 files -- Specifying and examining files
1024 status -- Status inquiries
1025 support -- Support facilities
1026 user-defined -- User-defined commands
1027 aliases -- Aliases of other commands
1028 obscure -- Obscure features
1029
1030 Type "help" followed by a class name for a list of commands in that class.
1031 Type "help" followed by command name for full documentation.
1032 Command name abbreviations are allowed if unambiguous.
1033 (_GDBP__)
1034 @end smallexample
1035
1036 @item help @var{category}
1037 Using one of the general help categories as an argument, you can get a
1038 list of the individual commands in a category. For example, here is the
1039 help display for category @samp{status}:
1040 @smallexample
1041 (_GDBP__) help status
1042 Status inquiries.
1043
1044 List of commands:
1045
1046 show -- Generic command for showing things set with "set"
1047 info -- Generic command for printing status
1048
1049 Type "help" followed by command name for full documentation.
1050 Command name abbreviations are allowed if unambiguous.
1051 (_GDBP__)
1052 @end smallexample
1053
1054 @item help @var{command}
1055 With a command name as @samp{help} argument, _GDBN__ will display a
1056 short paragraph on how to use that command.
1057 @end table
1058
1059 In addition to @samp{help}, you can use the _GDBN__ commands @samp{info}
1060 and @samp{show} to inquire about the state of your program, or the state
1061 of _GDBN__ itself. Both commands support many ``sub-commands'', or
1062 topics of inquiry; this manual introduces each of them in the
1063 appropriate context. The listings under ``@code{info}'' and under
1064 ``@code{show}'' in the Index point to all the sub-commands.
1065 @c FIXME: @pxref{Index} used to be here, but even though it shows up in
1066 @c FIXME...the 'aux' file with a pageno the xref can't find it.
1067
1068 @table @code
1069 @item info
1070 @kindex info
1071 @kindex i
1072 This command (abbreviated @code{i}) is for describing the state of your
1073 program; for example, it can list the arguments given to your program
1074 (@samp{info args}), the registers currently in use (@samp{info
1075 registers}), or the breakpoints you've set (@samp{info breakpoints}).
1076 You can get a complete list of the @code{info} sub-commands with
1077 @samp{help info}.
1078
1079 @kindex show
1080 @item show
1081 In contrast, @samp{show} is for describing the state of _GDBN__ itself.
1082 You can change most of the things you can @code{show}, by using the
1083 related command @samp{set}; for example, you can control what number
1084 system is used for displays with @samp{set radix}, or simply inquire
1085 which is currently in use with @samp{show radix}.
1086
1087 @kindex info set
1088 To display all the settable parameters and their current
1089 values, you can use @samp{show} with no arguments; you may also use
1090 @samp{info set}. Both commands produce the same display.
1091 @c FIXME: "info set" violates the rule that "info" is for state of
1092 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1093 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1094 @end table
1095
1096 Here are three miscellaneous @samp{show} subcommands, all of which are
1097 exceptional in lacking corresponding @samp{set} commands:
1098
1099 @table @code
1100 @kindex show version
1101 @item show version
1102 Show what version of _GDBN__ is running. You should include this
1103 information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are
1104 in use at your site, you may occasionally want to make sure what version
1105 of _GDBN__ you're running; as _GDBN__ evolves, new commands are
1106 introduced, and old ones may wither away. The version number is also
1107 announced when you start _GDBN__ with no arguments.
1108
1109 @kindex show copying
1110 @item show copying
1111 Display information about permission for copying _GDBN__.
1112
1113 @kindex show warranty
1114 @item show warranty
1115 Display the GNU ``NO WARRANTY'' statement.
1116 @end table
1117
1118 @node Running,,,
1119 @chapter Running Programs Under _GDBN__
1120
1121 @node Compilation,,,
1122 @section Compiling for Debugging
1123
1124 In order to debug a program most effectively, you need to generate
1125 debugging information when you compile it. This debugging information
1126 is stored in the object file; it describes the data type of each
1127 variable or function and the correspondence between source line numbers
1128 and addresses in the executable code.
1129
1130 To request debugging information, specify the @samp{-g} option when you run
1131 the compiler.
1132
1133 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1134 options together. Using those compilers, you cannot generate optimized
1135 executables containing debugging information.
1136
1137 The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it
1138 possible to debug optimized code. We recommend that you @emph{always} use
1139 @samp{-g} whenever you compile a program. You may think the program is
1140 correct, but there's no sense in pushing your luck.
1141
1142 Some things do not work as well with @samp{-g -O} as with just
1143 @samp{-g}, particularly on machines with instruction scheduling. If in
1144 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1145 please report it as a bug (including a test case!).
1146
1147 Older versions of the GNU C compiler permitted a variant option
1148 @samp{-gg} for debugging information. _GDBN__ no longer supports this
1149 format; if your GNU C compiler has this option, do not use it.
1150
1151 @ignore
1152 @comment As far as I know, there are no cases in which _GDBN__ will
1153 @comment produce strange output in this case. (but no promises).
1154 If your program includes archives made with the @code{ar} program, and
1155 if the object files used as input to @code{ar} were compiled without the
1156 @samp{-g} option and have names longer than 15 characters, _GDBN__ will get
1157 confused reading the program's symbol table. No error message will be
1158 given, but _GDBN__ may behave strangely. The reason for this problem is a
1159 deficiency in the Unix archive file format, which cannot represent file
1160 names longer than 15 characters.
1161
1162 To avoid this problem, compile the archive members with the @samp{-g}
1163 option or use shorter file names. Alternatively, use a version of GNU
1164 @code{ar} dated more recently than August 1989.
1165 @end ignore
1166
1167
1168 @node Starting,,,
1169 @section Starting your Program
1170 @cindex starting
1171 @cindex running
1172 @table @code
1173 @item run
1174 @itemx r
1175 @kindex run
1176 Use the @samp{run} command to start your program under _GDBN__.
1177 _if__(_VXWORKS__)
1178 Except on VxWorks, you
1179 _fi__(_VXWORKS__)
1180 _if__(!_VXWORKS__)
1181 You
1182 _fi__(!_VXWORKS__)
1183 must first specify the program name with an argument to _GDBN__
1184 (@pxref{Invocation}), or using the @samp{file} or @samp{exec-file}
1185 command (@pxref{Files}).@refill
1186 @end table
1187
1188 On targets that support processes, @samp{run} creates an inferior
1189 process and makes that process run your program. On other targets,
1190 @samp{run} jumps to the start of the program.
1191
1192 The execution of a program is affected by certain information it
1193 receives from its superior. _GDBN__ provides ways to specify this
1194 information, which you must do @i{before} starting the program. (You
1195 can change it after starting the program, but such changes will only affect
1196 the program the next time you start it.) This information may be
1197 divided into four categories:
1198
1199 @table @asis
1200 @item The @i{arguments.}
1201 You specify the arguments to give your program as the arguments of the
1202 @samp{run} command. If a shell is available on your target, the shell
1203 is used to pass the arguments, so that you may use normal conventions
1204 (for example regular expression expansion or variable substitution) in
1205 describing the arguments. In Unix systems, you can control which shell
1206 is used with the @code{SHELL} environment variable.
1207
1208 @item The @i{environment.}
1209 Your program normally inherits its environment from _GDBN__, but you can
1210 use the _GDBN__ commands @samp{set environment} and @samp{unset
1211 environment} to change parts of the environment that will be given to
1212 the program.@refill
1213
1214 @item The @i{working directory.}
1215 Your program inherits its working directory from _GDBN__. You can set
1216 _GDBN__'s working directory with the @samp{cd} command in _GDBN__.
1217
1218 @item The @i{standard input and output.}
1219 Your program normally uses the same device for standard input and
1220 standard output as _GDBN__ is using. You can redirect input and output
1221 in the @code{run} command line, or you can use the @samp{tty} command to
1222 set a different device for your program.
1223 @end table
1224
1225 When you issue the @samp{run} command, your program begins to execute
1226 immediately. @xref{Stopping}, for discussion of how to arrange for your
1227 program to stop.
1228
1229 Note that once your program has been started by the @samp{run} command,
1230 you may evaluate expressions that involve calls to functions in the
1231 inferior, using the @samp{print} or @samp{call} commands. @xref{Data}.
1232
1233 If the modification time of your symbol file has changed since the last
1234 time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and re-read
1235 it. In this process, it tries to retain your current breakpoints.
1236
1237 @node Arguments,,,
1238 @section Your Program's Arguments
1239
1240 @cindex arguments (to your program)
1241 The arguments to your program can be specified by the arguments of the
1242 @samp{run} command. They are passed to a shell, which expands wildcard
1243 characters and performs redirection of I/O, and thence to the program.
1244 _GDBN__ uses the shell indicated by your environment variable
1245 @code{SHELL} if it exists; otherwise, _GDBN__ uses @samp{/bin/sh}.
1246
1247 @samp{run} with no arguments uses the same arguments used by the previous
1248 @samp{run}, or those set by the @samp{set args} command.
1249
1250 @kindex set args
1251 @table @code
1252 @item set args
1253 Specify the arguments to be used the next time your program is run. If
1254 @samp{set args} has no arguments, @samp{run} will execute your program
1255 with no arguments. Once you have run your program with arguments, this
1256 is the only way to run it again without arguments.
1257
1258 @item show args
1259 @kindex show args
1260 Show the arguments to give your program when it is started.
1261 @end table
1262
1263 @node Environment,,,
1264 @section Your Program's Environment
1265
1266 @cindex environment (of your program)
1267 The @dfn{environment} consists of a set of environment variables and
1268 their values. Environment variables conventionally record such things as
1269 your user name, your home directory, your terminal type, and your search
1270 path for programs to run. Usually you set up environment variables with
1271 the shell and they are inherited by all the other programs you run. When
1272 debugging, it can be useful to try running the program with a modified
1273 environment without having to start _GDBN__ over again.
1274
1275 @table @code
1276 @item path @var{directory}
1277 @kindex path
1278 Add @var{directory} to the front of the @code{PATH} environment variable
1279 (the search path for executables), for both _GDBN__ and your program.
1280 You may specify several directory names, separated by @samp{:} or
1281 whitespace. If a directory is already in the path, it is moved to the
1282 front, so it will be searched sooner. You can use the string
1283 @samp{$cwd} to refer to the current working directory.
1284
1285 This command will not repeat if you press @key{RET} a second time after
1286 using it once.
1287
1288 @item show paths
1289 @kindex info paths
1290 Display the list of search paths for executables (the @code{PATH}
1291 environment variable).
1292
1293 @item show environment @var{varname}
1294 @kindex show environment
1295 Print the value of environment variable @var{varname} to be given to
1296 your program when it starts.
1297
1298 @item show environment
1299 Print the names and values of all environment variables to be given to
1300 your program.
1301
1302 @item set environment @var{varname} @var{value}
1303 @itemx set environment @var{varname} = @var{value}
1304 @kindex set environment
1305 Sets environment variable @var{varname} to @var{value}. The value
1306 changes for your program only, not for _GDBN__ itself. @var{value} may
1307 be any string; the values of environment variables are just strings, and
1308 any interpretation is supplied by your program itself. The @var{value}
1309 parameter is optional; if it is eliminated, the variable is set to a
1310 null value.
1311 @c FIXME: I think "any string" here doesn't include leading, trailing
1312 @c FIXME... blanks. Queried J Gilmore. ---pesch@cygnus.com, 4apr91
1313
1314 For example, this command:
1315
1316 @example
1317 set env USER = foo
1318 @end example
1319
1320 @noindent
1321 tells a Unix program, when subsequently run, that its user is named
1322 @samp{foo}.
1323
1324 @item unset environment @var{varname}
1325 @kindex unset environment
1326 Remove variable @var{varname} from the environment to be passed to your
1327 program. This is different from @samp{set env @var{varname}=};
1328 @samp{unset environment} removes the variable from the environment,
1329 rather than assigning it an empty value.
1330 @end table
1331
1332 @node Working Directory,,,
1333 @section Your Program's Working Directory
1334
1335 @cindex working directory (of your program)
1336 Each time you start your program with @samp{run}, it inherits its
1337 working directory from the current working directory of _GDBN__. _GDBN__'s
1338 working directory is initially whatever it inherited from its parent
1339 process (typically the shell), but you can specify a new working
1340 directory in _GDBN__ with the @samp{cd} command.
1341
1342 The _GDBN__ working directory also serves as a default for the commands
1343 that specify files for _GDBN__ to operate on. @xref{Files}.
1344
1345 @table @code
1346 @item cd @var{directory}
1347 @kindex cd
1348 Set _GDBN__'s working directory to @var{directory}.
1349
1350 @item pwd
1351 @kindex pwd
1352 Print _GDBN__'s working directory.
1353 @end table
1354
1355 @node Input/Output,,,
1356 @section Your Program's Input and Output
1357
1358 @cindex redirection
1359 @cindex i/o
1360 @cindex terminal
1361 @cindex controlling terminal
1362 By default, the program you run under _GDBN__ does input and output to
1363 the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to
1364 its own terminal modes to interact with you, but it records the terminal
1365 modes your program was using and switches back to them when you continue
1366 running your program.
1367
1368 @table @code
1369 @item info terminal
1370 @kindex info terminal
1371 Displays _GDBN__'s recorded information about the terminal modes your
1372 program is using.
1373 @end table
1374
1375 You can redirect the program's input and/or output using shell
1376 redirection with the @samp{run} command. For example,
1377
1378 _0__@example
1379 run > outfile
1380 _1__@end example
1381
1382 @noindent
1383 starts the program, diverting its output to the file @file{outfile}.
1384
1385 @kindex tty
1386 Another way to specify where the program should do input and output is
1387 with the @samp{tty} command. This command accepts a file name as
1388 argument, and causes this file to be the default for future @samp{run}
1389 commands. It also resets the controlling terminal for the child
1390 process, for future @samp{run} commands. For example,
1391
1392 @example
1393 tty /dev/ttyb
1394 @end example
1395
1396 @noindent
1397 directs that processes started with subsequent @samp{run} commands
1398 default to do input and output on the terminal @file{/dev/ttyb} and have
1399 that as their controlling terminal.
1400
1401 An explicit redirection in @samp{run} overrides the @samp{tty} command's
1402 effect on input/output redirection, but not its effect on the
1403 controlling terminal.
1404
1405 When you use the @samp{tty} command or redirect input in the @samp{run}
1406 command, only the input @emph{for your program} is affected. The input
1407 for _GDBN__ still comes from your terminal.
1408
1409 @node Attach,,,
1410 @section Debugging an Already-Running Process
1411 @kindex attach
1412 @cindex attach
1413
1414 @table @code
1415 @item attach @var{process-id}
1416 If your currently selected target supports processes, this command
1417 attaches to a running process---one that was started outside _GDBN__.
1418 (@samp{info files} will show your active targets). The command takes as
1419 argument a process ID. The usual way to find out the process-id of
1420 a Unix process is with the @code{ps} utility, or with the @code{jobs -l}
1421 shell command.
1422
1423 @samp{attach} will not repeat if you press @key{RET} a second time after
1424 executing the command.
1425 @end table
1426
1427 To use @samp{attach}, you must have permission to send the process a
1428 signal, and it must have the same effective user ID as the _GDBN__
1429 process.
1430
1431 When using @samp{attach}, you should first use the @samp{file} command
1432 to specify the program running in the process and load its symbol table.
1433
1434 The first thing _GDBN__ does after arranging to debug the specified
1435 process is to stop it. You can examine and modify an attached process
1436 with all the _GDBN__ commands that ordinarily available when you start
1437 processes with @samp{run}. You can insert breakpoints; you can step and
1438 continue; you can modify storage. If you would rather the process
1439 continue running, you may use the @samp{continue} command after
1440 attaching _GDBN__ to the process.
1441
1442 @table @code
1443 @item detach
1444 @kindex detach
1445 When you have finished debugging the attached process, you can use the
1446 @samp{detach} command to release it from _GDBN__'s control. Detaching
1447 the process continues its execution. After the @samp{detach} command,
1448 that process and _GDBN__ become completely independent once more, and you
1449 are ready to @samp{attach} another process or start one with @samp{run}.
1450 @samp{detach} will not repeat if you press @key{RET} again after using
1451 it once.
1452 @end table
1453
1454 If you exit _GDBN__ or use the @samp{run} command while you have an attached
1455 process, you kill that process. By default, you will be asked for
1456 confirmation if you try to do either of these things; you can control
1457 whether or not this happens by using the @samp{set confirm} command
1458 (@pxref{Messages/Warnings}).
1459
1460 @group
1461 @node Kill Process,,,
1462 @section Killing the Child Process
1463
1464 @table @code
1465 @item kill
1466 @kindex kill
1467 Kill the child process in which your program is running under _GDBN__.
1468 @end table
1469
1470 This command is useful if you wish to debug a core dump instead of a
1471 running process. _GDBN__ ignores any core dump file while your program
1472 is running.
1473 @end group
1474
1475 On some operating systems, you can't execute your program in another
1476 process while breakpoints are active inside _GDBN__. You can use the
1477 @samp{kill} command in this situation to permit running the program
1478 outside the debugger.
1479
1480 The @samp{kill} command is also useful if you wish to recompile and
1481 relink the program, since on many systems it is impossible to modify an
1482 executable file which is running in a process. In this case, when you
1483 next type @samp{run}, _GDBN__ will notice that the file has changed, and
1484 will re-read the symbol table (while trying to preserve your current
1485 breakpoint settings).
1486
1487 @node Stopping,,,
1488 @chapter Stopping and Continuing
1489
1490 When you run a program normally, it runs until it terminates. The
1491 principal purpose of using a debugger is so that you can stop it before
1492 that point; or so that if the program runs into trouble you can
1493 investigate and find out why.
1494
1495 Inside _GDBN__, your program may stop for any of several reasons, such
1496 as a signal, a breakpoint, or reaching a new line after a _GDBN__
1497 command such as @code{step}. Usually, the messages shown by _GDBN__
1498 provide ample explanation of the status of your program---but you can
1499 also explicitly request this information at any time.
1500
1501 @table @code
1502 @item info program
1503 @kindex info program
1504 Display information about the status of your program: whether it is
1505 running or not, what process it is, and why it stopped.
1506 @end table
1507
1508 @node Breakpoints,,,
1509 @section Breakpoints
1510
1511 @cindex breakpoints
1512 A @dfn{breakpoint} makes your program stop whenever a certain point in the
1513 program is reached. You set breakpoints explicitly with _GDBN__ commands,
1514 specifying the place where the program should stop by line number, function
1515 name or exact address in the program. You can add various other conditions
1516 to control whether the program will stop.
1517
1518 Each breakpoint is assigned a number when it is created; these numbers are
1519 successive integers starting with 1. In many of the commands for controlling
1520 various features of breakpoints you use the breakpoint number to say which
1521 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
1522 @dfn{disabled}; if disabled, it has no effect on the program until you
1523 enable it again.
1524
1525 @node Set Breaks,,,
1526 @subsection Setting Breakpoints
1527
1528 @kindex break
1529 @kindex b
1530 Breakpoints are set with the @samp{break} command (abbreviated @samp{b}).
1531
1532 You have several ways to say where the breakpoint should go.
1533
1534 @table @code
1535 @item break @var{function}
1536 Set a breakpoint at entry to function @var{function}.
1537
1538 @item break @var{+offset}
1539 @itemx break @var{-offset}
1540 Set a breakpoint some number of lines forward or back from the position
1541 at which execution stopped in the currently selected frame.
1542
1543 @item break @var{linenum}
1544 Set a breakpoint at line @var{linenum} in the current source file.
1545 That file is the last file whose source text was printed. This
1546 breakpoint will stop the program just before it executes any of the
1547 code on that line.
1548
1549 @item break @var{filename}:@var{linenum}
1550 Set a breakpoint at line @var{linenum} in source file @var{filename}.
1551
1552 @item break @var{filename}:@var{function}
1553 Set a breakpoint at entry to function @var{function} found in file
1554 @var{filename}. Specifying a file name as well as a function name is
1555 superfluous except when multiple files contain similarly named
1556 functions.
1557
1558 @item break *@var{address}
1559 Set a breakpoint at address @var{address}. You can use this to set
1560 breakpoints in parts of the program which do not have debugging
1561 information or source files.
1562
1563 @item break
1564 Set a breakpoint at the next instruction to be executed in the selected
1565 stack frame (@pxref{Stack}). In any selected frame but the innermost,
1566 this will cause the program to stop as soon as control returns to that
1567 frame. This is equivalent to a @samp{finish} command in the frame
1568 inside the selected frame. If this is done in the innermost frame, _GDBN__
1569 will stop the next time it reaches the current location; this may be
1570 useful inside of loops.
1571
1572 _GDBN__ normally ignores breakpoints when it resumes execution, until at
1573 least one instruction has been executed. If it did not do this, you
1574 would be unable to proceed past a breakpoint without first disabling the
1575 breakpoint. This rule applies whether or not the breakpoint already
1576 existed when the program stopped.
1577
1578 @item break @dots{} if @var{cond}
1579 Set a breakpoint with condition @var{cond}; evaluate the expression
1580 @var{cond} each time the breakpoint is reached, and stop only if the
1581 value is nonzero. @samp{@dots{}} stands for one of the possible
1582 arguments described above (or no argument) specifying where to break.
1583 @xref{Conditions}, for more information on breakpoint conditions.
1584
1585 @item tbreak @var{args}
1586 @kindex tbreak
1587 Set a breakpoint enabled only for one stop. @var{args} are the
1588 same as in the @samp{break} command, and the breakpoint is set in the same
1589 way, but the breakpoint is automatically disabled the first time it
1590 is hit. @xref{Disabling}.
1591
1592 @item rbreak @var{regex}
1593 @kindex rbreak
1594 Set a breakpoint on all functions matching @var{regex}. This is
1595 useful for setting breakpoints on overloaded functions that are not
1596 members of any special classes. This command sets an unconditional
1597 breakpoint on all matches, printing a list of all breakpoints it set.
1598 Once these breakpoints are set, they are treated just like the
1599 breakpoints set with the @samp{break} command. They can be deleted,
1600 disabled, made conditional, etc., in the standard ways.
1601
1602 @kindex info breakpoints
1603 @kindex $_
1604 @item info breakpoints
1605 The command @samp{info breakpoints} prints a list of all breakpoints set
1606 and not deleted, showing their numbers, where in the program they are,
1607 and any special features in use for them. Disabled breakpoints are
1608 included in the list, but marked as disabled. @samp{info break} with a
1609 breakpoint number as argument lists only that breakpoint. The
1610 convenience variable @code{$_} and the default examining-address for the
1611 @samp{x} command are set to the address of the last breakpoint listed
1612 (@pxref{Memory}).
1613 @end table
1614
1615 _GDBN__ allows you to set any number of breakpoints at the same place in the
1616 program. There is nothing silly or meaningless about this. When the
1617 breakpoints are conditional, this is even useful (@pxref{Conditions}).
1618
1619 @node Set Watchpoints,,,
1620 @subsection Setting Watchpoints
1621 @cindex watchpoints
1622 A @dfn{watchpoint} is a special breakpoint that stops your program when
1623 the value of an expression changes. You can use a watchpoint to stop
1624 execution whenever the value of an expression changes, without having to
1625 predict a particular place in the inferior process where this may
1626 happen. Aside from the different syntax in setting a watchpoint, it is
1627 managed exactly like any other breakpoint and is enabled, disabled, and
1628 deleted using exactly the same commands.
1629
1630 Watchpoints currently execute two orders of magnitude more slowly than
1631 other breakpoints, but this can well be worth it to catch errors where
1632 you have no clue what part of your program is the culprit. Some
1633 processors provide special hardware to implement this feature; future
1634 releases of _GDBN__ will use such hardware if it is available.
1635
1636 @table @code
1637 @kindex watch
1638 @item watch @var{expr}
1639 Set a watchpoint for an expression.
1640
1641 @kindex info watchpoints
1642 @item info watchpoints
1643 This command prints a list of watchpoints.
1644 @end table
1645
1646 @node Exception Handling,,,
1647 @subsection Breakpoints and Exceptions
1648 @cindex exception handlers
1649
1650 Some languages, such as GNU C++, implement exception handling. _GDBN__
1651 can be used to examine what caused the program to raise an exception
1652 and to list the exceptions the program is prepared to handle at a
1653 given point in time.
1654
1655 @table @code
1656 @item catch @var{exceptions}
1657 @kindex catch
1658
1659 You can set breakpoints at active exception handlers by using the
1660 @samp{catch} command. @var{exceptions} is a list of names of exceptions
1661 to catch.
1662 @end table
1663
1664 You can use @samp{info catch} to list active exception handlers;
1665 @pxref{Frame Info}.
1666
1667 There are currently some limitations to exception handling in _GDBN__.
1668 These will be corrected in a future release.
1669
1670 @itemize @bullet
1671 @item
1672 If you call a function interactively, _GDBN__ will normally return
1673 control to you when the function has finished executing. If the call
1674 raises an exception, however, the call may bypass the mechanism that
1675 returns control to the user and cause the program to simply continue
1676 running until it hits a breakpoint, catches a signal that _GDBN__ is
1677 listening for, or exits.
1678 @item
1679 You cannot raise an exception interactively.
1680 @item
1681 You cannot interactively install an exception handler.
1682 @end itemize
1683
1684 @cindex raise exceptions
1685 Sometimes @samp{catch} is not the best way to debug exception handling:
1686 if you need to know exactly where an exception is raised, it's better to
1687 stop @emph{before} the exception handler is called, since that way you
1688 can see the stack before any unwinding takes place.
1689
1690 To stop just before an exception handler is called, you need some
1691 knowledge of the implementation. In the case of GNU C++ exception are
1692 raised by calling a library function named @code{__raise_exception}
1693 which has the following ANSI C interface:
1694
1695 @example
1696 /* ADDR is where the exception identifier is stored.
1697 ID is the exception identifier. */
1698 void __raise_exception (void **addr, void *id);
1699 @end example
1700
1701 @noindent
1702 To make the debugger catch all exceptions before any stack
1703 unwinding takes place, set a breakpoint on @code{__raise_exception}
1704 (@pxref{Breakpoints}). If you set a breakpoint in an exception handler
1705 instead, it may not be easy to find out where the exception was raised.
1706
1707 With a conditional breakpoint (@xref{Conditions}) that depends on the
1708 value of @code{id}, you can cause the debugger to stop only when a
1709 specific exception is raised. Multiple conditional breakpoints can be
1710 used to stop the program when any of a number of exceptions are raised.
1711
1712 @node Delete Breaks,,,
1713 @subsection Deleting Breakpoints
1714
1715 @cindex clearing breakpoints, watchpoints
1716 @cindex deleting breakpoints, watchpoints
1717 It is often necessary to eliminate a breakpoint once it has done its job
1718 and you no longer want the program to stop there. This is called
1719 @dfn{deleting} the breakpoint. A breakpoint that has been deleted no
1720 longer exists in any sense; it is forgotten.
1721
1722 With the @samp{clear} command you can delete breakpoints according to where
1723 they are in the program. With the @samp{delete} command you can delete
1724 individual breakpoints by specifying their breakpoint numbers.
1725
1726 It is not necessary to delete a breakpoint to proceed past it. _GDBN__
1727 automatically ignores breakpoints on the first instruction to be executed
1728 when you continue execution without changing the execution address.
1729
1730 @table @code
1731 @item clear
1732 @kindex clear
1733 Delete any breakpoints at the next instruction to be executed in the
1734 selected stack frame (@pxref{Selection}). When the innermost frame
1735 is selected, this is a good way to delete a breakpoint that the program
1736 just stopped at.
1737
1738 @item clear @var{function}
1739 @itemx clear @var{filename}:@var{function}
1740 Delete any breakpoints set at entry to the function @var{function}.
1741
1742 @item clear @var{linenum}
1743 @itemx clear @var{filename}:@var{linenum}
1744 Delete any breakpoints set at or within the code of the specified line.
1745
1746 @item delete breakpoints @var{bnums}@dots{}
1747 @itemx delete @var{bnums}@dots{}
1748 @itemx delete
1749 @cindex delete breakpoints
1750 @kindex delete
1751 @kindex d
1752 Delete the breakpoints of the numbers specified as arguments. If no
1753 argument is specified, delete all breakpoints. You can abbreviate this
1754 command as @samp{d}.
1755 @end table
1756
1757 @node Disabling,,,
1758 @subsection Disabling Breakpoints
1759
1760 @cindex disabled breakpoints
1761 @cindex enabled breakpoints
1762 Rather than deleting a breakpoint, you might prefer to @dfn{disable} it.
1763 This makes the breakpoint inoperative as if it had been deleted, but
1764 remembers the information on the breakpoint so that you can @dfn{enable}
1765 it again later.
1766
1767 You disable and enable breakpoints with the @samp{enable} and
1768 @samp{disable} commands, optionally specifying one or more breakpoint
1769 numbers as arguments. Use @samp{info break} to print a list of
1770 breakpoints if you don't know which breakpoint numbers to use.
1771
1772 A breakpoint can have any of four different states of enablement:
1773
1774 @itemize @bullet
1775 @item
1776 Enabled. The breakpoint will stop the program. A breakpoint made
1777 with the @samp{break} command starts out in this state.
1778 @item
1779 Disabled. The breakpoint has no effect on the program.
1780 @item
1781 Enabled once. The breakpoint will stop the program, but
1782 when it does so it will become disabled. A breakpoint made
1783 with the @samp{tbreak} command starts out in this state.
1784 @item
1785 Enabled for deletion. The breakpoint will stop the program, but
1786 immediately after it does so it will be deleted permanently.
1787 @end itemize
1788
1789 You can use the following commands to enable or disable a breakpoint:
1790
1791 @table @code
1792 @item disable breakpoints @var{bnums}@dots{}
1793 @itemx disable @var{bnums}@dots{}
1794 @itemx disable
1795 @kindex disable breakpoints
1796 @kindex disable
1797 @kindex dis
1798 Disable the specified breakpoints---or all breakpoints, if none are
1799 listed. A disabled breakpoint has no effect but is not forgotten. All
1800 options such as ignore-counts, conditions and commands are remembered in
1801 case the breakpoint is enabled again later. You may abbreviate
1802 @code{disable} as @code{dis}.
1803
1804 @item enable breakpoints @var{bnums}@dots{}
1805 @itemx enable @var{bnums}@dots{}
1806 @itemx enable
1807 @kindex enable breakpoints
1808 @kindex enable
1809 Enable the specified breakpoints (or all defined breakpoints). They
1810 become effective once again in stopping the program, until you specify
1811 otherwise.
1812
1813 @item enable breakpoints once @var{bnums}@dots{}
1814 @itemx enable once @var{bnums}@dots{}
1815 Enable the specified breakpoints temporarily. Each will be disabled
1816 again the next time it stops the program (unless you have used one of
1817 these commands to specify a different state before that time comes).
1818
1819 @item enable breakpoints delete @var{bnums}@dots{}
1820 @itemx enable delete @var{bnums}@dots{}
1821 Enable the specified breakpoints to work once and then die. Each of
1822 the breakpoints will be deleted the next time it stops the program
1823 (unless you have used one of these commands to specify a different
1824 state before that time comes).
1825 @end table
1826
1827 Save for a breakpoint set with @samp{tbreak} (@pxref{Set Breaks}),
1828 breakpoints that you set initially enabled; subsequently, they become
1829 disabled or enabled only when you use one of the commands above. (The
1830 command @samp{until} can set and delete a breakpoint of its own, but it
1831 will not change the state of your other breakpoints).
1832
1833 @node Conditions,,,
1834 @subsection Break Conditions
1835 @cindex conditional breakpoints
1836 @cindex breakpoint conditions
1837
1838 The simplest sort of breakpoint breaks every time the program reaches a
1839 specified place. You can also specify a @dfn{condition} for a
1840 breakpoint. A condition is just a Boolean expression in your
1841 programming language. (@xref{Expressions}). A breakpoint with a
1842 condition evaluates the expression each time the program reaches it, and
1843 the program stops only if the condition is true.
1844
1845 Break conditions may have side effects, and may even call functions in your
1846 program. These may sound like strange things to do, but their effects are
1847 completely predictable unless there is another enabled breakpoint at the
1848 same address. (In that case, _GDBN__ might see the other breakpoint first and
1849 stop the program without checking the condition of this one.) Note that
1850 breakpoint commands are usually more convenient and flexible for the
1851 purpose of performing side effects when a breakpoint is reached
1852 (@pxref{Break Commands}).
1853
1854 Break conditions can be specified when a breakpoint is set, by using
1855 @samp{if} in the arguments to the @samp{break} command. @xref{Set Breaks}.
1856 They can also be changed at any time with the @samp{condition} command:
1857
1858 @table @code
1859 @item condition @var{bnum} @var{expression}
1860 @kindex condition
1861 Specify @var{expression} as the break condition for breakpoint number
1862 @var{bnum}. From now on, this breakpoint will stop the program only if
1863 the value of @var{expression} is true (nonzero, in C). @var{expression}
1864 is not evaluated at the time the @samp{condition} command is given.
1865 When you call @samp{condition}, the expression you specify is checked
1866 immediately for syntactic correctness, and to determine whether symbols
1867 in it have referents in the context of your breakpoint.
1868 @xref{Expressions}.
1869
1870 @item condition @var{bnum}
1871 Remove the condition from breakpoint number @var{bnum}. It becomes
1872 an ordinary unconditional breakpoint.
1873 @end table
1874
1875 @cindex ignore count (of breakpoint)
1876 A special case of a breakpoint condition is to stop only when the
1877 breakpoint has been reached a certain number of times. This is so
1878 useful that there is a special way to do it, using the @dfn{ignore
1879 count} of the breakpoint. Every breakpoint has an ignore count, which
1880 is an integer. Most of the time, the ignore count is zero, and
1881 therefore has no effect. But if the program reaches a breakpoint whose
1882 ignore count is positive, then instead of stopping, it just decrements
1883 the ignore count by one and continues. As a result, if the ignore count
1884 value is @var{n}, the breakpoint will not stop the next @var{n} times it
1885 is reached.
1886
1887 @table @code
1888 @item ignore @var{bnum} @var{count}
1889 @kindex ignore
1890 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
1891 The next @var{count} times the breakpoint is reached, your program's
1892 execution will not stop; other than to decrement the ignore count, _GDBN__
1893 takes no action.
1894
1895 To make the breakpoint stop the next time it is reached, specify
1896 a count of zero.
1897
1898 @item continue @var{count}
1899 @itemx c @var{count}
1900 @itemx fg @var{count}
1901 @kindex continue @var{count}
1902 Continue execution of the program, setting the ignore count of the
1903 breakpoint that the program stopped at to @var{count} minus one.
1904 Thus, the program will not stop at this breakpoint until the
1905 @var{count}'th time it is reached.
1906
1907 An argument to this command is meaningful only when the program stopped
1908 due to a breakpoint. At other times, the argument to @samp{continue} is
1909 ignored.
1910
1911 The synonym @samp{fg} is provided purely for convenience, and has
1912 exactly the same behavior as other forms of the command.
1913 @end table
1914
1915 If a breakpoint has a positive ignore count and a condition, the condition
1916 is not checked. Once the ignore count reaches zero, the condition will
1917 be checked.
1918
1919 You could achieve the effect of the ignore count with a
1920 condition such as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience
1921 variable that is decremented each time. @xref{Convenience Vars}.
1922
1923 @node Break Commands,,,
1924 @subsection Breakpoint Command Lists
1925
1926 @cindex breakpoint commands
1927 You can give any breakpoint a series of commands to execute when the
1928 program stops due to that breakpoint. For example, you might want to
1929 print the values of certain expressions, or enable other breakpoints.
1930
1931 @table @code
1932 @item commands @var{bnum}
1933 @itemx @dots{} @var{command-list} @dots{}
1934 @itemx end
1935 @kindex commands
1936 @kindex end
1937 Specify a list of commands for breakpoint number @var{bnum}. The commands
1938 themselves appear on the following lines. Type a line containing just
1939 @samp{end} to terminate the commands.
1940
1941 To remove all commands from a breakpoint, use the command
1942 @samp{commands} and follow it immediately by @samp{end}; that is, give
1943 no commands.
1944
1945 With no arguments, @samp{commands} refers to the last breakpoint set
1946 (not to the breakpoint most recently encountered).
1947 @end table
1948
1949 Pressing @key{RET} as a means of repeating the last _GDBN__ command is
1950 disabled from the time you enter @samp{commands} to just after the
1951 corresponding @samp{end}.
1952
1953 You can use breakpoint commands to start the program up again. Simply
1954 use the @samp{continue} command, or @samp{step}, or any other command to
1955 resume execution. However, if you do this, any further commands in the
1956 same breakpoint's command list are ignored. When the program stops
1957 again, _GDBN__ will act according to the cause of that stop.
1958
1959 @kindex silent
1960 If the first command specified is @samp{silent}, the usual message about
1961 stopping at a breakpoint is not printed. This may be desirable for
1962 breakpoints that are to print a specific message and then continue.
1963 If the remaining commands too print nothing, you will see no sign that
1964 the breakpoint was reached at all. @samp{silent} is not really a command;
1965 it is meaningful only at the beginning of the commands for a breakpoint.
1966
1967 The commands @samp{echo} and @samp{output} that allow you to print precisely
1968 controlled output are often useful in silent breakpoints. @xref{Output}.
1969
1970 For example, here is how you could use breakpoint commands to print the
1971 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
1972
1973 _0__@example
1974 break foo if x>0
1975 commands
1976 silent
1977 echo x is\040
1978 output x
1979 echo \n
1980 cont
1981 end
1982 _1__@end example
1983
1984 One application for breakpoint commands is to correct one bug so you can
1985 test another. Put a breakpoint just after the erroneous line of code, give
1986 it a condition to detect the case in which something erroneous has been
1987 done, and give it commands to assign correct values to any variables that
1988 need them. End with the @samp{continue} command so that the program does not
1989 stop, and start with the @samp{silent} command so that no output is
1990 produced. Here is an example:
1991
1992 @example
1993 break 403
1994 commands
1995 silent
1996 set x = y + 4
1997 cont
1998 end
1999 @end example
2000
2001 @cindex lost output
2002 One deficiency in the operation of automatically continuing breakpoints
2003 under Unix appears when your program uses raw mode for the terminal.
2004 _GDBN__ switches back to its own terminal modes (not raw) before executing
2005 commands, and then must switch back to raw mode when your program is
2006 continued. This causes any pending terminal input to be lost.
2007 In the GNU system, this will be fixed by changing the behavior of
2008 terminal modes.
2009
2010 Under Unix, when you have this problem, you might be able to get around
2011 it by putting your actions into the breakpoint condition instead of
2012 commands. For example
2013
2014 @example
2015 condition 5 (x = y + 4), 0
2016 @end example
2017
2018 @noindent
2019 specifies a condition expression (@xref{Expressions}) that will change
2020 @code{x} as needed, then always have the value 0 so the program will not
2021 stop. Loss of input is avoided here because break conditions are
2022 evaluated without changing the terminal modes. When you want to have
2023 nontrivial conditions for performing the side effects, the operators
2024 @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
2025
2026 @node Error in Breakpoints,,,
2027 @subsection ``Cannot Insert Breakpoints''
2028
2029 @c FIXME: "cannot insert breakpoints" error, v unclear.
2030 @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91
2031 Under some operating systems, breakpoints cannot be used in a program if
2032 any other process is running that program. In this situation,
2033 attempting to run or continue a program with a breakpoint will cause _GDBN__
2034 to stop the other process.
2035
2036 When this happens, you have three ways to proceed:
2037
2038 @enumerate
2039 @item
2040 Remove or disable the breakpoints, then continue.
2041
2042 @item
2043 Suspend _GDBN__, and copy the file containing the program to a new name.
2044 Resume _GDBN__ and use the @samp{exec-file} command to specify that _GDBN__
2045 should run the program under that name. Then start the program again.
2046
2047 @item
2048 Relink the program so that the text segment is nonsharable, using the
2049 linker option @samp{-N}. The operating system limitation may not apply
2050 to nonsharable executables.
2051 @end enumerate
2052
2053 @node Stepping,,,
2054 @section Stepping
2055
2056 @cindex stepping
2057 @dfn{Stepping} means setting your program in motion for a limited time, so
2058 that control will return automatically to _GDBN__ after one line of
2059 code or one machine instruction. Breakpoints are active during stepping
2060 and the program will stop for them even if it has not gone as far as the
2061 stepping command specifies.
2062
2063 @table @code
2064 @item step
2065 @kindex step
2066 @kindex s
2067 Continue running the program until control reaches a different source
2068 line, then stop it and return control to the debugger. This command is
2069 abbreviated @samp{s}.
2070
2071 This command may be given when control is within a function for which
2072 there is no debugging information. In that case, execution will proceed
2073 until control reaches a different function, or is about to return from
2074 this function.
2075
2076 @item step @var{count}
2077 Continue running as in @samp{step}, but do so @var{count} times. If a
2078 breakpoint is reached or a signal not related to stepping occurs before
2079 @var{count} steps, stepping stops right away.
2080
2081 @item next
2082 @kindex next
2083 @kindex n
2084 Continue to the next source line in the current stack frame. Similar to
2085 @samp{step}, but any function calls appearing within the line of code
2086 are executed without stopping. Execution stops when control reaches a
2087 different line of code at the stack level which was executing when the
2088 @samp{next} command was given. This command is abbreviated @samp{n}.
2089
2090 An argument is a repeat count, as in @samp{step}.
2091
2092 @samp{next} within a function that lacks debugging information acts as does
2093 @samp{step}, but any function calls appearing within the code of the
2094 function are executed without stopping.
2095 @c FIXME: great; so what does *step* do within a fn that lacks debug info?
2096
2097 @item finish
2098 @kindex finish
2099 Continue running until just after the selected stack frame returns (or
2100 until there is some other reason to stop, such as a fatal signal or a
2101 breakpoint). Print the value returned by the selected stack frame (if
2102 any).
2103
2104 Contrast this with the @samp{return} command (@pxref{Returning}).
2105
2106 @item until
2107 @kindex until
2108 @item u
2109 @kindex u
2110 Continue running until a source line past the current line, in the
2111 current stack frame, is reached. This command is used to avoid single
2112 stepping through a loop more than once. It is like the @samp{next}
2113 command, except that when @samp{until} encounters a jump, it
2114 automatically continues execution until the program counter is greater
2115 than the address of the jump.
2116
2117 This means that when you reach the end of a loop after single stepping
2118 though it, @samp{until} will cause the program to continue execution
2119 until the loop is exited. In contrast, a @samp{next} command at the end
2120 of a loop will simply step back to the beginning of the loop, which
2121 would force you to step through the next iteration.
2122
2123 @samp{until} always stops the program if it attempts to exit the current
2124 stack frame.
2125
2126 @samp{until} may produce somewhat counterintuitive results if the order
2127 of the source lines does not match the actual order of execution. For
2128 example, in a typical C @code{for}-loop, the third expression in the
2129 @code{for}-statement (the loop-step expression) is executed after the
2130 statements in the body of the loop, but is written before them.
2131 Therefore, the @samp{until} command would appear to step back to the
2132 beginning of the loop when it advances to this expression. However, it
2133 has not really done so, not in terms of the actual machine code.
2134
2135 @samp{until} with no argument works by means of single
2136 instruction stepping, and hence is slower than @samp{until} with an
2137 argument.
2138
2139 @item until @var{location}
2140 @item u @var{location}
2141 Continue running the program until either the specified location is
2142 reached, or the current (innermost) stack frame returns. @var{location}
2143 is any of the forms of argument acceptable to @samp{break} (@pxref{Set
2144 Breaks}). This form of the command uses breakpoints, and hence is
2145 quicker than @samp{until} without an argument.
2146
2147 @item stepi
2148 @itemx si
2149 @kindex stepi
2150 @kindex si
2151 Execute one machine instruction, then stop and return to the debugger.
2152
2153 It is often useful to do @samp{display/i $pc} when stepping by machine
2154 instructions. This will cause the next instruction to be executed to
2155 be displayed automatically at each stop. @xref{Auto Display}.
2156
2157 An argument is a repeat count, as in @samp{step}.
2158
2159 @item nexti
2160 @itemx ni
2161 @kindex nexti
2162 @kindex ni
2163 Execute one machine instruction, but if it is a function call,
2164 proceed until the function returns.
2165
2166 An argument is a repeat count, as in @samp{next}.
2167 @end table
2168
2169 A typical technique for using stepping is to put a breakpoint
2170 (@pxref{Breakpoints}) at the beginning of the function or the section of
2171 the program in which a problem is believed to lie, run the program until
2172 it stops at that breakpoint, and then step through the suspect area,
2173 examining the variables that are interesting, until you see the problem
2174 happen.
2175
2176 The @samp{continue} command can be used after stepping to resume execution
2177 until the next breakpoint or signal.
2178
2179 @node Continuing,,,
2180 @section Continuing
2181
2182 After your program stops, most likely you will want it to run some more if
2183 the bug you are looking for has not happened yet.
2184
2185 @table @code
2186 @item continue
2187 @kindex continue
2188 Continue running the program at the place where it stopped.
2189 @end table
2190
2191 If the program stopped at a breakpoint, the place to continue running
2192 is the address of the breakpoint. You might expect that continuing would
2193 just stop at the same breakpoint immediately. In fact, @samp{continue}
2194 takes special care to prevent that from happening. You do not need
2195 to delete the breakpoint to proceed through it after stopping at it.
2196 You can, however, specify an ignore-count for the breakpoint that the
2197 program stopped at, by means of an argument to the @samp{continue} command.
2198 @xref{Conditions}.
2199
2200 If the program stopped because of a signal other than @code{SIGINT} or
2201 @code{SIGTRAP}, continuing will cause the program to see that signal.
2202 You may not want this to happen. For example, if the program stopped
2203 due to some sort of memory reference error, you might store correct
2204 values into the erroneous variables and continue, hoping to see more
2205 execution; but the program would probably terminate immediately as
2206 a result of the fatal signal once it sees the signal. To prevent this,
2207 you can continue with @samp{signal 0}. @xref{Signaling}. You can
2208 also act in advance to control what signals your program will see, using
2209 the @samp{handle} command (@pxref{Signals}).
2210
2211 @node Signals,,,
2212 @section Signals
2213 @cindex signals
2214
2215 A signal is an asynchronous event that can happen in a program. The
2216 operating system defines the possible kinds of signals, and gives each
2217 kind a name and a number. For example, in Unix @code{SIGINT} is the
2218 signal a program gets when you type an interrupt (often @kbd{C-c});
2219 @code{SIGSEGV} is the signal a program gets from referencing a place in
2220 memory far away from all the areas in use; @code{SIGALRM} occurs when
2221 the alarm clock timer goes off (which happens only if the program has
2222 requested an alarm).
2223
2224 @cindex fatal signals
2225 Some signals, including @code{SIGALRM}, are a normal part of the
2226 functioning of the program. Others, such as @code{SIGSEGV}, indicate
2227 errors; these signals are @dfn{fatal} (kill the program immediately) if the
2228 program has not specified in advance some other way to handle the signal.
2229 @code{SIGINT} does not indicate an error in the program, but it is normally
2230 fatal so it can carry out the purpose of the interrupt: to kill the program.
2231
2232 _GDBN__ has the ability to detect any occurrence of a signal in the program
2233 running under _GDBN__'s control. You can tell _GDBN__ in advance what to do for
2234 each kind of signal.
2235
2236 @cindex handling signals
2237 Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM}
2238 (so as not to interfere with their role in the functioning of the program)
2239 but to stop the program immediately whenever an error signal happens.
2240 You can change these settings with the @samp{handle} command.
2241
2242 @table @code
2243 @item info signals
2244 @kindex info signals
2245 Print a table of all the kinds of signals and how _GDBN__ has been told to
2246 handle each one. You can use this to see the signal numbers of all
2247 the defined types of signals.
2248
2249 @item handle @var{signal} @var{keywords}@dots{}
2250 @kindex handle
2251 Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the
2252 number of a signal or its name (with or without the @samp{SIG} at the
2253 beginning). The @var{keywords} say what change to make.
2254 @end table
2255
2256 @group
2257 The keywords allowed by the @samp{handle} command can be abbreviated.
2258 Their full names are:
2259
2260 @table @code
2261 @item nostop
2262 _GDBN__ should not stop the program when this signal happens. It may
2263 still print a message telling you that the signal has come in.
2264
2265 @item stop
2266 _GDBN__ should stop the program when this signal happens. This implies
2267 the @samp{print} keyword as well.
2268
2269 @item print
2270 _GDBN__ should print a message when this signal happens.
2271
2272 @item noprint
2273 _GDBN__ should not mention the occurrence of the signal at all. This
2274 implies the @samp{nostop} keyword as well.
2275
2276 @item pass
2277 _GDBN__ should allow the program to see this signal; the program will be
2278 able to handle the signal, or may be terminated if the signal is fatal
2279 and not handled.
2280
2281 @item nopass
2282 _GDBN__ should not allow the program to see this signal.
2283 @end table
2284 @end group
2285
2286 When a signal has been set to stop the program, the program cannot see the
2287 signal until you continue. It will see the signal then, if @samp{pass} is
2288 in effect for the signal in question @i{at that time}. In other words,
2289 after _GDBN__ reports a signal, you can use the @samp{handle} command with
2290 @samp{pass} or @samp{nopass} to control whether that signal will be seen by
2291 the program when you later continue it.
2292
2293 You can also use the @samp{signal} command to prevent the program from
2294 seeing a signal, or cause it to see a signal it normally would not see,
2295 or to give it any signal at any time. @xref{Signaling}.
2296
2297
2298 @node Stack,,,
2299 @chapter Examining the Stack
2300
2301 When your program has stopped, the first thing you need to know is where it
2302 stopped and how it got there.
2303
2304 @cindex call stack
2305 Each time your program performs a function call, the information about
2306 where in the program the call was made from is saved in a block of data
2307 called a @dfn{stack frame}. The frame also contains the arguments of the
2308 call and the local variables of the function that was called. All the
2309 stack frames are allocated in a region of memory called the @dfn{call
2310 stack}.
2311
2312 When your program stops, the _GDBN__ commands for examining the stack allow you
2313 to see all of this information.
2314
2315 @cindex selected frame
2316 One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands
2317 refer implicitly to the selected frame. In particular, whenever you ask
2318 _GDBN__ for the value of a variable in the program, the value is found in the
2319 selected frame. There are special _GDBN__ commands to select whichever frame
2320 you are interested in.
2321
2322 When the program stops, _GDBN__ automatically selects the currently executing
2323 frame and describes it briefly as the @samp{frame} command does
2324 (@pxref{Frame Info, Info}).
2325
2326 @node Frames,,,
2327 @section Stack Frames
2328
2329 @cindex frame
2330 @cindex stack frame
2331 The call stack is divided up into contiguous pieces called @dfn{stack
2332 frames}, or @dfn{frames} for short; each frame is the data associated
2333 with one call to one function. The frame contains the arguments given
2334 to the function, the function's local variables, and the address at
2335 which the function is executing.
2336
2337 @cindex initial frame
2338 @cindex outermost frame
2339 @cindex innermost frame
2340 When your program is started, the stack has only one frame, that of the
2341 function @code{main}. This is called the @dfn{initial} frame or the
2342 @dfn{outermost} frame. Each time a function is called, a new frame is
2343 made. Each time a function returns, the frame for that function invocation
2344 is eliminated. If a function is recursive, there can be many frames for
2345 the same function. The frame for the function in which execution is
2346 actually occurring is called the @dfn{innermost} frame. This is the most
2347 recently created of all the stack frames that still exist.
2348
2349 @cindex frame pointer
2350 Inside your program, stack frames are identified by their addresses. A
2351 stack frame consists of many bytes, each of which has its own address; each
2352 kind of computer has a convention for choosing one of those bytes whose
2353 address serves as the address of the frame. Usually this address is kept
2354 in a register called the @dfn{frame pointer register} while execution is
2355 going on in that frame.
2356
2357 @cindex frame number
2358 _GDBN__ assigns numbers to all existing stack frames, starting with
2359 @code{0} for the innermost frame, @code{1} for the frame that called it,
2360 and so on upward. These numbers do not really exist in your program;
2361 they are assigned by _GDBN__ to give you a way of designating stack
2362 frames in _GDBN__ commands.
2363
2364 @cindex frameless execution
2365 Some compilers allow functions to be compiled so that they operate
2366 without stack frames. (For example, the @code{_GCC__} option
2367 @samp{-fomit-frame-pointer} will generate functions without a frame.)
2368 This is occasionally done with heavily used library functions to save
2369 the frame setup time. _GDBN__ has limited facilities for dealing with
2370 these function invocations; if the innermost function invocation has no
2371 stack frame, _GDBN__ will give it a virtual stack frame of 0 and
2372 correctly allow tracing of the function call chain. Results are
2373 undefined if a function invocation besides the innermost one is
2374 frameless.
2375
2376 @node Backtrace,,,
2377 @section Backtraces
2378
2379 A backtrace is a summary of how the program got where it is. It shows one
2380 line per frame, for many frames, starting with the currently executing
2381 frame (frame zero), followed by its caller (frame one), and on up the
2382 stack.
2383
2384 @table @code
2385 @item backtrace
2386 @itemx bt
2387 @kindex backtrace
2388 @kindex bt
2389 Print a backtrace of the entire stack: one line per frame for all
2390 frames in the stack.
2391
2392 You can stop the backtrace at any time by typing the system interrupt
2393 character, normally @kbd{Control-C}.
2394
2395 @item backtrace @var{n}
2396 @itemx bt @var{n}
2397 Similar, but print only the innermost @var{n} frames.
2398
2399 @item backtrace -@var{n}
2400 @itemx bt -@var{n}
2401 Similar, but print only the outermost @var{n} frames.
2402 @end table
2403
2404 @kindex where
2405 @kindex info stack
2406 @kindex info s
2407 The names @code{where} and @code{info stack} (abbreviated @code{info s})
2408 are additional aliases for @code{backtrace}.
2409
2410 Each line in the backtrace shows the frame number and the function name.
2411 The program counter value is also shown---unless you use @samp{set
2412 print address off}. The backtrace also shows the source file name and
2413 line number, as well as the arguments to the function. The program
2414 counter value is omitted if it is at the beginning of the code for that
2415 line number.
2416
2417 Here is an example of a backtrace. It was made with the command
2418 @samp{bt 3}, so it shows the innermost three frames.
2419
2420 @smallexample
2421 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) at builtin.c:993
2422 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
2423 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
2424 at macro.c:71
2425 (More stack frames follow...)
2426 @end smallexample
2427
2428 @noindent
2429 The display for frame @code{#0} doesn't begin with a program counter
2430 value, indicating that the program has stopped at the beginning of the
2431 code for line @code{993} of @code{builtin.c}.
2432
2433 @node Selection,,,
2434 @section Selecting a Frame
2435
2436 Most commands for examining the stack and other data in the program work on
2437 whichever stack frame is selected at the moment. Here are the commands for
2438 selecting a stack frame; all of them finish by printing a brief description
2439 of the stack frame just selected.
2440
2441 @table @code
2442 @item frame @var{n}
2443 @itemx f @var{n}
2444 @kindex frame
2445 @kindex f
2446 Select frame number @var{n}. Recall that frame zero is the innermost
2447 (currently executing) frame, frame one is the frame that called the
2448 innermost one, and so on. The highest-numbered frame is @code{main}'s
2449 frame.
2450
2451 @item frame @var{addr}
2452 @itemx f @var{addr}
2453 Select the frame at address @var{addr}. This is useful mainly if the
2454 chaining of stack frames has been damaged by a bug, making it
2455 impossible for _GDBN__ to assign numbers properly to all frames. In
2456 addition, this can be useful when the program has multiple stacks and
2457 switches between them.
2458
2459 @item up @var{n}
2460 @kindex up
2461 Move @var{n} frames up the stack. For positive numbers @var{n}, this
2462 advances toward the outermost frame, to higher frame numbers, to frames
2463 that have existed longer. @var{n} defaults to one.
2464
2465 @item down @var{n}
2466 @kindex down
2467 @kindex do
2468 Move @var{n} frames down the stack. For positive numbers @var{n}, this
2469 advances toward the innermost frame, to lower frame numbers, to frames
2470 that were created more recently. @var{n} defaults to one. You may
2471 abbreviate @code{down} as @code{do}.
2472 @end table
2473
2474 All of these commands end by printing some information on the frame that
2475 has been selected: the frame number, the function name, the arguments, the
2476 source file and line number of execution in that frame, and the text of
2477 that source line. For example:
2478
2479 @smallexample
2480 (_GDBP__) up
2481 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) at env.c:10
2482 10 read_input_file (argv[i]);
2483 @end smallexample
2484
2485 After such a printout, the @samp{list} command with no arguments will print
2486 ten lines centered on the point of execution in the frame. @xref{List}.
2487
2488 @table @code
2489 @item up-silently @var{n}
2490 @itemx down-silently @var{n}
2491 @kindex down-silently
2492 @kindex up-silently
2493 These two commands are variants of @samp{up} and @samp{down},
2494 respectively; they differ in that they do their work silently, without
2495 causing display of the new frame. They are intended primarily for use
2496 in _GDBN__ command scripts, where the output might be unnecessary and
2497 distracting.
2498
2499 @end table
2500
2501 @node Frame Info,,,
2502 @section Information on a Frame
2503
2504 There are several other commands to print information about the selected
2505 stack frame.
2506
2507 @table @code
2508 @item frame
2509 @itemx f
2510 When used without any argument, this command does not change which frame
2511 is selected, but prints a brief description of the currently
2512 selected stack frame. It can be abbreviated @samp{f}. With an
2513 argument, this command is used to select a stack frame (@pxref{Selection}).
2514
2515 @item info frame
2516 @kindex info frame
2517 @itemx info f
2518 @kindex info f
2519 This command prints a verbose description of the selected stack frame,
2520 including the address of the frame, the addresses of the next frame down
2521 (called by this frame) and the next frame up (caller of this frame),
2522 the address of the frame's arguments, the program counter saved in it
2523 (the address of execution in the caller frame), and which registers
2524 were saved in the frame. The verbose description is useful when
2525 something has gone wrong that has made the stack format fail to fit
2526 the usual conventions.
2527
2528 @item info frame @var{addr}
2529 @itemx info f @var{addr}
2530 Print a verbose description of the frame at address @var{addr},
2531 without selecting that frame. The selected frame remains unchanged by
2532 this command.
2533
2534 @item info args
2535 @kindex info args
2536 Print the arguments of the selected frame, each on a separate line.
2537
2538 @item info locals
2539 @kindex info locals
2540 Print the local variables of the selected frame, each on a separate
2541 line. These are all variables declared static or automatic within all
2542 program blocks that execution in this frame is currently inside of.
2543
2544 @item info catch
2545 @kindex info catch
2546 @cindex catch exceptions
2547 @cindex exception handlers
2548 Print a list of all the exception handlers that are active in the
2549 current stack frame at the current point of execution. To see other
2550 exception handlers, visit the associated frame (using the @samp{up},
2551 @samp{down}, or @samp{frame} commands); then type @samp{info catch}.
2552 @xref{Exception Handling}.
2553 @end table
2554
2555 @node Source,,,
2556 @chapter Examining Source Files
2557
2558 _GDBN__ can print parts of your program's source, since the debugging
2559 information recorded in your program tells _GDBN__ what source files
2560 were used to built it. When your program stops, _GDBN__
2561 spontaneously prints the line where it stopped. Likewise, when you
2562 select a stack frame (@pxref{Selection}), _GDBN__ prints the line
2563 where execution in that frame has stopped. You can also
2564 print parts of source files by explicit command.
2565
2566 If you use _GDBN__ through its GNU Emacs interface, you may prefer to
2567 use Emacs facilities to view source; @pxref{Emacs}.
2568
2569 @node List,,,
2570 @section Printing Source Lines
2571
2572 @kindex list
2573 @kindex l
2574 To print lines from a source file, use the @samp{list} command
2575 (abbreviated @samp{l}). There are several ways to specify what part
2576 of the file you want to print.
2577
2578 Here are the forms of the @samp{list} command most commonly used:
2579
2580 @table @code
2581 @item list @var{linenum}
2582 Print ten lines centered around line number @var{linenum} in the
2583 current source file.
2584
2585 @item list @var{function}
2586 Print ten lines centered around the beginning of function
2587 @var{function}.
2588
2589 @item list
2590 Print ten more lines. If the last lines printed were printed with a
2591 @samp{list} command, this prints ten lines following the last lines
2592 printed; however, if the last line printed was a solitary line printed
2593 as part of displaying a stack frame (@pxref{Stack}), this prints ten
2594 lines centered around that line.
2595
2596 @item list -
2597 Print ten lines just before the lines last printed.
2598 @end table
2599
2600 Repeating a @samp{list} command with @key{RET} discards the argument,
2601 so it is equivalent to typing just @samp{list}. This is more useful
2602 than listing the same lines again. An exception is made for an
2603 argument of @samp{-}; that argument is preserved in repetition so that
2604 each repetition moves up in the source file.
2605
2606 @cindex linespec
2607 In general, the @samp{list} command expects you to supply zero, one or two
2608 @dfn{linespecs}. Linespecs specify source lines; there are several ways
2609 of writing them but the effect is always to specify some source line.
2610 Here is a complete description of the possible arguments for @samp{list}:
2611
2612 @table @code
2613 @item list @var{linespec}
2614 Print ten lines centered around the line specified by @var{linespec}.
2615
2616 @item list @var{first},@var{last}
2617 Print lines from @var{first} to @var{last}. Both arguments are
2618 linespecs.
2619
2620 @item list ,@var{last}
2621 Print ten lines ending with @var{last}.
2622
2623 @item list @var{first},
2624 Print ten lines starting with @var{first}.
2625
2626 @item list +
2627 Print ten lines just after the lines last printed.
2628
2629 @item list -
2630 Print ten lines just before the lines last printed.
2631
2632 @item list
2633 As described in the preceding table.
2634 @end table
2635
2636 Here are the ways of specifying a single source line---all the
2637 kinds of linespec.
2638
2639 @table @code
2640 @item @var{number}
2641 Specifies line @var{number} of the current source file.
2642 When a @samp{list} command has two linespecs, this refers to
2643 the same source file as the first linespec.
2644
2645 @item +@var{offset}
2646 Specifies the line @var{offset} lines after the last line printed.
2647 When used as the second linespec in a @samp{list} command that has
2648 two, this specifies the line @var{offset} lines down from the
2649 first linespec.
2650
2651 @item -@var{offset}
2652 Specifies the line @var{offset} lines before the last line printed.
2653
2654 @item @var{filename}:@var{number}
2655 Specifies line @var{number} in the source file @var{filename}.
2656
2657 @item @var{function}
2658 @c FIXME: "of the open-brace" is C-centric. When we add other langs...
2659 Specifies the line of the open-brace that begins the body of the
2660 function @var{function}.
2661
2662 @item @var{filename}:@var{function}
2663 Specifies the line of the open-brace that begins the body of the
2664 function @var{function} in the file @var{filename}. You only need the
2665 file name with a function name to avoid ambiguity when there are
2666 identically named functions in different source files.
2667
2668 @item *@var{address}
2669 Specifies the line containing the program address @var{address}.
2670 @var{address} may be any expression.
2671 @end table
2672
2673 @node Search,,,
2674 @section Searching Source Files
2675 @cindex searching
2676 @kindex reverse-search
2677
2678 There are two commands for searching through the current source file for a
2679 regular expression.
2680
2681 @table @code
2682 @item forward-search @var{regexp}
2683 @itemx search @var{regexp}
2684 @kindex search
2685 @kindex forward-search
2686 The command @samp{forward-search @var{regexp}} checks each line, starting
2687 with the one following the last line listed, for a match for @var{regexp}.
2688 It lists the line that is found. You can abbreviate the command name
2689 as @samp{fo}. The synonym @samp{search @var{regexp}} is also supported.
2690
2691 @item reverse-search @var{regexp}
2692 The command @samp{reverse-search @var{regexp}} checks each line, starting
2693 with the one before the last line listed and going backward, for a match
2694 for @var{regexp}. It lists the line that is found. You can abbreviate
2695 this command as @samp{rev}.
2696 @end table
2697
2698 @node Source Path,,,
2699 @section Specifying Source Directories
2700
2701 @cindex source path
2702 @cindex directories for source files
2703 Executable programs sometimes do not record the directories of the source
2704 files from which they were compiled, just the names. Even when they do,
2705 the directories could be moved between the compilation and your debugging
2706 session. _GDBN__ has a list of directories to search for source files;
2707 this is called the @dfn{source path}. Each time _GDBN__ wants a source file,
2708 it tries all the directories in the list, in the order they are present
2709 in the list, until it finds a file with the desired name. Note that
2710 the executable search path is @emph{not} used for this purpose. Neither is
2711 the current working directory, unless it happens to be in the source
2712 path.
2713
2714 If _GDBN__ can't find a source file in the source path, and the object
2715 program records a directory, _GDBN__ tries that directory too. If the
2716 source path is empty, and there is no record of the compilation
2717 directory, _GDBN__ will, as a last resort, look in the current
2718 directory.
2719
2720 Whenever you reset or rearrange the source path, _GDBN__ will clear out
2721 any information it has cached about where source files are found, where
2722 each line is in the file, etc.
2723
2724 @kindex directory
2725 When you start _GDBN__, its source path is empty.
2726 To add other directories, use the @samp{directory} command.
2727
2728 @table @code
2729 @item directory @var{dirname} @dots{}
2730 Add directory @var{dirname} to the front of the source path. Several
2731 directory names may be given to this command, separated by @samp{:} or
2732 whitespace. You may specify a directory that is already in the source
2733 path; this moves it forward, so it will be searched sooner. You can use
2734 the string @samp{$cwd} to refer to the current working directory, and
2735 @samp{$cdir} to refer to the compilation directory (if one is recorded).
2736
2737 @item directory
2738 Reset the source path to empty again. This requires confirmation.
2739
2740 The @samp{directory} command will not repeat if you press @key{RET} a
2741 second time after executing it once.
2742
2743 @item show directories
2744 @kindex show directories
2745 Print the source path: show which directories it contains.
2746 @end table
2747
2748 If your source path is cluttered with directories that are no longer of
2749 interest, _GDBN__ may sometimes cause confusion by finding the wrong
2750 versions of source. You can correct the situation as follows:
2751
2752 @enumerate
2753 @item
2754 Use @samp{directory} with no argument to reset the source path to empty.
2755
2756 @item
2757 Use @samp{directory} with suitable arguments to add any other
2758 directories you want in the source path. You can add all the directories
2759 in one command.
2760 @end enumerate
2761
2762 @node Machine Code,,,
2763 @section Source and Machine Code
2764 You can use the command @samp{info line} to map source lines to program
2765 addresses, and the command @samp{disassemble} or its synonym
2766 @samp{disasm} to display a range of addresses as machine instructions.
2767
2768 @table @code
2769 @item info line @var{linespec}
2770 @kindex info line
2771 Print the starting and ending addresses of the compiled code for
2772 source line @var{linespec}.
2773
2774 @kindex $_
2775 After @samp{info line}, the default address for the @samp{x}
2776 command is changed to the starting address of the line, so that
2777 @samp{x/i} is sufficient to begin examining the machine code
2778 (@pxref{Memory}). Also, this address is saved as the value of the
2779 convenience variable @code{$_} (@pxref{Convenience Vars}).
2780
2781 @kindex disassemble
2782 @kindex disasm
2783 @item disassemble
2784 @itemx disasm
2785 @c FIXME: "disasm" isn't currently in GDB. Should it be?
2786 This specialized command is provided to dump a range of memory as
2787 machine instructions. The default memory range is the function
2788 surrounding the program counter of the selected frame. A single
2789 argument to this command is a program counter value; the function
2790 surrounding this value will be dumped. Two arguments (separated by one
2791 or more spaces) specify a range of addresses (first inclusive, second
2792 exclusive) to be dumped. The two spellings, @samp{disasm} and
2793 @samp{disassemble}, are equivalent.
2794 @end table
2795
2796 @node Data,,,
2797 @chapter Examining Data
2798
2799 @cindex printing data
2800 @cindex examining data
2801 @kindex print
2802 @kindex inspect
2803 @c "inspect" isn't quite a synonym if you're using Epoch, which we don't
2804 @c document because it's nonstandard... Under Epoch it displays in a
2805 @c different window or something like that.
2806 The usual way to examine data in your program is with the @samp{print}
2807 command (abbreviated @samp{p}), or its synonym @samp{inspect}. It
2808 evaluates and prints the value of any valid expression of the language
2809 the program is written in (for now, C or C++). You type
2810
2811 @example
2812 print @var{exp}
2813 @end example
2814
2815 @noindent
2816 where @var{exp} is any valid expression (in the source language), and
2817 the value of @var{exp} is printed in a format appropriate to its data
2818 type.
2819
2820 A more low-level way of examining data is with the @samp{x} command.
2821 It examines data in memory at a specified address and prints it in a
2822 specified format. @xref{Memory}.
2823
2824 @node Expressions,,,
2825 @section Expressions
2826
2827 @cindex expressions
2828 @code{print} and many other _GDBN__ commands accept an expression and
2829 compute its value. Any kind of constant, variable or operator defined
2830 by the programming language you are using is legal in an expression in
2831 _GDBN__. This includes conditional expressions, function calls, casts
2832 and string constants. It unfortunately does not include symbols defined
2833 by preprocessor @code{#define} commands, or C++ expressions involving
2834 @samp{::}, the name resolution operator.
2835 @c FIXME: actually C++ a::b works except in obscure circumstances where it
2836 @c FIXME...can conflict with GDB's own name scope resolution.
2837
2838 Casts are supported in all languages, not just in C, because it is so
2839 useful to cast a number into a pointer so as to examine a structure
2840 at that address in memory.
2841
2842 _GDBN__ supports three kinds of operator in addition to those of programming
2843 languages:
2844
2845 @table @code
2846 @item @@
2847 @samp{@@} is a binary operator for treating parts of memory as arrays.
2848 @xref{Arrays}, for more information.
2849
2850 @item ::
2851 @samp{::} allows you to specify a variable in terms of the file or
2852 function where it is defined. @xref{Variables}.
2853
2854 @item @{@var{type}@} @var{addr}
2855 Refers to an object of type @var{type} stored at address @var{addr} in
2856 memory. @var{addr} may be any expression whose value is an integer or
2857 pointer (but parentheses are required around binary operators, just as in
2858 a cast). This construct is allowed regardless of what kind of data is
2859 officially supposed to reside at @var{addr}.@refill
2860 @end table
2861
2862 @node Variables,,,
2863 @section Program Variables
2864
2865 The most common kind of expression to use is the name of a variable
2866 in your program.
2867
2868 Variables in expressions are understood in the selected stack frame
2869 (@pxref{Selection}); they must either be global (or static) or be visible
2870 according to the scope rules of the programming language from the point of
2871 execution in that frame. This means that in the function
2872
2873 @example
2874 foo (a)
2875 int a;
2876 @{
2877 bar (a);
2878 @{
2879 int b = test ();
2880 bar (b);
2881 @}
2882 @}
2883 @end example
2884
2885 @noindent
2886 the variable @code{a} is usable whenever the program is executing
2887 within the function @code{foo}, but the variable @code{b} is visible
2888 only while the program is executing inside the block in which @code{b}
2889 is declared.
2890
2891 There is an exception: you can refer to a variable or function whose
2892 scope is a single source file even if the current execution point is not
2893 in this file. But it is possible to have more than one such variable or
2894 function with the same name (in different source files). If that happens,
2895 referring to that name has unpredictable effects. If you wish, you can
2896 specify a variable in a particular file, using the colon-colon construct:
2897
2898 @cindex colon-colon
2899 @cindex scope
2900 @kindex ::
2901 @example
2902 @var{block}::@var{variable}
2903 @end example
2904
2905 @noindent
2906 Here @var{block} is the name of the source file whose variable you want.
2907
2908 @cindex name resolution (C++)
2909 Unfortunately, this use of @samp{::} conflicts with the very similar use
2910 of the same notation in C++; accordingly, _GDBN__ does not support use of
2911 the C++ name resolution operator in _GDBN__ expressions.
2912
2913 @node Arrays,,,
2914 @section Artificial Arrays
2915
2916 @cindex artificial array
2917 @kindex @@
2918 It is often useful to print out several successive objects of the
2919 same type in memory; a section of an array, or an array of
2920 dynamically determined size for which only a pointer exists in the
2921 program.
2922
2923 This can be done by constructing an @dfn{artificial array} with the
2924 binary operator @samp{@@}. The left operand of @samp{@@} should be
2925 the first element of the desired array, as an individual object.
2926 The right operand should be the length of the array. The result is
2927 an array value whose elements are all of the type of the left argument.
2928 The first element is actually the left argument; the second element
2929 comes from bytes of memory immediately following those that hold the
2930 first element, and so on. Here is an example. If a program says
2931
2932 @example
2933 int *array = (int *) malloc (len * sizeof (int));
2934 @end example
2935
2936 @noindent
2937 you can print the contents of @code{array} with
2938
2939 @example
2940 p *array@@len
2941 @end example
2942
2943 The left operand of @samp{@@} must reside in memory. Array values made
2944 with @samp{@@} in this way behave just like other arrays in terms of
2945 subscripting, and are coerced to pointers when used in expressions.
2946 Artificial arrays most often appear in expressions via the value history
2947 (@pxref{Value History}), after printing one out.)
2948
2949 @node Output formats,,,
2950 @section Output formats
2951
2952 @cindex formatted output
2953 @cindex output formats
2954 By default, _GDBN__ prints a value according to its data type. Sometimes
2955 this is not what you want. For example, you might want to print a number
2956 in hex, or a pointer in decimal. Or you might want to view data in memory
2957 at a certain address as a character string or as an instruction. To do
2958 these things, specify an @dfn{output format} when you print a value.
2959
2960 The simplest use of output formats is to say how to print a value
2961 already computed. This is done by starting the arguments of the
2962 @samp{print} command with a slash and a format letter. The format
2963 letters supported are:
2964
2965 @table @samp
2966 @item x
2967 Regard the bits of the value as an integer, and print the integer in
2968 hexadecimal.
2969
2970 @item d
2971 Print as integer in signed decimal.
2972
2973 @item u
2974 Print as integer in unsigned decimal.
2975
2976 @item o
2977 Print as integer in octal.
2978
2979 @item t
2980 Print as integer in binary. The letter @samp{t} stands for ``two'', as
2981 in base two.
2982
2983 @item a
2984 Print as an address, both absolute in hex and as an offset from the
2985 nearest preceding symbol. This format can be used to discover where (in
2986 what function) an unknown address is located:
2987 @example
2988 (_GDBP__) p/a 0x54320
2989 _0__$3 = 0x54320 <_initialize_vx+396>_1__
2990 @end example
2991
2992
2993 @item c
2994 Regard as an integer and print it as a character constant.
2995
2996 @item f
2997 Regard the bits of the value as a floating point number and print
2998 using typical floating point syntax.
2999 @end table
3000
3001 For example, to print the program counter in hex (@pxref{Registers}), type
3002
3003 @example
3004 p/x $pc
3005 @end example
3006
3007 @noindent
3008 Note that no space is required before the slash; this is because command
3009 names in _GDBN__ cannot contain a slash.
3010
3011 To reprint the last value in the value history with a different format,
3012 you can use the @samp{print} command with just a format and no
3013 expression. For example, @samp{p/x} reprints the last value in hex.
3014
3015 @node Memory,,,
3016 @section Examining Memory
3017
3018 @cindex examining memory
3019 @table @code
3020 @kindex x
3021 @item x/@var{Nuf} @var{expr}
3022 The command @samp{x} (for `examine') can be used to examine memory
3023 without being constrained by your program's data types. You can specify
3024 the unit size @var{u} of memory to inspect, and a repeat count @var{N} of how
3025 many of those units to display. @samp{x} understands the formats
3026 @var{f} used by @samp{print}; two additional formats, @samp{s} (string)
3027 and @samp{i} (machine instruction) can be used without specifying a unit
3028 size.
3029 @end table
3030
3031 For example, @samp{x/3hu 0x54320} is a request to display three halfwords
3032 (@code{h}) of memory, formatted as unsigned decimal integers (@code{u}),
3033 starting at address @code{0x54320}. @samp{x/4wx $sp} prints the four
3034 words (@code{w}) of memory above the stack pointer (here, @samp{$sp};
3035 @pxref{Registers}) in hexadecimal (@code{x}).
3036
3037 Since the letters indicating unit sizes are all distinct from the
3038 letters specifying output formats, you don't have to remember whether
3039 unit size or format comes first; either order will work. The output
3040 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
3041
3042 After the format specification, you indicate the address where _GDBN__
3043 is to begin reading memory for display, using an expression. The
3044 expression need not have a pointer value (though it may); it is always
3045 interpreted as an integer address of a byte of memory.
3046 @xref{Expressions} for more information on expressions.
3047
3048 These are the memory units @var{u} you can specify with @samp{x}:
3049
3050 @table @samp
3051 @item b
3052 Examine individual bytes.
3053
3054 @item h
3055 Examine halfwords (two bytes each).
3056
3057 @item w
3058 Examine words (four bytes each).
3059
3060 @cindex word
3061 Many assemblers and cpu designers still use `word' for a 16-bit quantity,
3062 as a holdover from specific predecessor machines of the 1970's that really
3063 did use two-byte words. But more generally the term `word' has always
3064 referred to the size of quantity that a machine normally operates on and
3065 stores in its registers. This is 32 bits for all the machines that _GDBN__
3066 runs on.
3067
3068 @item g
3069 Examine giant words (8 bytes).
3070 @end table
3071
3072 You can combine these unit specifications with any of the formats
3073 described for @samp{print}. @xref{Output formats}.
3074
3075 @samp{x} has two additional output specifications which derive the unit
3076 size from the data inspected:
3077
3078 @table @samp
3079 @item s
3080 Print a null-terminated string of characters. Any explicitly specified
3081 unit size is ignored; instead, the unit is however many bytes it takes
3082 to reach a null character (including the null character).
3083
3084 @item i
3085 Print a machine instruction in assembler syntax (or nearly). Any
3086 specified unit size is ignored; the number of bytes in an instruction
3087 varies depending on the type of machine, the opcode and the addressing
3088 modes used. The command @samp{disassemble} gives an alternative way of
3089 inspecting machine instructions. @xref{Machine Code}.
3090 @end table
3091
3092 If you omit either the format @var{f} or the unit size @var{u}, @samp{x}
3093 will use the same one that was used last. If you don't use any letters
3094 after the slash, you can omit the slash as well.
3095
3096 You can also omit the address to examine. Then the address used is just
3097 after the last unit examined. This is why string and instruction
3098 formats actually compute a unit-size based on the data: so that the next
3099 string or instruction examined will start in the right place.
3100
3101 When the @samp{print} command shows a value that resides in memory,
3102 @samp{print} also sets the default address for the @samp{x} command.
3103 @samp{info line} also sets the default for @samp{x}, to the address of
3104 the start of the machine code for the specified line (@pxref{Machine
3105 Code}), and @samp{info breakpoints} sets it to the address of the last
3106 breakpoint listed (@pxref{Set Breaks}).
3107
3108 When you use @key{RET} to repeat an @samp{x} command, the address
3109 specified previously (if any) is ignored, so that the repeated command
3110 examines the successive locations in memory rather than the same ones.
3111
3112 You can examine several consecutive units of memory with one command by
3113 writing a repeat-count after the slash (before the format letters, if
3114 any). Omitting the repeat count @var{N} displays one unit of the
3115 appropriate size. The repeat count must be a decimal integer. It has
3116 the same effect as repeating the @samp{x} command @var{N} times except
3117 that the output may be more compact, with several units per line. For
3118 example,
3119
3120 @example
3121 x/10i $pc
3122 @end example
3123
3124 @noindent
3125 prints ten instructions starting with the one to be executed next in the
3126 selected frame. After doing this, you could print a further seven
3127 instructions with
3128
3129 @example
3130 x/7
3131 @end example
3132
3133 @noindent
3134 ---where the format and address are allowed to default.
3135
3136 @kindex $_
3137 @kindex $__
3138 The addresses and contents printed by the @samp{x} command are not put
3139 in the value history because there is often too much of them and they
3140 would get in the way. Instead, _GDBN__ makes these values available for
3141 subsequent use in expressions as values of the convenience variables
3142 @code{$_} and @code{$__}. After an @samp{x} command, the last address
3143 examined is available for use in expressions in the convenience variable
3144 @code{$_}. The contents of that address, as examined, are available in
3145 the convenience variable @code{$__}.
3146
3147 If the @samp{x} command has a repeat count, the address and contents saved
3148 are from the last memory unit printed; this is not the same as the last
3149 address printed if several units were printed on the last line of output.
3150
3151 @node Auto Display,,,
3152 @section Automatic Display
3153 @cindex automatic display
3154 @cindex display of expressions
3155
3156 If you find that you want to print the value of an expression frequently
3157 (to see how it changes), you might want to add it to the @dfn{automatic
3158 display list} so that _GDBN__ will print its value each time the program stops.
3159 Each expression added to the list is given a number to identify it;
3160 to remove an expression from the list, you specify that number.
3161 The automatic display looks like this:
3162
3163 @example
3164 2: foo = 38
3165 3: bar[5] = (struct hack *) 0x3804
3166 @end example
3167
3168 @noindent
3169 showing item numbers, expressions and their current values. As with
3170 displays you request manually using @samp{x} or @samp{print}, you can
3171 specify the output format you prefer; in fact, @dfn{display} decides
3172 whether to use @code{print} or @code{x} depending on how elaborate your
3173 format specification is---it uses @code{x} if you specify a unit size,
3174 or one of the two formats (@samp{i} and @samp{s}) that are only
3175 supported by @code{x}; otherwise it uses @code{print}.
3176
3177 @table @code
3178 @item display @var{exp}
3179 @kindex display
3180 Add the expression @var{exp} to the list of expressions to display
3181 each time the program stops. @xref{Expressions}.
3182
3183 @samp{display} will not repeat if you press @key{RET} again after using it.
3184
3185 @item display/@var{fmt} @var{exp}
3186 For @var{fmt} specifying only a display format and not a size or
3187 count, add the expression @var{exp} to the auto-display list but
3188 arranges to display it each time in the specified format @var{fmt}.
3189 @xref{Output formats}.
3190
3191 @item display/@var{fmt} @var{addr}
3192 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3193 number of units, add the expression @var{addr} as a memory address to
3194 be examined each time the program stops. Examining means in effect
3195 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}.
3196 @end table
3197
3198 For example, @samp{display/i $pc} can be helpful, to see the machine
3199 instruction about to be executed each time execution stops (@samp{$pc}
3200 is a common name for the program counter; @pxref{Registers}).
3201
3202 @table @code
3203 @item undisplay @var{dnums}@dots{}
3204 @itemx delete display @var{dnums}@dots{}
3205 @kindex delete display
3206 @kindex undisplay
3207 Remove item numbers @var{dnums} from the list of expressions to display.
3208
3209 @samp{undisplay} will not repeat if you press @key{RET} after using it.
3210
3211 @item disable display @var{dnums}@dots{}
3212 @kindex disable display
3213 Disable the display of item numbers @var{dnums}. A disabled display
3214 item is not printed automatically, but is not forgotten. It may be
3215 enabled again later.
3216
3217 @item enable display @var{dnums}@dots{}
3218 @kindex enable display
3219 Enable display of item numbers @var{dnums}. It becomes effective once
3220 again in auto display of its expression, until you specify otherwise.
3221
3222 @item display
3223 Display the current values of the expressions on the list, just as is
3224 done when the program stops.
3225
3226 @item info display
3227 @kindex info display
3228 Print the list of expressions previously set up to display
3229 automatically, each one with its item number, but without showing the
3230 values. This includes disabled expressions, which are marked as such.
3231 It also includes expressions which would not be displayed right now
3232 because they refer to automatic variables not currently available.
3233 @end table
3234
3235 If a display expression refers to local variables, then it does not make
3236 sense outside the lexical context for which it was set up. Such an
3237 expression is disabled when execution enters a context where one of its
3238 variables is not defined. For example, if you give the command
3239 @samp{display name} while inside a function with an argument
3240 @code{name}, then this argument will be displayed while the program
3241 continues to stop inside that function. When it stops elsewhere---where
3242 there is no variable @samp{name}---display is disabled. The next time
3243 your program stops where @samp{name} is meaningful, you can enable the
3244 display expression once again.
3245
3246 @node Print Settings,,,
3247 @section Print Settings
3248
3249 @cindex format options
3250 @cindex print settings
3251 _GDBN__ provides the following ways to control how arrays, structures,
3252 and symbols are printed.
3253
3254 @noindent
3255 These settings are useful for debugging programs in any language:
3256
3257 @table @code
3258 @item set print address
3259 @item set print address on
3260 @kindex set print address
3261 _GDBN__ will print memory addresses in stack traces, structure values, pointer
3262 values, breakpoints, etc. The default is on.
3263
3264 @item set print address off
3265 Do not print addresses.
3266
3267 @item show print address
3268 @kindex show print address
3269 Show whether or not addresses are to be printed.
3270
3271 @item set print array
3272 @itemx set print array on
3273 @kindex set print array
3274 _GDBN__ will pretty print arrays. This format is more convenient to read,
3275 but uses more space. The default is off.
3276
3277 @item set print array off.
3278 Return to compressed format for arrays.
3279
3280 @item show print array
3281 @kindex show print array
3282 Show whether compressed or pretty format is selected for displaying
3283 arrays.
3284
3285 @item set print elements @var{number-of-elements}
3286 @kindex set print elements
3287 If _GDBN__ is printing a large array, it will stop printing after it has
3288 printed the number of elements set by the @samp{set print elements} command.
3289 This limit also applies to the display of strings.
3290
3291 @item show print elements
3292 @kindex show print elements
3293 Display the number of elements of a large array that _GDBN__ will print
3294 before losing patience.
3295
3296 @item set print pretty on
3297 @kindex set print pretty
3298 Cause _GDBN__ to print structures in an indented format with one member per
3299 line, like this:
3300
3301 @example
3302 $1 = @{
3303 next = 0x0,
3304 flags = @{
3305 sweet = 1,
3306 sour = 1
3307 @},
3308 meat = 0x54 "Pork"
3309 @}
3310 @end example
3311
3312 @item set print pretty off
3313 Cause _GDBN__ to print structures in a compact format, like this:
3314
3315 @smallexample
3316 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \
3317 = 0x54 "Pork"@}
3318 @end smallexample
3319
3320 @noindent
3321 This is the default format.
3322
3323 @item show print pretty
3324 @kindex show print pretty
3325 Show which format _GDBN__ will use to print structures.
3326
3327 @item set print sevenbit-strings on
3328 Print using only seven-bit characters; if this option is set,
3329 _GDBN__ will display any eight-bit characters (in strings or character
3330 values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
3331 displayed as @code{\341}.
3332
3333 @item set print sevenbit-strings off
3334 Print using either seven-bit or eight-bit characters, as required. This
3335 is the default.
3336
3337 @item show print sevenbit-strings
3338 Show whether or not _GDBN__ will print only seven-bit characters.
3339
3340 @item set print union on
3341 @kindex set print union
3342 Tell _GDBN__ to print unions which are contained in structures. This is the
3343 default setting.
3344
3345 @item set print union off
3346 Tell _GDBN__ not to print unions which are contained in structures.
3347
3348 @item show print union
3349 @kindex show print union
3350 Ask _GDBN__ whether or not it will print unions which are contained in
3351 structures.
3352
3353 For example, given the declarations
3354
3355 @smallexample
3356 typedef enum @{Tree, Bug@} Species;
3357 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
3358 typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms;
3359
3360 struct thing @{
3361 Species it;
3362 union @{
3363 Tree_forms tree;
3364 Bug_forms bug;
3365 @} form;
3366 @};
3367
3368 struct thing foo = @{Tree, @{Acorn@}@};
3369 @end smallexample
3370
3371 @noindent
3372 with @samp{set print union on} in effect @samp{p foo} would print
3373
3374 @smallexample
3375 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
3376 @end smallexample
3377
3378 @noindent
3379 and with @samp{set print union off} in effect it would print
3380
3381 @smallexample
3382 $1 = @{it = Tree, form = @{...@}@}
3383 @end smallexample
3384 @end table
3385
3386 @noindent
3387 These settings are of interest when debugging C++ programs:
3388
3389 @table @code
3390 @item set print demangle
3391 @itemx set print demangle on
3392 @kindex set print demangle
3393 Print C++ names in their source form rather than in the mangled form
3394 in which they are passed to the assembler and linker for type-safe linkage.
3395 The default is on.
3396
3397 @item show print demangle
3398 @kindex show print demangle
3399 Show whether C++ names will be printed in mangled or demangled form.
3400
3401 @item set print asm-demangle
3402 @itemx set print asm-demangle on
3403 @kindex set print asm-demangle
3404 Print C++ names in their source form rather than their mangled form, even
3405 in assembler code printouts such as instruction disassemblies.
3406 The default is off.
3407
3408 @item show print asm-demangle
3409 @kindex show print asm-demangle
3410 Show whether C++ names in assembly listings will be printed in mangled
3411 or demangled form.
3412
3413 @item set print object
3414 @itemx set print object on
3415 @kindex set print object
3416 When displaying a pointer to an object, identify the @emph{actual}
3417 (derived) type of the object rather than the @emph{declared} type, using
3418 the virtual function table.
3419
3420 @item set print object off
3421 Display only the declared type of objects, without reference to the
3422 virtual function table. This is the default setting.
3423
3424 @item show print object
3425 @kindex show print object
3426 Show whether actual, or declared, object types will be displayed.
3427
3428 @item set print vtbl
3429 @itemx set print vtbl on
3430 @kindex set print vtbl
3431 Pretty print C++ virtual function tables. The default is off.
3432
3433 @item set print vtbl off
3434 Do not pretty print C++ virtual function tables.
3435
3436 @item show print vtbl
3437 @kindex show print vtbl
3438 Show whether C++ virtual function tables are pretty printed, or not.
3439
3440 @end table
3441
3442 @node Value History,,,
3443 @section Value History
3444
3445 @cindex value history
3446 Values printed by the @samp{print} command are saved in _GDBN__'s @dfn{value
3447 history} so that you can refer to them in other expressions. Values are
3448 kept until the symbol table is re-read or discarded (for example with
3449 the @samp{file} or @samp{symbol-file} commands). When the symbol table
3450 changes, the value history is discarded, since the values may contain
3451 pointers back to the types defined in the symbol table.
3452
3453 @cindex @code{$}
3454 @cindex @code{$$}
3455 @cindex history number
3456 The values printed are given @dfn{history numbers} for you to refer to them
3457 by. These are successive integers starting with 1. @samp{print} shows you
3458 the history number assigned to a value by printing @samp{$@var{num} = }
3459 before the value; here @var{num} is the history number.
3460
3461 To refer to any previous value, use @samp{$} followed by the value's
3462 history number. The way @samp{print} labels its output is designed to
3463 remind you of this. Just @code{$} refers to the most recent value in
3464 the history, and @code{$$} refers to the value before that.
3465 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
3466 is the value just prior to @code{$$}, @code{$$1} is equivalent to
3467 @code{$$}, and @code{$$0} is equivalent to @code{$}.
3468
3469 For example, suppose you have just printed a pointer to a structure and
3470 want to see the contents of the structure. It suffices to type
3471
3472 @example
3473 p *$
3474 @end example
3475
3476 If you have a chain of structures where the component @samp{next} points
3477 to the next one, you can print the contents of the next one with this:
3478
3479 @example
3480 p *$.next
3481 @end example
3482
3483 @noindent
3484 You can print successive links in the chain by repeating this
3485 command---which you can do by just typing @key{RET}.
3486
3487 Note that the history records values, not expressions. If the value of
3488 @code{x} is 4 and you type these commands:
3489
3490 @example
3491 print x
3492 set x=5
3493 @end example
3494
3495 @noindent
3496 then the value recorded in the value history by the @samp{print} command
3497 remains 4 even though the value of @code{x} has changed.
3498
3499 @table @code
3500 @kindex show values
3501 @item show values
3502 Print the last ten values in the value history, with their item numbers.
3503 This is like @samp{p@ $$9} repeated ten times, except that @samp{show
3504 values} does not change the history.
3505
3506 @item show values @var{n}
3507 Print ten history values centered on history item number @var{n}.
3508
3509 @item show values +
3510 Print ten history values just after the values last printed.
3511 @end table
3512
3513 @node Convenience Vars,,,
3514 @section Convenience Variables
3515
3516 @cindex convenience variables
3517 _GDBN__ provides @dfn{convenience variables} that you can use within
3518 _GDBN__ to hold on to a value and refer to it later. These variables
3519 exist entirely within _GDBN__; they are not part of your program, and
3520 setting a convenience variable has no direct effect on further execution
3521 of your program. That's why you can use them freely.
3522
3523 Convenience variables have names starting with @samp{$}. Any name starting
3524 with @samp{$} can be used for a convenience variable, unless it is one of
3525 the predefined machine-specific register names (@pxref{Registers}).
3526
3527 You can save a value in a convenience variable with an assignment
3528 expression, just as you would set a variable in your program. Example:
3529
3530 @example
3531 set $foo = *object_ptr
3532 @end example
3533
3534 @noindent
3535 would save in @code{$foo} the value contained in the object pointed to by
3536 @code{object_ptr}.
3537
3538 Using a convenience variable for the first time creates it; but its value
3539 is @code{void} until you assign a new value. You can alter the value with
3540 another assignment at any time.
3541
3542 Convenience variables have no fixed types. You can assign a convenience
3543 variable any type of value, including structures and arrays, even if
3544 that variable already has a value of a different type. The convenience
3545 variable, when used as an expression, has the type of its current value.
3546
3547 @table @code
3548 @item show convenience
3549 @kindex show convenience
3550 Print a list of convenience variables used so far, and their values.
3551 Abbreviated @samp{i con}.
3552 @end table
3553
3554 One of the ways to use a convenience variable is as a counter to be
3555 incremented or a pointer to be advanced. For example, to print
3556 a field from successive elements of an array of structures:
3557
3558 _0__@example
3559 set $i = 0
3560 print bar[$i++]->contents
3561 @i{@dots{} repeat that command by typing @key{RET}.}
3562 _1__@end example
3563
3564 Some convenience variables are created automatically by _GDBN__ and given
3565 values likely to be useful.
3566
3567 @table @code
3568 @item $_
3569 The variable @code{$_} is automatically set by the @samp{x} command to
3570 the last address examined (@pxref{Memory}). Other commands which
3571 provide a default address for @samp{x} to examine also set @code{$_}
3572 to that address; these commands include @samp{info line} and @samp{info
3573 breakpoint}.
3574
3575 @item $__
3576 The variable @code{$__} is automatically set by the @samp{x} command
3577 to the value found in the last address examined.
3578 @end table
3579
3580 @node Registers,,,
3581 @section Registers
3582
3583 @cindex registers
3584 Machine register contents can be referred to in expressions as variables
3585 with names starting with @samp{$}. The names of registers are different
3586 for each machine; use @samp{info registers} to see the names used on
3587 your machine. The names @code{$pc} and @code{$sp} are used on most
3588 machines for the program counter register and the stack pointer. Often
3589 @code{$fp} is used for a register that contains a pointer to the current
3590 stack frame, and @code{$ps} is sometimes used for a register that
3591 contains the processor status. These standard register names may be
3592 available on your machine even though the @code{info registers} command
3593 shows other names. For example, on the SPARC, @code{info registers}
3594 displays the processor status register as @code{$psr} but you can also
3595 refer to it as @code{$ps}.
3596
3597 _GDBN__ always considers the contents of an ordinary register as an
3598 integer when the register is examined in this way. Some machines have
3599 special registers which can hold nothing but floating point; these
3600 registers are considered to have floating point values. There is no way
3601 to refer to the contents of an ordinary register as floating point value
3602 (although you can @emph{print} it as a floating point value with
3603 @samp{print/f $@var{regname}}).
3604
3605 Some registers have distinct ``raw'' and ``virtual'' data formats. This
3606 means that the data format in which the register contents are saved by
3607 the operating system is not the same one that your program normally
3608 sees. For example, the registers of the 68881 floating point
3609 coprocessor are always saved in ``extended'' (raw) format, but all C
3610 programs expect to work with ``double'' (virtual) format. In such
3611 cases, _GDBN__ normally works with the virtual format only (the format that
3612 makes sense for your program), but the @samp{info registers} command
3613 prints the data in both formats.
3614
3615 Normally, register values are relative to the selected stack frame
3616 (@pxref{Selection}). This means that you get the value that the register
3617 would contain if all stack frames farther in were exited and their saved
3618 registers restored. In order to see the contents of hardware registers,
3619 you must select the innermost frame (with @samp{frame 0}).
3620
3621 However, _GDBN__ must deduce where registers are saved, from the machine
3622 code generated by your compiler. If some registers are not saved, or if
3623 _GDBN__ is unable to locate the saved registers, the selected stack
3624 frame will make no difference.
3625
3626 @table @code
3627 @item info registers
3628 @kindex info registers
3629 Print the names and values of all registers (in the selected stack frame).
3630
3631 @item info registers @var{regname}
3632 Print the relativized value of register @var{regname}. @var{regname}
3633 may be any register name valid on the machine you are using, with
3634 or without the initial @samp{$}.
3635 @end table
3636
3637 For example, you could print the program counter in hex with
3638
3639 @example
3640 p/x $pc
3641 @end example
3642
3643 @noindent
3644 or print the instruction to be executed next with
3645
3646 @example
3647 x/i $pc
3648 @end example
3649
3650 @noindent
3651 or add four to the stack pointer with
3652
3653 @example
3654 set $sp += 4
3655 @end example
3656
3657 @noindent
3658 The last is a way of removing one word from the stack, on machines where
3659 stacks grow downward in memory (most machines, nowadays). This assumes
3660 that the innermost stack frame is selected. Setting @code{$sp} is
3661 not allowed when other stack frames are selected. (To pop entire frames
3662 off the stack, regardless of machine architecture, use @samp{return};
3663 @pxref{Returning}.)
3664
3665 @node Floating Point Hardware,,,
3666 @section Floating Point Hardware
3667 @cindex floating point
3668 Depending on the host machine architecture, _GDBN__ may be able to give
3669 you more information about the status of the floating point hardware.
3670
3671 @table @code
3672 @item info float
3673 @kindex info float
3674 If available, provides hardware-dependent information about the floating
3675 point unit. The exact contents and layout vary depending on the
3676 floating point chip.
3677 @end table
3678 @c FIXME: this is a cop-out. Try to get examples, explanations. Only
3679 @c FIXME...supported currently on arm's and 386's. Mark properly with
3680 @c FIXME... m4 macros to isolate general statements from hardware-dep,
3681 @c FIXME... at that point.
3682
3683 @node Symbols,,,
3684 @chapter Examining the Symbol Table
3685
3686 The commands described in this section allow you to inquire about the
3687 symbols (names of variables, functions and types) defined in your
3688 program. This information is inherent in the text of your program and
3689 does not change as the program executes. _GDBN__ finds it in your
3690 program's symbol table, as indicated when you started _GDBN__
3691 (@pxref{File Options}), or by one of the file-management commands
3692 (@pxref{Files}).
3693
3694 @table @code
3695 @item info address @var{symbol}
3696 @kindex info address
3697 Describe where the data for @var{symbol} is stored. For a register
3698 variable, this says which register it is kept in. For a non-register
3699 local variable, this prints the stack-frame offset at which the variable
3700 is always stored.
3701
3702 Note the contrast with @samp{print &@var{symbol}}, which does not work
3703 at all for a register variables, and for a stack local variable prints
3704 the exact address of the current instantiation of the variable.
3705
3706 @item whatis @var{exp}
3707 @kindex whatis
3708 Print the data type of expression @var{exp}. @var{exp} is not
3709 actually evaluated, and any side-effecting operations (such as
3710 assignments or function calls) inside it do not take place.
3711 @xref{Expressions}.
3712
3713 @item whatis
3714 Print the data type of @code{$}, the last value in the value history.
3715
3716 @item ptype @var{typename}
3717 @kindex ptype
3718 Print a description of data type @var{typename}. @var{typename} may be
3719 the name of a type, or for C code it may have the form
3720 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
3721 @samp{enum @var{enum-tag}}.@refill
3722
3723 @item ptype @var{exp}
3724 Print a description of the type of expression @var{exp}. @samp{ptype}
3725 differs from @samp{whatis} by printing a detailed description, instead of just
3726 the name of the type. For example, if your program declares a variable
3727 as
3728 @example
3729 struct complex {double real; double imag;} v;
3730 @end example
3731 @noindent
3732 compare the output of the two commands:
3733 @example
3734 (_GDBP__) whatis v
3735 type = struct complex
3736 (_GDBP__) ptype v
3737 type = struct complex {
3738 double real;
3739 double imag;
3740 }
3741 @end example
3742
3743 @item info types @var{regexp}
3744 @itemx info types
3745 @kindex info types
3746 Print a brief description of all types whose name matches @var{regexp}
3747 (or all types in your program, if you supply no argument). Each
3748 complete typename is matched as though it were a complete line; thus,
3749 @samp{i type value} gives information on all types in your program whose
3750 name includes the string @samp{value}, but @samp{i type ^value$} gives
3751 information only on types whose complete name is @samp{value}.
3752
3753 This command differs from @code{ptype} in two ways: first, like
3754 @code{whatis}, it does not print a detailed description; second, it
3755 lists all source files where a type is defined.
3756
3757 @item info source
3758 @kindex info source
3759 Show the name of the current source file---that is, the source file for
3760 the function containing the current point of execution.
3761
3762 @item info sources
3763 @kindex info sources
3764 Print the names of all source files in the program for which there is
3765 debugging information, organized into two lists: those for which symbols
3766 have been read in, and those for which symbols will be read in on
3767 demand.
3768 @c FIXME: above passive AND awkward!
3769
3770 @item info functions
3771 @kindex info functions
3772 Print the names and data types of all defined functions.
3773
3774 @item info functions @var{regexp}
3775 Print the names and data types of all defined functions
3776 whose names contain a match for regular expression @var{regexp}.
3777 Thus, @samp{info fun step} finds all functions whose names
3778 include @samp{step}; @samp{info fun ^step} finds those whose names
3779 start with @samp{step}.
3780
3781 @item info variables
3782 @kindex info variables
3783 Print the names and data types of all variables that are declared
3784 outside of functions (i.e., excluding local variables).
3785
3786 @item info variables @var{regexp}
3787 Print the names and data types of all variables (except for local
3788 variables) whose names contain a match for regular expression
3789 @var{regexp}.
3790
3791
3792 @ignore
3793 This was never implemented.
3794 @item info methods
3795 @itemx info methods @var{regexp}
3796 @kindex info methods
3797 The @samp{info-methods} command permits the user to examine all defined
3798 methods within C++ program, or (with the @var{regexp} argument) a
3799 specific set of methods found in the various C++ classes. Many
3800 C++ classes provide a large number of methods. Thus, the output
3801 from the @samp{ptype} command can be overwhelming and hard to use. The
3802 @samp{info-methods} command filters the methods, printing only those
3803 which match the regular-expression @var{regexp}.
3804 @end ignore
3805
3806 @item printsyms @var{filename}
3807 @kindex printsyms
3808 Write a complete dump of the debugger's symbol data into the
3809 file @var{filename}.
3810 @end table
3811
3812 @node Altering,,,
3813 @chapter Altering Execution
3814
3815 Once you think you have found an error in the program, you might want to
3816 find out for certain whether correcting the apparent error would lead to
3817 correct results in the rest of the run. You can find the answer by
3818 experiment, using the _GDBN__ features for altering execution of the
3819 program.
3820
3821 For example, you can store new values into variables or memory
3822 locations, give the program a signal, restart it at a different address,
3823 or even return prematurely from a function to its caller.
3824
3825 @node Assignment,,,
3826 @section Assignment to Variables
3827
3828 @cindex assignment
3829 @cindex setting variables
3830 To alter the value of a variable, evaluate an assignment expression.
3831 @xref{Expressions}. For example,
3832
3833 @example
3834 print x=4
3835 @end example
3836
3837 @noindent
3838 would store the value 4 into the variable @code{x}, and then print the
3839 value of the assignment expression (which is 4). All the assignment
3840 operators of C are supported, including the increment operators
3841 @samp{++} and @samp{--}, and combining assignments such as @samp{+=} and
3842 _0__@samp{<<=}_1__.
3843
3844 @kindex set
3845 @kindex set variable
3846 @cindex variables, setting
3847 If you are not interested in seeing the value of the assignment, use the
3848 @samp{set} command instead of the @samp{print} command. @samp{set} is
3849 really the same as @samp{print} except that the expression's value is not
3850 printed and is not put in the value history (@pxref{Value History}). The
3851 expression is evaluated only for its effects.
3852
3853 If the beginning of the argument string of the @samp{set} command
3854 appears identical to a @samp{set} subcommand, use the @samp{set
3855 variable} command instead of just @samp{set}. This command is identical
3856 to @samp{set} except for its lack of subcommands.
3857
3858 _GDBN__ allows more implicit conversions in assignments than C does; you can
3859 freely store an integer value into a pointer variable or vice versa, and
3860 any structure can be converted to any other structure that is the same
3861 length or shorter.
3862 @comment FIXME: how do structs align/pad in these conversions?
3863 @comment /pesch@cygnus.com 18dec1990
3864
3865 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
3866 construct to generate a value of specified type at a specified address
3867 (@pxref{Expressions}). For example, @code{@{int@}0x83040} refers
3868 to memory location @code{0x83040} as an integer (which implies a certain size
3869 and representation in memory), and
3870
3871 @example
3872 set @{int@}0x83040 = 4
3873 @end example
3874
3875 @noindent
3876 stores the value 4 into that memory location.
3877
3878 @node Jumping,,,
3879 @section Continuing at a Different Address
3880
3881 Ordinarily, when you continue the program, you do so at the place where
3882 it stopped, with the @samp{continue} command. You can instead continue at
3883 an address of your own choosing, with the following commands:
3884
3885 @table @code
3886 @item jump @var{linenum}
3887 @kindex jump
3888 Resume execution at line number @var{linenum}. Execution will stop
3889 immediately if there is a breakpoint there.
3890
3891 The @samp{jump} command does not change the current stack frame, or
3892 the stack pointer, or the contents of any memory location or any
3893 register other than the program counter. If line @var{linenum} is in
3894 a different function from the one currently executing, the results may
3895 be bizarre if the two functions expect different patterns of arguments or
3896 of local variables. For this reason, the @samp{jump} command requests
3897 confirmation if the specified line is not in the function currently
3898 executing. However, even bizarre results are predictable if you are
3899 well acquainted with the machine-language code of the program.
3900
3901 @item jump *@var{address}
3902 Resume execution at the instruction at address @var{address}.
3903 @end table
3904
3905 You can get much the same effect as the @code{jump} command by storing a
3906 new value into the register @code{$pc}. The difference is that this
3907 does not start the program running; it only changes the address where it
3908 @emph{will} run when it is continued. For example,
3909
3910 @example
3911 set $pc = 0x485
3912 @end example
3913
3914 @noindent
3915 causes the next @samp{continue} command or stepping command to execute at
3916 address 0x485, rather than at the address where the program stopped.
3917 @xref{Stepping}.
3918
3919 The most common occasion to use the @samp{jump} command is to back up,
3920 perhaps with more breakpoints set, over a portion of a program that has
3921 already executed.
3922
3923 @group
3924 @node Signaling,,,
3925 @section Giving the Program a Signal
3926
3927 @table @code
3928 @item signal @var{signalnum}
3929 @kindex signal
3930 Resume execution where the program stopped, but give it immediately the
3931 signal number @var{signalnum}.
3932
3933 Alternatively, if @var{signalnum} is zero, continue execution without
3934 giving a signal. This is useful when the program stopped on account of
3935 a signal and would ordinary see the signal when resumed with the
3936 @samp{continue} command; @samp{signal 0} causes it to resume without a
3937 signal.
3938
3939 This command does not repeat when you press @key{RET} a second time
3940 after using it once.
3941 @end table
3942 @end group
3943
3944 @node Returning,,,
3945 @section Returning from a Function
3946
3947 @table @code
3948 @item return
3949 @cindex returning from a function
3950 @kindex return
3951 You can cancel execution of a function call with the @samp{return}
3952 command.
3953 @end table
3954
3955 This command abandons execution of a function. When you use
3956 @code{return}, _GDBN__ discards the selected stack frame (and all frames
3957 within it). You can think of this as making the discarded frame return
3958 prematurely. If you wish to specify a value to be returned, give that
3959 value as the argument to @code{return}.
3960
3961 This pops the selected stack frame (@pxref{Selection}), and any other
3962 frames inside of it, leaving its caller as the innermost remaining
3963 frame. That frame becomes selected. The specified value is stored in
3964 the registers used for returning values of functions.
3965
3966 The @samp{return} command does not resume execution; it leaves the
3967 program stopped in the state that would exist if the function had just
3968 returned. In contrast, the @samp{finish} command (@pxref{Stepping})
3969 resumes execution until the selected stack frame returns naturally.
3970
3971 @node Calling,,,
3972 @section Calling your Program's Functions
3973
3974 @cindex calling functions
3975 @kindex call
3976 @table @code
3977 @item call @var{expr}
3978 Evaluate the expression @var{expr} without displaying @code{void}
3979 returned values.
3980 @end table
3981
3982 You can use this variant of the @samp{print} command if you want to
3983 execute a function from your program, but without cluttering the output
3984 with @code{void} returned values. The result is printed and saved in
3985 the value history, if it is not void.
3986
3987 @node GDB Files,,,
3988 @chapter _GDBN__'s Files
3989
3990 @node Files,,,
3991 @section Commands to Specify Files
3992 @cindex core dump file
3993 @cindex symbol table
3994 _GDBN__ needs to know the file name of the program to be debugged, both in
3995 order to read its symbol table and in order to start the program. To
3996 debug a core dump of a previous run, _GDBN__ must be told the file name of
3997 the core dump.
3998
3999 The usual way to specify the executable and core dump file names is with
4000 the command arguments given when you start _GDBN__, as discussed in
4001 @pxref{Invocation}.
4002
4003 Occasionally it is necessary to change to a different file during a
4004 _GDBN__ session. Or you may run _GDBN__ and forget to specify the files you
4005 want to use. In these situations the _GDBN__ commands to specify new files
4006 are useful.
4007
4008 @table @code
4009 @item file @var{filename}
4010 @cindex executable file
4011 @kindex file
4012 Use @var{filename} as the program to be debugged. It is read for its
4013 symbols and for the contents of pure memory. It is also the program
4014 executed when you use the @samp{run} command. If you do not specify a
4015 directory and the file is not found in _GDBN__'s working directory,
4016
4017 _GDBN__ will use the environment variable @code{PATH} as a list of
4018 directories to search, just as the shell does when looking for a program
4019 to run. You can change the value of this variable, for both _GDBN__ and
4020 your program, using the @code{path} command.
4021
4022 @samp{file} with no argument makes _GDBN__ discard any information it
4023 has on both executable file and the symbol table.
4024
4025 @item exec-file @var{filename}
4026 @kindex exec-file
4027 Specify that the program to be run (but not the symbol table) is found
4028 in @var{filename}. _GDBN__ will search the environment variable @code{PATH}
4029 if necessary to locate the program.
4030
4031 @item symbol-file @var{filename}
4032 @kindex symbol-file
4033 Read symbol table information from file @var{filename}. @code{PATH} is
4034 searched when necessary. Use the @samp{file} command to get both symbol
4035 table and program to run from the same file.
4036
4037 @samp{symbol-file} with no argument clears out _GDBN__'s information on your
4038 program's symbol table.
4039
4040 The @samp{symbol-file} command causes _GDBN__ to forget the contents of its
4041 convenience variables, the value history, and all breakpoints and
4042 auto-display expressions. This is because they may contain pointers to
4043 the internal data recording symbols and data types, which are part of
4044 the old symbol table data being discarded inside _GDBN__.
4045
4046 @samp{symbol-file} will not repeat if you press @key{RET} again after
4047 executing it once.
4048
4049 On some kinds of object files, the @samp{symbol-file} command does not
4050 actually read the symbol table in full right away. Instead, it scans
4051 the symbol table quickly to find which source files and which symbols
4052 are present. The details are read later, one source file at a time,
4053 when they are needed.
4054
4055 The purpose of this two-stage reading strategy is to make _GDBN__ start up
4056 faster. For the most part, it is invisible except for occasional pauses
4057 while the symbol table details for a particular source file are being
4058 read. (The @samp{set verbose} command can turn these pauses into
4059 messages if desired. @xref{Messages/Warnings}).
4060
4061 When the symbol table is stored in COFF format, @samp{symbol-file} does
4062 read the symbol table data in full right away. We haven't implemented
4063 the two-stage strategy for COFF yet.
4064
4065 When _GDBN__ is configured for a particular environment, it will
4066 understand debugging information in whatever format is the standard
4067 generated for that environment; you may use either a GNU compiler, or
4068 other compilers that adhere to the local conventions. Best results are
4069 usually obtained from GNU compilers; for example, using @code{_GCC__}
4070 you can generate debugging information for optimized code.
4071
4072 @item core-file @var{filename}
4073 @itemx core @var{filename}
4074 @kindex core
4075 @kindex core-file
4076 Specify the whereabouts of a core dump file to be used as the ``contents
4077 of memory''. Traditionally, core files contain only some parts of the
4078 address space of the process that generated them; _GDBN__ can access the
4079 executable file itself for other parts.
4080
4081 @samp{core-file} with no argument specifies that no core file is
4082 to be used.
4083
4084 Note that the core file is ignored when your program is actually running
4085 under _GDBN__. So, if you have been running the program and you wish to
4086 debug a core file instead, you must kill the subprocess in which the
4087 program is running. To do this, use the @samp{kill} command
4088 (@pxref{Kill Process}).
4089
4090 @item load @var{filename}
4091 @kindex load
4092 _if__(_GENERIC__)
4093 Depending on what remote debugging facilities are configured into
4094 _GDBN__, the @samp{load} command may be available. Where it exists, it
4095 is meant to make @var{filename} (an executable) available for debugging
4096 on the remote system---by downloading, or dynamic linking, for example.
4097 @samp{load} also records @var{filename}'s symbol table in _GDBN__, like
4098 the @samp{add-symbol-file} command.
4099
4100 If @samp{load} is not available on your _GDBN__, attempting to execute
4101 it gets the error message ``@code{You can't do that when your target is
4102 @dots{}}''
4103 _fi__(_GENERIC__)
4104
4105 _if__(_VXWORKS__)
4106 On VxWorks, @samp{load} will dynamically link @var{filename} on the
4107 current target system as well as adding its symbols in _GDBN__.
4108 _fi__(_VXWORKS__)
4109
4110 _if__(_I960__)
4111 With the Nindy interface to an Intel 960 board, @samp{load} will
4112 download @var{filename} to the 960 as well as adding its symbols in
4113 _GDBN__.
4114 _fi__(_I960__)
4115
4116 @samp{load} will not repeat if you press @key{RET} again after using it.
4117
4118 @item add-symbol-file @var{filename} @var{address}
4119 @kindex add-symbol-file
4120 @cindex dynamic linking
4121 The @samp{add-symbol-file} command reads additional symbol table information
4122 from the file @var{filename}. You would use this command when that file
4123 has been dynamically loaded (by some other means) into the program that
4124 is running. @var{address} should be the memory address at which the
4125 file has been loaded; _GDBN__ cannot figure this out for itself.
4126
4127 The symbol table of the file @var{filename} is added to the symbol table
4128 originally read with the @samp{symbol-file} command. You can use the
4129 @samp{add-symbol-file} command any number of times; the new symbol data thus
4130 read keeps adding to the old. To discard all old symbol data instead,
4131 use the @samp{symbol-file} command.
4132
4133 @samp{add-symbol-file} will not repeat if you press @key{RET} after using it.
4134
4135 @item info files
4136 @itemx info target
4137 @kindex info files
4138 @kindex info target
4139 @samp{info files} and @samp{info target} are synonymous; both print the
4140 current targets (@pxref{Targets}), including the names of the executable
4141 and core dump files currently in use by _GDBN__, and the files from
4142 which symbols were loaded. The command @samp{help targets} lists all
4143 possible targets rather than current ones.
4144
4145 @end table
4146
4147 All file-specifying commands allow both absolute and relative file names
4148 as arguments. _GDBN__ always converts the file name to an absolute path
4149 name and remembers it that way.
4150
4151 @kindex sharedlibrary
4152 @kindex share
4153 @cindex shared libraries
4154
4155 _GDBN__ supports the SunOS shared library format. Symbols from a shared
4156 library cannot be referenced before the shared library has been linked
4157 with the program. (That is to say, until after you type @samp{run} and
4158 the function @code{main} has been entered; or when examining core
4159 files.) Once the shared library has been linked in, you can use the
4160 following commands:
4161
4162 @table @code
4163 @item sharedlibrary @var{regex}
4164 @itemx share @var{regex}
4165 Load shared object library symbols for files matching a UNIX regular
4166 expression.
4167
4168 @item share
4169 @itemx sharedlibrary
4170 Load symbols for all shared libraries.
4171
4172 @item info share
4173 @itemx info sharedlibrary
4174 @kindex info sharedlibrary
4175 @kindex info share
4176 Print the names of the shared libraries which are currently loaded.
4177 @end table
4178
4179 @samp{sharedlibrary} does not repeat automatically when you press
4180 @key{RET} after using it once.
4181
4182 @node Symbol Errors,,,
4183 @section Errors Reading Symbol Files
4184 While a symbol file is being read, _GDBN__ will occasionally encounter
4185 problems, such as symbol types it does not recognize, or known bugs in
4186 compiler output. By default, it prints one message about each such
4187 type of problem, no matter how many times the problem occurs. You can
4188 ask it to print more messages, to see how many times the problems occur,
4189 or can shut the messages off entirely, with the @samp{set
4190 complaints} command (@xref{Messages/Warnings}).
4191
4192 The messages currently printed, and their meanings, are:
4193
4194 @table @code
4195 @item inner block not inside outer block in @var{symbol}
4196
4197 The symbol information shows where symbol scopes begin and end
4198 (such as at the start of a function or a block of statements). This
4199 error indicates that an inner scope block is not fully contained
4200 in its outer scope blocks.
4201
4202 _GDBN__ circumvents the problem by treating the inner block as if it had
4203 the same scope as the outer block. In the error message, @var{symbol}
4204 may be shown as ``@code{(don't know)}'' if the outer block is not a
4205 function.
4206
4207 @item block at @var{address} out of order
4208
4209 The symbol information for symbol scope blocks should occur in
4210 order of increasing addresses. This error indicates that it does not
4211 do so.
4212
4213 _GDBN__ does not circumvent this problem, and will have trouble locating
4214 symbols in the source file whose symbols being read. (You can often
4215 determine what source file is affected by specifying @samp{set verbose
4216 on}. @xref{Messages/Warnings}.)
4217
4218 @item bad block start address patched
4219
4220 The symbol information for a symbol scope block has a start address
4221 smaller than the address of the preceding source line. This is known
4222 to occur in the SunOS 4.1.1 (and earlier) C compiler.
4223
4224 _GDBN__ circumvents the problem by treating the symbol scope block as
4225 starting on the previous source line.
4226
4227 @c @item{encountered DBX-style class variable debugging information.
4228 @c You seem to have compiled your program with "g++ -g0" instead of "g++ -g".
4229 @c Therefore _GDBN__ will not know about your class variables}
4230 @c
4231 @c This error indicates that the symbol information produced for a C++
4232 @c program includes zero-size fields, which indicated static fields in
4233 @c a previous release of the G++ compiler. This message is probably
4234 @c obsolete.
4235 @c
4236 @item bad string table offset in symbol @var{n}
4237
4238 @cindex foo
4239 Symbol number @var{n} contains a pointer into the string table which is
4240 larger than the size of the string table.
4241
4242 _GDBN__ circumvents the problem by considering the symbol to have the
4243 name @code{foo}, which may cause other problems if many symbols end up
4244 with this name.
4245
4246 @item unknown symbol type @code{0x@var{NN}}
4247
4248 The symbol information contains new data types that _GDBN__ does not yet
4249 know how to read. @code{0x@var{NN}} is the symbol type of the misunderstood
4250 information, in hexadecimal.
4251
4252 _GDBN__ circumvents the error by ignoring this symbol information. This
4253 will usually allow the program to be debugged, though certain symbols
4254 will not be accessible. If you encounter such a problem and feel like
4255 debugging it, you can debug @code{_GDBP__} with itself, breakpoint on
4256 @samp{complain}, then go up to the function @samp{read_dbx_symtab} and
4257 examine @code{*bufp} to see the symbol.
4258
4259 @c @item stub type has NULL name
4260 @c
4261 @c FIXME, Mike Tiemann needs to write about what this means.
4262
4263 @item const/volatile indicator missing, got 'X'
4264
4265 The symbol information for a C++ type is missing some information that
4266 the compiler should have output for it.
4267
4268 @item C++ type mismatch between compiler and debugger
4269
4270 The debugger could not parse a type specification output by the compiler
4271 for some C++ object.
4272
4273 @end table
4274
4275 @node Targets,,,
4276 @chapter Specifying a Debugging Target
4277 @cindex debugging target
4278 @kindex target
4279 A @dfn{target} is an interface between the debugger and a particular
4280 kind of file or process.
4281
4282 Often, you will be able to run _GDBN__ in the same host environment as the
4283 program you are debugging; in that case, the debugging target can just be
4284 specified as a side effect of the @samp{file} or @samp{core} commands.
4285 When you need more flexibility---for example, running _GDBN__ on a
4286 physically separate host, controlling standalone systems over a
4287 serial port, or realtime systems over a TCP/IP connection---you can use
4288 the @samp{target} command.
4289
4290 @node Active Targets,,,
4291 @section Active Targets
4292 @cindex stacking targets
4293 @cindex active targets
4294 @cindex multiple targets
4295
4296 Targets are managed in three @dfn{strata} that correspond to different
4297 classes of target: processes, core files, and executable files. This
4298 allows you to (for example) start a process and inspect its activity
4299 without abandoning your work on a core file.
4300
4301 More than one target can potentially respond to a request. In
4302 particular, when you access memory _GDBN__ will examine the three strata of
4303 targets until it finds a target that can handle that particular address.
4304
4305 Strata are always examined in a fixed order: first a process if there is
4306 one, then a core file if there is one, and finally an executable file if
4307 there is one of those.
4308
4309 When you specify a new target in a given stratum, it replaces any target
4310 previously in that stratum.
4311
4312 To get rid of a target without replacing it, use the @samp{detach}
4313 command. The related command @samp{attach} provides you with a way of
4314 choosing a particular running process as a new target. @xref{Attach}.
4315
4316 @node Target Commands,,,
4317 @section Commands for Managing Targets
4318
4319 @table @code
4320 @item target @var{type} @var{parameters}
4321 Connects the _GDBN__ host environment to a target machine or process. A
4322 target is typically a protocol for talking to debugging facilities. You
4323 use the argument @var{type} to specify the type or protocol of the
4324 target machine.
4325
4326 Further @var{parameters} are interpreted by the target protocol, but
4327 typically include things like device names or host names to connect
4328 with, process numbers, and baud rates.
4329
4330 The @samp{target} command will not repeat if you press @key{RET} again
4331 after executing the command.
4332
4333 @item help target
4334 @kindex help target
4335 Displays the names of all targets available. To display targets
4336 currently selected, use either @samp{info target} or @samp{info files}
4337 (@pxref{Files}).
4338
4339 @item help target @var{name}
4340 Describe a particular target, including any parameters necessary to
4341 select it.
4342 @end table
4343
4344 Here are some common targets (available, or not, depending on the _GDBN__
4345 configuration):
4346
4347 @table @code
4348 @item target exec @var{prog}
4349 @kindex target exec
4350 An executable file. @samp{target exec @var{prog}} is the same as
4351 @samp{exec-file @var{prog}}.
4352
4353 @item target core @var{filename}
4354 @kindex target core
4355 A core dump file. @samp{target core @var{filename}} is the same as
4356 @samp{core-file @var{filename}}.
4357
4358 @item target remote @var{dev}
4359 @kindex target remote
4360 Remote serial target in _GDBN__-specific protocol. The argument @var{dev}
4361 specifies what serial device to use for the connection (e.g.
4362 @code{/dev/ttya}). @xref{Remote}.
4363
4364 _if__(_AMD29K__)
4365 @item target amd-eb @var{dev} @var{speed} @var{PROG}
4366 @kindex target amd-eb
4367 @cindex AMD EB29K
4368 Remote PC-resident AMD EB29K board, attached over serial lines.
4369 @var{dev} is the serial device, as for @samp{target remote};
4370 @samp{speed} allows you to specify the linespeed; and @var{PROG} is the
4371 name of the program to be debugged, as it appears to DOS on the PC.
4372 @xref{EB29K Remote}.
4373
4374 _fi__(_AMD29K__)
4375 _if__(_I960__)
4376 @item target nindy @var{devicename}
4377 @kindex target nindy
4378 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
4379 the name of the serial device to use for the connection, e.g.
4380 @samp{/dev/ttya}. @xref{i960-Nindy Remote}.
4381
4382 _fi__(_I960__)
4383 _if__(_VXWORKS__)
4384 @item target vxworks @var{machinename}
4385 @kindex target vxworks
4386 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
4387 is the target system's machine name or IP address.
4388 @xref{VxWorks Remote}.
4389 _fi__(_VXWORKS__)
4390 @end table
4391
4392 _if__(_GENERIC__)
4393 Different targets are available on different configurations of _GDBN__; your
4394 configuration may have more or fewer targets.
4395 _fi__(_GENERIC__)
4396
4397 @node Remote,,,
4398 @section Remote Debugging
4399 @cindex remote debugging
4400
4401 If you are trying to debug a program running on a machine that can't run
4402 _GDBN__ in the usual way, it is often useful to use remote debugging. For
4403 example, you might be debugging an operating system kernel, or debugging
4404 a small system which does not have a general purpose operating system
4405 powerful enough to run a full-featured debugger.
4406
4407 Some configurations of _GDBN__ have special serial or TCP/IP interfaces
4408 to make this work with particular debugging targets. In addition,
4409 _GDBN__ comes with a generic serial protocol (specific to _GDBN__, but
4410 not specific to any particular target system) which you can adapt.
4411
4412 To use the _GDBN__ remote serial protocol, the program to be debugged on
4413 the remote machine needs to contain a debugging device driver which
4414 talks to _GDBN__ over the serial line. Several sample remote debugging
4415 drivers are distributed with _GDBN__; see the @file{README} file in the
4416 _GDBN__ distribution for more information.
4417
4418 For details of this communication protocol, see the comments in the
4419 _GDBN__ source file @file{remote.c}.
4420
4421 To start remote debugging, first run _GDBN__ and specify as an executable file
4422 the program that is running in the remote machine. This tells _GDBN__ how
4423 to find the program's symbols and the contents of its pure text. Then
4424 establish communication using the @samp{target remote} command with a device
4425 name as an argument. For example:
4426
4427 @example
4428 target remote /dev/ttyb
4429 @end example
4430
4431 @noindent
4432 if the serial line is connected to the device named @file{/dev/ttyb}. This
4433 will stop the remote machine if it is not already stopped.
4434
4435 Now you can use all the usual commands to examine and change data and to
4436 step and continue the remote program.
4437
4438 To resume the remote program and stop debugging it, use the @samp{detach}
4439 command.
4440
4441 Other remote targets may be available in your
4442 configuration of _GDBN__; use @samp{help targets} to list them.
4443
4444 @node Controlling _GDBN__,,,
4445 @chapter Controlling _GDBN__
4446
4447 You can alter many aspects of _GDBN__'s interaction with you by using
4448 the @samp{set} command. For commands controlling how _GDBN__ displays
4449 data, @pxref{Print Settings}; other settings are described here.
4450
4451 @node Prompt,,,
4452 @section Prompt
4453 @cindex prompt
4454 _GDBN__ indicates its readiness to read a command by printing a string
4455 called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You
4456 can change the prompt string with the @samp{set prompt} command. For
4457 instance, when debugging _GDBN__ with _GDBN__, it is useful to change
4458 the prompt in one of the _GDBN__<>s so that you tell which one you are
4459 talking to.
4460
4461 @table @code
4462 @item set prompt @var{newprompt}
4463 @kindex set prompt
4464 Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth.
4465 @kindex show prompt
4466 @item show prompt
4467 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
4468 @end table
4469
4470 @node Editing,,,
4471 @section Command Editing
4472 @cindex readline
4473 @cindex command line editing
4474 _GDBN__ reads its input commands via the @dfn{readline} interface. This
4475 GNU library provides consistent behavior for programs which provide a
4476 command line interface to the user. Advantages are @samp{emacs}-style
4477 or @samp{vi}-style inline editing of commands, @samp{csh}-like history
4478 substitution, and a storage and recall of command history across
4479 debugging sessions.
4480
4481 You may control the behavior of command line editing in _GDBN__ with the
4482 command @samp{set}. You may check the status of any of these settings
4483 with the command @samp{show}.
4484
4485 @table @code
4486 @kindex set editing
4487 @cindex editing
4488 @item set editing
4489 @itemx set editing on
4490 Enable command line editing (enabled by default).
4491
4492 @item set editing off
4493 Disable command line editing.
4494
4495 @kindex show editing
4496 @item show editing
4497 Show whether command line editing is enabled.
4498
4499 @node History,,,
4500 @section Command History
4501 @cindex history substitution
4502 @cindex history file
4503 @kindex set history filename
4504 @item set history filename @var{fname}
4505 Set the name of the _GDBN__ command history file to @var{fname}. This is
4506 the file from which _GDBN__ will read an initial command history
4507 list or to which it will write this list when it exits. This list is
4508 accessed through history expansion or through the history
4509 command editing characters listed below. This file defaults to the
4510 value of the environment variable @code{GDBHISTFILE}, or to
4511 @file{./.gdb_history} if this variable is not set.
4512
4513 @cindex history save
4514 @kindex set history save
4515 @item set history save
4516 @itemx set history save on
4517 Record command history in a file, whose name may be specified with the
4518 @samp{set history filename} command. By default, this option is disabled.
4519
4520 @item set history save off
4521 Stop recording command history in a file.
4522
4523 @cindex history size
4524 @kindex set history size
4525 @item set history size @var{size}
4526 Set the number of commands which _GDBN__ will keep in its history list.
4527 This defaults to the value of the environment variable
4528 @code{HISTSIZE}, or to 256 if this variable is not set.
4529 @end table
4530
4531 @cindex history expansion
4532 History expansion assigns special meaning to the character @samp{!}.
4533 @iftex
4534 (@xref{Event Designators}.)
4535 @end iftex
4536 Since @samp{!} is also the logical not operator in C, history expansion
4537 is off by default. If you decide to enable history expansion with the
4538 @samp{set history expansion on} command, you may sometimes need to
4539 follow @samp{!} (when it is used as logical not, in an expression) with
4540 a space or a tab to prevent it from being expanded. The readline
4541 history facilities will not attempt substitution on the strings
4542 @samp{!=} and @samp{!(}, even when history expansion is enabled.
4543
4544 The commands to control history expansion are:
4545
4546 @table @code
4547
4548 @kindex set history expansion
4549 @item set history expansion on
4550 @itemx set history expansion
4551 Enable history expansion. History expansion is off by default.
4552
4553 @item set history expansion off
4554 Disable history expansion.
4555
4556 The readline code comes with more complete documentation of
4557 editing and history expansion features. Users unfamiliar with @samp{emacs}
4558 or @samp{vi} may wish to read it.
4559 @iftex
4560 @xref{Command Line Editing}.
4561 @end iftex
4562
4563 @group
4564 @kindex show history
4565 @item show history
4566 @itemx show history filename
4567 @itemx show history save
4568 @itemx show history size
4569 @itemx show history expansion
4570 These commands display the state of the _GDBN__ history parameters.
4571 @samp{show history} by itself displays all four states.
4572 @end group
4573
4574 @end table
4575
4576 @table @code
4577 @kindex show commands
4578 @item show commands
4579 Display the last ten commands in the command history.
4580
4581 @item show commands @var{n}
4582 Print ten commands centered on command number @var{n}.
4583
4584 @item show commands +
4585 Print ten commands just after the commands last printed.
4586
4587 @end table
4588
4589 @node Screen Size,,,
4590 @section Screen Size
4591 @cindex size of screen
4592 @cindex pauses in output
4593 Certain commands to _GDBN__ may produce large amounts of information
4594 output to the screen. To help you read all of it, _GDBN__ pauses and
4595 asks you for input at the end of each page of output. Type @key{RET}
4596 when you want to continue the output. _GDBN__ also uses the screen
4597 width setting to determine when to wrap lines of output. Depending on
4598 what is being printed, it tries to break the line at a readable place,
4599 rather than simply letting it overflow onto the following line.
4600
4601 Normally _GDBN__ knows the size of the screen from the termcap data base
4602 together with the value of the @code{TERM} environment variable and the
4603 @code{stty rows} and @code{stty cols} settings. If this is not correct,
4604 you can override it with the @samp{set height} and @samp{set
4605 width} commands:
4606
4607 @table @code
4608 @item set height @var{lpp}
4609 @itemx show height
4610 @itemx set width @var{cpl}
4611 @itemx show width
4612 @kindex set height
4613 @kindex set width
4614 @kindex show width
4615 @kindex show height
4616 These @samp{set} commands specify a screen height of @var{lpp} lines and
4617 a screen width of @var{cpl} characters. The associated @samp{show}
4618 commands display the current settings.
4619
4620 If you specify a height of zero lines, _GDBN__ will not pause during output
4621 no matter how long the output is. This is useful if output is to a file
4622 or to an editor buffer.
4623 @end table
4624
4625 @node Numbers,,,
4626 @section Numbers
4627 @cindex number representation
4628 @cindex entering numbers
4629 You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by
4630 the usual conventions: octal numbers begin with @samp{0}, decimal
4631 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
4632 Numbers that begin with none of these are, by default, entered in base
4633 10; likewise, the default display for numbers---when no particular
4634 format is specified---is base 10. You can change the default base for
4635 both input and output with the @samp{set radix} command.
4636
4637 @table @code
4638 @kindex set radix
4639 @item set radix @var{base}
4640 Set the default base for numeric input and display. Supported choices
4641 for @var{base} are decimal 8, 10, 16. @var{base} must itself be
4642 specified either unambiguously or using the current default radix; for
4643 example, any of
4644
4645 @example
4646 set radix 012
4647 set radix 10.
4648 set radix 0xa
4649 @end example
4650
4651 @noindent
4652 will set the base to decimal. On the other hand, @samp{set radix 10}
4653 will leave the radix unchanged no matter what it was.
4654
4655 @kindex show radix
4656 @item show radix
4657 Display the current default base for numeric input and display.
4658
4659 @end table
4660
4661 @node Messages/Warnings,,,
4662 @section Optional Warnings and Messages
4663 By default, _GDBN__ is silent about its inner workings. If you are running
4664 on a slow machine, you may want to use the @samp{set verbose} command.
4665 It will make _GDBN__ tell you when it does a lengthy internal operation, so
4666 you won't think it has crashed.
4667
4668 Currently, the messages controlled by @samp{set verbose} are those which
4669 announce that the symbol table for a source file is being read
4670 (@pxref{Files}, in the description of the command
4671 @samp{symbol-file}).
4672 @c The following is the right way to do it, but emacs 18.55 doesn't support
4673 @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo
4674 @c is released.
4675 @ignore
4676 see @samp{symbol-file} in @ref{Files}).
4677 @end ignore
4678
4679 @table @code
4680 @kindex set verbose
4681 @item set verbose on
4682 Enables _GDBN__'s output of certain informational messages.
4683
4684 @item set verbose off
4685 Disables _GDBN__'s output of certain informational messages.
4686
4687 @kindex show verbose
4688 @item show verbose
4689 Displays whether @samp{set verbose} is on or off.
4690 @end table
4691
4692 By default, if _GDBN__ encounters bugs in the symbol table of an object file,
4693 it prints a single message about each type of problem it finds, then
4694 shuts up. You can suppress these messages, or allow more than one such
4695 message to be printed if you want to see how frequent the problems are.
4696 @xref{Symbol Errors}.
4697
4698 @table @code
4699 @kindex set complaints
4700 @item set complaints @var{limit}
4701 Permits _GDBN__ to output @var{limit} complaints about each type of unusual
4702 symbols before becoming silent about the problem. Set @var{limit} to
4703 zero to suppress all complaints; set it to a large number to prevent
4704 complaints from being suppressed.
4705
4706 @kindex show complaints
4707 @item show complaints
4708 Displays how many symbol complaints _GDBN__ is permitted to produce.
4709 @end table
4710
4711 By default, _GDBN__ is cautious, and asks what sometimes seem to be a
4712 lot of stupid questions to confirm certain commands. For example, if
4713 you try to run a program which is already running:
4714 @example
4715
4716 (_GDBP__) run
4717 The program being debugged has been started already.
4718 Start it from the beginning? (y or n)
4719 @end example
4720
4721 If you're willing to unflinchingly face the consequences of your own
4722 commands, you can disable this ``feature'':
4723
4724 @table @code
4725 @kindex set confirm
4726 @cindex flinching
4727 @cindex confirmation
4728 @cindex stupid questions
4729 @item set confirm off
4730 Disables confirmation requests.
4731
4732 @item set confirm on
4733 Enables confirmation requests (the default).
4734
4735 @item show confirm
4736 @kindex show confirm
4737 Displays state of confirmation requests.
4738 @end table
4739
4740 @node Sequences,,,
4741 @chapter Canned Sequences of Commands
4742
4743 Aside from breakpoint commands (@pxref{Break Commands}),_GDBN__ provides two
4744 ways to store sequences of commands for execution as a unit:
4745 user-defined commands and command files.
4746
4747 @node Define,,,
4748 @section User-Defined Commands
4749
4750 @cindex user-defined command
4751 A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
4752 assign a new name as a command. This is done with the @samp{define}
4753 command.
4754
4755 @table @code
4756 @item define @var{commandname}
4757 @kindex define
4758 Define a command named @var{commandname}. If there is already a command
4759 by that name, you are asked to confirm that you want to redefine it.
4760
4761 The definition of the command is made up of other _GDBN__ command lines,
4762 which are given following the @samp{define} command. The end of these
4763 commands is marked by a line containing @samp{end}.
4764
4765 @item document @var{commandname}
4766 @kindex document
4767 Give documentation to the user-defined command @var{commandname}. The
4768 command @var{commandname} must already be defined. This command reads
4769 lines of documentation just as @samp{define} reads the lines of the
4770 command definition, ending with @samp{end}. After the @samp{document}
4771 command is finished, @samp{help} on command @var{commandname} will print
4772 the documentation you have specified.
4773
4774 You may use the @samp{document} command again to change the
4775 documentation of a command. Redefining the command with @samp{define}
4776 does not change the documentation.
4777
4778 @item help user-defined
4779 @kindex help user-defined
4780 List all user-defined commands, with the first line of the documentation
4781 (if any) for each.
4782
4783 @item info user
4784 @itemx info user @var{commandname}
4785 @kindex info user
4786 Display the GDB commands used to define @var{commandname} (but not its
4787 documentation). If no @var{commandname} is given, display the
4788 definitions for all user-defined commands.
4789 @end table
4790
4791 User-defined commands do not take arguments. When they are executed, the
4792 commands of the definition are not printed. An error in any command
4793 stops execution of the user-defined command.
4794
4795 Commands that would ask for confirmation if used interactively proceed
4796 without asking when used inside a user-defined command. Many _GDBN__ commands
4797 that normally print messages to say what they are doing omit the messages
4798 when used in a user-defined command.
4799
4800 @node Command Files,,,
4801 @section Command Files
4802
4803 @cindex command files
4804 A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
4805 (lines starting with @samp{#}) may also be included. An empty line in a
4806 command file does nothing; it does not mean to repeat the last command, as
4807 it would from the terminal.
4808
4809 @cindex init file
4810 @cindex @file{_GDBINIT__}
4811 When you start _GDBN__, it automatically executes commands from its
4812 @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__
4813 reads the init file (if any) in your home directory and then the init
4814 file (if any) in the current working directory. (The init files are not
4815 executed if the @samp{-nx} option is given.) You can also request the
4816 execution of a command file with the @samp{source} command:
4817
4818 @table @code
4819 @item source @var{filename}
4820 @kindex source
4821 Execute the command file @var{filename}.
4822 @end table
4823
4824 The lines in a command file are executed sequentially. They are not
4825 printed as they are executed. An error in any command terminates execution
4826 of the command file.
4827
4828 Commands that would ask for confirmation if used interactively proceed
4829 without asking when used in a command file. Many _GDBN__ commands that
4830 normally print messages to say what they are doing omit the messages
4831 when called from command files.
4832
4833 @node Output,,,
4834 @section Commands for Controlled Output
4835
4836 During the execution of a command file or a user-defined command, normal
4837 _GDBN__ output is suppressed; the only output that appears is what is
4838 explicitly printed by the commands in the definition. This section
4839 describes three commands useful for generating exactly the output you
4840 want.
4841
4842 @table @code
4843 @item echo @var{text}
4844 @kindex echo
4845 @c I don't consider backslash-space a standard C escape sequence
4846 @c because it's not in ANSI.
4847 Print @var{text}. Nonprinting characters can be included in @var{text}
4848 using C escape sequences, such as @samp{\n} to print a newline. @b{No
4849 newline will be printed unless you specify one.} In addition to the
4850 standard C escape sequences a backslash followed by a space stands for a
4851 space. This is useful for outputting a string with spaces at the
4852 beginning or the end, since leading and trailing spaces are otherwise
4853 trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the
4854 command @samp{echo \@ and foo = \@ }.
4855 @c FIXME: verify hard copy actually issues enspaces for '@ '! Will this
4856 @c confuse texinfo?
4857
4858 A backslash at the end of @var{text} can be used, as in C, to continue
4859 the command onto subsequent lines. For example,
4860
4861 @example
4862 echo This is some text\n\
4863 which is continued\n\
4864 onto several lines.\n
4865 @end example
4866
4867 produces the same output as
4868
4869 @example
4870 echo This is some text\n
4871 echo which is continued\n
4872 echo onto several lines.\n
4873 @end example
4874
4875 @item output @var{expression}
4876 @kindex output
4877 Print the value of @var{expression} and nothing but that value: no
4878 newlines, no @samp{$@var{nn} = }. The value is not entered in the
4879 value history either. @xref{Expressions} for more information on
4880 expressions.
4881
4882 @item output/@var{fmt} @var{expression}
4883 Print the value of @var{expression} in format @var{fmt}. You can use
4884 the same formats as for @samp{print}; @pxref{Output formats}, for more
4885 information.
4886
4887 @item printf @var{string}, @var{expressions}@dots{}
4888 @kindex printf
4889 Print the values of the @var{expressions} under the control of
4890 @var{string}. The @var{expressions} are separated by commas and may
4891 be either numbers or pointers. Their values are printed as specified
4892 by @var{string}, exactly as if the program were to execute
4893
4894 @example
4895 printf (@var{string}, @var{expressions}@dots{});
4896 @end example
4897
4898 For example, you can print two values in hex like this:
4899
4900 @example
4901 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
4902 @end example
4903
4904 The only backslash-escape sequences that you can use in the format
4905 string are the simple ones that consist of backslash followed by a
4906 letter.
4907 @end table
4908
4909 @node Emacs,,,
4910 @chapter Using _GDBN__ under GNU Emacs
4911
4912 @cindex emacs
4913 A special interface allows you to use GNU Emacs to view (and
4914 edit) the source files for the program you are debugging with
4915 _GDBN__.
4916
4917 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
4918 executable file you want to debug as an argument. This command starts
4919 _GDBN__ as a subprocess of Emacs, with input and output through a newly
4920 created Emacs buffer.
4921
4922 Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two
4923 things:
4924
4925 @itemize @bullet
4926 @item
4927 All ``terminal'' input and output goes through the Emacs buffer.
4928 @end itemize
4929
4930 This applies both to _GDBN__ commands and their output, and to the input
4931 and output done by the program you are debugging.
4932
4933 This is useful because it means that you can copy the text of previous
4934 commands and input them again; you can even use parts of the output
4935 in this way.
4936
4937 All the facilities of Emacs' Shell mode are available for this purpose.
4938
4939 @itemize @bullet
4940 @item
4941 _GDBN__ displays source code through Emacs.
4942 @end itemize
4943
4944 Each time _GDBN__ displays a stack frame, Emacs automatically finds the
4945 source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the
4946 left margin of the current line. Emacs uses a separate buffer for
4947 source display, and splits the window to show both your _GDBN__ session
4948 and the source.
4949
4950 Explicit _GDBN__ @samp{list} or search commands still produce output as
4951 usual, but you probably will have no reason to use them.
4952
4953 @quotation
4954 @emph{Warning:} If the directory where your program resides is not your
4955 current directory, it can be easy to confuse Emacs about the location of
4956 the source files, in which case the auxiliary display buffer will not
4957 appear to show your source. _GDBN__ can find programs by searching your
4958 environment's @samp{PATH} variable, so the _GDBN__ input and output
4959 session will proceed normally; but Emacs doesn't get enough information
4960 back from _GDBN__ to locate the source files in this situation. To
4961 avoid this problem, either start _GDBN__ mode from the directory where
4962 your program resides, or specify a full path name when prompted for the
4963 @kbd{M-x gdb} argument.
4964
4965 A similar confusion can result if you use the _GDBN__ @samp{file} command to
4966 switch to debugging a program in some other location, from an existing
4967 _GDBN__ buffer in Emacs.
4968 @end quotation
4969
4970 By default, @kbd{M-x gdb} calls the program called ``@code{gdb}''. If
4971 you need to call _GDBN__ by a different name (for example, if you keep
4972 several configurations around, with different names) you can set the
4973 Emacs variable @code{gdb-command-name}; for example,
4974 @example
4975 (setq gdb-command-name "mygdb")
4976 @end example
4977 @noindent
4978 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
4979 in your @samp{.emacs} file) will make Emacs call the program named
4980 ``@code{mygdb}'' instead.
4981
4982 In the _GDBN__ I/O buffer, you can use these special Emacs commands in
4983 addition to the standard Shell mode commands:
4984
4985 @table @kbd
4986 @item C-h m
4987 Describe the features of Emacs' _GDBN__ Mode.
4988
4989 @item M-s
4990 Execute to another source line, like the _GDBN__ @samp{step} command; also
4991 update the display window to show the current file and location.
4992
4993 @item M-n
4994 Execute to next source line in this function, skipping all function
4995 calls, like the _GDBN__ @samp{next} command. Then update the display window
4996 to show the current file and location.
4997
4998 @item M-i
4999 Execute one instruction, like the _GDBN__ @samp{stepi} command; update
5000 display window accordingly.
5001
5002 @item M-x gdb-nexti
5003 Execute to next instruction, using the _GDBN__ @samp{nexti} command; update
5004 display window accordingly.
5005
5006 @item C-c C-f
5007 Execute until exit from the selected stack frame, like the _GDBN__
5008 @samp{finish} command.
5009
5010 @item M-c
5011 @c C-c C-p in emacs 19
5012 Continue execution of the program, like the _GDBN__ @samp{continue} command.
5013
5014 @item M-u
5015 @c C-c C-u in emacs 19
5016 Go up the number of frames indicated by the numeric argument
5017 (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
5018 like the _GDBN__ @samp{up} command.@refill
5019
5020 @item M-d
5021 @c C-c C-d in emacs 19
5022 Go down the number of frames indicated by the numeric argument, like the
5023 _GDBN__ @samp{down} command.
5024
5025 @item C-x &
5026 Read the number where the cursor is positioned, and insert it at the end
5027 of the _GDBN__ I/O buffer. For example, if you wish to disassemble code
5028 around an address that was displayed earlier, type @kbd{disassemble};
5029 then move the cursor to the address display, and pick up the
5030 argument for @samp{disassemble} by typing @kbd{C-x &}.
5031
5032 You can customize this further on the fly by defining elements of the list
5033 @samp{gdb-print-command}; once it is defined, you can format or
5034 otherwise process numbers picked up by @kbd{C-x &} before they are
5035 inserted. A numeric argument to @kbd{C-x &} will both flag that you
5036 wish special formatting, and act as an index to pick an element of the
5037 list. If the list element is a string, the number to be inserted is
5038 formatted using the Emacs function @samp{format}; otherwise the number
5039 is passed as an argument to the corresponding list element.
5040
5041 @item M-x gdb-display-frame
5042 Explicitly request display of the source code surrounding the current
5043 frame location, in another window. _GDBN__ does this display automatically;
5044 but if, for example, you accidentally kill the buffer where it is
5045 displayed, this command is a way of getting it back.
5046 @end table
5047
5048 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
5049 tells _GDBN__ to set a breakpoint on the source line point is on.
5050
5051 The source files displayed in Emacs are in ordinary Emacs buffers
5052 which are visiting the source files in the usual way. You can edit
5053 the files with these buffers if you wish; but keep in mind that _GDBN__
5054 communicates with Emacs in terms of line numbers. If you add or
5055 delete lines from the text, the line numbers that _GDBN__ knows will cease
5056 to correspond properly to the code.
5057
5058 @c The following dropped because Epoch is nonstandard. Reactivate
5059 @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990
5060 @ignore
5061 @kindex emacs epoch environment
5062 @kindex epoch
5063 @kindex inspect
5064
5065 Version 18 of Emacs has a built-in window system called the @samp{epoch}
5066 environment. Users of this environment can use a new command,
5067 @samp{inspect} which performs identically to @samp{print} except that
5068 each value is printed in its own window.
5069 @end ignore
5070
5071 @node _GDBN__ Bugs,,,
5072 @c node-name, next, previous, up
5073 @chapter Reporting Bugs in _GDBN__
5074 @cindex Bugs in _GDBN__
5075 @cindex Reporting Bugs in _GDBN__
5076
5077 Your bug reports play an essential role in making _GDBN__ reliable.
5078
5079 Reporting a bug may help you by bringing a solution to your problem, or it
5080 may not. But in any case the principal function of a bug report is to help
5081 the entire community by making the next version of _GDBN__ work better. Bug
5082 reports are your contribution to the maintenance of _GDBN__.
5083
5084 In order for a bug report to serve its purpose, you must include the
5085 information that enables us to fix the bug.
5086
5087 @node Bug Criteria,,,
5088 @section Have You Found a Bug?
5089 @cindex Bug Criteria
5090
5091 If you are not sure whether you have found a bug, here are some guidelines:
5092
5093 @itemize @bullet
5094 @item
5095 @cindex Fatal Signal
5096 @cindex Core Dump
5097 If the debugger gets a fatal signal, for any input whatever, that is a
5098 _GDBN__ bug. Reliable debuggers never crash.
5099
5100 @item
5101 @cindex error on Valid Input
5102 If _GDBN__ produces an error message for valid input, that is a bug.
5103
5104 @item
5105 @cindex Invalid Input
5106 If _GDBN__ does not produce an error message for invalid input,
5107 that is a bug. However, you should note that your idea of
5108 ``invalid input'' might be our idea of ``an extension'' or ``support
5109 for traditional practice''.
5110
5111 @item
5112 If you are an experienced user of debugging tools, your suggestions
5113 for improvement of _GDBN__ are welcome in any case.
5114 @end itemize
5115
5116 @node Bug Reporting,,,
5117 @section How to Report Bugs
5118 @cindex Bug Reports
5119 @cindex Compiler Bugs, Reporting
5120
5121 A number of companies and individuals offer support for GNU products.
5122 If you obtained _GDBN__ from a support organization, we recommend you
5123 contact that organization first.
5124
5125 Contact information for many support companies and individuals is
5126 available in the file @samp{etc/SERVICE} in the GNU Emacs distribution.
5127
5128 In any event, we also recommend that you send bug reports for _GDBN__ to one
5129 of these addresses:
5130
5131 @example
5132 bug-gdb@@prep.ai.mit.edu
5133 @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
5134 @end example
5135
5136 @strong{Do not send bug reports to @samp{info-gdb}, or to
5137 @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to
5138 receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
5139
5140 The mailing list @samp{bug-gdb} has a newsgroup which serves as a
5141 repeater. The mailing list and the newsgroup carry exactly the same
5142 messages. Often people think of posting bug reports to the newsgroup
5143 instead of mailing them. This appears to work, but it has one problem
5144 which can be crucial: a newsgroup posting does not contain a mail path
5145 back to the sender. Thus, if we need to ask for more information, we
5146 may be unable to reach you. For this reason, it is better to send bug
5147 reports to the mailing list.
5148
5149 As a last resort, send bug reports on paper to:
5150
5151 @example
5152 GNU Debugger Bugs
5153 545 Tech Square
5154 Cambridge, MA 02139
5155 @end example
5156
5157 The fundamental principle of reporting bugs usefully is this:
5158 @strong{report all the facts}. If you are not sure whether to state a
5159 fact or leave it out, state it!
5160
5161 Often people omit facts because they think they know what causes the
5162 problem and assume that some details don't matter. Thus, you might
5163 assume that the name of the variable you use in an example does not matter.
5164 Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
5165 stray memory reference which happens to fetch from the location where that
5166 name is stored in memory; perhaps, if the name were different, the contents
5167 of that location would fool the debugger into doing the right thing despite
5168 the bug. Play it safe and give a specific, complete example. That is the
5169 easiest thing for you to do, and the most helpful.
5170
5171 Keep in mind that the purpose of a bug report is to enable us to fix
5172 the bug if it is new to us. It isn't as important what happens if
5173 the bug is already known. Therefore, always write your bug reports on
5174 the assumption that the bug has not been reported previously.
5175
5176 Sometimes people give a few sketchy facts and ask, ``Does this ring a
5177 bell?'' Those bug reports are useless, and we urge everyone to
5178 @emph{refuse to respond to them} except to chide the sender to report
5179 bugs properly.
5180
5181 To enable us to fix the bug, you should include all these things:
5182
5183 @itemize @bullet
5184 @item
5185 The version of _GDBN__. _GDBN__ announces it if you start with no
5186 arguments; you can also print it at any time using @samp{show version}.
5187
5188 Without this, we won't know whether there is any point in looking for
5189 the bug in the current version of _GDBN__.
5190
5191 @item
5192 A complete input script, and all necessary source files, that will
5193 reproduce the bug.
5194
5195 @item
5196 What compiler (and its version) was used to compile _GDBN__---e.g.
5197 ``_GCC__-1.37.1''.
5198
5199 @item
5200 The command arguments you gave the compiler to compile your example and
5201 observe the bug. For example, did you use @samp{-O}? To guarantee
5202 you won't omit something important, list them all.
5203
5204 If we were to try to guess the arguments, we would probably guess wrong
5205 and then we would not encounter the bug.
5206
5207 @item
5208 The type of machine you are using, and the operating system name and
5209 version number.
5210
5211 @item
5212 A description of what behavior you observe that you believe is
5213 incorrect. For example, ``It gets a fatal signal.''
5214
5215 Of course, if the bug is that _GDBN__ gets a fatal signal, then we
5216 will certainly notice it. But if the bug is incorrect output, we might
5217 not notice unless it is glaringly wrong.
5218
5219 Even if the problem you experience is a fatal signal, you should still
5220 say so explicitly. Suppose something strange is going on, such as,
5221 your copy of _GDBN__ is out of synch, or you have encountered a
5222 bug in the C library on your system. (This has happened!) Your copy
5223 might crash and ours would not. If you told us to expect a crash,
5224 then when ours fails to crash, we would know that the bug was not
5225 happening for us. If you had not told us to expect a crash, then we
5226 would not be able to draw any conclusion from our observations.
5227
5228 @item
5229 If you wish to suggest changes to the _GDBN__ source, send us context
5230 diffs. If you even discuss something in the _GDBN__ source, refer to
5231 it by context, not by line number.
5232
5233 The line numbers in our development sources won't match those in your
5234 sources. Your line numbers would convey no useful information to us.
5235
5236 @end itemize
5237
5238 Here are some things that are not necessary:
5239
5240 @itemize @bullet
5241 @item
5242 A description of the envelope of the bug.
5243
5244 Often people who encounter a bug spend a lot of time investigating
5245 which changes to the input file will make the bug go away and which
5246 changes will not affect it.
5247
5248 This is often time consuming and not very useful, because the way we
5249 will find the bug is by running a single example under the debugger
5250 with breakpoints, not by pure deduction from a series of examples.
5251 We recommend that you save your time for something else.
5252
5253 Of course, if you can find a simpler example to report @emph{instead}
5254 of the original one, that is a convenience for us. Errors in the
5255 output will be easier to spot, running under the debugger will take
5256 less time, etc.
5257
5258 However, simplification is not vital; if you don't want to do this,
5259 report the bug anyway and send us the entire test case you used.
5260
5261 @item
5262 A patch for the bug.
5263
5264 A patch for the bug does help us if it is a good one. But don't omit
5265 the necessary information, such as the test case, on the assumption that
5266 a patch is all we need. We might see problems with your patch and decide
5267 to fix the problem another way, or we might not understand it at all.
5268
5269 Sometimes with a program as complicated as _GDBN__ it is very hard to
5270 construct an example that will make the program follow a certain path
5271 through the code. If you don't send us the example, we won't be able
5272 to construct one, so we won't be able to verify that the bug is fixed.
5273
5274 And if we can't understand what bug you are trying to fix, or why your
5275 patch should be an improvement, we won't install it. A test case will
5276 help us to understand.
5277
5278 @item
5279 A guess about what the bug is or what it depends on.
5280
5281 Such guesses are usually wrong. Even we can't guess right about such
5282 things without first using the debugger to find the facts.
5283 @end itemize
5284
5285 @iftex
5286 @include readline/inc-readline.texinfo
5287 @include readline/inc-history.texinfo
5288 @end iftex
5289
5290 @node Installing _GDBN__,,,
5291 @appendix Installing _GDBN__
5292 @cindex configuring _GDBN__
5293 @cindex installation
5294
5295 The script @samp{config.gdb} automates the process of preparing _GDBN__
5296 for installation; you can then use @samp{make} to actually build it.
5297 The best way to build GDB is in a subdirectory that records the
5298 configuration options used; this gives you a clean way of building
5299 _GDBN__ binaries with several different configuration options.
5300 @samp{config.gdb} doesn't depend on this---it's just a good habit. For
5301 example, assuming the _GDBN__ source is in a directory called
5302 ``@code{gdb-4.0}'':
5303
5304 @example
5305 cd gdb-4.0
5306 mkdir =sun3os4
5307 cd =sun3os4
5308 ../config.gdb sun3os4
5309 make
5310 @end example
5311
5312 @noindent
5313 will install _GDBN__ on a Sun 3 running SunOS 4.
5314
5315 @table @code
5316 @kindex config.gdb
5317 @item config.gdb @var{machine}
5318 @itemx config.gdb -srcdir=@var{dir} @var{machine}
5319 This is the most usual way of configuring _GDBN__; to debug programs running
5320 on the same machine as _GDBN__ itself. If you wish to build the _GDBN__ binaries
5321 in a completely different directory from the sources, specify a path to
5322 the source directory using the @samp{-srcdir} option.
5323
5324 @item config.gdb -host
5325 @cindex host environments
5326 Display a list of supported host environments for _GDBN__.
5327
5328 @item config.gdb @var{host} @var{target}
5329 @itemx config.gdb -srcdir=@var{dir} @var{host} @var{target}
5330 @cindex cross-debugging
5331 _GDBN__ can also be used as a cross-debugger, running on a machine of one
5332 type while debugging a program running on a machine of another type.
5333 You configure it this way by specifying first the @var{host}, then the
5334 @var{target} environment on the @code{config.gdb} argument list; the
5335 @var{host} is where _GDBN__ runs, and the @var{target} is where your program
5336 runs. @xref{Remote}. Again, you can use @samp{-srcdir} to specify a
5337 path to the _GDBN__ source.
5338
5339 @item config.gdb -target
5340 @cindex target environments
5341 Display a list of supported target environments for _GDBN__.
5342 @end table
5343
5344 @node License,,,
5345 @unnumbered GNU GENERAL PUBLIC LICENSE
5346 @center Version 1, February 1989
5347
5348 @display
5349 Copyright @copyright{} 1989 Free Software Foundation, Inc.
5350 675 Mass Ave, Cambridge, MA 02139, USA
5351
5352 Everyone is permitted to copy and distribute verbatim copies
5353 of this license document, but changing it is not allowed.
5354 @end display
5355
5356 @unnumberedsec Preamble
5357
5358 The license agreements of most software companies try to keep users
5359 at the mercy of those companies. By contrast, our General Public
5360 License is intended to guarantee your freedom to share and change free
5361 software---to make sure the software is free for all its users. The
5362 General Public License applies to the Free Software Foundation's
5363 software and to any other program whose authors commit to using it.
5364 You can use it for your programs, too.
5365
5366 When we speak of free software, we are referring to freedom, not
5367 price. Specifically, the General Public License is designed to make
5368 sure that you have the freedom to give away or sell copies of free
5369 software, that you receive source code or can get it if you want it,
5370 that you can change the software or use pieces of it in new free
5371 programs; and that you know you can do these things.
5372
5373 To protect your rights, we need to make restrictions that forbid
5374 anyone to deny you these rights or to ask you to surrender the rights.
5375 These restrictions translate to certain responsibilities for you if you
5376 distribute copies of the software, or if you modify it.
5377
5378 For example, if you distribute copies of a such a program, whether
5379 gratis or for a fee, you must give the recipients all the rights that
5380 you have. You must make sure that they, too, receive or can get the
5381 source code. And you must tell them their rights.
5382
5383 We protect your rights with two steps: (1) copyright the software, and
5384 (2) offer you this license which gives you legal permission to copy,
5385 distribute and/or modify the software.
5386
5387 Also, for each author's protection and ours, we want to make certain
5388 that everyone understands that there is no warranty for this free
5389 software. If the software is modified by someone else and passed on, we
5390 want its recipients to know that what they have is not the original, so
5391 that any problems introduced by others will not reflect on the original
5392 authors' reputations.
5393
5394 The precise terms and conditions for copying, distribution and
5395 modification follow.
5396
5397 @iftex
5398 @unnumberedsec TERMS AND CONDITIONS
5399 @end iftex
5400 @ifinfo
5401 @center TERMS AND CONDITIONS
5402 @end ifinfo
5403
5404 @enumerate
5405 @item
5406 This License Agreement applies to any program or other work which
5407 contains a notice placed by the copyright holder saying it may be
5408 distributed under the terms of this General Public License. The
5409 ``Program'', below, refers to any such program or work, and a ``work based
5410 on the Program'' means either the Program or any work containing the
5411 Program or a portion of it, either verbatim or with modifications. Each
5412 licensee is addressed as ``you''.
5413
5414 @item
5415 You may copy and distribute verbatim copies of the Program's source
5416 code as you receive it, in any medium, provided that you conspicuously and
5417 appropriately publish on each copy an appropriate copyright notice and
5418 disclaimer of warranty; keep intact all the notices that refer to this
5419 General Public License and to the absence of any warranty; and give any
5420 other recipients of the Program a copy of this General Public License
5421 along with the Program. You may charge a fee for the physical act of
5422 transferring a copy.
5423
5424 @item
5425 You may modify your copy or copies of the Program or any portion of
5426 it, and copy and distribute such modifications under the terms of Paragraph
5427 1 above, provided that you also do the following:
5428
5429 @itemize @bullet
5430 @item
5431 cause the modified files to carry prominent notices stating that
5432 you changed the files and the date of any change; and
5433
5434 @item
5435 cause the whole of any work that you distribute or publish, that
5436 in whole or in part contains the Program or any part thereof, either
5437 with or without modifications, to be licensed at no charge to all
5438 third parties under the terms of this General Public License (except
5439 that you may choose to grant warranty protection to some or all
5440 third parties, at your option).
5441
5442 @item
5443 If the modified program normally reads commands interactively when
5444 run, you must cause it, when started running for such interactive use
5445 in the simplest and most usual way, to print or display an
5446 announcement including an appropriate copyright notice and a notice
5447 that there is no warranty (or else, saying that you provide a
5448 warranty) and that users may redistribute the program under these
5449 conditions, and telling the user how to view a copy of this General
5450 Public License.
5451
5452 @item
5453 You may charge a fee for the physical act of transferring a
5454 copy, and you may at your option offer warranty protection in
5455 exchange for a fee.
5456 @end itemize
5457
5458 Mere aggregation of another independent work with the Program (or its
5459 derivative) on a volume of a storage or distribution medium does not bring
5460 the other work under the scope of these terms.
5461
5462 @item
5463 You may copy and distribute the Program (or a portion or derivative of
5464 it, under Paragraph 2) in object code or executable form under the terms of
5465 Paragraphs 1 and 2 above provided that you also do one of the following:
5466
5467 @itemize @bullet
5468 @item
5469 accompany it with the complete corresponding machine-readable
5470 source code, which must be distributed under the terms of
5471 Paragraphs 1 and 2 above; or,
5472
5473 @item
5474 accompany it with a written offer, valid for at least three
5475 years, to give any third party free (except for a nominal charge
5476 for the cost of distribution) a complete machine-readable copy of the
5477 corresponding source code, to be distributed under the terms of
5478 Paragraphs 1 and 2 above; or,
5479
5480 @item
5481 accompany it with the information you received as to where the
5482 corresponding source code may be obtained. (This alternative is
5483 allowed only for noncommercial distribution and only if you
5484 received the program in object code or executable form alone.)
5485 @end itemize
5486
5487 Source code for a work means the preferred form of the work for making
5488 modifications to it. For an executable file, complete source code means
5489 all the source code for all modules it contains; but, as a special
5490 exception, it need not include source code for modules which are standard
5491 libraries that accompany the operating system on which the executable
5492 file runs, or for standard header files or definitions files that
5493 accompany that operating system.
5494
5495 @item
5496 You may not copy, modify, sublicense, distribute or transfer the
5497 Program except as expressly provided under this General Public License.
5498 Any attempt otherwise to copy, modify, sublicense, distribute or transfer
5499 the Program is void, and will automatically terminate your rights to use
5500 the Program under this License. However, parties who have received
5501 copies, or rights to use copies, from you under this General Public
5502 License will not have their licenses terminated so long as such parties
5503 remain in full compliance.
5504
5505 @item
5506 By copying, distributing or modifying the Program (or any work based
5507 on the Program) you indicate your acceptance of this license to do so,
5508 and all its terms and conditions.
5509
5510 @item
5511 Each time you redistribute the Program (or any work based on the
5512 Program), the recipient automatically receives a license from the original
5513 licensor to copy, distribute or modify the Program subject to these
5514 terms and conditions. You may not impose any further restrictions on the
5515 recipients' exercise of the rights granted herein.
5516
5517 @item
5518 The Free Software Foundation may publish revised and/or new versions
5519 of the General Public License from time to time. Such new versions will
5520 be similar in spirit to the present version, but may differ in detail to
5521 address new problems or concerns.
5522
5523 Each version is given a distinguishing version number. If the Program
5524 specifies a version number of the license which applies to it and ``any
5525 later version'', you have the option of following the terms and conditions
5526 either of that version or of any later version published by the Free
5527 Software Foundation. If the Program does not specify a version number of
5528 the license, you may choose any version ever published by the Free Software
5529 Foundation.
5530
5531 @item
5532 If you wish to incorporate parts of the Program into other free
5533 programs whose distribution conditions are different, write to the author
5534 to ask for permission. For software which is copyrighted by the Free
5535 Software Foundation, write to the Free Software Foundation; we sometimes
5536 make exceptions for this. Our decision will be guided by the two goals
5537 of preserving the free status of all derivatives of our free software and
5538 of promoting the sharing and reuse of software generally.
5539
5540 @iftex
5541 @heading NO WARRANTY
5542 @end iftex
5543 @ifinfo
5544 @center NO WARRANTY
5545 @end ifinfo
5546
5547 @item
5548 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
5549 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
5550 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
5551 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
5552 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5553 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
5554 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
5555 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
5556 REPAIR OR CORRECTION.
5557
5558 @item
5559 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
5560 ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
5561 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
5562 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
5563 ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
5564 LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
5565 SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
5566 WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
5567 ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
5568 @end enumerate
5569
5570 @iftex
5571 @heading END OF TERMS AND CONDITIONS
5572 @end iftex
5573 @ifinfo
5574 @center END OF TERMS AND CONDITIONS
5575 @end ifinfo
5576
5577 @page
5578 @unnumberedsec Applying These Terms to Your New Programs
5579
5580 If you develop a new program, and you want it to be of the greatest
5581 possible use to humanity, the best way to achieve this is to make it
5582 free software which everyone can redistribute and change under these
5583 terms.
5584
5585 To do so, attach the following notices to the program. It is safest to
5586 attach them to the start of each source file to most effectively convey
5587 the exclusion of warranty; and each file should have at least the
5588 ``copyright'' line and a pointer to where the full notice is found.
5589
5590 @smallexample
5591 @var{one line to give the program's name and a brief idea of what it does.}
5592 Copyright (C) 19@var{yy} @var{name of author}
5593
5594 This program is free software; you can redistribute it and/or modify
5595 it under the terms of the GNU General Public License as published by
5596 the Free Software Foundation; either version 1, or (at your option)
5597 any later version.
5598
5599 This program is distributed in the hope that it will be useful,
5600 but WITHOUT ANY WARRANTY; without even the implied warranty of
5601 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5602 GNU General Public License for more details.
5603
5604 You should have received a copy of the GNU General Public License
5605 along with this program; if not, write to the Free Software
5606 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5607 @end smallexample
5608
5609 Also add information on how to contact you by electronic and paper mail.
5610
5611 If the program is interactive, make it output a short notice like this
5612 when it starts in an interactive mode:
5613
5614 @smallexample
5615 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
5616 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
5617 This is free software, and you are welcome to redistribute it
5618 under certain conditions; type `show c' for details.
5619 @end smallexample
5620
5621 The hypothetical commands `show w' and `show c' should show the
5622 appropriate parts of the General Public License. Of course, the
5623 commands you use may be called something other than `show w' and `show
5624 c'; they could even be mouse-clicks or menu items---whatever suits your
5625 program.
5626
5627 You should also get your employer (if you work as a programmer) or your
5628 school, if any, to sign a ``copyright disclaimer'' for the program, if
5629 necessary. Here is a sample; alter the names:
5630
5631 @smallexample
5632 Yoyodyne, Inc., hereby disclaims all copyright interest in the
5633 program `Gnomovision' (a program to direct compilers to make passes
5634 at assemblers) written by James Hacker.
5635
5636 @var{signature of Ty Coon}, 1 April 1989
5637 Ty Coon, President of Vice
5638 @end smallexample
5639
5640 That's all there is to it!
5641
5642 @node Index,,,
5643 @unnumbered Index
5644
5645 @printindex cp
5646
5647 @tex
5648 % I think something like @colophon should be in texinfo. In the
5649 % meantime:
5650 \long\def\colophon{\hbox to0pt{}\vfill
5651 \centerline{The body of this manual is set in}
5652 \centerline{\fontname\tenrm,}
5653 \centerline{with headings in {\bf\fontname\tenbf}}
5654 \centerline{and examples in {\tt\fontname\tentt}.}
5655 \centerline{{\it\fontname\tenit\/} and}
5656 \centerline{{\sl\fontname\tensl\/}}
5657 \centerline{are used for emphasis.}\vfill}
5658 \page\colophon
5659 % Blame: pesch@cygnus.com, 28mar91.
5660 @end tex
5661
5662 @contents
5663 @bye
This page took 0.146451 seconds and 3 git commands to generate.