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