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