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