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