]>
Commit | Line | Data |
---|---|---|
b80282d5 | 1 | _dnl__ -*-Texinfo-*- |
1041a570 | 2 | _dnl__ Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc. |
29a2b744 RP |
3 | _dnl__ $Id$ |
4 | \input texinfo @c -*-texinfo-*- | |
1041a570 | 5 | @c Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc. |
29a2b744 | 6 | @c %**start of header |
5a131cc7 | 7 | @setfilename _GDBP__.info |
29a2b744 | 8 | _if__(_GENERIC__) |
1041a570 | 9 | @settitle Using _GDBN__ (v4) |
29a2b744 RP |
10 | _fi__(_GENERIC__) |
11 | _if__(!_GENERIC__) | |
1041a570 | 12 | @settitle Using _GDBN__ v4 (_HOST__) |
29a2b744 RP |
13 | _fi__(!_GENERIC__) |
14 | @setchapternewpage odd | |
15 | @c @smallbook | |
16 | @c @cropmarks | |
17 | @c %**end of header | |
18 | ||
19 | @finalout | |
20 | @syncodeindex ky cp | |
21 | ||
22 | _0__@c ===> NOTE! <==_1__ | |
23 | @c Determine the edition number in *three* places by hand: | |
24 | @c 1. First ifinfo section 2. title page 3. top node | |
25 | @c To find the locations, search for !!set | |
26 | ||
27 | @c The following is for Pesch for his RCS system. | |
28 | @c This revision number *not* the same as the Edition number. | |
29 | @tex | |
30 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
31 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
32 | @end tex | |
33 | ||
34 | @c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN: | |
35 | @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com) | |
36 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
37 | ||
9c3ad547 | 38 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. |
29a2b744 | 39 | |
b7becc8f RP |
40 | @ifinfo |
41 | @format | |
42 | START-INFO-DIR-ENTRY | |
29a2b744 | 43 | * Gdb: (gdb). The GNU debugger. |
b7becc8f RP |
44 | END-INFO-DIR-ENTRY |
45 | @end format | |
46 | @end ifinfo | |
5a131cc7 RP |
47 | _if__(0) |
48 | ||
a6d0b6d3 RP |
49 | NOTE: this manual is marked up for preprocessing with a collection |
50 | of m4 macros called "pretex.m4". | |
51 | ||
9bcc06ef RP |
52 | THIS IS THE SOURCE PRIOR TO PREPROCESSING. The full source needs to |
53 | be run through m4 before either tex- or info- formatting: for example, | |
08665207 | 54 | _0__ |
3e0d0a27 | 55 | m4 pretex.m4 none.m4 all.m4 gdb.texinfo >gdb-all.texinfo |
70b88761 | 56 | will produce (assuming your path finds either GNU m4 >= 0.84, or SysV |
1041a570 | 57 | m4; Berkeley will not do) a file suitable for formatting. See the text in |
70b88761 | 58 | "pretex.m4" for a fuller explanation (and the macro definitions). |
29a2b744 | 59 | _1__ |
e91b87a3 | 60 | |
9bcc06ef | 61 | _fi__(0) |
70b88761 | 62 | @c |
70b88761 RP |
63 | @ifinfo |
64 | This file documents the GNU debugger _GDBN__. | |
65 | ||
29a2b744 | 66 | @c !!set edition, date, version |
1041a570 | 67 | This is Edition 4.01, January 1992, |
29a2b744 RP |
68 | of @cite{Using GDB: A Guide to the GNU Source-Level Debugger} |
69 | for GDB Version _GDB_VN__. | |
70 | ||
1041a570 | 71 | Copyright (C) 1988, 1989, 1990, 1991 1992 Free Software Foundation, Inc. |
70b88761 RP |
72 | |
73 | Permission is granted to make and distribute verbatim copies of | |
74 | this manual provided the copyright notice and this permission notice | |
75 | are preserved on all copies. | |
76 | ||
77 | @ignore | |
78 | Permission is granted to process this file through TeX and print the | |
79 | results, provided the printed document carries copying permission | |
80 | notice identical to this one except for the removal of this paragraph | |
81 | (this paragraph not being relevant to the printed manual). | |
82 | ||
83 | @end ignore | |
84 | Permission is granted to copy and distribute modified versions of this | |
85 | manual under the conditions for verbatim copying, provided also that the | |
86 | section entitled ``GNU General Public License'' is included exactly as | |
87 | in the original, and provided that the entire resulting derived work is | |
88 | distributed under the terms of a permission notice identical to this | |
89 | one. | |
90 | ||
91 | Permission is granted to copy and distribute translations of this manual | |
92 | into another language, under the above conditions for modified versions, | |
93 | except that the section entitled ``GNU General Public License'' may be | |
94 | included in a translation approved by the Free Software Foundation | |
95 | instead of in the original English. | |
96 | @end ifinfo | |
1041a570 | 97 | |
70b88761 | 98 | @titlepage |
92b73793 RP |
99 | @title Using _GDBN__ |
100 | @subtitle A Guide to the GNU Source-Level Debugger | |
70b88761 | 101 | _if__(!_GENERIC__) |
92b73793 | 102 | @subtitle On _HOST__ Systems |
70b88761 RP |
103 | _fi__(!_GENERIC__) |
104 | @sp 1 | |
29a2b744 | 105 | @c !!set edition, date, version |
1041a570 RP |
106 | @subtitle Edition 4.01, for _GDBN__ version _GDB_VN__ |
107 | @subtitle January 1992 | |
29a2b744 | 108 | @author by Richard M. Stallman and Roland H. Pesch |
70b88761 RP |
109 | @page |
110 | @tex | |
111 | {\parskip=0pt | |
112 | \hfill rms\@ai.mit.edu, pesch\@cygnus.com\par | |
113 | \hfill {\it Using _GDBN__}, \manvers\par | |
114 | \hfill \TeX{}info \texinfoversion\par | |
115 | } | |
116 | @end tex | |
117 | ||
118 | @vskip 0pt plus 1filll | |
1041a570 | 119 | Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. |
70b88761 RP |
120 | |
121 | Permission is granted to make and distribute verbatim copies of | |
122 | this manual provided the copyright notice and this permission notice | |
123 | are preserved on all copies. | |
124 | ||
125 | Permission is granted to copy and distribute modified versions of this | |
126 | manual under the conditions for verbatim copying, provided also that the | |
127 | section entitled ``GNU General Public License'' is included exactly as | |
128 | in the original, and provided that the entire resulting derived work is | |
129 | distributed under the terms of a permission notice identical to this | |
130 | one. | |
131 | ||
132 | Permission is granted to copy and distribute translations of this manual | |
133 | into another language, under the above conditions for modified versions, | |
134 | except that the section entitled ``GNU General Public License'' may be | |
135 | included in a translation approved by the Free Software Foundation | |
136 | instead of in the original English. | |
137 | @end titlepage | |
138 | @page | |
139 | ||
70b88761 | 140 | @ifinfo |
29a2b744 RP |
141 | @node Top, Summary, (dir), (dir) |
142 | @top _GDBN__, the GNU symbolic debugger | |
143 | ||
144 | This file describes _GDBN__, the GNU symbolic debugger. | |
145 | ||
146 | @c !!set edition, date, version | |
1041a570 | 147 | This is Edition 4.01, January 1992, for GDB Version _GDB_VN__. |
70b88761 RP |
148 | @end ifinfo |
149 | ||
150 | @menu | |
b80282d5 | 151 | * Summary:: Summary of _GDBN__ |
29a2b744 | 152 | * New Features:: New features since _GDBN__ version 3.5 |
1041a570 | 153 | * Sample Session:: A Sample _GDBN__ session |
29a2b744 RP |
154 | * Invocation:: Getting in and out of _GDBN__ |
155 | * Commands:: _GDBN__ commands | |
156 | * Running:: Running programs under _GDBN__ | |
157 | * Stopping:: Stopping and continuing | |
158 | * Stack:: Examining the stack | |
159 | * Source:: Examining source files | |
160 | * Data:: Examining data | |
161 | * Languages:: Using _GDBN__ with different languages | |
162 | * Symbols:: Examining the symbol table | |
163 | * Altering:: Altering execution | |
164 | * _GDBN__ Files:: _GDBN__'s files | |
165 | * Targets:: Specifying a debugging target | |
c2bbbb22 | 166 | * Controlling _GDBN__:: Controlling _GDBN__ |
29a2b744 | 167 | * Sequences:: Canned sequences of commands |
b80282d5 | 168 | * Emacs:: Using _GDBN__ under GNU Emacs |
29a2b744 | 169 | * _GDBN__ Bugs:: Reporting bugs in _GDBN__ |
e251e767 | 170 | * Renamed Commands:: |
c2bbbb22 | 171 | * Installing _GDBN__:: Installing _GDBN__ |
b80282d5 RP |
172 | * Copying:: GNU GENERAL PUBLIC LICENSE |
173 | * Index:: Index | |
c2bbbb22 | 174 | |
70b88761 RP |
175 | --- The Detailed Node Listing --- |
176 | ||
177 | Summary of _GDBN__ | |
178 | ||
b80282d5 RP |
179 | * Free Software:: Free Software |
180 | * Contributors:: Contributors to _GDBN__ | |
70b88761 RP |
181 | |
182 | Getting In and Out of _GDBN__ | |
183 | ||
29a2b744 | 184 | * Invoking _GDBN__:: Starting _GDBN__ |
c2bbbb22 | 185 | * Leaving _GDBN__:: Leaving _GDBN__ |
b80282d5 | 186 | * Shell Commands:: Shell Commands |
70b88761 RP |
187 | |
188 | Starting _GDBN__ | |
189 | ||
b80282d5 RP |
190 | * File Options:: Choosing Files |
191 | * Mode Options:: Choosing Modes | |
70b88761 RP |
192 | |
193 | _GDBN__ Commands | |
194 | ||
b80282d5 RP |
195 | * Command Syntax:: Command Syntax |
196 | * Help:: Getting Help | |
70b88761 RP |
197 | |
198 | Running Programs Under _GDBN__ | |
199 | ||
b80282d5 RP |
200 | * Compilation:: Compiling for Debugging |
201 | * Starting:: Starting your Program | |
202 | * Arguments:: Your Program's Arguments | |
203 | * Environment:: Your Program's Environment | |
204 | * Working Directory:: Your Program's Working Directory | |
205 | * Input/Output:: Your Program's Input and Output | |
206 | * Attach:: Debugging an Already-Running Process | |
207 | * Kill Process:: Killing the Child Process | |
70b88761 RP |
208 | |
209 | Stopping and Continuing | |
210 | ||
b80282d5 RP |
211 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
212 | * Continuing and Stepping:: Resuming Execution | |
213 | * Signals:: Signals | |
70b88761 RP |
214 | |
215 | Breakpoints, Watchpoints, and Exceptions | |
216 | ||
b80282d5 RP |
217 | * Set Breaks:: Setting Breakpoints |
218 | * Set Watchpoints:: Setting Watchpoints | |
219 | * Exception Handling:: Breakpoints and Exceptions | |
220 | * Delete Breaks:: Deleting Breakpoints | |
221 | * Disabling:: Disabling Breakpoints | |
222 | * Conditions:: Break Conditions | |
223 | * Break Commands:: Breakpoint Command Lists | |
224 | * Breakpoint Menus:: Breakpoint Menus | |
c2bbbb22 | 225 | * Error in Breakpoints:: ``Cannot insert breakpoints'' |
70b88761 RP |
226 | |
227 | Examining the Stack | |
228 | ||
b80282d5 RP |
229 | * Frames:: Stack Frames |
230 | * Backtrace:: Backtraces | |
231 | * Selection:: Selecting a Frame | |
232 | * Frame Info:: Information on a Frame | |
70b88761 RP |
233 | |
234 | Examining Source Files | |
235 | ||
b80282d5 RP |
236 | * List:: Printing Source Lines |
237 | * Search:: Searching Source Files | |
238 | * Source Path:: Specifying Source Directories | |
239 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
240 | |
241 | Examining Data | |
242 | ||
b80282d5 RP |
243 | * Expressions:: Expressions |
244 | * Variables:: Program Variables | |
245 | * Arrays:: Artificial Arrays | |
246 | * Output formats:: Output formats | |
247 | * Memory:: Examining Memory | |
248 | * Auto Display:: Automatic Display | |
249 | * Print Settings:: Print Settings | |
250 | * Value History:: Value History | |
251 | * Convenience Vars:: Convenience Variables | |
252 | * Registers:: Registers | |
253 | * Floating Point Hardware:: Floating Point Hardware | |
70b88761 | 254 | |
c2bbbb22 RP |
255 | Using GDB with Different Languages |
256 | ||
257 | * Setting:: Switching between source languages | |
258 | * Show:: Displaying the language | |
259 | * Checks:: Type and Range checks | |
260 | * Support:: Supported languages | |
261 | ||
262 | Switching between source languages | |
263 | ||
264 | * Manually:: Setting the working language manually | |
265 | * Automatically:: Having GDB infer the source language | |
266 | ||
267 | Type and range Checking | |
268 | ||
269 | * Type Checking:: An overview of type checking | |
270 | * Range Checking:: An overview of range checking | |
271 | ||
272 | Supported Languages | |
273 | ||
274 | * C:: C and C++ | |
275 | * Modula-2:: Modula-2 | |
276 | ||
277 | C and C++ | |
278 | ||
279 | * C Operators:: C and C++ Operators | |
280 | * C Constants:: C and C++ Constants | |
281 | * Cplusplus expressions:: C++ Expressions | |
282 | * C Defaults:: Default settings for C and C++ | |
283 | * C Checks:: C and C++ Type and Range Checks | |
284 | * Debugging C:: _GDBN__ and C | |
285 | * Debugging C plus plus:: Special features for C++ | |
286 | ||
287 | Modula-2 | |
288 | ||
289 | * M2 Operators:: Built-in operators | |
29a2b744 | 290 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
291 | * M2 Constants:: Modula-2 Constants |
292 | * M2 Defaults:: Default settings for Modula-2 | |
293 | * Deviations:: Deviations from standard Modula-2 | |
294 | * M2 Checks:: Modula-2 Type and Range Checks | |
295 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
296 | * GDB/M2:: GDB and Modula-2 | |
297 | ||
70b88761 RP |
298 | Altering Execution |
299 | ||
b80282d5 RP |
300 | * Assignment:: Assignment to Variables |
301 | * Jumping:: Continuing at a Different Address | |
29a2b744 | 302 | * Signaling:: Giving your program a Signal |
b80282d5 RP |
303 | * Returning:: Returning from a Function |
304 | * Calling:: Calling your Program's Functions | |
c338a2fd | 305 | * Patching:: Patching your Program |
70b88761 RP |
306 | |
307 | _GDBN__'s Files | |
308 | ||
b80282d5 RP |
309 | * Files:: Commands to Specify Files |
310 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 | 311 | |
e251e767 | 312 | Specifying a Debugging Target |
70b88761 | 313 | |
b80282d5 RP |
314 | * Active Targets:: Active Targets |
315 | * Target Commands:: Commands for Managing Targets | |
316 | * Remote:: Remote Debugging | |
70b88761 RP |
317 | |
318 | Remote Debugging | |
319 | ||
c2bbbb22 RP |
320 | * i960-Nindy Remote:: _GDBN__ with a Remote i960 (Nindy) |
321 | * EB29K Remote:: _GDBN__ with a Remote EB29K | |
322 | * VxWorks Remote:: _GDBN__ and VxWorks | |
70b88761 RP |
323 | |
324 | _GDBN__ with a Remote i960 (Nindy) | |
325 | ||
b80282d5 RP |
326 | * Nindy Startup:: Startup with Nindy |
327 | * Nindy Options:: Options for Nindy | |
328 | * Nindy reset:: Nindy Reset Command | |
70b88761 RP |
329 | |
330 | _GDBN__ with a Remote EB29K | |
331 | ||
b80282d5 RP |
332 | * Comms (EB29K):: Communications Setup |
333 | * gdb-EB29K:: EB29K cross-debugging | |
334 | * Remote Log:: Remote Log | |
70b88761 RP |
335 | |
336 | _GDBN__ and VxWorks | |
337 | ||
b80282d5 RP |
338 | * VxWorks connection:: Connecting to VxWorks |
339 | * VxWorks download:: VxWorks Download | |
340 | * VxWorks attach:: Running Tasks | |
70b88761 RP |
341 | |
342 | Controlling _GDBN__ | |
343 | ||
b80282d5 RP |
344 | * Prompt:: Prompt |
345 | * Editing:: Command Editing | |
346 | * History:: Command History | |
347 | * Screen Size:: Screen Size | |
348 | * Numbers:: Numbers | |
349 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
350 | |
351 | Canned Sequences of Commands | |
352 | ||
b80282d5 RP |
353 | * Define:: User-Defined Commands |
354 | * Command Files:: Command Files | |
355 | * Output:: Commands for Controlled Output | |
70b88761 RP |
356 | |
357 | Reporting Bugs in _GDBN__ | |
358 | ||
b80282d5 RP |
359 | * Bug Criteria:: Have You Found a Bug? |
360 | * Bug Reporting:: How to Report Bugs | |
c2bbbb22 RP |
361 | |
362 | Installing GDB | |
363 | ||
364 | * Subdirectories:: Configuration subdirectories | |
365 | * Config Names:: Specifying names for hosts and targets | |
366 | * configure Options:: Summary of options for configure | |
d7b569d5 | 367 | * Formatting Documentation:: How to format and print GDB documentation |
70b88761 RP |
368 | @end menu |
369 | ||
370 | @node Summary, New Features, Top, Top | |
371 | @unnumbered Summary of _GDBN__ | |
372 | ||
373 | The purpose of a debugger such as _GDBN__ is to allow you to see what is | |
374 | going on ``inside'' another program while it executes---or what another | |
1041a570 | 375 | program was doing at the moment it crashed. |
70b88761 RP |
376 | |
377 | _GDBN__ can do four main kinds of things (plus other things in support of | |
1041a570 | 378 | these) to help you catch bugs in the act: |
70b88761 RP |
379 | |
380 | @itemize @bullet | |
381 | @item | |
382 | Start your program, specifying anything that might affect its behavior. | |
383 | ||
384 | @item | |
385 | Make your program stop on specified conditions. | |
386 | ||
387 | @item | |
388 | Examine what has happened, when your program has stopped. | |
389 | ||
390 | @item | |
391 | Change things in your program, so you can experiment with correcting the | |
392 | effects of one bug and go on to learn about another. | |
393 | @end itemize | |
394 | ||
c2bbbb22 RP |
395 | You can use _GDBN__ to debug programs written in C, C++, and Modula-2. |
396 | Fortran support will be added when a GNU Fortran compiler is ready. | |
70b88761 RP |
397 | |
398 | @menu | |
b80282d5 RP |
399 | * Free Software:: Free Software |
400 | * Contributors:: Contributors to GDB | |
70b88761 RP |
401 | @end menu |
402 | ||
403 | @node Free Software, Contributors, Summary, Summary | |
404 | @unnumberedsec Free Software | |
1041a570 RP |
405 | |
406 | _GDBN__ is @dfn{free software}, protected by the GNU General Public License | |
407 | (GPL). The GPL gives you the freedom to copy or adapt a licensed | |
70b88761 RP |
408 | program---but every person getting a copy also gets with it the |
409 | freedom to modify that copy (which means that they must get access to | |
410 | the source code), and the freedom to distribute further copies. | |
411 | Typical software companies use copyrights to limit your freedoms; the | |
412 | Free Software Foundation uses the GPL to preserve these freedoms. | |
413 | ||
414 | Fundamentally, the General Public License is a license which says that | |
29a2b744 | 415 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
416 | from anyone else. |
417 | ||
29a2b744 | 418 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
1041a570 | 419 | |
70b88761 RP |
420 | @node Contributors, , Free Software, Summary |
421 | @unnumberedsec Contributors to GDB | |
422 | ||
423 | Richard Stallman was the original author of GDB, and of many other GNU | |
424 | programs. Many others have contributed to its development. This | |
425 | section attempts to credit major contributors. One of the virtues of | |
426 | free software is that everyone is free to contribute to it; with | |
427 | regret, we cannot actually acknowledge everyone here. The file | |
428 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
429 | account. | |
430 | ||
431 | Changes much prior to version 2.0 are lost in the mists of time. | |
432 | ||
433 | @quotation | |
434 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
435 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
436 | omitted from this list, we would like to add your names! | |
437 | @end quotation | |
438 | ||
439 | So that they may not regard their long labor as thankless, we | |
b80282d5 | 440 | particularly thank those who shepherded GDB through major releases: John |
1041a570 RP |
441 | Gilmore (all releases of _GDBN__ 4); Jim Kingdon (releases 3.9, 3.5, |
442 | 3.4, 3.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major | |
440d9834 | 443 | maintainer of GDB for some period, each contributed significantly to the |
1041a570 | 444 | structure, stability, and capabilities of the entire debugger. |
70b88761 RP |
445 | |
446 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
447 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
448 | ||
449 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
450 | with significant additional contributions from Per Bothner. James | |
451 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
452 | TerMaat (who also did much general update work leading to release 3.0). | |
453 | ||
1041a570 RP |
454 | GDB 4 uses the BFD subroutine library to examine multiple |
455 | object-file formats; BFD was a joint project of David V. | |
456 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
70b88761 | 457 | |
1041a570 RP |
458 | David Johnson wrote the original COFF support; Pace Willison did |
459 | the original support for encapsulated COFF. | |
70b88761 RP |
460 | |
461 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
462 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
463 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris |
464 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
465 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
466 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
467 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
468 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
469 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
470 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
471 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
472 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
473 | support. | |
70b88761 | 474 | |
c338a2fd RP |
475 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
476 | libraries. | |
70b88761 RP |
477 | |
478 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
479 | several machine instruction sets. | |
480 | ||
1041a570 RP |
481 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped |
482 | develop remote debugging. Intel Corporation and Wind River Systems | |
483 | contributed remote debugging modules for their products. | |
70b88761 | 484 | |
1041a570 RP |
485 | Brian Fox is the author of the readline libraries providing |
486 | command-line editing and command history. | |
70b88761 | 487 | |
1041a570 RP |
488 | Andrew Beers of SUNY Buffalo wrote the language-switching code and |
489 | the Modula-2 support, and contributed the Languages chapter of this | |
490 | manual. | |
c2bbbb22 | 491 | |
70b88761 RP |
492 | @node New Features, Sample Session, Summary, Top |
493 | @unnumbered New Features since _GDBN__ version 3.5 | |
494 | ||
495 | @table @emph | |
496 | @item Targets | |
497 | Using the new command @code{target}, you can select at runtime whether | |
498 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
499 | a serial port, realtime systems over a TCP/IP connection, etc. The |
500 | command @code{load} can download programs into a remote system. Serial | |
501 | stubs are available for Motorola 680x0 and Intel 80386 remote systems; | |
502 | _GDBN__ also supports debugging realtime processes running under | |
503 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a | |
504 | debugger stub on the target system. Internally, _GDBN__ now uses a | |
505 | function vector to mediate access to different targets; if you need to | |
506 | add your own support for a remote protocol, this makes it much easier. | |
70b88761 RP |
507 | |
508 | @item Watchpoints | |
509 | _GDBN__ now sports watchpoints as well as breakpoints. You can use a | |
510 | watchpoint to stop execution whenever the value of an expression | |
511 | changes, without having to predict a particular place in your program | |
512 | where this may happen. | |
513 | ||
b80282d5 RP |
514 | @item Wide Output |
515 | Commands that issue wide output now insert newlines at places designed | |
516 | to make the output more readable. | |
517 | ||
70b88761 | 518 | @item Object Code Formats |
b80282d5 | 519 | _GDBN__ uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
520 | Library to permit it to switch dynamically, without reconfiguration or |
521 | recompilation, between different object-file formats. Formats currently | |
522 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
523 | .o's, archive libraries, or core dumps. BFD is available as a | |
524 | subroutine library so that other programs may take advantage of it, and | |
525 | the other GNU binary utilities are being converted to use it. | |
70b88761 | 526 | |
b80282d5 | 527 | @item Configuration and Ports |
70b88761 | 528 | Compile-time configuration (to select a particular architecture and |
7463aadd | 529 | operating system) is much easier. The script @code{configure} now |
3d3ab540 | 530 | allows you to configure _GDBN__ as either a native debugger or a |
29a2b744 | 531 | cross-debugger. @xref{Installing _GDBN__}, for details on how to |
b80282d5 | 532 | configure and on what architectures are now available. |
70b88761 RP |
533 | |
534 | @item Interaction | |
535 | The user interface to _GDBN__'s control variables has been simplified | |
536 | and consolidated in two commands, @code{set} and @code{show}. Output | |
537 | lines are now broken at readable places, rather than overflowing onto | |
538 | the next line. You can suppress output of machine-level addresses, | |
539 | displaying only source language information. | |
540 | ||
b80282d5 RP |
541 | @item C++ |
542 | _GDBN__ now supports C++ multiple inheritance (if used with a GCC | |
543 | version 2 compiler), and also has limited support for C++ exception | |
544 | handling, with the commands @code{catch} and @code{info catch}: _GDBN__ | |
545 | can break when an exception is raised, before the stack is peeled back | |
546 | to the exception handler's context. | |
70b88761 | 547 | |
c2bbbb22 RP |
548 | @item Modula-2 |
549 | _GDBN__ now has preliminary support for the GNU Modula-2 compiler, | |
550 | currently under development at the State University of New York at | |
551 | Buffalo. Coordinated development of both _GDBN__ and the GNU Modula-2 | |
552 | compiler will continue through the fall of 1991 and into 1992. Other | |
553 | Modula-2 compilers are currently not supported, and attempting to debug | |
554 | programs compiled with them will likely result in an error as the symbol | |
555 | table of the executable is read in. | |
556 | ||
70b88761 RP |
557 | @item Command Rationalization |
558 | Many _GDBN__ commands have been renamed to make them easier to remember | |
559 | and use. In particular, the subcommands of @code{info} and | |
560 | @code{show}/@code{set} are grouped to make the former refer to the state | |
561 | of your program, and the latter refer to the state of _GDBN__ itself. | |
562 | @xref{Renamed Commands}, for details on what commands were renamed. | |
563 | ||
70b88761 | 564 | @item Shared Libraries |
29a2b744 | 565 | _GDBN__ 4 can debug programs and core files that use SunOS shared |
e251e767 | 566 | libraries. |
b80282d5 RP |
567 | |
568 | @item Reference Card | |
1041a570 | 569 | _GDBN__ 4 has a reference card. @xref{Formatting Documentation} for |
b80282d5 | 570 | instructions on printing it. |
70b88761 RP |
571 | |
572 | @item Work in Progress | |
573 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
574 | support. | |
70b88761 RP |
575 | @end table |
576 | ||
577 | @node Sample Session, Invocation, New Features, Top | |
578 | @chapter A Sample _GDBN__ Session | |
579 | ||
580 | You can use this manual at your leisure to read all about _GDBN__. | |
581 | However, a handful of commands are enough to get started using the | |
582 | debugger. This chapter illustrates these commands. | |
583 | ||
584 | @iftex | |
585 | In this sample session, we emphasize user input like this: @i{input}, | |
586 | to make it easier to pick out from the surrounding output. | |
587 | @end iftex | |
588 | ||
589 | @c FIXME: this example may not be appropriate for some configs, where | |
590 | @c FIXME...primary interest is in remote use. | |
591 | _0__ | |
592 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
593 | processor) exhibits the following bug: sometimes, when we change its | |
594 | quote strings from the default, the commands used to capture one macro's | |
595 | definition in another stop working. In the following short @code{m4} | |
596 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
29a2b744 | 597 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
598 | same thing. However, when we change the open quote string to |
599 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
600 | procedure fails to define a new synonym @code{baz}: | |
601 | ||
602 | @smallexample | |
603 | $ @i{cd gnu/m4} | |
604 | $ @i{./m4} | |
605 | @i{define(foo,0000)} | |
606 | ||
607 | @i{foo} | |
608 | 0000 | |
609 | @i{define(bar,defn(`foo'))} | |
610 | ||
611 | @i{bar} | |
612 | 0000 | |
613 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
614 | ||
615 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
616 | @i{baz} | |
617 | @i{C-d} | |
618 | m4: End of input: 0: fatal error: EOF in string | |
619 | @end smallexample | |
620 | ||
621 | @noindent | |
622 | Let's use _GDBN__ to try to see what's going on. | |
623 | ||
624 | @smallexample | |
625 | $ @i{_GDBP__ m4} | |
203eea5d RP |
626 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
627 | @c FIXME... format to come out better. | |
628 | GDB is free software and you are welcome to distribute copies | |
629 | of it under certain conditions; type "show copying" to see | |
630 | the conditions. | |
631 | There is absolutely no warranty for GDB; type "show warranty" | |
632 | for details. | |
c338a2fd | 633 | GDB _GDB_VN__, Copyright 1991 Free Software Foundation, Inc... |
e251e767 | 634 | (_GDBP__) |
70b88761 RP |
635 | @end smallexample |
636 | ||
637 | @noindent | |
1041a570 RP |
638 | _GDBN__ reads only enough symbol data to know where to find the rest when |
639 | needed; as a result, the first prompt comes up very quickly. We now | |
640 | tell _GDBN__ to use a narrower display width than usual, so that examples | |
641 | will fit in this manual. | |
70b88761 RP |
642 | |
643 | @smallexample | |
644 | (_GDBP__) @i{set width 70} | |
645 | @end smallexample | |
646 | ||
e251e767 | 647 | @noindent |
29a2b744 | 648 | Let's see how the @code{m4} built-in @code{changequote} works. |
70b88761 RP |
649 | Having looked at the source, we know the relevant subroutine is |
650 | @code{m4_changequote}, so we set a breakpoint there with _GDBN__'s | |
651 | @code{break} command. | |
652 | ||
653 | @smallexample | |
654 | (_GDBP__) @i{break m4_changequote} | |
655 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. | |
656 | @end smallexample | |
657 | ||
658 | @noindent | |
659 | Using the @code{run} command, we start @code{m4} running under _GDBN__ | |
660 | control; as long as control does not reach the @code{m4_changequote} | |
661 | subroutine, the program runs as usual: | |
662 | ||
663 | @smallexample | |
664 | (_GDBP__) @i{run} | |
e251e767 | 665 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
70b88761 RP |
666 | @i{define(foo,0000)} |
667 | ||
668 | @i{foo} | |
669 | 0000 | |
670 | @end smallexample | |
671 | ||
672 | @noindent | |
673 | To trigger the breakpoint, we call @code{changequote}. _GDBN__ | |
674 | suspends execution of @code{m4}, displaying information about the | |
675 | context where it stops. | |
676 | ||
677 | @smallexample | |
678 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
679 | ||
203eea5d RP |
680 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
681 | at builtin.c:879 | |
70b88761 RP |
682 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3)) |
683 | @end smallexample | |
684 | ||
685 | @noindent | |
686 | Now we use the command @code{n} (@code{next}) to advance execution to | |
687 | the next line of the current function. | |
688 | ||
689 | @smallexample | |
690 | (_GDBP__) @i{n} | |
203eea5d RP |
691 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
692 | : nil, | |
70b88761 RP |
693 | @end smallexample |
694 | ||
695 | @noindent | |
696 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
697 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
698 | @code{step} goes to the next line to be executed in @emph{any} | |
e251e767 | 699 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
700 | |
701 | @smallexample | |
702 | (_GDBP__) @i{s} | |
703 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
704 | at input.c:530 | |
705 | 530 if (lquote != def_lquote) | |
706 | @end smallexample | |
707 | ||
708 | @noindent | |
29a2b744 RP |
709 | The display that shows the subroutine where @code{m4} is now |
710 | suspended (and its arguments) is called a stack frame display. It | |
711 | shows a summary of the stack. We can use the @code{backtrace} | |
712 | command (which can also be spelled @code{bt}), to see where we are | |
713 | in the stack as a whole: the @code{backtrace} command displays a | |
714 | stack frame for each active subroutine. | |
70b88761 RP |
715 | |
716 | @smallexample | |
717 | (_GDBP__) @i{bt} | |
718 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
719 | at input.c:530 | |
203eea5d RP |
720 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
721 | at builtin.c:882 | |
70b88761 RP |
722 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
723 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
724 | at macro.c:71 | |
725 | #4 0x79dc in expand_input () at macro.c:40 | |
726 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
727 | @end smallexample | |
728 | ||
729 | @noindent | |
730 | Let's step through a few more lines to see what happens. The first two | |
731 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
732 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 733 | |
70b88761 RP |
734 | @smallexample |
735 | (_GDBP__) @i{s} | |
736 | 0x3b5c 532 if (rquote != def_rquote) | |
737 | (_GDBP__) @i{s} | |
203eea5d RP |
738 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
739 | def_lquote : xstrdup(lq); | |
70b88761 | 740 | (_GDBP__) @i{n} |
203eea5d RP |
741 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
742 | : xstrdup(rq); | |
70b88761 RP |
743 | (_GDBP__) @i{n} |
744 | 538 len_lquote = strlen(rquote); | |
745 | @end smallexample | |
746 | ||
747 | @noindent | |
748 | The last line displayed looks a little odd; let's examine the variables | |
749 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
750 | and right quotes we specified. We can use the command @code{p} | |
751 | (@code{print}) to see their values. | |
752 | ||
753 | @smallexample | |
754 | (_GDBP__) @i{p lquote} | |
755 | $1 = 0x35d40 "<QUOTE>" | |
756 | (_GDBP__) @i{p rquote} | |
757 | $2 = 0x35d50 "<UNQUOTE>" | |
758 | @end smallexample | |
759 | ||
760 | @noindent | |
761 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
762 | Let's look at some context; we can display ten lines of source | |
763 | surrounding the current line, with the @code{l} (@code{list}) command. | |
764 | ||
765 | @smallexample | |
766 | (_GDBP__) @i{l} | |
767 | 533 xfree(rquote); | |
e251e767 | 768 | 534 |
203eea5d RP |
769 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
770 | : xstrdup (lq); | |
771 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
772 | : xstrdup (rq); | |
e251e767 | 773 | 537 |
70b88761 RP |
774 | 538 len_lquote = strlen(rquote); |
775 | 539 len_rquote = strlen(lquote); | |
776 | 540 @} | |
e251e767 | 777 | 541 |
70b88761 RP |
778 | 542 void |
779 | @end smallexample | |
780 | ||
781 | @noindent | |
782 | Let's step past the two lines that set @code{len_lquote} and | |
783 | @code{len_rquote}, and then examine the values of those variables. | |
784 | ||
785 | @smallexample | |
786 | (_GDBP__) @i{n} | |
787 | 539 len_rquote = strlen(lquote); | |
788 | (_GDBP__) @i{n} | |
789 | 540 @} | |
790 | (_GDBP__) @i{p len_lquote} | |
791 | $3 = 9 | |
792 | (_GDBP__) @i{p len_rquote} | |
793 | $4 = 7 | |
794 | @end smallexample | |
795 | ||
796 | @noindent | |
797 | That certainly looks wrong, assuming @code{len_lquote} and | |
798 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
799 | @code{rquote} respectively. Let's try setting them to better values. | |
800 | We can use the @code{p} command for this, since it'll print the value of | |
801 | any expression---and that expression can include subroutine calls and | |
e251e767 | 802 | assignments. |
70b88761 RP |
803 | |
804 | @smallexample | |
805 | (_GDBP__) p len_lquote=strlen(lquote) | |
806 | $5 = 7 | |
807 | (_GDBP__) p len_rquote=strlen(rquote) | |
808 | $6 = 9 | |
809 | @end smallexample | |
810 | ||
811 | @noindent | |
812 | Let's see if that fixes the problem of using the new quotes with the | |
813 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
814 | executing with the @code{c} (@code{continue}) command, and then try the | |
815 | example that caused trouble initially: | |
816 | ||
817 | @smallexample | |
818 | (_GDBP__) @i{c} | |
819 | Continuing. | |
820 | ||
821 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
822 | ||
823 | baz | |
824 | 0000 | |
825 | @end smallexample | |
826 | ||
827 | @noindent | |
828 | Success! The new quotes now work just as well as the default ones. The | |
829 | problem seems to have been just the two typos defining the wrong | |
830 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
831 | ||
832 | @smallexample | |
833 | @i{C-d} | |
834 | Program exited normally. | |
835 | @end smallexample | |
836 | ||
e251e767 | 837 | @noindent |
70b88761 RP |
838 | The message @samp{Program exited normally.} is from _GDBN__; it |
839 | indicates @code{m4} has finished executing. We can end our _GDBN__ | |
840 | session with the _GDBN__ @code{quit} command. | |
841 | ||
842 | @smallexample | |
843 | (_GDBP__) @i{quit} | |
70b88761 RP |
844 | _1__@end smallexample |
845 | ||
846 | @node Invocation, Commands, Sample Session, Top | |
847 | @chapter Getting In and Out of _GDBN__ | |
848 | ||
29a2b744 RP |
849 | Type @kbd{gdb} or @kbd{gdb @var{program} @var{core}} to start GDB |
850 | and type @kbd{quit} or @kbd{C-d} to exit. | |
851 | ||
70b88761 | 852 | @menu |
29a2b744 | 853 | * Invoking _GDBN__:: Starting _GDBN__ |
c2bbbb22 | 854 | * Leaving _GDBN__:: Leaving _GDBN__ |
b80282d5 | 855 | * Shell Commands:: Shell Commands |
70b88761 RP |
856 | @end menu |
857 | ||
29a2b744 | 858 | @node Invoking _GDBN__, Leaving _GDBN__, Invocation, Invocation |
70b88761 RP |
859 | @section Starting _GDBN__ |
860 | ||
1041a570 RP |
861 | Start _GDBN__ with the shell command @code{_GDBP__}. Once it's running, |
862 | _GDBN__ reads commands from the terminal until you tell it to exit. | |
70b88761 RP |
863 | |
864 | You can run @code{_GDBP__} with no arguments or options; but the most | |
865 | usual way to start _GDBN__ is with one argument or two, specifying an | |
866 | executable program as the argument: | |
1041a570 | 867 | |
70b88761 | 868 | @example |
29a2b744 | 869 | _GDBP__ @var{program} |
70b88761 | 870 | @end example |
1041a570 | 871 | |
70b88761 | 872 | @noindent |
29a2b744 RP |
873 | You can also start with both an executable program and a core file |
874 | specified: | |
1041a570 | 875 | |
70b88761 | 876 | @example |
29a2b744 | 877 | _GDBP__ @var{program} @var{core} |
70b88761 RP |
878 | @end example |
879 | ||
b80282d5 RP |
880 | You can, instead, specify a process ID as a second argument, if you want |
881 | to debug a running process: | |
1041a570 | 882 | |
b80282d5 | 883 | @example |
29a2b744 | 884 | _GDBP__ @var{program} 1234 |
b80282d5 | 885 | @end example |
1041a570 | 886 | |
b80282d5 RP |
887 | @noindent |
888 | would attach _GDBN__ to process @code{1234} (unless you also have a file | |
889 | named @file{1234}; _GDBN__ does check for a core file first). | |
890 | ||
70b88761 RP |
891 | @noindent |
892 | You can further control how _GDBN__ starts up by using command-line | |
29a2b744 RP |
893 | options. _GDBN__ itself can remind you of the options available. |
894 | ||
895 | @noindent | |
896 | Type | |
897 | ||
70b88761 RP |
898 | @example |
899 | _GDBP__ -help | |
900 | @end example | |
29a2b744 | 901 | |
70b88761 | 902 | @noindent |
29a2b744 | 903 | to display all available options and briefly describe their use |
70b88761 RP |
904 | (@samp{_GDBP__ -h} is a shorter equivalent). |
905 | ||
906 | All options and command line arguments you give are processed | |
907 | in sequential order. The order makes a difference when the | |
e251e767 | 908 | @samp{-x} option is used. |
70b88761 RP |
909 | |
910 | @menu | |
b80282d5 RP |
911 | * File Options:: Choosing Files |
912 | * Mode Options:: Choosing Modes | |
70b88761 RP |
913 | _if__(!_GENERIC__) |
914 | _include__(gdbinv-m.m4)_dnl__ | |
915 | _fi__(!_GENERIC__) | |
916 | @end menu | |
917 | ||
29a2b744 | 918 | @node File Options, Mode Options, Invoking _GDBN__, Invoking _GDBN__ |
70b88761 RP |
919 | @subsection Choosing Files |
920 | ||
29a2b744 RP |
921 | When _GDBN__ starts, it reads any arguments other than options as |
922 | specifying an executable file and core file (or process ID). This is | |
923 | the same as if the arguments were specified by the @samp{-se} and | |
924 | @samp{-c} options respectively. (_GDBN__ reads the first argument | |
925 | that does not have an associated option flag as equivalent to the | |
926 | @samp{-se} option followed by that argument; and the second argument | |
927 | that does not have an associated option flag, if any, as equivalent to | |
928 | the @samp{-c} option followed by that argument.) | |
929 | ||
930 | Many options have both long and short forms; both are shown in the | |
931 | following list. _GDBN__ also recognizes the long forms if you truncate | |
932 | them, so long as enough of the option is present to be unambiguous. | |
933 | (If you prefer, you can flag option arguments with @samp{--} rather | |
934 | than @samp{-}, though we illustrate the more usual convention.) | |
70b88761 RP |
935 | |
936 | @table @code | |
937 | @item -symbols=@var{file} | |
938 | @itemx -s @var{file} | |
939 | Read symbol table from file @var{file}. | |
940 | ||
941 | @item -exec=@var{file} | |
942 | @itemx -e @var{file} | |
943 | Use file @var{file} as the executable file to execute when | |
944 | appropriate, and for examining pure data in conjunction with a core | |
945 | dump. | |
946 | ||
3d3ab540 | 947 | @item -se=@var{file} |
70b88761 RP |
948 | Read symbol table from file @var{file} and use it as the executable |
949 | file. | |
950 | ||
951 | @item -core=@var{file} | |
952 | @itemx -c @var{file} | |
953 | Use file @var{file} as a core dump to examine. | |
954 | ||
955 | @item -command=@var{file} | |
956 | @itemx -x @var{file} | |
957 | Execute _GDBN__ commands from file @var{file}. @xref{Command Files}. | |
958 | ||
959 | @item -directory=@var{directory} | |
960 | @itemx -d @var{directory} | |
961 | Add @var{directory} to the path to search for source files. | |
962 | @end table | |
963 | ||
964 | _if__(!_GENERIC__) | |
29a2b744 | 965 | @node Mode Options, Mode Options, File Options, Invoking _GDBN__ |
70b88761 RP |
966 | _fi__(!_GENERIC__) |
967 | _if__(_GENERIC__) | |
29a2b744 RP |
968 | @node Mode Options, , File Options, Invoking _GDBN__ |
969 | _fi__(_GENERIC__) | |
1041a570 RP |
970 | @subsection Choosing Modes |
971 | ||
29a2b744 RP |
972 | You can run _GDBN__ in various alternative modes---for example, in |
973 | batch mode or quiet mode. | |
70b88761 RP |
974 | |
975 | @table @code | |
976 | @item -nx | |
977 | @itemx -n | |
978 | Do not execute commands from any @file{_GDBINIT__} initialization files. | |
979 | Normally, the commands in these files are executed after all the | |
e251e767 | 980 | command options and arguments have been processed. |
c728f1f0 | 981 | @xref{Command Files}. |
70b88761 RP |
982 | |
983 | @item -quiet | |
984 | @itemx -q | |
985 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 986 | messages are also suppressed in batch mode. |
70b88761 RP |
987 | |
988 | @item -batch | |
989 | Run in batch mode. Exit with status @code{0} after processing all the command | |
990 | files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited). | |
991 | Exit with nonzero status if an error occurs in executing the _GDBN__ | |
e251e767 | 992 | commands in the command files. |
70b88761 RP |
993 | |
994 | Batch mode may be useful for running _GDBN__ as a filter, for example to | |
995 | download and run a program on another computer; in order to make this | |
e251e767 | 996 | more useful, the message |
1041a570 | 997 | |
70b88761 RP |
998 | @example |
999 | Program exited normally. | |
1000 | @end example | |
1041a570 | 1001 | |
70b88761 RP |
1002 | @noindent |
1003 | (which is ordinarily issued whenever a program running under _GDBN__ control | |
1004 | terminates) is not issued when running in batch mode. | |
1005 | ||
3d3ab540 | 1006 | @item -cd=@var{directory} |
70b88761 RP |
1007 | Run _GDBN__ using @var{directory} as its working directory, |
1008 | instead of the current directory. | |
1009 | ||
1010 | @item -fullname | |
1011 | @itemx -f | |
1012 | Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ | |
1013 | to output the full file name and line number in a standard, | |
1014 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 1015 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
1016 | like two @samp{\032} characters, followed by the file name, line number |
1017 | and character position separated by colons, and a newline. The | |
1018 | Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as | |
1019 | a signal to display the source code for the frame. | |
1020 | ||
1021 | @item -b @var{bps} | |
1022 | Set the line speed (baud rate or bits per second) of any serial | |
1023 | interface used by _GDBN__ for remote debugging. | |
1024 | ||
3d3ab540 | 1025 | @item -tty=@var{device} |
70b88761 | 1026 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 1027 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
70b88761 RP |
1028 | @end table |
1029 | ||
1030 | _if__(!_GENERIC__) | |
1031 | _include__(gdbinv-s.m4) | |
1032 | _fi__(!_GENERIC__) | |
29a2b744 | 1033 | @node Leaving _GDBN__, Shell Commands, Invoking _GDBN__, Invocation |
70b88761 RP |
1034 | @section Leaving _GDBN__ |
1035 | @cindex exiting _GDBN__ | |
1041a570 | 1036 | |
70b88761 RP |
1037 | @table @code |
1038 | @item quit | |
1039 | @kindex quit | |
1040 | @kindex q | |
1041 | To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type | |
e251e767 | 1042 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
1043 | @end table |
1044 | ||
1045 | @cindex interrupt | |
1046 | An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather | |
1047 | will terminate the action of any _GDBN__ command that is in progress and | |
1048 | return to _GDBN__ command level. It is safe to type the interrupt | |
1049 | character at any time because _GDBN__ does not allow it to take effect | |
1050 | until a time when it is safe. | |
1051 | ||
1041a570 RP |
1052 | If you have been using _GDBN__ to control an attached process or device, you |
1053 | can release it with the @code{detach} command; @pxref{Attach, | |
1054 | ,Debugging an Already-Running Process}.. | |
70b88761 RP |
1055 | |
1056 | @node Shell Commands, , Leaving _GDBN__, Invocation | |
1057 | @section Shell Commands | |
1041a570 | 1058 | |
70b88761 | 1059 | If you need to execute occasional shell commands during your |
29a2b744 | 1060 | debugging session, there is no need to leave or suspend _GDBN__; you can |
70b88761 RP |
1061 | just use the @code{shell} command. |
1062 | ||
1063 | @table @code | |
1064 | @item shell @var{command string} | |
1065 | @kindex shell | |
1066 | @cindex shell escape | |
1067 | Directs _GDBN__ to invoke an inferior shell to execute @var{command | |
1068 | string}. If it exists, the environment variable @code{SHELL} is used | |
1069 | for the name of the shell to run. Otherwise _GDBN__ uses | |
1070 | @code{/bin/sh}. | |
1071 | @end table | |
1072 | ||
1073 | The utility @code{make} is often needed in development environments. | |
29a2b744 | 1074 | You do not have to use the @code{shell} command for this purpose in _GDBN__: |
70b88761 RP |
1075 | |
1076 | @table @code | |
1077 | @item make @var{make-args} | |
1078 | @kindex make | |
1079 | @cindex calling make | |
1080 | Causes _GDBN__ to execute an inferior @code{make} program with the specified | |
1081 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
1082 | @end table | |
1083 | ||
1084 | @node Commands, Running, Invocation, Top | |
1085 | @chapter _GDBN__ Commands | |
1086 | ||
29a2b744 RP |
1087 | You can abbreviate GDB command if that abbreviation is unambiguous; |
1088 | and you can repeat certain GDB commands by typing just @key{RET}. | |
1089 | ||
70b88761 | 1090 | @menu |
b80282d5 RP |
1091 | * Command Syntax:: Command Syntax |
1092 | * Help:: Getting Help | |
70b88761 RP |
1093 | @end menu |
1094 | ||
1095 | @node Command Syntax, Help, Commands, Commands | |
1096 | @section Command Syntax | |
1041a570 | 1097 | |
70b88761 RP |
1098 | A _GDBN__ command is a single line of input. There is no limit on how long |
1099 | it can be. It starts with a command name, which is followed by arguments | |
1100 | whose meaning depends on the command name. For example, the command | |
1101 | @code{step} accepts an argument which is the number of times to step, | |
1102 | as in @samp{step 5}. You can also use the @code{step} command with | |
1103 | no arguments. Some command names do not allow any arguments. | |
1104 | ||
1105 | @cindex abbreviation | |
1106 | _GDBN__ command names may always be truncated if that abbreviation is | |
1107 | unambiguous. Other possible command abbreviations are listed in the | |
1108 | documentation for individual commands. In some cases, even ambiguous | |
1109 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1110 | equivalent to @code{step} even though there are other commands whose | |
1111 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1112 | arguments to the @code{help} command. |
70b88761 | 1113 | |
e251e767 | 1114 | @cindex repeating commands |
70b88761 RP |
1115 | @kindex RET |
1116 | A blank line as input to _GDBN__ (typing just @key{RET}) means to | |
1117 | repeat the previous command. Certain commands (for example, @code{run}) | |
1118 | will not repeat this way; these are commands for which unintentional | |
1119 | repetition might cause trouble and which you are unlikely to want to | |
1120 | repeat. | |
1121 | ||
1122 | The @code{list} and @code{x} commands, when you repeat them with | |
1123 | @key{RET}, construct new arguments rather than repeating | |
1124 | exactly as typed. This permits easy scanning of source or memory. | |
1125 | ||
b80282d5 RP |
1126 | _GDBN__ can also use @key{RET} in another way: to partition lengthy |
1127 | output, in a way similar to the common utility @code{more} | |
29a2b744 | 1128 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many |
b80282d5 RP |
1129 | in this situation, _GDBN__ disables command repetition after any command |
1130 | that generates this sort of display. | |
1131 | ||
70b88761 RP |
1132 | @kindex # |
1133 | @cindex comment | |
1134 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
29a2b744 | 1135 | This is useful mainly in command files (@pxref{Command Files}). |
70b88761 RP |
1136 | |
1137 | @node Help, , Command Syntax, Commands | |
1138 | @section Getting Help | |
1139 | @cindex online documentation | |
1140 | @kindex help | |
1041a570 | 1141 | |
70b88761 | 1142 | You can always ask _GDBN__ itself for information on its commands, using the |
e251e767 | 1143 | command @code{help}. |
70b88761 RP |
1144 | |
1145 | @table @code | |
1146 | @item help | |
1147 | @itemx h | |
1148 | @kindex h | |
1149 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1150 | display a short list of named classes of commands: | |
1041a570 | 1151 | |
70b88761 RP |
1152 | @smallexample |
1153 | (_GDBP__) help | |
1154 | List of classes of commands: | |
1155 | ||
1156 | running -- Running the program | |
1157 | stack -- Examining the stack | |
1158 | data -- Examining data | |
1159 | breakpoints -- Making program stop at certain points | |
1160 | files -- Specifying and examining files | |
1161 | status -- Status inquiries | |
1162 | support -- Support facilities | |
1163 | user-defined -- User-defined commands | |
1164 | aliases -- Aliases of other commands | |
1165 | obscure -- Obscure features | |
1166 | ||
203eea5d RP |
1167 | Type "help" followed by a class name for a list of |
1168 | commands in that class. | |
1169 | Type "help" followed by command name for full | |
1170 | documentation. | |
70b88761 | 1171 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1172 | (_GDBP__) |
70b88761 RP |
1173 | @end smallexample |
1174 | ||
1175 | @item help @var{class} | |
1176 | Using one of the general help classes as an argument, you can get a | |
1177 | list of the individual commands in that class. For example, here is the | |
1178 | help display for the class @code{status}: | |
1041a570 | 1179 | |
70b88761 RP |
1180 | @smallexample |
1181 | (_GDBP__) help status | |
1182 | Status inquiries. | |
1183 | ||
1184 | List of commands: | |
1185 | ||
1186 | show -- Generic command for showing things set with "set" | |
1187 | info -- Generic command for printing status | |
1188 | ||
203eea5d RP |
1189 | Type "help" followed by command name for full |
1190 | documentation. | |
70b88761 | 1191 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1192 | (_GDBP__) |
70b88761 RP |
1193 | @end smallexample |
1194 | ||
1195 | @item help @var{command} | |
1196 | With a command name as @code{help} argument, _GDBN__ will display a | |
e251e767 | 1197 | short paragraph on how to use that command. |
70b88761 RP |
1198 | @end table |
1199 | ||
1200 | In addition to @code{help}, you can use the _GDBN__ commands @code{info} | |
1201 | and @code{show} to inquire about the state of your program, or the state | |
1202 | of _GDBN__ itself. Each command supports many topics of inquiry; this | |
1203 | manual introduces each of them in the appropriate context. The listings | |
1204 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1205 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1206 | |
1207 | @c @group | |
1208 | @table @code | |
1209 | @item info | |
1210 | @kindex info | |
1211 | @kindex i | |
1212 | This command (abbreviated @code{i}) is for describing the state of your | |
1213 | program; for example, it can list the arguments given to your program | |
1214 | (@code{info args}), the registers currently in use (@code{info | |
1041a570 | 1215 | registers}), or the breakpoints you have set (@code{info breakpoints}). |
70b88761 RP |
1216 | You can get a complete list of the @code{info} sub-commands with |
1217 | @w{@code{help info}}. | |
1218 | ||
1219 | @kindex show | |
1220 | @item show | |
1221 | In contrast, @code{show} is for describing the state of _GDBN__ itself. | |
1222 | You can change most of the things you can @code{show}, by using the | |
1223 | related command @code{set}; for example, you can control what number | |
1224 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1225 | which is currently in use with @code{show radix}. |
70b88761 RP |
1226 | |
1227 | @kindex info set | |
1228 | To display all the settable parameters and their current | |
1229 | values, you can use @code{show} with no arguments; you may also use | |
1230 | @code{info set}. Both commands produce the same display. | |
1231 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1232 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1233 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1234 | @end table | |
1235 | @c @end group | |
1236 | ||
1237 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1238 | exceptional in lacking corresponding @code{set} commands: | |
1239 | ||
1240 | @table @code | |
1241 | @kindex show version | |
3d3ab540 | 1242 | @cindex version number |
70b88761 RP |
1243 | @item show version |
1244 | Show what version of _GDBN__ is running. You should include this | |
1041a570 RP |
1245 | information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are in |
1246 | use at your site, you may occasionally want to make sure what version | |
1247 | of _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced, | |
1248 | and old ones may wither away. The version number is also announced | |
1249 | when you start _GDBN__ with no arguments. | |
70b88761 RP |
1250 | |
1251 | @kindex show copying | |
1252 | @item show copying | |
1253 | Display information about permission for copying _GDBN__. | |
1254 | ||
1255 | @kindex show warranty | |
1256 | @item show warranty | |
1257 | Display the GNU ``NO WARRANTY'' statement. | |
1258 | @end table | |
1259 | ||
1260 | @node Running, Stopping, Commands, Top | |
1261 | @chapter Running Programs Under _GDBN__ | |
1262 | ||
1041a570 RP |
1263 | To debug a program, you must run it under _GDBN__. |
1264 | ||
70b88761 | 1265 | @menu |
b80282d5 RP |
1266 | * Compilation:: Compiling for Debugging |
1267 | * Starting:: Starting your Program | |
1268 | * Arguments:: Your Program's Arguments | |
1269 | * Environment:: Your Program's Environment | |
1270 | * Working Directory:: Your Program's Working Directory | |
1271 | * Input/Output:: Your Program's Input and Output | |
1272 | * Attach:: Debugging an Already-Running Process | |
1273 | * Kill Process:: Killing the Child Process | |
70b88761 RP |
1274 | @end menu |
1275 | ||
1276 | @node Compilation, Starting, Running, Running | |
1277 | @section Compiling for Debugging | |
1278 | ||
1279 | In order to debug a program effectively, you need to generate | |
1280 | debugging information when you compile it. This debugging information | |
1281 | is stored in the object file; it describes the data type of each | |
1282 | variable or function and the correspondence between source line numbers | |
1283 | and addresses in the executable code. | |
1284 | ||
1285 | To request debugging information, specify the @samp{-g} option when you run | |
1286 | the compiler. | |
1287 | ||
1288 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1289 | options together. Using those compilers, you cannot generate optimized | |
1290 | executables containing debugging information. | |
1291 | ||
1292 | The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it | |
1293 | possible to debug optimized code. We recommend that you @emph{always} use | |
29a2b744 RP |
1294 | @samp{-g} whenever you compile a program. You may think your program is |
1295 | correct, but there is no sense in pushing your luck. | |
70b88761 RP |
1296 | |
1297 | Some things do not work as well with @samp{-g -O} as with just | |
1298 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1299 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1300 | please report it as a bug (including a test case!). | |
1301 | ||
1302 | Older versions of the GNU C compiler permitted a variant option | |
1303 | @samp{-gg} for debugging information. _GDBN__ no longer supports this | |
1304 | format; if your GNU C compiler has this option, do not use it. | |
1305 | ||
1306 | @ignore | |
1307 | @comment As far as I know, there are no cases in which _GDBN__ will | |
1308 | @comment produce strange output in this case. (but no promises). | |
1309 | If your program includes archives made with the @code{ar} program, and | |
1310 | if the object files used as input to @code{ar} were compiled without the | |
1311 | @samp{-g} option and have names longer than 15 characters, _GDBN__ will get | |
29a2b744 | 1312 | confused reading your program's symbol table. No error message will be |
70b88761 RP |
1313 | given, but _GDBN__ may behave strangely. The reason for this problem is a |
1314 | deficiency in the Unix archive file format, which cannot represent file | |
1315 | names longer than 15 characters. | |
1316 | ||
1317 | To avoid this problem, compile the archive members with the @samp{-g} | |
1318 | option or use shorter file names. Alternatively, use a version of GNU | |
1319 | @code{ar} dated more recently than August 1989. | |
1320 | @end ignore | |
1321 | ||
70b88761 RP |
1322 | @node Starting, Arguments, Compilation, Running |
1323 | @section Starting your Program | |
1324 | @cindex starting | |
1325 | @cindex running | |
1041a570 | 1326 | |
70b88761 RP |
1327 | @table @code |
1328 | @item run | |
1329 | @itemx r | |
1330 | @kindex run | |
1041a570 RP |
1331 | Use the @code{run} command to start your program under _GDBN__. You must |
1332 | first specify the program name | |
e251e767 | 1333 | _if__(_VXWORKS__) |
7463aadd | 1334 | (except on VxWorks) |
70b88761 | 1335 | _fi__(_VXWORKS__) |
1041a570 RP |
1336 | with an argument to |
1337 | _GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the | |
1338 | @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to | |
1339 | Specify Files}). | |
1340 | ||
70b88761 RP |
1341 | @end table |
1342 | ||
29a2b744 RP |
1343 | If you are running your program in an execution environment that |
1344 | supports processes, @code{run} creates an inferior process and makes | |
1345 | that process run your program. (In environments without processes, | |
1346 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
1347 | |
1348 | The execution of a program is affected by certain information it | |
1349 | receives from its superior. _GDBN__ provides ways to specify this | |
29a2b744 RP |
1350 | information, which you must do @i{before} starting your program. (You |
1351 | can change it after starting your program, but such changes will only affect | |
1352 | your program the next time you start it.) This information may be | |
70b88761 RP |
1353 | divided into four categories: |
1354 | ||
1355 | @table @asis | |
1356 | @item The @i{arguments.} | |
29a2b744 | 1357 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
1358 | @code{run} command. If a shell is available on your target, the shell |
1359 | is used to pass the arguments, so that you may use normal conventions | |
1360 | (such as wildcard expansion or variable substitution) in describing | |
1361 | the arguments. In Unix systems, you can control which shell is used | |
1362 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
1363 | Program's Arguments}. | |
70b88761 RP |
1364 | |
1365 | @item The @i{environment.} | |
1366 | Your program normally inherits its environment from _GDBN__, but you can | |
1367 | use the _GDBN__ commands @code{set environment} and @code{unset | |
1368 | environment} to change parts of the environment that will be given to | |
1041a570 | 1369 | your program. @xref{Environment, ,Your Program's Environment}. |
70b88761 RP |
1370 | |
1371 | @item The @i{working directory.} | |
1372 | Your program inherits its working directory from _GDBN__. You can set | |
1373 | _GDBN__'s working directory with the @code{cd} command in _GDBN__. | |
29a2b744 | 1374 | @xref{Working Directory, ,Your Program's Working Directory}. |
70b88761 RP |
1375 | |
1376 | @item The @i{standard input and output.} | |
1377 | Your program normally uses the same device for standard input and | |
1378 | standard output as _GDBN__ is using. You can redirect input and output | |
1379 | in the @code{run} command line, or you can use the @code{tty} command to | |
1380 | set a different device for your program. | |
1041a570 | 1381 | @xref{Input/Output, ,Your Program's Input and Output}. |
3d3ab540 RP |
1382 | |
1383 | @cindex pipes | |
29a2b744 RP |
1384 | @emph{Warning:} While input and output redirection work, you cannot use |
1385 | pipes to pass the output of the program you are debugging to another | |
3d3ab540 RP |
1386 | program; if you attempt this, _GDBN__ is likely to wind up debugging the |
1387 | wrong program. | |
70b88761 RP |
1388 | @end table |
1389 | ||
29a2b744 | 1390 | @c FIXME: Rewrite following paragraph, especially its third sentence. |
1041a570 RP |
1391 | When you issue the @code{run} command, your program begins to execute |
1392 | immediately. @xref{Stopping, ,Stopping and Continuing}, for | |
29a2b744 RP |
1393 | discussion of how to arrange for your program to stop. Once your |
1394 | program has been started by the @code{run} command (and then stopped), | |
1041a570 RP |
1395 | you may evaluate expressions that involve calls to functions in your |
1396 | program, using the @code{print} or @code{call} commands. @xref{Data, | |
1397 | ,Examining Data}. | |
70b88761 | 1398 | |
29a2b744 | 1399 | If the modification time of your symbol file has changed since the |
1041a570 RP |
1400 | last time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and |
1401 | re-read it. When it does this, _GDBN__ tries to retain your current | |
1402 | breakpoints. | |
70b88761 RP |
1403 | |
1404 | @node Arguments, Environment, Starting, Running | |
1405 | @section Your Program's Arguments | |
1406 | ||
1407 | @cindex arguments (to your program) | |
1408 | The arguments to your program can be specified by the arguments of the | |
1409 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 1410 | characters and performs redirection of I/O, and thence to your program. |
70b88761 RP |
1411 | _GDBN__ uses the shell indicated by your environment variable |
1412 | @code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}. | |
1413 | ||
1414 | @code{run} with no arguments uses the same arguments used by the previous | |
1415 | @code{run}, or those set by the @code{set args} command. | |
1416 | ||
1417 | @kindex set args | |
1418 | @table @code | |
1419 | @item set args | |
1420 | Specify the arguments to be used the next time your program is run. If | |
1421 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 1422 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
1423 | using @code{set args} before the next @code{run} is the only way to run |
1424 | it again without arguments. | |
1425 | ||
1426 | @item show args | |
1427 | @kindex show args | |
1428 | Show the arguments to give your program when it is started. | |
1429 | @end table | |
1430 | ||
1431 | @node Environment, Working Directory, Arguments, Running | |
1432 | @section Your Program's Environment | |
1433 | ||
1434 | @cindex environment (of your program) | |
1435 | The @dfn{environment} consists of a set of environment variables and | |
1436 | their values. Environment variables conventionally record such things as | |
1437 | your user name, your home directory, your terminal type, and your search | |
1438 | path for programs to run. Usually you set up environment variables with | |
1439 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 1440 | debugging, it can be useful to try running your program with a modified |
70b88761 RP |
1441 | environment without having to start _GDBN__ over again. |
1442 | ||
1443 | @table @code | |
1444 | @item path @var{directory} | |
1445 | @kindex path | |
1446 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1447 | (the search path for executables), for both _GDBN__ and your program. | |
1448 | You may specify several directory names, separated by @samp{:} or | |
1449 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 1450 | the front, so it will be searched sooner. |
7463aadd RP |
1451 | |
1452 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1453 | working directory at the time _GDBN__ searches the path. If you use | |
1454 | @samp{.} instead, it refers to the directory where you executed the | |
1455 | @code{path} command. _GDBN__ fills in the current path where needed in | |
1456 | the @var{directory} argument, before adding it to the search path. | |
29a2b744 | 1457 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
1458 | @c document that, since repeating it would be a no-op. |
1459 | ||
1460 | @item show paths | |
1461 | @kindex show paths | |
1462 | Display the list of search paths for executables (the @code{PATH} | |
1463 | environment variable). | |
1464 | ||
1465 | @item show environment @r{[}@var{varname}@r{]} | |
1466 | @kindex show environment | |
1467 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 1468 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
1469 | print the names and values of all environment variables to be given to |
1470 | your program. You can abbreviate @code{environment} as @code{env}. | |
1471 | ||
7463aadd | 1472 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 RP |
1473 | @kindex set environment |
1474 | Sets environment variable @var{varname} to @var{value}. The value | |
1475 | changes for your program only, not for _GDBN__ itself. @var{value} may | |
1476 | be any string; the values of environment variables are just strings, and | |
1477 | any interpretation is supplied by your program itself. The @var{value} | |
1478 | parameter is optional; if it is eliminated, the variable is set to a | |
1479 | null value. | |
29a2b744 | 1480 | @c "any string" here does not include leading, trailing |
70b88761 RP |
1481 | @c blanks. Gnu asks: does anyone care? |
1482 | ||
1483 | For example, this command: | |
1484 | ||
1485 | @example | |
1486 | set env USER = foo | |
1487 | @end example | |
1488 | ||
1489 | @noindent | |
1490 | tells a Unix program, when subsequently run, that its user is named | |
1491 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1492 | are not actually required.) | |
1493 | ||
1494 | @item unset environment @var{varname} | |
1495 | @kindex unset environment | |
1496 | Remove variable @var{varname} from the environment to be passed to your | |
1497 | program. This is different from @samp{set env @var{varname} =}; | |
1498 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 1499 | rather than assigning it an empty value. |
70b88761 RP |
1500 | @end table |
1501 | ||
1502 | @node Working Directory, Input/Output, Environment, Running | |
1503 | @section Your Program's Working Directory | |
1504 | ||
1505 | @cindex working directory (of your program) | |
1506 | Each time you start your program with @code{run}, it inherits its | |
1507 | working directory from the current working directory of _GDBN__. _GDBN__'s | |
1508 | working directory is initially whatever it inherited from its parent | |
1509 | process (typically the shell), but you can specify a new working | |
1510 | directory in _GDBN__ with the @code{cd} command. | |
1511 | ||
1512 | The _GDBN__ working directory also serves as a default for the commands | |
1041a570 RP |
1513 | that specify files for _GDBN__ to operate on. @xref{Files, ,Commands to |
1514 | Specify Files}. | |
70b88761 RP |
1515 | |
1516 | @table @code | |
1517 | @item cd @var{directory} | |
1518 | @kindex cd | |
1519 | Set _GDBN__'s working directory to @var{directory}. | |
1520 | ||
1521 | @item pwd | |
1522 | @kindex pwd | |
1523 | Print _GDBN__'s working directory. | |
1524 | @end table | |
1525 | ||
1526 | @node Input/Output, Attach, Working Directory, Running | |
1527 | @section Your Program's Input and Output | |
1528 | ||
1529 | @cindex redirection | |
1530 | @cindex i/o | |
1531 | @cindex terminal | |
1532 | By default, the program you run under _GDBN__ does input and output to | |
1533 | the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to | |
1534 | its own terminal modes to interact with you, but it records the terminal | |
1535 | modes your program was using and switches back to them when you continue | |
1536 | running your program. | |
1537 | ||
1538 | @table @code | |
1539 | @item info terminal | |
1540 | @kindex info terminal | |
1541 | Displays _GDBN__'s recorded information about the terminal modes your | |
1542 | program is using. | |
1543 | @end table | |
1544 | ||
29a2b744 | 1545 | You can redirect your program's input and/or output using shell |
70b88761 RP |
1546 | redirection with the @code{run} command. For example, |
1547 | ||
1548 | _0__@example | |
1549 | run > outfile | |
1550 | _1__@end example | |
1551 | ||
1552 | @noindent | |
29a2b744 | 1553 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
1554 | |
1555 | @kindex tty | |
1556 | @cindex controlling terminal | |
29a2b744 | 1557 | Another way to specify where your program should do input and output is |
70b88761 RP |
1558 | with the @code{tty} command. This command accepts a file name as |
1559 | argument, and causes this file to be the default for future @code{run} | |
1560 | commands. It also resets the controlling terminal for the child | |
1561 | process, for future @code{run} commands. For example, | |
1562 | ||
1563 | @example | |
1564 | tty /dev/ttyb | |
1565 | @end example | |
1566 | ||
1567 | @noindent | |
1568 | directs that processes started with subsequent @code{run} commands | |
1569 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1570 | that as their controlling terminal. | |
1571 | ||
1572 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1573 | effect on the input/output device, but not its effect on the controlling | |
1574 | terminal. | |
1575 | ||
1576 | When you use the @code{tty} command or redirect input in the @code{run} | |
1577 | command, only the input @emph{for your program} is affected. The input | |
1578 | for _GDBN__ still comes from your terminal. | |
1579 | ||
1580 | @node Attach, Kill Process, Input/Output, Running | |
1581 | @section Debugging an Already-Running Process | |
1582 | @kindex attach | |
1583 | @cindex attach | |
1584 | ||
1585 | @table @code | |
1586 | @item attach @var{process-id} | |
1587 | This command | |
1588 | attaches to a running process---one that was started outside _GDBN__. | |
1589 | (@code{info files} will show your active targets.) The command takes as | |
1590 | argument a process ID. The usual way to find out the process-id of | |
1591 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
e251e767 | 1592 | shell command. |
70b88761 RP |
1593 | |
1594 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1595 | executing the command. | |
1596 | @end table | |
1597 | ||
1598 | To use @code{attach}, you must be debugging in an environment which | |
1599 | supports processes. You must also have permission to send the process a | |
1600 | signal, and it must have the same effective user ID as the _GDBN__ | |
1601 | process. | |
1602 | ||
1603 | When using @code{attach}, you should first use the @code{file} command | |
1604 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 1605 | @xref{Files, ,Commands to Specify Files}. |
70b88761 RP |
1606 | |
1607 | The first thing _GDBN__ does after arranging to debug the specified | |
1608 | process is to stop it. You can examine and modify an attached process | |
1609 | with all the _GDBN__ commands that are ordinarily available when you start | |
1610 | processes with @code{run}. You can insert breakpoints; you can step and | |
1611 | continue; you can modify storage. If you would rather the process | |
1612 | continue running, you may use the @code{continue} command after | |
1613 | attaching _GDBN__ to the process. | |
1614 | ||
1615 | @table @code | |
1616 | @item detach | |
1617 | @kindex detach | |
1618 | When you have finished debugging the attached process, you can use the | |
1619 | @code{detach} command to release it from _GDBN__'s control. Detaching | |
1620 | the process continues its execution. After the @code{detach} command, | |
1621 | that process and _GDBN__ become completely independent once more, and you | |
1622 | are ready to @code{attach} another process or start one with @code{run}. | |
1623 | @code{detach} will not repeat if you press @key{RET} again after | |
1624 | executing the command. | |
1625 | @end table | |
1626 | ||
1627 | If you exit _GDBN__ or use the @code{run} command while you have an attached | |
1628 | process, you kill that process. By default, you will be asked for | |
1629 | confirmation if you try to do either of these things; you can control | |
1630 | whether or not you need to confirm by using the @code{set confirm} command | |
29a2b744 | 1631 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). |
70b88761 RP |
1632 | |
1633 | @node Kill Process, , Attach, Running | |
1634 | @c @group | |
1635 | @section Killing the Child Process | |
1636 | ||
1637 | @table @code | |
1638 | @item kill | |
1639 | @kindex kill | |
1640 | Kill the child process in which your program is running under _GDBN__. | |
1641 | @end table | |
1642 | ||
1643 | This command is useful if you wish to debug a core dump instead of a | |
1644 | running process. _GDBN__ ignores any core dump file while your program | |
1645 | is running. | |
1646 | @c @end group | |
1647 | ||
29a2b744 | 1648 | On some operating systems, a program cannot be executed outside _GDBN__ |
70b88761 | 1649 | while you have breakpoints set on it inside _GDBN__. You can use the |
29a2b744 | 1650 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
1651 | outside the debugger. |
1652 | ||
1653 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 1654 | relink your program, since on many systems it is impossible to modify an |
70b88761 RP |
1655 | executable file while it is running in a process. In this case, when you |
1656 | next type @code{run}, _GDBN__ will notice that the file has changed, and | |
1657 | will re-read the symbol table (while trying to preserve your current | |
1658 | breakpoint settings). | |
1659 | ||
1660 | @node Stopping, Stack, Running, Top | |
1661 | @chapter Stopping and Continuing | |
1662 | ||
1663 | The principal purpose of using a debugger is so that you can stop your | |
29a2b744 | 1664 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
1665 | trouble, you can investigate and find out why. |
1666 | ||
1667 | Inside _GDBN__, your program may stop for any of several reasons, such | |
1668 | as a signal, a breakpoint, or reaching a new line after a _GDBN__ | |
1669 | command such as @code{step}. You may then examine and change | |
1670 | variables, set new breakpoints or remove old ones, and then continue | |
1671 | execution. Usually, the messages shown by _GDBN__ provide ample | |
1672 | explanation of the status of your program---but you can also explicitly | |
1673 | request this information at any time. | |
1674 | ||
1675 | @table @code | |
1676 | @item info program | |
1677 | @kindex info program | |
1678 | Display information about the status of your program: whether it is | |
1679 | running or not, what process it is, and why it stopped. | |
1680 | @end table | |
1681 | ||
1682 | @menu | |
b80282d5 RP |
1683 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
1684 | * Continuing and Stepping:: Resuming Execution | |
1685 | * Signals:: Signals | |
70b88761 RP |
1686 | @end menu |
1687 | ||
3d3ab540 | 1688 | @node Breakpoints, Continuing and Stepping, Stopping, Stopping |
70b88761 RP |
1689 | @section Breakpoints, Watchpoints, and Exceptions |
1690 | ||
1691 | @cindex breakpoints | |
1692 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 1693 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 1694 | conditions to control in finer detail whether your program will stop. |
70b88761 | 1695 | You can set breakpoints with the @code{break} command and its variants |
29a2b744 RP |
1696 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where |
1697 | your program should stop by line number, function name or exact address | |
1041a570 | 1698 | in the program. In languages with exception handling (such as GNU |
29a2b744 | 1699 | C++), you can also set breakpoints where an exception is raised |
1041a570 | 1700 | (@pxref{Exception Handling, ,Breakpoints and Exceptions}). |
70b88761 RP |
1701 | |
1702 | @cindex watchpoints | |
29a2b744 RP |
1703 | A @dfn{watchpoint} is a special breakpoint that stops your program |
1704 | when the value of an expression changes. You must use a different | |
1705 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
1706 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
1707 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1041a570 | 1708 | and watchpoints using the same commands. |
70b88761 RP |
1709 | |
1710 | Each breakpoint or watchpoint is assigned a number when it is created; | |
1711 | these numbers are successive integers starting with one. In many of the | |
1712 | commands for controlling various features of breakpoints you use the | |
1713 | breakpoint number to say which breakpoint you want to change. Each | |
1714 | breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 1715 | no effect on your program until you enable it again. |
70b88761 RP |
1716 | |
1717 | @menu | |
b80282d5 RP |
1718 | * Set Breaks:: Setting Breakpoints |
1719 | * Set Watchpoints:: Setting Watchpoints | |
1720 | * Exception Handling:: Breakpoints and Exceptions | |
1721 | * Delete Breaks:: Deleting Breakpoints | |
1722 | * Disabling:: Disabling Breakpoints | |
1723 | * Conditions:: Break Conditions | |
1724 | * Break Commands:: Breakpoint Command Lists | |
1725 | * Breakpoint Menus:: Breakpoint Menus | |
e251e767 | 1726 | * Error in Breakpoints:: |
70b88761 RP |
1727 | @end menu |
1728 | ||
1729 | @node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints | |
1730 | @subsection Setting Breakpoints | |
1731 | ||
4906534f RP |
1732 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
1733 | @c consider in particular declaration with/without initialization. | |
1734 | @c | |
1735 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1736 | ||
70b88761 RP |
1737 | @kindex break |
1738 | @kindex b | |
1739 | Breakpoints are set with the @code{break} command (abbreviated @code{b}). | |
1740 | ||
1741 | You have several ways to say where the breakpoint should go. | |
1742 | ||
1743 | @table @code | |
1744 | @item break @var{function} | |
1745 | Set a breakpoint at entry to function @var{function}. When using source | |
1746 | languages that permit overloading of symbols, such as C++, | |
1747 | @var{function} may refer to more than one possible place to break. | |
1748 | @xref{Breakpoint Menus}, for a discussion of that situation. | |
1749 | ||
1750 | @item break +@var{offset} | |
1751 | @itemx break -@var{offset} | |
1752 | Set a breakpoint some number of lines forward or back from the position | |
1753 | at which execution stopped in the currently selected frame. | |
1754 | ||
1755 | @item break @var{linenum} | |
1756 | Set a breakpoint at line @var{linenum} in the current source file. | |
1757 | That file is the last file whose source text was printed. This | |
29a2b744 | 1758 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
1759 | code on that line. |
1760 | ||
1761 | @item break @var{filename}:@var{linenum} | |
1762 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1763 | ||
1764 | @item break @var{filename}:@var{function} | |
1765 | Set a breakpoint at entry to function @var{function} found in file | |
1766 | @var{filename}. Specifying a file name as well as a function name is | |
1767 | superfluous except when multiple files contain similarly named | |
1768 | functions. | |
1769 | ||
1770 | @item break *@var{address} | |
1771 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 1772 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
1773 | information or source files. |
1774 | ||
1775 | @item break | |
29a2b744 RP |
1776 | When called without any arguments, @code{break} sets a breakpoint at |
1777 | the next instruction to be executed in the selected stack frame | |
1778 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
1779 | innermost, this will cause your program to stop as soon as control | |
1780 | returns to that frame. This is similar to the effect of a | |
1781 | @code{finish} command in the frame inside the selected frame---except | |
1782 | that @code{finish} does not leave an active breakpoint. If you use | |
1041a570 RP |
1783 | @code{break} without an argument in the innermost frame, _GDBN__ will stop |
1784 | the next time it reaches the current location; this may be useful | |
1785 | inside loops. | |
70b88761 RP |
1786 | |
1787 | _GDBN__ normally ignores breakpoints when it resumes execution, until at | |
1788 | least one instruction has been executed. If it did not do this, you | |
1789 | would be unable to proceed past a breakpoint without first disabling the | |
1790 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 1791 | existed when your program stopped. |
70b88761 RP |
1792 | |
1793 | @item break @dots{} if @var{cond} | |
1794 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1795 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 1796 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
1797 | @samp{@dots{}} stands for one of the possible arguments described |
1798 | above (or no argument) specifying where to break. @xref{Conditions, | |
1799 | ,Break Conditions}, for more information on breakpoint conditions. | |
70b88761 RP |
1800 | |
1801 | @item tbreak @var{args} | |
1802 | @kindex tbreak | |
1803 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1804 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 RP |
1805 | way, but the breakpoint is automatically disabled after the first time your |
1806 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
70b88761 RP |
1807 | |
1808 | @item rbreak @var{regex} | |
1809 | @kindex rbreak | |
1810 | @cindex regular expression | |
4906534f | 1811 | @c FIXME what kind of regexp? |
70b88761 | 1812 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 1813 | @var{regex}. This command |
70b88761 RP |
1814 | sets an unconditional breakpoint on all matches, printing a list of all |
1815 | breakpoints it set. Once these breakpoints are set, they are treated | |
1816 | just like the breakpoints set with the @code{break} command. They can | |
1817 | be deleted, disabled, made conditional, etc., in the standard ways. | |
1818 | ||
b80282d5 RP |
1819 | When debugging C++ programs, @code{rbreak} is useful for setting |
1820 | breakpoints on overloaded functions that are not members of any special | |
1821 | classes. | |
1822 | ||
70b88761 | 1823 | @kindex info breakpoints |
c338a2fd | 1824 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 RP |
1825 | @item info breakpoints @r{[}@var{n}@r{]} |
1826 | @item info break @r{[}@var{n}@r{]} | |
1827 | Print a list of all breakpoints (but not watchpoints) set and not | |
29a2b744 | 1828 | deleted, showing their numbers, where in your program they are, and any |
70b88761 RP |
1829 | special features in use for them. Disabled breakpoints are included in |
1830 | the list, but marked as disabled. @code{info break} with a breakpoint | |
29a2b744 RP |
1831 | number @var{n} as argument lists only that breakpoint. The |
1832 | convenience variable @code{$_} and the default examining-address for | |
1833 | the @code{x} command are set to the address of the last breakpoint | |
1834 | listed (@pxref{Memory, ,Examining Memory}). The equivalent command | |
1041a570 RP |
1835 | for watchpoints is @code{info watch}. |
1836 | @end table | |
70b88761 | 1837 | |
1041a570 RP |
1838 | _GDBN__ allows you to set any number of breakpoints at the same place in |
1839 | your program. There is nothing silly or meaningless about this. When | |
1840 | the breakpoints are conditional, this is even useful | |
29a2b744 | 1841 | (@pxref{Conditions, ,Break Conditions}). |
70b88761 RP |
1842 | |
1843 | @node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints | |
1844 | @subsection Setting Watchpoints | |
1845 | @cindex setting watchpoints | |
1041a570 | 1846 | |
70b88761 | 1847 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 1848 | expression changes, without having to predict a particular place |
70b88761 RP |
1849 | where this may happen. |
1850 | ||
1851 | Watchpoints currently execute two orders of magnitude more slowly than | |
1852 | other breakpoints, but this can well be worth it to catch errors where | |
1853 | you have no clue what part of your program is the culprit. Some | |
1854 | processors provide special hardware to support watchpoint evaluation; future | |
1855 | releases of _GDBN__ will use such hardware if it is available. | |
1856 | ||
1857 | @table @code | |
e251e767 | 1858 | @kindex watch |
70b88761 RP |
1859 | @item watch @var{expr} |
1860 | Set a watchpoint for an expression. | |
1861 | ||
1862 | @kindex info watchpoints | |
1863 | @item info watchpoints | |
1864 | This command prints a list of watchpoints; it is otherwise similar to | |
1865 | @code{info break}. | |
1866 | @end table | |
1867 | ||
1868 | @node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints | |
1869 | @subsection Breakpoints and Exceptions | |
1870 | @cindex exception handlers | |
1871 | ||
b80282d5 | 1872 | Some languages, such as GNU C++, implement exception handling. You can |
29a2b744 RP |
1873 | use _GDBN__ to examine what caused your program to raise an exception, |
1874 | and to list the exceptions your program is prepared to handle at a | |
70b88761 RP |
1875 | given point in time. |
1876 | ||
1877 | @table @code | |
1878 | @item catch @var{exceptions} | |
1879 | @kindex catch | |
1880 | You can set breakpoints at active exception handlers by using the | |
1881 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
1882 | to catch. | |
1883 | @end table | |
1884 | ||
29a2b744 RP |
1885 | You can use @code{info catch} to list active exception handlers. |
1886 | @xref{Frame Info, ,Information About a Frame}. | |
70b88761 RP |
1887 | |
1888 | There are currently some limitations to exception handling in _GDBN__. | |
1889 | These will be corrected in a future release. | |
1890 | ||
1891 | @itemize @bullet | |
1892 | @item | |
1893 | If you call a function interactively, _GDBN__ normally returns | |
1894 | control to you when the function has finished executing. If the call | |
1895 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 1896 | returns control to you and cause your program to simply continue |
70b88761 RP |
1897 | running until it hits a breakpoint, catches a signal that _GDBN__ is |
1898 | listening for, or exits. | |
1899 | @item | |
1900 | You cannot raise an exception interactively. | |
1901 | @item | |
1902 | You cannot interactively install an exception handler. | |
1903 | @end itemize | |
1904 | ||
1905 | @cindex raise exceptions | |
1906 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 1907 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
1908 | stop @emph{before} the exception handler is called, since that way you |
1909 | can see the stack before any unwinding takes place. If you set a | |
1910 | breakpoint in an exception handler instead, it may not be easy to find | |
1911 | out where the exception was raised. | |
1912 | ||
1913 | To stop just before an exception handler is called, you need some | |
b80282d5 | 1914 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
1915 | raised by calling a library function named @code{__raise_exception} |
1916 | which has the following ANSI C interface: | |
1917 | ||
1918 | @example | |
b80282d5 | 1919 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
1920 | ID is the exception identifier. */ |
1921 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
1922 | @end example | |
1923 | ||
1924 | @noindent | |
1925 | To make the debugger catch all exceptions before any stack | |
1926 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
29a2b744 | 1927 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). |
70b88761 | 1928 | |
29a2b744 RP |
1929 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) |
1930 | that depends on the value of @var{id}, you can stop your program when | |
1931 | a specific exception is raised. You can use multiple conditional | |
1932 | breakpoints to stop your program when any of a number of exceptions are | |
1933 | raised. | |
70b88761 RP |
1934 | |
1935 | @node Delete Breaks, Disabling, Exception Handling, Breakpoints | |
1936 | @subsection Deleting Breakpoints | |
1937 | ||
1938 | @cindex clearing breakpoints, watchpoints | |
1939 | @cindex deleting breakpoints, watchpoints | |
1940 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 1941 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
1942 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
1943 | deleted no longer exists; it is forgotten. | |
1944 | ||
1945 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 1946 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
1947 | delete individual breakpoints or watchpoints by specifying their |
1948 | breakpoint numbers. | |
1949 | ||
1950 | It is not necessary to delete a breakpoint to proceed past it. _GDBN__ | |
1951 | automatically ignores breakpoints on the first instruction to be executed | |
1952 | when you continue execution without changing the execution address. | |
1953 | ||
1954 | @table @code | |
1955 | @item clear | |
1956 | @kindex clear | |
1957 | Delete any breakpoints at the next instruction to be executed in the | |
29a2b744 RP |
1958 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When |
1959 | the innermost frame is selected, this is a good way to delete a | |
1960 | breakpoint where your program just stopped. | |
70b88761 RP |
1961 | |
1962 | @item clear @var{function} | |
1963 | @itemx clear @var{filename}:@var{function} | |
1964 | Delete any breakpoints set at entry to the function @var{function}. | |
1965 | ||
1966 | @item clear @var{linenum} | |
1967 | @itemx clear @var{filename}:@var{linenum} | |
1968 | Delete any breakpoints set at or within the code of the specified line. | |
1969 | ||
1970 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1971 | @cindex delete breakpoints | |
1972 | @kindex delete | |
1973 | @kindex d | |
1974 | Delete the breakpoints or watchpoints of the numbers specified as | |
1975 | arguments. If no argument is specified, delete all breakpoints (_GDBN__ | |
1041a570 | 1976 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
1977 | can abbreviate this command as @code{d}. |
1978 | @end table | |
1979 | ||
1980 | @node Disabling, Conditions, Delete Breaks, Breakpoints | |
1981 | @subsection Disabling Breakpoints | |
1982 | ||
1983 | @cindex disabled breakpoints | |
1984 | @cindex enabled breakpoints | |
1985 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
1986 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
1987 | been deleted, but remembers the information on the breakpoint so that | |
1988 | you can @dfn{enable} it again later. | |
1989 | ||
1990 | You disable and enable breakpoints and watchpoints with the | |
1991 | @code{enable} and @code{disable} commands, optionally specifying one or | |
1992 | more breakpoint numbers as arguments. Use @code{info break} or | |
1993 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 1994 | do not know which numbers to use. |
70b88761 RP |
1995 | |
1996 | A breakpoint or watchpoint can have any of four different states of | |
1997 | enablement: | |
1998 | ||
1999 | @itemize @bullet | |
2000 | @item | |
29a2b744 | 2001 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2002 | with the @code{break} command starts out in this state. |
2003 | @item | |
29a2b744 | 2004 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2005 | @item |
29a2b744 | 2006 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2007 | when it does so it will become disabled. A breakpoint set |
2008 | with the @code{tbreak} command starts out in this state. | |
2009 | @item | |
29a2b744 | 2010 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2011 | immediately after it does so it will be deleted permanently. |
2012 | @end itemize | |
2013 | ||
2014 | You can use the following commands to enable or disable breakpoints and | |
2015 | watchpoints: | |
2016 | ||
2017 | @table @code | |
2018 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2019 | @kindex disable breakpoints | |
2020 | @kindex disable | |
2021 | @kindex dis | |
2022 | Disable the specified breakpoints---or all breakpoints, if none are | |
2023 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2024 | options such as ignore-counts, conditions and commands are remembered in | |
2025 | case the breakpoint is enabled again later. You may abbreviate | |
2026 | @code{disable} as @code{dis}. | |
2027 | ||
2028 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2029 | @kindex enable breakpoints | |
2030 | @kindex enable | |
2031 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2032 | become effective once again in stopping your program. |
70b88761 RP |
2033 | |
2034 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2035 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2036 | again the next time it stops your program. |
70b88761 RP |
2037 | |
2038 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2039 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2040 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2041 | @end table |
2042 | ||
29a2b744 RP |
2043 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
2044 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2045 | enabled; subsequently, they become disabled or enabled only when you | |
2046 | use one of the commands above. (The command @code{until} can set and | |
2047 | delete a breakpoint of its own, but it will not change the state of | |
1041a570 | 2048 | your other breakpoints; @pxref{Continuing and Stepping, ,Continuing and Stepping}.) |
70b88761 RP |
2049 | |
2050 | @node Conditions, Break Commands, Disabling, Breakpoints | |
2051 | @subsection Break Conditions | |
2052 | @cindex conditional breakpoints | |
2053 | @cindex breakpoint conditions | |
2054 | ||
4906534f RP |
2055 | @c FIXME what is scope of break condition expr? Context where wanted? |
2056 | @c in particular for a watchpoint? | |
29a2b744 | 2057 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2058 | specified place. You can also specify a @dfn{condition} for a |
2059 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2060 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2061 | a condition evaluates the expression each time your program reaches it, | |
2062 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2063 | |
2064 | This is the converse of using assertions for program validation; in that | |
2065 | situation, you want to stop when the assertion is violated---that is, | |
2066 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2067 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2068 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2069 | |
2070 | Conditions are also accepted for watchpoints; you may not need them, | |
2071 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2072 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2073 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2074 | one. |
70b88761 | 2075 | |
29a2b744 | 2076 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2077 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2078 | that log program progress, or to use your own print functions to |
2079 | format special data structures. The effects are completely predictable | |
2080 | unless there is another enabled breakpoint at the same address. (In | |
2081 | that case, _GDBN__ might see the other breakpoint first and stop your | |
2082 | program without checking the condition of this one.) Note that | |
2083 | breakpoint commands are usually more convenient and flexible for the | |
2084 | purpose of performing side effects when a breakpoint is reached | |
2085 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
70b88761 RP |
2086 | |
2087 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 RP |
2088 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
2089 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2090 | with the @code{condition} command. The @code{watch} command does not | |
2091 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2092 | impose a further condition on a watchpoint. | |
70b88761 | 2093 | |
e251e767 RP |
2094 | @table @code |
2095 | @item condition @var{bnum} @var{expression} | |
2096 | @kindex condition | |
70b88761 RP |
2097 | Specify @var{expression} as the break condition for breakpoint or |
2098 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2099 | your program only if the value of @var{expression} is true (nonzero, in |
70b88761 RP |
2100 | C). When you use @code{condition}, _GDBN__ checks @var{expression} |
2101 | immediately for syntactic correctness, and to determine whether symbols | |
1041a570 | 2102 | in it have referents in the context of your breakpoint. |
29a2b744 | 2103 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f RP |
2104 | @c about watchpoints? |
2105 | _GDBN__ does | |
70b88761 | 2106 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 2107 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
2108 | |
2109 | @item condition @var{bnum} | |
2110 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2111 | an ordinary unconditional breakpoint. | |
2112 | @end table | |
2113 | ||
2114 | @cindex ignore count (of breakpoint) | |
2115 | A special case of a breakpoint condition is to stop only when the | |
2116 | breakpoint has been reached a certain number of times. This is so | |
2117 | useful that there is a special way to do it, using the @dfn{ignore | |
2118 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2119 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 2120 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
2121 | ignore count is positive, then instead of stopping, it just decrements |
2122 | the ignore count by one and continues. As a result, if the ignore count | |
2123 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2124 | is reached. | |
2125 | ||
2126 | @table @code | |
2127 | @item ignore @var{bnum} @var{count} | |
2128 | @kindex ignore | |
2129 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2130 | The next @var{count} times the breakpoint is reached, your program's | |
2131 | execution will not stop; other than to decrement the ignore count, _GDBN__ | |
2132 | takes no action. | |
2133 | ||
2134 | To make the breakpoint stop the next time it is reached, specify | |
2135 | a count of zero. | |
2136 | ||
2137 | @item continue @var{count} | |
2138 | @itemx c @var{count} | |
2139 | @itemx fg @var{count} | |
2140 | @kindex continue @var{count} | |
29a2b744 RP |
2141 | Continue execution of your program, setting the ignore count of the |
2142 | breakpoint where your program stopped to @var{count} minus one. | |
2143 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
2144 | @var{count}'th time it is reached. |
2145 | ||
29a2b744 | 2146 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
2147 | due to a breakpoint. At other times, the argument to @code{continue} is |
2148 | ignored. | |
2149 | ||
2150 | The synonym @code{fg} is provided purely for convenience, and has | |
2151 | exactly the same behavior as other forms of the command. | |
2152 | @end table | |
2153 | ||
2154 | If a breakpoint has a positive ignore count and a condition, the condition | |
2155 | is not checked. Once the ignore count reaches zero, the condition will | |
2156 | be checked. | |
2157 | ||
29a2b744 | 2158 | You could achieve the effect of the ignore count with a condition such |
1041a570 RP |
2159 | as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience variable that |
2160 | is decremented each time. @xref{Convenience Vars, ,Convenience | |
2161 | Variables}. | |
70b88761 RP |
2162 | |
2163 | @node Break Commands, Breakpoint Menus, Conditions, Breakpoints | |
2164 | @subsection Breakpoint Command Lists | |
2165 | ||
2166 | @cindex breakpoint commands | |
2167 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 2168 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
2169 | might want to print the values of certain expressions, or enable other |
2170 | breakpoints. | |
2171 | ||
2172 | @table @code | |
2173 | @item commands @r{[}@var{bnum}@r{]} | |
2174 | @itemx @dots{} @var{command-list} @dots{} | |
2175 | @itemx end | |
2176 | @kindex commands | |
2177 | @kindex end | |
2178 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2179 | themselves appear on the following lines. Type a line containing just | |
2180 | @code{end} to terminate the commands. | |
2181 | ||
203eea5d RP |
2182 | To remove all commands from a breakpoint, type @code{commands} and |
2183 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
2184 | |
2185 | With no @var{bnum} argument, @code{commands} refers to the last | |
2186 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2187 | encountered). | |
2188 | @end table | |
2189 | ||
2190 | Pressing @key{RET} as a means of repeating the last _GDBN__ command is | |
2191 | disabled within a @var{command-list}. | |
2192 | ||
29a2b744 | 2193 | You can use breakpoint commands to start your program up again. Simply |
70b88761 RP |
2194 | use the @code{continue} command, or @code{step}, or any other command |
2195 | that resumes execution. Subsequent commands in the command list are | |
2196 | ignored. | |
2197 | ||
2198 | @kindex silent | |
2199 | If the first command specified is @code{silent}, the usual message about | |
2200 | stopping at a breakpoint is not printed. This may be desirable for | |
2201 | breakpoints that are to print a specific message and then continue. | |
2202 | If the remaining commands too print nothing, you will see no sign that | |
e251e767 | 2203 | the breakpoint was reached at all. @code{silent} is meaningful only |
70b88761 RP |
2204 | at the beginning of a breakpoint command list. |
2205 | ||
29a2b744 RP |
2206 | The commands @code{echo} and @code{output} that allow you to print |
2207 | precisely controlled output are often useful in silent breakpoints. | |
2208 | @xref{Output, ,Commands for Controlled Output}. | |
70b88761 RP |
2209 | |
2210 | For example, here is how you could use breakpoint commands to print the | |
2211 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2212 | ||
2213 | _0__@example | |
2214 | break foo if x>0 | |
2215 | commands | |
2216 | silent | |
2217 | echo x is\040 | |
2218 | output x | |
2219 | echo \n | |
2220 | cont | |
2221 | end | |
2222 | _1__@end example | |
2223 | ||
2224 | One application for breakpoint commands is to compensate for one bug so | |
2225 | you can test for another. Put a breakpoint just after the erroneous line | |
2226 | of code, give it a condition to detect the case in which something | |
2227 | erroneous has been done, and give it commands to assign correct values | |
2228 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 2229 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
2230 | command so that no output is produced. Here is an example: |
2231 | ||
2232 | @example | |
2233 | break 403 | |
2234 | commands | |
2235 | silent | |
2236 | set x = y + 4 | |
2237 | cont | |
2238 | end | |
2239 | @end example | |
2240 | ||
2241 | @cindex lost output | |
2242 | One deficiency in the operation of automatically continuing breakpoints | |
2243 | under Unix appears when your program uses raw mode for the terminal. | |
2244 | _GDBN__ switches back to its own terminal modes (not raw) before executing | |
2245 | commands, and then must switch back to raw mode when your program is | |
e251e767 | 2246 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
2247 | @c FIXME: revisit below when GNU sys avail. |
2248 | @c In the GNU system, this will be fixed by changing the behavior of | |
2249 | @c terminal modes. | |
2250 | ||
2251 | Under Unix, you can get around this problem by writing actions into | |
2252 | the breakpoint condition rather than in commands. For example | |
2253 | ||
2254 | @example | |
2255 | condition 5 (x = y + 4), 0 | |
2256 | @end example | |
2257 | ||
2258 | @noindent | |
1041a570 RP |
2259 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
2260 | change @code{x} as needed, then always have the value zero so your | |
2261 | program will not stop. No input is lost here, because _GDBN__ evaluates | |
2262 | break conditions without changing the terminal modes. When you want | |
2263 | to have nontrivial conditions for performing the side effects, the | |
2264 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 RP |
2265 | |
2266 | @node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints | |
2267 | @subsection Breakpoint Menus | |
b80282d5 | 2268 | @cindex overloading |
e251e767 | 2269 | @cindex symbol overloading |
70b88761 RP |
2270 | |
2271 | Some programming languages (notably C++) permit a single function name | |
2272 | to be defined several times, for application in different contexts. | |
2273 | This is called @dfn{overloading}. When a function name is overloaded, | |
2274 | @samp{break @var{function}} is not enough to tell _GDBN__ where you | |
2275 | want a breakpoint. _GDBN__ offers you a menu of numbered choices for | |
2276 | different possible breakpoints, and waits for your selection with the | |
2277 | prompt @samp{>}. The first two options are always @samp{[0] cancel} | |
2278 | and @samp{[1] all}. Typing @kbd{1} sets a breakpoint at each | |
2279 | definition of @var{function}, and typing @kbd{0} aborts the | |
2280 | @code{break} command without setting any new breakpoints. | |
2281 | ||
2282 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 2283 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
2284 | We choose three particular definitions of that function name: |
2285 | ||
2286 | @example | |
2287 | (_GDBP__) b String::after | |
2288 | [0] cancel | |
2289 | [1] all | |
2290 | [2] file:String.cc; line number:867 | |
2291 | [3] file:String.cc; line number:860 | |
2292 | [4] file:String.cc; line number:875 | |
2293 | [5] file:String.cc; line number:853 | |
2294 | [6] file:String.cc; line number:846 | |
2295 | [7] file:String.cc; line number:735 | |
2296 | > 2 4 6 | |
2297 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2298 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2299 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2300 | Multiple breakpoints were set. | |
2301 | Use the "delete" command to delete unwanted breakpoints. | |
e251e767 | 2302 | (_GDBP__) |
70b88761 RP |
2303 | @end example |
2304 | ||
70b88761 RP |
2305 | @node Error in Breakpoints, , Breakpoint Menus, Breakpoints |
2306 | @subsection ``Cannot Insert Breakpoints'' | |
2307 | ||
e251e767 | 2308 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 2309 | @c Q in pending mail to Gilmore. [email protected], 26mar91 |
e251e767 | 2310 | @c some light may be shed by looking at instances of |
c338a2fd RP |
2311 | @c ONE_PROCESS_WRITETEXT. But error seems possible otherwise |
2312 | @c too. pesch, 20sep91 | |
70b88761 RP |
2313 | Under some operating systems, breakpoints cannot be used in a program if |
2314 | any other process is running that program. In this situation, | |
2315 | attempting to run or continue a program with a breakpoint causes _GDBN__ | |
2316 | to stop the other process. | |
2317 | ||
2318 | When this happens, you have three ways to proceed: | |
2319 | ||
2320 | @enumerate | |
2321 | @item | |
2322 | Remove or disable the breakpoints, then continue. | |
2323 | ||
2324 | @item | |
29a2b744 | 2325 | Suspend _GDBN__, and copy the file containing your program to a new name. |
70b88761 | 2326 | Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__ |
29a2b744 | 2327 | should run your program under that name. Then start your program again. |
70b88761 RP |
2328 | |
2329 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2330 | @c explains the first FIXME: in this section... | |
2331 | ||
2332 | @item | |
29a2b744 | 2333 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
2334 | linker option @samp{-N}. The operating system limitation may not apply |
2335 | to nonsharable executables. | |
2336 | @end enumerate | |
2337 | ||
3d3ab540 RP |
2338 | @node Continuing and Stepping, Signals, Breakpoints, Stopping |
2339 | @section Continuing and Stepping | |
70b88761 RP |
2340 | |
2341 | @cindex stepping | |
7463aadd RP |
2342 | @cindex continuing |
2343 | @cindex resuming execution | |
3d3ab540 | 2344 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
2345 | completes normally. In contrast, @dfn{stepping} means executing just |
2346 | one more ``step'' of your program, where ``step'' may mean either one | |
2347 | line of source code, or one machine instruction (depending on what | |
2348 | particular command you use). Either when continuing | |
29a2b744 | 2349 | or when stepping, your program may stop even sooner, due to a breakpoint |
cedaf8bc | 2350 | or to a signal. (If due to a signal, you may want to use @code{handle}, |
1041a570 | 2351 | or use @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.) |
3d3ab540 RP |
2352 | |
2353 | @table @code | |
2354 | @item continue @r{[}@var{ignore-count}@r{]} | |
2355 | @kindex continue | |
29a2b744 | 2356 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
2357 | any breakpoints set at that address are bypassed. The optional argument |
2358 | @var{ignore-count} allows you to specify a further number of times to | |
2359 | ignore a breakpoint at this location; its effect is like that of | |
29a2b744 | 2360 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). |
3d3ab540 RP |
2361 | |
2362 | To resume execution at a different place, you can use @code{return} | |
29a2b744 RP |
2363 | (@pxref{Returning, ,Returning from a Function}) to go back to the |
2364 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
1041a570 | 2365 | Different Address}) to go to an arbitrary location in your program. |
3d3ab540 | 2366 | @end table |
7463aadd RP |
2367 | |
2368 | A typical technique for using stepping is to set a breakpoint | |
29a2b744 RP |
2369 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the |
2370 | beginning of the function or the section of your program where a | |
2371 | problem is believed to lie, run your program until it stops at that | |
2372 | breakpoint, and then step through the suspect area, examining the | |
2373 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
2374 | |
2375 | @table @code | |
2376 | @item step | |
2377 | @kindex step | |
2378 | @kindex s | |
29a2b744 | 2379 | Continue running your program until control reaches a different source |
7463aadd | 2380 | line, then stop it and return control to _GDBN__. This command is |
70b88761 RP |
2381 | abbreviated @code{s}. |
2382 | ||
3d3ab540 RP |
2383 | @quotation |
2384 | @emph{Warning:} If you use the @code{step} command while control is | |
2385 | within a function that was compiled without debugging information, | |
2386 | execution will proceed until control reaches another function. | |
2387 | @end quotation | |
70b88761 RP |
2388 | |
2389 | @item step @var{count} | |
2390 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2391 | breakpoint is reached or a signal not related to stepping occurs before | |
2392 | @var{count} steps, stepping stops right away. | |
2393 | ||
7463aadd | 2394 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2395 | @kindex next |
2396 | @kindex n | |
7463aadd RP |
2397 | Continue to the next source line in the current (innermost) stack frame. |
2398 | Similar to @code{step}, but any function calls appearing within the line | |
2399 | of code are executed without stopping. Execution stops when control | |
2400 | reaches a different line of code at the stack level which was executing | |
2401 | when the @code{next} command was given. This command is abbreviated | |
2402 | @code{n}. | |
70b88761 | 2403 | |
7463aadd | 2404 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2405 | |
2406 | @code{next} within a function that lacks debugging information acts like | |
2407 | @code{step}, but any function calls appearing within the code of the | |
2408 | function are executed without stopping. | |
2409 | ||
2410 | @item finish | |
2411 | @kindex finish | |
7463aadd RP |
2412 | Continue running until just after function in the selected stack frame |
2413 | returns. Print the returned value (if any). | |
70b88761 | 2414 | |
29a2b744 | 2415 | Contrast this with the @code{return} command (@pxref{Returning, |
1041a570 | 2416 | ,Returning from a Function}). |
70b88761 RP |
2417 | |
2418 | @item until | |
2419 | @kindex until | |
2420 | @item u | |
2421 | @kindex u | |
2422 | Continue running until a source line past the current line, in the | |
2423 | current stack frame, is reached. This command is used to avoid single | |
2424 | stepping through a loop more than once. It is like the @code{next} | |
2425 | command, except that when @code{until} encounters a jump, it | |
2426 | automatically continues execution until the program counter is greater | |
2427 | than the address of the jump. | |
2428 | ||
2429 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 2430 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
2431 | until the loop is exited. In contrast, a @code{next} command at the end |
2432 | of a loop will simply step back to the beginning of the loop, which | |
2433 | would force you to step through the next iteration. | |
2434 | ||
29a2b744 | 2435 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
2436 | stack frame. |
2437 | ||
2438 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2439 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2440 | example, in the following excerpt from a debugging session, the @code{f} |
2441 | (@code{frame}) command shows that execution is stopped at line | |
2442 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2443 | ||
2444 | @example | |
2445 | (_GDBP__) f | |
2446 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
b80282d5 | 2447 | 206 expand_input(); |
70b88761 | 2448 | (_GDBP__) until |
b80282d5 | 2449 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
2450 | @end example |
2451 | ||
7463aadd RP |
2452 | This happened because, for execution efficiency, the compiler had |
2453 | generated code for the loop closure test at the end, rather than the | |
2454 | start, of the loop---even though the test in a C @code{for}-loop is | |
2455 | written before the body of the loop. The @code{until} command appeared | |
2456 | to step back to the beginning of the loop when it advanced to this | |
2457 | expression; however, it has not really gone to an earlier | |
2458 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2459 | |
2460 | @code{until} with no argument works by means of single | |
2461 | instruction stepping, and hence is slower than @code{until} with an | |
2462 | argument. | |
2463 | ||
2464 | @item until @var{location} | |
2465 | @item u @var{location} | |
29a2b744 RP |
2466 | Continue running your program until either the specified location is |
2467 | reached, or the current stack frame returns. @var{location} is any of | |
2468 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
2469 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
1041a570 | 2470 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
2471 | |
2472 | @item stepi | |
2473 | @itemx si | |
2474 | @kindex stepi | |
2475 | @kindex si | |
2476 | Execute one machine instruction, then stop and return to the debugger. | |
2477 | ||
2478 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2479 | instructions. This will cause the next instruction to be executed to | |
29a2b744 RP |
2480 | be displayed automatically at each stop. @xref{Auto Display, |
2481 | ,Automatic Display}. | |
70b88761 RP |
2482 | |
2483 | An argument is a repeat count, as in @code{step}. | |
2484 | ||
2485 | @item nexti | |
2486 | @itemx ni | |
2487 | @kindex nexti | |
2488 | @kindex ni | |
2489 | Execute one machine instruction, but if it is a function call, | |
2490 | proceed until the function returns. | |
2491 | ||
2492 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
2493 | @end table |
2494 | ||
3d3ab540 | 2495 | @node Signals, , Continuing and Stepping, Stopping |
70b88761 RP |
2496 | @section Signals |
2497 | @cindex signals | |
2498 | ||
2499 | A signal is an asynchronous event that can happen in a program. The | |
2500 | operating system defines the possible kinds of signals, and gives each | |
2501 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2502 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2503 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2504 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 2505 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
2506 | requested an alarm). |
2507 | ||
2508 | @cindex fatal signals | |
2509 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
2510 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
2511 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 2512 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 2513 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
2514 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
2515 | ||
29a2b744 RP |
2516 | _GDBN__ has the ability to detect any occurrence of a signal in your |
2517 | program. You can tell _GDBN__ in advance what to do for each kind of | |
2518 | signal. | |
70b88761 RP |
2519 | |
2520 | @cindex handling signals | |
2521 | Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM} | |
29a2b744 RP |
2522 | (so as not to interfere with their role in the functioning of your program) |
2523 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
2524 | You can change these settings with the @code{handle} command. |
2525 | ||
2526 | @table @code | |
2527 | @item info signals | |
2528 | @kindex info signals | |
2529 | Print a table of all the kinds of signals and how _GDBN__ has been told to | |
2530 | handle each one. You can use this to see the signal numbers of all | |
2531 | the defined types of signals. | |
2532 | ||
2533 | @item handle @var{signal} @var{keywords}@dots{} | |
2534 | @kindex handle | |
2535 | Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the | |
2536 | number of a signal or its name (with or without the @samp{SIG} at the | |
2537 | beginning). The @var{keywords} say what change to make. | |
2538 | @end table | |
2539 | ||
2540 | @c @group | |
2541 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2542 | Their full names are: | |
2543 | ||
2544 | @table @code | |
2545 | @item nostop | |
29a2b744 | 2546 | _GDBN__ should not stop your program when this signal happens. It may |
70b88761 RP |
2547 | still print a message telling you that the signal has come in. |
2548 | ||
2549 | @item stop | |
29a2b744 | 2550 | _GDBN__ should stop your program when this signal happens. This implies |
70b88761 RP |
2551 | the @code{print} keyword as well. |
2552 | ||
2553 | @item print | |
2554 | _GDBN__ should print a message when this signal happens. | |
2555 | ||
2556 | @item noprint | |
2557 | _GDBN__ should not mention the occurrence of the signal at all. This | |
2558 | implies the @code{nostop} keyword as well. | |
2559 | ||
2560 | @item pass | |
29a2b744 | 2561 | _GDBN__ should allow your program to see this signal; your program will be |
70b88761 RP |
2562 | able to handle the signal, or may be terminated if the signal is fatal |
2563 | and not handled. | |
2564 | ||
2565 | @item nopass | |
29a2b744 | 2566 | _GDBN__ should not allow your program to see this signal. |
70b88761 RP |
2567 | @end table |
2568 | @c @end group | |
2569 | ||
29a2b744 | 2570 | When a signal has been set to stop your program, your program cannot see the |
70b88761 RP |
2571 | signal until you continue. It will see the signal then, if @code{pass} is |
2572 | in effect for the signal in question @i{at that time}. In other words, | |
2573 | after _GDBN__ reports a signal, you can use the @code{handle} command with | |
2574 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
29a2b744 | 2575 | your program when you later continue it. |
70b88761 | 2576 | |
29a2b744 | 2577 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 2578 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 2579 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
2580 | due to some sort of memory reference error, you might store correct |
2581 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
2582 | execution; but your program would probably terminate immediately as |
2583 | a result of the fatal signal once it saw the signal. To prevent this, | |
2584 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
2585 | Program a Signal}. | |
70b88761 RP |
2586 | |
2587 | @node Stack, Source, Stopping, Top | |
2588 | @chapter Examining the Stack | |
2589 | ||
2590 | When your program has stopped, the first thing you need to know is where it | |
2591 | stopped and how it got there. | |
2592 | ||
2593 | @cindex call stack | |
2594 | Each time your program performs a function call, the information about | |
29a2b744 | 2595 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
2596 | called a @dfn{stack frame}. The frame also contains the arguments of the |
2597 | call and the local variables of the function that was called. All the | |
2598 | stack frames are allocated in a region of memory called the @dfn{call | |
2599 | stack}. | |
2600 | ||
2601 | When your program stops, the _GDBN__ commands for examining the stack allow you | |
2602 | to see all of this information. | |
2603 | ||
2604 | @cindex selected frame | |
2605 | One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands | |
2606 | refer implicitly to the selected frame. In particular, whenever you ask | |
29a2b744 | 2607 | _GDBN__ for the value of a variable in your program, the value is found in the |
70b88761 RP |
2608 | selected frame. There are special _GDBN__ commands to select whichever frame |
2609 | you are interested in. | |
2610 | ||
29a2b744 | 2611 | When your program stops, _GDBN__ automatically selects the currently executing |
70b88761 | 2612 | frame and describes it briefly as the @code{frame} command does |
29a2b744 | 2613 | (@pxref{Frame Info, ,Information About a Frame}). |
70b88761 RP |
2614 | |
2615 | @menu | |
b80282d5 RP |
2616 | * Frames:: Stack Frames |
2617 | * Backtrace:: Backtraces | |
2618 | * Selection:: Selecting a Frame | |
2619 | * Frame Info:: Information on a Frame | |
70b88761 RP |
2620 | @end menu |
2621 | ||
2622 | @node Frames, Backtrace, Stack, Stack | |
2623 | @section Stack Frames | |
2624 | ||
2625 | @cindex frame | |
2626 | @cindex stack frame | |
2627 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2628 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2629 | with one call to one function. The frame contains the arguments given | |
2630 | to the function, the function's local variables, and the address at | |
2631 | which the function is executing. | |
2632 | ||
2633 | @cindex initial frame | |
2634 | @cindex outermost frame | |
2635 | @cindex innermost frame | |
2636 | When your program is started, the stack has only one frame, that of the | |
2637 | function @code{main}. This is called the @dfn{initial} frame or the | |
2638 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2639 | made. Each time a function returns, the frame for that function invocation | |
2640 | is eliminated. If a function is recursive, there can be many frames for | |
2641 | the same function. The frame for the function in which execution is | |
2642 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2643 | recently created of all the stack frames that still exist. | |
2644 | ||
2645 | @cindex frame pointer | |
2646 | Inside your program, stack frames are identified by their addresses. A | |
2647 | stack frame consists of many bytes, each of which has its own address; each | |
2648 | kind of computer has a convention for choosing one of those bytes whose | |
2649 | address serves as the address of the frame. Usually this address is kept | |
2650 | in a register called the @dfn{frame pointer register} while execution is | |
2651 | going on in that frame. | |
2652 | ||
2653 | @cindex frame number | |
2654 | _GDBN__ assigns numbers to all existing stack frames, starting with | |
2655 | zero for the innermost frame, one for the frame that called it, | |
2656 | and so on upward. These numbers do not really exist in your program; | |
2657 | they are assigned by _GDBN__ to give you a way of designating stack | |
2658 | frames in _GDBN__ commands. | |
2659 | ||
2660 | @cindex frameless execution | |
2661 | Some compilers allow functions to be compiled so that they operate | |
2662 | without stack frames. (For example, the @code{_GCC__} option | |
2663 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2664 | This is occasionally done with heavily used library functions to save | |
2665 | the frame setup time. _GDBN__ has limited facilities for dealing with | |
2666 | these function invocations. If the innermost function invocation has no | |
2667 | stack frame, _GDBN__ will nevertheless regard it as though it had a | |
2668 | separate frame, which is numbered zero as usual, allowing correct | |
2669 | tracing of the function call chain. However, _GDBN__ has no provision | |
2670 | for frameless functions elsewhere in the stack. | |
2671 | ||
2672 | @node Backtrace, Selection, Frames, Stack | |
2673 | @section Backtraces | |
2674 | ||
29a2b744 | 2675 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
2676 | line per frame, for many frames, starting with the currently executing |
2677 | frame (frame zero), followed by its caller (frame one), and on up the | |
2678 | stack. | |
2679 | ||
2680 | @table @code | |
2681 | @item backtrace | |
2682 | @itemx bt | |
2683 | @kindex backtrace | |
2684 | @kindex bt | |
2685 | Print a backtrace of the entire stack: one line per frame for all | |
2686 | frames in the stack. | |
2687 | ||
2688 | You can stop the backtrace at any time by typing the system interrupt | |
2689 | character, normally @kbd{C-c}. | |
2690 | ||
2691 | @item backtrace @var{n} | |
2692 | @itemx bt @var{n} | |
2693 | Similar, but print only the innermost @var{n} frames. | |
2694 | ||
2695 | @item backtrace -@var{n} | |
2696 | @itemx bt -@var{n} | |
2697 | Similar, but print only the outermost @var{n} frames. | |
2698 | @end table | |
2699 | ||
2700 | @kindex where | |
2701 | @kindex info stack | |
2702 | @kindex info s | |
2703 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
2704 | are additional aliases for @code{backtrace}. | |
2705 | ||
2706 | Each line in the backtrace shows the frame number and the function name. | |
2707 | The program counter value is also shown---unless you use @code{set | |
2708 | print address off}. The backtrace also shows the source file name and | |
2709 | line number, as well as the arguments to the function. The program | |
2710 | counter value is omitted if it is at the beginning of the code for that | |
2711 | line number. | |
2712 | ||
2713 | Here is an example of a backtrace. It was made with the command | |
2714 | @samp{bt 3}, so it shows the innermost three frames. | |
2715 | ||
2716 | @smallexample | |
2717 | @group | |
203eea5d RP |
2718 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
2719 | at builtin.c:993 | |
70b88761 RP |
2720 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
2721 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
2722 | at macro.c:71 | |
2723 | (More stack frames follow...) | |
2724 | @end group | |
2725 | @end smallexample | |
2726 | ||
2727 | @noindent | |
29a2b744 RP |
2728 | The display for frame zero does not begin with a program counter |
2729 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
2730 | code for line @code{993} of @code{builtin.c}. |
2731 | ||
2732 | @node Selection, Frame Info, Backtrace, Stack | |
2733 | @section Selecting a Frame | |
2734 | ||
29a2b744 | 2735 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
2736 | whichever stack frame is selected at the moment. Here are the commands for |
2737 | selecting a stack frame; all of them finish by printing a brief description | |
2738 | of the stack frame just selected. | |
2739 | ||
2740 | @table @code | |
2741 | @item frame @var{n} | |
2742 | @itemx f @var{n} | |
2743 | @kindex frame | |
2744 | @kindex f | |
2745 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2746 | (currently executing) frame, frame one is the frame that called the | |
2747 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2748 | frame. | |
2749 | ||
2750 | @item frame @var{addr} | |
2751 | @itemx f @var{addr} | |
2752 | Select the frame at address @var{addr}. This is useful mainly if the | |
2753 | chaining of stack frames has been damaged by a bug, making it | |
2754 | impossible for _GDBN__ to assign numbers properly to all frames. In | |
29a2b744 | 2755 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
2756 | switches between them. |
2757 | ||
c728f1f0 | 2758 | _if__(_SPARC__) |
70b88761 | 2759 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 2760 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
2761 | @c note to future updaters: this is conditioned on a flag |
2762 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
2763 | @c by SPARC, hence the specific attribution. Generalize or list all | |
2764 | @c possibilities if more supported machines start doing this. | |
c728f1f0 | 2765 | _fi__(_SPARC__) |
70b88761 RP |
2766 | |
2767 | @item up @var{n} | |
2768 | @kindex up | |
2769 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
2770 | advances toward the outermost frame, to higher frame numbers, to frames | |
2771 | that have existed longer. @var{n} defaults to one. | |
2772 | ||
2773 | @item down @var{n} | |
2774 | @kindex down | |
2775 | @kindex do | |
2776 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
2777 | advances toward the innermost frame, to lower frame numbers, to frames | |
2778 | that were created more recently. @var{n} defaults to one. You may | |
2779 | abbreviate @code{down} as @code{do}. | |
2780 | @end table | |
2781 | ||
2782 | All of these commands end by printing two lines of output describing the | |
2783 | frame. The first line shows the frame number, the function name, the | |
2784 | arguments, and the source file and line number of execution in that | |
2785 | frame. The second line shows the text of that source line. For | |
2786 | example: | |
2787 | ||
2788 | @smallexample | |
29a2b744 | 2789 | @group |
70b88761 | 2790 | (_GDBP__) up |
203eea5d RP |
2791 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
2792 | at env.c:10 | |
70b88761 | 2793 | 10 read_input_file (argv[i]); |
29a2b744 | 2794 | @end group |
70b88761 RP |
2795 | @end smallexample |
2796 | ||
29a2b744 RP |
2797 | After such a printout, the @code{list} command with no arguments will |
2798 | print ten lines centered on the point of execution in the frame. | |
2799 | @xref{List, ,Printing Source Lines}. | |
70b88761 RP |
2800 | |
2801 | @table @code | |
2802 | @item up-silently @var{n} | |
2803 | @itemx down-silently @var{n} | |
2804 | @kindex down-silently | |
2805 | @kindex up-silently | |
2806 | These two commands are variants of @code{up} and @code{down}, | |
2807 | respectively; they differ in that they do their work silently, without | |
2808 | causing display of the new frame. They are intended primarily for use | |
2809 | in _GDBN__ command scripts, where the output might be unnecessary and | |
e251e767 | 2810 | distracting. |
70b88761 RP |
2811 | @end table |
2812 | ||
2813 | @node Frame Info, , Selection, Stack | |
2814 | @section Information About a Frame | |
2815 | ||
2816 | There are several other commands to print information about the selected | |
2817 | stack frame. | |
2818 | ||
2819 | @table @code | |
2820 | @item frame | |
2821 | @itemx f | |
29a2b744 RP |
2822 | When used without any argument, this command does not change which |
2823 | frame is selected, but prints a brief description of the currently | |
70b88761 | 2824 | selected stack frame. It can be abbreviated @code{f}. With an |
29a2b744 RP |
2825 | argument, this command is used to select a stack frame |
2826 | (@pxref{Selection, ,Selecting a Frame}). | |
70b88761 RP |
2827 | |
2828 | @item info frame | |
70b88761 | 2829 | @itemx info f |
29a2b744 | 2830 | @kindex info frame |
70b88761 RP |
2831 | @kindex info f |
2832 | This command prints a verbose description of the selected stack frame, | |
2833 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
2834 | (called by this frame) and the next frame up (caller of this frame), the |
2835 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
2836 | the address of the frame's arguments, the program counter saved in it |
2837 | (the address of execution in the caller frame), and which registers | |
2838 | were saved in the frame. The verbose description is useful when | |
2839 | something has gone wrong that has made the stack format fail to fit | |
2840 | the usual conventions. | |
2841 | ||
2842 | @item info frame @var{addr} | |
2843 | @itemx info f @var{addr} | |
2844 | Print a verbose description of the frame at address @var{addr}, | |
2845 | without selecting that frame. The selected frame remains unchanged by | |
2846 | this command. | |
2847 | ||
2848 | @item info args | |
2849 | @kindex info args | |
2850 | Print the arguments of the selected frame, each on a separate line. | |
2851 | ||
2852 | @item info locals | |
2853 | @kindex info locals | |
2854 | Print the local variables of the selected frame, each on a separate | |
2855 | line. These are all variables declared static or automatic within all | |
2856 | program blocks that execution in this frame is currently inside of. | |
2857 | ||
2858 | @item info catch | |
2859 | @kindex info catch | |
2860 | @cindex catch exceptions | |
2861 | @cindex exception handlers | |
2862 | Print a list of all the exception handlers that are active in the | |
2863 | current stack frame at the current point of execution. To see other | |
2864 | exception handlers, visit the associated frame (using the @code{up}, | |
2865 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
1041a570 | 2866 | @xref{Exception Handling, ,Breakpoints and Exceptions}. |
70b88761 RP |
2867 | @end table |
2868 | ||
2869 | @node Source, Data, Stack, Top | |
2870 | @chapter Examining Source Files | |
2871 | ||
2872 | _GDBN__ can print parts of your program's source, since the debugging | |
1041a570 RP |
2873 | information recorded in your program tells _GDBN__ what source files were |
2874 | used to build it. When your program stops, _GDBN__ spontaneously prints | |
2875 | the line where it stopped. Likewise, when you select a stack frame | |
2876 | (@pxref{Selection, ,Selecting a Frame}), _GDBN__ prints the line where | |
2877 | execution in that frame has stopped. You can print other portions of | |
2878 | source files by explicit command. | |
70b88761 | 2879 | |
1041a570 RP |
2880 | If you use _GDBN__ through its GNU Emacs interface, you may prefer to use |
2881 | Emacs facilities to view source; @pxref{Emacs, ,Using _GDBN__ under GNU | |
2882 | Emacs}. | |
70b88761 RP |
2883 | |
2884 | @menu | |
b80282d5 RP |
2885 | * List:: Printing Source Lines |
2886 | * Search:: Searching Source Files | |
2887 | * Source Path:: Specifying Source Directories | |
2888 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
2889 | @end menu |
2890 | ||
2891 | @node List, Search, Source, Source | |
2892 | @section Printing Source Lines | |
2893 | ||
2894 | @kindex list | |
2895 | @kindex l | |
2896 | To print lines from a source file, use the @code{list} command | |
2897 | (abbreviated @code{l}). There are several ways to specify what part | |
2898 | of the file you want to print. | |
2899 | ||
2900 | Here are the forms of the @code{list} command most commonly used: | |
2901 | ||
2902 | @table @code | |
2903 | @item list @var{linenum} | |
c338a2fd | 2904 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
2905 | current source file. |
2906 | ||
2907 | @item list @var{function} | |
c338a2fd | 2908 | Print lines centered around the beginning of function |
70b88761 RP |
2909 | @var{function}. |
2910 | ||
2911 | @item list | |
c338a2fd RP |
2912 | Print more lines. If the last lines printed were printed with a |
2913 | @code{list} command, this prints lines following the last lines | |
70b88761 | 2914 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 2915 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 2916 | Stack}), this prints lines centered around that line. |
70b88761 RP |
2917 | |
2918 | @item list - | |
c338a2fd RP |
2919 | Print lines just before the lines last printed. |
2920 | @end table | |
2921 | ||
2922 | By default, _GDBN__ prints ten source lines with any of these forms of | |
2923 | the @code{list} command. You can change this using @code{set listsize}: | |
2924 | ||
2925 | @table @code | |
2926 | @item set listsize @var{count} | |
2927 | @kindex set listsize | |
2928 | Make the @code{list} command display @var{count} source lines (unless | |
2929 | the @code{list} argument explicitly specifies some other number). | |
2930 | ||
2931 | @item show listsize | |
2932 | @kindex show listsize | |
2933 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 2934 | default. |
70b88761 RP |
2935 | @end table |
2936 | ||
2937 | Repeating a @code{list} command with @key{RET} discards the argument, | |
2938 | so it is equivalent to typing just @code{list}. This is more useful | |
2939 | than listing the same lines again. An exception is made for an | |
2940 | argument of @samp{-}; that argument is preserved in repetition so that | |
2941 | each repetition moves up in the source file. | |
2942 | ||
2943 | @cindex linespec | |
2944 | In general, the @code{list} command expects you to supply zero, one or two | |
2945 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
2946 | of writing them but the effect is always to specify some source line. | |
2947 | Here is a complete description of the possible arguments for @code{list}: | |
2948 | ||
2949 | @table @code | |
2950 | @item list @var{linespec} | |
c338a2fd | 2951 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
2952 | |
2953 | @item list @var{first},@var{last} | |
2954 | Print lines from @var{first} to @var{last}. Both arguments are | |
2955 | linespecs. | |
2956 | ||
2957 | @item list ,@var{last} | |
c338a2fd | 2958 | Print lines ending with @var{last}. |
70b88761 RP |
2959 | |
2960 | @item list @var{first}, | |
c338a2fd | 2961 | Print lines starting with @var{first}. |
70b88761 RP |
2962 | |
2963 | @item list + | |
c338a2fd | 2964 | Print lines just after the lines last printed. |
70b88761 RP |
2965 | |
2966 | @item list - | |
c338a2fd | 2967 | Print lines just before the lines last printed. |
70b88761 RP |
2968 | |
2969 | @item list | |
2970 | As described in the preceding table. | |
2971 | @end table | |
2972 | ||
2973 | Here are the ways of specifying a single source line---all the | |
2974 | kinds of linespec. | |
2975 | ||
2976 | @table @code | |
2977 | @item @var{number} | |
2978 | Specifies line @var{number} of the current source file. | |
2979 | When a @code{list} command has two linespecs, this refers to | |
2980 | the same source file as the first linespec. | |
2981 | ||
2982 | @item +@var{offset} | |
2983 | Specifies the line @var{offset} lines after the last line printed. | |
2984 | When used as the second linespec in a @code{list} command that has | |
2985 | two, this specifies the line @var{offset} lines down from the | |
2986 | first linespec. | |
2987 | ||
2988 | @item -@var{offset} | |
2989 | Specifies the line @var{offset} lines before the last line printed. | |
2990 | ||
2991 | @item @var{filename}:@var{number} | |
2992 | Specifies line @var{number} in the source file @var{filename}. | |
2993 | ||
2994 | @item @var{function} | |
2995 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
2996 | Specifies the line of the open-brace that begins the body of the | |
2997 | function @var{function}. | |
2998 | ||
2999 | @item @var{filename}:@var{function} | |
3000 | Specifies the line of the open-brace that begins the body of the | |
3001 | function @var{function} in the file @var{filename}. You only need the | |
3002 | file name with a function name to avoid ambiguity when there are | |
3003 | identically named functions in different source files. | |
3004 | ||
3005 | @item *@var{address} | |
3006 | Specifies the line containing the program address @var{address}. | |
3007 | @var{address} may be any expression. | |
3008 | @end table | |
3009 | ||
3010 | @node Search, Source Path, List, Source | |
3011 | @section Searching Source Files | |
3012 | @cindex searching | |
3013 | @kindex reverse-search | |
3014 | ||
3015 | There are two commands for searching through the current source file for a | |
3016 | regular expression. | |
3017 | ||
3018 | @table @code | |
3019 | @item forward-search @var{regexp} | |
3020 | @itemx search @var{regexp} | |
3021 | @kindex search | |
3022 | @kindex forward-search | |
1041a570 RP |
3023 | The command @samp{forward-search @var{regexp}} checks each line, |
3024 | starting with the one following the last line listed, for a match for | |
3025 | @var{regexp}. It lists the line that is found. You can use | |
3026 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3027 | @code{fo}. | |
70b88761 RP |
3028 | |
3029 | @item reverse-search @var{regexp} | |
3030 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3031 | with the one before the last line listed and going backward, for a match | |
3032 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3033 | this command as @code{rev}. | |
3034 | @end table | |
3035 | ||
3036 | @node Source Path, Machine Code, Search, Source | |
3037 | @section Specifying Source Directories | |
3038 | ||
3039 | @cindex source path | |
3040 | @cindex directories for source files | |
3041 | Executable programs sometimes do not record the directories of the source | |
3042 | files from which they were compiled, just the names. Even when they do, | |
3043 | the directories could be moved between the compilation and your debugging | |
3044 | session. _GDBN__ has a list of directories to search for source files; | |
3045 | this is called the @dfn{source path}. Each time _GDBN__ wants a source file, | |
3046 | it tries all the directories in the list, in the order they are present | |
3047 | in the list, until it finds a file with the desired name. Note that | |
3048 | the executable search path is @emph{not} used for this purpose. Neither is | |
3049 | the current working directory, unless it happens to be in the source | |
3050 | path. | |
3051 | ||
29a2b744 | 3052 | If _GDBN__ cannot find a source file in the source path, and the object |
70b88761 RP |
3053 | program records a directory, _GDBN__ tries that directory too. If the |
3054 | source path is empty, and there is no record of the compilation | |
3055 | directory, _GDBN__ will, as a last resort, look in the current | |
3056 | directory. | |
3057 | ||
3058 | Whenever you reset or rearrange the source path, _GDBN__ will clear out | |
3059 | any information it has cached about where source files are found, where | |
3060 | each line is in the file, etc. | |
3061 | ||
3062 | @kindex directory | |
3063 | When you start _GDBN__, its source path is empty. | |
3064 | To add other directories, use the @code{directory} command. | |
3065 | ||
3066 | @table @code | |
3067 | @item directory @var{dirname} @dots{} | |
3068 | Add directory @var{dirname} to the front of the source path. Several | |
3069 | directory names may be given to this command, separated by @samp{:} or | |
3070 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 3071 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
3072 | |
3073 | You can use the string @samp{$cdir} to refer to the compilation | |
3074 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3075 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
3076 | tracks the current working directory as it changes during your _GDBN__ | |
3077 | session, while the latter is immediately expanded to the current | |
3078 | directory at the time you add an entry to the source path. | |
70b88761 RP |
3079 | |
3080 | @item directory | |
3081 | Reset the source path to empty again. This requires confirmation. | |
3082 | ||
3083 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 3084 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
3085 | |
3086 | @item show directories | |
3087 | @kindex show directories | |
3088 | Print the source path: show which directories it contains. | |
3089 | @end table | |
3090 | ||
3091 | If your source path is cluttered with directories that are no longer of | |
3092 | interest, _GDBN__ may sometimes cause confusion by finding the wrong | |
3093 | versions of source. You can correct the situation as follows: | |
3094 | ||
3095 | @enumerate | |
3096 | @item | |
3097 | Use @code{directory} with no argument to reset the source path to empty. | |
3098 | ||
3099 | @item | |
3100 | Use @code{directory} with suitable arguments to reinstall the | |
3101 | directories you want in the source path. You can add all the | |
3102 | directories in one command. | |
3103 | @end enumerate | |
3104 | ||
3105 | @node Machine Code, , Source Path, Source | |
3106 | @section Source and Machine Code | |
1041a570 | 3107 | |
70b88761 RP |
3108 | You can use the command @code{info line} to map source lines to program |
3109 | addresses (and viceversa), and the command @code{disassemble} to display | |
3110 | a range of addresses as machine instructions. | |
3111 | ||
3112 | @table @code | |
3113 | @item info line @var{linespec} | |
3114 | @kindex info line | |
3115 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
3116 | source line @var{linespec}. You can specify source lines in any of |
3117 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
3118 | Source Lines}). | |
70b88761 RP |
3119 | @end table |
3120 | ||
1041a570 RP |
3121 | For example, we can use @code{info line} to discover the location of |
3122 | the object code for the first line of function | |
3123 | @code{m4_changequote}: | |
3124 | ||
70b88761 RP |
3125 | @smallexample |
3126 | (_GDBP__) info line m4_changecom | |
3127 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
3128 | @end smallexample | |
3129 | ||
3130 | @noindent | |
3131 | We can also inquire (using @code{*@var{addr}} as the form for | |
3132 | @var{linespec}) what source line covers a particular address: | |
3133 | @smallexample | |
3134 | (_GDBP__) info line *0x63ff | |
3135 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
3136 | @end smallexample | |
3137 | ||
c338a2fd | 3138 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
3139 | After @code{info line}, the default address for the @code{x} command |
3140 | is changed to the starting address of the line, so that @samp{x/i} is | |
3141 | sufficient to begin examining the machine code (@pxref{Memory, | |
3142 | ,Examining Memory}). Also, this address is saved as the value of the | |
3143 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
3144 | Variables}). | |
70b88761 RP |
3145 | |
3146 | @table @code | |
3147 | @kindex disassemble | |
3148 | @item disassemble | |
3149 | This specialized command is provided to dump a range of memory as | |
3150 | machine instructions. The default memory range is the function | |
3151 | surrounding the program counter of the selected frame. A single | |
3152 | argument to this command is a program counter value; the function | |
3153 | surrounding this value will be dumped. Two arguments (separated by one | |
3154 | or more spaces) specify a range of addresses (first inclusive, second | |
e251e767 | 3155 | exclusive) to be dumped. |
70b88761 RP |
3156 | @end table |
3157 | ||
3158 | We can use @code{disassemble} to inspect the object code | |
3159 | range shown in the last @code{info line} example: | |
3160 | ||
3161 | @smallexample | |
3162 | (_GDBP__) disas 0x63e4 0x6404 | |
3163 | Dump of assembler code from 0x63e4 to 0x6404: | |
b80282d5 RP |
3164 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
3165 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
3166 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
3167 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
3168 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
3169 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
3170 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 3171 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 3172 | End of assembler dump. |
e251e767 | 3173 | (_GDBP__) |
70b88761 RP |
3174 | @end smallexample |
3175 | ||
c2bbbb22 | 3176 | @node Data, Languages, Source, Top |
70b88761 RP |
3177 | @chapter Examining Data |
3178 | ||
3179 | @cindex printing data | |
3180 | @cindex examining data | |
3181 | @kindex print | |
3182 | @kindex inspect | |
1041a570 | 3183 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 3184 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
3185 | @c different window or something like that. |
3186 | The usual way to examine data in your program is with the @code{print} | |
3187 | command (abbreviated @code{p}), or its synonym @code{inspect}. It | |
b80282d5 | 3188 | evaluates and prints the value of an expression of the language your |
1041a570 RP |
3189 | program is written in (@pxref{Languages, ,Using _GDBN__ with Different |
3190 | Languages}). | |
70b88761 | 3191 | |
e0dacfd1 RP |
3192 | @table @code |
3193 | @item print @var{exp} | |
3194 | @itemx print /@var{f} @var{exp} | |
3195 | @var{exp} is an expression (in the source language). By default | |
70b88761 | 3196 | the value of @var{exp} is printed in a format appropriate to its data |
e0dacfd1 RP |
3197 | type; you can choose a different format by specifying @samp{/@var{f}}, |
3198 | where @var{f} is a letter specifying the format; @pxref{Output formats}. | |
3199 | ||
3200 | @item print | |
3201 | @itemx print /@var{f} | |
3202 | If you omit @var{exp}, _GDBN__ displays the last value again (from the | |
1041a570 | 3203 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to |
e0dacfd1 RP |
3204 | conveniently inspect the same value in an alternative format. |
3205 | @end table | |
70b88761 RP |
3206 | |
3207 | A more low-level way of examining data is with the @code{x} command. | |
3208 | It examines data in memory at a specified address and prints it in a | |
29a2b744 | 3209 | specified format. @xref{Memory, ,Examining Memory}. |
70b88761 | 3210 | |
29a2b744 | 3211 | If you are interested in information about types, or about how the fields |
b80282d5 | 3212 | of a struct or class are declared, use the @code{ptype @var{exp}} |
1041a570 | 3213 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 | 3214 | |
70b88761 | 3215 | @menu |
b80282d5 RP |
3216 | * Expressions:: Expressions |
3217 | * Variables:: Program Variables | |
3218 | * Arrays:: Artificial Arrays | |
3219 | * Output formats:: Output formats | |
3220 | * Memory:: Examining Memory | |
3221 | * Auto Display:: Automatic Display | |
3222 | * Print Settings:: Print Settings | |
3223 | * Value History:: Value History | |
3224 | * Convenience Vars:: Convenience Variables | |
3225 | * Registers:: Registers | |
3226 | * Floating Point Hardware:: Floating Point Hardware | |
70b88761 RP |
3227 | @end menu |
3228 | ||
3229 | @node Expressions, Variables, Data, Data | |
3230 | @section Expressions | |
3231 | ||
3232 | @cindex expressions | |
3233 | @code{print} and many other _GDBN__ commands accept an expression and | |
3234 | compute its value. Any kind of constant, variable or operator defined | |
3235 | by the programming language you are using is legal in an expression in | |
3236 | _GDBN__. This includes conditional expressions, function calls, casts | |
3237 | and string constants. It unfortunately does not include symbols defined | |
b80282d5 | 3238 | by preprocessor @code{#define} commands. |
70b88761 | 3239 | |
c2bbbb22 | 3240 | Because C is so widespread, most of the expressions shown in examples in |
1041a570 | 3241 | this manual are in C. @xref{Languages, , Using _GDBN__ with Different |
c2bbbb22 | 3242 | Languages}, for information on how to use expressions in other |
e251e767 | 3243 | languages. |
c2bbbb22 RP |
3244 | |
3245 | In this section, we discuss operators that you can use in _GDBN__ | |
e251e767 | 3246 | expressions regardless of your programming language. |
c2bbbb22 | 3247 | |
70b88761 RP |
3248 | Casts are supported in all languages, not just in C, because it is so |
3249 | useful to cast a number into a pointer so as to examine a structure | |
3250 | at that address in memory. | |
c2bbbb22 | 3251 | @c FIXME: casts supported---Mod2 true? |
70b88761 | 3252 | |
c2bbbb22 | 3253 | _GDBN__ supports these operators in addition to those of programming |
70b88761 RP |
3254 | languages: |
3255 | ||
3256 | @table @code | |
3257 | @item @@ | |
3258 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
1041a570 | 3259 | @xref{Arrays, ,Artificial Arrays}, for more information. |
70b88761 RP |
3260 | |
3261 | @item :: | |
3262 | @samp{::} allows you to specify a variable in terms of the file or | |
1041a570 | 3263 | function where it is defined. @xref{Variables, ,Program Variables}. |
70b88761 RP |
3264 | |
3265 | @item @{@var{type}@} @var{addr} | |
3266 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3267 | memory. @var{addr} may be any expression whose value is an integer or | |
3268 | pointer (but parentheses are required around binary operators, just as in | |
3269 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 3270 | normally supposed to reside at @var{addr}. |
70b88761 RP |
3271 | @end table |
3272 | ||
3273 | @node Variables, Arrays, Expressions, Data | |
3274 | @section Program Variables | |
3275 | ||
3276 | The most common kind of expression to use is the name of a variable | |
3277 | in your program. | |
3278 | ||
3279 | Variables in expressions are understood in the selected stack frame | |
29a2b744 RP |
3280 | (@pxref{Selection, ,Selecting a Frame}); they must either be global |
3281 | (or static) or be visible according to the scope rules of the | |
3282 | programming language from the point of execution in that frame. This | |
3283 | means that in the function | |
70b88761 RP |
3284 | |
3285 | @example | |
3286 | foo (a) | |
3287 | int a; | |
3288 | @{ | |
3289 | bar (a); | |
3290 | @{ | |
3291 | int b = test (); | |
3292 | bar (b); | |
3293 | @} | |
3294 | @} | |
3295 | @end example | |
3296 | ||
3297 | @noindent | |
29a2b744 | 3298 | the variable @code{a} is usable whenever your program is executing |
70b88761 | 3299 | within the function @code{foo}, but the variable @code{b} is visible |
29a2b744 | 3300 | only while your program is executing inside the block in which @code{b} |
70b88761 RP |
3301 | is declared. |
3302 | ||
3303 | @cindex variable name conflict | |
3304 | There is an exception: you can refer to a variable or function whose | |
3305 | scope is a single source file even if the current execution point is not | |
3306 | in this file. But it is possible to have more than one such variable or | |
3307 | function with the same name (in different source files). If that happens, | |
3308 | referring to that name has unpredictable effects. If you wish, you can | |
3309 | specify a variable in a particular file, using the colon-colon notation: | |
3310 | ||
3311 | @cindex colon-colon | |
a6d0b6d3 | 3312 | @iftex |
29a2b744 | 3313 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 3314 | @kindex :: |
a6d0b6d3 | 3315 | @end iftex |
70b88761 RP |
3316 | @example |
3317 | @var{file}::@var{variable} | |
3318 | @end example | |
3319 | ||
3320 | @noindent | |
3321 | Here @var{file} is the name of the source file whose variable you want. | |
3322 | ||
c2bbbb22 | 3323 | @cindex C++ scope resolution |
70b88761 RP |
3324 | This use of @samp{::} is very rarely in conflict with the very similar |
3325 | use of the same notation in C++. _GDBN__ also supports use of the C++ | |
c2bbbb22 | 3326 | scope resolution operator in _GDBN__ expressions. |
70b88761 | 3327 | |
3d3ab540 RP |
3328 | @cindex wrong values |
3329 | @cindex variable values, wrong | |
3330 | @quotation | |
3331 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
3332 | wrong value at certain points in a function---just after entry to the | |
29a2b744 | 3333 | function, and just before exit. You may see this problem when you are |
3d3ab540 RP |
3334 | stepping by machine instructions. This is because on most machines, it |
3335 | takes more than one instruction to set up a stack frame (including local | |
29a2b744 | 3336 | variable definitions); if you are stepping by machine instructions, |
3d3ab540 RP |
3337 | variables may appear to have the wrong values until the stack frame is |
3338 | completely built. On function exit, it usually also takes more than one | |
3339 | machine instruction to destroy a stack frame; after you begin stepping | |
3340 | through that group of instructions, local variable definitions may be | |
3341 | gone. | |
3342 | @end quotation | |
3343 | ||
70b88761 RP |
3344 | @node Arrays, Output formats, Variables, Data |
3345 | @section Artificial Arrays | |
3346 | ||
3347 | @cindex artificial array | |
3348 | @kindex @@ | |
3349 | It is often useful to print out several successive objects of the | |
3350 | same type in memory; a section of an array, or an array of | |
3351 | dynamically determined size for which only a pointer exists in the | |
3352 | program. | |
3353 | ||
3354 | This can be done by constructing an @dfn{artificial array} with the | |
3355 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3356 | the first element of the desired array, as an individual object. | |
3357 | The right operand should be the desired length of the array. The result is | |
3358 | an array value whose elements are all of the type of the left argument. | |
3359 | The first element is actually the left argument; the second element | |
3360 | comes from bytes of memory immediately following those that hold the | |
3361 | first element, and so on. Here is an example. If a program says | |
3362 | ||
3363 | @example | |
3364 | int *array = (int *) malloc (len * sizeof (int)); | |
3365 | @end example | |
3366 | ||
3367 | @noindent | |
3368 | you can print the contents of @code{array} with | |
3369 | ||
3370 | @example | |
3371 | p *array@@len | |
3372 | @end example | |
3373 | ||
3374 | The left operand of @samp{@@} must reside in memory. Array values made | |
3375 | with @samp{@@} in this way behave just like other arrays in terms of | |
3376 | subscripting, and are coerced to pointers when used in expressions. | |
3377 | Artificial arrays most often appear in expressions via the value history | |
1041a570 | 3378 | (@pxref{Value History, ,Value History}), after printing one out.) |
70b88761 | 3379 | |
1041a570 | 3380 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 3381 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
3382 | actually be adjacent---for example, if you are interested in the values |
3383 | of pointers in an array. One useful work-around in this situation is | |
3384 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
3385 | Variables}) as a counter in an expression that prints the first | |
3386 | interesting value, and then repeat that expression via @key{RET}. For | |
3387 | instance, suppose you have an array @code{dtab} of pointers to | |
3388 | structures, and you are interested in the values of a field @code{fv} | |
3389 | in each structure. Here is an example of what you might type: | |
3390 | ||
3d3ab540 RP |
3391 | @example |
3392 | set $i = 0 | |
3393 | p dtab[$i++]->fv | |
3394 | @key{RET} | |
3395 | @key{RET} | |
3396 | @dots{} | |
3397 | @end example | |
3398 | ||
70b88761 RP |
3399 | @node Output formats, Memory, Arrays, Data |
3400 | @section Output formats | |
3401 | ||
3402 | @cindex formatted output | |
3403 | @cindex output formats | |
3404 | By default, _GDBN__ prints a value according to its data type. Sometimes | |
3405 | this is not what you want. For example, you might want to print a number | |
3406 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3407 | at a certain address as a character string or as an instruction. To do | |
3408 | these things, specify an @dfn{output format} when you print a value. | |
3409 | ||
3410 | The simplest use of output formats is to say how to print a value | |
3411 | already computed. This is done by starting the arguments of the | |
3412 | @code{print} command with a slash and a format letter. The format | |
3413 | letters supported are: | |
3414 | ||
3415 | @table @code | |
3416 | @item x | |
3417 | Regard the bits of the value as an integer, and print the integer in | |
3418 | hexadecimal. | |
3419 | ||
3420 | @item d | |
3421 | Print as integer in signed decimal. | |
3422 | ||
3423 | @item u | |
3424 | Print as integer in unsigned decimal. | |
3425 | ||
3426 | @item o | |
3427 | Print as integer in octal. | |
3428 | ||
3429 | @item t | |
3430 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3431 | ||
3432 | @item a | |
3433 | Print as an address, both absolute in hex and as an offset from the | |
3434 | nearest preceding symbol. This format can be used to discover where (in | |
3435 | what function) an unknown address is located: | |
1041a570 | 3436 | |
70b88761 RP |
3437 | @example |
3438 | (_GDBP__) p/a 0x54320 | |
3439 | _0__$3 = 0x54320 <_initialize_vx+396>_1__ | |
3440 | @end example | |
3441 | ||
70b88761 RP |
3442 | @item c |
3443 | Regard as an integer and print it as a character constant. | |
3444 | ||
3445 | @item f | |
3446 | Regard the bits of the value as a floating point number and print | |
3447 | using typical floating point syntax. | |
3448 | @end table | |
3449 | ||
3450 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3451 | ||
3452 | @example | |
3453 | p/x $pc | |
3454 | @end example | |
3455 | ||
3456 | @noindent | |
3457 | Note that no space is required before the slash; this is because command | |
3458 | names in _GDBN__ cannot contain a slash. | |
3459 | ||
3460 | To reprint the last value in the value history with a different format, | |
3461 | you can use the @code{print} command with just a format and no | |
3462 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3463 | ||
3464 | @node Memory, Auto Display, Output formats, Data | |
3465 | @section Examining Memory | |
3466 | ||
1041a570 RP |
3467 | You can use the command @code{x} (for ``examine'') to examine memory in |
3468 | any of several formats, independently of your program's data types. | |
3469 | ||
70b88761 RP |
3470 | @cindex examining memory |
3471 | @table @code | |
3472 | @kindex x | |
cedaf8bc RP |
3473 | @item x/@var{nfu} @var{addr} |
3474 | @itemx x @var{addr} | |
3475 | @itemx x | |
1041a570 RP |
3476 | Use the command @code{x} to examine memory. |
3477 | @end table | |
3478 | ||
3479 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3480 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
3481 | expression giving the address where you want to start displaying memory. |
3482 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3483 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 3484 | |
1041a570 RP |
3485 | @table @r |
3486 | @item @var{n}, the repeat count | |
3487 | The repeat count is a decimal integer; the default is 1. It specifies | |
3488 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
3489 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
3490 | @c 4.1.2. | |
70b88761 | 3491 | |
1041a570 RP |
3492 | @item @var{f}, the display format |
3493 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
3494 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
3495 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3496 | last time you used either @code{x} or @code{print}. | |
70b88761 | 3497 | |
1041a570 RP |
3498 | @item @var{u}, the unit size |
3499 | The unit size is any of | |
70b88761 RP |
3500 | @table @code |
3501 | @item b | |
cedaf8bc | 3502 | Bytes. |
70b88761 | 3503 | @item h |
cedaf8bc | 3504 | Halfwords (two bytes). |
70b88761 | 3505 | @item w |
cedaf8bc | 3506 | Words (four bytes). This is the initial default. |
70b88761 | 3507 | @item g |
cedaf8bc | 3508 | Giant words (eight bytes). |
70b88761 RP |
3509 | @end table |
3510 | ||
cedaf8bc RP |
3511 | Each time you specify a unit size with @code{x}, that size becomes the |
3512 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3513 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3514 | ||
1041a570 | 3515 | @item @var{addr}, starting display address |
cedaf8bc RP |
3516 | @var{addr} is the address where you want _GDBN__ to begin displaying |
3517 | memory. The expression need not have a pointer value (though it may); | |
3518 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 3519 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
3520 | @var{addr} is usually just after the last address examined---but several |
3521 | other commands also set the default address: @code{info breakpoints} (to | |
3522 | the address of the last breakpoint listed), @code{info line} (to the | |
3523 | starting address of a line), and @code{print} (if you use it to display | |
3524 | a value from memory). | |
1041a570 | 3525 | @end table |
70b88761 | 3526 | |
cedaf8bc RP |
3527 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
3528 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3529 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3530 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3531 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 3532 | |
cedaf8bc | 3533 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 3534 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
3535 | unit size or format comes first; either order will work. The output |
3536 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3537 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3538 | ||
3539 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3540 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3541 | @samp{3i} specifies that you want to see three machine instructions, | |
3542 | including any operands. The command @code{disassemble} gives an | |
3543 | alternative way of inspecting machine instructions; @pxref{Machine | |
3544 | Code}. | |
3545 | ||
3546 | All the defaults for the arguments to @code{x} are designed to make it | |
3547 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 3548 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
3549 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
3550 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3551 | the repeat count @var{n} is used again; the other arguments default as | |
3552 | for successive uses of @code{x}. | |
70b88761 | 3553 | |
c338a2fd | 3554 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 3555 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 RP |
3556 | in the value history because there is often too much of them and they |
3557 | would get in the way. Instead, _GDBN__ makes these values available for | |
3558 | subsequent use in expressions as values of the convenience variables | |
3559 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3560 | examined is available for use in expressions in the convenience variable | |
3561 | @code{$_}. The contents of that address, as examined, are available in | |
3562 | the convenience variable @code{$__}. | |
3563 | ||
3564 | If the @code{x} command has a repeat count, the address and contents saved | |
3565 | are from the last memory unit printed; this is not the same as the last | |
3566 | address printed if several units were printed on the last line of output. | |
3567 | ||
3568 | @node Auto Display, Print Settings, Memory, Data | |
3569 | @section Automatic Display | |
3570 | @cindex automatic display | |
3571 | @cindex display of expressions | |
3572 | ||
3573 | If you find that you want to print the value of an expression frequently | |
3574 | (to see how it changes), you might want to add it to the @dfn{automatic | |
29a2b744 | 3575 | display list} so that _GDBN__ will print its value each time your program stops. |
70b88761 RP |
3576 | Each expression added to the list is given a number to identify it; |
3577 | to remove an expression from the list, you specify that number. | |
3578 | The automatic display looks like this: | |
3579 | ||
3580 | @example | |
3581 | 2: foo = 38 | |
3582 | 3: bar[5] = (struct hack *) 0x3804 | |
3583 | @end example | |
3584 | ||
3585 | @noindent | |
3586 | showing item numbers, expressions and their current values. As with | |
3587 | displays you request manually using @code{x} or @code{print}, you can | |
3588 | specify the output format you prefer; in fact, @code{display} decides | |
3589 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3590 | format specification is---it uses @code{x} if you specify a unit size, | |
3591 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3592 | supported by @code{x}; otherwise it uses @code{print}. | |
3593 | ||
3594 | @table @code | |
3595 | @item display @var{exp} | |
3596 | @kindex display | |
3597 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 3598 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3599 | |
3600 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3601 | ||
3602 | @item display/@var{fmt} @var{exp} | |
3603 | For @var{fmt} specifying only a display format and not a size or | |
3604 | count, add the expression @var{exp} to the auto-display list but | |
3605 | arranges to display it each time in the specified format @var{fmt}. | |
3606 | @xref{Output formats}. | |
3607 | ||
3608 | @item display/@var{fmt} @var{addr} | |
3609 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3610 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 RP |
3611 | be examined each time your program stops. Examining means in effect |
3612 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
70b88761 RP |
3613 | @end table |
3614 | ||
3615 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3616 | instruction about to be executed each time execution stops (@samp{$pc} | |
3617 | is a common name for the program counter; @pxref{Registers}). | |
3618 | ||
3619 | @table @code | |
3620 | @item undisplay @var{dnums}@dots{} | |
3621 | @itemx delete display @var{dnums}@dots{} | |
3622 | @kindex delete display | |
3623 | @kindex undisplay | |
3624 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3625 | ||
3626 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3627 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3628 | ||
3629 | @item disable display @var{dnums}@dots{} | |
3630 | @kindex disable display | |
3631 | Disable the display of item numbers @var{dnums}. A disabled display | |
3632 | item is not printed automatically, but is not forgotten. It may be | |
3633 | enabled again later. | |
3634 | ||
3635 | @item enable display @var{dnums}@dots{} | |
3636 | @kindex enable display | |
3637 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3638 | again in auto display of its expression, until you specify otherwise. | |
3639 | ||
3640 | @item display | |
3641 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 3642 | done when your program stops. |
70b88761 RP |
3643 | |
3644 | @item info display | |
3645 | @kindex info display | |
3646 | Print the list of expressions previously set up to display | |
3647 | automatically, each one with its item number, but without showing the | |
3648 | values. This includes disabled expressions, which are marked as such. | |
3649 | It also includes expressions which would not be displayed right now | |
3650 | because they refer to automatic variables not currently available. | |
3651 | @end table | |
3652 | ||
3653 | If a display expression refers to local variables, then it does not make | |
3654 | sense outside the lexical context for which it was set up. Such an | |
3655 | expression is disabled when execution enters a context where one of its | |
3656 | variables is not defined. For example, if you give the command | |
3657 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 3658 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
3659 | continues to stop inside that function. When it stops elsewhere---where |
3660 | there is no variable @code{last_char}---display is disabled. The next time | |
3661 | your program stops where @code{last_char} is meaningful, you can enable the | |
3662 | display expression once again. | |
3663 | ||
3664 | @node Print Settings, Value History, Auto Display, Data | |
3665 | @section Print Settings | |
3666 | ||
3667 | @cindex format options | |
3668 | @cindex print settings | |
3669 | _GDBN__ provides the following ways to control how arrays, structures, | |
e251e767 | 3670 | and symbols are printed. |
70b88761 RP |
3671 | |
3672 | @noindent | |
3673 | These settings are useful for debugging programs in any language: | |
3674 | ||
3675 | @table @code | |
3676 | @item set print address | |
3677 | @item set print address on | |
3678 | @kindex set print address | |
3679 | _GDBN__ will print memory addresses showing the location of stack | |
3680 | traces, structure values, pointer values, breakpoints, and so forth, | |
3681 | even when it also displays the contents of those addresses. The default | |
3682 | is on. For example, this is what a stack frame display looks like, with | |
3683 | @code{set print address on}: | |
1041a570 | 3684 | |
70b88761 | 3685 | @smallexample |
1041a570 | 3686 | @group |
70b88761 | 3687 | (_GDBP__) f |
e251e767 | 3688 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 3689 | at input.c:530 |
b80282d5 | 3690 | 530 if (lquote != def_lquote) |
1041a570 | 3691 | @end group |
70b88761 RP |
3692 | @end smallexample |
3693 | ||
3694 | @item set print address off | |
3695 | Do not print addresses when displaying their contents. For example, | |
3696 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 3697 | |
70b88761 | 3698 | @example |
1041a570 | 3699 | @group |
70b88761 RP |
3700 | (_GDBP__) set print addr off |
3701 | (_GDBP__) f | |
3702 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
b80282d5 | 3703 | 530 if (lquote != def_lquote) |
1041a570 | 3704 | @end group |
70b88761 RP |
3705 | @end example |
3706 | ||
3707 | @item show print address | |
3708 | @kindex show print address | |
3709 | Show whether or not addresses are to be printed. | |
3710 | ||
3711 | @item set print array | |
3712 | @itemx set print array on | |
3713 | @kindex set print array | |
3714 | _GDBN__ will pretty print arrays. This format is more convenient to read, | |
3715 | but uses more space. The default is off. | |
3716 | ||
3717 | @item set print array off. | |
3718 | Return to compressed format for arrays. | |
3719 | ||
3720 | @item show print array | |
3721 | @kindex show print array | |
3722 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 3723 | arrays. |
70b88761 RP |
3724 | |
3725 | @item set print elements @var{number-of-elements} | |
3726 | @kindex set print elements | |
3727 | If _GDBN__ is printing a large array, it will stop printing after it has | |
3728 | printed the number of elements set by the @code{set print elements} command. | |
3729 | This limit also applies to the display of strings. | |
3730 | ||
3731 | @item show print elements | |
3732 | @kindex show print elements | |
3733 | Display the number of elements of a large array that _GDBN__ will print | |
3734 | before losing patience. | |
3735 | ||
3736 | @item set print pretty on | |
3737 | @kindex set print pretty | |
3738 | Cause _GDBN__ to print structures in an indented format with one member per | |
3739 | line, like this: | |
3740 | ||
3741 | @example | |
1041a570 | 3742 | @group |
70b88761 RP |
3743 | $1 = @{ |
3744 | next = 0x0, | |
3745 | flags = @{ | |
3746 | sweet = 1, | |
3747 | sour = 1 | |
3748 | @}, | |
3749 | meat = 0x54 "Pork" | |
3750 | @} | |
1041a570 | 3751 | @end group |
70b88761 RP |
3752 | @end example |
3753 | ||
3754 | @item set print pretty off | |
3755 | Cause _GDBN__ to print structures in a compact format, like this: | |
3756 | ||
3757 | @smallexample | |
1041a570 | 3758 | @group |
70b88761 RP |
3759 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \ |
3760 | = 0x54 "Pork"@} | |
1041a570 | 3761 | @end group |
70b88761 RP |
3762 | @end smallexample |
3763 | ||
3764 | @noindent | |
3765 | This is the default format. | |
3766 | ||
3767 | @item show print pretty | |
3768 | @kindex show print pretty | |
3769 | Show which format _GDBN__ will use to print structures. | |
3770 | ||
3771 | @item set print sevenbit-strings on | |
f2857bd9 | 3772 | @kindex set print sevenbit-strings |
e251e767 | 3773 | Print using only seven-bit characters; if this option is set, |
70b88761 RP |
3774 | _GDBN__ will display any eight-bit characters (in strings or character |
3775 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
3776 | displayed as @code{\341}. | |
3777 | ||
3778 | @item set print sevenbit-strings off | |
3779 | Print using either seven-bit or eight-bit characters, as required. This | |
3780 | is the default. | |
3781 | ||
3782 | @item show print sevenbit-strings | |
f2857bd9 | 3783 | @kindex show print sevenbit-strings |
70b88761 RP |
3784 | Show whether or not _GDBN__ will print only seven-bit characters. |
3785 | ||
3786 | @item set print union on | |
3787 | @kindex set print union | |
3788 | Tell _GDBN__ to print unions which are contained in structures. This is the | |
3789 | default setting. | |
3790 | ||
3791 | @item set print union off | |
3792 | Tell _GDBN__ not to print unions which are contained in structures. | |
3793 | ||
3794 | @item show print union | |
3795 | @kindex show print union | |
3796 | Ask _GDBN__ whether or not it will print unions which are contained in | |
e251e767 | 3797 | structures. |
70b88761 RP |
3798 | |
3799 | For example, given the declarations | |
3800 | ||
3801 | @smallexample | |
3802 | typedef enum @{Tree, Bug@} Species; | |
3803 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
3804 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
3805 | Bug_forms; | |
70b88761 RP |
3806 | |
3807 | struct thing @{ | |
3808 | Species it; | |
3809 | union @{ | |
3810 | Tree_forms tree; | |
3811 | Bug_forms bug; | |
3812 | @} form; | |
3813 | @}; | |
3814 | ||
3815 | struct thing foo = @{Tree, @{Acorn@}@}; | |
3816 | @end smallexample | |
3817 | ||
3818 | @noindent | |
3819 | with @code{set print union on} in effect @samp{p foo} would print | |
3820 | ||
3821 | @smallexample | |
3822 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
3823 | @end smallexample | |
3824 | ||
3825 | @noindent | |
3826 | and with @code{set print union off} in effect it would print | |
3827 | ||
3828 | @smallexample | |
3829 | $1 = @{it = Tree, form = @{...@}@} | |
3830 | @end smallexample | |
3831 | @end table | |
3832 | ||
3833 | @noindent | |
3834 | These settings are of interest when debugging C++ programs: | |
3835 | ||
3836 | @table @code | |
e251e767 RP |
3837 | @item set print demangle |
3838 | @itemx set print demangle on | |
70b88761 RP |
3839 | @kindex set print demangle |
3840 | Print C++ names in their source form rather than in the mangled form | |
3841 | in which they are passed to the assembler and linker for type-safe linkage. | |
3842 | The default is on. | |
3843 | ||
3844 | @item show print demangle | |
3845 | @kindex show print demangle | |
3846 | Show whether C++ names will be printed in mangled or demangled form. | |
3847 | ||
e251e767 RP |
3848 | @item set print asm-demangle |
3849 | @itemx set print asm-demangle on | |
70b88761 RP |
3850 | @kindex set print asm-demangle |
3851 | Print C++ names in their source form rather than their mangled form, even | |
3852 | in assembler code printouts such as instruction disassemblies. | |
3853 | The default is off. | |
3854 | ||
3855 | @item show print asm-demangle | |
3856 | @kindex show print asm-demangle | |
3857 | Show whether C++ names in assembly listings will be printed in mangled | |
3858 | or demangled form. | |
3859 | ||
3860 | @item set print object | |
3861 | @itemx set print object on | |
3862 | @kindex set print object | |
3863 | When displaying a pointer to an object, identify the @emph{actual} | |
3864 | (derived) type of the object rather than the @emph{declared} type, using | |
3865 | the virtual function table. | |
3866 | ||
3867 | @item set print object off | |
3868 | Display only the declared type of objects, without reference to the | |
3869 | virtual function table. This is the default setting. | |
3870 | ||
3871 | @item show print object | |
3872 | @kindex show print object | |
3873 | Show whether actual, or declared, object types will be displayed. | |
3874 | ||
e251e767 RP |
3875 | @item set print vtbl |
3876 | @itemx set print vtbl on | |
70b88761 RP |
3877 | @kindex set print vtbl |
3878 | Pretty print C++ virtual function tables. The default is off. | |
3879 | ||
3880 | @item set print vtbl off | |
3881 | Do not pretty print C++ virtual function tables. | |
3882 | ||
3883 | @item show print vtbl | |
3884 | @kindex show print vtbl | |
3885 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 RP |
3886 | @end table |
3887 | ||
3888 | @node Value History, Convenience Vars, Print Settings, Data | |
3889 | @section Value History | |
3890 | ||
3891 | @cindex value history | |
3892 | Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value | |
3893 | history} so that you can refer to them in other expressions. Values are | |
3894 | kept until the symbol table is re-read or discarded (for example with | |
3895 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
3896 | changes, the value history is discarded, since the values may contain | |
3897 | pointers back to the types defined in the symbol table. | |
3898 | ||
3899 | @cindex @code{$} | |
3900 | @cindex @code{$$} | |
3901 | @cindex history number | |
3902 | The values printed are given @dfn{history numbers} for you to refer to them | |
3903 | by. These are successive integers starting with one. @code{print} shows you | |
3904 | the history number assigned to a value by printing @samp{$@var{num} = } | |
3905 | before the value; here @var{num} is the history number. | |
3906 | ||
3907 | To refer to any previous value, use @samp{$} followed by the value's | |
3908 | history number. The way @code{print} labels its output is designed to | |
3909 | remind you of this. Just @code{$} refers to the most recent value in | |
3910 | the history, and @code{$$} refers to the value before that. | |
3911 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
3912 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
3913 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
3914 | ||
3915 | For example, suppose you have just printed a pointer to a structure and | |
3916 | want to see the contents of the structure. It suffices to type | |
3917 | ||
3918 | @example | |
3919 | p *$ | |
3920 | @end example | |
3921 | ||
3922 | If you have a chain of structures where the component @code{next} points | |
3923 | to the next one, you can print the contents of the next one with this: | |
3924 | ||
3925 | @example | |
3926 | p *$.next | |
3927 | @end example | |
3928 | ||
3929 | @noindent | |
3930 | You can print successive links in the chain by repeating this | |
3931 | command---which you can do by just typing @key{RET}. | |
3932 | ||
3933 | Note that the history records values, not expressions. If the value of | |
3934 | @code{x} is 4 and you type these commands: | |
3935 | ||
3936 | @example | |
3937 | print x | |
3938 | set x=5 | |
3939 | @end example | |
3940 | ||
3941 | @noindent | |
3942 | then the value recorded in the value history by the @code{print} command | |
3943 | remains 4 even though the value of @code{x} has changed. | |
3944 | ||
3945 | @table @code | |
3946 | @kindex show values | |
3947 | @item show values | |
3948 | Print the last ten values in the value history, with their item numbers. | |
3949 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
3950 | values} does not change the history. | |
3951 | ||
3952 | @item show values @var{n} | |
3953 | Print ten history values centered on history item number @var{n}. | |
3954 | ||
3955 | @item show values + | |
3956 | Print ten history values just after the values last printed. If no more | |
3957 | values are available, produces no display. | |
3958 | @end table | |
3959 | ||
3960 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 3961 | same effect as @samp{show values +}. |
70b88761 RP |
3962 | |
3963 | @node Convenience Vars, Registers, Value History, Data | |
3964 | @section Convenience Variables | |
3965 | ||
3966 | @cindex convenience variables | |
3967 | _GDBN__ provides @dfn{convenience variables} that you can use within | |
3968 | _GDBN__ to hold on to a value and refer to it later. These variables | |
3969 | exist entirely within _GDBN__; they are not part of your program, and | |
3970 | setting a convenience variable has no direct effect on further execution | |
1041a570 | 3971 | of your program. That is why you can use them freely. |
70b88761 RP |
3972 | |
3973 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
3974 | @samp{$} can be used for a convenience variable, unless it is one of | |
3975 | the predefined machine-specific register names (@pxref{Registers}). | |
3976 | (Value history references, in contrast, are @emph{numbers} preceded | |
1041a570 | 3977 | by @samp{$}. @xref{Value History, ,Value History}.) |
70b88761 RP |
3978 | |
3979 | You can save a value in a convenience variable with an assignment | |
3980 | expression, just as you would set a variable in your program. Example: | |
3981 | ||
3982 | @example | |
3983 | set $foo = *object_ptr | |
3984 | @end example | |
3985 | ||
3986 | @noindent | |
3987 | would save in @code{$foo} the value contained in the object pointed to by | |
3988 | @code{object_ptr}. | |
3989 | ||
3990 | Using a convenience variable for the first time creates it; but its value | |
3991 | is @code{void} until you assign a new value. You can alter the value with | |
3992 | another assignment at any time. | |
3993 | ||
3994 | Convenience variables have no fixed types. You can assign a convenience | |
3995 | variable any type of value, including structures and arrays, even if | |
3996 | that variable already has a value of a different type. The convenience | |
3997 | variable, when used as an expression, has the type of its current value. | |
3998 | ||
3999 | @table @code | |
4000 | @item show convenience | |
4001 | @kindex show convenience | |
4002 | Print a list of convenience variables used so far, and their values. | |
4003 | Abbreviated @code{show con}. | |
4004 | @end table | |
4005 | ||
4006 | One of the ways to use a convenience variable is as a counter to be | |
4007 | incremented or a pointer to be advanced. For example, to print | |
4008 | a field from successive elements of an array of structures: | |
4009 | ||
4010 | _0__@example | |
4011 | set $i = 0 | |
4012 | print bar[$i++]->contents | |
4013 | @i{@dots{} repeat that command by typing @key{RET}.} | |
4014 | _1__@end example | |
4015 | ||
4016 | Some convenience variables are created automatically by _GDBN__ and given | |
4017 | values likely to be useful. | |
4018 | ||
4019 | @table @code | |
4020 | @item $_ | |
c338a2fd | 4021 | @kindex $_ |
70b88761 | 4022 | The variable @code{$_} is automatically set by the @code{x} command to |
29a2b744 RP |
4023 | the last address examined (@pxref{Memory, ,Examining Memory}). Other |
4024 | commands which provide a default address for @code{x} to examine also | |
4025 | set @code{$_} to that address; these commands include @code{info line} | |
4026 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4027 | except when set by the @code{x} command, in which case it is a pointer | |
4028 | to the type of @code{$__}. | |
70b88761 RP |
4029 | |
4030 | @item $__ | |
c338a2fd | 4031 | @kindex $__ |
70b88761 | 4032 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
4033 | to the value found in the last address examined. Its type is chosen |
4034 | to match the format in which the data was printed. | |
70b88761 RP |
4035 | @end table |
4036 | ||
4037 | @node Registers, Floating Point Hardware, Convenience Vars, Data | |
4038 | @section Registers | |
4039 | ||
4040 | @cindex registers | |
b80282d5 | 4041 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
4042 | with names starting with @samp{$}. The names of registers are different |
4043 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 4044 | your machine. |
70b88761 RP |
4045 | |
4046 | @table @code | |
4047 | @item info registers | |
4048 | @kindex info registers | |
b80282d5 RP |
4049 | Print the names and values of all registers except floating-point |
4050 | registers (in the selected stack frame). | |
4051 | ||
4052 | @item info all-registers | |
4053 | @kindex info all-registers | |
4054 | @cindex floating point registers | |
4055 | Print the names and values of all registers, including floating-point | |
4056 | registers. | |
70b88761 RP |
4057 | |
4058 | @item info registers @var{regname} | |
4059 | Print the relativized value of register @var{regname}. @var{regname} | |
4060 | may be any register name valid on the machine you are using, with | |
4061 | or without the initial @samp{$}. | |
4062 | @end table | |
4063 | ||
09267865 | 4064 | _GDBN__ has four ``standard'' register names that are available (in |
29a2b744 | 4065 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
4066 | architecture's canonical mnemonics for registers. The register names |
4067 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4068 | the stack pointer. @code{$fp} is used for a register that contains a | |
4069 | pointer to the current stack frame, and @code{$ps} is used for a | |
4070 | register that contains the processor status. For example, | |
70b88761 | 4071 | you could print the program counter in hex with |
1041a570 | 4072 | |
70b88761 RP |
4073 | @example |
4074 | p/x $pc | |
4075 | @end example | |
4076 | ||
4077 | @noindent | |
4078 | or print the instruction to be executed next with | |
1041a570 | 4079 | |
70b88761 RP |
4080 | @example |
4081 | x/i $pc | |
4082 | @end example | |
4083 | ||
4084 | @noindent | |
29a2b744 RP |
4085 | or add four to the stack pointer @footnote{This is a way of removing |
4086 | one word from the stack, on machines where stacks grow downward in | |
4087 | memory (most machines, nowadays). This assumes that the innermost | |
4088 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4089 | stack frames are selected. To pop entire frames off the stack, | |
4090 | regardless of machine architecture, use @code{return}; | |
1041a570 RP |
4091 | @pxref{Returning, ,Returning from a Function}.} with |
4092 | ||
70b88761 RP |
4093 | @example |
4094 | set $sp += 4 | |
4095 | @end example | |
4096 | ||
09267865 RP |
4097 | Whenever possible, these four standard register names are available on |
4098 | your machine even though the machine has different canonical mnemonics, | |
4099 | so long as there is no conflict. The @code{info registers} command | |
4100 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
4101 | registers} displays the processor status register as @code{$psr} but you |
4102 | can also refer to it as @code{$ps}. | |
4103 | ||
4104 | _GDBN__ always considers the contents of an ordinary register as an | |
4105 | integer when the register is examined in this way. Some machines have | |
4106 | special registers which can hold nothing but floating point; these | |
4107 | registers are considered to have floating point values. There is no way | |
4108 | to refer to the contents of an ordinary register as floating point value | |
4109 | (although you can @emph{print} it as a floating point value with | |
4110 | @samp{print/f $@var{regname}}). | |
4111 | ||
4112 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4113 | means that the data format in which the register contents are saved by | |
4114 | the operating system is not the same one that your program normally | |
4115 | sees. For example, the registers of the 68881 floating point | |
4116 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4117 | programs expect to work with ``double'' (virtual) format. In such | |
4118 | cases, _GDBN__ normally works with the virtual format only (the format that | |
4119 | makes sense for your program), but the @code{info registers} command | |
4120 | prints the data in both formats. | |
4121 | ||
4122 | Normally, register values are relative to the selected stack frame | |
29a2b744 RP |
4123 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the |
4124 | value that the register would contain if all stack frames farther in | |
4125 | were exited and their saved registers restored. In order to see the | |
4126 | true contents of hardware registers, you must select the innermost | |
4127 | frame (with @samp{frame 0}). | |
70b88761 RP |
4128 | |
4129 | However, _GDBN__ must deduce where registers are saved, from the machine | |
4130 | code generated by your compiler. If some registers are not saved, or if | |
4131 | _GDBN__ is unable to locate the saved registers, the selected stack | |
4132 | frame will make no difference. | |
4133 | ||
4134 | @node Floating Point Hardware, , Registers, Data | |
4135 | @section Floating Point Hardware | |
4136 | @cindex floating point | |
1041a570 | 4137 | |
70b88761 RP |
4138 | Depending on the host machine architecture, _GDBN__ may be able to give |
4139 | you more information about the status of the floating point hardware. | |
4140 | ||
4141 | @table @code | |
4142 | @item info float | |
4143 | @kindex info float | |
4144 | If available, provides hardware-dependent information about the floating | |
4145 | point unit. The exact contents and layout vary depending on the | |
4146 | floating point chip. | |
4147 | @end table | |
4148 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
4149 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
4150 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 RP |
4151 | @c FIXME... at that point. |
4152 | ||
c2bbbb22 RP |
4153 | @node Languages, Symbols, Data, Top |
4154 | @chapter Using _GDBN__ with Different Languages | |
4155 | @cindex languages | |
4156 | ||
4157 | Although programming languages generally have common aspects, they are | |
4158 | rarely expressed in the same manner. For instance, in ANSI C, | |
4159 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4160 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4161 | represented (and displayed) differently. Hex numbers in C are written | |
4162 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4163 | ||
4164 | @cindex working language | |
4165 | Language-specific information is built into _GDBN__ for some languages, | |
29a2b744 | 4166 | allowing you to express operations like the above in your program's |
c2bbbb22 | 4167 | native language, and allowing _GDBN__ to output values in a manner |
29a2b744 | 4168 | consistent with the syntax of your program's native language. The |
c2bbbb22 RP |
4169 | language you use to build expressions, called the @dfn{working |
4170 | language}, can be selected manually, or _GDBN__ can set it | |
4171 | automatically. | |
4172 | ||
4173 | @menu | |
4174 | * Setting:: Switching between source languages | |
4175 | * Show:: Displaying the language | |
4176 | * Checks:: Type and Range checks | |
4177 | * Support:: Supported languages | |
4178 | @end menu | |
4179 | ||
4180 | @node Setting, Show, Languages, Languages | |
4181 | @section Switching between source languages | |
4182 | ||
4183 | There are two ways to control the working language---either have _GDBN__ | |
4184 | set it automatically, or select it manually yourself. You can use the | |
4185 | @code{set language} command for either purpose. On startup, _GDBN__ | |
4186 | defaults to setting the language automatically. | |
4187 | ||
4188 | @menu | |
4189 | * Manually:: Setting the working language manually | |
4190 | * Automatically:: Having _GDBN__ infer the source language | |
4191 | @end menu | |
4192 | ||
4193 | @node Manually, Automatically, Setting, Setting | |
4194 | @subsection Setting the working language | |
4195 | ||
4196 | @kindex set language | |
4197 | To set the language, issue the command @samp{set language @var{lang}}, | |
c338a2fd RP |
4198 | where @var{lang} is the name of a language: @code{c} or @code{modula-2}. |
4199 | For a list of the supported languages, type @samp{set language}. | |
c2bbbb22 RP |
4200 | |
4201 | Setting the language manually prevents _GDBN__ from updating the working | |
4202 | language automatically. This can lead to confusion if you try | |
4203 | to debug a program when the working language is not the same as the | |
4204 | source language, when an expression is acceptable to both | |
4205 | languages---but means different things. For instance, if the current | |
4206 | source file were written in C, and _GDBN__ was parsing Modula-2, a | |
4207 | command such as: | |
4208 | ||
4209 | @example | |
4210 | print a = b + c | |
4211 | @end example | |
4212 | ||
4213 | @noindent | |
4214 | might not have the effect you intended. In C, this means to add | |
4215 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4216 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4217 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4218 | ||
4219 | If you allow _GDBN__ to set the language automatically, then | |
4220 | you can count on expressions evaluating the same way in your debugging | |
4221 | session and in your program. | |
4222 | ||
4223 | @node Automatically, , Manually, Setting | |
4224 | @subsection Having _GDBN__ infer the source language | |
4225 | ||
4226 | To have _GDBN__ set the working language automatically, use @samp{set | |
4227 | language local} or @samp{set language auto}. _GDBN__ then infers the | |
4228 | language that a program was written in by looking at the name of its | |
4229 | source files, and examining their extensions: | |
4230 | ||
4231 | @table @file | |
4232 | @item *.mod | |
4233 | Modula-2 source file | |
4234 | ||
4235 | @item *.c | |
4236 | @itemx *.cc | |
4237 | C or C++ source file. | |
4238 | @end table | |
4239 | ||
4240 | This information is recorded for each function or procedure in a source | |
4241 | file. When your program stops in a frame (usually by encountering a | |
4242 | breakpoint), _GDBN__ sets the working language to the language recorded | |
4243 | for the function in that frame. If the language for a frame is unknown | |
4244 | (that is, if the function or block corresponding to the frame was | |
4245 | defined in a source file that does not have a recognized extension), the | |
4246 | current working language is not changed, and _GDBN__ issues a warning. | |
4247 | ||
4248 | This may not seem necessary for most programs, which are written | |
4249 | entirely in one source language. However, program modules and libraries | |
4250 | written in one source language can be used by a main program written in | |
4251 | a different source language. Using @samp{set language auto} in this | |
4252 | case frees you from having to set the working language manually. | |
4253 | ||
4254 | @node Show, Checks, Setting, Languages | |
4255 | @section Displaying the language | |
4256 | ||
4257 | The following commands will help you find out which language is the | |
4258 | working language, and also what language source files were written in. | |
4259 | ||
4260 | @kindex show language | |
4261 | @kindex info frame | |
4262 | @kindex info source | |
4263 | @table @code | |
4264 | @item show language | |
4265 | Display the current working language. This is the | |
4266 | language you can use with commands such as @code{print} to | |
29a2b744 | 4267 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
4268 | |
4269 | @item info frame | |
1041a570 | 4270 | Among the other information listed here (@pxref{Frame Info, ,Information |
c2bbbb22 RP |
4271 | about a Frame}) is the source language for this frame. This is the |
4272 | language that will become the working language if you ever use an | |
4273 | identifier that is in this frame. | |
4274 | ||
4275 | @item info source | |
1041a570 | 4276 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 4277 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
4278 | @end table |
4279 | ||
4280 | @node Checks, Support, Show, Languages | |
4281 | @section Type and range Checking | |
4282 | ||
4283 | @quotation | |
4284 | @emph{Warning:} In this release, the _GDBN__ commands for type and range | |
4285 | checking are included, but they do not yet have any effect. This | |
4286 | section documents the intended facilities. | |
4287 | @end quotation | |
4288 | @c FIXME remove warning when type/range code added | |
4289 | ||
4290 | Some languages are designed to guard you against making seemingly common | |
4291 | errors through a series of compile- and run-time checks. These include | |
4292 | checking the type of arguments to functions and operators, and making | |
4293 | sure mathematical overflows are caught at run time. Checks such as | |
4294 | these help to ensure a program's correctness once it has been compiled | |
4295 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 4296 | errors when your program is running. |
c2bbbb22 | 4297 | |
1041a570 RP |
4298 | _GDBN__ can check for conditions like the above if you wish. |
4299 | Although _GDBN__ will not check the statements in your program, it | |
4300 | can check expressions entered directly into _GDBN__ for evaluation via | |
4301 | the @code{print} command, for example. As with the working language, | |
c2bbbb22 | 4302 | _GDBN__ can also decide whether or not to check automatically based on |
1041a570 RP |
4303 | your program's source language. @xref{Support, ,Supported Languages}, |
4304 | for the default settings of supported languages. | |
c2bbbb22 RP |
4305 | |
4306 | @menu | |
4307 | * Type Checking:: An overview of type checking | |
4308 | * Range Checking:: An overview of range checking | |
4309 | @end menu | |
4310 | ||
4311 | @cindex type checking | |
4312 | @cindex checks, type | |
4313 | @node Type Checking, Range Checking, Checks, Checks | |
4314 | @subsection An overview of type checking | |
4315 | ||
4316 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4317 | arguments to operators and functions have to be of the correct type, | |
4318 | otherwise an error occurs. These checks prevent type mismatch | |
4319 | errors from ever causing any run-time problems. For example, | |
4320 | ||
4321 | @example | |
4322 | 1 + 2 @result{} 3 | |
1041a570 | 4323 | @exdent but |
c2bbbb22 RP |
4324 | @error{} 1 + 2.3 |
4325 | @end example | |
4326 | ||
4327 | The second example fails because the @code{CARDINAL} 1 is not | |
4328 | type-compatible with the @code{REAL} 2.3. | |
4329 | ||
4330 | For expressions you use in _GDBN__ commands, you can tell the _GDBN__ | |
4331 | type checker to skip checking; to treat any mismatches as errors and | |
4332 | abandon the expression; or only issue warnings when type mismatches | |
4333 | occur, but evaluate the expression anyway. When you choose the last of | |
4334 | these, _GDBN__ evaluates expressions like the second example above, but | |
4335 | also issues a warning. | |
4336 | ||
4337 | Even though you may turn type checking off, other type-based reasons may | |
4338 | prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not | |
4339 | know how to add an @code{int} and a @code{struct foo}. These particular | |
4340 | type errors have nothing to do with the language in use, and usually | |
4341 | arise from expressions, such as the one described above, which make | |
4342 | little sense to evaluate anyway. | |
4343 | ||
4344 | Each language defines to what degree it is strict about type. For | |
4345 | instance, both Modula-2 and C require the arguments to arithmetical | |
4346 | operators to be numbers. In C, enumerated types and pointers can be | |
4347 | represented as numbers, so that they are valid arguments to mathematical | |
1041a570 | 4348 | operators. @xref{Support, ,Supported Languages}, for further |
c2bbbb22 RP |
4349 | details on specific languages. |
4350 | ||
4351 | _GDBN__ provides some additional commands for controlling the type checker: | |
4352 | ||
4353 | @kindex set check | |
4354 | @kindex set check type | |
4355 | @kindex show check type | |
4356 | @table @code | |
4357 | @item set check type auto | |
e251e767 | 4358 | Set type checking on or off based on the current working language. |
1041a570 | 4359 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4360 | each language. |
4361 | ||
4362 | @item set check type on | |
4363 | @itemx set check type off | |
4364 | Set type checking on or off, overriding the default setting for the | |
4365 | current working language. Issue a warning if the setting does not | |
4366 | match the language's default. If any type mismatches occur in | |
4367 | evaluating an expression while typechecking is on, _GDBN__ prints a | |
4368 | message and aborts evaluation of the expression. | |
4369 | ||
4370 | @item set check type warn | |
4371 | Cause the type checker to issue warnings, but to always attempt to | |
4372 | evaluate the expression. Evaluating the expression may still | |
4373 | be impossible for other reasons. For example, _GDBN__ cannot add | |
4374 | numbers and structures. | |
4375 | ||
4376 | @item show type | |
e251e767 | 4377 | Show the current setting of the type checker, and whether or not _GDBN__ is |
c2bbbb22 RP |
4378 | setting it automatically. |
4379 | @end table | |
4380 | ||
4381 | @cindex range checking | |
4382 | @cindex checks, range | |
4383 | @node Range Checking, , Type Checking, Checks | |
4384 | @subsection An overview of Range Checking | |
4385 | ||
4386 | In some languages (such as Modula-2), it is an error to exceed the | |
4387 | bounds of a type; this is enforced with run-time checks. Such range | |
4388 | checking is meant to ensure program correctness by making sure | |
4389 | computations do not overflow, or indices on an array element access do | |
4390 | not exceed the bounds of the array. | |
4391 | ||
4392 | For expressions you use in _GDBN__ commands, you can tell _GDBN__ to | |
4393 | ignore range errors; to always treat them as errors and abandon the | |
4394 | expression; or to issue warnings when a range error occurs but evaluate | |
4395 | the expression anyway. | |
4396 | ||
4397 | A range error can result from numerical overflow, from exceeding an | |
4398 | array index bound, or when you type in a constant that is not a member | |
4399 | of any type. Some languages, however, do not treat overflows as an | |
4400 | error. In many implementations of C, mathematical overflow causes the | |
4401 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4402 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 4403 | |
c2bbbb22 RP |
4404 | @example |
4405 | @var{m} + 1 @result{} @var{s} | |
4406 | @end example | |
4407 | ||
4408 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 4409 | specific to individual compilers or machines. @xref{Support, , |
c2bbbb22 RP |
4410 | Supported Languages}, for further details on specific languages. |
4411 | ||
4412 | _GDBN__ provides some additional commands for controlling the range checker: | |
4413 | ||
4414 | @kindex set check | |
4415 | @kindex set check range | |
4416 | @kindex show check range | |
4417 | @table @code | |
4418 | @item set check range auto | |
e251e767 | 4419 | Set range checking on or off based on the current working language. |
1041a570 | 4420 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4421 | each language. |
4422 | ||
4423 | @item set check range on | |
4424 | @itemx set check range off | |
4425 | Set range checking on or off, overriding the default setting for the | |
4426 | current working language. A warning is issued if the setting does not | |
4427 | match the language's default. If a range error occurs, then a message | |
4428 | is printed and evaluation of the expression is aborted. | |
4429 | ||
4430 | @item set check range warn | |
4431 | Output messages when the _GDBN__ range checker detects a range error, | |
4432 | but attempt to evaluate the expression anyway. Evaluating the | |
4433 | expression may still be impossible for other reasons, such as accessing | |
4434 | memory that the process does not own (a typical example from many UNIX | |
4435 | systems). | |
4436 | ||
4437 | @item show range | |
e251e767 | 4438 | Show the current setting of the range checker, and whether or not it is |
c2bbbb22 RP |
4439 | being set automatically by _GDBN__. |
4440 | @end table | |
4441 | ||
4442 | @node Support, , Checks, Languages | |
4443 | @section Supported Languages | |
4444 | ||
1041a570 RP |
4445 | _GDBN__ 4 supports C, C++, and Modula-2. The syntax for C and C++ is so |
4446 | closely related that _GDBN__ does not distinguish the two. Some _GDBN__ | |
4447 | features may be used in expressions regardless of the language you | |
4448 | use: the _GDBN__ @code{@@} and @code{::} operators, and the | |
4449 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be | |
4450 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
4451 | |
4452 | The following sections detail to what degree each of these | |
4453 | source languages is supported by _GDBN__. These sections are | |
4454 | not meant to be language tutorials or references, but serve only as a | |
4455 | reference guide to what the _GDBN__ expression parser will accept, and | |
4456 | what input and output formats should look like for different languages. | |
4457 | There are many good books written on each of these languages; please | |
4458 | look to these for a language reference or tutorial. | |
4459 | ||
4460 | @menu | |
4461 | * C:: C and C++ | |
4462 | * Modula-2:: Modula-2 | |
4463 | @end menu | |
4464 | ||
4465 | @node C, Modula-2, Support, Support | |
4466 | @subsection C and C++ | |
4467 | @cindex C and C++ | |
4468 | ||
4469 | @cindex expressions in C or C++ | |
4470 | Since C and C++ are so closely related, _GDBN__ does not distinguish | |
4471 | between them when interpreting the expressions recognized in _GDBN__ | |
e251e767 | 4472 | commands. |
b80282d5 RP |
4473 | |
4474 | @cindex C++ | |
4475 | @kindex g++ | |
4476 | @cindex GNU C++ | |
c2bbbb22 RP |
4477 | The C++ debugging facilities are jointly implemented by the GNU C++ |
4478 | compiler and _GDBN__. Therefore, to debug your C++ code effectively, | |
4479 | you must compile your C++ programs with the GNU C++ compiler, | |
4480 | @code{g++}. | |
4481 | ||
b80282d5 | 4482 | @menu |
c2bbbb22 RP |
4483 | * C Operators:: C and C++ Operators |
4484 | * C Constants:: C and C++ Constants | |
4485 | * Cplusplus expressions:: C++ Expressions | |
4486 | * C Defaults:: Default settings for C and C++ | |
4487 | * C Checks:: C and C++ Type and Range Checks | |
4488 | * Debugging C:: _GDBN__ and C | |
4489 | * Debugging C plus plus:: Special features for C++ | |
b80282d5 RP |
4490 | @end menu |
4491 | ||
c2bbbb22 RP |
4492 | @cindex C and C++ operators |
4493 | @node C Operators, C Constants, C, C | |
4494 | @subsubsection C and C++ Operators | |
4495 | ||
4496 | Operators must be defined on values of specific types. For instance, | |
4497 | @code{+} is defined on numbers, but not on structures. Operators are | |
4498 | often defined on groups of types. For the purposes of C and C++, the | |
4499 | following definitions hold: | |
4500 | ||
4501 | @itemize @bullet | |
e251e767 | 4502 | @item |
c2bbbb22 RP |
4503 | @emph{Integral types} include @code{int} with any of its storage-class |
4504 | specifiers, @code{char}, and @code{enum}s. | |
4505 | ||
4506 | @item | |
4507 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4508 | ||
4509 | @item | |
4510 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4511 | *)}. | |
4512 | ||
e251e767 | 4513 | @item |
c2bbbb22 | 4514 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
4515 | @end itemize |
4516 | ||
4517 | @noindent | |
4518 | The following operators are supported. They are listed here | |
4519 | in order of increasing precedence: | |
4520 | ||
4521 | @table @code | |
1041a570 | 4522 | _0__@item , |
c2bbbb22 RP |
4523 | The comma or sequencing operator. Expressions in a comma-separated list |
4524 | are evaluated from left to right, with the result of the entire | |
4525 | expression being the last expression evaluated. | |
4526 | ||
4527 | @item = | |
4528 | Assignment. The value of an assignment expression is the value | |
4529 | assigned. Defined on scalar types. | |
4530 | ||
4531 | @item @var{op}= | |
1041a570 RP |
4532 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
4533 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
4534 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
4535 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
4536 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
4537 | |
4538 | @item ?: | |
4539 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
4540 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
4541 | integral type. | |
4542 | ||
4543 | @item || | |
1041a570 | 4544 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4545 | |
4546 | @item && | |
1041a570 | 4547 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4548 | |
4549 | @item | | |
1041a570 | 4550 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4551 | |
4552 | @item ^ | |
1041a570 | 4553 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
4554 | |
4555 | @item & | |
1041a570 | 4556 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4557 | |
4558 | @item ==@r{, }!= | |
4559 | Equality and inequality. Defined on scalar types. The value of these | |
4560 | expressions is 0 for false and non-zero for true. | |
4561 | ||
4562 | @item <@r{, }>@r{, }<=@r{, }>= | |
4563 | Less than, greater than, less than or equal, greater than or equal. | |
4564 | Defined on scalar types. The value of these expressions is 0 for false | |
4565 | and non-zero for true. | |
4566 | ||
4567 | @item <<@r{, }>> | |
4568 | left shift, and right shift. Defined on integral types. | |
4569 | ||
e251e767 | 4570 | @item @@ |
1041a570 | 4571 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
4572 | |
4573 | @item +@r{, }- | |
4574 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 4575 | pointer types. |
c2bbbb22 RP |
4576 | |
4577 | @item *@r{, }/@r{, }% | |
4578 | Multiplication, division, and modulus. Multiplication and division are | |
4579 | defined on integral and floating-point types. Modulus is defined on | |
4580 | integral types. | |
4581 | ||
4582 | @item ++@r{, }-- | |
4583 | Increment and decrement. When appearing before a variable, the | |
4584 | operation is performed before the variable is used in an expression; | |
4585 | when appearing after it, the variable's value is used before the | |
4586 | operation takes place. | |
4587 | ||
4588 | @item * | |
4589 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
4590 | @code{++}. | |
4591 | ||
4592 | @item & | |
4593 | Address operator. Defined on variables. Same precedence as @code{++}. | |
4594 | ||
4595 | @item - | |
4596 | Negative. Defined on integral and floating-point types. Same | |
4597 | precedence as @code{++}. | |
4598 | ||
4599 | @item ! | |
4600 | Logical negation. Defined on integral types. Same precedence as | |
4601 | @code{++}. | |
4602 | ||
4603 | @item ~ | |
4604 | Bitwise complement operator. Defined on integral types. Same precedence as | |
4605 | @code{++}. | |
4606 | ||
4607 | @item .@r{, }-> | |
4608 | Structure member, and pointer-to-structure member. For convenience, | |
4609 | _GDBN__ regards the two as equivalent, choosing whether to dereference a | |
e251e767 | 4610 | pointer based on the stored type information. |
c2bbbb22 RP |
4611 | Defined on @code{struct}s and @code{union}s. |
4612 | ||
4613 | @item [] | |
4614 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
4615 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
4616 | ||
4617 | @item () | |
4618 | Function parameter list. Same precedence as @code{->}. | |
4619 | ||
4620 | @item :: | |
4621 | C++ scope resolution operator. Defined on | |
4622 | @code{struct}, @code{union}, and @code{class} types. | |
4623 | ||
4624 | @item :: | |
1041a570 RP |
4625 | The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}). Same precedence as |
4626 | @code{::}, above._1__ | |
c2bbbb22 RP |
4627 | @end table |
4628 | ||
4629 | @cindex C and C++ constants | |
4630 | @node C Constants, Cplusplus expressions, C Operators, C | |
4631 | @subsubsection C and C++ Constants | |
4632 | ||
4633 | _GDBN__ allows you to express the constants of C and C++ in the | |
4634 | following ways: | |
4635 | ||
4636 | @itemize @bullet | |
c2bbbb22 RP |
4637 | @item |
4638 | Integer constants are a sequence of digits. Octal constants are | |
4639 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 4640 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
4641 | @samp{l}, specifying that the constant should be treated as a |
4642 | @code{long} value. | |
4643 | ||
4644 | @item | |
4645 | Floating point constants are a sequence of digits, followed by a decimal | |
4646 | point, followed by a sequence of digits, and optionally followed by an | |
4647 | exponent. An exponent is of the form: | |
4648 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
4649 | sequence of digits. The @samp{+} is optional for positive exponents. | |
4650 | ||
4651 | @item | |
4652 | Enumerated constants consist of enumerated identifiers, or their | |
4653 | integral equivalents. | |
4654 | ||
4655 | @item | |
4656 | Character constants are a single character surrounded by single quotes | |
4657 | (@code{'}), or a number---the ordinal value of the corresponding character | |
4658 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
4659 | be represented by a letter or by @dfn{escape sequences}, which are of | |
4660 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
4661 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
4662 | @samp{@var{x}} is a predefined special character---for example, | |
4663 | @samp{\n} for newline. | |
4664 | ||
4665 | @item | |
4666 | String constants are a sequence of character constants surrounded | |
4667 | by double quotes (@code{"}). | |
4668 | ||
4669 | @item | |
4670 | Pointer constants are an integral value. | |
c2bbbb22 RP |
4671 | @end itemize |
4672 | ||
c2bbbb22 RP |
4673 | @node Cplusplus expressions, C Defaults, C Constants, C |
4674 | @subsubsection C++ Expressions | |
b80282d5 RP |
4675 | |
4676 | @cindex expressions in C++ | |
c2bbbb22 RP |
4677 | _GDBN__'s expression handling has the following extensions to |
4678 | interpret a significant subset of C++ expressions: | |
b80282d5 RP |
4679 | |
4680 | @enumerate | |
4681 | ||
4682 | @cindex member functions | |
e251e767 | 4683 | @item |
b80282d5 | 4684 | Member function calls are allowed; you can use expressions like |
1041a570 | 4685 | |
b80282d5 RP |
4686 | @example |
4687 | count = aml->GetOriginal(x, y) | |
4688 | @end example | |
4689 | ||
4690 | @kindex this | |
4691 | @cindex namespace in C++ | |
e251e767 | 4692 | @item |
b80282d5 RP |
4693 | While a member function is active (in the selected stack frame), your |
4694 | expressions have the same namespace available as the member function; | |
4695 | that is, _GDBN__ allows implicit references to the class instance | |
4696 | pointer @code{this} following the same rules as C++. | |
4697 | ||
4698 | @cindex call overloaded functions | |
4699 | @cindex type conversions in C++ | |
e251e767 | 4700 | @item |
b80282d5 RP |
4701 | You can call overloaded functions; _GDBN__ will resolve the function |
4702 | call to the right definition, with one restriction---you must use | |
4703 | arguments of the type required by the function that you want to call. | |
4704 | _GDBN__ will not perform conversions requiring constructors or | |
4705 | user-defined type operators. | |
4706 | ||
4707 | @cindex reference declarations | |
4708 | @item | |
4709 | _GDBN__ understands variables declared as C++ references; you can use them in | |
4710 | expressions just as you do in C++ source---they are automatically | |
e251e767 | 4711 | dereferenced. |
b80282d5 RP |
4712 | |
4713 | In the parameter list shown when _GDBN__ displays a frame, the values of | |
4714 | reference variables are not displayed (unlike other variables); this | |
4715 | avoids clutter, since references are often used for large structures. | |
4716 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 4717 | you have specified @samp{set print address off}. |
b80282d5 RP |
4718 | |
4719 | @item | |
4720 | _GDBN__ supports the C++ name resolution operator @code{::}---your | |
c2bbbb22 RP |
4721 | expressions can use it just as expressions in your program do. Since |
4722 | one scope may be defined in another, you can use @code{::} repeatedly if | |
4723 | necessary, for example in an expression like | |
4724 | @samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows | |
4725 | resolving name scope by reference to source files, in both C and C++ | |
1041a570 | 4726 | debugging (@pxref{Variables, ,Program Variables}). |
b80282d5 RP |
4727 | @end enumerate |
4728 | ||
c2bbbb22 RP |
4729 | @node C Defaults, C Checks, Cplusplus expressions, C |
4730 | @subsubsection C and C++ Defaults | |
4731 | @cindex C and C++ defaults | |
4732 | ||
e251e767 RP |
4733 | If you allow _GDBN__ to set type and range checking automatically, they |
4734 | both default to @code{off} whenever the working language changes to | |
c2bbbb22 RP |
4735 | C/C++. This happens regardless of whether you, or _GDBN__, |
4736 | selected the working language. | |
4737 | ||
4738 | If you allow _GDBN__ to set the language automatically, it sets the | |
4739 | working language to C/C++ on entering code compiled from a source file | |
4740 | whose name ends with @file{.c} or @file{.cc}. | |
1041a570 | 4741 | @xref{Automatically, ,Having _GDBN__ infer the source language}, for |
c2bbbb22 RP |
4742 | further details. |
4743 | ||
4744 | @node C Checks, Debugging C, C Defaults, C | |
4745 | @subsubsection C and C++ Type and Range Checks | |
4746 | @cindex C and C++ checks | |
4747 | ||
4748 | @quotation | |
4749 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
4750 | range checking. | |
4751 | @end quotation | |
4752 | @c FIXME remove warning when type/range checks added | |
4753 | ||
4754 | By default, when _GDBN__ parses C or C++ expressions, type checking | |
4755 | is not used. However, if you turn type checking on, _GDBN__ will | |
4756 | consider two variables type equivalent if: | |
4757 | ||
4758 | @itemize @bullet | |
4759 | @item | |
4760 | The two variables are structured and have the same structure, union, or | |
4761 | enumerated tag. | |
4762 | ||
e251e767 | 4763 | @item |
c2bbbb22 RP |
4764 | Two two variables have the same type name, or types that have been |
4765 | declared equivalent through @code{typedef}. | |
4766 | ||
4767 | @ignore | |
4768 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
4769 | @c FIXME--beers? | |
4770 | @item | |
4771 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
4772 | declared in the same declaration. (Note: this may not be true for all C | |
4773 | compilers.) | |
4774 | @end ignore | |
c2bbbb22 RP |
4775 | @end itemize |
4776 | ||
4777 | Range checking, if turned on, is done on mathematical operations. Array | |
4778 | indices are not checked, since they are often used to index a pointer | |
4779 | that is not itself an array. | |
4780 | ||
4781 | @node Debugging C, Debugging C plus plus, C Checks, C | |
4782 | @subsubsection _GDBN__ and C | |
4783 | ||
4784 | The @code{set print union} and @code{show print union} commands apply to | |
4785 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
4786 | inside a @code{struct} or @code{class} will also be printed. | |
4787 | Otherwise, it will appear as @samp{@{...@}}. | |
4788 | ||
4789 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
1041a570 | 4790 | with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
4791 | |
4792 | @node Debugging C plus plus, , Debugging C, C | |
4793 | @subsubsection _GDBN__ Commands for C++ | |
b80282d5 RP |
4794 | |
4795 | @cindex commands for C++ | |
4796 | Some _GDBN__ commands are particularly useful with C++, and some are | |
4797 | designed specifically for use with C++. Here is a summary: | |
4798 | ||
4799 | @table @code | |
4800 | @cindex break in overloaded functions | |
4801 | @item @r{breakpoint menus} | |
4802 | When you want a breakpoint in a function whose name is overloaded, | |
4803 | _GDBN__'s breakpoint menus help you specify which function definition | |
4804 | you want. @xref{Breakpoint Menus}. | |
4805 | ||
4806 | @cindex overloading in C++ | |
4807 | @item rbreak @var{regex} | |
4808 | Setting breakpoints using regular expressions is helpful for setting | |
4809 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 4810 | classes. |
29a2b744 | 4811 | @xref{Set Breaks, ,Setting Breakpoints}. |
b80282d5 RP |
4812 | |
4813 | @cindex C++ exception handling | |
4814 | @item catch @var{exceptions} | |
4815 | @itemx info catch | |
29a2b744 | 4816 | Debug C++ exception handling using these commands. @xref{Exception |
1041a570 | 4817 | Handling, ,Breakpoints and Exceptions}. |
b80282d5 | 4818 | |
e251e767 | 4819 | @cindex inheritance |
b80282d5 RP |
4820 | @item ptype @var{typename} |
4821 | Print inheritance relationships as well as other information for type | |
e251e767 | 4822 | @var{typename}. |
1041a570 | 4823 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
4824 | |
4825 | @cindex C++ symbol display | |
4826 | @item set print demangle | |
4827 | @itemx show print demangle | |
4828 | @itemx set print asm-demangle | |
4829 | @itemx show print asm-demangle | |
4830 | Control whether C++ symbols display in their source form, both when | |
4831 | displaying code as C++ source and when displaying disassemblies. | |
1041a570 | 4832 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
4833 | |
4834 | @item set print object | |
4835 | @itemx show print object | |
e251e767 | 4836 | Choose whether to print derived (actual) or declared types of objects. |
1041a570 | 4837 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
4838 | |
4839 | @item set print vtbl | |
4840 | @itemx show print vtbl | |
4841 | Control the format for printing virtual function tables. | |
1041a570 | 4842 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
4843 | @end table |
4844 | ||
c2bbbb22 RP |
4845 | @node Modula-2, , C, Support |
4846 | @subsection Modula-2 | |
4847 | @cindex Modula-2 | |
4848 | ||
4849 | The extensions made to _GDBN__ to support Modula-2 support output | |
4850 | from the GNU Modula-2 compiler (which is currently being developed). | |
4851 | Other Modula-2 compilers are not currently supported, and attempting to | |
4852 | debug executables produced by them will most likely result in an error | |
4853 | as _GDBN__ reads in the executable's symbol table. | |
4854 | ||
4855 | @cindex expressions in Modula-2 | |
4856 | @menu | |
4857 | * M2 Operators:: Built-in operators | |
29a2b744 | 4858 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
4859 | * M2 Constants:: Modula-2 Constants |
4860 | * M2 Defaults:: Default settings for Modula-2 | |
4861 | * Deviations:: Deviations from standard Modula-2 | |
4862 | * M2 Checks:: Modula-2 Type and Range Checks | |
4863 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
4864 | * GDB/M2:: _GDBN__ and Modula-2 | |
4865 | @end menu | |
4866 | ||
29a2b744 | 4867 | @node M2 Operators, Built-In Func/Proc, Modula-2, Modula-2 |
c2bbbb22 RP |
4868 | @subsubsection Operators |
4869 | @cindex Modula-2 operators | |
4870 | ||
4871 | Operators must be defined on values of specific types. For instance, | |
4872 | @code{+} is defined on numbers, but not on structures. Operators are | |
4873 | often defined on groups of types. For the purposes of Modula-2, the | |
4874 | following definitions hold: | |
4875 | ||
4876 | @itemize @bullet | |
4877 | ||
4878 | @item | |
4879 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
4880 | their subranges. | |
4881 | ||
4882 | @item | |
4883 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
4884 | ||
4885 | @item | |
4886 | @emph{Floating-point types} consist of @code{REAL}. | |
4887 | ||
4888 | @item | |
4889 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
4890 | @var{type}}. | |
4891 | ||
4892 | @item | |
4893 | @emph{Scalar types} consist of all of the above. | |
4894 | ||
4895 | @item | |
4896 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
4897 | ||
4898 | @item | |
4899 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
4900 | @end itemize |
4901 | ||
4902 | @noindent | |
4903 | The following operators are supported, and appear in order of | |
4904 | increasing precedence: | |
4905 | ||
4906 | @table @code | |
c2bbbb22 RP |
4907 | @item , |
4908 | Function argument or array index separator. | |
1041a570 | 4909 | _0__ |
c2bbbb22 RP |
4910 | @item := |
4911 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
4912 | @var{value}. | |
4913 | ||
4914 | @item <@r{, }> | |
4915 | Less than, greater than on integral, floating-point, or enumerated | |
4916 | types. | |
4917 | ||
4918 | @item <=@r{, }>= | |
4919 | Less than, greater than, less than or equal to, greater than or equal to | |
4920 | on integral, floating-point and enumerated types, or set inclusion on | |
4921 | set types. Same precedence as @code{<}. | |
4922 | ||
4923 | @item =@r{, }<>@r{, }# | |
4924 | Equality and two ways of expressing inequality, valid on scalar types. | |
4925 | Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is | |
4926 | available for inequality, since @code{#} conflicts with the script | |
4927 | comment character. | |
4928 | ||
4929 | @item IN | |
4930 | Set membership. Defined on set types and the types of their members. | |
4931 | Same precedence as @code{<}. | |
4932 | ||
4933 | @item OR | |
4934 | Boolean disjunction. Defined on boolean types. | |
4935 | ||
4936 | @item AND@r{, }& | |
4937 | Boolean conjuction. Defined on boolean types. | |
4938 | ||
4939 | @item @@ | |
1041a570 | 4940 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
4941 | |
4942 | @item +@r{, }- | |
4943 | Addition and subtraction on integral and floating-point types, or union | |
4944 | and difference on set types. | |
4945 | ||
4946 | @item * | |
4947 | Multiplication on integral and floating-point types, or set intersection | |
4948 | on set types. | |
4949 | ||
4950 | @item / | |
4951 | Division on floating-point types, or symmetric set difference on set | |
4952 | types. Same precedence as @code{*}. | |
4953 | ||
4954 | @item DIV@r{, }MOD | |
4955 | Integer division and remainder. Defined on integral types. Same | |
4956 | precedence as @code{*}. | |
4957 | ||
4958 | @item - | |
4959 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
4960 | ||
4961 | @item ^ | |
e251e767 | 4962 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
4963 | |
4964 | @item NOT | |
4965 | Boolean negation. Defined on boolean types. Same precedence as | |
4966 | @code{^}. | |
4967 | ||
4968 | @item . | |
4969 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
4970 | precedence as @code{^}. | |
4971 | ||
4972 | @item [] | |
4973 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
4974 | ||
4975 | @item () | |
4976 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
4977 | as @code{^}. | |
4978 | ||
4979 | @item ::@r{, }. | |
4980 | _GDBN__ and Modula-2 scope operators. | |
c2bbbb22 RP |
4981 | @end table |
4982 | ||
4983 | @quotation | |
4984 | @emph{Warning:} Sets and their operations are not yet supported, so _GDBN__ | |
4985 | will treat the use of the operator @code{IN}, or the use of operators | |
4986 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
4987 | @code{<=}, and @code{>=} on sets as an error. | |
4988 | @end quotation | |
4989 | _1__ | |
29a2b744 RP |
4990 | @cindex Modula-2 built-ins |
4991 | @node Built-In Func/Proc, M2 Constants, M2 Operators, Modula-2 | |
c2bbbb22 RP |
4992 | @subsubsection Built-in Functions and Procedures |
4993 | ||
4994 | Modula-2 also makes available several built-in procedures and functions. | |
4995 | In describing these, the following metavariables are used: | |
4996 | ||
4997 | @table @var | |
4998 | ||
4999 | @item a | |
5000 | represents an @code{ARRAY} variable. | |
5001 | ||
5002 | @item c | |
5003 | represents a @code{CHAR} constant or variable. | |
5004 | ||
5005 | @item i | |
5006 | represents a variable or constant of integral type. | |
5007 | ||
5008 | @item m | |
5009 | represents an identifier that belongs to a set. Generally used in the | |
5010 | same function with the metavariable @var{s}. The type of @var{s} should | |
5011 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
5012 | ||
5013 | @item n | |
5014 | represents a variable or constant of integral or floating-point type. | |
5015 | ||
5016 | @item r | |
5017 | represents a variable or constant of floating-point type. | |
5018 | ||
5019 | @item t | |
5020 | represents a type. | |
5021 | ||
5022 | @item v | |
5023 | represents a variable. | |
5024 | ||
5025 | @item x | |
5026 | represents a variable or constant of one of many types. See the | |
5027 | explanation of the function for details. | |
c2bbbb22 RP |
5028 | @end table |
5029 | ||
5030 | All Modula-2 built-in procedures also return a result, described below. | |
5031 | ||
5032 | @table @code | |
5033 | @item ABS(@var{n}) | |
5034 | Returns the absolute value of @var{n}. | |
5035 | ||
5036 | @item CAP(@var{c}) | |
5037 | If @var{c} is a lower case letter, it returns its upper case | |
5038 | equivalent, otherwise it returns its argument | |
5039 | ||
5040 | @item CHR(@var{i}) | |
5041 | Returns the character whose ordinal value is @var{i}. | |
5042 | ||
5043 | @item DEC(@var{v}) | |
5044 | Decrements the value in the variable @var{v}. Returns the new value. | |
5045 | ||
5046 | @item DEC(@var{v},@var{i}) | |
5047 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5048 | new value. | |
5049 | ||
5050 | @item EXCL(@var{m},@var{s}) | |
5051 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5052 | set. | |
5053 | ||
5054 | @item FLOAT(@var{i}) | |
5055 | Returns the floating point equivalent of the integer @var{i}. | |
5056 | ||
5057 | @item HIGH(@var{a}) | |
5058 | Returns the index of the last member of @var{a}. | |
5059 | ||
5060 | @item INC(@var{v}) | |
5061 | Increments the value in the variable @var{v}. Returns the new value. | |
5062 | ||
5063 | @item INC(@var{v},@var{i}) | |
5064 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5065 | new value. | |
5066 | ||
5067 | @item INCL(@var{m},@var{s}) | |
5068 | Adds the element @var{m} to the set @var{s} if it is not already | |
5069 | there. Returns the new set. | |
5070 | ||
5071 | @item MAX(@var{t}) | |
5072 | Returns the maximum value of the type @var{t}. | |
5073 | ||
5074 | @item MIN(@var{t}) | |
5075 | Returns the minimum value of the type @var{t}. | |
5076 | ||
5077 | @item ODD(@var{i}) | |
5078 | Returns boolean TRUE if @var{i} is an odd number. | |
5079 | ||
5080 | @item ORD(@var{x}) | |
5081 | Returns the ordinal value of its argument. For example, the ordinal | |
5082 | value of a character is its ASCII value (on machines supporting the | |
5083 | ASCII character set). @var{x} must be of an ordered type, which include | |
5084 | integral, character and enumerated types. | |
5085 | ||
5086 | @item SIZE(@var{x}) | |
5087 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5088 | ||
5089 | @item TRUNC(@var{r}) | |
5090 | Returns the integral part of @var{r}. | |
5091 | ||
5092 | @item VAL(@var{t},@var{i}) | |
5093 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5094 | @end table | |
5095 | ||
5096 | @quotation | |
5097 | @emph{Warning:} Sets and their operations are not yet supported, so | |
5098 | _GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as | |
5099 | an error. | |
5100 | @end quotation | |
5101 | ||
5102 | @cindex Modula-2 constants | |
29a2b744 | 5103 | @node M2 Constants, M2 Defaults, Built-In Func/Proc, Modula-2 |
c2bbbb22 RP |
5104 | @subsubsection Constants |
5105 | ||
5106 | _GDBN__ allows you to express the constants of Modula-2 in the following | |
5107 | ways: | |
5108 | ||
5109 | @itemize @bullet | |
5110 | ||
5111 | @item | |
5112 | Integer constants are simply a sequence of digits. When used in an | |
5113 | expression, a constant is interpreted to be type-compatible with the | |
5114 | rest of the expression. Hexadecimal integers are specified by a | |
5115 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5116 | ||
5117 | @item | |
5118 | Floating point constants appear as a sequence of digits, followed by a | |
5119 | decimal point and another sequence of digits. An optional exponent can | |
5120 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5121 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5122 | digits of the floating point constant must be valid decimal (base 10) | |
5123 | digits. | |
5124 | ||
5125 | @item | |
5126 | Character constants consist of a single character enclosed by a pair of | |
5127 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5128 | also be expressed by their ordinal value (their ASCII value, usually) | |
5129 | followed by a @samp{C}. | |
5130 | ||
5131 | @item | |
1041a570 RP |
5132 | String constants consist of a sequence of characters enclosed by a |
5133 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5134 | Escape sequences in the style of C are also allowed. @xref{C | |
5135 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
5136 | sequences. | |
c2bbbb22 RP |
5137 | |
5138 | @item | |
5139 | Enumerated constants consist of an enumerated identifier. | |
5140 | ||
5141 | @item | |
5142 | Boolean constants consist of the identifiers @code{TRUE} and | |
5143 | @code{FALSE}. | |
5144 | ||
5145 | @item | |
5146 | Pointer constants consist of integral values only. | |
5147 | ||
5148 | @item | |
5149 | Set constants are not yet supported. | |
c2bbbb22 RP |
5150 | @end itemize |
5151 | ||
5152 | @node M2 Defaults, Deviations, M2 Constants, Modula-2 | |
5153 | @subsubsection Modula-2 Defaults | |
5154 | @cindex Modula-2 defaults | |
5155 | ||
e251e767 RP |
5156 | If type and range checking are set automatically by _GDBN__, they |
5157 | both default to @code{on} whenever the working language changes to | |
c2bbbb22 RP |
5158 | Modula-2. This happens regardless of whether you, or _GDBN__, |
5159 | selected the working language. | |
5160 | ||
5161 | If you allow _GDBN__ to set the language automatically, then entering | |
5162 | code compiled from a file whose name ends with @file{.mod} will set the | |
1041a570 | 5163 | working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set |
c2bbbb22 RP |
5164 | the language automatically}, for further details. |
5165 | ||
5166 | @node Deviations, M2 Checks, M2 Defaults, Modula-2 | |
5167 | @subsubsection Deviations from Standard Modula-2 | |
5168 | @cindex Modula-2, deviations from | |
5169 | ||
5170 | A few changes have been made to make Modula-2 programs easier to debug. | |
5171 | This is done primarily via loosening its type strictness: | |
5172 | ||
5173 | @itemize @bullet | |
e251e767 | 5174 | @item |
c2bbbb22 RP |
5175 | Unlike in standard Modula-2, pointer constants can be formed by |
5176 | integers. This allows you to modify pointer variables during | |
5177 | debugging. (In standard Modula-2, the actual address contained in a | |
5178 | pointer variable is hidden from you; it can only be modified | |
5179 | through direct assignment to another pointer variable or expression that | |
5180 | returned a pointer.) | |
5181 | ||
e251e767 | 5182 | @item |
c2bbbb22 RP |
5183 | C escape sequences can be used in strings and characters to represent |
5184 | non-printable characters. _GDBN__ will print out strings with these | |
5185 | escape sequences embedded. Single non-printable characters are | |
5186 | printed using the @samp{CHR(@var{nnn})} format. | |
5187 | ||
5188 | @item | |
5189 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5190 | argument. | |
5191 | ||
5192 | @item | |
29a2b744 | 5193 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 5194 | @end itemize |
c2bbbb22 RP |
5195 | |
5196 | @node M2 Checks, M2 Scope, Deviations, Modula-2 | |
5197 | @subsubsection Modula-2 Type and Range Checks | |
5198 | @cindex Modula-2 checks | |
5199 | ||
5200 | @quotation | |
5201 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5202 | range checking. | |
5203 | @end quotation | |
5204 | @c FIXME remove warning when type/range checks added | |
5205 | ||
5206 | _GDBN__ considers two Modula-2 variables type equivalent if: | |
5207 | ||
5208 | @itemize @bullet | |
5209 | @item | |
5210 | They are of types that have been declared equivalent via a @code{TYPE | |
5211 | @var{t1} = @var{t2}} statement | |
5212 | ||
5213 | @item | |
5214 | They have been declared on the same line. (Note: This is true of the | |
5215 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
5216 | @end itemize |
5217 | ||
5218 | As long as type checking is enabled, any attempt to combine variables | |
5219 | whose types are not equivalent is an error. | |
5220 | ||
5221 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 5222 | index bounds, and all built-in functions and procedures. |
c2bbbb22 RP |
5223 | |
5224 | @node M2 Scope, GDB/M2, M2 Checks, Modula-2 | |
5225 | @subsubsection The scope operators @code{::} and @code{.} | |
5226 | @cindex scope | |
5227 | @kindex . | |
1041a570 RP |
5228 | @kindex colon, doubled as scope operator |
5229 | @ifinfo | |
5230 | @kindex colon-colon | |
5231 | @c Info cannot handoe :: but TeX can. | |
5232 | @end ifinfo | |
5233 | @iftex | |
c2bbbb22 | 5234 | @kindex :: |
1041a570 | 5235 | @end iftex |
c2bbbb22 RP |
5236 | |
5237 | There are a few subtle differences between the Modula-2 scope operator | |
5238 | (@code{.}) and the _GDBN__ scope operator (@code{::}). The two have | |
5239 | similar syntax: | |
5240 | ||
5241 | @example | |
5242 | ||
5243 | @var{module} . @var{id} | |
5244 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
5245 | @end example |
5246 | ||
5247 | @noindent | |
5248 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
5249 | @var{module} the name of a module, and @var{id} is any declared |
5250 | identifier within your program, except another module. | |
c2bbbb22 RP |
5251 | |
5252 | Using the @code{::} operator makes _GDBN__ search the scope | |
5253 | specified by @var{scope} for the identifier @var{id}. If it is not | |
5254 | found in the specified scope, then _GDBN__ will search all scopes | |
5255 | enclosing the one specified by @var{scope}. | |
5256 | ||
5257 | Using the @code{.} operator makes _GDBN__ search the current scope for | |
5258 | the identifier specified by @var{id} that was imported from the | |
5259 | definition module specified by @var{module}. With this operator, it is | |
5260 | an error if the identifier @var{id} was not imported from definition | |
5261 | module @var{module}, or if @var{id} is not an identifier in | |
5262 | @var{module}. | |
5263 | ||
5264 | @node GDB/M2, , M2 Scope, Modula-2 | |
5265 | @subsubsection _GDBN__ and Modula-2 | |
5266 | ||
5267 | Some _GDBN__ commands have little use when debugging Modula-2 programs. | |
5268 | Five subcommands of @code{set print} and @code{show print} apply | |
5269 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5270 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
5271 | apply to C++, and the last to C's @code{union} type, which has no direct | |
5272 | analogue in Modula-2. | |
5273 | ||
1041a570 | 5274 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
5275 | while using any language, is not useful with Modula-2. Its |
5276 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5277 | created in Modula-2 as they can in C or C++. However, because an | |
5278 | address can be specified by an integral constant, the construct | |
1041a570 | 5279 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
5280 | _0__ |
5281 | @cindex @code{#} in Modula-2 | |
5282 | In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is | |
5283 | interpreted as the beginning of a comment. Use @code{<>} instead. | |
5284 | _1__ | |
c2bbbb22 | 5285 | @node Symbols, Altering, Languages, Top |
70b88761 RP |
5286 | @chapter Examining the Symbol Table |
5287 | ||
5288 | The commands described in this section allow you to inquire about the | |
5289 | symbols (names of variables, functions and types) defined in your | |
5290 | program. This information is inherent in the text of your program and | |
29a2b744 | 5291 | does not change as your program executes. _GDBN__ finds it in your |
e251e767 | 5292 | program's symbol table, in the file indicated when you started _GDBN__ |
1041a570 RP |
5293 | (@pxref{File Options, ,Choosing Files}), or by one of the |
5294 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
70b88761 RP |
5295 | |
5296 | @table @code | |
5297 | @item info address @var{symbol} | |
5298 | @kindex info address | |
5299 | Describe where the data for @var{symbol} is stored. For a register | |
5300 | variable, this says which register it is kept in. For a non-register | |
5301 | local variable, this prints the stack-frame offset at which the variable | |
5302 | is always stored. | |
5303 | ||
5304 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5305 | at all for a register variables, and for a stack local variable prints | |
5306 | the exact address of the current instantiation of the variable. | |
5307 | ||
5308 | @item whatis @var{exp} | |
5309 | @kindex whatis | |
5310 | Print the data type of expression @var{exp}. @var{exp} is not | |
5311 | actually evaluated, and any side-effecting operations (such as | |
5312 | assignments or function calls) inside it do not take place. | |
1041a570 | 5313 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
5314 | |
5315 | @item whatis | |
5316 | Print the data type of @code{$}, the last value in the value history. | |
5317 | ||
5318 | @item ptype @var{typename} | |
5319 | @kindex ptype | |
5320 | Print a description of data type @var{typename}. @var{typename} may be | |
5321 | the name of a type, or for C code it may have the form | |
5322 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 5323 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
5324 | |
5325 | @item ptype @var{exp} | |
e0dacfd1 | 5326 | @itemx ptype |
70b88761 | 5327 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 RP |
5328 | differs from @code{whatis} by printing a detailed description, instead |
5329 | of just the name of the type. For example, if your program declares a | |
5330 | variable as | |
5331 | ||
70b88761 RP |
5332 | @example |
5333 | struct complex @{double real; double imag;@} v; | |
5334 | @end example | |
1041a570 | 5335 | |
70b88761 RP |
5336 | @noindent |
5337 | compare the output of the two commands: | |
1041a570 | 5338 | |
70b88761 | 5339 | @example |
1041a570 | 5340 | @group |
70b88761 RP |
5341 | (_GDBP__) whatis v |
5342 | type = struct complex | |
5343 | (_GDBP__) ptype v | |
5344 | type = struct complex @{ | |
5345 | double real; | |
5346 | double imag; | |
5347 | @} | |
1041a570 | 5348 | @end group |
70b88761 | 5349 | @end example |
1041a570 | 5350 | |
e0dacfd1 RP |
5351 | @noindent |
5352 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5353 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
5354 | |
5355 | @item info types @var{regexp} | |
5356 | @itemx info types | |
e251e767 | 5357 | @kindex info types |
70b88761 RP |
5358 | Print a brief description of all types whose name matches @var{regexp} |
5359 | (or all types in your program, if you supply no argument). Each | |
5360 | complete typename is matched as though it were a complete line; thus, | |
5361 | @samp{i type value} gives information on all types in your program whose | |
5362 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5363 | information only on types whose complete name is @code{value}. | |
5364 | ||
5365 | This command differs from @code{ptype} in two ways: first, like | |
5366 | @code{whatis}, it does not print a detailed description; second, it | |
5367 | lists all source files where a type is defined. | |
5368 | ||
5369 | @item info source | |
5370 | @kindex info source | |
5371 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
5372 | the function containing the current point of execution---and the language |
5373 | it was written in. | |
70b88761 RP |
5374 | |
5375 | @item info sources | |
5376 | @kindex info sources | |
29a2b744 | 5377 | Print the names of all source files in your program for which there is |
b80282d5 RP |
5378 | debugging information, organized into two lists: files whose symbols |
5379 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
5380 | |
5381 | @item info functions | |
5382 | @kindex info functions | |
5383 | Print the names and data types of all defined functions. | |
5384 | ||
5385 | @item info functions @var{regexp} | |
5386 | Print the names and data types of all defined functions | |
5387 | whose names contain a match for regular expression @var{regexp}. | |
5388 | Thus, @samp{info fun step} finds all functions whose names | |
5389 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5390 | start with @code{step}. | |
5391 | ||
5392 | @item info variables | |
5393 | @kindex info variables | |
5394 | Print the names and data types of all variables that are declared | |
5395 | outside of functions (i.e., excluding local variables). | |
5396 | ||
5397 | @item info variables @var{regexp} | |
5398 | Print the names and data types of all variables (except for local | |
5399 | variables) whose names contain a match for regular expression | |
5400 | @var{regexp}. | |
5401 | ||
70b88761 RP |
5402 | @ignore |
5403 | This was never implemented. | |
5404 | @item info methods | |
5405 | @itemx info methods @var{regexp} | |
5406 | @kindex info methods | |
5407 | The @code{info methods} command permits the user to examine all defined | |
5408 | methods within C++ program, or (with the @var{regexp} argument) a | |
5409 | specific set of methods found in the various C++ classes. Many | |
5410 | C++ classes provide a large number of methods. Thus, the output | |
5411 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5412 | @code{info-methods} command filters the methods, printing only those | |
5413 | which match the regular-expression @var{regexp}. | |
5414 | @end ignore | |
5415 | ||
5416 | @item printsyms @var{filename} | |
440d9834 | 5417 | @itemx printpsyms @var{filename} |
70b88761 | 5418 | @kindex printsyms |
440d9834 RP |
5419 | @cindex symbol dump |
5420 | @kindex printsyms | |
5421 | @cindex partial symbol dump | |
5422 | Write a dump of debugging symbol data into the file @var{filename}. | |
e0dacfd1 RP |
5423 | These commands are used to debug the _GDBN__ symbol-reading code. Only |
5424 | symbols with debugging data are included. If you use @code{printsyms}, | |
5425 | _GDBN__ includes all the symbols for which it has already collected full | |
5426 | details: that is, @var{filename} reflects symbols for only those files | |
5427 | whose symbols _GDBN__ has read. You can use the command @code{info | |
5428 | sources} to find out which files these are. If you use | |
5429 | @code{printpsyms}, the dump also shows information about symbols that | |
5430 | _GDBN__ only knows partially---that is, symbols defined in files that | |
5431 | _GDBN__ has skimmed, but not yet read completely. The description of | |
5432 | @code{symbol-file} describes how _GDBN__ reads symbols; both commands | |
29a2b744 | 5433 | are described under @ref{Files, ,Commands to Specify Files}. |
70b88761 RP |
5434 | @end table |
5435 | ||
5436 | @node Altering, _GDBN__ Files, Symbols, Top | |
5437 | @chapter Altering Execution | |
5438 | ||
29a2b744 | 5439 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
5440 | find out for certain whether correcting the apparent error would lead to |
5441 | correct results in the rest of the run. You can find the answer by | |
5442 | experiment, using the _GDBN__ features for altering execution of the | |
5443 | program. | |
5444 | ||
5445 | For example, you can store new values into variables or memory | |
29a2b744 | 5446 | locations, give your program a signal, restart it at a different address, |
70b88761 RP |
5447 | or even return prematurely from a function to its caller. |
5448 | ||
5449 | @menu | |
b80282d5 RP |
5450 | * Assignment:: Assignment to Variables |
5451 | * Jumping:: Continuing at a Different Address | |
29a2b744 | 5452 | * Signaling:: Giving your program a Signal |
b80282d5 RP |
5453 | * Returning:: Returning from a Function |
5454 | * Calling:: Calling your Program's Functions | |
c338a2fd | 5455 | * Patching:: Patching your Program |
70b88761 RP |
5456 | @end menu |
5457 | ||
5458 | @node Assignment, Jumping, Altering, Altering | |
5459 | @section Assignment to Variables | |
5460 | ||
5461 | @cindex assignment | |
5462 | @cindex setting variables | |
5463 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 5464 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
5465 | |
5466 | @example | |
5467 | print x=4 | |
5468 | @end example | |
5469 | ||
5470 | @noindent | |
1041a570 RP |
5471 | stores the value 4 into the variable @code{x}, and then prints the |
5472 | value of the assignment expression (which is 4). @xref{Languages, | |
5473 | ,Using _GDBN__ with Different Languages}, for more information on | |
5474 | operators in supported languages. | |
70b88761 | 5475 | |
70b88761 RP |
5476 | @kindex set variable |
5477 | @cindex variables, setting | |
5478 | If you are not interested in seeing the value of the assignment, use the | |
5479 | @code{set} command instead of the @code{print} command. @code{set} is | |
5480 | really the same as @code{print} except that the expression's value is not | |
1041a570 | 5481 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The |
70b88761 RP |
5482 | expression is evaluated only for its effects. |
5483 | ||
5484 | If the beginning of the argument string of the @code{set} command | |
5485 | appears identical to a @code{set} subcommand, use the @code{set | |
5486 | variable} command instead of just @code{set}. This command is identical | |
5487 | to @code{set} except for its lack of subcommands. For example, a | |
5488 | program might well have a variable @code{width}---which leads to | |
5489 | an error if we try to set a new value with just @samp{set width=13}, as | |
1041a570 RP |
5490 | we might if @code{set width} did not happen to be a _GDBN__ command: |
5491 | ||
70b88761 RP |
5492 | @example |
5493 | (_GDBP__) whatis width | |
5494 | type = double | |
5495 | (_GDBP__) p width | |
5496 | $4 = 13 | |
5497 | (_GDBP__) set width=47 | |
5498 | Invalid syntax in expression. | |
5499 | @end example | |
1041a570 | 5500 | |
70b88761 RP |
5501 | @noindent |
5502 | The invalid expression, of course, is @samp{=47}. What we can do in | |
e251e767 | 5503 | order to actually set our program's variable @code{width} is |
1041a570 | 5504 | |
70b88761 RP |
5505 | @example |
5506 | (_GDBP__) set var width=47 | |
5507 | @end example | |
5508 | ||
1041a570 RP |
5509 | _GDBN__ allows more implicit conversions in assignments than C; you can |
5510 | freely store an integer value into a pointer variable or vice versa, | |
5511 | and any structure can be converted to any other structure that is the | |
5512 | same length or shorter. | |
e251e767 | 5513 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
5514 | @comment /[email protected] 18dec1990 |
5515 | ||
5516 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
5517 | construct to generate a value of specified type at a specified address | |
1041a570 | 5518 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
5519 | to memory location @code{0x83040} as an integer (which implies a certain size |
5520 | and representation in memory), and | |
5521 | ||
5522 | @example | |
5523 | set @{int@}0x83040 = 4 | |
5524 | @end example | |
5525 | ||
5526 | @noindent | |
5527 | stores the value 4 into that memory location. | |
5528 | ||
5529 | @node Jumping, Signaling, Assignment, Altering | |
5530 | @section Continuing at a Different Address | |
5531 | ||
29a2b744 | 5532 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
5533 | it stopped, with the @code{continue} command. You can instead continue at |
5534 | an address of your own choosing, with the following commands: | |
5535 | ||
5536 | @table @code | |
5537 | @item jump @var{linespec} | |
5538 | @kindex jump | |
5539 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 RP |
5540 | immediately if there is a breakpoint there. @xref{List, ,Printing |
5541 | Source Lines}, for a description of the different forms of | |
5542 | @var{linespec}. | |
70b88761 RP |
5543 | |
5544 | The @code{jump} command does not change the current stack frame, or | |
5545 | the stack pointer, or the contents of any memory location or any | |
5546 | register other than the program counter. If line @var{linespec} is in | |
5547 | a different function from the one currently executing, the results may | |
5548 | be bizarre if the two functions expect different patterns of arguments or | |
5549 | of local variables. For this reason, the @code{jump} command requests | |
5550 | confirmation if the specified line is not in the function currently | |
5551 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 5552 | well acquainted with the machine-language code of your program. |
70b88761 RP |
5553 | |
5554 | @item jump *@var{address} | |
5555 | Resume execution at the instruction at address @var{address}. | |
5556 | @end table | |
5557 | ||
5558 | You can get much the same effect as the @code{jump} command by storing a | |
5559 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 5560 | does not start your program running; it only changes the address where it |
70b88761 RP |
5561 | @emph{will} run when it is continued. For example, |
5562 | ||
5563 | @example | |
5564 | set $pc = 0x485 | |
5565 | @end example | |
5566 | ||
5567 | @noindent | |
5568 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 RP |
5569 | address @code{0x485}, rather than at the address where your program stopped. |
5570 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
70b88761 RP |
5571 | |
5572 | The most common occasion to use the @code{jump} command is to back up, | |
5573 | perhaps with more breakpoints set, over a portion of a program that has | |
5574 | already executed, in order to examine its execution in more detail. | |
5575 | ||
5576 | @node Signaling, Returning, Jumping, Altering | |
5577 | @c @group | |
29a2b744 | 5578 | @section Giving your program a Signal |
70b88761 RP |
5579 | |
5580 | @table @code | |
5581 | @item signal @var{signalnum} | |
5582 | @kindex signal | |
29a2b744 | 5583 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
5584 | signal number @var{signalnum}. |
5585 | ||
5586 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 5587 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
5588 | a signal and would ordinary see the signal when resumed with the |
5589 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
5590 | signal. | |
5591 | ||
5592 | @code{signal} does not repeat when you press @key{RET} a second time | |
5593 | after executing the command. | |
5594 | @end table | |
5595 | @c @end group | |
5596 | ||
5597 | @node Returning, Calling, Signaling, Altering | |
5598 | @section Returning from a Function | |
5599 | ||
5600 | @table @code | |
5601 | @item return | |
5602 | @itemx return @var{expression} | |
5603 | @cindex returning from a function | |
5604 | @kindex return | |
5605 | You can cancel execution of a function call with the @code{return} | |
5606 | command. If you give an | |
5607 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 5608 | value. |
70b88761 RP |
5609 | @end table |
5610 | ||
5611 | When you use @code{return}, _GDBN__ discards the selected stack frame | |
5612 | (and all frames within it). You can think of this as making the | |
5613 | discarded frame return prematurely. If you wish to specify a value to | |
5614 | be returned, give that value as the argument to @code{return}. | |
5615 | ||
29a2b744 RP |
5616 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
5617 | Frame}), and any other frames inside of it, leaving its caller as the | |
5618 | innermost remaining frame. That frame becomes selected. The | |
5619 | specified value is stored in the registers used for returning values | |
5620 | of functions. | |
70b88761 RP |
5621 | |
5622 | The @code{return} command does not resume execution; it leaves the | |
5623 | program stopped in the state that would exist if the function had just | |
1041a570 RP |
5624 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
5625 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
5626 | selected stack frame returns naturally. | |
70b88761 | 5627 | |
c338a2fd | 5628 | @node Calling, Patching, Returning, Altering |
70b88761 RP |
5629 | @section Calling your Program's Functions |
5630 | ||
5631 | @cindex calling functions | |
5632 | @kindex call | |
5633 | @table @code | |
5634 | @item call @var{expr} | |
5635 | Evaluate the expression @var{expr} without displaying @code{void} | |
5636 | returned values. | |
5637 | @end table | |
5638 | ||
5639 | You can use this variant of the @code{print} command if you want to | |
5640 | execute a function from your program, but without cluttering the output | |
5641 | with @code{void} returned values. The result is printed and saved in | |
5642 | the value history, if it is not void. | |
5643 | ||
c338a2fd RP |
5644 | @node Patching, , Calling, Altering |
5645 | @section Patching your Program | |
5646 | @cindex patching binaries | |
5647 | @cindex writing into executables | |
5648 | @cindex writing into corefiles | |
1041a570 | 5649 | |
c338a2fd RP |
5650 | By default, _GDBN__ opens the file containing your program's executable |
5651 | code (or the corefile) read-only. This prevents accidental alterations | |
5652 | to machine code; but it also prevents you from intentionally patching | |
5653 | your program's binary. | |
5654 | ||
5655 | If you'd like to be able to patch the binary, you can specify that | |
5656 | explicitly with the @code{set write} command. For example, you might | |
5657 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 5658 | repairs. |
c338a2fd RP |
5659 | |
5660 | @table @code | |
5661 | @item set write on | |
5662 | @itemx set write off | |
5663 | @kindex set write | |
5664 | If you specify @samp{set write on}, _GDBN__ will open executable and | |
5665 | core files for both reading and writing; if you specify @samp{set write | |
5666 | off} (the default), _GDBN__ will open them read-only. | |
5667 | ||
1041a570 | 5668 | If you have already loaded a file, you must load it |
c338a2fd RP |
5669 | again (using the @code{exec-file} or @code{core-file} command) after |
5670 | changing @code{set write}, for your new setting to take effect. | |
5671 | ||
5672 | @item show write | |
7d7ff5f6 | 5673 | @kindex show write |
c338a2fd RP |
5674 | Display whether executable files and core files will be opened for |
5675 | writing as well as reading. | |
c338a2fd RP |
5676 | @end table |
5677 | ||
70b88761 RP |
5678 | @node _GDBN__ Files, Targets, Altering, Top |
5679 | @chapter _GDBN__'s Files | |
5680 | ||
1041a570 RP |
5681 | _GDBN__ needs to know the file name of the program to be debugged, both in |
5682 | order to read its symbol table and in order to start your program. To | |
5683 | debug a core dump of a previous run, _GDBN__ must be told the file name of | |
5684 | the core dump. | |
5685 | ||
70b88761 | 5686 | @menu |
b80282d5 RP |
5687 | * Files:: Commands to Specify Files |
5688 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 RP |
5689 | @end menu |
5690 | ||
5691 | @node Files, Symbol Errors, _GDBN__ Files, _GDBN__ Files | |
5692 | @section Commands to Specify Files | |
5693 | @cindex core dump file | |
5694 | @cindex symbol table | |
70b88761 | 5695 | |
1041a570 RP |
5696 | The usual way to specify executable and core dump file names is with |
5697 | the command arguments given when you start _GDBN__, (@pxref{Invocation, | |
5698 | ,Getting In and Out of _GDBN__}. | |
70b88761 RP |
5699 | |
5700 | Occasionally it is necessary to change to a different file during a | |
5701 | _GDBN__ session. Or you may run _GDBN__ and forget to specify the files you | |
5702 | want to use. In these situations the _GDBN__ commands to specify new files | |
5703 | are useful. | |
5704 | ||
5705 | @table @code | |
5706 | @item file @var{filename} | |
5707 | @cindex executable file | |
5708 | @kindex file | |
5709 | Use @var{filename} as the program to be debugged. It is read for its | |
5710 | symbols and for the contents of pure memory. It is also the program | |
5711 | executed when you use the @code{run} command. If you do not specify a | |
1041a570 RP |
5712 | directory and the file is not found in _GDBN__'s working directory, _GDBN__ |
5713 | uses the environment variable @code{PATH} as a list of directories to | |
5714 | search, just as the shell does when looking for a program to run. You | |
5715 | can change the value of this variable, for both _GDBN__ and your program, | |
5716 | using the @code{path} command. | |
70b88761 | 5717 | |
e0dacfd1 | 5718 | @item file |
70b88761 RP |
5719 | @code{file} with no argument makes _GDBN__ discard any information it |
5720 | has on both executable file and the symbol table. | |
5721 | ||
e0dacfd1 | 5722 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
5723 | @kindex exec-file |
5724 | Specify that the program to be run (but not the symbol table) is found | |
5725 | in @var{filename}. _GDBN__ will search the environment variable @code{PATH} | |
29a2b744 | 5726 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 5727 | discard information on the executable file. |
70b88761 | 5728 | |
e0dacfd1 | 5729 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
5730 | @kindex symbol-file |
5731 | Read symbol table information from file @var{filename}. @code{PATH} is | |
5732 | searched when necessary. Use the @code{file} command to get both symbol | |
5733 | table and program to run from the same file. | |
5734 | ||
5735 | @code{symbol-file} with no argument clears out _GDBN__'s information on your | |
5736 | program's symbol table. | |
5737 | ||
5738 | The @code{symbol-file} command causes _GDBN__ to forget the contents of its | |
5739 | convenience variables, the value history, and all breakpoints and | |
5740 | auto-display expressions. This is because they may contain pointers to | |
5741 | the internal data recording symbols and data types, which are part of | |
5742 | the old symbol table data being discarded inside _GDBN__. | |
5743 | ||
5744 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
5745 | executing it once. | |
5746 | ||
5747 | On some kinds of object files, the @code{symbol-file} command does not | |
5748 | actually read the symbol table in full right away. Instead, it scans | |
5749 | the symbol table quickly to find which source files and which symbols | |
5750 | are present. The details are read later, one source file at a time, | |
1041a570 | 5751 | as they are needed. |
70b88761 RP |
5752 | |
5753 | The purpose of this two-stage reading strategy is to make _GDBN__ start up | |
1041a570 RP |
5754 | faster. For the most part, it is invisible except for occasional |
5755 | pauses while the symbol table details for a particular source file are | |
5756 | being read. (The @code{set verbose} command can turn these pauses | |
5757 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings | |
5758 | and Messages}.) | |
70b88761 RP |
5759 | |
5760 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
1041a570 | 5761 | read the symbol table data in full right away. We have not implemented |
70b88761 RP |
5762 | the two-stage strategy for COFF yet. |
5763 | ||
5764 | When _GDBN__ is configured for a particular environment, it will | |
5765 | understand debugging information in whatever format is the standard | |
5766 | generated for that environment; you may use either a GNU compiler, or | |
5767 | other compilers that adhere to the local conventions. Best results are | |
5768 | usually obtained from GNU compilers; for example, using @code{_GCC__} | |
5769 | you can generate debugging information for optimized code. | |
5770 | ||
e0dacfd1 | 5771 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
5772 | @kindex core |
5773 | @kindex core-file | |
5774 | Specify the whereabouts of a core dump file to be used as the ``contents | |
5775 | of memory''. Traditionally, core files contain only some parts of the | |
5776 | address space of the process that generated them; _GDBN__ can access the | |
5777 | executable file itself for other parts. | |
5778 | ||
5779 | @code{core-file} with no argument specifies that no core file is | |
5780 | to be used. | |
5781 | ||
5782 | Note that the core file is ignored when your program is actually running | |
29a2b744 | 5783 | under _GDBN__. So, if you have been running your program and you wish to |
70b88761 RP |
5784 | debug a core file instead, you must kill the subprocess in which the |
5785 | program is running. To do this, use the @code{kill} command | |
1041a570 | 5786 | (@pxref{Kill Process, ,Killing the Child Process}). |
70b88761 RP |
5787 | |
5788 | @item load @var{filename} | |
5789 | @kindex load | |
5790 | _if__(_GENERIC__) | |
5791 | Depending on what remote debugging facilities are configured into | |
5792 | _GDBN__, the @code{load} command may be available. Where it exists, it | |
5793 | is meant to make @var{filename} (an executable) available for debugging | |
5794 | on the remote system---by downloading, or dynamic linking, for example. | |
5795 | @code{load} also records @var{filename}'s symbol table in _GDBN__, like | |
5796 | the @code{add-symbol-file} command. | |
5797 | ||
5798 | If @code{load} is not available on your _GDBN__, attempting to execute | |
5799 | it gets the error message ``@code{You can't do that when your target is | |
e251e767 | 5800 | @dots{}}'' |
70b88761 RP |
5801 | _fi__(_GENERIC__) |
5802 | ||
e251e767 | 5803 | _if__(_VXWORKS__) |
70b88761 RP |
5804 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
5805 | current target system as well as adding its symbols in _GDBN__. | |
5806 | _fi__(_VXWORKS__) | |
5807 | ||
5808 | _if__(_I960__) | |
5809 | @cindex download to Nindy-960 | |
5810 | With the Nindy interface to an Intel 960 board, @code{load} will | |
5811 | download @var{filename} to the 960 as well as adding its symbols in | |
e251e767 | 5812 | _GDBN__. |
70b88761 RP |
5813 | _fi__(_I960__) |
5814 | ||
5815 | @code{load} will not repeat if you press @key{RET} again after using it. | |
5816 | ||
5817 | @item add-symbol-file @var{filename} @var{address} | |
5818 | @kindex add-symbol-file | |
5819 | @cindex dynamic linking | |
5820 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 5821 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
5822 | has been dynamically loaded (by some other means) into the program that |
5823 | is running. @var{address} should be the memory address at which the | |
5824 | file has been loaded; _GDBN__ cannot figure this out for itself. | |
5825 | ||
5826 | The symbol table of the file @var{filename} is added to the symbol table | |
5827 | originally read with the @code{symbol-file} command. You can use the | |
5828 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
5829 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 5830 | use the @code{symbol-file} command. |
70b88761 RP |
5831 | |
5832 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
5833 | ||
5834 | @item info files | |
5835 | @itemx info target | |
5836 | @kindex info files | |
5837 | @kindex info target | |
1041a570 RP |
5838 | @code{info files} and @code{info target} are synonymous; both print |
5839 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
5840 | including the names of the executable and core dump files currently in | |
5841 | use by _GDBN__, and the files from which symbols were loaded. The command | |
5842 | @code{help targets} lists all possible targets rather than current | |
5843 | ones. | |
70b88761 RP |
5844 | |
5845 | @end table | |
5846 | ||
5847 | All file-specifying commands allow both absolute and relative file names | |
5848 | as arguments. _GDBN__ always converts the file name to an absolute path | |
5849 | name and remembers it that way. | |
5850 | ||
70b88761 RP |
5851 | @cindex shared libraries |
5852 | ||
c338a2fd RP |
5853 | _GDBN__ supports the SunOS shared library format. _GDBN__ automatically |
5854 | loads symbol definitions from shared libraries when you use the | |
5855 | @code{run} command, or when you examine a core file. (Before you issue | |
1041a570 | 5856 | the @code{run} command, _GDBN__ will not understand references to a |
29a2b744 | 5857 | function in a shared library, however---unless you are debugging a core |
c338a2fd RP |
5858 | file). |
5859 | @c FIXME: next _GDBN__ release should permit some refs to undef | |
1041a570 | 5860 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
5861 | |
5862 | @table @code | |
70b88761 RP |
5863 | @item info share |
5864 | @itemx info sharedlibrary | |
5865 | @kindex info sharedlibrary | |
5866 | @kindex info share | |
c338a2fd | 5867 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 5868 | |
c338a2fd RP |
5869 | @item sharedlibrary @var{regex} |
5870 | @itemx share @var{regex} | |
5871 | @kindex sharedlibrary | |
5872 | @kindex share | |
5873 | This is an obsolescent command; you can use it to explicitly | |
5874 | load shared object library symbols for files matching a UNIX regular | |
5875 | expression, but as with files loaded automatically, it will only load | |
5876 | shared libraries required by your program for a core file or after | |
5877 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
5878 | required by your program are loaded. | |
5879 | @end table | |
70b88761 RP |
5880 | |
5881 | @node Symbol Errors, , Files, _GDBN__ Files | |
5882 | @section Errors Reading Symbol Files | |
1041a570 RP |
5883 | |
5884 | While reading a symbol file, _GDBN__ will occasionally encounter problems, | |
5885 | such as symbol types it does not recognize, or known bugs in compiler | |
5886 | output. By default, _GDBN__ does not notify you of such problems, since | |
5887 | they are relatively common and primarily of interest to people | |
5888 | debugging compilers. If you are interested in seeing information | |
b80282d5 RP |
5889 | about ill-constructed symbol tables, you can either ask _GDBN__ to print |
5890 | only one message about each such type of problem, no matter how many | |
5891 | times the problem occurs; or you can ask _GDBN__ to print more messages, | |
1041a570 RP |
5892 | to see how many times the problems occur, with the @code{set |
5893 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
5894 | Messages}). | |
70b88761 RP |
5895 | |
5896 | The messages currently printed, and their meanings, are: | |
5897 | ||
5898 | @table @code | |
5899 | @item inner block not inside outer block in @var{symbol} | |
5900 | ||
5901 | The symbol information shows where symbol scopes begin and end | |
5902 | (such as at the start of a function or a block of statements). This | |
5903 | error indicates that an inner scope block is not fully contained | |
e251e767 | 5904 | in its outer scope blocks. |
70b88761 RP |
5905 | |
5906 | _GDBN__ circumvents the problem by treating the inner block as if it had | |
5907 | the same scope as the outer block. In the error message, @var{symbol} | |
5908 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
5909 | function. | |
5910 | ||
5911 | @item block at @var{address} out of order | |
5912 | ||
e251e767 | 5913 | The symbol information for symbol scope blocks should occur in |
70b88761 | 5914 | order of increasing addresses. This error indicates that it does not |
e251e767 | 5915 | do so. |
70b88761 RP |
5916 | |
5917 | _GDBN__ does not circumvent this problem, and will have trouble locating | |
5918 | symbols in the source file whose symbols being read. (You can often | |
5919 | determine what source file is affected by specifying @code{set verbose | |
29a2b744 | 5920 | on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.) |
70b88761 RP |
5921 | |
5922 | @item bad block start address patched | |
5923 | ||
5924 | The symbol information for a symbol scope block has a start address | |
5925 | smaller than the address of the preceding source line. This is known | |
e251e767 | 5926 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 RP |
5927 | |
5928 | _GDBN__ circumvents the problem by treating the symbol scope block as | |
5929 | starting on the previous source line. | |
5930 | ||
70b88761 RP |
5931 | @item bad string table offset in symbol @var{n} |
5932 | ||
5933 | @cindex foo | |
5934 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 5935 | larger than the size of the string table. |
70b88761 RP |
5936 | |
5937 | _GDBN__ circumvents the problem by considering the symbol to have the | |
5938 | name @code{foo}, which may cause other problems if many symbols end up | |
5939 | with this name. | |
5940 | ||
5941 | @item unknown symbol type @code{0x@var{nn}} | |
5942 | ||
5943 | The symbol information contains new data types that _GDBN__ does not yet | |
5944 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
e251e767 | 5945 | information, in hexadecimal. |
70b88761 RP |
5946 | |
5947 | _GDBN__ circumvents the error by ignoring this symbol information. This | |
29a2b744 | 5948 | will usually allow your program to be debugged, though certain symbols |
70b88761 RP |
5949 | will not be accessible. If you encounter such a problem and feel like |
5950 | debugging it, you can debug @code{_GDBP__} with itself, breakpoint on | |
5951 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
5952 | examine @code{*bufp} to see the symbol. | |
5953 | ||
5954 | @item stub type has NULL name | |
e251e767 | 5955 | _GDBN__ could not find the full definition for a struct or class. |
70b88761 | 5956 | |
440d9834 | 5957 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
5958 | |
5959 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
5960 | information that recent versions of the compiler should have output |
5961 | for it. | |
70b88761 | 5962 | |
440d9834 | 5963 | @item info mismatch between compiler and debugger |
70b88761 | 5964 | |
440d9834 | 5965 | _GDBN__ could not parse a type specification output by the compiler. |
70b88761 RP |
5966 | @end table |
5967 | ||
5968 | @node Targets, Controlling _GDBN__, _GDBN__ Files, Top | |
e251e767 | 5969 | @chapter Specifying a Debugging Target |
70b88761 RP |
5970 | @cindex debugging target |
5971 | @kindex target | |
1041a570 | 5972 | |
cedaf8bc | 5973 | A @dfn{target} is the execution environment occupied by your program. |
1041a570 RP |
5974 | Often, _GDBN__ runs in the same host environment as your program; in |
5975 | that case, the debugging target is specified as a side effect when you | |
5976 | use the @code{file} or @code{core} commands. When you need more | |
5977 | flexibility---for example, running _GDBN__ on a physically separate | |
5978 | host, or controlling a standalone system over a serial port or a | |
5979 | realtime system over a TCP/IP connection---you can use the @code{target} | |
5980 | command to specify one of the target types configured for _GDBN__ | |
5981 | (@pxref{Target Commands, ,Commands for Managing Targets}). | |
70b88761 RP |
5982 | |
5983 | @menu | |
b80282d5 RP |
5984 | * Active Targets:: Active Targets |
5985 | * Target Commands:: Commands for Managing Targets | |
5986 | * Remote:: Remote Debugging | |
70b88761 RP |
5987 | @end menu |
5988 | ||
5989 | @node Active Targets, Target Commands, Targets, Targets | |
5990 | @section Active Targets | |
5991 | @cindex stacking targets | |
5992 | @cindex active targets | |
5993 | @cindex multiple targets | |
5994 | ||
cedaf8bc RP |
5995 | There are three classes of targets: processes, core files, and |
5996 | executable files. _GDBN__ can work concurrently on up to three active | |
5997 | targets, one in each class. This allows you to (for example) start a | |
5998 | process and inspect its activity without abandoning your work on a core | |
5999 | file. | |
70b88761 | 6000 | |
cedaf8bc RP |
6001 | If, for example, you execute @samp{gdb a.out}, then the executable file |
6002 | @code{a.out} is the only active target. If you designate a core file as | |
6003 | well---presumably from a prior run that crashed and coredumped---then | |
6004 | _GDBN__ has two active targets and will use them in tandem, looking | |
6005 | first in the corefile target, then in the executable file, to satisfy | |
6006 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 6007 | are complementary, since core files contain only a program's |
cedaf8bc RP |
6008 | read-write memory---variables and so on---plus machine status, while |
6009 | executable files contain only the program text and initialized data.) | |
6010 | ||
6011 | When you type @code{run}, your executable file becomes an active process | |
6012 | target as well. When a process target is active, all _GDBN__ commands | |
6013 | requesting memory addresses refer to that target; addresses in an active | |
6014 | core file or executable file target are obscured while the process | |
6015 | target is active. | |
6016 | ||
1041a570 RP |
6017 | Use the @code{core-file} and @code{exec-file} commands to select a |
6018 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
6019 | Files}). To specify as a target a process that is already running, use | |
6020 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
6021 | Already-Running Process}.). | |
70b88761 RP |
6022 | |
6023 | @node Target Commands, Remote, Active Targets, Targets | |
6024 | @section Commands for Managing Targets | |
6025 | ||
6026 | @table @code | |
6027 | @item target @var{type} @var{parameters} | |
6028 | Connects the _GDBN__ host environment to a target machine or process. A | |
6029 | target is typically a protocol for talking to debugging facilities. You | |
6030 | use the argument @var{type} to specify the type or protocol of the | |
6031 | target machine. | |
6032 | ||
6033 | Further @var{parameters} are interpreted by the target protocol, but | |
6034 | typically include things like device names or host names to connect | |
e251e767 | 6035 | with, process numbers, and baud rates. |
70b88761 RP |
6036 | |
6037 | The @code{target} command will not repeat if you press @key{RET} again | |
6038 | after executing the command. | |
6039 | ||
6040 | @item help target | |
6041 | @kindex help target | |
6042 | Displays the names of all targets available. To display targets | |
6043 | currently selected, use either @code{info target} or @code{info files} | |
29a2b744 | 6044 | (@pxref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6045 | |
6046 | @item help target @var{name} | |
6047 | Describe a particular target, including any parameters necessary to | |
6048 | select it. | |
6049 | @end table | |
6050 | ||
6051 | Here are some common targets (available, or not, depending on the _GDBN__ | |
6052 | configuration): | |
6053 | ||
6054 | @table @code | |
6055 | @item target exec @var{prog} | |
6056 | @kindex target exec | |
6057 | An executable file. @samp{target exec @var{prog}} is the same as | |
6058 | @samp{exec-file @var{prog}}. | |
6059 | ||
6060 | @item target core @var{filename} | |
6061 | @kindex target core | |
6062 | A core dump file. @samp{target core @var{filename}} is the same as | |
6063 | @samp{core-file @var{filename}}. | |
6064 | ||
6065 | @item target remote @var{dev} | |
6066 | @kindex target remote | |
6067 | Remote serial target in _GDBN__-specific protocol. The argument @var{dev} | |
6068 | specifies what serial device to use for the connection (e.g. | |
1041a570 | 6069 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. |
70b88761 RP |
6070 | |
6071 | _if__(_AMD29K__) | |
6072 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
6073 | @kindex target amd-eb | |
6074 | @cindex AMD EB29K | |
6075 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6076 | @var{dev} is the serial device, as for @code{target remote}; | |
6077 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6078 | name of the program to be debugged, as it appears to DOS on the PC. | |
1041a570 | 6079 | @xref{EB29K Remote, ,GDB with a Remote EB29K}. |
70b88761 RP |
6080 | |
6081 | _fi__(_AMD29K__) | |
6082 | _if__(_I960__) | |
6083 | @item target nindy @var{devicename} | |
6084 | @kindex target nindy | |
6085 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6086 | the name of the serial device to use for the connection, e.g. | |
1041a570 | 6087 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}. |
70b88761 RP |
6088 | |
6089 | _fi__(_I960__) | |
6090 | _if__(_VXWORKS__) | |
6091 | @item target vxworks @var{machinename} | |
6092 | @kindex target vxworks | |
6093 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6094 | is the target system's machine name or IP address. | |
1041a570 | 6095 | @xref{VxWorks Remote, ,_GDBN__ and VxWorks}. |
70b88761 RP |
6096 | _fi__(_VXWORKS__) |
6097 | @end table | |
6098 | ||
6099 | _if__(_GENERIC__) | |
6100 | Different targets are available on different configurations of _GDBN__; your | |
6101 | configuration may have more or fewer targets. | |
6102 | _fi__(_GENERIC__) | |
6103 | ||
6104 | @node Remote, , Target Commands, Targets | |
6105 | @section Remote Debugging | |
6106 | @cindex remote debugging | |
6107 | ||
29a2b744 | 6108 | If you are trying to debug a program running on a machine that cannot run |
70b88761 RP |
6109 | _GDBN__ in the usual way, it is often useful to use remote debugging. For |
6110 | example, you might use remote debugging on an operating system kernel, or on | |
6111 | a small system which does not have a general purpose operating system | |
e251e767 | 6112 | powerful enough to run a full-featured debugger. |
70b88761 RP |
6113 | |
6114 | Some configurations of _GDBN__ have special serial or TCP/IP interfaces | |
6115 | to make this work with particular debugging targets. In addition, | |
6116 | _GDBN__ comes with a generic serial protocol (specific to _GDBN__, but | |
6117 | not specific to any particular target system) which you can use if you | |
6118 | write the remote stubs---the code that will run on the remote system to | |
6119 | communicate with _GDBN__. | |
6120 | ||
6121 | To use the _GDBN__ remote serial protocol, the program to be debugged on | |
6122 | the remote machine needs to contain a debugging stub which talks to | |
6123 | _GDBN__ over the serial line. Several working remote stubs are | |
6124 | distributed with _GDBN__; see the @file{README} file in the _GDBN__ | |
6125 | distribution for more information. | |
6126 | ||
6127 | For details of this communication protocol, see the comments in the | |
6128 | _GDBN__ source file @file{remote.c}. | |
6129 | ||
6130 | To start remote debugging, first run _GDBN__ and specify as an executable file | |
6131 | the program that is running in the remote machine. This tells _GDBN__ how | |
29a2b744 | 6132 | to find your program's symbols and the contents of its pure text. Then |
70b88761 RP |
6133 | establish communication using the @code{target remote} command with a device |
6134 | name as an argument. For example: | |
6135 | ||
6136 | @example | |
6137 | target remote /dev/ttyb | |
6138 | @end example | |
6139 | ||
6140 | @noindent | |
6141 | if the serial line is connected to the device named @file{/dev/ttyb}. This | |
6142 | will stop the remote machine if it is not already stopped. | |
6143 | ||
6144 | Now you can use all the usual commands to examine and change data and to | |
6145 | step and continue the remote program. | |
6146 | ||
6147 | To resume the remote program and stop debugging it, use the @code{detach} | |
6148 | command. | |
6149 | ||
6150 | Other remote targets may be available in your | |
e251e767 | 6151 | configuration of _GDBN__; use @code{help targets} to list them. |
70b88761 RP |
6152 | |
6153 | _if__(_GENERIC__) | |
1041a570 RP |
6154 | _dnl__ Text on starting up GDB in various specific cases; it goes up front |
6155 | _dnl__ in manuals configured for any of those particular situations, here | |
6156 | _dnl__ otherwise. | |
6157 | @menu | |
6158 | _include__(gdbinv-m.m4)<>_dnl__ | |
6159 | @end menu | |
70b88761 RP |
6160 | _include__(gdbinv-s.m4) |
6161 | _fi__(_GENERIC__) | |
6162 | ||
6163 | @node Controlling _GDBN__, Sequences, Targets, Top | |
6164 | @chapter Controlling _GDBN__ | |
6165 | ||
6166 | You can alter many aspects of _GDBN__'s interaction with you by using | |
6167 | the @code{set} command. For commands controlling how _GDBN__ displays | |
1041a570 | 6168 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. |
70b88761 RP |
6169 | |
6170 | @menu | |
b80282d5 RP |
6171 | * Prompt:: Prompt |
6172 | * Editing:: Command Editing | |
6173 | * History:: Command History | |
6174 | * Screen Size:: Screen Size | |
6175 | * Numbers:: Numbers | |
6176 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
6177 | @end menu |
6178 | ||
6179 | @node Prompt, Editing, Controlling _GDBN__, Controlling _GDBN__ | |
6180 | @section Prompt | |
6181 | @cindex prompt | |
1041a570 | 6182 | |
70b88761 RP |
6183 | _GDBN__ indicates its readiness to read a command by printing a string |
6184 | called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You | |
6185 | can change the prompt string with the @code{set prompt} command. For | |
6186 | instance, when debugging _GDBN__ with _GDBN__, it is useful to change | |
6187 | the prompt in one of the _GDBN__<>s so that you can always tell which | |
6188 | one you are talking to. | |
6189 | ||
6190 | @table @code | |
6191 | @item set prompt @var{newprompt} | |
6192 | @kindex set prompt | |
6193 | Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth. | |
6194 | @kindex show prompt | |
6195 | @item show prompt | |
6196 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6197 | @end table | |
6198 | ||
6199 | @node Editing, History, Prompt, Controlling _GDBN__ | |
6200 | @section Command Editing | |
6201 | @cindex readline | |
6202 | @cindex command line editing | |
1041a570 | 6203 | |
70b88761 RP |
6204 | _GDBN__ reads its input commands via the @dfn{readline} interface. This |
6205 | GNU library provides consistent behavior for programs which provide a | |
6206 | command line interface to the user. Advantages are @code{emacs}-style | |
6207 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6208 | substitution, and a storage and recall of command history across | |
6209 | debugging sessions. | |
6210 | ||
6211 | You may control the behavior of command line editing in _GDBN__ with the | |
e251e767 | 6212 | command @code{set}. |
70b88761 RP |
6213 | |
6214 | @table @code | |
6215 | @kindex set editing | |
6216 | @cindex editing | |
6217 | @item set editing | |
6218 | @itemx set editing on | |
6219 | Enable command line editing (enabled by default). | |
6220 | ||
6221 | @item set editing off | |
6222 | Disable command line editing. | |
6223 | ||
6224 | @kindex show editing | |
6225 | @item show editing | |
6226 | Show whether command line editing is enabled. | |
6227 | @end table | |
6228 | ||
6229 | @node History, Screen Size, Editing, Controlling _GDBN__ | |
6230 | @section Command History | |
1041a570 | 6231 | |
70b88761 RP |
6232 | @table @code |
6233 | @cindex history substitution | |
6234 | @cindex history file | |
6235 | @kindex set history filename | |
6236 | @item set history filename @var{fname} | |
6237 | Set the name of the _GDBN__ command history file to @var{fname}. This is | |
6238 | the file from which _GDBN__ will read an initial command history | |
6239 | list or to which it will write this list when it exits. This list is | |
6240 | accessed through history expansion or through the history | |
6241 | command editing characters listed below. This file defaults to the | |
6242 | value of the environment variable @code{GDBHISTFILE}, or to | |
6243 | @file{./.gdb_history} if this variable is not set. | |
6244 | ||
6245 | @cindex history save | |
6246 | @kindex set history save | |
6247 | @item set history save | |
6248 | @itemx set history save on | |
6249 | Record command history in a file, whose name may be specified with the | |
6250 | @code{set history filename} command. By default, this option is disabled. | |
6251 | ||
6252 | @item set history save off | |
6253 | Stop recording command history in a file. | |
6254 | ||
6255 | @cindex history size | |
6256 | @kindex set history size | |
6257 | @item set history size @var{size} | |
6258 | Set the number of commands which _GDBN__ will keep in its history list. | |
6259 | This defaults to the value of the environment variable | |
6260 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6261 | @end table | |
6262 | ||
6263 | @cindex history expansion | |
6264 | History expansion assigns special meaning to the character @kbd{!}. | |
6265 | @iftex | |
1041a570 | 6266 | @xref{Event Designators}. |
70b88761 RP |
6267 | @end iftex |
6268 | Since @kbd{!} is also the logical not operator in C, history expansion | |
6269 | is off by default. If you decide to enable history expansion with the | |
6270 | @code{set history expansion on} command, you may sometimes need to | |
6271 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
6272 | a space or a tab to prevent it from being expanded. The readline | |
6273 | history facilities will not attempt substitution on the strings | |
6274 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
6275 | ||
6276 | The commands to control history expansion are: | |
6277 | ||
6278 | @table @code | |
6279 | ||
6280 | @kindex set history expansion | |
6281 | @item set history expansion on | |
6282 | @itemx set history expansion | |
6283 | Enable history expansion. History expansion is off by default. | |
6284 | ||
6285 | @item set history expansion off | |
6286 | Disable history expansion. | |
6287 | ||
6288 | The readline code comes with more complete documentation of | |
6289 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 6290 | or @code{vi} may wish to read it. |
70b88761 RP |
6291 | @iftex |
6292 | @xref{Command Line Editing}. | |
6293 | @end iftex | |
6294 | ||
6295 | @c @group | |
6296 | @kindex show history | |
6297 | @item show history | |
6298 | @itemx show history filename | |
6299 | @itemx show history save | |
6300 | @itemx show history size | |
6301 | @itemx show history expansion | |
6302 | These commands display the state of the _GDBN__ history parameters. | |
6303 | @code{show history} by itself displays all four states. | |
6304 | @c @end group | |
70b88761 RP |
6305 | @end table |
6306 | ||
6307 | @table @code | |
6308 | @kindex show commands | |
6309 | @item show commands | |
6310 | Display the last ten commands in the command history. | |
6311 | ||
6312 | @item show commands @var{n} | |
6313 | Print ten commands centered on command number @var{n}. | |
6314 | ||
6315 | @item show commands + | |
6316 | Print ten commands just after the commands last printed. | |
70b88761 RP |
6317 | @end table |
6318 | ||
6319 | @node Screen Size, Numbers, History, Controlling _GDBN__ | |
6320 | @section Screen Size | |
6321 | @cindex size of screen | |
6322 | @cindex pauses in output | |
1041a570 | 6323 | |
70b88761 RP |
6324 | Certain commands to _GDBN__ may produce large amounts of information |
6325 | output to the screen. To help you read all of it, _GDBN__ pauses and | |
6326 | asks you for input at the end of each page of output. Type @key{RET} | |
6327 | when you want to continue the output. _GDBN__ also uses the screen | |
6328 | width setting to determine when to wrap lines of output. Depending on | |
6329 | what is being printed, it tries to break the line at a readable place, | |
6330 | rather than simply letting it overflow onto the following line. | |
6331 | ||
6332 | Normally _GDBN__ knows the size of the screen from the termcap data base | |
6333 | together with the value of the @code{TERM} environment variable and the | |
6334 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
6335 | you can override it with the @code{set height} and @code{set | |
6336 | width} commands: | |
6337 | ||
6338 | @table @code | |
6339 | @item set height @var{lpp} | |
6340 | @itemx show height | |
6341 | @itemx set width @var{cpl} | |
6342 | @itemx show width | |
6343 | @kindex set height | |
6344 | @kindex set width | |
6345 | @kindex show width | |
6346 | @kindex show height | |
6347 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
6348 | a screen width of @var{cpl} characters. The associated @code{show} | |
6349 | commands display the current settings. | |
6350 | ||
6351 | If you specify a height of zero lines, _GDBN__ will not pause during output | |
6352 | no matter how long the output is. This is useful if output is to a file | |
6353 | or to an editor buffer. | |
6354 | @end table | |
6355 | ||
6356 | @node Numbers, Messages/Warnings, Screen Size, Controlling _GDBN__ | |
6357 | @section Numbers | |
6358 | @cindex number representation | |
6359 | @cindex entering numbers | |
1041a570 | 6360 | |
70b88761 RP |
6361 | You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by |
6362 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
6363 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
6364 | Numbers that begin with none of these are, by default, entered in base | |
6365 | 10; likewise, the default display for numbers---when no particular | |
6366 | format is specified---is base 10. You can change the default base for | |
6367 | both input and output with the @code{set radix} command. | |
6368 | ||
6369 | @table @code | |
6370 | @kindex set radix | |
6371 | @item set radix @var{base} | |
6372 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 6373 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
6374 | specified either unambiguously or using the current default radix; for |
6375 | example, any of | |
6376 | ||
6377 | @example | |
c2bbbb22 | 6378 | set radix 1010 |
70b88761 RP |
6379 | set radix 012 |
6380 | set radix 10. | |
6381 | set radix 0xa | |
6382 | @end example | |
6383 | ||
6384 | @noindent | |
6385 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
6386 | will leave the radix unchanged no matter what it was. | |
6387 | ||
6388 | @kindex show radix | |
6389 | @item show radix | |
6390 | Display the current default base for numeric input and display. | |
70b88761 RP |
6391 | @end table |
6392 | ||
c2bbbb22 | 6393 | @node Messages/Warnings, , Numbers, Controlling _GDBN__ |
70b88761 | 6394 | @section Optional Warnings and Messages |
1041a570 | 6395 | |
70b88761 RP |
6396 | By default, _GDBN__ is silent about its inner workings. If you are running |
6397 | on a slow machine, you may want to use the @code{set verbose} command. | |
6398 | It will make _GDBN__ tell you when it does a lengthy internal operation, so | |
1041a570 | 6399 | you will not think it has crashed. |
70b88761 | 6400 | |
1041a570 RP |
6401 | Currently, the messages controlled by @code{set verbose} are those |
6402 | which announce that the symbol table for a source file is being read | |
6403 | (@pxref{Files, ,Commands to Specify Files}, in the description of the | |
6404 | command @code{symbol-file}). | |
29a2b744 | 6405 | @c The following is the right way to do it, but emacs 18.55 does not support |
70b88761 | 6406 | @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo |
e251e767 | 6407 | @c is released. |
70b88761 | 6408 | @ignore |
29a2b744 | 6409 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6410 | @end ignore |
6411 | ||
6412 | @table @code | |
6413 | @kindex set verbose | |
6414 | @item set verbose on | |
6415 | Enables _GDBN__'s output of certain informational messages. | |
6416 | ||
6417 | @item set verbose off | |
6418 | Disables _GDBN__'s output of certain informational messages. | |
6419 | ||
6420 | @kindex show verbose | |
6421 | @item show verbose | |
6422 | Displays whether @code{set verbose} is on or off. | |
6423 | @end table | |
6424 | ||
b80282d5 RP |
6425 | By default, if _GDBN__ encounters bugs in the symbol table of an object |
6426 | file, it is silent; but if you are debugging a compiler, you may find | |
1041a570 | 6427 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). |
70b88761 RP |
6428 | |
6429 | @table @code | |
6430 | @kindex set complaints | |
6431 | @item set complaints @var{limit} | |
6432 | Permits _GDBN__ to output @var{limit} complaints about each type of unusual | |
6433 | symbols before becoming silent about the problem. Set @var{limit} to | |
6434 | zero to suppress all complaints; set it to a large number to prevent | |
6435 | complaints from being suppressed. | |
6436 | ||
6437 | @kindex show complaints | |
6438 | @item show complaints | |
6439 | Displays how many symbol complaints _GDBN__ is permitted to produce. | |
6440 | @end table | |
6441 | ||
6442 | By default, _GDBN__ is cautious, and asks what sometimes seem to be a | |
6443 | lot of stupid questions to confirm certain commands. For example, if | |
6444 | you try to run a program which is already running: | |
1041a570 | 6445 | |
70b88761 RP |
6446 | @example |
6447 | (_GDBP__) run | |
6448 | The program being debugged has been started already. | |
e251e767 | 6449 | Start it from the beginning? (y or n) |
70b88761 RP |
6450 | @end example |
6451 | ||
29a2b744 | 6452 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
6453 | commands, you can disable this ``feature'': |
6454 | ||
6455 | @table @code | |
6456 | @kindex set confirm | |
6457 | @cindex flinching | |
6458 | @cindex confirmation | |
6459 | @cindex stupid questions | |
6460 | @item set confirm off | |
6461 | Disables confirmation requests. | |
6462 | ||
6463 | @item set confirm on | |
6464 | Enables confirmation requests (the default). | |
6465 | ||
6466 | @item show confirm | |
6467 | @kindex show confirm | |
6468 | Displays state of confirmation requests. | |
6469 | @end table | |
6470 | ||
29a2b744 | 6471 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
6472 | @cindex reloading symbols |
6473 | Some systems allow individual object files that make up your program to | |
6474 | be replaced without stopping and restarting your program. | |
6475 | _if__(_VXWORKS__) | |
6476 | For example, in VxWorks you can simply recompile a defective object file | |
6477 | and keep on running. | |
6478 | _fi__(_VXWORKS__) | |
29a2b744 | 6479 | If you are running on one of these systems, you can allow _GDBN__ to |
1041a570 RP |
6480 | reload the symbols for automatically relinked modules: |
6481 | ||
b80282d5 RP |
6482 | @table @code |
6483 | @kindex set symbol-reloading | |
6484 | @item set symbol-reloading on | |
6485 | Replace symbol definitions for the corresponding source file when an | |
6486 | object file with a particular name is seen again. | |
6487 | ||
6488 | @item set symbol-reloading off | |
1041a570 | 6489 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 6490 | the same name. This is the default state; if you are not running on a |
b80282d5 RP |
6491 | system that permits automatically relinking modules, you should leave |
6492 | @code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols | |
6493 | when linking large programs, that may contain several modules (from | |
6494 | different directories or libraries) with the same name. | |
6495 | ||
6496 | @item show symbol-reloading | |
6497 | Show the current @code{on} or @code{off} setting. | |
6498 | @end table | |
6499 | ||
70b88761 RP |
6500 | @node Sequences, Emacs, Controlling _GDBN__, Top |
6501 | @chapter Canned Sequences of Commands | |
6502 | ||
29a2b744 | 6503 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
1041a570 RP |
6504 | Command Lists}), _GDBN__ provides two ways to store sequences of commands |
6505 | for execution as a unit: user-defined commands and command files. | |
70b88761 RP |
6506 | |
6507 | @menu | |
b80282d5 RP |
6508 | * Define:: User-Defined Commands |
6509 | * Command Files:: Command Files | |
6510 | * Output:: Commands for Controlled Output | |
70b88761 RP |
6511 | @end menu |
6512 | ||
6513 | @node Define, Command Files, Sequences, Sequences | |
6514 | @section User-Defined Commands | |
6515 | ||
6516 | @cindex user-defined command | |
6517 | A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you | |
6518 | assign a new name as a command. This is done with the @code{define} | |
6519 | command. | |
6520 | ||
6521 | @table @code | |
6522 | @item define @var{commandname} | |
6523 | @kindex define | |
6524 | Define a command named @var{commandname}. If there is already a command | |
6525 | by that name, you are asked to confirm that you want to redefine it. | |
6526 | ||
6527 | The definition of the command is made up of other _GDBN__ command lines, | |
6528 | which are given following the @code{define} command. The end of these | |
6529 | commands is marked by a line containing @code{end}. | |
6530 | ||
6531 | @item document @var{commandname} | |
6532 | @kindex document | |
6533 | Give documentation to the user-defined command @var{commandname}. The | |
6534 | command @var{commandname} must already be defined. This command reads | |
6535 | lines of documentation just as @code{define} reads the lines of the | |
6536 | command definition, ending with @code{end}. After the @code{document} | |
6537 | command is finished, @code{help} on command @var{commandname} will print | |
6538 | the documentation you have specified. | |
6539 | ||
6540 | You may use the @code{document} command again to change the | |
6541 | documentation of a command. Redefining the command with @code{define} | |
6542 | does not change the documentation. | |
6543 | ||
6544 | @item help user-defined | |
6545 | @kindex help user-defined | |
6546 | List all user-defined commands, with the first line of the documentation | |
6547 | (if any) for each. | |
6548 | ||
6549 | @item info user | |
6550 | @itemx info user @var{commandname} | |
6551 | @kindex info user | |
6552 | Display the _GDBN__ commands used to define @var{commandname} (but not its | |
6553 | documentation). If no @var{commandname} is given, display the | |
6554 | definitions for all user-defined commands. | |
6555 | @end table | |
6556 | ||
6557 | User-defined commands do not take arguments. When they are executed, the | |
6558 | commands of the definition are not printed. An error in any command | |
6559 | stops execution of the user-defined command. | |
6560 | ||
6561 | Commands that would ask for confirmation if used interactively proceed | |
6562 | without asking when used inside a user-defined command. Many _GDBN__ commands | |
6563 | that normally print messages to say what they are doing omit the messages | |
6564 | when used in a user-defined command. | |
6565 | ||
6566 | @node Command Files, Output, Define, Sequences | |
6567 | @section Command Files | |
6568 | ||
6569 | @cindex command files | |
6570 | A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments | |
6571 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
6572 | command file does nothing; it does not mean to repeat the last command, as | |
6573 | it would from the terminal. | |
6574 | ||
6575 | @cindex init file | |
6576 | @cindex @file{_GDBINIT__} | |
6577 | When you start _GDBN__, it automatically executes commands from its | |
1041a570 RP |
6578 | @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads |
6579 | the init file (if any) in your home directory and then the init file | |
6580 | (if any) in the current working directory. (The init files are not | |
6581 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
6582 | ,Choosing Modes}.) You can also request the execution of a command | |
6583 | file with the @code{source} command: | |
70b88761 RP |
6584 | |
6585 | @table @code | |
6586 | @item source @var{filename} | |
6587 | @kindex source | |
6588 | Execute the command file @var{filename}. | |
6589 | @end table | |
6590 | ||
6591 | The lines in a command file are executed sequentially. They are not | |
6592 | printed as they are executed. An error in any command terminates execution | |
6593 | of the command file. | |
6594 | ||
6595 | Commands that would ask for confirmation if used interactively proceed | |
6596 | without asking when used in a command file. Many _GDBN__ commands that | |
6597 | normally print messages to say what they are doing omit the messages | |
6598 | when called from command files. | |
6599 | ||
6600 | @node Output, , Command Files, Sequences | |
6601 | @section Commands for Controlled Output | |
6602 | ||
6603 | During the execution of a command file or a user-defined command, normal | |
6604 | _GDBN__ output is suppressed; the only output that appears is what is | |
6605 | explicitly printed by the commands in the definition. This section | |
6606 | describes three commands useful for generating exactly the output you | |
6607 | want. | |
6608 | ||
6609 | @table @code | |
6610 | @item echo @var{text} | |
6611 | @kindex echo | |
29a2b744 RP |
6612 | @c I do not consider backslash-space a standard C escape sequence |
6613 | @c because it is not in ANSI. | |
1041a570 RP |
6614 | Print @var{text}. Nonprinting characters can be included in |
6615 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
6616 | newline. @strong{No newline will be printed unless you specify one.} | |
6617 | In addition to the standard C escape sequences, a backslash followed | |
6618 | by a space stands for a space. This is useful for outputting a | |
6619 | string with spaces at the beginning or the end, since leading and | |
6620 | trailing spaces are otherwise trimmed from all arguments. | |
6621 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
6622 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
6623 | |
6624 | A backslash at the end of @var{text} can be used, as in C, to continue | |
6625 | the command onto subsequent lines. For example, | |
6626 | ||
6627 | @example | |
6628 | echo This is some text\n\ | |
6629 | which is continued\n\ | |
6630 | onto several lines.\n | |
6631 | @end example | |
6632 | ||
6633 | produces the same output as | |
6634 | ||
6635 | @example | |
6636 | echo This is some text\n | |
6637 | echo which is continued\n | |
6638 | echo onto several lines.\n | |
6639 | @end example | |
6640 | ||
6641 | @item output @var{expression} | |
6642 | @kindex output | |
6643 | Print the value of @var{expression} and nothing but that value: no | |
6644 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 6645 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 6646 | expressions. |
70b88761 RP |
6647 | |
6648 | @item output/@var{fmt} @var{expression} | |
6649 | Print the value of @var{expression} in format @var{fmt}. You can use | |
6650 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
6651 | information. | |
6652 | ||
6653 | @item printf @var{string}, @var{expressions}@dots{} | |
6654 | @kindex printf | |
6655 | Print the values of the @var{expressions} under the control of | |
6656 | @var{string}. The @var{expressions} are separated by commas and may | |
6657 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 6658 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
6659 | |
6660 | @example | |
6661 | printf (@var{string}, @var{expressions}@dots{}); | |
6662 | @end example | |
6663 | ||
6664 | For example, you can print two values in hex like this: | |
6665 | ||
6666 | @example | |
6667 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo | |
6668 | @end example | |
6669 | ||
6670 | The only backslash-escape sequences that you can use in the format | |
6671 | string are the simple ones that consist of backslash followed by a | |
6672 | letter. | |
6673 | @end table | |
6674 | ||
6675 | @node Emacs, _GDBN__ Bugs, Sequences, Top | |
6676 | @chapter Using _GDBN__ under GNU Emacs | |
6677 | ||
6678 | @cindex emacs | |
6679 | A special interface allows you to use GNU Emacs to view (and | |
6680 | edit) the source files for the program you are debugging with | |
6681 | _GDBN__. | |
6682 | ||
6683 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
6684 | executable file you want to debug as an argument. This command starts | |
6685 | _GDBN__ as a subprocess of Emacs, with input and output through a newly | |
6686 | created Emacs buffer. | |
6687 | ||
6688 | Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two | |
6689 | things: | |
6690 | ||
6691 | @itemize @bullet | |
6692 | @item | |
e251e767 | 6693 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
6694 | @end itemize |
6695 | ||
6696 | This applies both to _GDBN__ commands and their output, and to the input | |
6697 | and output done by the program you are debugging. | |
6698 | ||
6699 | This is useful because it means that you can copy the text of previous | |
6700 | commands and input them again; you can even use parts of the output | |
6701 | in this way. | |
6702 | ||
3d3ab540 RP |
6703 | All the facilities of Emacs' Shell mode are available for interacting |
6704 | with your program. In particular, you can send signals the usual | |
6705 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
6706 | stop. | |
70b88761 RP |
6707 | |
6708 | @itemize @bullet | |
6709 | @item | |
e251e767 | 6710 | _GDBN__ displays source code through Emacs. |
70b88761 RP |
6711 | @end itemize |
6712 | ||
6713 | Each time _GDBN__ displays a stack frame, Emacs automatically finds the | |
6714 | source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the | |
6715 | left margin of the current line. Emacs uses a separate buffer for | |
6716 | source display, and splits the window to show both your _GDBN__ session | |
6717 | and the source. | |
6718 | ||
6719 | Explicit _GDBN__ @code{list} or search commands still produce output as | |
6720 | usual, but you probably will have no reason to use them. | |
6721 | ||
6722 | @quotation | |
6723 | @emph{Warning:} If the directory where your program resides is not your | |
6724 | current directory, it can be easy to confuse Emacs about the location of | |
6725 | the source files, in which case the auxiliary display buffer will not | |
6726 | appear to show your source. _GDBN__ can find programs by searching your | |
6727 | environment's @code{PATH} variable, so the _GDBN__ input and output | |
29a2b744 | 6728 | session will proceed normally; but Emacs does not get enough information |
70b88761 RP |
6729 | back from _GDBN__ to locate the source files in this situation. To |
6730 | avoid this problem, either start _GDBN__ mode from the directory where | |
6731 | your program resides, or specify a full path name when prompted for the | |
6732 | @kbd{M-x gdb} argument. | |
6733 | ||
6734 | A similar confusion can result if you use the _GDBN__ @code{file} command to | |
6735 | switch to debugging a program in some other location, from an existing | |
6736 | _GDBN__ buffer in Emacs. | |
6737 | @end quotation | |
6738 | ||
6739 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
6740 | you need to call _GDBN__ by a different name (for example, if you keep | |
6741 | several configurations around, with different names) you can set the | |
6742 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 6743 | |
70b88761 RP |
6744 | @example |
6745 | (setq gdb-command-name "mygdb") | |
6746 | @end example | |
1041a570 | 6747 | |
70b88761 RP |
6748 | @noindent |
6749 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
6750 | in your @file{.emacs} file) will make Emacs call the program named | |
6751 | ``@code{mygdb}'' instead. | |
6752 | ||
6753 | In the _GDBN__ I/O buffer, you can use these special Emacs commands in | |
6754 | addition to the standard Shell mode commands: | |
6755 | ||
6756 | @table @kbd | |
6757 | @item C-h m | |
6758 | Describe the features of Emacs' _GDBN__ Mode. | |
6759 | ||
6760 | @item M-s | |
6761 | Execute to another source line, like the _GDBN__ @code{step} command; also | |
6762 | update the display window to show the current file and location. | |
6763 | ||
6764 | @item M-n | |
6765 | Execute to next source line in this function, skipping all function | |
6766 | calls, like the _GDBN__ @code{next} command. Then update the display window | |
6767 | to show the current file and location. | |
6768 | ||
6769 | @item M-i | |
6770 | Execute one instruction, like the _GDBN__ @code{stepi} command; update | |
6771 | display window accordingly. | |
6772 | ||
6773 | @item M-x gdb-nexti | |
6774 | Execute to next instruction, using the _GDBN__ @code{nexti} command; update | |
6775 | display window accordingly. | |
6776 | ||
6777 | @item C-c C-f | |
6778 | Execute until exit from the selected stack frame, like the _GDBN__ | |
6779 | @code{finish} command. | |
6780 | ||
6781 | @item M-c | |
29a2b744 | 6782 | Continue execution of your program, like the _GDBN__ @code{continue} |
1041a570 | 6783 | command. |
203eea5d RP |
6784 | |
6785 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
6786 | |
6787 | @item M-u | |
6788 | Go up the number of frames indicated by the numeric argument | |
6789 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
1041a570 | 6790 | like the _GDBN__ @code{up} command. |
203eea5d | 6791 | |
1041a570 | 6792 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
6793 | |
6794 | @item M-d | |
6795 | Go down the number of frames indicated by the numeric argument, like the | |
1041a570 | 6796 | _GDBN__ @code{down} command. |
203eea5d RP |
6797 | |
6798 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
6799 | |
6800 | @item C-x & | |
6801 | Read the number where the cursor is positioned, and insert it at the end | |
6802 | of the _GDBN__ I/O buffer. For example, if you wish to disassemble code | |
6803 | around an address that was displayed earlier, type @kbd{disassemble}; | |
6804 | then move the cursor to the address display, and pick up the | |
e251e767 | 6805 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 RP |
6806 | |
6807 | You can customize this further on the fly by defining elements of the list | |
6808 | @code{gdb-print-command}; once it is defined, you can format or | |
6809 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 6810 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
6811 | wish special formatting, and act as an index to pick an element of the |
6812 | list. If the list element is a string, the number to be inserted is | |
6813 | formatted using the Emacs function @code{format}; otherwise the number | |
6814 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
6815 | @end table |
6816 | ||
6817 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
6818 | tells _GDBN__ to set a breakpoint on the source line point is on. | |
6819 | ||
6820 | If you accidentally delete the source-display buffer, an easy way to get | |
6821 | it back is to type the command @code{f} in the _GDBN__ buffer, to | |
6822 | request a frame display; when you run under Emacs, this will recreate | |
6823 | the source buffer if necessary to show you the context of the current | |
6824 | frame. | |
6825 | ||
6826 | The source files displayed in Emacs are in ordinary Emacs buffers | |
6827 | which are visiting the source files in the usual way. You can edit | |
6828 | the files with these buffers if you wish; but keep in mind that _GDBN__ | |
6829 | communicates with Emacs in terms of line numbers. If you add or | |
6830 | delete lines from the text, the line numbers that _GDBN__ knows will cease | |
6831 | to correspond properly to the code. | |
6832 | ||
6833 | @c The following dropped because Epoch is nonstandard. Reactivate | |
6834 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
6835 | @ignore | |
e251e767 | 6836 | @kindex emacs epoch environment |
70b88761 RP |
6837 | @kindex epoch |
6838 | @kindex inspect | |
6839 | ||
6840 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
6841 | environment. Users of this environment can use a new command, | |
6842 | @code{inspect} which performs identically to @code{print} except that | |
6843 | each value is printed in its own window. | |
6844 | @end ignore | |
6845 | ||
6846 | @node _GDBN__ Bugs, Renamed Commands, Emacs, Top | |
6847 | @chapter Reporting Bugs in _GDBN__ | |
6848 | @cindex Bugs in _GDBN__ | |
6849 | @cindex Reporting Bugs in _GDBN__ | |
6850 | ||
6851 | Your bug reports play an essential role in making _GDBN__ reliable. | |
6852 | ||
6853 | Reporting a bug may help you by bringing a solution to your problem, or it | |
6854 | may not. But in any case the principal function of a bug report is to help | |
6855 | the entire community by making the next version of _GDBN__ work better. Bug | |
6856 | reports are your contribution to the maintenance of _GDBN__. | |
6857 | ||
6858 | In order for a bug report to serve its purpose, you must include the | |
6859 | information that enables us to fix the bug. | |
6860 | ||
6861 | @menu | |
b80282d5 RP |
6862 | * Bug Criteria:: Have You Found a Bug? |
6863 | * Bug Reporting:: How to Report Bugs | |
70b88761 RP |
6864 | @end menu |
6865 | ||
6866 | @node Bug Criteria, Bug Reporting, _GDBN__ Bugs, _GDBN__ Bugs | |
6867 | @section Have You Found a Bug? | |
6868 | @cindex Bug Criteria | |
6869 | ||
6870 | If you are not sure whether you have found a bug, here are some guidelines: | |
6871 | ||
6872 | @itemize @bullet | |
6873 | @item | |
6874 | @cindex Fatal Signal | |
6875 | @cindex Core Dump | |
6876 | If the debugger gets a fatal signal, for any input whatever, that is a | |
6877 | _GDBN__ bug. Reliable debuggers never crash. | |
6878 | ||
6879 | @item | |
6880 | @cindex error on Valid Input | |
6881 | If _GDBN__ produces an error message for valid input, that is a bug. | |
6882 | ||
6883 | @item | |
6884 | @cindex Invalid Input | |
6885 | If _GDBN__ does not produce an error message for invalid input, | |
6886 | that is a bug. However, you should note that your idea of | |
6887 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
6888 | for traditional practice''. | |
6889 | ||
6890 | @item | |
6891 | If you are an experienced user of debugging tools, your suggestions | |
6892 | for improvement of _GDBN__ are welcome in any case. | |
6893 | @end itemize | |
6894 | ||
6895 | @node Bug Reporting, , Bug Criteria, _GDBN__ Bugs | |
6896 | @section How to Report Bugs | |
6897 | @cindex Bug Reports | |
3d3ab540 | 6898 | @cindex _GDBN__ Bugs, Reporting |
70b88761 RP |
6899 | |
6900 | A number of companies and individuals offer support for GNU products. | |
6901 | If you obtained _GDBN__ from a support organization, we recommend you | |
e251e767 | 6902 | contact that organization first. |
70b88761 RP |
6903 | |
6904 | Contact information for many support companies and individuals is | |
6905 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
6906 | ||
6907 | In any event, we also recommend that you send bug reports for _GDBN__ to one | |
6908 | of these addresses: | |
6909 | ||
6910 | @example | |
6911 | bug-gdb@@prep.ai.mit.edu | |
6912 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
6913 | @end example | |
6914 | ||
6915 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
6916 | @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to | |
6917 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
6918 | ||
3d3ab540 RP |
6919 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
6920 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
6921 | the same messages. Often people think of posting bug reports to the | |
6922 | newsgroup instead of mailing them. This appears to work, but it has one | |
6923 | problem which can be crucial: a newsgroup posting often lacks a mail | |
6924 | path back to the sender. Thus, if we need to ask for more information, | |
6925 | we may be unable to reach you. For this reason, it is better to send | |
6926 | bug reports to the mailing list. | |
70b88761 RP |
6927 | |
6928 | As a last resort, send bug reports on paper to: | |
6929 | ||
6930 | @example | |
6931 | GNU Debugger Bugs | |
3d3ab540 | 6932 | Free Software Foundation |
70b88761 RP |
6933 | 545 Tech Square |
6934 | Cambridge, MA 02139 | |
6935 | @end example | |
6936 | ||
6937 | The fundamental principle of reporting bugs usefully is this: | |
6938 | @strong{report all the facts}. If you are not sure whether to state a | |
6939 | fact or leave it out, state it! | |
6940 | ||
6941 | Often people omit facts because they think they know what causes the | |
29a2b744 | 6942 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 6943 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 6944 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
6945 | stray memory reference which happens to fetch from the location where that |
6946 | name is stored in memory; perhaps, if the name were different, the contents | |
6947 | of that location would fool the debugger into doing the right thing despite | |
6948 | the bug. Play it safe and give a specific, complete example. That is the | |
6949 | easiest thing for you to do, and the most helpful. | |
6950 | ||
6951 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 6952 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
6953 | the bug is already known. Therefore, always write your bug reports on |
6954 | the assumption that the bug has not been reported previously. | |
6955 | ||
6956 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
6957 | bell?'' Those bug reports are useless, and we urge everyone to | |
6958 | @emph{refuse to respond to them} except to chide the sender to report | |
6959 | bugs properly. | |
6960 | ||
6961 | To enable us to fix the bug, you should include all these things: | |
6962 | ||
6963 | @itemize @bullet | |
6964 | @item | |
6965 | The version of _GDBN__. _GDBN__ announces it if you start with no | |
6966 | arguments; you can also print it at any time using @code{show version}. | |
6967 | ||
1041a570 | 6968 | Without this, we will not know whether there is any point in looking for |
70b88761 RP |
6969 | the bug in the current version of _GDBN__. |
6970 | ||
6971 | @item | |
ddf21240 JG |
6972 | The type of machine you are using, and the operating system name and |
6973 | version number. | |
70b88761 RP |
6974 | |
6975 | @item | |
6976 | What compiler (and its version) was used to compile _GDBN__---e.g. | |
6977 | ``_GCC__-1.37.1''. | |
6978 | ||
ddf21240 JG |
6979 | @item |
6980 | What compiler (and its version) was used to compile the program you | |
6981 | are debugging---e.g. ``_GCC__-1.37.1''. | |
6982 | ||
70b88761 RP |
6983 | @item |
6984 | The command arguments you gave the compiler to compile your example and | |
6985 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 6986 | you will not omit something important, list them all. A copy of the |
ddf21240 | 6987 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
6988 | |
6989 | If we were to try to guess the arguments, we would probably guess wrong | |
6990 | and then we might not encounter the bug. | |
6991 | ||
6992 | @item | |
ddf21240 JG |
6993 | A complete input script, and all necessary source files, that will |
6994 | reproduce the bug. | |
70b88761 RP |
6995 | |
6996 | @item | |
6997 | A description of what behavior you observe that you believe is | |
6998 | incorrect. For example, ``It gets a fatal signal.'' | |
6999 | ||
7000 | Of course, if the bug is that _GDBN__ gets a fatal signal, then we will | |
7001 | certainly notice it. But if the bug is incorrect output, we might not | |
7002 | notice unless it is glaringly wrong. We are human, after all. You | |
7003 | might as well not give us a chance to make a mistake. | |
7004 | ||
7005 | Even if the problem you experience is a fatal signal, you should still | |
7006 | say so explicitly. Suppose something strange is going on, such as, | |
7007 | your copy of _GDBN__ is out of synch, or you have encountered a | |
7008 | bug in the C library on your system. (This has happened!) Your copy | |
7009 | might crash and ours would not. If you told us to expect a crash, | |
7010 | then when ours fails to crash, we would know that the bug was not | |
7011 | happening for us. If you had not told us to expect a crash, then we | |
7012 | would not be able to draw any conclusion from our observations. | |
7013 | ||
7014 | @item | |
7015 | If you wish to suggest changes to the _GDBN__ source, send us context | |
7016 | diffs. If you even discuss something in the _GDBN__ source, refer to | |
7017 | it by context, not by line number. | |
7018 | ||
1041a570 | 7019 | The line numbers in our development sources will not match those in your |
70b88761 | 7020 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
7021 | @end itemize |
7022 | ||
7023 | Here are some things that are not necessary: | |
7024 | ||
7025 | @itemize @bullet | |
7026 | @item | |
7027 | A description of the envelope of the bug. | |
7028 | ||
7029 | Often people who encounter a bug spend a lot of time investigating | |
7030 | which changes to the input file will make the bug go away and which | |
7031 | changes will not affect it. | |
7032 | ||
7033 | This is often time consuming and not very useful, because the way we | |
7034 | will find the bug is by running a single example under the debugger | |
7035 | with breakpoints, not by pure deduction from a series of examples. | |
7036 | We recommend that you save your time for something else. | |
7037 | ||
7038 | Of course, if you can find a simpler example to report @emph{instead} | |
7039 | of the original one, that is a convenience for us. Errors in the | |
7040 | output will be easier to spot, running under the debugger will take | |
e251e767 | 7041 | less time, etc. |
70b88761 | 7042 | |
29a2b744 | 7043 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
7044 | report the bug anyway and send us the entire test case you used. |
7045 | ||
7046 | @item | |
7047 | A patch for the bug. | |
7048 | ||
29a2b744 | 7049 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
7050 | the necessary information, such as the test case, on the assumption that |
7051 | a patch is all we need. We might see problems with your patch and decide | |
7052 | to fix the problem another way, or we might not understand it at all. | |
7053 | ||
7054 | Sometimes with a program as complicated as _GDBN__ it is very hard to | |
7055 | construct an example that will make the program follow a certain path | |
1041a570 RP |
7056 | through the code. If you do not send us the example, we will not be able |
7057 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 7058 | |
29a2b744 | 7059 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 7060 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
7061 | help us to understand. |
7062 | ||
7063 | @item | |
7064 | A guess about what the bug is or what it depends on. | |
7065 | ||
29a2b744 | 7066 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
7067 | things without first using the debugger to find the facts. |
7068 | @end itemize | |
7069 | ||
1041a570 RP |
7070 | @c Note: no need to update nodes for rdl-apps.texi since it appears |
7071 | @c *only* in the TeX version of the manual. | |
7072 | @c Note: eventually, make a cross reference to the readline Info nodes. | |
70b88761 | 7073 | @iftex |
cacf5942 RP |
7074 | @c appendices describing GNU readline. Distributed with readline code. |
7075 | @include rluser.texinfo | |
7076 | @include inc-hist.texi | |
70b88761 RP |
7077 | @end iftex |
7078 | ||
7079 | @node Renamed Commands, Installing _GDBN__, _GDBN__ Bugs, Top | |
7080 | @appendix Renamed Commands | |
7081 | ||
1041a570 | 7082 | The following commands were renamed in _GDBN__ 4, in order to make the |
70b88761 RP |
7083 | command set as a whole more consistent and easier to use and remember: |
7084 | ||
e251e767 RP |
7085 | @kindex add-syms |
7086 | @kindex delete environment | |
7087 | @kindex info copying | |
7088 | @kindex info convenience | |
7089 | @kindex info directories | |
7090 | @kindex info editing | |
7091 | @kindex info history | |
7092 | @kindex info targets | |
7093 | @kindex info values | |
7094 | @kindex info version | |
7095 | @kindex info warranty | |
7096 | @kindex set addressprint | |
7097 | @kindex set arrayprint | |
7098 | @kindex set prettyprint | |
7099 | @kindex set screen-height | |
7100 | @kindex set screen-width | |
7101 | @kindex set unionprint | |
7102 | @kindex set vtblprint | |
7103 | @kindex set demangle | |
7104 | @kindex set asm-demangle | |
7105 | @kindex set sevenbit-strings | |
7106 | @kindex set array-max | |
7107 | @kindex set caution | |
7108 | @kindex set history write | |
7109 | @kindex show addressprint | |
7110 | @kindex show arrayprint | |
7111 | @kindex show prettyprint | |
7112 | @kindex show screen-height | |
7113 | @kindex show screen-width | |
7114 | @kindex show unionprint | |
7115 | @kindex show vtblprint | |
7116 | @kindex show demangle | |
7117 | @kindex show asm-demangle | |
7118 | @kindex show sevenbit-strings | |
7119 | @kindex show array-max | |
7120 | @kindex show caution | |
7121 | @kindex show history write | |
7122 | @kindex unset | |
70b88761 | 7123 | |
92b73793 | 7124 | @c TEXI2ROFF-KILL |
70b88761 | 7125 | @ifinfo |
92b73793 | 7126 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7127 | @example |
7128 | OLD COMMAND NEW COMMAND | |
92b73793 | 7129 | @c TEXI2ROFF-KILL |
cf496415 | 7130 | --------------- ------------------------------- |
92b73793 | 7131 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7132 | add-syms add-symbol-file |
7133 | delete environment unset environment | |
7134 | info convenience show convenience | |
7135 | info copying show copying | |
e251e767 | 7136 | info directories show directories |
cf496415 RP |
7137 | info editing show commands |
7138 | info history show values | |
7139 | info targets help target | |
7140 | info values show values | |
7141 | info version show version | |
7142 | info warranty show warranty | |
7143 | set/show addressprint set/show print address | |
7144 | set/show array-max set/show print elements | |
7145 | set/show arrayprint set/show print array | |
7146 | set/show asm-demangle set/show print asm-demangle | |
7147 | set/show caution set/show confirm | |
7148 | set/show demangle set/show print demangle | |
7149 | set/show history write set/show history save | |
7150 | set/show prettyprint set/show print pretty | |
7151 | set/show screen-height set/show height | |
7152 | set/show screen-width set/show width | |
7153 | set/show sevenbit-strings set/show print sevenbit-strings | |
7154 | set/show unionprint set/show print union | |
7155 | set/show vtblprint set/show print vtbl | |
7156 | ||
7157 | unset [No longer an alias for delete] | |
7158 | @end example | |
92b73793 | 7159 | @c TEXI2ROFF-KILL |
70b88761 RP |
7160 | @end ifinfo |
7161 | ||
7162 | @tex | |
7163 | \vskip \parskip\vskip \baselineskip | |
7164 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
7165 | {\bf Old Command} &&{\bf New Command}\cr | |
7166 | add-syms &&add-symbol-file\cr | |
7167 | delete environment &&unset environment\cr | |
7168 | info convenience &&show convenience\cr | |
7169 | info copying &&show copying\cr | |
7170 | info directories &&show directories \cr | |
7171 | info editing &&show commands\cr | |
7172 | info history &&show values\cr | |
7173 | info targets &&help target\cr | |
7174 | info values &&show values\cr | |
7175 | info version &&show version\cr | |
7176 | info warranty &&show warranty\cr | |
7177 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
7178 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
7179 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
7180 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
7181 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
7182 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
7183 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
7184 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
7185 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
7186 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
7187 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
7188 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
7189 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
7190 | \cr | |
7191 | unset &&\rm(No longer an alias for delete)\cr | |
7192 | } | |
7193 | @end tex | |
92b73793 | 7194 | @c END TEXI2ROFF-KILL |
70b88761 RP |
7195 | |
7196 | @node Installing _GDBN__, Copying, Renamed Commands, Top | |
7197 | @appendix Installing _GDBN__ | |
7198 | @cindex configuring _GDBN__ | |
7199 | @cindex installation | |
7200 | ||
b80282d5 RP |
7201 | _GDBN__ comes with a @code{configure} script that automates the process |
7202 | of preparing _GDBN__ for installation; you can then use @code{make} to | |
7203 | build the @code{_GDBP__} program. | |
7204 | ||
1041a570 RP |
7205 | The _GDBN__ distribution includes all the source code you need for _GDBN__ in |
7206 | a single directory, whose name is usually composed by appending the | |
7207 | version number to @samp{gdb}. | |
7208 | ||
7209 | For example, the _GDBN__ version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__} | |
7210 | directory. That directory contains: | |
b80282d5 | 7211 | |
3d3ab540 | 7212 | @table @code |
c7637ea6 RP |
7213 | @item gdb-_GDB_VN__/configure @r{(and supporting files)} |
7214 | script for configuring _GDBN__ and all its supporting libraries. | |
b80282d5 | 7215 | |
3e0d0a27 | 7216 | @item gdb-_GDB_VN__/gdb |
3d3ab540 RP |
7217 | the source specific to _GDBN__ itself |
7218 | ||
3e0d0a27 | 7219 | @item gdb-_GDB_VN__/bfd |
3d3ab540 RP |
7220 | source for the Binary File Descriptor Library |
7221 | ||
3e0d0a27 | 7222 | @item gdb-_GDB_VN__/include |
b80282d5 | 7223 | GNU include files |
3d3ab540 | 7224 | |
3e0d0a27 | 7225 | @item gdb-_GDB_VN__/libiberty |
3d3ab540 RP |
7226 | source for the @samp{-liberty} free software library |
7227 | ||
3e0d0a27 | 7228 | @item gdb-_GDB_VN__/readline |
b80282d5 | 7229 | source for the GNU command-line interface |
3d3ab540 | 7230 | @end table |
1041a570 RP |
7231 | |
7232 | The simplest way to configure and build _GDBN__ is to run @code{configure} | |
7233 | from the @file{gdb-@var{version-number}} source directory, which in | |
7234 | this example is the @file{gdb-_GDB_VN__} directory. | |
7235 | ||
7236 | First switch to the @file{gdb-@var{version-number}} source directory | |
7237 | if you are not already in it; then run @code{configure}. Pass the | |
7238 | identifier for the platform on which _GDBN__ will run as an | |
7239 | argument. | |
7240 | ||
7241 | For example: | |
7242 | ||
7463aadd | 7243 | @example |
3e0d0a27 | 7244 | cd gdb-_GDB_VN__ |
3d3ab540 | 7245 | ./configure @var{host} |
7463aadd RP |
7246 | make |
7247 | @end example | |
1041a570 | 7248 | |
7463aadd | 7249 | @noindent |
1041a570 RP |
7250 | where @var{host} is an identifier such as @samp{sun4} or |
7251 | @samp{decstation}, that identifies the platform where _GDBN__ will run. | |
7252 | ||
7253 | This @code{configure} command builds the three libraries @file{bfd}, | |
7254 | @file{readline}, and @file{libiberty}, then @code{gdb} itself. The | |
7255 | configured source files, and the binaries, are left in the | |
7256 | corresponding source directories. | |
3d3ab540 | 7257 | |
e251e767 | 7258 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 7259 | system does not recognize this automatically when you run a different |
1041a570 RP |
7260 | shell, you may need to run @code{sh} on it explicitly: |
7261 | ||
7262 | @example | |
7263 | sh configure @var{host} | |
7264 | @end example | |
e251e767 RP |
7265 | |
7266 | You can @emph{run} the @code{configure} script from any of the | |
1041a570 RP |
7267 | subordinate directories in the _GDBN__ distribution, if you only want to |
7268 | configure that subdirectory; but be sure to specify a path to it. | |
7269 | ||
7270 | For example, with version _GDB_VN__, type the following to configure only | |
7271 | the @code{bfd} subdirectory: | |
7272 | ||
e251e767 | 7273 | @example |
203eea5d | 7274 | @group |
e251e767 RP |
7275 | cd gdb-_GDB_VN__/bfd |
7276 | ../configure @var{host} | |
203eea5d | 7277 | @end group |
e251e767 RP |
7278 | @end example |
7279 | ||
1041a570 RP |
7280 | You can install @code{_GDBP__} anywhere; it has no hardwired paths. |
7281 | However, you should make sure that the shell on your path (named by | |
7282 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
7283 | that _GDBN__ uses the shell to start your program---some systems refuse to | |
7284 | let _GDBN__ debug child processes whose programs are not readable. | |
3d3ab540 RP |
7285 | |
7286 | @menu | |
b80282d5 RP |
7287 | * Subdirectories:: Configuration subdirectories |
7288 | * Config Names:: Specifying names for hosts and targets | |
7289 | * configure Options:: Summary of options for configure | |
d7b569d5 | 7290 | * Formatting Documentation:: How to format and print _GDBN__ documentation |
3d3ab540 RP |
7291 | @end menu |
7292 | ||
b80282d5 | 7293 | @node Subdirectories, Config Names, Installing _GDBN__, Installing _GDBN__ |
3d3ab540 | 7294 | @section Configuration Subdirectories |
1041a570 | 7295 | |
b80282d5 | 7296 | If you want to run _GDBN__ versions for several host or target machines, |
1041a570 RP |
7297 | you'll need a different @code{_GDBP__} compiled for each combination of |
7298 | host and target. @code{configure} is designed to make this easy by | |
7299 | allowing you to generate each configuration in a separate | |
7300 | subdirectory. If your @code{make} program handles the @samp{VPATH} | |
7301 | feature (GNU @code{make} does), running @code{make} in each of these | |
7302 | directories then builds the @code{_GDBP__} program specified there. | |
b80282d5 RP |
7303 | |
7304 | @code{configure} creates these subdirectories for you when you | |
29a2b744 | 7305 | simultaneously specify several configurations; but it is a good habit |
b80282d5 RP |
7306 | even for a single configuration. You can specify the use of |
7307 | subdirectories using the @samp{+subdirs} option (abbreviated | |
1041a570 RP |
7308 | @samp{+sub}). |
7309 | ||
7310 | For example, with version _GDB_VN__, you can build _GDBN__ on a | |
7311 | Sun 4 like this: | |
70b88761 RP |
7312 | |
7313 | @example | |
3d3ab540 | 7314 | @group |
3e0d0a27 | 7315 | cd gdb-_GDB_VN__ |
b80282d5 | 7316 | ./configure +sub sun4 |
c7637ea6 | 7317 | cd H-sun4/T-sun4 |
70b88761 | 7318 | make |
3d3ab540 | 7319 | @end group |
70b88761 RP |
7320 | @end example |
7321 | ||
3d3ab540 RP |
7322 | When @code{configure} uses subdirectories to build programs or |
7323 | libraries, it creates nested directories | |
c7637ea6 RP |
7324 | @file{H-@var{host}/T-@var{target}}. @code{configure} uses these two |
7325 | directory levels because _GDBN__ can be configured for cross-compiling: | |
7326 | _GDBN__ can run on one machine (the host) while debugging programs that | |
7327 | run on another machine (the target). You specify cross-debugging | |
7328 | targets by giving the @samp{+target=@var{target}} option to | |
7329 | @code{configure}. Specifying only hosts still gives you two levels of | |
7330 | subdirectory for each host, with the same configuration suffix on both; | |
7331 | that is, if you give any number of hosts but no targets, _GDBN__ will be | |
7332 | configured for native debugging on each host. On the other hand, | |
7333 | whenever you specify both hosts and targets on the same command line, | |
7334 | @code{configure} creates all combinations of the hosts and targets you | |
1041a570 RP |
7335 | list. |
7336 | ||
7337 | If you run @code{configure} from a directory that contains source | |
7338 | directories for multiple libraries or programs, such as the | |
7339 | @file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure} | |
7340 | creates the @file{H-@var{host}/T-@var{target}} subdirectories in each | |
7341 | library or program's source directory. | |
7342 | ||
7343 | For example, with version _GDB_VN__, typing: | |
c7637ea6 | 7344 | |
3d3ab540 | 7345 | @example |
3e0d0a27 | 7346 | cd gdb-_GDB_VN__ |
b80282d5 | 7347 | configure sun4 +target=vxworks960 |
3d3ab540 | 7348 | @end example |
1041a570 | 7349 | |
3d3ab540 RP |
7350 | @noindent |
7351 | creates the following directories: | |
1041a570 | 7352 | |
203eea5d | 7353 | @example |
c7637ea6 RP |
7354 | gdb-_GDB_VN__/H-sun4/T-vxworks960 |
7355 | gdb-_GDB_VN__/bfd/H-sun4/T-vxworks960 | |
7356 | gdb-_GDB_VN__/gdb/H-sun4/T-vxworks960 | |
7357 | gdb-_GDB_VN__/libiberty/H-sun4/T-vxworks960 | |
7358 | gdb-_GDB_VN__/readline/H-sun4/T-vxworks960 | |
203eea5d | 7359 | @end example |
c7637ea6 | 7360 | |
1041a570 RP |
7361 | When you run @code{make} to build a program or library, you must run |
7362 | it in a configured directory. If you made a single configuration, | |
7363 | without subdirectories, run @code{make} in the source directory. If | |
7364 | you have @file{H-@var{host}/T-@var{target}} subdirectories, run | |
7365 | @code{make} in those subdirectories. | |
c7637ea6 RP |
7366 | |
7367 | The @code{Makefile} generated by @code{configure} for each source | |
1041a570 RP |
7368 | directory runs recursively. If you type @code{make} in a source |
7369 | directory such as @file{gdb-_GDB_VN__} (or in a subdirectory, such as | |
7370 | @file{gdb-_GDB_VN__/H-@var{host}/T-@var{target}}), you will build all the | |
7371 | required libraries, then build _GDBN__. | |
3d3ab540 RP |
7372 | |
7373 | When you have multiple hosts or targets configured, you can run | |
7374 | @code{make} on them in parallel (for example, if they are NFS-mounted on | |
7375 | each of the hosts); they will not interfere with each other. | |
7376 | ||
c7637ea6 RP |
7377 | You can also use the @samp{+objdir=@var{altroot}} option to have the |
7378 | configured files placed in a parallel directory structure rather than | |
1041a570 RP |
7379 | alongside the source files; @pxref{configure Options, |
7380 | ,@code{configure} Options}. | |
7d7ff5f6 | 7381 | |
b80282d5 RP |
7382 | @node Config Names, configure Options, Subdirectories, Installing _GDBN__ |
7383 | @section Specifying Names for Hosts and Targets | |
7384 | ||
7385 | The specifications used for hosts and targets in the @code{configure} | |
7386 | script are based on a three-part naming scheme, but some short predefined | |
7387 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 7388 | of information in the following pattern: |
1041a570 | 7389 | |
b80282d5 RP |
7390 | @example |
7391 | @var{architecture}-@var{vendor}-@var{os} | |
7392 | @end example | |
7393 | ||
7394 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
e251e767 RP |
7395 | or in a @code{+target=@var{target}} option, but the equivalent full name |
7396 | is @samp{sparc-sun-sunos4}. | |
b80282d5 | 7397 | |
1041a570 RP |
7398 | The following table shows all the architectures, hosts, and OS |
7399 | prefixes that @code{configure} recognizes in _GDBN__ version _GDB_VN__. Entries | |
7400 | in the ``OS prefix'' column ending in a @samp{*} may be followed by a | |
7401 | release number. | |
b80282d5 | 7402 | |
1041a570 | 7403 | @c FIXME! Update for gdb 4.4 |
92b73793 | 7404 | @c TEXI2ROFF-KILL |
b80282d5 | 7405 | @ifinfo |
92b73793 | 7406 | @c END TEXI2ROFF-KILL |
b80282d5 RP |
7407 | @example |
7408 | ||
203eea5d | 7409 | ARCHITECTURE VENDOR OS prefix |
92b73793 | 7410 | @c TEXI2ROFF-KILL |
203eea5d | 7411 | ------------+--------------------------+--------------------------- |
92b73793 | 7412 | @c END TEXI2ROFF-KILL |
203eea5d RP |
7413 | | | |
7414 | 580 | altos hp | aix* msdos* | |
7415 | a29k | amd ibm | amigados newsos* | |
7416 | alliant | amdahl intel | aout nindy* | |
7417 | arm | aout isi | bout osf* | |
7418 | c1 | apollo little | bsd* sco* | |
7419 | c2 | att mips | coff sunos* | |
7420 | cray2 | bcs motorola | ctix* svr4 | |
7421 | h8300 | bout ncr | dgux* sym* | |
7422 | i386 | bull next | dynix* sysv* | |
7423 | i860 | cbm nyu | ebmon ultrix* | |
7424 | i960 | coff sco | esix* unicos* | |
7425 | m68000 | convergent sequent | hds unos* | |
7426 | m68k | convex sgi | hpux* uts | |
7427 | m88k | cray sony | irix* v88r* | |
7428 | mips | dec sun | isc* vms* | |
7429 | ns32k | encore unicom | kern vxworks* | |
7430 | pyramid | gould utek | mach* | |
7431 | romp | hitachi wrs | | |
7432 | rs6000 | | | |
7433 | sparc | | | |
7434 | tahoe | | | |
7435 | tron | | | |
7436 | vax | | | |
7437 | xmp | | | |
7438 | ymp | | | |
b80282d5 | 7439 | @end example |
1041a570 | 7440 | |
92b73793 | 7441 | @c TEXI2ROFF-KILL |
b80282d5 RP |
7442 | @end ifinfo |
7443 | @tex | |
c338a2fd RP |
7444 | %\vskip\parskip |
7445 | \vskip \baselineskip | |
203eea5d RP |
7446 | \hfil\vbox{\offinterlineskip |
7447 | \halign{\strut\tt #\hfil\ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil | |
7448 | \ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil \cr | |
7449 | {\bf Architecture} &&{\bf Vendor} &&&{\bf OS prefix}\cr | |
7450 | \multispan7\hrulefill\cr | |
7451 | 580 && altos & hp && aix* & msdos* \cr | |
7452 | a29k && amd & ibm && amigados & newsos* \cr | |
7453 | alliant && amdahl & intel && aout & nindy* \cr | |
7454 | arm && aout & isi && bout & osf* \cr | |
7455 | c1 && apollo & little && bsd* & sco* \cr | |
7456 | c2 && att & mips && coff & sunos* \cr | |
7457 | cray2 && bcs & motorola && ctix* & svr4 \cr | |
7458 | h8300 && bout & ncr && dgux* & sym* \cr | |
7459 | i386 && bull & next && dynix* & sysv* \cr | |
7460 | i860 && cbm & nyu && ebmon & ultrix* \cr | |
7461 | i960 && coff & sco && esix* & unicos* \cr | |
7462 | m68000 && convergent& sequent && hds & unos* \cr | |
7463 | m68k && convex & sgi && hpux* & uts \cr | |
7464 | m88k && cray & sony && irix* & v88r* \cr | |
7465 | mips && dec & sun && isc* & vms* \cr | |
7466 | ns32k && encore & unicom && kern & vxworks* \cr | |
7467 | pyramid && gould & utek && mach* & \cr | |
7468 | romp && hitachi & wrs && & \cr | |
7469 | rs6000 && & && & \cr | |
7470 | sparc && & && & \cr | |
7471 | tahoe && & && & \cr | |
7472 | tron && & && & \cr | |
7473 | vax && & && & \cr | |
7474 | xmp && & && & \cr | |
7475 | ymp && & && & \cr | |
7476 | }\hfil} | |
1041a570 | 7477 | @end tex |
92b73793 | 7478 | @c END TEXI2ROFF-KILL |
1041a570 | 7479 | |
203eea5d | 7480 | @quotation |
a6d0b6d3 RP |
7481 | @emph{Warning:} @code{configure} can represent a very large number of |
7482 | combinations of architecture, vendor, and OS. There is by no means | |
7483 | support available for all possible combinations! | |
203eea5d | 7484 | @end quotation |
b80282d5 | 7485 | |
1041a570 | 7486 | The @code{configure} script accompanying _GDBN__ does not provide |
b80282d5 RP |
7487 | any query facility to list all supported host and target names or |
7488 | aliases. @code{configure} calls the Bourne shell script | |
7489 | @code{config.sub} to map abbreviations to full names; you can read the | |
7490 | script, if you wish, or you can use it to test your guesses on | |
7491 | abbreviations---for example: | |
1041a570 | 7492 | |
b80282d5 RP |
7493 | @example |
7494 | % sh config.sub sun4 | |
7495 | sparc-sun-sunos4 | |
7496 | % sh config.sub sun3 | |
7497 | m68k-sun-sunos4 | |
7498 | % sh config.sub decstation | |
7499 | mips-dec-ultrix | |
7500 | % sh config.sub hp300bsd | |
7501 | m68k-hp-bsd | |
7502 | % sh config.sub i386v | |
7503 | i386-none-sysv | |
7504 | % sh config.sub i486v | |
c7637ea6 | 7505 | *** Configuration "i486v" not recognized |
b80282d5 | 7506 | @end example |
1041a570 | 7507 | |
c7637ea6 | 7508 | @noindent |
1041a570 RP |
7509 | @code{config.sub} is also distributed in the GDB source |
7510 | directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__). | |
b80282d5 | 7511 | |
d7b569d5 | 7512 | @node configure Options, Formatting Documentation, Config Names, Installing _GDBN__ |
3d3ab540 | 7513 | @section @code{configure} Options |
7463aadd RP |
7514 | |
7515 | Here is a summary of all the @code{configure} options and arguments that | |
7516 | you might use for building _GDBN__: | |
7517 | ||
7518 | @example | |
c7637ea6 RP |
7519 | configure @r{[}+destdir=@var{dir}@r{]} @r{[}+subdirs@r{]} |
7520 | @r{[}+objdir=@var{altroot}@r{]} @r{[}+norecursion@r{]} @r{[}+rm@r{]} | |
b80282d5 | 7521 | @r{[}+target=@var{target}@dots{}@r{]} @var{host}@dots{} |
7463aadd | 7522 | @end example |
1041a570 | 7523 | |
3d3ab540 | 7524 | @noindent |
7463aadd | 7525 | You may introduce options with the character @samp{-} rather than |
b80282d5 RP |
7526 | @samp{+} if you prefer; but you may abbreviate option names if you use |
7527 | @samp{+}. | |
70b88761 RP |
7528 | |
7529 | @table @code | |
7463aadd | 7530 | @item +destdir=@var{dir} |
3d3ab540 RP |
7531 | @var{dir} is an installation directory @emph{path prefix}. After you |
7532 | configure with this option, @code{make install} will install _GDBN__ as | |
7533 | @file{@var{dir}/bin/_GDBP__}, and the libraries in @file{@var{dir}/lib}. | |
7534 | If you specify @samp{+destdir=/usr/local}, for example, @code{make | |
1041a570 | 7535 | install} creates @file{/usr/local/bin/gdb}. |
7463aadd | 7536 | |
b80282d5 | 7537 | @item +subdirs |
3d3ab540 | 7538 | Write configuration specific files in subdirectories of the form |
1041a570 | 7539 | |
7463aadd | 7540 | @example |
c7637ea6 | 7541 | H-@var{host}/T-@var{target} |
7463aadd | 7542 | @end example |
1041a570 | 7543 | |
7463aadd | 7544 | @noindent |
e251e767 RP |
7545 | (and configure the @code{Makefile} to generate object code in |
7546 | subdirectories of this form as well). Without this option, if you | |
7547 | specify only one configuration for _GDBN__, @code{configure} will use | |
7548 | the same directory for source, configured files, and binaries. This | |
7549 | option is used automatically if you specify more than one @var{host} or | |
7550 | more than one @samp{+target=@var{target}} option on the @code{configure} | |
7551 | command line. | |
7463aadd | 7552 | |
c7637ea6 | 7553 | @item +norecursion |
7463aadd RP |
7554 | Configure only the directory where @code{configure} is executed; do not |
7555 | propagate configuration to subdirectories. | |
7556 | ||
c7637ea6 RP |
7557 | @item +objdir=@var{altroot} |
7558 | @var{altroot} is an alternative directory used as the root for | |
7559 | configured files. @code{configure} will create directories under | |
7560 | @var{altroot} in parallel to the source directories. If you use | |
7561 | @samp{+objdir=@var{altroot}} with @samp{+subdirs}, @code{configure} also | |
7562 | builds the @samp{H-@var{host}/T-@var{target}} subdirectories in the | |
7563 | directory tree rooted in @var{altroot}. | |
7564 | ||
7463aadd | 7565 | @item +rm |
b80282d5 | 7566 | Remove the configuration that the other arguments specify. |
7463aadd | 7567 | |
29a2b744 | 7568 | @c This does not work (yet if ever). FIXME. |
d7b569d5 RP |
7569 | @c @item +parse=@var{lang} @dots{} |
7570 | @c Configure the _GDBN__ expression parser to parse the listed languages. | |
7571 | @c @samp{all} configures _GDBN__ for all supported languages. To get a | |
7572 | @c list of all supported languages, omit the argument. Without this | |
7573 | @c option, _GDBN__ is configured to parse all supported languages. | |
c2bbbb22 | 7574 | |
b80282d5 | 7575 | @item +target=@var{target} @dots{} |
3d3ab540 | 7576 | Configure _GDBN__ for cross-debugging programs running on each specified |
b80282d5 RP |
7577 | @var{target}. You may specify as many @samp{+target} options as you |
7578 | wish. Without this option, _GDBN__ is configured to debug programs that | |
7579 | run on the same machine (@var{host}) as _GDBN__ itself. | |
7580 | ||
7581 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
7582 | |
7583 | @item @var{host} @dots{} | |
3d3ab540 | 7584 | Configure _GDBN__ to run on each specified @var{host}. You may specify as |
e251e767 | 7585 | many host names as you wish. |
b80282d5 RP |
7586 | |
7587 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
7588 | @end table |
7589 | ||
3d3ab540 RP |
7590 | @noindent |
7591 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 7592 | configuring other GNU tools recursively; but these are the only |
3d3ab540 RP |
7593 | options that affect _GDBN__ or its supporting libraries. |
7594 | ||
d7b569d5 RP |
7595 | @node Formatting Documentation, , configure Options, Installing _GDBN__ |
7596 | @section Formatting the Documentation | |
7597 | ||
1041a570 RP |
7598 | All the documentation for _GDBN__, including this manual, comes as part of |
7599 | the distribution. The documentation is written in Texinfo format, | |
7600 | which is a documentation system that uses a single source file to | |
7601 | produce both on-line information and a printed manual. You can use | |
7602 | one of the Info formatting commands to create the on-line version of | |
7603 | the documentation and @TeX{} (or @code{texi2roff}) to typeset the | |
7604 | printed version. | |
7605 | ||
7606 | _GDBN__ includes an already formatted copy of the on-line Info version of | |
7607 | this manual in the @file{gdb} subdirectory. The main Info file is | |
7608 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
7609 | subordinate files matching @samp{gdb.info*} in the same directory. | |
7610 | ||
7611 | If you want to format these Info files yourself, you need one of the | |
7612 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
7613 | @code{makeinfo}. | |
7614 | ||
7615 | If you have @code{makeinfo} installed, and are in the top level _GDBN__ | |
7616 | source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can | |
7617 | make the Info file by typing: | |
b80282d5 | 7618 | |
3d3ab540 | 7619 | @example |
1041a570 | 7620 | cd gdb |
3d3ab540 RP |
7621 | make gdb.info |
7622 | @end example | |
3d3ab540 | 7623 | |
1041a570 RP |
7624 | If you want to typeset and print copies of this manual, you need |
7625 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
7626 | the Texinfo definitions file. | |
7627 | ||
7628 | @TeX{} is typesetting program; it does not print files directly, but | |
7629 | produces output files called @sc{dvi} files. To print a typeset | |
7630 | document, you need a program to print @sc{dvi} files. If your system | |
7631 | has @TeX{} installed, chances are it has such a program. The precise | |
7632 | command to use depends on your system; @kbd{lpr -d} is common; another | |
7633 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
7634 | without any extension or a @samp{.dvi} extension. | |
7635 | ||
7636 | @TeX{} also requires a macro definitions file called | |
7637 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
7638 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
7639 | typeset a Texinfo file. @file{texinfo.tex} is distributed with _GDBN__ | |
7640 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
7641 | directory. | |
7642 | ||
7643 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
7644 | typeset and print this manual. First switch to the the @file{gdb} | |
7645 | subdirectory of the main source directory (for example, to | |
7646 | @file{gdb-_GDB_VN__/gdb}) and then type: | |
7647 | ||
3d3ab540 | 7648 | @example |
3d3ab540 RP |
7649 | make gdb.dvi |
7650 | @end example | |
3d3ab540 | 7651 | |
1041a570 RP |
7652 | @cindex _GDBN__ reference card |
7653 | @cindex reference card | |
7654 | In addition to the manual, the _GDBN__ 4 release includes a three-column | |
7655 | reference card. Format the _GDBN__ reference card by typing: | |
7656 | ||
b80282d5 | 7657 | @example |
b80282d5 RP |
7658 | make refcard.dvi |
7659 | @end example | |
b80282d5 RP |
7660 | |
7661 | The _GDBN__ reference card is designed to print in landscape mode on US | |
7662 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
7663 | high. You will need to specify this form of printing as an option to | |
7664 | your @sc{dvi} output program. | |
7665 | ||
1041a570 RP |
7666 | The GDB 4 release includes an already-formatted reference card, ready |
7667 | for printing on a PostScript or GhostScript printer, in the @file{gdb} | |
7668 | subdirectory of the main source directory---in | |
7669 | @file{gdb-4.2/gdb/refcard.ps} of the version 4.2 release. If you have | |
7670 | a PostScript or GhostScript printer, you can print the reference card | |
7671 | by just sending @file{refcard.ps} to the printer. | |
b80282d5 | 7672 | |
70b88761 | 7673 | @node Copying, Index, Installing _GDBN__, Top |
70b88761 | 7674 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 7675 | @center Version 2, June 1991 |
70b88761 RP |
7676 | |
7677 | @display | |
7463aadd | 7678 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
7679 | 675 Mass Ave, Cambridge, MA 02139, USA |
7680 | ||
7681 | Everyone is permitted to copy and distribute verbatim copies | |
7682 | of this license document, but changing it is not allowed. | |
7683 | @end display | |
7684 | ||
7685 | @unnumberedsec Preamble | |
7686 | ||
7463aadd RP |
7687 | The licenses for most software are designed to take away your |
7688 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 7689 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
7690 | software---to make sure the software is free for all its users. This |
7691 | General Public License applies to most of the Free Software | |
7692 | Foundation's software and to any other program whose authors commit to | |
7693 | using it. (Some other Free Software Foundation software is covered by | |
7694 | the GNU Library General Public License instead.) You can apply it to | |
7695 | your programs, too. | |
70b88761 RP |
7696 | |
7697 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
7698 | price. Our General Public Licenses are designed to make sure that you |
7699 | have the freedom to distribute copies of free software (and charge for | |
7700 | this service if you wish), that you receive source code or can get it | |
7701 | if you want it, that you can change the software or use pieces of it | |
7702 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
7703 | |
7704 | To protect your rights, we need to make restrictions that forbid | |
7705 | anyone to deny you these rights or to ask you to surrender the rights. | |
7706 | These restrictions translate to certain responsibilities for you if you | |
7707 | distribute copies of the software, or if you modify it. | |
7708 | ||
7463aadd | 7709 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
7710 | gratis or for a fee, you must give the recipients all the rights that |
7711 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
7712 | source code. And you must show them these terms so they know their |
7713 | rights. | |
70b88761 RP |
7714 | |
7715 | We protect your rights with two steps: (1) copyright the software, and | |
7716 | (2) offer you this license which gives you legal permission to copy, | |
7717 | distribute and/or modify the software. | |
7718 | ||
7719 | Also, for each author's protection and ours, we want to make certain | |
7720 | that everyone understands that there is no warranty for this free | |
7721 | software. If the software is modified by someone else and passed on, we | |
7722 | want its recipients to know that what they have is not the original, so | |
7723 | that any problems introduced by others will not reflect on the original | |
7724 | authors' reputations. | |
7725 | ||
7463aadd RP |
7726 | Finally, any free program is threatened constantly by software |
7727 | patents. We wish to avoid the danger that redistributors of a free | |
7728 | program will individually obtain patent licenses, in effect making the | |
7729 | program proprietary. To prevent this, we have made it clear that any | |
7730 | patent must be licensed for everyone's free use or not licensed at all. | |
7731 | ||
70b88761 RP |
7732 | The precise terms and conditions for copying, distribution and |
7733 | modification follow. | |
7734 | ||
7735 | @iftex | |
7463aadd | 7736 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
7737 | @end iftex |
7738 | @ifinfo | |
7463aadd | 7739 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
7740 | @end ifinfo |
7741 | ||
7742 | @enumerate | |
7743 | @item | |
7463aadd RP |
7744 | This License applies to any program or other work which contains |
7745 | a notice placed by the copyright holder saying it may be distributed | |
7746 | under the terms of this General Public License. The ``Program'', below, | |
7747 | refers to any such program or work, and a ``work based on the Program'' | |
7748 | means either the Program or any derivative work under copyright law: | |
7749 | that is to say, a work containing the Program or a portion of it, | |
7750 | either verbatim or with modifications and/or translated into another | |
7751 | language. (Hereinafter, translation is included without limitation in | |
7752 | the term ``modification''.) Each licensee is addressed as ``you''. | |
7753 | ||
7754 | Activities other than copying, distribution and modification are not | |
7755 | covered by this License; they are outside its scope. The act of | |
7756 | running the Program is not restricted, and the output from the Program | |
7757 | is covered only if its contents constitute a work based on the | |
7758 | Program (independent of having been made by running the Program). | |
7759 | Whether that is true depends on what the Program does. | |
70b88761 RP |
7760 | |
7761 | @item | |
7463aadd RP |
7762 | You may copy and distribute verbatim copies of the Program's |
7763 | source code as you receive it, in any medium, provided that you | |
7764 | conspicuously and appropriately publish on each copy an appropriate | |
7765 | copyright notice and disclaimer of warranty; keep intact all the | |
7766 | notices that refer to this License and to the absence of any warranty; | |
7767 | and give any other recipients of the Program a copy of this License | |
7768 | along with the Program. | |
70b88761 | 7769 | |
7463aadd RP |
7770 | You may charge a fee for the physical act of transferring a copy, and |
7771 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 7772 | |
70b88761 | 7773 | @item |
7463aadd RP |
7774 | You may modify your copy or copies of the Program or any portion |
7775 | of it, thus forming a work based on the Program, and copy and | |
7776 | distribute such modifications or work under the terms of Section 1 | |
7777 | above, provided that you also meet all of these conditions: | |
70b88761 | 7778 | |
1041a570 | 7779 | @enumerate a |
70b88761 | 7780 | @item |
7463aadd RP |
7781 | You must cause the modified files to carry prominent notices |
7782 | stating that you changed the files and the date of any change. | |
70b88761 RP |
7783 | |
7784 | @item | |
7463aadd RP |
7785 | You must cause any work that you distribute or publish, that in |
7786 | whole or in part contains or is derived from the Program or any | |
7787 | part thereof, to be licensed as a whole at no charge to all third | |
7788 | parties under the terms of this License. | |
70b88761 RP |
7789 | |
7790 | @item | |
7463aadd RP |
7791 | If the modified program normally reads commands interactively |
7792 | when run, you must cause it, when started running for such | |
7793 | interactive use in the most ordinary way, to print or display an | |
7794 | announcement including an appropriate copyright notice and a | |
7795 | notice that there is no warranty (or else, saying that you provide | |
7796 | a warranty) and that users may redistribute the program under | |
7797 | these conditions, and telling the user how to view a copy of this | |
7798 | License. (Exception: if the Program itself is interactive but | |
7799 | does not normally print such an announcement, your work based on | |
7800 | the Program is not required to print an announcement.) | |
1041a570 | 7801 | @end enumerate |
7463aadd RP |
7802 | |
7803 | These requirements apply to the modified work as a whole. If | |
7804 | identifiable sections of that work are not derived from the Program, | |
7805 | and can be reasonably considered independent and separate works in | |
7806 | themselves, then this License, and its terms, do not apply to those | |
7807 | sections when you distribute them as separate works. But when you | |
7808 | distribute the same sections as part of a whole which is a work based | |
7809 | on the Program, the distribution of the whole must be on the terms of | |
7810 | this License, whose permissions for other licensees extend to the | |
7811 | entire whole, and thus to each and every part regardless of who wrote it. | |
7812 | ||
7813 | Thus, it is not the intent of this section to claim rights or contest | |
7814 | your rights to work written entirely by you; rather, the intent is to | |
7815 | exercise the right to control the distribution of derivative or | |
7816 | collective works based on the Program. | |
7817 | ||
7818 | In addition, mere aggregation of another work not based on the Program | |
7819 | with the Program (or with a work based on the Program) on a volume of | |
7820 | a storage or distribution medium does not bring the other work under | |
7821 | the scope of this License. | |
70b88761 RP |
7822 | |
7823 | @item | |
7463aadd RP |
7824 | You may copy and distribute the Program (or a work based on it, |
7825 | under Section 2) in object code or executable form under the terms of | |
7826 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 7827 | |
1041a570 | 7828 | @enumerate a |
70b88761 | 7829 | @item |
7463aadd RP |
7830 | Accompany it with the complete corresponding machine-readable |
7831 | source code, which must be distributed under the terms of Sections | |
7832 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
7833 | |
7834 | @item | |
7463aadd RP |
7835 | Accompany it with a written offer, valid for at least three |
7836 | years, to give any third party, for a charge no more than your | |
7837 | cost of physically performing source distribution, a complete | |
7838 | machine-readable copy of the corresponding source code, to be | |
7839 | distributed under the terms of Sections 1 and 2 above on a medium | |
7840 | customarily used for software interchange; or, | |
70b88761 RP |
7841 | |
7842 | @item | |
7463aadd RP |
7843 | Accompany it with the information you received as to the offer |
7844 | to distribute corresponding source code. (This alternative is | |
70b88761 | 7845 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
7846 | received the program in object code or executable form with such |
7847 | an offer, in accord with Subsection b above.) | |
1041a570 | 7848 | @end enumerate |
7463aadd RP |
7849 | |
7850 | The source code for a work means the preferred form of the work for | |
7851 | making modifications to it. For an executable work, complete source | |
7852 | code means all the source code for all modules it contains, plus any | |
7853 | associated interface definition files, plus the scripts used to | |
7854 | control compilation and installation of the executable. However, as a | |
7855 | special exception, the source code distributed need not include | |
7856 | anything that is normally distributed (in either source or binary | |
7857 | form) with the major components (compiler, kernel, and so on) of the | |
7858 | operating system on which the executable runs, unless that component | |
7859 | itself accompanies the executable. | |
7860 | ||
7861 | If distribution of executable or object code is made by offering | |
7862 | access to copy from a designated place, then offering equivalent | |
7863 | access to copy the source code from the same place counts as | |
7864 | distribution of the source code, even though third parties are not | |
7865 | compelled to copy the source along with the object code. | |
70b88761 RP |
7866 | |
7867 | @item | |
7463aadd RP |
7868 | You may not copy, modify, sublicense, or distribute the Program |
7869 | except as expressly provided under this License. Any attempt | |
7870 | otherwise to copy, modify, sublicense or distribute the Program is | |
7871 | void, and will automatically terminate your rights under this License. | |
7872 | However, parties who have received copies, or rights, from you under | |
7873 | this License will not have their licenses terminated so long as such | |
7874 | parties remain in full compliance. | |
70b88761 RP |
7875 | |
7876 | @item | |
7463aadd RP |
7877 | You are not required to accept this License, since you have not |
7878 | signed it. However, nothing else grants you permission to modify or | |
7879 | distribute the Program or its derivative works. These actions are | |
7880 | prohibited by law if you do not accept this License. Therefore, by | |
7881 | modifying or distributing the Program (or any work based on the | |
7882 | Program), you indicate your acceptance of this License to do so, and | |
7883 | all its terms and conditions for copying, distributing or modifying | |
7884 | the Program or works based on it. | |
70b88761 RP |
7885 | |
7886 | @item | |
7887 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
7888 | Program), the recipient automatically receives a license from the |
7889 | original licensor to copy, distribute or modify the Program subject to | |
7890 | these terms and conditions. You may not impose any further | |
7891 | restrictions on the recipients' exercise of the rights granted herein. | |
7892 | You are not responsible for enforcing compliance by third parties to | |
7893 | this License. | |
7894 | ||
7895 | @item | |
7896 | If, as a consequence of a court judgment or allegation of patent | |
7897 | infringement or for any other reason (not limited to patent issues), | |
7898 | conditions are imposed on you (whether by court order, agreement or | |
7899 | otherwise) that contradict the conditions of this License, they do not | |
7900 | excuse you from the conditions of this License. If you cannot | |
7901 | distribute so as to satisfy simultaneously your obligations under this | |
7902 | License and any other pertinent obligations, then as a consequence you | |
7903 | may not distribute the Program at all. For example, if a patent | |
7904 | license would not permit royalty-free redistribution of the Program by | |
7905 | all those who receive copies directly or indirectly through you, then | |
7906 | the only way you could satisfy both it and this License would be to | |
7907 | refrain entirely from distribution of the Program. | |
7908 | ||
7909 | If any portion of this section is held invalid or unenforceable under | |
7910 | any particular circumstance, the balance of the section is intended to | |
7911 | apply and the section as a whole is intended to apply in other | |
7912 | circumstances. | |
7913 | ||
7914 | It is not the purpose of this section to induce you to infringe any | |
7915 | patents or other property right claims or to contest validity of any | |
7916 | such claims; this section has the sole purpose of protecting the | |
7917 | integrity of the free software distribution system, which is | |
7918 | implemented by public license practices. Many people have made | |
7919 | generous contributions to the wide range of software distributed | |
7920 | through that system in reliance on consistent application of that | |
7921 | system; it is up to the author/donor to decide if he or she is willing | |
7922 | to distribute software through any other system and a licensee cannot | |
7923 | impose that choice. | |
7924 | ||
7925 | This section is intended to make thoroughly clear what is believed to | |
7926 | be a consequence of the rest of this License. | |
7927 | ||
7928 | @item | |
7929 | If the distribution and/or use of the Program is restricted in | |
7930 | certain countries either by patents or by copyrighted interfaces, the | |
7931 | original copyright holder who places the Program under this License | |
7932 | may add an explicit geographical distribution limitation excluding | |
7933 | those countries, so that distribution is permitted only in or among | |
7934 | countries not thus excluded. In such case, this License incorporates | |
7935 | the limitation as if written in the body of this License. | |
70b88761 RP |
7936 | |
7937 | @item | |
7938 | The Free Software Foundation may publish revised and/or new versions | |
7939 | of the General Public License from time to time. Such new versions will | |
7940 | be similar in spirit to the present version, but may differ in detail to | |
7941 | address new problems or concerns. | |
7942 | ||
7943 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 7944 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
7945 | later version'', you have the option of following the terms and conditions |
7946 | either of that version or of any later version published by the Free | |
7947 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 7948 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
7949 | Foundation. |
7950 | ||
7951 | @item | |
7952 | If you wish to incorporate parts of the Program into other free | |
7953 | programs whose distribution conditions are different, write to the author | |
7954 | to ask for permission. For software which is copyrighted by the Free | |
7955 | Software Foundation, write to the Free Software Foundation; we sometimes | |
7956 | make exceptions for this. Our decision will be guided by the two goals | |
7957 | of preserving the free status of all derivatives of our free software and | |
7958 | of promoting the sharing and reuse of software generally. | |
7959 | ||
7960 | @iftex | |
7961 | @heading NO WARRANTY | |
7962 | @end iftex | |
7963 | @ifinfo | |
7964 | @center NO WARRANTY | |
7965 | @end ifinfo | |
7966 | ||
7967 | @item | |
7968 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
7969 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
7970 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
7971 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
7972 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
7973 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
7974 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
7975 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
7976 | REPAIR OR CORRECTION. | |
7977 | ||
7978 | @item | |
7463aadd RP |
7979 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
7980 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 7981 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
7982 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
7983 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
7984 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
7985 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
7986 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
7987 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
7988 | @end enumerate |
7989 | ||
7990 | @iftex | |
7991 | @heading END OF TERMS AND CONDITIONS | |
7992 | @end iftex | |
7993 | @ifinfo | |
7994 | @center END OF TERMS AND CONDITIONS | |
7995 | @end ifinfo | |
7996 | ||
7997 | @page | |
54e6b3c3 | 7998 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
7999 | |
8000 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
8001 | possible use to the public, the best way to achieve this is to make it |
8002 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 8003 | |
7463aadd RP |
8004 | To do so, attach the following notices to the program. It is safest |
8005 | to attach them to the start of each source file to most effectively | |
8006 | convey the exclusion of warranty; and each file should have at least | |
8007 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
8008 | |
8009 | @smallexample | |
203eea5d | 8010 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
8011 | Copyright (C) 19@var{yy} @var{name of author} |
8012 | ||
203eea5d RP |
8013 | This program is free software; you can redistribute it and/or |
8014 | modify it under the terms of the GNU General Public License | |
8015 | as published by the Free Software Foundation; either version 2 | |
8016 | of the License, or (at your option) any later version. | |
70b88761 RP |
8017 | |
8018 | This program is distributed in the hope that it will be useful, | |
8019 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8020 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8021 | GNU General Public License for more details. | |
8022 | ||
8023 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
8024 | along with this program; if not, write to the |
8025 | Free Software Foundation, Inc., 675 Mass Ave, | |
8026 | Cambridge, MA 02139, USA. | |
70b88761 RP |
8027 | @end smallexample |
8028 | ||
8029 | Also add information on how to contact you by electronic and paper mail. | |
8030 | ||
8031 | If the program is interactive, make it output a short notice like this | |
8032 | when it starts in an interactive mode: | |
8033 | ||
8034 | @smallexample | |
8035 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
8036 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
8037 | type `show w'. This is free software, and you are welcome | |
8038 | to redistribute it under certain conditions; type `show c' | |
8039 | for details. | |
70b88761 RP |
8040 | @end smallexample |
8041 | ||
7463aadd RP |
8042 | The hypothetical commands @samp{show w} and @samp{show c} should show |
8043 | the appropriate parts of the General Public License. Of course, the | |
8044 | commands you use may be called something other than @samp{show w} and | |
8045 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8046 | suits your program. | |
70b88761 RP |
8047 | |
8048 | You should also get your employer (if you work as a programmer) or your | |
8049 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8050 | necessary. Here is a sample; alter the names: | |
8051 | ||
1041a570 RP |
8052 | @example |
8053 | Yoyodyne, Inc., hereby disclaims all copyright | |
8054 | interest in the program `Gnomovision' | |
8055 | (which makes passes at compilers) written | |
8056 | by James Hacker. | |
70b88761 RP |
8057 | |
8058 | @var{signature of Ty Coon}, 1 April 1989 | |
8059 | Ty Coon, President of Vice | |
1041a570 | 8060 | @end example |
7463aadd RP |
8061 | |
8062 | This General Public License does not permit incorporating your program into | |
8063 | proprietary programs. If your program is a subroutine library, you may | |
8064 | consider it more useful to permit linking proprietary applications with the | |
8065 | library. If this is what you want to do, use the GNU Library General | |
8066 | Public License instead of this License. | |
70b88761 | 8067 | |
9c3ad547 | 8068 | @node Index, , Copying, Top |
d2e08421 | 8069 | @unnumbered Index |
e91b87a3 | 8070 | |
8071 | @printindex cp | |
8072 | ||
fe3f5fc8 RP |
8073 | @tex |
8074 | % I think something like @colophon should be in texinfo. In the | |
8075 | % meantime: | |
8076 | \long\def\colophon{\hbox to0pt{}\vfill | |
8077 | \centerline{The body of this manual is set in} | |
8078 | \centerline{\fontname\tenrm,} | |
8079 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8080 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
8081 | \centerline{{\it\fontname\tenit\/},} |
8082 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
8083 | \centerline{{\sl\fontname\tensl\/}} |
8084 | \centerline{are used for emphasis.}\vfill} | |
8085 | \page\colophon | |
a6d0b6d3 | 8086 | % Blame: [email protected], 1991. |
fe3f5fc8 RP |
8087 | @end tex |
8088 | ||
e91b87a3 | 8089 | @contents |
8090 | @bye |