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