]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/doc/gdb.texinfo
import gdb-1999-06-07 snapshot
[thirdparty/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 If you use both watchpoints, both must be set with the @code{rwatch}
2671 command.
2672
2673 @kindex awatch
2674 @item awatch @var{expr}
2675 Set a watchpoint that will break when @var{args} is read and written into
2676 by the program. If you use both watchpoints, both must be set with the
2677 @code{awatch} command.
2678
2679 @kindex info watchpoints
2680 @item info watchpoints
2681 This command prints a list of watchpoints, breakpoints, and catchpoints;
2682 it is the same as @code{info break}.
2683 @end table
2684
2685 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2686 watchpoints execute very quickly, and the debugger reports a change in
2687 value at the exact instruction where the change occurs. If @value{GDBN}
2688 cannot set a hardware watchpoint, it sets a software watchpoint, which
2689 executes more slowly and reports the change in value at the next
2690 statement, not the instruction, after the change occurs.
2691
2692 When you issue the @code{watch} command, @value{GDBN} reports
2693
2694 @example
2695 Hardware watchpoint @var{num}: @var{expr}
2696 @end example
2697
2698 @noindent
2699 if it was able to set a hardware watchpoint.
2700
2701 The SPARClite DSU will generate traps when a program accesses
2702 some data or instruction address that is assigned to the debug registers.
2703 For the data addresses, DSU facilitates the @code{watch} command.
2704 However the hardware breakpoint registers can only take two data watchpoints,
2705 and both watchpoints must be the same kind. For example, you can set two
2706 watchpoints with @code{watch} commands, two with @code{rwatch}
2707 commands, @strong{or} two with @code{awatch} commands, but you cannot set one
2708 watchpoint with one command and the other with a different command.
2709 @value{GDBN} will reject the command if you try to mix watchpoints.
2710 Delete or disable unused watchpoint commands before setting new ones.
2711
2712 If you call a function interactively using @code{print} or @code{call},
2713 any watchpoints you have set will be inactive until GDB reaches another
2714 kind of breakpoint or the call completes.
2715
2716 @quotation
2717 @cindex watchpoints and threads
2718 @cindex threads and watchpoints
2719 @ifclear HPPA
2720 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2721 usefulness. With the current watchpoint implementation, @value{GDBN}
2722 can only watch the value of an expression @emph{in a single thread}. If
2723 you are confident that the expression can only change due to the current
2724 thread's activity (and if you are also confident that no other thread
2725 can become current), then you can use watchpoints as usual. However,
2726 @value{GDBN} may not notice when a non-current thread's activity changes
2727 the expression.
2728 @end ifclear
2729 @ifset HPPA
2730 @emph{Warning:} In multi-thread programs, software watchpoints have only
2731 limited usefulness. If @value{GDBN} creates a software watchpoint, it
2732 can only watch the value of an expression @emph{in a single thread}. If
2733 you are confident that the expression can only change due to the current
2734 thread's activity (and if you are also confident that no other thread
2735 can become current), then you can use software watchpoints as usual.
2736 However, @value{GDBN} may not notice when a non-current thread's
2737 activity changes the expression. (Hardware watchpoints, in contrast,
2738 watch an expression in all threads.)
2739 @end ifset
2740 @end quotation
2741
2742 @node Set Catchpoints, Delete Breaks, Set Watchpoints, Breakpoints
2743 @subsection Setting catchpoints
2744 @cindex catchpoints
2745 @cindex exception handlers
2746 @cindex event handling
2747
2748 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2749 kinds of program events, such as C++ exceptions or the loading of a
2750 shared library. Use the @code{catch} command to set a catchpoint.
2751
2752 @table @code
2753 @kindex catch
2754 @item catch @var{event}
2755 Stop when @var{event} occurs. @var{event} can be any of the following:
2756 @table @code
2757 @item throw
2758 @kindex catch throw
2759 The throwing of a C++ exception.
2760
2761 @item catch
2762 @kindex catch catch
2763 The catching of a C++ exception.
2764
2765 @item exec
2766 @kindex catch exec
2767 A call to @code{exec}. This is currently only available for HP-UX.
2768
2769 @item fork
2770 @kindex catch fork
2771 A call to @code{fork}. This is currently only available for HP-UX.
2772
2773 @item vfork
2774 @kindex catch vfork
2775 A call to @code{vfork}. This is currently only available for HP-UX.
2776
2777 @item load
2778 @itemx load @var{libname}
2779 @kindex catch load
2780 The dynamic loading of any shared library, or the loading of the library
2781 @var{libname}. This is currently only available for HP-UX.
2782
2783 @item unload
2784 @itemx unload @var{libname}
2785 @kindex catch unload
2786 The unloading of any dynamically loaded shared library, or the unloading
2787 of the library @var{libname}. This is currently only available for HP-UX.
2788 @end table
2789
2790 @item tcatch @var{event}
2791 Set a catchpoint that is enabled only for one stop. The catchpoint is
2792 automatically deleted after the first time the event is caught.
2793
2794 @end table
2795
2796 Use the @code{info break} command to list the current catchpoints.
2797
2798 There are currently some limitations to C++ exception handling
2799 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2800
2801 @itemize @bullet
2802 @item
2803 If you call a function interactively, @value{GDBN} normally returns
2804 control to you when the function has finished executing. If the call
2805 raises an exception, however, the call may bypass the mechanism that
2806 returns control to you and cause your program either to abort or to
2807 simply continue running until it hits a breakpoint, catches a signal
2808 that @value{GDBN} is listening for, or exits. This is the case even if
2809 you set a catchpoint for the exception; catchpoints on exceptions are
2810 disabled within interactive calls.
2811
2812 @item
2813 You cannot raise an exception interactively.
2814
2815 @item
2816 You cannot install an exception handler interactively.
2817 @end itemize
2818
2819 @cindex raise exceptions
2820 Sometimes @code{catch} is not the best way to debug exception handling:
2821 if you need to know exactly where an exception is raised, it is better to
2822 stop @emph{before} the exception handler is called, since that way you
2823 can see the stack before any unwinding takes place. If you set a
2824 breakpoint in an exception handler instead, it may not be easy to find
2825 out where the exception was raised.
2826
2827 To stop just before an exception handler is called, you need some
2828 knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2829 raised by calling a library function named @code{__raise_exception}
2830 which has the following ANSI C interface:
2831
2832 @example
2833 /* @var{addr} is where the exception identifier is stored.
2834 ID is the exception identifier. */
2835 void __raise_exception (void **@var{addr}, void *@var{id});
2836 @end example
2837
2838 @noindent
2839 To make the debugger catch all exceptions before any stack
2840 unwinding takes place, set a breakpoint on @code{__raise_exception}
2841 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2842
2843 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2844 that depends on the value of @var{id}, you can stop your program when
2845 a specific exception is raised. You can use multiple conditional
2846 breakpoints to stop your program when any of a number of exceptions are
2847 raised.
2848
2849
2850 @node Delete Breaks, Disabling, Set Catchpoints, Breakpoints
2851 @subsection Deleting breakpoints
2852
2853 @cindex clearing breakpoints, watchpoints, catchpoints
2854 @cindex deleting breakpoints, watchpoints, catchpoints
2855 It is often necessary to eliminate a breakpoint, watchpoint, or
2856 catchpoint once it has done its job and you no longer want your program
2857 to stop there. This is called @dfn{deleting} the breakpoint. A
2858 breakpoint that has been deleted no longer exists; it is forgotten.
2859
2860 With the @code{clear} command you can delete breakpoints according to
2861 where they are in your program. With the @code{delete} command you can
2862 delete individual breakpoints, watchpoints, or catchpoints by specifying
2863 their breakpoint numbers.
2864
2865 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2866 automatically ignores breakpoints on the first instruction to be executed
2867 when you continue execution without changing the execution address.
2868
2869 @table @code
2870 @kindex clear
2871 @item clear
2872 Delete any breakpoints at the next instruction to be executed in the
2873 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2874 the innermost frame is selected, this is a good way to delete a
2875 breakpoint where your program just stopped.
2876
2877 @item clear @var{function}
2878 @itemx clear @var{filename}:@var{function}
2879 Delete any breakpoints set at entry to the function @var{function}.
2880
2881 @item clear @var{linenum}
2882 @itemx clear @var{filename}:@var{linenum}
2883 Delete any breakpoints set at or within the code of the specified line.
2884
2885 @cindex delete breakpoints
2886 @kindex delete
2887 @kindex d
2888 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2889 Delete the breakpoints, watchpoints, or catchpoints of the numbers
2890 specified as arguments. If no argument is specified, delete all
2891 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2892 confirm off}). You can abbreviate this command as @code{d}.
2893 @end table
2894
2895 @node Disabling, Conditions, Delete Breaks, Breakpoints
2896 @subsection Disabling breakpoints
2897
2898 @kindex disable breakpoints
2899 @kindex enable breakpoints
2900 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2901 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2902 it had been deleted, but remembers the information on the breakpoint so
2903 that you can @dfn{enable} it again later.
2904
2905 You disable and enable breakpoints, watchpoints, and catchpoints with
2906 the @code{enable} and @code{disable} commands, optionally specifying one
2907 or more breakpoint numbers as arguments. Use @code{info break} or
2908 @code{info watch} to print a list of breakpoints, watchpoints, and
2909 catchpoints if you do not know which numbers to use.
2910
2911 A breakpoint, watchpoint, or catchpoint can have any of four different
2912 states of enablement:
2913
2914 @itemize @bullet
2915 @item
2916 Enabled. The breakpoint stops your program. A breakpoint set
2917 with the @code{break} command starts out in this state.
2918 @item
2919 Disabled. The breakpoint has no effect on your program.
2920 @item
2921 Enabled once. The breakpoint stops your program, but then becomes
2922 disabled. A breakpoint set with the @code{tbreak} command starts out in
2923 this state.
2924 @item
2925 Enabled for deletion. The breakpoint stops your program, but
2926 immediately after it does so it is deleted permanently.
2927 @end itemize
2928
2929 You can use the following commands to enable or disable breakpoints,
2930 watchpoints, and catchpoints:
2931
2932 @table @code
2933 @kindex disable breakpoints
2934 @kindex disable
2935 @kindex dis
2936 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2937 Disable the specified breakpoints---or all breakpoints, if none are
2938 listed. A disabled breakpoint has no effect but is not forgotten. All
2939 options such as ignore-counts, conditions and commands are remembered in
2940 case the breakpoint is enabled again later. You may abbreviate
2941 @code{disable} as @code{dis}.
2942
2943 @kindex enable breakpoints
2944 @kindex enable
2945 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2946 Enable the specified breakpoints (or all defined breakpoints). They
2947 become effective once again in stopping your program.
2948
2949 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2950 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2951 of these breakpoints immediately after stopping your program.
2952
2953 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2954 Enable the specified breakpoints to work once, then die. @value{GDBN}
2955 deletes any of these breakpoints as soon as your program stops there.
2956 @end table
2957
2958 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2959 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2960 subsequently, they become disabled or enabled only when you use one of
2961 the commands above. (The command @code{until} can set and delete a
2962 breakpoint of its own, but it does not change the state of your other
2963 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2964 stepping}.)
2965
2966 @node Conditions, Break Commands, Disabling, Breakpoints
2967 @subsection Break conditions
2968 @cindex conditional breakpoints
2969 @cindex breakpoint conditions
2970
2971 @c FIXME what is scope of break condition expr? Context where wanted?
2972 @c in particular for a watchpoint?
2973 The simplest sort of breakpoint breaks every time your program reaches a
2974 specified place. You can also specify a @dfn{condition} for a
2975 breakpoint. A condition is just a Boolean expression in your
2976 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2977 a condition evaluates the expression each time your program reaches it,
2978 and your program stops only if the condition is @emph{true}.
2979
2980 This is the converse of using assertions for program validation; in that
2981 situation, you want to stop when the assertion is violated---that is,
2982 when the condition is false. In C, if you want to test an assertion expressed
2983 by the condition @var{assert}, you should set the condition
2984 @samp{! @var{assert}} on the appropriate breakpoint.
2985
2986 Conditions are also accepted for watchpoints; you may not need them,
2987 since a watchpoint is inspecting the value of an expression anyhow---but
2988 it might be simpler, say, to just set a watchpoint on a variable name,
2989 and specify a condition that tests whether the new value is an interesting
2990 one.
2991
2992 Break conditions can have side effects, and may even call functions in
2993 your program. This can be useful, for example, to activate functions
2994 that log program progress, or to use your own print functions to
2995 format special data structures. The effects are completely predictable
2996 unless there is another enabled breakpoint at the same address. (In
2997 that case, @value{GDBN} might see the other breakpoint first and stop your
2998 program without checking the condition of this one.) Note that
2999 breakpoint commands are usually more convenient and flexible for the
3000 purpose of performing side effects when a breakpoint is reached
3001 (@pxref{Break Commands, ,Breakpoint command lists}).
3002
3003 Break conditions can be specified when a breakpoint is set, by using
3004 @samp{if} in the arguments to the @code{break} command. @xref{Set
3005 Breaks, ,Setting breakpoints}. They can also be changed at any time
3006 with the @code{condition} command.
3007 @ifclear HPPA
3008 @c The watch command now seems to recognize the if keyword.
3009 @c catch doesn't, though.
3010 The @code{watch} command does not recognize the @code{if} keyword;
3011 @code{condition} is the only way to impose a further condition on a
3012 watchpoint.
3013 @end ifclear
3014 @ifset HPPA
3015 You can also use the @code{if} keyword with the @code{watch} command.
3016 The @code{catch} command does not recognize the @code{if} keyword;
3017 @code{condition} is the only way to impose a further condition on a
3018 catchpoint.
3019 @end ifset
3020
3021 @table @code
3022 @kindex condition
3023 @item condition @var{bnum} @var{expression}
3024 Specify @var{expression} as the break condition for breakpoint,
3025 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3026 breakpoint @var{bnum} stops your program only if the value of
3027 @var{expression} is true (nonzero, in C). When you use
3028 @code{condition}, @value{GDBN} checks @var{expression} immediately for
3029 syntactic correctness, and to determine whether symbols in it have
3030 referents in the context of your breakpoint.
3031 @c FIXME so what does GDB do if there is no referent? Moreover, what
3032 @c about watchpoints?
3033 @value{GDBN} does
3034 not actually evaluate @var{expression} at the time the @code{condition}
3035 command is given, however. @xref{Expressions, ,Expressions}.
3036
3037 @item condition @var{bnum}
3038 Remove the condition from breakpoint number @var{bnum}. It becomes
3039 an ordinary unconditional breakpoint.
3040 @end table
3041
3042 @cindex ignore count (of breakpoint)
3043 A special case of a breakpoint condition is to stop only when the
3044 breakpoint has been reached a certain number of times. This is so
3045 useful that there is a special way to do it, using the @dfn{ignore
3046 count} of the breakpoint. Every breakpoint has an ignore count, which
3047 is an integer. Most of the time, the ignore count is zero, and
3048 therefore has no effect. But if your program reaches a breakpoint whose
3049 ignore count is positive, then instead of stopping, it just decrements
3050 the ignore count by one and continues. As a result, if the ignore count
3051 value is @var{n}, the breakpoint does not stop the next @var{n} times
3052 your program reaches it.
3053
3054 @table @code
3055 @kindex ignore
3056 @item ignore @var{bnum} @var{count}
3057 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3058 The next @var{count} times the breakpoint is reached, your program's
3059 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3060 takes no action.
3061
3062 To make the breakpoint stop the next time it is reached, specify
3063 a count of zero.
3064
3065 When you use @code{continue} to resume execution of your program from a
3066 breakpoint, you can specify an ignore count directly as an argument to
3067 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3068 Stepping,,Continuing and stepping}.
3069
3070 If a breakpoint has a positive ignore count and a condition, the
3071 condition is not checked. Once the ignore count reaches zero,
3072 @value{GDBN} resumes checking the condition.
3073
3074 You could achieve the effect of the ignore count with a condition such
3075 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3076 is decremented each time. @xref{Convenience Vars, ,Convenience
3077 variables}.
3078 @end table
3079
3080 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3081
3082
3083 @node Break Commands, Breakpoint Menus, Conditions, Breakpoints
3084 @subsection Breakpoint command lists
3085
3086 @cindex breakpoint commands
3087 You can give any breakpoint (or watchpoint or catchpoint) a series of
3088 commands to execute when your program stops due to that breakpoint. For
3089 example, you might want to print the values of certain expressions, or
3090 enable other breakpoints.
3091
3092 @table @code
3093 @kindex commands
3094 @kindex end
3095 @item commands @r{[}@var{bnum}@r{]}
3096 @itemx @dots{} @var{command-list} @dots{}
3097 @itemx end
3098 Specify a list of commands for breakpoint number @var{bnum}. The commands
3099 themselves appear on the following lines. Type a line containing just
3100 @code{end} to terminate the commands.
3101
3102 To remove all commands from a breakpoint, type @code{commands} and
3103 follow it immediately with @code{end}; that is, give no commands.
3104
3105 With no @var{bnum} argument, @code{commands} refers to the last
3106 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3107 recently encountered).
3108 @end table
3109
3110 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3111 disabled within a @var{command-list}.
3112
3113 You can use breakpoint commands to start your program up again. Simply
3114 use the @code{continue} command, or @code{step}, or any other command
3115 that resumes execution.
3116
3117 Any other commands in the command list, after a command that resumes
3118 execution, are ignored. This is because any time you resume execution
3119 (even with a simple @code{next} or @code{step}), you may encounter
3120 another breakpoint---which could have its own command list, leading to
3121 ambiguities about which list to execute.
3122
3123 @kindex silent
3124 If the first command you specify in a command list is @code{silent}, the
3125 usual message about stopping at a breakpoint is not printed. This may
3126 be desirable for breakpoints that are to print a specific message and
3127 then continue. If none of the remaining commands print anything, you
3128 see no sign that the breakpoint was reached. @code{silent} is
3129 meaningful only at the beginning of a breakpoint command list.
3130
3131 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3132 print precisely controlled output, and are often useful in silent
3133 breakpoints. @xref{Output, ,Commands for controlled output}.
3134
3135 For example, here is how you could use breakpoint commands to print the
3136 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3137
3138 @example
3139 break foo if x>0
3140 commands
3141 silent
3142 printf "x is %d\n",x
3143 cont
3144 end
3145 @end example
3146
3147 One application for breakpoint commands is to compensate for one bug so
3148 you can test for another. Put a breakpoint just after the erroneous line
3149 of code, give it a condition to detect the case in which something
3150 erroneous has been done, and give it commands to assign correct values
3151 to any variables that need them. End with the @code{continue} command
3152 so that your program does not stop, and start with the @code{silent}
3153 command so that no output is produced. Here is an example:
3154
3155 @example
3156 break 403
3157 commands
3158 silent
3159 set x = y + 4
3160 cont
3161 end
3162 @end example
3163
3164 @node Breakpoint Menus, , Break Commands, Breakpoints
3165 @subsection Breakpoint menus
3166 @cindex overloading
3167 @cindex symbol overloading
3168
3169 Some programming languages (notably C++) permit a single function name
3170 to be defined several times, for application in different contexts.
3171 This is called @dfn{overloading}. When a function name is overloaded,
3172 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3173 a breakpoint. If you realize this is a problem, you can use
3174 something like @samp{break @var{function}(@var{types})} to specify which
3175 particular version of the function you want. Otherwise, @value{GDBN} offers
3176 you a menu of numbered choices for different possible breakpoints, and
3177 waits for your selection with the prompt @samp{>}. The first two
3178 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3179 sets a breakpoint at each definition of @var{function}, and typing
3180 @kbd{0} aborts the @code{break} command without setting any new
3181 breakpoints.
3182
3183 For example, the following session excerpt shows an attempt to set a
3184 breakpoint at the overloaded symbol @code{String::after}.
3185 We choose three particular definitions of that function name:
3186
3187 @c FIXME! This is likely to change to show arg type lists, at least
3188 @smallexample
3189 @group
3190 (@value{GDBP}) b String::after
3191 [0] cancel
3192 [1] all
3193 [2] file:String.cc; line number:867
3194 [3] file:String.cc; line number:860
3195 [4] file:String.cc; line number:875
3196 [5] file:String.cc; line number:853
3197 [6] file:String.cc; line number:846
3198 [7] file:String.cc; line number:735
3199 > 2 4 6
3200 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3201 Breakpoint 2 at 0xb344: file String.cc, line 875.
3202 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3203 Multiple breakpoints were set.
3204 Use the "delete" command to delete unwanted
3205 breakpoints.
3206 (@value{GDBP})
3207 @end group
3208 @end smallexample
3209
3210 @c @ifclear BARETARGET
3211 @c @node Error in Breakpoints
3212 @c @subsection ``Cannot insert breakpoints''
3213 @c
3214 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3215 @c
3216 @c Under some operating systems, breakpoints cannot be used in a program if
3217 @c any other process is running that program. In this situation,
3218 @c attempting to run or continue a program with a breakpoint causes
3219 @c @value{GDBN} to stop the other process.
3220 @c
3221 @c When this happens, you have three ways to proceed:
3222 @c
3223 @c @enumerate
3224 @c @item
3225 @c Remove or disable the breakpoints, then continue.
3226 @c
3227 @c @item
3228 @c Suspend @value{GDBN}, and copy the file containing your program to a new
3229 @c name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3230 @c that @value{GDBN} should run your program under that name.
3231 @c Then start your program again.
3232 @c
3233 @c @item
3234 @c Relink your program so that the text segment is nonsharable, using the
3235 @c linker option @samp{-N}. The operating system limitation may not apply
3236 @c to nonsharable executables.
3237 @c @end enumerate
3238 @c @end ifclear
3239
3240 @node Continuing and Stepping, Signals, Breakpoints, Stopping
3241 @section Continuing and stepping
3242
3243 @cindex stepping
3244 @cindex continuing
3245 @cindex resuming execution
3246 @dfn{Continuing} means resuming program execution until your program
3247 completes normally. In contrast, @dfn{stepping} means executing just
3248 one more ``step'' of your program, where ``step'' may mean either one
3249 line of source code, or one machine instruction (depending on what
3250 particular command you use). Either when continuing or when stepping,
3251 your program may stop even sooner, due to a breakpoint or a signal. (If
3252 due to a signal, you may want to use @code{handle}, or use @samp{signal
3253 0} to resume execution. @xref{Signals, ,Signals}.)
3254
3255 @table @code
3256 @kindex continue
3257 @kindex c
3258 @kindex fg
3259 @item continue @r{[}@var{ignore-count}@r{]}
3260 @itemx c @r{[}@var{ignore-count}@r{]}
3261 @itemx fg @r{[}@var{ignore-count}@r{]}
3262 Resume program execution, at the address where your program last stopped;
3263 any breakpoints set at that address are bypassed. The optional argument
3264 @var{ignore-count} allows you to specify a further number of times to
3265 ignore a breakpoint at this location; its effect is like that of
3266 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3267
3268 The argument @var{ignore-count} is meaningful only when your program
3269 stopped due to a breakpoint. At other times, the argument to
3270 @code{continue} is ignored.
3271
3272 The synonyms @code{c} and @code{fg} are provided purely for convenience,
3273 and have exactly the same behavior as @code{continue}.
3274 @end table
3275
3276 To resume execution at a different place, you can use @code{return}
3277 (@pxref{Returning, ,Returning from a function}) to go back to the
3278 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3279 different address}) to go to an arbitrary location in your program.
3280
3281 A typical technique for using stepping is to set a breakpoint
3282 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3283 beginning of the function or the section of your program where a problem
3284 is believed to lie, run your program until it stops at that breakpoint,
3285 and then step through the suspect area, examining the variables that are
3286 interesting, until you see the problem happen.
3287
3288 @table @code
3289 @kindex step
3290 @kindex s
3291 @item step
3292 Continue running your program until control reaches a different source
3293 line, then stop it and return control to @value{GDBN}. This command is
3294 abbreviated @code{s}.
3295
3296 @quotation
3297 @c "without debugging information" is imprecise; actually "without line
3298 @c numbers in the debugging information". (gcc -g1 has debugging info but
3299 @c not line numbers). But it seems complex to try to make that
3300 @c distinction here.
3301 @emph{Warning:} If you use the @code{step} command while control is
3302 within a function that was compiled without debugging information,
3303 execution proceeds until control reaches a function that does have
3304 debugging information. Likewise, it will not step into a function which
3305 is compiled without debugging information. To step through functions
3306 without debugging information, use the @code{stepi} command, described
3307 below.
3308 @end quotation
3309
3310 The @code{step} command now only stops at the first instruction of a
3311 source line. This prevents the multiple stops that used to occur in
3312 switch statements, for loops, etc. @code{step} continues to stop if a
3313 function that has debugging information is called within the line.
3314
3315 Also, the @code{step} command now only enters a subroutine if there is line
3316 number information for the subroutine. Otherwise it acts like the
3317 @code{next} command. This avoids problems when using @code{cc -gl}
3318 on MIPS machines. Previously, @code{step} entered subroutines if there
3319 was any debugging information about the routine.
3320
3321 @item step @var{count}
3322 Continue running as in @code{step}, but do so @var{count} times. If a
3323 breakpoint is reached, or a signal not related to stepping occurs before
3324 @var{count} steps, stepping stops right away.
3325
3326 @kindex next
3327 @kindex n
3328 @item next @r{[}@var{count}@r{]}
3329 Continue to the next source line in the current (innermost) stack frame.
3330 This is similar to @code{step}, but function calls that appear within
3331 the line of code are executed without stopping. Execution stops when
3332 control reaches a different line of code at the original stack level
3333 that was executing when you gave the @code{next} command. This command
3334 is abbreviated @code{n}.
3335
3336 An argument @var{count} is a repeat count, as for @code{step}.
3337
3338
3339 @c FIX ME!! Do we delete this, or is there a way it fits in with
3340 @c the following paragraph? --- Vctoria
3341 @c
3342 @c @code{next} within a function that lacks debugging information acts like
3343 @c @code{step}, but any function calls appearing within the code of the
3344 @c function are executed without stopping.
3345
3346 The @code{next} command now only stops at the first instruction of a
3347 source line. This prevents the multiple stops that used to occur in
3348 switch statements, for loops, etc.
3349
3350 @kindex finish
3351 @item finish
3352 Continue running until just after function in the selected stack frame
3353 returns. Print the returned value (if any).
3354
3355 Contrast this with the @code{return} command (@pxref{Returning,
3356 ,Returning from a function}).
3357
3358 @kindex until
3359 @kindex u
3360 @item until
3361 @itemx u
3362 Continue running until a source line past the current line, in the
3363 current stack frame, is reached. This command is used to avoid single
3364 stepping through a loop more than once. It is like the @code{next}
3365 command, except that when @code{until} encounters a jump, it
3366 automatically continues execution until the program counter is greater
3367 than the address of the jump.
3368
3369 This means that when you reach the end of a loop after single stepping
3370 though it, @code{until} makes your program continue execution until it
3371 exits the loop. In contrast, a @code{next} command at the end of a loop
3372 simply steps back to the beginning of the loop, which forces you to step
3373 through the next iteration.
3374
3375 @code{until} always stops your program if it attempts to exit the current
3376 stack frame.
3377
3378 @code{until} may produce somewhat counterintuitive results if the order
3379 of machine code does not match the order of the source lines. For
3380 example, in the following excerpt from a debugging session, the @code{f}
3381 (@code{frame}) command shows that execution is stopped at line
3382 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3383
3384 @example
3385 (@value{GDBP}) f
3386 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3387 206 expand_input();
3388 (@value{GDBP}) until
3389 195 for ( ; argc > 0; NEXTARG) @{
3390 @end example
3391
3392 This happened because, for execution efficiency, the compiler had
3393 generated code for the loop closure test at the end, rather than the
3394 start, of the loop---even though the test in a C @code{for}-loop is
3395 written before the body of the loop. The @code{until} command appeared
3396 to step back to the beginning of the loop when it advanced to this
3397 expression; however, it has not really gone to an earlier
3398 statement---not in terms of the actual machine code.
3399
3400 @code{until} with no argument works by means of single
3401 instruction stepping, and hence is slower than @code{until} with an
3402 argument.
3403
3404 @item until @var{location}
3405 @itemx u @var{location}
3406 Continue running your program until either the specified location is
3407 reached, or the current stack frame returns. @var{location} is any of
3408 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3409 ,Setting breakpoints}). This form of the command uses breakpoints,
3410 and hence is quicker than @code{until} without an argument.
3411
3412 @kindex stepi
3413 @kindex si
3414 @item stepi
3415 @itemx si
3416 Execute one machine instruction, then stop and return to the debugger.
3417
3418 It is often useful to do @samp{display/i $pc} when stepping by machine
3419 instructions. This makes @value{GDBN} automatically display the next
3420 instruction to be executed, each time your program stops. @xref{Auto
3421 Display,, Automatic display}.
3422
3423 An argument is a repeat count, as in @code{step}.
3424
3425 @need 750
3426 @kindex nexti
3427 @kindex ni
3428 @item nexti
3429 @itemx ni
3430 Execute one machine instruction, but if it is a function call,
3431 proceed until the function returns.
3432
3433 An argument is a repeat count, as in @code{next}.
3434 @end table
3435
3436 @node Signals, Thread Stops, Continuing and Stepping, Stopping
3437 @section Signals
3438 @cindex signals
3439
3440 A signal is an asynchronous event that can happen in a program. The
3441 operating system defines the possible kinds of signals, and gives each
3442 kind a name and a number. For example, in Unix @code{SIGINT} is the
3443 signal a program gets when you type an interrupt (often @kbd{C-c});
3444 @code{SIGSEGV} is the signal a program gets from referencing a place in
3445 memory far away from all the areas in use; @code{SIGALRM} occurs when
3446 the alarm clock timer goes off (which happens only if your program has
3447 requested an alarm).
3448
3449 @cindex fatal signals
3450 Some signals, including @code{SIGALRM}, are a normal part of the
3451 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3452 errors; these signals are @dfn{fatal} (kill your program immediately) if the
3453 program has not specified in advance some other way to handle the signal.
3454 @code{SIGINT} does not indicate an error in your program, but it is normally
3455 fatal so it can carry out the purpose of the interrupt: to kill the program.
3456
3457 @value{GDBN} has the ability to detect any occurrence of a signal in your
3458 program. You can tell @value{GDBN} in advance what to do for each kind of
3459 signal.
3460
3461 @cindex handling signals
3462 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3463 (so as not to interfere with their role in the functioning of your program)
3464 but to stop your program immediately whenever an error signal happens.
3465 You can change these settings with the @code{handle} command.
3466
3467 @table @code
3468 @kindex info signals
3469 @item info signals
3470 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3471 handle each one. You can use this to see the signal numbers of all
3472 the defined types of signals.
3473
3474 @code{info handle} is the new alias for @code{info signals}.
3475
3476 @kindex handle
3477 @item handle @var{signal} @var{keywords}@dots{}
3478 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3479 be the number of a signal or its name (with or without the @samp{SIG} at the
3480 beginning). The @var{keywords} say what change to make.
3481 @end table
3482
3483 @c @group
3484 The keywords allowed by the @code{handle} command can be abbreviated.
3485 Their full names are:
3486
3487 @table @code
3488 @item nostop
3489 @value{GDBN} should not stop your program when this signal happens. It may
3490 still print a message telling you that the signal has come in.
3491
3492 @item stop
3493 @value{GDBN} should stop your program when this signal happens. This implies
3494 the @code{print} keyword as well.
3495
3496 @item print
3497 @value{GDBN} should print a message when this signal happens.
3498
3499 @item noprint
3500 @value{GDBN} should not mention the occurrence of the signal at all. This
3501 implies the @code{nostop} keyword as well.
3502
3503 @item pass
3504 @value{GDBN} should allow your program to see this signal; your program
3505 can handle the signal, or else it may terminate if the signal is fatal
3506 and not handled.
3507
3508 @item nopass
3509 @value{GDBN} should not allow your program to see this signal.
3510 @end table
3511 @c @end group
3512
3513 When a signal stops your program, the signal is not visible until you
3514 continue. Your program sees the signal then, if @code{pass} is in
3515 effect for the signal in question @emph{at that time}. In other words,
3516 after @value{GDBN} reports a signal, you can use the @code{handle}
3517 command with @code{pass} or @code{nopass} to control whether your
3518 program sees that signal when you continue.
3519
3520 You can also use the @code{signal} command to prevent your program from
3521 seeing a signal, or cause it to see a signal it normally would not see,
3522 or to give it any signal at any time. For example, if your program stopped
3523 due to some sort of memory reference error, you might store correct
3524 values into the erroneous variables and continue, hoping to see more
3525 execution; but your program would probably terminate immediately as
3526 a result of the fatal signal once it saw the signal. To prevent this,
3527 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3528 program a signal}.
3529
3530 @node Thread Stops, , Signals, Stopping
3531 @section Stopping and starting multi-thread programs
3532
3533 When your program has multiple threads (@pxref{Threads,, Debugging
3534 programs with multiple threads}), you can choose whether to set
3535 breakpoints on all threads, or on a particular thread.
3536
3537 @table @code
3538 @cindex breakpoints and threads
3539 @cindex thread breakpoints
3540 @kindex break @dots{} thread @var{threadno}
3541 @item break @var{linespec} thread @var{threadno}
3542 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3543 @var{linespec} specifies source lines; there are several ways of
3544 writing them, but the effect is always to specify some source line.
3545
3546 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3547 to specify that you only want @value{GDBN} to stop the program when a
3548 particular thread reaches this breakpoint. @var{threadno} is one of the
3549 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3550 column of the @samp{info threads} display.
3551
3552 If you do not specify @samp{thread @var{threadno}} when you set a
3553 breakpoint, the breakpoint applies to @emph{all} threads of your
3554 program.
3555
3556 You can use the @code{thread} qualifier on conditional breakpoints as
3557 well; in this case, place @samp{thread @var{threadno}} before the
3558 breakpoint condition, like this:
3559
3560 @smallexample
3561 (gdb) break frik.c:13 thread 28 if bartab > lim
3562 @end smallexample
3563
3564 @end table
3565
3566 @cindex stopped threads
3567 @cindex threads, stopped
3568 Whenever your program stops under @value{GDBN} for any reason,
3569 @emph{all} threads of execution stop, not just the current thread. This
3570 allows you to examine the overall state of the program, including
3571 switching between threads, without worrying that things may change
3572 underfoot.
3573
3574 @cindex continuing threads
3575 @cindex threads, continuing
3576 Conversely, whenever you restart the program, @emph{all} threads start
3577 executing. @emph{This is true even when single-stepping} with commands
3578 like @code{step} or @code{next}.
3579
3580 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3581 Since thread scheduling is up to your debugging target's operating
3582 system (not controlled by @value{GDBN}), other threads may
3583 execute more than one statement while the current thread completes a
3584 single step. Moreover, in general other threads stop in the middle of a
3585 statement, rather than at a clean statement boundary, when the program
3586 stops.
3587
3588 You might even find your program stopped in another thread after
3589 continuing or even single-stepping. This happens whenever some other
3590 thread runs into a breakpoint, a signal, or an exception before the
3591 first thread completes whatever you requested.
3592
3593 On some OSes, you can lock the OS scheduler and thus allow only a single
3594 thread to run.
3595
3596 @table @code
3597 @item set scheduler-locking @var{mode}
3598 Set the scheduler locking mode. If it is @code{off}, then there is no
3599 locking and any thread may run at any time. If @code{on}, then only the
3600 current thread may run when the inferior is resumed. The @code{step}
3601 mode optimizes for single-stepping. It stops other threads from
3602 ``seizing the prompt'' by preempting the current thread while you are
3603 stepping. Other threads will only rarely (or never) get a chance to run
3604 when you step. They are more likely to run when you ``next'' over a
3605 function call, and they are completely free to run when you use commands
3606 like ``continue'', ``until'', or ``finish''. However, unless another
3607 thread hits a breakpoint during its timeslice, they will never steal the
3608 GDB prompt away from the thread that you are debugging.
3609
3610 @item show scheduler-locking
3611 Display the current scheduler locking mode.
3612 @end table
3613
3614
3615 @node Stack, Source, Stopping, Top
3616 @chapter Examining the Stack
3617
3618 When your program has stopped, the first thing you need to know is where it
3619 stopped and how it got there.
3620
3621 @cindex call stack
3622 Each time your program performs a function call, information about the call
3623 is generated.
3624 That information includes the location of the call in your program,
3625 the arguments of the call,
3626 and the local variables of the function being called.
3627 The information is saved in a block of data called a @dfn{stack frame}.
3628 The stack frames are allocated in a region of memory called the @dfn{call
3629 stack}.
3630
3631 When your program stops, the @value{GDBN} commands for examining the
3632 stack allow you to see all of this information.
3633
3634 @cindex selected frame
3635 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3636 @value{GDBN} commands refer implicitly to the selected frame. In
3637 particular, whenever you ask @value{GDBN} for the value of a variable in
3638 your program, the value is found in the selected frame. There are
3639 special @value{GDBN} commands to select whichever frame you are
3640 interested in. @xref{Selection, ,Selecting a frame}.
3641
3642 When your program stops, @value{GDBN} automatically selects the
3643 currently executing frame and describes it briefly, similar to the
3644 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3645
3646 @menu
3647 * Frames:: Stack frames
3648 * Backtrace:: Backtraces
3649 * Selection:: Selecting a frame
3650 * Frame Info:: Information on a frame
3651 * Alpha/MIPS Stack:: Alpha and MIPS machines and the function stack
3652
3653 @end menu
3654
3655 @node Frames, Backtrace, Stack, Stack
3656 @section Stack frames
3657
3658 @cindex frame
3659 @cindex stack frame
3660 The call stack is divided up into contiguous pieces called @dfn{stack
3661 frames}, or @dfn{frames} for short; each frame is the data associated
3662 with one call to one function. The frame contains the arguments given
3663 to the function, the function's local variables, and the address at
3664 which the function is executing.
3665
3666 @cindex initial frame
3667 @cindex outermost frame
3668 @cindex innermost frame
3669 When your program is started, the stack has only one frame, that of the
3670 function @code{main}. This is called the @dfn{initial} frame or the
3671 @dfn{outermost} frame. Each time a function is called, a new frame is
3672 made. Each time a function returns, the frame for that function invocation
3673 is eliminated. If a function is recursive, there can be many frames for
3674 the same function. The frame for the function in which execution is
3675 actually occurring is called the @dfn{innermost} frame. This is the most
3676 recently created of all the stack frames that still exist.
3677
3678 @cindex frame pointer
3679 Inside your program, stack frames are identified by their addresses. A
3680 stack frame consists of many bytes, each of which has its own address; each
3681 kind of computer has a convention for choosing one byte whose
3682 address serves as the address of the frame. Usually this address is kept
3683 in a register called the @dfn{frame pointer register} while execution is
3684 going on in that frame.
3685
3686 @cindex frame number
3687 @value{GDBN} assigns numbers to all existing stack frames, starting with
3688 zero for the innermost frame, one for the frame that called it,
3689 and so on upward. These numbers do not really exist in your program;
3690 they are assigned by @value{GDBN} to give you a way of designating stack
3691 frames in @value{GDBN} commands.
3692
3693 @c below produces an acceptable overful hbox. --mew 13aug1993
3694 @cindex frameless execution
3695 Some compilers provide a way to compile functions so that they operate
3696 without stack frames. (For example, the @code{@value{GCC}} option
3697 @samp{-fomit-frame-pointer} generates functions without a frame.)
3698 This is occasionally done with heavily used library functions to save
3699 the frame setup time. @value{GDBN} has limited facilities for dealing
3700 with these function invocations. If the innermost function invocation
3701 has no stack frame, @value{GDBN} nevertheless regards it as though
3702 it had a separate frame, which is numbered zero as usual, allowing
3703 correct tracing of the function call chain. However, @value{GDBN} has
3704 no provision for frameless functions elsewhere in the stack.
3705
3706 @table @code
3707 @kindex frame
3708 @item frame @var{args}
3709 The @code{frame} command allows you to move from one stack frame to another,
3710 and to print the stack frame you select. @var{args} may be either the
3711 address of the frame or the stack frame number. Without an argument,
3712 @code{frame} prints the current stack frame.
3713
3714 @kindex select-frame
3715 @item select-frame
3716 The @code{select-frame} command allows you to move from one stack frame
3717 to another without printing the frame. This is the silent version of
3718 @code{frame}.
3719 @end table
3720
3721 @node Backtrace, Selection, Frames, Stack
3722 @section Backtraces
3723
3724 @cindex backtraces
3725 @cindex tracebacks
3726 @cindex stack traces
3727 A backtrace is a summary of how your program got where it is. It shows one
3728 line per frame, for many frames, starting with the currently executing
3729 frame (frame zero), followed by its caller (frame one), and on up the
3730 stack.
3731
3732 @table @code
3733 @kindex backtrace
3734 @kindex bt
3735 @item backtrace
3736 @itemx bt
3737 Print a backtrace of the entire stack: one line per frame for all
3738 frames in the stack.
3739
3740 You can stop the backtrace at any time by typing the system interrupt
3741 character, normally @kbd{C-c}.
3742
3743 @item backtrace @var{n}
3744 @itemx bt @var{n}
3745 Similar, but print only the innermost @var{n} frames.
3746
3747 @item backtrace -@var{n}
3748 @itemx bt -@var{n}
3749 Similar, but print only the outermost @var{n} frames.
3750 @end table
3751
3752 @kindex where
3753 @kindex info stack
3754 @kindex info s
3755 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3756 are additional aliases for @code{backtrace}.
3757
3758 Each line in the backtrace shows the frame number and the function name.
3759 The program counter value is also shown---unless you use @code{set
3760 print address off}. The backtrace also shows the source file name and
3761 line number, as well as the arguments to the function. The program
3762 counter value is omitted if it is at the beginning of the code for that
3763 line number.
3764
3765 Here is an example of a backtrace. It was made with the command
3766 @samp{bt 3}, so it shows the innermost three frames.
3767
3768 @smallexample
3769 @group
3770 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3771 at builtin.c:993
3772 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3773 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3774 at macro.c:71
3775 (More stack frames follow...)
3776 @end group
3777 @end smallexample
3778
3779 @noindent
3780 The display for frame zero does not begin with a program counter
3781 value, indicating that your program has stopped at the beginning of the
3782 code for line @code{993} of @code{builtin.c}.
3783
3784 @node Selection, Frame Info, Backtrace, Stack
3785 @section Selecting a frame
3786
3787 Most commands for examining the stack and other data in your program work on
3788 whichever stack frame is selected at the moment. Here are the commands for
3789 selecting a stack frame; all of them finish by printing a brief description
3790 of the stack frame just selected.
3791
3792 @table @code
3793 @kindex frame
3794 @kindex f
3795 @item frame @var{n}
3796 @itemx f @var{n}
3797 Select frame number @var{n}. Recall that frame zero is the innermost
3798 (currently executing) frame, frame one is the frame that called the
3799 innermost one, and so on. The highest-numbered frame is the one for
3800 @code{main}.
3801
3802 @item frame @var{addr}
3803 @itemx f @var{addr}
3804 Select the frame at address @var{addr}. This is useful mainly if the
3805 chaining of stack frames has been damaged by a bug, making it
3806 impossible for @value{GDBN} to assign numbers properly to all frames. In
3807 addition, this can be useful when your program has multiple stacks and
3808 switches between them.
3809
3810 @ifclear HPPA
3811 On the SPARC architecture, @code{frame} needs two addresses to
3812 select an arbitrary frame: a frame pointer and a stack pointer.
3813
3814 On the MIPS and Alpha architecture, it needs two addresses: a stack
3815 pointer and a program counter.
3816
3817 On the 29k architecture, it needs three addresses: a register stack
3818 pointer, a program counter, and a memory stack pointer.
3819 @c note to future updaters: this is conditioned on a flag
3820 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3821 @c as of 27 Jan 1994.
3822 @end ifclear
3823
3824 @kindex up
3825 @item up @var{n}
3826 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3827 advances toward the outermost frame, to higher frame numbers, to frames
3828 that have existed longer. @var{n} defaults to one.
3829
3830 @kindex down
3831 @kindex do
3832 @item down @var{n}
3833 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3834 advances toward the innermost frame, to lower frame numbers, to frames
3835 that were created more recently. @var{n} defaults to one. You may
3836 abbreviate @code{down} as @code{do}.
3837 @end table
3838
3839 All of these commands end by printing two lines of output describing the
3840 frame. The first line shows the frame number, the function name, the
3841 arguments, and the source file and line number of execution in that
3842 frame. The second line shows the text of that source line.
3843
3844 @need 1000
3845 For example:
3846
3847 @smallexample
3848 @group
3849 (@value{GDBP}) up
3850 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3851 at env.c:10
3852 10 read_input_file (argv[i]);
3853 @end group
3854 @end smallexample
3855
3856 After such a printout, the @code{list} command with no arguments
3857 prints ten lines centered on the point of execution in the frame.
3858 @xref{List, ,Printing source lines}.
3859
3860 @table @code
3861 @kindex down-silently
3862 @kindex up-silently
3863 @item up-silently @var{n}
3864 @itemx down-silently @var{n}
3865 These two commands are variants of @code{up} and @code{down},
3866 respectively; they differ in that they do their work silently, without
3867 causing display of the new frame. They are intended primarily for use
3868 in @value{GDBN} command scripts, where the output might be unnecessary and
3869 distracting.
3870 @end table
3871
3872 @node Frame Info, Alpha/MIPS Stack, Selection, Stack
3873 @section Information about a frame
3874
3875 There are several other commands to print information about the selected
3876 stack frame.
3877
3878 @table @code
3879 @item frame
3880 @itemx f
3881 When used without any argument, this command does not change which
3882 frame is selected, but prints a brief description of the currently
3883 selected stack frame. It can be abbreviated @code{f}. With an
3884 argument, this command is used to select a stack frame.
3885 @xref{Selection, ,Selecting a frame}.
3886
3887 @kindex info frame
3888 @kindex info f
3889 @item info frame
3890 @itemx info f
3891 This command prints a verbose description of the selected stack frame,
3892 including:
3893
3894 @itemize @bullet
3895 @item
3896 the address of the frame
3897 @item
3898 the address of the next frame down (called by this frame)
3899 @item
3900 the address of the next frame up (caller of this frame)
3901 @item
3902 the language in which the source code corresponding to this frame is written
3903 @item
3904 the address of the frame's arguments
3905 @item
3906 the program counter saved in it (the address of execution in the caller frame)
3907 @item
3908 which registers were saved in the frame
3909 @end itemize
3910
3911 @noindent The verbose description is useful when
3912 something has gone wrong that has made the stack format fail to fit
3913 the usual conventions.
3914
3915 @item info frame @var{addr}
3916 @itemx info f @var{addr}
3917 Print a verbose description of the frame at address @var{addr}, without
3918 selecting that frame. The selected frame remains unchanged by this
3919 command. This requires the same kind of address (more than one for some
3920 architectures) that you specify in the @code{frame} command.
3921 @xref{Selection, ,Selecting a frame}.
3922
3923 @kindex info args
3924 @item info args
3925 Print the arguments of the selected frame, each on a separate line.
3926
3927 @item info locals
3928 @kindex info locals
3929 Print the local variables of the selected frame, each on a separate
3930 line. These are all variables (declared either static or automatic)
3931 accessible at the point of execution of the selected frame.
3932
3933 @ifclear HPPA
3934 @kindex info catch
3935 @cindex catch exceptions
3936 @cindex exception handlers
3937 @item info catch
3938 Print a list of all the exception handlers that are active in the
3939 current stack frame at the current point of execution. To see other
3940 exception handlers, visit the associated frame (using the @code{up},
3941 @code{down}, or @code{frame} commands); then type @code{info catch}.
3942 @xref{Set Catchpoints, , Setting catchpoints}.
3943 @end ifclear
3944 @end table
3945
3946 @node Alpha/MIPS Stack, , Frame Info, Stack
3947 @section MIPS/Alpha machines and the function stack
3948
3949 @cindex stack on Alpha
3950 @cindex stack on MIPS
3951 @cindex Alpha stack
3952 @cindex MIPS stack
3953 Alpha- and MIPS-based computers use an unusual stack frame, which
3954 sometimes requires @value{GDBN} to search backward in the object code to
3955 find the beginning of a function.
3956
3957 @cindex response time, MIPS debugging
3958 To improve response time (especially for embedded applications, where
3959 @value{GDBN} may be restricted to a slow serial line for this search)
3960 you may want to limit the size of this search, using one of these
3961 commands:
3962
3963 @table @code
3964 @cindex @code{heuristic-fence-post} (Alpha,MIPS)
3965 @item set heuristic-fence-post @var{limit}
3966 Restrict @value{GDBN} to examining at most @var{limit} bytes in its search
3967 for the beginning of a function. A value of @var{0} (the default)
3968 means there is no limit. However, except for @var{0}, the larger the
3969 limit the more bytes @code{heuristic-fence-post} must search and
3970 therefore the longer it takes to run.
3971
3972 @item show heuristic-fence-post
3973 Display the current limit.
3974 @end table
3975
3976 @noindent
3977 These commands are available @emph{only} when @value{GDBN} is configured
3978 for debugging programs on Alpha or MIPS processors.
3979
3980
3981 @node Source, Data, Stack, Top
3982 @chapter Examining Source Files
3983
3984 @value{GDBN} can print parts of your program's source, since the debugging
3985 information recorded in the program tells @value{GDBN} what source files were
3986 used to build it. When your program stops, @value{GDBN} spontaneously prints
3987 the line where it stopped. Likewise, when you select a stack frame
3988 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3989 execution in that frame has stopped. You can print other portions of
3990 source files by explicit command.
3991
3992 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
3993 prefer to use Emacs facilities to view source; @pxref{Emacs, ,Using
3994 @value{GDBN} under @sc{gnu} Emacs}.
3995
3996 @menu
3997 * List:: Printing source lines
3998 * Search:: Searching source files
3999 * Source Path:: Specifying source directories
4000 * Machine Code:: Source and machine code
4001 @end menu
4002
4003 @node List, Search, Source, Source
4004 @section Printing source lines
4005
4006 @kindex list
4007 @kindex l
4008 To print lines from a source file, use the @code{list} command
4009 (abbreviated @code{l}). By default, ten lines are printed.
4010 There are several ways to specify what part of the file you want to print.
4011
4012 Here are the forms of the @code{list} command most commonly used:
4013
4014 @table @code
4015 @item list @var{linenum}
4016 Print lines centered around line number @var{linenum} in the
4017 current source file.
4018
4019 @item list @var{function}
4020 Print lines centered around the beginning of function
4021 @var{function}.
4022
4023 @item list
4024 Print more lines. If the last lines printed were printed with a
4025 @code{list} command, this prints lines following the last lines
4026 printed; however, if the last line printed was a solitary line printed
4027 as part of displaying a stack frame (@pxref{Stack, ,Examining the
4028 Stack}), this prints lines centered around that line.
4029
4030 @item list -
4031 Print lines just before the lines last printed.
4032 @end table
4033
4034 By default, @value{GDBN} prints ten source lines with any of these forms of
4035 the @code{list} command. You can change this using @code{set listsize}:
4036
4037 @table @code
4038 @kindex set listsize
4039 @item set listsize @var{count}
4040 Make the @code{list} command display @var{count} source lines (unless
4041 the @code{list} argument explicitly specifies some other number).
4042
4043 @kindex show listsize
4044 @item show listsize
4045 Display the number of lines that @code{list} prints.
4046 @end table
4047
4048 Repeating a @code{list} command with @key{RET} discards the argument,
4049 so it is equivalent to typing just @code{list}. This is more useful
4050 than listing the same lines again. An exception is made for an
4051 argument of @samp{-}; that argument is preserved in repetition so that
4052 each repetition moves up in the source file.
4053
4054 @cindex linespec
4055 In general, the @code{list} command expects you to supply zero, one or two
4056 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4057 of writing them but the effect is always to specify some source line.
4058 Here is a complete description of the possible arguments for @code{list}:
4059
4060 @table @code
4061 @item list @var{linespec}
4062 Print lines centered around the line specified by @var{linespec}.
4063
4064 @item list @var{first},@var{last}
4065 Print lines from @var{first} to @var{last}. Both arguments are
4066 linespecs.
4067
4068 @item list ,@var{last}
4069 Print lines ending with @var{last}.
4070
4071 @item list @var{first},
4072 Print lines starting with @var{first}.
4073
4074 @item list +
4075 Print lines just after the lines last printed.
4076
4077 @item list -
4078 Print lines just before the lines last printed.
4079
4080 @item list
4081 As described in the preceding table.
4082 @end table
4083
4084 Here are the ways of specifying a single source line---all the
4085 kinds of linespec.
4086
4087 @table @code
4088 @item @var{number}
4089 Specifies line @var{number} of the current source file.
4090 When a @code{list} command has two linespecs, this refers to
4091 the same source file as the first linespec.
4092
4093 @item +@var{offset}
4094 Specifies the line @var{offset} lines after the last line printed.
4095 When used as the second linespec in a @code{list} command that has
4096 two, this specifies the line @var{offset} lines down from the
4097 first linespec.
4098
4099 @item -@var{offset}
4100 Specifies the line @var{offset} lines before the last line printed.
4101
4102 @item @var{filename}:@var{number}
4103 Specifies line @var{number} in the source file @var{filename}.
4104
4105 @item @var{function}
4106 Specifies the line that begins the body of the function @var{function}.
4107 For example: in C, this is the line with the open brace.
4108
4109 @item @var{filename}:@var{function}
4110 Specifies the line of the open-brace that begins the body of the
4111 function @var{function} in the file @var{filename}. You only need the
4112 file name with a function name to avoid ambiguity when there are
4113 identically named functions in different source files.
4114
4115 @item *@var{address}
4116 Specifies the line containing the program address @var{address}.
4117 @var{address} may be any expression.
4118 @end table
4119
4120 @node Search, Source Path, List, Source
4121 @section Searching source files
4122 @cindex searching
4123 @kindex reverse-search
4124
4125 There are two commands for searching through the current source file for a
4126 regular expression.
4127
4128 @table @code
4129 @kindex search
4130 @kindex forward-search
4131 @item forward-search @var{regexp}
4132 @itemx search @var{regexp}
4133 The command @samp{forward-search @var{regexp}} checks each line,
4134 starting with the one following the last line listed, for a match for
4135 @var{regexp}. It lists the line that is found. You can use the
4136 synonym @samp{search @var{regexp}} or abbreviate the command name as
4137 @code{fo}.
4138
4139 @item reverse-search @var{regexp}
4140 The command @samp{reverse-search @var{regexp}} checks each line, starting
4141 with the one before the last line listed and going backward, for a match
4142 for @var{regexp}. It lists the line that is found. You can abbreviate
4143 this command as @code{rev}.
4144 @end table
4145
4146 @node Source Path, Machine Code, Search, Source
4147 @section Specifying source directories
4148
4149 @cindex source path
4150 @cindex directories for source files
4151 Executable programs sometimes do not record the directories of the source
4152 files from which they were compiled, just the names. Even when they do,
4153 the directories could be moved between the compilation and your debugging
4154 session. @value{GDBN} has a list of directories to search for source files;
4155 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4156 it tries all the directories in the list, in the order they are present
4157 in the list, until it finds a file with the desired name. Note that
4158 the executable search path is @emph{not} used for this purpose. Neither is
4159 the current working directory, unless it happens to be in the source
4160 path.
4161
4162 If @value{GDBN} cannot find a source file in the source path, and the
4163 object program records a directory, @value{GDBN} tries that directory
4164 too. If the source path is empty, and there is no record of the
4165 compilation directory, @value{GDBN} looks in the current directory as a
4166 last resort.
4167
4168 Whenever you reset or rearrange the source path, @value{GDBN} clears out
4169 any information it has cached about where source files are found and where
4170 each line is in the file.
4171
4172 @kindex directory
4173 @kindex dir
4174 When you start @value{GDBN}, its source path is empty.
4175 To add other directories, use the @code{directory} command.
4176
4177 @table @code
4178 @item directory @var{dirname} @dots{}
4179 @item dir @var{dirname} @dots{}
4180 Add directory @var{dirname} to the front of the source path. Several
4181 directory names may be given to this command, separated by @samp{:} or
4182 whitespace. You may specify a directory that is already in the source
4183 path; this moves it forward, so @value{GDBN} searches it sooner.
4184
4185 @kindex cdir
4186 @kindex cwd
4187 @kindex $cdir
4188 @kindex $cwd
4189 @cindex compilation directory
4190 @cindex current directory
4191 @cindex working directory
4192 @cindex directory, current
4193 @cindex directory, compilation
4194 You can use the string @samp{$cdir} to refer to the compilation
4195 directory (if one is recorded), and @samp{$cwd} to refer to the current
4196 working directory. @samp{$cwd} is not the same as @samp{.}---the former
4197 tracks the current working directory as it changes during your @value{GDBN}
4198 session, while the latter is immediately expanded to the current
4199 directory at the time you add an entry to the source path.
4200
4201 @item directory
4202 Reset the source path to empty again. This requires confirmation.
4203
4204 @c RET-repeat for @code{directory} is explicitly disabled, but since
4205 @c repeating it would be a no-op we do not say that. (thanks to RMS)
4206
4207 @item show directories
4208 @kindex show directories
4209 Print the source path: show which directories it contains.
4210 @end table
4211
4212 If your source path is cluttered with directories that are no longer of
4213 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4214 versions of source. You can correct the situation as follows:
4215
4216 @enumerate
4217 @item
4218 Use @code{directory} with no argument to reset the source path to empty.
4219
4220 @item
4221 Use @code{directory} with suitable arguments to reinstall the
4222 directories you want in the source path. You can add all the
4223 directories in one command.
4224 @end enumerate
4225
4226 @node Machine Code, , Source Path, Source
4227 @section Source and machine code
4228
4229 You can use the command @code{info line} to map source lines to program
4230 addresses (and vice versa), and the command @code{disassemble} to display
4231 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
4232 mode, the @code{info line} command now causes the arrow to point to the
4233 line specified. Also, @code{info line} prints addresses in symbolic form as
4234 well as hex.
4235
4236 @table @code
4237 @kindex info line
4238 @item info line @var{linespec}
4239 Print the starting and ending addresses of the compiled code for
4240 source line @var{linespec}. You can specify source lines in any of
4241 the ways understood by the @code{list} command (@pxref{List, ,Printing
4242 source lines}).
4243 @end table
4244
4245 For example, we can use @code{info line} to discover the location of
4246 the object code for the first line of function
4247 @code{m4_changequote}:
4248
4249 @smallexample
4250 (@value{GDBP}) info line m4_changecom
4251 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4252 @end smallexample
4253
4254 @noindent
4255 We can also inquire (using @code{*@var{addr}} as the form for
4256 @var{linespec}) what source line covers a particular address:
4257 @smallexample
4258 (@value{GDBP}) info line *0x63ff
4259 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4260 @end smallexample
4261
4262 @cindex @code{$_} and @code{info line}
4263 After @code{info line}, the default address for the @code{x} command
4264 is changed to the starting address of the line, so that @samp{x/i} is
4265 sufficient to begin examining the machine code (@pxref{Memory,
4266 ,Examining memory}). Also, this address is saved as the value of the
4267 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4268 variables}).
4269
4270 @table @code
4271 @kindex disassemble
4272 @cindex assembly instructions
4273 @cindex instructions, assembly
4274 @cindex machine instructions
4275 @cindex listing machine instructions
4276 @item disassemble
4277 This specialized command dumps a range of memory as machine
4278 instructions. The default memory range is the function surrounding the
4279 program counter of the selected frame. A single argument to this
4280 command is a program counter value; @value{GDBN} dumps the function
4281 surrounding this value. Two arguments specify a range of addresses
4282 (first inclusive, second exclusive) to dump.
4283 @end table
4284
4285 The following example shows the disassembly of a range of addresses of
4286 HP PA-RISC 2.0 code:
4287
4288 @smallexample
4289 (@value{GDBP}) disas 0x32c4 0x32e4
4290 Dump of assembler code from 0x32c4 to 0x32e4:
4291 0x32c4 <main+204>: addil 0,dp
4292 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4293 0x32cc <main+212>: ldil 0x3000,r31
4294 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4295 0x32d4 <main+220>: ldo 0(r31),rp
4296 0x32d8 <main+224>: addil -0x800,dp
4297 0x32dc <main+228>: ldo 0x588(r1),r26
4298 0x32e0 <main+232>: ldil 0x3000,r31
4299 End of assembler dump.
4300 @end smallexample
4301
4302 Some architectures have more than one commonly-used set of instruction
4303 mnemonics or other syntax.
4304
4305 @table @code
4306 @kindex set assembly-language
4307 @cindex assembly instructions
4308 @cindex instructions, assembly
4309 @cindex machine instructions
4310 @cindex listing machine instructions
4311 @item set assembly-language @var{instruction-set}
4312 Select the instruction set to use when disassembling the
4313 program via the @code{disassemble} or @code{x/i} commands.
4314
4315 Currently this command is only defined for the Intel x86 family. You
4316 can set @var{instruction-set} to either @code{i386} or @code{i8086}.
4317 The default is @code{i386}.
4318 @end table
4319
4320
4321 @node Data, Languages, Source, Top
4322 @chapter Examining Data
4323
4324 @cindex printing data
4325 @cindex examining data
4326 @kindex print
4327 @kindex inspect
4328 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4329 @c document because it is nonstandard... Under Epoch it displays in a
4330 @c different window or something like that.
4331 The usual way to examine data in your program is with the @code{print}
4332 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4333 evaluates and prints the value of an expression of the language your
4334 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4335 Different Languages}).
4336
4337 @table @code
4338 @item print @var{exp}
4339 @itemx print /@var{f} @var{exp}
4340 @var{exp} is an expression (in the source language). By default the
4341 value of @var{exp} is printed in a format appropriate to its data type;
4342 you can choose a different format by specifying @samp{/@var{f}}, where
4343 @var{f} is a letter specifying the format; @pxref{Output Formats,,Output
4344 formats}.
4345
4346 @item print
4347 @itemx print /@var{f}
4348 If you omit @var{exp}, @value{GDBN} displays the last value again (from the
4349 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4350 conveniently inspect the same value in an alternative format.
4351 @end table
4352
4353 A more low-level way of examining data is with the @code{x} command.
4354 It examines data in memory at a specified address and prints it in a
4355 specified format. @xref{Memory, ,Examining memory}.
4356
4357 If you are interested in information about types, or about how the
4358 fields of a struct or class are declared, use the @code{ptype @var{exp}}
4359 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4360 Table}.
4361
4362 @menu
4363 * Expressions:: Expressions
4364 * Variables:: Program variables
4365 * Arrays:: Artificial arrays
4366 * Output Formats:: Output formats
4367 * Memory:: Examining memory
4368 * Auto Display:: Automatic display
4369 * Print Settings:: Print settings
4370 * Value History:: Value history
4371 * Convenience Vars:: Convenience variables
4372 * Registers:: Registers
4373 * Floating Point Hardware:: Floating point hardware
4374 @end menu
4375
4376 @node Expressions, Variables, Data, Data
4377 @section Expressions
4378
4379 @cindex expressions
4380 @code{print} and many other @value{GDBN} commands accept an expression and
4381 compute its value. Any kind of constant, variable or operator defined
4382 by the programming language you are using is valid in an expression in
4383 @value{GDBN}. This includes conditional expressions, function calls, casts
4384 and string constants. It unfortunately does not include symbols defined
4385 by preprocessor @code{#define} commands.
4386
4387 @value{GDBN} now supports array constants in expressions input by
4388 the user. The syntax is @var{@{element, element@dots{}@}}. For example,
4389 you can now use the command @code{print @{1, 2, 3@}} to build up an array in
4390 memory that is malloc'd in the target program.
4391
4392 Because C is so widespread, most of the expressions shown in examples in
4393 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4394 Languages}, for information on how to use expressions in other
4395 languages.
4396
4397 In this section, we discuss operators that you can use in @value{GDBN}
4398 expressions regardless of your programming language.
4399
4400 Casts are supported in all languages, not just in C, because it is so
4401 useful to cast a number into a pointer in order to examine a structure
4402 at that address in memory.
4403 @c FIXME: casts supported---Mod2 true?
4404
4405 @value{GDBN} supports these operators, in addition to those common
4406 to programming languages:
4407
4408 @table @code
4409 @item @@
4410 @samp{@@} is a binary operator for treating parts of memory as arrays.
4411 @xref{Arrays, ,Artificial arrays}, for more information.
4412
4413 @item ::
4414 @samp{::} allows you to specify a variable in terms of the file or
4415 function where it is defined. @xref{Variables, ,Program variables}.
4416
4417 @cindex @{@var{type}@}
4418 @cindex type casting memory
4419 @cindex memory, viewing as typed object
4420 @cindex casts, to view memory
4421 @item @{@var{type}@} @var{addr}
4422 Refers to an object of type @var{type} stored at address @var{addr} in
4423 memory. @var{addr} may be any expression whose value is an integer or
4424 pointer (but parentheses are required around binary operators, just as in
4425 a cast). This construct is allowed regardless of what kind of data is
4426 normally supposed to reside at @var{addr}.
4427 @end table
4428
4429 @node Variables, Arrays, Expressions, Data
4430 @section Program variables
4431
4432 The most common kind of expression to use is the name of a variable
4433 in your program.
4434
4435 Variables in expressions are understood in the selected stack frame
4436 (@pxref{Selection, ,Selecting a frame}); they must be either:
4437
4438 @itemize @bullet
4439 @item
4440 global (or file-static)
4441 @end itemize
4442
4443 @noindent or
4444
4445 @itemize @bullet
4446 @item
4447 visible according to the scope rules of the
4448 programming language from the point of execution in that frame
4449 @end itemize
4450
4451 @noindent This means that in the function
4452
4453 @example
4454 foo (a)
4455 int a;
4456 @{
4457 bar (a);
4458 @{
4459 int b = test ();
4460 bar (b);
4461 @}
4462 @}
4463 @end example
4464
4465 @noindent
4466 you can examine and use the variable @code{a} whenever your program is
4467 executing within the function @code{foo}, but you can only use or
4468 examine the variable @code{b} while your program is executing inside
4469 the block where @code{b} is declared.
4470
4471 @cindex variable name conflict
4472 There is an exception: you can refer to a variable or function whose
4473 scope is a single source file even if the current execution point is not
4474 in this file. But it is possible to have more than one such variable or
4475 function with the same name (in different source files). If that
4476 happens, referring to that name has unpredictable effects. If you wish,
4477 you can specify a static variable in a particular function or file,
4478 using the colon-colon notation:
4479
4480 @cindex colon-colon
4481 @iftex
4482 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4483 @kindex ::
4484 @end iftex
4485 @example
4486 @var{file}::@var{variable}
4487 @var{function}::@var{variable}
4488 @end example
4489
4490 @noindent
4491 Here @var{file} or @var{function} is the name of the context for the
4492 static @var{variable}. In the case of file names, you can use quotes to
4493 make sure @value{GDBN} parses the file name as a single word---for example,
4494 to print a global value of @code{x} defined in @file{f2.c}:
4495
4496 @example
4497 (@value{GDBP}) p 'f2.c'::x
4498 @end example
4499
4500 @cindex C++ scope resolution
4501 This use of @samp{::} is very rarely in conflict with the very similar
4502 use of the same notation in C++. @value{GDBN} also supports use of the C++
4503 scope resolution operator in @value{GDBN} expressions.
4504 @c FIXME: Um, so what happens in one of those rare cases where it's in
4505 @c conflict?? --mew
4506
4507 @cindex wrong values
4508 @cindex variable values, wrong
4509 @quotation
4510 @emph{Warning:} Occasionally, a local variable may appear to have the
4511 wrong value at certain points in a function---just after entry to a new
4512 scope, and just before exit.
4513 @end quotation
4514 You may see this problem when you are stepping by machine instructions.
4515 This is because, on most machines, it takes more than one instruction to
4516 set up a stack frame (including local variable definitions); if you are
4517 stepping by machine instructions, variables may appear to have the wrong
4518 values until the stack frame is completely built. On exit, it usually
4519 also takes more than one machine instruction to destroy a stack frame;
4520 after you begin stepping through that group of instructions, local
4521 variable definitions may be gone.
4522
4523 This may also happen when the compiler does significant optimizations.
4524 To be sure of always seeing accurate values, turn off all optimization
4525 when compiling.
4526
4527 @node Arrays, Output Formats, Variables, Data
4528 @section Artificial arrays
4529
4530 @cindex artificial array
4531 @kindex @@
4532 It is often useful to print out several successive objects of the
4533 same type in memory; a section of an array, or an array of
4534 dynamically determined size for which only a pointer exists in the
4535 program.
4536
4537 You can do this by referring to a contiguous span of memory as an
4538 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4539 operand of @samp{@@} should be the first element of the desired array
4540 and be an individual object. The right operand should be the desired length
4541 of the array. The result is an array value whose elements are all of
4542 the type of the left argument. The first element is actually the left
4543 argument; the second element comes from bytes of memory immediately
4544 following those that hold the first element, and so on. Here is an
4545 example. If a program says
4546
4547 @example
4548 int *array = (int *) malloc (len * sizeof (int));
4549 @end example
4550
4551 @noindent
4552 you can print the contents of @code{array} with
4553
4554 @example
4555 p *array@@len
4556 @end example
4557
4558 The left operand of @samp{@@} must reside in memory. Array values made
4559 with @samp{@@} in this way behave just like other arrays in terms of
4560 subscripting, and are coerced to pointers when used in expressions.
4561 Artificial arrays most often appear in expressions via the value history
4562 (@pxref{Value History, ,Value history}), after printing one out.
4563
4564 Another way to create an artificial array is to use a cast.
4565 This re-interprets a value as if it were an array.
4566 The value need not be in memory:
4567 @example
4568 (@value{GDBP}) p/x (short[2])0x12345678
4569 $1 = @{0x1234, 0x5678@}
4570 @end example
4571
4572 As a convenience, if you leave the array length out (as in
4573 @samp{(@var{type})[])@var{value}}) gdb calculates the size to fill
4574 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4575 @example
4576 (@value{GDBP}) p/x (short[])0x12345678
4577 $2 = @{0x1234, 0x5678@}
4578 @end example
4579
4580 Sometimes the artificial array mechanism is not quite enough; in
4581 moderately complex data structures, the elements of interest may not
4582 actually be adjacent---for example, if you are interested in the values
4583 of pointers in an array. One useful work-around in this situation is
4584 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4585 variables}) as a counter in an expression that prints the first
4586 interesting value, and then repeat that expression via @key{RET}. For
4587 instance, suppose you have an array @code{dtab} of pointers to
4588 structures, and you are interested in the values of a field @code{fv}
4589 in each structure. Here is an example of what you might type:
4590
4591 @example
4592 set $i = 0
4593 p dtab[$i++]->fv
4594 @key{RET}
4595 @key{RET}
4596 @dots{}
4597 @end example
4598
4599 @node Output Formats, Memory, Arrays, Data
4600 @section Output formats
4601
4602 @cindex formatted output
4603 @cindex output formats
4604 By default, @value{GDBN} prints a value according to its data type. Sometimes
4605 this is not what you want. For example, you might want to print a number
4606 in hex, or a pointer in decimal. Or you might want to view data in memory
4607 at a certain address as a character string or as an instruction. To do
4608 these things, specify an @dfn{output format} when you print a value.
4609
4610 The simplest use of output formats is to say how to print a value
4611 already computed. This is done by starting the arguments of the
4612 @code{print} command with a slash and a format letter. The format
4613 letters supported are:
4614
4615 @table @code
4616 @item x
4617 Regard the bits of the value as an integer, and print the integer in
4618 hexadecimal.
4619
4620 @item d
4621 Print as integer in signed decimal.
4622
4623 @item u
4624 Print as integer in unsigned decimal.
4625
4626 @item o
4627 Print as integer in octal.
4628
4629 @item t
4630 Print as integer in binary. The letter @samp{t} stands for ``two''.
4631 @footnote{@samp{b} cannot be used because these format letters are also
4632 used with the @code{x} command, where @samp{b} stands for ``byte'';
4633 @pxref{Memory,,Examining memory}.}
4634
4635 @item a
4636 @cindex unknown address, locating
4637 Print as an address, both absolute in hexadecimal and as an offset from
4638 the nearest preceding symbol. You can use this format used to discover
4639 where (in what function) an unknown address is located:
4640
4641 @example
4642 (@value{GDBP}) p/a 0x54320
4643 $3 = 0x54320 <_initialize_vx+396>
4644 @end example
4645
4646 @item c
4647 Regard as an integer and print it as a character constant.
4648
4649 @item f
4650 Regard the bits of the value as a floating point number and print
4651 using typical floating point syntax.
4652 @end table
4653
4654 For example, to print the program counter in hex (@pxref{Registers}), type
4655
4656 @example
4657 p/x $pc
4658 @end example
4659
4660 @noindent
4661 Note that no space is required before the slash; this is because command
4662 names in @value{GDBN} cannot contain a slash.
4663
4664 To reprint the last value in the value history with a different format,
4665 you can use the @code{print} command with just a format and no
4666 expression. For example, @samp{p/x} reprints the last value in hex.
4667
4668 @node Memory, Auto Display, Output Formats, Data
4669 @section Examining memory
4670
4671 You can use the command @code{x} (for ``examine'') to examine memory in
4672 any of several formats, independently of your program's data types.
4673
4674 @cindex examining memory
4675 @table @code
4676 @kindex x
4677 @item x/@var{nfu} @var{addr}
4678 @itemx x @var{addr}
4679 @itemx x
4680 Use the @code{x} command to examine memory.
4681 @end table
4682
4683 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4684 much memory to display and how to format it; @var{addr} is an
4685 expression giving the address where you want to start displaying memory.
4686 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4687 Several commands set convenient defaults for @var{addr}.
4688
4689 @table @r
4690 @item @var{n}, the repeat count
4691 The repeat count is a decimal integer; the default is 1. It specifies
4692 how much memory (counting by units @var{u}) to display.
4693 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4694 @c 4.1.2.
4695
4696 @item @var{f}, the display format
4697 The display format is one of the formats used by @code{print},
4698 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4699 The default is @samp{x} (hexadecimal) initially.
4700 The default changes each time you use either @code{x} or @code{print}.
4701
4702 @item @var{u}, the unit size
4703 The unit size is any of
4704
4705 @table @code
4706 @item b
4707 Bytes.
4708 @item h
4709 Halfwords (two bytes).
4710 @item w
4711 Words (four bytes). This is the initial default.
4712 @item g
4713 Giant words (eight bytes).
4714 @end table
4715
4716 Each time you specify a unit size with @code{x}, that size becomes the
4717 default unit the next time you use @code{x}. (For the @samp{s} and
4718 @samp{i} formats, the unit size is ignored and is normally not written.)
4719
4720 @item @var{addr}, starting display address
4721 @var{addr} is the address where you want @value{GDBN} to begin displaying
4722 memory. The expression need not have a pointer value (though it may);
4723 it is always interpreted as an integer address of a byte of memory.
4724 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4725 @var{addr} is usually just after the last address examined---but several
4726 other commands also set the default address: @code{info breakpoints} (to
4727 the address of the last breakpoint listed), @code{info line} (to the
4728 starting address of a line), and @code{print} (if you use it to display
4729 a value from memory).
4730 @end table
4731
4732 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4733 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4734 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4735 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4736 @pxref{Registers}) in hexadecimal (@samp{x}).
4737
4738 Since the letters indicating unit sizes are all distinct from the
4739 letters specifying output formats, you do not have to remember whether
4740 unit size or format comes first; either order works. The output
4741 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4742 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4743
4744 Even though the unit size @var{u} is ignored for the formats @samp{s}
4745 and @samp{i}, you might still want to use a count @var{n}; for example,
4746 @samp{3i} specifies that you want to see three machine instructions,
4747 including any operands. The command @code{disassemble} gives an
4748 alternative way of inspecting machine instructions; @pxref{Machine
4749 Code,,Source and machine code}.
4750
4751 All the defaults for the arguments to @code{x} are designed to make it
4752 easy to continue scanning memory with minimal specifications each time
4753 you use @code{x}. For example, after you have inspected three machine
4754 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4755 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4756 the repeat count @var{n} is used again; the other arguments default as
4757 for successive uses of @code{x}.
4758
4759 @cindex @code{$_}, @code{$__}, and value history
4760 The addresses and contents printed by the @code{x} command are not saved
4761 in the value history because there is often too much of them and they
4762 would get in the way. Instead, @value{GDBN} makes these values available for
4763 subsequent use in expressions as values of the convenience variables
4764 @code{$_} and @code{$__}. After an @code{x} command, the last address
4765 examined is available for use in expressions in the convenience variable
4766 @code{$_}. The contents of that address, as examined, are available in
4767 the convenience variable @code{$__}.
4768
4769 If the @code{x} command has a repeat count, the address and contents saved
4770 are from the last memory unit printed; this is not the same as the last
4771 address printed if several units were printed on the last line of output.
4772
4773 @node Auto Display, Print Settings, Memory, Data
4774 @section Automatic display
4775 @cindex automatic display
4776 @cindex display of expressions
4777
4778 If you find that you want to print the value of an expression frequently
4779 (to see how it changes), you might want to add it to the @dfn{automatic
4780 display list} so that @value{GDBN} prints its value each time your program stops.
4781 Each expression added to the list is given a number to identify it;
4782 to remove an expression from the list, you specify that number.
4783 The automatic display looks like this:
4784
4785 @example
4786 2: foo = 38
4787 3: bar[5] = (struct hack *) 0x3804
4788 @end example
4789
4790 @noindent
4791 This display shows item numbers, expressions and their current values. As with
4792 displays you request manually using @code{x} or @code{print}, you can
4793 specify the output format you prefer; in fact, @code{display} decides
4794 whether to use @code{print} or @code{x} depending on how elaborate your
4795 format specification is---it uses @code{x} if you specify a unit size,
4796 or one of the two formats (@samp{i} and @samp{s}) that are only
4797 supported by @code{x}; otherwise it uses @code{print}.
4798
4799 @table @code
4800 @kindex display
4801 @item display @var{exp}
4802 Add the expression @var{exp} to the list of expressions to display
4803 each time your program stops. @xref{Expressions, ,Expressions}.
4804
4805 @code{display} does not repeat if you press @key{RET} again after using it.
4806
4807 @item display/@var{fmt} @var{exp}
4808 For @var{fmt} specifying only a display format and not a size or
4809 count, add the expression @var{exp} to the auto-display list but
4810 arrange to display it each time in the specified format @var{fmt}.
4811 @xref{Output Formats,,Output formats}.
4812
4813 @item display/@var{fmt} @var{addr}
4814 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4815 number of units, add the expression @var{addr} as a memory address to
4816 be examined each time your program stops. Examining means in effect
4817 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4818 @end table
4819
4820 For example, @samp{display/i $pc} can be helpful, to see the machine
4821 instruction about to be executed each time execution stops (@samp{$pc}
4822 is a common name for the program counter; @pxref{Registers}).
4823
4824 @table @code
4825 @kindex delete display
4826 @kindex undisplay
4827 @item undisplay @var{dnums}@dots{}
4828 @itemx delete display @var{dnums}@dots{}
4829 Remove item numbers @var{dnums} from the list of expressions to display.
4830
4831 @code{undisplay} does not repeat if you press @key{RET} after using it.
4832 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4833
4834 @kindex disable display
4835 @item disable display @var{dnums}@dots{}
4836 Disable the display of item numbers @var{dnums}. A disabled display
4837 item is not printed automatically, but is not forgotten. It may be
4838 enabled again later.
4839
4840 @kindex enable display
4841 @item enable display @var{dnums}@dots{}
4842 Enable display of item numbers @var{dnums}. It becomes effective once
4843 again in auto display of its expression, until you specify otherwise.
4844
4845 @item display
4846 Display the current values of the expressions on the list, just as is
4847 done when your program stops.
4848
4849 @kindex info display
4850 @item info display
4851 Print the list of expressions previously set up to display
4852 automatically, each one with its item number, but without showing the
4853 values. This includes disabled expressions, which are marked as such.
4854 It also includes expressions which would not be displayed right now
4855 because they refer to automatic variables not currently available.
4856 @end table
4857
4858 If a display expression refers to local variables, then it does not make
4859 sense outside the lexical context for which it was set up. Such an
4860 expression is disabled when execution enters a context where one of its
4861 variables is not defined. For example, if you give the command
4862 @code{display last_char} while inside a function with an argument
4863 @code{last_char}, @value{GDBN} displays this argument while your program
4864 continues to stop inside that function. When it stops elsewhere---where
4865 there is no variable @code{last_char}---the display is disabled
4866 automatically. The next time your program stops where @code{last_char}
4867 is meaningful, you can enable the display expression once again.
4868
4869 @node Print Settings, Value History, Auto Display, Data
4870 @section Print settings
4871
4872 @cindex format options
4873 @cindex print settings
4874 @value{GDBN} provides the following ways to control how arrays, structures,
4875 and symbols are printed.
4876
4877 @noindent
4878 These settings are useful for debugging programs in any language:
4879
4880 @table @code
4881 @kindex set print address
4882 @item set print address
4883 @itemx set print address on
4884 @value{GDBN} prints memory addresses showing the location of stack
4885 traces, structure values, pointer values, breakpoints, and so forth,
4886 even when it also displays the contents of those addresses. The default
4887 is @code{on}. For example, this is what a stack frame display looks like with
4888 @code{set print address on}:
4889
4890 @smallexample
4891 @group
4892 (@value{GDBP}) f
4893 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4894 at input.c:530
4895 530 if (lquote != def_lquote)
4896 @end group
4897 @end smallexample
4898
4899 @item set print address off
4900 Do not print addresses when displaying their contents. For example,
4901 this is the same stack frame displayed with @code{set print address off}:
4902
4903 @smallexample
4904 @group
4905 (@value{GDBP}) set print addr off
4906 (@value{GDBP}) f
4907 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4908 530 if (lquote != def_lquote)
4909 @end group
4910 @end smallexample
4911
4912 You can use @samp{set print address off} to eliminate all machine
4913 dependent displays from the @value{GDBN} interface. For example, with
4914 @code{print address off}, you should get the same text for backtraces on
4915 all machines---whether or not they involve pointer arguments.
4916
4917 @kindex show print address
4918 @item show print address
4919 Show whether or not addresses are to be printed.
4920 @end table
4921
4922 When @value{GDBN} prints a symbolic address, it normally prints the
4923 closest earlier symbol plus an offset. If that symbol does not uniquely
4924 identify the address (for example, it is a name whose scope is a single
4925 source file), you may need to clarify. One way to do this is with
4926 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4927 you can set @value{GDBN} to print the source file and line number when
4928 it prints a symbolic address:
4929
4930 @table @code
4931 @kindex set print symbol-filename
4932 @item set print symbol-filename on
4933 Tell @value{GDBN} to print the source file name and line number of a
4934 symbol in the symbolic form of an address.
4935
4936 @item set print symbol-filename off
4937 Do not print source file name and line number of a symbol. This is the
4938 default.
4939
4940 @kindex show print symbol-filename
4941 @item show print symbol-filename
4942 Show whether or not @value{GDBN} will print the source file name and
4943 line number of a symbol in the symbolic form of an address.
4944 @end table
4945
4946 Another situation where it is helpful to show symbol filenames and line
4947 numbers is when disassembling code; @value{GDBN} shows you the line
4948 number and source file that corresponds to each instruction.
4949
4950 Also, you may wish to see the symbolic form only if the address being
4951 printed is reasonably close to the closest earlier symbol:
4952
4953 @table @code
4954 @kindex set print max-symbolic-offset
4955 @item set print max-symbolic-offset @var{max-offset}
4956 Tell @value{GDBN} to only display the symbolic form of an address if the
4957 offset between the closest earlier symbol and the address is less than
4958 @var{max-offset}. The default is 0, which tells @value{GDBN}
4959 to always print the symbolic form of an address if any symbol precedes it.
4960
4961 @kindex show print max-symbolic-offset
4962 @item show print max-symbolic-offset
4963 Ask how large the maximum offset is that @value{GDBN} prints in a
4964 symbolic address.
4965 @end table
4966
4967 @cindex wild pointer, interpreting
4968 @cindex pointer, finding referent
4969 If you have a pointer and you are not sure where it points, try
4970 @samp{set print symbol-filename on}. Then you can determine the name
4971 and source file location of the variable where it points, using
4972 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4973 For example, here @value{GDBN} shows that a variable @code{ptt} points
4974 at another variable @code{t}, defined in @file{hi2.c}:
4975
4976 @example
4977 (@value{GDBP}) set print symbol-filename on
4978 (@value{GDBP}) p/a ptt
4979 $4 = 0xe008 <t in hi2.c>
4980 @end example
4981
4982 @quotation
4983 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4984 does not show the symbol name and filename of the referent, even with
4985 the appropriate @code{set print} options turned on.
4986 @end quotation
4987
4988 Other settings control how different kinds of objects are printed:
4989
4990 @table @code
4991 @kindex set print array
4992 @item set print array
4993 @itemx set print array on
4994 Pretty print arrays. This format is more convenient to read,
4995 but uses more space. The default is off.
4996
4997 @item set print array off
4998 Return to compressed format for arrays.
4999
5000 @kindex show print array
5001 @item show print array
5002 Show whether compressed or pretty format is selected for displaying
5003 arrays.
5004
5005 @kindex set print elements
5006 @item set print elements @var{number-of-elements}
5007 Set a limit on how many elements of an array @value{GDBN} will print.
5008 If @value{GDBN} is printing a large array, it stops printing after it has
5009 printed the number of elements set by the @code{set print elements} command.
5010 This limit also applies to the display of strings.
5011 Setting @var{number-of-elements} to zero means that the printing is unlimited.
5012
5013 @kindex show print elements
5014 @item show print elements
5015 Display the number of elements of a large array that @value{GDBN} will print.
5016 If the number is 0, then the printing is unlimited.
5017
5018 @kindex set print null-stop
5019 @item set print null-stop
5020 Cause @value{GDBN} to stop printing the characters of an array when the first
5021 @sc{NULL} is encountered. This is useful when large arrays actually
5022 contain only short strings.
5023
5024 @kindex set print pretty
5025 @item set print pretty on
5026 Cause @value{GDBN} to print structures in an indented format with one member
5027 per line, like this:
5028
5029 @smallexample
5030 @group
5031 $1 = @{
5032 next = 0x0,
5033 flags = @{
5034 sweet = 1,
5035 sour = 1
5036 @},
5037 meat = 0x54 "Pork"
5038 @}
5039 @end group
5040 @end smallexample
5041
5042 @item set print pretty off
5043 Cause @value{GDBN} to print structures in a compact format, like this:
5044
5045 @smallexample
5046 @group
5047 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5048 meat = 0x54 "Pork"@}
5049 @end group
5050 @end smallexample
5051
5052 @noindent
5053 This is the default format.
5054
5055 @kindex show print pretty
5056 @item show print pretty
5057 Show which format @value{GDBN} is using to print structures.
5058
5059 @kindex set print sevenbit-strings
5060 @item set print sevenbit-strings on
5061 Print using only seven-bit characters; if this option is set,
5062 @value{GDBN} displays any eight-bit characters (in strings or
5063 character values) using the notation @code{\}@var{nnn}. This setting is
5064 best if you are working in English (@sc{ascii}) and you use the
5065 high-order bit of characters as a marker or ``meta'' bit.
5066
5067 @item set print sevenbit-strings off
5068 Print full eight-bit characters. This allows the use of more
5069 international character sets, and is the default.
5070
5071 @kindex show print sevenbit-strings
5072 @item show print sevenbit-strings
5073 Show whether or not @value{GDBN} is printing only seven-bit characters.
5074
5075 @kindex set print union
5076 @item set print union on
5077 Tell @value{GDBN} to print unions which are contained in structures. This
5078 is the default setting.
5079
5080 @item set print union off
5081 Tell @value{GDBN} not to print unions which are contained in structures.
5082
5083 @kindex show print union
5084 @item show print union
5085 Ask @value{GDBN} whether or not it will print unions which are contained in
5086 structures.
5087
5088 For example, given the declarations
5089
5090 @smallexample
5091 typedef enum @{Tree, Bug@} Species;
5092 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5093 typedef enum @{Caterpillar, Cocoon, Butterfly@}
5094 Bug_forms;
5095
5096 struct thing @{
5097 Species it;
5098 union @{
5099 Tree_forms tree;
5100 Bug_forms bug;
5101 @} form;
5102 @};
5103
5104 struct thing foo = @{Tree, @{Acorn@}@};
5105 @end smallexample
5106
5107 @noindent
5108 with @code{set print union on} in effect @samp{p foo} would print
5109
5110 @smallexample
5111 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5112 @end smallexample
5113
5114 @noindent
5115 and with @code{set print union off} in effect it would print
5116
5117 @smallexample
5118 $1 = @{it = Tree, form = @{...@}@}
5119 @end smallexample
5120 @end table
5121
5122 @need 1000
5123 @noindent
5124 These settings are of interest when debugging C++ programs:
5125
5126 @table @code
5127 @cindex demangling
5128 @kindex set print demangle
5129 @item set print demangle
5130 @itemx set print demangle on
5131 Print C++ names in their source form rather than in the encoded
5132 (``mangled'') form passed to the assembler and linker for type-safe
5133 linkage. The default is @samp{on}.
5134
5135 @kindex show print demangle
5136 @item show print demangle
5137 Show whether C++ names are printed in mangled or demangled form.
5138
5139 @kindex set print asm-demangle
5140 @item set print asm-demangle
5141 @itemx set print asm-demangle on
5142 Print C++ names in their source form rather than their mangled form, even
5143 in assembler code printouts such as instruction disassemblies.
5144 The default is off.
5145
5146 @kindex show print asm-demangle
5147 @item show print asm-demangle
5148 Show whether C++ names in assembly listings are printed in mangled
5149 or demangled form.
5150
5151 @kindex set demangle-style
5152 @cindex C++ symbol decoding style
5153 @cindex symbol decoding style, C++
5154 @item set demangle-style @var{style}
5155 Choose among several encoding schemes used by different compilers to
5156 represent C++ names. The choices for @var{style} are currently:
5157
5158 @table @code
5159 @item auto
5160 Allow @value{GDBN} to choose a decoding style by inspecting your program.
5161
5162 @item gnu
5163 Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
5164 @ifclear HPPA
5165 This is the default.
5166 @end ifclear
5167
5168 @item hp
5169 Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5170
5171 @item lucid
5172 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5173
5174 @item arm
5175 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5176 @strong{Warning:} this setting alone is not sufficient to allow
5177 debugging @code{cfront}-generated executables. @value{GDBN} would
5178 require further enhancement to permit that.
5179
5180 @end table
5181 If you omit @var{style}, you will see a list of possible formats.
5182
5183 @kindex show demangle-style
5184 @item show demangle-style
5185 Display the encoding style currently in use for decoding C++ symbols.
5186
5187 @kindex set print object
5188 @item set print object
5189 @itemx set print object on
5190 When displaying a pointer to an object, identify the @emph{actual}
5191 (derived) type of the object rather than the @emph{declared} type, using
5192 the virtual function table.
5193
5194 @item set print object off
5195 Display only the declared type of objects, without reference to the
5196 virtual function table. This is the default setting.
5197
5198 @kindex show print object
5199 @item show print object
5200 Show whether actual, or declared, object types are displayed.
5201
5202 @kindex set print static-members
5203 @item set print static-members
5204 @itemx set print static-members on
5205 Print static members when displaying a C++ object. The default is on.
5206
5207 @item set print static-members off
5208 Do not print static members when displaying a C++ object.
5209
5210 @kindex show print static-members
5211 @item show print static-members
5212 Show whether C++ static members are printed, or not.
5213
5214 @c These don't work with HP ANSI C++ yet.
5215 @kindex set print vtbl
5216 @item set print vtbl
5217 @itemx set print vtbl on
5218 Pretty print C++ virtual function tables. The default is off.
5219 @ifset HPPA
5220 (The @code{vtbl} commands do not work on programs compiled with the HP
5221 ANSI C++ compiler (@code{aCC}).)
5222 @end ifset
5223
5224 @item set print vtbl off
5225 Do not pretty print C++ virtual function tables.
5226
5227 @kindex show print vtbl
5228 @item show print vtbl
5229 Show whether C++ virtual function tables are pretty printed, or not.
5230 @end table
5231
5232 @node Value History, Convenience Vars, Print Settings, Data
5233 @section Value history
5234
5235 @cindex value history
5236 Values printed by the @code{print} command are saved in the @value{GDBN}
5237 @dfn{value history}. This allows you to refer to them in other expressions.
5238 Values are kept until the symbol table is re-read or discarded
5239 (for example with the @code{file} or @code{symbol-file} commands).
5240 When the symbol table changes, the value history is discarded,
5241 since the values may contain pointers back to the types defined in the
5242 symbol table.
5243
5244 @cindex @code{$}
5245 @cindex @code{$$}
5246 @cindex history number
5247 The values printed are given @dfn{history numbers} by which you can
5248 refer to them. These are successive integers starting with one.
5249 @code{print} shows you the history number assigned to a value by
5250 printing @samp{$@var{num} = } before the value; here @var{num} is the
5251 history number.
5252
5253 To refer to any previous value, use @samp{$} followed by the value's
5254 history number. The way @code{print} labels its output is designed to
5255 remind you of this. Just @code{$} refers to the most recent value in
5256 the history, and @code{$$} refers to the value before that.
5257 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5258 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5259 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5260
5261 For example, suppose you have just printed a pointer to a structure and
5262 want to see the contents of the structure. It suffices to type
5263
5264 @example
5265 p *$
5266 @end example
5267
5268 If you have a chain of structures where the component @code{next} points
5269 to the next one, you can print the contents of the next one with this:
5270
5271 @example
5272 p *$.next
5273 @end example
5274
5275 @noindent
5276 You can print successive links in the chain by repeating this
5277 command---which you can do by just typing @key{RET}.
5278
5279 Note that the history records values, not expressions. If the value of
5280 @code{x} is 4 and you type these commands:
5281
5282 @example
5283 print x
5284 set x=5
5285 @end example
5286
5287 @noindent
5288 then the value recorded in the value history by the @code{print} command
5289 remains 4 even though the value of @code{x} has changed.
5290
5291 @table @code
5292 @kindex show values
5293 @item show values
5294 Print the last ten values in the value history, with their item numbers.
5295 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5296 values} does not change the history.
5297
5298 @item show values @var{n}
5299 Print ten history values centered on history item number @var{n}.
5300
5301 @item show values +
5302 Print ten history values just after the values last printed. If no more
5303 values are available, @code{show values +} produces no display.
5304 @end table
5305
5306 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5307 same effect as @samp{show values +}.
5308
5309 @node Convenience Vars, Registers, Value History, Data
5310 @section Convenience variables
5311
5312 @cindex convenience variables
5313 @value{GDBN} provides @dfn{convenience variables} that you can use within
5314 @value{GDBN} to hold on to a value and refer to it later. These variables
5315 exist entirely within @value{GDBN}; they are not part of your program, and
5316 setting a convenience variable has no direct effect on further execution
5317 of your program. That is why you can use them freely.
5318
5319 Convenience variables are prefixed with @samp{$}. Any name preceded by
5320 @samp{$} can be used for a convenience variable, unless it is one of
5321 the predefined machine-specific register names (@pxref{Registers}).
5322 (Value history references, in contrast, are @emph{numbers} preceded
5323 by @samp{$}. @xref{Value History, ,Value history}.)
5324
5325 You can save a value in a convenience variable with an assignment
5326 expression, just as you would set a variable in your program.
5327 For example:
5328
5329 @example
5330 set $foo = *object_ptr
5331 @end example
5332
5333 @noindent
5334 would save in @code{$foo} the value contained in the object pointed to by
5335 @code{object_ptr}.
5336
5337 Using a convenience variable for the first time creates it, but its
5338 value is @code{void} until you assign a new value. You can alter the
5339 value with another assignment at any time.
5340
5341 Convenience variables have no fixed types. You can assign a convenience
5342 variable any type of value, including structures and arrays, even if
5343 that variable already has a value of a different type. The convenience
5344 variable, when used as an expression, has the type of its current value.
5345
5346 @table @code
5347 @kindex show convenience
5348 @item show convenience
5349 Print a list of convenience variables used so far, and their values.
5350 Abbreviated @code{show con}.
5351 @end table
5352
5353 One of the ways to use a convenience variable is as a counter to be
5354 incremented or a pointer to be advanced. For example, to print
5355 a field from successive elements of an array of structures:
5356
5357 @example
5358 set $i = 0
5359 print bar[$i++]->contents
5360 @end example
5361
5362 @noindent Repeat that command by typing @key{RET}.
5363
5364 Some convenience variables are created automatically by @value{GDBN} and given
5365 values likely to be useful.
5366
5367 @table @code
5368 @kindex $_
5369 @item $_
5370 The variable @code{$_} is automatically set by the @code{x} command to
5371 the last address examined (@pxref{Memory, ,Examining memory}). Other
5372 commands which provide a default address for @code{x} to examine also
5373 set @code{$_} to that address; these commands include @code{info line}
5374 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5375 except when set by the @code{x} command, in which case it is a pointer
5376 to the type of @code{$__}.
5377
5378 @kindex $__
5379 @item $__
5380 The variable @code{$__} is automatically set by the @code{x} command
5381 to the value found in the last address examined. Its type is chosen
5382 to match the format in which the data was printed.
5383
5384 @item $_exitcode
5385 @kindex $_exitcode
5386 The variable @code{$_exitcode} is automatically set to the exit code when
5387 the program being debugged terminates.
5388 @end table
5389
5390 @ifset HPPA
5391 If you refer to a function or variable name that begins with a dollar
5392 sign, @value{GDBN} searches for a user or system name first, before it
5393 searches for a convenience variable.
5394 @end ifset
5395
5396 @node Registers, Floating Point Hardware, Convenience Vars, Data
5397 @section Registers
5398
5399 @cindex registers
5400 You can refer to machine register contents, in expressions, as variables
5401 with names starting with @samp{$}. The names of registers are different
5402 for each machine; use @code{info registers} to see the names used on
5403 your machine.
5404
5405 @table @code
5406 @kindex info registers
5407 @item info registers
5408 Print the names and values of all registers except floating-point
5409 registers (in the selected stack frame).
5410
5411 @kindex info all-registers
5412 @cindex floating point registers
5413 @item info all-registers
5414 Print the names and values of all registers, including floating-point
5415 registers.
5416
5417 @item info registers @var{regname} @dots{}
5418 Print the @dfn{relativized} value of each specified register @var{regname}.
5419 As discussed in detail below, register values are normally relative to
5420 the selected stack frame. @var{regname} may be any register name valid on
5421 the machine you are using, with or without the initial @samp{$}.
5422 @end table
5423
5424 @value{GDBN} has four ``standard'' register names that are available (in
5425 expressions) on most machines---whenever they do not conflict with an
5426 architecture's canonical mnemonics for registers. The register names
5427 @code{$pc} and @code{$sp} are used for the program counter register and
5428 the stack pointer. @code{$fp} is used for a register that contains a
5429 pointer to the current stack frame, and @code{$ps} is used for a
5430 register that contains the processor status. For example,
5431 you could print the program counter in hex with
5432
5433 @example
5434 p/x $pc
5435 @end example
5436
5437 @noindent
5438 or print the instruction to be executed next with
5439
5440 @example
5441 x/i $pc
5442 @end example
5443
5444 @noindent
5445 or add four to the stack pointer@footnote{This is a way of removing
5446 one word from the stack, on machines where stacks grow downward in
5447 memory (most machines, nowadays). This assumes that the innermost
5448 stack frame is selected; setting @code{$sp} is not allowed when other
5449 stack frames are selected. To pop entire frames off the stack,
5450 regardless of machine architecture, use @code{return};
5451 @pxref{Returning, ,Returning from a function}.} with
5452
5453 @example
5454 set $sp += 4
5455 @end example
5456
5457 Whenever possible, these four standard register names are available on
5458 your machine even though the machine has different canonical mnemonics,
5459 so long as there is no conflict. The @code{info registers} command
5460 shows the canonical names. For example, on the SPARC, @code{info
5461 registers} displays the processor status register as @code{$psr} but you
5462 can also refer to it as @code{$ps}.
5463
5464 @value{GDBN} always considers the contents of an ordinary register as an
5465 integer when the register is examined in this way. Some machines have
5466 special registers which can hold nothing but floating point; these
5467 registers are considered to have floating point values. There is no way
5468 to refer to the contents of an ordinary register as floating point value
5469 (although you can @emph{print} it as a floating point value with
5470 @samp{print/f $@var{regname}}).
5471
5472 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5473 means that the data format in which the register contents are saved by
5474 the operating system is not the same one that your program normally
5475 sees. For example, the registers of the 68881 floating point
5476 coprocessor are always saved in ``extended'' (raw) format, but all C
5477 programs expect to work with ``double'' (virtual) format. In such
5478 cases, @value{GDBN} normally works with the virtual format only (the format
5479 that makes sense for your program), but the @code{info registers} command
5480 prints the data in both formats.
5481
5482 Normally, register values are relative to the selected stack frame
5483 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5484 value that the register would contain if all stack frames farther in
5485 were exited and their saved registers restored. In order to see the
5486 true contents of hardware registers, you must select the innermost
5487 frame (with @samp{frame 0}).
5488
5489 However, @value{GDBN} must deduce where registers are saved, from the machine
5490 code generated by your compiler. If some registers are not saved, or if
5491 @value{GDBN} is unable to locate the saved registers, the selected stack
5492 frame makes no difference.
5493
5494 @table @code
5495 @kindex set rstack_high_address
5496 @cindex AMD 29K register stack
5497 @cindex register stack, AMD29K
5498 @item set rstack_high_address @var{address}
5499 On AMD 29000 family processors, registers are saved in a separate
5500 ``register stack''. There is no way for @value{GDBN} to determine the extent
5501 of this stack. Normally, @value{GDBN} just assumes that the stack is ``large
5502 enough''. This may result in @value{GDBN} referencing memory locations that
5503 do not exist. If necessary, you can get around this problem by
5504 specifying the ending address of the register stack with the @code{set
5505 rstack_high_address} command. The argument should be an address, which
5506 you probably want to precede with @samp{0x} to specify in
5507 hexadecimal.
5508
5509 @kindex show rstack_high_address
5510 @item show rstack_high_address
5511 Display the current limit of the register stack, on AMD 29000 family
5512 processors.
5513 @end table
5514
5515 @node Floating Point Hardware, , Registers, Data
5516 @section Floating point hardware
5517 @cindex floating point
5518
5519 Depending on the configuration, @value{GDBN} may be able to give
5520 you more information about the status of the floating point hardware.
5521
5522 @table @code
5523 @kindex info float
5524 @item info float
5525 Display hardware-dependent information about the floating
5526 point unit. The exact contents and layout vary depending on the
5527 floating point chip. Currently, @samp{info float} is supported on
5528 the ARM and x86 machines.
5529 @end table
5530
5531 @node Languages, Symbols, Data, Top
5532 @chapter Using @value{GDBN} with Different Languages
5533 @cindex languages
5534
5535 Although programming languages generally have common aspects, they are
5536 rarely expressed in the same manner. For instance, in ANSI C,
5537 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5538 Modula-2, it is accomplished by @code{p^}. Values can also be
5539 represented (and displayed) differently. Hex numbers in C appear as
5540 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
5541
5542 @cindex working language
5543 Language-specific information is built into @value{GDBN} for some languages,
5544 allowing you to express operations like the above in your program's
5545 native language, and allowing @value{GDBN} to output values in a manner
5546 consistent with the syntax of your program's native language. The
5547 language you use to build expressions is called the @dfn{working
5548 language}.
5549
5550 @menu
5551 * Setting:: Switching between source languages
5552 * Show:: Displaying the language
5553 * Checks:: Type and range checks
5554 * Support:: Supported languages
5555 @end menu
5556
5557 @node Setting, Show, Languages, Languages
5558 @section Switching between source languages
5559
5560 There are two ways to control the working language---either have @value{GDBN}
5561 set it automatically, or select it manually yourself. You can use the
5562 @code{set language} command for either purpose. On startup, @value{GDBN}
5563 defaults to setting the language automatically. The working language is
5564 used to determine how expressions you type are interpreted, how values
5565 are printed, etc.
5566
5567 In addition to the working language, every source file that
5568 @value{GDBN} knows about has its own working language. For some object
5569 file formats, the compiler might indicate which language a particular
5570 source file is in. However, most of the time @value{GDBN} infers the
5571 language from the name of the file. The language of a source file
5572 controls whether C++ names are demangled---this way @code{backtrace} can
5573 show each frame appropriately for its own language. There is no way to
5574 set the language of a source file from within @value{GDBN}.
5575
5576 This is most commonly a problem when you use a program, such
5577 as @code{cfront} or @code{f2c}, that generates C but is written in
5578 another language. In that case, make the
5579 program use @code{#line} directives in its C output; that way
5580 @value{GDBN} will know the correct language of the source code of the original
5581 program, and will display that source code, not the generated C code.
5582
5583 @menu
5584 * Filenames:: Filename extensions and languages.
5585 * Manually:: Setting the working language manually
5586 * Automatically:: Having @value{GDBN} infer the source language
5587 @end menu
5588
5589 @node Filenames, Manually, Setting, Setting
5590 @subsection List of filename extensions and languages
5591
5592 If a source file name ends in one of the following extensions, then
5593 @value{GDBN} infers that its language is the one indicated.
5594
5595 @table @file
5596
5597 @item .c
5598 C source file
5599
5600 @item .C
5601 @itemx .cc
5602 @itemx .cp
5603 @itemx .cpp
5604 @itemx .cxx
5605 @itemx .c++
5606 C++ source file
5607
5608 @item .f
5609 @itemx .F
5610 Fortran source file
5611
5612 @ifclear HPPA
5613 @item .ch
5614 @itemx .c186
5615 @itemx .c286
5616 CHILL source file.
5617 @end ifclear
5618
5619 @item .mod
5620 Modula-2 source file
5621
5622 @item .s
5623 @itemx .S
5624 Assembler source file. This actually behaves almost like C, but
5625 @value{GDBN} does not skip over function prologues when stepping.
5626 @end table
5627
5628 In addition, you may set the language associated with a filename
5629 extension. @xref{Show, , Displaying the language}.
5630
5631 @node Manually, Automatically, Filenames, Setting
5632 @subsection Setting the working language
5633
5634 If you allow @value{GDBN} to set the language automatically,
5635 expressions are interpreted the same way in your debugging session and
5636 your program.
5637
5638 @kindex set language
5639 If you wish, you may set the language manually. To do this, issue the
5640 command @samp{set language @var{lang}}, where @var{lang} is the name of
5641 a language, such as
5642 @code{c} or @code{modula-2}.
5643 For a list of the supported languages, type @samp{set language}.
5644
5645 Setting the language manually prevents @value{GDBN} from updating the working
5646 language automatically. This can lead to confusion if you try
5647 to debug a program when the working language is not the same as the
5648 source language, when an expression is acceptable to both
5649 languages---but means different things. For instance, if the current
5650 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5651 command such as:
5652
5653 @example
5654 print a = b + c
5655 @end example
5656
5657 @noindent
5658 might not have the effect you intended. In C, this means to add
5659 @code{b} and @code{c} and place the result in @code{a}. The result
5660 printed would be the value of @code{a}. In Modula-2, this means to compare
5661 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5662
5663 @node Automatically, , Manually, Setting
5664 @subsection Having @value{GDBN} infer the source language
5665
5666 To have @value{GDBN} set the working language automatically, use
5667 @samp{set language local} or @samp{set language auto}. @value{GDBN}
5668 then infers the working language. That is, when your program stops in a
5669 frame (usually by encountering a breakpoint), @value{GDBN} sets the
5670 working language to the language recorded for the function in that
5671 frame. If the language for a frame is unknown (that is, if the function
5672 or block corresponding to the frame was defined in a source file that
5673 does not have a recognized extension), the current working language is
5674 not changed, and @value{GDBN} issues a warning.
5675
5676 This may not seem necessary for most programs, which are written
5677 entirely in one source language. However, program modules and libraries
5678 written in one source language can be used by a main program written in
5679 a different source language. Using @samp{set language auto} in this
5680 case frees you from having to set the working language manually.
5681
5682 @node Show, Checks, Setting, Languages
5683 @section Displaying the language
5684
5685 The following commands help you find out which language is the
5686 working language, and also what language source files were written in.
5687
5688 @kindex show language
5689 @kindex info frame
5690 @kindex info source
5691 @table @code
5692 @item show language
5693 Display the current working language. This is the
5694 language you can use with commands such as @code{print} to
5695 build and compute expressions that may involve variables in your program.
5696
5697 @item info frame
5698 Display the source language for this frame. This language becomes the
5699 working language if you use an identifier from this frame.
5700 @xref{Frame Info, ,Information about a frame}, to identify the other
5701 information listed here.
5702
5703 @item info source
5704 Display the source language of this source file.
5705 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
5706 information listed here.
5707 @end table
5708
5709 In unusual circumstances, you may have source files with extensions
5710 not in the standard list. You can then set the extension associated
5711 with a language explicitly:
5712
5713 @kindex set extension-language
5714 @kindex info extensions
5715 @table @code
5716 @item set extension-language @var{.ext} @var{language}
5717 Set source files with extension @var{.ext} to be assumed to be in
5718 the source language @var{language}.
5719
5720 @item info extensions
5721 List all the filename extensions and the associated languages.
5722 @end table
5723
5724 @node Checks, Support, Show, Languages
5725 @section Type and range checking
5726
5727 @quotation
5728 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5729 checking are included, but they do not yet have any effect. This
5730 section documents the intended facilities.
5731 @end quotation
5732 @c FIXME remove warning when type/range code added
5733
5734 Some languages are designed to guard you against making seemingly common
5735 errors through a series of compile- and run-time checks. These include
5736 checking the type of arguments to functions and operators, and making
5737 sure mathematical overflows are caught at run time. Checks such as
5738 these help to ensure a program's correctness once it has been compiled
5739 by eliminating type mismatches, and providing active checks for range
5740 errors when your program is running.
5741
5742 @value{GDBN} can check for conditions like the above if you wish.
5743 Although @value{GDBN} does not check the statements in your program, it
5744 can check expressions entered directly into @value{GDBN} for evaluation via
5745 the @code{print} command, for example. As with the working language,
5746 @value{GDBN} can also decide whether or not to check automatically based on
5747 your program's source language. @xref{Support, ,Supported languages},
5748 for the default settings of supported languages.
5749
5750 @menu
5751 * Type Checking:: An overview of type checking
5752 * Range Checking:: An overview of range checking
5753 @end menu
5754
5755 @cindex type checking
5756 @cindex checks, type
5757 @node Type Checking, Range Checking, Checks, Checks
5758 @subsection An overview of type checking
5759
5760 Some languages, such as Modula-2, are strongly typed, meaning that the
5761 arguments to operators and functions have to be of the correct type,
5762 otherwise an error occurs. These checks prevent type mismatch
5763 errors from ever causing any run-time problems. For example,
5764
5765 @smallexample
5766 1 + 2 @result{} 3
5767 @exdent but
5768 @error{} 1 + 2.3
5769 @end smallexample
5770
5771 The second example fails because the @code{CARDINAL} 1 is not
5772 type-compatible with the @code{REAL} 2.3.
5773
5774 For the expressions you use in @value{GDBN} commands, you can tell the
5775 @value{GDBN} type checker to skip checking;
5776 to treat any mismatches as errors and abandon the expression;
5777 or to only issue warnings when type mismatches occur,
5778 but evaluate the expression anyway. When you choose the last of
5779 these, @value{GDBN} evaluates expressions like the second example above, but
5780 also issues a warning.
5781
5782 Even if you turn type checking off, there may be other reasons
5783 related to type that prevent @value{GDBN} from evaluating an expression.
5784 For instance, @value{GDBN} does not know how to add an @code{int} and
5785 a @code{struct foo}. These particular type errors have nothing to do
5786 with the language in use, and usually arise from expressions, such as
5787 the one described above, which make little sense to evaluate anyway.
5788
5789 Each language defines to what degree it is strict about type. For
5790 instance, both Modula-2 and C require the arguments to arithmetical
5791 operators to be numbers. In C, enumerated types and pointers can be
5792 represented as numbers, so that they are valid arguments to mathematical
5793 operators. @xref{Support, ,Supported languages}, for further
5794 details on specific languages.
5795
5796 @value{GDBN} provides some additional commands for controlling the type checker:
5797
5798 @kindex set check
5799 @kindex set check type
5800 @kindex show check type
5801 @table @code
5802 @item set check type auto
5803 Set type checking on or off based on the current working language.
5804 @xref{Support, ,Supported languages}, for the default settings for
5805 each language.
5806
5807 @item set check type on
5808 @itemx set check type off
5809 Set type checking on or off, overriding the default setting for the
5810 current working language. Issue a warning if the setting does not
5811 match the language default. If any type mismatches occur in
5812 evaluating an expression while typechecking is on, @value{GDBN} prints a
5813 message and aborts evaluation of the expression.
5814
5815 @item set check type warn
5816 Cause the type checker to issue warnings, but to always attempt to
5817 evaluate the expression. Evaluating the expression may still
5818 be impossible for other reasons. For example, @value{GDBN} cannot add
5819 numbers and structures.
5820
5821 @item show type
5822 Show the current setting of the type checker, and whether or not @value{GDBN}
5823 is setting it automatically.
5824 @end table
5825
5826 @cindex range checking
5827 @cindex checks, range
5828 @node Range Checking, , Type Checking, Checks
5829 @subsection An overview of range checking
5830
5831 In some languages (such as Modula-2), it is an error to exceed the
5832 bounds of a type; this is enforced with run-time checks. Such range
5833 checking is meant to ensure program correctness by making sure
5834 computations do not overflow, or indices on an array element access do
5835 not exceed the bounds of the array.
5836
5837 For expressions you use in @value{GDBN} commands, you can tell
5838 @value{GDBN} to treat range errors in one of three ways: ignore them,
5839 always treat them as errors and abandon the expression, or issue
5840 warnings but evaluate the expression anyway.
5841
5842 A range error can result from numerical overflow, from exceeding an
5843 array index bound, or when you type a constant that is not a member
5844 of any type. Some languages, however, do not treat overflows as an
5845 error. In many implementations of C, mathematical overflow causes the
5846 result to ``wrap around'' to lower values---for example, if @var{m} is
5847 the largest integer value, and @var{s} is the smallest, then
5848
5849 @example
5850 @var{m} + 1 @result{} @var{s}
5851 @end example
5852
5853 This, too, is specific to individual languages, and in some cases
5854 specific to individual compilers or machines. @xref{Support, ,
5855 Supported languages}, for further details on specific languages.
5856
5857 @value{GDBN} provides some additional commands for controlling the range checker:
5858
5859 @kindex set check
5860 @kindex set check range
5861 @kindex show check range
5862 @table @code
5863 @item set check range auto
5864 Set range checking on or off based on the current working language.
5865 @xref{Support, ,Supported languages}, for the default settings for
5866 each language.
5867
5868 @item set check range on
5869 @itemx set check range off
5870 Set range checking on or off, overriding the default setting for the
5871 current working language. A warning is issued if the setting does not
5872 match the language default. If a range error occurs, then a message
5873 is printed and evaluation of the expression is aborted.
5874
5875 @item set check range warn
5876 Output messages when the @value{GDBN} range checker detects a range error,
5877 but attempt to evaluate the expression anyway. Evaluating the
5878 expression may still be impossible for other reasons, such as accessing
5879 memory that the process does not own (a typical example from many Unix
5880 systems).
5881
5882 @item show range
5883 Show the current setting of the range checker, and whether or not it is
5884 being set automatically by @value{GDBN}.
5885 @end table
5886
5887 @node Support, , Checks, Languages
5888 @section Supported languages
5889
5890 @value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5891 @c This is false ...
5892 Some @value{GDBN} features may be used in expressions regardless of the
5893 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5894 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5895 ,Expressions}) can be used with the constructs of any supported
5896 language.
5897
5898 The following sections detail to what degree each source language is
5899 supported by @value{GDBN}. These sections are not meant to be language
5900 tutorials or references, but serve only as a reference guide to what the
5901 @value{GDBN} expression parser accepts, and what input and output
5902 formats should look like for different languages. There are many good
5903 books written on each of these languages; please look to these for a
5904 language reference or tutorial.
5905
5906 @menu
5907 * C:: C and C++
5908 * Modula-2:: Modula-2
5909 * Chill:: Chill
5910 @end menu
5911
5912 @node C, Modula-2, , Support
5913 @subsection C and C++
5914
5915 @cindex C and C++
5916 @cindex expressions in C or C++
5917
5918 Since C and C++ are so closely related, many features of @value{GDBN} apply
5919 to both languages. Whenever this is the case, we discuss those languages
5920 together.
5921
5922 @ifclear HPPA
5923 @cindex C++
5924 @kindex g++
5925 @cindex @sc{gnu} C++
5926 The C++ debugging facilities are jointly implemented by the C++
5927 compiler and @value{GDBN}. Therefore, to debug your C++ code
5928 effectively, you must compile your C++ programs with a supported
5929 C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5930 compiler (@code{aCC}).
5931
5932 For best results when using @sc{gnu} C++, use the stabs debugging
5933 format. You can select that format explicitly with the @code{g++}
5934 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5935 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5936 CC, gcc.info, Using @sc{gnu} CC}, for more information.
5937 @end ifclear
5938 @ifset HPPA
5939 @cindex C++
5940 @kindex g++
5941 @cindex @sc{gnu} C++
5942 You can use @value{GDBN} to debug C programs compiled with either the HP
5943 C compiler (@code{cc}) or the GNU C compiler (@code{gcc}), and to debug
5944 programs compiled with either the HP ANSI C++ compiler (@code{aCC}) or
5945 the @sc{gnu} C++ compiler (@code{g++}).
5946
5947 If you compile with the @sc{gnu} C++ compiler, use the stabs debugging
5948 format for best results when debugging. You can select that format
5949 explicitly with the @code{g++} command-line options @samp{-gstabs} or
5950 @samp{-gstabs+}. See @ref{Debugging Options,,Options for Debugging Your
5951 Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
5952 information.
5953 @end ifset
5954
5955 @menu
5956 * C Operators:: C and C++ operators
5957 * C Constants:: C and C++ constants
5958 * C plus plus expressions:: C++ expressions
5959 * C Defaults:: Default settings for C and C++
5960 * C Checks:: C and C++ type and range checks
5961 * Debugging C:: @value{GDBN} and C
5962 * Debugging C plus plus:: @value{GDBN} features for C++
5963 @end menu
5964
5965 @node C Operators, C Constants, , C
5966 @subsubsection C and C++ operators
5967
5968 @cindex C and C++ operators
5969
5970 Operators must be defined on values of specific types. For instance,
5971 @code{+} is defined on numbers, but not on structures. Operators are
5972 often defined on groups of types.
5973
5974 For the purposes of C and C++, the following definitions hold:
5975
5976 @itemize @bullet
5977 @item
5978 @ifclear HPPA
5979 @emph{Integral types} include @code{int} with any of its storage-class
5980 specifiers; @code{char}; and @code{enum}.
5981 @end ifclear
5982 @ifset HPPA
5983 @emph{Integral types} include @code{int} with any of its storage-class
5984 specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
5985 @end ifset
5986
5987 @item
5988 @emph{Floating-point types} include @code{float} and @code{double}.
5989
5990 @item
5991 @emph{Pointer types} include all types defined as @code{(@var{type}
5992 *)}.
5993
5994 @item
5995 @emph{Scalar types} include all of the above.
5996 @end itemize
5997
5998 @noindent
5999 The following operators are supported. They are listed here
6000 in order of increasing precedence:
6001
6002 @table @code
6003 @item ,
6004 The comma or sequencing operator. Expressions in a comma-separated list
6005 are evaluated from left to right, with the result of the entire
6006 expression being the last expression evaluated.
6007
6008 @item =
6009 Assignment. The value of an assignment expression is the value
6010 assigned. Defined on scalar types.
6011
6012 @item @var{op}=
6013 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
6014 and translated to @w{@code{@var{a} = @var{a op b}}}.
6015 @w{@code{@var{op}=}} and @code{=} have the same precendence.
6016 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
6017 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
6018
6019 @item ?:
6020 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
6021 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
6022 integral type.
6023
6024 @item ||
6025 Logical @sc{or}. Defined on integral types.
6026
6027 @item &&
6028 Logical @sc{and}. Defined on integral types.
6029
6030 @item |
6031 Bitwise @sc{or}. Defined on integral types.
6032
6033 @item ^
6034 Bitwise exclusive-@sc{or}. Defined on integral types.
6035
6036 @item &
6037 Bitwise @sc{and}. Defined on integral types.
6038
6039 @item ==@r{, }!=
6040 Equality and inequality. Defined on scalar types. The value of these
6041 expressions is 0 for false and non-zero for true.
6042
6043 @item <@r{, }>@r{, }<=@r{, }>=
6044 Less than, greater than, less than or equal, greater than or equal.
6045 Defined on scalar types. The value of these expressions is 0 for false
6046 and non-zero for true.
6047
6048 @item <<@r{, }>>
6049 left shift, and right shift. Defined on integral types.
6050
6051 @item @@
6052 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6053
6054 @item +@r{, }-
6055 Addition and subtraction. Defined on integral types, floating-point types and
6056 pointer types.
6057
6058 @item *@r{, }/@r{, }%
6059 Multiplication, division, and modulus. Multiplication and division are
6060 defined on integral and floating-point types. Modulus is defined on
6061 integral types.
6062
6063 @item ++@r{, }--
6064 Increment and decrement. When appearing before a variable, the
6065 operation is performed before the variable is used in an expression;
6066 when appearing after it, the variable's value is used before the
6067 operation takes place.
6068
6069 @item *
6070 Pointer dereferencing. Defined on pointer types. Same precedence as
6071 @code{++}.
6072
6073 @item &
6074 Address operator. Defined on variables. Same precedence as @code{++}.
6075
6076 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6077 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6078 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6079 where a C++ reference variable (declared with @samp{&@var{ref}}) is
6080 stored.
6081
6082 @item -
6083 Negative. Defined on integral and floating-point types. Same
6084 precedence as @code{++}.
6085
6086 @item !
6087 Logical negation. Defined on integral types. Same precedence as
6088 @code{++}.
6089
6090 @item ~
6091 Bitwise complement operator. Defined on integral types. Same precedence as
6092 @code{++}.
6093
6094
6095 @item .@r{, }->
6096 Structure member, and pointer-to-structure member. For convenience,
6097 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
6098 pointer based on the stored type information.
6099 Defined on @code{struct} and @code{union} data.
6100
6101 @ifset HPPA
6102 @item .*@r{, }->*
6103 Dereferences of pointers to members.
6104 @end ifset
6105
6106 @item []
6107 Array indexing. @code{@var{a}[@var{i}]} is defined as
6108 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6109
6110 @item ()
6111 Function parameter list. Same precedence as @code{->}.
6112
6113 @item ::
6114 C++ scope resolution operator. Defined on @code{struct}, @code{union},
6115 and @code{class} types.
6116
6117 @item ::
6118 Doubled colons also represent the @value{GDBN} scope operator
6119 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6120 above.
6121 @end table
6122
6123 @ifset HPPA
6124 If an operator is redefined in the user code, @value{GDBN} usually
6125 attempts to invoke the redefined version instead of using the operator's
6126 predefined meaning.
6127 @end ifset
6128
6129 @menu
6130 * C Constants::
6131 @end menu
6132
6133 @node C Constants, C plus plus expressions, C Operators, C
6134 @subsubsection C and C++ constants
6135
6136 @cindex C and C++ constants
6137
6138 @value{GDBN} allows you to express the constants of C and C++ in the
6139 following ways:
6140
6141 @itemize @bullet
6142 @item
6143 Integer constants are a sequence of digits. Octal constants are
6144 specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6145 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6146 @samp{l}, specifying that the constant should be treated as a
6147 @code{long} value.
6148
6149 @item
6150 Floating point constants are a sequence of digits, followed by a decimal
6151 point, followed by a sequence of digits, and optionally followed by an
6152 exponent. An exponent is of the form:
6153 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6154 sequence of digits. The @samp{+} is optional for positive exponents.
6155
6156 @item
6157 Enumerated constants consist of enumerated identifiers, or their
6158 integral equivalents.
6159
6160 @item
6161 Character constants are a single character surrounded by single quotes
6162 (@code{'}), or a number---the ordinal value of the corresponding character
6163 (usually its @sc{ASCII} value). Within quotes, the single character may
6164 be represented by a letter or by @dfn{escape sequences}, which are of
6165 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6166 of the character's ordinal value; or of the form @samp{\@var{x}}, where
6167 @samp{@var{x}} is a predefined special character---for example,
6168 @samp{\n} for newline.
6169
6170 @item
6171 String constants are a sequence of character constants surrounded
6172 by double quotes (@code{"}).
6173
6174 @item
6175 Pointer constants are an integral value. You can also write pointers
6176 to constants using the C operator @samp{&}.
6177
6178 @item
6179 Array constants are comma-separated lists surrounded by braces @samp{@{}
6180 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6181 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6182 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6183 @end itemize
6184
6185 @menu
6186 * C plus plus expressions::
6187 * C Defaults::
6188 * C Checks::
6189
6190 * Debugging C::
6191 @end menu
6192
6193 @node C plus plus expressions, C Defaults, C Constants, C
6194 @subsubsection C++ expressions
6195
6196 @cindex expressions in C++
6197 @value{GDBN} expression handling can interpret most C++ expressions.
6198
6199 @ifclear HPPA
6200 @cindex C++ support, not in @sc{coff}
6201 @cindex @sc{coff} versus C++
6202 @cindex C++ and object formats
6203 @cindex object formats and C++
6204 @cindex a.out and C++
6205 @cindex @sc{ecoff} and C++
6206 @cindex @sc{xcoff} and C++
6207 @cindex @sc{elf}/stabs and C++
6208 @cindex @sc{elf}/@sc{dwarf} and C++
6209 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6210 @c periodically whether this has happened...
6211 @quotation
6212 @emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6213 proper compiler. Typically, C++ debugging depends on the use of
6214 additional debugging information in the symbol table, and thus requires
6215 special support. In particular, if your compiler generates a.out, MIPS
6216 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6217 symbol table, these facilities are all available. (With @sc{gnu} CC,
6218 you can use the @samp{-gstabs} option to request stabs debugging
6219 extensions explicitly.) Where the object code format is standard
6220 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6221 support in @value{GDBN} does @emph{not} work.
6222 @end quotation
6223 @end ifclear
6224
6225 @enumerate
6226
6227 @cindex member functions
6228 @item
6229 Member function calls are allowed; you can use expressions like
6230
6231 @example
6232 count = aml->GetOriginal(x, y)
6233 @end example
6234
6235 @kindex this
6236 @cindex namespace in C++
6237 @item
6238 While a member function is active (in the selected stack frame), your
6239 expressions have the same namespace available as the member function;
6240 that is, @value{GDBN} allows implicit references to the class instance
6241 pointer @code{this} following the same rules as C++.
6242
6243 @ifclear HPPA
6244 @cindex call overloaded functions
6245 @cindex type conversions in C++
6246 @item
6247 You can call overloaded functions; @value{GDBN} resolves the function
6248 call to the right definition, with one restriction---you must use
6249 arguments of the type required by the function that you want to call.
6250 @value{GDBN} does not perform conversions requiring constructors or
6251 user-defined type operators.
6252 @end ifclear
6253 @ifset HPPA
6254 @cindex call overloaded functions
6255 @cindex overloaded functions
6256 @cindex type conversions in C++
6257 @item
6258 You can call overloaded functions; @value{GDBN} resolves the function
6259 call to the right definition, with some restrictions. GDB does not
6260 perform overload resolution involving user-defined type conversions,
6261 calls to constructors, or instantiations of templates that do not exist
6262 in the program. It also cannot handle ellipsis argument lists or
6263 default arguments.
6264
6265 It does perform integral conversions and promotions, floating-point
6266 promotions, arithmetic conversions, pointer conversions, conversions of
6267 class objects to base classes, and standard conversions such as those of
6268 functions or arrays to pointers; it requires an exact match on the
6269 number of function arguments.
6270
6271 Overload resolution is always performed, unless you have specified
6272 @code{set overload-resolution off}. @xref{Debugging C plus plus,
6273 ,@value{GDBN} features for C++}.
6274
6275 You must specify@code{set overload-resolution off} in order to use an
6276 explicit function signature to call an overloaded function, as in
6277 @smallexample
6278 p 'foo(char,int)'('x', 13)
6279 @end smallexample
6280 The @value{GDBN} command-completion facility can simplify this;
6281 @pxref{Completion, ,Command completion}.
6282
6283 @end ifset
6284
6285 @cindex reference declarations
6286 @item
6287 @value{GDBN} understands variables declared as C++ references; you can use
6288 them in expressions just as you do in C++ source---they are automatically
6289 dereferenced.
6290
6291 In the parameter list shown when @value{GDBN} displays a frame, the values of
6292 reference variables are not displayed (unlike other variables); this
6293 avoids clutter, since references are often used for large structures.
6294 The @emph{address} of a reference variable is always shown, unless
6295 you have specified @samp{set print address off}.
6296
6297 @item
6298 @value{GDBN} supports the C++ name resolution operator @code{::}---your
6299 expressions can use it just as expressions in your program do. Since
6300 one scope may be defined in another, you can use @code{::} repeatedly if
6301 necessary, for example in an expression like
6302 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6303 resolving name scope by reference to source files, in both C and C++
6304 debugging (@pxref{Variables, ,Program variables}).
6305 @end enumerate
6306
6307 @ifset HPPA
6308 In addition, @value{GDBN} supports calling virtual functions correctly,
6309 printing out virtual bases of objects, calling functions in a base
6310 subobject, casting objects, and invoking user-defined operators.
6311 @end ifset
6312
6313 @node C Defaults, C Checks, C plus plus expressions, C
6314 @subsubsection C and C++ defaults
6315
6316 @cindex C and C++ defaults
6317
6318 @ifclear HPPA
6319 If you allow @value{GDBN} to set type and range checking automatically, they
6320 both default to @code{off} whenever the working language changes to
6321 C or C++. This happens regardless of whether you or @value{GDBN}
6322 selects the working language.
6323 @end ifclear
6324
6325 If you allow @value{GDBN} to set the language automatically, it
6326 recognizes source files whose names end with @file{.c}, @file{.C}, or
6327 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6328 these files, it sets the working language to C or C++.
6329 @xref{Automatically, ,Having @value{GDBN} infer the source language},
6330 for further details.
6331
6332 @c Type checking is (a) primarily motivated by Modula-2, and (b)
6333 @c unimplemented. If (b) changes, it might make sense to let this node
6334 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
6335
6336 @node C Checks, Debugging C, C Defaults, C Constants
6337 @subsubsection C and C++ type and range checks
6338
6339 @cindex C and C++ checks
6340
6341 By default, when @value{GDBN} parses C or C++ expressions, type checking
6342 is not used. However, if you turn type checking on, @value{GDBN}
6343 considers two variables type equivalent if:
6344
6345 @itemize @bullet
6346 @item
6347 The two variables are structured and have the same structure, union, or
6348 enumerated tag.
6349
6350 @item
6351 The two variables have the same type name, or types that have been
6352 declared equivalent through @code{typedef}.
6353
6354 @ignore
6355 @c leaving this out because neither J Gilmore nor R Pesch understand it.
6356 @c FIXME--beers?
6357 @item
6358 The two @code{struct}, @code{union}, or @code{enum} variables are
6359 declared in the same declaration. (Note: this may not be true for all C
6360 compilers.)
6361 @end ignore
6362 @end itemize
6363
6364 Range checking, if turned on, is done on mathematical operations. Array
6365 indices are not checked, since they are often used to index a pointer
6366 that is not itself an array.
6367
6368 @node Debugging C, Debugging C plus plus, C Checks, C
6369 @subsubsection @value{GDBN} and C
6370
6371 The @code{set print union} and @code{show print union} commands apply to
6372 the @code{union} type. When set to @samp{on}, any @code{union} that is
6373 inside a @code{struct} or @code{class} is also printed. Otherwise, it
6374 appears as @samp{@{...@}}.
6375
6376 The @code{@@} operator aids in the debugging of dynamic arrays, formed
6377 with pointers and a memory allocation function. @xref{Expressions,
6378 ,Expressions}.
6379
6380 @menu
6381 * Debugging C plus plus::
6382 @end menu
6383
6384 @node Debugging C plus plus, , Debugging C, C
6385 @subsubsection @value{GDBN} features for C++
6386
6387 @cindex commands for C++
6388
6389 Some @value{GDBN} commands are particularly useful with C++, and some are
6390 designed specifically for use with C++. Here is a summary:
6391
6392 @table @code
6393 @cindex break in overloaded functions
6394 @item @r{breakpoint menus}
6395 When you want a breakpoint in a function whose name is overloaded,
6396 @value{GDBN} breakpoint menus help you specify which function definition
6397 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6398
6399 @cindex overloading in C++
6400 @item rbreak @var{regex}
6401 Setting breakpoints using regular expressions is helpful for setting
6402 breakpoints on overloaded functions that are not members of any special
6403 classes.
6404 @xref{Set Breaks, ,Setting breakpoints}.
6405
6406 @cindex C++ exception handling
6407 @item catch throw
6408 @itemx catch catch
6409 Debug C++ exception handling using these commands. @xref{Set
6410 Catchpoints, , Setting catchpoints}.
6411
6412 @cindex inheritance
6413 @item ptype @var{typename}
6414 Print inheritance relationships as well as other information for type
6415 @var{typename}.
6416 @xref{Symbols, ,Examining the Symbol Table}.
6417
6418 @cindex C++ symbol display
6419 @item set print demangle
6420 @itemx show print demangle
6421 @itemx set print asm-demangle
6422 @itemx show print asm-demangle
6423 Control whether C++ symbols display in their source form, both when
6424 displaying code as C++ source and when displaying disassemblies.
6425 @xref{Print Settings, ,Print settings}.
6426
6427 @item set print object
6428 @itemx show print object
6429 Choose whether to print derived (actual) or declared types of objects.
6430 @xref{Print Settings, ,Print settings}.
6431
6432 @item set print vtbl
6433 @itemx show print vtbl
6434 Control the format for printing virtual function tables.
6435 @xref{Print Settings, ,Print settings}.
6436 @ifset HPPA
6437 (The @code{vtbl} commands do not work on programs compiled with the HP
6438 ANSI C++ compiler (@code{aCC}).)
6439
6440 @kindex set overload-resolution
6441 @cindex overloaded functions
6442 @item set overload-resolution on
6443 Enable overload resolution for C++ expression evaluation. The default
6444 is on. For overloaded functions, @value{GDBN} evaluates the arguments
6445 and searches for a function whose signature matches the argument types,
6446 using the standard C++ conversion rules (@pxref{C plus plus expressions, ,C++
6447 expressions} for details). If it cannot find a match, it emits a
6448 message.
6449
6450 @item set overload-resolution off
6451 Disable overload resolution for C++ expression evaluation. For
6452 overloaded functions that are not class member functions, @value{GDBN}
6453 chooses the first function of the specified name that it finds in the
6454 symbol table, whether or not its arguments are of the correct type. For
6455 overloaded functions that are class member functions, @value{GDBN}
6456 searches for a function whose signature @emph{exactly} matches the
6457 argument types.
6458 @end ifset
6459
6460 @item @r{Overloaded symbol names}
6461 You can specify a particular definition of an overloaded symbol, using
6462 the same notation that is used to declare such symbols in C++: type
6463 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6464 also use the @value{GDBN} command-line word completion facilities to list the
6465 available choices, or to finish the type list for you.
6466 @xref{Completion,, Command completion}, for details on how to do this.
6467 @end table
6468
6469 @node Modula-2, Chill, C, Support
6470 @subsection Modula-2
6471
6472 @cindex Modula-2
6473
6474 The extensions made to @value{GDBN} to support Modula-2 only support
6475 output from the @sc{gnu} Modula-2 compiler (which is currently being
6476 developed). Other Modula-2 compilers are not currently supported, and
6477 attempting to debug executables produced by them is most likely
6478 to give an error as @value{GDBN} reads in the executable's symbol
6479 table.
6480
6481 @cindex expressions in Modula-2
6482 @menu
6483 * M2 Operators:: Built-in operators
6484 * Built-In Func/Proc:: Built-in functions and procedures
6485 * M2 Constants:: Modula-2 constants
6486 * M2 Defaults:: Default settings for Modula-2
6487 * Deviations:: Deviations from standard Modula-2
6488 * M2 Checks:: Modula-2 type and range checks
6489 * M2 Scope:: The scope operators @code{::} and @code{.}
6490 * GDB/M2:: @value{GDBN} and Modula-2
6491 @end menu
6492
6493 @node M2 Operators, Built-In Func/Proc, Modula-2, Modula-2
6494 @subsubsection Operators
6495 @cindex Modula-2 operators
6496
6497 Operators must be defined on values of specific types. For instance,
6498 @code{+} is defined on numbers, but not on structures. Operators are
6499 often defined on groups of types. For the purposes of Modula-2, the
6500 following definitions hold:
6501
6502 @itemize @bullet
6503
6504 @item
6505 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6506 their subranges.
6507
6508 @item
6509 @emph{Character types} consist of @code{CHAR} and its subranges.
6510
6511 @item
6512 @emph{Floating-point types} consist of @code{REAL}.
6513
6514 @item
6515 @emph{Pointer types} consist of anything declared as @code{POINTER TO
6516 @var{type}}.
6517
6518 @item
6519 @emph{Scalar types} consist of all of the above.
6520
6521 @item
6522 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
6523
6524 @item
6525 @emph{Boolean types} consist of @code{BOOLEAN}.
6526 @end itemize
6527
6528 @noindent
6529 The following operators are supported, and appear in order of
6530 increasing precedence:
6531
6532 @table @code
6533 @item ,
6534 Function argument or array index separator.
6535
6536 @item :=
6537 Assignment. The value of @var{var} @code{:=} @var{value} is
6538 @var{value}.
6539
6540 @item <@r{, }>
6541 Less than, greater than on integral, floating-point, or enumerated
6542 types.
6543
6544 @item <=@r{, }>=
6545 Less than, greater than, less than or equal to, greater than or equal to
6546 on integral, floating-point and enumerated types, or set inclusion on
6547 set types. Same precedence as @code{<}.
6548
6549 @item =@r{, }<>@r{, }#
6550 Equality and two ways of expressing inequality, valid on scalar types.
6551 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6552 available for inequality, since @code{#} conflicts with the script
6553 comment character.
6554
6555 @item IN
6556 Set membership. Defined on set types and the types of their members.
6557 Same precedence as @code{<}.
6558
6559 @item OR
6560 Boolean disjunction. Defined on boolean types.
6561
6562 @item AND@r{, }&
6563 Boolean conjuction. Defined on boolean types.
6564
6565 @item @@
6566 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6567
6568 @item +@r{, }-
6569 Addition and subtraction on integral and floating-point types, or union
6570 and difference on set types.
6571
6572 @item *
6573 Multiplication on integral and floating-point types, or set intersection
6574 on set types.
6575
6576 @item /
6577 Division on floating-point types, or symmetric set difference on set
6578 types. Same precedence as @code{*}.
6579
6580 @item DIV@r{, }MOD
6581 Integer division and remainder. Defined on integral types. Same
6582 precedence as @code{*}.
6583
6584 @item -
6585 Negative. Defined on @code{INTEGER} and @code{REAL} data.
6586
6587 @item ^
6588 Pointer dereferencing. Defined on pointer types.
6589
6590 @item NOT
6591 Boolean negation. Defined on boolean types. Same precedence as
6592 @code{^}.
6593
6594 @item .
6595 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
6596 precedence as @code{^}.
6597
6598 @item []
6599 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6600
6601 @item ()
6602 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6603 as @code{^}.
6604
6605 @item ::@r{, }.
6606 @value{GDBN} and Modula-2 scope operators.
6607 @end table
6608
6609 @quotation
6610 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6611 treats the use of the operator @code{IN}, or the use of operators
6612 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6613 @code{<=}, and @code{>=} on sets as an error.
6614 @end quotation
6615
6616 @cindex Modula-2 built-ins
6617 @node Built-In Func/Proc, M2 Constants, M2 Operators, Modula-2
6618 @subsubsection Built-in functions and procedures
6619
6620 Modula-2 also makes available several built-in procedures and functions.
6621 In describing these, the following metavariables are used:
6622
6623 @table @var
6624
6625 @item a
6626 represents an @code{ARRAY} variable.
6627
6628 @item c
6629 represents a @code{CHAR} constant or variable.
6630
6631 @item i
6632 represents a variable or constant of integral type.
6633
6634 @item m
6635 represents an identifier that belongs to a set. Generally used in the
6636 same function with the metavariable @var{s}. The type of @var{s} should
6637 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6638
6639 @item n
6640 represents a variable or constant of integral or floating-point type.
6641
6642 @item r
6643 represents a variable or constant of floating-point type.
6644
6645 @item t
6646 represents a type.
6647
6648 @item v
6649 represents a variable.
6650
6651 @item x
6652 represents a variable or constant of one of many types. See the
6653 explanation of the function for details.
6654 @end table
6655
6656 All Modula-2 built-in procedures also return a result, described below.
6657
6658 @table @code
6659 @item ABS(@var{n})
6660 Returns the absolute value of @var{n}.
6661
6662 @item CAP(@var{c})
6663 If @var{c} is a lower case letter, it returns its upper case
6664 equivalent, otherwise it returns its argument
6665
6666 @item CHR(@var{i})
6667 Returns the character whose ordinal value is @var{i}.
6668
6669 @item DEC(@var{v})
6670 Decrements the value in the variable @var{v}. Returns the new value.
6671
6672 @item DEC(@var{v},@var{i})
6673 Decrements the value in the variable @var{v} by @var{i}. Returns the
6674 new value.
6675
6676 @item EXCL(@var{m},@var{s})
6677 Removes the element @var{m} from the set @var{s}. Returns the new
6678 set.
6679
6680 @item FLOAT(@var{i})
6681 Returns the floating point equivalent of the integer @var{i}.
6682
6683 @item HIGH(@var{a})
6684 Returns the index of the last member of @var{a}.
6685
6686 @item INC(@var{v})
6687 Increments the value in the variable @var{v}. Returns the new value.
6688
6689 @item INC(@var{v},@var{i})
6690 Increments the value in the variable @var{v} by @var{i}. Returns the
6691 new value.
6692
6693 @item INCL(@var{m},@var{s})
6694 Adds the element @var{m} to the set @var{s} if it is not already
6695 there. Returns the new set.
6696
6697 @item MAX(@var{t})
6698 Returns the maximum value of the type @var{t}.
6699
6700 @item MIN(@var{t})
6701 Returns the minimum value of the type @var{t}.
6702
6703 @item ODD(@var{i})
6704 Returns boolean TRUE if @var{i} is an odd number.
6705
6706 @item ORD(@var{x})
6707 Returns the ordinal value of its argument. For example, the ordinal
6708 value of a character is its ASCII value (on machines supporting the
6709 ASCII character set). @var{x} must be of an ordered type, which include
6710 integral, character and enumerated types.
6711
6712 @item SIZE(@var{x})
6713 Returns the size of its argument. @var{x} can be a variable or a type.
6714
6715 @item TRUNC(@var{r})
6716 Returns the integral part of @var{r}.
6717
6718 @item VAL(@var{t},@var{i})
6719 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6720 @end table
6721
6722 @quotation
6723 @emph{Warning:} Sets and their operations are not yet supported, so
6724 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6725 an error.
6726 @end quotation
6727
6728 @cindex Modula-2 constants
6729 @node M2 Constants, M2 Defaults, Built-In Func/Proc, Modula-2
6730 @subsubsection Constants
6731
6732 @value{GDBN} allows you to express the constants of Modula-2 in the following
6733 ways:
6734
6735 @itemize @bullet
6736
6737 @item
6738 Integer constants are simply a sequence of digits. When used in an
6739 expression, a constant is interpreted to be type-compatible with the
6740 rest of the expression. Hexadecimal integers are specified by a
6741 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6742
6743 @item
6744 Floating point constants appear as a sequence of digits, followed by a
6745 decimal point and another sequence of digits. An optional exponent can
6746 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6747 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6748 digits of the floating point constant must be valid decimal (base 10)
6749 digits.
6750
6751 @item
6752 Character constants consist of a single character enclosed by a pair of
6753 like quotes, either single (@code{'}) or double (@code{"}). They may
6754 also be expressed by their ordinal value (their ASCII value, usually)
6755 followed by a @samp{C}.
6756
6757 @item
6758 String constants consist of a sequence of characters enclosed by a
6759 pair of like quotes, either single (@code{'}) or double (@code{"}).
6760 Escape sequences in the style of C are also allowed. @xref{C
6761 Constants, ,C and C++ constants}, for a brief explanation of escape
6762 sequences.
6763
6764 @item
6765 Enumerated constants consist of an enumerated identifier.
6766
6767 @item
6768 Boolean constants consist of the identifiers @code{TRUE} and
6769 @code{FALSE}.
6770
6771 @item
6772 Pointer constants consist of integral values only.
6773
6774 @item
6775 Set constants are not yet supported.
6776 @end itemize
6777
6778 @node M2 Defaults, Deviations, M2 Constants, Modula-2
6779 @subsubsection Modula-2 defaults
6780 @cindex Modula-2 defaults
6781
6782 If type and range checking are set automatically by @value{GDBN}, they
6783 both default to @code{on} whenever the working language changes to
6784 Modula-2. This happens regardless of whether you, or @value{GDBN},
6785 selected the working language.
6786
6787 If you allow @value{GDBN} to set the language automatically, then entering
6788 code compiled from a file whose name ends with @file{.mod} sets the
6789 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6790 the language automatically}, for further details.
6791
6792 @node Deviations, M2 Checks, M2 Defaults, Modula-2
6793 @subsubsection Deviations from standard Modula-2
6794 @cindex Modula-2, deviations from
6795
6796 A few changes have been made to make Modula-2 programs easier to debug.
6797 This is done primarily via loosening its type strictness:
6798
6799 @itemize @bullet
6800 @item
6801 Unlike in standard Modula-2, pointer constants can be formed by
6802 integers. This allows you to modify pointer variables during
6803 debugging. (In standard Modula-2, the actual address contained in a
6804 pointer variable is hidden from you; it can only be modified
6805 through direct assignment to another pointer variable or expression that
6806 returned a pointer.)
6807
6808 @item
6809 C escape sequences can be used in strings and characters to represent
6810 non-printable characters. @value{GDBN} prints out strings with these
6811 escape sequences embedded. Single non-printable characters are
6812 printed using the @samp{CHR(@var{nnn})} format.
6813
6814 @item
6815 The assignment operator (@code{:=}) returns the value of its right-hand
6816 argument.
6817
6818 @item
6819 All built-in procedures both modify @emph{and} return their argument.
6820 @end itemize
6821
6822 @node M2 Checks, M2 Scope, Deviations, Modula-2
6823 @subsubsection Modula-2 type and range checks
6824 @cindex Modula-2 checks
6825
6826 @quotation
6827 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6828 range checking.
6829 @end quotation
6830 @c FIXME remove warning when type/range checks added
6831
6832 @value{GDBN} considers two Modula-2 variables type equivalent if:
6833
6834 @itemize @bullet
6835 @item
6836 They are of types that have been declared equivalent via a @code{TYPE
6837 @var{t1} = @var{t2}} statement
6838
6839 @item
6840 They have been declared on the same line. (Note: This is true of the
6841 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6842 @end itemize
6843
6844 As long as type checking is enabled, any attempt to combine variables
6845 whose types are not equivalent is an error.
6846
6847 Range checking is done on all mathematical operations, assignment, array
6848 index bounds, and all built-in functions and procedures.
6849
6850 @node M2 Scope, GDB/M2, M2 Checks, Modula-2
6851 @subsubsection The scope operators @code{::} and @code{.}
6852 @cindex scope
6853 @kindex .
6854 @cindex colon, doubled as scope operator
6855 @ifinfo
6856 @kindex colon-colon
6857 @c Info cannot handle :: but TeX can.
6858 @end ifinfo
6859 @iftex
6860 @kindex ::
6861 @end iftex
6862
6863 There are a few subtle differences between the Modula-2 scope operator
6864 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6865 similar syntax:
6866
6867 @example
6868
6869 @var{module} . @var{id}
6870 @var{scope} :: @var{id}
6871 @end example
6872
6873 @noindent
6874 where @var{scope} is the name of a module or a procedure,
6875 @var{module} the name of a module, and @var{id} is any declared
6876 identifier within your program, except another module.
6877
6878 Using the @code{::} operator makes @value{GDBN} search the scope
6879 specified by @var{scope} for the identifier @var{id}. If it is not
6880 found in the specified scope, then @value{GDBN} searches all scopes
6881 enclosing the one specified by @var{scope}.
6882
6883 Using the @code{.} operator makes @value{GDBN} search the current scope for
6884 the identifier specified by @var{id} that was imported from the
6885 definition module specified by @var{module}. With this operator, it is
6886 an error if the identifier @var{id} was not imported from definition
6887 module @var{module}, or if @var{id} is not an identifier in
6888 @var{module}.
6889
6890 @node GDB/M2, , M2 Scope, Modula-2
6891 @subsubsection @value{GDBN} and Modula-2
6892
6893 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6894 Five subcommands of @code{set print} and @code{show print} apply
6895 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6896 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6897 apply to C++, and the last to the C @code{union} type, which has no direct
6898 analogue in Modula-2.
6899
6900 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6901 while using any language, is not useful with Modula-2. Its
6902 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6903 created in Modula-2 as they can in C or C++. However, because an
6904 address can be specified by an integral constant, the construct
6905 @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
6906
6907 @cindex @code{#} in Modula-2
6908 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6909 interpreted as the beginning of a comment. Use @code{<>} instead.
6910
6911 @node Chill, , Modula-2, Support
6912 @subsection Chill
6913
6914 The extensions made to @value{GDBN} to support Chill only support output
6915 from the GNU Chill compiler. Other Chill compilers are not currently
6916 supported, and attempting to debug executables produced by them is most
6917 likely to give an error as @value{GDBN} reads in the executable's symbol
6918 table.
6919
6920 This section covers the following Chill related topics and the features
6921 of @value{GDBN} which support these topics.
6922
6923 @menu
6924 * How modes are displayed:: How modes are displayed
6925 * Locations:: Locations and their accesses
6926 * Values and their Operations:: Values and their Operations
6927 @end menu
6928
6929 @node How modes are displayed
6930 @subsubsection How modes are displayed
6931
6932 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
6933 with the functionality of the GNU Chill compiler, and therefore deviates
6934 slightly from the standard specification of the Chill language. The
6935 provided modes are:
6936 @table @code
6937 @item @r{@emph{Discrete modes:}}
6938 @itemize @bullet
6939 @item
6940 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6941 UINT, LONG, ULONG},
6942 @item
6943 @emph{Boolean Mode} which is predefined by @code{BOOL},
6944 @item
6945 @emph{Character Mode} which is predefined by @code{CHAR},
6946 @item
6947 @emph{Set Mode} which is displayed by the keyword @code{SET}.
6948 @smallexample
6949 (@value{GDBP}) ptype x
6950 type = SET (karli = 10, susi = 20, fritzi = 100)
6951 @end smallexample
6952 If the type is an unnumbered set the set element values are omitted.
6953 @item
6954 @emph{Range Mode} which is displayed by @code{type = <basemode>
6955 (<lower bound> : <upper bound>)}, where @code{<lower bound>, <upper
6956 bound>} can be of any discrete literal expression (e.g. set element
6957 names).
6958 @end itemize
6959
6960 @item @r{@emph{Powerset Mode:}}
6961 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
6962 the member mode of the powerset. The member mode can be any discrete mode.
6963 @smallexample
6964 (@value{GDBP}) ptype x
6965 type = POWERSET SET (egon, hugo, otto)
6966 @end smallexample
6967
6968 @item @r{@emph{Reference Modes:}}
6969 @itemize @bullet
6970 @item
6971 @emph{Bound Reference Mode} which is diplayed by the keyword @code{REF}
6972 followed by the mode name to which the reference is bound.
6973 @item
6974 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6975 @end itemize
6976
6977 @item @r{@emph{Procedure mode}}
6978 The procedure mode is displayed by @code{type = PROC(<parameter list>)
6979 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
6980 list>} is a list of the parameter modes. @code{<return mode>} indicates
6981 the mode of the result of the procedure if any. The exceptionlist lists
6982 all possible exceptions which can be raised by the procedure.
6983
6984 @ignore
6985 @item @r{@emph{Instance mode}}
6986 The instance mode is represented by a structure, which has a static
6987 type, and is therefore not really of interest.
6988 @end ignore
6989
6990 @item @r{@emph{Synchronization Modes:}}
6991 @itemize @bullet
6992 @item
6993 @emph{Event Mode} which is displayed by @code{EVENT (<event length>)},
6994 where @code{(<event length>)} is optional.
6995 @item
6996 @emph{Buffer Mode} which is displayed by @code{BUFFER (<buffer length>)
6997 <buffer element mode>}, where @code{(<buffer length>)} is optional.
6998 @end itemize
6999
7000 @item @r{@emph{Timing Modes:}}
7001 @itemize @bullet
7002 @item
7003 @emph{Duration Mode} which is predefined by @code{DURATION}
7004 @item
7005 @emph{Absolute Time Mode} which is predefined by @code{TIME}
7006 @end itemize
7007
7008 @item @r{@emph{Real Modes:}}
7009 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
7010
7011 @item @r{@emph{String Modes:}}
7012 @itemize @bullet
7013 @item
7014 @emph{Character String Mode} which is displayed by @code{CHARS(<string
7015 length>)}, followed by the keyword @code{VARYING} if the String Mode is
7016 a varying mode
7017 @item
7018 @emph{Bit String Mode} which is displayed by @code{BOOLS(<string
7019 length>)}.
7020 @end itemize
7021
7022 @item @r{@emph{Array Mode:}}
7023 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
7024 followed by the element mode (which may in turn be an array mode).
7025 @smallexample
7026 (@value{GDBP}) ptype x
7027 type = ARRAY (1:42)
7028 ARRAY (1:20)
7029 SET (karli = 10, susi = 20, fritzi = 100)
7030 @end smallexample
7031
7032 @item @r{@emph{Structure Mode}}
7033 The Structure mode is displayed by the keyword @code{STRUCT(<field
7034 list>)}. The @code{<field list>} consists of names and modes of fields
7035 of the structure. Variant structures have the keyword @code{CASE <field>
7036 OF <variant fields> ESAC} in their field list. Since the current version
7037 of the GNU Chill compiler doesn't implement tag processing (no runtime
7038 checks of variant fields, and therefore no debugging info), the output
7039 always displays all variant fields.
7040 @smallexample
7041 (@value{GDBP}) ptype str
7042 type = STRUCT (
7043 as x,
7044 bs x,
7045 CASE bs OF
7046 (karli):
7047 cs a
7048 (ott):
7049 ds x
7050 ESAC
7051 )
7052 @end smallexample
7053 @end table
7054
7055 @node Locations
7056 @subsubsection Locations and their accesses
7057
7058 A location in Chill is an object which can contain values.
7059
7060 A value of a location is generally accessed by the (declared) name of
7061 the location. The output conforms to the specification of values in
7062 Chill programs. How values are specified, and which operations are valid
7063 is the topic of the next section.
7064
7065 The pseudo-location @code{RESULT} (or @code{result}) can be used to
7066 display or change the result of a currently-active procedure:
7067 @smallexample
7068 set result := EXPR
7069 @end smallexample
7070 - does the same as the Chill action @code{RESULT EXPR} (which
7071 is not available in gdb).
7072
7073 Values of reference mode locations are printed by @code{PTR(<hex
7074 value>)} in case of a free reference mode, and by @code{(REF <reference
7075 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
7076 represents the address where the reference points to. To access the
7077 value of the location referenced by the pointer, use the dereference
7078 operator `@code{->}'.
7079
7080 Values of procedure mode locations are displayed by @code{@{ PROC
7081 (<argument modes> ) <return mode> @} <address> <name of procedure
7082 location>}. @code{<argument modes>} is a list of modes according to the
7083 parameter specification of the procedure and @code{<address>} shows the
7084 address of the entry point.
7085
7086 @ignore
7087 Locations of instance modes are displayed just like a structure with two
7088 fields specifying the @emph{process type} and the @emph{copy number} of
7089 the investigated instance location@footnote{This comes from the current
7090 implementation of instances. They are implemented as a structure (no
7091 na). The output should be something like @code{[<name of the process>;
7092 <instance number>]}.}. The field names are @code{__proc_type} and
7093 @code{__proc_copy}.
7094
7095 Locations of synchronization modes are displayed like a structure with
7096 the field name @code{__event_data} in case of a event mode location, and
7097 like a structure with the field @code{__buffer_data} in case of a buffer
7098 mode location (refer to previous paragraph).
7099
7100 Structure Mode locations are printed by @code{[.<field name>: <value>,
7101 ...]}. The @code{<field name>} corresponds to the structure mode
7102 definition and the layout of @code{<value>} varies depending of the mode
7103 of the field. If the investigated structure mode location is of variant
7104 structure mode the variant parts of the structure are enclosed in curled
7105 braces (`@code{@{@}}'). Fields enclosed by `@code{@{,@}}' are residing
7106 on the same memory location and represent the current values of the
7107 memory location in their specific modes. Since no tag processing is done
7108 all variants are displayed. A variant field is printed by
7109 @code{(<variant name>) = .<field name>: <value>}. (who implements the
7110 stuff ???)
7111 @smallexample
7112 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7113 [.cs: []], (susi) = [.ds: susi]}]
7114 @end smallexample
7115 @end ignore
7116
7117 Substructures of string mode-, array mode- or structure mode-values
7118 (e.g. array slices, fields of structure locations) are accessed using
7119 certain operations which are descibed in the next chapter.
7120
7121 A location value may be interpreted as having a different mode using the
7122 location conversion. This mode conversion is written as @code{<mode
7123 name>(<location>)}. The user has to consider that the sizes of the modes
7124 have to be equal otherwise an error message occurs. Further no range
7125 checking of the location against the destination mode is performed and
7126 therefore the result can be quite confusing.
7127 @smallexample
7128 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7129 @end smallexample
7130
7131 @node Values and their Operations
7132 @subsubsection Values and their Operations
7133
7134 Values are used to alter locations, to investigate complex structures in
7135 more detail or to filter relevant information out of a large amount of
7136 data. There are several (mode dependent) operations defined which enable
7137 such investigations. These operations are not only applicable to
7138 constant values but also to locations, which can become quite useful
7139 when debugging complex structures. During parsing the command line
7140 (e.g. evaluating an expression) @value{GDBN} treats location names as
7141 the values behind these locations.
7142
7143 This subchapters describes how values have to be specified and which
7144 operations are legal to be used with such values.
7145
7146 @table @code
7147 @item Literal Values
7148 Literal values are specified in the same manner as in GNU Chill programs.
7149 For detailed specification refer to the GNU Chill implementation Manual
7150 chapter 1.5.
7151
7152 @ignore
7153 @itemize @bullet
7154 @item
7155 @emph{Integer Literals} are specified in the same manner as in Chill
7156 programs (refer z200/88 chpt 5.2.4.2)
7157 @item
7158 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7159 @item
7160 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7161 @code{'M'})
7162 @item
7163 @emph{Set Literals} are defined by a name which was specified in a set
7164 mode. The value delivered by a Set Literal is the set value. This is
7165 comparable to an enumaration in C/C++ language.
7166 @item
7167 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
7168 emptiness literal delivers either the empty reference value, the empty
7169 procedure value or the empty instance value.
7170
7171 @item
7172 @emph{Character String Literals} are defined by a sequence of characters
7173 enclosed in single- or double quotes. If a single- or double quote has
7174 to be part of the string literal it has to be stuffed (specified twice).
7175 @item
7176 @emph{Bitstring Literals} are specified in the same manner as in Chill
7177 programs (refer z200/88 chpt 5.2.4.8).
7178 @item
7179 @emph{Floating point literals} are specified in the same manner as in
7180 (gnu-)Chill programs (refer GNU Chill implementation Manual chapter 1.5).
7181 @end itemize
7182 @end ignore
7183
7184 @item Tuple Values
7185 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
7186 name>} can be omitted if the mode of the tuple is unambigous. This
7187 unambiguity is derived from the context of a evaluated expression.
7188 @code{<tuple>} can be one of the following:
7189 @itemize @bullet
7190 @item @emph{Powerset Tuple}
7191 @item @emph{Array Tuple}
7192 @item @emph{Structure Tuple}
7193 Powerset tuples, array tuples and structure tuples are specified in the
7194 same manner as in Chill programs refer z200/88 chpt 5.2.5.
7195 @end itemize
7196
7197 @item String Element Value
7198 A string element value is specified by @code{<string value>(<index>)},
7199 where @code{<index>} is a integer expression. It delivers a character
7200 value which is equivalent to the character indexed by @code{<index>} in
7201 the string.
7202
7203 @item String Slice Value
7204 A string slice value is specified by @code{<string value>(<slice
7205 spec>)}, where @code{<slice spec>} can be either a range of integer
7206 expressions or specified by @code{<start expr> up <size>}.
7207 @code{<size>} denotes the number of elements which the slice contains.
7208 The delivered value is a string value, which is part of the specified
7209 string.
7210
7211 @item Array Element Values
7212 An array element value is specified by @code{<array value>(<expr>)} and
7213 delivers a array element value of the mode of the specified array.
7214
7215 @item Array Slice Values
7216 An array slice is specified by @code{<array value>(<slice spec>)}, where
7217 @code{<slice spec>} can be either a range specified by expressions or by
7218 @code{<start expr> up <size>}. @code{<size>} denotes the number of
7219 arrayelements the slice contains. The delivered value is an array value
7220 which is part of the specified array.
7221
7222 @item Structure Field Values
7223 A structure field value is derived by @code{<structure value>.<field
7224 name>}, where @code{<field name>} indcates the name of a field specified
7225 in the mode definition of the structure. The mode of the delivered value
7226 corresponds to this mode definition in the structure definition.
7227
7228 @item Procedure Call Value
7229 The procedure call value is derived from the return value of the
7230 procedure@footnote{If a procedure call is used for instance in an
7231 expression, then this procedure is called with all its side
7232 effects. This can lead to confusing results if used carelessly.}.
7233
7234 Values of duration mode locations are represented by ULONG literals.
7235
7236 Values of time mode locations are represented by TIME(<secs>:<nsecs>).
7237
7238 @ignore
7239 This is not implemented yet:
7240 @item Built-in Value
7241 @noindent
7242 The following built in functions are provided:
7243 @table @code
7244 @item @code{ADDR()}
7245 @item @code{NUM()}
7246 @item @code{PRED()}
7247 @item @code{SUCC()}
7248 @item @code{ABS()}
7249 @item @code{CARD()}
7250 @item @code{MAX()}
7251 @item @code{MIN()}
7252 @item @code{SIZE()}
7253 @item @code{UPPER()}
7254 @item @code{LOWER()}
7255 @item @code{LENGTH()}
7256 @item @code{SIN()}
7257 @item @code{COS()}
7258 @item @code{TAN()}
7259 @item @code{ARCSIN()}
7260 @item @code{ARCCOS()}
7261 @item @code{ARCTAN()}
7262 @item @code{EXP()}
7263 @item @code{LN()}
7264 @item @code{LOG()}
7265 @item @code{SQRT()}
7266 @end table
7267
7268 For a detailed description refer to the GNU Chill implementation manual
7269 chapter 1.6.
7270 @end ignore
7271
7272 @item Zero-adic Operator Value
7273 The zero-adic operator value is derived from the instance value for the
7274 current active process.
7275
7276 @item Expression Values
7277 The value delivered by an expression is the result of the evaluation of
7278 the specified expression. If there are error conditions (mode
7279 incompatibility, etc.) the evaluation of expressions is aborted with a
7280 corresponding error message. Expressions may be paranthesised which
7281 causes the evaluation of this expression before any other expression
7282 which uses the result of the paranthesised expression. The following
7283 operators are supported by @value{GDBN}:
7284 @table @code
7285 @item @code{OR, ORIF, XOR}
7286 @item @code{AND, ANDIF}
7287 @item @code{NOT}
7288 Logical operators defined over operands of boolean mode.
7289 @item @code{=, /=}
7290 Equality and inequality operators defined over all modes.
7291 @item @code{>, >=}
7292 @item @code{<, <=}
7293 Relational operators defined over predefined modes.
7294 @item @code{+, -}
7295 @item @code{*, /, MOD, REM}
7296 Arithmetic operators defined over predefined modes.
7297 @item @code{-}
7298 Change sign operator.
7299 @item @code{//}
7300 String concatenation operator.
7301 @item @code{()}
7302 String repetition operator.
7303 @item @code{->}
7304 Referenced location operator which can be used either to take the
7305 address of a location (@code{->loc}), or to dereference a reference
7306 location (@code{loc->}).
7307 @item @code{OR, XOR}
7308 @item @code{AND}
7309 @item @code{NOT}
7310 Powerset and bitstring operators.
7311 @item @code{>, >=}
7312 @item @code{<, <=}
7313 Powerset inclusion operators.
7314 @item @code{IN}
7315 Membership operator.
7316 @end table
7317 @end table
7318
7319 @subsubsection Chill type and range checks
7320
7321 @value{GDBN} considers two Chill variables mode equivalent if the sizes
7322 of the two modes are equal. This rule applies recursively to more
7323 complex datatypes which means that complex modes are treated
7324 eqivalent if all element modes (which also can be complex modes like
7325 structures, arrays, etc.) have the same size.
7326
7327 Range checking is done on all mathematical operations, assignment, array
7328 index bounds and all built in procedures.
7329
7330 Strong type checks are forced using the @value{GDBN} command @code{set
7331 check strong}. This enforces strong type and range checks on all
7332 operations where Chill constructs are used (expressions, built in
7333 functions, etc.) in respect to the semantics as defined in the z.200
7334 language specification.
7335
7336 @noindent
7337 All checks can be disabled by the @value{GDBN} command @code{set check
7338 off}.
7339
7340 @ignore
7341 @subsubsection Deviations from the Chill Standard Z200/88
7342 see last paragraph ?
7343 @end ignore
7344
7345 @subsubsection Chill defaults
7346
7347 If type and range checking are set automatically by @value{GDBN}, they
7348 both default to @code{on} whenever the working language changes to
7349 Chill. This happens regardless of whether you, or @value{GDBN},
7350 selected the working language.
7351
7352 If you allow @value{GDBN} to set the language automatically, then entering
7353 code compiled from a file whose name ends with @file{.ch} sets the
7354 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
7355 the language automatically}, for further details.
7356
7357 @node Symbols, Altering, Languages, Top
7358 @chapter Examining the Symbol Table
7359
7360 The commands described in this section allow you to inquire about the
7361 symbols (names of variables, functions and types) defined in your
7362 program. This information is inherent in the text of your program and
7363 does not change as your program executes. @value{GDBN} finds it in your
7364 program's symbol table, in the file indicated when you started @value{GDBN}
7365 (@pxref{File Options, ,Choosing files}), or by one of the
7366 file-management commands (@pxref{Files, ,Commands to specify files}).
7367
7368 @cindex symbol names
7369 @cindex names of symbols
7370 @cindex quoting names
7371 Occasionally, you may need to refer to symbols that contain unusual
7372 characters, which @value{GDBN} ordinarily treats as word delimiters. The
7373 most frequent case is in referring to static variables in other
7374 source files (@pxref{Variables,,Program variables}). File names
7375 are recorded in object files as debugging symbols, but @value{GDBN} would
7376 ordinarily parse a typical file name, like @file{foo.c}, as the three words
7377 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7378 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7379
7380 @example
7381 p 'foo.c'::x
7382 @end example
7383
7384 @noindent
7385 looks up the value of @code{x} in the scope of the file @file{foo.c}.
7386
7387 @table @code
7388 @kindex info address
7389 @item info address @var{symbol}
7390 Describe where the data for @var{symbol} is stored. For a register
7391 variable, this says which register it is kept in. For a non-register
7392 local variable, this prints the stack-frame offset at which the variable
7393 is always stored.
7394
7395 Note the contrast with @samp{print &@var{symbol}}, which does not work
7396 at all for a register variable, and for a stack local variable prints
7397 the exact address of the current instantiation of the variable.
7398
7399 @kindex whatis
7400 @item whatis @var{exp}
7401 Print the data type of expression @var{exp}. @var{exp} is not
7402 actually evaluated, and any side-effecting operations (such as
7403 assignments or function calls) inside it do not take place.
7404 @xref{Expressions, ,Expressions}.
7405
7406 @item whatis
7407 Print the data type of @code{$}, the last value in the value history.
7408
7409 @kindex ptype
7410 @item ptype @var{typename}
7411 Print a description of data type @var{typename}. @var{typename} may be
7412 the name of a type, or for C code it may have the form @samp{class
7413 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7414 @var{union-tag}} or @samp{enum @var{enum-tag}}.
7415
7416 @item ptype @var{exp}
7417 @itemx ptype
7418 Print a description of the type of expression @var{exp}. @code{ptype}
7419 differs from @code{whatis} by printing a detailed description, instead
7420 of just the name of the type.
7421
7422 For example, for this variable declaration:
7423
7424 @example
7425 struct complex @{double real; double imag;@} v;
7426 @end example
7427
7428 @noindent
7429 the two commands give this output:
7430
7431 @example
7432 @group
7433 (@value{GDBP}) whatis v
7434 type = struct complex
7435 (@value{GDBP}) ptype v
7436 type = struct complex @{
7437 double real;
7438 double imag;
7439 @}
7440 @end group
7441 @end example
7442
7443 @noindent
7444 As with @code{whatis}, using @code{ptype} without an argument refers to
7445 the type of @code{$}, the last value in the value history.
7446
7447 @kindex info types
7448 @item info types @var{regexp}
7449 @itemx info types
7450 Print a brief description of all types whose name matches @var{regexp}
7451 (or all types in your program, if you supply no argument). Each
7452 complete typename is matched as though it were a complete line; thus,
7453 @samp{i type value} gives information on all types in your program whose
7454 name includes the string @code{value}, but @samp{i type ^value$} gives
7455 information only on types whose complete name is @code{value}.
7456
7457 This command differs from @code{ptype} in two ways: first, like
7458 @code{whatis}, it does not print a detailed description; second, it
7459 lists all source files where a type is defined.
7460
7461 @kindex info source
7462 @item info source
7463 Show the name of the current source file---that is, the source file for
7464 the function containing the current point of execution---and the language
7465 it was written in.
7466
7467 @kindex info sources
7468 @item info sources
7469 Print the names of all source files in your program for which there is
7470 debugging information, organized into two lists: files whose symbols
7471 have already been read, and files whose symbols will be read when needed.
7472
7473 @kindex info functions
7474 @item info functions
7475 Print the names and data types of all defined functions.
7476
7477 @item info functions @var{regexp}
7478 Print the names and data types of all defined functions
7479 whose names contain a match for regular expression @var{regexp}.
7480 Thus, @samp{info fun step} finds all functions whose names
7481 include @code{step}; @samp{info fun ^step} finds those whose names
7482 start with @code{step}.
7483
7484 @kindex info variables
7485 @item info variables
7486 Print the names and data types of all variables that are declared
7487 outside of functions (i.e., excluding local variables).
7488
7489 @item info variables @var{regexp}
7490 Print the names and data types of all variables (except for local
7491 variables) whose names contain a match for regular expression
7492 @var{regexp}.
7493
7494 @ignore
7495 This was never implemented.
7496 @kindex info methods
7497 @item info methods
7498 @itemx info methods @var{regexp}
7499 The @code{info methods} command permits the user to examine all defined
7500 methods within C++ program, or (with the @var{regexp} argument) a
7501 specific set of methods found in the various C++ classes. Many
7502 C++ classes provide a large number of methods. Thus, the output
7503 from the @code{ptype} command can be overwhelming and hard to use. The
7504 @code{info-methods} command filters the methods, printing only those
7505 which match the regular-expression @var{regexp}.
7506 @end ignore
7507
7508 @ifclear HPPA
7509 @cindex reloading symbols
7510 Some systems allow individual object files that make up your program to
7511 be replaced without stopping and restarting your program. For example,
7512 in VxWorks you can simply recompile a defective object file and keep on
7513 running. If you are running on one of these systems, you can allow
7514 @value{GDBN} to reload the symbols for automatically relinked modules:
7515
7516 @table @code
7517 @kindex set symbol-reloading
7518 @item set symbol-reloading on
7519 Replace symbol definitions for the corresponding source file when an
7520 object file with a particular name is seen again.
7521
7522 @item set symbol-reloading off
7523 Do not replace symbol definitions when re-encountering object files of
7524 the same name. This is the default state; if you are not running on a
7525 system that permits automatically relinking modules, you should leave
7526 @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7527 when linking large programs, that may contain several modules (from
7528 different directories or libraries) with the same name.
7529
7530 @kindex show symbol-reloading
7531 @item show symbol-reloading
7532 Show the current @code{on} or @code{off} setting.
7533 @end table
7534 @end ifclear
7535
7536 @ifset HPPA
7537 @kindex set opaque-type-resolution
7538 @item set opaque-type-resolution on
7539 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7540 declared as a pointer to a @code{struct}, @code{class}, or
7541 @code{union}---for example, @code{struct MyType *}---that is used in one
7542 source file although the full declaration of @code{struct MyType} is in
7543 another source file. The default is on.
7544
7545 A change in the setting of this subcommand will not take effect until
7546 the next time symbols for a file are loaded.
7547
7548 @item set opaque-type-resolution off
7549 Tell @value{GDBN} not to resolve opaque types. In this case, the type
7550 is printed as follows:
7551 @smallexample
7552 @{<no data fields>@}
7553 @end smallexample
7554
7555 @kindex show opaque-type-resolution
7556 @item show opaque-type-resolution
7557 Show whether opaque types are resolved or not.
7558 @end ifset
7559
7560 @kindex maint print symbols
7561 @cindex symbol dump
7562 @kindex maint print psymbols
7563 @cindex partial symbol dump
7564 @item maint print symbols @var{filename}
7565 @itemx maint print psymbols @var{filename}
7566 @itemx maint print msymbols @var{filename}
7567 Write a dump of debugging symbol data into the file @var{filename}.
7568 These commands are used to debug the @value{GDBN} symbol-reading code. Only
7569 symbols with debugging data are included. If you use @samp{maint print
7570 symbols}, @value{GDBN} includes all the symbols for which it has already
7571 collected full details: that is, @var{filename} reflects symbols for
7572 only those files whose symbols @value{GDBN} has read. You can use the
7573 command @code{info sources} to find out which files these are. If you
7574 use @samp{maint print psymbols} instead, the dump shows information about
7575 symbols that @value{GDBN} only knows partially---that is, symbols defined in
7576 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7577 @samp{maint print msymbols} dumps just the minimal symbol information
7578 required for each object file from which @value{GDBN} has read some symbols.
7579 @xref{Files, ,Commands to specify files}, for a discussion of how
7580 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
7581 @end table
7582
7583 @node Altering, GDB Files, Symbols, Top
7584 @chapter Altering Execution
7585
7586 Once you think you have found an error in your program, you might want to
7587 find out for certain whether correcting the apparent error would lead to
7588 correct results in the rest of the run. You can find the answer by
7589 experiment, using the @value{GDBN} features for altering execution of the
7590 program.
7591
7592 For example, you can store new values into variables or memory
7593 locations, give your program a signal, restart it at a different
7594 address, or even return prematurely from a function.
7595
7596 @menu
7597 * Assignment:: Assignment to variables
7598 * Jumping:: Continuing at a different address
7599 * Signaling:: Giving your program a signal
7600 * Returning:: Returning from a function
7601 * Calling:: Calling your program's functions
7602 * Patching:: Patching your program
7603 @end menu
7604
7605 @node Assignment, Jumping, Altering, Altering
7606 @section Assignment to variables
7607
7608 @cindex assignment
7609 @cindex setting variables
7610 To alter the value of a variable, evaluate an assignment expression.
7611 @xref{Expressions, ,Expressions}. For example,
7612
7613 @example
7614 print x=4
7615 @end example
7616
7617 @noindent
7618 stores the value 4 into the variable @code{x}, and then prints the
7619 value of the assignment expression (which is 4).
7620 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7621 information on operators in supported languages.
7622
7623 @kindex set variable
7624 @cindex variables, setting
7625 If you are not interested in seeing the value of the assignment, use the
7626 @code{set} command instead of the @code{print} command. @code{set} is
7627 really the same as @code{print} except that the expression's value is
7628 not printed and is not put in the value history (@pxref{Value History,
7629 ,Value history}). The expression is evaluated only for its effects.
7630
7631 @ifclear HPPA
7632 If the beginning of the argument string of the @code{set} command
7633 appears identical to a @code{set} subcommand, use the @code{set
7634 variable} command instead of just @code{set}. This command is identical
7635 to @code{set} except for its lack of subcommands. For example, if your
7636 program has a variable @code{width}, you get an error if you try to set
7637 a new value with just @samp{set width=13}, because @value{GDBN} has the
7638 command @code{set width}:
7639
7640 @example
7641 (@value{GDBP}) whatis width
7642 type = double
7643 (@value{GDBP}) p width
7644 $4 = 13
7645 (@value{GDBP}) set width=47
7646 Invalid syntax in expression.
7647 @end example
7648
7649 @noindent
7650 The invalid expression, of course, is @samp{=47}. In
7651 order to actually set the program's variable @code{width}, use
7652
7653 @example
7654 (@value{GDBP}) set var width=47
7655 @end example
7656 @end ifclear
7657 @ifset HPPA
7658 Because the @code{set} command has many subcommands that can conflict
7659 with the names of program variables, it is a good idea to use the
7660 @code{set variable} command instead of just @code{set}. For example, if
7661 your program has a variable @code{g}, you run into problems if you try
7662 to set a new value with just @samp{set g=4}, because @value{GDBN} has
7663 the command @code{set gnutarget}, abbreviated @code{set g}:
7664
7665 @example
7666 @group
7667 (@value{GDBP}) whatis g
7668 type = double
7669 (@value{GDBP}) p g
7670 $1 = 1
7671 (@value{GDBP}) set g=4
7672 (gdb) p g
7673 $2 = 1
7674 (@value{GDBP}) r
7675 The program being debugged has been started already.
7676 Start it from the beginning? (y or n) y
7677 Starting program: /home/smith/cc_progs/a.out
7678 "/home/smith/cc_progs/a.out": can't open to read symbols: Invalid bfd target.
7679 (@value{GDBP}) show g
7680 The current BFD target is "=4".
7681 @end group
7682 @end example
7683
7684 @noindent
7685 The program variable @code{g} did not change, and you silently set the
7686 @code{gnutarget} to an invalid value. In order to set the variable
7687 @code{g}, use
7688
7689 @example
7690 (@value{GDBP}) set var g=4
7691 @end example
7692 @end ifset
7693
7694 @value{GDBN} allows more implicit conversions in assignments than C; you can
7695 freely store an integer value into a pointer variable or vice versa,
7696 and you can convert any structure to any other structure that is the
7697 same length or shorter.
7698 @comment FIXME: how do structs align/pad in these conversions?
7699 @comment /doc@cygnus.com 18dec1990
7700
7701 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7702 construct to generate a value of specified type at a specified address
7703 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7704 to memory location @code{0x83040} as an integer (which implies a certain size
7705 and representation in memory), and
7706
7707 @example
7708 set @{int@}0x83040 = 4
7709 @end example
7710
7711 @noindent
7712 stores the value 4 into that memory location.
7713
7714 @node Jumping, Signaling, Assignment, Altering
7715 @section Continuing at a different address
7716
7717 Ordinarily, when you continue your program, you do so at the place where
7718 it stopped, with the @code{continue} command. You can instead continue at
7719 an address of your own choosing, with the following commands:
7720
7721 @table @code
7722 @kindex jump
7723 @item jump @var{linespec}
7724 Resume execution at line @var{linespec}. Execution stops again
7725 immediately if there is a breakpoint there. @xref{List, ,Printing
7726 source lines}, for a description of the different forms of
7727 @var{linespec}. It is common practice to use the @code{tbreak} command
7728 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7729 breakpoints}.
7730
7731 The @code{jump} command does not change the current stack frame, or
7732 the stack pointer, or the contents of any memory location or any
7733 register other than the program counter. If line @var{linespec} is in
7734 a different function from the one currently executing, the results may
7735 be bizarre if the two functions expect different patterns of arguments or
7736 of local variables. For this reason, the @code{jump} command requests
7737 confirmation if the specified line is not in the function currently
7738 executing. However, even bizarre results are predictable if you are
7739 well acquainted with the machine-language code of your program.
7740
7741 @item jump *@var{address}
7742 Resume execution at the instruction at address @var{address}.
7743 @end table
7744
7745 @ifclear HPPA
7746 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
7747 You can get much the same effect as the @code{jump} command by storing a
7748 new value into the register @code{$pc}. The difference is that this
7749 does not start your program running; it only changes the address of where it
7750 @emph{will} run when you continue. For example,
7751
7752 @example
7753 set $pc = 0x485
7754 @end example
7755
7756 @noindent
7757 makes the next @code{continue} command or stepping command execute at
7758 address @code{0x485}, rather than at the address where your program stopped.
7759 @xref{Continuing and Stepping, ,Continuing and stepping}.
7760 @end ifclear
7761
7762 The most common occasion to use the @code{jump} command is to back
7763 up---perhaps with more breakpoints set---over a portion of a program
7764 that has already executed, in order to examine its execution in more
7765 detail.
7766
7767 @c @group
7768 @node Signaling, Returning, Jumping, Altering
7769 @section Giving your program a signal
7770
7771 @table @code
7772 @kindex signal
7773 @item signal @var{signal}
7774 Resume execution where your program stopped, but immediately give it the
7775 signal @var{signal}. @var{signal} can be the name or the number of a
7776 signal. For example, on many systems @code{signal 2} and @code{signal
7777 SIGINT} are both ways of sending an interrupt signal.
7778
7779 Alternatively, if @var{signal} is zero, continue execution without
7780 giving a signal. This is useful when your program stopped on account of
7781 a signal and would ordinary see the signal when resumed with the
7782 @code{continue} command; @samp{signal 0} causes it to resume without a
7783 signal.
7784
7785 @code{signal} does not repeat when you press @key{RET} a second time
7786 after executing the command.
7787 @end table
7788 @c @end group
7789
7790 Invoking the @code{signal} command is not the same as invoking the
7791 @code{kill} utility from the shell. Sending a signal with @code{kill}
7792 causes @value{GDBN} to decide what to do with the signal depending on
7793 the signal handling tables (@pxref{Signals}). The @code{signal} command
7794 passes the signal directly to your program.
7795
7796
7797 @node Returning, Calling, Signaling, Altering
7798 @section Returning from a function
7799
7800 @table @code
7801 @cindex returning from a function
7802 @kindex return
7803 @item return
7804 @itemx return @var{expression}
7805 You can cancel execution of a function call with the @code{return}
7806 command. If you give an
7807 @var{expression} argument, its value is used as the function's return
7808 value.
7809 @end table
7810
7811 When you use @code{return}, @value{GDBN} discards the selected stack frame
7812 (and all frames within it). You can think of this as making the
7813 discarded frame return prematurely. If you wish to specify a value to
7814 be returned, give that value as the argument to @code{return}.
7815
7816 This pops the selected stack frame (@pxref{Selection, ,Selecting a
7817 frame}), and any other frames inside of it, leaving its caller as the
7818 innermost remaining frame. That frame becomes selected. The
7819 specified value is stored in the registers used for returning values
7820 of functions.
7821
7822 The @code{return} command does not resume execution; it leaves the
7823 program stopped in the state that would exist if the function had just
7824 returned. In contrast, the @code{finish} command (@pxref{Continuing
7825 and Stepping, ,Continuing and stepping}) resumes execution until the
7826 selected stack frame returns naturally.
7827
7828 @node Calling, Patching, Returning, Altering
7829 @section Calling program functions
7830
7831 @cindex calling functions
7832 @kindex call
7833 @table @code
7834 @item call @var{expr}
7835 Evaluate the expression @var{expr} without displaying @code{void}
7836 returned values.
7837 @end table
7838
7839 You can use this variant of the @code{print} command if you want to
7840 execute a function from your program, but without cluttering the output
7841 with @code{void} returned values. If the result is not void, it
7842 is printed and saved in the value history.
7843
7844 @ifclear HPPA
7845 For the A29K, a user-controlled variable @code{call_scratch_address},
7846 specifies the location of a scratch area to be used when @value{GDBN}
7847 calls a function in the target. This is necessary because the usual
7848 method of putting the scratch area on the stack does not work in systems
7849 that have separate instruction and data spaces.
7850 @end ifclear
7851
7852 @node Patching, , Calling, Altering
7853 @section Patching programs
7854
7855 @cindex patching binaries
7856 @cindex writing into executables
7857 @cindex writing into corefiles
7858
7859 By default, @value{GDBN} opens the file containing your program's
7860 executable code (or the corefile) read-only. This prevents accidental
7861 alterations to machine code; but it also prevents you from intentionally
7862 patching your program's binary.
7863
7864 If you'd like to be able to patch the binary, you can specify that
7865 explicitly with the @code{set write} command. For example, you might
7866 want to turn on internal debugging flags, or even to make emergency
7867 repairs.
7868
7869 @table @code
7870 @kindex set write
7871 @item set write on
7872 @itemx set write off
7873 If you specify @samp{set write on}, @value{GDBN} opens executable and
7874 core files for both reading and writing; if you specify @samp{set write
7875 off} (the default), @value{GDBN} opens them read-only.
7876
7877 If you have already loaded a file, you must load it again (using the
7878 @code{exec-file} or @code{core-file} command) after changing @code{set
7879 write}, for your new setting to take effect.
7880
7881 @item show write
7882 @kindex show write
7883 Display whether executable files and core files are opened for writing
7884 as well as reading.
7885 @end table
7886
7887 @node GDB Files, Targets, Altering, Top
7888 @chapter @value{GDBN} Files
7889
7890 @value{GDBN} needs to know the file name of the program to be debugged,
7891 both in order to read its symbol table and in order to start your
7892 program. To debug a core dump of a previous run, you must also tell
7893 @value{GDBN} the name of the core dump file.
7894
7895 @menu
7896 * Files:: Commands to specify files
7897 * Symbol Errors:: Errors reading symbol files
7898 @end menu
7899
7900 @node Files, Symbol Errors, GDB Files, GDB Files
7901 @section Commands to specify files
7902
7903 @cindex symbol table
7904 @cindex core dump file
7905
7906 You may want to specify executable and core dump file names. The usual
7907 way to do this is at start-up time, using the arguments to
7908 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7909 Out of @value{GDBN}}).
7910
7911 Occasionally it is necessary to change to a different file during a
7912 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7913 a file you want to use. In these situations the @value{GDBN} commands
7914 to specify new files are useful.
7915
7916 @table @code
7917 @cindex executable file
7918 @kindex file
7919 @item file @var{filename}
7920 Use @var{filename} as the program to be debugged. It is read for its
7921 symbols and for the contents of pure memory. It is also the program
7922 executed when you use the @code{run} command. If you do not specify a
7923 directory and the file is not found in the @value{GDBN} working directory,
7924 @value{GDBN} uses the environment variable @code{PATH} as a list of
7925 directories to search, just as the shell does when looking for a program
7926 to run. You can change the value of this variable, for both @value{GDBN}
7927 and your program, using the @code{path} command.
7928
7929 @ifclear HPPA
7930 On systems with memory-mapped files, an auxiliary file
7931 @file{@var{filename}.syms} may hold symbol table information for
7932 @var{filename}. If so, @value{GDBN} maps in the symbol table from
7933 @file{@var{filename}.syms}, starting up more quickly. See the
7934 descriptions of the file options @samp{-mapped} and @samp{-readnow}
7935 (available on the command line, and with the commands @code{file},
7936 @code{symbol-file}, or @code{add-symbol-file}, described below),
7937 for more information.
7938 @end ifclear
7939
7940 @item file
7941 @code{file} with no argument makes @value{GDBN} discard any information it
7942 has on both executable file and the symbol table.
7943
7944 @kindex exec-file
7945 @item exec-file @r{[} @var{filename} @r{]}
7946 Specify that the program to be run (but not the symbol table) is found
7947 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7948 if necessary to locate your program. Omitting @var{filename} means to
7949 discard information on the executable file.
7950
7951 @kindex symbol-file
7952 @item symbol-file @r{[} @var{filename} @r{]}
7953 Read symbol table information from file @var{filename}. @code{PATH} is
7954 searched when necessary. Use the @code{file} command to get both symbol
7955 table and program to run from the same file.
7956
7957 @code{symbol-file} with no argument clears out @value{GDBN} information on your
7958 program's symbol table.
7959
7960 The @code{symbol-file} command causes @value{GDBN} to forget the contents
7961 of its convenience variables, the value history, and all breakpoints and
7962 auto-display expressions. This is because they may contain pointers to
7963 the internal data recording symbols and data types, which are part of
7964 the old symbol table data being discarded inside @value{GDBN}.
7965
7966 @code{symbol-file} does not repeat if you press @key{RET} again after
7967 executing it once.
7968
7969 When @value{GDBN} is configured for a particular environment, it
7970 understands debugging information in whatever format is the standard
7971 generated for that environment; you may use either a @sc{gnu} compiler, or
7972 other compilers that adhere to the local conventions.
7973 @ifclear HPPA
7974 Best results are usually obtained from @sc{gnu} compilers; for example,
7975 using @code{@value{GCC}} you can generate debugging information for
7976 optimized code.
7977 @end ifclear
7978
7979 For most kinds of object files, with the exception of old SVR3 systems
7980 using COFF, the @code{symbol-file} command does not normally read the
7981 symbol table in full right away. Instead, it scans the symbol table
7982 quickly to find which source files and which symbols are present. The
7983 details are read later, one source file at a time, as they are needed.
7984
7985 The purpose of this two-stage reading strategy is to make @value{GDBN}
7986 start up faster. For the most part, it is invisible except for
7987 occasional pauses while the symbol table details for a particular source
7988 file are being read. (The @code{set verbose} command can turn these
7989 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7990 warnings and messages}.)
7991
7992 @ifclear HPPA
7993 We have not implemented the two-stage strategy for COFF yet. When the
7994 symbol table is stored in COFF format, @code{symbol-file} reads the
7995 symbol table data in full right away. Note that ``stabs-in-COFF''
7996 still does the two-stage strategy, since the debug info is actually
7997 in stabs format.
7998
7999 @kindex readnow
8000 @cindex reading symbols immediately
8001 @cindex symbols, reading immediately
8002 @kindex mapped
8003 @cindex memory-mapped symbol file
8004 @cindex saving symbol table
8005 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8006 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8007 You can override the @value{GDBN} two-stage strategy for reading symbol
8008 tables by using the @samp{-readnow} option with any of the commands that
8009 load symbol table information, if you want to be sure @value{GDBN} has the
8010 entire symbol table available.
8011 @end ifclear
8012
8013 @ifclear HPPA
8014 If memory-mapped files are available on your system through the
8015 @code{mmap} system call, you can use another option, @samp{-mapped}, to
8016 cause @value{GDBN} to write the symbols for your program into a reusable
8017 file. Future @value{GDBN} debugging sessions map in symbol information
8018 from this auxiliary symbol file (if the program has not changed), rather
8019 than spending time reading the symbol table from the executable
8020 program. Using the @samp{-mapped} option has the same effect as
8021 starting @value{GDBN} with the @samp{-mapped} command-line option.
8022
8023 You can use both options together, to make sure the auxiliary symbol
8024 file has all the symbol information for your program.
8025
8026 The auxiliary symbol file for a program called @var{myprog} is called
8027 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
8028 than the corresponding executable), @value{GDBN} always attempts to use
8029 it when you debug @var{myprog}; no special options or commands are
8030 needed.
8031
8032 The @file{.syms} file is specific to the host machine where you run
8033 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
8034 symbol table. It cannot be shared across multiple host platforms.
8035
8036 @c FIXME: for now no mention of directories, since this seems to be in
8037 @c flux. 13mar1992 status is that in theory GDB would look either in
8038 @c current dir or in same dir as myprog; but issues like competing
8039 @c GDB's, or clutter in system dirs, mean that in practice right now
8040 @c only current dir is used. FFish says maybe a special GDB hierarchy
8041 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
8042 @c files.
8043
8044 @kindex core
8045 @kindex core-file
8046 @item core-file @r{[} @var{filename} @r{]}
8047 Specify the whereabouts of a core dump file to be used as the ``contents
8048 of memory''. Traditionally, core files contain only some parts of the
8049 address space of the process that generated them; @value{GDBN} can access the
8050 executable file itself for other parts.
8051
8052 @code{core-file} with no argument specifies that no core file is
8053 to be used.
8054
8055 Note that the core file is ignored when your program is actually running
8056 under @value{GDBN}. So, if you have been running your program and you
8057 wish to debug a core file instead, you must kill the subprocess in which
8058 the program is running. To do this, use the @code{kill} command
8059 (@pxref{Kill Process, ,Killing the child process}).
8060 @end ifclear
8061
8062 @ifclear HPPA
8063 @kindex add-symbol-file
8064 @cindex dynamic linking
8065 @item add-symbol-file @var{filename} @var{address}
8066 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8067 The @code{add-symbol-file} command reads additional symbol table information
8068 from the file @var{filename}. You would use this command when @var{filename}
8069 has been dynamically loaded (by some other means) into the program that
8070 is running. @var{address} should be the memory address at which the
8071 file has been loaded; @value{GDBN} cannot figure this out for itself.
8072 You can specify @var{address} as an expression.
8073
8074 The symbol table of the file @var{filename} is added to the symbol table
8075 originally read with the @code{symbol-file} command. You can use the
8076 @code{add-symbol-file} command any number of times; the new symbol data thus
8077 read keeps adding to the old. To discard all old symbol data instead,
8078 use the @code{symbol-file} command.
8079
8080 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8081
8082 You can use the @samp{-mapped} and @samp{-readnow} options just as with
8083 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8084 table information for @var{filename}.
8085
8086 @kindex add-shared-symbol-file
8087 @item add-shared-symbol-file
8088 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
8089 operating system for the Motorola 88k. @value{GDBN} automatically looks for
8090 shared libraries, however if @value{GDBN} does not find yours, you can run
8091 @code{add-shared-symbol-file}. It takes no arguments.
8092 @end ifclear
8093
8094 @ifclear HPPA
8095 @kindex section
8096 @item section
8097 The @code{section} command changes the base address of section SECTION of
8098 the exec file to ADDR. This can be used if the exec file does not contain
8099 section addresses, (such as in the a.out format), or when the addresses
8100 specified in the file itself are wrong. Each section must be changed
8101 separately. The ``info files'' command lists all the sections and their
8102 addresses.
8103 @end ifclear
8104
8105 @kindex info files
8106 @kindex info target
8107 @item info files
8108 @itemx info target
8109 @code{info files} and @code{info target} are synonymous; both print the
8110 current target (@pxref{Targets, ,Specifying a Debugging Target}),
8111 including the names of the executable and core dump files currently in
8112 use by @value{GDBN}, and the files from which symbols were loaded. The
8113 command @code{help target} lists all possible targets rather than
8114 current ones.
8115
8116 @end table
8117
8118 All file-specifying commands allow both absolute and relative file names
8119 as arguments. @value{GDBN} always converts the file name to an absolute file
8120 name and remembers it that way.
8121
8122 @cindex shared libraries
8123 @ifclear HPPA
8124 @c added HP-UX -- Kim (HP writer)
8125 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8126 libraries.
8127 @end ifclear
8128 @ifset HPPA
8129 @value{GDBN} supports HP-UX shared libraries.
8130 @end ifset
8131 @value{GDBN} automatically loads symbol definitions from shared libraries
8132 when you use the @code{run} command, or when you examine a core file.
8133 (Before you issue the @code{run} command, @value{GDBN} does not understand
8134 references to a function in a shared library, however---unless you are
8135 debugging a core file).
8136 @ifset HPPA
8137 If the program loads a library explicitly, @value{GDBN} automatically
8138 loads the symbols at the time of the @code{shl_load} call.
8139 @end ifset
8140 @c FIXME: some @value{GDBN} release may permit some refs to undef
8141 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8142 @c FIXME...lib; check this from time to time when updating manual
8143
8144 @table @code
8145 @kindex info sharedlibrary
8146 @kindex info share
8147 @item info share
8148 @itemx info sharedlibrary
8149 Print the names of the shared libraries which are currently loaded.
8150
8151 @kindex sharedlibrary
8152 @kindex share
8153 @item sharedlibrary @var{regex}
8154 @itemx share @var{regex}
8155
8156 Load shared object library symbols for files matching a
8157 Unix regular expression.
8158 As with files loaded automatically, it only loads shared libraries
8159 required by your program for a core file or after typing @code{run}. If
8160 @var{regex} is omitted all shared libraries required by your program are
8161 loaded.
8162 @end table
8163
8164 @ifset HPPA
8165 @value{GDBN} detects the loading of a shared library and automatically
8166 reads in symbols from the newly loaded library, up to a threshold that
8167 is initially set but that you can modify if you wish.
8168
8169 Beyond that threshold, symbols from shared libraries must be explicitly
8170 loaded. To load these symbols, use the command @code{sharedlibrary}
8171 @var{filename}. The base address of the shared library is determined
8172 automatically by @value{GDBN} and need not be specified.
8173
8174 To display or set the threshold, use the commands:
8175
8176 @table @code
8177 @kindex set auto-solib-add
8178 @item set auto-solib-add @var{threshold}
8179 Set the autoloading size threshold, in megabytes. If @var{threshold} is
8180 nonzero, symbols from all shared object libraries will be loaded
8181 automatically when the inferior begins execution or when the dynamic
8182 linker informs @value{GDBN} that a new library has been loaded, until
8183 the symbol table of the program and libraries exceeds this threshold.
8184 Otherwise, symbols must be loaded manually, using the
8185 @code{sharedlibrary} command. The default threshold is 100 megabytes.
8186
8187 @kindex show auto-solib-add
8188 @item show auto-solib-add
8189 Display the current autoloading size threshold, in megabytes.
8190 @end table
8191 @end ifset
8192
8193 @node Symbol Errors, , Files, GDB Files
8194 @section Errors reading symbol files
8195
8196 While reading a symbol file, @value{GDBN} occasionally encounters problems,
8197 such as symbol types it does not recognize, or known bugs in compiler
8198 output. By default, @value{GDBN} does not notify you of such problems, since
8199 they are relatively common and primarily of interest to people
8200 debugging compilers. If you are interested in seeing information
8201 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8202 only one message about each such type of problem, no matter how many
8203 times the problem occurs; or you can ask @value{GDBN} to print more messages,
8204 to see how many times the problems occur, with the @code{set
8205 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8206 messages}).
8207
8208 The messages currently printed, and their meanings, include:
8209
8210 @table @code
8211 @item inner block not inside outer block in @var{symbol}
8212
8213 The symbol information shows where symbol scopes begin and end
8214 (such as at the start of a function or a block of statements). This
8215 error indicates that an inner scope block is not fully contained
8216 in its outer scope blocks.
8217
8218 @value{GDBN} circumvents the problem by treating the inner block as if it had
8219 the same scope as the outer block. In the error message, @var{symbol}
8220 may be shown as ``@code{(don't know)}'' if the outer block is not a
8221 function.
8222
8223 @item block at @var{address} out of order
8224
8225 The symbol information for symbol scope blocks should occur in
8226 order of increasing addresses. This error indicates that it does not
8227 do so.
8228
8229 @value{GDBN} does not circumvent this problem, and has trouble
8230 locating symbols in the source file whose symbols it is reading. (You
8231 can often determine what source file is affected by specifying
8232 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8233 messages}.)
8234
8235 @item bad block start address patched
8236
8237 The symbol information for a symbol scope block has a start address
8238 smaller than the address of the preceding source line. This is known
8239 to occur in the SunOS 4.1.1 (and earlier) C compiler.
8240
8241 @value{GDBN} circumvents the problem by treating the symbol scope block as
8242 starting on the previous source line.
8243
8244 @item bad string table offset in symbol @var{n}
8245
8246 @cindex foo
8247 Symbol number @var{n} contains a pointer into the string table which is
8248 larger than the size of the string table.
8249
8250 @value{GDBN} circumvents the problem by considering the symbol to have the
8251 name @code{foo}, which may cause other problems if many symbols end up
8252 with this name.
8253
8254 @item unknown symbol type @code{0x@var{nn}}
8255
8256 The symbol information contains new data types that @value{GDBN} does
8257 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
8258 misunderstood information, in hexadecimal.
8259
8260 @value{GDBN} circumvents the error by ignoring this symbol information.
8261 This usually allows you to debug your program, though certain symbols
8262 are not accessible. If you encounter such a problem and feel like
8263 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8264 on @code{complain}, then go up to the function @code{read_dbx_symtab}
8265 and examine @code{*bufp} to see the symbol.
8266
8267 @item stub type has NULL name
8268
8269 @value{GDBN} could not find the full definition for a struct or class.
8270
8271 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
8272 The symbol information for a C++ member function is missing some
8273 information that recent versions of the compiler should have output for
8274 it.
8275
8276 @item info mismatch between compiler and debugger
8277
8278 @value{GDBN} could not parse a type specification output by the compiler.
8279
8280 @end table
8281
8282 @node Targets, Controlling GDB, GDB Files, Top
8283 @chapter Specifying a Debugging Target
8284
8285 @cindex debugging target
8286 @kindex target
8287
8288 A @dfn{target} is the execution environment occupied by your program.
8289 @ifclear HPPA
8290 Often, @value{GDBN} runs in the same host environment as your program; in
8291 that case, the debugging target is specified as a side effect when you
8292 use the @code{file} or @code{core} commands. When you need more
8293 flexibility---for example, running @value{GDBN} on a physically separate
8294 host, or controlling a standalone system over a serial port or a
8295 realtime system over a TCP/IP connection---you
8296 @end ifclear
8297 @ifset HPPA
8298 On HP-UX systems, @value{GDBN} has been configured to support debugging
8299 of processes running on the PA-RISC architecture. This means that the
8300 only possible targets are:
8301
8302 @itemize @bullet
8303 @item
8304 An executable that has been compiled and linked to run on HP-UX
8305
8306 @item
8307 A live HP-UX process, either started by @value{GDBN} (with the
8308 @code{run} command) or started outside of @value{GDBN} and attached to
8309 (with the @code{attach} command)
8310
8311 @item
8312 A core file generated by an HP-UX process that previously aborted
8313 execution
8314 @end itemize
8315
8316 @value{GDBN} on HP-UX has not been configured to support remote
8317 debugging, or to support programs running on other platforms. You
8318 can use the @code{target} command to specify one of the target types
8319 configured for @value{GDBN} (@pxref{Target Commands, ,Commands for managing
8320 targets}).
8321 @end ifset
8322
8323 @menu
8324 * Active Targets:: Active targets
8325 * Target Commands:: Commands for managing targets
8326 * Byte Order:: Choosing target byte order
8327 * Remote:: Remote debugging
8328
8329 @end menu
8330
8331 @node Active Targets, Target Commands, Targets, Targets
8332 @section Active targets
8333
8334 @cindex stacking targets
8335 @cindex active targets
8336 @cindex multiple targets
8337
8338 There are three classes of targets: processes, core files, and
8339 executable files. @value{GDBN} can work concurrently on up to three
8340 active targets, one in each class. This allows you to (for example)
8341 start a process and inspect its activity without abandoning your work on
8342 a core file.
8343
8344 For example, if you execute @samp{gdb a.out}, then the executable file
8345 @code{a.out} is the only active target. If you designate a core file as
8346 well---presumably from a prior run that crashed and coredumped---then
8347 @value{GDBN} has two active targets and uses them in tandem, looking
8348 first in the corefile target, then in the executable file, to satisfy
8349 requests for memory addresses. (Typically, these two classes of target
8350 are complementary, since core files contain only a program's
8351 read-write memory---variables and so on---plus machine status, while
8352 executable files contain only the program text and initialized data.)
8353
8354 When you type @code{run}, your executable file becomes an active process
8355 target as well. When a process target is active, all @value{GDBN}
8356 commands requesting memory addresses refer to that target; addresses in
8357 an active core file or executable file target are obscured while the
8358 process target is active.
8359
8360 Use the @code{core-file} and @code{exec-file} commands to select a new
8361 core file or executable target (@pxref{Files, ,Commands to specify
8362 files}). To specify as a target a process that is already running, use
8363 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8364 process}).
8365
8366 @node Target Commands, Byte Order, Active Targets, Targets
8367 @section Commands for managing targets
8368
8369 @table @code
8370 @item target @var{type} @var{parameters}
8371 Connects the @value{GDBN} host environment to a target machine or
8372 process. A target is typically a protocol for talking to debugging
8373 facilities. You use the argument @var{type} to specify the type or
8374 protocol of the target machine.
8375
8376 Further @var{parameters} are interpreted by the target protocol, but
8377 typically include things like device names or host names to connect
8378 with, process numbers, and baud rates.
8379
8380 The @code{target} command does not repeat if you press @key{RET} again
8381 after executing the command.
8382
8383 @kindex help target
8384 @item help target
8385 Displays the names of all targets available. To display targets
8386 currently selected, use either @code{info target} or @code{info files}
8387 (@pxref{Files, ,Commands to specify files}).
8388
8389 @item help target @var{name}
8390 Describe a particular target, including any parameters necessary to
8391 select it.
8392
8393 @kindex set gnutarget
8394 @item set gnutarget @var{args}
8395 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8396 knows whether it is reading an @dfn{executable},
8397 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8398 with the @code{set gnutarget} command. Unlike most @code{target} commands,
8399 with @code{gnutarget} the @code{target} refers to a program, not a machine.
8400
8401 @emph{Warning:} To specify a file format with @code{set gnutarget},
8402 you must know the actual BFD name.
8403
8404 @noindent @xref{Files, , Commands to specify files}.
8405
8406 @kindex show gnutarget
8407 @item show gnutarget
8408 Use the @code{show gnutarget} command to display what file format
8409 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
8410 @value{GDBN} will determine the file format for each file automatically,
8411 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8412 @end table
8413
8414 @ifclear HPPA
8415 Here are some common targets (available, or not, depending on the GDB
8416 configuration):
8417 @end ifclear
8418 @ifset HPPA
8419 These are the valid targets on HP-UX systems:
8420 @end ifset
8421
8422 @table @code
8423 @kindex target exec
8424 @item target exec @var{program}
8425 An executable file. @samp{target exec @var{program}} is the same as
8426 @samp{exec-file @var{program}}.
8427
8428 @kindex target core
8429 @item target core @var{filename}
8430 A core dump file. @samp{target core @var{filename}} is the same as
8431 @samp{core-file @var{filename}}.
8432
8433 @kindex target remote
8434 @item target remote @var{dev}
8435 Remote serial target in GDB-specific protocol. The argument @var{dev}
8436 specifies what serial device to use for the connection (e.g.
8437 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
8438 now supports the @code{load} command. This is only useful if you have
8439 some other way of getting the stub to the target system, and you can put
8440 it somewhere in memory where it won't get clobbered by the download.
8441
8442 @ifclear HPPA
8443 @kindex target sim
8444 @item target sim
8445 CPU simulator. @xref{Simulator,,Simulated CPU Target}.
8446 @end ifclear
8447 @end table
8448
8449 The following targets are all CPU-specific, and only available for
8450 specific configurations.
8451 @c should organize by CPU
8452
8453 @table @code
8454
8455 @kindex target abug
8456 @item target abug @var{dev}
8457 ABug ROM monitor for M68K.
8458
8459 @kindex target adapt
8460 @item target adapt @var{dev}
8461 Adapt monitor for A29K.
8462
8463 @kindex target amd-eb
8464 @item target amd-eb @var{dev} @var{speed} @var{PROG}
8465 @cindex AMD EB29K
8466 Remote PC-resident AMD EB29K board, attached over serial lines.
8467 @var{dev} is the serial device, as for @code{target remote};
8468 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
8469 name of the program to be debugged, as it appears to DOS on the PC.
8470 @xref{EB29K Remote, ,The EBMON protocol for AMD29K}.
8471
8472 @kindex target array
8473 @item target array @var{dev}
8474 Array Tech LSI33K RAID controller board.
8475
8476 @kindex target bug
8477 @item target bug @var{dev}
8478 BUG monitor, running on a MVME187 (m88k) board.
8479
8480 @kindex target cpu32bug
8481 @item target cpu32bug @var{dev}
8482 CPU32BUG monitor, running on a CPU32 (M68K) board.
8483
8484 @kindex target dbug
8485 @item target dbug @var{dev}
8486 dBUG ROM monitor for Motorola ColdFire.
8487
8488 @kindex target ddb
8489 @item target ddb @var{dev}
8490 NEC's DDB monitor for Mips Vr4300.
8491
8492 @kindex target dink32
8493 @item target dink32 @var{dev}
8494 DINK32 ROM monitor for PowerPC.
8495
8496 @kindex target e7000
8497 @item target e7000 @var{dev}
8498 E7000 emulator for Hitachi H8 and SH.
8499
8500 @kindex target es1800
8501 @item target es1800 @var{dev}
8502 ES-1800 emulator for M68K.
8503
8504 @kindex target est
8505 @item target est @var{dev}
8506 EST-300 ICE monitor, running on a CPU32 (M68K) board.
8507
8508 @kindex target hms
8509 @item target hms @var{dev}
8510 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
8511 Use special commands @code{device} and @code{speed} to control the serial
8512 line and the communications speed used.
8513 @xref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}.
8514
8515 @kindex target lsi
8516 @item target lsi @var{dev}
8517 LSI ROM monitor for Mips.
8518
8519 @kindex target m32r
8520 @item target m32r @var{dev}
8521 Mitsubishi M32R/D ROM monitor.
8522
8523 @kindex target mips
8524 @item target mips @var{dev}
8525 IDT/SIM ROM monitor for Mips.
8526
8527 @kindex target mon960
8528 @item target mon960 @var{dev}
8529 MON960 monitor for Intel i960.
8530
8531 @kindex target nindy
8532 @item target nindy @var{devicename}
8533 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
8534 the name of the serial device to use for the connection, e.g.
8535 @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}.
8536
8537 @kindex target nrom
8538 @item target nrom @var{dev}
8539 NetROM ROM emulator. This target only supports downloading.
8540
8541 @kindex target op50n
8542 @item target op50n @var{dev}
8543 OP50N monitor, running on an OKI HPPA board.
8544
8545 @kindex target pmon
8546 @item target pmon @var{dev}
8547 PMON ROM monitor for Mips.
8548
8549 @kindex target ppcbug
8550 @item target ppcbug @var{dev}
8551 @kindex target ppcbug1
8552 @item target ppcbug1 @var{dev}
8553 PPCBUG ROM monitor for PowerPC.
8554
8555 @kindex target r3900
8556 @item target r3900 @var{dev}
8557 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
8558
8559 @kindex target rdi
8560 @item target rdi @var{dev}
8561 ARM Angel monitor, via RDI library interface.
8562
8563 @kindex target rdp
8564 @item target rdp @var{dev}
8565 ARM Demon monitor.
8566
8567 @kindex target rom68k
8568 @item target rom68k @var{dev}
8569 ROM 68K monitor, running on an M68K IDP board.
8570
8571 @kindex target rombug
8572 @item target rombug @var{dev}
8573 ROMBUG ROM monitor for OS/9000.
8574
8575 @kindex target sds
8576 @item target sds @var{dev}
8577 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
8578
8579 @kindex target sparclite
8580 @item target sparclite @var{dev}
8581 Fujitsu sparclite boards, used only for the purpose of loading.
8582 You must use an additional command to debug the program.
8583 For example: target remote @var{dev} using @value{GDBN} standard
8584 remote protocol.
8585
8586 @kindex target sh3
8587 @kindex target sh3e
8588 @item target sh3 @var{dev}
8589 @item target sh3e @var{dev}
8590 Hitachi SH-3 and SH-3E target systems.
8591
8592 @kindex target st2000
8593 @item target st2000 @var{dev} @var{speed}
8594 A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev}
8595 is the name of the device attached to the ST2000 serial line;
8596 @var{speed} is the communication line speed. The arguments are not used
8597 if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet.
8598 @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}.
8599
8600 @kindex target udi
8601 @item target udi @var{keyword}
8602 Remote AMD29K target, using the AMD UDI protocol. The @var{keyword}
8603 argument specifies which 29K board or simulator to use. @xref{UDI29K
8604 Remote,,The UDI protocol for AMD29K}.
8605
8606 @kindex target vxworks
8607 @item target vxworks @var{machinename}
8608 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
8609 is the target system's machine name or IP address.
8610 @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}.
8611
8612 @kindex target w89k
8613 @item target w89k @var{dev}
8614 W89K monitor, running on a Winbond HPPA board.
8615
8616 @end table
8617
8618 Different targets are available on different configurations of @value{GDBN};
8619 your configuration may have more or fewer targets.
8620
8621 Many remote targets require you to download the executable's code
8622 once you've successfully established a connection.
8623
8624 @table @code
8625
8626 @kindex load @var{filename}
8627 @item load @var{filename}
8628 Depending on what remote debugging facilities are configured into
8629 @value{GDBN}, the @code{load} command may be available. Where it exists, it
8630 is meant to make @var{filename} (an executable) available for debugging
8631 on the remote system---by downloading, or dynamic linking, for example.
8632 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8633 the @code{add-symbol-file} command.
8634
8635 If your @value{GDBN} does not have a @code{load} command, attempting to
8636 execute it gets the error message ``@code{You can't do that when your
8637 target is @dots{}}''
8638
8639 The file is loaded at whatever address is specified in the executable.
8640 For some object file formats, you can specify the load address when you
8641 link the program; for other formats, like a.out, the object file format
8642 specifies a fixed address.
8643 @c FIXME! This would be a good place for an xref to the GNU linker doc.
8644
8645 On VxWorks, @code{load} links @var{filename} dynamically on the
8646 current target system as well as adding its symbols in @value{GDBN}.
8647
8648 @cindex download to Nindy-960
8649 With the Nindy interface to an Intel 960 board, @code{load}
8650 downloads @var{filename} to the 960 as well as adding its symbols in
8651 @value{GDBN}.
8652
8653 @cindex download to H8/300 or H8/500
8654 @cindex H8/300 or H8/500 download
8655 @cindex download to Hitachi SH
8656 @cindex Hitachi SH download
8657 When you select remote debugging to a Hitachi SH, H8/300, or H8/500 board
8658 (@pxref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}),
8659 the @code{load} command downloads your program to the Hitachi board and also
8660 opens it as the current executable target for @value{GDBN} on your host
8661 (like the @code{file} command).
8662
8663 @code{load} does not repeat if you press @key{RET} again after using it.
8664 @end table
8665
8666 @node Byte Order, Remote, Target Commands, Targets
8667 @section Choosing target byte order
8668
8669 @cindex choosing target byte order
8670 @cindex target byte order
8671 @kindex set endian big
8672 @kindex set endian little
8673 @kindex set endian auto
8674 @kindex show endian
8675
8676 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8677 offer the ability to run either big-endian or little-endian byte
8678 orders. Usually the executable or symbol will include a bit to
8679 designate the endian-ness, and you will not need to worry about
8680 which to use. However, you may still find it useful to adjust
8681 GDB's idea of processor endian-ness manually.
8682
8683 @table @code
8684 @kindex set endian big
8685 @item set endian big
8686 Instruct @value{GDBN} to assume the target is big-endian.
8687
8688 @kindex set endian little
8689 @item set endian little
8690 Instruct @value{GDBN} to assume the target is little-endian.
8691
8692 @kindex set endian auto
8693 @item set endian auto
8694 Instruct @value{GDBN} to use the byte order associated with the
8695 executable.
8696
8697 @item show endian
8698 Display @value{GDBN}'s current idea of the target byte order.
8699
8700 @end table
8701
8702 Note that these commands merely adjust interpretation of symbolic
8703 data on the host, and that they have absolutely no effect on the
8704 target system.
8705
8706 @node Remote, , Byte Order, Targets
8707 @section Remote debugging
8708 @cindex remote debugging
8709
8710 If you are trying to debug a program running on a machine that cannot run
8711 @value{GDBN} in the usual way, it is often useful to use remote debugging.
8712 For example, you might use remote debugging on an operating system kernel,
8713 or on a small system which does not have a general purpose operating system
8714 powerful enough to run a full-featured debugger.
8715
8716 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8717 to make this work with particular debugging targets. In addition,
8718 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8719 but not specific to any particular target system) which you can use if you
8720 write the remote stubs---the code that runs on the remote system to
8721 communicate with @value{GDBN}.
8722
8723 Other remote targets may be available in your
8724 configuration of @value{GDBN}; use @code{help target} to list them.
8725
8726 @c Text on starting up GDB in various specific cases; it goes up front
8727 @c in manuals configured for any of those particular situations, here
8728 @c otherwise.
8729 @menu
8730 * Remote Serial:: @value{GDBN} remote serial protocol
8731 * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy)
8732 * UDI29K Remote:: The UDI protocol for AMD29K
8733 * EB29K Remote:: The EBMON protocol for AMD29K
8734 * VxWorks Remote:: @value{GDBN} and VxWorks
8735 * ST2000 Remote:: @value{GDBN} with a Tandem ST2000
8736 * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors
8737 * MIPS Remote:: @value{GDBN} and MIPS boards
8738 * Sparclet Remote:: @value{GDBN} and Sparclet boards
8739 * Simulator:: Simulated CPU target
8740 @end menu
8741
8742 @include remote.texi
8743
8744
8745 @node Controlling GDB
8746 @chapter Controlling @value{GDBN}
8747
8748 You can alter the way @value{GDBN} interacts with you by using
8749 the @code{set} command. For commands controlling how @value{GDBN} displays
8750 data, @pxref{Print Settings, ,Print settings}; other settings are described
8751 here.
8752
8753 @menu
8754 * Prompt:: Prompt
8755 * Editing:: Command editing
8756 * History:: Command history
8757 * Screen Size:: Screen size
8758 * Numbers:: Numbers
8759 * Messages/Warnings:: Optional warnings and messages
8760 @end menu
8761
8762 @node Prompt, Editing, Controlling GDB, Controlling GDB
8763 @section Prompt
8764
8765 @cindex prompt
8766
8767 @value{GDBN} indicates its readiness to read a command by printing a string
8768 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
8769 can change the prompt string with the @code{set prompt} command. For
8770 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
8771 the prompt in one of the @value{GDBN} sessions so that you can always tell
8772 which one you are talking to.
8773
8774 @emph{Note:} @code{set prompt} no longer adds a space for you after the
8775 prompt you set. This allows you to set a prompt which ends in a space
8776 or a prompt that does not.
8777
8778 @table @code
8779 @kindex set prompt
8780 @item set prompt @var{newprompt}
8781 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
8782
8783 @kindex show prompt
8784 @item show prompt
8785 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
8786 @end table
8787
8788 @node Editing, History, Prompt, Controlling GDB
8789 @section Command editing
8790 @cindex readline
8791 @cindex command line editing
8792
8793 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
8794 @sc{gnu} library provides consistent behavior for programs which provide a
8795 command line interface to the user. Advantages are @sc{gnu} Emacs-style
8796 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
8797 substitution, and a storage and recall of command history across
8798 debugging sessions.
8799
8800 You may control the behavior of command line editing in @value{GDBN} with the
8801 command @code{set}.
8802
8803 @table @code
8804 @kindex set editing
8805 @cindex editing
8806 @item set editing
8807 @itemx set editing on
8808 Enable command line editing (enabled by default).
8809
8810 @item set editing off
8811 Disable command line editing.
8812
8813 @kindex show editing
8814 @item show editing
8815 Show whether command line editing is enabled.
8816 @end table
8817
8818 @node History, Screen Size, Editing, Controlling GDB
8819 @section Command history
8820
8821 @value{GDBN} can keep track of the commands you type during your
8822 debugging sessions, so that you can be certain of precisely what
8823 happened. Use these commands to manage the @value{GDBN} command
8824 history facility.
8825
8826 @table @code
8827 @cindex history substitution
8828 @cindex history file
8829 @kindex set history filename
8830 @kindex GDBHISTFILE
8831 @item set history filename @var{fname}
8832 Set the name of the @value{GDBN} command history file to @var{fname}.
8833 This is the file where @value{GDBN} reads an initial command history
8834 list, and where it writes the command history from this session when it
8835 exits. You can access this list through history expansion or through
8836 the history command editing characters listed below. This file defaults
8837 to the value of the environment variable @code{GDBHISTFILE}, or to
8838 @file{./.gdb_history} if this variable is not set.
8839
8840 @cindex history save
8841 @kindex set history save
8842 @item set history save
8843 @itemx set history save on
8844 Record command history in a file, whose name may be specified with the
8845 @code{set history filename} command. By default, this option is disabled.
8846
8847 @item set history save off
8848 Stop recording command history in a file.
8849
8850 @cindex history size
8851 @kindex set history size
8852 @item set history size @var{size}
8853 Set the number of commands which @value{GDBN} keeps in its history list.
8854 This defaults to the value of the environment variable
8855 @code{HISTSIZE}, or to 256 if this variable is not set.
8856 @end table
8857
8858 @cindex history expansion
8859 History expansion assigns special meaning to the character @kbd{!}.
8860 @ifset have-readline-appendices
8861 @xref{Event Designators}.
8862 @end ifset
8863
8864 Since @kbd{!} is also the logical not operator in C, history expansion
8865 is off by default. If you decide to enable history expansion with the
8866 @code{set history expansion on} command, you may sometimes need to
8867 follow @kbd{!} (when it is used as logical not, in an expression) with
8868 a space or a tab to prevent it from being expanded. The readline
8869 history facilities do not attempt substitution on the strings
8870 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
8871
8872 The commands to control history expansion are:
8873
8874 @table @code
8875 @kindex set history expansion
8876 @item set history expansion on
8877 @itemx set history expansion
8878 Enable history expansion. History expansion is off by default.
8879
8880 @item set history expansion off
8881 Disable history expansion.
8882
8883 The readline code comes with more complete documentation of
8884 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
8885 or @code{vi} may wish to read it.
8886 @ifset have-readline-appendices
8887 @xref{Command Line Editing}.
8888 @end ifset
8889
8890 @c @group
8891 @kindex show history
8892 @item show history
8893 @itemx show history filename
8894 @itemx show history save
8895 @itemx show history size
8896 @itemx show history expansion
8897 These commands display the state of the @value{GDBN} history parameters.
8898 @code{show history} by itself displays all four states.
8899 @c @end group
8900 @end table
8901
8902 @table @code
8903 @kindex show commands
8904 @item show commands
8905 Display the last ten commands in the command history.
8906
8907 @item show commands @var{n}
8908 Print ten commands centered on command number @var{n}.
8909
8910 @item show commands +
8911 Print ten commands just after the commands last printed.
8912 @end table
8913
8914 @node Screen Size, Numbers, History, Controlling GDB
8915 @section Screen size
8916 @cindex size of screen
8917 @cindex pauses in output
8918
8919 Certain commands to @value{GDBN} may produce large amounts of
8920 information output to the screen. To help you read all of it,
8921 @value{GDBN} pauses and asks you for input at the end of each page of
8922 output. Type @key{RET} when you want to continue the output, or @kbd{q}
8923 to discard the remaining output. Also, the screen width setting
8924 determines when to wrap lines of output. Depending on what is being
8925 printed, @value{GDBN} tries to break the line at a readable place,
8926 rather than simply letting it overflow onto the following line.
8927
8928 Normally @value{GDBN} knows the size of the screen from the termcap data base
8929 together with the value of the @code{TERM} environment variable and the
8930 @code{stty rows} and @code{stty cols} settings. If this is not correct,
8931 you can override it with the @code{set height} and @code{set
8932 width} commands:
8933
8934 @table @code
8935 @kindex set height
8936 @kindex set width
8937 @kindex show width
8938 @kindex show height
8939 @item set height @var{lpp}
8940 @itemx show height
8941 @itemx set width @var{cpl}
8942 @itemx show width
8943 These @code{set} commands specify a screen height of @var{lpp} lines and
8944 a screen width of @var{cpl} characters. The associated @code{show}
8945 commands display the current settings.
8946
8947 If you specify a height of zero lines, @value{GDBN} does not pause during
8948 output no matter how long the output is. This is useful if output is to a
8949 file or to an editor buffer.
8950
8951 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
8952 from wrapping its output.
8953 @end table
8954
8955 @node Numbers, Messages/Warnings, Screen Size, Controlling GDB
8956 @section Numbers
8957 @cindex number representation
8958 @cindex entering numbers
8959
8960 You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by
8961 the usual conventions: octal numbers begin with @samp{0}, decimal
8962 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
8963 Numbers that begin with none of these are, by default, entered in base
8964 10; likewise, the default display for numbers---when no particular
8965 format is specified---is base 10. You can change the default base for
8966 both input and output with the @code{set radix} command.
8967
8968 @table @code
8969 @kindex set input-radix
8970 @item set input-radix @var{base}
8971 Set the default base for numeric input. Supported choices
8972 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
8973 specified either unambiguously or using the current default radix; for
8974 example, any of
8975
8976 @smallexample
8977 set radix 012
8978 set radix 10.
8979 set radix 0xa
8980 @end smallexample
8981
8982 @noindent
8983 sets the base to decimal. On the other hand, @samp{set radix 10}
8984 leaves the radix unchanged no matter what it was.
8985
8986 @kindex set output-radix
8987 @item set output-radix @var{base}
8988 Set the default base for numeric display. Supported choices
8989 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
8990 specified either unambiguously or using the current default radix.
8991
8992 @kindex show input-radix
8993 @item show input-radix
8994 Display the current default base for numeric input.
8995
8996 @kindex show output-radix
8997 @item show output-radix
8998 Display the current default base for numeric display.
8999 @end table
9000
9001 @node Messages/Warnings, , Numbers, Controlling GDB
9002 @section Optional warnings and messages
9003
9004 By default, @value{GDBN} is silent about its inner workings. If you are running
9005 on a slow machine, you may want to use the @code{set verbose} command.
9006 This makes @value{GDBN} tell you when it does a lengthy internal operation, so
9007 you will not think it has crashed.
9008
9009 Currently, the messages controlled by @code{set verbose} are those
9010 which announce that the symbol table for a source file is being read;
9011 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
9012
9013 @table @code
9014 @kindex set verbose
9015 @item set verbose on
9016 Enables @value{GDBN} output of certain informational messages.
9017
9018 @item set verbose off
9019 Disables @value{GDBN} output of certain informational messages.
9020
9021 @kindex show verbose
9022 @item show verbose
9023 Displays whether @code{set verbose} is on or off.
9024 @end table
9025
9026 By default, if @value{GDBN} encounters bugs in the symbol table of an object
9027 file, it is silent; but if you are debugging a compiler, you may find
9028 this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}).
9029
9030 @table @code
9031 @kindex set complaints
9032 @item set complaints @var{limit}
9033 Permits @value{GDBN} to output @var{limit} complaints about each type of unusual
9034 symbols before becoming silent about the problem. Set @var{limit} to
9035 zero to suppress all complaints; set it to a large number to prevent
9036 complaints from being suppressed.
9037
9038 @kindex show complaints
9039 @item show complaints
9040 Displays how many symbol complaints @value{GDBN} is permitted to produce.
9041 @end table
9042
9043 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
9044 lot of stupid questions to confirm certain commands. For example, if
9045 you try to run a program which is already running:
9046
9047 @example
9048 (@value{GDBP}) run
9049 The program being debugged has been started already.
9050 Start it from the beginning? (y or n)
9051 @end example
9052
9053 If you are willing to unflinchingly face the consequences of your own
9054 commands, you can disable this ``feature'':
9055
9056 @table @code
9057 @kindex set confirm
9058 @cindex flinching
9059 @cindex confirmation
9060 @cindex stupid questions
9061 @item set confirm off
9062 Disables confirmation requests.
9063
9064 @item set confirm on
9065 Enables confirmation requests (the default).
9066
9067 @kindex show confirm
9068 @item show confirm
9069 Displays state of confirmation requests.
9070 @end table
9071
9072 @node Sequences, Emacs, Controlling GDB, Top
9073 @chapter Canned Sequences of Commands
9074
9075 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
9076 command lists}), @value{GDBN} provides two ways to store sequences of commands
9077 for execution as a unit: user-defined commands and command files.
9078
9079 @menu
9080 * Define:: User-defined commands
9081 * Hooks:: User-defined command hooks
9082 * Command Files:: Command files
9083 * Output:: Commands for controlled output
9084 @end menu
9085
9086 @node Define, Hooks, Sequences, Sequences
9087 @section User-defined commands
9088
9089 @cindex user-defined command
9090 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which
9091 you assign a new name as a command. This is done with the @code{define}
9092 command. User commands may accept up to 10 arguments separated by whitespace.
9093 Arguments are accessed within the user command via @var{$arg0@dots{}$arg9}.
9094 A trivial example:
9095
9096 @smallexample
9097 define adder
9098 print $arg0 + $arg1 + $arg2
9099 @end smallexample
9100
9101 @noindent To execute the command use:
9102
9103 @smallexample
9104 adder 1 2 3
9105 @end smallexample
9106
9107 @noindent This defines the command @code{adder}, which prints the sum of
9108 its three arguments. Note the arguments are text substitutions, so they may
9109 reference variables, use complex expressions, or even perform inferior
9110 functions calls.
9111
9112 @table @code
9113 @kindex define
9114 @item define @var{commandname}
9115 Define a command named @var{commandname}. If there is already a command
9116 by that name, you are asked to confirm that you want to redefine it.
9117
9118 The definition of the command is made up of other @value{GDBN} command lines,
9119 which are given following the @code{define} command. The end of these
9120 commands is marked by a line containing @code{end}.
9121
9122 @kindex if
9123 @kindex else
9124 @item if
9125 Takes a single argument, which is an expression to evaluate.
9126 It is followed by a series of commands that are executed
9127 only if the expression is true (nonzero).
9128 There can then optionally be a line @code{else}, followed
9129 by a series of commands that are only executed if the expression
9130 was false. The end of the list is marked by a line containing @code{end}.
9131
9132 @kindex while
9133 @item while
9134 The syntax is similar to @code{if}: the command takes a single argument,
9135 which is an expression to evaluate, and must be followed by the commands to
9136 execute, one per line, terminated by an @code{end}.
9137 The commands are executed repeatedly as long as the expression
9138 evaluates to true.
9139
9140 @kindex document
9141 @item document @var{commandname}
9142 Document the user-defined command @var{commandname}, so that it can be
9143 accessed by @code{help}. The command @var{commandname} must already be
9144 defined. This command reads lines of documentation just as @code{define}
9145 reads the lines of the command definition, ending with @code{end}.
9146 After the @code{document} command is finished, @code{help} on command
9147 @var{commandname} displays the documentation you have written.
9148
9149 You may use the @code{document} command again to change the
9150 documentation of a command. Redefining the command with @code{define}
9151 does not change the documentation.
9152
9153 @kindex help user-defined
9154 @item help user-defined
9155 List all user-defined commands, with the first line of the documentation
9156 (if any) for each.
9157
9158 @kindex show user
9159 @item show user
9160 @itemx show user @var{commandname}
9161 Display the @value{GDBN} commands used to define @var{commandname} (but not its
9162 documentation). If no @var{commandname} is given, display the
9163 definitions for all user-defined commands.
9164 @end table
9165
9166 When user-defined commands are executed, the
9167 commands of the definition are not printed. An error in any command
9168 stops execution of the user-defined command.
9169
9170 If used interactively, commands that would ask for confirmation proceed
9171 without asking when used inside a user-defined command. Many @value{GDBN}
9172 commands that normally print messages to say what they are doing omit the
9173 messages when used in a user-defined command.
9174
9175 @node Hooks, Command Files, Define, Sequences
9176 @section User-defined command hooks
9177 @cindex command files
9178
9179 You may define @emph{hooks}, which are a special kind of user-defined
9180 command. Whenever you run the command @samp{foo}, if the user-defined
9181 command @samp{hook-foo} exists, it is executed (with no arguments)
9182 before that command.
9183
9184 In addition, a pseudo-command, @samp{stop} exists. Defining
9185 (@samp{hook-stop}) makes the associated commands execute every time
9186 execution stops in your program: before breakpoint commands are run,
9187 displays are printed, or the stack frame is printed.
9188
9189 For example, to ignore @code{SIGALRM} signals while
9190 single-stepping, but treat them normally during normal execution,
9191 you could define:
9192
9193 @example
9194 define hook-stop
9195 handle SIGALRM nopass
9196 end
9197
9198 define hook-run
9199 handle SIGALRM pass
9200 end
9201
9202 define hook-continue
9203 handle SIGLARM pass
9204 end
9205 @end example
9206
9207 You can define a hook for any single-word command in @value{GDBN}, but
9208 not for command aliases; you should define a hook for the basic command
9209 name, e.g. @code{backtrace} rather than @code{bt}.
9210 @c FIXME! So how does Joe User discover whether a command is an alias
9211 @c or not?
9212 If an error occurs during the execution of your hook, execution of
9213 @value{GDBN} commands stops and @value{GDBN} issues a prompt
9214 (before the command that you actually typed had a chance to run).
9215
9216 If you try to define a hook which does not match any known command, you
9217 get a warning from the @code{define} command.
9218
9219 @node Command Files, Output, Hooks, Sequences
9220 @section Command files
9221
9222 @cindex command files
9223 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
9224 commands. Comments (lines starting with @kbd{#}) may also be included.
9225 An empty line in a command file does nothing; it does not mean to repeat
9226 the last command, as it would from the terminal.
9227
9228 @cindex init file
9229 @cindex @file{.gdbinit}
9230 When you start @value{GDBN}, it automatically executes commands from its
9231 @dfn{init files}. These are files named @file{.gdbinit} on Unix, or
9232 @file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
9233 any) in your home directory, then processes command line options and
9234 operands, and then reads the init file (if any) in the current working
9235 directory. This is so the init file in your home directory can set
9236 options (such as @code{set complaints}) which affect the processing of
9237 the command line options and operands. The init files are not executed
9238 if you use the @samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
9239
9240 @cindex init file name
9241 On some configurations of @value{GDBN}, the init file is known by a
9242 different name (these are typically environments where a specialized
9243 form of @value{GDBN} may need to coexist with other forms, hence a
9244 different name for the specialized version's init file). These are the
9245 environments with special init file names:
9246
9247 @kindex .vxgdbinit
9248 @itemize @bullet
9249 @item
9250 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
9251
9252 @kindex .os68gdbinit
9253 @item
9254 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
9255
9256 @kindex .esgdbinit
9257 @item
9258 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
9259 @end itemize
9260
9261 You can also request the execution of a command file with the
9262 @code{source} command:
9263
9264 @table @code
9265 @kindex source
9266 @item source @var{filename}
9267 Execute the command file @var{filename}.
9268 @end table
9269
9270 The lines in a command file are executed sequentially. They are not
9271 printed as they are executed. An error in any command terminates execution
9272 of the command file.
9273
9274 Commands that would ask for confirmation if used interactively proceed
9275 without asking when used in a command file. Many @value{GDBN} commands that
9276 normally print messages to say what they are doing omit the messages
9277 when called from command files.
9278
9279 @node Output, , Command Files, Sequences
9280 @section Commands for controlled output
9281
9282 During the execution of a command file or a user-defined command, normal
9283 @value{GDBN} output is suppressed; the only output that appears is what is
9284 explicitly printed by the commands in the definition. This section
9285 describes three commands useful for generating exactly the output you
9286 want.
9287
9288 @table @code
9289 @kindex echo
9290 @item echo @var{text}
9291 @c I do not consider backslash-space a standard C escape sequence
9292 @c because it is not in ANSI.
9293 Print @var{text}. Nonprinting characters can be included in
9294 @var{text} using C escape sequences, such as @samp{\n} to print a
9295 newline. @strong{No newline is printed unless you specify one.}
9296 In addition to the standard C escape sequences, a backslash followed
9297 by a space stands for a space. This is useful for displaying a
9298 string with spaces at the beginning or the end, since leading and
9299 trailing spaces are otherwise trimmed from all arguments.
9300 To print @samp{@w{ }and foo =@w{ }}, use the command
9301 @samp{echo \@w{ }and foo = \@w{ }}.
9302
9303 A backslash at the end of @var{text} can be used, as in C, to continue
9304 the command onto subsequent lines. For example,
9305
9306 @example
9307 echo This is some text\n\
9308 which is continued\n\
9309 onto several lines.\n
9310 @end example
9311
9312 produces the same output as
9313
9314 @example
9315 echo This is some text\n
9316 echo which is continued\n
9317 echo onto several lines.\n
9318 @end example
9319
9320 @kindex output
9321 @item output @var{expression}
9322 Print the value of @var{expression} and nothing but that value: no
9323 newlines, no @samp{$@var{nn} = }. The value is not entered in the
9324 value history either. @xref{Expressions, ,Expressions}, for more information
9325 on expressions.
9326
9327 @item output/@var{fmt} @var{expression}
9328 Print the value of @var{expression} in format @var{fmt}. You can use
9329 the same formats as for @code{print}. @xref{Output Formats,,Output
9330 formats}, for more information.
9331
9332 @kindex printf
9333 @item printf @var{string}, @var{expressions}@dots{}
9334 Print the values of the @var{expressions} under the control of
9335 @var{string}. The @var{expressions} are separated by commas and may be
9336 either numbers or pointers. Their values are printed as specified by
9337 @var{string}, exactly as if your program were to execute the C
9338 subroutine
9339
9340 @example
9341 printf (@var{string}, @var{expressions}@dots{});
9342 @end example
9343
9344 For example, you can print two values in hex like this:
9345
9346 @smallexample
9347 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
9348 @end smallexample
9349
9350 The only backslash-escape sequences that you can use in the format
9351 string are the simple ones that consist of backslash followed by a
9352 letter.
9353 @end table
9354
9355 @node Emacs, GDB Bugs, Sequences, Top
9356 @chapter Using @value{GDBN} under @sc{gnu} Emacs
9357
9358 @cindex Emacs
9359 @cindex @sc{gnu} Emacs
9360 A special interface allows you to use @sc{gnu} Emacs to view (and
9361 edit) the source files for the program you are debugging with
9362 @value{GDBN}.
9363
9364 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
9365 executable file you want to debug as an argument. This command starts
9366 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
9367 created Emacs buffer.
9368 @ifset HPPA
9369 (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
9370 @end ifset
9371
9372 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
9373 things:
9374
9375 @itemize @bullet
9376 @item
9377 All ``terminal'' input and output goes through the Emacs buffer.
9378 @end itemize
9379
9380 This applies both to @value{GDBN} commands and their output, and to the input
9381 and output done by the program you are debugging.
9382
9383 This is useful because it means that you can copy the text of previous
9384 commands and input them again; you can even use parts of the output
9385 in this way.
9386
9387 All the facilities of Emacs' Shell mode are available for interacting
9388 with your program. In particular, you can send signals the usual
9389 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
9390 stop.
9391
9392 @itemize @bullet
9393 @item
9394 @value{GDBN} displays source code through Emacs.
9395 @end itemize
9396
9397 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
9398 source file for that frame and puts an arrow (@samp{=>}) at the
9399 left margin of the current line. Emacs uses a separate buffer for
9400 source display, and splits the screen to show both your @value{GDBN} session
9401 and the source.
9402
9403 Explicit @value{GDBN} @code{list} or search commands still produce output as
9404 usual, but you probably have no reason to use them from Emacs.
9405
9406 @quotation
9407 @emph{Warning:} If the directory where your program resides is not your
9408 current directory, it can be easy to confuse Emacs about the location of
9409 the source files, in which case the auxiliary display buffer does not
9410 appear to show your source. @value{GDBN} can find programs by searching your
9411 environment's @code{PATH} variable, so the @value{GDBN} input and output
9412 session proceeds normally; but Emacs does not get enough information
9413 back from @value{GDBN} to locate the source files in this situation. To
9414 avoid this problem, either start @value{GDBN} mode from the directory where
9415 your program resides, or specify an absolute file name when prompted for the
9416 @kbd{M-x gdb} argument.
9417
9418 A similar confusion can result if you use the @value{GDBN} @code{file} command to
9419 switch to debugging a program in some other location, from an existing
9420 @value{GDBN} buffer in Emacs.
9421 @end quotation
9422
9423 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
9424 you need to call @value{GDBN} by a different name (for example, if you keep
9425 several configurations around, with different names) you can set the
9426 Emacs variable @code{gdb-command-name}; for example,
9427
9428 @example
9429 (setq gdb-command-name "mygdb")
9430 @end example
9431
9432 @noindent
9433 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
9434 in your @file{.emacs} file) makes Emacs call the program named
9435 ``@code{mygdb}'' instead.
9436
9437 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
9438 addition to the standard Shell mode commands:
9439
9440 @table @kbd
9441 @item C-h m
9442 Describe the features of Emacs' @value{GDBN} Mode.
9443
9444 @item M-s
9445 Execute to another source line, like the @value{GDBN} @code{step} command; also
9446 update the display window to show the current file and location.
9447
9448 @item M-n
9449 Execute to next source line in this function, skipping all function
9450 calls, like the @value{GDBN} @code{next} command. Then update the display window
9451 to show the current file and location.
9452
9453 @item M-i
9454 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
9455 display window accordingly.
9456
9457 @item M-x gdb-nexti
9458 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
9459 display window accordingly.
9460
9461 @item C-c C-f
9462 Execute until exit from the selected stack frame, like the @value{GDBN}
9463 @code{finish} command.
9464
9465 @item M-c
9466 Continue execution of your program, like the @value{GDBN} @code{continue}
9467 command.
9468
9469 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
9470
9471 @item M-u
9472 Go up the number of frames indicated by the numeric argument
9473 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
9474 like the @value{GDBN} @code{up} command.
9475
9476 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
9477
9478 @item M-d
9479 Go down the number of frames indicated by the numeric argument, like the
9480 @value{GDBN} @code{down} command.
9481
9482 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
9483
9484 @item C-x &
9485 Read the number where the cursor is positioned, and insert it at the end
9486 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
9487 around an address that was displayed earlier, type @kbd{disassemble};
9488 then move the cursor to the address display, and pick up the
9489 argument for @code{disassemble} by typing @kbd{C-x &}.
9490
9491 You can customize this further by defining elements of the list
9492 @code{gdb-print-command}; once it is defined, you can format or
9493 otherwise process numbers picked up by @kbd{C-x &} before they are
9494 inserted. A numeric argument to @kbd{C-x &} indicates that you
9495 wish special formatting, and also acts as an index to pick an element of the
9496 list. If the list element is a string, the number to be inserted is
9497 formatted using the Emacs function @code{format}; otherwise the number
9498 is passed as an argument to the corresponding list element.
9499 @end table
9500
9501 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
9502 tells @value{GDBN} to set a breakpoint on the source line point is on.
9503
9504 If you accidentally delete the source-display buffer, an easy way to get
9505 it back is to type the command @code{f} in the @value{GDBN} buffer, to
9506 request a frame display; when you run under Emacs, this recreates
9507 the source buffer if necessary to show you the context of the current
9508 frame.
9509
9510 The source files displayed in Emacs are in ordinary Emacs buffers
9511 which are visiting the source files in the usual way. You can edit
9512 the files with these buffers if you wish; but keep in mind that @value{GDBN}
9513 communicates with Emacs in terms of line numbers. If you add or
9514 delete lines from the text, the line numbers that @value{GDBN} knows cease
9515 to correspond properly with the code.
9516
9517 @c The following dropped because Epoch is nonstandard. Reactivate
9518 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
9519 @ignore
9520 @kindex Emacs Epoch environment
9521 @kindex Epoch
9522 @kindex inspect
9523
9524 Version 18 of @sc{gnu} Emacs has a built-in window system
9525 called the @code{epoch}
9526 environment. Users of this environment can use a new command,
9527 @code{inspect} which performs identically to @code{print} except that
9528 each value is printed in its own window.
9529 @end ignore
9530
9531 @node GDB Bugs
9532 @c links whacked to pacify makeinfo
9533 @c , Command Line Editing, Emacs, Top
9534 @chapter Reporting Bugs in @value{GDBN}
9535 @cindex bugs in @value{GDBN}
9536 @cindex reporting bugs in @value{GDBN}
9537
9538 Your bug reports play an essential role in making @value{GDBN} reliable.
9539
9540 Reporting a bug may help you by bringing a solution to your problem, or it
9541 may not. But in any case the principal function of a bug report is to help
9542 the entire community by making the next version of @value{GDBN} work better. Bug
9543 reports are your contribution to the maintenance of @value{GDBN}.
9544
9545 In order for a bug report to serve its purpose, you must include the
9546 information that enables us to fix the bug.
9547
9548 @menu
9549 * Bug Criteria:: Have you found a bug?
9550 * Bug Reporting:: How to report bugs
9551 @end menu
9552
9553 @node Bug Criteria, Bug Reporting, GDB Bugs, GDB Bugs
9554 @section Have you found a bug?
9555 @cindex bug criteria
9556
9557 If you are not sure whether you have found a bug, here are some guidelines:
9558
9559 @itemize @bullet
9560 @cindex fatal signal
9561 @cindex debugger crash
9562 @cindex crash of debugger
9563 @item
9564 If the debugger gets a fatal signal, for any input whatever, that is a
9565 @value{GDBN} bug. Reliable debuggers never crash.
9566
9567 @cindex error on valid input
9568 @item
9569 If @value{GDBN} produces an error message for valid input, that is a
9570 bug. (Note that if you're cross debugging, the problem may also be
9571 somewhere in the connection to the target.)
9572
9573 @cindex invalid input
9574 @item
9575 If @value{GDBN} does not produce an error message for invalid input,
9576 that is a bug. However, you should note that your idea of
9577 ``invalid input'' might be our idea of ``an extension'' or ``support
9578 for traditional practice''.
9579
9580 @item
9581 If you are an experienced user of debugging tools, your suggestions
9582 for improvement of @value{GDBN} are welcome in any case.
9583 @end itemize
9584
9585 @node Bug Reporting, , Bug Criteria, GDB Bugs
9586 @section How to report bugs
9587 @cindex bug reports
9588 @cindex @value{GDBN} bugs, reporting
9589
9590 @ifclear HPPA
9591 A number of companies and individuals offer support for @sc{gnu} products.
9592 If you obtained @value{GDBN} from a support organization, we recommend you
9593 contact that organization first.
9594
9595 You can find contact information for many support companies and
9596 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9597 distribution.
9598 @c should add a web page ref...
9599
9600 In any event, we also recommend that you send bug reports for
9601 @value{GDBN} to this addresses:
9602
9603 @example
9604 bug-gdb@@prep.ai.mit.edu
9605 @end example
9606
9607 @strong{Do not send bug reports to @samp{info-gdb}, or to
9608 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
9609 not want to receive bug reports. Those that do have arranged to receive
9610 @samp{bug-gdb}.
9611
9612 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
9613 serves as a repeater. The mailing list and the newsgroup carry exactly
9614 the same messages. Often people think of posting bug reports to the
9615 newsgroup instead of mailing them. This appears to work, but it has one
9616 problem which can be crucial: a newsgroup posting often lacks a mail
9617 path back to the sender. Thus, if we need to ask for more information,
9618 we may be unable to reach you. For this reason, it is better to send
9619 bug reports to the mailing list.
9620
9621 As a last resort, send bug reports on paper to:
9622
9623 @example
9624 @sc{gnu} Debugger Bugs
9625 Free Software Foundation Inc.
9626 59 Temple Place - Suite 330
9627 Boston, MA 02111-1307
9628 USA
9629 @end example
9630 @end ifclear
9631
9632 @ifset HPPA
9633 If you obtained HP GDB as part of your HP ANSI C or HP ANSI C++ compiler
9634 kit, report problems to your HP Support Representative.
9635
9636 If you obtained HP GDB from the Hewlett-Packard Web site, report
9637 problems by electronic mail to @code{wdb-www@@ch.hp.com}.
9638 @end ifset
9639
9640 The fundamental principle of reporting bugs usefully is this:
9641 @strong{report all the facts}. If you are not sure whether to state a
9642 fact or leave it out, state it!
9643
9644 Often people omit facts because they think they know what causes the
9645 problem and assume that some details do not matter. Thus, you might
9646 assume that the name of the variable you use in an example does not matter.
9647 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
9648 stray memory reference which happens to fetch from the location where that
9649 name is stored in memory; perhaps, if the name were different, the contents
9650 of that location would fool the debugger into doing the right thing despite
9651 the bug. Play it safe and give a specific, complete example. That is the
9652 easiest thing for you to do, and the most helpful.
9653
9654 Keep in mind that the purpose of a bug report is to enable us to fix the
9655 bug. It may be that the bug has been reported previously, but neither
9656 you nor we can know that unless your bug report is complete and
9657 self-contained.
9658
9659 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9660 bell?'' Those bug reports are useless, and we urge everyone to
9661 @emph{refuse to respond to them} except to chide the sender to report
9662 bugs properly.
9663
9664 To enable us to fix the bug, you should include all these things:
9665
9666 @itemize @bullet
9667 @item
9668 The version of @value{GDBN}. @value{GDBN} announces it if you start
9669 with no arguments; you can also print it at any time using @code{show
9670 version}.
9671
9672 Without this, we will not know whether there is any point in looking for
9673 the bug in the current version of @value{GDBN}.
9674
9675 @item
9676 The type of machine you are using, and the operating system name and
9677 version number.
9678
9679 @ifclear HPPA
9680 @item
9681 What compiler (and its version) was used to compile @value{GDBN}---e.g.
9682 ``@value{GCC}--2.8.1''.
9683 @end ifclear
9684
9685 @item
9686 What compiler (and its version) was used to compile the program you are
9687 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
9688 C Compiler''. For GCC, you can say @code{gcc --version} to get this
9689 information; for other compilers, see the documentation for those
9690 compilers.
9691
9692 @item
9693 The command arguments you gave the compiler to compile your example and
9694 observe the bug. For example, did you use @samp{-O}? To guarantee
9695 you will not omit something important, list them all. A copy of the
9696 Makefile (or the output from make) is sufficient.
9697
9698 If we were to try to guess the arguments, we would probably guess wrong
9699 and then we might not encounter the bug.
9700
9701 @item
9702 A complete input script, and all necessary source files, that will
9703 reproduce the bug.
9704
9705 @item
9706 A description of what behavior you observe that you believe is
9707 incorrect. For example, ``It gets a fatal signal.''
9708
9709 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
9710 will certainly notice it. But if the bug is incorrect output, we might
9711 not notice unless it is glaringly wrong. You might as well not give us
9712 a chance to make a mistake.
9713
9714 Even if the problem you experience is a fatal signal, you should still
9715 say so explicitly. Suppose something strange is going on, such as, your
9716 copy of @value{GDBN} is out of synch, or you have encountered a bug in
9717 the C library on your system. (This has happened!) Your copy might
9718 crash and ours would not. If you told us to expect a crash, then when
9719 ours fails to crash, we would know that the bug was not happening for
9720 us. If you had not told us to expect a crash, then we would not be able
9721 to draw any conclusion from our observations.
9722
9723 @ifclear HPPA
9724 @item
9725 If you wish to suggest changes to the @value{GDBN} source, send us context
9726 diffs. If you even discuss something in the @value{GDBN} source, refer to
9727 it by context, not by line number.
9728
9729 The line numbers in our development sources will not match those in your
9730 sources. Your line numbers would convey no useful information to us.
9731 @end ifclear
9732 @end itemize
9733
9734 Here are some things that are not necessary:
9735
9736 @itemize @bullet
9737 @item
9738 A description of the envelope of the bug.
9739
9740 Often people who encounter a bug spend a lot of time investigating
9741 which changes to the input file will make the bug go away and which
9742 changes will not affect it.
9743
9744 This is often time consuming and not very useful, because the way we
9745 will find the bug is by running a single example under the debugger
9746 with breakpoints, not by pure deduction from a series of examples.
9747 We recommend that you save your time for something else.
9748
9749 Of course, if you can find a simpler example to report @emph{instead}
9750 of the original one, that is a convenience for us. Errors in the
9751 output will be easier to spot, running under the debugger will take
9752 less time, and so on.
9753
9754 However, simplification is not vital; if you do not want to do this,
9755 report the bug anyway and send us the entire test case you used.
9756
9757 @item
9758 A patch for the bug.
9759
9760 A patch for the bug does help us if it is a good one. But do not omit
9761 the necessary information, such as the test case, on the assumption that
9762 a patch is all we need. We might see problems with your patch and decide
9763 to fix the problem another way, or we might not understand it at all.
9764
9765 Sometimes with a program as complicated as @value{GDBN} it is very hard to
9766 construct an example that will make the program follow a certain path
9767 through the code. If you do not send us the example, we will not be able
9768 to construct one, so we will not be able to verify that the bug is fixed.
9769
9770 And if we cannot understand what bug you are trying to fix, or why your
9771 patch should be an improvement, we will not install it. A test case will
9772 help us to understand.
9773
9774 @item
9775 A guess about what the bug is or what it depends on.
9776
9777 Such guesses are usually wrong. Even we cannot guess right about such
9778 things without first using the debugger to find the facts.
9779 @end itemize
9780
9781 @c The readline documentation is distributed with the readline code
9782 @c and consists of the two following files:
9783 @c rluser.texinfo
9784 @c inc-hist.texi
9785 @c Use -I with makeinfo to point to the appropriate directory,
9786 @c environment var TEXINPUTS with TeX.
9787 @include rluser.texinfo
9788 @include inc-hist.texi
9789
9790
9791 @ifclear PRECONFIGURED
9792 @ifclear HPPA
9793 @node Formatting Documentation
9794 @c links whacked to pacify makeinfo
9795 @c , Installing GDB, Renamed Commands, Top
9796 @appendix Formatting Documentation
9797
9798 @cindex @value{GDBN} reference card
9799 @cindex reference card
9800 The @value{GDBN} 4 release includes an already-formatted reference card, ready
9801 for printing with PostScript or Ghostscript, in the @file{gdb}
9802 subdirectory of the main source directory@footnote{In
9803 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
9804 release.}. If you can use PostScript or Ghostscript with your printer,
9805 you can print the reference card immediately with @file{refcard.ps}.
9806
9807 The release also includes the source for the reference card. You
9808 can format it, using @TeX{}, by typing:
9809
9810 @example
9811 make refcard.dvi
9812 @end example
9813
9814 The @value{GDBN} reference card is designed to print in @dfn{landscape}
9815 mode on US ``letter'' size paper;
9816 that is, on a sheet 11 inches wide by 8.5 inches
9817 high. You will need to specify this form of printing as an option to
9818 your @sc{dvi} output program.
9819
9820 @cindex documentation
9821
9822 All the documentation for @value{GDBN} comes as part of the machine-readable
9823 distribution. The documentation is written in Texinfo format, which is
9824 a documentation system that uses a single source file to produce both
9825 on-line information and a printed manual. You can use one of the Info
9826 formatting commands to create the on-line version of the documentation
9827 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
9828
9829 @value{GDBN} includes an already formatted copy of the on-line Info
9830 version of this manual in the @file{gdb} subdirectory. The main Info
9831 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
9832 subordinate files matching @samp{gdb.info*} in the same directory. If
9833 necessary, you can print out these files, or read them with any editor;
9834 but they are easier to read using the @code{info} subsystem in @sc{gnu}
9835 Emacs or the standalone @code{info} program, available as part of the
9836 @sc{gnu} Texinfo distribution.
9837
9838 If you want to format these Info files yourself, you need one of the
9839 Info formatting programs, such as @code{texinfo-format-buffer} or
9840 @code{makeinfo}.
9841
9842 If you have @code{makeinfo} installed, and are in the top level
9843 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
9844 version @value{GDBVN}), you can make the Info file by typing:
9845
9846 @example
9847 cd gdb
9848 make gdb.info
9849 @end example
9850
9851 If you want to typeset and print copies of this manual, you need @TeX{},
9852 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
9853 Texinfo definitions file.
9854
9855 @TeX{} is a typesetting program; it does not print files directly, but
9856 produces output files called @sc{dvi} files. To print a typeset
9857 document, you need a program to print @sc{dvi} files. If your system
9858 has @TeX{} installed, chances are it has such a program. The precise
9859 command to use depends on your system; @kbd{lpr -d} is common; another
9860 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
9861 require a file name without any extension or a @samp{.dvi} extension.
9862
9863 @TeX{} also requires a macro definitions file called
9864 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
9865 written in Texinfo format. On its own, @TeX{} cannot either read or
9866 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
9867 and is located in the @file{gdb-@var{version-number}/texinfo}
9868 directory.
9869
9870 If you have @TeX{} and a @sc{dvi} printer program installed, you can
9871 typeset and print this manual. First switch to the the @file{gdb}
9872 subdirectory of the main source directory (for example, to
9873 @file{gdb-@value{GDBVN}/gdb}) and type:
9874
9875 @example
9876 make gdb.dvi
9877 @end example
9878
9879 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
9880 @end ifclear
9881
9882 @node Installing GDB, Index, Using History Interactively, Top
9883 @appendix Installing @value{GDBN}
9884 @cindex configuring @value{GDBN}
9885 @cindex installation
9886
9887 @ifset HPPA
9888 If you obtain @value{GDBN} (HP WDB 0.75) as part of your HP ANSI C or
9889 HP ANSI C++ Developer's Kit at HP-UX Release 11.0, you do not have to
9890 take any special action to build or install @value{GDBN}.
9891
9892 If you obtain @value{GDBN} (HP WDB 0.75) from an HP web site, you may
9893 download either a @code{swinstall}-able package or a source tree, or
9894 both.
9895
9896 Most customers will want to install the @value{GDBN} binary that is part
9897 of the @code{swinstall}-able package. To do so, use a command of the
9898 form
9899
9900 @smallexample
9901 /usr/sbin/swinstall -s @var{package-name} WDB
9902 @end smallexample
9903
9904 Alternatively, it is possible to build @value{GDBN} from the source
9905 distribution. Sophisticated customers who want to modify the debugger
9906 sources to tailor @value{GDBN} to their their needs may wish to do this.
9907 The source distribution consists of a @code{tar}'ed source tree rooted
9908 at @file{gdb-4.16/...}. The instructions that follow describe how to
9909 build a @file{gdb} executable from this source tree. HP believes that
9910 these instructions apply to the WDB source tree that it distributes.
9911 However, HP does not explicitly support building a @file{gdb} for any
9912 non-HP platform from the WDB source tree. It may work, but HP has not
9913 tested it for any platforms other than those described in the WDB 0.75
9914 Release Notes.
9915 @end ifset
9916
9917 @value{GDBN} comes with a @code{configure} script that automates the process
9918 of preparing @value{GDBN} for installation; you can then use @code{make} to
9919 build the @code{gdb} program.
9920 @iftex
9921 @c irrelevant in info file; it's as current as the code it lives with.
9922 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
9923 look at the @file{README} file in the sources; we may have improved the
9924 installation procedures since publishing this manual.}
9925 @end iftex
9926
9927 The @value{GDBN} distribution includes all the source code you need for
9928 @value{GDBN} in a single directory, whose name is usually composed by
9929 appending the version number to @samp{gdb}.
9930
9931 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
9932 @file{gdb-@value{GDBVN}} directory. That directory contains:
9933
9934 @table @code
9935 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
9936 script for configuring @value{GDBN} and all its supporting libraries
9937
9938 @item gdb-@value{GDBVN}/gdb
9939 the source specific to @value{GDBN} itself
9940
9941 @item gdb-@value{GDBVN}/bfd
9942 source for the Binary File Descriptor library
9943
9944 @item gdb-@value{GDBVN}/include
9945 @sc{gnu} include files
9946
9947 @item gdb-@value{GDBVN}/libiberty
9948 source for the @samp{-liberty} free software library
9949
9950 @item gdb-@value{GDBVN}/opcodes
9951 source for the library of opcode tables and disassemblers
9952
9953 @item gdb-@value{GDBVN}/readline
9954 source for the @sc{gnu} command-line interface
9955
9956 @item gdb-@value{GDBVN}/glob
9957 source for the @sc{gnu} filename pattern-matching subroutine
9958
9959 @item gdb-@value{GDBVN}/mmalloc
9960 source for the @sc{gnu} memory-mapped malloc package
9961 @end table
9962
9963 The simplest way to configure and build @value{GDBN} is to run @code{configure}
9964 from the @file{gdb-@var{version-number}} source directory, which in
9965 this example is the @file{gdb-@value{GDBVN}} directory.
9966
9967 First switch to the @file{gdb-@var{version-number}} source directory
9968 if you are not already in it; then run @code{configure}. Pass the
9969 identifier for the platform on which @value{GDBN} will run as an
9970 argument.
9971
9972 For example:
9973
9974 @example
9975 cd gdb-@value{GDBVN}
9976 ./configure @var{host}
9977 make
9978 @end example
9979
9980 @noindent
9981 where @var{host} is an identifier such as @samp{sun4} or
9982 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
9983 (You can often leave off @var{host}; @code{configure} tries to guess the
9984 correct value by examining your system.)
9985
9986 Running @samp{configure @var{host}} and then running @code{make} builds the
9987 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
9988 libraries, then @code{gdb} itself. The configured source files, and the
9989 binaries, are left in the corresponding source directories.
9990
9991 @need 750
9992 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
9993 system does not recognize this automatically when you run a different
9994 shell, you may need to run @code{sh} on it explicitly:
9995
9996 @example
9997 sh configure @var{host}
9998 @end example
9999
10000 If you run @code{configure} from a directory that contains source
10001 directories for multiple libraries or programs, such as the
10002 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
10003 creates configuration files for every directory level underneath (unless
10004 you tell it not to, with the @samp{--norecursion} option).
10005
10006 You can run the @code{configure} script from any of the
10007 subordinate directories in the @value{GDBN} distribution if you only want to
10008 configure that subdirectory, but be sure to specify a path to it.
10009
10010 For example, with version @value{GDBVN}, type the following to configure only
10011 the @code{bfd} subdirectory:
10012
10013 @example
10014 @group
10015 cd gdb-@value{GDBVN}/bfd
10016 ../configure @var{host}
10017 @end group
10018 @end example
10019
10020 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
10021 However, you should make sure that the shell on your path (named by
10022 the @samp{SHELL} environment variable) is publicly readable. Remember
10023 that @value{GDBN} uses the shell to start your program---some systems refuse to
10024 let @value{GDBN} debug child processes whose programs are not readable.
10025
10026 @menu
10027 * Separate Objdir:: Compiling @value{GDBN} in another directory
10028 * Config Names:: Specifying names for hosts and targets
10029 * Configure Options:: Summary of options for configure
10030 @end menu
10031
10032 @node Separate Objdir, Config Names, Installing GDB, Installing GDB
10033 @section Compiling @value{GDBN} in another directory
10034
10035 If you want to run @value{GDBN} versions for several host or target machines,
10036 you need a different @code{gdb} compiled for each combination of
10037 host and target. @code{configure} is designed to make this easy by
10038 allowing you to generate each configuration in a separate subdirectory,
10039 rather than in the source directory. If your @code{make} program
10040 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
10041 @code{make} in each of these directories builds the @code{gdb}
10042 program specified there.
10043
10044 To build @code{gdb} in a separate directory, run @code{configure}
10045 with the @samp{--srcdir} option to specify where to find the source.
10046 (You also need to specify a path to find @code{configure}
10047 itself from your working directory. If the path to @code{configure}
10048 would be the same as the argument to @samp{--srcdir}, you can leave out
10049 the @samp{--srcdir} option; it is assumed.)
10050
10051 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
10052 separate directory for a Sun 4 like this:
10053
10054 @example
10055 @group
10056 cd gdb-@value{GDBVN}
10057 mkdir ../gdb-sun4
10058 cd ../gdb-sun4
10059 ../gdb-@value{GDBVN}/configure sun4
10060 make
10061 @end group
10062 @end example
10063
10064 When @code{configure} builds a configuration using a remote source
10065 directory, it creates a tree for the binaries with the same structure
10066 (and using the same names) as the tree under the source directory. In
10067 the example, you'd find the Sun 4 library @file{libiberty.a} in the
10068 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
10069 @file{gdb-sun4/gdb}.
10070
10071 One popular reason to build several @value{GDBN} configurations in separate
10072 directories is to configure @value{GDBN} for cross-compiling (where
10073 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
10074 programs that run on another machine---the @dfn{target}).
10075 You specify a cross-debugging target by
10076 giving the @samp{--target=@var{target}} option to @code{configure}.
10077
10078 When you run @code{make} to build a program or library, you must run
10079 it in a configured directory---whatever directory you were in when you
10080 called @code{configure} (or one of its subdirectories).
10081
10082 The @code{Makefile} that @code{configure} generates in each source
10083 directory also runs recursively. If you type @code{make} in a source
10084 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
10085 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
10086 will build all the required libraries, and then build GDB.
10087
10088 When you have multiple hosts or targets configured in separate
10089 directories, you can run @code{make} on them in parallel (for example,
10090 if they are NFS-mounted on each of the hosts); they will not interfere
10091 with each other.
10092
10093 @node Config Names, Configure Options, Separate Objdir, Installing GDB
10094 @section Specifying names for hosts and targets
10095
10096 The specifications used for hosts and targets in the @code{configure}
10097 script are based on a three-part naming scheme, but some short predefined
10098 aliases are also supported. The full naming scheme encodes three pieces
10099 of information in the following pattern:
10100
10101 @example
10102 @var{architecture}-@var{vendor}-@var{os}
10103 @end example
10104
10105 For example, you can use the alias @code{sun4} as a @var{host} argument,
10106 or as the value for @var{target} in a @code{--target=@var{target}}
10107 option. The equivalent full name is @samp{sparc-sun-sunos4}.
10108
10109 The @code{configure} script accompanying @value{GDBN} does not provide
10110 any query facility to list all supported host and target names or
10111 aliases. @code{configure} calls the Bourne shell script
10112 @code{config.sub} to map abbreviations to full names; you can read the
10113 script, if you wish, or you can use it to test your guesses on
10114 abbreviations---for example:
10115
10116 @smallexample
10117 % sh config.sub i386-linux
10118 i386-pc-linux-gnu
10119 % sh config.sub alpha-linux
10120 alpha-unknown-linux-gnu
10121 % sh config.sub hp9k700
10122 hppa1.1-hp-hpux
10123 % sh config.sub sun4
10124 sparc-sun-sunos4.1.1
10125 % sh config.sub sun3
10126 m68k-sun-sunos4.1.1
10127 % sh config.sub i986v
10128 Invalid configuration `i986v': machine `i986v' not recognized
10129 @end smallexample
10130
10131 @noindent
10132 @code{config.sub} is also distributed in the @value{GDBN} source
10133 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
10134
10135 @node Configure Options, , Config Names, Installing GDB
10136 @section @code{configure} options
10137
10138 Here is a summary of the @code{configure} options and arguments that
10139 are most often useful for building @value{GDBN}. @code{configure} also has
10140 several other options not listed here. @inforef{What Configure
10141 Does,,configure.info}, for a full explanation of @code{configure}.
10142
10143 @example
10144 configure @r{[}--help@r{]}
10145 @r{[}--prefix=@var{dir}@r{]}
10146 @r{[}--exec-prefix=@var{dir}@r{]}
10147 @r{[}--srcdir=@var{dirname}@r{]}
10148 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
10149 @r{[}--target=@var{target}@r{]}
10150 @var{host}
10151 @end example
10152
10153 @noindent
10154 You may introduce options with a single @samp{-} rather than
10155 @samp{--} if you prefer; but you may abbreviate option names if you use
10156 @samp{--}.
10157
10158 @table @code
10159 @item --help
10160 Display a quick summary of how to invoke @code{configure}.
10161
10162 @item --prefix=@var{dir}
10163 Configure the source to install programs and files under directory
10164 @file{@var{dir}}.
10165
10166 @item --exec-prefix=@var{dir}
10167 Configure the source to install programs under directory
10168 @file{@var{dir}}.
10169
10170 @c avoid splitting the warning from the explanation:
10171 @need 2000
10172 @item --srcdir=@var{dirname}
10173 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
10174 @code{make} that implements the @code{VPATH} feature.}@*
10175 Use this option to make configurations in directories separate from the
10176 @value{GDBN} source directories. Among other things, you can use this to
10177 build (or maintain) several configurations simultaneously, in separate
10178 directories. @code{configure} writes configuration specific files in
10179 the current directory, but arranges for them to use the source in the
10180 directory @var{dirname}. @code{configure} creates directories under
10181 the working directory in parallel to the source directories below
10182 @var{dirname}.
10183
10184 @item --norecursion
10185 Configure only the directory level where @code{configure} is executed; do not
10186 propagate configuration to subdirectories.
10187
10188 @item --target=@var{target}
10189 Configure @value{GDBN} for cross-debugging programs running on the specified
10190 @var{target}. Without this option, @value{GDBN} is configured to debug
10191 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
10192
10193 There is no convenient way to generate a list of all available targets.
10194
10195 @item @var{host} @dots{}
10196 Configure @value{GDBN} to run on the specified @var{host}.
10197
10198 There is no convenient way to generate a list of all available hosts.
10199 @end table
10200
10201 There are many other options available as well, but they are generally
10202 needed for special purposes only.
10203 @end ifclear
10204
10205
10206 @node Index, , Installing GDB, Top
10207 @unnumbered Index
10208
10209 @printindex cp
10210
10211 @tex
10212 % I think something like @colophon should be in texinfo. In the
10213 % meantime:
10214 \long\def\colophon{\hbox to0pt{}\vfill
10215 \centerline{The body of this manual is set in}
10216 \centerline{\fontname\tenrm,}
10217 \centerline{with headings in {\bf\fontname\tenbf}}
10218 \centerline{and examples in {\tt\fontname\tentt}.}
10219 \centerline{{\it\fontname\tenit\/},}
10220 \centerline{{\bf\fontname\tenbf}, and}
10221 \centerline{{\sl\fontname\tensl\/}}
10222 \centerline{are used for emphasis.}\vfill}
10223 \page\colophon
10224 % Blame: doc@cygnus.com, 1991.
10225 @end tex
10226
10227 @contents
10228 @bye