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