]>
Commit | Line | Data |
---|---|---|
29a2b744 | 1 | \input texinfo @c -*-texinfo-*- |
ed447b95 | 2 | @c Copyright (c) 1988 1989 1990 1991 1992 1993 Free Software Foundation, Inc. |
18fae2a8 | 3 | @c |
29a2b744 | 4 | @c %**start of header |
18fae2a8 RP |
5 | @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use |
6 | @c of @set vars. However, we can override filename with makeinfo -o. | |
7 | @setfilename gdb.info | |
8 | @c | |
9 | @include gdb-config.texi | |
10 | @c | |
11 | @ifset GENERIC | |
12 | @settitle Debugging with @value{GDBN} | |
13 | @end ifset | |
14 | @ifclear GENERIC | |
15 | @settitle Debugging with @value{GDBN} (@value{HOST}) | |
16 | @end ifclear | |
29a2b744 | 17 | @setchapternewpage odd |
29a2b744 RP |
18 | @c %**end of header |
19 | ||
ed447b95 RP |
20 | @iftex |
21 | @c smallbook | |
22 | @c cropmarks | |
23 | @end iftex | |
24 | ||
25 | @c Include the readline documentation in the TeX output, | |
26 | @c but not in the Info output. | |
27 | @c Eventually, we should make a cross reference to the Readline Info | |
28 | @c nodes; but this requires that the nodes exist and be in an expected | |
29 | @c place. Wait for a standard, complete GNU distribution. Meanwhile, | |
30 | @c cross references are only in the printed TeX output, and only when | |
31 | @c `have-readline-appendices' is set. | |
32 | @c | |
33 | @c The readline documentation is distributed with the readline code | |
34 | @c and consists of the two following files: | |
35 | @c rluser.texinfo | |
36 | @c inc-hist.texi | |
37 | @iftex | |
38 | @set have-readline-appendices | |
39 | @end iftex | |
40 | @ifinfo | |
41 | @clear have-readline-appendices | |
42 | @end ifinfo | |
43 | ||
29a2b744 RP |
44 | @finalout |
45 | @syncodeindex ky cp | |
46 | ||
18fae2a8 | 47 | @c ===> NOTE! <== |
29a2b744 RP |
48 | @c Determine the edition number in *three* places by hand: |
49 | @c 1. First ifinfo section 2. title page 3. top node | |
50 | @c To find the locations, search for !!set | |
51 | ||
d24e0922 | 52 | @c GDB CHANGELOG CONSULTED BETWEEN: |
29a2b744 RP |
53 | @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com) |
54 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
55 | ||
9c3ad547 | 56 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. |
29a2b744 | 57 | |
b7becc8f | 58 | @ifinfo |
ed447b95 RP |
59 | @c This is a dir.info fragment to support semi-automated addition of |
60 | @c manuals to an info tree. [email protected] is developing this facility. | |
b7becc8f RP |
61 | @format |
62 | START-INFO-DIR-ENTRY | |
29a2b744 | 63 | * Gdb: (gdb). The GNU debugger. |
b7becc8f RP |
64 | END-INFO-DIR-ENTRY |
65 | @end format | |
66 | @end ifinfo | |
18fae2a8 | 67 | @c |
70b88761 | 68 | @c |
70b88761 | 69 | @ifinfo |
18fae2a8 | 70 | This file documents the GNU debugger @value{GDBN}. |
70b88761 | 71 | |
29a2b744 | 72 | @c !!set edition, date, version |
ed447b95 | 73 | This is Edition 4.07, January 1993, |
18fae2a8 RP |
74 | of @cite{Debugging with @value{GDBN}: the GNU Source-Level Debugger} |
75 | for GDB Version @value{GDBVN}. | |
29a2b744 | 76 | |
ed447b95 | 77 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
70b88761 RP |
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 | |
1041a570 | 103 | |
70b88761 | 104 | @titlepage |
18fae2a8 | 105 | @title Debugging with @value{GDBN} |
95d5ceb9 | 106 | @subtitle The GNU Source-Level Debugger |
18fae2a8 RP |
107 | @ifclear GENERIC |
108 | @subtitle on @value{HOST} Systems | |
109 | @end ifclear | |
70b88761 | 110 | @sp 1 |
29a2b744 | 111 | @c !!set edition, date, version |
ed447b95 RP |
112 | @subtitle Edition 4.07, for @value{GDBN} version @value{GDBVN} |
113 | @subtitle January 1993 | |
29a2b744 | 114 | @author by Richard M. Stallman and Roland H. Pesch |
70b88761 RP |
115 | @page |
116 | @tex | |
117 | {\parskip=0pt | |
18fae2a8 | 118 | \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@prep.ai.mit.edu.)\par |
ed447b95 | 119 | \hfill {\it Debugging with @value{GDBN}}\par |
70b88761 | 120 | \hfill \TeX{}info \texinfoversion\par |
ed447b95 | 121 | \hfill pesch\@cygnus.com\par |
70b88761 RP |
122 | } |
123 | @end tex | |
124 | ||
125 | @vskip 0pt plus 1filll | |
ed447b95 | 126 | Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
70b88761 RP |
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 | ||
70b88761 | 147 | @ifinfo |
4eb4cf57 | 148 | @node Top |
18fae2a8 | 149 | @top Debugging with @value{GDBN} |
29a2b744 | 150 | |
18fae2a8 | 151 | This file describes @value{GDBN}, the GNU symbolic debugger. |
29a2b744 RP |
152 | |
153 | @c !!set edition, date, version | |
ed447b95 | 154 | This is Edition 4.07, January 1993, for GDB Version @value{GDBVN}. |
70b88761 | 155 | |
18fae2a8 RP |
156 | @c Makeinfo node defaulting gets very confused by conditionals in menus, |
157 | @c unfortunately. Otherwise we would use the following ignored menu, | |
158 | @c which involves four switches: | |
159 | @ignore | |
70b88761 | 160 | @menu |
18fae2a8 RP |
161 | * Summary:: Summary of @value{GDBN} |
162 | @ifset NOVEL | |
c7cb8acb | 163 | * New Features:: New features since GDB version 3.5 |
18fae2a8 RP |
164 | @end ifset |
165 | @ifclear BARETARGET | |
166 | * Sample Session:: A sample @value{GDBN} session | |
167 | @end ifclear | |
168 | * Invocation:: Getting in and out of @value{GDBN} | |
169 | * Commands:: @value{GDBN} commands | |
170 | * Running:: Running programs under @value{GDBN} | |
29a2b744 RP |
171 | * Stopping:: Stopping and continuing |
172 | * Stack:: Examining the stack | |
173 | * Source:: Examining source files | |
174 | * Data:: Examining data | |
18fae2a8 RP |
175 | @ifclear CONLY |
176 | * Languages:: Using @value{GDBN} with different languages | |
177 | @end ifclear | |
178 | @ifset CONLY | |
4eb4cf57 | 179 | * C:: C and C++ |
18fae2a8 RP |
180 | @end ifset |
181 | * Symbols:: Examining the symbol table | |
182 | * Altering:: Altering execution | |
93918348 | 183 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
184 | * Targets:: Specifying a debugging target |
185 | * Controlling GDB:: Controlling @value{GDBN} | |
186 | * Sequences:: Canned sequences of commands | |
187 | @ifclear DOSHOST | |
188 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
189 | @end ifclear | |
190 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
191 | @ifset NOVEL | |
192 | * Renamed Commands:: | |
193 | @end ifset | |
194 | * Formatting Documentation:: How to format and print GDB documentation | |
195 | * Installing GDB:: Installing GDB | |
196 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
197 | * Index:: Index | |
198 | @end menu | |
199 | @end ignore | |
200 | @c | |
93918348 | 201 | @c Since that does not work, we must unroll the above into 16 cases: |
18fae2a8 RP |
202 | @c |
203 | @c Menu for NOVEL && !BARETARGET && !CONLY && !DOSHOST | |
204 | @ifset NOVEL | |
205 | @ifclear BARETARGET | |
206 | @ifclear CONLY | |
207 | @ifclear DOSHOST | |
208 | @menu | |
209 | * Summary:: Summary of @value{GDBN} | |
210 | * New Features:: New features since GDB version 3.5 | |
211 | * Sample Session:: A sample @value{GDBN} session | |
212 | * Invocation:: Getting in and out of @value{GDBN} | |
213 | * Commands:: @value{GDBN} commands | |
214 | * Running:: Running programs under @value{GDBN} | |
215 | * Stopping:: Stopping and continuing | |
216 | * Stack:: Examining the stack | |
217 | * Source:: Examining source files | |
218 | * Data:: Examining data | |
219 | * Languages:: Using @value{GDBN} with different languages | |
220 | * Symbols:: Examining the symbol table | |
221 | * Altering:: Altering execution | |
93918348 | 222 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
223 | * Targets:: Specifying a debugging target |
224 | * Controlling GDB:: Controlling @value{GDBN} | |
225 | * Sequences:: Canned sequences of commands | |
226 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
227 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
228 | * Renamed Commands:: | |
229 | * Formatting Documentation:: How to format and print GDB documentation | |
230 | * Installing GDB:: Installing GDB | |
231 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
232 | * Index:: Index | |
233 | @end menu | |
234 | @end ifclear | |
235 | @end ifclear | |
236 | @end ifclear | |
237 | @end ifset | |
238 | ||
239 | @c Menu for NOVEL && !BARETARGET && !CONLY && DOSHOST | |
240 | @ifset NOVEL | |
241 | @ifclear BARETARGET | |
242 | @ifclear CONLY | |
243 | @ifset DOSHOST | |
244 | @menu | |
245 | * Summary:: Summary of @value{GDBN} | |
246 | * New Features:: New features since GDB version 3.5 | |
247 | * Sample Session:: A sample @value{GDBN} session | |
248 | * Invocation:: Getting in and out of @value{GDBN} | |
249 | * Commands:: @value{GDBN} commands | |
250 | * Running:: Running programs under @value{GDBN} | |
251 | * Stopping:: Stopping and continuing | |
252 | * Stack:: Examining the stack | |
253 | * Source:: Examining source files | |
254 | * Data:: Examining data | |
255 | * Languages:: Using @value{GDBN} with different languages | |
256 | * Symbols:: Examining the symbol table | |
257 | * Altering:: Altering execution | |
93918348 | 258 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
259 | * Targets:: Specifying a debugging target |
260 | * Controlling GDB:: Controlling @value{GDBN} | |
261 | * Sequences:: Canned sequences of commands | |
262 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
263 | * Renamed Commands:: | |
264 | * Formatting Documentation:: How to format and print GDB documentation | |
265 | * Installing GDB:: Installing GDB | |
266 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
267 | * Index:: Index | |
268 | @end menu | |
269 | @end ifset | |
270 | @end ifclear | |
271 | @end ifclear | |
272 | @end ifset | |
273 | ||
274 | @c Menu for NOVEL && !BARETARGET && CONLY && !DOSHOST | |
275 | @ifset NOVEL | |
276 | @ifclear BARETARGET | |
277 | @ifset CONLY | |
278 | @ifclear DOSHOST | |
279 | @menu | |
280 | * Summary:: Summary of @value{GDBN} | |
281 | * New Features:: New features since GDB version 3.5 | |
282 | * Sample Session:: A sample @value{GDBN} session | |
283 | * Invocation:: Getting in and out of @value{GDBN} | |
284 | * Commands:: @value{GDBN} commands | |
285 | * Running:: Running programs under @value{GDBN} | |
286 | * Stopping:: Stopping and continuing | |
287 | * Stack:: Examining the stack | |
288 | * Source:: Examining source files | |
289 | * Data:: Examining data | |
290 | * C:: C Language Support | |
291 | * Symbols:: Examining the symbol table | |
292 | * Altering:: Altering execution | |
93918348 | 293 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
294 | * Targets:: Specifying a debugging target |
295 | * Controlling GDB:: Controlling @value{GDBN} | |
296 | * Sequences:: Canned sequences of commands | |
297 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
298 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
299 | * Renamed Commands:: | |
300 | * Formatting Documentation:: How to format and print GDB documentation | |
301 | * Installing GDB:: Installing GDB | |
302 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
303 | * Index:: Index | |
304 | @end menu | |
305 | @end ifclear | |
306 | @end ifset | |
307 | @end ifclear | |
308 | @end ifset | |
309 | ||
310 | @c Menu for NOVEL && !BARETARGET && CONLY && DOSHOST | |
311 | @ifset NOVEL | |
312 | @ifclear BARETARGET | |
313 | @ifset CONLY | |
314 | @ifset DOSHOST | |
315 | @menu | |
316 | * Summary:: Summary of @value{GDBN} | |
317 | * New Features:: New features since GDB version 3.5 | |
318 | * Sample Session:: A sample @value{GDBN} session | |
319 | * Invocation:: Getting in and out of @value{GDBN} | |
320 | * Commands:: @value{GDBN} commands | |
321 | * Running:: Running programs under @value{GDBN} | |
322 | * Stopping:: Stopping and continuing | |
323 | * Stack:: Examining the stack | |
324 | * Source:: Examining source files | |
325 | * Data:: Examining data | |
326 | * C:: C Language Support | |
327 | * Symbols:: Examining the symbol table | |
328 | * Altering:: Altering execution | |
93918348 | 329 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
330 | * Targets:: Specifying a debugging target |
331 | * Controlling GDB:: Controlling @value{GDBN} | |
332 | * Sequences:: Canned sequences of commands | |
333 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
334 | * Renamed Commands:: | |
335 | * Formatting Documentation:: How to format and print GDB documentation | |
336 | * Installing GDB:: Installing GDB | |
337 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
338 | * Index:: Index | |
339 | @end menu | |
340 | @end ifset | |
341 | @end ifset | |
342 | @end ifclear | |
343 | @end ifset | |
344 | ||
345 | @c Menu for NOVEL && BARETARGET && !CONLY && !DOSHOST | |
346 | @ifset NOVEL | |
347 | @ifset BARETARGET | |
348 | @ifclear CONLY | |
349 | @ifclear DOSHOST | |
350 | @menu | |
351 | * Summary:: Summary of @value{GDBN} | |
352 | * New Features:: New features since GDB version 3.5 | |
353 | * Invocation:: Getting in and out of @value{GDBN} | |
354 | * Commands:: @value{GDBN} commands | |
355 | * Running:: Running programs under @value{GDBN} | |
356 | * Stopping:: Stopping and continuing | |
357 | * Stack:: Examining the stack | |
358 | * Source:: Examining source files | |
359 | * Data:: Examining data | |
360 | * Languages:: Using @value{GDBN} with different languages | |
361 | * Symbols:: Examining the symbol table | |
362 | * Altering:: Altering execution | |
93918348 | 363 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
364 | * Targets:: Specifying a debugging target |
365 | * Controlling GDB:: Controlling @value{GDBN} | |
366 | * Sequences:: Canned sequences of commands | |
367 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
368 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
369 | * Renamed Commands:: | |
370 | * Formatting Documentation:: How to format and print GDB documentation | |
371 | * Installing GDB:: Installing GDB | |
372 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
373 | * Index:: Index | |
374 | @end menu | |
375 | @end ifclear | |
376 | @end ifclear | |
377 | @end ifset | |
378 | @end ifset | |
379 | ||
380 | @c Menu for NOVEL && BARETARGET && !CONLY && DOSHOST | |
381 | @ifset NOVEL | |
382 | @ifset BARETARGET | |
383 | @ifclear CONLY | |
384 | @ifset DOSHOST | |
385 | @menu | |
386 | * Summary:: Summary of @value{GDBN} | |
387 | * New Features:: New features since GDB version 3.5 | |
388 | * Invocation:: Getting in and out of @value{GDBN} | |
389 | * Commands:: @value{GDBN} commands | |
390 | * Running:: Running programs under @value{GDBN} | |
391 | * Stopping:: Stopping and continuing | |
392 | * Stack:: Examining the stack | |
393 | * Source:: Examining source files | |
394 | * Data:: Examining data | |
395 | * Languages:: Using @value{GDBN} with different languages | |
396 | * Symbols:: Examining the symbol table | |
397 | * Altering:: Altering execution | |
93918348 | 398 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
399 | * Targets:: Specifying a debugging target |
400 | * Controlling GDB:: Controlling @value{GDBN} | |
401 | * Sequences:: Canned sequences of commands | |
402 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
403 | * Renamed Commands:: | |
404 | * Formatting Documentation:: How to format and print GDB documentation | |
405 | * Installing GDB:: Installing GDB | |
406 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
407 | * Index:: Index | |
408 | @end menu | |
409 | @end ifset | |
410 | @end ifclear | |
411 | @end ifset | |
412 | @end ifset | |
413 | ||
414 | @c Menu for NOVEL && BARETARGET && CONLY && !DOSHOST | |
415 | @ifset NOVEL | |
416 | @ifset BARETARGET | |
417 | @ifset CONLY | |
418 | @ifclear DOSHOST | |
419 | @menu | |
420 | * Summary:: Summary of @value{GDBN} | |
421 | * New Features:: New features since GDB version 3.5 | |
422 | * Invocation:: Getting in and out of @value{GDBN} | |
423 | * Commands:: @value{GDBN} commands | |
424 | * Running:: Running programs under @value{GDBN} | |
425 | * Stopping:: Stopping and continuing | |
426 | * Stack:: Examining the stack | |
427 | * Source:: Examining source files | |
428 | * Data:: Examining data | |
429 | * C:: C Language support | |
29a2b744 RP |
430 | * Symbols:: Examining the symbol table |
431 | * Altering:: Altering execution | |
93918348 | 432 | * GDB Files:: @value{GDBN} files |
29a2b744 | 433 | * Targets:: Specifying a debugging target |
18fae2a8 | 434 | * Controlling GDB:: Controlling @value{GDBN} |
29a2b744 | 435 | * Sequences:: Canned sequences of commands |
18fae2a8 RP |
436 | * Emacs:: Using @value{GDBN} under GNU Emacs |
437 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
e251e767 | 438 | * Renamed Commands:: |
77b46d13 | 439 | * Formatting Documentation:: How to format and print GDB documentation |
c7cb8acb | 440 | * Installing GDB:: Installing GDB |
b80282d5 RP |
441 | * Copying:: GNU GENERAL PUBLIC LICENSE |
442 | * Index:: Index | |
70b88761 | 443 | @end menu |
18fae2a8 RP |
444 | @end ifclear |
445 | @end ifset | |
446 | @end ifset | |
447 | @end ifset | |
448 | ||
449 | @c Menu for NOVEL && BARETARGET && CONLY && DOSHOST | |
450 | @ifset NOVEL | |
451 | @ifset BARETARGET | |
452 | @ifset CONLY | |
453 | @ifset DOSHOST | |
454 | @menu | |
455 | * Summary:: Summary of @value{GDBN} | |
456 | * New Features:: New features since GDB version 3.5 | |
457 | * Invocation:: Getting in and out of @value{GDBN} | |
458 | * Commands:: @value{GDBN} commands | |
459 | * Running:: Running programs under @value{GDBN} | |
460 | * Stopping:: Stopping and continuing | |
461 | * Stack:: Examining the stack | |
462 | * Source:: Examining source files | |
463 | * Data:: Examining data | |
464 | * C:: C Language support | |
465 | * Symbols:: Examining the symbol table | |
466 | * Altering:: Altering execution | |
93918348 | 467 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
468 | * Targets:: Specifying a debugging target |
469 | * Controlling GDB:: Controlling @value{GDBN} | |
470 | * Sequences:: Canned sequences of commands | |
471 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
472 | * Renamed Commands:: | |
473 | * Formatting Documentation:: How to format and print GDB documentation | |
474 | * Installing GDB:: Installing GDB | |
475 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
476 | * Index:: Index | |
477 | @end menu | |
478 | @end ifset | |
479 | @end ifset | |
480 | @end ifset | |
481 | @end ifset | |
482 | ||
483 | @c Menu for !NOVEL && !BARETARGET && !CONLY && !DOSHOST | |
484 | @ifclear NOVEL | |
485 | @ifclear BARETARGET | |
486 | @ifclear CONLY | |
487 | @ifclear DOSHOST | |
488 | @menu | |
489 | * Summary:: Summary of @value{GDBN} | |
490 | * Sample Session:: A sample @value{GDBN} session | |
491 | * Invocation:: Getting in and out of @value{GDBN} | |
492 | * Commands:: @value{GDBN} commands | |
493 | * Running:: Running programs under @value{GDBN} | |
494 | * Stopping:: Stopping and continuing | |
495 | * Stack:: Examining the stack | |
496 | * Source:: Examining source files | |
497 | * Data:: Examining data | |
498 | * Languages:: Using @value{GDBN} with different languages | |
499 | * Symbols:: Examining the symbol table | |
500 | * Altering:: Altering execution | |
93918348 | 501 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
502 | * Targets:: Specifying a debugging target |
503 | * Controlling GDB:: Controlling @value{GDBN} | |
504 | * Sequences:: Canned sequences of commands | |
505 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
506 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
507 | * Formatting Documentation:: How to format and print GDB documentation | |
508 | * Installing GDB:: Installing GDB | |
509 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
510 | * Index:: Index | |
511 | @end menu | |
512 | @end ifclear | |
513 | @end ifclear | |
514 | @end ifclear | |
515 | @end ifclear | |
516 | ||
517 | @c Menu for !NOVEL && !BARETARGET && !CONLY && DOSHOST | |
518 | @ifclear NOVEL | |
519 | @ifclear BARETARGET | |
520 | @ifclear CONLY | |
521 | @ifset DOSHOST | |
522 | @menu | |
523 | * Summary:: Summary of @value{GDBN} | |
524 | * Sample Session:: A sample @value{GDBN} session | |
525 | * Invocation:: Getting in and out of @value{GDBN} | |
526 | * Commands:: @value{GDBN} commands | |
527 | * Running:: Running programs under @value{GDBN} | |
528 | * Stopping:: Stopping and continuing | |
529 | * Stack:: Examining the stack | |
530 | * Source:: Examining source files | |
531 | * Data:: Examining data | |
532 | * Languages:: Using @value{GDBN} with different languages | |
533 | * Symbols:: Examining the symbol table | |
534 | * Altering:: Altering execution | |
93918348 | 535 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
536 | * Targets:: Specifying a debugging target |
537 | * Controlling GDB:: Controlling @value{GDBN} | |
538 | * Sequences:: Canned sequences of commands | |
539 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
540 | * Formatting Documentation:: How to format and print GDB documentation | |
541 | * Installing GDB:: Installing GDB | |
542 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
543 | * Index:: Index | |
544 | @end menu | |
545 | @end ifset | |
546 | @end ifclear | |
547 | @end ifclear | |
548 | @end ifclear | |
549 | ||
550 | @c Menu for !NOVEL && !BARETARGET && CONLY && !DOSHOST | |
551 | @ifclear NOVEL | |
552 | @ifclear BARETARGET | |
553 | @ifset CONLY | |
554 | @ifclear DOSHOST | |
555 | @menu | |
556 | * Summary:: Summary of @value{GDBN} | |
557 | * Sample Session:: A sample @value{GDBN} session | |
558 | * Invocation:: Getting in and out of @value{GDBN} | |
559 | * Commands:: @value{GDBN} commands | |
560 | * Running:: Running programs under @value{GDBN} | |
561 | * Stopping:: Stopping and continuing | |
562 | * Stack:: Examining the stack | |
563 | * Source:: Examining source files | |
564 | * Data:: Examining data | |
565 | * C:: C Language support | |
566 | * Symbols:: Examining the symbol table | |
567 | * Altering:: Altering execution | |
93918348 | 568 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
569 | * Targets:: Specifying a debugging target |
570 | * Controlling GDB:: Controlling @value{GDBN} | |
571 | * Sequences:: Canned sequences of commands | |
572 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
573 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
574 | * Formatting Documentation:: How to format and print GDB documentation | |
575 | * Installing GDB:: Installing GDB | |
576 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
577 | * Index:: Index | |
578 | @end menu | |
579 | @end ifclear | |
580 | @end ifset | |
581 | @end ifclear | |
582 | @end ifclear | |
583 | ||
584 | @c Menu for !NOVEL && !BARETARGET && CONLY && DOSHOST | |
585 | @ifclear NOVEL | |
586 | @ifclear BARETARGET | |
587 | @ifset CONLY | |
588 | @ifset DOSHOST | |
589 | @menu | |
590 | * Summary:: Summary of @value{GDBN} | |
591 | * Sample Session:: A sample @value{GDBN} session | |
592 | * Invocation:: Getting in and out of @value{GDBN} | |
593 | * Commands:: @value{GDBN} commands | |
594 | * Running:: Running programs under @value{GDBN} | |
595 | * Stopping:: Stopping and continuing | |
596 | * Stack:: Examining the stack | |
597 | * Source:: Examining source files | |
598 | * Data:: Examining data | |
599 | * C:: C Language support | |
600 | * Symbols:: Examining the symbol table | |
601 | * Altering:: Altering execution | |
93918348 | 602 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
603 | * Targets:: Specifying a debugging target |
604 | * Controlling GDB:: Controlling @value{GDBN} | |
605 | * Sequences:: Canned sequences of commands | |
606 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
607 | * Formatting Documentation:: How to format and print GDB documentation | |
608 | * Installing GDB:: Installing GDB | |
609 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
610 | * Index:: Index | |
611 | @end menu | |
612 | @end ifset | |
613 | @end ifset | |
614 | @end ifclear | |
615 | @end ifclear | |
616 | ||
617 | @c Menu for !NOVEL && BARETARGET && !CONLY && !DOSHOST | |
618 | @ifclear NOVEL | |
619 | @ifset BARETARGET | |
620 | @ifclear CONLY | |
621 | @ifclear DOSHOST | |
622 | @menu | |
623 | * Summary:: Summary of @value{GDBN} | |
624 | * Invocation:: Getting in and out of @value{GDBN} | |
625 | * Commands:: @value{GDBN} commands | |
626 | * Running:: Running programs under @value{GDBN} | |
627 | * Stopping:: Stopping and continuing | |
628 | * Stack:: Examining the stack | |
629 | * Source:: Examining source files | |
630 | * Data:: Examining data | |
631 | * Languages:: Using @value{GDBN} with different languages | |
632 | * Symbols:: Examining the symbol table | |
633 | * Altering:: Altering execution | |
93918348 | 634 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
635 | * Targets:: Specifying a debugging target |
636 | * Controlling GDB:: Controlling @value{GDBN} | |
637 | * Sequences:: Canned sequences of commands | |
638 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
639 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
640 | * Formatting Documentation:: How to format and print GDB documentation | |
641 | * Installing GDB:: Installing GDB | |
642 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
643 | * Index:: Index | |
644 | @end menu | |
645 | @end ifclear | |
646 | @end ifclear | |
647 | @end ifset | |
648 | @end ifclear | |
649 | ||
650 | @c Menu for !NOVEL && BARETARGET && !CONLY && DOSHOST | |
651 | @ifclear NOVEL | |
652 | @ifset BARETARGET | |
653 | @ifclear CONLY | |
654 | @ifset DOSHOST | |
655 | @menu | |
656 | * Summary:: Summary of @value{GDBN} | |
657 | * Invocation:: Getting in and out of @value{GDBN} | |
658 | * Commands:: @value{GDBN} commands | |
659 | * Running:: Running programs under @value{GDBN} | |
660 | * Stopping:: Stopping and continuing | |
661 | * Stack:: Examining the stack | |
662 | * Source:: Examining source files | |
663 | * Data:: Examining data | |
664 | * Languages:: Using @value{GDBN} with different languages | |
665 | * Symbols:: Examining the symbol table | |
666 | * Altering:: Altering execution | |
93918348 | 667 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
668 | * Targets:: Specifying a debugging target |
669 | * Controlling GDB:: Controlling @value{GDBN} | |
670 | * Sequences:: Canned sequences of commands | |
671 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
672 | * Formatting Documentation:: How to format and print GDB documentation | |
673 | * Installing GDB:: Installing GDB | |
674 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
675 | * Index:: Index | |
676 | @end menu | |
677 | @end ifset | |
678 | @end ifclear | |
679 | @end ifset | |
680 | @end ifclear | |
681 | ||
682 | @c Menu for !NOVEL && BARETARGET && CONLY && !DOSHOST | |
683 | @ifclear NOVEL | |
684 | @ifset BARETARGET | |
685 | @ifset CONLY | |
686 | @ifclear DOSHOST | |
687 | @menu | |
688 | * Summary:: Summary of @value{GDBN} | |
689 | * Invocation:: Getting in and out of @value{GDBN} | |
690 | * Commands:: @value{GDBN} commands | |
691 | * Running:: Running programs under @value{GDBN} | |
692 | * Stopping:: Stopping and continuing | |
693 | * Stack:: Examining the stack | |
694 | * Source:: Examining source files | |
695 | * Data:: Examining data | |
696 | * C:: C Language Support | |
697 | * Symbols:: Examining the symbol table | |
698 | * Altering:: Altering execution | |
93918348 | 699 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
700 | * Targets:: Specifying a debugging target |
701 | * Controlling GDB:: Controlling @value{GDBN} | |
702 | * Sequences:: Canned sequences of commands | |
703 | * Emacs:: Using @value{GDBN} under GNU Emacs | |
704 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
705 | * Formatting Documentation:: How to format and print GDB documentation | |
706 | * Installing GDB:: Installing GDB | |
707 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
708 | * Index:: Index | |
709 | @end menu | |
710 | @end ifclear | |
711 | @end ifset | |
712 | @end ifset | |
713 | @end ifclear | |
714 | ||
715 | @c Menu for !NOVEL && BARETARGET && CONLY && DOSHOST | |
716 | @ifclear NOVEL | |
717 | @ifset BARETARGET | |
718 | @ifset CONLY | |
719 | @ifset DOSHOST | |
720 | @menu | |
721 | * Summary:: Summary of @value{GDBN} | |
722 | * Invocation:: Getting in and out of @value{GDBN} | |
723 | * Commands:: @value{GDBN} commands | |
724 | * Running:: Running programs under @value{GDBN} | |
725 | * Stopping:: Stopping and continuing | |
726 | * Stack:: Examining the stack | |
727 | * Source:: Examining source files | |
728 | * Data:: Examining data | |
729 | * C:: C Language Support | |
730 | * Symbols:: Examining the symbol table | |
731 | * Altering:: Altering execution | |
93918348 | 732 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
733 | * Targets:: Specifying a debugging target |
734 | * Controlling GDB:: Controlling @value{GDBN} | |
735 | * Sequences:: Canned sequences of commands | |
736 | * GDB Bugs:: Reporting bugs in @value{GDBN} | |
737 | * Formatting Documentation:: How to format and print GDB documentation | |
738 | * Installing GDB:: Installing GDB | |
739 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
740 | * Index:: Index | |
741 | @end menu | |
742 | @end ifset | |
743 | @end ifset | |
744 | @end ifset | |
745 | @end ifclear | |
746 | ||
747 | @end ifinfo | |
70b88761 | 748 | |
4eb4cf57 | 749 | @node Summary |
18fae2a8 | 750 | @unnumbered Summary of @value{GDBN} |
70b88761 | 751 | |
18fae2a8 | 752 | The purpose of a debugger such as @value{GDBN} is to allow you to see what is |
70b88761 | 753 | going on ``inside'' another program while it executes---or what another |
1041a570 | 754 | program was doing at the moment it crashed. |
70b88761 | 755 | |
18fae2a8 | 756 | @value{GDBN} can do four main kinds of things (plus other things in support of |
1041a570 | 757 | these) to help you catch bugs in the act: |
70b88761 RP |
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 | ||
18fae2a8 RP |
774 | @ifclear CONLY |
775 | You can use @value{GDBN} to debug programs written in C, C++, and Modula-2. | |
c2bbbb22 | 776 | Fortran support will be added when a GNU Fortran compiler is ready. |
18fae2a8 | 777 | @end ifclear |
70b88761 RP |
778 | |
779 | @menu | |
ed447b95 | 780 | * Free Software:: Freely redistributable software |
b80282d5 | 781 | * Contributors:: Contributors to GDB |
70b88761 RP |
782 | @end menu |
783 | ||
4eb4cf57 | 784 | @node Free Software |
70b88761 | 785 | @unnumberedsec Free Software |
1041a570 | 786 | |
18fae2a8 | 787 | @value{GDBN} is @dfn{free software}, protected by the GNU General Public License |
1041a570 | 788 | (GPL). The GPL gives you the freedom to copy or adapt a licensed |
70b88761 RP |
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 | |
29a2b744 | 796 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
797 | from anyone else. |
798 | ||
18fae2a8 | 799 | @ifclear AGGLOMERATION |
29a2b744 | 800 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
18fae2a8 | 801 | @end ifclear |
1041a570 | 802 | |
4eb4cf57 | 803 | @node Contributors |
70b88761 RP |
804 | @unnumberedsec Contributors to GDB |
805 | ||
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 | |
93918348 | 818 | or your friends (or enemies, to be evenhanded) have been unfairly |
70b88761 RP |
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 | |
69bbcf05 | 823 | particularly thank those who shepherded GDB through major releases: Stu |
93918348 | 824 | Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore |
6f3ec223 RP |
825 | (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, |
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. | |
70b88761 RP |
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 | ||
1041a570 RP |
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. | |
70b88761 | 841 | |
1041a570 RP |
842 | David Johnson wrote the original COFF support; Pace Willison did |
843 | the original support for encapsulated COFF. | |
70b88761 RP |
844 | |
845 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
846 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
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. | |
70b88761 | 858 | |
c338a2fd RP |
859 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
860 | libraries. | |
70b88761 RP |
861 | |
862 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
863 | several machine instruction sets. | |
864 | ||
1041a570 RP |
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. | |
70b88761 | 868 | |
1041a570 RP |
869 | Brian Fox is the author of the readline libraries providing |
870 | command-line editing and command history. | |
70b88761 | 871 | |
1041a570 RP |
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. | |
c2bbbb22 | 875 | |
6f3ec223 RP |
876 | Fred Fish wrote most of the support for Unix System Vr4, and enhanced |
877 | the command-completion support to cover C++ overloaded symbols. | |
14d01801 | 878 | |
18fae2a8 | 879 | @ifset NOVEL |
4eb4cf57 | 880 | @node New Features |
ed447b95 | 881 | @unnumbered New Features since GDB Version 3.5 |
70b88761 RP |
882 | |
883 | @table @emph | |
884 | @item Targets | |
885 | Using the new command @code{target}, you can select at runtime whether | |
886 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
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 | |
b21b18e1 RP |
889 | stubs are available for Motorola 680x0, Intel 80386, and Sparc remote |
890 | systems; GDB also supports debugging realtime processes running under | |
b80282d5 | 891 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a |
b21b18e1 RP |
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. | |
70b88761 RP |
895 | |
896 | @item Watchpoints | |
c7cb8acb | 897 | GDB now sports watchpoints as well as breakpoints. You can use a |
70b88761 RP |
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 | ||
b80282d5 RP |
902 | @item Wide Output |
903 | Commands that issue wide output now insert newlines at places designed | |
904 | to make the output more readable. | |
905 | ||
70b88761 | 906 | @item Object Code Formats |
c7cb8acb | 907 | GDB uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
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 | |
93918348 | 911 | .o files, archive libraries, or core dumps. BFD is available as a |
3d3ab540 RP |
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. | |
70b88761 | 914 | |
b80282d5 | 915 | @item Configuration and Ports |
70b88761 | 916 | Compile-time configuration (to select a particular architecture and |
7463aadd | 917 | operating system) is much easier. The script @code{configure} now |
c7cb8acb RP |
918 | allows you to configure GDB as either a native debugger or a |
919 | cross-debugger. @xref{Installing GDB}, for details on how to | |
6a8cb0e7 | 920 | configure. |
70b88761 RP |
921 | |
922 | @item Interaction | |
93918348 RP |
923 | The user interface to the GDB control variables is simpler, |
924 | and is consolidated in two commands, @code{set} and @code{show}. Output | |
70b88761 RP |
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 | ||
b80282d5 | 929 | @item C++ |
c7cb8acb | 930 | GDB now supports C++ multiple inheritance (if used with a GCC |
b80282d5 | 931 | version 2 compiler), and also has limited support for C++ exception |
c7cb8acb | 932 | handling, with the commands @code{catch} and @code{info catch}: GDB |
b80282d5 RP |
933 | can break when an exception is raised, before the stack is peeled back |
934 | to the exception handler's context. | |
70b88761 | 935 | |
c2bbbb22 | 936 | @item Modula-2 |
ed447b95 RP |
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. | |
c2bbbb22 | 943 | |
70b88761 | 944 | @item Command Rationalization |
c7cb8acb | 945 | Many GDB commands have been renamed to make them easier to remember |
70b88761 RP |
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 | |
c7cb8acb | 948 | of your program, and the latter refer to the state of GDB itself. |
70b88761 RP |
949 | @xref{Renamed Commands}, for details on what commands were renamed. |
950 | ||
70b88761 | 951 | @item Shared Libraries |
77b46d13 JG |
952 | GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000 |
953 | shared libraries. | |
b80282d5 RP |
954 | |
955 | @item Reference Card | |
6f3ec223 | 956 | GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting |
ed447b95 | 957 | the Documentation}, for instructions about how to print it. |
70b88761 RP |
958 | |
959 | @item Work in Progress | |
960 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
961 | support. | |
70b88761 | 962 | @end table |
18fae2a8 | 963 | @end ifset |
70b88761 | 964 | |
18fae2a8 | 965 | @ifclear BARETARGET |
4eb4cf57 | 966 | @node Sample Session |
18fae2a8 | 967 | @chapter A Sample @value{GDBN} Session |
70b88761 | 968 | |
18fae2a8 | 969 | You can use this manual at your leisure to read all about @value{GDBN}. |
70b88761 | 970 | However, a handful of commands are enough to get started using the |
ed447b95 | 971 | debugger. This chapter illustrates those commands. |
70b88761 RP |
972 | |
973 | @iftex | |
6ca72cc6 | 974 | In this sample session, we emphasize user input like this: @b{input}, |
70b88761 RP |
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. | |
18fae2a8 | 980 | |
70b88761 RP |
981 | One of the preliminary versions of GNU @code{m4} (a generic macro |
982 | processor) exhibits the following bug: sometimes, when we change its | |
93918348 RP |
983 | quote strings from the default, the commands used to capture one macro |
984 | definition within another stop working. In the following short @code{m4} | |
70b88761 | 985 | session, we define a macro @code{foo} which expands to @code{0000}; we |
29a2b744 | 986 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
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 | |
6ca72cc6 RP |
992 | $ @b{cd gnu/m4} |
993 | $ @b{./m4} | |
994 | @b{define(foo,0000)} | |
70b88761 | 995 | |
6ca72cc6 | 996 | @b{foo} |
70b88761 | 997 | 0000 |
6ca72cc6 | 998 | @b{define(bar,defn(`foo'))} |
70b88761 | 999 | |
6ca72cc6 | 1000 | @b{bar} |
70b88761 | 1001 | 0000 |
6ca72cc6 | 1002 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 1003 | |
6ca72cc6 RP |
1004 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
1005 | @b{baz} | |
1006 | @b{C-d} | |
70b88761 RP |
1007 | m4: End of input: 0: fatal error: EOF in string |
1008 | @end smallexample | |
1009 | ||
1010 | @noindent | |
93918348 | 1011 | Let us use @value{GDBN} to try to see what is going on. |
70b88761 RP |
1012 | |
1013 | @smallexample | |
18fae2a8 | 1014 | $ @b{@value{GDBP} m4} |
203eea5d RP |
1015 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
1016 | @c FIXME... format to come out better. | |
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" | |
ed447b95 RP |
1021 | for details. |
1022 | GDB @value{GDBVN}, Copyright 1993 Free Software Foundation, Inc... | |
18fae2a8 | 1023 | (@value{GDBP}) |
70b88761 RP |
1024 | @end smallexample |
1025 | ||
1026 | @noindent | |
18fae2a8 | 1027 | @value{GDBN} reads only enough symbol data to know where to find the rest when |
1041a570 | 1028 | needed; as a result, the first prompt comes up very quickly. We now |
18fae2a8 | 1029 | tell @value{GDBN} to use a narrower display width than usual, so that examples |
1041a570 | 1030 | will fit in this manual. |
70b88761 RP |
1031 | |
1032 | @smallexample | |
18fae2a8 | 1033 | (@value{GDBP}) @b{set width 70} |
70b88761 RP |
1034 | @end smallexample |
1035 | ||
e251e767 | 1036 | @noindent |
93918348 | 1037 | We need to see how the @code{m4} built-in @code{changequote} works. |
70b88761 | 1038 | Having looked at the source, we know the relevant subroutine is |
93918348 | 1039 | @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN} |
70b88761 RP |
1040 | @code{break} command. |
1041 | ||
1042 | @smallexample | |
18fae2a8 | 1043 | (@value{GDBP}) @b{break m4_changequote} |
70b88761 RP |
1044 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. |
1045 | @end smallexample | |
1046 | ||
1047 | @noindent | |
18fae2a8 | 1048 | Using the @code{run} command, we start @code{m4} running under @value{GDBN} |
70b88761 RP |
1049 | control; as long as control does not reach the @code{m4_changequote} |
1050 | subroutine, the program runs as usual: | |
1051 | ||
1052 | @smallexample | |
18fae2a8 | 1053 | (@value{GDBP}) @b{run} |
e251e767 | 1054 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
6ca72cc6 | 1055 | @b{define(foo,0000)} |
70b88761 | 1056 | |
6ca72cc6 | 1057 | @b{foo} |
70b88761 RP |
1058 | 0000 |
1059 | @end smallexample | |
1060 | ||
1061 | @noindent | |
18fae2a8 | 1062 | To trigger the breakpoint, we call @code{changequote}. @value{GDBN} |
70b88761 RP |
1063 | suspends execution of @code{m4}, displaying information about the |
1064 | context where it stops. | |
1065 | ||
1066 | @smallexample | |
6ca72cc6 | 1067 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 1068 | |
203eea5d RP |
1069 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
1070 | at builtin.c:879 | |
38962738 | 1071 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) |
70b88761 RP |
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 | |
18fae2a8 | 1079 | (@value{GDBP}) @b{n} |
203eea5d RP |
1080 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
1081 | : nil, | |
70b88761 RP |
1082 | @end smallexample |
1083 | ||
1084 | @noindent | |
1085 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
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} | |
e251e767 | 1088 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
1089 | |
1090 | @smallexample | |
18fae2a8 | 1091 | (@value{GDBP}) @b{s} |
70b88761 RP |
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 | |
29a2b744 RP |
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. | |
70b88761 RP |
1104 | |
1105 | @smallexample | |
18fae2a8 | 1106 | (@value{GDBP}) @b{bt} |
70b88761 RP |
1107 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
1108 | at input.c:530 | |
203eea5d RP |
1109 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
1110 | at builtin.c:882 | |
70b88761 RP |
1111 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
1112 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
1113 | at macro.c:71 | |
1114 | #4 0x79dc in expand_input () at macro.c:40 | |
1115 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
1116 | @end smallexample | |
1117 | ||
1118 | @noindent | |
93918348 | 1119 | We will step through a few more lines to see what happens. The first two |
70b88761 RP |
1120 | times, we can use @samp{s}; the next two times we use @code{n} to avoid |
1121 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 1122 | |
70b88761 | 1123 | @smallexample |
18fae2a8 | 1124 | (@value{GDBP}) @b{s} |
70b88761 | 1125 | 0x3b5c 532 if (rquote != def_rquote) |
18fae2a8 | 1126 | (@value{GDBP}) @b{s} |
203eea5d RP |
1127 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
1128 | def_lquote : xstrdup(lq); | |
18fae2a8 | 1129 | (@value{GDBP}) @b{n} |
203eea5d RP |
1130 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
1131 | : xstrdup(rq); | |
18fae2a8 | 1132 | (@value{GDBP}) @b{n} |
70b88761 RP |
1133 | 538 len_lquote = strlen(rquote); |
1134 | @end smallexample | |
1135 | ||
1136 | @noindent | |
93918348 | 1137 | The last line displayed looks a little odd; we can examine the variables |
70b88761 | 1138 | @code{lquote} and @code{rquote} to see if they are in fact the new left |
93918348 | 1139 | and right quotes we specified. We use the command @code{p} |
70b88761 RP |
1140 | (@code{print}) to see their values. |
1141 | ||
1142 | @smallexample | |
18fae2a8 | 1143 | (@value{GDBP}) @b{p lquote} |
70b88761 | 1144 | $1 = 0x35d40 "<QUOTE>" |
18fae2a8 | 1145 | (@value{GDBP}) @b{p rquote} |
70b88761 RP |
1146 | $2 = 0x35d50 "<UNQUOTE>" |
1147 | @end smallexample | |
1148 | ||
1149 | @noindent | |
1150 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
93918348 RP |
1151 | To look at some context, we can display ten lines of source |
1152 | surrounding the current line with the @code{l} (@code{list}) command. | |
70b88761 RP |
1153 | |
1154 | @smallexample | |
18fae2a8 | 1155 | (@value{GDBP}) @b{l} |
70b88761 | 1156 | 533 xfree(rquote); |
e251e767 | 1157 | 534 |
203eea5d RP |
1158 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
1159 | : xstrdup (lq); | |
1160 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
1161 | : xstrdup (rq); | |
e251e767 | 1162 | 537 |
70b88761 RP |
1163 | 538 len_lquote = strlen(rquote); |
1164 | 539 len_rquote = strlen(lquote); | |
1165 | 540 @} | |
e251e767 | 1166 | 541 |
70b88761 RP |
1167 | 542 void |
1168 | @end smallexample | |
1169 | ||
1170 | @noindent | |
93918348 | 1171 | Let us step past the two lines that set @code{len_lquote} and |
70b88761 RP |
1172 | @code{len_rquote}, and then examine the values of those variables. |
1173 | ||
1174 | @smallexample | |
18fae2a8 | 1175 | (@value{GDBP}) @b{n} |
70b88761 | 1176 | 539 len_rquote = strlen(lquote); |
18fae2a8 | 1177 | (@value{GDBP}) @b{n} |
70b88761 | 1178 | 540 @} |
18fae2a8 | 1179 | (@value{GDBP}) @b{p len_lquote} |
70b88761 | 1180 | $3 = 9 |
18fae2a8 | 1181 | (@value{GDBP}) @b{p len_rquote} |
70b88761 RP |
1182 | $4 = 7 |
1183 | @end smallexample | |
1184 | ||
1185 | @noindent | |
1186 | That certainly looks wrong, assuming @code{len_lquote} and | |
1187 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
93918348 RP |
1188 | @code{rquote} respectively. We can set them to better values using |
1189 | the @code{p} command, since it can print the value of | |
70b88761 | 1190 | any expression---and that expression can include subroutine calls and |
e251e767 | 1191 | assignments. |
70b88761 RP |
1192 | |
1193 | @smallexample | |
18fae2a8 | 1194 | (@value{GDBP}) @b{p len_lquote=strlen(lquote)} |
70b88761 | 1195 | $5 = 7 |
18fae2a8 | 1196 | (@value{GDBP}) @b{p len_rquote=strlen(rquote)} |
70b88761 RP |
1197 | $6 = 9 |
1198 | @end smallexample | |
1199 | ||
1200 | @noindent | |
93918348 RP |
1201 | Is that enough to fix the problem of using the new quotes with the |
1202 | @code{m4} built-in @code{defn}? We can allow @code{m4} to continue | |
70b88761 RP |
1203 | executing with the @code{c} (@code{continue}) command, and then try the |
1204 | example that caused trouble initially: | |
1205 | ||
1206 | @smallexample | |
18fae2a8 | 1207 | (@value{GDBP}) @b{c} |
70b88761 RP |
1208 | Continuing. |
1209 | ||
6ca72cc6 | 1210 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
70b88761 RP |
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 | |
93918348 | 1219 | lengths. We allow @code{m4} exit by giving it an EOF as input: |
70b88761 RP |
1220 | |
1221 | @smallexample | |
6ca72cc6 | 1222 | @b{C-d} |
70b88761 RP |
1223 | Program exited normally. |
1224 | @end smallexample | |
1225 | ||
e251e767 | 1226 | @noindent |
18fae2a8 RP |
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. | |
70b88761 RP |
1230 | |
1231 | @smallexample | |
18fae2a8 RP |
1232 | (@value{GDBP}) @b{quit} |
1233 | @end smallexample | |
1234 | @end ifclear | |
70b88761 | 1235 | |
4eb4cf57 | 1236 | @node Invocation |
18fae2a8 | 1237 | @chapter Getting In and Out of @value{GDBN} |
70b88761 | 1238 | |
18fae2a8 RP |
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} | |
c7cb8acb | 1241 | or @kbd{C-d} to exit.) |
29a2b744 | 1242 | |
18fae2a8 RP |
1243 | @ignore |
1244 | @c original form of menu, pre-unfolding: | |
70b88761 | 1245 | @menu |
ed447b95 RP |
1246 | * Invoking GDB:: How to start @value{GDBN} |
1247 | * Quitting GDB:: How to quit @value{GDBN} | |
18fae2a8 | 1248 | @ifclear BARETARGET |
ed447b95 | 1249 | * Shell Commands:: How to use shell commands inside @value{GDBN} |
18fae2a8 | 1250 | @end ifclear |
70b88761 | 1251 | @end menu |
18fae2a8 | 1252 | @end ignore |
70b88761 | 1253 | |
18fae2a8 RP |
1254 | @ifclear BARETARGET |
1255 | @menu | |
ed447b95 RP |
1256 | * Invoking GDB:: How to start @value{GDBN} |
1257 | * Quitting GDB:: How to quit @value{GDBN} | |
1258 | * Shell Commands:: How to use shell commands inside @value{GDBN} | |
18fae2a8 RP |
1259 | @end menu |
1260 | @end ifclear | |
70b88761 | 1261 | |
18fae2a8 RP |
1262 | @ifset BARETARGET |
1263 | @menu | |
ed447b95 RP |
1264 | * Invoking GDB:: How to start @value{GDBN} |
1265 | * Quitting GDB:: How to quit @value{GDBN} | |
18fae2a8 RP |
1266 | @end menu |
1267 | @end ifset | |
1268 | ||
1269 | @node Invoking GDB | |
ed447b95 | 1270 | @section Invoking @value{GDBN} |
18fae2a8 RP |
1271 | |
1272 | @ifset HviiiEXCLUSIVE | |
1273 | For details on starting up @value{GDBP} as a | |
4eb4cf57 | 1274 | remote debugger attached to a Hitachi H8/300 board, see @ref{Hitachi |
18fae2a8 RP |
1275 | H8/300 Remote,,@value{GDBN} and the Hitachi H8/300}. |
1276 | @end ifset | |
4eb4cf57 | 1277 | |
ed447b95 | 1278 | Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started, |
18fae2a8 | 1279 | @value{GDBN} reads commands from the terminal until you tell it to exit. |
70b88761 | 1280 | |
18fae2a8 | 1281 | You can also run @code{@value{GDBP}} with a variety of arguments and options, |
c7cb8acb RP |
1282 | to specify more of your debugging environment at the outset. |
1283 | ||
18fae2a8 | 1284 | @ifset GENERIC |
c7cb8acb RP |
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. | |
18fae2a8 | 1288 | @end ifset |
c7cb8acb | 1289 | |
18fae2a8 | 1290 | The most usual way to start @value{GDBN} is with one argument, |
4eb4cf57 | 1291 | specifying an executable program: |
1041a570 | 1292 | |
70b88761 | 1293 | @example |
18fae2a8 | 1294 | @value{GDBP} @var{program} |
70b88761 | 1295 | @end example |
1041a570 | 1296 | |
18fae2a8 | 1297 | @ifclear BARETARGET |
70b88761 | 1298 | @noindent |
29a2b744 RP |
1299 | You can also start with both an executable program and a core file |
1300 | specified: | |
1041a570 | 1301 | |
70b88761 | 1302 | @example |
18fae2a8 | 1303 | @value{GDBP} @var{program} @var{core} |
70b88761 RP |
1304 | @end example |
1305 | ||
b80282d5 RP |
1306 | You can, instead, specify a process ID as a second argument, if you want |
1307 | to debug a running process: | |
1041a570 | 1308 | |
b80282d5 | 1309 | @example |
18fae2a8 | 1310 | @value{GDBP} @var{program} 1234 |
b80282d5 | 1311 | @end example |
1041a570 | 1312 | |
b80282d5 | 1313 | @noindent |
18fae2a8 RP |
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). | |
b80282d5 | 1316 | |
c7cb8acb | 1317 | Taking advantage of the second command-line argument requires a fairly |
18fae2a8 | 1318 | complete operating system; when you use @value{GDBN} as a remote debugger |
c7cb8acb RP |
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. | |
18fae2a8 | 1321 | @end ifclear |
c7cb8acb | 1322 | |
70b88761 | 1323 | @noindent |
18fae2a8 RP |
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. | |
29a2b744 RP |
1326 | |
1327 | @noindent | |
1328 | Type | |
1329 | ||
70b88761 | 1330 | @example |
18fae2a8 | 1331 | @value{GDBP} -help |
70b88761 | 1332 | @end example |
29a2b744 | 1333 | |
70b88761 | 1334 | @noindent |
29a2b744 | 1335 | to display all available options and briefly describe their use |
18fae2a8 | 1336 | (@samp{@value{GDBP} -h} is a shorter equivalent). |
70b88761 RP |
1337 | |
1338 | All options and command line arguments you give are processed | |
1339 | in sequential order. The order makes a difference when the | |
e251e767 | 1340 | @samp{-x} option is used. |
70b88761 | 1341 | |
18fae2a8 RP |
1342 | |
1343 | @ignore | |
1344 | @c original, intended form of this menu (pre-unfolding): | |
70b88761 | 1345 | @menu |
18fae2a8 RP |
1346 | @ifclear GENERIC |
1347 | @ifset REMOTESTUB | |
1348 | * Remote Serial:: @value{GDBN} remote serial protocol | |
1349 | @end ifset | |
1350 | @ifset Icmlx | |
1351 | * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy) | |
1352 | @end ifset | |
1353 | @ifset AMDxxixK | |
1354 | * EB29K Remote:: @value{GDBN} with a remote EB29K | |
1355 | @end ifset | |
1356 | @ifset VXWORKS | |
1357 | * VxWorks Remote:: @value{GDBN} and VxWorks | |
1358 | @end ifset | |
1359 | @ifset STmm | |
1360 | * ST2000 Remote:: @value{GDBN} with a Tandem ST2000 | |
1361 | @end ifset | |
1362 | @ifset Hviii | |
1363 | * Hitachi H8/300 Remote:: @value{GDBN} and the Hitachi H8/300 | |
1364 | @end ifset | |
1365 | @ifset ZviiiK | |
1366 | * Z8000 Simulator:: @value{GDBN} and its Zilog Z8000 Simulator | |
1367 | @end ifset | |
1368 | @end ifclear | |
ed447b95 RP |
1369 | * File Options:: Choosing files |
1370 | * Mode Options:: Choosing modes | |
70b88761 | 1371 | @end menu |
18fae2a8 | 1372 | @end ignore |
70b88761 | 1373 | |
18fae2a8 RP |
1374 | @c Unfolded form: |
1375 | @c Sigh--- GENERIC plus 7 switches mean 1+2^7 forms of this menu! | |
1376 | @c Add them only on demand; no point in including forms for which | |
1377 | @c there's no defined config file. Maybe by the time all are needed, | |
1378 | @c makeinfo will be capable of dealing with menus like the above. | |
1379 | ||
1380 | @ifset GENERIC | |
1381 | @menu | |
ed447b95 RP |
1382 | * File Options:: Choosing files |
1383 | * Mode Options:: Choosing modes | |
18fae2a8 RP |
1384 | @end menu |
1385 | @end ifset | |
1386 | ||
1387 | @c Hviii config: !GENERIC && Hviii && nothing else | |
1388 | @ifclear GENERIC | |
1389 | @ifclear REMOTESTUB | |
1390 | @ifclear Icmlx | |
1391 | @ifclear AMDxxixK | |
1392 | @ifclear VXWORKS | |
1393 | @ifclear STmm | |
1394 | @ifset Hviii | |
1395 | @ifclear ZviiiK | |
1396 | @menu | |
1397 | * Hitachi H8/300 Remote:: @value{GDBN} and the Hitachi H8/300 | |
ed447b95 RP |
1398 | * File Options:: Choosing files |
1399 | * Mode Options:: Choosing modes | |
18fae2a8 RP |
1400 | @end menu |
1401 | @end ifclear | |
1402 | @end ifset | |
1403 | @end ifclear | |
1404 | @end ifclear | |
1405 | @end ifclear | |
1406 | @end ifclear | |
1407 | @end ifclear | |
1408 | @end ifclear | |
1409 | ||
1410 | @ifclear GENERIC | |
1411 | @include gdbinv-s.texi | |
1412 | @end ifclear | |
4eb4cf57 RP |
1413 | |
1414 | @node File Options | |
70b88761 RP |
1415 | @subsection Choosing Files |
1416 | ||
18fae2a8 RP |
1417 | @ifclear BARETARGET |
1418 | When @value{GDBN} starts, it reads any arguments other than options as | |
29a2b744 RP |
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 | |
18fae2a8 | 1421 | @samp{-c} options respectively. (@value{GDBN} reads the first argument |
29a2b744 RP |
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.) | |
18fae2a8 RP |
1426 | @end ifclear |
1427 | @ifset BARETARGET | |
1428 | When @value{GDBN} starts, it reads any argument other than options as | |
4eb4cf57 RP |
1429 | specifying an executable file. This is the same as if the argument was |
1430 | specified by the @samp{-se} option. | |
18fae2a8 | 1431 | @end ifset |
29a2b744 RP |
1432 | |
1433 | Many options have both long and short forms; both are shown in the | |
18fae2a8 | 1434 | following list. @value{GDBN} also recognizes the long forms if you truncate |
29a2b744 RP |
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.) | |
70b88761 RP |
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 | ||
3d3ab540 | 1450 | @item -se=@var{file} |
70b88761 RP |
1451 | Read symbol table from file @var{file} and use it as the executable |
1452 | file. | |
1453 | ||
18fae2a8 | 1454 | @ifclear BARETARGET |
70b88761 RP |
1455 | @item -core=@var{file} |
1456 | @itemx -c @var{file} | |
1457 | Use file @var{file} as a core dump to examine. | |
18fae2a8 | 1458 | @end ifclear |
70b88761 RP |
1459 | |
1460 | @item -command=@var{file} | |
1461 | @itemx -x @var{file} | |
18fae2a8 | 1462 | Execute @value{GDBN} commands from file @var{file}. @xref{Command Files}. |
70b88761 RP |
1463 | |
1464 | @item -directory=@var{directory} | |
1465 | @itemx -d @var{directory} | |
1466 | Add @var{directory} to the path to search for source files. | |
14d01801 | 1467 | |
18fae2a8 | 1468 | @ifclear BARETARGET |
14d01801 RP |
1469 | @item -m |
1470 | @itemx -mapped | |
1471 | @emph{Warning: this option depends on operating system facilities that are not | |
1472 | supported on all systems.}@* | |
77b46d13 JG |
1473 | If memory-mapped files are available on your system through the @code{mmap} |
1474 | system call, you can use this option | |
18fae2a8 | 1475 | to have @value{GDBN} write the symbols from your |
77b46d13 JG |
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}. | |
18fae2a8 | 1478 | Future @value{GDBN} debugging sessions will notice the presence of this file, |
77b46d13 JG |
1479 | and will quickly map in symbol information from it, rather than reading |
1480 | the symbol table from the executable program. | |
1481 | ||
18fae2a8 | 1482 | The @file{.syms} file is specific to the host machine on which @value{GDBN} is run. |
93918348 | 1483 | It holds an exact image of the internal @value{GDBN} symbol table. It cannot be |
77b46d13 | 1484 | shared across multiple host platforms. |
18fae2a8 | 1485 | @end ifclear |
77b46d13 JG |
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. | |
70b88761 RP |
1492 | @end table |
1493 | ||
18fae2a8 | 1494 | @ifclear BARETARGET |
93918348 RP |
1495 | The @code{-mapped} and @code{-readnow} options are typically combined in |
1496 | order to build a @file{.syms} file that contains complete symbol | |
1497 | information. (@xref{Files,,Commands to Specify Files}, for information | |
1498 | on @file{.syms} files.) A simple GDB invocation to do nothing but build | |
1499 | a @file{.syms} file for future use is: | |
77b46d13 JG |
1500 | |
1501 | @example | |
1502 | gdb -batch -nx -mapped -readnow programname | |
1503 | @end example | |
18fae2a8 | 1504 | @end ifclear |
77b46d13 | 1505 | |
4eb4cf57 | 1506 | @node Mode Options |
1041a570 RP |
1507 | @subsection Choosing Modes |
1508 | ||
18fae2a8 | 1509 | You can run @value{GDBN} in various alternative modes---for example, in |
29a2b744 | 1510 | batch mode or quiet mode. |
70b88761 RP |
1511 | |
1512 | @table @code | |
1513 | @item -nx | |
1514 | @itemx -n | |
18fae2a8 | 1515 | Do not execute commands from any @file{@value{GDBINIT}} initialization files. |
70b88761 | 1516 | Normally, the commands in these files are executed after all the |
e251e767 | 1517 | command options and arguments have been processed. |
c728f1f0 | 1518 | @xref{Command Files}. |
70b88761 RP |
1519 | |
1520 | @item -quiet | |
1521 | @itemx -q | |
1522 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 1523 | messages are also suppressed in batch mode. |
70b88761 RP |
1524 | |
1525 | @item -batch | |
1526 | Run in batch mode. Exit with status @code{0} after processing all the command | |
18fae2a8 RP |
1527 | files specified with @samp{-x} (and @file{@value{GDBINIT}}, if not inhibited). |
1528 | Exit with nonzero status if an error occurs in executing the @value{GDBN} | |
e251e767 | 1529 | commands in the command files. |
70b88761 | 1530 | |
18fae2a8 | 1531 | Batch mode may be useful for running @value{GDBN} as a filter, for example to |
70b88761 | 1532 | download and run a program on another computer; in order to make this |
e251e767 | 1533 | more useful, the message |
1041a570 | 1534 | |
70b88761 RP |
1535 | @example |
1536 | Program exited normally. | |
1537 | @end example | |
1041a570 | 1538 | |
70b88761 | 1539 | @noindent |
18fae2a8 | 1540 | (which is ordinarily issued whenever a program running under @value{GDBN} control |
70b88761 RP |
1541 | terminates) is not issued when running in batch mode. |
1542 | ||
3d3ab540 | 1543 | @item -cd=@var{directory} |
18fae2a8 | 1544 | Run @value{GDBN} using @var{directory} as its working directory, |
70b88761 RP |
1545 | instead of the current directory. |
1546 | ||
18fae2a8 | 1547 | @ifset LUCID |
45c53080 | 1548 | @item -context @var{authentication} |
18fae2a8 | 1549 | When the Energize programming system starts up @value{GDBN}, it uses this |
6ca72cc6 | 1550 | option to trigger an alternate mode of interaction. |
18fae2a8 | 1551 | @var{authentication} is a pair of numeric codes that identify @value{GDBN} |
6ca72cc6 | 1552 | as a client in the Energize environment. Avoid this option when you run |
18fae2a8 RP |
1553 | @value{GDBN} directly from the command line. See @ref{Energize,,Using |
1554 | @value{GDBN} with Energize} for more discussion of using @value{GDBN} with Energize. | |
1555 | @end ifset | |
6ca72cc6 | 1556 | |
70b88761 RP |
1557 | @item -fullname |
1558 | @itemx -f | |
18fae2a8 | 1559 | Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells @value{GDBN} |
70b88761 RP |
1560 | to output the full file name and line number in a standard, |
1561 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 1562 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
1563 | like two @samp{\032} characters, followed by the file name, line number |
1564 | and character position separated by colons, and a newline. The | |
18fae2a8 | 1565 | Emacs-to-@value{GDBN} interface program uses the two @samp{\032} characters as |
70b88761 RP |
1566 | a signal to display the source code for the frame. |
1567 | ||
18fae2a8 | 1568 | @ifset SERIAL |
70b88761 RP |
1569 | @item -b @var{bps} |
1570 | Set the line speed (baud rate or bits per second) of any serial | |
18fae2a8 | 1571 | interface used by @value{GDBN} for remote debugging. |
70b88761 | 1572 | |
3d3ab540 | 1573 | @item -tty=@var{device} |
70b88761 | 1574 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 1575 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
18fae2a8 | 1576 | @end ifset |
70b88761 RP |
1577 | @end table |
1578 | ||
ed447b95 RP |
1579 | @node Quitting GDB |
1580 | @section Quitting @value{GDBN} | |
18fae2a8 | 1581 | @cindex exiting @value{GDBN} |
ed447b95 | 1582 | @cindex leaving @value{GDBN} |
1041a570 | 1583 | |
70b88761 RP |
1584 | @table @code |
1585 | @item quit | |
1586 | @kindex quit | |
1587 | @kindex q | |
18fae2a8 | 1588 | To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or type |
e251e767 | 1589 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
1590 | @end table |
1591 | ||
1592 | @cindex interrupt | |
18fae2a8 RP |
1593 | An interrupt (often @kbd{C-c}) will not exit from @value{GDBN}, but rather |
1594 | will terminate the action of any @value{GDBN} command that is in progress and | |
1595 | return to @value{GDBN} command level. It is safe to type the interrupt | |
1596 | character at any time because @value{GDBN} does not allow it to take effect | |
70b88761 RP |
1597 | until a time when it is safe. |
1598 | ||
18fae2a8 | 1599 | @ifclear BARETARGET |
ed447b95 RP |
1600 | If you have been using @value{GDBN} to control an attached process or |
1601 | device, you can release it with the @code{detach} command | |
1602 | (@pxref{Attach, ,Debugging an Already-Running Process}). | |
18fae2a8 | 1603 | @end ifclear |
70b88761 | 1604 | |
18fae2a8 | 1605 | @ifclear BARETARGET |
4eb4cf57 | 1606 | @node Shell Commands |
70b88761 | 1607 | @section Shell Commands |
1041a570 | 1608 | |
70b88761 | 1609 | If you need to execute occasional shell commands during your |
18fae2a8 | 1610 | debugging session, there is no need to leave or suspend @value{GDBN}; you can |
70b88761 RP |
1611 | just use the @code{shell} command. |
1612 | ||
1613 | @table @code | |
1614 | @item shell @var{command string} | |
1615 | @kindex shell | |
1616 | @cindex shell escape | |
18fae2a8 | 1617 | Directs @value{GDBN} to invoke an inferior shell to execute @var{command |
70b88761 | 1618 | string}. If it exists, the environment variable @code{SHELL} is used |
18fae2a8 | 1619 | for the name of the shell to run. Otherwise @value{GDBN} uses |
70b88761 RP |
1620 | @code{/bin/sh}. |
1621 | @end table | |
1622 | ||
1623 | The utility @code{make} is often needed in development environments. | |
18fae2a8 | 1624 | You do not have to use the @code{shell} command for this purpose in @value{GDBN}: |
70b88761 RP |
1625 | |
1626 | @table @code | |
1627 | @item make @var{make-args} | |
1628 | @kindex make | |
1629 | @cindex calling make | |
18fae2a8 | 1630 | Causes @value{GDBN} to execute an inferior @code{make} program with the specified |
70b88761 RP |
1631 | arguments. This is equivalent to @samp{shell make @var{make-args}}. |
1632 | @end table | |
18fae2a8 | 1633 | @end ifclear |
70b88761 | 1634 | |
4eb4cf57 | 1635 | @node Commands |
18fae2a8 | 1636 | @chapter @value{GDBN} Commands |
70b88761 | 1637 | |
18fae2a8 | 1638 | You can abbreviate a @value{GDBN} command to the first few letters of the command |
6f3ec223 | 1639 | name, if that abbreviation is unambiguous; and you can repeat certain |
18fae2a8 RP |
1640 | @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB} |
1641 | key to get @value{GDBN} to fill out the rest of a word in a command (or to | |
93918348 | 1642 | show you the alternatives available, if there is more than one possibility). |
29a2b744 | 1643 | |
70b88761 | 1644 | @menu |
ed447b95 RP |
1645 | * Command Syntax:: How to give commands to @value{GDBN} |
1646 | * Completion:: Command completion | |
1647 | * Help:: How to ask @value{GDBN} for help | |
70b88761 RP |
1648 | @end menu |
1649 | ||
4eb4cf57 | 1650 | @node Command Syntax |
70b88761 | 1651 | @section Command Syntax |
1041a570 | 1652 | |
18fae2a8 | 1653 | A @value{GDBN} command is a single line of input. There is no limit on how long |
70b88761 RP |
1654 | it can be. It starts with a command name, which is followed by arguments |
1655 | whose meaning depends on the command name. For example, the command | |
1656 | @code{step} accepts an argument which is the number of times to step, | |
1657 | as in @samp{step 5}. You can also use the @code{step} command with | |
1658 | no arguments. Some command names do not allow any arguments. | |
1659 | ||
1660 | @cindex abbreviation | |
18fae2a8 | 1661 | @value{GDBN} command names may always be truncated if that abbreviation is |
70b88761 RP |
1662 | unambiguous. Other possible command abbreviations are listed in the |
1663 | documentation for individual commands. In some cases, even ambiguous | |
1664 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1665 | equivalent to @code{step} even though there are other commands whose | |
1666 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1667 | arguments to the @code{help} command. |
70b88761 | 1668 | |
e251e767 | 1669 | @cindex repeating commands |
70b88761 | 1670 | @kindex RET |
18fae2a8 | 1671 | A blank line as input to @value{GDBN} (typing just @key{RET}) means to |
70b88761 RP |
1672 | repeat the previous command. Certain commands (for example, @code{run}) |
1673 | will not repeat this way; these are commands for which unintentional | |
1674 | repetition might cause trouble and which you are unlikely to want to | |
1675 | repeat. | |
1676 | ||
1677 | The @code{list} and @code{x} commands, when you repeat them with | |
1678 | @key{RET}, construct new arguments rather than repeating | |
1679 | exactly as typed. This permits easy scanning of source or memory. | |
1680 | ||
18fae2a8 | 1681 | @value{GDBN} can also use @key{RET} in another way: to partition lengthy |
b80282d5 | 1682 | output, in a way similar to the common utility @code{more} |
29a2b744 | 1683 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many |
18fae2a8 | 1684 | in this situation, @value{GDBN} disables command repetition after any command |
b80282d5 RP |
1685 | that generates this sort of display. |
1686 | ||
70b88761 RP |
1687 | @kindex # |
1688 | @cindex comment | |
1689 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
29a2b744 | 1690 | This is useful mainly in command files (@pxref{Command Files}). |
70b88761 | 1691 | |
4eb4cf57 | 1692 | @node Completion |
6f3ec223 RP |
1693 | @section Command Completion |
1694 | ||
1695 | @cindex completion | |
1696 | @cindex word completion | |
93918348 | 1697 | @value{GDBN} can fill in the rest of a word in a command for you, if there is |
6f3ec223 | 1698 | only one possibility; it can also show you what the valid possibilities |
18fae2a8 RP |
1699 | are for the next word in a command, at any time. This works for @value{GDBN} |
1700 | commands, @value{GDBN} subcommands, and the names of symbols in your program. | |
6f3ec223 | 1701 | |
18fae2a8 | 1702 | Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest |
93918348 | 1703 | of a word. If there is only one possibility, @value{GDBN} will fill in the |
6f3ec223 RP |
1704 | word, and wait for you to finish the command (or press @key{RET} to |
1705 | enter it). For example, if you type | |
1706 | ||
93918348 | 1707 | @c FIXME "@key" does not distinguish its argument sufficiently to permit |
0fdc6e27 RP |
1708 | @c complete accuracy in these examples; space introduced for clarity. |
1709 | @c If texinfo enhancements make it unnecessary, it would be nice to | |
1710 | @c replace " @key" by "@key" in the following... | |
6f3ec223 | 1711 | @example |
18fae2a8 | 1712 | (@value{GDBP}) info bre @key{TAB} |
6f3ec223 RP |
1713 | @end example |
1714 | ||
1715 | @noindent | |
93918348 | 1716 | @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is |
6f3ec223 RP |
1717 | the only @code{info} subcommand beginning with @samp{bre}: |
1718 | ||
1719 | @example | |
18fae2a8 | 1720 | (@value{GDBP}) info breakpoints |
6f3ec223 RP |
1721 | @end example |
1722 | ||
1723 | @noindent | |
1724 | You can either press @key{RET} at this point, to run the @code{info | |
1725 | breakpoints} command, or backspace and enter something else, if | |
93918348 | 1726 | @samp{breakpoints} does not look like the command you expected. (If you |
6f3ec223 RP |
1727 | were sure you wanted @code{info breakpoints} in the first place, you |
1728 | might as well just type @key{RET} immediately after @samp{info bre}, | |
1729 | to exploit command abbreviations rather than command completion). | |
1730 | ||
1731 | If there is more than one possibility for the next word when you press | |
18fae2a8 | 1732 | @key{TAB}, @value{GDBN} will sound a bell. You can either supply more |
6f3ec223 | 1733 | characters and try again, or just press @key{TAB} a second time, and |
18fae2a8 | 1734 | @value{GDBN} will display all the possible completions for that word. For |
6f3ec223 | 1735 | example, you might want to set a breakpoint on a subroutine whose name |
18fae2a8 | 1736 | begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN} |
6f3ec223 RP |
1737 | just sounds the bell. Typing @key{TAB} again will display all the |
1738 | function names in your program that begin with those characters, for | |
1739 | example: | |
1740 | ||
1741 | @example | |
18fae2a8 RP |
1742 | (@value{GDBP}) b make_ @key{TAB} |
1743 | @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see: | |
6f3ec223 RP |
1744 | make_a_section_from_file make_environ |
1745 | make_abs_section make_function_type | |
1746 | make_blockvector make_pointer_type | |
1747 | make_cleanup make_reference_type | |
1748 | make_command make_symbol_completion_list | |
18fae2a8 | 1749 | (@value{GDBP}) b make_ |
6f3ec223 RP |
1750 | @end example |
1751 | ||
1752 | @noindent | |
18fae2a8 | 1753 | After displaying the available possibilities, @value{GDBN} copies your |
b1385986 | 1754 | partial input (@samp{b make_} in the example) so you can finish the |
6f3ec223 RP |
1755 | command. |
1756 | ||
1757 | If you just want to see the list of alternatives in the first place, you | |
b1385986 | 1758 | can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?} |
0f153e74 | 1759 | means @kbd{@key{META} ?}. You can type this |
18fae2a8 | 1760 | @ifclear DOSHOST |
0f153e74 | 1761 | either by holding down a |
b1385986 | 1762 | key designated as the @key{META} shift on your keyboard (if there is |
0f153e74 | 1763 | one) while typing @kbd{?}, or |
18fae2a8 | 1764 | @end ifclear |
0f153e74 | 1765 | as @key{ESC} followed by @kbd{?}. |
6f3ec223 RP |
1766 | |
1767 | @cindex quotes in commands | |
1768 | @cindex completion of quoted strings | |
1769 | Sometimes the string you need, while logically a ``word'', may contain | |
18fae2a8 | 1770 | parentheses or other characters that @value{GDBN} normally excludes from its |
6f3ec223 | 1771 | notion of a word. To permit word completion to work in this situation, |
18fae2a8 | 1772 | you may enclose words in @code{'} (single quote marks) in @value{GDBN} commands. |
6f3ec223 RP |
1773 | |
1774 | The most likely situation where you might need this is in typing the | |
1775 | name of a C++ function. This is because C++ allows function overloading | |
1776 | (multiple definitions of the same function, distinguished by argument | |
b1385986 RP |
1777 | type). For example, when you want to set a breakpoint you may need to |
1778 | distinguish whether you mean the version of @code{name} that takes an | |
1779 | @code{int} parameter, @code{name(int)}, or the version that takes a | |
1780 | @code{float} parameter, @code{name(float)}. To use the word-completion | |
1781 | facilities in this situation, type a single quote @code{'} at the | |
18fae2a8 | 1782 | beginning of the function name. This alerts @value{GDBN} that it may need to |
b1385986 RP |
1783 | consider more information than usual when you press @key{TAB} or |
1784 | @kbd{M-?} to request word completion: | |
6f3ec223 RP |
1785 | |
1786 | @example | |
18fae2a8 | 1787 | (@value{GDBP}) b 'bubble( @key{M-?} |
0fdc6e27 | 1788 | bubble(double,double) bubble(int,int) |
18fae2a8 | 1789 | (@value{GDBP}) b 'bubble( |
6f3ec223 RP |
1790 | @end example |
1791 | ||
18fae2a8 RP |
1792 | In some cases, @value{GDBN} can tell that completing a name will require |
1793 | quotes. When this happens, @value{GDBN} will insert the quote for you (while | |
0fdc6e27 RP |
1794 | completing as much as it can) if you do not type the quote in the first |
1795 | place: | |
1796 | ||
1797 | @example | |
18fae2a8 RP |
1798 | (@value{GDBP}) b bub @key{TAB} |
1799 | @exdent @value{GDBN} alters your input line to the following, and rings a bell: | |
1800 | (@value{GDBP}) b 'bubble( | |
0fdc6e27 RP |
1801 | @end example |
1802 | ||
1803 | @noindent | |
18fae2a8 | 1804 | In general, @value{GDBN} can tell that a quote is needed (and inserts it) if |
0fdc6e27 RP |
1805 | you have not yet started typing the argument list when you ask for |
1806 | completion on an overloaded symbol. | |
1807 | ||
1808 | ||
4eb4cf57 | 1809 | @node Help |
70b88761 RP |
1810 | @section Getting Help |
1811 | @cindex online documentation | |
1812 | @kindex help | |
1041a570 | 1813 | |
18fae2a8 | 1814 | You can always ask @value{GDBN} itself for information on its commands, using the |
e251e767 | 1815 | command @code{help}. |
70b88761 RP |
1816 | |
1817 | @table @code | |
1818 | @item help | |
1819 | @itemx h | |
1820 | @kindex h | |
1821 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1822 | display a short list of named classes of commands: | |
1041a570 | 1823 | |
70b88761 | 1824 | @smallexample |
18fae2a8 | 1825 | (@value{GDBP}) help |
70b88761 RP |
1826 | List of classes of commands: |
1827 | ||
1828 | running -- Running the program | |
1829 | stack -- Examining the stack | |
1830 | data -- Examining data | |
1831 | breakpoints -- Making program stop at certain points | |
1832 | files -- Specifying and examining files | |
1833 | status -- Status inquiries | |
1834 | support -- Support facilities | |
1835 | user-defined -- User-defined commands | |
1836 | aliases -- Aliases of other commands | |
1837 | obscure -- Obscure features | |
1838 | ||
203eea5d RP |
1839 | Type "help" followed by a class name for a list of |
1840 | commands in that class. | |
1841 | Type "help" followed by command name for full | |
1842 | documentation. | |
70b88761 | 1843 | Command name abbreviations are allowed if unambiguous. |
18fae2a8 | 1844 | (@value{GDBP}) |
70b88761 RP |
1845 | @end smallexample |
1846 | ||
1847 | @item help @var{class} | |
1848 | Using one of the general help classes as an argument, you can get a | |
1849 | list of the individual commands in that class. For example, here is the | |
1850 | help display for the class @code{status}: | |
1041a570 | 1851 | |
70b88761 | 1852 | @smallexample |
18fae2a8 | 1853 | (@value{GDBP}) help status |
70b88761 RP |
1854 | Status inquiries. |
1855 | ||
1856 | List of commands: | |
1857 | ||
1858 | show -- Generic command for showing things set with "set" | |
1859 | info -- Generic command for printing status | |
1860 | ||
203eea5d RP |
1861 | Type "help" followed by command name for full |
1862 | documentation. | |
70b88761 | 1863 | Command name abbreviations are allowed if unambiguous. |
18fae2a8 | 1864 | (@value{GDBP}) |
70b88761 RP |
1865 | @end smallexample |
1866 | ||
1867 | @item help @var{command} | |
18fae2a8 | 1868 | With a command name as @code{help} argument, @value{GDBN} will display a |
e251e767 | 1869 | short paragraph on how to use that command. |
70b88761 RP |
1870 | @end table |
1871 | ||
18fae2a8 | 1872 | In addition to @code{help}, you can use the @value{GDBN} commands @code{info} |
70b88761 | 1873 | and @code{show} to inquire about the state of your program, or the state |
18fae2a8 | 1874 | of @value{GDBN} itself. Each command supports many topics of inquiry; this |
70b88761 RP |
1875 | manual introduces each of them in the appropriate context. The listings |
1876 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1877 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1878 | |
1879 | @c @group | |
1880 | @table @code | |
1881 | @item info | |
1882 | @kindex info | |
1883 | @kindex i | |
1884 | This command (abbreviated @code{i}) is for describing the state of your | |
ed447b95 RP |
1885 | program. For example, you can list the arguments given to your program |
1886 | with @code{info args}, list the registers currently in use with @code{info | |
1887 | registers}, or list the breakpoints you have set with @code{info breakpoints}. | |
70b88761 RP |
1888 | You can get a complete list of the @code{info} sub-commands with |
1889 | @w{@code{help info}}. | |
1890 | ||
1891 | @kindex show | |
1892 | @item show | |
18fae2a8 | 1893 | In contrast, @code{show} is for describing the state of @value{GDBN} itself. |
70b88761 RP |
1894 | You can change most of the things you can @code{show}, by using the |
1895 | related command @code{set}; for example, you can control what number | |
1896 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1897 | which is currently in use with @code{show radix}. |
70b88761 RP |
1898 | |
1899 | @kindex info set | |
1900 | To display all the settable parameters and their current | |
1901 | values, you can use @code{show} with no arguments; you may also use | |
1902 | @code{info set}. Both commands produce the same display. | |
1903 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1904 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1905 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1906 | @end table | |
1907 | @c @end group | |
1908 | ||
1909 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1910 | exceptional in lacking corresponding @code{set} commands: | |
1911 | ||
1912 | @table @code | |
1913 | @kindex show version | |
3d3ab540 | 1914 | @cindex version number |
70b88761 | 1915 | @item show version |
18fae2a8 RP |
1916 | Show what version of @value{GDBN} is running. You should include this |
1917 | information in @value{GDBN} bug-reports. If multiple versions of @value{GDBN} are in | |
ed447b95 | 1918 | use at your site, you may occasionally want to determine which version |
18fae2a8 | 1919 | of @value{GDBN} you are running; as @value{GDBN} evolves, new commands are introduced, |
1041a570 | 1920 | and old ones may wither away. The version number is also announced |
18fae2a8 | 1921 | when you start @value{GDBN} with no arguments. |
70b88761 RP |
1922 | |
1923 | @kindex show copying | |
1924 | @item show copying | |
18fae2a8 | 1925 | Display information about permission for copying @value{GDBN}. |
70b88761 RP |
1926 | |
1927 | @kindex show warranty | |
1928 | @item show warranty | |
1929 | Display the GNU ``NO WARRANTY'' statement. | |
1930 | @end table | |
1931 | ||
4eb4cf57 | 1932 | @node Running |
18fae2a8 | 1933 | @chapter Running Programs Under @value{GDBN} |
70b88761 | 1934 | |
ed447b95 RP |
1935 | When you run a program under @value{GDBN}, you must first generate |
1936 | debugging information when you compile it. You may start it with its | |
1937 | arguments, if any, in an environment of your choice. You may redirect | |
1938 | your program's input and output, debug an already running process, or | |
1939 | kill a child process. | |
1041a570 | 1940 | |
18fae2a8 RP |
1941 | @ignore |
1942 | @c pre-unfolding: | |
70b88761 | 1943 | @menu |
ed447b95 RP |
1944 | * Compilation:: Compiling for debugging |
1945 | * Starting:: Starting your program | |
18fae2a8 | 1946 | @ifclear BARETARGET |
ed447b95 RP |
1947 | * Arguments:: Your program's arguments |
1948 | * Environment:: Your program's environment | |
1949 | * Working Directory:: Your program's working directory | |
1950 | * Input/Output:: Your program's input and output | |
1951 | * Attach:: Debugging an already-running process | |
1952 | * Kill Process:: Killing the child process | |
1953 | * Process Information:: Additional process information | |
18fae2a8 | 1954 | @end ifclear |
70b88761 | 1955 | @end menu |
18fae2a8 RP |
1956 | @end ignore |
1957 | ||
1958 | @ifclear BARETARGET | |
1959 | @menu | |
ed447b95 RP |
1960 | * Compilation:: Compiling for debugging |
1961 | * Starting:: Starting your program | |
1962 | * Arguments:: Your program's arguments | |
1963 | * Environment:: Your program's environment | |
1964 | * Working Directory:: Your program's working directory | |
1965 | * Input/Output:: Your program's input and output | |
1966 | * Attach:: Debugging an already-running process | |
1967 | * Kill Process:: Killing the child process | |
1968 | * Process Information:: Additional process information | |
18fae2a8 RP |
1969 | @end menu |
1970 | @end ifclear | |
1971 | ||
1972 | @ifset BARETARGET | |
1973 | @menu | |
ed447b95 RP |
1974 | * Compilation:: Compiling for debugging |
1975 | * Starting:: Starting your program | |
18fae2a8 RP |
1976 | @end menu |
1977 | @end ifset | |
70b88761 | 1978 | |
4eb4cf57 | 1979 | @node Compilation |
70b88761 RP |
1980 | @section Compiling for Debugging |
1981 | ||
1982 | In order to debug a program effectively, you need to generate | |
1983 | debugging information when you compile it. This debugging information | |
1984 | is stored in the object file; it describes the data type of each | |
1985 | variable or function and the correspondence between source line numbers | |
1986 | and addresses in the executable code. | |
1987 | ||
1988 | To request debugging information, specify the @samp{-g} option when you run | |
1989 | the compiler. | |
1990 | ||
1991 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1992 | options together. Using those compilers, you cannot generate optimized | |
1993 | executables containing debugging information. | |
1994 | ||
18fae2a8 | 1995 | @value{NGCC}, the GNU C compiler, supports @samp{-g} with or without |
c7cb8acb RP |
1996 | @samp{-O}, making it possible to debug optimized code. We recommend |
1997 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1998 | You may think your program is correct, but there is no sense in pushing | |
1999 | your luck. | |
70b88761 | 2000 | |
6ca72cc6 RP |
2001 | @cindex optimized code, debugging |
2002 | @cindex debugging optimized code | |
2003 | When you debug a program compiled with @samp{-g -O}, remember that the | |
93918348 RP |
2004 | optimizer is rearranging your code; the debugger will show you what is |
2005 | really there. Do not be too surprised when the execution path does not | |
6ca72cc6 | 2006 | exactly match your source file! An extreme example: if you define a |
18fae2a8 | 2007 | variable, but never use it, @value{GDBN} will never see that |
6ca72cc6 RP |
2008 | variable---because the compiler optimizes it out of existence. |
2009 | ||
70b88761 RP |
2010 | Some things do not work as well with @samp{-g -O} as with just |
2011 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
2012 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
2013 | please report it as a bug (including a test case!). | |
2014 | ||
2015 | Older versions of the GNU C compiler permitted a variant option | |
18fae2a8 | 2016 | @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this |
70b88761 RP |
2017 | format; if your GNU C compiler has this option, do not use it. |
2018 | ||
2019 | @ignore | |
18fae2a8 | 2020 | @comment As far as I know, there are no cases in which @value{GDBN} will |
70b88761 RP |
2021 | @comment produce strange output in this case. (but no promises). |
2022 | If your program includes archives made with the @code{ar} program, and | |
2023 | if the object files used as input to @code{ar} were compiled without the | |
18fae2a8 | 2024 | @samp{-g} option and have names longer than 15 characters, @value{GDBN} will get |
29a2b744 | 2025 | confused reading your program's symbol table. No error message will be |
18fae2a8 | 2026 | given, but @value{GDBN} may behave strangely. The reason for this problem is a |
70b88761 RP |
2027 | deficiency in the Unix archive file format, which cannot represent file |
2028 | names longer than 15 characters. | |
2029 | ||
2030 | To avoid this problem, compile the archive members with the @samp{-g} | |
2031 | option or use shorter file names. Alternatively, use a version of GNU | |
2032 | @code{ar} dated more recently than August 1989. | |
2033 | @end ignore | |
2034 | ||
4eb4cf57 | 2035 | @node Starting |
70b88761 RP |
2036 | @section Starting your Program |
2037 | @cindex starting | |
2038 | @cindex running | |
1041a570 | 2039 | |
70b88761 RP |
2040 | @table @code |
2041 | @item run | |
2042 | @itemx r | |
2043 | @kindex run | |
18fae2a8 | 2044 | Use the @code{run} command to start your program under @value{GDBN}. You must |
1041a570 | 2045 | first specify the program name |
18fae2a8 | 2046 | @ifset VXWORKS |
7463aadd | 2047 | (except on VxWorks) |
18fae2a8 | 2048 | @end ifset |
ed447b95 RP |
2049 | with an argument to @value{GDBN} (@pxref{Invocation, ,Getting In and |
2050 | Out of @value{GDBN}}), or by using the @code{file} or @code{exec-file} | |
2051 | command (@pxref{Files, ,Commands to Specify Files}). | |
1041a570 | 2052 | |
70b88761 RP |
2053 | @end table |
2054 | ||
18fae2a8 | 2055 | @ifclear BARETARGET |
29a2b744 RP |
2056 | If you are running your program in an execution environment that |
2057 | supports processes, @code{run} creates an inferior process and makes | |
2058 | that process run your program. (In environments without processes, | |
2059 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
2060 | |
2061 | The execution of a program is affected by certain information it | |
18fae2a8 | 2062 | receives from its superior. @value{GDBN} provides ways to specify this |
6ca72cc6 | 2063 | information, which you must do @emph{before} starting your program. (You |
29a2b744 RP |
2064 | can change it after starting your program, but such changes will only affect |
2065 | your program the next time you start it.) This information may be | |
70b88761 RP |
2066 | divided into four categories: |
2067 | ||
2068 | @table @asis | |
6ca72cc6 | 2069 | @item The @emph{arguments.} |
29a2b744 | 2070 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
2071 | @code{run} command. If a shell is available on your target, the shell |
2072 | is used to pass the arguments, so that you may use normal conventions | |
2073 | (such as wildcard expansion or variable substitution) in describing | |
2074 | the arguments. In Unix systems, you can control which shell is used | |
2075 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
2076 | Program's Arguments}. | |
70b88761 | 2077 | |
6ca72cc6 | 2078 | @item The @emph{environment.} |
18fae2a8 RP |
2079 | Your program normally inherits its environment from @value{GDBN}, but you can |
2080 | use the @value{GDBN} commands @code{set environment} and @code{unset | |
70b88761 | 2081 | environment} to change parts of the environment that will be given to |
1041a570 | 2082 | your program. @xref{Environment, ,Your Program's Environment}. |
70b88761 | 2083 | |
6ca72cc6 | 2084 | @item The @emph{working directory.} |
18fae2a8 | 2085 | Your program inherits its working directory from @value{GDBN}. You can set |
93918348 | 2086 | the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}. |
29a2b744 | 2087 | @xref{Working Directory, ,Your Program's Working Directory}. |
70b88761 | 2088 | |
6ca72cc6 | 2089 | @item The @emph{standard input and output.} |
70b88761 | 2090 | Your program normally uses the same device for standard input and |
18fae2a8 | 2091 | standard output as @value{GDBN} is using. You can redirect input and output |
70b88761 RP |
2092 | in the @code{run} command line, or you can use the @code{tty} command to |
2093 | set a different device for your program. | |
1041a570 | 2094 | @xref{Input/Output, ,Your Program's Input and Output}. |
3d3ab540 RP |
2095 | |
2096 | @cindex pipes | |
29a2b744 RP |
2097 | @emph{Warning:} While input and output redirection work, you cannot use |
2098 | pipes to pass the output of the program you are debugging to another | |
18fae2a8 | 2099 | program; if you attempt this, @value{GDBN} is likely to wind up debugging the |
3d3ab540 | 2100 | wrong program. |
70b88761 | 2101 | @end table |
18fae2a8 | 2102 | @end ifclear |
70b88761 | 2103 | |
1041a570 | 2104 | When you issue the @code{run} command, your program begins to execute |
4eb4cf57 RP |
2105 | immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion |
2106 | of how to arrange for your program to stop. Once your program has | |
2107 | stopped, you may calls functions in your program, using the @code{print} | |
2108 | or @code{call} commands. @xref{Data, ,Examining Data}. | |
70b88761 | 2109 | |
29a2b744 | 2110 | If the modification time of your symbol file has changed since the |
18fae2a8 RP |
2111 | last time @value{GDBN} read its symbols, @value{GDBN} will discard its symbol table and |
2112 | re-read it. When it does this, @value{GDBN} tries to retain your current | |
1041a570 | 2113 | breakpoints. |
70b88761 | 2114 | |
18fae2a8 | 2115 | @ifclear BARETARGET |
4eb4cf57 | 2116 | @node Arguments |
70b88761 RP |
2117 | @section Your Program's Arguments |
2118 | ||
2119 | @cindex arguments (to your program) | |
2120 | The arguments to your program can be specified by the arguments of the | |
2121 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 2122 | characters and performs redirection of I/O, and thence to your program. |
ed447b95 RP |
2123 | @value{GDBN} uses the shell indicated by your @code{SHELL} environment |
2124 | variable if it exists; otherwise, @value{GDBN} uses @code{/bin/sh}. | |
70b88761 RP |
2125 | |
2126 | @code{run} with no arguments uses the same arguments used by the previous | |
2127 | @code{run}, or those set by the @code{set args} command. | |
2128 | ||
2129 | @kindex set args | |
2130 | @table @code | |
2131 | @item set args | |
2132 | Specify the arguments to be used the next time your program is run. If | |
2133 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 2134 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
2135 | using @code{set args} before the next @code{run} is the only way to run |
2136 | it again without arguments. | |
2137 | ||
2138 | @item show args | |
2139 | @kindex show args | |
2140 | Show the arguments to give your program when it is started. | |
2141 | @end table | |
2142 | ||
4eb4cf57 | 2143 | @node Environment |
70b88761 RP |
2144 | @section Your Program's Environment |
2145 | ||
2146 | @cindex environment (of your program) | |
2147 | The @dfn{environment} consists of a set of environment variables and | |
2148 | their values. Environment variables conventionally record such things as | |
2149 | your user name, your home directory, your terminal type, and your search | |
2150 | path for programs to run. Usually you set up environment variables with | |
2151 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 2152 | debugging, it can be useful to try running your program with a modified |
18fae2a8 | 2153 | environment without having to start @value{GDBN} over again. |
70b88761 RP |
2154 | |
2155 | @table @code | |
2156 | @item path @var{directory} | |
2157 | @kindex path | |
2158 | Add @var{directory} to the front of the @code{PATH} environment variable | |
18fae2a8 | 2159 | (the search path for executables), for both @value{GDBN} and your program. |
70b88761 RP |
2160 | You may specify several directory names, separated by @samp{:} or |
2161 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 2162 | the front, so it will be searched sooner. |
7463aadd RP |
2163 | |
2164 | You can use the string @samp{$cwd} to refer to whatever is the current | |
18fae2a8 | 2165 | working directory at the time @value{GDBN} searches the path. If you use |
7463aadd | 2166 | @samp{.} instead, it refers to the directory where you executed the |
18fae2a8 | 2167 | @code{path} command. @value{GDBN} fills in the current path where needed in |
7463aadd | 2168 | the @var{directory} argument, before adding it to the search path. |
29a2b744 | 2169 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
2170 | @c document that, since repeating it would be a no-op. |
2171 | ||
2172 | @item show paths | |
2173 | @kindex show paths | |
2174 | Display the list of search paths for executables (the @code{PATH} | |
2175 | environment variable). | |
2176 | ||
2177 | @item show environment @r{[}@var{varname}@r{]} | |
2178 | @kindex show environment | |
2179 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 2180 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
2181 | print the names and values of all environment variables to be given to |
2182 | your program. You can abbreviate @code{environment} as @code{env}. | |
2183 | ||
7463aadd | 2184 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 | 2185 | @kindex set environment |
ed447b95 | 2186 | Set environment variable @var{varname} to @var{value}. The value |
18fae2a8 | 2187 | changes for your program only, not for @value{GDBN} itself. @var{value} may |
70b88761 RP |
2188 | be any string; the values of environment variables are just strings, and |
2189 | any interpretation is supplied by your program itself. The @var{value} | |
2190 | parameter is optional; if it is eliminated, the variable is set to a | |
2191 | null value. | |
29a2b744 | 2192 | @c "any string" here does not include leading, trailing |
70b88761 RP |
2193 | @c blanks. Gnu asks: does anyone care? |
2194 | ||
2195 | For example, this command: | |
2196 | ||
2197 | @example | |
2198 | set env USER = foo | |
2199 | @end example | |
2200 | ||
2201 | @noindent | |
2202 | tells a Unix program, when subsequently run, that its user is named | |
2203 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
2204 | are not actually required.) | |
2205 | ||
2206 | @item unset environment @var{varname} | |
2207 | @kindex unset environment | |
2208 | Remove variable @var{varname} from the environment to be passed to your | |
2209 | program. This is different from @samp{set env @var{varname} =}; | |
2210 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 2211 | rather than assigning it an empty value. |
70b88761 RP |
2212 | @end table |
2213 | ||
4eb4cf57 | 2214 | @node Working Directory |
70b88761 RP |
2215 | @section Your Program's Working Directory |
2216 | ||
2217 | @cindex working directory (of your program) | |
2218 | Each time you start your program with @code{run}, it inherits its | |
93918348 RP |
2219 | working directory from the current working directory of @value{GDBN}. |
2220 | The @value{GDBN} working directory is initially whatever it inherited | |
2221 | from its parent process (typically the shell), but you can specify a new | |
2222 | working directory in @value{GDBN} with the @code{cd} command. | |
70b88761 | 2223 | |
18fae2a8 RP |
2224 | The @value{GDBN} working directory also serves as a default for the commands |
2225 | that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to | |
1041a570 | 2226 | Specify Files}. |
70b88761 RP |
2227 | |
2228 | @table @code | |
2229 | @item cd @var{directory} | |
2230 | @kindex cd | |
93918348 | 2231 | Set the @value{GDBN} working directory to @var{directory}. |
70b88761 RP |
2232 | |
2233 | @item pwd | |
2234 | @kindex pwd | |
93918348 | 2235 | Print the @value{GDBN} working directory. |
70b88761 RP |
2236 | @end table |
2237 | ||
4eb4cf57 | 2238 | @node Input/Output |
70b88761 RP |
2239 | @section Your Program's Input and Output |
2240 | ||
2241 | @cindex redirection | |
2242 | @cindex i/o | |
2243 | @cindex terminal | |
18fae2a8 RP |
2244 | By default, the program you run under @value{GDBN} does input and output to |
2245 | the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal to | |
70b88761 RP |
2246 | its own terminal modes to interact with you, but it records the terminal |
2247 | modes your program was using and switches back to them when you continue | |
2248 | running your program. | |
2249 | ||
2250 | @table @code | |
2251 | @item info terminal | |
2252 | @kindex info terminal | |
93918348 | 2253 | Displays information recorded by @value{GDBN} about the terminal modes your |
70b88761 RP |
2254 | program is using. |
2255 | @end table | |
2256 | ||
29a2b744 | 2257 | You can redirect your program's input and/or output using shell |
70b88761 RP |
2258 | redirection with the @code{run} command. For example, |
2259 | ||
18fae2a8 | 2260 | @example |
70b88761 | 2261 | run > outfile |
18fae2a8 | 2262 | @end example |
70b88761 RP |
2263 | |
2264 | @noindent | |
29a2b744 | 2265 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
2266 | |
2267 | @kindex tty | |
2268 | @cindex controlling terminal | |
29a2b744 | 2269 | Another way to specify where your program should do input and output is |
70b88761 RP |
2270 | with the @code{tty} command. This command accepts a file name as |
2271 | argument, and causes this file to be the default for future @code{run} | |
2272 | commands. It also resets the controlling terminal for the child | |
2273 | process, for future @code{run} commands. For example, | |
2274 | ||
2275 | @example | |
2276 | tty /dev/ttyb | |
2277 | @end example | |
2278 | ||
2279 | @noindent | |
2280 | directs that processes started with subsequent @code{run} commands | |
2281 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
2282 | that as their controlling terminal. | |
2283 | ||
2284 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
2285 | effect on the input/output device, but not its effect on the controlling | |
2286 | terminal. | |
2287 | ||
2288 | When you use the @code{tty} command or redirect input in the @code{run} | |
2289 | command, only the input @emph{for your program} is affected. The input | |
18fae2a8 | 2290 | for @value{GDBN} still comes from your terminal. |
70b88761 | 2291 | |
4eb4cf57 | 2292 | @node Attach |
70b88761 RP |
2293 | @section Debugging an Already-Running Process |
2294 | @kindex attach | |
2295 | @cindex attach | |
2296 | ||
2297 | @table @code | |
2298 | @item attach @var{process-id} | |
2299 | This command | |
18fae2a8 | 2300 | attaches to a running process---one that was started outside @value{GDBN}. |
70b88761 RP |
2301 | (@code{info files} will show your active targets.) The command takes as |
2302 | argument a process ID. The usual way to find out the process-id of | |
2303 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
e251e767 | 2304 | shell command. |
70b88761 RP |
2305 | |
2306 | @code{attach} will not repeat if you press @key{RET} a second time after | |
2307 | executing the command. | |
2308 | @end table | |
2309 | ||
2310 | To use @code{attach}, you must be debugging in an environment which | |
2311 | supports processes. You must also have permission to send the process a | |
18fae2a8 | 2312 | signal, and it must have the same effective user ID as the @value{GDBN} |
70b88761 RP |
2313 | process. |
2314 | ||
2315 | When using @code{attach}, you should first use the @code{file} command | |
2316 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 2317 | @xref{Files, ,Commands to Specify Files}. |
70b88761 | 2318 | |
18fae2a8 | 2319 | The first thing @value{GDBN} does after arranging to debug the specified |
70b88761 | 2320 | process is to stop it. You can examine and modify an attached process |
18fae2a8 | 2321 | with all the @value{GDBN} commands that are ordinarily available when you start |
70b88761 RP |
2322 | processes with @code{run}. You can insert breakpoints; you can step and |
2323 | continue; you can modify storage. If you would rather the process | |
2324 | continue running, you may use the @code{continue} command after | |
18fae2a8 | 2325 | attaching @value{GDBN} to the process. |
70b88761 RP |
2326 | |
2327 | @table @code | |
2328 | @item detach | |
2329 | @kindex detach | |
2330 | When you have finished debugging the attached process, you can use the | |
93918348 | 2331 | @code{detach} command to release it from @value{GDBN} control. Detaching |
70b88761 | 2332 | the process continues its execution. After the @code{detach} command, |
18fae2a8 | 2333 | that process and @value{GDBN} become completely independent once more, and you |
70b88761 RP |
2334 | are ready to @code{attach} another process or start one with @code{run}. |
2335 | @code{detach} will not repeat if you press @key{RET} again after | |
2336 | executing the command. | |
2337 | @end table | |
2338 | ||
18fae2a8 | 2339 | If you exit @value{GDBN} or use the @code{run} command while you have an attached |
70b88761 RP |
2340 | process, you kill that process. By default, you will be asked for |
2341 | confirmation if you try to do either of these things; you can control | |
2342 | whether or not you need to confirm by using the @code{set confirm} command | |
29a2b744 | 2343 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). |
70b88761 | 2344 | |
4eb4cf57 | 2345 | @node Kill Process |
70b88761 RP |
2346 | @c @group |
2347 | @section Killing the Child Process | |
2348 | ||
2349 | @table @code | |
2350 | @item kill | |
2351 | @kindex kill | |
18fae2a8 | 2352 | Kill the child process in which your program is running under @value{GDBN}. |
70b88761 RP |
2353 | @end table |
2354 | ||
2355 | This command is useful if you wish to debug a core dump instead of a | |
18fae2a8 | 2356 | running process. @value{GDBN} ignores any core dump file while your program |
70b88761 RP |
2357 | is running. |
2358 | @c @end group | |
2359 | ||
18fae2a8 RP |
2360 | On some operating systems, a program cannot be executed outside @value{GDBN} |
2361 | while you have breakpoints set on it inside @value{GDBN}. You can use the | |
29a2b744 | 2362 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
2363 | outside the debugger. |
2364 | ||
2365 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 2366 | relink your program, since on many systems it is impossible to modify an |
70b88761 | 2367 | executable file while it is running in a process. In this case, when you |
18fae2a8 | 2368 | next type @code{run}, @value{GDBN} will notice that the file has changed, and |
70b88761 RP |
2369 | will re-read the symbol table (while trying to preserve your current |
2370 | breakpoint settings). | |
2371 | ||
4eb4cf57 | 2372 | @node Process Information |
d24e0922 RP |
2373 | @section Additional Process Information |
2374 | ||
2375 | @kindex /proc | |
2376 | @cindex process image | |
2377 | Some operating systems provide a facility called @samp{/proc} that can | |
cc9bc574 | 2378 | be used to examine the image of a running process using file-system |
18fae2a8 | 2379 | subroutines. If @value{GDBN} is configured for an operating system with this |
cc9bc574 RP |
2380 | facility, the command @code{info proc} is available to report on several |
2381 | kinds of information about the process running your program. | |
d24e0922 RP |
2382 | |
2383 | @table @code | |
2384 | @item info proc | |
2385 | @kindex info proc | |
2386 | Summarize available information about the process. | |
2387 | ||
2388 | @item info proc mappings | |
2389 | @kindex info proc mappings | |
2390 | Report on the address ranges accessible in the program, with information | |
2391 | on whether your program may read, write, or execute each range. | |
2392 | ||
2393 | @item info proc times | |
2394 | @kindex info proc times | |
2395 | Starting time, user CPU time, and system CPU time for your program and | |
2396 | its children. | |
2397 | ||
2398 | @item info proc id | |
2399 | @kindex info proc id | |
93918348 RP |
2400 | Report on the process IDs related to your program: its own process ID, |
2401 | the ID of its parent, the process group ID, and the session ID. | |
d24e0922 RP |
2402 | |
2403 | @item info proc status | |
2404 | @kindex info proc status | |
2405 | General information on the state of the process. If the process is | |
2406 | stopped, this report includes the reason for stopping, and any signal | |
2407 | received. | |
cc9bc574 RP |
2408 | |
2409 | @item info proc all | |
2410 | Show all the above information about the process. | |
d24e0922 | 2411 | @end table |
18fae2a8 | 2412 | @end ifclear |
d24e0922 | 2413 | |
4eb4cf57 | 2414 | @node Stopping |
70b88761 RP |
2415 | @chapter Stopping and Continuing |
2416 | ||
ed447b95 | 2417 | The principal purposes of using a debugger are so that you can stop your |
29a2b744 | 2418 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
2419 | trouble, you can investigate and find out why. |
2420 | ||
18fae2a8 RP |
2421 | Inside @value{GDBN}, your program may stop for any of several reasons, such |
2422 | as a signal, a breakpoint, or reaching a new line after a @value{GDBN} | |
70b88761 RP |
2423 | command such as @code{step}. You may then examine and change |
2424 | variables, set new breakpoints or remove old ones, and then continue | |
18fae2a8 | 2425 | execution. Usually, the messages shown by @value{GDBN} provide ample |
70b88761 RP |
2426 | explanation of the status of your program---but you can also explicitly |
2427 | request this information at any time. | |
2428 | ||
2429 | @table @code | |
2430 | @item info program | |
2431 | @kindex info program | |
2432 | Display information about the status of your program: whether it is | |
2433 | running or not, what process it is, and why it stopped. | |
2434 | @end table | |
2435 | ||
18fae2a8 RP |
2436 | @ignore |
2437 | @c original menu | |
2438 | @menu | |
2439 | @ifclear CONLY | |
ed447b95 | 2440 | * Breakpoints:: Breakpoints, watchpoints, and exceptions |
18fae2a8 RP |
2441 | @end ifclear |
2442 | @ifset CONLY | |
ed447b95 | 2443 | * Breakpoints:: Breakpoints and watchpoints |
18fae2a8 | 2444 | @end ifset |
ed447b95 | 2445 | * Continuing and Stepping:: Resuming execution |
18fae2a8 RP |
2446 | @ifset POSIX |
2447 | * Signals:: Signals | |
2448 | @end ifset | |
2449 | @end menu | |
2450 | @end ignore | |
2451 | ||
2452 | @c !CONLY && POSIX | |
2453 | @ifclear CONLY | |
2454 | @ifset POSIX | |
70b88761 | 2455 | @menu |
ed447b95 RP |
2456 | * Breakpoints:: Breakpoints, watchpoints, and exceptions |
2457 | * Continuing and Stepping:: Resuming execution | |
18fae2a8 RP |
2458 | * Signals:: Signals |
2459 | @end menu | |
2460 | @end ifset | |
2461 | @end ifclear | |
2462 | ||
2463 | @c CONLY && POSIX | |
2464 | @ifset CONLY | |
2465 | @ifset POSIX | |
2466 | @menu | |
ed447b95 RP |
2467 | * Breakpoints:: Breakpoints and watchpoints |
2468 | * Continuing and Stepping:: Resuming execution | |
b80282d5 | 2469 | * Signals:: Signals |
70b88761 | 2470 | @end menu |
18fae2a8 RP |
2471 | @end ifset |
2472 | @end ifset | |
2473 | ||
2474 | @c !CONLY && !POSIX | |
2475 | @ifclear CONLY | |
2476 | @ifclear POSIX | |
2477 | @menu | |
ed447b95 RP |
2478 | * Breakpoints:: Breakpoints, watchpoints, and exceptions |
2479 | * Continuing and Stepping:: Resuming execution | |
18fae2a8 RP |
2480 | @end menu |
2481 | @end ifclear | |
2482 | @end ifclear | |
2483 | ||
2484 | @c CONLY && !POSIX | |
2485 | @ifset CONLY | |
2486 | @ifclear POSIX | |
2487 | @menu | |
ed447b95 RP |
2488 | * Breakpoints:: Breakpoints and watchpoints |
2489 | * Continuing and Stepping:: Resuming execution | |
18fae2a8 RP |
2490 | @end menu |
2491 | @end ifclear | |
2492 | @end ifset | |
70b88761 | 2493 | |
18fae2a8 RP |
2494 | @c node-defaulting requires adjacency of @node and sectioning cmds |
2495 | @c ...hence distribute @node Breakpoints over two possible @if expansions. | |
2496 | @c | |
2497 | @ifclear CONLY | |
4eb4cf57 | 2498 | @node Breakpoints |
70b88761 | 2499 | @section Breakpoints, Watchpoints, and Exceptions |
18fae2a8 RP |
2500 | @end ifclear |
2501 | @ifset CONLY | |
2502 | @node Breakpoints | |
0f153e74 | 2503 | @section Breakpoints and Watchpoints |
18fae2a8 | 2504 | @end ifset |
70b88761 RP |
2505 | |
2506 | @cindex breakpoints | |
2507 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 2508 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 2509 | conditions to control in finer detail whether your program will stop. |
70b88761 | 2510 | You can set breakpoints with the @code{break} command and its variants |
29a2b744 RP |
2511 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where |
2512 | your program should stop by line number, function name or exact address | |
0f153e74 | 2513 | in the program. |
18fae2a8 | 2514 | @ifclear CONLY |
0f153e74 RP |
2515 | In languages with exception handling (such as GNU C++), you can also set |
2516 | breakpoints where an exception is raised (@pxref{Exception Handling, | |
2517 | ,Breakpoints and Exceptions}). | |
18fae2a8 | 2518 | @end ifclear |
70b88761 RP |
2519 | |
2520 | @cindex watchpoints | |
6ca72cc6 RP |
2521 | @cindex memory tracing |
2522 | @cindex breakpoint on memory address | |
2523 | @cindex breakpoint on variable modification | |
29a2b744 RP |
2524 | A @dfn{watchpoint} is a special breakpoint that stops your program |
2525 | when the value of an expression changes. You must use a different | |
2526 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
2527 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
2528 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1041a570 | 2529 | and watchpoints using the same commands. |
70b88761 | 2530 | |
6ca72cc6 RP |
2531 | @cindex breakpoint numbers |
2532 | @cindex numbers for breakpoints | |
18fae2a8 | 2533 | @value{GDBN} assigns a number to each breakpoint or watchpoint when you |
6ca72cc6 RP |
2534 | create it; these numbers are successive integers starting with one. In |
2535 | many of the commands for controlling various features of breakpoints you | |
2536 | use the breakpoint number to say which breakpoint you want to change. | |
2537 | Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 2538 | no effect on your program until you enable it again. |
70b88761 RP |
2539 | |
2540 | @menu | |
ed447b95 RP |
2541 | * Set Breaks:: Setting breakpoints |
2542 | * Set Watchpoints:: Setting watchpoints | |
2543 | * Exception Handling:: Breakpoints and exceptions | |
2544 | * Delete Breaks:: Deleting breakpoints | |
2545 | * Disabling:: Disabling breakpoints | |
2546 | * Conditions:: Break conditions | |
2547 | * Break Commands:: Breakpoint command lists | |
2548 | * Breakpoint Menus:: Breakpoint menus | |
2549 | * Error in Breakpoints:: ``Cannot insert breakpoints'' | |
70b88761 RP |
2550 | @end menu |
2551 | ||
4eb4cf57 | 2552 | @node Set Breaks |
70b88761 RP |
2553 | @subsection Setting Breakpoints |
2554 | ||
4906534f RP |
2555 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
2556 | @c consider in particular declaration with/without initialization. | |
2557 | @c | |
2558 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
2559 | ||
70b88761 RP |
2560 | @kindex break |
2561 | @kindex b | |
6ca72cc6 RP |
2562 | @kindex $bpnum |
2563 | @cindex latest breakpoint | |
2564 | Breakpoints are set with the @code{break} command (abbreviated | |
2565 | @code{b}). The debugger convenience variable @samp{$bpnum} records the | |
2566 | number of the beakpoint you've set most recently; see @ref{Convenience | |
d24e0922 | 2567 | Vars,, Convenience Variables}, for a discussion of what you can do with |
6ca72cc6 | 2568 | convenience variables. |
70b88761 RP |
2569 | |
2570 | You have several ways to say where the breakpoint should go. | |
2571 | ||
2572 | @table @code | |
2573 | @item break @var{function} | |
0f153e74 | 2574 | Set a breakpoint at entry to function @var{function}. |
18fae2a8 | 2575 | @ifclear CONLY |
0f153e74 RP |
2576 | When using source languages that permit overloading of symbols, such as |
2577 | C++, @var{function} may refer to more than one possible place to break. | |
70b88761 | 2578 | @xref{Breakpoint Menus}, for a discussion of that situation. |
18fae2a8 | 2579 | @end ifclear |
70b88761 RP |
2580 | |
2581 | @item break +@var{offset} | |
2582 | @itemx break -@var{offset} | |
2583 | Set a breakpoint some number of lines forward or back from the position | |
2584 | at which execution stopped in the currently selected frame. | |
2585 | ||
2586 | @item break @var{linenum} | |
2587 | Set a breakpoint at line @var{linenum} in the current source file. | |
2588 | That file is the last file whose source text was printed. This | |
29a2b744 | 2589 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
2590 | code on that line. |
2591 | ||
2592 | @item break @var{filename}:@var{linenum} | |
2593 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
2594 | ||
2595 | @item break @var{filename}:@var{function} | |
2596 | Set a breakpoint at entry to function @var{function} found in file | |
2597 | @var{filename}. Specifying a file name as well as a function name is | |
2598 | superfluous except when multiple files contain similarly named | |
2599 | functions. | |
2600 | ||
2601 | @item break *@var{address} | |
2602 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 2603 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
2604 | information or source files. |
2605 | ||
2606 | @item break | |
29a2b744 RP |
2607 | When called without any arguments, @code{break} sets a breakpoint at |
2608 | the next instruction to be executed in the selected stack frame | |
2609 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
2610 | innermost, this will cause your program to stop as soon as control | |
2611 | returns to that frame. This is similar to the effect of a | |
2612 | @code{finish} command in the frame inside the selected frame---except | |
2613 | that @code{finish} does not leave an active breakpoint. If you use | |
18fae2a8 | 2614 | @code{break} without an argument in the innermost frame, @value{GDBN} will stop |
1041a570 RP |
2615 | the next time it reaches the current location; this may be useful |
2616 | inside loops. | |
70b88761 | 2617 | |
18fae2a8 | 2618 | @value{GDBN} normally ignores breakpoints when it resumes execution, until at |
70b88761 RP |
2619 | least one instruction has been executed. If it did not do this, you |
2620 | would be unable to proceed past a breakpoint without first disabling the | |
2621 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 2622 | existed when your program stopped. |
70b88761 RP |
2623 | |
2624 | @item break @dots{} if @var{cond} | |
2625 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
2626 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 2627 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
2628 | @samp{@dots{}} stands for one of the possible arguments described |
2629 | above (or no argument) specifying where to break. @xref{Conditions, | |
2630 | ,Break Conditions}, for more information on breakpoint conditions. | |
70b88761 RP |
2631 | |
2632 | @item tbreak @var{args} | |
2633 | @kindex tbreak | |
2634 | Set a breakpoint enabled only for one stop. @var{args} are the | |
2635 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 RP |
2636 | way, but the breakpoint is automatically disabled after the first time your |
2637 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
70b88761 RP |
2638 | |
2639 | @item rbreak @var{regex} | |
2640 | @kindex rbreak | |
2641 | @cindex regular expression | |
4906534f | 2642 | @c FIXME what kind of regexp? |
70b88761 | 2643 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 2644 | @var{regex}. This command |
70b88761 RP |
2645 | sets an unconditional breakpoint on all matches, printing a list of all |
2646 | breakpoints it set. Once these breakpoints are set, they are treated | |
2647 | just like the breakpoints set with the @code{break} command. They can | |
2648 | be deleted, disabled, made conditional, etc., in the standard ways. | |
2649 | ||
18fae2a8 | 2650 | @ifclear CONLY |
b80282d5 RP |
2651 | When debugging C++ programs, @code{rbreak} is useful for setting |
2652 | breakpoints on overloaded functions that are not members of any special | |
2653 | classes. | |
18fae2a8 | 2654 | @end ifclear |
b80282d5 | 2655 | |
70b88761 | 2656 | @kindex info breakpoints |
c338a2fd | 2657 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 | 2658 | @item info breakpoints @r{[}@var{n}@r{]} |
6ca72cc6 RP |
2659 | @itemx info break @r{[}@var{n}@r{]} |
2660 | @itemx info watchpoints @r{[}@var{n}@r{]} | |
2661 | Print a table of all breakpoints and watchpoints set and not | |
2662 | deleted, with the following columns for each breakpoint: | |
2663 | ||
2664 | @table @emph | |
2665 | @item Breakpoint Numbers | |
2666 | @item Type | |
2667 | Breakpoint or watchpoint. | |
2668 | @item Disposition | |
2669 | Whether the breakpoint is marked to be disabled or deleted when hit. | |
2670 | @item Enabled or Disabled | |
d24e0922 | 2671 | Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints |
6ca72cc6 RP |
2672 | that are not enabled. |
2673 | @item Address | |
2674 | Where the breakpoint is in your program, as a memory address | |
2675 | @item What | |
2676 | Where the breakpoint is in the source for your program, as a file and | |
2677 | line number. | |
2678 | @end table | |
2679 | ||
2680 | @noindent | |
2681 | Breakpoint commands, if any, are listed after the line for the | |
2682 | corresponding breakpoint. | |
2683 | ||
2684 | @noindent | |
2685 | @code{info break} with a breakpoint | |
29a2b744 RP |
2686 | number @var{n} as argument lists only that breakpoint. The |
2687 | convenience variable @code{$_} and the default examining-address for | |
2688 | the @code{x} command are set to the address of the last breakpoint | |
6ca72cc6 | 2689 | listed (@pxref{Memory, ,Examining Memory}). |
1041a570 | 2690 | @end table |
70b88761 | 2691 | |
18fae2a8 | 2692 | @value{GDBN} allows you to set any number of breakpoints at the same place in |
1041a570 RP |
2693 | your program. There is nothing silly or meaningless about this. When |
2694 | the breakpoints are conditional, this is even useful | |
29a2b744 | 2695 | (@pxref{Conditions, ,Break Conditions}). |
70b88761 | 2696 | |
6ca72cc6 | 2697 | @cindex negative breakpoint numbers |
18fae2a8 RP |
2698 | @cindex internal @value{GDBN} breakpoints |
2699 | @value{GDBN} itself sometimes sets breakpoints in your program for special | |
6ca72cc6 RP |
2700 | purposes, such as proper handling of @code{longjmp} (in C programs). |
2701 | These internal breakpoints are assigned negative numbers, starting with | |
5a2c1d85 | 2702 | @code{-1}; @samp{info breakpoints} does not display them. |
d48da190 | 2703 | |
18fae2a8 | 2704 | You can see these breakpoints with the @value{GDBN} maintenance command |
5a2c1d85 | 2705 | @samp{maint info breakpoints}. |
6ca72cc6 RP |
2706 | |
2707 | @table @code | |
d48da190 RP |
2708 | @kindex maint info breakpoints |
2709 | @item maint info breakpoints | |
6ca72cc6 | 2710 | Using the same format as @samp{info breakpoints}, display both the |
18fae2a8 | 2711 | breakpoints you've set explicitly, and those @value{GDBN} is using for |
6ca72cc6 RP |
2712 | internal purposes. Internal breakpoints are shown with negative |
2713 | breakpoint numbers. The type column identifies what kind of breakpoint | |
2714 | is shown: | |
2715 | ||
2716 | @table @code | |
2717 | @item breakpoint | |
2718 | Normal, explicitly set breakpoint. | |
2719 | ||
2720 | @item watchpoint | |
2721 | Normal, explicitly set watchpoint. | |
2722 | ||
2723 | @item longjmp | |
2724 | Internal breakpoint, used to handle correctly stepping through | |
2725 | @code{longjmp} calls. | |
2726 | ||
2727 | @item longjmp resume | |
2728 | Internal breakpoint at the target of a @code{longjmp}. | |
2729 | ||
2730 | @item until | |
18fae2a8 | 2731 | Temporary internal breakpoint used by the @value{GDBN} @code{until} command. |
6ca72cc6 RP |
2732 | |
2733 | @item finish | |
18fae2a8 | 2734 | Temporary internal breakpoint used by the @value{GDBN} @code{finish} command. |
6ca72cc6 RP |
2735 | @end table |
2736 | ||
2737 | @end table | |
2738 | ||
2739 | ||
4eb4cf57 | 2740 | @node Set Watchpoints |
70b88761 RP |
2741 | @subsection Setting Watchpoints |
2742 | @cindex setting watchpoints | |
1041a570 | 2743 | |
70b88761 | 2744 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 2745 | expression changes, without having to predict a particular place |
70b88761 RP |
2746 | where this may happen. |
2747 | ||
2748 | Watchpoints currently execute two orders of magnitude more slowly than | |
2749 | other breakpoints, but this can well be worth it to catch errors where | |
2750 | you have no clue what part of your program is the culprit. Some | |
2751 | processors provide special hardware to support watchpoint evaluation; future | |
18fae2a8 | 2752 | releases of @value{GDBN} will use such hardware if it is available. |
70b88761 RP |
2753 | |
2754 | @table @code | |
e251e767 | 2755 | @kindex watch |
70b88761 RP |
2756 | @item watch @var{expr} |
2757 | Set a watchpoint for an expression. | |
2758 | ||
2759 | @kindex info watchpoints | |
2760 | @item info watchpoints | |
6ca72cc6 RP |
2761 | This command prints a list of watchpoints and breakpoints; it is the |
2762 | same as @code{info break}. | |
70b88761 RP |
2763 | @end table |
2764 | ||
4eb4cf57 | 2765 | @node Exception Handling |
70b88761 RP |
2766 | @subsection Breakpoints and Exceptions |
2767 | @cindex exception handlers | |
2768 | ||
b80282d5 | 2769 | Some languages, such as GNU C++, implement exception handling. You can |
18fae2a8 | 2770 | use @value{GDBN} to examine what caused your program to raise an exception, |
29a2b744 | 2771 | and to list the exceptions your program is prepared to handle at a |
70b88761 RP |
2772 | given point in time. |
2773 | ||
2774 | @table @code | |
2775 | @item catch @var{exceptions} | |
2776 | @kindex catch | |
2777 | You can set breakpoints at active exception handlers by using the | |
2778 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
2779 | to catch. | |
2780 | @end table | |
2781 | ||
29a2b744 RP |
2782 | You can use @code{info catch} to list active exception handlers. |
2783 | @xref{Frame Info, ,Information About a Frame}. | |
70b88761 | 2784 | |
18fae2a8 | 2785 | There are currently some limitations to exception handling in @value{GDBN}. |
70b88761 RP |
2786 | These will be corrected in a future release. |
2787 | ||
2788 | @itemize @bullet | |
2789 | @item | |
18fae2a8 | 2790 | If you call a function interactively, @value{GDBN} normally returns |
70b88761 RP |
2791 | control to you when the function has finished executing. If the call |
2792 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 2793 | returns control to you and cause your program to simply continue |
18fae2a8 | 2794 | running until it hits a breakpoint, catches a signal that @value{GDBN} is |
70b88761 RP |
2795 | listening for, or exits. |
2796 | @item | |
2797 | You cannot raise an exception interactively. | |
2798 | @item | |
2799 | You cannot interactively install an exception handler. | |
2800 | @end itemize | |
2801 | ||
2802 | @cindex raise exceptions | |
2803 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 2804 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
2805 | stop @emph{before} the exception handler is called, since that way you |
2806 | can see the stack before any unwinding takes place. If you set a | |
2807 | breakpoint in an exception handler instead, it may not be easy to find | |
2808 | out where the exception was raised. | |
2809 | ||
2810 | To stop just before an exception handler is called, you need some | |
b80282d5 | 2811 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
2812 | raised by calling a library function named @code{__raise_exception} |
2813 | which has the following ANSI C interface: | |
2814 | ||
2815 | @example | |
b80282d5 | 2816 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
2817 | ID is the exception identifier. */ |
2818 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
2819 | @end example | |
2820 | ||
2821 | @noindent | |
2822 | To make the debugger catch all exceptions before any stack | |
2823 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
29a2b744 | 2824 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). |
70b88761 | 2825 | |
29a2b744 RP |
2826 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) |
2827 | that depends on the value of @var{id}, you can stop your program when | |
2828 | a specific exception is raised. You can use multiple conditional | |
2829 | breakpoints to stop your program when any of a number of exceptions are | |
2830 | raised. | |
70b88761 | 2831 | |
4eb4cf57 | 2832 | @node Delete Breaks |
70b88761 RP |
2833 | @subsection Deleting Breakpoints |
2834 | ||
2835 | @cindex clearing breakpoints, watchpoints | |
2836 | @cindex deleting breakpoints, watchpoints | |
2837 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 2838 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
2839 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
2840 | deleted no longer exists; it is forgotten. | |
2841 | ||
2842 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 2843 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
2844 | delete individual breakpoints or watchpoints by specifying their |
2845 | breakpoint numbers. | |
2846 | ||
18fae2a8 | 2847 | It is not necessary to delete a breakpoint to proceed past it. @value{GDBN} |
70b88761 RP |
2848 | automatically ignores breakpoints on the first instruction to be executed |
2849 | when you continue execution without changing the execution address. | |
2850 | ||
2851 | @table @code | |
2852 | @item clear | |
2853 | @kindex clear | |
2854 | Delete any breakpoints at the next instruction to be executed in the | |
29a2b744 RP |
2855 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When |
2856 | the innermost frame is selected, this is a good way to delete a | |
2857 | breakpoint where your program just stopped. | |
70b88761 RP |
2858 | |
2859 | @item clear @var{function} | |
2860 | @itemx clear @var{filename}:@var{function} | |
2861 | Delete any breakpoints set at entry to the function @var{function}. | |
2862 | ||
2863 | @item clear @var{linenum} | |
2864 | @itemx clear @var{filename}:@var{linenum} | |
2865 | Delete any breakpoints set at or within the code of the specified line. | |
2866 | ||
2867 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2868 | @cindex delete breakpoints | |
2869 | @kindex delete | |
2870 | @kindex d | |
2871 | Delete the breakpoints or watchpoints of the numbers specified as | |
18fae2a8 | 2872 | arguments. If no argument is specified, delete all breakpoints (@value{GDBN} |
1041a570 | 2873 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
2874 | can abbreviate this command as @code{d}. |
2875 | @end table | |
2876 | ||
4eb4cf57 | 2877 | @node Disabling |
70b88761 RP |
2878 | @subsection Disabling Breakpoints |
2879 | ||
2880 | @cindex disabled breakpoints | |
2881 | @cindex enabled breakpoints | |
2882 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
2883 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
2884 | been deleted, but remembers the information on the breakpoint so that | |
2885 | you can @dfn{enable} it again later. | |
2886 | ||
2887 | You disable and enable breakpoints and watchpoints with the | |
2888 | @code{enable} and @code{disable} commands, optionally specifying one or | |
2889 | more breakpoint numbers as arguments. Use @code{info break} or | |
2890 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 2891 | do not know which numbers to use. |
70b88761 RP |
2892 | |
2893 | A breakpoint or watchpoint can have any of four different states of | |
2894 | enablement: | |
2895 | ||
2896 | @itemize @bullet | |
2897 | @item | |
29a2b744 | 2898 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2899 | with the @code{break} command starts out in this state. |
2900 | @item | |
29a2b744 | 2901 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2902 | @item |
29a2b744 | 2903 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2904 | when it does so it will become disabled. A breakpoint set |
2905 | with the @code{tbreak} command starts out in this state. | |
2906 | @item | |
29a2b744 | 2907 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2908 | immediately after it does so it will be deleted permanently. |
2909 | @end itemize | |
2910 | ||
2911 | You can use the following commands to enable or disable breakpoints and | |
2912 | watchpoints: | |
2913 | ||
2914 | @table @code | |
2915 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2916 | @kindex disable breakpoints | |
2917 | @kindex disable | |
2918 | @kindex dis | |
2919 | Disable the specified breakpoints---or all breakpoints, if none are | |
2920 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2921 | options such as ignore-counts, conditions and commands are remembered in | |
2922 | case the breakpoint is enabled again later. You may abbreviate | |
2923 | @code{disable} as @code{dis}. | |
2924 | ||
2925 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2926 | @kindex enable breakpoints | |
2927 | @kindex enable | |
2928 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2929 | become effective once again in stopping your program. |
70b88761 RP |
2930 | |
2931 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2932 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2933 | again the next time it stops your program. |
70b88761 RP |
2934 | |
2935 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2936 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2937 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2938 | @end table |
2939 | ||
29a2b744 RP |
2940 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
2941 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2942 | enabled; subsequently, they become disabled or enabled only when you | |
2943 | use one of the commands above. (The command @code{until} can set and | |
2944 | delete a breakpoint of its own, but it will not change the state of | |
98fe4566 | 2945 | your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.) |
70b88761 | 2946 | |
4eb4cf57 | 2947 | @node Conditions |
70b88761 RP |
2948 | @subsection Break Conditions |
2949 | @cindex conditional breakpoints | |
2950 | @cindex breakpoint conditions | |
2951 | ||
4906534f RP |
2952 | @c FIXME what is scope of break condition expr? Context where wanted? |
2953 | @c in particular for a watchpoint? | |
29a2b744 | 2954 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2955 | specified place. You can also specify a @dfn{condition} for a |
2956 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2957 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2958 | a condition evaluates the expression each time your program reaches it, | |
2959 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2960 | |
2961 | This is the converse of using assertions for program validation; in that | |
2962 | situation, you want to stop when the assertion is violated---that is, | |
2963 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2964 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2965 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2966 | |
2967 | Conditions are also accepted for watchpoints; you may not need them, | |
2968 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2969 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2970 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2971 | one. |
70b88761 | 2972 | |
29a2b744 | 2973 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2974 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2975 | that log program progress, or to use your own print functions to |
2976 | format special data structures. The effects are completely predictable | |
2977 | unless there is another enabled breakpoint at the same address. (In | |
18fae2a8 | 2978 | that case, @value{GDBN} might see the other breakpoint first and stop your |
29a2b744 RP |
2979 | program without checking the condition of this one.) Note that |
2980 | breakpoint commands are usually more convenient and flexible for the | |
2981 | purpose of performing side effects when a breakpoint is reached | |
2982 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
70b88761 RP |
2983 | |
2984 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 RP |
2985 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
2986 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2987 | with the @code{condition} command. The @code{watch} command does not | |
2988 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2989 | impose a further condition on a watchpoint. | |
70b88761 | 2990 | |
e251e767 RP |
2991 | @table @code |
2992 | @item condition @var{bnum} @var{expression} | |
2993 | @kindex condition | |
70b88761 RP |
2994 | Specify @var{expression} as the break condition for breakpoint or |
2995 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2996 | your program only if the value of @var{expression} is true (nonzero, in |
18fae2a8 | 2997 | C). When you use @code{condition}, @value{GDBN} checks @var{expression} |
70b88761 | 2998 | immediately for syntactic correctness, and to determine whether symbols |
1041a570 | 2999 | in it have referents in the context of your breakpoint. |
29a2b744 | 3000 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f | 3001 | @c about watchpoints? |
18fae2a8 | 3002 | @value{GDBN} does |
70b88761 | 3003 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 3004 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3005 | |
3006 | @item condition @var{bnum} | |
3007 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
3008 | an ordinary unconditional breakpoint. | |
3009 | @end table | |
3010 | ||
3011 | @cindex ignore count (of breakpoint) | |
3012 | A special case of a breakpoint condition is to stop only when the | |
3013 | breakpoint has been reached a certain number of times. This is so | |
3014 | useful that there is a special way to do it, using the @dfn{ignore | |
3015 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
3016 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 3017 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
3018 | ignore count is positive, then instead of stopping, it just decrements |
3019 | the ignore count by one and continues. As a result, if the ignore count | |
3020 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
3021 | is reached. | |
3022 | ||
3023 | @table @code | |
3024 | @item ignore @var{bnum} @var{count} | |
3025 | @kindex ignore | |
3026 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
3027 | The next @var{count} times the breakpoint is reached, your program's | |
18fae2a8 | 3028 | execution will not stop; other than to decrement the ignore count, @value{GDBN} |
70b88761 RP |
3029 | takes no action. |
3030 | ||
3031 | To make the breakpoint stop the next time it is reached, specify | |
3032 | a count of zero. | |
3033 | ||
3034 | @item continue @var{count} | |
3035 | @itemx c @var{count} | |
3036 | @itemx fg @var{count} | |
3037 | @kindex continue @var{count} | |
29a2b744 RP |
3038 | Continue execution of your program, setting the ignore count of the |
3039 | breakpoint where your program stopped to @var{count} minus one. | |
3040 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
3041 | @var{count}'th time it is reached. |
3042 | ||
29a2b744 | 3043 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
3044 | due to a breakpoint. At other times, the argument to @code{continue} is |
3045 | ignored. | |
3046 | ||
3047 | The synonym @code{fg} is provided purely for convenience, and has | |
3048 | exactly the same behavior as other forms of the command. | |
3049 | @end table | |
3050 | ||
3051 | If a breakpoint has a positive ignore count and a condition, the condition | |
3052 | is not checked. Once the ignore count reaches zero, the condition will | |
3053 | be checked. | |
3054 | ||
29a2b744 | 3055 | You could achieve the effect of the ignore count with a condition such |
18fae2a8 | 3056 | as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that |
1041a570 RP |
3057 | is decremented each time. @xref{Convenience Vars, ,Convenience |
3058 | Variables}. | |
70b88761 | 3059 | |
4eb4cf57 | 3060 | @node Break Commands |
70b88761 RP |
3061 | @subsection Breakpoint Command Lists |
3062 | ||
3063 | @cindex breakpoint commands | |
3064 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 3065 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
3066 | might want to print the values of certain expressions, or enable other |
3067 | breakpoints. | |
3068 | ||
3069 | @table @code | |
3070 | @item commands @r{[}@var{bnum}@r{]} | |
3071 | @itemx @dots{} @var{command-list} @dots{} | |
3072 | @itemx end | |
3073 | @kindex commands | |
3074 | @kindex end | |
3075 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
3076 | themselves appear on the following lines. Type a line containing just | |
3077 | @code{end} to terminate the commands. | |
3078 | ||
203eea5d RP |
3079 | To remove all commands from a breakpoint, type @code{commands} and |
3080 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
3081 | |
3082 | With no @var{bnum} argument, @code{commands} refers to the last | |
3083 | breakpoint or watchpoint set (not to the breakpoint most recently | |
3084 | encountered). | |
3085 | @end table | |
3086 | ||
18fae2a8 | 3087 | Pressing @key{RET} as a means of repeating the last @value{GDBN} command is |
70b88761 RP |
3088 | disabled within a @var{command-list}. |
3089 | ||
29a2b744 | 3090 | You can use breakpoint commands to start your program up again. Simply |
70b88761 RP |
3091 | use the @code{continue} command, or @code{step}, or any other command |
3092 | that resumes execution. Subsequent commands in the command list are | |
3093 | ignored. | |
3094 | ||
3095 | @kindex silent | |
ed447b95 RP |
3096 | If the first command specified is @code{silent}, the usual message |
3097 | about stopping at a breakpoint is not printed. This may be desirable | |
3098 | for breakpoints that are to print a specific message and then continue. | |
3099 | If none of the remaining commands print anything, you will see no sign | |
3100 | that the breakpoint was reached. @code{silent} is meaningful only at | |
3101 | the beginning of a breakpoint command list. | |
70b88761 | 3102 | |
29a2b744 RP |
3103 | The commands @code{echo} and @code{output} that allow you to print |
3104 | precisely controlled output are often useful in silent breakpoints. | |
3105 | @xref{Output, ,Commands for Controlled Output}. | |
70b88761 RP |
3106 | |
3107 | For example, here is how you could use breakpoint commands to print the | |
3108 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
3109 | ||
18fae2a8 | 3110 | @example |
70b88761 RP |
3111 | break foo if x>0 |
3112 | commands | |
3113 | silent | |
3114 | echo x is\040 | |
3115 | output x | |
3116 | echo \n | |
3117 | cont | |
3118 | end | |
18fae2a8 | 3119 | @end example |
70b88761 RP |
3120 | |
3121 | One application for breakpoint commands is to compensate for one bug so | |
3122 | you can test for another. Put a breakpoint just after the erroneous line | |
3123 | of code, give it a condition to detect the case in which something | |
3124 | erroneous has been done, and give it commands to assign correct values | |
3125 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 3126 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
3127 | command so that no output is produced. Here is an example: |
3128 | ||
3129 | @example | |
3130 | break 403 | |
3131 | commands | |
3132 | silent | |
3133 | set x = y + 4 | |
3134 | cont | |
3135 | end | |
3136 | @end example | |
3137 | ||
3138 | @cindex lost output | |
3139 | One deficiency in the operation of automatically continuing breakpoints | |
3140 | under Unix appears when your program uses raw mode for the terminal. | |
18fae2a8 | 3141 | @value{GDBN} switches back to its own terminal modes (not raw) before executing |
70b88761 | 3142 | commands, and then must switch back to raw mode when your program is |
e251e767 | 3143 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
3144 | @c FIXME: revisit below when GNU sys avail. |
3145 | @c In the GNU system, this will be fixed by changing the behavior of | |
3146 | @c terminal modes. | |
3147 | ||
3148 | Under Unix, you can get around this problem by writing actions into | |
ed447b95 | 3149 | the breakpoint condition rather than in commands. For example, |
70b88761 RP |
3150 | |
3151 | @example | |
3152 | condition 5 (x = y + 4), 0 | |
3153 | @end example | |
3154 | ||
3155 | @noindent | |
1041a570 RP |
3156 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
3157 | change @code{x} as needed, then always have the value zero so your | |
18fae2a8 | 3158 | program will not stop. No input is lost here, because @value{GDBN} evaluates |
1041a570 RP |
3159 | break conditions without changing the terminal modes. When you want |
3160 | to have nontrivial conditions for performing the side effects, the | |
3161 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 | 3162 | |
4eb4cf57 | 3163 | @node Breakpoint Menus |
70b88761 | 3164 | @subsection Breakpoint Menus |
b80282d5 | 3165 | @cindex overloading |
e251e767 | 3166 | @cindex symbol overloading |
70b88761 RP |
3167 | |
3168 | Some programming languages (notably C++) permit a single function name | |
3169 | to be defined several times, for application in different contexts. | |
3170 | This is called @dfn{overloading}. When a function name is overloaded, | |
18fae2a8 | 3171 | @samp{break @var{function}} is not enough to tell @value{GDBN} where you want |
6f3ec223 RP |
3172 | a breakpoint. If you realize this will be a problem, you can use |
3173 | something like @samp{break @var{function}(@var{types})} to specify which | |
18fae2a8 | 3174 | particular version of the function you want. Otherwise, @value{GDBN} offers |
6f3ec223 RP |
3175 | you a menu of numbered choices for different possible breakpoints, and |
3176 | waits for your selection with the prompt @samp{>}. The first two | |
3177 | options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1} | |
3178 | sets a breakpoint at each definition of @var{function}, and typing | |
3179 | @kbd{0} aborts the @code{break} command without setting any new | |
3180 | breakpoints. | |
70b88761 RP |
3181 | |
3182 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 3183 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
3184 | We choose three particular definitions of that function name: |
3185 | ||
6f3ec223 | 3186 | @c FIXME! This is likely to change to show arg type lists, at least |
70b88761 | 3187 | @example |
18fae2a8 | 3188 | (@value{GDBP}) b String::after |
70b88761 RP |
3189 | [0] cancel |
3190 | [1] all | |
3191 | [2] file:String.cc; line number:867 | |
3192 | [3] file:String.cc; line number:860 | |
3193 | [4] file:String.cc; line number:875 | |
3194 | [5] file:String.cc; line number:853 | |
3195 | [6] file:String.cc; line number:846 | |
3196 | [7] file:String.cc; line number:735 | |
3197 | > 2 4 6 | |
3198 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
3199 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
3200 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
3201 | Multiple breakpoints were set. | |
3202 | Use the "delete" command to delete unwanted breakpoints. | |
18fae2a8 | 3203 | (@value{GDBP}) |
70b88761 RP |
3204 | @end example |
3205 | ||
4eb4cf57 | 3206 | @node Error in Breakpoints |
70b88761 RP |
3207 | @subsection ``Cannot Insert Breakpoints'' |
3208 | ||
e251e767 | 3209 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 3210 | @c Q in pending mail to Gilmore. [email protected], 26mar91 |
e251e767 | 3211 | @c some light may be shed by looking at instances of |
d24e0922 | 3212 | @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise |
c338a2fd | 3213 | @c too. pesch, 20sep91 |
70b88761 RP |
3214 | Under some operating systems, breakpoints cannot be used in a program if |
3215 | any other process is running that program. In this situation, | |
18fae2a8 | 3216 | attempting to run or continue a program with a breakpoint causes @value{GDBN} |
70b88761 RP |
3217 | to stop the other process. |
3218 | ||
3219 | When this happens, you have three ways to proceed: | |
3220 | ||
3221 | @enumerate | |
3222 | @item | |
3223 | Remove or disable the breakpoints, then continue. | |
3224 | ||
3225 | @item | |
18fae2a8 RP |
3226 | Suspend @value{GDBN}, and copy the file containing your program to a new name. |
3227 | Resume @value{GDBN} and use the @code{exec-file} command to specify that @value{GDBN} | |
29a2b744 | 3228 | should run your program under that name. Then start your program again. |
70b88761 RP |
3229 | |
3230 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
3231 | @c explains the first FIXME: in this section... | |
3232 | ||
3233 | @item | |
29a2b744 | 3234 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
3235 | linker option @samp{-N}. The operating system limitation may not apply |
3236 | to nonsharable executables. | |
3237 | @end enumerate | |
3238 | ||
4eb4cf57 | 3239 | @node Continuing and Stepping |
3d3ab540 | 3240 | @section Continuing and Stepping |
70b88761 RP |
3241 | |
3242 | @cindex stepping | |
7463aadd RP |
3243 | @cindex continuing |
3244 | @cindex resuming execution | |
3d3ab540 | 3245 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
3246 | completes normally. In contrast, @dfn{stepping} means executing just |
3247 | one more ``step'' of your program, where ``step'' may mean either one | |
3248 | line of source code, or one machine instruction (depending on what | |
3249 | particular command you use). Either when continuing | |
4eb4cf57 | 3250 | or when stepping, your program may stop even sooner, due to |
18fae2a8 | 3251 | @ifset BARETARGET |
4eb4cf57 | 3252 | a breakpoint. |
18fae2a8 RP |
3253 | @end ifset |
3254 | @ifclear BARETARGET | |
4eb4cf57 RP |
3255 | a breakpoint or to a signal. (If due to a signal, you may want to use |
3256 | @code{handle}, or use @samp{signal 0} to resume execution. | |
3257 | @xref{Signals, ,Signals}.) | |
18fae2a8 | 3258 | @end ifclear |
3d3ab540 RP |
3259 | |
3260 | @table @code | |
3261 | @item continue @r{[}@var{ignore-count}@r{]} | |
3262 | @kindex continue | |
29a2b744 | 3263 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
3264 | any breakpoints set at that address are bypassed. The optional argument |
3265 | @var{ignore-count} allows you to specify a further number of times to | |
3266 | ignore a breakpoint at this location; its effect is like that of | |
29a2b744 | 3267 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). |
3d3ab540 RP |
3268 | |
3269 | To resume execution at a different place, you can use @code{return} | |
29a2b744 RP |
3270 | (@pxref{Returning, ,Returning from a Function}) to go back to the |
3271 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
1041a570 | 3272 | Different Address}) to go to an arbitrary location in your program. |
3d3ab540 | 3273 | @end table |
7463aadd RP |
3274 | |
3275 | A typical technique for using stepping is to set a breakpoint | |
29a2b744 RP |
3276 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the |
3277 | beginning of the function or the section of your program where a | |
3278 | problem is believed to lie, run your program until it stops at that | |
3279 | breakpoint, and then step through the suspect area, examining the | |
3280 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
3281 | |
3282 | @table @code | |
3283 | @item step | |
3284 | @kindex step | |
3285 | @kindex s | |
29a2b744 | 3286 | Continue running your program until control reaches a different source |
18fae2a8 | 3287 | line, then stop it and return control to @value{GDBN}. This command is |
70b88761 RP |
3288 | abbreviated @code{s}. |
3289 | ||
3d3ab540 RP |
3290 | @quotation |
3291 | @emph{Warning:} If you use the @code{step} command while control is | |
3292 | within a function that was compiled without debugging information, | |
3293 | execution will proceed until control reaches another function. | |
3294 | @end quotation | |
70b88761 RP |
3295 | |
3296 | @item step @var{count} | |
3297 | Continue running as in @code{step}, but do so @var{count} times. If a | |
3298 | breakpoint is reached or a signal not related to stepping occurs before | |
3299 | @var{count} steps, stepping stops right away. | |
3300 | ||
7463aadd | 3301 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
3302 | @kindex next |
3303 | @kindex n | |
7463aadd RP |
3304 | Continue to the next source line in the current (innermost) stack frame. |
3305 | Similar to @code{step}, but any function calls appearing within the line | |
3306 | of code are executed without stopping. Execution stops when control | |
3307 | reaches a different line of code at the stack level which was executing | |
3308 | when the @code{next} command was given. This command is abbreviated | |
3309 | @code{n}. | |
70b88761 | 3310 | |
7463aadd | 3311 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
3312 | |
3313 | @code{next} within a function that lacks debugging information acts like | |
3314 | @code{step}, but any function calls appearing within the code of the | |
3315 | function are executed without stopping. | |
3316 | ||
3317 | @item finish | |
3318 | @kindex finish | |
7463aadd RP |
3319 | Continue running until just after function in the selected stack frame |
3320 | returns. Print the returned value (if any). | |
70b88761 | 3321 | |
29a2b744 | 3322 | Contrast this with the @code{return} command (@pxref{Returning, |
1041a570 | 3323 | ,Returning from a Function}). |
70b88761 RP |
3324 | |
3325 | @item until | |
3326 | @kindex until | |
3327 | @item u | |
3328 | @kindex u | |
3329 | Continue running until a source line past the current line, in the | |
3330 | current stack frame, is reached. This command is used to avoid single | |
3331 | stepping through a loop more than once. It is like the @code{next} | |
3332 | command, except that when @code{until} encounters a jump, it | |
3333 | automatically continues execution until the program counter is greater | |
3334 | than the address of the jump. | |
3335 | ||
3336 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 3337 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
3338 | until the loop is exited. In contrast, a @code{next} command at the end |
3339 | of a loop will simply step back to the beginning of the loop, which | |
3340 | would force you to step through the next iteration. | |
3341 | ||
29a2b744 | 3342 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
3343 | stack frame. |
3344 | ||
3345 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 3346 | of machine code does not match the order of the source lines. For |
70b88761 RP |
3347 | example, in the following excerpt from a debugging session, the @code{f} |
3348 | (@code{frame}) command shows that execution is stopped at line | |
3349 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
3350 | ||
3351 | @example | |
18fae2a8 | 3352 | (@value{GDBP}) f |
70b88761 | 3353 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 |
b80282d5 | 3354 | 206 expand_input(); |
18fae2a8 | 3355 | (@value{GDBP}) until |
b80282d5 | 3356 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
3357 | @end example |
3358 | ||
7463aadd RP |
3359 | This happened because, for execution efficiency, the compiler had |
3360 | generated code for the loop closure test at the end, rather than the | |
3361 | start, of the loop---even though the test in a C @code{for}-loop is | |
3362 | written before the body of the loop. The @code{until} command appeared | |
3363 | to step back to the beginning of the loop when it advanced to this | |
3364 | expression; however, it has not really gone to an earlier | |
3365 | statement---not in terms of the actual machine code. | |
70b88761 RP |
3366 | |
3367 | @code{until} with no argument works by means of single | |
3368 | instruction stepping, and hence is slower than @code{until} with an | |
3369 | argument. | |
3370 | ||
3371 | @item until @var{location} | |
3372 | @item u @var{location} | |
29a2b744 RP |
3373 | Continue running your program until either the specified location is |
3374 | reached, or the current stack frame returns. @var{location} is any of | |
3375 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
3376 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
1041a570 | 3377 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
3378 | |
3379 | @item stepi | |
3380 | @itemx si | |
3381 | @kindex stepi | |
3382 | @kindex si | |
3383 | Execute one machine instruction, then stop and return to the debugger. | |
3384 | ||
3385 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
3386 | instructions. This will cause the next instruction to be executed to | |
29a2b744 RP |
3387 | be displayed automatically at each stop. @xref{Auto Display, |
3388 | ,Automatic Display}. | |
70b88761 RP |
3389 | |
3390 | An argument is a repeat count, as in @code{step}. | |
3391 | ||
ed447b95 | 3392 | @need 750 |
70b88761 RP |
3393 | @item nexti |
3394 | @itemx ni | |
3395 | @kindex nexti | |
3396 | @kindex ni | |
3397 | Execute one machine instruction, but if it is a function call, | |
3398 | proceed until the function returns. | |
3399 | ||
3400 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
3401 | @end table |
3402 | ||
18fae2a8 | 3403 | @ifset POSIX |
4eb4cf57 | 3404 | @node Signals |
70b88761 RP |
3405 | @section Signals |
3406 | @cindex signals | |
3407 | ||
3408 | A signal is an asynchronous event that can happen in a program. The | |
3409 | operating system defines the possible kinds of signals, and gives each | |
3410 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
3411 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
3412 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
3413 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 3414 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
3415 | requested an alarm). |
3416 | ||
3417 | @cindex fatal signals | |
3418 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
3419 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
3420 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 3421 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 3422 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
3423 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
3424 | ||
18fae2a8 RP |
3425 | @value{GDBN} has the ability to detect any occurrence of a signal in your |
3426 | program. You can tell @value{GDBN} in advance what to do for each kind of | |
29a2b744 | 3427 | signal. |
70b88761 RP |
3428 | |
3429 | @cindex handling signals | |
18fae2a8 | 3430 | Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM} |
29a2b744 RP |
3431 | (so as not to interfere with their role in the functioning of your program) |
3432 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
3433 | You can change these settings with the @code{handle} command. |
3434 | ||
3435 | @table @code | |
3436 | @item info signals | |
3437 | @kindex info signals | |
18fae2a8 | 3438 | Print a table of all the kinds of signals and how @value{GDBN} has been told to |
70b88761 RP |
3439 | handle each one. You can use this to see the signal numbers of all |
3440 | the defined types of signals. | |
3441 | ||
3442 | @item handle @var{signal} @var{keywords}@dots{} | |
3443 | @kindex handle | |
18fae2a8 | 3444 | Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can be the |
70b88761 RP |
3445 | number of a signal or its name (with or without the @samp{SIG} at the |
3446 | beginning). The @var{keywords} say what change to make. | |
3447 | @end table | |
3448 | ||
3449 | @c @group | |
3450 | The keywords allowed by the @code{handle} command can be abbreviated. | |
3451 | Their full names are: | |
3452 | ||
3453 | @table @code | |
3454 | @item nostop | |
18fae2a8 | 3455 | @value{GDBN} should not stop your program when this signal happens. It may |
70b88761 RP |
3456 | still print a message telling you that the signal has come in. |
3457 | ||
3458 | @item stop | |
18fae2a8 | 3459 | @value{GDBN} should stop your program when this signal happens. This implies |
70b88761 RP |
3460 | the @code{print} keyword as well. |
3461 | ||
3462 | @item print | |
18fae2a8 | 3463 | @value{GDBN} should print a message when this signal happens. |
70b88761 RP |
3464 | |
3465 | @item noprint | |
18fae2a8 | 3466 | @value{GDBN} should not mention the occurrence of the signal at all. This |
70b88761 RP |
3467 | implies the @code{nostop} keyword as well. |
3468 | ||
3469 | @item pass | |
18fae2a8 | 3470 | @value{GDBN} should allow your program to see this signal; your program will be |
70b88761 RP |
3471 | able to handle the signal, or may be terminated if the signal is fatal |
3472 | and not handled. | |
3473 | ||
3474 | @item nopass | |
18fae2a8 | 3475 | @value{GDBN} should not allow your program to see this signal. |
70b88761 RP |
3476 | @end table |
3477 | @c @end group | |
3478 | ||
ed447b95 RP |
3479 | When a signal stops your program, the signal is not visible until you |
3480 | continue. Your program will see the signal then, if @code{pass} is in | |
3481 | effect for the signal in question @emph{at that time}. In other words, | |
3482 | after @value{GDBN} reports a signal, you can use the @code{handle} | |
3483 | command with @code{pass} or @code{nopass} to control whether that | |
3484 | signal will be seen by your program when you later continue it. | |
70b88761 | 3485 | |
29a2b744 | 3486 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 3487 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 3488 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
3489 | due to some sort of memory reference error, you might store correct |
3490 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
3491 | execution; but your program would probably terminate immediately as |
3492 | a result of the fatal signal once it saw the signal. To prevent this, | |
3493 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
3494 | Program a Signal}. | |
18fae2a8 | 3495 | @end ifset |
70b88761 | 3496 | |
4eb4cf57 | 3497 | @node Stack |
70b88761 RP |
3498 | @chapter Examining the Stack |
3499 | ||
3500 | When your program has stopped, the first thing you need to know is where it | |
3501 | stopped and how it got there. | |
3502 | ||
3503 | @cindex call stack | |
3504 | Each time your program performs a function call, the information about | |
29a2b744 | 3505 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
3506 | called a @dfn{stack frame}. The frame also contains the arguments of the |
3507 | call and the local variables of the function that was called. All the | |
3508 | stack frames are allocated in a region of memory called the @dfn{call | |
3509 | stack}. | |
3510 | ||
18fae2a8 | 3511 | When your program stops, the @value{GDBN} commands for examining the stack allow you |
70b88761 RP |
3512 | to see all of this information. |
3513 | ||
3514 | @cindex selected frame | |
18fae2a8 | 3515 | One of the stack frames is @dfn{selected} by @value{GDBN} and many @value{GDBN} commands |
70b88761 | 3516 | refer implicitly to the selected frame. In particular, whenever you ask |
18fae2a8 RP |
3517 | @value{GDBN} for the value of a variable in your program, the value is found in the |
3518 | selected frame. There are special @value{GDBN} commands to select whichever frame | |
70b88761 RP |
3519 | you are interested in. |
3520 | ||
18fae2a8 | 3521 | When your program stops, @value{GDBN} automatically selects the currently executing |
70b88761 | 3522 | frame and describes it briefly as the @code{frame} command does |
29a2b744 | 3523 | (@pxref{Frame Info, ,Information About a Frame}). |
70b88761 RP |
3524 | |
3525 | @menu | |
ed447b95 | 3526 | * Frames:: Stack frames |
b80282d5 | 3527 | * Backtrace:: Backtraces |
ed447b95 RP |
3528 | * Selection:: Selecting a frame |
3529 | * Frame Info:: Information on a frame | |
70b88761 RP |
3530 | @end menu |
3531 | ||
4eb4cf57 | 3532 | @node Frames |
70b88761 RP |
3533 | @section Stack Frames |
3534 | ||
3535 | @cindex frame | |
3536 | @cindex stack frame | |
3537 | The call stack is divided up into contiguous pieces called @dfn{stack | |
3538 | frames}, or @dfn{frames} for short; each frame is the data associated | |
3539 | with one call to one function. The frame contains the arguments given | |
3540 | to the function, the function's local variables, and the address at | |
3541 | which the function is executing. | |
3542 | ||
3543 | @cindex initial frame | |
3544 | @cindex outermost frame | |
3545 | @cindex innermost frame | |
3546 | When your program is started, the stack has only one frame, that of the | |
3547 | function @code{main}. This is called the @dfn{initial} frame or the | |
3548 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
3549 | made. Each time a function returns, the frame for that function invocation | |
3550 | is eliminated. If a function is recursive, there can be many frames for | |
3551 | the same function. The frame for the function in which execution is | |
3552 | actually occurring is called the @dfn{innermost} frame. This is the most | |
3553 | recently created of all the stack frames that still exist. | |
3554 | ||
3555 | @cindex frame pointer | |
3556 | Inside your program, stack frames are identified by their addresses. A | |
3557 | stack frame consists of many bytes, each of which has its own address; each | |
3558 | kind of computer has a convention for choosing one of those bytes whose | |
3559 | address serves as the address of the frame. Usually this address is kept | |
3560 | in a register called the @dfn{frame pointer register} while execution is | |
3561 | going on in that frame. | |
3562 | ||
3563 | @cindex frame number | |
18fae2a8 | 3564 | @value{GDBN} assigns numbers to all existing stack frames, starting with |
70b88761 RP |
3565 | zero for the innermost frame, one for the frame that called it, |
3566 | and so on upward. These numbers do not really exist in your program; | |
18fae2a8 RP |
3567 | they are assigned by @value{GDBN} to give you a way of designating stack |
3568 | frames in @value{GDBN} commands. | |
70b88761 RP |
3569 | |
3570 | @cindex frameless execution | |
3571 | Some compilers allow functions to be compiled so that they operate | |
18fae2a8 | 3572 | without stack frames. (For example, the @code{@value{GCC}} option |
70b88761 RP |
3573 | @samp{-fomit-frame-pointer} will generate functions without a frame.) |
3574 | This is occasionally done with heavily used library functions to save | |
18fae2a8 | 3575 | the frame setup time. @value{GDBN} has limited facilities for dealing with |
70b88761 | 3576 | these function invocations. If the innermost function invocation has no |
18fae2a8 | 3577 | stack frame, @value{GDBN} will nevertheless regard it as though it had a |
70b88761 | 3578 | separate frame, which is numbered zero as usual, allowing correct |
18fae2a8 | 3579 | tracing of the function call chain. However, @value{GDBN} has no provision |
70b88761 RP |
3580 | for frameless functions elsewhere in the stack. |
3581 | ||
4eb4cf57 | 3582 | @node Backtrace |
70b88761 RP |
3583 | @section Backtraces |
3584 | ||
29a2b744 | 3585 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
3586 | line per frame, for many frames, starting with the currently executing |
3587 | frame (frame zero), followed by its caller (frame one), and on up the | |
3588 | stack. | |
3589 | ||
3590 | @table @code | |
3591 | @item backtrace | |
3592 | @itemx bt | |
3593 | @kindex backtrace | |
3594 | @kindex bt | |
3595 | Print a backtrace of the entire stack: one line per frame for all | |
3596 | frames in the stack. | |
3597 | ||
3598 | You can stop the backtrace at any time by typing the system interrupt | |
3599 | character, normally @kbd{C-c}. | |
3600 | ||
3601 | @item backtrace @var{n} | |
3602 | @itemx bt @var{n} | |
3603 | Similar, but print only the innermost @var{n} frames. | |
3604 | ||
3605 | @item backtrace -@var{n} | |
3606 | @itemx bt -@var{n} | |
3607 | Similar, but print only the outermost @var{n} frames. | |
3608 | @end table | |
3609 | ||
3610 | @kindex where | |
3611 | @kindex info stack | |
3612 | @kindex info s | |
3613 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
3614 | are additional aliases for @code{backtrace}. | |
3615 | ||
3616 | Each line in the backtrace shows the frame number and the function name. | |
3617 | The program counter value is also shown---unless you use @code{set | |
3618 | print address off}. The backtrace also shows the source file name and | |
3619 | line number, as well as the arguments to the function. The program | |
3620 | counter value is omitted if it is at the beginning of the code for that | |
3621 | line number. | |
3622 | ||
3623 | Here is an example of a backtrace. It was made with the command | |
3624 | @samp{bt 3}, so it shows the innermost three frames. | |
3625 | ||
3626 | @smallexample | |
3627 | @group | |
203eea5d RP |
3628 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
3629 | at builtin.c:993 | |
70b88761 RP |
3630 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
3631 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
3632 | at macro.c:71 | |
3633 | (More stack frames follow...) | |
3634 | @end group | |
3635 | @end smallexample | |
3636 | ||
3637 | @noindent | |
29a2b744 RP |
3638 | The display for frame zero does not begin with a program counter |
3639 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
3640 | code for line @code{993} of @code{builtin.c}. |
3641 | ||
4eb4cf57 | 3642 | @node Selection |
70b88761 RP |
3643 | @section Selecting a Frame |
3644 | ||
29a2b744 | 3645 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
3646 | whichever stack frame is selected at the moment. Here are the commands for |
3647 | selecting a stack frame; all of them finish by printing a brief description | |
3648 | of the stack frame just selected. | |
3649 | ||
3650 | @table @code | |
3651 | @item frame @var{n} | |
3652 | @itemx f @var{n} | |
3653 | @kindex frame | |
3654 | @kindex f | |
3655 | Select frame number @var{n}. Recall that frame zero is the innermost | |
3656 | (currently executing) frame, frame one is the frame that called the | |
93918348 RP |
3657 | innermost one, and so on. The highest-numbered frame is the one for |
3658 | @code{main}. | |
70b88761 RP |
3659 | |
3660 | @item frame @var{addr} | |
3661 | @itemx f @var{addr} | |
3662 | Select the frame at address @var{addr}. This is useful mainly if the | |
3663 | chaining of stack frames has been damaged by a bug, making it | |
18fae2a8 | 3664 | impossible for @value{GDBN} to assign numbers properly to all frames. In |
29a2b744 | 3665 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
3666 | switches between them. |
3667 | ||
18fae2a8 | 3668 | @ifset SPARC |
70b88761 | 3669 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 3670 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
3671 | @c note to future updaters: this is conditioned on a flag |
3672 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
3673 | @c by SPARC, hence the specific attribution. Generalize or list all | |
3674 | @c possibilities if more supported machines start doing this. | |
18fae2a8 | 3675 | @end ifset |
70b88761 RP |
3676 | |
3677 | @item up @var{n} | |
3678 | @kindex up | |
3679 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
3680 | advances toward the outermost frame, to higher frame numbers, to frames | |
3681 | that have existed longer. @var{n} defaults to one. | |
3682 | ||
3683 | @item down @var{n} | |
3684 | @kindex down | |
3685 | @kindex do | |
3686 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
3687 | advances toward the innermost frame, to lower frame numbers, to frames | |
3688 | that were created more recently. @var{n} defaults to one. You may | |
3689 | abbreviate @code{down} as @code{do}. | |
3690 | @end table | |
3691 | ||
3692 | All of these commands end by printing two lines of output describing the | |
3693 | frame. The first line shows the frame number, the function name, the | |
3694 | arguments, and the source file and line number of execution in that | |
ed447b95 | 3695 | frame. The second line shows the text of that source line. |
70b88761 | 3696 | |
ed447b95 | 3697 | For example: |
70b88761 | 3698 | @smallexample |
29a2b744 | 3699 | @group |
18fae2a8 | 3700 | (@value{GDBP}) up |
203eea5d RP |
3701 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
3702 | at env.c:10 | |
70b88761 | 3703 | 10 read_input_file (argv[i]); |
29a2b744 | 3704 | @end group |
70b88761 RP |
3705 | @end smallexample |
3706 | ||
29a2b744 RP |
3707 | After such a printout, the @code{list} command with no arguments will |
3708 | print ten lines centered on the point of execution in the frame. | |
3709 | @xref{List, ,Printing Source Lines}. | |
70b88761 RP |
3710 | |
3711 | @table @code | |
3712 | @item up-silently @var{n} | |
3713 | @itemx down-silently @var{n} | |
3714 | @kindex down-silently | |
3715 | @kindex up-silently | |
3716 | These two commands are variants of @code{up} and @code{down}, | |
3717 | respectively; they differ in that they do their work silently, without | |
3718 | causing display of the new frame. They are intended primarily for use | |
18fae2a8 | 3719 | in @value{GDBN} command scripts, where the output might be unnecessary and |
e251e767 | 3720 | distracting. |
70b88761 RP |
3721 | @end table |
3722 | ||
4eb4cf57 | 3723 | @node Frame Info |
70b88761 RP |
3724 | @section Information About a Frame |
3725 | ||
3726 | There are several other commands to print information about the selected | |
3727 | stack frame. | |
3728 | ||
3729 | @table @code | |
3730 | @item frame | |
3731 | @itemx f | |
29a2b744 RP |
3732 | When used without any argument, this command does not change which |
3733 | frame is selected, but prints a brief description of the currently | |
70b88761 | 3734 | selected stack frame. It can be abbreviated @code{f}. With an |
ed447b95 RP |
3735 | argument, this command is used to select a stack frame. |
3736 | @xref{Selection, ,Selecting a Frame}. | |
70b88761 RP |
3737 | |
3738 | @item info frame | |
70b88761 | 3739 | @itemx info f |
29a2b744 | 3740 | @kindex info frame |
70b88761 RP |
3741 | @kindex info f |
3742 | This command prints a verbose description of the selected stack frame, | |
3743 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
3744 | (called by this frame) and the next frame up (caller of this frame), the |
3745 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
3746 | the address of the frame's arguments, the program counter saved in it |
3747 | (the address of execution in the caller frame), and which registers | |
3748 | were saved in the frame. The verbose description is useful when | |
3749 | something has gone wrong that has made the stack format fail to fit | |
3750 | the usual conventions. | |
3751 | ||
3752 | @item info frame @var{addr} | |
3753 | @itemx info f @var{addr} | |
3754 | Print a verbose description of the frame at address @var{addr}, | |
3755 | without selecting that frame. The selected frame remains unchanged by | |
3756 | this command. | |
3757 | ||
3758 | @item info args | |
3759 | @kindex info args | |
3760 | Print the arguments of the selected frame, each on a separate line. | |
3761 | ||
3762 | @item info locals | |
3763 | @kindex info locals | |
3764 | Print the local variables of the selected frame, each on a separate | |
ed447b95 RP |
3765 | line. These are all variables (declared either static or automatic) |
3766 | accessible at the point of execution of the selected frame. | |
70b88761 RP |
3767 | |
3768 | @item info catch | |
3769 | @kindex info catch | |
3770 | @cindex catch exceptions | |
3771 | @cindex exception handlers | |
3772 | Print a list of all the exception handlers that are active in the | |
3773 | current stack frame at the current point of execution. To see other | |
3774 | exception handlers, visit the associated frame (using the @code{up}, | |
3775 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
1041a570 | 3776 | @xref{Exception Handling, ,Breakpoints and Exceptions}. |
70b88761 RP |
3777 | @end table |
3778 | ||
4eb4cf57 | 3779 | @node Source |
70b88761 RP |
3780 | @chapter Examining Source Files |
3781 | ||
18fae2a8 | 3782 | @value{GDBN} can print parts of your program's source, since the debugging |
ed447b95 | 3783 | information recorded in the program tells @value{GDBN} what source files were |
18fae2a8 | 3784 | used to build it. When your program stops, @value{GDBN} spontaneously prints |
1041a570 | 3785 | the line where it stopped. Likewise, when you select a stack frame |
18fae2a8 | 3786 | (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where |
1041a570 RP |
3787 | execution in that frame has stopped. You can print other portions of |
3788 | source files by explicit command. | |
70b88761 | 3789 | |
18fae2a8 RP |
3790 | @ifclear DOSHOST |
3791 | If you use @value{GDBN} through its GNU Emacs interface, you may prefer to use | |
3792 | Emacs facilities to view source; @pxref{Emacs, ,Using @value{GDBN} under GNU | |
1041a570 | 3793 | Emacs}. |
18fae2a8 | 3794 | @end ifclear |
70b88761 | 3795 | |
18fae2a8 RP |
3796 | @ignore |
3797 | @c pre-unfolded menu | |
70b88761 | 3798 | @menu |
ed447b95 | 3799 | * List:: Printing source lines |
18fae2a8 | 3800 | @ifclear DOSHOST |
ed447b95 | 3801 | * Search:: Searching source files |
18fae2a8 | 3802 | @end ifclear |
ed447b95 RP |
3803 | * Source Path:: Specifying source directories |
3804 | * Machine Code:: Source and machine code | |
70b88761 | 3805 | @end menu |
18fae2a8 RP |
3806 | @end ignore |
3807 | ||
3808 | @ifclear DOSHOST | |
3809 | @menu | |
ed447b95 RP |
3810 | * List:: Printing source lines |
3811 | * Search:: Searching source files | |
3812 | * Source Path:: Specifying source directories | |
3813 | * Machine Code:: Source and machine code | |
18fae2a8 RP |
3814 | @end menu |
3815 | @end ifclear | |
3816 | ||
3817 | @ifset DOSHOST | |
3818 | @menu | |
ed447b95 RP |
3819 | * List:: Printing source lines |
3820 | * Source Path:: Specifying source directories | |
3821 | * Machine Code:: Source and machine code | |
18fae2a8 RP |
3822 | @end menu |
3823 | @end ifset | |
70b88761 | 3824 | |
4eb4cf57 | 3825 | @node List |
70b88761 RP |
3826 | @section Printing Source Lines |
3827 | ||
3828 | @kindex list | |
3829 | @kindex l | |
3830 | To print lines from a source file, use the @code{list} command | |
3831 | (abbreviated @code{l}). There are several ways to specify what part | |
3832 | of the file you want to print. | |
3833 | ||
3834 | Here are the forms of the @code{list} command most commonly used: | |
3835 | ||
3836 | @table @code | |
3837 | @item list @var{linenum} | |
c338a2fd | 3838 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
3839 | current source file. |
3840 | ||
3841 | @item list @var{function} | |
c338a2fd | 3842 | Print lines centered around the beginning of function |
70b88761 RP |
3843 | @var{function}. |
3844 | ||
3845 | @item list | |
c338a2fd RP |
3846 | Print more lines. If the last lines printed were printed with a |
3847 | @code{list} command, this prints lines following the last lines | |
70b88761 | 3848 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 3849 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 3850 | Stack}), this prints lines centered around that line. |
70b88761 RP |
3851 | |
3852 | @item list - | |
c338a2fd RP |
3853 | Print lines just before the lines last printed. |
3854 | @end table | |
3855 | ||
18fae2a8 | 3856 | By default, @value{GDBN} prints ten source lines with any of these forms of |
c338a2fd RP |
3857 | the @code{list} command. You can change this using @code{set listsize}: |
3858 | ||
3859 | @table @code | |
3860 | @item set listsize @var{count} | |
3861 | @kindex set listsize | |
3862 | Make the @code{list} command display @var{count} source lines (unless | |
3863 | the @code{list} argument explicitly specifies some other number). | |
3864 | ||
3865 | @item show listsize | |
3866 | @kindex show listsize | |
3867 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 3868 | default. |
70b88761 RP |
3869 | @end table |
3870 | ||
3871 | Repeating a @code{list} command with @key{RET} discards the argument, | |
3872 | so it is equivalent to typing just @code{list}. This is more useful | |
3873 | than listing the same lines again. An exception is made for an | |
3874 | argument of @samp{-}; that argument is preserved in repetition so that | |
3875 | each repetition moves up in the source file. | |
3876 | ||
3877 | @cindex linespec | |
3878 | In general, the @code{list} command expects you to supply zero, one or two | |
3879 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
3880 | of writing them but the effect is always to specify some source line. | |
3881 | Here is a complete description of the possible arguments for @code{list}: | |
3882 | ||
3883 | @table @code | |
3884 | @item list @var{linespec} | |
c338a2fd | 3885 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
3886 | |
3887 | @item list @var{first},@var{last} | |
3888 | Print lines from @var{first} to @var{last}. Both arguments are | |
3889 | linespecs. | |
3890 | ||
3891 | @item list ,@var{last} | |
c338a2fd | 3892 | Print lines ending with @var{last}. |
70b88761 RP |
3893 | |
3894 | @item list @var{first}, | |
c338a2fd | 3895 | Print lines starting with @var{first}. |
70b88761 RP |
3896 | |
3897 | @item list + | |
c338a2fd | 3898 | Print lines just after the lines last printed. |
70b88761 RP |
3899 | |
3900 | @item list - | |
c338a2fd | 3901 | Print lines just before the lines last printed. |
70b88761 RP |
3902 | |
3903 | @item list | |
3904 | As described in the preceding table. | |
3905 | @end table | |
3906 | ||
3907 | Here are the ways of specifying a single source line---all the | |
3908 | kinds of linespec. | |
3909 | ||
3910 | @table @code | |
3911 | @item @var{number} | |
3912 | Specifies line @var{number} of the current source file. | |
3913 | When a @code{list} command has two linespecs, this refers to | |
3914 | the same source file as the first linespec. | |
3915 | ||
3916 | @item +@var{offset} | |
3917 | Specifies the line @var{offset} lines after the last line printed. | |
3918 | When used as the second linespec in a @code{list} command that has | |
3919 | two, this specifies the line @var{offset} lines down from the | |
3920 | first linespec. | |
3921 | ||
3922 | @item -@var{offset} | |
3923 | Specifies the line @var{offset} lines before the last line printed. | |
3924 | ||
3925 | @item @var{filename}:@var{number} | |
3926 | Specifies line @var{number} in the source file @var{filename}. | |
3927 | ||
3928 | @item @var{function} | |
3929 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
3930 | Specifies the line of the open-brace that begins the body of the | |
3931 | function @var{function}. | |
3932 | ||
3933 | @item @var{filename}:@var{function} | |
3934 | Specifies the line of the open-brace that begins the body of the | |
3935 | function @var{function} in the file @var{filename}. You only need the | |
3936 | file name with a function name to avoid ambiguity when there are | |
3937 | identically named functions in different source files. | |
3938 | ||
3939 | @item *@var{address} | |
3940 | Specifies the line containing the program address @var{address}. | |
3941 | @var{address} may be any expression. | |
3942 | @end table | |
3943 | ||
18fae2a8 | 3944 | @ifclear DOSHOST |
4eb4cf57 | 3945 | @node Search |
70b88761 RP |
3946 | @section Searching Source Files |
3947 | @cindex searching | |
3948 | @kindex reverse-search | |
3949 | ||
3950 | There are two commands for searching through the current source file for a | |
3951 | regular expression. | |
3952 | ||
3953 | @table @code | |
3954 | @item forward-search @var{regexp} | |
3955 | @itemx search @var{regexp} | |
3956 | @kindex search | |
3957 | @kindex forward-search | |
1041a570 RP |
3958 | The command @samp{forward-search @var{regexp}} checks each line, |
3959 | starting with the one following the last line listed, for a match for | |
3960 | @var{regexp}. It lists the line that is found. You can use | |
3961 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3962 | @code{fo}. | |
70b88761 RP |
3963 | |
3964 | @item reverse-search @var{regexp} | |
3965 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3966 | with the one before the last line listed and going backward, for a match | |
3967 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3968 | this command as @code{rev}. | |
3969 | @end table | |
18fae2a8 | 3970 | @end ifclear |
70b88761 | 3971 | |
4eb4cf57 | 3972 | @node Source Path |
70b88761 RP |
3973 | @section Specifying Source Directories |
3974 | ||
3975 | @cindex source path | |
3976 | @cindex directories for source files | |
3977 | Executable programs sometimes do not record the directories of the source | |
3978 | files from which they were compiled, just the names. Even when they do, | |
3979 | the directories could be moved between the compilation and your debugging | |
18fae2a8 RP |
3980 | session. @value{GDBN} has a list of directories to search for source files; |
3981 | this is called the @dfn{source path}. Each time @value{GDBN} wants a source file, | |
70b88761 RP |
3982 | it tries all the directories in the list, in the order they are present |
3983 | in the list, until it finds a file with the desired name. Note that | |
3984 | the executable search path is @emph{not} used for this purpose. Neither is | |
3985 | the current working directory, unless it happens to be in the source | |
3986 | path. | |
3987 | ||
18fae2a8 RP |
3988 | If @value{GDBN} cannot find a source file in the source path, and the object |
3989 | program records a directory, @value{GDBN} tries that directory too. If the | |
70b88761 | 3990 | source path is empty, and there is no record of the compilation |
18fae2a8 | 3991 | directory, @value{GDBN} will, as a last resort, look in the current |
70b88761 RP |
3992 | directory. |
3993 | ||
18fae2a8 | 3994 | Whenever you reset or rearrange the source path, @value{GDBN} will clear out |
70b88761 RP |
3995 | any information it has cached about where source files are found, where |
3996 | each line is in the file, etc. | |
3997 | ||
3998 | @kindex directory | |
18fae2a8 | 3999 | When you start @value{GDBN}, its source path is empty. |
70b88761 RP |
4000 | To add other directories, use the @code{directory} command. |
4001 | ||
4002 | @table @code | |
4003 | @item directory @var{dirname} @dots{} | |
4004 | Add directory @var{dirname} to the front of the source path. Several | |
4005 | directory names may be given to this command, separated by @samp{:} or | |
4006 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 4007 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
4008 | |
4009 | You can use the string @samp{$cdir} to refer to the compilation | |
4010 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
4011 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
18fae2a8 | 4012 | tracks the current working directory as it changes during your @value{GDBN} |
7463aadd RP |
4013 | session, while the latter is immediately expanded to the current |
4014 | directory at the time you add an entry to the source path. | |
70b88761 RP |
4015 | |
4016 | @item directory | |
4017 | Reset the source path to empty again. This requires confirmation. | |
4018 | ||
4019 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 4020 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
4021 | |
4022 | @item show directories | |
4023 | @kindex show directories | |
4024 | Print the source path: show which directories it contains. | |
4025 | @end table | |
4026 | ||
4027 | If your source path is cluttered with directories that are no longer of | |
18fae2a8 | 4028 | interest, @value{GDBN} may sometimes cause confusion by finding the wrong |
70b88761 RP |
4029 | versions of source. You can correct the situation as follows: |
4030 | ||
4031 | @enumerate | |
4032 | @item | |
4033 | Use @code{directory} with no argument to reset the source path to empty. | |
4034 | ||
4035 | @item | |
4036 | Use @code{directory} with suitable arguments to reinstall the | |
4037 | directories you want in the source path. You can add all the | |
4038 | directories in one command. | |
4039 | @end enumerate | |
4040 | ||
4eb4cf57 | 4041 | @node Machine Code |
70b88761 | 4042 | @section Source and Machine Code |
1041a570 | 4043 | |
70b88761 | 4044 | You can use the command @code{info line} to map source lines to program |
ed447b95 | 4045 | addresses (and vice versa), and the command @code{disassemble} to display |
70b88761 RP |
4046 | a range of addresses as machine instructions. |
4047 | ||
4048 | @table @code | |
4049 | @item info line @var{linespec} | |
4050 | @kindex info line | |
4051 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
4052 | source line @var{linespec}. You can specify source lines in any of |
4053 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
4054 | Source Lines}). | |
70b88761 RP |
4055 | @end table |
4056 | ||
1041a570 RP |
4057 | For example, we can use @code{info line} to discover the location of |
4058 | the object code for the first line of function | |
4059 | @code{m4_changequote}: | |
4060 | ||
70b88761 | 4061 | @smallexample |
18fae2a8 | 4062 | (@value{GDBP}) info line m4_changecom |
70b88761 RP |
4063 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. |
4064 | @end smallexample | |
4065 | ||
4066 | @noindent | |
4067 | We can also inquire (using @code{*@var{addr}} as the form for | |
4068 | @var{linespec}) what source line covers a particular address: | |
4069 | @smallexample | |
18fae2a8 | 4070 | (@value{GDBP}) info line *0x63ff |
70b88761 RP |
4071 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. |
4072 | @end smallexample | |
4073 | ||
c338a2fd | 4074 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
4075 | After @code{info line}, the default address for the @code{x} command |
4076 | is changed to the starting address of the line, so that @samp{x/i} is | |
4077 | sufficient to begin examining the machine code (@pxref{Memory, | |
4078 | ,Examining Memory}). Also, this address is saved as the value of the | |
4079 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
4080 | Variables}). | |
70b88761 RP |
4081 | |
4082 | @table @code | |
4083 | @kindex disassemble | |
4084 | @item disassemble | |
e94b4a2b RP |
4085 | This specialized command dumps a range of memory as machine |
4086 | instructions. The default memory range is the function surrounding the | |
4087 | program counter of the selected frame. A single argument to this | |
4088 | command is a program counter value; the function surrounding this value | |
4089 | will be dumped. Two arguments specify a range of addresses (first | |
4090 | inclusive, second exclusive) to dump. | |
70b88761 RP |
4091 | @end table |
4092 | ||
18fae2a8 | 4093 | @ifclear HviiiEXCLUSIVE |
70b88761 | 4094 | We can use @code{disassemble} to inspect the object code |
4eb4cf57 RP |
4095 | range shown in the last @code{info line} example (the example |
4096 | shows SPARC machine instructions): | |
70b88761 | 4097 | |
18fae2a8 | 4098 | |
70b88761 | 4099 | @smallexample |
18fae2a8 | 4100 | (@value{GDBP}) disas 0x63e4 0x6404 |
70b88761 | 4101 | Dump of assembler code from 0x63e4 to 0x6404: |
b80282d5 RP |
4102 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
4103 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
4104 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
4105 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
4106 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
4107 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
4108 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 4109 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 4110 | End of assembler dump. |
70b88761 | 4111 | @end smallexample |
18fae2a8 | 4112 | @end ifclear |
4eb4cf57 | 4113 | |
18fae2a8 | 4114 | @ifset HviiiEXCLUSIVE |
4eb4cf57 RP |
4115 | For example, here is the beginning of the output for the |
4116 | disassembly of a function @code{fact}: | |
70b88761 | 4117 | |
18fae2a8 | 4118 | |
4eb4cf57 | 4119 | @smallexample |
18fae2a8 | 4120 | (@value{GDBP}) disas fact |
4eb4cf57 RP |
4121 | Dump of assembler code for function fact: |
4122 | to 0x808c: | |
4123 | 0x802c <fact>: 6d f2 mov.w r2,@@-r7 | |
4124 | 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7 | |
4125 | 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7 | |
4126 | 0x8032 <fact+6>: 0d 76 mov.w r7,r6 | |
4127 | 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0 | |
4128 | 0x8038 <fact+12> 19 11 sub.w r1,r1 | |
4129 | . | |
4130 | . | |
4131 | . | |
4132 | @end smallexample | |
18fae2a8 | 4133 | @end ifset |
4eb4cf57 RP |
4134 | |
4135 | @node Data | |
70b88761 RP |
4136 | @chapter Examining Data |
4137 | ||
4138 | @cindex printing data | |
4139 | @cindex examining data | |
4140 | @kindex print | |
4141 | @kindex inspect | |
1041a570 | 4142 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 4143 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
4144 | @c different window or something like that. |
4145 | The usual way to examine data in your program is with the @code{print} | |
4eb4cf57 | 4146 | command (abbreviated @code{p}), or its synonym @code{inspect}. |
18fae2a8 | 4147 | @ifclear CONLY |
4eb4cf57 | 4148 | It evaluates and prints the value of an expression of the language your |
18fae2a8 | 4149 | program is written in (@pxref{Languages, ,Using @value{GDBN} with Different |
4eb4cf57 | 4150 | Languages}). |
18fae2a8 | 4151 | @end ifclear |
70b88761 | 4152 | |
e0dacfd1 RP |
4153 | @table @code |
4154 | @item print @var{exp} | |
4155 | @itemx print /@var{f} @var{exp} | |
4156 | @var{exp} is an expression (in the source language). By default | |
70b88761 | 4157 | the value of @var{exp} is printed in a format appropriate to its data |
e0dacfd1 | 4158 | type; you can choose a different format by specifying @samp{/@var{f}}, |
ed447b95 | 4159 | where @var{f} is a letter specifying the format; @pxref{Output Formats}. |
e0dacfd1 RP |
4160 | |
4161 | @item print | |
4162 | @itemx print /@var{f} | |
18fae2a8 | 4163 | If you omit @var{exp}, @value{GDBN} displays the last value again (from the |
1041a570 | 4164 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to |
e0dacfd1 RP |
4165 | conveniently inspect the same value in an alternative format. |
4166 | @end table | |
70b88761 RP |
4167 | |
4168 | A more low-level way of examining data is with the @code{x} command. | |
4169 | It examines data in memory at a specified address and prints it in a | |
29a2b744 | 4170 | specified format. @xref{Memory, ,Examining Memory}. |
70b88761 | 4171 | |
29a2b744 | 4172 | If you are interested in information about types, or about how the fields |
b80282d5 | 4173 | of a struct or class are declared, use the @code{ptype @var{exp}} |
1041a570 | 4174 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 | 4175 | |
18fae2a8 RP |
4176 | @ignore |
4177 | @c pre-unfold | |
4178 | @menu | |
4179 | * Expressions:: Expressions | |
ed447b95 RP |
4180 | * Variables:: Program variables |
4181 | * Arrays:: Artificial arrays | |
18fae2a8 | 4182 | * Output formats:: Output formats |
ed447b95 RP |
4183 | * Memory:: Examining memory |
4184 | * Auto Display:: Automatic display | |
4185 | * Print Settings:: Print settings | |
4186 | * Value History:: Value history | |
4187 | * Convenience Vars:: Convenience variables | |
18fae2a8 RP |
4188 | * Registers:: Registers |
4189 | @ifclear HviiiEXCLUSIVE | |
ed447b95 | 4190 | * Floating Point Hardware:: Floating point hardware |
18fae2a8 RP |
4191 | @end ifclear |
4192 | @end menu | |
4193 | @end ignore | |
4194 | ||
4195 | @ifclear HviiiEXCLUSIVE | |
70b88761 | 4196 | @menu |
b80282d5 | 4197 | * Expressions:: Expressions |
ed447b95 RP |
4198 | * Variables:: Program variables |
4199 | * Arrays:: Artificial arrays | |
eb7faec1 | 4200 | * Output Formats:: Output formats |
ed447b95 RP |
4201 | * Memory:: Examining memory |
4202 | * Auto Display:: Automatic display | |
4203 | * Print Settings:: Print settings | |
4204 | * Value History:: Value history | |
4205 | * Convenience Vars:: Convenience variables | |
b80282d5 | 4206 | * Registers:: Registers |
ed447b95 | 4207 | * Floating Point Hardware:: Floating point hardware |
70b88761 | 4208 | @end menu |
18fae2a8 RP |
4209 | @end ifclear |
4210 | ||
4211 | @ifset HviiiEXCLUSIVE | |
4212 | @menu | |
4213 | * Expressions:: Expressions | |
ed447b95 RP |
4214 | * Variables:: Program variables |
4215 | * Arrays:: Artificial arrays | |
eb7faec1 | 4216 | * Output Formats:: Output formats |
ed447b95 RP |
4217 | * Memory:: Examining memory |
4218 | * Auto Display:: Automatic display | |
4219 | * Print Settings:: Print settings | |
4220 | * Value History:: Value history | |
4221 | * Convenience Vars:: Convenience variables | |
18fae2a8 RP |
4222 | * Registers:: Registers |
4223 | @end menu | |
4224 | @end ifset | |
70b88761 | 4225 | |
4eb4cf57 | 4226 | @node Expressions |
70b88761 RP |
4227 | @section Expressions |
4228 | ||
4229 | @cindex expressions | |
18fae2a8 | 4230 | @code{print} and many other @value{GDBN} commands accept an expression and |
70b88761 RP |
4231 | compute its value. Any kind of constant, variable or operator defined |
4232 | by the programming language you are using is legal in an expression in | |
18fae2a8 | 4233 | @value{GDBN}. This includes conditional expressions, function calls, casts |
70b88761 | 4234 | and string constants. It unfortunately does not include symbols defined |
b80282d5 | 4235 | by preprocessor @code{#define} commands. |
70b88761 | 4236 | |
18fae2a8 | 4237 | @ifclear CONLY |
c2bbbb22 | 4238 | Because C is so widespread, most of the expressions shown in examples in |
18fae2a8 | 4239 | this manual are in C. @xref{Languages, , Using @value{GDBN} with Different |
c2bbbb22 | 4240 | Languages}, for information on how to use expressions in other |
e251e767 | 4241 | languages. |
c2bbbb22 | 4242 | |
18fae2a8 | 4243 | In this section, we discuss operators that you can use in @value{GDBN} |
e251e767 | 4244 | expressions regardless of your programming language. |
c2bbbb22 | 4245 | |
70b88761 RP |
4246 | Casts are supported in all languages, not just in C, because it is so |
4247 | useful to cast a number into a pointer so as to examine a structure | |
4248 | at that address in memory. | |
c2bbbb22 | 4249 | @c FIXME: casts supported---Mod2 true? |
18fae2a8 | 4250 | @end ifclear |
70b88761 | 4251 | |
18fae2a8 | 4252 | @value{GDBN} supports these operators in addition to those of programming |
70b88761 RP |
4253 | languages: |
4254 | ||
4255 | @table @code | |
4256 | @item @@ | |
4257 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
1041a570 | 4258 | @xref{Arrays, ,Artificial Arrays}, for more information. |
70b88761 RP |
4259 | |
4260 | @item :: | |
4261 | @samp{::} allows you to specify a variable in terms of the file or | |
1041a570 | 4262 | function where it is defined. @xref{Variables, ,Program Variables}. |
70b88761 RP |
4263 | |
4264 | @item @{@var{type}@} @var{addr} | |
4265 | Refers to an object of type @var{type} stored at address @var{addr} in | |
4266 | memory. @var{addr} may be any expression whose value is an integer or | |
4267 | pointer (but parentheses are required around binary operators, just as in | |
4268 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 4269 | normally supposed to reside at @var{addr}. |
70b88761 RP |
4270 | @end table |
4271 | ||
4eb4cf57 | 4272 | @node Variables |
70b88761 RP |
4273 | @section Program Variables |
4274 | ||
4275 | The most common kind of expression to use is the name of a variable | |
4276 | in your program. | |
4277 | ||
4278 | Variables in expressions are understood in the selected stack frame | |
29a2b744 RP |
4279 | (@pxref{Selection, ,Selecting a Frame}); they must either be global |
4280 | (or static) or be visible according to the scope rules of the | |
4281 | programming language from the point of execution in that frame. This | |
4282 | means that in the function | |
70b88761 RP |
4283 | |
4284 | @example | |
4285 | foo (a) | |
4286 | int a; | |
4287 | @{ | |
4288 | bar (a); | |
4289 | @{ | |
4290 | int b = test (); | |
4291 | bar (b); | |
4292 | @} | |
4293 | @} | |
4294 | @end example | |
4295 | ||
4296 | @noindent | |
ed447b95 RP |
4297 | you can examine and use the variable @code{a} whenever your program is |
4298 | executing within the function @code{foo}, but you can only use or | |
4299 | examine the variable @code{b} while your program is executing inside | |
4300 | the block where @code{b} is declared. | |
70b88761 RP |
4301 | |
4302 | @cindex variable name conflict | |
4303 | There is an exception: you can refer to a variable or function whose | |
4304 | scope is a single source file even if the current execution point is not | |
4305 | in this file. But it is possible to have more than one such variable or | |
6ca72cc6 RP |
4306 | function with the same name (in different source files). If that |
4307 | happens, referring to that name has unpredictable effects. If you wish, | |
4308 | you can specify a static variable in a particular function or file, | |
4309 | using the colon-colon notation: | |
70b88761 RP |
4310 | |
4311 | @cindex colon-colon | |
a6d0b6d3 | 4312 | @iftex |
29a2b744 | 4313 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 4314 | @kindex :: |
a6d0b6d3 | 4315 | @end iftex |
70b88761 RP |
4316 | @example |
4317 | @var{file}::@var{variable} | |
6ca72cc6 | 4318 | @var{function}::@var{variable} |
70b88761 RP |
4319 | @end example |
4320 | ||
4321 | @noindent | |
6ca72cc6 | 4322 | Here @var{file} or @var{function} is the name of the context for the |
6c380b13 | 4323 | static @var{variable}. In the case of file names, you can use quotes to |
18fae2a8 | 4324 | make sure @value{GDBN} parses the file name as a single word---for example, |
6c380b13 RP |
4325 | to print a global value of @code{x} defined in @file{f2.c}: |
4326 | ||
4327 | @example | |
18fae2a8 | 4328 | (@value{GDBP}) p 'f2.c'::x |
6c380b13 | 4329 | @end example |
70b88761 | 4330 | |
18fae2a8 | 4331 | @ifclear CONLY |
c2bbbb22 | 4332 | @cindex C++ scope resolution |
70b88761 | 4333 | This use of @samp{::} is very rarely in conflict with the very similar |
18fae2a8 RP |
4334 | use of the same notation in C++. @value{GDBN} also supports use of the C++ |
4335 | scope resolution operator in @value{GDBN} expressions. | |
ed447b95 RP |
4336 | @c FIXME: Um, so what happens in one of those rare cases where it's in |
4337 | @c conflict?? --mew | |
18fae2a8 | 4338 | @end ifclear |
70b88761 | 4339 | |
3d3ab540 RP |
4340 | @cindex wrong values |
4341 | @cindex variable values, wrong | |
4342 | @quotation | |
4343 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
4344 | wrong value at certain points in a function---just after entry to the | |
29a2b744 | 4345 | function, and just before exit. You may see this problem when you are |
3d3ab540 RP |
4346 | stepping by machine instructions. This is because on most machines, it |
4347 | takes more than one instruction to set up a stack frame (including local | |
29a2b744 | 4348 | variable definitions); if you are stepping by machine instructions, |
3d3ab540 RP |
4349 | variables may appear to have the wrong values until the stack frame is |
4350 | completely built. On function exit, it usually also takes more than one | |
4351 | machine instruction to destroy a stack frame; after you begin stepping | |
4352 | through that group of instructions, local variable definitions may be | |
4353 | gone. | |
4354 | @end quotation | |
4355 | ||
4eb4cf57 | 4356 | @node Arrays |
70b88761 RP |
4357 | @section Artificial Arrays |
4358 | ||
4359 | @cindex artificial array | |
4360 | @kindex @@ | |
4361 | It is often useful to print out several successive objects of the | |
4362 | same type in memory; a section of an array, or an array of | |
4363 | dynamically determined size for which only a pointer exists in the | |
4364 | program. | |
4365 | ||
4366 | This can be done by constructing an @dfn{artificial array} with the | |
4367 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
4368 | the first element of the desired array, as an individual object. | |
4369 | The right operand should be the desired length of the array. The result is | |
4370 | an array value whose elements are all of the type of the left argument. | |
4371 | The first element is actually the left argument; the second element | |
4372 | comes from bytes of memory immediately following those that hold the | |
4373 | first element, and so on. Here is an example. If a program says | |
4374 | ||
4375 | @example | |
4376 | int *array = (int *) malloc (len * sizeof (int)); | |
4377 | @end example | |
4378 | ||
4379 | @noindent | |
4380 | you can print the contents of @code{array} with | |
4381 | ||
4382 | @example | |
4383 | p *array@@len | |
4384 | @end example | |
4385 | ||
4386 | The left operand of @samp{@@} must reside in memory. Array values made | |
4387 | with @samp{@@} in this way behave just like other arrays in terms of | |
4388 | subscripting, and are coerced to pointers when used in expressions. | |
4389 | Artificial arrays most often appear in expressions via the value history | |
1041a570 | 4390 | (@pxref{Value History, ,Value History}), after printing one out.) |
70b88761 | 4391 | |
1041a570 | 4392 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 4393 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
4394 | actually be adjacent---for example, if you are interested in the values |
4395 | of pointers in an array. One useful work-around in this situation is | |
4396 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
4397 | Variables}) as a counter in an expression that prints the first | |
4398 | interesting value, and then repeat that expression via @key{RET}. For | |
4399 | instance, suppose you have an array @code{dtab} of pointers to | |
4400 | structures, and you are interested in the values of a field @code{fv} | |
4401 | in each structure. Here is an example of what you might type: | |
4402 | ||
3d3ab540 RP |
4403 | @example |
4404 | set $i = 0 | |
4405 | p dtab[$i++]->fv | |
4406 | @key{RET} | |
4407 | @key{RET} | |
4408 | @dots{} | |
4409 | @end example | |
4410 | ||
ed447b95 | 4411 | @node Output Formats |
70b88761 RP |
4412 | @section Output formats |
4413 | ||
4414 | @cindex formatted output | |
4415 | @cindex output formats | |
18fae2a8 | 4416 | By default, @value{GDBN} prints a value according to its data type. Sometimes |
70b88761 RP |
4417 | this is not what you want. For example, you might want to print a number |
4418 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
4419 | at a certain address as a character string or as an instruction. To do | |
4420 | these things, specify an @dfn{output format} when you print a value. | |
4421 | ||
4422 | The simplest use of output formats is to say how to print a value | |
4423 | already computed. This is done by starting the arguments of the | |
4424 | @code{print} command with a slash and a format letter. The format | |
4425 | letters supported are: | |
4426 | ||
4427 | @table @code | |
4428 | @item x | |
4429 | Regard the bits of the value as an integer, and print the integer in | |
4430 | hexadecimal. | |
4431 | ||
4432 | @item d | |
4433 | Print as integer in signed decimal. | |
4434 | ||
4435 | @item u | |
4436 | Print as integer in unsigned decimal. | |
4437 | ||
4438 | @item o | |
4439 | Print as integer in octal. | |
4440 | ||
4441 | @item t | |
4442 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
4443 | ||
4444 | @item a | |
4445 | Print as an address, both absolute in hex and as an offset from the | |
4446 | nearest preceding symbol. This format can be used to discover where (in | |
4447 | what function) an unknown address is located: | |
1041a570 | 4448 | |
70b88761 | 4449 | @example |
18fae2a8 RP |
4450 | (@value{GDBP}) p/a 0x54320 |
4451 | $3 = 0x54320 <_initialize_vx+396> | |
70b88761 RP |
4452 | @end example |
4453 | ||
70b88761 RP |
4454 | @item c |
4455 | Regard as an integer and print it as a character constant. | |
4456 | ||
4457 | @item f | |
4458 | Regard the bits of the value as a floating point number and print | |
4459 | using typical floating point syntax. | |
4460 | @end table | |
4461 | ||
4462 | For example, to print the program counter in hex (@pxref{Registers}), type | |
4463 | ||
4464 | @example | |
4465 | p/x $pc | |
4466 | @end example | |
4467 | ||
4468 | @noindent | |
4469 | Note that no space is required before the slash; this is because command | |
18fae2a8 | 4470 | names in @value{GDBN} cannot contain a slash. |
70b88761 RP |
4471 | |
4472 | To reprint the last value in the value history with a different format, | |
4473 | you can use the @code{print} command with just a format and no | |
4474 | expression. For example, @samp{p/x} reprints the last value in hex. | |
4475 | ||
4eb4cf57 | 4476 | @node Memory |
70b88761 RP |
4477 | @section Examining Memory |
4478 | ||
1041a570 RP |
4479 | You can use the command @code{x} (for ``examine'') to examine memory in |
4480 | any of several formats, independently of your program's data types. | |
4481 | ||
70b88761 RP |
4482 | @cindex examining memory |
4483 | @table @code | |
4484 | @kindex x | |
cedaf8bc RP |
4485 | @item x/@var{nfu} @var{addr} |
4486 | @itemx x @var{addr} | |
4487 | @itemx x | |
ed447b95 | 4488 | Use the @code{x} command to examine memory. |
1041a570 RP |
4489 | @end table |
4490 | ||
4491 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
4492 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
4493 | expression giving the address where you want to start displaying memory. |
4494 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
4495 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 4496 | |
1041a570 RP |
4497 | @table @r |
4498 | @item @var{n}, the repeat count | |
4499 | The repeat count is a decimal integer; the default is 1. It specifies | |
4500 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
4501 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
4502 | @c 4.1.2. | |
70b88761 | 4503 | |
1041a570 RP |
4504 | @item @var{f}, the display format |
4505 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
4506 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
4507 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
4508 | last time you used either @code{x} or @code{print}. | |
70b88761 | 4509 | |
1041a570 RP |
4510 | @item @var{u}, the unit size |
4511 | The unit size is any of | |
ed447b95 | 4512 | |
70b88761 RP |
4513 | @table @code |
4514 | @item b | |
cedaf8bc | 4515 | Bytes. |
70b88761 | 4516 | @item h |
cedaf8bc | 4517 | Halfwords (two bytes). |
70b88761 | 4518 | @item w |
cedaf8bc | 4519 | Words (four bytes). This is the initial default. |
70b88761 | 4520 | @item g |
cedaf8bc | 4521 | Giant words (eight bytes). |
70b88761 RP |
4522 | @end table |
4523 | ||
cedaf8bc RP |
4524 | Each time you specify a unit size with @code{x}, that size becomes the |
4525 | default unit the next time you use @code{x}. (For the @samp{s} and | |
4526 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
4527 | ||
1041a570 | 4528 | @item @var{addr}, starting display address |
18fae2a8 | 4529 | @var{addr} is the address where you want @value{GDBN} to begin displaying |
cedaf8bc RP |
4530 | memory. The expression need not have a pointer value (though it may); |
4531 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 4532 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
4533 | @var{addr} is usually just after the last address examined---but several |
4534 | other commands also set the default address: @code{info breakpoints} (to | |
4535 | the address of the last breakpoint listed), @code{info line} (to the | |
4536 | starting address of a line), and @code{print} (if you use it to display | |
4537 | a value from memory). | |
1041a570 | 4538 | @end table |
70b88761 | 4539 | |
cedaf8bc RP |
4540 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
4541 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
4542 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
4543 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
4544 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 4545 | |
cedaf8bc | 4546 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 4547 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
4548 | unit size or format comes first; either order will work. The output |
4549 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
4550 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
4551 | ||
4552 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
4553 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
4554 | @samp{3i} specifies that you want to see three machine instructions, | |
4555 | including any operands. The command @code{disassemble} gives an | |
4556 | alternative way of inspecting machine instructions; @pxref{Machine | |
4557 | Code}. | |
4558 | ||
4559 | All the defaults for the arguments to @code{x} are designed to make it | |
4560 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 4561 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
4562 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
4563 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
4564 | the repeat count @var{n} is used again; the other arguments default as | |
4565 | for successive uses of @code{x}. | |
70b88761 | 4566 | |
c338a2fd | 4567 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 4568 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 | 4569 | in the value history because there is often too much of them and they |
18fae2a8 | 4570 | would get in the way. Instead, @value{GDBN} makes these values available for |
70b88761 RP |
4571 | subsequent use in expressions as values of the convenience variables |
4572 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
4573 | examined is available for use in expressions in the convenience variable | |
4574 | @code{$_}. The contents of that address, as examined, are available in | |
4575 | the convenience variable @code{$__}. | |
4576 | ||
4577 | If the @code{x} command has a repeat count, the address and contents saved | |
4578 | are from the last memory unit printed; this is not the same as the last | |
4579 | address printed if several units were printed on the last line of output. | |
4580 | ||
4eb4cf57 | 4581 | @node Auto Display |
70b88761 RP |
4582 | @section Automatic Display |
4583 | @cindex automatic display | |
4584 | @cindex display of expressions | |
4585 | ||
4586 | If you find that you want to print the value of an expression frequently | |
4587 | (to see how it changes), you might want to add it to the @dfn{automatic | |
18fae2a8 | 4588 | display list} so that @value{GDBN} will print its value each time your program stops. |
70b88761 RP |
4589 | Each expression added to the list is given a number to identify it; |
4590 | to remove an expression from the list, you specify that number. | |
4591 | The automatic display looks like this: | |
4592 | ||
4593 | @example | |
4594 | 2: foo = 38 | |
4595 | 3: bar[5] = (struct hack *) 0x3804 | |
4596 | @end example | |
4597 | ||
4598 | @noindent | |
ed447b95 | 4599 | This display shows item numbers, expressions and their current values. As with |
70b88761 RP |
4600 | displays you request manually using @code{x} or @code{print}, you can |
4601 | specify the output format you prefer; in fact, @code{display} decides | |
4602 | whether to use @code{print} or @code{x} depending on how elaborate your | |
4603 | format specification is---it uses @code{x} if you specify a unit size, | |
4604 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
4605 | supported by @code{x}; otherwise it uses @code{print}. | |
4606 | ||
4607 | @table @code | |
4608 | @item display @var{exp} | |
4609 | @kindex display | |
4610 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 4611 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
4612 | |
4613 | @code{display} will not repeat if you press @key{RET} again after using it. | |
4614 | ||
4615 | @item display/@var{fmt} @var{exp} | |
4616 | For @var{fmt} specifying only a display format and not a size or | |
4617 | count, add the expression @var{exp} to the auto-display list but | |
4618 | arranges to display it each time in the specified format @var{fmt}. | |
ed447b95 | 4619 | @xref{Output Formats,,Output formats}. |
70b88761 RP |
4620 | |
4621 | @item display/@var{fmt} @var{addr} | |
4622 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
4623 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 RP |
4624 | be examined each time your program stops. Examining means in effect |
4625 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
70b88761 RP |
4626 | @end table |
4627 | ||
4628 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
4629 | instruction about to be executed each time execution stops (@samp{$pc} | |
4630 | is a common name for the program counter; @pxref{Registers}). | |
4631 | ||
4632 | @table @code | |
4633 | @item undisplay @var{dnums}@dots{} | |
4634 | @itemx delete display @var{dnums}@dots{} | |
4635 | @kindex delete display | |
4636 | @kindex undisplay | |
4637 | Remove item numbers @var{dnums} from the list of expressions to display. | |
4638 | ||
4639 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
4640 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
4641 | ||
4642 | @item disable display @var{dnums}@dots{} | |
4643 | @kindex disable display | |
4644 | Disable the display of item numbers @var{dnums}. A disabled display | |
4645 | item is not printed automatically, but is not forgotten. It may be | |
4646 | enabled again later. | |
4647 | ||
4648 | @item enable display @var{dnums}@dots{} | |
4649 | @kindex enable display | |
4650 | Enable display of item numbers @var{dnums}. It becomes effective once | |
4651 | again in auto display of its expression, until you specify otherwise. | |
4652 | ||
4653 | @item display | |
4654 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 4655 | done when your program stops. |
70b88761 RP |
4656 | |
4657 | @item info display | |
4658 | @kindex info display | |
4659 | Print the list of expressions previously set up to display | |
4660 | automatically, each one with its item number, but without showing the | |
4661 | values. This includes disabled expressions, which are marked as such. | |
4662 | It also includes expressions which would not be displayed right now | |
4663 | because they refer to automatic variables not currently available. | |
4664 | @end table | |
4665 | ||
4666 | If a display expression refers to local variables, then it does not make | |
4667 | sense outside the lexical context for which it was set up. Such an | |
4668 | expression is disabled when execution enters a context where one of its | |
4669 | variables is not defined. For example, if you give the command | |
4670 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 4671 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
4672 | continues to stop inside that function. When it stops elsewhere---where |
4673 | there is no variable @code{last_char}---display is disabled. The next time | |
4674 | your program stops where @code{last_char} is meaningful, you can enable the | |
4675 | display expression once again. | |
4676 | ||
4eb4cf57 | 4677 | @node Print Settings |
70b88761 RP |
4678 | @section Print Settings |
4679 | ||
4680 | @cindex format options | |
4681 | @cindex print settings | |
18fae2a8 | 4682 | @value{GDBN} provides the following ways to control how arrays, structures, |
e251e767 | 4683 | and symbols are printed. |
70b88761 RP |
4684 | |
4685 | @noindent | |
4686 | These settings are useful for debugging programs in any language: | |
4687 | ||
4688 | @table @code | |
4689 | @item set print address | |
4690 | @item set print address on | |
4691 | @kindex set print address | |
18fae2a8 | 4692 | @value{GDBN} will print memory addresses showing the location of stack |
70b88761 RP |
4693 | traces, structure values, pointer values, breakpoints, and so forth, |
4694 | even when it also displays the contents of those addresses. The default | |
4695 | is on. For example, this is what a stack frame display looks like, with | |
4696 | @code{set print address on}: | |
1041a570 | 4697 | |
70b88761 | 4698 | @smallexample |
1041a570 | 4699 | @group |
18fae2a8 | 4700 | (@value{GDBP}) f |
e251e767 | 4701 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 4702 | at input.c:530 |
b80282d5 | 4703 | 530 if (lquote != def_lquote) |
1041a570 | 4704 | @end group |
70b88761 RP |
4705 | @end smallexample |
4706 | ||
4707 | @item set print address off | |
4708 | Do not print addresses when displaying their contents. For example, | |
4709 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 4710 | |
70b88761 | 4711 | @example |
1041a570 | 4712 | @group |
18fae2a8 RP |
4713 | (@value{GDBP}) set print addr off |
4714 | (@value{GDBP}) f | |
70b88761 | 4715 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 |
b80282d5 | 4716 | 530 if (lquote != def_lquote) |
1041a570 | 4717 | @end group |
70b88761 RP |
4718 | @end example |
4719 | ||
4720 | @item show print address | |
4721 | @kindex show print address | |
4722 | Show whether or not addresses are to be printed. | |
4723 | ||
4724 | @item set print array | |
4725 | @itemx set print array on | |
4726 | @kindex set print array | |
18fae2a8 | 4727 | @value{GDBN} will pretty print arrays. This format is more convenient to read, |
70b88761 RP |
4728 | but uses more space. The default is off. |
4729 | ||
4730 | @item set print array off. | |
4731 | Return to compressed format for arrays. | |
4732 | ||
4733 | @item show print array | |
4734 | @kindex show print array | |
4735 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 4736 | arrays. |
70b88761 RP |
4737 | |
4738 | @item set print elements @var{number-of-elements} | |
4739 | @kindex set print elements | |
18fae2a8 | 4740 | If @value{GDBN} is printing a large array, it will stop printing after it has |
70b88761 RP |
4741 | printed the number of elements set by the @code{set print elements} command. |
4742 | This limit also applies to the display of strings. | |
4743 | ||
4744 | @item show print elements | |
4745 | @kindex show print elements | |
18fae2a8 | 4746 | Display the number of elements of a large array that @value{GDBN} will print |
70b88761 RP |
4747 | before losing patience. |
4748 | ||
4749 | @item set print pretty on | |
4750 | @kindex set print pretty | |
18fae2a8 | 4751 | Cause @value{GDBN} to print structures in an indented format with one member per |
70b88761 RP |
4752 | line, like this: |
4753 | ||
4754 | @example | |
1041a570 | 4755 | @group |
70b88761 RP |
4756 | $1 = @{ |
4757 | next = 0x0, | |
4758 | flags = @{ | |
4759 | sweet = 1, | |
4760 | sour = 1 | |
4761 | @}, | |
4762 | meat = 0x54 "Pork" | |
4763 | @} | |
1041a570 | 4764 | @end group |
70b88761 RP |
4765 | @end example |
4766 | ||
4767 | @item set print pretty off | |
18fae2a8 | 4768 | Cause @value{GDBN} to print structures in a compact format, like this: |
70b88761 RP |
4769 | |
4770 | @smallexample | |
1041a570 | 4771 | @group |
38962738 RP |
4772 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \ |
4773 | meat = 0x54 "Pork"@} | |
1041a570 | 4774 | @end group |
70b88761 RP |
4775 | @end smallexample |
4776 | ||
4777 | @noindent | |
4778 | This is the default format. | |
4779 | ||
4780 | @item show print pretty | |
4781 | @kindex show print pretty | |
18fae2a8 | 4782 | Show which format @value{GDBN} will use to print structures. |
70b88761 RP |
4783 | |
4784 | @item set print sevenbit-strings on | |
f2857bd9 | 4785 | @kindex set print sevenbit-strings |
e251e767 | 4786 | Print using only seven-bit characters; if this option is set, |
18fae2a8 | 4787 | @value{GDBN} will display any eight-bit characters (in strings or character |
70b88761 RP |
4788 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is |
4789 | displayed as @code{\341}. | |
4790 | ||
4791 | @item set print sevenbit-strings off | |
4792 | Print using either seven-bit or eight-bit characters, as required. This | |
4793 | is the default. | |
4794 | ||
4795 | @item show print sevenbit-strings | |
f2857bd9 | 4796 | @kindex show print sevenbit-strings |
18fae2a8 | 4797 | Show whether or not @value{GDBN} will print only seven-bit characters. |
70b88761 RP |
4798 | |
4799 | @item set print union on | |
4800 | @kindex set print union | |
18fae2a8 | 4801 | Tell @value{GDBN} to print unions which are contained in structures. This is the |
70b88761 RP |
4802 | default setting. |
4803 | ||
4804 | @item set print union off | |
18fae2a8 | 4805 | Tell @value{GDBN} not to print unions which are contained in structures. |
70b88761 RP |
4806 | |
4807 | @item show print union | |
4808 | @kindex show print union | |
18fae2a8 | 4809 | Ask @value{GDBN} whether or not it will print unions which are contained in |
e251e767 | 4810 | structures. |
70b88761 RP |
4811 | |
4812 | For example, given the declarations | |
4813 | ||
4814 | @smallexample | |
4815 | typedef enum @{Tree, Bug@} Species; | |
4816 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
4817 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
4818 | Bug_forms; | |
70b88761 RP |
4819 | |
4820 | struct thing @{ | |
4821 | Species it; | |
4822 | union @{ | |
4823 | Tree_forms tree; | |
4824 | Bug_forms bug; | |
4825 | @} form; | |
4826 | @}; | |
4827 | ||
4828 | struct thing foo = @{Tree, @{Acorn@}@}; | |
4829 | @end smallexample | |
4830 | ||
4831 | @noindent | |
4832 | with @code{set print union on} in effect @samp{p foo} would print | |
4833 | ||
4834 | @smallexample | |
4835 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
4836 | @end smallexample | |
4837 | ||
4838 | @noindent | |
4839 | and with @code{set print union off} in effect it would print | |
4840 | ||
4841 | @smallexample | |
4842 | $1 = @{it = Tree, form = @{...@}@} | |
4843 | @end smallexample | |
4844 | @end table | |
4845 | ||
4846 | @noindent | |
4847 | These settings are of interest when debugging C++ programs: | |
4848 | ||
4849 | @table @code | |
e251e767 RP |
4850 | @item set print demangle |
4851 | @itemx set print demangle on | |
70b88761 RP |
4852 | @kindex set print demangle |
4853 | Print C++ names in their source form rather than in the mangled form | |
4854 | in which they are passed to the assembler and linker for type-safe linkage. | |
4855 | The default is on. | |
4856 | ||
4857 | @item show print demangle | |
4858 | @kindex show print demangle | |
4859 | Show whether C++ names will be printed in mangled or demangled form. | |
4860 | ||
e251e767 RP |
4861 | @item set print asm-demangle |
4862 | @itemx set print asm-demangle on | |
70b88761 RP |
4863 | @kindex set print asm-demangle |
4864 | Print C++ names in their source form rather than their mangled form, even | |
4865 | in assembler code printouts such as instruction disassemblies. | |
4866 | The default is off. | |
4867 | ||
4868 | @item show print asm-demangle | |
4869 | @kindex show print asm-demangle | |
4870 | Show whether C++ names in assembly listings will be printed in mangled | |
4871 | or demangled form. | |
4872 | ||
4873 | @item set print object | |
4874 | @itemx set print object on | |
4875 | @kindex set print object | |
4876 | When displaying a pointer to an object, identify the @emph{actual} | |
4877 | (derived) type of the object rather than the @emph{declared} type, using | |
4878 | the virtual function table. | |
4879 | ||
4880 | @item set print object off | |
4881 | Display only the declared type of objects, without reference to the | |
4882 | virtual function table. This is the default setting. | |
4883 | ||
4884 | @item show print object | |
4885 | @kindex show print object | |
4886 | Show whether actual, or declared, object types will be displayed. | |
4887 | ||
e251e767 RP |
4888 | @item set print vtbl |
4889 | @itemx set print vtbl on | |
70b88761 RP |
4890 | @kindex set print vtbl |
4891 | Pretty print C++ virtual function tables. The default is off. | |
4892 | ||
4893 | @item set print vtbl off | |
4894 | Do not pretty print C++ virtual function tables. | |
4895 | ||
4896 | @item show print vtbl | |
4897 | @kindex show print vtbl | |
4898 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 RP |
4899 | @end table |
4900 | ||
4eb4cf57 | 4901 | @node Value History |
70b88761 RP |
4902 | @section Value History |
4903 | ||
4904 | @cindex value history | |
93918348 | 4905 | Values printed by the @code{print} command are saved in the @value{GDBN} @dfn{value |
70b88761 RP |
4906 | history} so that you can refer to them in other expressions. Values are |
4907 | kept until the symbol table is re-read or discarded (for example with | |
4908 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
4909 | changes, the value history is discarded, since the values may contain | |
4910 | pointers back to the types defined in the symbol table. | |
4911 | ||
4912 | @cindex @code{$} | |
4913 | @cindex @code{$$} | |
4914 | @cindex history number | |
4915 | The values printed are given @dfn{history numbers} for you to refer to them | |
4916 | by. These are successive integers starting with one. @code{print} shows you | |
4917 | the history number assigned to a value by printing @samp{$@var{num} = } | |
4918 | before the value; here @var{num} is the history number. | |
4919 | ||
4920 | To refer to any previous value, use @samp{$} followed by the value's | |
4921 | history number. The way @code{print} labels its output is designed to | |
4922 | remind you of this. Just @code{$} refers to the most recent value in | |
4923 | the history, and @code{$$} refers to the value before that. | |
4924 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
4925 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
4926 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
4927 | ||
4928 | For example, suppose you have just printed a pointer to a structure and | |
4929 | want to see the contents of the structure. It suffices to type | |
4930 | ||
4931 | @example | |
4932 | p *$ | |
4933 | @end example | |
4934 | ||
4935 | If you have a chain of structures where the component @code{next} points | |
4936 | to the next one, you can print the contents of the next one with this: | |
4937 | ||
4938 | @example | |
4939 | p *$.next | |
4940 | @end example | |
4941 | ||
4942 | @noindent | |
4943 | You can print successive links in the chain by repeating this | |
4944 | command---which you can do by just typing @key{RET}. | |
4945 | ||
4946 | Note that the history records values, not expressions. If the value of | |
4947 | @code{x} is 4 and you type these commands: | |
4948 | ||
4949 | @example | |
4950 | print x | |
4951 | set x=5 | |
4952 | @end example | |
4953 | ||
4954 | @noindent | |
4955 | then the value recorded in the value history by the @code{print} command | |
4956 | remains 4 even though the value of @code{x} has changed. | |
4957 | ||
4958 | @table @code | |
4959 | @kindex show values | |
4960 | @item show values | |
4961 | Print the last ten values in the value history, with their item numbers. | |
4962 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
4963 | values} does not change the history. | |
4964 | ||
4965 | @item show values @var{n} | |
4966 | Print ten history values centered on history item number @var{n}. | |
4967 | ||
4968 | @item show values + | |
4969 | Print ten history values just after the values last printed. If no more | |
4970 | values are available, produces no display. | |
4971 | @end table | |
4972 | ||
4973 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 4974 | same effect as @samp{show values +}. |
70b88761 | 4975 | |
4eb4cf57 | 4976 | @node Convenience Vars |
70b88761 RP |
4977 | @section Convenience Variables |
4978 | ||
4979 | @cindex convenience variables | |
18fae2a8 RP |
4980 | @value{GDBN} provides @dfn{convenience variables} that you can use within |
4981 | @value{GDBN} to hold on to a value and refer to it later. These variables | |
4982 | exist entirely within @value{GDBN}; they are not part of your program, and | |
70b88761 | 4983 | setting a convenience variable has no direct effect on further execution |
1041a570 | 4984 | of your program. That is why you can use them freely. |
70b88761 RP |
4985 | |
4986 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
4987 | @samp{$} can be used for a convenience variable, unless it is one of | |
4988 | the predefined machine-specific register names (@pxref{Registers}). | |
4989 | (Value history references, in contrast, are @emph{numbers} preceded | |
1041a570 | 4990 | by @samp{$}. @xref{Value History, ,Value History}.) |
70b88761 RP |
4991 | |
4992 | You can save a value in a convenience variable with an assignment | |
ed447b95 RP |
4993 | expression, just as you would set a variable in your program. |
4994 | For example: | |
70b88761 RP |
4995 | |
4996 | @example | |
4997 | set $foo = *object_ptr | |
4998 | @end example | |
4999 | ||
5000 | @noindent | |
5001 | would save in @code{$foo} the value contained in the object pointed to by | |
5002 | @code{object_ptr}. | |
5003 | ||
5004 | Using a convenience variable for the first time creates it; but its value | |
5005 | is @code{void} until you assign a new value. You can alter the value with | |
5006 | another assignment at any time. | |
5007 | ||
5008 | Convenience variables have no fixed types. You can assign a convenience | |
5009 | variable any type of value, including structures and arrays, even if | |
5010 | that variable already has a value of a different type. The convenience | |
5011 | variable, when used as an expression, has the type of its current value. | |
5012 | ||
5013 | @table @code | |
5014 | @item show convenience | |
5015 | @kindex show convenience | |
5016 | Print a list of convenience variables used so far, and their values. | |
5017 | Abbreviated @code{show con}. | |
5018 | @end table | |
5019 | ||
5020 | One of the ways to use a convenience variable is as a counter to be | |
5021 | incremented or a pointer to be advanced. For example, to print | |
5022 | a field from successive elements of an array of structures: | |
5023 | ||
18fae2a8 | 5024 | @example |
70b88761 RP |
5025 | set $i = 0 |
5026 | print bar[$i++]->contents | |
5027 | @i{@dots{} repeat that command by typing @key{RET}.} | |
18fae2a8 | 5028 | @end example |
70b88761 | 5029 | |
18fae2a8 | 5030 | Some convenience variables are created automatically by @value{GDBN} and given |
70b88761 RP |
5031 | values likely to be useful. |
5032 | ||
5033 | @table @code | |
5034 | @item $_ | |
c338a2fd | 5035 | @kindex $_ |
70b88761 | 5036 | The variable @code{$_} is automatically set by the @code{x} command to |
29a2b744 RP |
5037 | the last address examined (@pxref{Memory, ,Examining Memory}). Other |
5038 | commands which provide a default address for @code{x} to examine also | |
5039 | set @code{$_} to that address; these commands include @code{info line} | |
5040 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
5041 | except when set by the @code{x} command, in which case it is a pointer | |
5042 | to the type of @code{$__}. | |
70b88761 RP |
5043 | |
5044 | @item $__ | |
c338a2fd | 5045 | @kindex $__ |
70b88761 | 5046 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
5047 | to the value found in the last address examined. Its type is chosen |
5048 | to match the format in which the data was printed. | |
70b88761 RP |
5049 | @end table |
5050 | ||
4eb4cf57 | 5051 | @node Registers |
70b88761 RP |
5052 | @section Registers |
5053 | ||
5054 | @cindex registers | |
b80282d5 | 5055 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
5056 | with names starting with @samp{$}. The names of registers are different |
5057 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 5058 | your machine. |
70b88761 RP |
5059 | |
5060 | @table @code | |
5061 | @item info registers | |
5062 | @kindex info registers | |
b80282d5 RP |
5063 | Print the names and values of all registers except floating-point |
5064 | registers (in the selected stack frame). | |
5065 | ||
5066 | @item info all-registers | |
5067 | @kindex info all-registers | |
5068 | @cindex floating point registers | |
5069 | Print the names and values of all registers, including floating-point | |
5070 | registers. | |
70b88761 | 5071 | |
4eb4cf57 | 5072 | @item info registers @var{regname} @dots{} |
0d1cd01e JG |
5073 | Print the relativized value of each specified register @var{regname}. |
5074 | @var{regname} may be any register name valid on the machine you are using, with | |
70b88761 RP |
5075 | or without the initial @samp{$}. |
5076 | @end table | |
5077 | ||
18fae2a8 | 5078 | @value{GDBN} has four ``standard'' register names that are available (in |
29a2b744 | 5079 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
5080 | architecture's canonical mnemonics for registers. The register names |
5081 | @code{$pc} and @code{$sp} are used for the program counter register and | |
5082 | the stack pointer. @code{$fp} is used for a register that contains a | |
5083 | pointer to the current stack frame, and @code{$ps} is used for a | |
5084 | register that contains the processor status. For example, | |
70b88761 | 5085 | you could print the program counter in hex with |
1041a570 | 5086 | |
70b88761 RP |
5087 | @example |
5088 | p/x $pc | |
5089 | @end example | |
5090 | ||
5091 | @noindent | |
5092 | or print the instruction to be executed next with | |
1041a570 | 5093 | |
70b88761 RP |
5094 | @example |
5095 | x/i $pc | |
5096 | @end example | |
5097 | ||
5098 | @noindent | |
ed447b95 | 5099 | or add four to the stack pointer@footnote{This is a way of removing |
29a2b744 RP |
5100 | one word from the stack, on machines where stacks grow downward in |
5101 | memory (most machines, nowadays). This assumes that the innermost | |
5102 | stack frame is selected; setting @code{$sp} is not allowed when other | |
5103 | stack frames are selected. To pop entire frames off the stack, | |
5104 | regardless of machine architecture, use @code{return}; | |
1041a570 RP |
5105 | @pxref{Returning, ,Returning from a Function}.} with |
5106 | ||
70b88761 RP |
5107 | @example |
5108 | set $sp += 4 | |
5109 | @end example | |
5110 | ||
09267865 RP |
5111 | Whenever possible, these four standard register names are available on |
5112 | your machine even though the machine has different canonical mnemonics, | |
5113 | so long as there is no conflict. The @code{info registers} command | |
5114 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
5115 | registers} displays the processor status register as @code{$psr} but you |
5116 | can also refer to it as @code{$ps}. | |
5117 | ||
18fae2a8 | 5118 | @value{GDBN} always considers the contents of an ordinary register as an |
70b88761 RP |
5119 | integer when the register is examined in this way. Some machines have |
5120 | special registers which can hold nothing but floating point; these | |
5121 | registers are considered to have floating point values. There is no way | |
5122 | to refer to the contents of an ordinary register as floating point value | |
5123 | (although you can @emph{print} it as a floating point value with | |
5124 | @samp{print/f $@var{regname}}). | |
5125 | ||
5126 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
5127 | means that the data format in which the register contents are saved by | |
5128 | the operating system is not the same one that your program normally | |
5129 | sees. For example, the registers of the 68881 floating point | |
5130 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
5131 | programs expect to work with ``double'' (virtual) format. In such | |
18fae2a8 | 5132 | cases, @value{GDBN} normally works with the virtual format only (the format that |
70b88761 RP |
5133 | makes sense for your program), but the @code{info registers} command |
5134 | prints the data in both formats. | |
5135 | ||
5136 | Normally, register values are relative to the selected stack frame | |
29a2b744 RP |
5137 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the |
5138 | value that the register would contain if all stack frames farther in | |
5139 | were exited and their saved registers restored. In order to see the | |
5140 | true contents of hardware registers, you must select the innermost | |
5141 | frame (with @samp{frame 0}). | |
70b88761 | 5142 | |
18fae2a8 | 5143 | However, @value{GDBN} must deduce where registers are saved, from the machine |
70b88761 | 5144 | code generated by your compiler. If some registers are not saved, or if |
18fae2a8 | 5145 | @value{GDBN} is unable to locate the saved registers, the selected stack |
70b88761 RP |
5146 | frame will make no difference. |
5147 | ||
18fae2a8 | 5148 | @ifset AMDxxixK |
03a77779 | 5149 | @table @code |
d8a68b28 JG |
5150 | @item set rstack_high_address @var{address} |
5151 | @kindex set rstack_high_address | |
03a77779 RP |
5152 | @cindex AMD 29K register stack |
5153 | @cindex register stack, AMD29K | |
5154 | On AMD 29000 family processors, registers are saved in a separate | |
18fae2a8 RP |
5155 | ``register stack''. There is no way for @value{GDBN} to determine the extent |
5156 | of this stack. Normally, @value{GDBN} just assumes that the stack is ``large | |
5157 | enough''. This may result in @value{GDBN} referencing memory locations that | |
93918348 | 5158 | do not exist. If necessary, you can get around this problem by |
03a77779 RP |
5159 | specifying the ending address of the register stack with the @code{set |
5160 | rstack_high_address} command. The argument should be an address, which | |
5161 | you will probably want to precede with @samp{0x} to specify in | |
5162 | hexadecimal. | |
d8a68b28 JG |
5163 | |
5164 | @item show rstack_high_address | |
5165 | @kindex show rstack_high_address | |
03a77779 RP |
5166 | Display the current limit of the register stack, on AMD 29000 family |
5167 | processors. | |
5168 | @end table | |
18fae2a8 | 5169 | @end ifset |
d8a68b28 | 5170 | |
18fae2a8 | 5171 | @ifclear HviiiEXCLUSIVE |
4eb4cf57 | 5172 | @node Floating Point Hardware |
70b88761 RP |
5173 | @section Floating Point Hardware |
5174 | @cindex floating point | |
1041a570 | 5175 | |
18fae2a8 | 5176 | Depending on the host machine architecture, @value{GDBN} may be able to give |
70b88761 RP |
5177 | you more information about the status of the floating point hardware. |
5178 | ||
5179 | @table @code | |
5180 | @item info float | |
5181 | @kindex info float | |
5182 | If available, provides hardware-dependent information about the floating | |
5183 | point unit. The exact contents and layout vary depending on the | |
5184 | floating point chip. | |
5185 | @end table | |
5186 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
5187 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
5188 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 | 5189 | @c FIXME... at that point. |
18fae2a8 | 5190 | @end ifclear |
70b88761 | 5191 | |
18fae2a8 | 5192 | @ifclear CONLY |
4eb4cf57 | 5193 | @node Languages |
18fae2a8 | 5194 | @chapter Using @value{GDBN} with Different Languages |
c2bbbb22 RP |
5195 | @cindex languages |
5196 | ||
5197 | Although programming languages generally have common aspects, they are | |
5198 | rarely expressed in the same manner. For instance, in ANSI C, | |
5199 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
5200 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
5201 | represented (and displayed) differently. Hex numbers in C are written | |
5202 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
5203 | ||
5204 | @cindex working language | |
18fae2a8 | 5205 | Language-specific information is built into @value{GDBN} for some languages, |
29a2b744 | 5206 | allowing you to express operations like the above in your program's |
18fae2a8 | 5207 | native language, and allowing @value{GDBN} to output values in a manner |
29a2b744 | 5208 | consistent with the syntax of your program's native language. The |
c2bbbb22 | 5209 | language you use to build expressions, called the @dfn{working |
18fae2a8 | 5210 | language}, can be selected manually, or @value{GDBN} can set it |
c2bbbb22 RP |
5211 | automatically. |
5212 | ||
5213 | @menu | |
5214 | * Setting:: Switching between source languages | |
5215 | * Show:: Displaying the language | |
ed447b95 | 5216 | * Checks:: Type and range checks |
c2bbbb22 RP |
5217 | * Support:: Supported languages |
5218 | @end menu | |
5219 | ||
4eb4cf57 | 5220 | @node Setting |
c2bbbb22 RP |
5221 | @section Switching between source languages |
5222 | ||
18fae2a8 | 5223 | There are two ways to control the working language---either have @value{GDBN} |
c2bbbb22 | 5224 | set it automatically, or select it manually yourself. You can use the |
18fae2a8 | 5225 | @code{set language} command for either purpose. On startup, @value{GDBN} |
c2bbbb22 RP |
5226 | defaults to setting the language automatically. |
5227 | ||
5228 | @menu | |
5229 | * Manually:: Setting the working language manually | |
18fae2a8 | 5230 | * Automatically:: Having @value{GDBN} infer the source language |
c2bbbb22 RP |
5231 | @end menu |
5232 | ||
4eb4cf57 | 5233 | @node Manually |
c2bbbb22 RP |
5234 | @subsection Setting the working language |
5235 | ||
ed447b95 RP |
5236 | If you allow @value{GDBN} to set the language automatically, |
5237 | expressions are interpreted the same way in your debugging session and | |
5238 | your program. | |
5239 | ||
c2bbbb22 | 5240 | @kindex set language |
ed447b95 RP |
5241 | If you wish, you may set the language manually. To do this, issue the |
5242 | command @samp{set language @var{lang}}, where @var{lang} is the name of | |
5243 | a language, such as @code{c} or @code{modula-2}. For a list of the supported | |
5244 | languages, type @samp{set language}. | |
5245 | @c FIXME: rms: eventually this command should be "help set language". | |
c2bbbb22 | 5246 | |
18fae2a8 | 5247 | Setting the language manually prevents @value{GDBN} from updating the working |
c2bbbb22 RP |
5248 | language automatically. This can lead to confusion if you try |
5249 | to debug a program when the working language is not the same as the | |
5250 | source language, when an expression is acceptable to both | |
5251 | languages---but means different things. For instance, if the current | |
18fae2a8 | 5252 | source file were written in C, and @value{GDBN} was parsing Modula-2, a |
c2bbbb22 RP |
5253 | command such as: |
5254 | ||
5255 | @example | |
5256 | print a = b + c | |
5257 | @end example | |
5258 | ||
5259 | @noindent | |
5260 | might not have the effect you intended. In C, this means to add | |
5261 | @code{b} and @code{c} and place the result in @code{a}. The result | |
5262 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
5263 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
5264 | ||
4eb4cf57 | 5265 | @node Automatically |
18fae2a8 | 5266 | @subsection Having @value{GDBN} infer the source language |
c2bbbb22 | 5267 | |
18fae2a8 RP |
5268 | To have @value{GDBN} set the working language automatically, use @samp{set |
5269 | language local} or @samp{set language auto}. @value{GDBN} then infers the | |
c2bbbb22 RP |
5270 | language that a program was written in by looking at the name of its |
5271 | source files, and examining their extensions: | |
5272 | ||
5273 | @table @file | |
5274 | @item *.mod | |
5275 | Modula-2 source file | |
5276 | ||
5277 | @item *.c | |
5a2c1d85 RP |
5278 | C source file |
5279 | ||
5280 | @item *.C | |
c2bbbb22 | 5281 | @itemx *.cc |
5a2c1d85 | 5282 | C++ source file |
c2bbbb22 RP |
5283 | @end table |
5284 | ||
5285 | This information is recorded for each function or procedure in a source | |
5286 | file. When your program stops in a frame (usually by encountering a | |
18fae2a8 | 5287 | breakpoint), @value{GDBN} sets the working language to the language recorded |
c2bbbb22 RP |
5288 | for the function in that frame. If the language for a frame is unknown |
5289 | (that is, if the function or block corresponding to the frame was | |
5290 | defined in a source file that does not have a recognized extension), the | |
18fae2a8 | 5291 | current working language is not changed, and @value{GDBN} issues a warning. |
c2bbbb22 RP |
5292 | |
5293 | This may not seem necessary for most programs, which are written | |
5294 | entirely in one source language. However, program modules and libraries | |
5295 | written in one source language can be used by a main program written in | |
5296 | a different source language. Using @samp{set language auto} in this | |
5297 | case frees you from having to set the working language manually. | |
5298 | ||
4eb4cf57 | 5299 | @node Show |
c2bbbb22 RP |
5300 | @section Displaying the language |
5301 | ||
5302 | The following commands will help you find out which language is the | |
5303 | working language, and also what language source files were written in. | |
5304 | ||
5305 | @kindex show language | |
5306 | @kindex info frame | |
5307 | @kindex info source | |
5308 | @table @code | |
5309 | @item show language | |
5310 | Display the current working language. This is the | |
5311 | language you can use with commands such as @code{print} to | |
29a2b744 | 5312 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
5313 | |
5314 | @item info frame | |
1041a570 | 5315 | Among the other information listed here (@pxref{Frame Info, ,Information |
c2bbbb22 RP |
5316 | about a Frame}) is the source language for this frame. This is the |
5317 | language that will become the working language if you ever use an | |
5318 | identifier that is in this frame. | |
5319 | ||
5320 | @item info source | |
1041a570 | 5321 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 5322 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
5323 | @end table |
5324 | ||
4eb4cf57 | 5325 | @node Checks |
c2bbbb22 RP |
5326 | @section Type and range Checking |
5327 | ||
5328 | @quotation | |
18fae2a8 | 5329 | @emph{Warning:} In this release, the @value{GDBN} commands for type and range |
c2bbbb22 RP |
5330 | checking are included, but they do not yet have any effect. This |
5331 | section documents the intended facilities. | |
5332 | @end quotation | |
5333 | @c FIXME remove warning when type/range code added | |
5334 | ||
5335 | Some languages are designed to guard you against making seemingly common | |
5336 | errors through a series of compile- and run-time checks. These include | |
5337 | checking the type of arguments to functions and operators, and making | |
5338 | sure mathematical overflows are caught at run time. Checks such as | |
5339 | these help to ensure a program's correctness once it has been compiled | |
5340 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 5341 | errors when your program is running. |
c2bbbb22 | 5342 | |
18fae2a8 RP |
5343 | @value{GDBN} can check for conditions like the above if you wish. |
5344 | Although @value{GDBN} will not check the statements in your program, it | |
5345 | can check expressions entered directly into @value{GDBN} for evaluation via | |
1041a570 | 5346 | the @code{print} command, for example. As with the working language, |
18fae2a8 | 5347 | @value{GDBN} can also decide whether or not to check automatically based on |
1041a570 RP |
5348 | your program's source language. @xref{Support, ,Supported Languages}, |
5349 | for the default settings of supported languages. | |
c2bbbb22 RP |
5350 | |
5351 | @menu | |
5352 | * Type Checking:: An overview of type checking | |
5353 | * Range Checking:: An overview of range checking | |
5354 | @end menu | |
5355 | ||
5356 | @cindex type checking | |
5357 | @cindex checks, type | |
4eb4cf57 | 5358 | @node Type Checking |
c2bbbb22 RP |
5359 | @subsection An overview of type checking |
5360 | ||
5361 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
5362 | arguments to operators and functions have to be of the correct type, | |
5363 | otherwise an error occurs. These checks prevent type mismatch | |
5364 | errors from ever causing any run-time problems. For example, | |
5365 | ||
5366 | @example | |
5367 | 1 + 2 @result{} 3 | |
1041a570 | 5368 | @exdent but |
c2bbbb22 RP |
5369 | @error{} 1 + 2.3 |
5370 | @end example | |
5371 | ||
5372 | The second example fails because the @code{CARDINAL} 1 is not | |
5373 | type-compatible with the @code{REAL} 2.3. | |
5374 | ||
18fae2a8 | 5375 | For expressions you use in @value{GDBN} commands, you can tell the @value{GDBN} |
c2bbbb22 RP |
5376 | type checker to skip checking; to treat any mismatches as errors and |
5377 | abandon the expression; or only issue warnings when type mismatches | |
5378 | occur, but evaluate the expression anyway. When you choose the last of | |
18fae2a8 | 5379 | these, @value{GDBN} evaluates expressions like the second example above, but |
c2bbbb22 RP |
5380 | also issues a warning. |
5381 | ||
5382 | Even though you may turn type checking off, other type-based reasons may | |
18fae2a8 | 5383 | prevent @value{GDBN} from evaluating an expression. For instance, @value{GDBN} does not |
c2bbbb22 RP |
5384 | know how to add an @code{int} and a @code{struct foo}. These particular |
5385 | type errors have nothing to do with the language in use, and usually | |
5386 | arise from expressions, such as the one described above, which make | |
5387 | little sense to evaluate anyway. | |
5388 | ||
5389 | Each language defines to what degree it is strict about type. For | |
5390 | instance, both Modula-2 and C require the arguments to arithmetical | |
5391 | operators to be numbers. In C, enumerated types and pointers can be | |
5392 | represented as numbers, so that they are valid arguments to mathematical | |
1041a570 | 5393 | operators. @xref{Support, ,Supported Languages}, for further |
c2bbbb22 RP |
5394 | details on specific languages. |
5395 | ||
18fae2a8 | 5396 | @value{GDBN} provides some additional commands for controlling the type checker: |
c2bbbb22 RP |
5397 | |
5398 | @kindex set check | |
5399 | @kindex set check type | |
5400 | @kindex show check type | |
5401 | @table @code | |
5402 | @item set check type auto | |
e251e767 | 5403 | Set type checking on or off based on the current working language. |
1041a570 | 5404 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
5405 | each language. |
5406 | ||
5407 | @item set check type on | |
5408 | @itemx set check type off | |
5409 | Set type checking on or off, overriding the default setting for the | |
5410 | current working language. Issue a warning if the setting does not | |
93918348 | 5411 | match the language default. If any type mismatches occur in |
18fae2a8 | 5412 | evaluating an expression while typechecking is on, @value{GDBN} prints a |
c2bbbb22 RP |
5413 | message and aborts evaluation of the expression. |
5414 | ||
5415 | @item set check type warn | |
5416 | Cause the type checker to issue warnings, but to always attempt to | |
5417 | evaluate the expression. Evaluating the expression may still | |
18fae2a8 | 5418 | be impossible for other reasons. For example, @value{GDBN} cannot add |
c2bbbb22 RP |
5419 | numbers and structures. |
5420 | ||
5421 | @item show type | |
18fae2a8 | 5422 | Show the current setting of the type checker, and whether or not @value{GDBN} is |
c2bbbb22 RP |
5423 | setting it automatically. |
5424 | @end table | |
5425 | ||
5426 | @cindex range checking | |
5427 | @cindex checks, range | |
4eb4cf57 | 5428 | @node Range Checking |
ed447b95 | 5429 | @subsection An overview of range checking |
c2bbbb22 RP |
5430 | |
5431 | In some languages (such as Modula-2), it is an error to exceed the | |
5432 | bounds of a type; this is enforced with run-time checks. Such range | |
5433 | checking is meant to ensure program correctness by making sure | |
5434 | computations do not overflow, or indices on an array element access do | |
5435 | not exceed the bounds of the array. | |
5436 | ||
ed447b95 RP |
5437 | For expressions you use in @value{GDBN} commands, you can tell |
5438 | @value{GDBN} to treat range errors in one of three ways: ignore them, | |
5439 | always treat them as errors and abandon the expression, or issue | |
5440 | warnings but evaluate the expression anyway. | |
c2bbbb22 RP |
5441 | |
5442 | A range error can result from numerical overflow, from exceeding an | |
ed447b95 | 5443 | array index bound, or when you type a constant that is not a member |
c2bbbb22 RP |
5444 | of any type. Some languages, however, do not treat overflows as an |
5445 | error. In many implementations of C, mathematical overflow causes the | |
5446 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
5447 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 5448 | |
c2bbbb22 RP |
5449 | @example |
5450 | @var{m} + 1 @result{} @var{s} | |
5451 | @end example | |
5452 | ||
5453 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 5454 | specific to individual compilers or machines. @xref{Support, , |
c2bbbb22 RP |
5455 | Supported Languages}, for further details on specific languages. |
5456 | ||
18fae2a8 | 5457 | @value{GDBN} provides some additional commands for controlling the range checker: |
c2bbbb22 RP |
5458 | |
5459 | @kindex set check | |
5460 | @kindex set check range | |
5461 | @kindex show check range | |
5462 | @table @code | |
5463 | @item set check range auto | |
e251e767 | 5464 | Set range checking on or off based on the current working language. |
1041a570 | 5465 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
5466 | each language. |
5467 | ||
5468 | @item set check range on | |
5469 | @itemx set check range off | |
5470 | Set range checking on or off, overriding the default setting for the | |
5471 | current working language. A warning is issued if the setting does not | |
93918348 | 5472 | match the language default. If a range error occurs, then a message |
c2bbbb22 RP |
5473 | is printed and evaluation of the expression is aborted. |
5474 | ||
5475 | @item set check range warn | |
18fae2a8 | 5476 | Output messages when the @value{GDBN} range checker detects a range error, |
c2bbbb22 RP |
5477 | but attempt to evaluate the expression anyway. Evaluating the |
5478 | expression may still be impossible for other reasons, such as accessing | |
5479 | memory that the process does not own (a typical example from many UNIX | |
5480 | systems). | |
5481 | ||
5482 | @item show range | |
e251e767 | 5483 | Show the current setting of the range checker, and whether or not it is |
18fae2a8 | 5484 | being set automatically by @value{GDBN}. |
c2bbbb22 RP |
5485 | @end table |
5486 | ||
4eb4cf57 | 5487 | @node Support |
c2bbbb22 RP |
5488 | @section Supported Languages |
5489 | ||
18fae2a8 | 5490 | @value{GDBN} 4 supports C, C++, and Modula-2. Some @value{GDBN} |
1041a570 | 5491 | features may be used in expressions regardless of the language you |
18fae2a8 | 5492 | use: the @value{GDBN} @code{@@} and @code{::} operators, and the |
1041a570 RP |
5493 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be |
5494 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
5495 | |
5496 | The following sections detail to what degree each of these | |
18fae2a8 | 5497 | source languages is supported by @value{GDBN}. These sections are |
c2bbbb22 | 5498 | not meant to be language tutorials or references, but serve only as a |
18fae2a8 | 5499 | reference guide to what the @value{GDBN} expression parser will accept, and |
c2bbbb22 RP |
5500 | what input and output formats should look like for different languages. |
5501 | There are many good books written on each of these languages; please | |
5502 | look to these for a language reference or tutorial. | |
5503 | ||
5504 | @menu | |
5505 | * C:: C and C++ | |
5506 | * Modula-2:: Modula-2 | |
5507 | @end menu | |
5508 | ||
4eb4cf57 | 5509 | @node C |
c2bbbb22 RP |
5510 | @subsection C and C++ |
5511 | @cindex C and C++ | |
c2bbbb22 | 5512 | @cindex expressions in C or C++ |
0f153e74 | 5513 | |
18fae2a8 | 5514 | Since C and C++ are so closely related, many features of @value{GDBN} apply |
5a2c1d85 RP |
5515 | to both languages. Whenever this is the case, we discuss both languages |
5516 | together. | |
b80282d5 RP |
5517 | |
5518 | @cindex C++ | |
5519 | @kindex g++ | |
5520 | @cindex GNU C++ | |
c2bbbb22 | 5521 | The C++ debugging facilities are jointly implemented by the GNU C++ |
18fae2a8 | 5522 | compiler and @value{GDBN}. Therefore, to debug your C++ code effectively, |
c2bbbb22 RP |
5523 | you must compile your C++ programs with the GNU C++ compiler, |
5524 | @code{g++}. | |
18fae2a8 RP |
5525 | @end ifclear |
5526 | @ifset CONLY | |
0f153e74 RP |
5527 | @node C |
5528 | @chapter C Language Support | |
5529 | @cindex C language | |
5530 | @cindex expressions in C | |
5531 | ||
18fae2a8 RP |
5532 | Information specific to the C language is built into @value{GDBN} so that you |
5533 | can use C expressions while degugging. This also permits @value{GDBN} to | |
0f153e74 | 5534 | output values in a manner consistent with C conventions. |
c2bbbb22 | 5535 | |
0f153e74 | 5536 | @menu |
ed447b95 RP |
5537 | * C Operators:: C operators |
5538 | * C Constants:: C constants | |
18fae2a8 | 5539 | * Debugging C:: @value{GDBN} and C |
0f153e74 | 5540 | @end menu |
18fae2a8 RP |
5541 | @end ifset |
5542 | @ifclear CONLY | |
b80282d5 | 5543 | @menu |
ed447b95 RP |
5544 | * C Operators:: C and C++ operators |
5545 | * C Constants:: C and C++ constants | |
5546 | * Cplus expressions:: C++ expressions | |
c2bbbb22 | 5547 | * C Defaults:: Default settings for C and C++ |
ed447b95 | 5548 | * C Checks:: C and C++ type and range checks |
18fae2a8 | 5549 | * Debugging C:: @value{GDBN} and C |
c2bbbb22 | 5550 | * Debugging C plus plus:: Special features for C++ |
b80282d5 | 5551 | @end menu |
18fae2a8 | 5552 | @end ifclear |
b80282d5 | 5553 | |
18fae2a8 | 5554 | @ifclear CONLY |
c2bbbb22 | 5555 | @cindex C and C++ operators |
4eb4cf57 | 5556 | @node C Operators |
c2bbbb22 | 5557 | @subsubsection C and C++ Operators |
18fae2a8 RP |
5558 | @end ifclear |
5559 | @ifset CONLY | |
0f153e74 RP |
5560 | @cindex C operators |
5561 | @node C Operators | |
5562 | @section C Operators | |
18fae2a8 | 5563 | @end ifset |
c2bbbb22 RP |
5564 | |
5565 | Operators must be defined on values of specific types. For instance, | |
5566 | @code{+} is defined on numbers, but not on structures. Operators are | |
0f153e74 RP |
5567 | often defined on groups of types. |
5568 | ||
18fae2a8 | 5569 | @ifclear CONLY |
0f153e74 | 5570 | For the purposes of C and C++, the following definitions hold: |
18fae2a8 | 5571 | @end ifclear |
c2bbbb22 RP |
5572 | |
5573 | @itemize @bullet | |
e251e767 | 5574 | @item |
c2bbbb22 RP |
5575 | @emph{Integral types} include @code{int} with any of its storage-class |
5576 | specifiers, @code{char}, and @code{enum}s. | |
5577 | ||
5578 | @item | |
5579 | @emph{Floating-point types} include @code{float} and @code{double}. | |
5580 | ||
5581 | @item | |
5582 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
5583 | *)}. | |
5584 | ||
e251e767 | 5585 | @item |
c2bbbb22 | 5586 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
5587 | @end itemize |
5588 | ||
5589 | @noindent | |
5590 | The following operators are supported. They are listed here | |
5591 | in order of increasing precedence: | |
5592 | ||
5593 | @table @code | |
18fae2a8 | 5594 | @item , |
c2bbbb22 RP |
5595 | The comma or sequencing operator. Expressions in a comma-separated list |
5596 | are evaluated from left to right, with the result of the entire | |
5597 | expression being the last expression evaluated. | |
5598 | ||
5599 | @item = | |
5600 | Assignment. The value of an assignment expression is the value | |
5601 | assigned. Defined on scalar types. | |
5602 | ||
5603 | @item @var{op}= | |
1041a570 RP |
5604 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
5605 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
5606 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
5607 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
5608 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
5609 | |
5610 | @item ?: | |
5611 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
5612 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
5613 | integral type. | |
5614 | ||
5615 | @item || | |
1041a570 | 5616 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
5617 | |
5618 | @item && | |
1041a570 | 5619 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
5620 | |
5621 | @item | | |
1041a570 | 5622 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
5623 | |
5624 | @item ^ | |
1041a570 | 5625 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
5626 | |
5627 | @item & | |
1041a570 | 5628 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
5629 | |
5630 | @item ==@r{, }!= | |
5631 | Equality and inequality. Defined on scalar types. The value of these | |
5632 | expressions is 0 for false and non-zero for true. | |
5633 | ||
5634 | @item <@r{, }>@r{, }<=@r{, }>= | |
5635 | Less than, greater than, less than or equal, greater than or equal. | |
5636 | Defined on scalar types. The value of these expressions is 0 for false | |
5637 | and non-zero for true. | |
5638 | ||
5639 | @item <<@r{, }>> | |
18fae2a8 | 5640 | left shift, and right shift. Defined on integral types. |
c2bbbb22 | 5641 | |
e251e767 | 5642 | @item @@ |
18fae2a8 | 5643 | The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5644 | |
5645 | @item +@r{, }- | |
5646 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 5647 | pointer types. |
c2bbbb22 RP |
5648 | |
5649 | @item *@r{, }/@r{, }% | |
5650 | Multiplication, division, and modulus. Multiplication and division are | |
5651 | defined on integral and floating-point types. Modulus is defined on | |
5652 | integral types. | |
5653 | ||
5654 | @item ++@r{, }-- | |
5655 | Increment and decrement. When appearing before a variable, the | |
5656 | operation is performed before the variable is used in an expression; | |
5657 | when appearing after it, the variable's value is used before the | |
5658 | operation takes place. | |
5659 | ||
5660 | @item * | |
5661 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
5662 | @code{++}. | |
5663 | ||
5664 | @item & | |
5665 | Address operator. Defined on variables. Same precedence as @code{++}. | |
5666 | ||
18fae2a8 | 5667 | @ifclear CONLY |
93918348 | 5668 | For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is |
6ca72cc6 RP |
5669 | allowed in the C++ language itself: you can use @samp{&(&@var{ref})} |
5670 | (or, if you prefer, simply @samp{&&@var{ref}} to examine the address | |
5671 | where a C++ reference variable (declared with @samp{&@var{ref}}) is | |
5672 | stored. | |
18fae2a8 | 5673 | @end ifclear |
6ca72cc6 | 5674 | |
c2bbbb22 RP |
5675 | @item - |
5676 | Negative. Defined on integral and floating-point types. Same | |
5677 | precedence as @code{++}. | |
5678 | ||
5679 | @item ! | |
5680 | Logical negation. Defined on integral types. Same precedence as | |
5681 | @code{++}. | |
5682 | ||
5683 | @item ~ | |
5684 | Bitwise complement operator. Defined on integral types. Same precedence as | |
5685 | @code{++}. | |
5686 | ||
18fae2a8 | 5687 | |
c2bbbb22 RP |
5688 | @item .@r{, }-> |
5689 | Structure member, and pointer-to-structure member. For convenience, | |
18fae2a8 | 5690 | @value{GDBN} regards the two as equivalent, choosing whether to dereference a |
e251e767 | 5691 | pointer based on the stored type information. |
c2bbbb22 RP |
5692 | Defined on @code{struct}s and @code{union}s. |
5693 | ||
5694 | @item [] | |
5695 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
5696 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
5697 | ||
5698 | @item () | |
18fae2a8 | 5699 | Function parameter list. Same precedence as @code{->}. |
c2bbbb22 | 5700 | |
18fae2a8 | 5701 | @ifclear CONLY |
c2bbbb22 RP |
5702 | @item :: |
5703 | C++ scope resolution operator. Defined on | |
5704 | @code{struct}, @code{union}, and @code{class} types. | |
18fae2a8 | 5705 | @end ifclear |
c2bbbb22 RP |
5706 | |
5707 | @item :: | |
ed447b95 RP |
5708 | Doubled colons |
5709 | @ifclear CONLY | |
5710 | also | |
5711 | @end ifclear | |
5712 | represent the @value{GDBN} scope operator (@pxref{Expressions, | |
5713 | ,Expressions}). | |
18fae2a8 | 5714 | @ifclear CONLY |
0f153e74 | 5715 | Same precedence as @code{::}, above. |
18fae2a8 | 5716 | @end ifclear |
c2bbbb22 RP |
5717 | @end table |
5718 | ||
18fae2a8 | 5719 | @ifclear CONLY |
c2bbbb22 | 5720 | @cindex C and C++ constants |
4eb4cf57 | 5721 | @node C Constants |
c2bbbb22 | 5722 | @subsubsection C and C++ Constants |
0f153e74 | 5723 | |
18fae2a8 | 5724 | @value{GDBN} allows you to express the constants of C and C++ in the |
0f153e74 | 5725 | following ways: |
18fae2a8 RP |
5726 | @end ifclear |
5727 | @ifset CONLY | |
0f153e74 RP |
5728 | @cindex C constants |
5729 | @node C Constants | |
5730 | @section C Constants | |
c2bbbb22 | 5731 | |
18fae2a8 | 5732 | @value{GDBN} allows you to express the constants of C in the |
c2bbbb22 | 5733 | following ways: |
18fae2a8 | 5734 | @end ifset |
c2bbbb22 RP |
5735 | |
5736 | @itemize @bullet | |
c2bbbb22 RP |
5737 | @item |
5738 | Integer constants are a sequence of digits. Octal constants are | |
5739 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 5740 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
5741 | @samp{l}, specifying that the constant should be treated as a |
5742 | @code{long} value. | |
5743 | ||
5744 | @item | |
5745 | Floating point constants are a sequence of digits, followed by a decimal | |
5746 | point, followed by a sequence of digits, and optionally followed by an | |
5747 | exponent. An exponent is of the form: | |
5748 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
5749 | sequence of digits. The @samp{+} is optional for positive exponents. | |
5750 | ||
5751 | @item | |
5752 | Enumerated constants consist of enumerated identifiers, or their | |
5753 | integral equivalents. | |
5754 | ||
5755 | @item | |
5756 | Character constants are a single character surrounded by single quotes | |
5757 | (@code{'}), or a number---the ordinal value of the corresponding character | |
5758 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
5759 | be represented by a letter or by @dfn{escape sequences}, which are of | |
5760 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
5761 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
5762 | @samp{@var{x}} is a predefined special character---for example, | |
5763 | @samp{\n} for newline. | |
5764 | ||
5765 | @item | |
5766 | String constants are a sequence of character constants surrounded | |
5767 | by double quotes (@code{"}). | |
5768 | ||
5769 | @item | |
5770 | Pointer constants are an integral value. | |
c2bbbb22 RP |
5771 | @end itemize |
5772 | ||
18fae2a8 | 5773 | @ifclear CONLY |
ed447b95 | 5774 | @node Cplus expressions |
c2bbbb22 | 5775 | @subsubsection C++ Expressions |
b80282d5 RP |
5776 | |
5777 | @cindex expressions in C++ | |
93918348 | 5778 | @value{GDBN} expression handling has a number of extensions to |
b1385986 RP |
5779 | interpret a significant subset of C++ expressions. |
5780 | ||
5781 | @cindex C++ support, not in @sc{coff} | |
5782 | @cindex @sc{coff} versus C++ | |
5783 | @cindex C++ and object formats | |
5784 | @cindex object formats and C++ | |
5785 | @cindex a.out and C++ | |
5786 | @cindex @sc{ecoff} and C++ | |
5787 | @cindex @sc{xcoff} and C++ | |
5788 | @cindex @sc{elf}/stabs and C++ | |
5789 | @cindex @sc{elf}/@sc{dwarf} and C++ | |
5790 | @quotation | |
5791 | @emph{Warning:} Most of these extensions depend on the use of additional | |
5792 | debugging information in the symbol table, and thus require a rich, | |
5793 | extendable object code format. In particular, if your system uses | |
5794 | a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs | |
5795 | extensions to the symbol table, these facilities are all available. | |
5796 | Where the object code format is standard @sc{coff}, on the other hand, | |
18fae2a8 | 5797 | most of the C++ support in @value{GDBN} will @emph{not} work, nor can it. |
b1385986 | 5798 | For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the |
18fae2a8 | 5799 | standard is still evolving, so the C++ support in @value{GDBN} is still |
b1385986 RP |
5800 | fragile; when this debugging format stabilizes, however, C++ support |
5801 | will also be available on systems that use it. | |
5802 | @end quotation | |
b80282d5 RP |
5803 | |
5804 | @enumerate | |
5805 | ||
5806 | @cindex member functions | |
e251e767 | 5807 | @item |
b80282d5 | 5808 | Member function calls are allowed; you can use expressions like |
1041a570 | 5809 | |
b80282d5 RP |
5810 | @example |
5811 | count = aml->GetOriginal(x, y) | |
5812 | @end example | |
5813 | ||
5814 | @kindex this | |
5815 | @cindex namespace in C++ | |
e251e767 | 5816 | @item |
b80282d5 RP |
5817 | While a member function is active (in the selected stack frame), your |
5818 | expressions have the same namespace available as the member function; | |
18fae2a8 | 5819 | that is, @value{GDBN} allows implicit references to the class instance |
b80282d5 RP |
5820 | pointer @code{this} following the same rules as C++. |
5821 | ||
5822 | @cindex call overloaded functions | |
5823 | @cindex type conversions in C++ | |
e251e767 | 5824 | @item |
18fae2a8 | 5825 | You can call overloaded functions; @value{GDBN} will resolve the function |
b80282d5 RP |
5826 | call to the right definition, with one restriction---you must use |
5827 | arguments of the type required by the function that you want to call. | |
18fae2a8 | 5828 | @value{GDBN} will not perform conversions requiring constructors or |
b80282d5 RP |
5829 | user-defined type operators. |
5830 | ||
5831 | @cindex reference declarations | |
5832 | @item | |
18fae2a8 | 5833 | @value{GDBN} understands variables declared as C++ references; you can use them in |
b80282d5 | 5834 | expressions just as you do in C++ source---they are automatically |
e251e767 | 5835 | dereferenced. |
b80282d5 | 5836 | |
18fae2a8 | 5837 | In the parameter list shown when @value{GDBN} displays a frame, the values of |
b80282d5 RP |
5838 | reference variables are not displayed (unlike other variables); this |
5839 | avoids clutter, since references are often used for large structures. | |
5840 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 5841 | you have specified @samp{set print address off}. |
b80282d5 RP |
5842 | |
5843 | @item | |
18fae2a8 | 5844 | @value{GDBN} supports the C++ name resolution operator @code{::}---your |
c2bbbb22 RP |
5845 | expressions can use it just as expressions in your program do. Since |
5846 | one scope may be defined in another, you can use @code{::} repeatedly if | |
5847 | necessary, for example in an expression like | |
18fae2a8 | 5848 | @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows |
c2bbbb22 | 5849 | resolving name scope by reference to source files, in both C and C++ |
1041a570 | 5850 | debugging (@pxref{Variables, ,Program Variables}). |
b80282d5 RP |
5851 | @end enumerate |
5852 | ||
4eb4cf57 | 5853 | @node C Defaults |
c2bbbb22 RP |
5854 | @subsubsection C and C++ Defaults |
5855 | @cindex C and C++ defaults | |
5856 | ||
18fae2a8 | 5857 | If you allow @value{GDBN} to set type and range checking automatically, they |
e251e767 | 5858 | both default to @code{off} whenever the working language changes to |
18fae2a8 | 5859 | C or C++. This happens regardless of whether you, or @value{GDBN}, |
c2bbbb22 RP |
5860 | selected the working language. |
5861 | ||
18fae2a8 | 5862 | If you allow @value{GDBN} to set the language automatically, it sets the |
5a2c1d85 RP |
5863 | working language to C or C++ on entering code compiled from a source file |
5864 | whose name ends with @file{.c}, @file{.C}, or @file{.cc}. | |
18fae2a8 | 5865 | @xref{Automatically, ,Having @value{GDBN} infer the source language}, for |
c2bbbb22 RP |
5866 | further details. |
5867 | ||
4eb4cf57 | 5868 | @node C Checks |
c2bbbb22 RP |
5869 | @subsubsection C and C++ Type and Range Checks |
5870 | @cindex C and C++ checks | |
5871 | ||
18fae2a8 RP |
5872 | By default, when @value{GDBN} parses C or C++ expressions, type checking |
5873 | is not used. However, if you turn type checking on, @value{GDBN} will | |
c2bbbb22 RP |
5874 | consider two variables type equivalent if: |
5875 | ||
5876 | @itemize @bullet | |
5877 | @item | |
5878 | The two variables are structured and have the same structure, union, or | |
5879 | enumerated tag. | |
5880 | ||
e251e767 | 5881 | @item |
c2bbbb22 RP |
5882 | Two two variables have the same type name, or types that have been |
5883 | declared equivalent through @code{typedef}. | |
5884 | ||
5885 | @ignore | |
5886 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
5887 | @c FIXME--beers? | |
5888 | @item | |
5889 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
5890 | declared in the same declaration. (Note: this may not be true for all C | |
5891 | compilers.) | |
5892 | @end ignore | |
c2bbbb22 RP |
5893 | @end itemize |
5894 | ||
5895 | Range checking, if turned on, is done on mathematical operations. Array | |
5896 | indices are not checked, since they are often used to index a pointer | |
5897 | that is not itself an array. | |
18fae2a8 | 5898 | @end ifclear |
c2bbbb22 | 5899 | |
18fae2a8 | 5900 | @ifclear CONLY |
4eb4cf57 | 5901 | @node Debugging C |
18fae2a8 RP |
5902 | @subsubsection @value{GDBN} and C |
5903 | @end ifclear | |
5904 | @ifset CONLY | |
5905 | @node Debugging C | |
5906 | @section @value{GDBN} and C | |
5907 | @end ifset | |
c2bbbb22 RP |
5908 | |
5909 | The @code{set print union} and @code{show print union} commands apply to | |
5910 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
5911 | inside a @code{struct} or @code{class} will also be printed. | |
5912 | Otherwise, it will appear as @samp{@{...@}}. | |
5913 | ||
5914 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
ed447b95 RP |
5915 | with pointers and a memory allocation function. @xref{Expressions, |
5916 | ,Expressions}. | |
c2bbbb22 | 5917 | |
18fae2a8 | 5918 | @ifclear CONLY |
4eb4cf57 | 5919 | @node Debugging C plus plus |
18fae2a8 | 5920 | @subsubsection @value{GDBN} Features for C++ |
b80282d5 RP |
5921 | |
5922 | @cindex commands for C++ | |
18fae2a8 | 5923 | Some @value{GDBN} commands are particularly useful with C++, and some are |
b80282d5 RP |
5924 | designed specifically for use with C++. Here is a summary: |
5925 | ||
5926 | @table @code | |
5927 | @cindex break in overloaded functions | |
5928 | @item @r{breakpoint menus} | |
5929 | When you want a breakpoint in a function whose name is overloaded, | |
93918348 | 5930 | @value{GDBN} breakpoint menus help you specify which function definition |
b80282d5 RP |
5931 | you want. @xref{Breakpoint Menus}. |
5932 | ||
5933 | @cindex overloading in C++ | |
5934 | @item rbreak @var{regex} | |
5935 | Setting breakpoints using regular expressions is helpful for setting | |
5936 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 5937 | classes. |
29a2b744 | 5938 | @xref{Set Breaks, ,Setting Breakpoints}. |
b80282d5 RP |
5939 | |
5940 | @cindex C++ exception handling | |
5941 | @item catch @var{exceptions} | |
5942 | @itemx info catch | |
29a2b744 | 5943 | Debug C++ exception handling using these commands. @xref{Exception |
1041a570 | 5944 | Handling, ,Breakpoints and Exceptions}. |
b80282d5 | 5945 | |
e251e767 | 5946 | @cindex inheritance |
b80282d5 RP |
5947 | @item ptype @var{typename} |
5948 | Print inheritance relationships as well as other information for type | |
e251e767 | 5949 | @var{typename}. |
1041a570 | 5950 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
5951 | |
5952 | @cindex C++ symbol display | |
5953 | @item set print demangle | |
5954 | @itemx show print demangle | |
5955 | @itemx set print asm-demangle | |
5956 | @itemx show print asm-demangle | |
5957 | Control whether C++ symbols display in their source form, both when | |
5958 | displaying code as C++ source and when displaying disassemblies. | |
1041a570 | 5959 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5960 | |
5961 | @item set print object | |
5962 | @itemx show print object | |
e251e767 | 5963 | Choose whether to print derived (actual) or declared types of objects. |
1041a570 | 5964 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5965 | |
5966 | @item set print vtbl | |
5967 | @itemx show print vtbl | |
5968 | Control the format for printing virtual function tables. | |
1041a570 | 5969 | @xref{Print Settings, ,Print Settings}. |
6f3ec223 RP |
5970 | |
5971 | @item @r{Overloaded symbol names} | |
5972 | You can specify a particular definition of an overloaded symbol, using | |
93918348 | 5973 | the same notation that is used to declare such symbols in C++: type |
6f3ec223 | 5974 | @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can |
93918348 | 5975 | also use the @value{GDBN} command-line word completion facilities to list the |
6f3ec223 RP |
5976 | available choices, or to finish the type list for you. |
5977 | @xref{Completion,, Command Completion}, for details on how to do this. | |
b80282d5 RP |
5978 | @end table |
5979 | ||
4eb4cf57 | 5980 | @node Modula-2 |
c2bbbb22 RP |
5981 | @subsection Modula-2 |
5982 | @cindex Modula-2 | |
5983 | ||
ed447b95 RP |
5984 | The extensions made to @value{GDBN} to support Modula-2 only support |
5985 | output from the GNU Modula-2 compiler (which is currently being | |
5986 | developed). Other Modula-2 compilers are not currently supported, and | |
5987 | attempting to debug executables produced by them will most likely | |
5988 | result in an error as @value{GDBN} reads in the executable's symbol | |
5989 | table. | |
c2bbbb22 RP |
5990 | |
5991 | @cindex expressions in Modula-2 | |
5992 | @menu | |
5993 | * M2 Operators:: Built-in operators | |
ed447b95 RP |
5994 | * Built-In Func/Proc:: Built-in functions and procedures |
5995 | * M2 Constants:: Modula-2 constants | |
c2bbbb22 RP |
5996 | * M2 Defaults:: Default settings for Modula-2 |
5997 | * Deviations:: Deviations from standard Modula-2 | |
ed447b95 | 5998 | * M2 Checks:: Modula-2 type and range checks |
c2bbbb22 | 5999 | * M2 Scope:: The scope operators @code{::} and @code{.} |
18fae2a8 | 6000 | * GDB/M2:: @value{GDBN} and Modula-2 |
c2bbbb22 RP |
6001 | @end menu |
6002 | ||
4eb4cf57 | 6003 | @node M2 Operators |
c2bbbb22 RP |
6004 | @subsubsection Operators |
6005 | @cindex Modula-2 operators | |
6006 | ||
6007 | Operators must be defined on values of specific types. For instance, | |
6008 | @code{+} is defined on numbers, but not on structures. Operators are | |
6009 | often defined on groups of types. For the purposes of Modula-2, the | |
6010 | following definitions hold: | |
6011 | ||
6012 | @itemize @bullet | |
6013 | ||
6014 | @item | |
6015 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
6016 | their subranges. | |
6017 | ||
6018 | @item | |
6019 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
6020 | ||
6021 | @item | |
6022 | @emph{Floating-point types} consist of @code{REAL}. | |
6023 | ||
6024 | @item | |
6025 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
6026 | @var{type}}. | |
6027 | ||
6028 | @item | |
6029 | @emph{Scalar types} consist of all of the above. | |
6030 | ||
6031 | @item | |
6032 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
6033 | ||
6034 | @item | |
6035 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
6036 | @end itemize |
6037 | ||
6038 | @noindent | |
6039 | The following operators are supported, and appear in order of | |
6040 | increasing precedence: | |
6041 | ||
6042 | @table @code | |
c2bbbb22 RP |
6043 | @item , |
6044 | Function argument or array index separator. | |
18fae2a8 | 6045 | |
c2bbbb22 RP |
6046 | @item := |
6047 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
6048 | @var{value}. | |
6049 | ||
6050 | @item <@r{, }> | |
6051 | Less than, greater than on integral, floating-point, or enumerated | |
6052 | types. | |
6053 | ||
6054 | @item <=@r{, }>= | |
6055 | Less than, greater than, less than or equal to, greater than or equal to | |
6056 | on integral, floating-point and enumerated types, or set inclusion on | |
6057 | set types. Same precedence as @code{<}. | |
6058 | ||
6059 | @item =@r{, }<>@r{, }# | |
6060 | Equality and two ways of expressing inequality, valid on scalar types. | |
18fae2a8 | 6061 | Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is |
c2bbbb22 RP |
6062 | available for inequality, since @code{#} conflicts with the script |
6063 | comment character. | |
6064 | ||
6065 | @item IN | |
6066 | Set membership. Defined on set types and the types of their members. | |
6067 | Same precedence as @code{<}. | |
6068 | ||
6069 | @item OR | |
6070 | Boolean disjunction. Defined on boolean types. | |
6071 | ||
6072 | @item AND@r{, }& | |
6073 | Boolean conjuction. Defined on boolean types. | |
6074 | ||
6075 | @item @@ | |
18fae2a8 | 6076 | The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
6077 | |
6078 | @item +@r{, }- | |
6079 | Addition and subtraction on integral and floating-point types, or union | |
6080 | and difference on set types. | |
6081 | ||
6082 | @item * | |
6083 | Multiplication on integral and floating-point types, or set intersection | |
6084 | on set types. | |
6085 | ||
6086 | @item / | |
6087 | Division on floating-point types, or symmetric set difference on set | |
6088 | types. Same precedence as @code{*}. | |
6089 | ||
6090 | @item DIV@r{, }MOD | |
6091 | Integer division and remainder. Defined on integral types. Same | |
6092 | precedence as @code{*}. | |
6093 | ||
6094 | @item - | |
6095 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
6096 | ||
6097 | @item ^ | |
e251e767 | 6098 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
6099 | |
6100 | @item NOT | |
6101 | Boolean negation. Defined on boolean types. Same precedence as | |
6102 | @code{^}. | |
6103 | ||
6104 | @item . | |
6105 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
6106 | precedence as @code{^}. | |
6107 | ||
6108 | @item [] | |
6109 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
6110 | ||
6111 | @item () | |
6112 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
6113 | as @code{^}. | |
6114 | ||
6115 | @item ::@r{, }. | |
18fae2a8 | 6116 | @value{GDBN} and Modula-2 scope operators. |
c2bbbb22 RP |
6117 | @end table |
6118 | ||
6119 | @quotation | |
18fae2a8 | 6120 | @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN} |
c2bbbb22 RP |
6121 | will treat the use of the operator @code{IN}, or the use of operators |
6122 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
6123 | @code{<=}, and @code{>=} on sets as an error. | |
6124 | @end quotation | |
18fae2a8 | 6125 | |
29a2b744 | 6126 | @cindex Modula-2 built-ins |
4eb4cf57 | 6127 | @node Built-In Func/Proc |
c2bbbb22 RP |
6128 | @subsubsection Built-in Functions and Procedures |
6129 | ||
6130 | Modula-2 also makes available several built-in procedures and functions. | |
6131 | In describing these, the following metavariables are used: | |
6132 | ||
6133 | @table @var | |
6134 | ||
6135 | @item a | |
6136 | represents an @code{ARRAY} variable. | |
6137 | ||
6138 | @item c | |
6139 | represents a @code{CHAR} constant or variable. | |
6140 | ||
6141 | @item i | |
6142 | represents a variable or constant of integral type. | |
6143 | ||
6144 | @item m | |
6145 | represents an identifier that belongs to a set. Generally used in the | |
6146 | same function with the metavariable @var{s}. The type of @var{s} should | |
6147 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
6148 | ||
6149 | @item n | |
6150 | represents a variable or constant of integral or floating-point type. | |
6151 | ||
6152 | @item r | |
6153 | represents a variable or constant of floating-point type. | |
6154 | ||
6155 | @item t | |
6156 | represents a type. | |
6157 | ||
6158 | @item v | |
6159 | represents a variable. | |
6160 | ||
6161 | @item x | |
6162 | represents a variable or constant of one of many types. See the | |
6163 | explanation of the function for details. | |
c2bbbb22 RP |
6164 | @end table |
6165 | ||
6166 | All Modula-2 built-in procedures also return a result, described below. | |
6167 | ||
6168 | @table @code | |
6169 | @item ABS(@var{n}) | |
6170 | Returns the absolute value of @var{n}. | |
6171 | ||
6172 | @item CAP(@var{c}) | |
6173 | If @var{c} is a lower case letter, it returns its upper case | |
6174 | equivalent, otherwise it returns its argument | |
6175 | ||
6176 | @item CHR(@var{i}) | |
6177 | Returns the character whose ordinal value is @var{i}. | |
6178 | ||
6179 | @item DEC(@var{v}) | |
6180 | Decrements the value in the variable @var{v}. Returns the new value. | |
6181 | ||
6182 | @item DEC(@var{v},@var{i}) | |
6183 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
6184 | new value. | |
6185 | ||
6186 | @item EXCL(@var{m},@var{s}) | |
6187 | Removes the element @var{m} from the set @var{s}. Returns the new | |
6188 | set. | |
6189 | ||
6190 | @item FLOAT(@var{i}) | |
6191 | Returns the floating point equivalent of the integer @var{i}. | |
6192 | ||
6193 | @item HIGH(@var{a}) | |
6194 | Returns the index of the last member of @var{a}. | |
6195 | ||
6196 | @item INC(@var{v}) | |
6197 | Increments the value in the variable @var{v}. Returns the new value. | |
6198 | ||
6199 | @item INC(@var{v},@var{i}) | |
6200 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
6201 | new value. | |
6202 | ||
6203 | @item INCL(@var{m},@var{s}) | |
6204 | Adds the element @var{m} to the set @var{s} if it is not already | |
6205 | there. Returns the new set. | |
6206 | ||
6207 | @item MAX(@var{t}) | |
6208 | Returns the maximum value of the type @var{t}. | |
6209 | ||
6210 | @item MIN(@var{t}) | |
6211 | Returns the minimum value of the type @var{t}. | |
6212 | ||
6213 | @item ODD(@var{i}) | |
6214 | Returns boolean TRUE if @var{i} is an odd number. | |
6215 | ||
6216 | @item ORD(@var{x}) | |
6217 | Returns the ordinal value of its argument. For example, the ordinal | |
6218 | value of a character is its ASCII value (on machines supporting the | |
6219 | ASCII character set). @var{x} must be of an ordered type, which include | |
6220 | integral, character and enumerated types. | |
6221 | ||
6222 | @item SIZE(@var{x}) | |
6223 | Returns the size of its argument. @var{x} can be a variable or a type. | |
6224 | ||
6225 | @item TRUNC(@var{r}) | |
6226 | Returns the integral part of @var{r}. | |
6227 | ||
6228 | @item VAL(@var{t},@var{i}) | |
6229 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
6230 | @end table | |
6231 | ||
6232 | @quotation | |
6233 | @emph{Warning:} Sets and their operations are not yet supported, so | |
18fae2a8 | 6234 | @value{GDBN} will treat the use of procedures @code{INCL} and @code{EXCL} as |
c2bbbb22 RP |
6235 | an error. |
6236 | @end quotation | |
6237 | ||
6238 | @cindex Modula-2 constants | |
4eb4cf57 | 6239 | @node M2 Constants |
c2bbbb22 RP |
6240 | @subsubsection Constants |
6241 | ||
18fae2a8 | 6242 | @value{GDBN} allows you to express the constants of Modula-2 in the following |
c2bbbb22 RP |
6243 | ways: |
6244 | ||
6245 | @itemize @bullet | |
6246 | ||
6247 | @item | |
6248 | Integer constants are simply a sequence of digits. When used in an | |
6249 | expression, a constant is interpreted to be type-compatible with the | |
6250 | rest of the expression. Hexadecimal integers are specified by a | |
6251 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
6252 | ||
6253 | @item | |
6254 | Floating point constants appear as a sequence of digits, followed by a | |
6255 | decimal point and another sequence of digits. An optional exponent can | |
6256 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
6257 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
6258 | digits of the floating point constant must be valid decimal (base 10) | |
6259 | digits. | |
6260 | ||
6261 | @item | |
6262 | Character constants consist of a single character enclosed by a pair of | |
6263 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
6264 | also be expressed by their ordinal value (their ASCII value, usually) | |
6265 | followed by a @samp{C}. | |
6266 | ||
6267 | @item | |
1041a570 RP |
6268 | String constants consist of a sequence of characters enclosed by a |
6269 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
6270 | Escape sequences in the style of C are also allowed. @xref{C | |
6271 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
6272 | sequences. | |
c2bbbb22 RP |
6273 | |
6274 | @item | |
6275 | Enumerated constants consist of an enumerated identifier. | |
6276 | ||
6277 | @item | |
6278 | Boolean constants consist of the identifiers @code{TRUE} and | |
6279 | @code{FALSE}. | |
6280 | ||
6281 | @item | |
6282 | Pointer constants consist of integral values only. | |
6283 | ||
6284 | @item | |
6285 | Set constants are not yet supported. | |
c2bbbb22 RP |
6286 | @end itemize |
6287 | ||
4eb4cf57 | 6288 | @node M2 Defaults |
c2bbbb22 RP |
6289 | @subsubsection Modula-2 Defaults |
6290 | @cindex Modula-2 defaults | |
6291 | ||
18fae2a8 | 6292 | If type and range checking are set automatically by @value{GDBN}, they |
e251e767 | 6293 | both default to @code{on} whenever the working language changes to |
18fae2a8 | 6294 | Modula-2. This happens regardless of whether you, or @value{GDBN}, |
c2bbbb22 RP |
6295 | selected the working language. |
6296 | ||
18fae2a8 | 6297 | If you allow @value{GDBN} to set the language automatically, then entering |
c2bbbb22 | 6298 | code compiled from a file whose name ends with @file{.mod} will set the |
18fae2a8 | 6299 | working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set |
c2bbbb22 RP |
6300 | the language automatically}, for further details. |
6301 | ||
4eb4cf57 | 6302 | @node Deviations |
c2bbbb22 RP |
6303 | @subsubsection Deviations from Standard Modula-2 |
6304 | @cindex Modula-2, deviations from | |
6305 | ||
6306 | A few changes have been made to make Modula-2 programs easier to debug. | |
6307 | This is done primarily via loosening its type strictness: | |
6308 | ||
6309 | @itemize @bullet | |
e251e767 | 6310 | @item |
c2bbbb22 RP |
6311 | Unlike in standard Modula-2, pointer constants can be formed by |
6312 | integers. This allows you to modify pointer variables during | |
6313 | debugging. (In standard Modula-2, the actual address contained in a | |
6314 | pointer variable is hidden from you; it can only be modified | |
6315 | through direct assignment to another pointer variable or expression that | |
6316 | returned a pointer.) | |
6317 | ||
e251e767 | 6318 | @item |
c2bbbb22 | 6319 | C escape sequences can be used in strings and characters to represent |
18fae2a8 | 6320 | non-printable characters. @value{GDBN} will print out strings with these |
c2bbbb22 RP |
6321 | escape sequences embedded. Single non-printable characters are |
6322 | printed using the @samp{CHR(@var{nnn})} format. | |
6323 | ||
6324 | @item | |
6325 | The assignment operator (@code{:=}) returns the value of its right-hand | |
6326 | argument. | |
6327 | ||
6328 | @item | |
29a2b744 | 6329 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 6330 | @end itemize |
c2bbbb22 | 6331 | |
4eb4cf57 | 6332 | @node M2 Checks |
c2bbbb22 RP |
6333 | @subsubsection Modula-2 Type and Range Checks |
6334 | @cindex Modula-2 checks | |
6335 | ||
6336 | @quotation | |
18fae2a8 | 6337 | @emph{Warning:} in this release, @value{GDBN} does not yet perform type or |
c2bbbb22 RP |
6338 | range checking. |
6339 | @end quotation | |
6340 | @c FIXME remove warning when type/range checks added | |
6341 | ||
18fae2a8 | 6342 | @value{GDBN} considers two Modula-2 variables type equivalent if: |
c2bbbb22 RP |
6343 | |
6344 | @itemize @bullet | |
6345 | @item | |
6346 | They are of types that have been declared equivalent via a @code{TYPE | |
6347 | @var{t1} = @var{t2}} statement | |
6348 | ||
6349 | @item | |
6350 | They have been declared on the same line. (Note: This is true of the | |
6351 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
6352 | @end itemize |
6353 | ||
6354 | As long as type checking is enabled, any attempt to combine variables | |
6355 | whose types are not equivalent is an error. | |
6356 | ||
6357 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 6358 | index bounds, and all built-in functions and procedures. |
c2bbbb22 | 6359 | |
4eb4cf57 | 6360 | @node M2 Scope |
c2bbbb22 RP |
6361 | @subsubsection The scope operators @code{::} and @code{.} |
6362 | @cindex scope | |
6363 | @kindex . | |
e94b4a2b | 6364 | @cindex colon, doubled as scope operator |
1041a570 RP |
6365 | @ifinfo |
6366 | @kindex colon-colon | |
ed447b95 | 6367 | @c Info cannot handle :: but TeX can. |
1041a570 RP |
6368 | @end ifinfo |
6369 | @iftex | |
c2bbbb22 | 6370 | @kindex :: |
1041a570 | 6371 | @end iftex |
c2bbbb22 RP |
6372 | |
6373 | There are a few subtle differences between the Modula-2 scope operator | |
18fae2a8 | 6374 | (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have |
c2bbbb22 RP |
6375 | similar syntax: |
6376 | ||
6377 | @example | |
6378 | ||
6379 | @var{module} . @var{id} | |
6380 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
6381 | @end example |
6382 | ||
6383 | @noindent | |
6384 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
6385 | @var{module} the name of a module, and @var{id} is any declared |
6386 | identifier within your program, except another module. | |
c2bbbb22 | 6387 | |
18fae2a8 | 6388 | Using the @code{::} operator makes @value{GDBN} search the scope |
c2bbbb22 | 6389 | specified by @var{scope} for the identifier @var{id}. If it is not |
18fae2a8 | 6390 | found in the specified scope, then @value{GDBN} will search all scopes |
c2bbbb22 RP |
6391 | enclosing the one specified by @var{scope}. |
6392 | ||
18fae2a8 | 6393 | Using the @code{.} operator makes @value{GDBN} search the current scope for |
c2bbbb22 RP |
6394 | the identifier specified by @var{id} that was imported from the |
6395 | definition module specified by @var{module}. With this operator, it is | |
6396 | an error if the identifier @var{id} was not imported from definition | |
6397 | module @var{module}, or if @var{id} is not an identifier in | |
6398 | @var{module}. | |
6399 | ||
4eb4cf57 | 6400 | @node GDB/M2 |
18fae2a8 | 6401 | @subsubsection @value{GDBN} and Modula-2 |
c2bbbb22 | 6402 | |
18fae2a8 | 6403 | Some @value{GDBN} commands have little use when debugging Modula-2 programs. |
c2bbbb22 RP |
6404 | Five subcommands of @code{set print} and @code{show print} apply |
6405 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
6406 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
93918348 | 6407 | apply to C++, and the last to the C @code{union} type, which has no direct |
c2bbbb22 RP |
6408 | analogue in Modula-2. |
6409 | ||
1041a570 | 6410 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
6411 | while using any language, is not useful with Modula-2. Its |
6412 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
6413 | created in Modula-2 as they can in C or C++. However, because an | |
6414 | address can be specified by an integral constant, the construct | |
1041a570 | 6415 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
18fae2a8 | 6416 | |
c2bbbb22 | 6417 | @cindex @code{#} in Modula-2 |
18fae2a8 | 6418 | In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is |
c2bbbb22 | 6419 | interpreted as the beginning of a comment. Use @code{<>} instead. |
18fae2a8 RP |
6420 | |
6421 | @end ifclear | |
4eb4cf57 RP |
6422 | |
6423 | @node Symbols | |
70b88761 RP |
6424 | @chapter Examining the Symbol Table |
6425 | ||
6426 | The commands described in this section allow you to inquire about the | |
6427 | symbols (names of variables, functions and types) defined in your | |
6428 | program. This information is inherent in the text of your program and | |
18fae2a8 RP |
6429 | does not change as your program executes. @value{GDBN} finds it in your |
6430 | program's symbol table, in the file indicated when you started @value{GDBN} | |
1041a570 RP |
6431 | (@pxref{File Options, ,Choosing Files}), or by one of the |
6432 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
70b88761 | 6433 | |
6c380b13 RP |
6434 | @c FIXME! This might be intentionally specific to C and C++; if so, move |
6435 | @c to someplace in C section of lang chapter. | |
6436 | @cindex symbol names | |
6437 | @cindex names of symbols | |
6438 | @cindex quoting names | |
6439 | Occasionally, you may need to refer to symbols that contain unusual | |
18fae2a8 | 6440 | characters, which @value{GDBN} ordinarily treats as word delimiters. The |
6c380b13 RP |
6441 | most frequent case is in referring to static variables in other |
6442 | source files (@pxref{Variables,,Program Variables}). File names | |
18fae2a8 | 6443 | are recorded in object files as debugging symbols, but @value{GDBN} would |
6c380b13 | 6444 | ordinarily parse a typical file name, like @file{foo.c}, as the three words |
18fae2a8 | 6445 | @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize |
6c380b13 RP |
6446 | @samp{foo.c} as a single symbol, enclose it in single quotes; for example, |
6447 | ||
6448 | @example | |
6449 | p 'foo.c'::x | |
6450 | @end example | |
6451 | ||
6452 | @noindent | |
6453 | looks up the value of @code{x} in the scope of the file @file{foo.c}. | |
6454 | ||
70b88761 RP |
6455 | @table @code |
6456 | @item info address @var{symbol} | |
6457 | @kindex info address | |
6458 | Describe where the data for @var{symbol} is stored. For a register | |
6459 | variable, this says which register it is kept in. For a non-register | |
6460 | local variable, this prints the stack-frame offset at which the variable | |
6461 | is always stored. | |
6462 | ||
6463 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
6464 | at all for a register variables, and for a stack local variable prints | |
6465 | the exact address of the current instantiation of the variable. | |
6466 | ||
6467 | @item whatis @var{exp} | |
6468 | @kindex whatis | |
6469 | Print the data type of expression @var{exp}. @var{exp} is not | |
6470 | actually evaluated, and any side-effecting operations (such as | |
6471 | assignments or function calls) inside it do not take place. | |
1041a570 | 6472 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
6473 | |
6474 | @item whatis | |
6475 | Print the data type of @code{$}, the last value in the value history. | |
6476 | ||
6477 | @item ptype @var{typename} | |
6478 | @kindex ptype | |
6479 | Print a description of data type @var{typename}. @var{typename} may be | |
6480 | the name of a type, or for C code it may have the form | |
6481 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 6482 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
6483 | |
6484 | @item ptype @var{exp} | |
e0dacfd1 | 6485 | @itemx ptype |
70b88761 | 6486 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 | 6487 | differs from @code{whatis} by printing a detailed description, instead |
ed447b95 RP |
6488 | of just the name of the type. |
6489 | ||
6490 | For example, for this variable declaration: | |
1041a570 | 6491 | |
70b88761 RP |
6492 | @example |
6493 | struct complex @{double real; double imag;@} v; | |
6494 | @end example | |
1041a570 | 6495 | |
70b88761 | 6496 | @noindent |
ed447b95 | 6497 | the two commands give this output: |
1041a570 | 6498 | |
70b88761 | 6499 | @example |
1041a570 | 6500 | @group |
18fae2a8 | 6501 | (@value{GDBP}) whatis v |
70b88761 | 6502 | type = struct complex |
18fae2a8 | 6503 | (@value{GDBP}) ptype v |
70b88761 RP |
6504 | type = struct complex @{ |
6505 | double real; | |
6506 | double imag; | |
6507 | @} | |
1041a570 | 6508 | @end group |
70b88761 | 6509 | @end example |
1041a570 | 6510 | |
e0dacfd1 RP |
6511 | @noindent |
6512 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
6513 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
6514 | |
6515 | @item info types @var{regexp} | |
6516 | @itemx info types | |
e251e767 | 6517 | @kindex info types |
70b88761 RP |
6518 | Print a brief description of all types whose name matches @var{regexp} |
6519 | (or all types in your program, if you supply no argument). Each | |
6520 | complete typename is matched as though it were a complete line; thus, | |
6521 | @samp{i type value} gives information on all types in your program whose | |
6522 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
6523 | information only on types whose complete name is @code{value}. | |
6524 | ||
6525 | This command differs from @code{ptype} in two ways: first, like | |
6526 | @code{whatis}, it does not print a detailed description; second, it | |
6527 | lists all source files where a type is defined. | |
6528 | ||
6529 | @item info source | |
6530 | @kindex info source | |
6531 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
6532 | the function containing the current point of execution---and the language |
6533 | it was written in. | |
70b88761 RP |
6534 | |
6535 | @item info sources | |
6536 | @kindex info sources | |
29a2b744 | 6537 | Print the names of all source files in your program for which there is |
b80282d5 RP |
6538 | debugging information, organized into two lists: files whose symbols |
6539 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
6540 | |
6541 | @item info functions | |
6542 | @kindex info functions | |
6543 | Print the names and data types of all defined functions. | |
6544 | ||
6545 | @item info functions @var{regexp} | |
6546 | Print the names and data types of all defined functions | |
6547 | whose names contain a match for regular expression @var{regexp}. | |
6548 | Thus, @samp{info fun step} finds all functions whose names | |
6549 | include @code{step}; @samp{info fun ^step} finds those whose names | |
6550 | start with @code{step}. | |
6551 | ||
6552 | @item info variables | |
6553 | @kindex info variables | |
6554 | Print the names and data types of all variables that are declared | |
6555 | outside of functions (i.e., excluding local variables). | |
6556 | ||
6557 | @item info variables @var{regexp} | |
6558 | Print the names and data types of all variables (except for local | |
6559 | variables) whose names contain a match for regular expression | |
6560 | @var{regexp}. | |
6561 | ||
70b88761 RP |
6562 | @ignore |
6563 | This was never implemented. | |
6564 | @item info methods | |
6565 | @itemx info methods @var{regexp} | |
6566 | @kindex info methods | |
6567 | The @code{info methods} command permits the user to examine all defined | |
6568 | methods within C++ program, or (with the @var{regexp} argument) a | |
6569 | specific set of methods found in the various C++ classes. Many | |
6570 | C++ classes provide a large number of methods. Thus, the output | |
6571 | from the @code{ptype} command can be overwhelming and hard to use. The | |
6572 | @code{info-methods} command filters the methods, printing only those | |
6573 | which match the regular-expression @var{regexp}. | |
6574 | @end ignore | |
6575 | ||
d48da190 RP |
6576 | @item maint print symbols @var{filename} |
6577 | @itemx maint print psymbols @var{filename} | |
6578 | @itemx maint print msymbols @var{filename} | |
6579 | @kindex maint print symbols | |
440d9834 | 6580 | @cindex symbol dump |
d48da190 | 6581 | @kindex maint print psymbols |
440d9834 RP |
6582 | @cindex partial symbol dump |
6583 | Write a dump of debugging symbol data into the file @var{filename}. | |
18fae2a8 | 6584 | These commands are used to debug the @value{GDBN} symbol-reading code. Only |
d48da190 | 6585 | symbols with debugging data are included. If you use @samp{maint print |
18fae2a8 | 6586 | symbols}, @value{GDBN} includes all the symbols for which it has already |
d48da190 | 6587 | collected full details: that is, @var{filename} reflects symbols for |
18fae2a8 | 6588 | only those files whose symbols @value{GDBN} has read. You can use the |
d48da190 RP |
6589 | command @code{info sources} to find out which files these are. If you |
6590 | use @samp{maint print psymbols} instead, the dump shows information about | |
18fae2a8 RP |
6591 | symbols that @value{GDBN} only knows partially---that is, symbols defined in |
6592 | files that @value{GDBN} has skimmed, but not yet read completely. Finally, | |
d48da190 | 6593 | @samp{maint print msymbols} dumps just the minimal symbol information |
18fae2a8 RP |
6594 | required for each object file from which @value{GDBN} has read some symbols. |
6595 | The description of @code{symbol-file} explains how @value{GDBN} reads | |
d48da190 RP |
6596 | symbols; both @code{info source} and @code{symbol-file} are described in |
6597 | @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
6598 | @end table |
6599 | ||
4eb4cf57 | 6600 | @node Altering |
70b88761 RP |
6601 | @chapter Altering Execution |
6602 | ||
29a2b744 | 6603 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
6604 | find out for certain whether correcting the apparent error would lead to |
6605 | correct results in the rest of the run. You can find the answer by | |
18fae2a8 | 6606 | experiment, using the @value{GDBN} features for altering execution of the |
70b88761 RP |
6607 | program. |
6608 | ||
6609 | For example, you can store new values into variables or memory | |
29a2b744 | 6610 | locations, give your program a signal, restart it at a different address, |
70b88761 RP |
6611 | or even return prematurely from a function to its caller. |
6612 | ||
18fae2a8 RP |
6613 | @ignore |
6614 | @c pre-unfold | |
70b88761 | 6615 | @menu |
ed447b95 RP |
6616 | * Assignment:: Assignment to variables |
6617 | * Jumping:: Continuing at a different address | |
18fae2a8 | 6618 | @ifclear BARETARGET |
ed447b95 | 6619 | * Signaling:: Giving your program a signal |
18fae2a8 | 6620 | @end ifclear |
ed447b95 RP |
6621 | * Returning:: Returning from a function |
6622 | * Calling:: Calling your program's functions | |
6623 | * Patching:: Patching your program | |
70b88761 | 6624 | @end menu |
18fae2a8 RP |
6625 | @end ignore |
6626 | ||
6627 | @ifclear BARETARGET | |
6628 | @menu | |
ed447b95 RP |
6629 | * Assignment:: Assignment to variables |
6630 | * Jumping:: Continuing at a different address | |
6631 | * Signaling:: Giving your program a signal | |
6632 | * Returning:: Returning from a function | |
6633 | * Calling:: Calling your program's functions | |
6634 | * Patching:: Patching your program | |
18fae2a8 RP |
6635 | @end menu |
6636 | @end ifclear | |
6637 | ||
6638 | @ifset BARETARGET | |
6639 | @menu | |
ed447b95 RP |
6640 | * Assignment:: Assignment to variables |
6641 | * Jumping:: Continuing at a different address | |
6642 | * Returning:: Returning from a function | |
6643 | * Calling:: Calling your program's functions | |
6644 | * Patching:: Patching your program | |
18fae2a8 RP |
6645 | @end menu |
6646 | @end ifset | |
70b88761 | 6647 | |
4eb4cf57 | 6648 | @node Assignment |
70b88761 RP |
6649 | @section Assignment to Variables |
6650 | ||
6651 | @cindex assignment | |
6652 | @cindex setting variables | |
6653 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 6654 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
6655 | |
6656 | @example | |
6657 | print x=4 | |
6658 | @end example | |
6659 | ||
6660 | @noindent | |
1041a570 | 6661 | stores the value 4 into the variable @code{x}, and then prints the |
4eb4cf57 | 6662 | value of the assignment expression (which is 4). |
18fae2a8 RP |
6663 | @ifclear CONLY |
6664 | @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more | |
4eb4cf57 | 6665 | information on operators in supported languages. |
18fae2a8 | 6666 | @end ifclear |
70b88761 | 6667 | |
70b88761 RP |
6668 | @kindex set variable |
6669 | @cindex variables, setting | |
6670 | If you are not interested in seeing the value of the assignment, use the | |
6671 | @code{set} command instead of the @code{print} command. @code{set} is | |
6672 | really the same as @code{print} except that the expression's value is not | |
1041a570 | 6673 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The |
70b88761 RP |
6674 | expression is evaluated only for its effects. |
6675 | ||
6676 | If the beginning of the argument string of the @code{set} command | |
6677 | appears identical to a @code{set} subcommand, use the @code{set | |
6678 | variable} command instead of just @code{set}. This command is identical | |
ed447b95 RP |
6679 | to @code{set} except for its lack of subcommands. For example, if |
6680 | your program has a variable @code{width}, you get | |
6681 | an error if you try to set a new value with just @samp{set width=13}, | |
6682 | because @value{GDBN} has the command @code{set width}: | |
1041a570 | 6683 | |
70b88761 | 6684 | @example |
18fae2a8 | 6685 | (@value{GDBP}) whatis width |
70b88761 | 6686 | type = double |
18fae2a8 | 6687 | (@value{GDBP}) p width |
70b88761 | 6688 | $4 = 13 |
18fae2a8 | 6689 | (@value{GDBP}) set width=47 |
70b88761 RP |
6690 | Invalid syntax in expression. |
6691 | @end example | |
1041a570 | 6692 | |
70b88761 | 6693 | @noindent |
ed447b95 RP |
6694 | The invalid expression, of course, is @samp{=47}. In |
6695 | order to actually set the program's variable @code{width}, use | |
1041a570 | 6696 | |
70b88761 | 6697 | @example |
18fae2a8 | 6698 | (@value{GDBP}) set var width=47 |
70b88761 RP |
6699 | @end example |
6700 | ||
18fae2a8 | 6701 | @value{GDBN} allows more implicit conversions in assignments than C; you can |
1041a570 | 6702 | freely store an integer value into a pointer variable or vice versa, |
ed447b95 | 6703 | and you can convert any structure to any other structure that is the |
1041a570 | 6704 | same length or shorter. |
e251e767 | 6705 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
6706 | @comment /[email protected] 18dec1990 |
6707 | ||
6708 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
6709 | construct to generate a value of specified type at a specified address | |
1041a570 | 6710 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
6711 | to memory location @code{0x83040} as an integer (which implies a certain size |
6712 | and representation in memory), and | |
6713 | ||
6714 | @example | |
6715 | set @{int@}0x83040 = 4 | |
6716 | @end example | |
6717 | ||
6718 | @noindent | |
6719 | stores the value 4 into that memory location. | |
6720 | ||
4eb4cf57 | 6721 | @node Jumping |
70b88761 RP |
6722 | @section Continuing at a Different Address |
6723 | ||
29a2b744 | 6724 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
6725 | it stopped, with the @code{continue} command. You can instead continue at |
6726 | an address of your own choosing, with the following commands: | |
6727 | ||
6728 | @table @code | |
6729 | @item jump @var{linespec} | |
6730 | @kindex jump | |
6731 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 RP |
6732 | immediately if there is a breakpoint there. @xref{List, ,Printing |
6733 | Source Lines}, for a description of the different forms of | |
6734 | @var{linespec}. | |
70b88761 RP |
6735 | |
6736 | The @code{jump} command does not change the current stack frame, or | |
6737 | the stack pointer, or the contents of any memory location or any | |
6738 | register other than the program counter. If line @var{linespec} is in | |
6739 | a different function from the one currently executing, the results may | |
6740 | be bizarre if the two functions expect different patterns of arguments or | |
6741 | of local variables. For this reason, the @code{jump} command requests | |
6742 | confirmation if the specified line is not in the function currently | |
6743 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 6744 | well acquainted with the machine-language code of your program. |
70b88761 RP |
6745 | |
6746 | @item jump *@var{address} | |
6747 | Resume execution at the instruction at address @var{address}. | |
6748 | @end table | |
6749 | ||
6750 | You can get much the same effect as the @code{jump} command by storing a | |
6751 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 6752 | does not start your program running; it only changes the address where it |
70b88761 RP |
6753 | @emph{will} run when it is continued. For example, |
6754 | ||
6755 | @example | |
6756 | set $pc = 0x485 | |
6757 | @end example | |
6758 | ||
6759 | @noindent | |
6760 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 RP |
6761 | address @code{0x485}, rather than at the address where your program stopped. |
6762 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
70b88761 RP |
6763 | |
6764 | The most common occasion to use the @code{jump} command is to back up, | |
6765 | perhaps with more breakpoints set, over a portion of a program that has | |
6766 | already executed, in order to examine its execution in more detail. | |
6767 | ||
18fae2a8 | 6768 | @ifclear BARETARGET |
70b88761 | 6769 | @c @group |
ed447b95 RP |
6770 | @node Signaling |
6771 | @section Giving your program a signal | |
70b88761 RP |
6772 | |
6773 | @table @code | |
6774 | @item signal @var{signalnum} | |
6775 | @kindex signal | |
29a2b744 | 6776 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
6777 | signal number @var{signalnum}. |
6778 | ||
6779 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 6780 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
6781 | a signal and would ordinary see the signal when resumed with the |
6782 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
6783 | signal. | |
6784 | ||
6785 | @code{signal} does not repeat when you press @key{RET} a second time | |
6786 | after executing the command. | |
6787 | @end table | |
6788 | @c @end group | |
18fae2a8 | 6789 | @end ifclear |
70b88761 | 6790 | |
4eb4cf57 | 6791 | @node Returning |
70b88761 RP |
6792 | @section Returning from a Function |
6793 | ||
6794 | @table @code | |
6795 | @item return | |
6796 | @itemx return @var{expression} | |
6797 | @cindex returning from a function | |
6798 | @kindex return | |
6799 | You can cancel execution of a function call with the @code{return} | |
6800 | command. If you give an | |
6801 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 6802 | value. |
70b88761 RP |
6803 | @end table |
6804 | ||
18fae2a8 | 6805 | When you use @code{return}, @value{GDBN} discards the selected stack frame |
70b88761 RP |
6806 | (and all frames within it). You can think of this as making the |
6807 | discarded frame return prematurely. If you wish to specify a value to | |
6808 | be returned, give that value as the argument to @code{return}. | |
6809 | ||
29a2b744 RP |
6810 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
6811 | Frame}), and any other frames inside of it, leaving its caller as the | |
6812 | innermost remaining frame. That frame becomes selected. The | |
6813 | specified value is stored in the registers used for returning values | |
6814 | of functions. | |
70b88761 RP |
6815 | |
6816 | The @code{return} command does not resume execution; it leaves the | |
6817 | program stopped in the state that would exist if the function had just | |
1041a570 RP |
6818 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
6819 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
6820 | selected stack frame returns naturally. | |
70b88761 | 6821 | |
4eb4cf57 | 6822 | @node Calling |
ed447b95 | 6823 | @section Calling program functions |
70b88761 RP |
6824 | |
6825 | @cindex calling functions | |
6826 | @kindex call | |
6827 | @table @code | |
6828 | @item call @var{expr} | |
6829 | Evaluate the expression @var{expr} without displaying @code{void} | |
6830 | returned values. | |
6831 | @end table | |
6832 | ||
6833 | You can use this variant of the @code{print} command if you want to | |
6834 | execute a function from your program, but without cluttering the output | |
6835 | with @code{void} returned values. The result is printed and saved in | |
6836 | the value history, if it is not void. | |
6837 | ||
4eb4cf57 | 6838 | @node Patching |
ed447b95 | 6839 | @section Patching programs |
c338a2fd RP |
6840 | @cindex patching binaries |
6841 | @cindex writing into executables | |
6842 | @cindex writing into corefiles | |
1041a570 | 6843 | |
18fae2a8 | 6844 | By default, @value{GDBN} opens the file containing your program's executable |
c338a2fd RP |
6845 | code (or the corefile) read-only. This prevents accidental alterations |
6846 | to machine code; but it also prevents you from intentionally patching | |
6847 | your program's binary. | |
6848 | ||
6849 | If you'd like to be able to patch the binary, you can specify that | |
6850 | explicitly with the @code{set write} command. For example, you might | |
6851 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 6852 | repairs. |
c338a2fd RP |
6853 | |
6854 | @table @code | |
6855 | @item set write on | |
6856 | @itemx set write off | |
6857 | @kindex set write | |
18fae2a8 RP |
6858 | If you specify @samp{set write on}, @value{GDBN} will open executable |
6859 | @ifclear BARETARGET | |
0f153e74 | 6860 | and core |
18fae2a8 | 6861 | @end ifclear |
0f153e74 | 6862 | files for both reading and writing; if you specify @samp{set write |
18fae2a8 | 6863 | off} (the default), @value{GDBN} will open them read-only. |
c338a2fd | 6864 | |
1041a570 | 6865 | If you have already loaded a file, you must load it |
c338a2fd RP |
6866 | again (using the @code{exec-file} or @code{core-file} command) after |
6867 | changing @code{set write}, for your new setting to take effect. | |
6868 | ||
6869 | @item show write | |
7d7ff5f6 | 6870 | @kindex show write |
0f153e74 | 6871 | Display whether executable files |
18fae2a8 | 6872 | @ifclear BARETARGET |
0f153e74 | 6873 | and core files |
18fae2a8 | 6874 | @end ifclear |
0f153e74 | 6875 | will be opened for writing as well as reading. |
c338a2fd RP |
6876 | @end table |
6877 | ||
18fae2a8 | 6878 | @node GDB Files |
93918348 | 6879 | @chapter @value{GDBN} Files |
70b88761 | 6880 | |
18fae2a8 | 6881 | @value{GDBN} needs to know the file name of the program to be debugged, both in |
4eb4cf57 | 6882 | order to read its symbol table and in order to start your program. |
18fae2a8 | 6883 | @ifclear BARETARGET |
93918348 RP |
6884 | To debug a core dump of a previous run, you must also tell @value{GDBN} |
6885 | the name of the core dump file. | |
18fae2a8 | 6886 | @end ifclear |
1041a570 | 6887 | |
70b88761 | 6888 | @menu |
ed447b95 RP |
6889 | * Files:: Commands to specify files |
6890 | * Symbol Errors:: Errors reading symbol files | |
70b88761 RP |
6891 | @end menu |
6892 | ||
4eb4cf57 | 6893 | @node Files |
70b88761 | 6894 | @section Commands to Specify Files |
70b88761 | 6895 | @cindex symbol table |
70b88761 | 6896 | |
18fae2a8 | 6897 | @ifclear BARETARGET |
0f153e74 | 6898 | @cindex core dump file |
1041a570 | 6899 | The usual way to specify executable and core dump file names is with |
ed447b95 | 6900 | the command arguments given when you start @value{GDBN} (@pxref{Invocation, |
18fae2a8 RP |
6901 | ,Getting In and Out of @value{GDBN}}. |
6902 | @end ifclear | |
6903 | @ifset BARETARGET | |
4eb4cf57 | 6904 | The usual way to specify an executable file name is with |
18fae2a8 RP |
6905 | the command argument given when you start @value{GDBN}, (@pxref{Invocation, |
6906 | ,Getting In and Out of @value{GDBN}}. | |
6907 | @end ifset | |
70b88761 RP |
6908 | |
6909 | Occasionally it is necessary to change to a different file during a | |
93918348 RP |
6910 | @value{GDBN} session. Or you may run @value{GDBN} and forget to specify |
6911 | a file you want to use. In these situations the @value{GDBN} commands | |
6912 | to specify new files are useful. | |
70b88761 RP |
6913 | |
6914 | @table @code | |
6915 | @item file @var{filename} | |
6916 | @cindex executable file | |
6917 | @kindex file | |
6918 | Use @var{filename} as the program to be debugged. It is read for its | |
6919 | symbols and for the contents of pure memory. It is also the program | |
6920 | executed when you use the @code{run} command. If you do not specify a | |
93918348 | 6921 | directory and the file is not found in the @value{GDBN} working directory, @value{GDBN} |
1041a570 RP |
6922 | uses the environment variable @code{PATH} as a list of directories to |
6923 | search, just as the shell does when looking for a program to run. You | |
18fae2a8 | 6924 | can change the value of this variable, for both @value{GDBN} and your program, |
1041a570 | 6925 | using the @code{path} command. |
70b88761 | 6926 | |
14d01801 RP |
6927 | On systems with memory-mapped files, an auxiliary symbol table file |
6928 | @file{@var{filename}.syms} may be available for @var{filename}. If it | |
18fae2a8 | 6929 | is, @value{GDBN} will map in the symbol table from |
14d01801 | 6930 | @file{@var{filename}.syms}, starting up more quickly. See the |
95d5ceb9 | 6931 | descriptions of the options @samp{-mapped} and @samp{-readnow} (available |
77b46d13 JG |
6932 | on the command line, and with the commands @code{file}, @code{symbol-file}, |
6933 | or @code{add-symbol-file}), for more information. | |
14d01801 | 6934 | |
e0dacfd1 | 6935 | @item file |
18fae2a8 | 6936 | @code{file} with no argument makes @value{GDBN} discard any information it |
70b88761 RP |
6937 | has on both executable file and the symbol table. |
6938 | ||
e0dacfd1 | 6939 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6940 | @kindex exec-file |
6941 | Specify that the program to be run (but not the symbol table) is found | |
18fae2a8 | 6942 | in @var{filename}. @value{GDBN} will search the environment variable @code{PATH} |
29a2b744 | 6943 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 6944 | discard information on the executable file. |
70b88761 | 6945 | |
e0dacfd1 | 6946 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6947 | @kindex symbol-file |
6948 | Read symbol table information from file @var{filename}. @code{PATH} is | |
6949 | searched when necessary. Use the @code{file} command to get both symbol | |
6950 | table and program to run from the same file. | |
6951 | ||
93918348 | 6952 | @code{symbol-file} with no argument clears out @value{GDBN} information on your |
70b88761 RP |
6953 | program's symbol table. |
6954 | ||
18fae2a8 | 6955 | The @code{symbol-file} command causes @value{GDBN} to forget the contents of its |
70b88761 RP |
6956 | convenience variables, the value history, and all breakpoints and |
6957 | auto-display expressions. This is because they may contain pointers to | |
6958 | the internal data recording symbols and data types, which are part of | |
18fae2a8 | 6959 | the old symbol table data being discarded inside @value{GDBN}. |
70b88761 RP |
6960 | |
6961 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
6962 | executing it once. | |
6963 | ||
18fae2a8 | 6964 | When @value{GDBN} is configured for a particular environment, it will |
14d01801 RP |
6965 | understand debugging information in whatever format is the standard |
6966 | generated for that environment; you may use either a GNU compiler, or | |
6967 | other compilers that adhere to the local conventions. Best results are | |
18fae2a8 | 6968 | usually obtained from GNU compilers; for example, using @code{@value{GCC}} |
14d01801 RP |
6969 | you can generate debugging information for optimized code. |
6970 | ||
70b88761 | 6971 | On some kinds of object files, the @code{symbol-file} command does not |
14d01801 | 6972 | normally read the symbol table in full right away. Instead, it scans |
70b88761 RP |
6973 | the symbol table quickly to find which source files and which symbols |
6974 | are present. The details are read later, one source file at a time, | |
1041a570 | 6975 | as they are needed. |
70b88761 | 6976 | |
18fae2a8 | 6977 | The purpose of this two-stage reading strategy is to make @value{GDBN} start up |
1041a570 RP |
6978 | faster. For the most part, it is invisible except for occasional |
6979 | pauses while the symbol table details for a particular source file are | |
6980 | being read. (The @code{set verbose} command can turn these pauses | |
ed447b95 | 6981 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings |
1041a570 | 6982 | and Messages}.) |
70b88761 RP |
6983 | |
6984 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
1041a570 | 6985 | read the symbol table data in full right away. We have not implemented |
70b88761 RP |
6986 | the two-stage strategy for COFF yet. |
6987 | ||
95d5ceb9 RP |
6988 | @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
6989 | @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} | |
14d01801 RP |
6990 | @kindex readnow |
6991 | @cindex reading symbols immediately | |
6992 | @cindex symbols, reading immediately | |
6993 | @kindex mapped | |
6994 | @cindex memory-mapped symbol file | |
38962738 | 6995 | @cindex saving symbol table |
18fae2a8 | 6996 | You can override the @value{GDBN} two-stage strategy for reading symbol |
95d5ceb9 | 6997 | tables by using the @samp{-readnow} option with any of the commands that |
18fae2a8 | 6998 | load symbol table information, if you want to be sure @value{GDBN} has the |
14d01801 RP |
6999 | entire symbol table available. |
7000 | ||
18fae2a8 | 7001 | @ifclear BARETARGET |
14d01801 | 7002 | If memory-mapped files are available on your system through the |
95d5ceb9 | 7003 | @code{mmap} system call, you can use another option, @samp{-mapped}, to |
18fae2a8 RP |
7004 | cause @value{GDBN} to write the symbols for your program into a reusable |
7005 | file. Future @value{GDBN} debugging sessions will map in symbol information | |
93918348 | 7006 | from this auxiliary symbol file (if the program has not changed), rather |
77b46d13 JG |
7007 | than spending time reading the symbol table from the executable |
7008 | program. Using the @samp{-mapped} option has the same effect as | |
18fae2a8 | 7009 | starting @value{GDBN} with the @samp{-mapped} command-line option. |
14d01801 | 7010 | |
95d5ceb9 | 7011 | You can use both options together, to make sure the auxiliary symbol |
14d01801 RP |
7012 | file has all the symbol information for your program. |
7013 | ||
7014 | The auxiliary symbol file for a program called @var{myprog} is called | |
7015 | @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer | |
18fae2a8 | 7016 | than the corresponding executable), @value{GDBN} will always attempt to use |
14d01801 RP |
7017 | it when you debug @var{myprog}; no special options or commands are |
7018 | needed. | |
93918348 RP |
7019 | |
7020 | The @file{.syms} file is specific to the host machine where you run | |
7021 | @value{GDBN}. It holds an exact image of the internal @value{GDB} | |
7022 | symbol table. It cannot be shared across multiple host platforms. | |
7023 | ||
14d01801 RP |
7024 | @c FIXME: for now no mention of directories, since this seems to be in |
7025 | @c flux. 13mar1992 status is that in theory GDB would look either in | |
7026 | @c current dir or in same dir as myprog; but issues like competing | |
7027 | @c GDB's, or clutter in system dirs, mean that in practice right now | |
7028 | @c only current dir is used. FFish says maybe a special GDB hierarchy | |
7029 | @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol | |
7030 | @c files. | |
70b88761 | 7031 | |
e0dacfd1 | 7032 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
7033 | @kindex core |
7034 | @kindex core-file | |
7035 | Specify the whereabouts of a core dump file to be used as the ``contents | |
7036 | of memory''. Traditionally, core files contain only some parts of the | |
18fae2a8 | 7037 | address space of the process that generated them; @value{GDBN} can access the |
70b88761 RP |
7038 | executable file itself for other parts. |
7039 | ||
7040 | @code{core-file} with no argument specifies that no core file is | |
7041 | to be used. | |
7042 | ||
7043 | Note that the core file is ignored when your program is actually running | |
18fae2a8 | 7044 | under @value{GDBN}. So, if you have been running your program and you wish to |
70b88761 RP |
7045 | debug a core file instead, you must kill the subprocess in which the |
7046 | program is running. To do this, use the @code{kill} command | |
1041a570 | 7047 | (@pxref{Kill Process, ,Killing the Child Process}). |
18fae2a8 | 7048 | @end ifclear |
70b88761 RP |
7049 | |
7050 | @item load @var{filename} | |
7051 | @kindex load | |
18fae2a8 | 7052 | @ifset GENERIC |
70b88761 | 7053 | Depending on what remote debugging facilities are configured into |
18fae2a8 | 7054 | @value{GDBN}, the @code{load} command may be available. Where it exists, it |
70b88761 RP |
7055 | is meant to make @var{filename} (an executable) available for debugging |
7056 | on the remote system---by downloading, or dynamic linking, for example. | |
93918348 | 7057 | @code{load} also records the @var{filename} symbol table in @value{GDBN}, like |
70b88761 RP |
7058 | the @code{add-symbol-file} command. |
7059 | ||
ed447b95 RP |
7060 | If your @value{GDBN} does not have a @code{load} command, attempting to |
7061 | execute it gets the error message ``@code{You can't do that when your | |
7062 | target is @dots{}}'' | |
18fae2a8 | 7063 | @end ifset |
70b88761 | 7064 | |
18fae2a8 | 7065 | @ifset VXWORKS |
70b88761 | 7066 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
18fae2a8 RP |
7067 | current target system as well as adding its symbols in @value{GDBN}. |
7068 | @end ifset | |
70b88761 | 7069 | |
18fae2a8 | 7070 | @ifset Icmlx |
70b88761 RP |
7071 | @cindex download to Nindy-960 |
7072 | With the Nindy interface to an Intel 960 board, @code{load} will | |
7073 | download @var{filename} to the 960 as well as adding its symbols in | |
18fae2a8 RP |
7074 | @value{GDBN}. |
7075 | @end ifset | |
70b88761 | 7076 | |
18fae2a8 | 7077 | @ifset Hviii |
c7cb8acb RP |
7078 | @cindex download to H8/300 |
7079 | @cindex H8/300 download | |
7080 | When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi | |
18fae2a8 | 7081 | H8/300 Remote,,@value{GDBN} and the Hitachi H8/300}), the |
c7cb8acb | 7082 | @code{load} command downloads your program to the H8/300 and also opens |
18fae2a8 | 7083 | it as the current executable target for @value{GDBN} on your host (like the |
c7cb8acb | 7084 | @code{file} command). |
18fae2a8 | 7085 | @end ifset |
c7cb8acb | 7086 | |
70b88761 RP |
7087 | @code{load} will not repeat if you press @key{RET} again after using it. |
7088 | ||
18fae2a8 | 7089 | @ifclear BARETARGET |
70b88761 | 7090 | @item add-symbol-file @var{filename} @var{address} |
95d5ceb9 | 7091 | @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
70b88761 RP |
7092 | @kindex add-symbol-file |
7093 | @cindex dynamic linking | |
7094 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 7095 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
7096 | has been dynamically loaded (by some other means) into the program that |
7097 | is running. @var{address} should be the memory address at which the | |
18fae2a8 | 7098 | file has been loaded; @value{GDBN} cannot figure this out for itself. |
70b88761 RP |
7099 | |
7100 | The symbol table of the file @var{filename} is added to the symbol table | |
7101 | originally read with the @code{symbol-file} command. You can use the | |
7102 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
7103 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 7104 | use the @code{symbol-file} command. |
70b88761 RP |
7105 | |
7106 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
7107 | ||
95d5ceb9 | 7108 | You can use the @samp{-mapped} and @samp{-readnow} options just as with |
18fae2a8 | 7109 | the @code{symbol-file} command, to change how @value{GDBN} manages the symbol |
0f153e74 | 7110 | table information for @var{filename}. |
18fae2a8 | 7111 | @end ifclear |
95d5ceb9 | 7112 | |
70b88761 RP |
7113 | @item info files |
7114 | @itemx info target | |
7115 | @kindex info files | |
7116 | @kindex info target | |
1041a570 RP |
7117 | @code{info files} and @code{info target} are synonymous; both print |
7118 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
7119 | including the names of the executable and core dump files currently in | |
18fae2a8 | 7120 | use by @value{GDBN}, and the files from which symbols were loaded. The command |
1041a570 RP |
7121 | @code{help targets} lists all possible targets rather than current |
7122 | ones. | |
70b88761 RP |
7123 | @end table |
7124 | ||
7125 | All file-specifying commands allow both absolute and relative file names | |
18fae2a8 | 7126 | as arguments. @value{GDBN} always converts the file name to an absolute path |
70b88761 RP |
7127 | name and remembers it that way. |
7128 | ||
18fae2a8 | 7129 | @ifclear BARETARGET |
70b88761 | 7130 | @cindex shared libraries |
18fae2a8 RP |
7131 | @value{GDBN} supports SunOS, SVR4, and IBM RS/6000 shared libraries. |
7132 | @value{GDBN} automatically loads symbol definitions from shared libraries | |
77b46d13 | 7133 | when you use the @code{run} command, or when you examine a core file. |
18fae2a8 | 7134 | (Before you issue the @code{run} command, @value{GDBN} will not understand |
77b46d13 JG |
7135 | references to a function in a shared library, however---unless you are |
7136 | debugging a core file). | |
18fae2a8 | 7137 | @c FIXME: next @value{GDBN} release should permit some refs to undef |
1041a570 | 7138 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
7139 | |
7140 | @table @code | |
70b88761 RP |
7141 | @item info share |
7142 | @itemx info sharedlibrary | |
7143 | @kindex info sharedlibrary | |
7144 | @kindex info share | |
c338a2fd | 7145 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 7146 | |
c338a2fd RP |
7147 | @item sharedlibrary @var{regex} |
7148 | @itemx share @var{regex} | |
7149 | @kindex sharedlibrary | |
7150 | @kindex share | |
7151 | This is an obsolescent command; you can use it to explicitly | |
7152 | load shared object library symbols for files matching a UNIX regular | |
7153 | expression, but as with files loaded automatically, it will only load | |
7154 | shared libraries required by your program for a core file or after | |
7155 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
7156 | required by your program are loaded. | |
7157 | @end table | |
18fae2a8 | 7158 | @end ifclear |
70b88761 | 7159 | |
4eb4cf57 | 7160 | @node Symbol Errors |
70b88761 | 7161 | @section Errors Reading Symbol Files |
1041a570 | 7162 | |
18fae2a8 | 7163 | While reading a symbol file, @value{GDBN} will occasionally encounter problems, |
1041a570 | 7164 | such as symbol types it does not recognize, or known bugs in compiler |
18fae2a8 | 7165 | output. By default, @value{GDBN} does not notify you of such problems, since |
1041a570 RP |
7166 | they are relatively common and primarily of interest to people |
7167 | debugging compilers. If you are interested in seeing information | |
18fae2a8 | 7168 | about ill-constructed symbol tables, you can either ask @value{GDBN} to print |
b80282d5 | 7169 | only one message about each such type of problem, no matter how many |
18fae2a8 | 7170 | times the problem occurs; or you can ask @value{GDBN} to print more messages, |
1041a570 RP |
7171 | to see how many times the problems occur, with the @code{set |
7172 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
7173 | Messages}). | |
70b88761 RP |
7174 | |
7175 | The messages currently printed, and their meanings, are: | |
7176 | ||
7177 | @table @code | |
7178 | @item inner block not inside outer block in @var{symbol} | |
7179 | ||
7180 | The symbol information shows where symbol scopes begin and end | |
7181 | (such as at the start of a function or a block of statements). This | |
7182 | error indicates that an inner scope block is not fully contained | |
e251e767 | 7183 | in its outer scope blocks. |
70b88761 | 7184 | |
18fae2a8 | 7185 | @value{GDBN} circumvents the problem by treating the inner block as if it had |
70b88761 RP |
7186 | the same scope as the outer block. In the error message, @var{symbol} |
7187 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
7188 | function. | |
7189 | ||
7190 | @item block at @var{address} out of order | |
7191 | ||
e251e767 | 7192 | The symbol information for symbol scope blocks should occur in |
70b88761 | 7193 | order of increasing addresses. This error indicates that it does not |
e251e767 | 7194 | do so. |
70b88761 | 7195 | |
ed447b95 RP |
7196 | @value{GDBN} does not circumvent this problem, and will have trouble |
7197 | locating symbols in the source file whose symbols it is reading. (You | |
7198 | can often determine what source file is affected by specifying | |
7199 | @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and | |
7200 | Messages}.) | |
70b88761 RP |
7201 | |
7202 | @item bad block start address patched | |
7203 | ||
7204 | The symbol information for a symbol scope block has a start address | |
7205 | smaller than the address of the preceding source line. This is known | |
e251e767 | 7206 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 | 7207 | |
18fae2a8 | 7208 | @value{GDBN} circumvents the problem by treating the symbol scope block as |
70b88761 RP |
7209 | starting on the previous source line. |
7210 | ||
70b88761 RP |
7211 | @item bad string table offset in symbol @var{n} |
7212 | ||
7213 | @cindex foo | |
7214 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 7215 | larger than the size of the string table. |
70b88761 | 7216 | |
18fae2a8 | 7217 | @value{GDBN} circumvents the problem by considering the symbol to have the |
70b88761 RP |
7218 | name @code{foo}, which may cause other problems if many symbols end up |
7219 | with this name. | |
7220 | ||
7221 | @item unknown symbol type @code{0x@var{nn}} | |
7222 | ||
18fae2a8 | 7223 | The symbol information contains new data types that @value{GDBN} does not yet |
70b88761 | 7224 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood |
e251e767 | 7225 | information, in hexadecimal. |
70b88761 | 7226 | |
18fae2a8 | 7227 | @value{GDBN} circumvents the error by ignoring this symbol information. This |
29a2b744 | 7228 | will usually allow your program to be debugged, though certain symbols |
70b88761 | 7229 | will not be accessible. If you encounter such a problem and feel like |
18fae2a8 | 7230 | debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint on |
70b88761 RP |
7231 | @code{complain}, then go up to the function @code{read_dbx_symtab} and |
7232 | examine @code{*bufp} to see the symbol. | |
7233 | ||
7234 | @item stub type has NULL name | |
18fae2a8 | 7235 | @value{GDBN} could not find the full definition for a struct or class. |
70b88761 | 7236 | |
440d9834 | 7237 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
7238 | |
7239 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
7240 | information that recent versions of the compiler should have output |
7241 | for it. | |
70b88761 | 7242 | |
440d9834 | 7243 | @item info mismatch between compiler and debugger |
70b88761 | 7244 | |
18fae2a8 | 7245 | @value{GDBN} could not parse a type specification output by the compiler. |
70b88761 RP |
7246 | @end table |
7247 | ||
4eb4cf57 | 7248 | @node Targets |
e251e767 | 7249 | @chapter Specifying a Debugging Target |
70b88761 RP |
7250 | @cindex debugging target |
7251 | @kindex target | |
1041a570 | 7252 | |
cedaf8bc | 7253 | A @dfn{target} is the execution environment occupied by your program. |
18fae2a8 RP |
7254 | @ifclear BARETARGET |
7255 | Often, @value{GDBN} runs in the same host environment as your program; in | |
1041a570 RP |
7256 | that case, the debugging target is specified as a side effect when you |
7257 | use the @code{file} or @code{core} commands. When you need more | |
18fae2a8 | 7258 | flexibility---for example, running @value{GDBN} on a physically separate |
1041a570 | 7259 | host, or controlling a standalone system over a serial port or a |
0f153e74 | 7260 | realtime system over a TCP/IP connection---you |
18fae2a8 RP |
7261 | @end ifclear |
7262 | @ifset BARETARGET | |
0f153e74 | 7263 | You |
18fae2a8 | 7264 | @end ifset |
0f153e74 | 7265 | can use the @code{target} command to specify one of the target types |
18fae2a8 | 7266 | configured for @value{GDBN} (@pxref{Target Commands, ,Commands for Managing |
0f153e74 | 7267 | Targets}). |
70b88761 RP |
7268 | |
7269 | @menu | |
ed447b95 RP |
7270 | * Active Targets:: Active targets |
7271 | * Target Commands:: Commands for managing targets | |
7272 | * Remote:: Remote debugging | |
70b88761 RP |
7273 | @end menu |
7274 | ||
4eb4cf57 | 7275 | @node Active Targets |
70b88761 RP |
7276 | @section Active Targets |
7277 | @cindex stacking targets | |
7278 | @cindex active targets | |
7279 | @cindex multiple targets | |
7280 | ||
18fae2a8 | 7281 | @ifclear BARETARGET |
cedaf8bc | 7282 | There are three classes of targets: processes, core files, and |
18fae2a8 | 7283 | executable files. @value{GDBN} can work concurrently on up to three active |
cedaf8bc RP |
7284 | targets, one in each class. This allows you to (for example) start a |
7285 | process and inspect its activity without abandoning your work on a core | |
7286 | file. | |
70b88761 | 7287 | |
ed447b95 | 7288 | For example, if you execute @samp{gdb a.out}, then the executable file |
cedaf8bc RP |
7289 | @code{a.out} is the only active target. If you designate a core file as |
7290 | well---presumably from a prior run that crashed and coredumped---then | |
18fae2a8 | 7291 | @value{GDBN} has two active targets and will use them in tandem, looking |
cedaf8bc RP |
7292 | first in the corefile target, then in the executable file, to satisfy |
7293 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 7294 | are complementary, since core files contain only a program's |
cedaf8bc RP |
7295 | read-write memory---variables and so on---plus machine status, while |
7296 | executable files contain only the program text and initialized data.) | |
18fae2a8 | 7297 | @end ifclear |
cedaf8bc RP |
7298 | |
7299 | When you type @code{run}, your executable file becomes an active process | |
18fae2a8 | 7300 | target as well. When a process target is active, all @value{GDBN} commands |
0f153e74 | 7301 | requesting memory addresses refer to that target; addresses in an |
18fae2a8 | 7302 | @ifclear BARETARGET |
0f153e74 | 7303 | active core file or |
18fae2a8 | 7304 | @end ifclear |
0f153e74 | 7305 | executable file target are obscured while the process |
cedaf8bc RP |
7306 | target is active. |
7307 | ||
18fae2a8 | 7308 | @ifset BARETARGET |
4eb4cf57 RP |
7309 | Use the @code{exec-file} command to select a |
7310 | new executable target (@pxref{Files, ,Commands to Specify | |
7311 | Files}). | |
18fae2a8 RP |
7312 | @end ifset |
7313 | @ifclear BARETARGET | |
1041a570 RP |
7314 | Use the @code{core-file} and @code{exec-file} commands to select a |
7315 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
7316 | Files}). To specify as a target a process that is already running, use | |
7317 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
ed447b95 | 7318 | Already-Running Process}). |
18fae2a8 | 7319 | @end ifclear |
70b88761 | 7320 | |
4eb4cf57 | 7321 | @node Target Commands |
70b88761 RP |
7322 | @section Commands for Managing Targets |
7323 | ||
7324 | @table @code | |
7325 | @item target @var{type} @var{parameters} | |
18fae2a8 | 7326 | Connects the @value{GDBN} host environment to a target machine or process. A |
70b88761 RP |
7327 | target is typically a protocol for talking to debugging facilities. You |
7328 | use the argument @var{type} to specify the type or protocol of the | |
7329 | target machine. | |
7330 | ||
7331 | Further @var{parameters} are interpreted by the target protocol, but | |
7332 | typically include things like device names or host names to connect | |
e251e767 | 7333 | with, process numbers, and baud rates. |
70b88761 RP |
7334 | |
7335 | The @code{target} command will not repeat if you press @key{RET} again | |
7336 | after executing the command. | |
7337 | ||
7338 | @item help target | |
7339 | @kindex help target | |
7340 | Displays the names of all targets available. To display targets | |
7341 | currently selected, use either @code{info target} or @code{info files} | |
29a2b744 | 7342 | (@pxref{Files, ,Commands to Specify Files}). |
70b88761 RP |
7343 | |
7344 | @item help target @var{name} | |
7345 | Describe a particular target, including any parameters necessary to | |
7346 | select it. | |
7347 | @end table | |
7348 | ||
c7cb8acb | 7349 | Here are some common targets (available, or not, depending on the GDB |
70b88761 RP |
7350 | configuration): |
7351 | ||
7352 | @table @code | |
7353 | @item target exec @var{prog} | |
7354 | @kindex target exec | |
7355 | An executable file. @samp{target exec @var{prog}} is the same as | |
7356 | @samp{exec-file @var{prog}}. | |
7357 | ||
7358 | @item target core @var{filename} | |
7359 | @kindex target core | |
7360 | A core dump file. @samp{target core @var{filename}} is the same as | |
7361 | @samp{core-file @var{filename}}. | |
7362 | ||
18fae2a8 | 7363 | @ifset REMOTESTUB |
70b88761 RP |
7364 | @item target remote @var{dev} |
7365 | @kindex target remote | |
c7cb8acb | 7366 | Remote serial target in GDB-specific protocol. The argument @var{dev} |
70b88761 | 7367 | specifies what serial device to use for the connection (e.g. |
1041a570 | 7368 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. |
18fae2a8 | 7369 | @end ifset |
70b88761 | 7370 | |
18fae2a8 | 7371 | @ifset AMDxxixK |
70b88761 RP |
7372 | @item target amd-eb @var{dev} @var{speed} @var{PROG} |
7373 | @kindex target amd-eb | |
7374 | @cindex AMD EB29K | |
7375 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
7376 | @var{dev} is the serial device, as for @code{target remote}; | |
7377 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
7378 | name of the program to be debugged, as it appears to DOS on the PC. | |
ed447b95 | 7379 | @xref{EB29K Remote, ,@value{GDBN} with a remote EB29K}. |
77fe5411 | 7380 | |
18fae2a8 RP |
7381 | @end ifset |
7382 | @ifset Hviii | |
c7cb8acb RP |
7383 | @item target hms |
7384 | @kindex target hms | |
7385 | A Hitachi H8/300 board, attached via serial line to your host. Use | |
7386 | special commands @code{device} and @code{speed} to control the serial | |
7387 | line and the communications speed used. @xref{Hitachi H8/300 | |
18fae2a8 | 7388 | Remote,,@value{GDBN} and the Hitachi H8/300}. |
c7cb8acb | 7389 | |
18fae2a8 RP |
7390 | @end ifset |
7391 | @ifset Icmlx | |
70b88761 RP |
7392 | @item target nindy @var{devicename} |
7393 | @kindex target nindy | |
7394 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
7395 | the name of the serial device to use for the connection, e.g. | |
ed447b95 | 7396 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}. |
70b88761 | 7397 | |
18fae2a8 RP |
7398 | @end ifset |
7399 | @ifset STmm | |
77fe5411 RP |
7400 | @item target st2000 @var{dev} @var{speed} |
7401 | @kindex target st2000 | |
7402 | A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev} | |
7403 | is the name of the device attached to the ST2000 serial line; | |
7404 | @var{speed} is the communication line speed. The arguments are not used | |
18fae2a8 RP |
7405 | if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet. |
7406 | @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}. | |
77fe5411 | 7407 | |
18fae2a8 RP |
7408 | @end ifset |
7409 | @ifset VXWORKS | |
70b88761 RP |
7410 | @item target vxworks @var{machinename} |
7411 | @kindex target vxworks | |
7412 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
7413 | is the target system's machine name or IP address. | |
18fae2a8 RP |
7414 | @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}. |
7415 | @end ifset | |
70b88761 RP |
7416 | @end table |
7417 | ||
18fae2a8 RP |
7418 | @ifset GENERIC |
7419 | Different targets are available on different configurations of @value{GDBN}; your | |
70b88761 | 7420 | configuration may have more or fewer targets. |
18fae2a8 | 7421 | @end ifset |
70b88761 | 7422 | |
4eb4cf57 | 7423 | @node Remote |
70b88761 RP |
7424 | @section Remote Debugging |
7425 | @cindex remote debugging | |
7426 | ||
29a2b744 | 7427 | If you are trying to debug a program running on a machine that cannot run |
c7cb8acb | 7428 | GDB in the usual way, it is often useful to use remote debugging. For |
70b88761 RP |
7429 | example, you might use remote debugging on an operating system kernel, or on |
7430 | a small system which does not have a general purpose operating system | |
e251e767 | 7431 | powerful enough to run a full-featured debugger. |
70b88761 | 7432 | |
c7cb8acb | 7433 | Some configurations of GDB have special serial or TCP/IP interfaces |
70b88761 | 7434 | to make this work with particular debugging targets. In addition, |
c7cb8acb | 7435 | GDB comes with a generic serial protocol (specific to GDB, but |
70b88761 RP |
7436 | not specific to any particular target system) which you can use if you |
7437 | write the remote stubs---the code that will run on the remote system to | |
c7cb8acb | 7438 | communicate with GDB. |
70b88761 | 7439 | |
70b88761 | 7440 | Other remote targets may be available in your |
c7cb8acb | 7441 | configuration of GDB; use @code{help targets} to list them. |
70b88761 | 7442 | |
18fae2a8 RP |
7443 | @ifset GENERIC |
7444 | @c Text on starting up GDB in various specific cases; it goes up front | |
7445 | @c in manuals configured for any of those particular situations, here | |
7446 | @c otherwise. | |
7447 | @ignore | |
7448 | @c original, intended form of this menu (pre-unfolding): | |
7449 | @menu | |
7450 | @ifset REMOTESTUB | |
7451 | * Remote Serial:: @value{GDBN} remote serial protocol | |
7452 | @end ifset | |
7453 | @ifset Icmlx | |
7454 | * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy) | |
7455 | @end ifset | |
7456 | @ifset AMDxxixK | |
7457 | * EB29K Remote:: @value{GDBN} with a remote EB29K | |
7458 | @end ifset | |
7459 | @ifset VXWORKS | |
7460 | * VxWorks Remote:: @value{GDBN} and VxWorks | |
7461 | @end ifset | |
7462 | @ifset STmm | |
7463 | * ST2000 Remote:: @value{GDBN} with a Tandem ST2000 | |
7464 | @end ifset | |
7465 | @ifset Hviii | |
7466 | * Hitachi H8/300 Remote:: @value{GDBN} and the Hitachi H8/300 | |
7467 | @end ifset | |
7468 | @ifset ZviiiK | |
7469 | * Z8000 Simulator:: @value{GDBN} and its Zilog Z8000 Simulator | |
7470 | @end ifset | |
7471 | @end menu | |
7472 | @end ignore | |
7473 | ||
7474 | @c Unfolded menus: | |
7475 | @c add as configs require, while unfolding remains necessary. | |
7476 | @c | |
7477 | @c All target details: | |
1041a570 | 7478 | @menu |
18fae2a8 RP |
7479 | * Remote Serial:: @value{GDBN} remote serial protocol |
7480 | * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy) | |
7481 | * EB29K Remote:: @value{GDBN} with a remote EB29K | |
7482 | * VxWorks Remote:: @value{GDBN} and VxWorks | |
7483 | * ST2000 Remote:: @value{GDBN} with a Tandem ST2000 | |
7484 | * Hitachi H8/300 Remote:: @value{GDBN} and the Hitachi H8/300 | |
7485 | * Z8000 Simulator:: @value{GDBN} and its Zilog Z8000 Simulator | |
1041a570 | 7486 | @end menu |
70b88761 | 7487 | |
18fae2a8 RP |
7488 | @include gdbinv-s.texi |
7489 | @end ifset | |
7490 | ||
7491 | @node Controlling GDB | |
7492 | @chapter Controlling @value{GDBN} | |
70b88761 | 7493 | |
93918348 | 7494 | You can alter the way @value{GDBN} interacts with you by using |
18fae2a8 | 7495 | the @code{set} command. For commands controlling how @value{GDBN} displays |
1041a570 | 7496 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. |
70b88761 RP |
7497 | |
7498 | @menu | |
b80282d5 | 7499 | * Prompt:: Prompt |
ed447b95 RP |
7500 | * Editing:: Command editing |
7501 | * History:: Command history | |
7502 | * Screen Size:: Screen size | |
b80282d5 | 7503 | * Numbers:: Numbers |
ed447b95 | 7504 | * Messages/Warnings:: Optional warnings and messages |
70b88761 RP |
7505 | @end menu |
7506 | ||
4eb4cf57 | 7507 | @node Prompt |
70b88761 RP |
7508 | @section Prompt |
7509 | @cindex prompt | |
1041a570 | 7510 | |
18fae2a8 RP |
7511 | @value{GDBN} indicates its readiness to read a command by printing a string |
7512 | called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You | |
70b88761 | 7513 | can change the prompt string with the @code{set prompt} command. For |
18fae2a8 RP |
7514 | instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change |
7515 | the prompt in one of the @value{GDBN}s so that you can always tell which | |
70b88761 RP |
7516 | one you are talking to. |
7517 | ||
7518 | @table @code | |
7519 | @item set prompt @var{newprompt} | |
7520 | @kindex set prompt | |
18fae2a8 | 7521 | Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth. |
70b88761 RP |
7522 | @kindex show prompt |
7523 | @item show prompt | |
7524 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
7525 | @end table | |
7526 | ||
4eb4cf57 | 7527 | @node Editing |
70b88761 RP |
7528 | @section Command Editing |
7529 | @cindex readline | |
7530 | @cindex command line editing | |
1041a570 | 7531 | |
18fae2a8 | 7532 | @value{GDBN} reads its input commands via the @dfn{readline} interface. This |
70b88761 RP |
7533 | GNU library provides consistent behavior for programs which provide a |
7534 | command line interface to the user. Advantages are @code{emacs}-style | |
7535 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
7536 | substitution, and a storage and recall of command history across | |
7537 | debugging sessions. | |
7538 | ||
18fae2a8 | 7539 | You may control the behavior of command line editing in @value{GDBN} with the |
e251e767 | 7540 | command @code{set}. |
70b88761 RP |
7541 | |
7542 | @table @code | |
7543 | @kindex set editing | |
7544 | @cindex editing | |
7545 | @item set editing | |
7546 | @itemx set editing on | |
7547 | Enable command line editing (enabled by default). | |
7548 | ||
7549 | @item set editing off | |
7550 | Disable command line editing. | |
7551 | ||
7552 | @kindex show editing | |
7553 | @item show editing | |
7554 | Show whether command line editing is enabled. | |
7555 | @end table | |
7556 | ||
4eb4cf57 | 7557 | @node History |
ed447b95 RP |
7558 | @section Command history |
7559 | ||
7560 | @value{GDBN} can keep track of the commands you type during your | |
7561 | debugging sessions, so that you can be certain of precisely what | |
7562 | happened. Use these commands to manage the @value{GDBN} command | |
7563 | history facility. | |
1041a570 | 7564 | |
70b88761 RP |
7565 | @table @code |
7566 | @cindex history substitution | |
7567 | @cindex history file | |
7568 | @kindex set history filename | |
7569 | @item set history filename @var{fname} | |
18fae2a8 RP |
7570 | Set the name of the @value{GDBN} command history file to @var{fname}. This is |
7571 | the file from which @value{GDBN} will read an initial command history | |
70b88761 RP |
7572 | list or to which it will write this list when it exits. This list is |
7573 | accessed through history expansion or through the history | |
7574 | command editing characters listed below. This file defaults to the | |
7575 | value of the environment variable @code{GDBHISTFILE}, or to | |
7576 | @file{./.gdb_history} if this variable is not set. | |
7577 | ||
7578 | @cindex history save | |
7579 | @kindex set history save | |
7580 | @item set history save | |
7581 | @itemx set history save on | |
7582 | Record command history in a file, whose name may be specified with the | |
7583 | @code{set history filename} command. By default, this option is disabled. | |
7584 | ||
7585 | @item set history save off | |
7586 | Stop recording command history in a file. | |
7587 | ||
7588 | @cindex history size | |
7589 | @kindex set history size | |
7590 | @item set history size @var{size} | |
18fae2a8 | 7591 | Set the number of commands which @value{GDBN} will keep in its history list. |
70b88761 RP |
7592 | This defaults to the value of the environment variable |
7593 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
7594 | @end table | |
7595 | ||
7596 | @cindex history expansion | |
7597 | History expansion assigns special meaning to the character @kbd{!}. | |
ed447b95 | 7598 | @ifset have-readline-appendices |
1041a570 | 7599 | @xref{Event Designators}. |
ed447b95 RP |
7600 | @end ifset |
7601 | ||
70b88761 RP |
7602 | Since @kbd{!} is also the logical not operator in C, history expansion |
7603 | is off by default. If you decide to enable history expansion with the | |
7604 | @code{set history expansion on} command, you may sometimes need to | |
7605 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
7606 | a space or a tab to prevent it from being expanded. The readline | |
7607 | history facilities will not attempt substitution on the strings | |
7608 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
7609 | ||
7610 | The commands to control history expansion are: | |
7611 | ||
7612 | @table @code | |
7613 | ||
7614 | @kindex set history expansion | |
7615 | @item set history expansion on | |
7616 | @itemx set history expansion | |
7617 | Enable history expansion. History expansion is off by default. | |
7618 | ||
7619 | @item set history expansion off | |
7620 | Disable history expansion. | |
7621 | ||
7622 | The readline code comes with more complete documentation of | |
7623 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 7624 | or @code{vi} may wish to read it. |
ed447b95 | 7625 | @ifset have-readline-appendices |
70b88761 | 7626 | @xref{Command Line Editing}. |
ed447b95 | 7627 | @end ifset |
70b88761 RP |
7628 | |
7629 | @c @group | |
7630 | @kindex show history | |
7631 | @item show history | |
7632 | @itemx show history filename | |
7633 | @itemx show history save | |
7634 | @itemx show history size | |
7635 | @itemx show history expansion | |
18fae2a8 | 7636 | These commands display the state of the @value{GDBN} history parameters. |
70b88761 RP |
7637 | @code{show history} by itself displays all four states. |
7638 | @c @end group | |
70b88761 RP |
7639 | @end table |
7640 | ||
7641 | @table @code | |
7642 | @kindex show commands | |
7643 | @item show commands | |
7644 | Display the last ten commands in the command history. | |
7645 | ||
7646 | @item show commands @var{n} | |
7647 | Print ten commands centered on command number @var{n}. | |
7648 | ||
7649 | @item show commands + | |
7650 | Print ten commands just after the commands last printed. | |
70b88761 RP |
7651 | @end table |
7652 | ||
4eb4cf57 | 7653 | @node Screen Size |
70b88761 RP |
7654 | @section Screen Size |
7655 | @cindex size of screen | |
7656 | @cindex pauses in output | |
1041a570 | 7657 | |
18fae2a8 RP |
7658 | Certain commands to @value{GDBN} may produce large amounts of information |
7659 | output to the screen. To help you read all of it, @value{GDBN} pauses and | |
70b88761 | 7660 | asks you for input at the end of each page of output. Type @key{RET} |
18fae2a8 | 7661 | when you want to continue the output. @value{GDBN} also uses the screen |
70b88761 RP |
7662 | width setting to determine when to wrap lines of output. Depending on |
7663 | what is being printed, it tries to break the line at a readable place, | |
7664 | rather than simply letting it overflow onto the following line. | |
7665 | ||
18fae2a8 | 7666 | Normally @value{GDBN} knows the size of the screen from the termcap data base |
70b88761 RP |
7667 | together with the value of the @code{TERM} environment variable and the |
7668 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
7669 | you can override it with the @code{set height} and @code{set | |
7670 | width} commands: | |
7671 | ||
7672 | @table @code | |
7673 | @item set height @var{lpp} | |
7674 | @itemx show height | |
7675 | @itemx set width @var{cpl} | |
7676 | @itemx show width | |
7677 | @kindex set height | |
7678 | @kindex set width | |
7679 | @kindex show width | |
7680 | @kindex show height | |
7681 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
7682 | a screen width of @var{cpl} characters. The associated @code{show} | |
7683 | commands display the current settings. | |
7684 | ||
18fae2a8 | 7685 | If you specify a height of zero lines, @value{GDBN} will not pause during output |
70b88761 RP |
7686 | no matter how long the output is. This is useful if output is to a file |
7687 | or to an editor buffer. | |
7688 | @end table | |
7689 | ||
4eb4cf57 | 7690 | @node Numbers |
70b88761 RP |
7691 | @section Numbers |
7692 | @cindex number representation | |
7693 | @cindex entering numbers | |
1041a570 | 7694 | |
18fae2a8 | 7695 | You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by |
70b88761 RP |
7696 | the usual conventions: octal numbers begin with @samp{0}, decimal |
7697 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
7698 | Numbers that begin with none of these are, by default, entered in base | |
7699 | 10; likewise, the default display for numbers---when no particular | |
7700 | format is specified---is base 10. You can change the default base for | |
7701 | both input and output with the @code{set radix} command. | |
7702 | ||
7703 | @table @code | |
7704 | @kindex set radix | |
7705 | @item set radix @var{base} | |
7706 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 7707 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
7708 | specified either unambiguously or using the current default radix; for |
7709 | example, any of | |
7710 | ||
7711 | @example | |
c2bbbb22 | 7712 | set radix 1010 |
70b88761 RP |
7713 | set radix 012 |
7714 | set radix 10. | |
7715 | set radix 0xa | |
7716 | @end example | |
7717 | ||
7718 | @noindent | |
7719 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
7720 | will leave the radix unchanged no matter what it was. | |
7721 | ||
7722 | @kindex show radix | |
7723 | @item show radix | |
7724 | Display the current default base for numeric input and display. | |
70b88761 RP |
7725 | @end table |
7726 | ||
4eb4cf57 | 7727 | @node Messages/Warnings |
70b88761 | 7728 | @section Optional Warnings and Messages |
1041a570 | 7729 | |
18fae2a8 | 7730 | By default, @value{GDBN} is silent about its inner workings. If you are running |
70b88761 | 7731 | on a slow machine, you may want to use the @code{set verbose} command. |
18fae2a8 | 7732 | It will make @value{GDBN} tell you when it does a lengthy internal operation, so |
1041a570 | 7733 | you will not think it has crashed. |
70b88761 | 7734 | |
1041a570 | 7735 | Currently, the messages controlled by @code{set verbose} are those |
d48da190 RP |
7736 | which announce that the symbol table for a source file is being read; |
7737 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
7738 | |
7739 | @table @code | |
7740 | @kindex set verbose | |
7741 | @item set verbose on | |
93918348 | 7742 | Enables @value{GDBN} output of certain informational messages. |
70b88761 RP |
7743 | |
7744 | @item set verbose off | |
93918348 | 7745 | Disables @value{GDBN} output of certain informational messages. |
70b88761 RP |
7746 | |
7747 | @kindex show verbose | |
7748 | @item show verbose | |
7749 | Displays whether @code{set verbose} is on or off. | |
7750 | @end table | |
7751 | ||
18fae2a8 | 7752 | By default, if @value{GDBN} encounters bugs in the symbol table of an object |
b80282d5 | 7753 | file, it is silent; but if you are debugging a compiler, you may find |
1041a570 | 7754 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). |
70b88761 RP |
7755 | |
7756 | @table @code | |
7757 | @kindex set complaints | |
7758 | @item set complaints @var{limit} | |
18fae2a8 | 7759 | Permits @value{GDBN} to output @var{limit} complaints about each type of unusual |
70b88761 RP |
7760 | symbols before becoming silent about the problem. Set @var{limit} to |
7761 | zero to suppress all complaints; set it to a large number to prevent | |
7762 | complaints from being suppressed. | |
7763 | ||
7764 | @kindex show complaints | |
7765 | @item show complaints | |
18fae2a8 | 7766 | Displays how many symbol complaints @value{GDBN} is permitted to produce. |
70b88761 RP |
7767 | @end table |
7768 | ||
18fae2a8 | 7769 | By default, @value{GDBN} is cautious, and asks what sometimes seems to be a |
70b88761 RP |
7770 | lot of stupid questions to confirm certain commands. For example, if |
7771 | you try to run a program which is already running: | |
1041a570 | 7772 | |
70b88761 | 7773 | @example |
18fae2a8 | 7774 | (@value{GDBP}) run |
70b88761 | 7775 | The program being debugged has been started already. |
e251e767 | 7776 | Start it from the beginning? (y or n) |
70b88761 RP |
7777 | @end example |
7778 | ||
29a2b744 | 7779 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
7780 | commands, you can disable this ``feature'': |
7781 | ||
7782 | @table @code | |
7783 | @kindex set confirm | |
7784 | @cindex flinching | |
7785 | @cindex confirmation | |
7786 | @cindex stupid questions | |
7787 | @item set confirm off | |
7788 | Disables confirmation requests. | |
7789 | ||
7790 | @item set confirm on | |
7791 | Enables confirmation requests (the default). | |
7792 | ||
7793 | @item show confirm | |
7794 | @kindex show confirm | |
7795 | Displays state of confirmation requests. | |
7796 | @end table | |
7797 | ||
29a2b744 | 7798 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
7799 | @cindex reloading symbols |
7800 | Some systems allow individual object files that make up your program to | |
7801 | be replaced without stopping and restarting your program. | |
18fae2a8 | 7802 | @ifset VXWORKS |
b80282d5 RP |
7803 | For example, in VxWorks you can simply recompile a defective object file |
7804 | and keep on running. | |
18fae2a8 RP |
7805 | @end ifset |
7806 | If you are running on one of these systems, you can allow @value{GDBN} to | |
1041a570 RP |
7807 | reload the symbols for automatically relinked modules: |
7808 | ||
b80282d5 RP |
7809 | @table @code |
7810 | @kindex set symbol-reloading | |
7811 | @item set symbol-reloading on | |
7812 | Replace symbol definitions for the corresponding source file when an | |
7813 | object file with a particular name is seen again. | |
7814 | ||
7815 | @item set symbol-reloading off | |
1041a570 | 7816 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 7817 | the same name. This is the default state; if you are not running on a |
b80282d5 | 7818 | system that permits automatically relinking modules, you should leave |
18fae2a8 | 7819 | @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols |
b80282d5 RP |
7820 | when linking large programs, that may contain several modules (from |
7821 | different directories or libraries) with the same name. | |
7822 | ||
7823 | @item show symbol-reloading | |
7824 | Show the current @code{on} or @code{off} setting. | |
7825 | @end table | |
7826 | ||
4eb4cf57 | 7827 | @node Sequences |
70b88761 RP |
7828 | @chapter Canned Sequences of Commands |
7829 | ||
29a2b744 | 7830 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
18fae2a8 | 7831 | Command Lists}), @value{GDBN} provides two ways to store sequences of commands |
1041a570 | 7832 | for execution as a unit: user-defined commands and command files. |
70b88761 RP |
7833 | |
7834 | @menu | |
ed447b95 RP |
7835 | * Define:: User-defined commands |
7836 | * Hooks:: User-defined command hooks | |
7837 | * Command Files:: Command files | |
7838 | * Output:: Commands for controlled output | |
70b88761 RP |
7839 | @end menu |
7840 | ||
4eb4cf57 | 7841 | @node Define |
ed447b95 | 7842 | @section User-defined commands |
70b88761 RP |
7843 | |
7844 | @cindex user-defined command | |
18fae2a8 | 7845 | A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which you |
70b88761 RP |
7846 | assign a new name as a command. This is done with the @code{define} |
7847 | command. | |
7848 | ||
7849 | @table @code | |
7850 | @item define @var{commandname} | |
7851 | @kindex define | |
7852 | Define a command named @var{commandname}. If there is already a command | |
7853 | by that name, you are asked to confirm that you want to redefine it. | |
7854 | ||
18fae2a8 | 7855 | The definition of the command is made up of other @value{GDBN} command lines, |
70b88761 RP |
7856 | which are given following the @code{define} command. The end of these |
7857 | commands is marked by a line containing @code{end}. | |
7858 | ||
7859 | @item document @var{commandname} | |
7860 | @kindex document | |
7861 | Give documentation to the user-defined command @var{commandname}. The | |
7862 | command @var{commandname} must already be defined. This command reads | |
7863 | lines of documentation just as @code{define} reads the lines of the | |
7864 | command definition, ending with @code{end}. After the @code{document} | |
7865 | command is finished, @code{help} on command @var{commandname} will print | |
7866 | the documentation you have specified. | |
7867 | ||
7868 | You may use the @code{document} command again to change the | |
7869 | documentation of a command. Redefining the command with @code{define} | |
7870 | does not change the documentation. | |
7871 | ||
7872 | @item help user-defined | |
7873 | @kindex help user-defined | |
7874 | List all user-defined commands, with the first line of the documentation | |
7875 | (if any) for each. | |
7876 | ||
4768ba62 JG |
7877 | @item show user |
7878 | @itemx show user @var{commandname} | |
7879 | @kindex show user | |
18fae2a8 | 7880 | Display the @value{GDBN} commands used to define @var{commandname} (but not its |
70b88761 RP |
7881 | documentation). If no @var{commandname} is given, display the |
7882 | definitions for all user-defined commands. | |
7883 | @end table | |
7884 | ||
7885 | User-defined commands do not take arguments. When they are executed, the | |
7886 | commands of the definition are not printed. An error in any command | |
7887 | stops execution of the user-defined command. | |
7888 | ||
7889 | Commands that would ask for confirmation if used interactively proceed | |
18fae2a8 | 7890 | without asking when used inside a user-defined command. Many @value{GDBN} commands |
70b88761 RP |
7891 | that normally print messages to say what they are doing omit the messages |
7892 | when used in a user-defined command. | |
7893 | ||
35a15d60 JG |
7894 | @node Hooks |
7895 | @section User-Defined Command Hooks | |
7896 | @cindex command files | |
7897 | ||
7898 | You may define @emph{hooks}, which are a special kind of user-defined | |
7899 | command. Whenever you run the command @samp{foo}, if the user-defined | |
7900 | command @samp{hook-foo} exists, it is executed (with no arguments) | |
7901 | before that command. | |
7902 | ||
7903 | In addition, a pseudo-command, @samp{stop} exists. Hooking this command | |
7904 | will cause your hook to be executed every time execution stops in the | |
7905 | inferior program, before breakpoint commands are run, displays are | |
7906 | printed, or the stack frame is printed. | |
7907 | ||
7908 | For example, to cause @code{SIGALRM} signals to be ignored while | |
7909 | single-stepping, but cause them to be resumed during normal execution, | |
7910 | you could do: | |
7911 | ||
7912 | @example | |
7913 | define hook-stop | |
7914 | handle SIGALRM nopass | |
7915 | end | |
7916 | ||
7917 | define hook-run | |
7918 | handle SIGALRM pass | |
7919 | end | |
7920 | ||
7921 | define hook-continue | |
7922 | handle SIGLARM pass | |
7923 | end | |
7924 | @end example | |
7925 | ||
7926 | Any single-word command in GDB can be hooked. Aliases for other commands | |
7927 | cannot be hooked (you should hook the basic command name, e.g. @code{backtrace} | |
7928 | rather than @code{bt}). If an error occurs during the execution of your | |
7929 | hook, execution of GDB commands stops and you are returned to the GDB | |
7930 | prompt (before the command that you actually typed had a chance to run). | |
7931 | ||
93918348 | 7932 | If you try to define a hook which does not match any known command, you |
35a15d60 JG |
7933 | will get a warning from the @code{define} command. |
7934 | ||
4eb4cf57 | 7935 | @node Command Files |
70b88761 RP |
7936 | @section Command Files |
7937 | ||
7938 | @cindex command files | |
18fae2a8 | 7939 | A command file for @value{GDBN} is a file of lines that are @value{GDBN} commands. Comments |
70b88761 RP |
7940 | (lines starting with @kbd{#}) may also be included. An empty line in a |
7941 | command file does nothing; it does not mean to repeat the last command, as | |
7942 | it would from the terminal. | |
7943 | ||
7944 | @cindex init file | |
18fae2a8 RP |
7945 | @cindex @file{@value{GDBINIT}} |
7946 | When you start @value{GDBN}, it automatically executes commands from its | |
7947 | @dfn{init files}. These are files named @file{@value{GDBINIT}}. @value{GDBN} reads | |
1041a570 RP |
7948 | the init file (if any) in your home directory and then the init file |
7949 | (if any) in the current working directory. (The init files are not | |
7950 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
7951 | ,Choosing Modes}.) You can also request the execution of a command | |
7952 | file with the @code{source} command: | |
70b88761 RP |
7953 | |
7954 | @table @code | |
7955 | @item source @var{filename} | |
7956 | @kindex source | |
7957 | Execute the command file @var{filename}. | |
7958 | @end table | |
7959 | ||
7960 | The lines in a command file are executed sequentially. They are not | |
7961 | printed as they are executed. An error in any command terminates execution | |
7962 | of the command file. | |
7963 | ||
7964 | Commands that would ask for confirmation if used interactively proceed | |
18fae2a8 | 7965 | without asking when used in a command file. Many @value{GDBN} commands that |
70b88761 RP |
7966 | normally print messages to say what they are doing omit the messages |
7967 | when called from command files. | |
7968 | ||
4eb4cf57 | 7969 | @node Output |
70b88761 RP |
7970 | @section Commands for Controlled Output |
7971 | ||
7972 | During the execution of a command file or a user-defined command, normal | |
18fae2a8 | 7973 | @value{GDBN} output is suppressed; the only output that appears is what is |
70b88761 RP |
7974 | explicitly printed by the commands in the definition. This section |
7975 | describes three commands useful for generating exactly the output you | |
7976 | want. | |
7977 | ||
7978 | @table @code | |
7979 | @item echo @var{text} | |
7980 | @kindex echo | |
29a2b744 RP |
7981 | @c I do not consider backslash-space a standard C escape sequence |
7982 | @c because it is not in ANSI. | |
1041a570 RP |
7983 | Print @var{text}. Nonprinting characters can be included in |
7984 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
7985 | newline. @strong{No newline will be printed unless you specify one.} | |
7986 | In addition to the standard C escape sequences, a backslash followed | |
ed447b95 | 7987 | by a space stands for a space. This is useful for displaying a |
1041a570 RP |
7988 | string with spaces at the beginning or the end, since leading and |
7989 | trailing spaces are otherwise trimmed from all arguments. | |
7990 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
7991 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
7992 | |
7993 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7994 | the command onto subsequent lines. For example, | |
7995 | ||
7996 | @example | |
7997 | echo This is some text\n\ | |
7998 | which is continued\n\ | |
7999 | onto several lines.\n | |
8000 | @end example | |
8001 | ||
8002 | produces the same output as | |
8003 | ||
8004 | @example | |
8005 | echo This is some text\n | |
8006 | echo which is continued\n | |
8007 | echo onto several lines.\n | |
8008 | @end example | |
8009 | ||
8010 | @item output @var{expression} | |
8011 | @kindex output | |
8012 | Print the value of @var{expression} and nothing but that value: no | |
8013 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 8014 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 8015 | expressions. |
70b88761 RP |
8016 | |
8017 | @item output/@var{fmt} @var{expression} | |
8018 | Print the value of @var{expression} in format @var{fmt}. You can use | |
ed447b95 RP |
8019 | the same formats as for @code{print}. @xref{Output Formats,,Output |
8020 | formats}, for more information. | |
70b88761 RP |
8021 | |
8022 | @item printf @var{string}, @var{expressions}@dots{} | |
8023 | @kindex printf | |
8024 | Print the values of the @var{expressions} under the control of | |
8025 | @var{string}. The @var{expressions} are separated by commas and may | |
8026 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 8027 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
8028 | |
8029 | @example | |
8030 | printf (@var{string}, @var{expressions}@dots{}); | |
8031 | @end example | |
8032 | ||
8033 | For example, you can print two values in hex like this: | |
8034 | ||
0fd24984 | 8035 | @smallexample |
70b88761 | 8036 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo |
0fd24984 | 8037 | @end smallexample |
70b88761 RP |
8038 | |
8039 | The only backslash-escape sequences that you can use in the format | |
8040 | string are the simple ones that consist of backslash followed by a | |
8041 | letter. | |
8042 | @end table | |
8043 | ||
18fae2a8 | 8044 | @ifclear DOSHOST |
4eb4cf57 | 8045 | @node Emacs |
18fae2a8 | 8046 | @chapter Using @value{GDBN} under GNU Emacs |
70b88761 RP |
8047 | |
8048 | @cindex emacs | |
8049 | A special interface allows you to use GNU Emacs to view (and | |
8050 | edit) the source files for the program you are debugging with | |
18fae2a8 | 8051 | @value{GDBN}. |
70b88761 RP |
8052 | |
8053 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
8054 | executable file you want to debug as an argument. This command starts | |
18fae2a8 | 8055 | @value{GDBN} as a subprocess of Emacs, with input and output through a newly |
70b88761 RP |
8056 | created Emacs buffer. |
8057 | ||
18fae2a8 | 8058 | Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two |
70b88761 RP |
8059 | things: |
8060 | ||
8061 | @itemize @bullet | |
8062 | @item | |
e251e767 | 8063 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
8064 | @end itemize |
8065 | ||
18fae2a8 | 8066 | This applies both to @value{GDBN} commands and their output, and to the input |
70b88761 RP |
8067 | and output done by the program you are debugging. |
8068 | ||
8069 | This is useful because it means that you can copy the text of previous | |
8070 | commands and input them again; you can even use parts of the output | |
8071 | in this way. | |
8072 | ||
3d3ab540 RP |
8073 | All the facilities of Emacs' Shell mode are available for interacting |
8074 | with your program. In particular, you can send signals the usual | |
8075 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
8076 | stop. | |
70b88761 RP |
8077 | |
8078 | @itemize @bullet | |
8079 | @item | |
18fae2a8 | 8080 | @value{GDBN} displays source code through Emacs. |
70b88761 RP |
8081 | @end itemize |
8082 | ||
18fae2a8 RP |
8083 | Each time @value{GDBN} displays a stack frame, Emacs automatically finds the |
8084 | source file for that frame and puts an arrow (@samp{=>}) at the | |
70b88761 | 8085 | left margin of the current line. Emacs uses a separate buffer for |
18fae2a8 | 8086 | source display, and splits the window to show both your @value{GDBN} session |
70b88761 RP |
8087 | and the source. |
8088 | ||
18fae2a8 | 8089 | Explicit @value{GDBN} @code{list} or search commands still produce output as |
70b88761 RP |
8090 | usual, but you probably will have no reason to use them. |
8091 | ||
8092 | @quotation | |
8093 | @emph{Warning:} If the directory where your program resides is not your | |
8094 | current directory, it can be easy to confuse Emacs about the location of | |
8095 | the source files, in which case the auxiliary display buffer will not | |
18fae2a8 RP |
8096 | appear to show your source. @value{GDBN} can find programs by searching your |
8097 | environment's @code{PATH} variable, so the @value{GDBN} input and output | |
29a2b744 | 8098 | session will proceed normally; but Emacs does not get enough information |
18fae2a8 RP |
8099 | back from @value{GDBN} to locate the source files in this situation. To |
8100 | avoid this problem, either start @value{GDBN} mode from the directory where | |
70b88761 RP |
8101 | your program resides, or specify a full path name when prompted for the |
8102 | @kbd{M-x gdb} argument. | |
8103 | ||
18fae2a8 | 8104 | A similar confusion can result if you use the @value{GDBN} @code{file} command to |
70b88761 | 8105 | switch to debugging a program in some other location, from an existing |
18fae2a8 | 8106 | @value{GDBN} buffer in Emacs. |
70b88761 RP |
8107 | @end quotation |
8108 | ||
8109 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
18fae2a8 | 8110 | you need to call @value{GDBN} by a different name (for example, if you keep |
70b88761 RP |
8111 | several configurations around, with different names) you can set the |
8112 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 8113 | |
70b88761 RP |
8114 | @example |
8115 | (setq gdb-command-name "mygdb") | |
8116 | @end example | |
1041a570 | 8117 | |
70b88761 RP |
8118 | @noindent |
8119 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
8120 | in your @file{.emacs} file) will make Emacs call the program named | |
8121 | ``@code{mygdb}'' instead. | |
8122 | ||
18fae2a8 | 8123 | In the @value{GDBN} I/O buffer, you can use these special Emacs commands in |
70b88761 RP |
8124 | addition to the standard Shell mode commands: |
8125 | ||
8126 | @table @kbd | |
8127 | @item C-h m | |
18fae2a8 | 8128 | Describe the features of Emacs' @value{GDBN} Mode. |
70b88761 RP |
8129 | |
8130 | @item M-s | |
18fae2a8 | 8131 | Execute to another source line, like the @value{GDBN} @code{step} command; also |
70b88761 RP |
8132 | update the display window to show the current file and location. |
8133 | ||
8134 | @item M-n | |
8135 | Execute to next source line in this function, skipping all function | |
18fae2a8 | 8136 | calls, like the @value{GDBN} @code{next} command. Then update the display window |
70b88761 RP |
8137 | to show the current file and location. |
8138 | ||
8139 | @item M-i | |
18fae2a8 | 8140 | Execute one instruction, like the @value{GDBN} @code{stepi} command; update |
70b88761 RP |
8141 | display window accordingly. |
8142 | ||
8143 | @item M-x gdb-nexti | |
18fae2a8 | 8144 | Execute to next instruction, using the @value{GDBN} @code{nexti} command; update |
70b88761 RP |
8145 | display window accordingly. |
8146 | ||
8147 | @item C-c C-f | |
18fae2a8 | 8148 | Execute until exit from the selected stack frame, like the @value{GDBN} |
70b88761 RP |
8149 | @code{finish} command. |
8150 | ||
8151 | @item M-c | |
18fae2a8 | 8152 | Continue execution of your program, like the @value{GDBN} @code{continue} |
1041a570 | 8153 | command. |
203eea5d RP |
8154 | |
8155 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
8156 | |
8157 | @item M-u | |
8158 | Go up the number of frames indicated by the numeric argument | |
8159 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
18fae2a8 | 8160 | like the @value{GDBN} @code{up} command. |
203eea5d | 8161 | |
1041a570 | 8162 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
8163 | |
8164 | @item M-d | |
8165 | Go down the number of frames indicated by the numeric argument, like the | |
18fae2a8 | 8166 | @value{GDBN} @code{down} command. |
203eea5d RP |
8167 | |
8168 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
8169 | |
8170 | @item C-x & | |
8171 | Read the number where the cursor is positioned, and insert it at the end | |
18fae2a8 | 8172 | of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code |
70b88761 RP |
8173 | around an address that was displayed earlier, type @kbd{disassemble}; |
8174 | then move the cursor to the address display, and pick up the | |
e251e767 | 8175 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 | 8176 | |
ed447b95 | 8177 | You can customize this further by defining elements of the list |
70b88761 RP |
8178 | @code{gdb-print-command}; once it is defined, you can format or |
8179 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 8180 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
8181 | wish special formatting, and act as an index to pick an element of the |
8182 | list. If the list element is a string, the number to be inserted is | |
8183 | formatted using the Emacs function @code{format}; otherwise the number | |
8184 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
8185 | @end table |
8186 | ||
8187 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
18fae2a8 | 8188 | tells @value{GDBN} to set a breakpoint on the source line point is on. |
70b88761 RP |
8189 | |
8190 | If you accidentally delete the source-display buffer, an easy way to get | |
18fae2a8 | 8191 | it back is to type the command @code{f} in the @value{GDBN} buffer, to |
70b88761 RP |
8192 | request a frame display; when you run under Emacs, this will recreate |
8193 | the source buffer if necessary to show you the context of the current | |
8194 | frame. | |
8195 | ||
8196 | The source files displayed in Emacs are in ordinary Emacs buffers | |
8197 | which are visiting the source files in the usual way. You can edit | |
18fae2a8 | 8198 | the files with these buffers if you wish; but keep in mind that @value{GDBN} |
70b88761 | 8199 | communicates with Emacs in terms of line numbers. If you add or |
18fae2a8 | 8200 | delete lines from the text, the line numbers that @value{GDBN} knows will cease |
ed447b95 | 8201 | to correspond properly with the code. |
70b88761 RP |
8202 | |
8203 | @c The following dropped because Epoch is nonstandard. Reactivate | |
8204 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
8205 | @ignore | |
e251e767 | 8206 | @kindex emacs epoch environment |
70b88761 RP |
8207 | @kindex epoch |
8208 | @kindex inspect | |
8209 | ||
8210 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
8211 | environment. Users of this environment can use a new command, | |
8212 | @code{inspect} which performs identically to @code{print} except that | |
8213 | each value is printed in its own window. | |
8214 | @end ignore | |
18fae2a8 | 8215 | @end ifclear |
70b88761 | 8216 | |
18fae2a8 | 8217 | @ifset LUCID |
4eb4cf57 | 8218 | @node Energize |
18fae2a8 | 8219 | @chapter Using @value{GDBN} with Energize |
6ca72cc6 RP |
8220 | |
8221 | @cindex Energize | |
8222 | The Energize Programming System is an integrated development environment | |
8223 | that includes a point-and-click interface to many programming tools. | |
18fae2a8 RP |
8224 | When you use @value{GDBN} in this environment, you can use the standard |
8225 | Energize graphical interface to drive @value{GDBN}; you can also, if you | |
8226 | choose, type @value{GDBN} commands as usual in a debugging window. Even if | |
6ca72cc6 | 8227 | you use the graphical interface, the debugging window (which uses Emacs, |
18fae2a8 | 8228 | and resembles the standard Emacs interface to @value{GDBN}) displays the |
6ca72cc6 RP |
8229 | equivalent commands, so that the history of your debugging session is |
8230 | properly reflected. | |
8231 | ||
18fae2a8 | 8232 | When Energize starts up a @value{GDBN} session, it uses one of the |
6ca72cc6 RP |
8233 | command-line options @samp{-energize} or @samp{-cadillac} (``cadillac'' |
8234 | is the name of the communications protocol used by the Energize system). | |
18fae2a8 | 8235 | This option makes @value{GDBN} run as one of the tools in the Energize Tool |
6ca72cc6 RP |
8236 | Set: it sends all output to the Energize kernel, and accept input from |
8237 | it as well. | |
8238 | ||
8239 | See the user manual for the Energize Programming System for | |
8240 | information on how to use the Energize graphical interface and the other | |
18fae2a8 | 8241 | development tools that Energize integrates with @value{GDBN}. |
6ca72cc6 | 8242 | |
18fae2a8 | 8243 | @end ifset |
4eb4cf57 | 8244 | |
18fae2a8 RP |
8245 | @node GDB Bugs |
8246 | @chapter Reporting Bugs in @value{GDBN} | |
ed447b95 RP |
8247 | @cindex bugs in @value{GDBN} |
8248 | @cindex reporting bugs in @value{GDBN} | |
70b88761 | 8249 | |
18fae2a8 | 8250 | Your bug reports play an essential role in making @value{GDBN} reliable. |
70b88761 RP |
8251 | |
8252 | Reporting a bug may help you by bringing a solution to your problem, or it | |
8253 | may not. But in any case the principal function of a bug report is to help | |
18fae2a8 RP |
8254 | the entire community by making the next version of @value{GDBN} work better. Bug |
8255 | reports are your contribution to the maintenance of @value{GDBN}. | |
70b88761 RP |
8256 | |
8257 | In order for a bug report to serve its purpose, you must include the | |
8258 | information that enables us to fix the bug. | |
8259 | ||
8260 | @menu | |
ed447b95 RP |
8261 | * Bug Criteria:: Have you found a bug? |
8262 | * Bug Reporting:: How to report bugs | |
70b88761 RP |
8263 | @end menu |
8264 | ||
4eb4cf57 | 8265 | @node Bug Criteria |
70b88761 | 8266 | @section Have You Found a Bug? |
ed447b95 | 8267 | @cindex bug criteria |
70b88761 RP |
8268 | |
8269 | If you are not sure whether you have found a bug, here are some guidelines: | |
8270 | ||
8271 | @itemize @bullet | |
8272 | @item | |
0f153e74 RP |
8273 | @cindex fatal signal |
8274 | @cindex core dump | |
70b88761 | 8275 | If the debugger gets a fatal signal, for any input whatever, that is a |
18fae2a8 | 8276 | @value{GDBN} bug. Reliable debuggers never crash. |
70b88761 RP |
8277 | |
8278 | @item | |
0f153e74 | 8279 | @cindex error on valid input |
18fae2a8 | 8280 | If @value{GDBN} produces an error message for valid input, that is a bug. |
70b88761 RP |
8281 | |
8282 | @item | |
ed447b95 | 8283 | @cindex invalid input |
18fae2a8 | 8284 | If @value{GDBN} does not produce an error message for invalid input, |
70b88761 RP |
8285 | that is a bug. However, you should note that your idea of |
8286 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
8287 | for traditional practice''. | |
8288 | ||
8289 | @item | |
8290 | If you are an experienced user of debugging tools, your suggestions | |
18fae2a8 | 8291 | for improvement of @value{GDBN} are welcome in any case. |
70b88761 RP |
8292 | @end itemize |
8293 | ||
4eb4cf57 | 8294 | @node Bug Reporting |
70b88761 | 8295 | @section How to Report Bugs |
0f153e74 | 8296 | @cindex bug reports |
18fae2a8 | 8297 | @cindex @value{GDBN} bugs, reporting |
70b88761 RP |
8298 | |
8299 | A number of companies and individuals offer support for GNU products. | |
18fae2a8 | 8300 | If you obtained @value{GDBN} from a support organization, we recommend you |
e251e767 | 8301 | contact that organization first. |
70b88761 | 8302 | |
ed447b95 RP |
8303 | You can find contact information for many support companies and |
8304 | individuals in the file @file{etc/SERVICE} in the GNU Emacs | |
8305 | distribution. | |
70b88761 | 8306 | |
18fae2a8 | 8307 | In any event, we also recommend that you send bug reports for @value{GDBN} to one |
70b88761 RP |
8308 | of these addresses: |
8309 | ||
8310 | @example | |
8311 | bug-gdb@@prep.ai.mit.edu | |
8312 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
8313 | @end example | |
8314 | ||
8315 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
18fae2a8 | 8316 | @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do not want to |
70b88761 RP |
8317 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. |
8318 | ||
3d3ab540 RP |
8319 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
8320 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
8321 | the same messages. Often people think of posting bug reports to the | |
8322 | newsgroup instead of mailing them. This appears to work, but it has one | |
8323 | problem which can be crucial: a newsgroup posting often lacks a mail | |
8324 | path back to the sender. Thus, if we need to ask for more information, | |
8325 | we may be unable to reach you. For this reason, it is better to send | |
8326 | bug reports to the mailing list. | |
70b88761 RP |
8327 | |
8328 | As a last resort, send bug reports on paper to: | |
8329 | ||
8330 | @example | |
8331 | GNU Debugger Bugs | |
3d3ab540 | 8332 | Free Software Foundation |
70b88761 RP |
8333 | 545 Tech Square |
8334 | Cambridge, MA 02139 | |
8335 | @end example | |
8336 | ||
8337 | The fundamental principle of reporting bugs usefully is this: | |
8338 | @strong{report all the facts}. If you are not sure whether to state a | |
8339 | fact or leave it out, state it! | |
8340 | ||
8341 | Often people omit facts because they think they know what causes the | |
29a2b744 | 8342 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 8343 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 8344 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
8345 | stray memory reference which happens to fetch from the location where that |
8346 | name is stored in memory; perhaps, if the name were different, the contents | |
8347 | of that location would fool the debugger into doing the right thing despite | |
8348 | the bug. Play it safe and give a specific, complete example. That is the | |
8349 | easiest thing for you to do, and the most helpful. | |
8350 | ||
8351 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 8352 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
8353 | the bug is already known. Therefore, always write your bug reports on |
8354 | the assumption that the bug has not been reported previously. | |
8355 | ||
8356 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
8357 | bell?'' Those bug reports are useless, and we urge everyone to | |
8358 | @emph{refuse to respond to them} except to chide the sender to report | |
8359 | bugs properly. | |
8360 | ||
8361 | To enable us to fix the bug, you should include all these things: | |
8362 | ||
8363 | @itemize @bullet | |
8364 | @item | |
18fae2a8 | 8365 | The version of @value{GDBN}. @value{GDBN} announces it if you start with no |
70b88761 RP |
8366 | arguments; you can also print it at any time using @code{show version}. |
8367 | ||
1041a570 | 8368 | Without this, we will not know whether there is any point in looking for |
18fae2a8 | 8369 | the bug in the current version of @value{GDBN}. |
70b88761 RP |
8370 | |
8371 | @item | |
ddf21240 JG |
8372 | The type of machine you are using, and the operating system name and |
8373 | version number. | |
70b88761 RP |
8374 | |
8375 | @item | |
18fae2a8 RP |
8376 | What compiler (and its version) was used to compile @value{GDBN}---e.g. |
8377 | ``@value{GCC}--2.0''. | |
70b88761 | 8378 | |
ddf21240 JG |
8379 | @item |
8380 | What compiler (and its version) was used to compile the program you | |
18fae2a8 | 8381 | are debugging---e.g. ``@value{GCC}--2.0''. |
ddf21240 | 8382 | |
70b88761 RP |
8383 | @item |
8384 | The command arguments you gave the compiler to compile your example and | |
8385 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 8386 | you will not omit something important, list them all. A copy of the |
ddf21240 | 8387 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
8388 | |
8389 | If we were to try to guess the arguments, we would probably guess wrong | |
8390 | and then we might not encounter the bug. | |
8391 | ||
8392 | @item | |
ddf21240 JG |
8393 | A complete input script, and all necessary source files, that will |
8394 | reproduce the bug. | |
70b88761 RP |
8395 | |
8396 | @item | |
8397 | A description of what behavior you observe that you believe is | |
8398 | incorrect. For example, ``It gets a fatal signal.'' | |
8399 | ||
18fae2a8 | 8400 | Of course, if the bug is that @value{GDBN} gets a fatal signal, then we will |
70b88761 RP |
8401 | certainly notice it. But if the bug is incorrect output, we might not |
8402 | notice unless it is glaringly wrong. We are human, after all. You | |
8403 | might as well not give us a chance to make a mistake. | |
8404 | ||
8405 | Even if the problem you experience is a fatal signal, you should still | |
8406 | say so explicitly. Suppose something strange is going on, such as, | |
18fae2a8 | 8407 | your copy of @value{GDBN} is out of synch, or you have encountered a |
70b88761 RP |
8408 | bug in the C library on your system. (This has happened!) Your copy |
8409 | might crash and ours would not. If you told us to expect a crash, | |
8410 | then when ours fails to crash, we would know that the bug was not | |
8411 | happening for us. If you had not told us to expect a crash, then we | |
8412 | would not be able to draw any conclusion from our observations. | |
8413 | ||
8414 | @item | |
18fae2a8 RP |
8415 | If you wish to suggest changes to the @value{GDBN} source, send us context |
8416 | diffs. If you even discuss something in the @value{GDBN} source, refer to | |
70b88761 RP |
8417 | it by context, not by line number. |
8418 | ||
1041a570 | 8419 | The line numbers in our development sources will not match those in your |
70b88761 | 8420 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
8421 | @end itemize |
8422 | ||
8423 | Here are some things that are not necessary: | |
8424 | ||
8425 | @itemize @bullet | |
8426 | @item | |
8427 | A description of the envelope of the bug. | |
8428 | ||
8429 | Often people who encounter a bug spend a lot of time investigating | |
8430 | which changes to the input file will make the bug go away and which | |
8431 | changes will not affect it. | |
8432 | ||
8433 | This is often time consuming and not very useful, because the way we | |
8434 | will find the bug is by running a single example under the debugger | |
8435 | with breakpoints, not by pure deduction from a series of examples. | |
8436 | We recommend that you save your time for something else. | |
8437 | ||
8438 | Of course, if you can find a simpler example to report @emph{instead} | |
8439 | of the original one, that is a convenience for us. Errors in the | |
8440 | output will be easier to spot, running under the debugger will take | |
e251e767 | 8441 | less time, etc. |
70b88761 | 8442 | |
29a2b744 | 8443 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
8444 | report the bug anyway and send us the entire test case you used. |
8445 | ||
8446 | @item | |
8447 | A patch for the bug. | |
8448 | ||
29a2b744 | 8449 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
8450 | the necessary information, such as the test case, on the assumption that |
8451 | a patch is all we need. We might see problems with your patch and decide | |
8452 | to fix the problem another way, or we might not understand it at all. | |
8453 | ||
18fae2a8 | 8454 | Sometimes with a program as complicated as @value{GDBN} it is very hard to |
70b88761 | 8455 | construct an example that will make the program follow a certain path |
1041a570 RP |
8456 | through the code. If you do not send us the example, we will not be able |
8457 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 8458 | |
29a2b744 | 8459 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 8460 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
8461 | help us to understand. |
8462 | ||
8463 | @item | |
8464 | A guess about what the bug is or what it depends on. | |
8465 | ||
29a2b744 | 8466 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
8467 | things without first using the debugger to find the facts. |
8468 | @end itemize | |
8469 | ||
ed447b95 | 8470 | @ifset have-readline-appendices |
cacf5942 RP |
8471 | @include rluser.texinfo |
8472 | @include inc-hist.texi | |
ed447b95 | 8473 | @end ifset |
70b88761 | 8474 | |
18fae2a8 | 8475 | @ifset NOVEL |
4eb4cf57 | 8476 | @node Renamed Commands |
70b88761 RP |
8477 | @appendix Renamed Commands |
8478 | ||
c7cb8acb | 8479 | The following commands were renamed in GDB 4, in order to make the |
70b88761 RP |
8480 | command set as a whole more consistent and easier to use and remember: |
8481 | ||
e251e767 RP |
8482 | @kindex add-syms |
8483 | @kindex delete environment | |
8484 | @kindex info copying | |
8485 | @kindex info convenience | |
8486 | @kindex info directories | |
8487 | @kindex info editing | |
8488 | @kindex info history | |
8489 | @kindex info targets | |
8490 | @kindex info values | |
8491 | @kindex info version | |
8492 | @kindex info warranty | |
8493 | @kindex set addressprint | |
8494 | @kindex set arrayprint | |
8495 | @kindex set prettyprint | |
8496 | @kindex set screen-height | |
8497 | @kindex set screen-width | |
8498 | @kindex set unionprint | |
8499 | @kindex set vtblprint | |
8500 | @kindex set demangle | |
8501 | @kindex set asm-demangle | |
8502 | @kindex set sevenbit-strings | |
8503 | @kindex set array-max | |
8504 | @kindex set caution | |
8505 | @kindex set history write | |
8506 | @kindex show addressprint | |
8507 | @kindex show arrayprint | |
8508 | @kindex show prettyprint | |
8509 | @kindex show screen-height | |
8510 | @kindex show screen-width | |
8511 | @kindex show unionprint | |
8512 | @kindex show vtblprint | |
8513 | @kindex show demangle | |
8514 | @kindex show asm-demangle | |
8515 | @kindex show sevenbit-strings | |
8516 | @kindex show array-max | |
8517 | @kindex show caution | |
8518 | @kindex show history write | |
8519 | @kindex unset | |
70b88761 | 8520 | |
92b73793 | 8521 | @c TEXI2ROFF-KILL |
70b88761 | 8522 | @ifinfo |
92b73793 | 8523 | @c END TEXI2ROFF-KILL |
cf496415 RP |
8524 | @example |
8525 | OLD COMMAND NEW COMMAND | |
92b73793 | 8526 | @c TEXI2ROFF-KILL |
cf496415 | 8527 | --------------- ------------------------------- |
92b73793 | 8528 | @c END TEXI2ROFF-KILL |
cf496415 RP |
8529 | add-syms add-symbol-file |
8530 | delete environment unset environment | |
8531 | info convenience show convenience | |
8532 | info copying show copying | |
e251e767 | 8533 | info directories show directories |
cf496415 RP |
8534 | info editing show commands |
8535 | info history show values | |
8536 | info targets help target | |
8537 | info values show values | |
8538 | info version show version | |
8539 | info warranty show warranty | |
8540 | set/show addressprint set/show print address | |
8541 | set/show array-max set/show print elements | |
8542 | set/show arrayprint set/show print array | |
8543 | set/show asm-demangle set/show print asm-demangle | |
8544 | set/show caution set/show confirm | |
8545 | set/show demangle set/show print demangle | |
8546 | set/show history write set/show history save | |
8547 | set/show prettyprint set/show print pretty | |
8548 | set/show screen-height set/show height | |
8549 | set/show screen-width set/show width | |
8550 | set/show sevenbit-strings set/show print sevenbit-strings | |
8551 | set/show unionprint set/show print union | |
8552 | set/show vtblprint set/show print vtbl | |
8553 | ||
8554 | unset [No longer an alias for delete] | |
8555 | @end example | |
92b73793 | 8556 | @c TEXI2ROFF-KILL |
70b88761 RP |
8557 | @end ifinfo |
8558 | ||
8559 | @tex | |
8560 | \vskip \parskip\vskip \baselineskip | |
8561 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
8562 | {\bf Old Command} &&{\bf New Command}\cr | |
8563 | add-syms &&add-symbol-file\cr | |
8564 | delete environment &&unset environment\cr | |
8565 | info convenience &&show convenience\cr | |
8566 | info copying &&show copying\cr | |
8567 | info directories &&show directories \cr | |
8568 | info editing &&show commands\cr | |
8569 | info history &&show values\cr | |
8570 | info targets &&help target\cr | |
8571 | info values &&show values\cr | |
8572 | info version &&show version\cr | |
8573 | info warranty &&show warranty\cr | |
8574 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
8575 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
8576 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
8577 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
8578 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
8579 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
8580 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
8581 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
8582 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
8583 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
8584 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
8585 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
8586 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
8587 | \cr | |
8588 | unset &&\rm(No longer an alias for delete)\cr | |
8589 | } | |
8590 | @end tex | |
92b73793 | 8591 | @c END TEXI2ROFF-KILL |
18fae2a8 | 8592 | @end ifset |
70b88761 | 8593 | |
18fae2a8 | 8594 | @ifclear PRECONFIGURED |
4eb4cf57 | 8595 | @node Formatting Documentation |
77b46d13 JG |
8596 | @appendix Formatting the Documentation |
8597 | ||
8598 | @cindex GDB reference card | |
8599 | @cindex reference card | |
8600 | The GDB 4 release includes an already-formatted reference card, ready | |
b1385986 | 8601 | for printing with PostScript or GhostScript, in the @file{gdb} |
ed447b95 RP |
8602 | subdirectory of the main source directory@footnote{In |
8603 | @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN} | |
8604 | release.}. If you can use PostScript or GhostScript with your printer, | |
8605 | you can print the reference card immediately with @file{refcard.ps}. | |
77b46d13 JG |
8606 | |
8607 | The release also includes the source for the reference card. You | |
8608 | can format it, using @TeX{}, by typing: | |
8609 | ||
8610 | @example | |
8611 | make refcard.dvi | |
8612 | @end example | |
8613 | ||
8614 | The GDB reference card is designed to print in landscape mode on US | |
8615 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
8616 | high. You will need to specify this form of printing as an option to | |
8617 | your @sc{dvi} output program. | |
8618 | ||
8619 | @cindex documentation | |
8620 | ||
8621 | All the documentation for GDB comes as part of the machine-readable | |
8622 | distribution. The documentation is written in Texinfo format, which is | |
8623 | a documentation system that uses a single source file to produce both | |
8624 | on-line information and a printed manual. You can use one of the Info | |
8625 | formatting commands to create the on-line version of the documentation | |
8626 | and @TeX{} (or @code{texi2roff}) to typeset the printed version. | |
8627 | ||
8628 | GDB includes an already formatted copy of the on-line Info version of | |
8629 | this manual in the @file{gdb} subdirectory. The main Info file is | |
8630 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
a89f94c2 RP |
8631 | subordinate files matching @samp{gdb.info*} in the same directory. If |
8632 | necessary, you can print out these files, or read them with any editor; | |
8633 | but they are easier to read using the @code{info} subsystem in GNU Emacs | |
8634 | or the standalone @code{info} program, available as part of the GNU | |
8635 | Texinfo distribution. | |
77b46d13 JG |
8636 | |
8637 | If you want to format these Info files yourself, you need one of the | |
8638 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
8639 | @code{makeinfo}. | |
8640 | ||
8641 | If you have @code{makeinfo} installed, and are in the top level GDB | |
18fae2a8 | 8642 | source directory (@file{gdb-@value{GDBVN}}, in the case of version @value{GDBVN}), you can |
77b46d13 JG |
8643 | make the Info file by typing: |
8644 | ||
8645 | @example | |
8646 | cd gdb | |
8647 | make gdb.info | |
8648 | @end example | |
8649 | ||
8650 | If you want to typeset and print copies of this manual, you need | |
8651 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
8652 | the Texinfo definitions file. | |
8653 | ||
83bfcbae | 8654 | @TeX{} is a typesetting program; it does not print files directly, but |
77b46d13 JG |
8655 | produces output files called @sc{dvi} files. To print a typeset |
8656 | document, you need a program to print @sc{dvi} files. If your system | |
8657 | has @TeX{} installed, chances are it has such a program. The precise | |
8658 | command to use depends on your system; @kbd{lpr -d} is common; another | |
8659 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
8660 | without any extension or a @samp{.dvi} extension. | |
8661 | ||
8662 | @TeX{} also requires a macro definitions file called | |
8663 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
8664 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
8665 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
8666 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
8667 | directory. | |
8668 | ||
8669 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
8670 | typeset and print this manual. First switch to the the @file{gdb} | |
8671 | subdirectory of the main source directory (for example, to | |
18fae2a8 | 8672 | @file{gdb-@value{GDBVN}/gdb}) and then type: |
77b46d13 JG |
8673 | |
8674 | @example | |
8675 | make gdb.dvi | |
8676 | @end example | |
8677 | ||
4eb4cf57 | 8678 | @node Installing GDB |
c7cb8acb RP |
8679 | @appendix Installing GDB |
8680 | @cindex configuring GDB | |
70b88761 RP |
8681 | @cindex installation |
8682 | ||
ed447b95 RP |
8683 | GDB comes with a @code{configure} script that automates the process |
8684 | of preparing GDB for installation; you can then use @code{make} to | |
8685 | build the @code{gdb} program. | |
f672bb7f RP |
8686 | @iftex |
8687 | @c irrelevant in info file; it's as current as the code it lives with. | |
ed447b95 RP |
8688 | @footnote{If you have a more recent version of GDB than @value{GDBVN}, |
8689 | look at the @file{README} file in the sources; we may have improved the | |
8690 | installation procedures since publishing this manual.} | |
f672bb7f RP |
8691 | @end iftex |
8692 | ||
c7cb8acb | 8693 | The GDB distribution includes all the source code you need for GDB in |
1041a570 RP |
8694 | a single directory, whose name is usually composed by appending the |
8695 | version number to @samp{gdb}. | |
8696 | ||
ed447b95 RP |
8697 | For example, the GDB version @value{GDBVN} distribution is in the |
8698 | @file{gdb-@value{GDBVN}} directory. That directory contains: | |
b80282d5 | 8699 | |
3d3ab540 | 8700 | @table @code |
18fae2a8 | 8701 | @item gdb-@value{GDBVN}/configure @r{(and supporting files)} |
c7cb8acb | 8702 | script for configuring GDB and all its supporting libraries. |
b80282d5 | 8703 | |
18fae2a8 | 8704 | @item gdb-@value{GDBVN}/gdb |
c7cb8acb | 8705 | the source specific to GDB itself |
3d3ab540 | 8706 | |
18fae2a8 | 8707 | @item gdb-@value{GDBVN}/bfd |
77b46d13 | 8708 | source for the Binary File Descriptor library |
3d3ab540 | 8709 | |
18fae2a8 | 8710 | @item gdb-@value{GDBVN}/include |
b80282d5 | 8711 | GNU include files |
3d3ab540 | 8712 | |
18fae2a8 | 8713 | @item gdb-@value{GDBVN}/libiberty |
3d3ab540 RP |
8714 | source for the @samp{-liberty} free software library |
8715 | ||
18fae2a8 | 8716 | @item gdb-@value{GDBVN}/opcodes |
3214c51c JG |
8717 | source for the library of opcode tables and disassemblers |
8718 | ||
18fae2a8 | 8719 | @item gdb-@value{GDBVN}/readline |
b80282d5 | 8720 | source for the GNU command-line interface |
77b46d13 | 8721 | |
18fae2a8 | 8722 | @item gdb-@value{GDBVN}/glob |
77b46d13 JG |
8723 | source for the GNU filename pattern-matching subroutine |
8724 | ||
18fae2a8 | 8725 | @item gdb-@value{GDBVN}/mmalloc |
77b46d13 | 8726 | source for the GNU memory-mapped malloc package |
3d3ab540 | 8727 | @end table |
1041a570 | 8728 | |
c7cb8acb | 8729 | The simplest way to configure and build GDB is to run @code{configure} |
1041a570 | 8730 | from the @file{gdb-@var{version-number}} source directory, which in |
18fae2a8 | 8731 | this example is the @file{gdb-@value{GDBVN}} directory. |
1041a570 RP |
8732 | |
8733 | First switch to the @file{gdb-@var{version-number}} source directory | |
8734 | if you are not already in it; then run @code{configure}. Pass the | |
c7cb8acb | 8735 | identifier for the platform on which GDB will run as an |
1041a570 RP |
8736 | argument. |
8737 | ||
8738 | For example: | |
8739 | ||
7463aadd | 8740 | @example |
18fae2a8 | 8741 | cd gdb-@value{GDBVN} |
3d3ab540 | 8742 | ./configure @var{host} |
7463aadd RP |
8743 | make |
8744 | @end example | |
1041a570 | 8745 | |
7463aadd | 8746 | @noindent |
1041a570 | 8747 | where @var{host} is an identifier such as @samp{sun4} or |
c7cb8acb | 8748 | @samp{decstation}, that identifies the platform where GDB will run. |
1041a570 | 8749 | |
38962738 RP |
8750 | Running @samp{configure @var{host}} followed by @code{make} builds the |
8751 | @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty} | |
8752 | libraries, then @code{gdb} itself. The configured source files, and the | |
8753 | binaries, are left in the corresponding source directories. | |
3d3ab540 | 8754 | |
e251e767 | 8755 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 8756 | system does not recognize this automatically when you run a different |
1041a570 RP |
8757 | shell, you may need to run @code{sh} on it explicitly: |
8758 | ||
8759 | @example | |
8760 | sh configure @var{host} | |
8761 | @end example | |
e251e767 | 8762 | |
f672bb7f RP |
8763 | If you run @code{configure} from a directory that contains source |
8764 | directories for multiple libraries or programs, such as the | |
18fae2a8 | 8765 | @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure} |
f672bb7f | 8766 | creates configuration files for every directory level underneath (unless |
98349959 | 8767 | you tell it not to, with the @samp{--norecursion} option). |
f672bb7f RP |
8768 | |
8769 | You can run the @code{configure} script from any of the | |
c7cb8acb | 8770 | subordinate directories in the GDB distribution, if you only want to |
1041a570 RP |
8771 | configure that subdirectory; but be sure to specify a path to it. |
8772 | ||
18fae2a8 | 8773 | For example, with version @value{GDBVN}, type the following to configure only |
1041a570 RP |
8774 | the @code{bfd} subdirectory: |
8775 | ||
e251e767 | 8776 | @example |
203eea5d | 8777 | @group |
18fae2a8 | 8778 | cd gdb-@value{GDBVN}/bfd |
e251e767 | 8779 | ../configure @var{host} |
203eea5d | 8780 | @end group |
e251e767 RP |
8781 | @end example |
8782 | ||
18fae2a8 | 8783 | You can install @code{@value{GDBP}} anywhere; it has no hardwired paths. |
1041a570 RP |
8784 | However, you should make sure that the shell on your path (named by |
8785 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
c7cb8acb RP |
8786 | that GDB uses the shell to start your program---some systems refuse to |
8787 | let GDB debug child processes whose programs are not readable. | |
3d3ab540 RP |
8788 | |
8789 | @menu | |
c7cb8acb | 8790 | * Separate Objdir:: Compiling GDB in another directory |
b80282d5 RP |
8791 | * Config Names:: Specifying names for hosts and targets |
8792 | * configure Options:: Summary of options for configure | |
3d3ab540 RP |
8793 | @end menu |
8794 | ||
4eb4cf57 | 8795 | @node Separate Objdir |
c7cb8acb | 8796 | @section Compiling GDB in Another Directory |
1041a570 | 8797 | |
c7cb8acb | 8798 | If you want to run GDB versions for several host or target machines, |
ed447b95 | 8799 | you need a different @code{gdb} compiled for each combination of |
1041a570 | 8800 | host and target. @code{configure} is designed to make this easy by |
f672bb7f RP |
8801 | allowing you to generate each configuration in a separate subdirectory, |
8802 | rather than in the source directory. If your @code{make} program | |
8803 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
ed447b95 | 8804 | @code{make} in each of these directories builds the @code{gdb} |
f672bb7f | 8805 | program specified there. |
b80282d5 | 8806 | |
c7cb8acb | 8807 | To build @code{gdb} in a separate directory, run @code{configure} |
f672bb7f | 8808 | with the @samp{--srcdir} option to specify where to find the source. |
93918348 | 8809 | (You also need to specify a path to find @code{configure} |
77b46d13 JG |
8810 | itself from your working directory. If the path to @code{configure} |
8811 | would be the same as the argument to @samp{--srcdir}, you can leave out | |
8812 | the @samp{--srcdir} option; it will be assumed.) | |
1041a570 | 8813 | |
18fae2a8 | 8814 | For example, with version @value{GDBVN}, you can build GDB in a separate |
f672bb7f | 8815 | directory for a Sun 4 like this: |
70b88761 RP |
8816 | |
8817 | @example | |
3d3ab540 | 8818 | @group |
18fae2a8 | 8819 | cd gdb-@value{GDBVN} |
f672bb7f RP |
8820 | mkdir ../gdb-sun4 |
8821 | cd ../gdb-sun4 | |
18fae2a8 | 8822 | ../gdb-@value{GDBVN}/configure sun4 |
70b88761 | 8823 | make |
3d3ab540 | 8824 | @end group |
70b88761 RP |
8825 | @end example |
8826 | ||
f672bb7f RP |
8827 | When @code{configure} builds a configuration using a remote source |
8828 | directory, it creates a tree for the binaries with the same structure | |
8829 | (and using the same names) as the tree under the source directory. In | |
8830 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
c7cb8acb | 8831 | directory @file{gdb-sun4/libiberty}, and GDB itself in |
f672bb7f | 8832 | @file{gdb-sun4/gdb}. |
1041a570 | 8833 | |
38962738 | 8834 | One popular reason to build several GDB configurations in separate |
c7cb8acb | 8835 | directories is to configure GDB for cross-compiling (where GDB |
f672bb7f RP |
8836 | runs on one machine---the host---while debugging programs that run on |
8837 | another machine---the target). You specify a cross-debugging target by | |
8838 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
c7637ea6 | 8839 | |
1041a570 | 8840 | When you run @code{make} to build a program or library, you must run |
f672bb7f RP |
8841 | it in a configured directory---whatever directory you were in when you |
8842 | called @code{configure} (or one of its subdirectories). | |
c7637ea6 RP |
8843 | |
8844 | The @code{Makefile} generated by @code{configure} for each source | |
f672bb7f | 8845 | directory also runs recursively. If you type @code{make} in a source |
18fae2a8 RP |
8846 | directory such as @file{gdb-@value{GDBVN}} (or in a separate configured |
8847 | directory configured with @samp{--srcdir=@var{path}/gdb-@value{GDBVN}}), you | |
ed447b95 | 8848 | will build all the required libraries, and then build GDB. |
3d3ab540 | 8849 | |
f672bb7f RP |
8850 | When you have multiple hosts or targets configured in separate |
8851 | directories, you can run @code{make} on them in parallel (for example, | |
8852 | if they are NFS-mounted on each of the hosts); they will not interfere | |
8853 | with each other. | |
3d3ab540 | 8854 | |
4eb4cf57 | 8855 | @node Config Names |
b80282d5 RP |
8856 | @section Specifying Names for Hosts and Targets |
8857 | ||
8858 | The specifications used for hosts and targets in the @code{configure} | |
8859 | script are based on a three-part naming scheme, but some short predefined | |
8860 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 8861 | of information in the following pattern: |
1041a570 | 8862 | |
b80282d5 RP |
8863 | @example |
8864 | @var{architecture}-@var{vendor}-@var{os} | |
8865 | @end example | |
8866 | ||
8867 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
5e3186ab | 8868 | or in a @code{--target=@var{target}} option, but the equivalent full name |
e251e767 | 8869 | is @samp{sparc-sun-sunos4}. |
b80282d5 | 8870 | |
c7cb8acb | 8871 | The @code{configure} script accompanying GDB does not provide |
b80282d5 RP |
8872 | any query facility to list all supported host and target names or |
8873 | aliases. @code{configure} calls the Bourne shell script | |
8874 | @code{config.sub} to map abbreviations to full names; you can read the | |
8875 | script, if you wish, or you can use it to test your guesses on | |
8876 | abbreviations---for example: | |
1041a570 | 8877 | |
b1385986 | 8878 | @smallexample |
b80282d5 | 8879 | % sh config.sub sun4 |
6a8cb0e7 | 8880 | sparc-sun-sunos411 |
b80282d5 | 8881 | % sh config.sub sun3 |
6a8cb0e7 | 8882 | m68k-sun-sunos411 |
b80282d5 | 8883 | % sh config.sub decstation |
6a8cb0e7 | 8884 | mips-dec-ultrix42 |
b80282d5 RP |
8885 | % sh config.sub hp300bsd |
8886 | m68k-hp-bsd | |
8887 | % sh config.sub i386v | |
6a8cb0e7 | 8888 | i386-unknown-sysv |
e94b4a2b | 8889 | % sh config.sub i786v |
6a8cb0e7 | 8890 | Invalid configuration `i786v': machine `i786v' not recognized |
b1385986 | 8891 | @end smallexample |
1041a570 | 8892 | |
c7637ea6 | 8893 | @noindent |
1041a570 | 8894 | @code{config.sub} is also distributed in the GDB source |
18fae2a8 | 8895 | directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}). |
b80282d5 | 8896 | |
4eb4cf57 | 8897 | @node configure Options |
3d3ab540 | 8898 | @section @code{configure} Options |
7463aadd | 8899 | |
d48da190 | 8900 | Here is a summary of the @code{configure} options and arguments that |
18fae2a8 | 8901 | are most often useful for building @value{GDBN}. @code{configure} also has |
d48da190 RP |
8902 | several other options not listed here. @inforef{What Configure |
8903 | Does,,configure.info}, for a full explanation of @code{configure}. | |
8904 | @c FIXME: Would this be more, or less, useful as an xref (ref to printed | |
8905 | @c manual in the printed manual, ref to info file only from the info file)? | |
7463aadd RP |
8906 | |
8907 | @example | |
d48da190 RP |
8908 | configure @r{[}--help@r{]} |
8909 | @r{[}--prefix=@var{dir}@r{]} | |
8910 | @r{[}--srcdir=@var{path}@r{]} | |
f672bb7f RP |
8911 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} |
8912 | @r{[}--target=@var{target}@r{]} @var{host} | |
7463aadd | 8913 | @end example |
1041a570 | 8914 | |
3d3ab540 | 8915 | @noindent |
f672bb7f RP |
8916 | You may introduce options with a single @samp{-} rather than |
8917 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
8918 | @samp{--}. | |
70b88761 RP |
8919 | |
8920 | @table @code | |
d48da190 RP |
8921 | @item --help |
8922 | Display a quick summary of how to invoke @code{configure}. | |
8923 | ||
8924 | @item -prefix=@var{dir} | |
8925 | Configure the source to install programs and files under directory | |
8926 | @file{@var{dir}}. | |
8927 | ||
f672bb7f | 8928 | @item --srcdir=@var{path} |
6ca72cc6 RP |
8929 | @strong{Warning: using this option requires GNU @code{make}, or another |
8930 | @code{make} that implements the @code{VPATH} feature.}@* | |
f672bb7f | 8931 | Use this option to make configurations in directories separate from the |
c7cb8acb | 8932 | GDB source directories. Among other things, you can use this to |
f672bb7f RP |
8933 | build (or maintain) several configurations simultaneously, in separate |
8934 | directories. @code{configure} writes configuration specific files in | |
8935 | the current directory, but arranges for them to use the source in the | |
8936 | directory @var{path}. @code{configure} will create directories under | |
8937 | the working directory in parallel to the source directories below | |
8938 | @var{path}. | |
8939 | ||
8940 | @item --norecursion | |
8941 | Configure only the directory level where @code{configure} is executed; do not | |
7463aadd RP |
8942 | propagate configuration to subdirectories. |
8943 | ||
f672bb7f | 8944 | @item --rm |
b80282d5 | 8945 | Remove the configuration that the other arguments specify. |
7463aadd | 8946 | |
29a2b744 | 8947 | @c This does not work (yet if ever). FIXME. |
f672bb7f | 8948 | @c @item --parse=@var{lang} @dots{} |
c7cb8acb RP |
8949 | @c Configure the GDB expression parser to parse the listed languages. |
8950 | @c @samp{all} configures GDB for all supported languages. To get a | |
d7b569d5 | 8951 | @c list of all supported languages, omit the argument. Without this |
c7cb8acb | 8952 | @c option, GDB is configured to parse all supported languages. |
c2bbbb22 | 8953 | |
f672bb7f | 8954 | @item --target=@var{target} |
c7cb8acb RP |
8955 | Configure GDB for cross-debugging programs running on the specified |
8956 | @var{target}. Without this option, GDB is configured to debug | |
8957 | programs that run on the same machine (@var{host}) as GDB itself. | |
b80282d5 RP |
8958 | |
8959 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
8960 | |
8961 | @item @var{host} @dots{} | |
c7cb8acb | 8962 | Configure GDB to run on the specified @var{host}. |
b80282d5 RP |
8963 | |
8964 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
8965 | @end table |
8966 | ||
3d3ab540 RP |
8967 | @noindent |
8968 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 8969 | configuring other GNU tools recursively; but these are the only |
c7cb8acb | 8970 | options that affect GDB or its supporting libraries. |
18fae2a8 | 8971 | @end ifclear |
3d3ab540 | 8972 | |
18fae2a8 | 8973 | @ifclear AGGLOMERATION |
4eb4cf57 | 8974 | @node Copying |
70b88761 | 8975 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 8976 | @center Version 2, June 1991 |
70b88761 RP |
8977 | |
8978 | @display | |
7463aadd | 8979 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
8980 | 675 Mass Ave, Cambridge, MA 02139, USA |
8981 | ||
8982 | Everyone is permitted to copy and distribute verbatim copies | |
8983 | of this license document, but changing it is not allowed. | |
8984 | @end display | |
8985 | ||
8986 | @unnumberedsec Preamble | |
8987 | ||
7463aadd RP |
8988 | The licenses for most software are designed to take away your |
8989 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 8990 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
8991 | software---to make sure the software is free for all its users. This |
8992 | General Public License applies to most of the Free Software | |
8993 | Foundation's software and to any other program whose authors commit to | |
8994 | using it. (Some other Free Software Foundation software is covered by | |
8995 | the GNU Library General Public License instead.) You can apply it to | |
8996 | your programs, too. | |
70b88761 RP |
8997 | |
8998 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
8999 | price. Our General Public Licenses are designed to make sure that you |
9000 | have the freedom to distribute copies of free software (and charge for | |
9001 | this service if you wish), that you receive source code or can get it | |
9002 | if you want it, that you can change the software or use pieces of it | |
9003 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
9004 | |
9005 | To protect your rights, we need to make restrictions that forbid | |
9006 | anyone to deny you these rights or to ask you to surrender the rights. | |
9007 | These restrictions translate to certain responsibilities for you if you | |
9008 | distribute copies of the software, or if you modify it. | |
9009 | ||
7463aadd | 9010 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
9011 | gratis or for a fee, you must give the recipients all the rights that |
9012 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
9013 | source code. And you must show them these terms so they know their |
9014 | rights. | |
70b88761 RP |
9015 | |
9016 | We protect your rights with two steps: (1) copyright the software, and | |
9017 | (2) offer you this license which gives you legal permission to copy, | |
9018 | distribute and/or modify the software. | |
9019 | ||
9020 | Also, for each author's protection and ours, we want to make certain | |
9021 | that everyone understands that there is no warranty for this free | |
9022 | software. If the software is modified by someone else and passed on, we | |
9023 | want its recipients to know that what they have is not the original, so | |
9024 | that any problems introduced by others will not reflect on the original | |
9025 | authors' reputations. | |
9026 | ||
7463aadd RP |
9027 | Finally, any free program is threatened constantly by software |
9028 | patents. We wish to avoid the danger that redistributors of a free | |
9029 | program will individually obtain patent licenses, in effect making the | |
9030 | program proprietary. To prevent this, we have made it clear that any | |
9031 | patent must be licensed for everyone's free use or not licensed at all. | |
9032 | ||
70b88761 RP |
9033 | The precise terms and conditions for copying, distribution and |
9034 | modification follow. | |
9035 | ||
9036 | @iftex | |
7463aadd | 9037 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
9038 | @end iftex |
9039 | @ifinfo | |
7463aadd | 9040 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
9041 | @end ifinfo |
9042 | ||
9043 | @enumerate | |
9044 | @item | |
7463aadd RP |
9045 | This License applies to any program or other work which contains |
9046 | a notice placed by the copyright holder saying it may be distributed | |
9047 | under the terms of this General Public License. The ``Program'', below, | |
9048 | refers to any such program or work, and a ``work based on the Program'' | |
9049 | means either the Program or any derivative work under copyright law: | |
9050 | that is to say, a work containing the Program or a portion of it, | |
9051 | either verbatim or with modifications and/or translated into another | |
9052 | language. (Hereinafter, translation is included without limitation in | |
9053 | the term ``modification''.) Each licensee is addressed as ``you''. | |
9054 | ||
9055 | Activities other than copying, distribution and modification are not | |
9056 | covered by this License; they are outside its scope. The act of | |
9057 | running the Program is not restricted, and the output from the Program | |
9058 | is covered only if its contents constitute a work based on the | |
9059 | Program (independent of having been made by running the Program). | |
9060 | Whether that is true depends on what the Program does. | |
70b88761 RP |
9061 | |
9062 | @item | |
7463aadd RP |
9063 | You may copy and distribute verbatim copies of the Program's |
9064 | source code as you receive it, in any medium, provided that you | |
9065 | conspicuously and appropriately publish on each copy an appropriate | |
9066 | copyright notice and disclaimer of warranty; keep intact all the | |
9067 | notices that refer to this License and to the absence of any warranty; | |
9068 | and give any other recipients of the Program a copy of this License | |
9069 | along with the Program. | |
70b88761 | 9070 | |
7463aadd RP |
9071 | You may charge a fee for the physical act of transferring a copy, and |
9072 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 9073 | |
70b88761 | 9074 | @item |
7463aadd RP |
9075 | You may modify your copy or copies of the Program or any portion |
9076 | of it, thus forming a work based on the Program, and copy and | |
9077 | distribute such modifications or work under the terms of Section 1 | |
9078 | above, provided that you also meet all of these conditions: | |
70b88761 | 9079 | |
1041a570 | 9080 | @enumerate a |
70b88761 | 9081 | @item |
7463aadd RP |
9082 | You must cause the modified files to carry prominent notices |
9083 | stating that you changed the files and the date of any change. | |
70b88761 RP |
9084 | |
9085 | @item | |
7463aadd RP |
9086 | You must cause any work that you distribute or publish, that in |
9087 | whole or in part contains or is derived from the Program or any | |
9088 | part thereof, to be licensed as a whole at no charge to all third | |
9089 | parties under the terms of this License. | |
70b88761 RP |
9090 | |
9091 | @item | |
7463aadd RP |
9092 | If the modified program normally reads commands interactively |
9093 | when run, you must cause it, when started running for such | |
9094 | interactive use in the most ordinary way, to print or display an | |
9095 | announcement including an appropriate copyright notice and a | |
9096 | notice that there is no warranty (or else, saying that you provide | |
9097 | a warranty) and that users may redistribute the program under | |
9098 | these conditions, and telling the user how to view a copy of this | |
9099 | License. (Exception: if the Program itself is interactive but | |
9100 | does not normally print such an announcement, your work based on | |
9101 | the Program is not required to print an announcement.) | |
1041a570 | 9102 | @end enumerate |
7463aadd RP |
9103 | |
9104 | These requirements apply to the modified work as a whole. If | |
9105 | identifiable sections of that work are not derived from the Program, | |
9106 | and can be reasonably considered independent and separate works in | |
9107 | themselves, then this License, and its terms, do not apply to those | |
9108 | sections when you distribute them as separate works. But when you | |
9109 | distribute the same sections as part of a whole which is a work based | |
9110 | on the Program, the distribution of the whole must be on the terms of | |
9111 | this License, whose permissions for other licensees extend to the | |
9112 | entire whole, and thus to each and every part regardless of who wrote it. | |
9113 | ||
9114 | Thus, it is not the intent of this section to claim rights or contest | |
9115 | your rights to work written entirely by you; rather, the intent is to | |
9116 | exercise the right to control the distribution of derivative or | |
9117 | collective works based on the Program. | |
9118 | ||
9119 | In addition, mere aggregation of another work not based on the Program | |
9120 | with the Program (or with a work based on the Program) on a volume of | |
9121 | a storage or distribution medium does not bring the other work under | |
9122 | the scope of this License. | |
70b88761 RP |
9123 | |
9124 | @item | |
7463aadd RP |
9125 | You may copy and distribute the Program (or a work based on it, |
9126 | under Section 2) in object code or executable form under the terms of | |
9127 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 9128 | |
1041a570 | 9129 | @enumerate a |
70b88761 | 9130 | @item |
7463aadd RP |
9131 | Accompany it with the complete corresponding machine-readable |
9132 | source code, which must be distributed under the terms of Sections | |
9133 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
9134 | |
9135 | @item | |
7463aadd RP |
9136 | Accompany it with a written offer, valid for at least three |
9137 | years, to give any third party, for a charge no more than your | |
9138 | cost of physically performing source distribution, a complete | |
9139 | machine-readable copy of the corresponding source code, to be | |
9140 | distributed under the terms of Sections 1 and 2 above on a medium | |
9141 | customarily used for software interchange; or, | |
70b88761 RP |
9142 | |
9143 | @item | |
7463aadd RP |
9144 | Accompany it with the information you received as to the offer |
9145 | to distribute corresponding source code. (This alternative is | |
70b88761 | 9146 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
9147 | received the program in object code or executable form with such |
9148 | an offer, in accord with Subsection b above.) | |
1041a570 | 9149 | @end enumerate |
7463aadd RP |
9150 | |
9151 | The source code for a work means the preferred form of the work for | |
9152 | making modifications to it. For an executable work, complete source | |
9153 | code means all the source code for all modules it contains, plus any | |
9154 | associated interface definition files, plus the scripts used to | |
9155 | control compilation and installation of the executable. However, as a | |
9156 | special exception, the source code distributed need not include | |
9157 | anything that is normally distributed (in either source or binary | |
9158 | form) with the major components (compiler, kernel, and so on) of the | |
9159 | operating system on which the executable runs, unless that component | |
9160 | itself accompanies the executable. | |
9161 | ||
9162 | If distribution of executable or object code is made by offering | |
9163 | access to copy from a designated place, then offering equivalent | |
9164 | access to copy the source code from the same place counts as | |
9165 | distribution of the source code, even though third parties are not | |
9166 | compelled to copy the source along with the object code. | |
70b88761 RP |
9167 | |
9168 | @item | |
7463aadd RP |
9169 | You may not copy, modify, sublicense, or distribute the Program |
9170 | except as expressly provided under this License. Any attempt | |
9171 | otherwise to copy, modify, sublicense or distribute the Program is | |
9172 | void, and will automatically terminate your rights under this License. | |
9173 | However, parties who have received copies, or rights, from you under | |
9174 | this License will not have their licenses terminated so long as such | |
9175 | parties remain in full compliance. | |
70b88761 RP |
9176 | |
9177 | @item | |
7463aadd RP |
9178 | You are not required to accept this License, since you have not |
9179 | signed it. However, nothing else grants you permission to modify or | |
9180 | distribute the Program or its derivative works. These actions are | |
9181 | prohibited by law if you do not accept this License. Therefore, by | |
9182 | modifying or distributing the Program (or any work based on the | |
9183 | Program), you indicate your acceptance of this License to do so, and | |
9184 | all its terms and conditions for copying, distributing or modifying | |
9185 | the Program or works based on it. | |
70b88761 RP |
9186 | |
9187 | @item | |
9188 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
9189 | Program), the recipient automatically receives a license from the |
9190 | original licensor to copy, distribute or modify the Program subject to | |
9191 | these terms and conditions. You may not impose any further | |
9192 | restrictions on the recipients' exercise of the rights granted herein. | |
9193 | You are not responsible for enforcing compliance by third parties to | |
9194 | this License. | |
9195 | ||
9196 | @item | |
9197 | If, as a consequence of a court judgment or allegation of patent | |
9198 | infringement or for any other reason (not limited to patent issues), | |
9199 | conditions are imposed on you (whether by court order, agreement or | |
9200 | otherwise) that contradict the conditions of this License, they do not | |
9201 | excuse you from the conditions of this License. If you cannot | |
9202 | distribute so as to satisfy simultaneously your obligations under this | |
9203 | License and any other pertinent obligations, then as a consequence you | |
9204 | may not distribute the Program at all. For example, if a patent | |
9205 | license would not permit royalty-free redistribution of the Program by | |
9206 | all those who receive copies directly or indirectly through you, then | |
9207 | the only way you could satisfy both it and this License would be to | |
9208 | refrain entirely from distribution of the Program. | |
9209 | ||
9210 | If any portion of this section is held invalid or unenforceable under | |
9211 | any particular circumstance, the balance of the section is intended to | |
9212 | apply and the section as a whole is intended to apply in other | |
9213 | circumstances. | |
9214 | ||
9215 | It is not the purpose of this section to induce you to infringe any | |
9216 | patents or other property right claims or to contest validity of any | |
9217 | such claims; this section has the sole purpose of protecting the | |
9218 | integrity of the free software distribution system, which is | |
9219 | implemented by public license practices. Many people have made | |
9220 | generous contributions to the wide range of software distributed | |
9221 | through that system in reliance on consistent application of that | |
9222 | system; it is up to the author/donor to decide if he or she is willing | |
9223 | to distribute software through any other system and a licensee cannot | |
9224 | impose that choice. | |
9225 | ||
9226 | This section is intended to make thoroughly clear what is believed to | |
9227 | be a consequence of the rest of this License. | |
9228 | ||
9229 | @item | |
9230 | If the distribution and/or use of the Program is restricted in | |
9231 | certain countries either by patents or by copyrighted interfaces, the | |
9232 | original copyright holder who places the Program under this License | |
9233 | may add an explicit geographical distribution limitation excluding | |
9234 | those countries, so that distribution is permitted only in or among | |
9235 | countries not thus excluded. In such case, this License incorporates | |
9236 | the limitation as if written in the body of this License. | |
70b88761 RP |
9237 | |
9238 | @item | |
9239 | The Free Software Foundation may publish revised and/or new versions | |
9240 | of the General Public License from time to time. Such new versions will | |
9241 | be similar in spirit to the present version, but may differ in detail to | |
9242 | address new problems or concerns. | |
9243 | ||
9244 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 9245 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
9246 | later version'', you have the option of following the terms and conditions |
9247 | either of that version or of any later version published by the Free | |
9248 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 9249 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
9250 | Foundation. |
9251 | ||
9252 | @item | |
9253 | If you wish to incorporate parts of the Program into other free | |
9254 | programs whose distribution conditions are different, write to the author | |
9255 | to ask for permission. For software which is copyrighted by the Free | |
9256 | Software Foundation, write to the Free Software Foundation; we sometimes | |
9257 | make exceptions for this. Our decision will be guided by the two goals | |
9258 | of preserving the free status of all derivatives of our free software and | |
9259 | of promoting the sharing and reuse of software generally. | |
9260 | ||
9261 | @iftex | |
9262 | @heading NO WARRANTY | |
9263 | @end iftex | |
9264 | @ifinfo | |
9265 | @center NO WARRANTY | |
9266 | @end ifinfo | |
9267 | ||
9268 | @item | |
9269 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
9270 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
9271 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
9272 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
9273 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
9274 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
9275 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
9276 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
9277 | REPAIR OR CORRECTION. | |
9278 | ||
9279 | @item | |
7463aadd RP |
9280 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
9281 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 9282 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
9283 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
9284 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
9285 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
9286 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
9287 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
9288 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
9289 | @end enumerate |
9290 | ||
9291 | @iftex | |
9292 | @heading END OF TERMS AND CONDITIONS | |
9293 | @end iftex | |
9294 | @ifinfo | |
9295 | @center END OF TERMS AND CONDITIONS | |
9296 | @end ifinfo | |
9297 | ||
9298 | @page | |
54e6b3c3 | 9299 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
9300 | |
9301 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
9302 | possible use to the public, the best way to achieve this is to make it |
9303 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 9304 | |
7463aadd RP |
9305 | To do so, attach the following notices to the program. It is safest |
9306 | to attach them to the start of each source file to most effectively | |
9307 | convey the exclusion of warranty; and each file should have at least | |
9308 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
9309 | |
9310 | @smallexample | |
203eea5d | 9311 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
9312 | Copyright (C) 19@var{yy} @var{name of author} |
9313 | ||
203eea5d RP |
9314 | This program is free software; you can redistribute it and/or |
9315 | modify it under the terms of the GNU General Public License | |
9316 | as published by the Free Software Foundation; either version 2 | |
9317 | of the License, or (at your option) any later version. | |
70b88761 RP |
9318 | |
9319 | This program is distributed in the hope that it will be useful, | |
9320 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9321 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9322 | GNU General Public License for more details. | |
9323 | ||
9324 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
9325 | along with this program; if not, write to the |
9326 | Free Software Foundation, Inc., 675 Mass Ave, | |
9327 | Cambridge, MA 02139, USA. | |
70b88761 RP |
9328 | @end smallexample |
9329 | ||
9330 | Also add information on how to contact you by electronic and paper mail. | |
9331 | ||
9332 | If the program is interactive, make it output a short notice like this | |
9333 | when it starts in an interactive mode: | |
9334 | ||
9335 | @smallexample | |
9336 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
9337 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
9338 | type `show w'. This is free software, and you are welcome | |
9339 | to redistribute it under certain conditions; type `show c' | |
9340 | for details. | |
70b88761 RP |
9341 | @end smallexample |
9342 | ||
7463aadd RP |
9343 | The hypothetical commands @samp{show w} and @samp{show c} should show |
9344 | the appropriate parts of the General Public License. Of course, the | |
9345 | commands you use may be called something other than @samp{show w} and | |
9346 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
9347 | suits your program. | |
70b88761 RP |
9348 | |
9349 | You should also get your employer (if you work as a programmer) or your | |
9350 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
9351 | necessary. Here is a sample; alter the names: | |
9352 | ||
1041a570 RP |
9353 | @example |
9354 | Yoyodyne, Inc., hereby disclaims all copyright | |
9355 | interest in the program `Gnomovision' | |
9356 | (which makes passes at compilers) written | |
9357 | by James Hacker. | |
70b88761 RP |
9358 | |
9359 | @var{signature of Ty Coon}, 1 April 1989 | |
9360 | Ty Coon, President of Vice | |
1041a570 | 9361 | @end example |
7463aadd RP |
9362 | |
9363 | This General Public License does not permit incorporating your program into | |
9364 | proprietary programs. If your program is a subroutine library, you may | |
9365 | consider it more useful to permit linking proprietary applications with the | |
9366 | library. If this is what you want to do, use the GNU Library General | |
9367 | Public License instead of this License. | |
18fae2a8 | 9368 | @end ifclear |
70b88761 | 9369 | |
4eb4cf57 | 9370 | @node Index |
d2e08421 | 9371 | @unnumbered Index |
e91b87a3 | 9372 | |
9373 | @printindex cp | |
9374 | ||
fe3f5fc8 RP |
9375 | @tex |
9376 | % I think something like @colophon should be in texinfo. In the | |
9377 | % meantime: | |
9378 | \long\def\colophon{\hbox to0pt{}\vfill | |
9379 | \centerline{The body of this manual is set in} | |
9380 | \centerline{\fontname\tenrm,} | |
9381 | \centerline{with headings in {\bf\fontname\tenbf}} | |
9382 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
9383 | \centerline{{\it\fontname\tenit\/},} |
9384 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
9385 | \centerline{{\sl\fontname\tensl\/}} |
9386 | \centerline{are used for emphasis.}\vfill} | |
9387 | \page\colophon | |
a6d0b6d3 | 9388 | % Blame: [email protected], 1991. |
fe3f5fc8 RP |
9389 | @end tex |
9390 | ||
e91b87a3 | 9391 | @contents |
9392 | @bye |