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