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