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