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