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