]> Git Repo - binutils.git/blame - gdb/doc/gdb.texinfo
Incorporate changes from J. Gilmore on targets; also Pesch cosmetic
[binutils.git] / gdb / doc / gdb.texinfo
CommitLineData
e91b87a3 1\input texinfo
4187119d 2@setfilename gdb.info
e91b87a3 3@settitle GDB, The GNU Debugger
4187119d 4@synindex ky cp
e91b87a3 5@ifinfo
6This file documents the GNU debugger GDB.
7
4187119d 8Copyright (C) 1988, 1989 Free Software Foundation, Inc.
e91b87a3 9
10Permission is granted to make and distribute verbatim copies of
11this manual provided the copyright notice and this permission notice
12are preserved on all copies.
13
14@ignore
15Permission is granted to process this file through Tex and print the
16results, provided the printed document carries copying permission
17notice identical to this one except for the removal of this paragraph
18(this paragraph not being relevant to the printed manual).
19
20@end ignore
21Permission is granted to copy and distribute modified versions of this
22manual under the conditions for verbatim copying, provided also that the
4187119d 23section entitled ``GNU General Public License'' is included exactly as
24in the original, and provided that the entire resulting derived work is
25distributed under the terms of a permission notice identical to this
26one.
e91b87a3 27
28Permission is granted to copy and distribute translations of this manual
29into another language, under the above conditions for modified versions,
4187119d 30except that the section entitled ``GNU General Public License'' may be
31included in a translation approved by the author instead of in the
32original English.
e91b87a3 33@end ifinfo
34
35@setchapternewpage odd
36@settitle GDB Manual
37@titlepage
38@sp 6
6ad6aa52 39@center @titlefont{GDB}
e91b87a3 40@sp 1
41@center The GNU Source-Level Debugger
42@sp 4
96a816c5 43@center Third Edition, GDB version 4.0
e91b87a3 44@sp 1
6ad6aa52 45@center December 1990
e91b87a3 46@sp 5
47@center Richard M. Stallman
6ad6aa52 48@center (Revised by Cygnus Support)
e91b87a3 49@page
9c91ee3e
RP
50@hfill Cygnus Support
51@par@hskip -@parfillskip@hfill $Revision$
52@par@hskip -@parfillskip@hfill @TeX{}info @texinfoversion
e91b87a3 53@vskip 0pt plus 1filll
6ad6aa52 54Copyright @copyright{} 1988, 1989, 1990 Free Software Foundation, Inc.
e91b87a3 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
60Permission is granted to copy and distribute modified versions of this
61manual under the conditions for verbatim copying, provided also that the
4187119d 62section entitled ``GNU General Public License'' is included exactly as
63in the original, and provided that the entire resulting derived work is
64distributed under the terms of a permission notice identical to this
65one.
e91b87a3 66
67Permission is granted to copy and distribute translations of this manual
68into another language, under the above conditions for modified versions,
4187119d 69except that the section entitled ``GNU General Public License'' may be
70included in a translation approved by the author instead of in the
71original English.
e91b87a3 72@end titlepage
73@page
74
4187119d 75@node Top, Top, Top, (DIR)
e91b87a3 76@unnumbered Summary of GDB
77
78The purpose of a debugger such as GDB is to allow you to execute another
79program while examining what is going on inside it. We call the other
80program ``your program'' or ``the program being debugged''.
81
82GDB can do four kinds of things (plus other things in support of these):
83
84@enumerate
85@item
86Start the program, specifying anything that might affect its behavior.
87
88@item
89Make the program stop on specified conditions.
90
91@item
92Examine what has happened, when the program has stopped, so that you
93can see bugs happen.
94
95@item
96Change things in the program, so you can correct the effects of one bug
97and go on to learn about another without having to recompile first.
98@end enumerate
99
100GDB can be used to debug programs written in C and C++. Pascal support
101is being implemented, and Fortran support will be added when a GNU
102Fortran compiler is written.
103
104@menu
4187119d 105* License:: The GNU General Public License gives you permission
e91b87a3 106 to redistribute GDB on certain terms; and also
107 explains that there is no warranty.
4187119d 108* User Interface:: GDB command syntax and input and output conventions.
e91b87a3 109* Files:: Specifying files for GDB to operate on.
110* Options:: GDB arguments and options.
111* Compilation::Compiling your program so you can debug it.
112* Running:: Running your program under GDB.
113* Stopping:: Making your program stop. Why it may stop. What to do then.
114* Stack:: Examining your program's stack.
115* Source:: Examining your program's source files.
116* Data:: Examining data in your program.
117* Symbols:: Examining the debugger's symbol table.
118* Altering:: Altering things in your program.
119* Sequences:: Canned command sequences for repeated use.
120* Emacs:: Using GDB through GNU Emacs.
121* Remote:: Remote kernel debugging across a serial line.
9c91ee3e 122* GDB Bugs:: How to report bugs (if you want to get them fixed).
e91b87a3 123* Commands:: Index of GDB commands.
124* Concepts:: Index of GDB concepts.
125@end menu
126
4187119d 127@node License, User Interface, Top, Top
128@unnumbered GNU GENERAL PUBLIC LICENSE
129@center Version 1, February 1989
130
131@display
132Copyright @copyright{} 1989 Free Software Foundation, Inc.
133675 Mass Ave, Cambridge, MA 02139, USA
134
135Everyone is permitted to copy and distribute verbatim copies
136of this license document, but changing it is not allowed.
137@end display
138
139@unnumberedsec Preamble
140
141 The license agreements of most software companies try to keep users
142at the mercy of those companies. By contrast, our General Public
143License is intended to guarantee your freedom to share and change free
144software---to make sure the software is free for all its users. The
145General Public License applies to the Free Software Foundation's
146software and to any other program whose authors commit to using it.
147You can use it for your programs, too.
148
149 When we speak of free software, we are referring to freedom, not
150price. Specifically, the General Public License is designed to make
151sure that you have the freedom to give away or sell copies of free
152software, that you receive source code or can get it if you want it,
153that you can change the software or use pieces of it in new free
154programs; and that you know you can do these things.
155
156 To protect your rights, we need to make restrictions that forbid
157anyone to deny you these rights or to ask you to surrender the rights.
158These restrictions translate to certain responsibilities for you if you
159distribute copies of the software, or if you modify it.
160
161 For example, if you distribute copies of a such a program, whether
162gratis or for a fee, you must give the recipients all the rights that
163you have. You must make sure that they, too, receive or can get the
164source code. And you must tell them their rights.
165
166 We protect your rights with two steps: (1) copyright the software, and
167(2) offer you this license which gives you legal permission to copy,
168distribute and/or modify the software.
169
170 Also, for each author's protection and ours, we want to make certain
171that everyone understands that there is no warranty for this free
172software. If the software is modified by someone else and passed on, we
173want its recipients to know that what they have is not the original, so
174that any problems introduced by others will not reflect on the original
175authors' reputations.
176
177 The precise terms and conditions for copying, distribution and
178modification follow.
e91b87a3 179
4187119d 180@iftex
181@unnumberedsec TERMS AND CONDITIONS
182@end iftex
183@ifinfo
184@center TERMS AND CONDITIONS
185@end ifinfo
e91b87a3 186
187@enumerate
188@item
4187119d 189This License Agreement applies to any program or other work which
190contains a notice placed by the copyright holder saying it may be
191distributed under the terms of this General Public License. The
192``Program'', below, refers to any such program or work, and a ``work based
193on the Program'' means either the Program or any work containing the
194Program or a portion of it, either verbatim or with modifications. Each
195licensee is addressed as ``you''.
196
197@item
198You may copy and distribute verbatim copies of the Program's source
199code as you receive it, in any medium, provided that you conspicuously and
200appropriately publish on each copy an appropriate copyright notice and
201disclaimer of warranty; keep intact all the notices that refer to this
202General Public License and to the absence of any warranty; and give any
203other recipients of the Program a copy of this General Public License
204along with the Program. You may charge a fee for the physical act of
205transferring a copy.
e91b87a3 206
207@item
4187119d 208You may modify your copy or copies of the Program or any portion of
209it, and copy and distribute such modifications under the terms of Paragraph
2101 above, provided that you also do the following:
e91b87a3 211
212@itemize @bullet
213@item
4187119d 214cause the modified files to carry prominent notices stating that
215you changed the files and the date of any change; and
e91b87a3 216
217@item
218cause the whole of any work that you distribute or publish, that
4187119d 219in whole or in part contains the Program or any part thereof, either
220with or without modifications, to be licensed at no charge to all
221third parties under the terms of this General Public License (except
222that you may choose to grant warranty protection to some or all
223third parties, at your option).
e91b87a3 224
225@item
4187119d 226If the modified program normally reads commands interactively when
227run, you must cause it, when started running for such interactive use
228in the simplest and most usual way, to print or display an
229announcement including an appropriate copyright notice and a notice
230that there is no warranty (or else, saying that you provide a
231warranty) and that users may redistribute the program under these
232conditions, and telling the user how to view a copy of this General
233Public License.
e91b87a3 234
235@item
4187119d 236You may charge a fee for the physical act of transferring a
237copy, and you may at your option offer warranty protection in
238exchange for a fee.
e91b87a3 239@end itemize
240
4187119d 241Mere aggregation of another independent work with the Program (or its
e91b87a3 242derivative) on a volume of a storage or distribution medium does not bring
4187119d 243the other work under the scope of these terms.
e91b87a3 244
245@item
4187119d 246You may copy and distribute the Program (or a portion or derivative of
247it, under Paragraph 2) in object code or executable form under the terms of
248Paragraphs 1 and 2 above provided that you also do one of the following:
e91b87a3 249
250@itemize @bullet
251@item
252accompany it with the complete corresponding machine-readable
253source code, which must be distributed under the terms of
254Paragraphs 1 and 2 above; or,
255
256@item
257accompany it with a written offer, valid for at least three
4187119d 258years, to give any third party free (except for a nominal charge
259for the cost of distribution) a complete machine-readable copy of the
e91b87a3 260corresponding source code, to be distributed under the terms of
261Paragraphs 1 and 2 above; or,
262
263@item
264accompany it with the information you received as to where the
265corresponding source code may be obtained. (This alternative is
266allowed only for noncommercial distribution and only if you
267received the program in object code or executable form alone.)
268@end itemize
269
4187119d 270Source code for a work means the preferred form of the work for making
271modifications to it. For an executable file, complete source code means
272all the source code for all modules it contains; but, as a special
273exception, it need not include source code for modules which are standard
274libraries that accompany the operating system on which the executable
275file runs, or for standard header files or definitions files that
276accompany that operating system.
e91b87a3 277
278@item
4187119d 279You may not copy, modify, sublicense, distribute or transfer the
280Program except as expressly provided under this General Public License.
281Any attempt otherwise to copy, modify, sublicense, distribute or transfer
282the Program is void, and will automatically terminate your rights to use
283the Program under this License. However, parties who have received
284copies, or rights to use copies, from you under this General Public
285License will not have their licenses terminated so long as such parties
286remain in full compliance.
e91b87a3 287
288@item
4187119d 289By copying, distributing or modifying the Program (or any work based
290on the Program) you indicate your acceptance of this license to do so,
291and all its terms and conditions.
292
293@item
294Each time you redistribute the Program (or any work based on the
295Program), the recipient automatically receives a license from the original
296licensor to copy, distribute or modify the Program subject to these
297terms and conditions. You may not impose any further restrictions on the
298recipients' exercise of the rights granted herein.
299
300@item
301The Free Software Foundation may publish revised and/or new versions
302of the General Public License from time to time. Such new versions will
303be similar in spirit to the present version, but may differ in detail to
304address new problems or concerns.
305
306Each version is given a distinguishing version number. If the Program
307specifies a version number of the license which applies to it and ``any
308later version'', you have the option of following the terms and conditions
309either of that version or of any later version published by the Free
310Software Foundation. If the Program does not specify a version number of
311the license, you may choose any version ever published by the Free Software
312Foundation.
313
314@item
315If you wish to incorporate parts of the Program into other free
316programs whose distribution conditions are different, write to the author
317to ask for permission. For software which is copyrighted by the Free
318Software Foundation, write to the Free Software Foundation; we sometimes
319make exceptions for this. Our decision will be guided by the two goals
320of preserving the free status of all derivatives of our free software and
321of promoting the sharing and reuse of software generally.
322
323@iftex
324@heading NO WARRANTY
325@end iftex
326@ifinfo
327@center NO WARRANTY
328@end ifinfo
329
330@item
331BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
332FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
333OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
334PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
335OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
336MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
337TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
338PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
339REPAIR OR CORRECTION.
340
341@item
342IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
343ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
344REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
345INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
346ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
347LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
348SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
349WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
350ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
e91b87a3 351@end enumerate
352
353@iftex
4187119d 354@heading END OF TERMS AND CONDITIONS
e91b87a3 355@end iftex
4187119d 356@ifinfo
357@center END OF TERMS AND CONDITIONS
358@end ifinfo
359
360@page
361@unnumberedsec Appendix: How to Apply These Terms to Your New Programs
362
363 If you develop a new program, and you want it to be of the greatest
364possible use to humanity, the best way to achieve this is to make it
365free software which everyone can redistribute and change under these
366terms.
367
368 To do so, attach the following notices to the program. It is safest to
369attach them to the start of each source file to most effectively convey
370the exclusion of warranty; and each file should have at least the
371``copyright'' line and a pointer to where the full notice is found.
372
373@smallexample
374@var{one line to give the program's name and a brief idea of what it does.}
375Copyright (C) 19@var{yy} @var{name of author}
376
377This program is free software; you can redistribute it and/or modify
378it under the terms of the GNU General Public License as published by
379the Free Software Foundation; either version 1, or (at your option)
380any later version.
381
382This program is distributed in the hope that it will be useful,
383but WITHOUT ANY WARRANTY; without even the implied warranty of
384MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
385GNU General Public License for more details.
386
387You should have received a copy of the GNU General Public License
388along with this program; if not, write to the Free Software
389Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
390@end smallexample
391
392Also add information on how to contact you by electronic and paper mail.
393
394If the program is interactive, make it output a short notice like this
395when it starts in an interactive mode:
396
397@smallexample
398Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
399Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
400This is free software, and you are welcome to redistribute it
401under certain conditions; type `show c' for details.
402@end smallexample
403
404The hypothetical commands `show w' and `show c' should show the
405appropriate parts of the General Public License. Of course, the
406commands you use may be called something other than `show w' and `show
407c'; they could even be mouse-clicks or menu items---whatever suits your
408program.
409
410You should also get your employer (if you work as a programmer) or your
411school, if any, to sign a ``copyright disclaimer'' for the program, if
412necessary. Here a sample; alter the names:
413
414@example
415Yoyodyne, Inc., hereby disclaims all copyright interest in the
416program `Gnomovision' (a program to direct compilers to make passes
417at assemblers) written by James Hacker.
418
419@var{signature of Ty Coon}, 1 April 1989
420Ty Coon, President of Vice
421@end example
422
423That's all there is to it!
424
425@node User Interface, Files, License, Top
426@chapter GDB Input and Output Conventions
e91b87a3 427
428GDB is invoked with the shell command @samp{gdb}. Once started, it reads
429commands from the terminal until you tell it to exit.
430
431A GDB command is a single line of input. There is no limit on how long
432it can be. It starts with a command name, which is followed by arguments
4187119d 433whose meaning depends on the command name. For example, the command
434@samp{step} accepts an argument which is the number of times to step,
435as in @samp{step 5}. You can also use the @samp{step} command with
436no arguments. Some command names do not allow any arguments.
e91b87a3 437
4187119d 438@cindex abbreviation
e91b87a3 439GDB command names may always be abbreviated if the abbreviation is
440unambiguous. Sometimes even ambiguous abbreviations are allowed; for
441example, @samp{s} is specially defined as equivalent to @samp{step}
442even though there are other commands whose names start with @samp{s}.
443Possible command abbreviations are often stated in the documentation
444of the individual commands.
445
4187119d 446@cindex repeating commands
e91b87a3 447A blank line as input to GDB means to repeat the previous command verbatim.
448Certain commands do not allow themselves to be repeated this way; these are
449commands for which unintentional repetition might cause trouble and which
450you are unlikely to want to repeat. Certain others (@samp{list} and
451@samp{x}) act differently when repeated because that is more useful.
452
453A line of input starting with @samp{#} is a comment; it does nothing.
454This is useful mainly in command files (@xref{Command Files}).
455
4187119d 456@cindex prompt
457GDB indicates its readiness to read a command by printing a string
458called the @dfn{prompt}. This string is normally @samp{(gdb)}. You can
459change the prompt string with the @samp{set prompt} command. For
460instance, when debugging GDB with GDB, it is useful to change the prompt
461in one of the GDBs so that you tell which one you are talking to.
e91b87a3 462
463@table @code
9c91ee3e 464@item set prompt @var{newprompt}
e91b87a3 465@kindex set prompt
96a816c5
JG
466Directs GDB to use @samp{newprompt} as its prompt string henceforth.
467@kindex show prompt
468@item show prompt
469Prints the line: Gdb's prompt is: @samp{your-prompt}
e91b87a3 470@end table
471
472@cindex exiting GDB
473@kindex quit
9c91ee3e
RP
474To exit GDB, use the @samp{quit} command (abbreviated @samp{q}), or type
475an end-of-file character (usually @ctrl{d}). An interrupt (often
476@ctrl{c}) will not exit from GDB, but rather will terminate the action
e91b87a3 477of any GDB command that is in progress and return to GDB command level.
9c91ee3e
RP
478It is safe to type the interrupt character at any time because GDB does
479not allow it to take effect until a time when it is safe.
e91b87a3 480
96a816c5
JG
481@cindex readline
482@cindex command line editing
483@cindex history substitution
484GDB now reads its input commands via the @code{readline} interface.
9c91ee3e
RP
485This GNU library provides consistant behaviour for programs which
486provide a command line interface to the user. From the point
487of view of the user, the advantages are @samp{emacs}-style or @samp{vi}-style
96a816c5
JG
488inline editing of commands, @samp{csh}-like history substitution,
489and a storage and recall of command history across debugging sessions.
490
491You may control the behavior of command line editing in GDB with the
492following commands:
493
494@table @code
495@kindex set editing
496@item set editing
497@itemx set editing on
498Enable command line editing (enabled by default).
499
500@item set editing off
501Disable command line editing.
502
96a816c5
JG
503@kindex info editing
504@item info editing
505Display the current settings relating to command line editing, and also
506display the last ten commands in the command history.
507
508@item info editing @var{n}
509Print ten commands centered on command number @var{n}.
510
511@item info editing +
512Print ten commands just after the commands last printed.
513
514@kindex set history file
9c91ee3e 515@item set history file @var{filename}
96a816c5
JG
516Set the name of the GDB command history file to @samp{filename}. This is
517the file from which GDB will read an initial command history
518list or to which it will write this list when it exits. This list is
519accessed through history expansion or through the history
520command editing characters listed below. This file defaults to the
521value of the environmental variable @code{GDBHISTFILE}, or to
522@code{./.gdb_history} if this variable is not set.
523
524@kindex set history write
525@item set history write
526@itemx set history write on
9c91ee3e
RP
527Make GDB record command history in a file, whose name may be specified with the
528@samp{set history file} command. By default, this option is disabled.
96a816c5
JG
529
530@item set history write off
9c91ee3e 531Make GDB stop recording command history in a file.
96a816c5
JG
532
533@kindex set history size
534@item set history size @var{size}
535Set the number of commands which GDB will keep in its history list.
536This defaults to the value of the environmental variable
537@code{HISTSIZE}, or to 256 if this variable is not set.
6ad6aa52 538@end table
96a816c5
JG
539
540@cindex history expansion
541
96a816c5
JG
542The commands to control history expansion are:
543
544@table @code
545
546@kindex set history expansion
547@item set history expansion on
548@itemx set history expansion
9c91ee3e 549Enable history expansion. History expansion is off by default.
96a816c5
JG
550
551@item set history expansion off
9c91ee3e 552Disable history expansion.
96a816c5
JG
553
554@end table
555
9c91ee3e
RP
556Because of the additional meaning of `@code{!}' to GDB (as the logical
557not operator in C), history expansion is off by default. If you decide
558to enable history expansion with the @samp{set history expansion on}
559command, you will need to follow @samp{!} (when it is part of an
560expression) with a space or a tab to prevent it from being expanded.
561
562
96a816c5
JG
563The @code{readline} code comes with more complete documentation of
564editing and history expansion features. Users unfamiliar with @samp{emacs}
9c91ee3e 565or @samp{vi} may wish to read it. @xref{Command Line Editing}.
96a816c5
JG
566
567Occasionally it is useful to execute a shell command from within GDB.
568This can be done with the @samp{shell} command.
569
570@table @code
9c91ee3e 571@item shell @var{command string}
96a816c5
JG
572@kindex shell
573@cindex shell escape
9c91ee3e 574Directs GDB to invoke an inferior shell to execute @var{command string}.
96a816c5
JG
575The environment variable @code{SHELL} is used if it exists, otherwise GDB
576uses @samp{/bin/sh}.
577
9c91ee3e
RP
578@item make @var{target}
579@kindex make
580@cindex calling make
581Causes GDB to execute an inferior @code{make} program with the specified
582arguments. This is equivalent to @samp{shell make @var{target}}.
583@end table
584
4187119d 585@cindex screen size
586@cindex pauses in output
587Certain commands to GDB may produce large amounts of information output
588to the screen. To help you read all of it, GDB pauses and asks you for
589input at the end of each page of output. Type @key{RET} when you want
590to continue the output. Normally GDB knows the size of the screen from
9c91ee3e
RP
591the termcap data base together with the value of the @code{TERM}
592environment variable and the @code{stty rows} and @code{stty cols}
593settings. If this is not correct, you can override it with
96a816c5 594the @samp{set screen-height} and @samp{set screen-width} commands:
4187119d 595
596@table @code
96a816c5
JG
597@item set screen-height @var{lpp}
598@item set screen-width @var{cpl}
599@kindex set screen-height
600@kindex set screen-width
601Specify a screen height of @var{lpp} lines and a screen width of
602@var{cpl} characters.
4187119d 603
604If you specify a height of zero lines, GDB will not pause during output
605no matter how long the output is. This is useful if output is to a file
606or to an editor buffer.
607@end table
608
9c91ee3e
RP
609By default, GDB is silent about its inner workings. If you are running
610on a slow machine, you may want to use the @samp{set verbose} command.
611It will make GDB tell you when it does a lengthy internal operation, so
612you won't think it has crashed.
4187119d 613
614Currently, the messages controlled by @samp{set verbose} are those which
615announce that the symbol table for a source file is being read
616(@pxref{File Commands}, in the description of the command
617@samp{symbol-file}).
618@c The following is the right way to do it, but emacs 18.55 doesn't support
619@c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo
620@c is released.
621@ignore
622see @samp{symbol-file} in @ref{File Commands}).
623@end ignore
624
9c91ee3e
RP
625@table @code
626@kindex set verbose
627@item set verbose on
628Enables GDB's output of certain informational messages.
629
630@item set verbose off
631Disables GDB's output of certain informational messages.
632
633@end table
634
635By default, GDB asks what sometimes seem to be a lot of stupid
636questions. For example, if you try to run a program which is already
637running:
638@example
639
640(gdb) run
641The program being debugged has been started already.
642Start it from the beginning? (y or n)
643@end example
644
645If you're willing to unflinchingly face the consequences of your own
646commands, you can disable this ``feature'':
647
648@table @code
649@kindex set stupidity
650@cindex flinching
651@cindex verifying commands with serious side effects
652@item set stupidity off
653Disables stupid questions.
654
655@item set stupidity on
656Enables stupid questions (the default).
657
658
4187119d 659@node Files, Compilation, User Interface, Top
e91b87a3 660@chapter Specifying GDB's Files
661
662@cindex core dump file
663@cindex executable file
664@cindex symbol table
4187119d 665GDB needs to know the file name of the program to be debugged, both in
666order to read its symbol table and in order to start the program. To
667debug a core dump of a previous run, GDB must be told the file name of
668the core dump.
e91b87a3 669
670@menu
671* Arguments: File Arguments. Specifying files with arguments
672 (when you start GDB).
673* Commands: File Commands. Specifying files with GDB commands.
674@end menu
675
676@node File Arguments, File Commands, Files, Files
677@section Specifying Files with Arguments
678
679The usual way to specify the executable and core dump file names is with
680two command arguments given when you start GDB. The first argument is used
681as the file for execution and symbols, and the second argument (if any) is
682used as the core dump file name. Thus,
683
684@example
685gdb progm core
686@end example
687
688@noindent
689specifies @file{progm} as the executable program and @file{core} as a core
690dump file to examine. (You do not need to have a core dump file if what
691you plan to do is debug the program interactively.)
692
4187119d 693@xref{Options}, for full information on options and arguments for
694invoking GDB.
e91b87a3 695
696@node File Commands,, File Arguments, Files
697@section Specifying Files with Commands
698
699Usually you specify the files for GDB to work with by giving arguments when
700you invoke GDB. But occasionally it is necessary to change to a different
701file during a GDB session. Or you may run GDB and forget to specify the
702files you want to use. In these situations the GDB commands to specify new
703files are useful.
704
705@table @code
9c91ee3e
RP
706@item file @var{filename}
707@kindex file
708Use @var{file} as the program to be debugged. It is read for its
709symbols, for getting the contents of pure memory, and it is the program
710executed when you use the @samp{run} command. If you do not specify a
711directory and the file is not found in GDB's working directory, GDB will
712use the environment variable @code{PATH} as a list of directories to
713search, just as the shell does when looking for a program to run.
714
715@samp{file} with no argument makes both executable file and symbol
716table become unspecified.
717
e91b87a3 718@item exec-file @var{filename}
719@kindex exec-file
9c91ee3e
RP
720Specify that the program to be run (but not the symbol table) is found
721in @var{filename}. GDB will search the environment variable @code{PATH}
722if necessary to locate the program.
e91b87a3 723
724@item symbol-file @var{filename}
725@kindex symbol-file
9c91ee3e
RP
726Read symbol table information from file @var{filename}. @code{PATH} is
727searched when necessary. Use the @samp{file} command to get both symbol
728table and program to run from the same file.
e91b87a3 729
730@samp{symbol-file} with no argument clears out GDB's symbol table.
731
9c91ee3e
RP
732On some systems, the @samp{symbol-file} command does not actually read
733the symbol table in full right away. Instead, it scans the symbol table
734quickly to find which source files and which symbols are present. The
735details are read later, one source file at a time, when they are needed.
4187119d 736
737The purpose of this two-stage reading strategy is to make GDB start up
9c91ee3e
RP
738faster. For the most part, it is invisible except for occasional pauses
739while the symbol table details for a particular source file are being
740read. (The @samp{set verbose} command can turn these pauses into
741messages if desired. @xref{User Interface}).
4187119d 742
743When the symbol table is stored in COFF format, @samp{symbol-file} does
744read the symbol table data in full right away. We haven't bothered to
9c91ee3e 745implement the two-stage strategy for COFF yet.
4187119d 746
9c91ee3e
RP
747@item core @var{filename}
748@kindex core
e91b87a3 749Specify the whereabouts of a core dump file to be used as the
750``contents of memory''. Note that the core dump contains only the
751writable parts of memory; the read-only parts must come from the
752executable file.
753
754@samp{core-file} with no argument specifies that no core file is
755to be used.
756
4187119d 757Note that the core file is ignored when your program is actually running
758under GDB. So, if you have been running the program and you wish to
759debug a core file instead, you must kill the subprocess in which the
760program is running. To do this, use the @samp{kill} command
761(@pxref{Kill Process}).
762
e91b87a3 763@item add-file @var{filename} @var{address}
9c91ee3e 764@itemx load @var{filename} @var{address}
e91b87a3 765@kindex add-file
9c91ee3e 766@kindex load
4187119d 767@cindex dynamic linking
768The @samp{add-file} command reads additional symbol table information
769from the file @var{filename}. You would use this when that file has
770been dynamically loaded into the program that is running. @var{address}
771should be the memory address at which the file has been loaded; GDB cannot
772figure this out for itself.
773
9c91ee3e
RP
774When debugging with some targets (@pxref{Targets}), this command will
775also cause the file to be dynamically loaded into the target system.
776@comment FIXME: "some" is obnoxious. Currently this is only VxWorks.
777@comment ---pesch 18dec1990
778
4187119d 779The symbol table of the file @var{filename} is added to the symbol table
780originally read with the @samp{symbol-file} command. You can use the
781@samp{add-file} command any number of times; the new symbol data thus
782read keeps adding to the old. The @samp{symbol-file} command forgets
9c91ee3e 783all the symbol data GDB has read.
e91b87a3 784
785@item info files
786@kindex info files
787Print the names of the executable and core dump files currently in
9c91ee3e
RP
788use by GDB, and the file from which symbols were loaded, as well as the
789stack of current targets (@pxref{Targets}).
790
791@end table
e91b87a3 792
793While all three file-specifying commands allow both absolute and relative
794file names as arguments, GDB always converts the file name to an absolute
795one and remembers it that way.
796
797The @samp{symbol-file} command causes GDB to forget the contents of its
798convenience variables, the value history, and all breakpoints and
799auto-display expressions. This is because they may contain pointers to the
800internal data recording symbols and data types, which are part of the old
801symbol table data being discarded inside GDB.
802
96a816c5
JG
803@kindex shared-library
804@kindex share
805@cindex shared libraries
806
9c91ee3e 807GDB supports the SunOS shared library format. Symbols from a shared
96a816c5
JG
808library cannot be referenced before the shared library has been linked
809with the program. (That is to say, after one types @samp{run} and
9c91ee3e
RP
810the function @code{main()} has been entered; or when examining core
811files.) Once the shared library has been linked in, you can use the
812following commands:
96a816c5 813
9c91ee3e
RP
814@table @code
815@item sharedlibrary @var{regex}
816@itemx share @var{regex}
96a816c5
JG
817Load shared object library symbols for files matching a UNIX regular
818expresssion.
819
9c91ee3e
RP
820@item share
821@itemx sharedlibrary
96a816c5
JG
822Load symbols for all shared libraries.
823
9c91ee3e
RP
824@item info share
825@itemx info sharedlibrary
96a816c5 826@kindex info sharedlibrary
9c91ee3e 827@kindex info share
96a816c5 828Print the names of the shared libraries which are currently loaded.
6ad6aa52 829@end table
96a816c5
JG
830
831
9c91ee3e 832@node Compilation, Targets, Files, Top
e91b87a3 833@chapter Compiling Your Program for Debugging
834
835In order to debug a program effectively, you need to ask for debugging
836information when you compile it. This information in the object file
837describes the data type of each variable or function and the correspondence
838between source line numbers and addresses in the executable code.
839
840To request debugging information, specify the @samp{-g} option when you run
841the compiler.
842
843The Unix C compiler is unable to handle the @samp{-g} and @samp{-O} options
844together. This means that you cannot ask for optimization if you ask for
845debugger information.
846
847The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it
848possible to debug optimized code. We recommend that you @emph{always} use
849@samp{-g} whenever you compile a program. You may think the program is
850correct, but there's no sense in pushing your luck.
851
9c91ee3e
RP
852Some things do not work as well with @samp{-g -O} as with just
853@samp{-g}, particularly on machines with instruction scheduling. If in
854doubt, recompile with @samp{-g} alone, and if this fixes the problem,
855please report it as a bug (including a test case---@pxref{GDB Bugs}).
856
857Older versions of the GNU C compiler, GCC, permitted a variant option
858@samp{-gg} for debugging information. GDB no longer supports this format;
859if your GNU C compiler has this option, do not use it.
e91b87a3 860
1c997a4a 861@ignore
862@comment As far as I know, there are no cases in which GDB will
863@comment produce strange output in this case. (but no promises).
4187119d 864If your program includes archives made with the @code{ar} program, and
865if the object files used as input to @code{ar} were compiled without the
866@samp{-g} option and have names longer than 15 characters, GDB will get
867confused reading the program's symbol table. No error message will be
868given, but GDB may behave strangely. The reason for this problem is a
869deficiency in the Unix archive file format, which cannot represent file
870names longer than 15 characters.
e91b87a3 871
4187119d 872To avoid this problem, compile the archive members with the @samp{-g}
873option or use shorter file names. Alternatively, use a version of GNU
874@code{ar} dated more recently than August 1989.
1c997a4a 875@end ignore
e91b87a3 876
9c91ee3e
RP
877@node Targets, Running, Compilation, Top
878@chapter Specifying a Debugging Target
879@cindex debugging target
880@kindex target
881Often, you will be able to run GDB in the same host environment as the
882program you are debugging; in that case, the debugging target is
883specified as a side effect of the @samp{file} or @samp{core} commands.
884When you need more flexibility---for example, running GDB on a
885physically separate host, controlling standalone systems over a
886serial port, or realtime systems over a TCP/IP connection---you can use
887the @samp{target} command.
888
889@table @code
890@item target @var{type} @var{parameters}
891Connects the GDB host environment to a target machine or process. A
892target is typically a protocol for talking to debugging facilities. You
893use the argument @var{type} to specify the type or protocol of the
894target machine; for example, @samp{target child} for Unix child processes, or
895@samp{target vxworks} for a TCP/IP link to a VxWorks system.
896
897Further @var{parameters} are interpreted by the target protocol, but
898typically include things like device names or host names to connect
899with, process numbers, and baud rates. Executing
900@example
901 target @var{type}
902@end example
903
904@noindent{}(without any parameters) will issue a message about what
905parameters are required for that target type.
906
907@end table
908
909Targets are managed as a stack, so that you may (for example) specify
910a core file as a target without abandoning a running program; when
911you're done with the core file, you can return to the previous target
912using @samp{detach}. The related command @samp{attach} provides you
913with an alternative way of stacking a new target. @xref{Attach}.
914
915@table @code
916@item info targets
917Displays the names of all targets available.
918@end table
919
920To display the targets currently stacked, use the @samp{info files}
921command (@pxref{File Commands}).
922
923@node Running, Stopping, Targets, Top
e91b87a3 924@chapter Running Your Program Under GDB
925
926@cindex running
927@kindex run
9c91ee3e
RP
928To start your program under GDB, use the @samp{run} command. Except on
929VxWorks, the program must already have been specified using the
930@samp{file} or @samp{exec-file} command, or with an argument to GDB
931(@pxref{Files}); what @samp{run} does is create an inferior process,
932load the program into it, and set it in motion.
e91b87a3 933
4187119d 934The execution of a program is affected by certain information it
935receives from its superior. GDB provides ways to specify this
936information, which you must do @i{before} starting the program. (You
937can change it after starting the program, but such changes do not affect
938the program unless you start it over again.) This information may be
939divided into three categories:
e91b87a3 940
941@table @asis
942@item The @i{arguments.}
943You specify the arguments to give the program as the arguments of the
4187119d 944@samp{run} command.
e91b87a3 945
946@item The @i{environment.}
947The program normally inherits its environment from GDB, but you can
948use the GDB commands @samp{set environment} and
949@samp{unset environment} to change parts of the environment that will
950be given to the program.@refill
951
952@item The @i{working directory.}
953The program inherits its working directory from GDB. You can set GDB's
954working directory with the @samp{cd} command in GDB.
955@end table
956
9c91ee3e
RP
957When you issue the @samp{run} command, your program begins to execute
958immediately. @xref{Stopping}, for discussion of how to arrange for your
959program to stop.
e91b87a3 960
961Note that once your program has been started by the @samp{run} command,
962you may evaluate expressions that involve calls to functions in the
9c91ee3e
RP
963inferior, using the @samp{print} or @samp{call} commands. @xref{Data}.
964
965If your program's timestamp has changed since the last time GDB read its
966symbols, GDB will discard its symbol table and re-read it from your
967program. In this process, it tries to retain your current breakpoints.
e91b87a3 968
969@menu
970* Arguments:: Specifying the arguments for your program.
971* Environment:: Specifying the environment for your program.
972* Working Directory:: Specifying the working directory for giving
973 to your program when it is run.
974* Input/Output:: Specifying the program's standard input and output.
975* Attach:: Debugging a process started outside GDB.
4187119d 976* Kill Process:: Getting rid of the child process running your program.
e91b87a3 977@end menu
978
979@node Arguments, Environment, Running, Running
980@section Your Program's Arguments
981
982@cindex arguments (to your program)
4187119d 983The arguments to your program are specified by the arguments of the
e91b87a3 984@samp{run} command. They are passed to a shell, which expands wildcard
985characters and performs redirection of I/O, and thence to the program.
986
987@samp{run} with no arguments uses the same arguments used by the previous
988@samp{run}.
989
990@kindex set args
991The command @samp{set args} can be used to specify the arguments to be used
992the next time the program is run. If @samp{set args} has no arguments, it
993means to use no arguments the next time the program is run. If you have
994run your program with arguments and want to run it again with no arguments,
995this is the only way to do so.
996
997@node Environment, Working Directory, Arguments, Running
998@section Your Program's Environment
999
1000@cindex environment (of your program)
1001The @dfn{environment} consists of a set of @dfn{environment variables} and
1002their values. Environment variables conventionally record such things as
1003your user name, your home directory, your terminal type, and your search
1004path for programs to run. Usually you set up environment variables with
1005the shell and they are inherited by all the other programs you run. When
1006debugging, it can be useful to try running the program with different
1007environments without having to start the debugger over again.
1008
1009@table @code
1010@item info environment @var{varname}
1011@kindex info environment
1012Print the value of environment variable @var{varname} to be given to
1013your program when it is started. This command can be abbreviated
1014@samp{i env @var{varname}}.
1015
1016@item info environment
1017Print the names and values of all environment variables to be given to
1018your program when it is started. This command can be abbreviated
1019@samp{i env}.
1020
1021@item set environment @var{varname} @var{value}
4187119d 1022@itemx set environment @var{varname} = @var{value}
e91b87a3 1023@kindex set environment
1024Sets environment variable @var{varname} to @var{value}, for your program
1025only, not for GDB itself. @var{value} may be any string; the values of
1026environment variables are just strings, and any interpretation is
1027supplied by your program itself. The @var{value} parameter is optional;
1028if it is eliminated, the variable is set to a null value. This command
9c91ee3e 1029can be abbreviated as @samp{set e}.
e91b87a3 1030
4187119d 1031For example, this command:
1032
1033@example
1034set env USER = foo
1035@end example
1036
1037@noindent
1038tells the program, when subsequently run, to assume it is being run
1039on behalf of the user named @samp{foo}.
1040
e91b87a3 1041@item delete environment @var{varname}
4187119d 1042@itemx unset environment @var{varname}
e91b87a3 1043@kindex delete environment
e91b87a3 1044@kindex unset environment
4187119d 1045Remove variable @var{varname} from the environment to be passed to your
1046program. This is different from @samp{set env @var{varname}@ =} because
1047@samp{delete environment} leaves the variable with no value, which is
1048distinguishable from an empty value. This command can be abbreviated
1049@samp{d e}.
e91b87a3 1050@end table
1051
1052@node Working Directory, Input/Output, Environment, Running
1053@section Your Program's Working Directory
1054
1055@cindex working directory (of your program)
4187119d 1056Each time you start your program with @samp{run}, it inherits its
1057working directory from the current working directory of GDB. GDB's
1058working directory is initially whatever it inherited from its parent
1059process (typically the shell), but you can specify a new working
1060directory in GDB with the @samp{cd} command.
e91b87a3 1061
1062The GDB working directory also serves as a default for the commands
1063that specify files for GDB to operate on. @xref{Files}.
1064
1065@table @code
1066@item cd @var{directory}
1067@kindex cd
1068Set GDB's working directory to @var{directory}.
1069
1070@item pwd
1071@kindex pwd
1072Print GDB's working directory.
1073@end table
1074
1075@node Input/Output, Attach, Working Directory, Running
1076@section Your Program's Input and Output
1077
1078@cindex redirection
1079@cindex controlling terminal
1080By default, the program you run under GDB does input and output to the same
1081terminal that GDB uses.
1082
1083You can redirect the program's input and/or output using @samp{sh}-style
1084redirection commands in the @samp{run} command. For example,
1085
1086@example
1087run > outfile
1088@end example
1089
1090@noindent
1091starts the program, diverting its output to the file @file{outfile}.
1092
1093@kindex tty
4187119d 1094Another way to specify where the program should do input and output is
1095with the @samp{tty} command. This command accepts a file name as
1096argument, and causes this file to be the default for future @samp{run}
1097commands. It also resets the controlling terminal for the child
1098process, for future @samp{run} commands. For example,
e91b87a3 1099
1100@example
1101tty /dev/ttyb
1102@end example
1103
1104@noindent
4187119d 1105directs that processes started with subsequent @samp{run} commands
1106default to do input and output on the terminal @file{/dev/ttyb} and have
1107that as their controlling terminal.
1108
1109An explicit redirection in @samp{run} overrides the @samp{tty} command's
1110effect on input/output redirection, but not its effect on the
1111controlling terminal.
e91b87a3 1112
1113When you use the @samp{tty} command or redirect input in the @samp{run}
4187119d 1114command, only the @emph{input for your program} is affected. The input
1115for GDB still comes from your terminal.
e91b87a3 1116
4187119d 1117@node Attach, Kill Process, Input/Output, Running
e91b87a3 1118@section Debugging an Already-Running Process
1119@kindex detach
1120@kindex attach
1121@cindex attach
1122
9c91ee3e
RP
1123@table @code
1124@item attach @var{process--id}
1125@itemx attach @var{device}
1126This command attaches to another target, of the same type as your last
1127@samp{target} command (@samp{info files} will show your target stack).
1128The command may take as argument a process ID or a device file.
1129
1130You specify a process ID to debug an already-running process that was
1131started outside of GDB. (The usual way to find out the process-id of
1132the process is with the @code{ps} utility, or with the @code{jobs -l}
1133shell command.) In this case, you must have permission to send the
1134process a signal, and it must have the same effective user ID as the
1135debugger.
1136@end table
e91b87a3 1137
9c91ee3e
RP
1138When using @samp{attach}, you should first use the @samp{file} command
1139to specify the program running in the process and load its symbol table.
e91b87a3 1140
1141The first thing GDB does after arranging to debug the process is to stop
1142it. You can examine and modify an attached process with all the GDB
1143commands that ordinarily available when you start processes with
1144@samp{run}. You can insert breakpoints; you can step and continue; you
1145can modify storage. If you would rather the process continue running,
4187119d 1146you may use the @samp{continue} command after attaching GDB to the
1147process.
e91b87a3 1148
4187119d 1149When you have finished debugging the attached process, you can use the
e91b87a3 1150@samp{detach} command to release it from GDB's control. Detaching
1151the process continues its execution. After the @samp{detach} command,
1152that process and GDB become completely independent once more, and you
1153are ready to @samp{attach} another process or start one with @samp{run}.
1154
1155If you exit GDB or use the @samp{run} command while you have an attached
9c91ee3e
RP
1156process, you kill that process. By default, you will be asked for
1157confirmation if you try to do either of these things; you can control
1158whether or not this happens by using the @samp{set stupidity} command
1159(@pxref{User Interface}).
e91b87a3 1160
4187119d 1161The @samp{attach} command is also used to debug a remote machine via a
831c8511 1162serial connection. @xref{Remote}, for more info.
4187119d 1163
1164@node Kill Process,, Attach, Running
1165@section Killing the Child Process
1166
1167@table @code
1168@item kill
1169@kindex kill
1170Kill the child process in which the program being debugged is running
1171under GDB.
9c91ee3e 1172@end table
4187119d 1173
1174This command is useful if you wish to debug a core dump instead. GDB
1175ignores any core dump file if it is actually running the program, so the
1176@samp{kill} command is the only sure way to make sure the core dump file
1177is used once again.
1178
9c91ee3e
RP
1179On some operating systems, you can't execute your program in another
1180process while it is active inside GDB. The @samp{kill} command is also
1181useful in this situation, if you wish to run the program outside the
1182debugger.
4187119d 1183
1184The @samp{kill} command is also useful if you wish to recompile and
1185relink the program, since on many systems it is impossible to modify an
9c91ee3e
RP
1186executable file which is running in a process. In this case, when you
1187next type @samp{run}, GDB will notice that the file has changed, and
1188will re-read the symbol table (while trying to preserve your current
1189breakpoint settings).
4187119d 1190
e91b87a3 1191@node Stopping, Stack, Running, Top
1192@chapter Stopping and Continuing
1193
4187119d 1194When you run a program normally, it runs until it terminates. The
1195principal purpose of using a debugger is so that you can stop it before
1196that point; or so that if the program runs into trouble you can
1197investigate and find out why.
e91b87a3 1198
1199@menu
1200* Signals:: Fatal signals in your program just stop it;
1201 then you can use GDB to see what is going on.
1202* Breakpoints:: Breakpoints let you stop your program when it
1203 reaches a specified point in the code.
96a816c5 1204 an expression changes.
e91b87a3 1205* Continuing:: Resuming execution until the next signal or breakpoint.
1206* Stepping:: Stepping runs the program a short distance and
1207 then stops it wherever it has come to.
1208@end menu
1209
1210@node Signals, Breakpoints, Stopping, Stopping
1211@section Signals
4187119d 1212@cindex signals
e91b87a3 1213
1214A signal is an asynchronous event that can happen in a program. The
1215operating system defines the possible kinds of signals, and gives each kind
1216a name and a number. For example, @code{SIGINT} is the signal a program
1217gets when you type @kbd{Ctrl-c}; @code{SIGSEGV} is the signal a program
1218gets from referencing a place in memory far away from all the areas in use;
1219@code{SIGALRM} occurs when the alarm clock timer goes off (which happens
1220only if the program has requested an alarm).
1221
4187119d 1222@cindex fatal signals
e91b87a3 1223Some signals, including @code{SIGALRM}, are a normal part of the
1224functioning of the program. Others, such as @code{SIGSEGV}, indicate
1225errors; these signals are @dfn{fatal} (kill the program immediately) if the
1226program has not specified in advance some other way to handle the signal.
1227@code{SIGINT} does not indicate an error in the program, but it is normally
1228fatal so it can carry out the purpose of @kbd{Ctrl-c}: to kill the program.
1229
1230GDB has the ability to detect any occurrence of a signal in the program
1231running under GDB's control. You can tell GDB in advance what to do for
1232each kind of signal.
1233
4187119d 1234@cindex handling signals
e91b87a3 1235Normally, GDB is set up to ignore non-erroneous signals like @code{SIGALRM}
1236(so as not to interfere with their role in the functioning of the program)
1237but to stop the program immediately whenever an error signal happens.
831c8511 1238You can change these settings with the @samp{handle} command.
e91b87a3 1239
1240@table @code
1241@item info signal
1242@kindex info signal
1243Print a table of all the kinds of signals and how GDB has been told to
1244handle each one. You can use this to see the signal numbers of all
1245the defined types of signals.
1246
831c8511 1247@item handle @var{signal} @var{keywords}@dots{}
e91b87a3 1248@kindex handle
831c8511
JG
1249Change the way GDB handles signal @var{signal}. @var{signal} can be the
1250number of a signal or its name (with or without the @samp{SIG} at the
1251beginning). The @var{keywords} say what change to make.
e91b87a3 1252@end table
1253
e91b87a3 1254The keywords allowed by the handle command can be abbreviated. Their full
1255names are
1256
1257@table @code
1258@item stop
1259GDB should stop the program when this signal happens. This implies
1260the @samp{print} keyword as well.
1261
1262@item print
1263GDB should print a message when this signal happens.
1264
1265@item nostop
1266GDB should not stop the program when this signal happens. It may
1267still print a message telling you that the signal has come in.
1268
1269@item noprint
1270GDB should not mention the occurrence of the signal at all. This
1271implies the @samp{nostop} keyword as well.
1272
1273@item pass
1274GDB should allow the program to see this signal; the program will be
1275able to handle the signal, or may be terminated if the signal is fatal
1276and not handled.
1277
1278@item nopass
1279GDB should not allow the program to see this signal.
1280@end table
1281
1282When a signal has been set to stop the program, the program cannot see the
1283signal until you continue. It will see the signal then, if @samp{pass} is
1284in effect for the signal in question @i{at that time}. In other words,
1285after GDB reports a signal, you can use the @samp{handle} command with
1286@samp{pass} or @samp{nopass} to control whether that signal will be seen by
1287the program when you later continue it.
1288
1289You can also use the @samp{signal} command to prevent the program from
1290seeing a signal, or cause it to see a signal it normally would not see,
1291or to give it any signal at any time. @xref{Signaling}.
1292
96a816c5 1293@node Breakpoints, Watchpoints Continuing, Signals, Stopping
e91b87a3 1294@section Breakpoints
1295
1296@cindex breakpoints
1297A @dfn{breakpoint} makes your program stop whenever a certain point in the
1298program is reached. You set breakpoints explicitly with GDB commands,
1299specifying the place where the program should stop by line number, function
1300name or exact address in the program. You can add various other conditions
1301to control whether the program will stop.
1302
1303Each breakpoint is assigned a number when it is created; these numbers are
1304successive integers starting with 1. In many of the commands for controlling
1305various features of breakpoints you use the breakpoint number to say which
1306breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
1307@dfn{disabled}; if disabled, it has no effect on the program until you
1308enable it again.
1309
9c91ee3e 1310@table @code
e91b87a3 1311@kindex info break
1312@kindex $_
9c91ee3e 1313@item info break
e91b87a3 1314The command @samp{info break} prints a list of all breakpoints set and not
4187119d 1315deleted, showing their numbers, where in the program they are, and any
e91b87a3 1316special features in use for them. Disabled breakpoints are included in the
1317list, but marked as disabled. @samp{info break} with a breakpoint number
4187119d 1318as argument lists only that breakpoint. The convenience variable @code{$_}
e91b87a3 1319and the default examining-address for the @samp{x} command are set to the
1320address of the last breakpoint listed (@pxref{Memory}).
1321
96a816c5
JG
1322@kindex info watch
1323@item info watch
1324This command prints a list of watchpoints.
9c91ee3e
RP
1325
1326@cindex watchpoints
1327A @dfn{watchpoint} is a special breakpoint that stops your program when
1328the value of an expression changes. You can use a watchpoint to stop
1329execution whenever the value of an expression changes, without having to
1330predict a particular place in the inferior process where this may
1331happen. Aside from the different syntax in setting a watchpoint, it is
1332managed exactly like any other breakpoint and is enabled, disabled, and
1333deleted exactly like any other breakpoint.
1334
1335
1336
6ad6aa52 1337@end table
96a816c5 1338
e91b87a3 1339@menu
1340* Set Breaks:: How to establish breakpoints.
4187119d 1341* Delete Breaks:: How to remove breakpoints no longer needed.
e91b87a3 1342* Disabling:: How to disable breakpoints (turn them off temporarily).
1343* Conditions:: Making extra conditions on whether to stop.
1344* Break Commands:: Commands to be executed at a breakpoint.
1345* Error in Breakpoints:: "Cannot insert breakpoints" error--why, what to do.
1346@end menu
1347
4187119d 1348@node Set Breaks, Delete Breaks, Breakpoints, Breakpoints
e91b87a3 1349@subsection Setting Breakpoints
1350
1351@kindex break
96a816c5 1352@kindex watch
e91b87a3 1353Breakpoints are set with the @samp{break} command (abbreviated @samp{b}).
96a816c5
JG
1354Watchpoints are set with the @samp{watch} command.
1355
e91b87a3 1356You have several ways to say where the breakpoint should go.
1357
1358@table @code
1359@item break @var{function}
1360Set a breakpoint at entry to function @var{function}.
1361
4187119d 1362@item break @var{+offset}
1363@itemx break @var{-offset}
1364Set a breakpoint some number of lines forward or back from the position
1365at which execution stopped in the currently selected frame.
1366
e91b87a3 1367@item break @var{linenum}
1368Set a breakpoint at line @var{linenum} in the current source file.
1369That file is the last file whose source text was printed. This
1370breakpoint will stop the program just before it executes any of the
1371code on that line.
1372
1373@item break @var{filename}:@var{linenum}
1374Set a breakpoint at line @var{linenum} in source file @var{filename}.
1375
1376@item break @var{filename}:@var{function}
1377Set a breakpoint at entry to function @var{function} found in file
4187119d 1378@var{filename}. Specifying a file name as well as a function name is
e91b87a3 1379superfluous except when multiple files contain similarly named
1380functions.
1381
1382@item break *@var{address}
1383Set a breakpoint at address @var{address}. You can use this to set
1384breakpoints in parts of the program which do not have debugging
1385information or source files.
1386
1387@item break
1388Set a breakpoint at the next instruction to be executed in the selected
1389stack frame (@pxref{Stack}). In any selected frame but the innermost,
1390this will cause the program to stop as soon as control returns to that
1391frame. This is equivalent to a @samp{finish} command in the frame
4187119d 1392inside the selected frame. If this is done in the innermost frame, GDB
e91b87a3 1393will stop the next time it reaches the current location; this may be
4187119d 1394useful inside of loops.
1395
1396GDB normally ignores breakpoints when it resumes execution, until at
1397least one instruction has been executed. If it did not do this, you
1398would be unable to proceed past a breakpoint without first disabling the
1399breakpoint. This rule applies whether or not the breakpoint already
1400existed when the program stopped.
e91b87a3 1401
1402@item break @dots{} if @var{cond}
1403Set a breakpoint with condition @var{cond}; evaluate the expression
1404@var{cond} each time the breakpoint is reached, and stop only if the
1405value is nonzero. @samp{@dots{}} stands for one of the possible
1406arguments described above (or no argument) specifying where to break.
1407@xref{Conditions}, for more information on breakpoint conditions.
1408
1409@item tbreak @var{args}
1410@kindex tbreak
1411Set a breakpoint enabled only for one stop. @var{args} are the
1412same as in the @samp{break} command, and the breakpoint is set in the same
4187119d 1413way, but the breakpoint is automatically disabled the first time it
1414is hit. @xref{Disabling}.
96a816c5 1415
6ad6aa52
RP
1416@item rbreak @var{regex}
1417@kindex rbreak
1418Set a breakpoint on all functions matching @var{regex}. This is
1419useful for setting breakpoints on overloaded functions that are not
1420members of any special classes. This command sets an unconditional
1421breakpoint on all matches, printing a list of all breakpoints it set.
1422Once these breakpoints are set, they are treated just like the
1423breakpoints set with the @samp{break} command. They can be deleted,
1424disabled, made conditional, etc., in the standard ways.
1425
96a816c5 1426@kindex watch
9c91ee3e 1427@item watch @var{expr}
96a816c5 1428Set a watchpoint for an expression.
e91b87a3 1429@end table
1430
1431GDB allows you to set any number of breakpoints at the same place in the
1432program. There is nothing silly or meaningless about this. When the
1433breakpoints are conditional, this is even useful (@pxref{Conditions}).
1434
4187119d 1435@node Delete Breaks, Disabling, Set Breaks, Breakpoints
1436@subsection Deleting Breakpoints
e91b87a3 1437
96a816c5
JG
1438@cindex clearing breakpoints and watchpoints
1439@cindex deleting breakpoints and watchpoints
e91b87a3 1440It is often necessary to eliminate a breakpoint once it has done its job
1441and you no longer want the program to stop there. This is called
4187119d 1442@dfn{deleting} the breakpoint. A breakpoint that has been deleted no
1443longer exists in any sense; it is forgotten.
e91b87a3 1444
4187119d 1445With the @samp{clear} command you can delete breakpoints according to where
1446they are in the program. With the @samp{delete} command you can delete
e91b87a3 1447individual breakpoints by specifying their breakpoint numbers.
1448
4187119d 1449@b{It is not necessary to delete a breakpoint to proceed past it.} GDB
e91b87a3 1450automatically ignores breakpoints in the first instruction to be executed
4187119d 1451when you continue execution without changing the execution address.
e91b87a3 1452
1453@table @code
1454@item clear
1455@kindex clear
4187119d 1456Delete any breakpoints at the next instruction to be executed in the
e91b87a3 1457selected stack frame (@pxref{Selection}). When the innermost frame
4187119d 1458is selected, this is a good way to delete a breakpoint that the program
e91b87a3 1459just stopped at.
1460
1461@item clear @var{function}
1462@itemx clear @var{filename}:@var{function}
4187119d 1463Delete any breakpoints set at entry to the function @var{function}.
e91b87a3 1464
1465@item clear @var{linenum}
4187119d 1466@itemx clear @var{filename}:@var{linenum}
1467Delete any breakpoints set at or within the code of the specified line.
e91b87a3 1468
1469@item delete @var{bnums}@dots{}
1470@kindex delete
1471Delete the breakpoints of the numbers specified as arguments.
e91b87a3 1472@end table
1473
4187119d 1474@node Disabling, Conditions, Delete Breaks, Breakpoints
e91b87a3 1475@subsection Disabling Breakpoints
1476
1477@cindex disabled breakpoints
1478@cindex enabled breakpoints
4187119d 1479Rather than deleting a breakpoint, you might prefer to @dfn{disable} it.
1480This makes the breakpoint inoperative as if it had been deleted, but
e91b87a3 1481remembers the information on the breakpoint so that you can @dfn{enable}
1482it again later.
1483
1484You disable and enable breakpoints with the @samp{enable} and
1485@samp{disable} commands, specifying one or more breakpoint numbers as
1486arguments. Use @samp{info break} to print a list of breakpoints if you
1487don't know which breakpoint numbers to use.
1488
1489A breakpoint can have any of four different states of enablement:
1490
1491@itemize @bullet
1492@item
1493Enabled. The breakpoint will stop the program. A breakpoint made
1494with the @samp{break} command starts out in this state.
1495@item
1496Disabled. The breakpoint has no effect on the program.
1497@item
1498Enabled once. The breakpoint will stop the program, but
1499when it does so it will become disabled. A breakpoint made
1500with the @samp{tbreak} command starts out in this state.
1501@item
1502Enabled for deletion. The breakpoint will stop the program, but
1503immediately after it does so it will be deleted permanently.
1504@end itemize
1505
9c91ee3e 1506You can use the following commands to enable or disable a breakpoint:
e91b87a3 1507
1508@table @code
1509@item disable breakpoints @var{bnums}@dots{}
4187119d 1510@itemx disable @var{bnums}@dots{}
e91b87a3 1511@kindex disable breakpoints
e91b87a3 1512@kindex disable
1513Disable the specified breakpoints. A disabled breakpoint has no
1514effect but is not forgotten. All options such as ignore-counts,
1515conditions and commands are remembered in case the breakpoint is
1516enabled again later.
1517
1518@item enable breakpoints @var{bnums}@dots{}
4187119d 1519@itemx enable @var{bnums}@dots{}
e91b87a3 1520@kindex enable breakpoints
e91b87a3 1521@kindex enable
1522Enable the specified breakpoints. They become effective once again in
1523stopping the program, until you specify otherwise.
1524
1525@item enable breakpoints once @var{bnums}@dots{}
4187119d 1526@itemx enable once @var{bnums}@dots{}
e91b87a3 1527Enable the specified breakpoints temporarily. Each will be disabled
1528again the next time it stops the program (unless you have used one of
1529these commands to specify a different state before that time comes).
1530
1531@item enable breakpoints delete @var{bnums}@dots{}
4187119d 1532@itemx enable delete @var{bnums}@dots{}
e91b87a3 1533Enable the specified breakpoints to work once and then die. Each of
1534the breakpoints will be deleted the next time it stops the program
1535(unless you have used one of these commands to specify a different
1536state before that time comes).
1537@end table
1538
9c91ee3e
RP
1539Save for a breakpoint set with @samp{tbreak} (@pxref{Set Breaks},
1540breakpoints that you set are enabled or disabled only when you use one
1541of the commands above. (The command @samp{until} can set and delete a
1542breakpoint on its own, but it will not change the state of your
1543breakpoints).
e91b87a3 1544
1545@node Conditions, Break Commands, Disabling, Breakpoints
1546@subsection Break Conditions
4187119d 1547@cindex conditional breakpoints
1548@cindex breakpoint conditions
e91b87a3 1549
e91b87a3 1550The simplest sort of breakpoint breaks every time the program reaches a
4187119d 1551specified place. You can also specify a @dfn{condition} for a
1552breakpoint. A condition is just a boolean expression in your
1553programming language. (@xref{Expressions}). A breakpoint with a
1554condition evaluates the expression each time the program reaches it, and
1555the program stops only if the condition is true.
e91b87a3 1556
1557Break conditions may have side effects, and may even call functions in your
1558program. These may sound like strange things to do, but their effects are
1559completely predictable unless there is another enabled breakpoint at the
1560same address. (In that case, GDB might see the other breakpoint first and
1561stop the program without checking the condition of this one.) Note that
1562breakpoint commands are usually more convenient and flexible for the
1563purpose of performing side effects when a breakpoint is reached
1564(@pxref{Break Commands}).
1565
1566Break conditions can be specified when a breakpoint is set, by using
1567@samp{if} in the arguments to the @samp{break} command. @xref{Set Breaks}.
1568They can also be changed at any time with the @samp{condition} command:
1569
1570@table @code
1571@item condition @var{bnum} @var{expression}
1572@kindex condition
1573Specify @var{expression} as the break condition for breakpoint number
1574@var{bnum}. From now on, this breakpoint will stop the program only if
1575the value of @var{expression} is true (nonzero, in C). @var{expression}
1576is not evaluated at the time the @samp{condition} command is given.
1577@xref{Expressions}.
1578
1579@item condition @var{bnum}
1580Remove the condition from breakpoint number @var{bnum}. It becomes
1581an ordinary unconditional breakpoint.
1582@end table
1583
1584@cindex ignore count (of breakpoint)
4187119d 1585A special case of a breakpoint condition is to stop only when the
1586breakpoint has been reached a certain number of times. This is so
1587useful that there is a special way to do it, using the @dfn{ignore
1588count} of the breakpoint. Every breakpoint has an ignore count, which
1589is an integer. Most of the time, the ignore count is zero, and
1590therefore has no effect. But if the program reaches a breakpoint whose
1591ignore count is positive, then instead of stopping, it just decrements
1592the ignore count by one and continues. As a result, if the ignore count
1593value is @var{n}, the breakpoint will not stop the next @var{n} times it
1594is reached.
e91b87a3 1595
1596@table @code
1597@item ignore @var{bnum} @var{count}
1598@kindex ignore
1599Set the ignore count of breakpoint number @var{bnum} to @var{count}.
9c91ee3e
RP
1600The next @var{count} times the breakpoint is reached, your program's
1601execution will not stop; other than to decrement the ignore count, GDB
1602takes no action.
e91b87a3 1603
1604To make the breakpoint stop the next time it is reached, specify
1605a count of zero.
1606
1607@item cont @var{count}
1608Continue execution of the program, setting the ignore count of the
1609breakpoint that the program stopped at to @var{count} minus one.
4187119d 1610Thus, the program will not stop at this breakpoint until the
1611@var{count}'th time it is reached.
e91b87a3 1612
1613This command is allowed only when the program stopped due to a
1614breakpoint. At other times, the argument to @samp{cont} is ignored.
1615@end table
1616
1617If a breakpoint has a positive ignore count and a condition, the condition
1618is not checked. Once the ignore count reaches zero, the condition will
1619start to be checked.
1620
4187119d 1621Note that you could achieve the effect of the ignore count with a
1622condition such as @w{@samp{$foo-- <= 0}} using a debugger convenience
1623variable that is decremented each time. @xref{Convenience Vars}.
e91b87a3 1624
1625@node Break Commands, Error in Breakpoints, Conditions, Breakpoints
1626@subsection Commands Executed on Breaking
1627
1628@cindex breakpoint commands
1629You can give any breakpoint a series of commands to execute when the
1630program stops due to that breakpoint. For example, you might want to
1631print the values of certain expressions, or enable other breakpoints.
1632
1633@table @code
1634@item commands @var{bnum}
1635Specify commands for breakpoint number @var{bnum}. The commands
1636themselves appear on the following lines. Type a line containing just
1637@samp{end} to terminate the commands.
1638
1639To remove all commands from a breakpoint, use the command
1640@samp{commands} and follow it immediately by @samp{end}; that is, give
1641no commands.
1642
1643With no arguments, @samp{commands} refers to the last breakpoint set.
1644@end table
1645
9c91ee3e 1646You can use breakpoint commands to start the program up again.
e91b87a3 1647Simply use the @samp{cont} command, or @samp{step}, or any other command
1648to resume execution. However, any remaining breakpoint commands are
4187119d 1649ignored. When the program stops again, GDB will act according to the
1650cause of that stop.
e91b87a3 1651
1652@kindex silent
1653If the first command specified is @samp{silent}, the usual message about
1654stopping at a breakpoint is not printed. This may be desirable for
1655breakpoints that are to print a specific message and then continue.
1656If the remaining commands too print nothing, you will see no sign that
1657the breakpoint was reached at all. @samp{silent} is not really a command;
1658it is meaningful only at the beginning of the commands for a breakpoint.
1659
1660The commands @samp{echo} and @samp{output} that allow you to print precisely
1661controlled output are often useful in silent breakpoints. @xref{Output}.
1662
1663For example, here is how you could use breakpoint commands to print the
4187119d 1664value of @code{x} at entry to @code{foo} whenever it is positive.
e91b87a3 1665
1666@example
1667break foo if x>0
4187119d 1668commands
e91b87a3 1669silent
1670echo x is\040
1671output x
1672echo \n
1673cont
1674end
1675@end example
1676
1677One application for breakpoint commands is to correct one bug so you can
1678test another. Put a breakpoint just after the erroneous line of code, give
1679it a condition to detect the case in which something erroneous has been
1680done, and give it commands to assign correct values to any variables that
1681need them. End with the @samp{cont} command so that the program does not
1682stop, and start with the @samp{silent} command so that no output is
1683produced. Here is an example:
1684
1685@example
1686break 403
4187119d 1687commands
e91b87a3 1688silent
1689set x = y + 4
1690cont
1691end
1692@end example
1693
1694One deficiency in the operation of automatically continuing breakpoints
1695under Unix appears when your program uses raw mode for the terminal.
1696GDB switches back to its own terminal modes (not raw) before executing
1697commands, and then must switch back to raw mode when your program is
1698continued. This causes any pending terminal input to be lost.
1699
1700In the GNU system, this will be fixed by changing the behavior of
1701terminal modes.
1702
1703Under Unix, when you have this problem, you might be able to get around
1704it by putting your actions into the breakpoint condition instead of
1705commands. For example
1706
1707@example
1708condition 5 (x = y + 4), 0
1709@end example
1710
1711@noindent
4187119d 1712specifies a condition expression (@xref{Expressions}) that will change
1713@code{x} as needed, then always have the value 0 so the program will not
1714stop. Loss of input is avoided here because break conditions are
1715evaluated without changing the terminal modes. When you want to have
1716nontrivial conditions for performing the side effects, the operators
1717@samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
e91b87a3 1718
1719@node Error in Breakpoints,, Break Commands, Breakpoints
1720@subsection ``Cannot Insert Breakpoints'' Error
1721
4187119d 1722Under some operating systems, breakpoints cannot be used in a program if
1723any other process is running that program. Attempting to run or
9c91ee3e
RP
1724continue a program with a breakpoint in this case will cause GDB to
1725stop that program.
e91b87a3 1726
1727When this happens, you have three ways to proceed:
1728
1729@enumerate
1730@item
1731Remove or disable the breakpoints, then continue.
1732
1733@item
1734Suspend GDB, and copy the file containing the program to a new name.
1735Resume GDB and use the @samp{exec-file} command to specify that GDB
1736should run the program under that name. Then start the program again.
1737
1738@item
4187119d 1739Relink the program so that the text segment is nonsharable, using the
1740linker option @samp{-N}. The operating system limitation may not apply
1741to nonsharable executables.
e91b87a3 1742@end enumerate
1743
1744@node Continuing, Stepping, Breakpoints, Stopping
1745@section Continuing
1746
1747After your program stops, most likely you will want it to run some more if
1748the bug you are looking for has not happened yet.
1749
1750@table @code
1751@item cont
1752@kindex cont
1753Continue running the program at the place where it stopped.
1754@end table
1755
1756If the program stopped at a breakpoint, the place to continue running
1757is the address of the breakpoint. You might expect that continuing would
1758just stop at the same breakpoint immediately. In fact, @samp{cont}
1759takes special care to prevent that from happening. You do not need
4187119d 1760to delete the breakpoint to proceed through it after stopping at it.
e91b87a3 1761
1762You can, however, specify an ignore-count for the breakpoint that the
1763program stopped at, by means of an argument to the @samp{cont} command.
1764@xref{Conditions}.
1765
1766If the program stopped because of a signal other than @code{SIGINT} or
1767@code{SIGTRAP}, continuing will cause the program to see that signal.
1768You may not want this to happen. For example, if the program stopped
1769due to some sort of memory reference error, you might store correct
1770values into the erroneous variables and continue, hoping to see more
1771execution; but the program would probably terminate immediately as
1772a result of the fatal signal once it sees the signal. To prevent this,
1773you can continue with @samp{signal 0}. @xref{Signaling}. You can
1774also act in advance to prevent the program from seeing certain kinds
1775of signals, using the @samp{handle} command (@pxref{Signals}).
1776
1777@node Stepping,, Continuing, Stopping
1778@section Stepping
1779
1780@cindex stepping
1781@dfn{Stepping} means setting your program in motion for a limited time, so
1782that control will return automatically to the debugger after one line of
1783code or one machine instruction. Breakpoints are active during stepping
1784and the program will stop for them even if it has not gone as far as the
1785stepping command specifies.
1786
1787@table @code
1788@item step
1789@kindex step
4187119d 1790Continue running the program until control reaches a different line,
1791then stop it and return control to the debugger. This command is
1792abbreviated @samp{s}.
e91b87a3 1793
4187119d 1794This command may be given when control is within a function for which
e91b87a3 1795there is no debugging information. In that case, execution will proceed
4187119d 1796until control reaches a different function, or is about to return from
1797this function. An argument repeats this action.
1798
1799@item step @var{count}
1800Continue running as in @samp{step}, but do so @var{count} times. If a
1801breakpoint is reached or a signal not related to stepping occurs before
1802@var{count} steps, stepping stops right away.
e91b87a3 1803
1804@item next
1805@kindex next
1806Similar to @samp{step}, but any function calls appearing within the line of
1807code are executed without stopping. Execution stops when control reaches a
1808different line of code at the stack level which was executing when the
1809@samp{next} command was given. This command is abbreviated @samp{n}.
1810
1811An argument is a repeat count, as in @samp{step}.
1812
4187119d 1813@samp{next} within a function without debugging information acts as does
e91b87a3 1814@samp{step}, but any function calls appearing within the code of the
4187119d 1815function are executed without stopping.
e91b87a3 1816
1817@item finish
1818@kindex finish
4187119d 1819Continue running until just after the selected stack frame returns (or
1820until there is some other reason to stop, such as a fatal signal or a
1821breakpoint). Print value returned by the selected stack frame (if any).
e91b87a3 1822
1823Contrast this with the @samp{return} command (@pxref{Returning}).
1824
1825@item until
1826@kindex until
4187119d 1827This command is used to avoid single stepping through a loop more than
1828once. It is like the @samp{next} command, except that when @samp{until}
1829encounters a jump, it automatically continues execution until the
1830program counter is greater than the address of the jump.
1831
1832This means that when you reach the end of a loop after single stepping
1833though it, @samp{until} will cause the program to continue execution
1834until the loop is exited. In contrast, a @samp{next} command at the end
1835of a loop will simply step back to the beginning of the loop, which
1836would force you to step through the next iteration.
1837
1838@samp{until} always stops the program if it attempts to exit the current
1839stack frame.
1840
1841@samp{until} may produce somewhat counterintuitive results if the order
1842of the source lines does not match the actual order of execution. For
1843example, in a typical C @code{for}-loop, the third expression in the
1844@code{for}-statement (the loop-step expression) is executed after the
1845statements in the body of the loop, but is written before them.
1846Therefore, the @samp{until} command would appear to step back to the
1847beginning of the loop when it advances to this expression. However, it
1848has not really done so, not in terms of the actual machine code.
1849
1850Note that @samp{until} with no argument works by means of single
1851instruction stepping, and hence is slower than @samp{until} with an
1852argument.
e91b87a3 1853
1854@item until @var{location}
4187119d 1855Continue running the program until either the specified location is
9c91ee3e
RP
1856reached, or the current (innermost) stack frame returns. @var{location}
1857is any of the forms of argument acceptable to @samp{break} (@pxref{Set
1858Breaks}). This form of the command uses breakpoints, and hence is
1859quicker than @samp{until} without an argument.
e91b87a3 1860
1861@item stepi
1862@itemx si
1863@kindex stepi
1864@kindex si
4187119d 1865Execute one machine instruction, then stop and return to the debugger.
e91b87a3 1866
1867It is often useful to do @samp{display/i $pc} when stepping by machine
1868instructions. This will cause the next instruction to be executed to
1869be displayed automatically at each stop. @xref{Auto Display}.
1870
1871An argument is a repeat count, as in @samp{step}.
1872
1873@item nexti
1874@itemx ni
1875@kindex nexti
1876@kindex ni
4187119d 1877Execute one machine instruction, but if it is a subroutine call,
e91b87a3 1878proceed until the subroutine returns.
1879
1880An argument is a repeat count, as in @samp{next}.
1881@end table
1882
1883A typical technique for using stepping is to put a breakpoint
1884(@pxref{Breakpoints}) at the beginning of the function or the section of
1885the program in which a problem is believed to lie, and then step through
1886the suspect area, examining the variables that are interesting, until the
1887problem happens.
1888
1889The @samp{cont} command can be used after stepping to resume execution
1890until the next breakpoint or signal.
1891
1892@node Stack, Source, Stopping, Top
1893@chapter Examining the Stack
1894
1895When your program has stopped, the first thing you need to know is where it
1896stopped and how it got there.
1897
1898@cindex call stack
1899Each time your program performs a function call, the information about
1900where in the program the call was made from is saved in a block of data
1901called a @dfn{stack frame}. The frame also contains the arguments of the
1902call and the local variables of the function that was called. All the
1903stack frames are allocated in a region of memory called the @dfn{call
1904stack}.
1905
1906When your program stops, the GDB commands for examining the stack allow you
1907to see all of this information.
1908
1909One of the stack frames is @dfn{selected} by GDB and many GDB commands
1910refer implicitly to the selected frame. In particular, whenever you ask
1911GDB for the value of a variable in the program, the value is found in the
1912selected frame. There are special GDB commands to select whichever frame
1913you are interested in.
1914
1915When the program stops, GDB automatically selects the currently executing
1916frame and describes it briefly as the @samp{frame} command does
1917(@pxref{Frame Info, Info}).
1918
1919@menu
1920* Frames:: Explanation of stack frames and terminology.
1921* Backtrace:: Summarizing many frames at once.
1922* Selection:: How to select a stack frame.
1923* Info: Frame Info, Commands to print information on stack frames.
6ad6aa52 1924* Exception Handling: How GDB supports exception handling for C++.
e91b87a3 1925@end menu
1926
1927@node Frames, Backtrace, Stack, Stack
1928@section Stack Frames
1929
1930@cindex frame
4187119d 1931@cindex stack frame
1932The call stack is divided up into contiguous pieces called @dfn{stack
1933frames}, or @dfn{frames} for short; each frame is the data associated
1934with one call to one function. The frame contains the arguments given
1935to the function, the function's local variables, and the address at
1936which the function is executing.
e91b87a3 1937
1938@cindex initial frame
1939@cindex outermost frame
1940@cindex innermost frame
1941When your program is started, the stack has only one frame, that of the
1942function @code{main}. This is called the @dfn{initial} frame or the
1943@dfn{outermost} frame. Each time a function is called, a new frame is
1944made. Each time a function returns, the frame for that function invocation
1945is eliminated. If a function is recursive, there can be many frames for
1946the same function. The frame for the function in which execution is
1947actually occurring is called the @dfn{innermost} frame. This is the most
1948recently created of all the stack frames that still exist.
1949
1950@cindex frame pointer
1951Inside your program, stack frames are identified by their addresses. A
1952stack frame consists of many bytes, each of which has its own address; each
1953kind of computer has a convention for choosing one of those bytes whose
1954address serves as the address of the frame. Usually this address is kept
1955in a register called the @dfn{frame pointer register} while execution is
1956going on in that frame.
1957
1958@cindex frame number
1959GDB assigns numbers to all existing stack frames, starting with zero for
1960the innermost frame, one for the frame that called it, and so on upward.
1961These numbers do not really exist in your program; they are to give you a
1962way of talking about stack frames in GDB commands.
1963
1964@cindex selected frame
1965Many GDB commands refer implicitly to one stack frame. GDB records a stack
1966frame that is called the @dfn{selected} stack frame; you can select any
1967frame using one set of GDB commands, and then other commands will operate
1968on that frame. When your program stops, GDB automatically selects the
1969innermost frame.
1970
4187119d 1971@cindex frameless execution
1972Some functions can be compiled to run without a frame reserved for them
1973on the stack. This is occasionally done with heavily used library
1974functions to save the frame setup time. GDB has limited facilities for
1975dealing with these function invocations; if the innermost function
1976invocation has no stack frame, GDB will give it a virtual stack frame of
19770 and correctly allow tracing of the function call chain. Results are
1978undefined if a function invocation besides the innermost one is
1979frameless.
1980
e91b87a3 1981@node Backtrace, Selection, Frames, Stack
1982@section Backtraces
1983
1984A backtrace is a summary of how the program got where it is. It shows one
1985line per frame, for many frames, starting with the currently executing
1986frame (frame zero), followed by its caller (frame one), and on up the
1987stack.
1988
1989@table @code
1990@item backtrace
1991@itemx bt
4187119d 1992@kindex backtrace
1993@kindex bt
e91b87a3 1994Print a backtrace of the entire stack: one line per frame for all
1995frames in the stack.
1996
1997You can stop the backtrace at any time by typing the system interrupt
1998character, normally @kbd{Control-C}.
1999
2000@item backtrace @var{n}
2001@itemx bt @var{n}
4187119d 2002Similar, but print only the innermost @var{n} frames.
e91b87a3 2003
2004@item backtrace @var{-n}
2005@itemx bt @var{-n}
4187119d 2006Similar, but print only the outermost @var{n} frames.
e91b87a3 2007@end table
2008
4187119d 2009@kindex where
2010@kindex info stack
2011The names @samp{where} and @samp{info stack} are additional aliases
2012for @samp{backtrace}.
2013
2014Every line in the backtrace shows the frame number, the function name
2015and the program counter value.
2016
2017If the function is in a source file whose symbol table data has been
2018fully read, the backtrace shows the source file name and line number, as
2019well as the arguments to the function. (The program counter value is
2020omitted if it is at the beginning of the code for that line number.)
2021
4187119d 2022Here is an example of a backtrace. It was made with the command
2023@samp{bt 3}, so it shows the innermost three frames.
2024
2025@example
9c91ee3e
RP
2026#0 rtx_equal_p (x=(rtx) 0x8e58c, y=(rtx) 0x1086c4) \
2027(/gp/rms/cc/rtlanal.c line 337)
4187119d 2028#1 0x246b0 in expand_call (...) (...)
2029#2 0x21cfc in expand_expr (...) (...)
2030(More stack frames follow...)
2031@end example
2032
2033@noindent
2034The functions @code{expand_call} and @code{expand_expr} are in a file
2035whose symbol details have not been fully read. Full detail is available
2036for the function @code{rtx_equal_p}, which is in the file
2037@file{rtlanal.c}. Its arguments, named @code{x} and @code{y}, are shown
2038with their typed values.
e91b87a3 2039
2040@node Selection, Frame Info, Backtrace, Stack
2041@section Selecting a Frame
2042
2043Most commands for examining the stack and other data in the program work on
2044whichever stack frame is selected at the moment. Here are the commands for
2045selecting a stack frame; all of them finish by printing a brief description
2046of the stack frame just selected.
2047
2048@table @code
2049@item frame @var{n}
2050@kindex frame
2051Select frame number @var{n}. Recall that frame zero is the innermost
2052(currently executing) frame, frame one is the frame that called the
2053innermost one, and so on. The highest-numbered frame is @code{main}'s
2054frame.
2055
2056@item frame @var{addr}
2057Select the frame at address @var{addr}. This is useful mainly if the
2058chaining of stack frames has been damaged by a bug, making it
2059impossible for GDB to assign numbers properly to all frames. In
2060addition, this can be useful when the program has multiple stacks and
2061switches between them.
2062
2063@item up @var{n}
2064@kindex up
2065Select the frame @var{n} frames up from the frame previously selected.
2066For positive numbers @var{n}, this advances toward the outermost
2067frame, to higher frame numbers, to frames that have existed longer.
2068@var{n} defaults to one.
2069
2070@item down @var{n}
2071@kindex down
2072Select the frame @var{n} frames down from the frame previously
2073selected. For positive numbers @var{n}, this advances toward the
2074innermost frame, to lower frame numbers, to frames that were created
2075more recently. @var{n} defaults to one.
2076@end table
2077
2078All of these commands end by printing some information on the frame that
2079has been selected: the frame number, the function name, the arguments, the
2080source file and line number of execution in that frame, and the text of
2081that source line. For example:
2082
2083@example
2084#3 main (argc=3, argv=??, env=??) at main.c, line 67
208567 read_input_file (argv[i]);
2086@end example
2087
2088After such a printout, the @samp{list} command with no arguments will print
2089ten lines centered on the point of execution in the frame. @xref{List}.
2090
6ad6aa52 2091@node Frame Info, Exception Handling, Selection, Stack
e91b87a3 2092@section Information on a Frame
2093
2094There are several other commands to print information about the selected
2095stack frame.
2096
2097@table @code
2098@item frame
2099This command prints a brief description of the selected stack frame.
2100It can be abbreviated @samp{f}. With an argument, this command is
2101used to select a stack frame; with no argument, it does not change
2102which frame is selected, but still prints the same information.
2103
2104@item info frame
2105@kindex info frame
2106This command prints a verbose description of the selected stack frame,
2107including the address of the frame, the addresses of the next frame in
2108(called by this frame) and the next frame out (caller of this frame),
2109the address of the frame's arguments, the program counter saved in it
2110(the address of execution in the caller frame), and which registers
2111were saved in the frame. The verbose description is useful when
2112something has gone wrong that has made the stack format fail to fit
2113the usual conventions.
2114
2115@item info frame @var{addr}
2116Print a verbose description of the frame at address @var{addr},
2117without selecting that frame. The selected frame remains unchanged by
2118this command.
2119
2120@item info args
2121@kindex info args
2122Print the arguments of the selected frame, each on a separate line.
2123
2124@item info locals
2125@kindex info locals
2126Print the local variables of the selected frame, each on a separate
2127line. These are all variables declared static or automatic within all
2128program blocks that execution in this frame is currently inside of.
e91b87a3 2129
6ad6aa52
RP
2130@item info catch
2131@kindex info catch
2132Print a list of all the exception handlers that are active in the
2133current stack frame given the current value of @code{pc}. To see
2134other exception handlers of higher frames, visit the higher frame
2135(using the @samp{up} command) and type @samp{info catch}.
2136@end table
2137
2138@node Exception Handling,, Frame Info, Stack
2139
2140Some languages, such as GNU C++, implement exception handling. GDB
2141can be used to examine what caused the program to raise an exception
2142and to list the exceptions the program is prepared to handle at a
2143given point in time.
2144
2145@cindex raise exceptions
2146GNU C++ raises an exception by calling a library function named
2147@code{__raise_exception} which has the following ANSI C interface:
2148
2149@example
2150 /* ADDR is where the exception identifier is stored.
2151 ID is the exception identifier. */
2152 void __raise_exception (void **addr, void *id);
2153@end example
2154
2155@noindent
2156By setting a breakpoint on @code{__raise_exception}
2157(@xref{Breakpoints}), all exceptions that a program raises will be
2158first caught by the debugger before any stack unwinding has taken
2159place. If you set a breakpoint in an exception handler instead of at
2160the point of the raise, you will likely not easily have the
2161information needed to know from where the exception was raised.
2162
9c91ee3e 2163By using a conditional breakpoint (@xref{Conditions}), you can cause
6ad6aa52
RP
2164the debugger to stop only when a specific exception is raised.
2165Multiple conditional breakpoints can be used to stop the program when
2166any of a number of exceptions are raised.
2167
2168@cindex catch exceptions
2169To examine the exceptions that a piece of a program is prepared to
2170catch, the @samp{info catch} function is used. This function shows
2171all exception handlers that are active in the current frame (for the
2172current value of the program counter). By traversing frames (using
2173the @samp{up} and @samp{down} commands), other exception handlers can
2174be observed.
2175
2176Breakpoints can be set at active exception handlers by using the
2177@samp{catch} command. The syntax is @samp{catch @var{exceptions}},
2178where @var{exceptions} is a list of names of exceptions to catch.
2179
2180There are currently some limitations to exception handling in GDB.
2181These will be corrected in a future release.
2182
2183@itemize @bullet
2184@item If you call a function interactively it will normally return
2185control to the user when it has finished executing. If the call
2186raises an exception however, the call may bypass the mechanism that
2187returns control to the user and cause the program to simply continue
2188running until it hits a breakpoint, catches a signal that GDB is
2189listening for, or exits.
2190@item You cannot raise an exception interactively.
2191@item You cannot interactively install an exception handler.
2192@end itemize
2193
e91b87a3 2194@node Source, Data, Stack, Top
2195@chapter Examining Source Files
2196
2197GDB knows which source files your program was compiled from, and
2198can print parts of their text. When your program stops, GDB
2199spontaneously prints the line it stopped in. Likewise, when you
2200select a stack frame (@pxref{Selection}), GDB prints the line
2201which execution in that frame has stopped in. You can also
2202print parts of source files by explicit command.
2203
2204@menu
2205* List:: Using the @samp{list} command to print source files.
2206* Search:: Commands for searching source files.
2207* Source Path:: Specifying the directories to search for source files.
2208@end menu
2209
2210@node List, Search, Source, Source
2211@section Printing Source Lines
2212
2213@kindex list
2214To print lines from a source file, use the @samp{list} command
2215(abbreviated @samp{l}). There are several ways to specify what part
2216of the file you want to print.
2217
2218Here are the forms of the @samp{list} command most commonly used:
2219
2220@table @code
2221@item list @var{linenum}
2222Print ten lines centered around line number @var{linenum} in the
2223current source file.
2224
2225@item list @var{function}
2226Print ten lines centered around the beginning of function
2227@var{function}.
2228
2229@item list
2230Print ten more lines. If the last lines printed were printed with a
2231@samp{list} command, this prints ten lines following the last lines
2232printed; however, if the last line printed was a solitary line printed
2233as part of displaying a stack frame (@pxref{Stack}), this prints ten
2234lines centered around that line.
2235
4187119d 2236@item list -
e91b87a3 2237Print ten lines just before the lines last printed.
2238@end table
2239
2240Repeating a @samp{list} command with @key{RET} discards the argument,
2241so it is equivalent to typing just @samp{list}. This is more useful
2242than listing the same lines again. An exception is made for an
2243argument of @samp{-}; that argument is preserved in repetition so that
2244each repetition moves up in the file.
2245
4187119d 2246@cindex linespec
e91b87a3 2247In general, the @samp{list} command expects you to supply zero, one or two
2248@dfn{linespecs}. Linespecs specify source lines; there are several ways
2249of writing them but the effect is always to specify some source line.
2250Here is a complete description of the possible arguments for @samp{list}:
2251
2252@table @code
2253@item list @var{linespec}
2254Print ten lines centered around the line specified by @var{linespec}.
2255
2256@item list @var{first},@var{last}
2257Print lines from @var{first} to @var{last}. Both arguments are
2258linespecs.
2259
2260@item list ,@var{last}
2261Print ten lines ending with @var{last}.
2262
2263@item list @var{first},
2264Print ten lines starting with @var{first}.
2265
2266@item list +
2267Print ten lines just after the lines last printed.
2268
4187119d 2269@item list -
e91b87a3 2270Print ten lines just before the lines last printed.
2271
2272@item list
2273As described in the preceding table.
2274@end table
2275
2276Here are the ways of specifying a single source line---all the
2277kinds of linespec.
2278
4187119d 2279@table @code
e91b87a3 2280@item @var{linenum}
2281Specifies line @var{linenum} of the current source file.
2282When a @samp{list} command has two linespecs, this refers to
2283the same source file as the first linespec.
2284
2285@item +@var{offset}
2286Specifies the line @var{offset} lines after the last line printed.
2287When used as the second linespec in a @samp{list} command that has
2288two, this specifies the line @var{offset} lines down from the
2289first linespec.
2290
4187119d 2291@item -@var{offset}
e91b87a3 2292Specifies the line @var{offset} lines before the last line printed.
2293
2294@item @var{filename}:@var{linenum}
2295Specifies line @var{linenum} in the source file @var{filename}.
2296
2297@item @var{function}
2298Specifies the line of the open-brace that begins the body of the
2299function @var{function}.
2300
2301@item @var{filename}:@var{function}
2302Specifies the line of the open-brace that begins the body of the
2303function @var{function} in the file @var{filename}. The file name is
2304needed with a function name only for disambiguation of identically
2305named functions in different source files.
2306
2307@item *@var{address}
2308Specifies the line containing the program address @var{address}.
2309@var{address} may be any expression.
2310@end table
2311
2312One other command is used to map source lines to program addresses.
2313
2314@table @code
2315@item info line @var{linenum}
2316@kindex info line
2317Print the starting and ending addresses of the compiled code for
2318source line @var{linenum}.
2319
2320@kindex $_
2321The default examine address for the @samp{x} command is changed to the
2322starting address of the line, so that @samp{x/i} is sufficient to
2323begin examining the machine code (@pxref{Memory}). Also, this address
4187119d 2324is saved as the value of the convenience variable @code{$_}
e91b87a3 2325(@pxref{Convenience Vars}).
2326@end table
2327
2328@node Search, Source Path, List, Source
2329@section Searching Source Files
2330@cindex searching
2331@kindex forward-search
2332@kindex reverse-search
2333
2334There are two commands for searching through the current source file for a
2335regular expression.
2336
2337The command @samp{forward-search @var{regexp}} checks each line, starting
2338with the one following the last line listed, for a match for @var{regexp}.
2339It lists the line that is found. You can abbreviate the command name
2340as @samp{fo}.
2341
2342The command @samp{reverse-search @var{regexp}} checks each line, starting
2343with the one before the last line listed and going backward, for a match
2344for @var{regexp}. It lists the line that is found. You can abbreviate
2345this command with as little as @samp{rev}.
2346
2347@node Source Path,, Search, Source
2348@section Specifying Source Directories
2349
2350@cindex source path
2351@cindex directories for source files
6ad6aa52
RP
2352Executable programs sometimes do not record the directories of the source
2353files from which they were compiled, just the names. Even when they do,
2354the directories could be moved between the compilation and your debugging
2355session. GDB remembers a list of directories to search for source files;
2356this is called the @dfn{source path}. Each time GDB wants a source file,
2357it tries all the directories in the list, in the order they are present
2358in the list, until it finds a file with the desired name. @b{Note that
2359the executable search path is @i{not} used for this purpose. Neither is
2360the current working directory, unless it happens to be in the source
2361path.}
0bed9994
JG
2362
2363If it can't find a source file in the source path, and the object program
2364records what directory it was compiled in, GDB tries that directory too.
2365If the source path is empty, and there is no record of the compilation
2366directory, GDB will, as a last resort, look in the current directory.
2367
2368Whenever you reset or rearrange the source path, GDB will clear out
2369any information it has cached about where source files are found, where
2370each line is in the file, etc.
e91b87a3 2371
2372@kindex directory
0bed9994
JG
2373When you start GDB, its source path is empty.
2374To add other directories, use the @samp{directory} command.
e91b87a3 2375
2376@table @code
4187119d 2377@item directory @var{dirnames...}
0bed9994 2378Add directory @var{dirname} to the front of the source path. Several
4187119d 2379directory names may be given to this command, separated by whitespace or
0bed9994
JG
2380@samp{:}. If a name is already in the source path, it is moved to the
2381front of the path, so it will be searched sooner.
e91b87a3 2382
2383@item directory
0bed9994 2384Reset the source path to empty again. This requires confirmation.
e91b87a3 2385
2386@item info directories
2387@kindex info directories
2388Print the source path: show which directories it contains.
2389@end table
2390
9c91ee3e
RP
2391Because the @samp{directory} command, when used with arguments, adds to
2392the front of the source path, it can affect files that GDB has already
2393found. If the source path contains directories that you do not want,
2394and these directories contain misleading files with names matching your
2395source files, the way to correct the situation is as follows:
e91b87a3 2396
2397@enumerate
2398@item
0bed9994 2399Use @samp{directory} with no argument to reset the source path to empty.
e91b87a3 2400
2401@item
2402Use @samp{directory} with suitable arguments to add any other
0bed9994
JG
2403directories you want in the source path. You can add all the directories
2404in one command.
e91b87a3 2405@end enumerate
2406
2407@node Data, Symbols, Source, Top
2408@chapter Examining Data
2409
2410@cindex printing data
2411@cindex examining data
2412@kindex print
4187119d 2413The usual way to examine data in your program is with the @samp{print}
e91b87a3 2414command (abbreviated @samp{p}). It evaluates and prints the value of any
9c91ee3e
RP
2415valid expression of the language the program is written in (for now, C
2416or C++).
e91b87a3 2417You type
2418
2419@example
2420print @var{exp}
2421@end example
2422
2423@noindent
9c91ee3e
RP
2424where @var{exp} is any valid expression (in the source language), and
2425the value of @var{exp} is printed in a format appropriate to its data
2426type.
e91b87a3 2427
2428A more low-level way of examining data is with the @samp{x} command.
2429It examines data in memory at a specified address and prints it in a
2430specified format.
2431
e91b87a3 2432@menu
2433* Expressions:: Expressions that can be computed and printed.
2434* Variables:: Using your program's variables in expressions.
2435* Assignment:: Setting your program's variables.
2436* Arrays:: Examining part of memory as an array.
4187119d 2437* Format Options:: Controlling how structures and arrays are printed.
2438* Output formats:: Specifying formats for printing values.
e91b87a3 2439* Memory:: Examining memory explicitly.
2440* Auto Display:: Printing certain expressions whenever program stops.
2441* Value History:: Referring to values previously printed.
2442* Convenience Vars:: Giving names to values for future reference.
2443* Registers:: Referring to and storing in machine registers.
2444@end menu
2445
2446@node Expressions, Variables, Data, Data
2447@section Expressions
2448
2449@cindex expressions
2450Many different GDB commands accept an expression and compute its value.
2451Any kind of constant, variable or operator defined by the programming
2452language you are using is legal in an expression in GDB. This includes
2453conditional expressions, function calls, casts and string constants.
2454It unfortunately does not include symbols defined by preprocessor
4187119d 2455@code{#define} commands.
e91b87a3 2456
2457Casts are supported in all languages, not just in C, because it is so
2458useful to cast a number into a pointer so as to examine a structure
2459at that address in memory.
2460
2461GDB supports three kinds of operator in addition to those of programming
2462languages:
2463
2464@table @code
2465@item @@
2466@samp{@@} is a binary operator for treating parts of memory as arrays.
2467@xref{Arrays}, for more information.
2468
2469@item ::
2470@samp{::} allows you to specify a variable in terms of the file or
2471function it is defined in. @xref{Variables}.
2472
2473@item @{@var{type}@} @var{addr}
2474Refers to an object of type @var{type} stored at address @var{addr} in
2475memory. @var{addr} may be any expression whose value is an integer or
2476pointer (but parentheses are required around nonunary operators, just as in
2477a cast). This construct is allowed regardless of what kind of data is
2478officially supposed to reside at @var{addr}.@refill
2479@end table
2480
2481@node Variables, Arrays, Expressions, Data
2482@section Program Variables
2483
2484The most common kind of expression to use is the name of a variable
2485in your program.
2486
2487Variables in expressions are understood in the selected stack frame
2488(@pxref{Selection}); they must either be global (or static) or be visible
2489according to the scope rules of the programming language from the point of
2490execution in that frame. This means that in the function
2491
2492@example
2493foo (a)
2494 int a;
2495@{
2496 bar (a);
2497 @{
2498 int b = test ();
2499 bar (b);
2500 @}
2501@}
2502@end example
2503
2504@noindent
2505the variable @code{a} is usable whenever the program is executing
2506within the function @code{foo}, but the variable @code{b} is visible
2507only while the program is executing inside the block in which @code{b}
2508is declared.
2509
2510As a special exception, you can refer to a variable or function whose
2511scope is a single source file even if the current execution point is not
2512in this file. But it is possible to have more than one such variable
2513or function with the same name (if they are in different source files).
2514In such a case, it is not defined which one you will get. If you wish,
2515you can specify any one of them using the colon-colon construct:
2516
2517@example
2518@var{block}::@var{variable}
2519@end example
2520
2521@noindent
2522Here @var{block} is the name of the source file whose variable you want.
2523
4187119d 2524@node Arrays, Format options, Variables, Data
e91b87a3 2525@section Artificial Arrays
2526
2527@cindex artificial array
2528It is often useful to print out several successive objects of the
2529same type in memory; a section of an array, or an array of
2530dynamically determined size for which only a pointer exists in the
2531program.
2532
2533This can be done by constructing an @dfn{artificial array} with the
2534binary operator @samp{@@}. The left operand of @samp{@@} should be
2535the first element of the desired array, as an individual object.
2536The right operand should be the length of the array. The result is
2537an array value whose elements are all of the type of the left argument.
2538The first element is actually the left argument; the second element
2539comes from bytes of memory immediately following those that hold the
2540first element, and so on. Here is an example. If a program says
2541
2542@example
2543int *array = (int *) malloc (len * sizeof (int));
2544@end example
2545
2546@noindent
2547you can print the contents of @code{array} with
2548
2549@example
2550p *array@@len
2551@end example
2552
2553The left operand of @samp{@@} must reside in memory. Array values made
2554with @samp{@@} in this way behave just like other arrays in terms of
2555subscripting, and are coerced to pointers when used in expressions.
2556(It would probably appear in an expression via the value history,
2557after you had printed it out.)
2558
4187119d 2559@node Format options, Output formats, Arrays, Data
2560@section Format options
2561
2562@cindex format options
2563GDB provides a few ways to control how arrays and structures are
2564printed.
2565
2566@table @code
2567@item info format
2568@kindex info format
2569Display the current settings for the format options.
2570
2571@item set array-max @var{number-of-elements}
2572@kindex set array-max
2573If GDB is printing a large array, it will stop printing after it has
2574printed the number of elements set by the @samp{set array-max} command.
2575This limit also applies to the display of strings.
2576
96a816c5
JG
2577@item set arrayprint
2578@itemx set arrayprint on
2579@kindex set arrayprint
2580GDB will pretty print arrays. This format is more convenient to read,
2581but uses more space. The default is off.
2582
2583@item set arrayprint off.
2584Return to compressed format for arrays.
2585
2586@item set vtblprint
2587@itemx set vtblprint on
9c91ee3e 2588@kindex set vtblprint
96a816c5
JG
2589
2590Pretty print C++ virtual function tables. The default is off.
2591
2592@item set vtblprint off
2593Do not pretty print C++ virtual arrays.
2594
2595@item set addressprint
2596@item set adressprint on
2597@kindex set addressprint
2598GDB will print memory addresses in stack traces and structure values.
2599The default is on.
2600
2601@item set addressprint off
2602Do not print addresses.
2603
2604GDB will pretty print C++ virtual function tables. The default is off.
2605
4187119d 2606@item set prettyprint on
2607@kindex set prettyprint
2608Cause GDB to print structures in an indented format with one member per
2609line, like this:
2610
2611@example
2612$1 = @{
2613 next = 0x0,
2614 flags = @{
2615 sweet = 1,
2616 sour = 1
2617 @},
2618 meat = 0x54 "Pork"
2619@}
2620@end example
2621
2622@item set prettyprint off
2623Cause GDB to print structures in a compact format, like this:
2624
2625@example
2626$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat = 0x54 "Pork"@}
2627@end example
2628
2629This is the default format.
2630
2631@item set unionprint on
2632@kindex set unionprint
2633Tell GDB to print unions which are contained in structures. This is the
2634default setting.
2635@item set unionprint off
2636Tell GDB not to print unions which are contained in structures.
2637
2638For example, given the declarations
2639
2640@example
2641typedef enum @{Tree, Bug@} Species;
2642typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
9c91ee3e 2643typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms;
4187119d 2644
2645struct thing @{
2646 Species it;
2647 union @{
2648 Tree_forms tree;
2649 Bug_forms bug;
2650 @} form;
2651@};
2652
2653struct thing foo = @{Tree, @{Acorn@}@};
2654@end example
2655
2656@noindent
2657with @samp{set unionprint on} in effect @samp{p foo} would print
2658
2659@example
2660$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
2661@end example
2662
2663@noindent
2664and with @samp{set unionprint off} in effect it would print
2665
2666@example
2667$1 = @{it = Tree, form = @{...@}@}
2668@end example
2669@end table
2670
2671@node Output formats, Memory, Format options, Data
2672@section Output formats
e91b87a3 2673
2674@cindex formatted output
2675@cindex output formats
2676GDB normally prints all values according to their data types. Sometimes
2677this is not what you want. For example, you might want to print a number
2678in hex, or a pointer in decimal. Or you might want to view data in memory
2679at a certain address as a character string or an instruction. These things
2680can be done with @dfn{output formats}.
2681
2682The simplest use of output formats is to say how to print a value
2683already computed. This is done by starting the arguments of the
2684@samp{print} command with a slash and a format letter. The format
2685letters supported are:
2686
2687@table @samp
2688@item x
2689Regard the bits of the value as an integer, and print the integer in
2690hexadecimal.
2691
2692@item d
2693Print as integer in signed decimal.
2694
2695@item u
2696Print as integer in unsigned decimal.
2697
2698@item o
2699Print as integer in octal.
2700
2701@item a
9c91ee3e
RP
2702Print as an address, both absolute in hex and as an offset from the
2703nearest preceding symbol.
e91b87a3 2704
2705@item c
2706Regard as an integer and print it as a character constant.
2707
2708@item f
2709Regard the bits of the value as a floating point number and print
2710using typical floating point syntax.
2711@end table
2712
2713For example, to print the program counter in hex (@pxref{Registers}), type
2714
2715@example
2716p/x $pc
2717@end example
2718
2719@noindent
2720Note that no space is required before the slash; this is because command
2721names in GDB cannot contain a slash.
2722
2723To reprint the last value in the value history with a different format,
2724you can use the @samp{print} command with just a format and no
2725expression. For example, @samp{p/x} reprints the last value in hex.
2726
4187119d 2727@node Memory, Auto Display, Output formats, Data
e91b87a3 2728@subsection Examining Memory
2729
2730@cindex examining memory
2731@kindex x
4187119d 2732The command @samp{x} (for `examine') can be used to examine memory
2733without reference to the program's data types. The format in which you
2734wish to examine memory is instead explicitly specified. The allowable
2735formats are a superset of the formats described in the previous section.
e91b87a3 2736
2737@samp{x} is followed by a slash and an output format specification,
2738followed by an expression for an address. The expression need not have
2739a pointer value (though it may); it is used as an integer, as the
4187119d 2740address of a byte of memory. @xref{Expressions} for more information on
2741expressions. For example, @samp{x/4xw $sp} prints the four words of
2742memory above the stack pointer in hexadecimal.
e91b87a3 2743
2744The output format in this case specifies both how big a unit of memory
2745to examine and how to print the contents of that unit. It is done
2746with one or two of the following letters:
2747
2748These letters specify just the size of unit to examine:
2749
2750@table @samp
2751@item b
2752Examine individual bytes.
2753
2754@item h
2755Examine halfwords (two bytes each).
2756
2757@item w
2758Examine words (four bytes each).
2759
2760@cindex word
2761Many assemblers and cpu designers still use `word' for a 16-bit quantity,
2762as a holdover from specific predecessor machines of the 1970's that really
2763did use two-byte words. But more generally the term `word' has always
2764referred to the size of quantity that a machine normally operates on and
4187119d 2765stores in its registers. This is 32 bits for all the machines that GDB
e91b87a3 2766runs on.
2767
2768@item g
2769Examine giant words (8 bytes).
2770@end table
2771
2772These letters specify just the way to print the contents:
2773
2774@table @samp
2775@item x
2776Print as integers in unsigned hexadecimal.
2777
2778@item d
2779Print as integers in signed decimal.
2780
2781@item u
2782Print as integers in unsigned decimal.
2783
2784@item o
2785Print as integers in unsigned octal.
2786
2787@item a
2788Print as an address, both absolute in hex and then relative
2789to a symbol defined as an address below it.
2790
2791@item c
2792Print as character constants.
2793
2794@item f
2795Print as floating point. This works only with sizes @samp{w} and
2796@samp{g}.
2797
2798@item s
2799Print a null-terminated string of characters. The specified unit size
2800is ignored; instead, the unit is however many bytes it takes to reach
2801a null character (including the null character).
2802
2803@item i
2804Print a machine instruction in assembler syntax (or nearly). The
2805specified unit size is ignored; the number of bytes in an instruction
2806varies depending on the type of machine, the opcode and the addressing
2807modes used.
2808@end table
2809
2810If either the manner of printing or the size of unit fails to be specified,
2811the default is to use the same one that was used last. If you don't want
2812to use any letters after the slash, you can omit the slash as well.
2813
2814You can also omit the address to examine. Then the address used is
2815just after the last unit examined. This is why string and instruction
2816formats actually compute a unit-size based on the data: so that the
2817next string or instruction examined will start in the right place.
2818The @samp{print} command sometimes sets the default address for
2819the @samp{x} command; when the value printed resides in memory, the
2820default is set to examine the same location. @samp{info line} also
2821sets the default for @samp{x}, to the address of the start of the
2822machine code for the specified line and @samp{info breakpoints} sets
2823it to the address of the last breakpoint listed.
2824
2825When you use @key{RET} to repeat an @samp{x} command, it does not repeat
2826exactly the same: the address specified previously (if any) is ignored, so
2827that the repeated command examines the successive locations in memory
2828rather than the same ones.
2829
2830You can examine several consecutive units of memory with one command by
2831writing a repeat-count after the slash (before the format letters, if any).
2832The repeat count must be a decimal integer. It has the same effect as
2833repeating the @samp{x} command that many times except that the output may
4187119d 2834be more compact with several units per line. For example,
e91b87a3 2835
2836@example
2837x/10i $pc
2838@end example
2839
2840@noindent
4187119d 2841prints ten instructions starting with the one to be executed next in the
e91b87a3 2842selected frame. After doing this, you could print another ten following
2843instructions with
2844
2845@example
2846x/10
2847@end example
2848
2849@noindent
2850in which the format and address are allowed to default.
2851
2852@kindex $_
2853@kindex $__
2854The addresses and contents printed by the @samp{x} command are not put in
2855the value history because there is often too much of them and they would
2856get in the way. Instead, GDB makes these values available for subsequent
4187119d 2857use in expressions as values of the convenience variables @code{$_} and
2858@code{$__}.
e91b87a3 2859
2860After an @samp{x} command, the last address examined is available for use
4187119d 2861in expressions in the convenience variable @code{$_}. The contents of that
2862address, as examined, are available in the convenience variable @code{$__}.
e91b87a3 2863
2864If the @samp{x} command has a repeat count, the address and contents saved
2865are from the last memory unit printed; this is not the same as the last
2866address printed if several units were printed on the last line of output.
2867
4187119d 2868@kindex disassemble
2869The specialized command @samp{disassemble} is also provided to dump a
2870range of memory as machine instructions. The default memory range is
2871the function surrounding the program counter of the selected frame. A
2872single argument to this command is a program counter value; the function
831c8511
JG
2873surrounding this value will be dumped. Two arguments (separated by one
2874or more spaces) specify a range of addresss (first inclusive, second
2875exclusive) to be dumped.
4187119d 2876
e91b87a3 2877@node Auto Display, Value History, Memory, Data
2878@section Automatic Display
4187119d 2879@cindex automatic display
2880@cindex display of expressions
e91b87a3 2881
2882If you find that you want to print the value of an expression frequently
2883(to see how it changes), you might want to add it to the @dfn{automatic
2884display list} so that GDB will print its value each time the program stops.
2885Each expression added to the list is given a number to identify it;
2886to remove an expression from the list, you specify that number.
2887The automatic display looks like this:
2888
2889@example
28902: foo = 38
28913: bar[5] = (struct hack *) 0x3804
2892@end example
2893
2894@noindent
2895showing item numbers, expressions and their current values.
2896
4187119d 2897If the expression refers to local variables, then it does not make sense
2898outside the lexical context for which it was set up. Such an expression
9c91ee3e
RP
2899is disabled when execution enters a context where one of its variables
2900is not defined. For example, if you give the command
2901@samp{display name} while inside a function with an argument
2902@code{name}, then this argument will be displayed while the program
2903continues to stop inside that function. When it stops elsewhere---where
2904there is no variable @samp{name}---display is disabled. The next time
2905your program stops where @samp{name} is meaningful, you can enable the
2906display expression once again.
4187119d 2907
e91b87a3 2908@table @code
2909@item display @var{exp}
2910@kindex display
2911Add the expression @var{exp} to the list of expressions to display
2912each time the program stops. @xref{Expressions}.
2913
2914@item display/@var{fmt} @var{exp}
2915For @var{fmt} specifying only a display format and not a size or
2916count, add the expression @var{exp} to the auto-display list but
2917arranges to display it each time in the specified format @var{fmt}.
2918
2919@item display/@var{fmt} @var{addr}
2920For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
2921number of units, add the expression @var{addr} as a memory address to
2922be examined each time the program stops. Examining means in effect
2923doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}.
2924
2925@item undisplay @var{dnums}@dots{}
4187119d 2926@itemx delete display @var{dnums}@dots{}
e91b87a3 2927@kindex delete display
4187119d 2928@kindex undisplay
e91b87a3 2929Remove item numbers @var{dnums} from the list of expressions to display.
2930
2931@item disable display @var{dnums}@dots{}
2932@kindex disable display
4187119d 2933Disable the display of item numbers @var{dnums}. A disabled display
2934item is not printed automatically, but is not forgotten. It may be
2935reenabled later.
e91b87a3 2936
2937@item enable display @var{dnums}@dots{}
2938@kindex enable display
2939Enable display of item numbers @var{dnums}. It becomes effective once
2940again in auto display of its expression, until you specify otherwise.
2941
2942@item display
2943Display the current values of the expressions on the list, just as is
2944done when the program stops.
2945
2946@item info display
2947@kindex info display
4187119d 2948Print the list of expressions previously set up to display
2949automatically, each one with its item number, but without showing the
2950values. This includes disabled expressions, which are marked as such.
2951It also includes expressions which would not be displayed right now
2952because they refer to automatic variables not currently available.
e91b87a3 2953@end table
2954
2955@node Value History, Convenience Vars, Auto Display, Data
2956@section Value History
2957
2958@cindex value history
2959Every value printed by the @samp{print} command is saved for the entire
2960session in GDB's @dfn{value history} so that you can refer to it in
2961other expressions.
2962
4187119d 2963@cindex @code{$}
2964@cindex @code{$$}
2965@cindex history number
e91b87a3 2966The values printed are given @dfn{history numbers} for you to refer to them
2967by. These are successive integers starting with 1. @samp{print} shows you
4187119d 2968the history number assigned to a value by printing @samp{$@var{num} = }
2969before the value; here @var{num} is the history number.
e91b87a3 2970
2971To refer to any previous value, use @samp{$} followed by the value's
2972history number. The output printed by @samp{print} is designed to remind
4187119d 2973you of this. Just @code{$} refers to the most recent value in the history,
2974and @code{$$} refers to the value before that.
e91b87a3 2975
2976For example, suppose you have just printed a pointer to a structure and
2977want to see the contents of the structure. It suffices to type
2978
2979@example
2980p *$
2981@end example
2982
2983If you have a chain of structures where the component @samp{next} points
4187119d 2984to the next one, you can print the contents of the next one with this:
e91b87a3 2985
2986@example
2987p *$.next
2988@end example
2989
4187119d 2990@noindent
e91b87a3 2991It might be useful to repeat this command many times by typing @key{RET}.
2992
2993Note that the history records values, not expressions. If the value of
4187119d 2994@code{x} is 4 and you type this command:
e91b87a3 2995
2996@example
2997print x
2998set x=5
2999@end example
3000
3001@noindent
3002then the value recorded in the value history by the @samp{print} command
4187119d 3003remains 4 even though the value of @code{x} has changed.
e91b87a3 3004
3005@table @code
4187119d 3006@item info values
3007@kindex info values
e91b87a3 3008Print the last ten values in the value history, with their item
3009numbers. This is like @samp{p $$9} repeated ten times, except that
4187119d 3010@samp{info values} does not change the history.
e91b87a3 3011
4187119d 3012@item info values @var{n}
e91b87a3 3013Print ten history values centered on history item number @var{n}.
4187119d 3014
3015@item info values +
3016Print ten history values just after the values last printed.
e91b87a3 3017@end table
3018
3019@node Convenience Vars, Registers, Value History, Data
3020@section Convenience Variables
3021
3022@cindex convenience variables
3023GDB provides @dfn{convenience variables} that you can use within GDB to
3024hold on to a value and refer to it later. These variables exist entirely
3025within GDB; they are not part of your program, and setting a convenience
3026variable has no effect on further execution of your program. That's why
3027you can use them freely.
3028
3029Convenience variables have names starting with @samp{$}. Any name starting
3030with @samp{$} can be used for a convenience variable, unless it is one of
3031the predefined set of register names (@pxref{Registers}).
3032
3033You can save a value in a convenience variable with an assignment
3034expression, just as you would set a variable in your program. Example:
3035
3036@example
3037set $foo = *object_ptr
3038@end example
3039
3040@noindent
4187119d 3041would save in @code{$foo} the value contained in the object pointed to by
e91b87a3 3042@code{object_ptr}.
3043
3044Using a convenience variable for the first time creates it; but its value
3045is @code{void} until you assign a new value. You can alter the value with
3046another assignment at any time.
3047
3048Convenience variables have no fixed types. You can assign a convenience
3049variable any type of value, even if it already has a value of a different
3050type. The convenience variable as an expression has whatever type its
3051current value has.
3052
3053@table @code
3054@item info convenience
3055@kindex info convenience
3056Print a list of convenience variables used so far, and their values.
3057Abbreviated @samp{i con}.
3058@end table
3059
3060One of the ways to use a convenience variable is as a counter to be
3061incremented or a pointer to be advanced. For example:
3062
3063@example
3064set $i = 0
3065print bar[$i++]->contents
3066@i{@dots{}repeat that command by typing @key{RET}.}
3067@end example
3068
3069Some convenience variables are created automatically by GDB and given
3070values likely to be useful.
3071
4187119d 3072@table @code
e91b87a3 3073@item $_
4187119d 3074The variable @code{$_} is automatically set by the @samp{x} command to
e91b87a3 3075the last address examined (@pxref{Memory}). Other commands which
4187119d 3076provide a default address for @samp{x} to examine also set @code{$_}
e91b87a3 3077to that address; these commands include @samp{info line} and @samp{info
3078breakpoint}.
3079
3080@item $__
4187119d 3081The variable @code{$__} is automatically set by the @samp{x} command
e91b87a3 3082to the value found in the last address examined.
3083@end table
3084
3085@node Registers,, Convenience Vars, Data
3086@section Registers
3087
3088@cindex registers
3089Machine register contents can be referred to in expressions as variables
3090with names starting with @samp{$}. The names of registers are different
3091for each machine; use @samp{info registers} to see the names used on your
4187119d 3092machine. The names @code{$pc} and @code{$sp} are used on all machines for
3093the program counter register and the stack pointer. Often @code{$fp} is
3094used for a register that contains a pointer to the current stack frame,
3095and @code{$ps} is used for a register that contains the processor
3096status. These standard register names may be available on your machine
3097even though the @code{info registers} command displays them with a
3098different name. For example, on the SPARC, @code{info registers}
3099displays the processor status register as @code{$psr} but you can also
3100refer to it as @code{$ps}.
e91b87a3 3101
3102GDB always considers the contents of an ordinary register as an integer
3103when the register is examined in this way. Some machines have special
3104registers which can hold nothing but floating point; these registers are
3105considered floating point. There is no way to refer to the contents of an
3106ordinary register as floating point value (although you can @emph{print}
3107it as a floating point value with @samp{print/f $@var{regname}}).
3108
3109Some registers have distinct ``raw'' and ``virtual'' data formats. This
3110means that the data format in which the register contents are saved by the
3111operating system is not the same one that your program normally sees. For
3112example, the registers of the 68881 floating point coprocessor are always
4187119d 3113saved in ``extended'' format, but all C programs expect to work with
e91b87a3 3114``double'' format. In such cases, GDB normally works with the virtual
3115format only (the format that makes sense for your program), but the
3116@samp{info registers} command prints the data in both formats.
3117
3118Register values are relative to the selected stack frame
3119(@pxref{Selection}). This means that you get the value that the register
3120would contain if all stack frames farther in were exited and their saved
3121registers restored. In order to see the real contents of all registers,
3122you must select the innermost frame (with @samp{frame 0}).
3123
3124Some registers are never saved (typically those numbered zero or one)
3125because they are used for returning function values; for these registers,
3126relativization makes no difference.
3127
3128@table @code
3129@item info registers
3130@kindex info registers
3131Print the names and relativized values of all registers.
3132
3133@item info registers @var{regname}
3134Print the relativized value of register @var{regname}. @var{regname}
3135may be any register name valid on the machine you are using, with
3136or without the initial @samp{$}.
3137@end table
3138
3139@subsection Examples
3140
3141You could print the program counter in hex with
3142
3143@example
3144p/x $pc
3145@end example
3146
3147@noindent
3148or print the instruction to be executed next with
3149
3150@example
3151x/i $pc
3152@end example
3153
3154@noindent
3155or add four to the stack pointer with
3156
3157@example
3158set $sp += 4
3159@end example
3160
3161@noindent
3162The last is a way of removing one word from the stack, on machines where
3163stacks grow downward in memory (most machines, nowadays). This assumes
4187119d 3164that the innermost stack frame is selected. Setting @code{$sp} is
e91b87a3 3165not allowed when other stack frames are selected.
3166
3167@node Symbols, Altering, Data, Top
3168@chapter Examining the Symbol Table
3169
9c91ee3e
RP
3170The commands described in this section allow you to inquire about the
3171symbols (names of variables, functions and types) defined in your
3172program. This information is found by GDB in the symbol table loaded by
3173the @samp{symbol-file} command; it is inherent in the text of your
3174program and does not change as the program executes.
e91b87a3 3175
3176@table @code
e91b87a3 3177@item info address @var{symbol}
3178@kindex info address
4187119d 3179Describe where the data for @var{symbol} is stored. For a register
3180variable, this says which register it is kept in. For a non-register
3181local variable, this prints the stack-frame offset at which the variable
3182is always stored.
3183
3184Note the contrast with @samp{print &@var{symbol}}, which does not work
3185at all for a register variables, and for a stack local variable prints
3186the exact address of the current instantiation of the variable.
e91b87a3 3187
831c8511
JG
3188@item whatis @var{exp}
3189@kindex whatis
3190Print the data type of expression @var{exp}. @var{exp} is not
3191actually evaluated, and any side-effecting operations (such as
3192assignments or function calls) inside it do not take place.
3193@xref{Expressions}.
3194
3195@item whatis
3196Print the data type of @code{$}, the last value in the value history.
3197
e91b87a3 3198@item ptype @var{typename}
3199@kindex ptype
3200Print a description of data type @var{typename}. @var{typename} may be
3201the name of a type, or for C code it may have the form
3202@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
3203@samp{enum @var{enum-tag}}.@refill
3204
831c8511
JG
3205@item ptype @var{exp}
3206Print a description of the type of expression @var{exp}. This is like
3207@samp{whatis} except it prints a detailed description, instead of just
3208the name of the type. For example, if the type of a variable is
3209@samp{struct complex @{double real; double imag;@}}, @samp{whatis} will
3210print @samp{struct complex} and @samp{ptype} will print @samp{struct
3211complex @{double real; double imag;@}}
3212
e91b87a3 3213@item info sources
3214@kindex info sources
3215Print the names of all source files in the program for which there
3216is debugging information.
3217
3218@item info functions
3219@kindex info functions
3220Print the names and data types of all defined functions.
3221
3222@item info functions @var{regexp}
3223Print the names and data types of all defined functions
3224whose names contain a match for regular expression @var{regexp}.
3225Thus, @samp{info fun step} finds all functions whose names
3226include @samp{step}; @samp{info fun ^step} finds those whose names
3227start with @samp{step}.
3228
3229@item info variables
3230@kindex info variables
3231Print the names and data types of all variables that are declared
4187119d 3232outside of functions (i.e., except for local variables).
e91b87a3 3233
3234@item info variables @var{regexp}
4187119d 3235Print the names and data types of all variables (except for local
3236variables) whose names contain a match for regular expression
e91b87a3 3237@var{regexp}.
3238
e91b87a3 3239
7a67dd45 3240@ignore
3241This was never implemented.
e91b87a3 3242@item info methods
4187119d 3243@itemx info methods @var{regexp}
e91b87a3 3244@kindex info methods
3245The @samp{info-methods} command permits the user to examine all defined
4187119d 3246methods within C++ program, or (with the @var{regexp} argument) a
3247specific set of methods found in the various C++ classes. Many
3248C++ classes provide a large number of methods. Thus, the output
3249from the @samp{ptype} command can be overwhelming and hard to use. The
3250@samp{info-methods} command filters the methods, printing only those
3251which match the regular-expression @var{regexp}.
7a67dd45 3252@end ignore
e91b87a3 3253
3254@item printsyms @var{filename}
3255@kindex printsyms
3256Write a complete dump of the debugger's symbol data into the
3257file @var{filename}.
3258@end table
3259
3260@node Altering, Sequences, Symbols, Top
3261@chapter Altering Execution
3262
9c91ee3e 3263Once you think you have found an error in the program, you might want to
4187119d 3264find out for certain whether correcting the apparent error would lead to
3265correct results in the rest of the run. You can find the answer by
3266experiment, using the GDB features for altering execution of the
3267program.
3268
3269For example, you can store new values into variables or memory
3270locations, give the program a signal, restart it at a different address,
3271or even return prematurely from a function to its caller.
e91b87a3 3272
3273@menu
3274* Assignment:: Altering variable values or memory contents.
3275* Jumping:: Altering control flow.
3276* Signaling:: Making signals happen in the program.
3277* Returning:: Making a function return prematurely.
3278@end menu
3279
3280@node Assignment, Jumping, Altering, Altering
3281@section Assignment to Variables
3282
3283@cindex assignment
3284@cindex setting variables
3285To alter the value of a variable, evaluate an assignment expression.
3286@xref{Expressions}. For example,
3287
3288@example
3289print x=4
3290@end example
3291
3292@noindent
3293would store the value 4 into the variable @code{x}, and then print
3294the value of the assignment expression (which is 4).
3295
4187119d 3296All the assignment operators of C are supported, including the
3297incrementation operators @samp{++} and @samp{--}, and combining
3298assignments such as @samp{+=} and @samp{<<=}.
3299
e91b87a3 3300@kindex set
3301@kindex set variable
3302If you are not interested in seeing the value of the assignment, use the
3303@samp{set} command instead of the @samp{print} command. @samp{set} is
3304really the same as @samp{print} except that the expression's value is not
3305printed and is not put in the value history (@pxref{Value History}). The
3306expression is evaluated only for side effects.
3307
3308Note that if the beginning of the argument string of the @samp{set} command
3309appears identical to a @samp{set} subcommand, it may be necessary to use
3310the @samp{set variable} command. This command is identical to @samp{set}
3311except for its lack of subcommands.
3312
3313GDB allows more implicit conversions in assignments than C does; you can
3314freely store an integer value into a pointer variable or vice versa, and
3315any structure can be converted to any other structure that is the same
3316length or shorter.
9c91ee3e
RP
3317@comment FIXME: how do structs align/pad in these conversions?
3318@comment /[email protected] 18dec1990
e91b87a3 3319
4187119d 3320To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
e91b87a3 3321construct to generate a value of specified type at a specified address
4187119d 3322(@pxref{Expressions}). For example, @code{@{int@}0x83040} would refer
3323to memory location 0x83040 as an integer (which implies a certain size
3324and representation in memory), and
e91b87a3 3325
3326@example
3327set @{int@}0x83040 = 4
3328@end example
3329
4187119d 3330would store the value 4 into that memory location.
3331
e91b87a3 3332@node Jumping, Signaling, Assignment, Altering
3333@section Continuing at a Different Address
3334
4187119d 3335Ordinarily, when you continue the program, you do so at the place where
3336it stopped, with the @samp{cont} command. You can instead continue at
3337an address of your own choosing, with the following commands:
3338
e91b87a3 3339@table @code
3340@item jump @var{linenum}
3341@kindex jump
3342Resume execution at line number @var{linenum}. Execution may stop
3343immediately if there is a breakpoint there.
3344
3345The @samp{jump} command does not change the current stack frame, or
3346the stack pointer, or the contents of any memory location or any
3347register other than the program counter. If line @var{linenum} is in
3348a different function from the one currently executing, the results may
4187119d 3349be bizarre if the two functions expect different patterns of arguments or
e91b87a3 3350of local variables. For this reason, the @samp{jump} command requests
3351confirmation if the specified line is not in the function currently
4187119d 3352executing. However, even bizarre results are predictable based on
3353careful study of the machine-language code of the program.
e91b87a3 3354
3355@item jump *@var{address}
3356Resume execution at the instruction at address @var{address}.
3357@end table
3358
4187119d 3359You can get much the same effect as the @code{jump} command by storing a
3360new value into the register @code{$pc}. The difference is that this
3361does not start the program running; it only changes the address where it
3362@emph{will} run when it is continued. For example,
e91b87a3 3363
3364@example
3365set $pc = 0x485
3366@end example
3367
3368@noindent
4187119d 3369causes the next @samp{cont} command or stepping command to execute at
3370address 0x485, rather than at the address where the program stopped.
3371@xref{Stepping}.
3372
3373The most common occasion to use the @samp{jump} command is when you have
3374stepped across a function call with @code{next}, and found that the
3375return value is incorrect. If all the relevant data appeared correct
3376before the function call, the error is probably in the function that
3377just returned.
3378
3379In general, your next step would now be to rerun the program and execute
3380up to this function call, and then step into it to see where it goes
3381astray. But this may be time consuming. If the function did not have
3382significant side effects, you could get the same information by resuming
3383execution just before the function call and stepping through it. To do this,
3384first put a breakpoint on that function; then, use the @samp{jump} command
3385to continue on the line with the function call.
e91b87a3 3386
3387@node Signaling, Returning, Jumping, Altering
3388@section Giving the Program a Signal
3389
3390@table @code
3391@item signal @var{signalnum}
3392@kindex signal
4187119d 3393Resume execution where the program stopped, but give it immediately the
3394signal number @var{signalnum}.
3395
3396Alternatively, if @var{signalnum} is zero, continue execution without
3397giving a signal. This is useful when the program stopped on account of
3398a signal and would ordinary see the signal when resumed with the
3399@samp{cont} command; @samp{signal 0} causes it to resume without a
3400signal.
e91b87a3 3401@end table
3402
3403@node Returning,, Signaling, Altering
3404@section Returning from a Function
3405
3406@cindex returning from a function
3407@kindex return
4187119d 3408You can cancel execution of a function call with the @samp{return}
3409command. This command has the effect of discarding the selected stack
3410frame (and all frames within it), so that control moves to the caller of
3411that function. You can think of this as making the discarded frame
3412return prematurely.
e91b87a3 3413
3414First select the stack frame that you wish to return from
4187119d 3415(@pxref{Selection}). Then type the @samp{return} command. If you wish
3416to specify the value to be returned, give that as an argument.
e91b87a3 3417
3418This pops the selected stack frame (and any other frames inside of it),
3419leaving its caller as the innermost remaining frame. That frame becomes
3420selected. The specified value is stored in the registers used for
3421returning values of functions.
3422
4187119d 3423The @samp{return} command does not resume execution; it leaves the
3424program stopped in the state that would exist if the function had just
3425returned. Contrast this with the @samp{finish} command
3426(@pxref{Stepping}), which resumes execution until the selected stack
3427frame returns @emph{naturally}.
e91b87a3 3428
4187119d 3429@node Sequences, Options, Altering, Top
e91b87a3 3430@chapter Canned Sequences of Commands
3431
3432GDB provides two ways to store sequences of commands for execution as a
3433unit: user-defined commands and command files.
3434
3435@menu
3436* Define:: User-defined commands.
3437* Command Files:: Command files.
3438* Output:: Controlled output commands useful in
3439 user-defined commands and command files.
3440@end menu
3441
3442@node Define, Command Files, Sequences, Sequences
3443@section User-Defined Commands
3444
4187119d 3445@cindex user-defined command
e91b87a3 3446A @dfn{user-defined command} is a sequence of GDB commands to which you
3447assign a new name as a command. This is done with the @samp{define}
3448command.
3449
3450@table @code
3451@item define @var{commandname}
3452@kindex define
3453Define a command named @var{commandname}. If there is already a command
3454by that name, you are asked to confirm that you want to redefine it.
3455
3456The definition of the command is made up of other GDB command lines,
3457which are given following the @samp{define} command. The end of these
3458commands is marked by a line containing @samp{end}.
3459
3460@item document @var{commandname}
3461@kindex document
3462Give documentation to the user-defined command @var{commandname}. The
3463command @var{commandname} must already be defined. This command reads
3464lines of documentation just as @samp{define} reads the lines of the
4187119d 3465command definition, ending with @samp{end}. After the @samp{document}
3466command is finished, @samp{help} on command @var{commandname} will print
3467the documentation you have specified.
e91b87a3 3468
3469You may use the @samp{document} command again to change the
3470documentation of a command. Redefining the command with @samp{define}
3471does not change the documentation.
3472@end table
3473
3474User-defined commands do not take arguments. When they are executed, the
3475commands of the definition are not printed. An error in any command
3476stops execution of the user-defined command.
3477
3478Commands that would ask for confirmation if used interactively proceed
3479without asking when used inside a user-defined command. Many GDB commands
3480that normally print messages to say what they are doing omit the messages
3481when used in user-defined command.
3482
3483@node Command Files, Output, Define, Sequences
3484@section Command Files
3485
3486@cindex command files
3487A command file for GDB is a file of lines that are GDB commands. Comments
3488(lines starting with @samp{#}) may also be included. An empty line in a
3489command file does nothing; it does not mean to repeat the last command, as
3490it would from the terminal.
3491
3492@cindex init file
4187119d 3493@cindex @file{.gdbinit}
e91b87a3 3494When GDB starts, it automatically executes its @dfn{init files}, command
3495files named @file{.gdbinit}. GDB reads the init file (if any) in your home
3496directory and then the init file (if any) in the current working
3497directory. (The init files are not executed if the @samp{-nx} option
3498is given.) You can also request the execution of a command file with the
3499@samp{source} command:
3500
3501@table @code
3502@item source @var{filename}
3503@kindex source
3504Execute the command file @var{filename}.
3505@end table
3506
3507The lines in a command file are executed sequentially. They are not
3508printed as they are executed. An error in any command terminates execution
3509of the command file.
3510
3511Commands that would ask for confirmation if used interactively proceed
3512without asking when used in a command file. Many GDB commands that
3513normally print messages to say what they are doing omit the messages
3514when used in a command file.
3515
3516@node Output,, Command Files, Sequences
3517@section Commands for Controlled Output
3518
3519During the execution of a command file or a user-defined command, the only
3520output that appears is what is explicitly printed by the commands of the
3521definition. This section describes three commands useful for generating
3522exactly the output you want.
3523
3524@table @code
3525@item echo @var{text}
3526@kindex echo
4187119d 3527@comment I don't consider backslash-space a standard C escape sequence
3528@comment because it's not in ANSI.
3529Print @var{text}. Nonprinting characters can be included in @var{text}
3530using C escape sequences, such as @samp{\n} to print a newline. @b{No
3531newline will be printed unless you specify one.} In addition to the
3532standard C escape sequences a backslash followed by a space stands for a
3533space. This is useful for outputting a string with spaces at the
9c91ee3e
RP
3534beginning or the end, since leading and trailing spaces are otherwise
3535trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the
3536command @samp{echo \@ and foo = \@ }.
3537@comment FIXME: verify hard copy actually issues enspaces for '@ '! Will this
3538@comment confuse texinfo?
4187119d 3539
3540A backslash at the end of @var{text} can be used, as in C, to continue
3541the command onto subsequent lines. For example,
e91b87a3 3542
4187119d 3543@example
3544echo This is some text\n\
3545which is continued\n\
3546onto several lines.\n
3547@end example
3548
3549produces the same output as
e91b87a3 3550
3551@example
4187119d 3552echo This is some text\n
3553echo which is continued\n
3554echo onto several lines.\n
e91b87a3 3555@end example
3556
3557@item output @var{expression}
3558@kindex output
3559Print the value of @var{expression} and nothing but that value: no
3560newlines, no @samp{$@var{nn} = }. The value is not entered in the
4187119d 3561value history either. @xref{Expressions} for more information on
3562expressions.
e91b87a3 3563
3564@item output/@var{fmt} @var{expression}
3565Print the value of @var{expression} in format @var{fmt}.
4187119d 3566@xref{Output formats}, for more information.
e91b87a3 3567
3568@item printf @var{string}, @var{expressions}@dots{}
3569@kindex printf
3570Print the values of the @var{expressions} under the control of
3571@var{string}. The @var{expressions} are separated by commas and may
3572be either numbers or pointers. Their values are printed as specified
3573by @var{string}, exactly as if the program were to execute
3574
3575@example
3576printf (@var{string}, @var{expressions}@dots{});
3577@end example
3578
3579For example, you can print two values in hex like this:
3580
3581@example
3582printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
3583@end example
3584
3585The only backslash-escape sequences that you can use in the string are
3586the simple ones that consist of backslash followed by a letter.
3587@end table
3588
4187119d 3589@node Options, Emacs, Sequences, Top
3590@chapter Options and Arguments for GDB
3591
3592When you invoke GDB, you can specify arguments telling it what files to
3593operate on and what other things to do.
3594
3595@menu
3596* Mode Options:: Options controlling modes of operation.
3597* File Options:: Options to specify files (executable, coredump, commands)
3598* Other Arguments:: Any other arguments without options
3599 also specify files.
3600@end menu
3601
3602@node Mode Options, File Options, Options, Options
3603@section Mode Options
3604
3605@table @samp
3606@item -nx
3607Do not execute commands from the init files @file{.gdbinit}.
3608Normally, the commands in these files are executed after all the
3609command options and arguments have been processed. @xref{Command
3610Files}.
3611
3612@item -q
3613``Quiet''. Do not print the usual introductory messages.
3614
3615@item -batch
3616Run in batch mode. Exit with code 0 after processing all the command
3617files specified with @samp{-x} (and @file{.gdbinit}, if not inhibited).
3618Exit with nonzero status if an error occurs in executing the GDB
3619commands in the command files.
3620
3621@item -fullname
3622This option is used when Emacs runs GDB as a subprocess. It tells GDB
3623to output the full file name and line number in a standard,
3624recognizable fashion each time a stack frame is displayed (which
3625includes each time the program stops). This recognizable format looks
3626like two @samp{\032} characters, followed by the file name, line number
3627and character position separated by colons, and a newline. The
3628Emacs-to-GDB interface program uses the two @samp{\032} characters as
3629a signal to display the source code for the frame.
3630@end table
3631
3632@node File Options, Other Arguments, Mode Options, Options
3633@section File-specifying Options
3634
3635All the options and command line arguments given are processed
3636in sequential order. The order makes a difference when the
3637@samp{-x} option is used.
3638
3639@table @samp
3640@item -s @var{file}
3641Read symbol table from file @var{file}.
3642
3643@item -e @var{file}
3644Use file @var{file} as the executable file to execute when
3645appropriate, and for examining pure data in conjunction with a core
3646dump.
3647
3648@item -se @var{file}
3649Read symbol table from file @var{file} and use it as the executable
3650file.
3651
3652@item -c @var{file}
3653Use file @var{file} as a core dump to examine.
3654
3655@item -x @var{file}
3656Execute GDB commands from file @var{file}.
3657
3658@item -d @var{directory}
3659Add @var{directory} to the path to search for source files.
3660@end table
3661
3662@node Other Arguments,, File Options, Options
3663@section Other Arguments
3664
3665If there are arguments to GDB that are not options or associated with
3666options, the first one specifies the symbol table and executable file name
3667(as if it were preceded by @samp{-se}) and the second one specifies a core
3668dump file name (as if it were preceded by @samp{-c}).
3669
3670@node Emacs, Remote, Options, Top
e91b87a3 3671@chapter Using GDB under GNU Emacs
3672
45007746 3673@cindex emacs
e91b87a3 3674A special interface allows you to use GNU Emacs to view (and
3675edit) the source files for the program you are debugging with
3676GDB.
3677
4187119d 3678To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
3679executable file you want to debug as an argument. This command starts
3680GDB as a subprocess of Emacs, with input and output through a newly
3681created Emacs buffer.
e91b87a3 3682
4187119d 3683Using GDB under Emacs is just like using GDB normally except for two
3684things:
e91b87a3 3685
3686@itemize @bullet
3687@item
3688All ``terminal'' input and output goes through the Emacs buffer. This
3689applies both to GDB commands and their output, and to the input and
3690output done by the program you are debugging.
3691
3692This is useful because it means that you can copy the text of previous
3693commands and input them again; you can even use parts of the output
3694in this way.
3695
3696All the facilities of Emacs's Shell mode are available for this purpose.
3697
3698@item
3699GDB displays source code through Emacs. Each time GDB displays a
3700stack frame, Emacs automatically finds the source file for that frame
3701and puts an arrow (@samp{=>}) at the left margin of the current line.
9c91ee3e
RP
3702Emacs uses a separate buffer for source display, and splits the window
3703to show both your GDB session and the source.
e91b87a3 3704
3705Explicit GDB @samp{list} or search commands still produce output as
3706usual, but you probably will have no reason to use them.
3707@end itemize
3708
3709In the GDB I/O buffer, you can use these special Emacs commands:
3710
3711@table @kbd
3712@item M-s
3713Execute to another source line, like the GDB @samp{step} command.
3714
3715@item M-n
3716Execute to next source line in this function, skipping all function
3717calls, like the GDB @samp{next} command.
3718
3719@item M-i
3720Execute one instruction, like the GDB @samp{stepi} command.
3721
e91b87a3 3722@item C-c C-f
3723Execute until exit from the selected stack frame, like the GDB
3724@samp{finish} command.
4187119d 3725
7a67dd45 3726@item M-c
3727@comment C-c C-p in emacs 19
4187119d 3728Continue execution of the program, like the GDB @samp{cont} command.
7a67dd45 3729
3730@item M-u
3731@comment C-c C-u in emacs 19
3732Go up the number of frames indicated by the numeric argument
3733(@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
3734like the GDB @samp{up} command.@refill
3735
3736@item M-d
3737@comment C-c C-d in emacs 19
3738Go down the number of frames indicated by the numeric argument, like the
3739GDB @samp{down} command.
e91b87a3 3740@end table
3741
3742In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
3743tells GDB to set a breakpoint on the source line point is on.
3744
3745The source files displayed in Emacs are in ordinary Emacs buffers
3746which are visiting the source files in the usual way. You can edit
3747the files with these buffers if you wish; but keep in mind that GDB
3748communicates with Emacs in terms of line numbers. If you add or
3749delete lines from the text, the line numbers that GDB knows will cease
3750to correspond properly to the code.
3751
96a816c5
JG
3752@kindex emacs epoch environment
3753@kindex epoch
3754@kindex inspect
3755
3756Version 18 of Emacs has a built-in window system called the @samp{epoch}
3757environment. Users of this environment can use a new command,
3758@samp{inspect} which performs identically to @samp{print} except that
3759each value is printed in its own window.
3760
e91b87a3 3761@node Remote, Commands, Emacs, Top
3762@chapter Remote Kernel Debugging
3763
1c997a4a 3764If you are trying to debug a program running on a machine that can't run
3765GDB in the usual way, it is often useful to use remote debugging. For
3766example, you might be debugging an operating system kernel, or debugging
3767a small system which does not have a general purpose operating system
3768powerful enough to run a full-featured debugger. Currently GDB supports
3769remote debugging over a serial connection.
e91b87a3 3770
3771The program to be debugged on the remote machine needs to contain a
3772debugging device driver which talks to GDB over the serial line using the
3773protocol described below. The same version of GDB that is used ordinarily
1c997a4a 3774can be used for this. Several sample remote debugging drivers are
3775distributed with GDB; see the @file{README} file in the GDB distribution for
3776more information.
e91b87a3 3777
3778@menu
3779* Remote Commands:: Commands used to start and finish remote debugging.
3780@end menu
3781
3782For details of the communication protocol, see the comments in the GDB
3783source file @file{remote.c}.
3784
9c91ee3e 3785@node Remote Commands, GDB Bugs, Remote, Remote
e91b87a3 3786@section Commands for Remote Debugging
3787
3788To start remote debugging, first run GDB and specify as an executable file
3789the program that is running in the remote machine. This tells GDB how
3790to find the program's symbols and the contents of its pure text. Then
3791establish communication using the @samp{attach} command with a device
3792name rather than a pid as an argument. For example:
3793
3794@example
3795attach /dev/ttyd
3796@end example
3797
3798@noindent
3799if the serial line is connected to the device named @file{/dev/ttyd}. This
3800will stop the remote machine if it is not already stopped.
3801
3802Now you can use all the usual commands to examine and change data and to
3803step and continue the remote program.
3804
3805To resume the remote program and stop debugging it, use the @samp{detach}
3806command.
3807
9c91ee3e
RP
3808@node GDB Bugs, , Remote Commands, Top
3809@comment node-name, next, previous, up
3810@chapter Reporting Bugs in GDB
3811@cindex Bugs in GDB
3812@cindex Reporting Bugs in GDB
3813
3814Your bug reports play an essential role in making GDB reliable.
3815
3816Reporting a bug may help you by bringing a solution to your problem, or it
3817may not. But in any case the important function of a bug report is to help
3818the entire community by making the next version of GDB work better. Bug
3819reports are your contribution to the maintenance of GDB.
3820
3821In order for a bug report to serve its purpose, you must include the
3822information that makes for fixing the bug.
3823
3824@menu
3825* Criteria: Bug Criteria. Have you really found a bug?
3826* Reporting: Bug Reporting. How to report a bug effectively.
3827* Known: Trouble. Known problems.
3828* Help: Service. Where to ask for help.
3829@end menu
3830
3831@node Bug Criteria, Bug Reporting, Bugs, Bugs
3832@section Have You Found a Bug?
3833@cindex Bug Criteria
3834
3835If you are not sure whether you have found a bug, here are some guidelines:
3836
3837@itemize @bullet
3838@item
3839@cindex Fatal Signal
3840@cindex Core Dump
3841If the debugger gets a fatal signal, for any input whatever, that is a
3842GDB bug. Reliable debuggers never crash.
3843
3844@item
3845@cindex error on Valid Input
3846If GDB produces an error message for valid input, that is a bug.
3847
3848@item
3849@cindex Invalid Input
3850If GDB does not produce an error message for invalid input,
3851that is a bug. However, you should note that your idea of
3852``invalid input'' might be my idea of ``an extension'' or ``support
3853for traditional practice''.
3854
3855@item
3856If you are an experienced user of debugging tools, your suggestions
3857for improvement of GDB are welcome in any case.
3858@end itemize
3859
3860@node Bug Reporting,, Bug Criteria, Bugs
3861@section How to Report Bugs
3862@cindex Bug Reports
3863@cindex Compiler Bugs, Reporting
3864
3865Send bug reports for GDB to one of these addresses:
3866
3867@example
3868bug-gdb@@prep.ai.mit.edu
3869@{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
3870@end example
3871
3872@strong{Do not send bug reports to @samp{info-gdb}, or to any
3873newsgroups.} Most users of GDB do not want to receive bug reports.
3874Those that do, have asked to be on @samp{bug-gcc}.
3875
3876The mailing list @samp{bug-gcc} has a newsgroup which serves as a
3877repeater. The mailing list and the newsgroup carry exactly the same
3878messages. Often people think of posting bug reports to the newsgroup
3879instead of mailing them. This appears to work, but it has one problem
3880which can be crucial: a newsgroup posting does not contain a mail path
3881back to the sender. Thus, if I need to ask for more information, I
3882may be unable to reach you. For this reason, it is better to send bug
3883reports to the mailing list.
3884
3885As a last resort, send bug reports on paper to:
3886
3887@example
3888GNU Debugger Bugs
3889545 Tech Sq
3890Cambridge, MA 02139
3891@end example
3892
3893The fundamental principle of reporting bugs usefully is this:
3894@strong{report all the facts}. If you are not sure whether to state a
3895fact or leave it out, state it!
3896
3897Often people omit facts because they think they know what causes the
3898problem and they conclude that some details don't matter. Thus, you might
3899assume that the name of the variable you use in an example does not matter.
3900Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
3901stray memory reference which happens to fetch from the location where that
3902name is stored in memory; perhaps, if the name were different, the contents
3903of that location would fool the debugger into doing the right thing despite
3904the bug. Play it safe and give a specific, complete example. That is the
3905easiest thing for you to do, and the most helpful.
3906
3907Keep in mind that the purpose of a bug report is to enable me to fix
3908the bug if it is not known. It isn't very important what happens if
3909the bug is already known. Therefore, always write your bug reports on
3910the assumption that the bug is not known.
3911
3912Sometimes people give a few sketchy facts and ask, ``Does this ring a
3913bell?'' Those bug reports are useless, and I urge everyone to
3914@emph{refuse to respond to them} except to chide the sender to report
3915bugs properly.
3916
3917To enable me to fix the bug, you should include all these things:
3918
3919@itemize @bullet
3920@item
3921The version of GDB. GDB announces it on startup.
3922
3923Without this, I won't know whether there is any point in looking for
3924the bug in the current version of GDB.
3925
3926@item
3927
3928A complete input file, and all necessary source files, that will
3929reproduce the bug. Run your source files through the C
3930preprocessor by doing @samp{gcc -E @var{sourcefile} > @var{outfile}},
3931then include the contents of @var{outfile} in the bug report. (Any
3932@samp{-I}, @samp{-D} or @samp{-U} options that you used in actual
3933compilation should also be used when doing this.)
3934
3935A single statement is not enough of an example. In order to compile
3936it, it must be embedded in a function definition; and the bug might
3937depend on the details of how this is done.
3938
3939Without a real example I can compile, all I can do about your bug
3940report is wish you luck. It would be futile to try to guess how to
3941provoke the bug.
3942
3943@item
3944The command arguments you gave GCC or G++ to compile that example and
3945observe the bug. For example, did you use @samp{-O}? To guarantee
3946you won't omit something important, list them all.
3947
3948If I were to try to guess the arguments, I would probably guess wrong
3949and then I would not encounter the bug.
3950
3951@item
3952The type of machine you are using, and the operating system name and
3953version number.
3954
3955@item
3956A description of what behavior you observe that you believe is
3957incorrect. For example, ``It gets a fatal signal,'' or, ``There is an
3958incorrect assembler instruction in the output.''
3959
3960Of course, if the bug is that GDB gets a fatal signal, then I
3961will certainly notice it. But if the bug is incorrect output, I might
3962not notice unless it is glaringly wrong.
3963
3964Even if the problem you experience is a fatal signal, you should still
3965say so explicitly. Suppose something strange is going on, such as,
3966your copy of GDB is out of synch, or you have encountered a
3967bug in the C library on your system. (This has happened!) Your copy
3968might crash and mine would not. If you @i{told} me to expect a crash,
3969then when mine fails to crash, I would know that the bug was not
3970happening for me. If you had not told me to expect a crash, then I
3971would not be able to draw any conclusion from my observations.
3972
3973@item
3974If you wish to suggest changes to the GDB source, send me context
3975diffs. If you even discuss something in the GDB source, refer to
3976it by context, not by line number.
3977
3978The line numbers in my development sources don't match those in your
3979sources. Your line numbers would convey no useful information to me.
3980
3981@end itemize
3982
3983Here are some things that are not necessary:
3984
3985@itemize @bullet
3986@item
3987A description of the envelope of the bug.
3988
3989Often people who encounter a bug spend a lot of time investigating
3990which changes to the input file will make the bug go away and which
3991changes will not affect it.
3992
3993This is often time consuming and not very useful, because the way I
3994will find the bug is by running a single example under the debugger
3995with breakpoints, not by pure deduction from a series of examples.
3996I recommend that you save your time for something else.
3997
3998Of course, if you can find a simpler example to report @emph{instead}
3999of the original one, that is a convenience for me. Errors in the
4000output will be easier to spot, running under the debugger will take
4001less time, etc.
4002
4003However, simplification is not vital; if you don't want to do this,
4004report the bug anyway and send me the entire test case you used.
4005
4006@item
4007A patch for the bug.
4008
4009A patch for the bug does help me if it is a good one. But don't omit
4010the necessary information, such as the test case, on the assumption that
4011a patch is all I need. I might see problems with your patch and decide
4012to fix the problem another way, or I might not understand it at all.
4013
4014Sometimes with a program as complicated as GDB it is very hard to
4015construct an example that will make the program follow a certain path
4016through the code. If you don't send me the example, I won't be able
4017to construct one, so I won't be able to verify that the bug is fixed.
4018
4019And if I can't understand what bug you are trying to fix, or why your
4020patch should be an improvement, I won't install it. A test case will
4021help me to understand.
4022
4023@item
4024A guess about what the bug is or what it depends on.
4025
4026Such guesses are usually wrong. Even I can't guess right about such
4027things without first using the debugger to find the facts.
4028@end itemize
4029
6ad6aa52
RP
4030@include readline/inc-readline.texinfo
4031@include readline/inc-history.texinfo
4187119d 4032
e91b87a3 4033@node Commands, Concepts, Remote, Top
4034@unnumbered Command Index
4035
4036@printindex ky
4037
4187119d 4038@node Concepts, , Commands, Top
e91b87a3 4039@unnumbered Concept Index
4040
4041@printindex cp
4042
4043@contents
4044@bye
This page took 0.491868 seconds and 4 git commands to generate.