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