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