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