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