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