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