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