]>
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__) |
a6463583 | 9 | @settitle Debugging with _GDBN__ |
29a2b744 RP |
10 | _fi__(_GENERIC__) |
11 | _if__(!_GENERIC__) | |
a6463583 | 12 | @settitle Debugging with _GDBN__ (_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 | ||
d24e0922 | 34 | @c GDB CHANGELOG CONSULTED BETWEEN: |
29a2b744 RP |
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 |
a6463583 RP |
67 | This is Edition 4.06, July 1992, |
68 | of @cite{Debugging with _GDBN__: the GNU Source-Level Debugger} | |
29a2b744 RP |
69 | for GDB Version _GDB_VN__. |
70 | ||
95d5ceb9 | 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 |
a6463583 | 99 | @title Debugging with _GDBN__ |
95d5ceb9 | 100 | @subtitle 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 |
a6463583 RP |
106 | @subtitle Edition 4.06, for _GDBN__ version _GDB_VN__ |
107 | @subtitle July 1992 | |
29a2b744 | 108 | @author by Richard M. Stallman and Roland H. Pesch |
70b88761 RP |
109 | @page |
110 | @tex | |
111 | {\parskip=0pt | |
93ac5532 | 112 | \hfill pesch\@cygnus.com\par |
a6463583 | 113 | \hfill {\it Debugging with _GDBN__}, \manvers\par |
70b88761 RP |
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 | 141 | @node Top, Summary, (dir), (dir) |
a6463583 | 142 | @top Debugging with _GDBN__ |
29a2b744 RP |
143 | |
144 | This file describes _GDBN__, the GNU symbolic debugger. | |
145 | ||
146 | @c !!set edition, date, version | |
a6463583 | 147 | This is Edition 4.06, July 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 |
95d5ceb9 | 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:: |
77b46d13 | 171 | * Formatting Documentation:: How to format and print GDB documentation |
c7cb8acb | 172 | * Installing GDB:: Installing GDB |
b80282d5 RP |
173 | * Copying:: GNU GENERAL PUBLIC LICENSE |
174 | * Index:: Index | |
c2bbbb22 | 175 | |
70b88761 RP |
176 | --- The Detailed Node Listing --- |
177 | ||
178 | Summary of _GDBN__ | |
179 | ||
95d5ceb9 | 180 | * Free Software:: Freely redistributable software |
b80282d5 | 181 | * Contributors:: Contributors to _GDBN__ |
70b88761 RP |
182 | |
183 | Getting In and Out of _GDBN__ | |
184 | ||
95d5ceb9 RP |
185 | * Invoking _GDBN__:: How to start _GDBN__ |
186 | * Leaving _GDBN__:: How to quit _GDBN__ | |
187 | * Shell Commands:: How to use shell commands inside _GDBN__ | |
70b88761 RP |
188 | |
189 | Starting _GDBN__ | |
190 | ||
b80282d5 RP |
191 | * File Options:: Choosing Files |
192 | * Mode Options:: Choosing Modes | |
70b88761 RP |
193 | |
194 | _GDBN__ Commands | |
195 | ||
b80282d5 | 196 | * Command Syntax:: Command Syntax |
6f3ec223 | 197 | * Completion:: Command Completion |
b80282d5 | 198 | * Help:: Getting Help |
70b88761 RP |
199 | |
200 | Running Programs Under _GDBN__ | |
201 | ||
b80282d5 RP |
202 | * Compilation:: Compiling for Debugging |
203 | * Starting:: Starting your Program | |
204 | * Arguments:: Your Program's Arguments | |
205 | * Environment:: Your Program's Environment | |
206 | * Working Directory:: Your Program's Working Directory | |
207 | * Input/Output:: Your Program's Input and Output | |
208 | * Attach:: Debugging an Already-Running Process | |
209 | * Kill Process:: Killing the Child Process | |
d24e0922 | 210 | * Process Information:: Additional Process Information |
70b88761 RP |
211 | |
212 | Stopping and Continuing | |
213 | ||
b80282d5 RP |
214 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
215 | * Continuing and Stepping:: Resuming Execution | |
216 | * Signals:: Signals | |
70b88761 RP |
217 | |
218 | Breakpoints, Watchpoints, and Exceptions | |
219 | ||
b80282d5 RP |
220 | * Set Breaks:: Setting Breakpoints |
221 | * Set Watchpoints:: Setting Watchpoints | |
222 | * Exception Handling:: Breakpoints and Exceptions | |
223 | * Delete Breaks:: Deleting Breakpoints | |
224 | * Disabling:: Disabling Breakpoints | |
225 | * Conditions:: Break Conditions | |
226 | * Break Commands:: Breakpoint Command Lists | |
227 | * Breakpoint Menus:: Breakpoint Menus | |
c2bbbb22 | 228 | * Error in Breakpoints:: ``Cannot insert breakpoints'' |
70b88761 RP |
229 | |
230 | Examining the Stack | |
231 | ||
b80282d5 RP |
232 | * Frames:: Stack Frames |
233 | * Backtrace:: Backtraces | |
234 | * Selection:: Selecting a Frame | |
235 | * Frame Info:: Information on a Frame | |
70b88761 RP |
236 | |
237 | Examining Source Files | |
238 | ||
b80282d5 RP |
239 | * List:: Printing Source Lines |
240 | * Search:: Searching Source Files | |
241 | * Source Path:: Specifying Source Directories | |
242 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
243 | |
244 | Examining Data | |
245 | ||
b80282d5 RP |
246 | * Expressions:: Expressions |
247 | * Variables:: Program Variables | |
248 | * Arrays:: Artificial Arrays | |
249 | * Output formats:: Output formats | |
250 | * Memory:: Examining Memory | |
251 | * Auto Display:: Automatic Display | |
252 | * Print Settings:: Print Settings | |
253 | * Value History:: Value History | |
254 | * Convenience Vars:: Convenience Variables | |
255 | * Registers:: Registers | |
256 | * Floating Point Hardware:: Floating Point Hardware | |
70b88761 | 257 | |
c2bbbb22 RP |
258 | Using GDB with Different Languages |
259 | ||
260 | * Setting:: Switching between source languages | |
261 | * Show:: Displaying the language | |
262 | * Checks:: Type and Range checks | |
263 | * Support:: Supported languages | |
264 | ||
265 | Switching between source languages | |
266 | ||
267 | * Manually:: Setting the working language manually | |
268 | * Automatically:: Having GDB infer the source language | |
269 | ||
270 | Type and range Checking | |
271 | ||
272 | * Type Checking:: An overview of type checking | |
273 | * Range Checking:: An overview of range checking | |
274 | ||
275 | Supported Languages | |
276 | ||
277 | * C:: C and C++ | |
278 | * Modula-2:: Modula-2 | |
279 | ||
280 | C and C++ | |
281 | ||
282 | * C Operators:: C and C++ Operators | |
283 | * C Constants:: C and C++ Constants | |
284 | * Cplusplus expressions:: C++ Expressions | |
285 | * C Defaults:: Default settings for C and C++ | |
286 | * C Checks:: C and C++ Type and Range Checks | |
287 | * Debugging C:: _GDBN__ and C | |
288 | * Debugging C plus plus:: Special features for C++ | |
289 | ||
290 | Modula-2 | |
291 | ||
292 | * M2 Operators:: Built-in operators | |
29a2b744 | 293 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
294 | * M2 Constants:: Modula-2 Constants |
295 | * M2 Defaults:: Default settings for Modula-2 | |
296 | * Deviations:: Deviations from standard Modula-2 | |
297 | * M2 Checks:: Modula-2 Type and Range Checks | |
298 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
299 | * GDB/M2:: GDB and Modula-2 | |
300 | ||
70b88761 RP |
301 | Altering Execution |
302 | ||
b80282d5 RP |
303 | * Assignment:: Assignment to Variables |
304 | * Jumping:: Continuing at a Different Address | |
29a2b744 | 305 | * Signaling:: Giving your program a Signal |
b80282d5 RP |
306 | * Returning:: Returning from a Function |
307 | * Calling:: Calling your Program's Functions | |
c338a2fd | 308 | * Patching:: Patching your Program |
70b88761 RP |
309 | |
310 | _GDBN__'s Files | |
311 | ||
b80282d5 RP |
312 | * Files:: Commands to Specify Files |
313 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 | 314 | |
e251e767 | 315 | Specifying a Debugging Target |
70b88761 | 316 | |
b80282d5 RP |
317 | * Active Targets:: Active Targets |
318 | * Target Commands:: Commands for Managing Targets | |
319 | * Remote:: Remote Debugging | |
70b88761 RP |
320 | |
321 | Remote Debugging | |
322 | ||
c2bbbb22 RP |
323 | * i960-Nindy Remote:: _GDBN__ with a Remote i960 (Nindy) |
324 | * EB29K Remote:: _GDBN__ with a Remote EB29K | |
325 | * VxWorks Remote:: _GDBN__ and VxWorks | |
70b88761 RP |
326 | |
327 | _GDBN__ with a Remote i960 (Nindy) | |
328 | ||
b80282d5 RP |
329 | * Nindy Startup:: Startup with Nindy |
330 | * Nindy Options:: Options for Nindy | |
331 | * Nindy reset:: Nindy Reset Command | |
70b88761 RP |
332 | |
333 | _GDBN__ with a Remote EB29K | |
334 | ||
b80282d5 RP |
335 | * Comms (EB29K):: Communications Setup |
336 | * gdb-EB29K:: EB29K cross-debugging | |
337 | * Remote Log:: Remote Log | |
70b88761 RP |
338 | |
339 | _GDBN__ and VxWorks | |
340 | ||
b80282d5 RP |
341 | * VxWorks connection:: Connecting to VxWorks |
342 | * VxWorks download:: VxWorks Download | |
343 | * VxWorks attach:: Running Tasks | |
70b88761 RP |
344 | |
345 | Controlling _GDBN__ | |
346 | ||
b80282d5 RP |
347 | * Prompt:: Prompt |
348 | * Editing:: Command Editing | |
349 | * History:: Command History | |
350 | * Screen Size:: Screen Size | |
351 | * Numbers:: Numbers | |
352 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
353 | |
354 | Canned Sequences of Commands | |
355 | ||
b80282d5 RP |
356 | * Define:: User-Defined Commands |
357 | * Command Files:: Command Files | |
358 | * Output:: Commands for Controlled Output | |
70b88761 RP |
359 | |
360 | Reporting Bugs in _GDBN__ | |
361 | ||
b80282d5 RP |
362 | * Bug Criteria:: Have You Found a Bug? |
363 | * Bug Reporting:: How to Report Bugs | |
c2bbbb22 RP |
364 | |
365 | Installing GDB | |
366 | ||
f672bb7f | 367 | * Separate Objdir:: Compiling _GDBN__ in another directory |
c2bbbb22 RP |
368 | * Config Names:: Specifying names for hosts and targets |
369 | * configure Options:: Summary of options for configure | |
70b88761 RP |
370 | @end menu |
371 | ||
372 | @node Summary, New Features, Top, Top | |
373 | @unnumbered Summary of _GDBN__ | |
374 | ||
375 | The purpose of a debugger such as _GDBN__ is to allow you to see what is | |
376 | going on ``inside'' another program while it executes---or what another | |
1041a570 | 377 | program was doing at the moment it crashed. |
70b88761 RP |
378 | |
379 | _GDBN__ can do four main kinds of things (plus other things in support of | |
1041a570 | 380 | these) to help you catch bugs in the act: |
70b88761 RP |
381 | |
382 | @itemize @bullet | |
383 | @item | |
384 | Start your program, specifying anything that might affect its behavior. | |
385 | ||
386 | @item | |
387 | Make your program stop on specified conditions. | |
388 | ||
389 | @item | |
390 | Examine what has happened, when your program has stopped. | |
391 | ||
392 | @item | |
393 | Change things in your program, so you can experiment with correcting the | |
394 | effects of one bug and go on to learn about another. | |
395 | @end itemize | |
396 | ||
c2bbbb22 RP |
397 | You can use _GDBN__ to debug programs written in C, C++, and Modula-2. |
398 | Fortran support will be added when a GNU Fortran compiler is ready. | |
70b88761 RP |
399 | |
400 | @menu | |
b80282d5 RP |
401 | * Free Software:: Free Software |
402 | * Contributors:: Contributors to GDB | |
70b88761 RP |
403 | @end menu |
404 | ||
405 | @node Free Software, Contributors, Summary, Summary | |
406 | @unnumberedsec Free Software | |
1041a570 RP |
407 | |
408 | _GDBN__ is @dfn{free software}, protected by the GNU General Public License | |
409 | (GPL). The GPL gives you the freedom to copy or adapt a licensed | |
70b88761 RP |
410 | program---but every person getting a copy also gets with it the |
411 | freedom to modify that copy (which means that they must get access to | |
412 | the source code), and the freedom to distribute further copies. | |
413 | Typical software companies use copyrights to limit your freedoms; the | |
414 | Free Software Foundation uses the GPL to preserve these freedoms. | |
415 | ||
416 | Fundamentally, the General Public License is a license which says that | |
29a2b744 | 417 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
418 | from anyone else. |
419 | ||
29a2b744 | 420 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
1041a570 | 421 | |
70b88761 RP |
422 | @node Contributors, , Free Software, Summary |
423 | @unnumberedsec Contributors to GDB | |
424 | ||
425 | Richard Stallman was the original author of GDB, and of many other GNU | |
426 | programs. Many others have contributed to its development. This | |
427 | section attempts to credit major contributors. One of the virtues of | |
428 | free software is that everyone is free to contribute to it; with | |
429 | regret, we cannot actually acknowledge everyone here. The file | |
430 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
431 | account. | |
432 | ||
433 | Changes much prior to version 2.0 are lost in the mists of time. | |
434 | ||
435 | @quotation | |
436 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
437 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
438 | omitted from this list, we would like to add your names! | |
439 | @end quotation | |
440 | ||
441 | So that they may not regard their long labor as thankless, we | |
69bbcf05 | 442 | particularly thank those who shepherded GDB through major releases: Stu |
6f3ec223 RP |
443 | Grossman and John Gilmore (releases 4.6, 4.5, 4.4), John Gilmore |
444 | (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, | |
445 | 3.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of | |
446 | GDB for some period, each contributed significantly to the structure, | |
447 | stability, and capabilities of the entire debugger. | |
70b88761 RP |
448 | |
449 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
450 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
451 | ||
452 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
453 | with significant additional contributions from Per Bothner. James | |
454 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
455 | TerMaat (who also did much general update work leading to release 3.0). | |
456 | ||
1041a570 RP |
457 | GDB 4 uses the BFD subroutine library to examine multiple |
458 | object-file formats; BFD was a joint project of David V. | |
459 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
70b88761 | 460 | |
1041a570 RP |
461 | David Johnson wrote the original COFF support; Pace Willison did |
462 | the original support for encapsulated COFF. | |
70b88761 RP |
463 | |
464 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
465 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
466 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris |
467 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
468 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
469 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
470 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
471 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
472 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
473 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
474 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
475 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
476 | support. | |
70b88761 | 477 | |
c338a2fd RP |
478 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
479 | libraries. | |
70b88761 RP |
480 | |
481 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
482 | several machine instruction sets. | |
483 | ||
1041a570 RP |
484 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped |
485 | develop remote debugging. Intel Corporation and Wind River Systems | |
486 | contributed remote debugging modules for their products. | |
70b88761 | 487 | |
1041a570 RP |
488 | Brian Fox is the author of the readline libraries providing |
489 | command-line editing and command history. | |
70b88761 | 490 | |
1041a570 RP |
491 | Andrew Beers of SUNY Buffalo wrote the language-switching code and |
492 | the Modula-2 support, and contributed the Languages chapter of this | |
493 | manual. | |
c2bbbb22 | 494 | |
6f3ec223 RP |
495 | Fred Fish wrote most of the support for Unix System Vr4, and enhanced |
496 | the command-completion support to cover C++ overloaded symbols. | |
14d01801 | 497 | |
70b88761 | 498 | @node New Features, Sample Session, Summary, Top |
c7cb8acb | 499 | @unnumbered New Features since GDB version 3.5 |
70b88761 RP |
500 | |
501 | @table @emph | |
502 | @item Targets | |
503 | Using the new command @code{target}, you can select at runtime whether | |
504 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
505 | a serial port, realtime systems over a TCP/IP connection, etc. The |
506 | command @code{load} can download programs into a remote system. Serial | |
507 | stubs are available for Motorola 680x0 and Intel 80386 remote systems; | |
c7cb8acb | 508 | GDB also supports debugging realtime processes running under |
b80282d5 | 509 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a |
c7cb8acb | 510 | debugger stub on the target system. Internally, GDB now uses a |
b80282d5 RP |
511 | function vector to mediate access to different targets; if you need to |
512 | add your own support for a remote protocol, this makes it much easier. | |
70b88761 RP |
513 | |
514 | @item Watchpoints | |
c7cb8acb | 515 | GDB now sports watchpoints as well as breakpoints. You can use a |
70b88761 RP |
516 | watchpoint to stop execution whenever the value of an expression |
517 | changes, without having to predict a particular place in your program | |
518 | where this may happen. | |
519 | ||
b80282d5 RP |
520 | @item Wide Output |
521 | Commands that issue wide output now insert newlines at places designed | |
522 | to make the output more readable. | |
523 | ||
70b88761 | 524 | @item Object Code Formats |
c7cb8acb | 525 | GDB uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
526 | Library to permit it to switch dynamically, without reconfiguration or |
527 | recompilation, between different object-file formats. Formats currently | |
528 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
529 | .o's, archive libraries, or core dumps. BFD is available as a | |
530 | subroutine library so that other programs may take advantage of it, and | |
531 | the other GNU binary utilities are being converted to use it. | |
70b88761 | 532 | |
b80282d5 | 533 | @item Configuration and Ports |
70b88761 | 534 | Compile-time configuration (to select a particular architecture and |
7463aadd | 535 | operating system) is much easier. The script @code{configure} now |
c7cb8acb RP |
536 | allows you to configure GDB as either a native debugger or a |
537 | cross-debugger. @xref{Installing GDB}, for details on how to | |
6a8cb0e7 | 538 | configure. |
70b88761 RP |
539 | |
540 | @item Interaction | |
c7cb8acb | 541 | The user interface to GDB's control variables has been simplified |
70b88761 RP |
542 | and consolidated in two commands, @code{set} and @code{show}. Output |
543 | lines are now broken at readable places, rather than overflowing onto | |
544 | the next line. You can suppress output of machine-level addresses, | |
545 | displaying only source language information. | |
546 | ||
b80282d5 | 547 | @item C++ |
c7cb8acb | 548 | GDB now supports C++ multiple inheritance (if used with a GCC |
b80282d5 | 549 | version 2 compiler), and also has limited support for C++ exception |
c7cb8acb | 550 | handling, with the commands @code{catch} and @code{info catch}: GDB |
b80282d5 RP |
551 | can break when an exception is raised, before the stack is peeled back |
552 | to the exception handler's context. | |
70b88761 | 553 | |
c2bbbb22 | 554 | @item Modula-2 |
c7cb8acb | 555 | GDB now has preliminary support for the GNU Modula-2 compiler, |
c2bbbb22 | 556 | currently under development at the State University of New York at |
c7cb8acb | 557 | Buffalo. Coordinated development of both GDB and the GNU Modula-2 |
5b0fdf7b RP |
558 | compiler will continue into 1992. Other Modula-2 compilers are |
559 | currently not supported, and attempting to debug programs compiled with | |
560 | them will likely result in an error as the symbol table of the | |
561 | executable is read in. | |
c2bbbb22 | 562 | |
70b88761 | 563 | @item Command Rationalization |
c7cb8acb | 564 | Many GDB commands have been renamed to make them easier to remember |
70b88761 RP |
565 | and use. In particular, the subcommands of @code{info} and |
566 | @code{show}/@code{set} are grouped to make the former refer to the state | |
c7cb8acb | 567 | of your program, and the latter refer to the state of GDB itself. |
70b88761 RP |
568 | @xref{Renamed Commands}, for details on what commands were renamed. |
569 | ||
70b88761 | 570 | @item Shared Libraries |
77b46d13 JG |
571 | GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000 |
572 | shared libraries. | |
b80282d5 RP |
573 | |
574 | @item Reference Card | |
6f3ec223 RP |
575 | GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting |
576 | the Documentation}, for instructions to print it. | |
70b88761 RP |
577 | |
578 | @item Work in Progress | |
579 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
580 | support. | |
70b88761 RP |
581 | @end table |
582 | ||
583 | @node Sample Session, Invocation, New Features, Top | |
584 | @chapter A Sample _GDBN__ Session | |
585 | ||
586 | You can use this manual at your leisure to read all about _GDBN__. | |
587 | However, a handful of commands are enough to get started using the | |
588 | debugger. This chapter illustrates these commands. | |
589 | ||
590 | @iftex | |
6ca72cc6 | 591 | In this sample session, we emphasize user input like this: @b{input}, |
70b88761 RP |
592 | to make it easier to pick out from the surrounding output. |
593 | @end iftex | |
594 | ||
595 | @c FIXME: this example may not be appropriate for some configs, where | |
596 | @c FIXME...primary interest is in remote use. | |
597 | _0__ | |
598 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
599 | processor) exhibits the following bug: sometimes, when we change its | |
600 | quote strings from the default, the commands used to capture one macro's | |
601 | definition in another stop working. In the following short @code{m4} | |
602 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
29a2b744 | 603 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
604 | same thing. However, when we change the open quote string to |
605 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
606 | procedure fails to define a new synonym @code{baz}: | |
607 | ||
608 | @smallexample | |
6ca72cc6 RP |
609 | $ @b{cd gnu/m4} |
610 | $ @b{./m4} | |
611 | @b{define(foo,0000)} | |
70b88761 | 612 | |
6ca72cc6 | 613 | @b{foo} |
70b88761 | 614 | 0000 |
6ca72cc6 | 615 | @b{define(bar,defn(`foo'))} |
70b88761 | 616 | |
6ca72cc6 | 617 | @b{bar} |
70b88761 | 618 | 0000 |
6ca72cc6 | 619 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 620 | |
6ca72cc6 RP |
621 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
622 | @b{baz} | |
623 | @b{C-d} | |
70b88761 RP |
624 | m4: End of input: 0: fatal error: EOF in string |
625 | @end smallexample | |
626 | ||
627 | @noindent | |
628 | Let's use _GDBN__ to try to see what's going on. | |
629 | ||
630 | @smallexample | |
6ca72cc6 | 631 | $ @b{_GDBP__ m4} |
203eea5d RP |
632 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
633 | @c FIXME... format to come out better. | |
634 | GDB is free software and you are welcome to distribute copies | |
635 | of it under certain conditions; type "show copying" to see | |
636 | the conditions. | |
637 | There is absolutely no warranty for GDB; type "show warranty" | |
638 | for details. | |
5b0fdf7b | 639 | GDB _GDB_VN__, Copyright 1992 Free Software Foundation, Inc... |
e251e767 | 640 | (_GDBP__) |
70b88761 RP |
641 | @end smallexample |
642 | ||
643 | @noindent | |
1041a570 RP |
644 | _GDBN__ reads only enough symbol data to know where to find the rest when |
645 | needed; as a result, the first prompt comes up very quickly. We now | |
646 | tell _GDBN__ to use a narrower display width than usual, so that examples | |
647 | will fit in this manual. | |
70b88761 RP |
648 | |
649 | @smallexample | |
6ca72cc6 | 650 | (_GDBP__) @b{set width 70} |
70b88761 RP |
651 | @end smallexample |
652 | ||
e251e767 | 653 | @noindent |
29a2b744 | 654 | Let's see how the @code{m4} built-in @code{changequote} works. |
70b88761 RP |
655 | Having looked at the source, we know the relevant subroutine is |
656 | @code{m4_changequote}, so we set a breakpoint there with _GDBN__'s | |
657 | @code{break} command. | |
658 | ||
659 | @smallexample | |
6ca72cc6 | 660 | (_GDBP__) @b{break m4_changequote} |
70b88761 RP |
661 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. |
662 | @end smallexample | |
663 | ||
664 | @noindent | |
665 | Using the @code{run} command, we start @code{m4} running under _GDBN__ | |
666 | control; as long as control does not reach the @code{m4_changequote} | |
667 | subroutine, the program runs as usual: | |
668 | ||
669 | @smallexample | |
6ca72cc6 | 670 | (_GDBP__) @b{run} |
e251e767 | 671 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
6ca72cc6 | 672 | @b{define(foo,0000)} |
70b88761 | 673 | |
6ca72cc6 | 674 | @b{foo} |
70b88761 RP |
675 | 0000 |
676 | @end smallexample | |
677 | ||
678 | @noindent | |
679 | To trigger the breakpoint, we call @code{changequote}. _GDBN__ | |
680 | suspends execution of @code{m4}, displaying information about the | |
681 | context where it stops. | |
682 | ||
683 | @smallexample | |
6ca72cc6 | 684 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 685 | |
203eea5d RP |
686 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
687 | at builtin.c:879 | |
38962738 | 688 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) |
70b88761 RP |
689 | @end smallexample |
690 | ||
691 | @noindent | |
692 | Now we use the command @code{n} (@code{next}) to advance execution to | |
693 | the next line of the current function. | |
694 | ||
695 | @smallexample | |
6ca72cc6 | 696 | (_GDBP__) @b{n} |
203eea5d RP |
697 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
698 | : nil, | |
70b88761 RP |
699 | @end smallexample |
700 | ||
701 | @noindent | |
702 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
703 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
704 | @code{step} goes to the next line to be executed in @emph{any} | |
e251e767 | 705 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
706 | |
707 | @smallexample | |
6ca72cc6 | 708 | (_GDBP__) @b{s} |
70b88761 RP |
709 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
710 | at input.c:530 | |
711 | 530 if (lquote != def_lquote) | |
712 | @end smallexample | |
713 | ||
714 | @noindent | |
29a2b744 RP |
715 | The display that shows the subroutine where @code{m4} is now |
716 | suspended (and its arguments) is called a stack frame display. It | |
717 | shows a summary of the stack. We can use the @code{backtrace} | |
718 | command (which can also be spelled @code{bt}), to see where we are | |
719 | in the stack as a whole: the @code{backtrace} command displays a | |
720 | stack frame for each active subroutine. | |
70b88761 RP |
721 | |
722 | @smallexample | |
6ca72cc6 | 723 | (_GDBP__) @b{bt} |
70b88761 RP |
724 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
725 | at input.c:530 | |
203eea5d RP |
726 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
727 | at builtin.c:882 | |
70b88761 RP |
728 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
729 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
730 | at macro.c:71 | |
731 | #4 0x79dc in expand_input () at macro.c:40 | |
732 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
733 | @end smallexample | |
734 | ||
735 | @noindent | |
736 | Let's step through a few more lines to see what happens. The first two | |
737 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
738 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 739 | |
70b88761 | 740 | @smallexample |
6ca72cc6 | 741 | (_GDBP__) @b{s} |
70b88761 | 742 | 0x3b5c 532 if (rquote != def_rquote) |
6ca72cc6 | 743 | (_GDBP__) @b{s} |
203eea5d RP |
744 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
745 | def_lquote : xstrdup(lq); | |
6ca72cc6 | 746 | (_GDBP__) @b{n} |
203eea5d RP |
747 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
748 | : xstrdup(rq); | |
6ca72cc6 | 749 | (_GDBP__) @b{n} |
70b88761 RP |
750 | 538 len_lquote = strlen(rquote); |
751 | @end smallexample | |
752 | ||
753 | @noindent | |
754 | The last line displayed looks a little odd; let's examine the variables | |
755 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
756 | and right quotes we specified. We can use the command @code{p} | |
757 | (@code{print}) to see their values. | |
758 | ||
759 | @smallexample | |
6ca72cc6 | 760 | (_GDBP__) @b{p lquote} |
70b88761 | 761 | $1 = 0x35d40 "<QUOTE>" |
6ca72cc6 | 762 | (_GDBP__) @b{p rquote} |
70b88761 RP |
763 | $2 = 0x35d50 "<UNQUOTE>" |
764 | @end smallexample | |
765 | ||
766 | @noindent | |
767 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
768 | Let's look at some context; we can display ten lines of source | |
769 | surrounding the current line, with the @code{l} (@code{list}) command. | |
770 | ||
771 | @smallexample | |
6ca72cc6 | 772 | (_GDBP__) @b{l} |
70b88761 | 773 | 533 xfree(rquote); |
e251e767 | 774 | 534 |
203eea5d RP |
775 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
776 | : xstrdup (lq); | |
777 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
778 | : xstrdup (rq); | |
e251e767 | 779 | 537 |
70b88761 RP |
780 | 538 len_lquote = strlen(rquote); |
781 | 539 len_rquote = strlen(lquote); | |
782 | 540 @} | |
e251e767 | 783 | 541 |
70b88761 RP |
784 | 542 void |
785 | @end smallexample | |
786 | ||
787 | @noindent | |
788 | Let's step past the two lines that set @code{len_lquote} and | |
789 | @code{len_rquote}, and then examine the values of those variables. | |
790 | ||
791 | @smallexample | |
6ca72cc6 | 792 | (_GDBP__) @b{n} |
70b88761 | 793 | 539 len_rquote = strlen(lquote); |
6ca72cc6 | 794 | (_GDBP__) @b{n} |
70b88761 | 795 | 540 @} |
6ca72cc6 | 796 | (_GDBP__) @b{p len_lquote} |
70b88761 | 797 | $3 = 9 |
6ca72cc6 | 798 | (_GDBP__) @b{p len_rquote} |
70b88761 RP |
799 | $4 = 7 |
800 | @end smallexample | |
801 | ||
802 | @noindent | |
803 | That certainly looks wrong, assuming @code{len_lquote} and | |
804 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
805 | @code{rquote} respectively. Let's try setting them to better values. | |
806 | We can use the @code{p} command for this, since it'll print the value of | |
807 | any expression---and that expression can include subroutine calls and | |
e251e767 | 808 | assignments. |
70b88761 RP |
809 | |
810 | @smallexample | |
6ca72cc6 | 811 | (_GDBP__) @b{p len_lquote=strlen(lquote)} |
70b88761 | 812 | $5 = 7 |
6ca72cc6 | 813 | (_GDBP__) @b{p len_rquote=strlen(rquote)} |
70b88761 RP |
814 | $6 = 9 |
815 | @end smallexample | |
816 | ||
817 | @noindent | |
818 | Let's see if that fixes the problem of using the new quotes with the | |
819 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
820 | executing with the @code{c} (@code{continue}) command, and then try the | |
821 | example that caused trouble initially: | |
822 | ||
823 | @smallexample | |
6ca72cc6 | 824 | (_GDBP__) @b{c} |
70b88761 RP |
825 | Continuing. |
826 | ||
6ca72cc6 | 827 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
70b88761 RP |
828 | |
829 | baz | |
830 | 0000 | |
831 | @end smallexample | |
832 | ||
833 | @noindent | |
834 | Success! The new quotes now work just as well as the default ones. The | |
835 | problem seems to have been just the two typos defining the wrong | |
836 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
837 | ||
838 | @smallexample | |
6ca72cc6 | 839 | @b{C-d} |
70b88761 RP |
840 | Program exited normally. |
841 | @end smallexample | |
842 | ||
e251e767 | 843 | @noindent |
70b88761 RP |
844 | The message @samp{Program exited normally.} is from _GDBN__; it |
845 | indicates @code{m4} has finished executing. We can end our _GDBN__ | |
846 | session with the _GDBN__ @code{quit} command. | |
847 | ||
848 | @smallexample | |
6ca72cc6 | 849 | (_GDBP__) @b{quit} |
70b88761 RP |
850 | _1__@end smallexample |
851 | ||
852 | @node Invocation, Commands, Sample Session, Top | |
853 | @chapter Getting In and Out of _GDBN__ | |
854 | ||
c7cb8acb RP |
855 | This chapter discusses how to start _GDBN__, and how to get out of it. |
856 | (The essentials: type @samp{_GDBP__} to start GDB, and type @kbd{quit} | |
857 | or @kbd{C-d} to exit.) | |
29a2b744 | 858 | |
70b88761 | 859 | @menu |
29a2b744 | 860 | * Invoking _GDBN__:: Starting _GDBN__ |
c2bbbb22 | 861 | * Leaving _GDBN__:: Leaving _GDBN__ |
b80282d5 | 862 | * Shell Commands:: Shell Commands |
70b88761 RP |
863 | @end menu |
864 | ||
29a2b744 | 865 | @node Invoking _GDBN__, Leaving _GDBN__, Invocation, Invocation |
70b88761 RP |
866 | @section Starting _GDBN__ |
867 | ||
1041a570 RP |
868 | Start _GDBN__ with the shell command @code{_GDBP__}. Once it's running, |
869 | _GDBN__ reads commands from the terminal until you tell it to exit. | |
70b88761 | 870 | |
c7cb8acb RP |
871 | You can also run @code{_GDBP__} with a variety of arguments and options, |
872 | to specify more of your debugging environment at the outset. | |
873 | ||
874 | The command-line options described here are designed | |
875 | to cover a variety of situations; in some environments, some of these | |
876 | options may effectively be unavailable. | |
877 | ||
878 | _if__(_H8__) | |
879 | For details on starting up _GDBP__ as a | |
880 | remote debugger attached to a Hitachi H8/300 board, see @ref{Hitachi | |
881 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}. | |
882 | _fi__(_H8__) | |
883 | ||
884 | The most usual way to start _GDBN__ is with one argument or two, | |
885 | specifying an executable program as the argument: | |
1041a570 | 886 | |
70b88761 | 887 | @example |
29a2b744 | 888 | _GDBP__ @var{program} |
70b88761 | 889 | @end example |
1041a570 | 890 | |
70b88761 | 891 | @noindent |
29a2b744 RP |
892 | You can also start with both an executable program and a core file |
893 | specified: | |
1041a570 | 894 | |
70b88761 | 895 | @example |
29a2b744 | 896 | _GDBP__ @var{program} @var{core} |
70b88761 RP |
897 | @end example |
898 | ||
b80282d5 RP |
899 | You can, instead, specify a process ID as a second argument, if you want |
900 | to debug a running process: | |
1041a570 | 901 | |
b80282d5 | 902 | @example |
29a2b744 | 903 | _GDBP__ @var{program} 1234 |
b80282d5 | 904 | @end example |
1041a570 | 905 | |
b80282d5 RP |
906 | @noindent |
907 | would attach _GDBN__ to process @code{1234} (unless you also have a file | |
908 | named @file{1234}; _GDBN__ does check for a core file first). | |
909 | ||
c7cb8acb RP |
910 | Taking advantage of the second command-line argument requires a fairly |
911 | complete operating system; when you use _GDBN__ as a remote debugger | |
912 | attached to a bare board, there may not be any notion of ``process'', | |
913 | and there is often no way to get a core dump. | |
914 | ||
70b88761 RP |
915 | @noindent |
916 | You can further control how _GDBN__ starts up by using command-line | |
29a2b744 RP |
917 | options. _GDBN__ itself can remind you of the options available. |
918 | ||
919 | @noindent | |
920 | Type | |
921 | ||
70b88761 RP |
922 | @example |
923 | _GDBP__ -help | |
924 | @end example | |
29a2b744 | 925 | |
70b88761 | 926 | @noindent |
29a2b744 | 927 | to display all available options and briefly describe their use |
70b88761 RP |
928 | (@samp{_GDBP__ -h} is a shorter equivalent). |
929 | ||
930 | All options and command line arguments you give are processed | |
931 | in sequential order. The order makes a difference when the | |
e251e767 | 932 | @samp{-x} option is used. |
70b88761 RP |
933 | |
934 | @menu | |
b80282d5 RP |
935 | * File Options:: Choosing Files |
936 | * Mode Options:: Choosing Modes | |
70b88761 RP |
937 | _if__(!_GENERIC__) |
938 | _include__(gdbinv-m.m4)_dnl__ | |
939 | _fi__(!_GENERIC__) | |
940 | @end menu | |
941 | ||
29a2b744 | 942 | @node File Options, Mode Options, Invoking _GDBN__, Invoking _GDBN__ |
70b88761 RP |
943 | @subsection Choosing Files |
944 | ||
29a2b744 RP |
945 | When _GDBN__ starts, it reads any arguments other than options as |
946 | specifying an executable file and core file (or process ID). This is | |
947 | the same as if the arguments were specified by the @samp{-se} and | |
948 | @samp{-c} options respectively. (_GDBN__ reads the first argument | |
949 | that does not have an associated option flag as equivalent to the | |
950 | @samp{-se} option followed by that argument; and the second argument | |
951 | that does not have an associated option flag, if any, as equivalent to | |
952 | the @samp{-c} option followed by that argument.) | |
953 | ||
954 | Many options have both long and short forms; both are shown in the | |
955 | following list. _GDBN__ also recognizes the long forms if you truncate | |
956 | them, so long as enough of the option is present to be unambiguous. | |
957 | (If you prefer, you can flag option arguments with @samp{--} rather | |
958 | than @samp{-}, though we illustrate the more usual convention.) | |
70b88761 RP |
959 | |
960 | @table @code | |
961 | @item -symbols=@var{file} | |
962 | @itemx -s @var{file} | |
963 | Read symbol table from file @var{file}. | |
964 | ||
965 | @item -exec=@var{file} | |
966 | @itemx -e @var{file} | |
967 | Use file @var{file} as the executable file to execute when | |
968 | appropriate, and for examining pure data in conjunction with a core | |
969 | dump. | |
970 | ||
3d3ab540 | 971 | @item -se=@var{file} |
70b88761 RP |
972 | Read symbol table from file @var{file} and use it as the executable |
973 | file. | |
974 | ||
975 | @item -core=@var{file} | |
976 | @itemx -c @var{file} | |
977 | Use file @var{file} as a core dump to examine. | |
978 | ||
979 | @item -command=@var{file} | |
980 | @itemx -x @var{file} | |
981 | Execute _GDBN__ commands from file @var{file}. @xref{Command Files}. | |
982 | ||
983 | @item -directory=@var{directory} | |
984 | @itemx -d @var{directory} | |
985 | Add @var{directory} to the path to search for source files. | |
14d01801 RP |
986 | |
987 | @item -m | |
988 | @itemx -mapped | |
989 | @emph{Warning: this option depends on operating system facilities that are not | |
990 | supported on all systems.}@* | |
77b46d13 JG |
991 | If memory-mapped files are available on your system through the @code{mmap} |
992 | system call, you can use this option | |
993 | to cause _GDBN__ to write the symbols from your | |
994 | program into a reusable file in the current directory. If the program you are debugging is | |
995 | called @file{/tmp/fred}, the mapped symbol file will be @file{./fred.syms}. | |
996 | Future _GDBN__ debugging sessions will notice the presence of this file, | |
997 | and will quickly map in symbol information from it, rather than reading | |
998 | the symbol table from the executable program. | |
999 | ||
1000 | The @file{.syms} file is specific to the host machine on which _GDBN__ is run. | |
1001 | It holds an exact image of _GDBN__'s internal symbol table. It cannot be | |
1002 | shared across multiple host platforms. | |
1003 | ||
1004 | @item -r | |
1005 | @itemx -readnow | |
1006 | Read each symbol file's entire symbol table immediately, rather than | |
1007 | the default, which is to read it incrementally as it is needed. | |
1008 | This makes startup slower, but makes future operations faster. | |
70b88761 RP |
1009 | @end table |
1010 | ||
77b46d13 JG |
1011 | The @code{-mapped} and @code{-readnow} options are typically combined in order to |
1012 | build a @file{.syms} file that contains complete symbol information. | |
1013 | A simple GDB invocation to do nothing but build a @file{.syms} file for future | |
1014 | use is: | |
1015 | ||
1016 | @example | |
1017 | gdb -batch -nx -mapped -readnow programname | |
1018 | @end example | |
1019 | ||
70b88761 | 1020 | _if__(!_GENERIC__) |
29a2b744 | 1021 | @node Mode Options, Mode Options, File Options, Invoking _GDBN__ |
70b88761 RP |
1022 | _fi__(!_GENERIC__) |
1023 | _if__(_GENERIC__) | |
29a2b744 RP |
1024 | @node Mode Options, , File Options, Invoking _GDBN__ |
1025 | _fi__(_GENERIC__) | |
1041a570 RP |
1026 | @subsection Choosing Modes |
1027 | ||
29a2b744 RP |
1028 | You can run _GDBN__ in various alternative modes---for example, in |
1029 | batch mode or quiet mode. | |
70b88761 RP |
1030 | |
1031 | @table @code | |
1032 | @item -nx | |
1033 | @itemx -n | |
1034 | Do not execute commands from any @file{_GDBINIT__} initialization files. | |
1035 | Normally, the commands in these files are executed after all the | |
e251e767 | 1036 | command options and arguments have been processed. |
c728f1f0 | 1037 | @xref{Command Files}. |
70b88761 RP |
1038 | |
1039 | @item -quiet | |
1040 | @itemx -q | |
1041 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 1042 | messages are also suppressed in batch mode. |
70b88761 RP |
1043 | |
1044 | @item -batch | |
1045 | Run in batch mode. Exit with status @code{0} after processing all the command | |
1046 | files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited). | |
1047 | Exit with nonzero status if an error occurs in executing the _GDBN__ | |
e251e767 | 1048 | commands in the command files. |
70b88761 RP |
1049 | |
1050 | Batch mode may be useful for running _GDBN__ as a filter, for example to | |
1051 | download and run a program on another computer; in order to make this | |
e251e767 | 1052 | more useful, the message |
1041a570 | 1053 | |
70b88761 RP |
1054 | @example |
1055 | Program exited normally. | |
1056 | @end example | |
1041a570 | 1057 | |
70b88761 RP |
1058 | @noindent |
1059 | (which is ordinarily issued whenever a program running under _GDBN__ control | |
1060 | terminates) is not issued when running in batch mode. | |
1061 | ||
3d3ab540 | 1062 | @item -cd=@var{directory} |
70b88761 RP |
1063 | Run _GDBN__ using @var{directory} as its working directory, |
1064 | instead of the current directory. | |
1065 | ||
6ca72cc6 | 1066 | _if__(_LUCID__) |
45c53080 | 1067 | @item -context @var{authentication} |
6ca72cc6 RP |
1068 | When the Energize programming system starts up _GDBN__, it uses this |
1069 | option to trigger an alternate mode of interaction. | |
1070 | @var{authentication} is a pair of numeric codes that identify _GDBN__ | |
1071 | as a client in the Energize environment. Avoid this option when you run | |
1072 | _GDBN__ directly from the command line. See @ref{Energize,,Using | |
1073 | _GDBN__ with Energize} for more discussion of using _GDBN__ with Energize. | |
1074 | _fi__(_LUCID__) | |
1075 | ||
70b88761 RP |
1076 | @item -fullname |
1077 | @itemx -f | |
1078 | Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ | |
1079 | to output the full file name and line number in a standard, | |
1080 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 1081 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
1082 | like two @samp{\032} characters, followed by the file name, line number |
1083 | and character position separated by colons, and a newline. The | |
1084 | Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as | |
1085 | a signal to display the source code for the frame. | |
1086 | ||
1087 | @item -b @var{bps} | |
1088 | Set the line speed (baud rate or bits per second) of any serial | |
1089 | interface used by _GDBN__ for remote debugging. | |
1090 | ||
3d3ab540 | 1091 | @item -tty=@var{device} |
70b88761 | 1092 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 1093 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
70b88761 RP |
1094 | @end table |
1095 | ||
1096 | _if__(!_GENERIC__) | |
1097 | _include__(gdbinv-s.m4) | |
1098 | _fi__(!_GENERIC__) | |
29a2b744 | 1099 | @node Leaving _GDBN__, Shell Commands, Invoking _GDBN__, Invocation |
70b88761 RP |
1100 | @section Leaving _GDBN__ |
1101 | @cindex exiting _GDBN__ | |
1041a570 | 1102 | |
70b88761 RP |
1103 | @table @code |
1104 | @item quit | |
1105 | @kindex quit | |
1106 | @kindex q | |
1107 | To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type | |
e251e767 | 1108 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
1109 | @end table |
1110 | ||
1111 | @cindex interrupt | |
1112 | An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather | |
1113 | will terminate the action of any _GDBN__ command that is in progress and | |
1114 | return to _GDBN__ command level. It is safe to type the interrupt | |
1115 | character at any time because _GDBN__ does not allow it to take effect | |
1116 | until a time when it is safe. | |
1117 | ||
1041a570 RP |
1118 | If you have been using _GDBN__ to control an attached process or device, you |
1119 | can release it with the @code{detach} command; @pxref{Attach, | |
1120 | ,Debugging an Already-Running Process}.. | |
70b88761 RP |
1121 | |
1122 | @node Shell Commands, , Leaving _GDBN__, Invocation | |
1123 | @section Shell Commands | |
1041a570 | 1124 | |
70b88761 | 1125 | If you need to execute occasional shell commands during your |
29a2b744 | 1126 | debugging session, there is no need to leave or suspend _GDBN__; you can |
70b88761 RP |
1127 | just use the @code{shell} command. |
1128 | ||
1129 | @table @code | |
1130 | @item shell @var{command string} | |
1131 | @kindex shell | |
1132 | @cindex shell escape | |
1133 | Directs _GDBN__ to invoke an inferior shell to execute @var{command | |
1134 | string}. If it exists, the environment variable @code{SHELL} is used | |
1135 | for the name of the shell to run. Otherwise _GDBN__ uses | |
1136 | @code{/bin/sh}. | |
1137 | @end table | |
1138 | ||
1139 | The utility @code{make} is often needed in development environments. | |
29a2b744 | 1140 | You do not have to use the @code{shell} command for this purpose in _GDBN__: |
70b88761 RP |
1141 | |
1142 | @table @code | |
1143 | @item make @var{make-args} | |
1144 | @kindex make | |
1145 | @cindex calling make | |
1146 | Causes _GDBN__ to execute an inferior @code{make} program with the specified | |
1147 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
1148 | @end table | |
1149 | ||
1150 | @node Commands, Running, Invocation, Top | |
1151 | @chapter _GDBN__ Commands | |
1152 | ||
6f3ec223 RP |
1153 | You can abbreviate a _GDBN__ command to the first few letters of the command |
1154 | name, if that abbreviation is unambiguous; and you can repeat certain | |
84c2fcad | 1155 | _GDBN__ commands by typing just @key{RET}. You can also use the @key{TAB} |
6f3ec223 RP |
1156 | key to get _GDBN__ to fill out the rest of a word in a command (or to |
1157 | show you the alternatives available, if there's more than one possibility). | |
29a2b744 | 1158 | |
70b88761 | 1159 | @menu |
b80282d5 | 1160 | * Command Syntax:: Command Syntax |
6f3ec223 | 1161 | * Completion:: Command Completion |
b80282d5 | 1162 | * Help:: Getting Help |
70b88761 RP |
1163 | @end menu |
1164 | ||
6f3ec223 | 1165 | @node Command Syntax, Completion, Commands, Commands |
70b88761 | 1166 | @section Command Syntax |
1041a570 | 1167 | |
70b88761 RP |
1168 | A _GDBN__ command is a single line of input. There is no limit on how long |
1169 | it can be. It starts with a command name, which is followed by arguments | |
1170 | whose meaning depends on the command name. For example, the command | |
1171 | @code{step} accepts an argument which is the number of times to step, | |
1172 | as in @samp{step 5}. You can also use the @code{step} command with | |
1173 | no arguments. Some command names do not allow any arguments. | |
1174 | ||
1175 | @cindex abbreviation | |
1176 | _GDBN__ command names may always be truncated if that abbreviation is | |
1177 | unambiguous. Other possible command abbreviations are listed in the | |
1178 | documentation for individual commands. In some cases, even ambiguous | |
1179 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1180 | equivalent to @code{step} even though there are other commands whose | |
1181 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1182 | arguments to the @code{help} command. |
70b88761 | 1183 | |
e251e767 | 1184 | @cindex repeating commands |
70b88761 RP |
1185 | @kindex RET |
1186 | A blank line as input to _GDBN__ (typing just @key{RET}) means to | |
1187 | repeat the previous command. Certain commands (for example, @code{run}) | |
1188 | will not repeat this way; these are commands for which unintentional | |
1189 | repetition might cause trouble and which you are unlikely to want to | |
1190 | repeat. | |
1191 | ||
1192 | The @code{list} and @code{x} commands, when you repeat them with | |
1193 | @key{RET}, construct new arguments rather than repeating | |
1194 | exactly as typed. This permits easy scanning of source or memory. | |
1195 | ||
b80282d5 RP |
1196 | _GDBN__ can also use @key{RET} in another way: to partition lengthy |
1197 | output, in a way similar to the common utility @code{more} | |
29a2b744 | 1198 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many |
b80282d5 RP |
1199 | in this situation, _GDBN__ disables command repetition after any command |
1200 | that generates this sort of display. | |
1201 | ||
70b88761 RP |
1202 | @kindex # |
1203 | @cindex comment | |
1204 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
29a2b744 | 1205 | This is useful mainly in command files (@pxref{Command Files}). |
70b88761 | 1206 | |
6f3ec223 RP |
1207 | @node Completion, Help, Command Syntax, Commands |
1208 | @section Command Completion | |
1209 | ||
1210 | @cindex completion | |
1211 | @cindex word completion | |
1212 | _GDBN__ can fill in the rest of a word in a command for you, if there's | |
1213 | only one possibility; it can also show you what the valid possibilities | |
1214 | are for the next word in a command, at any time. This works for _GDBN__ | |
1215 | commands, _GDBN__ subcommands, and the names of symbols in your program. | |
1216 | ||
1217 | Press the @key{TAB} key whenever you want _GDBN__ to fill out the rest | |
1218 | of a word. If there's only one possibility, _GDBN__ will fill in the | |
1219 | word, and wait for you to finish the command (or press @key{RET} to | |
1220 | enter it). For example, if you type | |
1221 | ||
0fdc6e27 RP |
1222 | @c FIXME "@key" doesn't distinguish its argument sufficiently to permit |
1223 | @c complete accuracy in these examples; space introduced for clarity. | |
1224 | @c If texinfo enhancements make it unnecessary, it would be nice to | |
1225 | @c replace " @key" by "@key" in the following... | |
6f3ec223 | 1226 | @example |
0fdc6e27 | 1227 | (_GDBP__) info bre @key{TAB} |
6f3ec223 RP |
1228 | @end example |
1229 | ||
1230 | @noindent | |
1231 | _GDBN__ fills in the rest of the word @samp{breakpoints}, since that's | |
1232 | the only @code{info} subcommand beginning with @samp{bre}: | |
1233 | ||
1234 | @example | |
1235 | (_GDBP__) info breakpoints | |
1236 | @end example | |
1237 | ||
1238 | @noindent | |
1239 | You can either press @key{RET} at this point, to run the @code{info | |
1240 | breakpoints} command, or backspace and enter something else, if | |
1241 | @samp{breakpoints} doesn't look like the command you expected. (If you | |
1242 | were sure you wanted @code{info breakpoints} in the first place, you | |
1243 | might as well just type @key{RET} immediately after @samp{info bre}, | |
1244 | to exploit command abbreviations rather than command completion). | |
1245 | ||
1246 | If there is more than one possibility for the next word when you press | |
1247 | @key{TAB}, _GDBN__ will sound a bell. You can either supply more | |
1248 | characters and try again, or just press @key{TAB} a second time, and | |
1249 | _GDBN__ will display all the possible completions for that word. For | |
1250 | example, you might want to set a breakpoint on a subroutine whose name | |
b1385986 | 1251 | begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} _GDBN__ |
6f3ec223 RP |
1252 | just sounds the bell. Typing @key{TAB} again will display all the |
1253 | function names in your program that begin with those characters, for | |
1254 | example: | |
1255 | ||
1256 | @example | |
0fdc6e27 | 1257 | (_GDBP__) b make_ @key{TAB} |
b1385986 | 1258 | @exdent _GDBN__ sounds bell; press @key{TAB} again, to see: |
6f3ec223 RP |
1259 | make_a_section_from_file make_environ |
1260 | make_abs_section make_function_type | |
1261 | make_blockvector make_pointer_type | |
1262 | make_cleanup make_reference_type | |
1263 | make_command make_symbol_completion_list | |
b1385986 | 1264 | (GDBP__) b make_ |
6f3ec223 RP |
1265 | @end example |
1266 | ||
1267 | @noindent | |
1268 | After displaying the available possibilities, _GDBN__ copies your | |
b1385986 | 1269 | partial input (@samp{b make_} in the example) so you can finish the |
6f3ec223 RP |
1270 | command. |
1271 | ||
1272 | If you just want to see the list of alternatives in the first place, you | |
b1385986 RP |
1273 | can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?} |
1274 | means @kbd{@key{META} ?}. You can type this either by holding down a | |
1275 | key designated as the @key{META} shift on your keyboard (if there is | |
1276 | one) while typing @kbd{?}, or by typing @key{ESC} followed by @kbd{?}. | |
6f3ec223 RP |
1277 | |
1278 | @cindex quotes in commands | |
1279 | @cindex completion of quoted strings | |
1280 | Sometimes the string you need, while logically a ``word'', may contain | |
1281 | parentheses or other characters that _GDBN__ normally excludes from its | |
1282 | notion of a word. To permit word completion to work in this situation, | |
1283 | you may enclose words in @code{'} (single quote marks) in _GDBN__ commands. | |
1284 | ||
1285 | The most likely situation where you might need this is in typing the | |
1286 | name of a C++ function. This is because C++ allows function overloading | |
1287 | (multiple definitions of the same function, distinguished by argument | |
b1385986 RP |
1288 | type). For example, when you want to set a breakpoint you may need to |
1289 | distinguish whether you mean the version of @code{name} that takes an | |
1290 | @code{int} parameter, @code{name(int)}, or the version that takes a | |
1291 | @code{float} parameter, @code{name(float)}. To use the word-completion | |
1292 | facilities in this situation, type a single quote @code{'} at the | |
1293 | beginning of the function name. This alerts _GDBN__ that it may need to | |
1294 | consider more information than usual when you press @key{TAB} or | |
1295 | @kbd{M-?} to request word completion: | |
6f3ec223 RP |
1296 | |
1297 | @example | |
0fdc6e27 RP |
1298 | (_GDBP__) b 'bubble( @key{M-?} |
1299 | bubble(double,double) bubble(int,int) | |
1300 | (_GDBP__) b 'bubble( | |
6f3ec223 RP |
1301 | @end example |
1302 | ||
0fdc6e27 RP |
1303 | In some cases, _GDBN__ can tell that completing a name will require |
1304 | quotes. When this happens, _GDBN__ will insert the quote for you (while | |
1305 | completing as much as it can) if you do not type the quote in the first | |
1306 | place: | |
1307 | ||
1308 | @example | |
1309 | (_GDBP__) b bub @key{TAB} | |
1310 | @exdent _GDBN__ alters your input line to the following, and rings a bell: | |
1311 | (_GDBP__) b 'bubble( | |
1312 | @end example | |
1313 | ||
1314 | @noindent | |
1315 | In general, _GDBN__ can tell that a quote is needed (and inserts it) if | |
1316 | you have not yet started typing the argument list when you ask for | |
1317 | completion on an overloaded symbol. | |
1318 | ||
1319 | ||
6f3ec223 | 1320 | @node Help, , Completion, Commands |
70b88761 RP |
1321 | @section Getting Help |
1322 | @cindex online documentation | |
1323 | @kindex help | |
1041a570 | 1324 | |
70b88761 | 1325 | You can always ask _GDBN__ itself for information on its commands, using the |
e251e767 | 1326 | command @code{help}. |
70b88761 RP |
1327 | |
1328 | @table @code | |
1329 | @item help | |
1330 | @itemx h | |
1331 | @kindex h | |
1332 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1333 | display a short list of named classes of commands: | |
1041a570 | 1334 | |
70b88761 RP |
1335 | @smallexample |
1336 | (_GDBP__) help | |
1337 | List of classes of commands: | |
1338 | ||
1339 | running -- Running the program | |
1340 | stack -- Examining the stack | |
1341 | data -- Examining data | |
1342 | breakpoints -- Making program stop at certain points | |
1343 | files -- Specifying and examining files | |
1344 | status -- Status inquiries | |
1345 | support -- Support facilities | |
1346 | user-defined -- User-defined commands | |
1347 | aliases -- Aliases of other commands | |
1348 | obscure -- Obscure features | |
1349 | ||
203eea5d RP |
1350 | Type "help" followed by a class name for a list of |
1351 | commands in that class. | |
1352 | Type "help" followed by command name for full | |
1353 | documentation. | |
70b88761 | 1354 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1355 | (_GDBP__) |
70b88761 RP |
1356 | @end smallexample |
1357 | ||
1358 | @item help @var{class} | |
1359 | Using one of the general help classes as an argument, you can get a | |
1360 | list of the individual commands in that class. For example, here is the | |
1361 | help display for the class @code{status}: | |
1041a570 | 1362 | |
70b88761 RP |
1363 | @smallexample |
1364 | (_GDBP__) help status | |
1365 | Status inquiries. | |
1366 | ||
1367 | List of commands: | |
1368 | ||
1369 | show -- Generic command for showing things set with "set" | |
1370 | info -- Generic command for printing status | |
1371 | ||
203eea5d RP |
1372 | Type "help" followed by command name for full |
1373 | documentation. | |
70b88761 | 1374 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1375 | (_GDBP__) |
70b88761 RP |
1376 | @end smallexample |
1377 | ||
1378 | @item help @var{command} | |
1379 | With a command name as @code{help} argument, _GDBN__ will display a | |
e251e767 | 1380 | short paragraph on how to use that command. |
70b88761 RP |
1381 | @end table |
1382 | ||
1383 | In addition to @code{help}, you can use the _GDBN__ commands @code{info} | |
1384 | and @code{show} to inquire about the state of your program, or the state | |
1385 | of _GDBN__ itself. Each command supports many topics of inquiry; this | |
1386 | manual introduces each of them in the appropriate context. The listings | |
1387 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1388 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1389 | |
1390 | @c @group | |
1391 | @table @code | |
1392 | @item info | |
1393 | @kindex info | |
1394 | @kindex i | |
1395 | This command (abbreviated @code{i}) is for describing the state of your | |
1396 | program; for example, it can list the arguments given to your program | |
1397 | (@code{info args}), the registers currently in use (@code{info | |
1041a570 | 1398 | registers}), or the breakpoints you have set (@code{info breakpoints}). |
70b88761 RP |
1399 | You can get a complete list of the @code{info} sub-commands with |
1400 | @w{@code{help info}}. | |
1401 | ||
1402 | @kindex show | |
1403 | @item show | |
1404 | In contrast, @code{show} is for describing the state of _GDBN__ itself. | |
1405 | You can change most of the things you can @code{show}, by using the | |
1406 | related command @code{set}; for example, you can control what number | |
1407 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1408 | which is currently in use with @code{show radix}. |
70b88761 RP |
1409 | |
1410 | @kindex info set | |
1411 | To display all the settable parameters and their current | |
1412 | values, you can use @code{show} with no arguments; you may also use | |
1413 | @code{info set}. Both commands produce the same display. | |
1414 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1415 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1416 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1417 | @end table | |
1418 | @c @end group | |
1419 | ||
1420 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1421 | exceptional in lacking corresponding @code{set} commands: | |
1422 | ||
1423 | @table @code | |
1424 | @kindex show version | |
3d3ab540 | 1425 | @cindex version number |
70b88761 RP |
1426 | @item show version |
1427 | Show what version of _GDBN__ is running. You should include this | |
1041a570 RP |
1428 | information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are in |
1429 | use at your site, you may occasionally want to make sure what version | |
1430 | of _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced, | |
1431 | and old ones may wither away. The version number is also announced | |
1432 | when you start _GDBN__ with no arguments. | |
70b88761 RP |
1433 | |
1434 | @kindex show copying | |
1435 | @item show copying | |
1436 | Display information about permission for copying _GDBN__. | |
1437 | ||
1438 | @kindex show warranty | |
1439 | @item show warranty | |
1440 | Display the GNU ``NO WARRANTY'' statement. | |
1441 | @end table | |
1442 | ||
1443 | @node Running, Stopping, Commands, Top | |
1444 | @chapter Running Programs Under _GDBN__ | |
1445 | ||
1041a570 RP |
1446 | To debug a program, you must run it under _GDBN__. |
1447 | ||
70b88761 | 1448 | @menu |
b80282d5 RP |
1449 | * Compilation:: Compiling for Debugging |
1450 | * Starting:: Starting your Program | |
1451 | * Arguments:: Your Program's Arguments | |
1452 | * Environment:: Your Program's Environment | |
1453 | * Working Directory:: Your Program's Working Directory | |
1454 | * Input/Output:: Your Program's Input and Output | |
1455 | * Attach:: Debugging an Already-Running Process | |
1456 | * Kill Process:: Killing the Child Process | |
d24e0922 | 1457 | * Process Information:: Additional Process Information |
70b88761 RP |
1458 | @end menu |
1459 | ||
1460 | @node Compilation, Starting, Running, Running | |
1461 | @section Compiling for Debugging | |
1462 | ||
1463 | In order to debug a program effectively, you need to generate | |
1464 | debugging information when you compile it. This debugging information | |
1465 | is stored in the object file; it describes the data type of each | |
1466 | variable or function and the correspondence between source line numbers | |
1467 | and addresses in the executable code. | |
1468 | ||
1469 | To request debugging information, specify the @samp{-g} option when you run | |
1470 | the compiler. | |
1471 | ||
1472 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1473 | options together. Using those compilers, you cannot generate optimized | |
1474 | executables containing debugging information. | |
1475 | ||
c7cb8acb RP |
1476 | _GCC__, the GNU C compiler, supports @samp{-g} with or without |
1477 | @samp{-O}, making it possible to debug optimized code. We recommend | |
1478 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1479 | You may think your program is correct, but there is no sense in pushing | |
1480 | your luck. | |
70b88761 | 1481 | |
6ca72cc6 RP |
1482 | @cindex optimized code, debugging |
1483 | @cindex debugging optimized code | |
1484 | When you debug a program compiled with @samp{-g -O}, remember that the | |
1485 | optimizer is rearranging your code; the debugger will show you what's | |
1486 | really there. Don't be too surprised when the execution path doesn't | |
1487 | exactly match your source file! An extreme example: if you define a | |
1488 | variable, but never use it, _GDBN__ will never see that | |
1489 | variable---because the compiler optimizes it out of existence. | |
1490 | ||
70b88761 RP |
1491 | Some things do not work as well with @samp{-g -O} as with just |
1492 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1493 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1494 | please report it as a bug (including a test case!). | |
1495 | ||
1496 | Older versions of the GNU C compiler permitted a variant option | |
c7cb8acb | 1497 | @w{@samp{-gg}} for debugging information. _GDBN__ no longer supports this |
70b88761 RP |
1498 | format; if your GNU C compiler has this option, do not use it. |
1499 | ||
1500 | @ignore | |
1501 | @comment As far as I know, there are no cases in which _GDBN__ will | |
1502 | @comment produce strange output in this case. (but no promises). | |
1503 | If your program includes archives made with the @code{ar} program, and | |
1504 | if the object files used as input to @code{ar} were compiled without the | |
1505 | @samp{-g} option and have names longer than 15 characters, _GDBN__ will get | |
29a2b744 | 1506 | confused reading your program's symbol table. No error message will be |
70b88761 RP |
1507 | given, but _GDBN__ may behave strangely. The reason for this problem is a |
1508 | deficiency in the Unix archive file format, which cannot represent file | |
1509 | names longer than 15 characters. | |
1510 | ||
1511 | To avoid this problem, compile the archive members with the @samp{-g} | |
1512 | option or use shorter file names. Alternatively, use a version of GNU | |
1513 | @code{ar} dated more recently than August 1989. | |
1514 | @end ignore | |
1515 | ||
70b88761 RP |
1516 | @node Starting, Arguments, Compilation, Running |
1517 | @section Starting your Program | |
1518 | @cindex starting | |
1519 | @cindex running | |
1041a570 | 1520 | |
70b88761 RP |
1521 | @table @code |
1522 | @item run | |
1523 | @itemx r | |
1524 | @kindex run | |
1041a570 RP |
1525 | Use the @code{run} command to start your program under _GDBN__. You must |
1526 | first specify the program name | |
e251e767 | 1527 | _if__(_VXWORKS__) |
7463aadd | 1528 | (except on VxWorks) |
70b88761 | 1529 | _fi__(_VXWORKS__) |
1041a570 RP |
1530 | with an argument to |
1531 | _GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the | |
1532 | @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to | |
1533 | Specify Files}). | |
1534 | ||
70b88761 RP |
1535 | @end table |
1536 | ||
29a2b744 RP |
1537 | If you are running your program in an execution environment that |
1538 | supports processes, @code{run} creates an inferior process and makes | |
1539 | that process run your program. (In environments without processes, | |
1540 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
1541 | |
1542 | The execution of a program is affected by certain information it | |
1543 | receives from its superior. _GDBN__ provides ways to specify this | |
6ca72cc6 | 1544 | information, which you must do @emph{before} starting your program. (You |
29a2b744 RP |
1545 | can change it after starting your program, but such changes will only affect |
1546 | your program the next time you start it.) This information may be | |
70b88761 RP |
1547 | divided into four categories: |
1548 | ||
1549 | @table @asis | |
6ca72cc6 | 1550 | @item The @emph{arguments.} |
29a2b744 | 1551 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
1552 | @code{run} command. If a shell is available on your target, the shell |
1553 | is used to pass the arguments, so that you may use normal conventions | |
1554 | (such as wildcard expansion or variable substitution) in describing | |
1555 | the arguments. In Unix systems, you can control which shell is used | |
1556 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
1557 | Program's Arguments}. | |
70b88761 | 1558 | |
6ca72cc6 | 1559 | @item The @emph{environment.} |
70b88761 RP |
1560 | Your program normally inherits its environment from _GDBN__, but you can |
1561 | use the _GDBN__ commands @code{set environment} and @code{unset | |
1562 | environment} to change parts of the environment that will be given to | |
1041a570 | 1563 | your program. @xref{Environment, ,Your Program's Environment}. |
70b88761 | 1564 | |
6ca72cc6 | 1565 | @item The @emph{working directory.} |
70b88761 RP |
1566 | Your program inherits its working directory from _GDBN__. You can set |
1567 | _GDBN__'s working directory with the @code{cd} command in _GDBN__. | |
29a2b744 | 1568 | @xref{Working Directory, ,Your Program's Working Directory}. |
70b88761 | 1569 | |
6ca72cc6 | 1570 | @item The @emph{standard input and output.} |
70b88761 RP |
1571 | Your program normally uses the same device for standard input and |
1572 | standard output as _GDBN__ is using. You can redirect input and output | |
1573 | in the @code{run} command line, or you can use the @code{tty} command to | |
1574 | set a different device for your program. | |
1041a570 | 1575 | @xref{Input/Output, ,Your Program's Input and Output}. |
3d3ab540 RP |
1576 | |
1577 | @cindex pipes | |
29a2b744 RP |
1578 | @emph{Warning:} While input and output redirection work, you cannot use |
1579 | pipes to pass the output of the program you are debugging to another | |
3d3ab540 RP |
1580 | program; if you attempt this, _GDBN__ is likely to wind up debugging the |
1581 | wrong program. | |
70b88761 RP |
1582 | @end table |
1583 | ||
29a2b744 | 1584 | @c FIXME: Rewrite following paragraph, especially its third sentence. |
1041a570 RP |
1585 | When you issue the @code{run} command, your program begins to execute |
1586 | immediately. @xref{Stopping, ,Stopping and Continuing}, for | |
29a2b744 RP |
1587 | discussion of how to arrange for your program to stop. Once your |
1588 | program has been started by the @code{run} command (and then stopped), | |
1041a570 RP |
1589 | you may evaluate expressions that involve calls to functions in your |
1590 | program, using the @code{print} or @code{call} commands. @xref{Data, | |
1591 | ,Examining Data}. | |
70b88761 | 1592 | |
29a2b744 | 1593 | If the modification time of your symbol file has changed since the |
1041a570 RP |
1594 | last time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and |
1595 | re-read it. When it does this, _GDBN__ tries to retain your current | |
1596 | breakpoints. | |
70b88761 RP |
1597 | |
1598 | @node Arguments, Environment, Starting, Running | |
1599 | @section Your Program's Arguments | |
1600 | ||
1601 | @cindex arguments (to your program) | |
1602 | The arguments to your program can be specified by the arguments of the | |
1603 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 1604 | characters and performs redirection of I/O, and thence to your program. |
70b88761 RP |
1605 | _GDBN__ uses the shell indicated by your environment variable |
1606 | @code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}. | |
1607 | ||
1608 | @code{run} with no arguments uses the same arguments used by the previous | |
1609 | @code{run}, or those set by the @code{set args} command. | |
1610 | ||
1611 | @kindex set args | |
1612 | @table @code | |
1613 | @item set args | |
1614 | Specify the arguments to be used the next time your program is run. If | |
1615 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 1616 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
1617 | using @code{set args} before the next @code{run} is the only way to run |
1618 | it again without arguments. | |
1619 | ||
1620 | @item show args | |
1621 | @kindex show args | |
1622 | Show the arguments to give your program when it is started. | |
1623 | @end table | |
1624 | ||
1625 | @node Environment, Working Directory, Arguments, Running | |
1626 | @section Your Program's Environment | |
1627 | ||
1628 | @cindex environment (of your program) | |
1629 | The @dfn{environment} consists of a set of environment variables and | |
1630 | their values. Environment variables conventionally record such things as | |
1631 | your user name, your home directory, your terminal type, and your search | |
1632 | path for programs to run. Usually you set up environment variables with | |
1633 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 1634 | debugging, it can be useful to try running your program with a modified |
70b88761 RP |
1635 | environment without having to start _GDBN__ over again. |
1636 | ||
1637 | @table @code | |
1638 | @item path @var{directory} | |
1639 | @kindex path | |
1640 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1641 | (the search path for executables), for both _GDBN__ and your program. | |
1642 | You may specify several directory names, separated by @samp{:} or | |
1643 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 1644 | the front, so it will be searched sooner. |
7463aadd RP |
1645 | |
1646 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1647 | working directory at the time _GDBN__ searches the path. If you use | |
1648 | @samp{.} instead, it refers to the directory where you executed the | |
1649 | @code{path} command. _GDBN__ fills in the current path where needed in | |
1650 | the @var{directory} argument, before adding it to the search path. | |
29a2b744 | 1651 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
1652 | @c document that, since repeating it would be a no-op. |
1653 | ||
1654 | @item show paths | |
1655 | @kindex show paths | |
1656 | Display the list of search paths for executables (the @code{PATH} | |
1657 | environment variable). | |
1658 | ||
1659 | @item show environment @r{[}@var{varname}@r{]} | |
1660 | @kindex show environment | |
1661 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 1662 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
1663 | print the names and values of all environment variables to be given to |
1664 | your program. You can abbreviate @code{environment} as @code{env}. | |
1665 | ||
7463aadd | 1666 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 RP |
1667 | @kindex set environment |
1668 | Sets environment variable @var{varname} to @var{value}. The value | |
1669 | changes for your program only, not for _GDBN__ itself. @var{value} may | |
1670 | be any string; the values of environment variables are just strings, and | |
1671 | any interpretation is supplied by your program itself. The @var{value} | |
1672 | parameter is optional; if it is eliminated, the variable is set to a | |
1673 | null value. | |
29a2b744 | 1674 | @c "any string" here does not include leading, trailing |
70b88761 RP |
1675 | @c blanks. Gnu asks: does anyone care? |
1676 | ||
1677 | For example, this command: | |
1678 | ||
1679 | @example | |
1680 | set env USER = foo | |
1681 | @end example | |
1682 | ||
1683 | @noindent | |
1684 | tells a Unix program, when subsequently run, that its user is named | |
1685 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1686 | are not actually required.) | |
1687 | ||
1688 | @item unset environment @var{varname} | |
1689 | @kindex unset environment | |
1690 | Remove variable @var{varname} from the environment to be passed to your | |
1691 | program. This is different from @samp{set env @var{varname} =}; | |
1692 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 1693 | rather than assigning it an empty value. |
70b88761 RP |
1694 | @end table |
1695 | ||
1696 | @node Working Directory, Input/Output, Environment, Running | |
1697 | @section Your Program's Working Directory | |
1698 | ||
1699 | @cindex working directory (of your program) | |
1700 | Each time you start your program with @code{run}, it inherits its | |
1701 | working directory from the current working directory of _GDBN__. _GDBN__'s | |
1702 | working directory is initially whatever it inherited from its parent | |
1703 | process (typically the shell), but you can specify a new working | |
1704 | directory in _GDBN__ with the @code{cd} command. | |
1705 | ||
1706 | The _GDBN__ working directory also serves as a default for the commands | |
1041a570 RP |
1707 | that specify files for _GDBN__ to operate on. @xref{Files, ,Commands to |
1708 | Specify Files}. | |
70b88761 RP |
1709 | |
1710 | @table @code | |
1711 | @item cd @var{directory} | |
1712 | @kindex cd | |
1713 | Set _GDBN__'s working directory to @var{directory}. | |
1714 | ||
1715 | @item pwd | |
1716 | @kindex pwd | |
1717 | Print _GDBN__'s working directory. | |
1718 | @end table | |
1719 | ||
1720 | @node Input/Output, Attach, Working Directory, Running | |
1721 | @section Your Program's Input and Output | |
1722 | ||
1723 | @cindex redirection | |
1724 | @cindex i/o | |
1725 | @cindex terminal | |
1726 | By default, the program you run under _GDBN__ does input and output to | |
1727 | the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to | |
1728 | its own terminal modes to interact with you, but it records the terminal | |
1729 | modes your program was using and switches back to them when you continue | |
1730 | running your program. | |
1731 | ||
1732 | @table @code | |
1733 | @item info terminal | |
1734 | @kindex info terminal | |
1735 | Displays _GDBN__'s recorded information about the terminal modes your | |
1736 | program is using. | |
1737 | @end table | |
1738 | ||
29a2b744 | 1739 | You can redirect your program's input and/or output using shell |
70b88761 RP |
1740 | redirection with the @code{run} command. For example, |
1741 | ||
1742 | _0__@example | |
1743 | run > outfile | |
1744 | _1__@end example | |
1745 | ||
1746 | @noindent | |
29a2b744 | 1747 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
1748 | |
1749 | @kindex tty | |
1750 | @cindex controlling terminal | |
29a2b744 | 1751 | Another way to specify where your program should do input and output is |
70b88761 RP |
1752 | with the @code{tty} command. This command accepts a file name as |
1753 | argument, and causes this file to be the default for future @code{run} | |
1754 | commands. It also resets the controlling terminal for the child | |
1755 | process, for future @code{run} commands. For example, | |
1756 | ||
1757 | @example | |
1758 | tty /dev/ttyb | |
1759 | @end example | |
1760 | ||
1761 | @noindent | |
1762 | directs that processes started with subsequent @code{run} commands | |
1763 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1764 | that as their controlling terminal. | |
1765 | ||
1766 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1767 | effect on the input/output device, but not its effect on the controlling | |
1768 | terminal. | |
1769 | ||
1770 | When you use the @code{tty} command or redirect input in the @code{run} | |
1771 | command, only the input @emph{for your program} is affected. The input | |
1772 | for _GDBN__ still comes from your terminal. | |
1773 | ||
1774 | @node Attach, Kill Process, Input/Output, Running | |
1775 | @section Debugging an Already-Running Process | |
1776 | @kindex attach | |
1777 | @cindex attach | |
1778 | ||
1779 | @table @code | |
1780 | @item attach @var{process-id} | |
1781 | This command | |
1782 | attaches to a running process---one that was started outside _GDBN__. | |
1783 | (@code{info files} will show your active targets.) The command takes as | |
1784 | argument a process ID. The usual way to find out the process-id of | |
1785 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
e251e767 | 1786 | shell command. |
70b88761 RP |
1787 | |
1788 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1789 | executing the command. | |
1790 | @end table | |
1791 | ||
1792 | To use @code{attach}, you must be debugging in an environment which | |
1793 | supports processes. You must also have permission to send the process a | |
1794 | signal, and it must have the same effective user ID as the _GDBN__ | |
1795 | process. | |
1796 | ||
1797 | When using @code{attach}, you should first use the @code{file} command | |
1798 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 1799 | @xref{Files, ,Commands to Specify Files}. |
70b88761 RP |
1800 | |
1801 | The first thing _GDBN__ does after arranging to debug the specified | |
1802 | process is to stop it. You can examine and modify an attached process | |
1803 | with all the _GDBN__ commands that are ordinarily available when you start | |
1804 | processes with @code{run}. You can insert breakpoints; you can step and | |
1805 | continue; you can modify storage. If you would rather the process | |
1806 | continue running, you may use the @code{continue} command after | |
1807 | attaching _GDBN__ to the process. | |
1808 | ||
1809 | @table @code | |
1810 | @item detach | |
1811 | @kindex detach | |
1812 | When you have finished debugging the attached process, you can use the | |
1813 | @code{detach} command to release it from _GDBN__'s control. Detaching | |
1814 | the process continues its execution. After the @code{detach} command, | |
1815 | that process and _GDBN__ become completely independent once more, and you | |
1816 | are ready to @code{attach} another process or start one with @code{run}. | |
1817 | @code{detach} will not repeat if you press @key{RET} again after | |
1818 | executing the command. | |
1819 | @end table | |
1820 | ||
1821 | If you exit _GDBN__ or use the @code{run} command while you have an attached | |
1822 | process, you kill that process. By default, you will be asked for | |
1823 | confirmation if you try to do either of these things; you can control | |
1824 | whether or not you need to confirm by using the @code{set confirm} command | |
29a2b744 | 1825 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). |
70b88761 | 1826 | |
d24e0922 | 1827 | @node Kill Process, Process Information, Attach, Running |
70b88761 RP |
1828 | @c @group |
1829 | @section Killing the Child Process | |
1830 | ||
1831 | @table @code | |
1832 | @item kill | |
1833 | @kindex kill | |
1834 | Kill the child process in which your program is running under _GDBN__. | |
1835 | @end table | |
1836 | ||
1837 | This command is useful if you wish to debug a core dump instead of a | |
1838 | running process. _GDBN__ ignores any core dump file while your program | |
1839 | is running. | |
1840 | @c @end group | |
1841 | ||
29a2b744 | 1842 | On some operating systems, a program cannot be executed outside _GDBN__ |
70b88761 | 1843 | while you have breakpoints set on it inside _GDBN__. You can use the |
29a2b744 | 1844 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
1845 | outside the debugger. |
1846 | ||
1847 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 1848 | relink your program, since on many systems it is impossible to modify an |
70b88761 RP |
1849 | executable file while it is running in a process. In this case, when you |
1850 | next type @code{run}, _GDBN__ will notice that the file has changed, and | |
1851 | will re-read the symbol table (while trying to preserve your current | |
1852 | breakpoint settings). | |
1853 | ||
d24e0922 RP |
1854 | @node Process Information, , Kill Process, Running |
1855 | @section Additional Process Information | |
1856 | ||
1857 | @kindex /proc | |
1858 | @cindex process image | |
1859 | Some operating systems provide a facility called @samp{/proc} that can | |
cc9bc574 RP |
1860 | be used to examine the image of a running process using file-system |
1861 | subroutines. If _GDBN__ is configured for an operating system with this | |
1862 | facility, the command @code{info proc} is available to report on several | |
1863 | kinds of information about the process running your program. | |
d24e0922 RP |
1864 | |
1865 | @table @code | |
1866 | @item info proc | |
1867 | @kindex info proc | |
1868 | Summarize available information about the process. | |
1869 | ||
1870 | @item info proc mappings | |
1871 | @kindex info proc mappings | |
1872 | Report on the address ranges accessible in the program, with information | |
1873 | on whether your program may read, write, or execute each range. | |
1874 | ||
1875 | @item info proc times | |
1876 | @kindex info proc times | |
1877 | Starting time, user CPU time, and system CPU time for your program and | |
1878 | its children. | |
1879 | ||
1880 | @item info proc id | |
1881 | @kindex info proc id | |
1882 | Report on the process ID's related to your program: its own process id, | |
1883 | the id of its parent, the process group id, and the session id. | |
1884 | ||
1885 | @item info proc status | |
1886 | @kindex info proc status | |
1887 | General information on the state of the process. If the process is | |
1888 | stopped, this report includes the reason for stopping, and any signal | |
1889 | received. | |
cc9bc574 RP |
1890 | |
1891 | @item info proc all | |
1892 | Show all the above information about the process. | |
d24e0922 RP |
1893 | @end table |
1894 | ||
70b88761 RP |
1895 | @node Stopping, Stack, Running, Top |
1896 | @chapter Stopping and Continuing | |
1897 | ||
1898 | The principal purpose of using a debugger is so that you can stop your | |
29a2b744 | 1899 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
1900 | trouble, you can investigate and find out why. |
1901 | ||
1902 | Inside _GDBN__, your program may stop for any of several reasons, such | |
1903 | as a signal, a breakpoint, or reaching a new line after a _GDBN__ | |
1904 | command such as @code{step}. You may then examine and change | |
1905 | variables, set new breakpoints or remove old ones, and then continue | |
1906 | execution. Usually, the messages shown by _GDBN__ provide ample | |
1907 | explanation of the status of your program---but you can also explicitly | |
1908 | request this information at any time. | |
1909 | ||
1910 | @table @code | |
1911 | @item info program | |
1912 | @kindex info program | |
1913 | Display information about the status of your program: whether it is | |
1914 | running or not, what process it is, and why it stopped. | |
1915 | @end table | |
1916 | ||
1917 | @menu | |
b80282d5 RP |
1918 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
1919 | * Continuing and Stepping:: Resuming Execution | |
1920 | * Signals:: Signals | |
70b88761 RP |
1921 | @end menu |
1922 | ||
3d3ab540 | 1923 | @node Breakpoints, Continuing and Stepping, Stopping, Stopping |
70b88761 RP |
1924 | @section Breakpoints, Watchpoints, and Exceptions |
1925 | ||
1926 | @cindex breakpoints | |
1927 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 1928 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 1929 | conditions to control in finer detail whether your program will stop. |
70b88761 | 1930 | You can set breakpoints with the @code{break} command and its variants |
29a2b744 RP |
1931 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where |
1932 | your program should stop by line number, function name or exact address | |
1041a570 | 1933 | in the program. In languages with exception handling (such as GNU |
29a2b744 | 1934 | C++), you can also set breakpoints where an exception is raised |
1041a570 | 1935 | (@pxref{Exception Handling, ,Breakpoints and Exceptions}). |
70b88761 RP |
1936 | |
1937 | @cindex watchpoints | |
6ca72cc6 RP |
1938 | @cindex memory tracing |
1939 | @cindex breakpoint on memory address | |
1940 | @cindex breakpoint on variable modification | |
29a2b744 RP |
1941 | A @dfn{watchpoint} is a special breakpoint that stops your program |
1942 | when the value of an expression changes. You must use a different | |
1943 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
1944 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
1945 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1041a570 | 1946 | and watchpoints using the same commands. |
70b88761 | 1947 | |
6ca72cc6 RP |
1948 | @cindex breakpoint numbers |
1949 | @cindex numbers for breakpoints | |
1950 | _GDBN__ assigns a number to each breakpoint or watchpoint when you | |
1951 | create it; these numbers are successive integers starting with one. In | |
1952 | many of the commands for controlling various features of breakpoints you | |
1953 | use the breakpoint number to say which breakpoint you want to change. | |
1954 | Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 1955 | no effect on your program until you enable it again. |
70b88761 RP |
1956 | |
1957 | @menu | |
b80282d5 RP |
1958 | * Set Breaks:: Setting Breakpoints |
1959 | * Set Watchpoints:: Setting Watchpoints | |
1960 | * Exception Handling:: Breakpoints and Exceptions | |
1961 | * Delete Breaks:: Deleting Breakpoints | |
1962 | * Disabling:: Disabling Breakpoints | |
1963 | * Conditions:: Break Conditions | |
1964 | * Break Commands:: Breakpoint Command Lists | |
1965 | * Breakpoint Menus:: Breakpoint Menus | |
e251e767 | 1966 | * Error in Breakpoints:: |
70b88761 RP |
1967 | @end menu |
1968 | ||
1969 | @node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints | |
1970 | @subsection Setting Breakpoints | |
1971 | ||
4906534f RP |
1972 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
1973 | @c consider in particular declaration with/without initialization. | |
1974 | @c | |
1975 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1976 | ||
70b88761 RP |
1977 | @kindex break |
1978 | @kindex b | |
6ca72cc6 RP |
1979 | @kindex $bpnum |
1980 | @cindex latest breakpoint | |
1981 | Breakpoints are set with the @code{break} command (abbreviated | |
1982 | @code{b}). The debugger convenience variable @samp{$bpnum} records the | |
1983 | number of the beakpoint you've set most recently; see @ref{Convenience | |
d24e0922 | 1984 | Vars,, Convenience Variables}, for a discussion of what you can do with |
6ca72cc6 | 1985 | convenience variables. |
70b88761 RP |
1986 | |
1987 | You have several ways to say where the breakpoint should go. | |
1988 | ||
1989 | @table @code | |
1990 | @item break @var{function} | |
1991 | Set a breakpoint at entry to function @var{function}. When using source | |
1992 | languages that permit overloading of symbols, such as C++, | |
1993 | @var{function} may refer to more than one possible place to break. | |
1994 | @xref{Breakpoint Menus}, for a discussion of that situation. | |
1995 | ||
1996 | @item break +@var{offset} | |
1997 | @itemx break -@var{offset} | |
1998 | Set a breakpoint some number of lines forward or back from the position | |
1999 | at which execution stopped in the currently selected frame. | |
2000 | ||
2001 | @item break @var{linenum} | |
2002 | Set a breakpoint at line @var{linenum} in the current source file. | |
2003 | That file is the last file whose source text was printed. This | |
29a2b744 | 2004 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
2005 | code on that line. |
2006 | ||
2007 | @item break @var{filename}:@var{linenum} | |
2008 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
2009 | ||
2010 | @item break @var{filename}:@var{function} | |
2011 | Set a breakpoint at entry to function @var{function} found in file | |
2012 | @var{filename}. Specifying a file name as well as a function name is | |
2013 | superfluous except when multiple files contain similarly named | |
2014 | functions. | |
2015 | ||
2016 | @item break *@var{address} | |
2017 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 2018 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
2019 | information or source files. |
2020 | ||
2021 | @item break | |
29a2b744 RP |
2022 | When called without any arguments, @code{break} sets a breakpoint at |
2023 | the next instruction to be executed in the selected stack frame | |
2024 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
2025 | innermost, this will cause your program to stop as soon as control | |
2026 | returns to that frame. This is similar to the effect of a | |
2027 | @code{finish} command in the frame inside the selected frame---except | |
2028 | that @code{finish} does not leave an active breakpoint. If you use | |
1041a570 RP |
2029 | @code{break} without an argument in the innermost frame, _GDBN__ will stop |
2030 | the next time it reaches the current location; this may be useful | |
2031 | inside loops. | |
70b88761 RP |
2032 | |
2033 | _GDBN__ normally ignores breakpoints when it resumes execution, until at | |
2034 | least one instruction has been executed. If it did not do this, you | |
2035 | would be unable to proceed past a breakpoint without first disabling the | |
2036 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 2037 | existed when your program stopped. |
70b88761 RP |
2038 | |
2039 | @item break @dots{} if @var{cond} | |
2040 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
2041 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 2042 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
2043 | @samp{@dots{}} stands for one of the possible arguments described |
2044 | above (or no argument) specifying where to break. @xref{Conditions, | |
2045 | ,Break Conditions}, for more information on breakpoint conditions. | |
70b88761 RP |
2046 | |
2047 | @item tbreak @var{args} | |
2048 | @kindex tbreak | |
2049 | Set a breakpoint enabled only for one stop. @var{args} are the | |
2050 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 RP |
2051 | way, but the breakpoint is automatically disabled after the first time your |
2052 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
70b88761 RP |
2053 | |
2054 | @item rbreak @var{regex} | |
2055 | @kindex rbreak | |
2056 | @cindex regular expression | |
4906534f | 2057 | @c FIXME what kind of regexp? |
70b88761 | 2058 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 2059 | @var{regex}. This command |
70b88761 RP |
2060 | sets an unconditional breakpoint on all matches, printing a list of all |
2061 | breakpoints it set. Once these breakpoints are set, they are treated | |
2062 | just like the breakpoints set with the @code{break} command. They can | |
2063 | be deleted, disabled, made conditional, etc., in the standard ways. | |
2064 | ||
b80282d5 RP |
2065 | When debugging C++ programs, @code{rbreak} is useful for setting |
2066 | breakpoints on overloaded functions that are not members of any special | |
2067 | classes. | |
2068 | ||
70b88761 | 2069 | @kindex info breakpoints |
c338a2fd | 2070 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 | 2071 | @item info breakpoints @r{[}@var{n}@r{]} |
6ca72cc6 RP |
2072 | @itemx info break @r{[}@var{n}@r{]} |
2073 | @itemx info watchpoints @r{[}@var{n}@r{]} | |
2074 | Print a table of all breakpoints and watchpoints set and not | |
2075 | deleted, with the following columns for each breakpoint: | |
2076 | ||
2077 | @table @emph | |
2078 | @item Breakpoint Numbers | |
2079 | @item Type | |
2080 | Breakpoint or watchpoint. | |
2081 | @item Disposition | |
2082 | Whether the breakpoint is marked to be disabled or deleted when hit. | |
2083 | @item Enabled or Disabled | |
d24e0922 | 2084 | Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints |
6ca72cc6 RP |
2085 | that are not enabled. |
2086 | @item Address | |
2087 | Where the breakpoint is in your program, as a memory address | |
2088 | @item What | |
2089 | Where the breakpoint is in the source for your program, as a file and | |
2090 | line number. | |
2091 | @end table | |
2092 | ||
2093 | @noindent | |
2094 | Breakpoint commands, if any, are listed after the line for the | |
2095 | corresponding breakpoint. | |
2096 | ||
2097 | @noindent | |
2098 | @code{info break} with a breakpoint | |
29a2b744 RP |
2099 | number @var{n} as argument lists only that breakpoint. The |
2100 | convenience variable @code{$_} and the default examining-address for | |
2101 | the @code{x} command are set to the address of the last breakpoint | |
6ca72cc6 | 2102 | listed (@pxref{Memory, ,Examining Memory}). |
1041a570 | 2103 | @end table |
70b88761 | 2104 | |
1041a570 RP |
2105 | _GDBN__ allows you to set any number of breakpoints at the same place in |
2106 | your program. There is nothing silly or meaningless about this. When | |
2107 | the breakpoints are conditional, this is even useful | |
29a2b744 | 2108 | (@pxref{Conditions, ,Break Conditions}). |
70b88761 | 2109 | |
6ca72cc6 RP |
2110 | @cindex negative breakpoint numbers |
2111 | @cindex internal _GDBN__ breakpoints | |
2112 | _GDBN__ itself sometimes sets breakpoints in your program for special | |
2113 | purposes, such as proper handling of @code{longjmp} (in C programs). | |
2114 | These internal breakpoints are assigned negative numbers, starting with | |
2115 | @code{-1}; @samp{info breakpoints} does not display them, but the | |
2116 | similar command @samp{info all-breakpoints} does. | |
2117 | ||
2118 | @table @code | |
2119 | @kindex all-breakpoints | |
2120 | @item info all-breakpoints | |
2121 | Using the same format as @samp{info breakpoints}, display both the | |
2122 | breakpoints you've set explicitly, and those _GDBN__ is using for | |
2123 | internal purposes. Internal breakpoints are shown with negative | |
2124 | breakpoint numbers. The type column identifies what kind of breakpoint | |
2125 | is shown: | |
2126 | ||
2127 | @table @code | |
2128 | @item breakpoint | |
2129 | Normal, explicitly set breakpoint. | |
2130 | ||
2131 | @item watchpoint | |
2132 | Normal, explicitly set watchpoint. | |
2133 | ||
2134 | @item longjmp | |
2135 | Internal breakpoint, used to handle correctly stepping through | |
2136 | @code{longjmp} calls. | |
2137 | ||
2138 | @item longjmp resume | |
2139 | Internal breakpoint at the target of a @code{longjmp}. | |
2140 | ||
2141 | @item until | |
2142 | Temporary internal breakpoint used by the _GDBN__ @code{until} command. | |
2143 | ||
2144 | @item finish | |
2145 | Temporary internal breakpoint used by the _GDBN__ @code{finish} command. | |
2146 | @end table | |
2147 | ||
2148 | @end table | |
2149 | ||
2150 | ||
70b88761 RP |
2151 | @node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints |
2152 | @subsection Setting Watchpoints | |
2153 | @cindex setting watchpoints | |
1041a570 | 2154 | |
70b88761 | 2155 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 2156 | expression changes, without having to predict a particular place |
70b88761 RP |
2157 | where this may happen. |
2158 | ||
2159 | Watchpoints currently execute two orders of magnitude more slowly than | |
2160 | other breakpoints, but this can well be worth it to catch errors where | |
2161 | you have no clue what part of your program is the culprit. Some | |
2162 | processors provide special hardware to support watchpoint evaluation; future | |
2163 | releases of _GDBN__ will use such hardware if it is available. | |
2164 | ||
2165 | @table @code | |
e251e767 | 2166 | @kindex watch |
70b88761 RP |
2167 | @item watch @var{expr} |
2168 | Set a watchpoint for an expression. | |
2169 | ||
2170 | @kindex info watchpoints | |
2171 | @item info watchpoints | |
6ca72cc6 RP |
2172 | This command prints a list of watchpoints and breakpoints; it is the |
2173 | same as @code{info break}. | |
70b88761 RP |
2174 | @end table |
2175 | ||
2176 | @node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints | |
2177 | @subsection Breakpoints and Exceptions | |
2178 | @cindex exception handlers | |
2179 | ||
b80282d5 | 2180 | Some languages, such as GNU C++, implement exception handling. You can |
29a2b744 RP |
2181 | use _GDBN__ to examine what caused your program to raise an exception, |
2182 | and to list the exceptions your program is prepared to handle at a | |
70b88761 RP |
2183 | given point in time. |
2184 | ||
2185 | @table @code | |
2186 | @item catch @var{exceptions} | |
2187 | @kindex catch | |
2188 | You can set breakpoints at active exception handlers by using the | |
2189 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
2190 | to catch. | |
2191 | @end table | |
2192 | ||
29a2b744 RP |
2193 | You can use @code{info catch} to list active exception handlers. |
2194 | @xref{Frame Info, ,Information About a Frame}. | |
70b88761 RP |
2195 | |
2196 | There are currently some limitations to exception handling in _GDBN__. | |
2197 | These will be corrected in a future release. | |
2198 | ||
2199 | @itemize @bullet | |
2200 | @item | |
2201 | If you call a function interactively, _GDBN__ normally returns | |
2202 | control to you when the function has finished executing. If the call | |
2203 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 2204 | returns control to you and cause your program to simply continue |
70b88761 RP |
2205 | running until it hits a breakpoint, catches a signal that _GDBN__ is |
2206 | listening for, or exits. | |
2207 | @item | |
2208 | You cannot raise an exception interactively. | |
2209 | @item | |
2210 | You cannot interactively install an exception handler. | |
2211 | @end itemize | |
2212 | ||
2213 | @cindex raise exceptions | |
2214 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 2215 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
2216 | stop @emph{before} the exception handler is called, since that way you |
2217 | can see the stack before any unwinding takes place. If you set a | |
2218 | breakpoint in an exception handler instead, it may not be easy to find | |
2219 | out where the exception was raised. | |
2220 | ||
2221 | To stop just before an exception handler is called, you need some | |
b80282d5 | 2222 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
2223 | raised by calling a library function named @code{__raise_exception} |
2224 | which has the following ANSI C interface: | |
2225 | ||
2226 | @example | |
b80282d5 | 2227 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
2228 | ID is the exception identifier. */ |
2229 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
2230 | @end example | |
2231 | ||
2232 | @noindent | |
2233 | To make the debugger catch all exceptions before any stack | |
2234 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
29a2b744 | 2235 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). |
70b88761 | 2236 | |
29a2b744 RP |
2237 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) |
2238 | that depends on the value of @var{id}, you can stop your program when | |
2239 | a specific exception is raised. You can use multiple conditional | |
2240 | breakpoints to stop your program when any of a number of exceptions are | |
2241 | raised. | |
70b88761 RP |
2242 | |
2243 | @node Delete Breaks, Disabling, Exception Handling, Breakpoints | |
2244 | @subsection Deleting Breakpoints | |
2245 | ||
2246 | @cindex clearing breakpoints, watchpoints | |
2247 | @cindex deleting breakpoints, watchpoints | |
2248 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 2249 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
2250 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
2251 | deleted no longer exists; it is forgotten. | |
2252 | ||
2253 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 2254 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
2255 | delete individual breakpoints or watchpoints by specifying their |
2256 | breakpoint numbers. | |
2257 | ||
2258 | It is not necessary to delete a breakpoint to proceed past it. _GDBN__ | |
2259 | automatically ignores breakpoints on the first instruction to be executed | |
2260 | when you continue execution without changing the execution address. | |
2261 | ||
2262 | @table @code | |
2263 | @item clear | |
2264 | @kindex clear | |
2265 | Delete any breakpoints at the next instruction to be executed in the | |
29a2b744 RP |
2266 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When |
2267 | the innermost frame is selected, this is a good way to delete a | |
2268 | breakpoint where your program just stopped. | |
70b88761 RP |
2269 | |
2270 | @item clear @var{function} | |
2271 | @itemx clear @var{filename}:@var{function} | |
2272 | Delete any breakpoints set at entry to the function @var{function}. | |
2273 | ||
2274 | @item clear @var{linenum} | |
2275 | @itemx clear @var{filename}:@var{linenum} | |
2276 | Delete any breakpoints set at or within the code of the specified line. | |
2277 | ||
2278 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2279 | @cindex delete breakpoints | |
2280 | @kindex delete | |
2281 | @kindex d | |
2282 | Delete the breakpoints or watchpoints of the numbers specified as | |
2283 | arguments. If no argument is specified, delete all breakpoints (_GDBN__ | |
1041a570 | 2284 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
2285 | can abbreviate this command as @code{d}. |
2286 | @end table | |
2287 | ||
2288 | @node Disabling, Conditions, Delete Breaks, Breakpoints | |
2289 | @subsection Disabling Breakpoints | |
2290 | ||
2291 | @cindex disabled breakpoints | |
2292 | @cindex enabled breakpoints | |
2293 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
2294 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
2295 | been deleted, but remembers the information on the breakpoint so that | |
2296 | you can @dfn{enable} it again later. | |
2297 | ||
2298 | You disable and enable breakpoints and watchpoints with the | |
2299 | @code{enable} and @code{disable} commands, optionally specifying one or | |
2300 | more breakpoint numbers as arguments. Use @code{info break} or | |
2301 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 2302 | do not know which numbers to use. |
70b88761 RP |
2303 | |
2304 | A breakpoint or watchpoint can have any of four different states of | |
2305 | enablement: | |
2306 | ||
2307 | @itemize @bullet | |
2308 | @item | |
29a2b744 | 2309 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2310 | with the @code{break} command starts out in this state. |
2311 | @item | |
29a2b744 | 2312 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2313 | @item |
29a2b744 | 2314 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2315 | when it does so it will become disabled. A breakpoint set |
2316 | with the @code{tbreak} command starts out in this state. | |
2317 | @item | |
29a2b744 | 2318 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2319 | immediately after it does so it will be deleted permanently. |
2320 | @end itemize | |
2321 | ||
2322 | You can use the following commands to enable or disable breakpoints and | |
2323 | watchpoints: | |
2324 | ||
2325 | @table @code | |
2326 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2327 | @kindex disable breakpoints | |
2328 | @kindex disable | |
2329 | @kindex dis | |
2330 | Disable the specified breakpoints---or all breakpoints, if none are | |
2331 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2332 | options such as ignore-counts, conditions and commands are remembered in | |
2333 | case the breakpoint is enabled again later. You may abbreviate | |
2334 | @code{disable} as @code{dis}. | |
2335 | ||
2336 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2337 | @kindex enable breakpoints | |
2338 | @kindex enable | |
2339 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2340 | become effective once again in stopping your program. |
70b88761 RP |
2341 | |
2342 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2343 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2344 | again the next time it stops your program. |
70b88761 RP |
2345 | |
2346 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2347 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2348 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2349 | @end table |
2350 | ||
29a2b744 RP |
2351 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
2352 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2353 | enabled; subsequently, they become disabled or enabled only when you | |
2354 | use one of the commands above. (The command @code{until} can set and | |
2355 | delete a breakpoint of its own, but it will not change the state of | |
98fe4566 | 2356 | your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.) |
70b88761 RP |
2357 | |
2358 | @node Conditions, Break Commands, Disabling, Breakpoints | |
2359 | @subsection Break Conditions | |
2360 | @cindex conditional breakpoints | |
2361 | @cindex breakpoint conditions | |
2362 | ||
4906534f RP |
2363 | @c FIXME what is scope of break condition expr? Context where wanted? |
2364 | @c in particular for a watchpoint? | |
29a2b744 | 2365 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2366 | specified place. You can also specify a @dfn{condition} for a |
2367 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2368 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2369 | a condition evaluates the expression each time your program reaches it, | |
2370 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2371 | |
2372 | This is the converse of using assertions for program validation; in that | |
2373 | situation, you want to stop when the assertion is violated---that is, | |
2374 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2375 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2376 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2377 | |
2378 | Conditions are also accepted for watchpoints; you may not need them, | |
2379 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2380 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2381 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2382 | one. |
70b88761 | 2383 | |
29a2b744 | 2384 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2385 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2386 | that log program progress, or to use your own print functions to |
2387 | format special data structures. The effects are completely predictable | |
2388 | unless there is another enabled breakpoint at the same address. (In | |
2389 | that case, _GDBN__ might see the other breakpoint first and stop your | |
2390 | program without checking the condition of this one.) Note that | |
2391 | breakpoint commands are usually more convenient and flexible for the | |
2392 | purpose of performing side effects when a breakpoint is reached | |
2393 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
70b88761 RP |
2394 | |
2395 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 RP |
2396 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
2397 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2398 | with the @code{condition} command. The @code{watch} command does not | |
2399 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2400 | impose a further condition on a watchpoint. | |
70b88761 | 2401 | |
e251e767 RP |
2402 | @table @code |
2403 | @item condition @var{bnum} @var{expression} | |
2404 | @kindex condition | |
70b88761 RP |
2405 | Specify @var{expression} as the break condition for breakpoint or |
2406 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2407 | your program only if the value of @var{expression} is true (nonzero, in |
70b88761 RP |
2408 | C). When you use @code{condition}, _GDBN__ checks @var{expression} |
2409 | immediately for syntactic correctness, and to determine whether symbols | |
1041a570 | 2410 | in it have referents in the context of your breakpoint. |
29a2b744 | 2411 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f RP |
2412 | @c about watchpoints? |
2413 | _GDBN__ does | |
70b88761 | 2414 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 2415 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
2416 | |
2417 | @item condition @var{bnum} | |
2418 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2419 | an ordinary unconditional breakpoint. | |
2420 | @end table | |
2421 | ||
2422 | @cindex ignore count (of breakpoint) | |
2423 | A special case of a breakpoint condition is to stop only when the | |
2424 | breakpoint has been reached a certain number of times. This is so | |
2425 | useful that there is a special way to do it, using the @dfn{ignore | |
2426 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2427 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 2428 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
2429 | ignore count is positive, then instead of stopping, it just decrements |
2430 | the ignore count by one and continues. As a result, if the ignore count | |
2431 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2432 | is reached. | |
2433 | ||
2434 | @table @code | |
2435 | @item ignore @var{bnum} @var{count} | |
2436 | @kindex ignore | |
2437 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2438 | The next @var{count} times the breakpoint is reached, your program's | |
2439 | execution will not stop; other than to decrement the ignore count, _GDBN__ | |
2440 | takes no action. | |
2441 | ||
2442 | To make the breakpoint stop the next time it is reached, specify | |
2443 | a count of zero. | |
2444 | ||
2445 | @item continue @var{count} | |
2446 | @itemx c @var{count} | |
2447 | @itemx fg @var{count} | |
2448 | @kindex continue @var{count} | |
29a2b744 RP |
2449 | Continue execution of your program, setting the ignore count of the |
2450 | breakpoint where your program stopped to @var{count} minus one. | |
2451 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
2452 | @var{count}'th time it is reached. |
2453 | ||
29a2b744 | 2454 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
2455 | due to a breakpoint. At other times, the argument to @code{continue} is |
2456 | ignored. | |
2457 | ||
2458 | The synonym @code{fg} is provided purely for convenience, and has | |
2459 | exactly the same behavior as other forms of the command. | |
2460 | @end table | |
2461 | ||
2462 | If a breakpoint has a positive ignore count and a condition, the condition | |
2463 | is not checked. Once the ignore count reaches zero, the condition will | |
2464 | be checked. | |
2465 | ||
29a2b744 | 2466 | You could achieve the effect of the ignore count with a condition such |
1041a570 RP |
2467 | as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience variable that |
2468 | is decremented each time. @xref{Convenience Vars, ,Convenience | |
2469 | Variables}. | |
70b88761 RP |
2470 | |
2471 | @node Break Commands, Breakpoint Menus, Conditions, Breakpoints | |
2472 | @subsection Breakpoint Command Lists | |
2473 | ||
2474 | @cindex breakpoint commands | |
2475 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 2476 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
2477 | might want to print the values of certain expressions, or enable other |
2478 | breakpoints. | |
2479 | ||
2480 | @table @code | |
2481 | @item commands @r{[}@var{bnum}@r{]} | |
2482 | @itemx @dots{} @var{command-list} @dots{} | |
2483 | @itemx end | |
2484 | @kindex commands | |
2485 | @kindex end | |
2486 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2487 | themselves appear on the following lines. Type a line containing just | |
2488 | @code{end} to terminate the commands. | |
2489 | ||
203eea5d RP |
2490 | To remove all commands from a breakpoint, type @code{commands} and |
2491 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
2492 | |
2493 | With no @var{bnum} argument, @code{commands} refers to the last | |
2494 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2495 | encountered). | |
2496 | @end table | |
2497 | ||
2498 | Pressing @key{RET} as a means of repeating the last _GDBN__ command is | |
2499 | disabled within a @var{command-list}. | |
2500 | ||
29a2b744 | 2501 | You can use breakpoint commands to start your program up again. Simply |
70b88761 RP |
2502 | use the @code{continue} command, or @code{step}, or any other command |
2503 | that resumes execution. Subsequent commands in the command list are | |
2504 | ignored. | |
2505 | ||
2506 | @kindex silent | |
2507 | If the first command specified is @code{silent}, the usual message about | |
2508 | stopping at a breakpoint is not printed. This may be desirable for | |
2509 | breakpoints that are to print a specific message and then continue. | |
2510 | If the remaining commands too print nothing, you will see no sign that | |
e251e767 | 2511 | the breakpoint was reached at all. @code{silent} is meaningful only |
70b88761 RP |
2512 | at the beginning of a breakpoint command list. |
2513 | ||
29a2b744 RP |
2514 | The commands @code{echo} and @code{output} that allow you to print |
2515 | precisely controlled output are often useful in silent breakpoints. | |
2516 | @xref{Output, ,Commands for Controlled Output}. | |
70b88761 RP |
2517 | |
2518 | For example, here is how you could use breakpoint commands to print the | |
2519 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2520 | ||
2521 | _0__@example | |
2522 | break foo if x>0 | |
2523 | commands | |
2524 | silent | |
2525 | echo x is\040 | |
2526 | output x | |
2527 | echo \n | |
2528 | cont | |
2529 | end | |
2530 | _1__@end example | |
2531 | ||
2532 | One application for breakpoint commands is to compensate for one bug so | |
2533 | you can test for another. Put a breakpoint just after the erroneous line | |
2534 | of code, give it a condition to detect the case in which something | |
2535 | erroneous has been done, and give it commands to assign correct values | |
2536 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 2537 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
2538 | command so that no output is produced. Here is an example: |
2539 | ||
2540 | @example | |
2541 | break 403 | |
2542 | commands | |
2543 | silent | |
2544 | set x = y + 4 | |
2545 | cont | |
2546 | end | |
2547 | @end example | |
2548 | ||
2549 | @cindex lost output | |
2550 | One deficiency in the operation of automatically continuing breakpoints | |
2551 | under Unix appears when your program uses raw mode for the terminal. | |
2552 | _GDBN__ switches back to its own terminal modes (not raw) before executing | |
2553 | commands, and then must switch back to raw mode when your program is | |
e251e767 | 2554 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
2555 | @c FIXME: revisit below when GNU sys avail. |
2556 | @c In the GNU system, this will be fixed by changing the behavior of | |
2557 | @c terminal modes. | |
2558 | ||
2559 | Under Unix, you can get around this problem by writing actions into | |
2560 | the breakpoint condition rather than in commands. For example | |
2561 | ||
2562 | @example | |
2563 | condition 5 (x = y + 4), 0 | |
2564 | @end example | |
2565 | ||
2566 | @noindent | |
1041a570 RP |
2567 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
2568 | change @code{x} as needed, then always have the value zero so your | |
2569 | program will not stop. No input is lost here, because _GDBN__ evaluates | |
2570 | break conditions without changing the terminal modes. When you want | |
2571 | to have nontrivial conditions for performing the side effects, the | |
2572 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 RP |
2573 | |
2574 | @node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints | |
2575 | @subsection Breakpoint Menus | |
b80282d5 | 2576 | @cindex overloading |
e251e767 | 2577 | @cindex symbol overloading |
70b88761 RP |
2578 | |
2579 | Some programming languages (notably C++) permit a single function name | |
2580 | to be defined several times, for application in different contexts. | |
2581 | This is called @dfn{overloading}. When a function name is overloaded, | |
6f3ec223 RP |
2582 | @samp{break @var{function}} is not enough to tell _GDBN__ where you want |
2583 | a breakpoint. If you realize this will be a problem, you can use | |
2584 | something like @samp{break @var{function}(@var{types})} to specify which | |
2585 | particular version of the function you want. Otherwise, _GDBN__ offers | |
2586 | you a menu of numbered choices for different possible breakpoints, and | |
2587 | waits for your selection with the prompt @samp{>}. The first two | |
2588 | options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1} | |
2589 | sets a breakpoint at each definition of @var{function}, and typing | |
2590 | @kbd{0} aborts the @code{break} command without setting any new | |
2591 | breakpoints. | |
70b88761 RP |
2592 | |
2593 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 2594 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
2595 | We choose three particular definitions of that function name: |
2596 | ||
6f3ec223 | 2597 | @c FIXME! This is likely to change to show arg type lists, at least |
70b88761 RP |
2598 | @example |
2599 | (_GDBP__) b String::after | |
2600 | [0] cancel | |
2601 | [1] all | |
2602 | [2] file:String.cc; line number:867 | |
2603 | [3] file:String.cc; line number:860 | |
2604 | [4] file:String.cc; line number:875 | |
2605 | [5] file:String.cc; line number:853 | |
2606 | [6] file:String.cc; line number:846 | |
2607 | [7] file:String.cc; line number:735 | |
2608 | > 2 4 6 | |
2609 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2610 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2611 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2612 | Multiple breakpoints were set. | |
2613 | Use the "delete" command to delete unwanted breakpoints. | |
e251e767 | 2614 | (_GDBP__) |
70b88761 RP |
2615 | @end example |
2616 | ||
70b88761 RP |
2617 | @node Error in Breakpoints, , Breakpoint Menus, Breakpoints |
2618 | @subsection ``Cannot Insert Breakpoints'' | |
2619 | ||
e251e767 | 2620 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 2621 | @c Q in pending mail to Gilmore. [email protected], 26mar91 |
e251e767 | 2622 | @c some light may be shed by looking at instances of |
d24e0922 | 2623 | @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise |
c338a2fd | 2624 | @c too. pesch, 20sep91 |
70b88761 RP |
2625 | Under some operating systems, breakpoints cannot be used in a program if |
2626 | any other process is running that program. In this situation, | |
2627 | attempting to run or continue a program with a breakpoint causes _GDBN__ | |
2628 | to stop the other process. | |
2629 | ||
2630 | When this happens, you have three ways to proceed: | |
2631 | ||
2632 | @enumerate | |
2633 | @item | |
2634 | Remove or disable the breakpoints, then continue. | |
2635 | ||
2636 | @item | |
29a2b744 | 2637 | Suspend _GDBN__, and copy the file containing your program to a new name. |
70b88761 | 2638 | Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__ |
29a2b744 | 2639 | should run your program under that name. Then start your program again. |
70b88761 RP |
2640 | |
2641 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2642 | @c explains the first FIXME: in this section... | |
2643 | ||
2644 | @item | |
29a2b744 | 2645 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
2646 | linker option @samp{-N}. The operating system limitation may not apply |
2647 | to nonsharable executables. | |
2648 | @end enumerate | |
2649 | ||
3d3ab540 RP |
2650 | @node Continuing and Stepping, Signals, Breakpoints, Stopping |
2651 | @section Continuing and Stepping | |
70b88761 RP |
2652 | |
2653 | @cindex stepping | |
7463aadd RP |
2654 | @cindex continuing |
2655 | @cindex resuming execution | |
3d3ab540 | 2656 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
2657 | completes normally. In contrast, @dfn{stepping} means executing just |
2658 | one more ``step'' of your program, where ``step'' may mean either one | |
2659 | line of source code, or one machine instruction (depending on what | |
2660 | particular command you use). Either when continuing | |
29a2b744 | 2661 | or when stepping, your program may stop even sooner, due to a breakpoint |
cedaf8bc | 2662 | or to a signal. (If due to a signal, you may want to use @code{handle}, |
1041a570 | 2663 | or use @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.) |
3d3ab540 RP |
2664 | |
2665 | @table @code | |
2666 | @item continue @r{[}@var{ignore-count}@r{]} | |
2667 | @kindex continue | |
29a2b744 | 2668 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
2669 | any breakpoints set at that address are bypassed. The optional argument |
2670 | @var{ignore-count} allows you to specify a further number of times to | |
2671 | ignore a breakpoint at this location; its effect is like that of | |
29a2b744 | 2672 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). |
3d3ab540 RP |
2673 | |
2674 | To resume execution at a different place, you can use @code{return} | |
29a2b744 RP |
2675 | (@pxref{Returning, ,Returning from a Function}) to go back to the |
2676 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
1041a570 | 2677 | Different Address}) to go to an arbitrary location in your program. |
3d3ab540 | 2678 | @end table |
7463aadd RP |
2679 | |
2680 | A typical technique for using stepping is to set a breakpoint | |
29a2b744 RP |
2681 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the |
2682 | beginning of the function or the section of your program where a | |
2683 | problem is believed to lie, run your program until it stops at that | |
2684 | breakpoint, and then step through the suspect area, examining the | |
2685 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
2686 | |
2687 | @table @code | |
2688 | @item step | |
2689 | @kindex step | |
2690 | @kindex s | |
29a2b744 | 2691 | Continue running your program until control reaches a different source |
7463aadd | 2692 | line, then stop it and return control to _GDBN__. This command is |
70b88761 RP |
2693 | abbreviated @code{s}. |
2694 | ||
3d3ab540 RP |
2695 | @quotation |
2696 | @emph{Warning:} If you use the @code{step} command while control is | |
2697 | within a function that was compiled without debugging information, | |
2698 | execution will proceed until control reaches another function. | |
2699 | @end quotation | |
70b88761 RP |
2700 | |
2701 | @item step @var{count} | |
2702 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2703 | breakpoint is reached or a signal not related to stepping occurs before | |
2704 | @var{count} steps, stepping stops right away. | |
2705 | ||
7463aadd | 2706 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2707 | @kindex next |
2708 | @kindex n | |
7463aadd RP |
2709 | Continue to the next source line in the current (innermost) stack frame. |
2710 | Similar to @code{step}, but any function calls appearing within the line | |
2711 | of code are executed without stopping. Execution stops when control | |
2712 | reaches a different line of code at the stack level which was executing | |
2713 | when the @code{next} command was given. This command is abbreviated | |
2714 | @code{n}. | |
70b88761 | 2715 | |
7463aadd | 2716 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2717 | |
2718 | @code{next} within a function that lacks debugging information acts like | |
2719 | @code{step}, but any function calls appearing within the code of the | |
2720 | function are executed without stopping. | |
2721 | ||
2722 | @item finish | |
2723 | @kindex finish | |
7463aadd RP |
2724 | Continue running until just after function in the selected stack frame |
2725 | returns. Print the returned value (if any). | |
70b88761 | 2726 | |
29a2b744 | 2727 | Contrast this with the @code{return} command (@pxref{Returning, |
1041a570 | 2728 | ,Returning from a Function}). |
70b88761 RP |
2729 | |
2730 | @item until | |
2731 | @kindex until | |
2732 | @item u | |
2733 | @kindex u | |
2734 | Continue running until a source line past the current line, in the | |
2735 | current stack frame, is reached. This command is used to avoid single | |
2736 | stepping through a loop more than once. It is like the @code{next} | |
2737 | command, except that when @code{until} encounters a jump, it | |
2738 | automatically continues execution until the program counter is greater | |
2739 | than the address of the jump. | |
2740 | ||
2741 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 2742 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
2743 | until the loop is exited. In contrast, a @code{next} command at the end |
2744 | of a loop will simply step back to the beginning of the loop, which | |
2745 | would force you to step through the next iteration. | |
2746 | ||
29a2b744 | 2747 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
2748 | stack frame. |
2749 | ||
2750 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2751 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2752 | example, in the following excerpt from a debugging session, the @code{f} |
2753 | (@code{frame}) command shows that execution is stopped at line | |
2754 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2755 | ||
2756 | @example | |
2757 | (_GDBP__) f | |
2758 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
b80282d5 | 2759 | 206 expand_input(); |
70b88761 | 2760 | (_GDBP__) until |
b80282d5 | 2761 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
2762 | @end example |
2763 | ||
7463aadd RP |
2764 | This happened because, for execution efficiency, the compiler had |
2765 | generated code for the loop closure test at the end, rather than the | |
2766 | start, of the loop---even though the test in a C @code{for}-loop is | |
2767 | written before the body of the loop. The @code{until} command appeared | |
2768 | to step back to the beginning of the loop when it advanced to this | |
2769 | expression; however, it has not really gone to an earlier | |
2770 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2771 | |
2772 | @code{until} with no argument works by means of single | |
2773 | instruction stepping, and hence is slower than @code{until} with an | |
2774 | argument. | |
2775 | ||
2776 | @item until @var{location} | |
2777 | @item u @var{location} | |
29a2b744 RP |
2778 | Continue running your program until either the specified location is |
2779 | reached, or the current stack frame returns. @var{location} is any of | |
2780 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
2781 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
1041a570 | 2782 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
2783 | |
2784 | @item stepi | |
2785 | @itemx si | |
2786 | @kindex stepi | |
2787 | @kindex si | |
2788 | Execute one machine instruction, then stop and return to the debugger. | |
2789 | ||
2790 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2791 | instructions. This will cause the next instruction to be executed to | |
29a2b744 RP |
2792 | be displayed automatically at each stop. @xref{Auto Display, |
2793 | ,Automatic Display}. | |
70b88761 RP |
2794 | |
2795 | An argument is a repeat count, as in @code{step}. | |
2796 | ||
2797 | @item nexti | |
2798 | @itemx ni | |
2799 | @kindex nexti | |
2800 | @kindex ni | |
2801 | Execute one machine instruction, but if it is a function call, | |
2802 | proceed until the function returns. | |
2803 | ||
2804 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
2805 | @end table |
2806 | ||
3d3ab540 | 2807 | @node Signals, , Continuing and Stepping, Stopping |
70b88761 RP |
2808 | @section Signals |
2809 | @cindex signals | |
2810 | ||
2811 | A signal is an asynchronous event that can happen in a program. The | |
2812 | operating system defines the possible kinds of signals, and gives each | |
2813 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2814 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2815 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2816 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 2817 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
2818 | requested an alarm). |
2819 | ||
2820 | @cindex fatal signals | |
2821 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
2822 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
2823 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 2824 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 2825 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
2826 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
2827 | ||
29a2b744 RP |
2828 | _GDBN__ has the ability to detect any occurrence of a signal in your |
2829 | program. You can tell _GDBN__ in advance what to do for each kind of | |
2830 | signal. | |
70b88761 RP |
2831 | |
2832 | @cindex handling signals | |
2833 | Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM} | |
29a2b744 RP |
2834 | (so as not to interfere with their role in the functioning of your program) |
2835 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
2836 | You can change these settings with the @code{handle} command. |
2837 | ||
2838 | @table @code | |
2839 | @item info signals | |
2840 | @kindex info signals | |
2841 | Print a table of all the kinds of signals and how _GDBN__ has been told to | |
2842 | handle each one. You can use this to see the signal numbers of all | |
2843 | the defined types of signals. | |
2844 | ||
2845 | @item handle @var{signal} @var{keywords}@dots{} | |
2846 | @kindex handle | |
2847 | Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the | |
2848 | number of a signal or its name (with or without the @samp{SIG} at the | |
2849 | beginning). The @var{keywords} say what change to make. | |
2850 | @end table | |
2851 | ||
2852 | @c @group | |
2853 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2854 | Their full names are: | |
2855 | ||
2856 | @table @code | |
2857 | @item nostop | |
29a2b744 | 2858 | _GDBN__ should not stop your program when this signal happens. It may |
70b88761 RP |
2859 | still print a message telling you that the signal has come in. |
2860 | ||
2861 | @item stop | |
29a2b744 | 2862 | _GDBN__ should stop your program when this signal happens. This implies |
70b88761 RP |
2863 | the @code{print} keyword as well. |
2864 | ||
2865 | @item print | |
2866 | _GDBN__ should print a message when this signal happens. | |
2867 | ||
2868 | @item noprint | |
2869 | _GDBN__ should not mention the occurrence of the signal at all. This | |
2870 | implies the @code{nostop} keyword as well. | |
2871 | ||
2872 | @item pass | |
29a2b744 | 2873 | _GDBN__ should allow your program to see this signal; your program will be |
70b88761 RP |
2874 | able to handle the signal, or may be terminated if the signal is fatal |
2875 | and not handled. | |
2876 | ||
2877 | @item nopass | |
29a2b744 | 2878 | _GDBN__ should not allow your program to see this signal. |
70b88761 RP |
2879 | @end table |
2880 | @c @end group | |
2881 | ||
29a2b744 | 2882 | When a signal has been set to stop your program, your program cannot see the |
70b88761 | 2883 | signal until you continue. It will see the signal then, if @code{pass} is |
6ca72cc6 | 2884 | in effect for the signal in question @emph{at that time}. In other words, |
70b88761 RP |
2885 | after _GDBN__ reports a signal, you can use the @code{handle} command with |
2886 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
29a2b744 | 2887 | your program when you later continue it. |
70b88761 | 2888 | |
29a2b744 | 2889 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 2890 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 2891 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
2892 | due to some sort of memory reference error, you might store correct |
2893 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
2894 | execution; but your program would probably terminate immediately as |
2895 | a result of the fatal signal once it saw the signal. To prevent this, | |
2896 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
2897 | Program a Signal}. | |
70b88761 RP |
2898 | |
2899 | @node Stack, Source, Stopping, Top | |
2900 | @chapter Examining the Stack | |
2901 | ||
2902 | When your program has stopped, the first thing you need to know is where it | |
2903 | stopped and how it got there. | |
2904 | ||
2905 | @cindex call stack | |
2906 | Each time your program performs a function call, the information about | |
29a2b744 | 2907 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
2908 | called a @dfn{stack frame}. The frame also contains the arguments of the |
2909 | call and the local variables of the function that was called. All the | |
2910 | stack frames are allocated in a region of memory called the @dfn{call | |
2911 | stack}. | |
2912 | ||
2913 | When your program stops, the _GDBN__ commands for examining the stack allow you | |
2914 | to see all of this information. | |
2915 | ||
2916 | @cindex selected frame | |
2917 | One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands | |
2918 | refer implicitly to the selected frame. In particular, whenever you ask | |
29a2b744 | 2919 | _GDBN__ for the value of a variable in your program, the value is found in the |
70b88761 RP |
2920 | selected frame. There are special _GDBN__ commands to select whichever frame |
2921 | you are interested in. | |
2922 | ||
29a2b744 | 2923 | When your program stops, _GDBN__ automatically selects the currently executing |
70b88761 | 2924 | frame and describes it briefly as the @code{frame} command does |
29a2b744 | 2925 | (@pxref{Frame Info, ,Information About a Frame}). |
70b88761 RP |
2926 | |
2927 | @menu | |
b80282d5 RP |
2928 | * Frames:: Stack Frames |
2929 | * Backtrace:: Backtraces | |
2930 | * Selection:: Selecting a Frame | |
2931 | * Frame Info:: Information on a Frame | |
70b88761 RP |
2932 | @end menu |
2933 | ||
2934 | @node Frames, Backtrace, Stack, Stack | |
2935 | @section Stack Frames | |
2936 | ||
2937 | @cindex frame | |
2938 | @cindex stack frame | |
2939 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2940 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2941 | with one call to one function. The frame contains the arguments given | |
2942 | to the function, the function's local variables, and the address at | |
2943 | which the function is executing. | |
2944 | ||
2945 | @cindex initial frame | |
2946 | @cindex outermost frame | |
2947 | @cindex innermost frame | |
2948 | When your program is started, the stack has only one frame, that of the | |
2949 | function @code{main}. This is called the @dfn{initial} frame or the | |
2950 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2951 | made. Each time a function returns, the frame for that function invocation | |
2952 | is eliminated. If a function is recursive, there can be many frames for | |
2953 | the same function. The frame for the function in which execution is | |
2954 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2955 | recently created of all the stack frames that still exist. | |
2956 | ||
2957 | @cindex frame pointer | |
2958 | Inside your program, stack frames are identified by their addresses. A | |
2959 | stack frame consists of many bytes, each of which has its own address; each | |
2960 | kind of computer has a convention for choosing one of those bytes whose | |
2961 | address serves as the address of the frame. Usually this address is kept | |
2962 | in a register called the @dfn{frame pointer register} while execution is | |
2963 | going on in that frame. | |
2964 | ||
2965 | @cindex frame number | |
2966 | _GDBN__ assigns numbers to all existing stack frames, starting with | |
2967 | zero for the innermost frame, one for the frame that called it, | |
2968 | and so on upward. These numbers do not really exist in your program; | |
2969 | they are assigned by _GDBN__ to give you a way of designating stack | |
2970 | frames in _GDBN__ commands. | |
2971 | ||
2972 | @cindex frameless execution | |
2973 | Some compilers allow functions to be compiled so that they operate | |
2974 | without stack frames. (For example, the @code{_GCC__} option | |
2975 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2976 | This is occasionally done with heavily used library functions to save | |
2977 | the frame setup time. _GDBN__ has limited facilities for dealing with | |
2978 | these function invocations. If the innermost function invocation has no | |
2979 | stack frame, _GDBN__ will nevertheless regard it as though it had a | |
2980 | separate frame, which is numbered zero as usual, allowing correct | |
2981 | tracing of the function call chain. However, _GDBN__ has no provision | |
2982 | for frameless functions elsewhere in the stack. | |
2983 | ||
2984 | @node Backtrace, Selection, Frames, Stack | |
2985 | @section Backtraces | |
2986 | ||
29a2b744 | 2987 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
2988 | line per frame, for many frames, starting with the currently executing |
2989 | frame (frame zero), followed by its caller (frame one), and on up the | |
2990 | stack. | |
2991 | ||
2992 | @table @code | |
2993 | @item backtrace | |
2994 | @itemx bt | |
2995 | @kindex backtrace | |
2996 | @kindex bt | |
2997 | Print a backtrace of the entire stack: one line per frame for all | |
2998 | frames in the stack. | |
2999 | ||
3000 | You can stop the backtrace at any time by typing the system interrupt | |
3001 | character, normally @kbd{C-c}. | |
3002 | ||
3003 | @item backtrace @var{n} | |
3004 | @itemx bt @var{n} | |
3005 | Similar, but print only the innermost @var{n} frames. | |
3006 | ||
3007 | @item backtrace -@var{n} | |
3008 | @itemx bt -@var{n} | |
3009 | Similar, but print only the outermost @var{n} frames. | |
3010 | @end table | |
3011 | ||
3012 | @kindex where | |
3013 | @kindex info stack | |
3014 | @kindex info s | |
3015 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
3016 | are additional aliases for @code{backtrace}. | |
3017 | ||
3018 | Each line in the backtrace shows the frame number and the function name. | |
3019 | The program counter value is also shown---unless you use @code{set | |
3020 | print address off}. The backtrace also shows the source file name and | |
3021 | line number, as well as the arguments to the function. The program | |
3022 | counter value is omitted if it is at the beginning of the code for that | |
3023 | line number. | |
3024 | ||
3025 | Here is an example of a backtrace. It was made with the command | |
3026 | @samp{bt 3}, so it shows the innermost three frames. | |
3027 | ||
3028 | @smallexample | |
3029 | @group | |
203eea5d RP |
3030 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
3031 | at builtin.c:993 | |
70b88761 RP |
3032 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
3033 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
3034 | at macro.c:71 | |
3035 | (More stack frames follow...) | |
3036 | @end group | |
3037 | @end smallexample | |
3038 | ||
3039 | @noindent | |
29a2b744 RP |
3040 | The display for frame zero does not begin with a program counter |
3041 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
3042 | code for line @code{993} of @code{builtin.c}. |
3043 | ||
3044 | @node Selection, Frame Info, Backtrace, Stack | |
3045 | @section Selecting a Frame | |
3046 | ||
29a2b744 | 3047 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
3048 | whichever stack frame is selected at the moment. Here are the commands for |
3049 | selecting a stack frame; all of them finish by printing a brief description | |
3050 | of the stack frame just selected. | |
3051 | ||
3052 | @table @code | |
3053 | @item frame @var{n} | |
3054 | @itemx f @var{n} | |
3055 | @kindex frame | |
3056 | @kindex f | |
3057 | Select frame number @var{n}. Recall that frame zero is the innermost | |
3058 | (currently executing) frame, frame one is the frame that called the | |
3059 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
3060 | frame. | |
3061 | ||
3062 | @item frame @var{addr} | |
3063 | @itemx f @var{addr} | |
3064 | Select the frame at address @var{addr}. This is useful mainly if the | |
3065 | chaining of stack frames has been damaged by a bug, making it | |
3066 | impossible for _GDBN__ to assign numbers properly to all frames. In | |
29a2b744 | 3067 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
3068 | switches between them. |
3069 | ||
c728f1f0 | 3070 | _if__(_SPARC__) |
70b88761 | 3071 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 3072 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
3073 | @c note to future updaters: this is conditioned on a flag |
3074 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
3075 | @c by SPARC, hence the specific attribution. Generalize or list all | |
3076 | @c possibilities if more supported machines start doing this. | |
c728f1f0 | 3077 | _fi__(_SPARC__) |
70b88761 RP |
3078 | |
3079 | @item up @var{n} | |
3080 | @kindex up | |
3081 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
3082 | advances toward the outermost frame, to higher frame numbers, to frames | |
3083 | that have existed longer. @var{n} defaults to one. | |
3084 | ||
3085 | @item down @var{n} | |
3086 | @kindex down | |
3087 | @kindex do | |
3088 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
3089 | advances toward the innermost frame, to lower frame numbers, to frames | |
3090 | that were created more recently. @var{n} defaults to one. You may | |
3091 | abbreviate @code{down} as @code{do}. | |
3092 | @end table | |
3093 | ||
3094 | All of these commands end by printing two lines of output describing the | |
3095 | frame. The first line shows the frame number, the function name, the | |
3096 | arguments, and the source file and line number of execution in that | |
3097 | frame. The second line shows the text of that source line. For | |
3098 | example: | |
3099 | ||
3100 | @smallexample | |
29a2b744 | 3101 | @group |
70b88761 | 3102 | (_GDBP__) up |
203eea5d RP |
3103 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
3104 | at env.c:10 | |
70b88761 | 3105 | 10 read_input_file (argv[i]); |
29a2b744 | 3106 | @end group |
70b88761 RP |
3107 | @end smallexample |
3108 | ||
29a2b744 RP |
3109 | After such a printout, the @code{list} command with no arguments will |
3110 | print ten lines centered on the point of execution in the frame. | |
3111 | @xref{List, ,Printing Source Lines}. | |
70b88761 RP |
3112 | |
3113 | @table @code | |
3114 | @item up-silently @var{n} | |
3115 | @itemx down-silently @var{n} | |
3116 | @kindex down-silently | |
3117 | @kindex up-silently | |
3118 | These two commands are variants of @code{up} and @code{down}, | |
3119 | respectively; they differ in that they do their work silently, without | |
3120 | causing display of the new frame. They are intended primarily for use | |
3121 | in _GDBN__ command scripts, where the output might be unnecessary and | |
e251e767 | 3122 | distracting. |
70b88761 RP |
3123 | @end table |
3124 | ||
3125 | @node Frame Info, , Selection, Stack | |
3126 | @section Information About a Frame | |
3127 | ||
3128 | There are several other commands to print information about the selected | |
3129 | stack frame. | |
3130 | ||
3131 | @table @code | |
3132 | @item frame | |
3133 | @itemx f | |
29a2b744 RP |
3134 | When used without any argument, this command does not change which |
3135 | frame is selected, but prints a brief description of the currently | |
70b88761 | 3136 | selected stack frame. It can be abbreviated @code{f}. With an |
29a2b744 RP |
3137 | argument, this command is used to select a stack frame |
3138 | (@pxref{Selection, ,Selecting a Frame}). | |
70b88761 RP |
3139 | |
3140 | @item info frame | |
70b88761 | 3141 | @itemx info f |
29a2b744 | 3142 | @kindex info frame |
70b88761 RP |
3143 | @kindex info f |
3144 | This command prints a verbose description of the selected stack frame, | |
3145 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
3146 | (called by this frame) and the next frame up (caller of this frame), the |
3147 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
3148 | the address of the frame's arguments, the program counter saved in it |
3149 | (the address of execution in the caller frame), and which registers | |
3150 | were saved in the frame. The verbose description is useful when | |
3151 | something has gone wrong that has made the stack format fail to fit | |
3152 | the usual conventions. | |
3153 | ||
3154 | @item info frame @var{addr} | |
3155 | @itemx info f @var{addr} | |
3156 | Print a verbose description of the frame at address @var{addr}, | |
3157 | without selecting that frame. The selected frame remains unchanged by | |
3158 | this command. | |
3159 | ||
3160 | @item info args | |
3161 | @kindex info args | |
3162 | Print the arguments of the selected frame, each on a separate line. | |
3163 | ||
3164 | @item info locals | |
3165 | @kindex info locals | |
3166 | Print the local variables of the selected frame, each on a separate | |
3167 | line. These are all variables declared static or automatic within all | |
3168 | program blocks that execution in this frame is currently inside of. | |
3169 | ||
3170 | @item info catch | |
3171 | @kindex info catch | |
3172 | @cindex catch exceptions | |
3173 | @cindex exception handlers | |
3174 | Print a list of all the exception handlers that are active in the | |
3175 | current stack frame at the current point of execution. To see other | |
3176 | exception handlers, visit the associated frame (using the @code{up}, | |
3177 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
1041a570 | 3178 | @xref{Exception Handling, ,Breakpoints and Exceptions}. |
70b88761 RP |
3179 | @end table |
3180 | ||
3181 | @node Source, Data, Stack, Top | |
3182 | @chapter Examining Source Files | |
3183 | ||
3184 | _GDBN__ can print parts of your program's source, since the debugging | |
1041a570 RP |
3185 | information recorded in your program tells _GDBN__ what source files were |
3186 | used to build it. When your program stops, _GDBN__ spontaneously prints | |
3187 | the line where it stopped. Likewise, when you select a stack frame | |
3188 | (@pxref{Selection, ,Selecting a Frame}), _GDBN__ prints the line where | |
3189 | execution in that frame has stopped. You can print other portions of | |
3190 | source files by explicit command. | |
70b88761 | 3191 | |
1041a570 RP |
3192 | If you use _GDBN__ through its GNU Emacs interface, you may prefer to use |
3193 | Emacs facilities to view source; @pxref{Emacs, ,Using _GDBN__ under GNU | |
3194 | Emacs}. | |
70b88761 RP |
3195 | |
3196 | @menu | |
b80282d5 RP |
3197 | * List:: Printing Source Lines |
3198 | * Search:: Searching Source Files | |
3199 | * Source Path:: Specifying Source Directories | |
3200 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
3201 | @end menu |
3202 | ||
3203 | @node List, Search, Source, Source | |
3204 | @section Printing Source Lines | |
3205 | ||
3206 | @kindex list | |
3207 | @kindex l | |
3208 | To print lines from a source file, use the @code{list} command | |
3209 | (abbreviated @code{l}). There are several ways to specify what part | |
3210 | of the file you want to print. | |
3211 | ||
3212 | Here are the forms of the @code{list} command most commonly used: | |
3213 | ||
3214 | @table @code | |
3215 | @item list @var{linenum} | |
c338a2fd | 3216 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
3217 | current source file. |
3218 | ||
3219 | @item list @var{function} | |
c338a2fd | 3220 | Print lines centered around the beginning of function |
70b88761 RP |
3221 | @var{function}. |
3222 | ||
3223 | @item list | |
c338a2fd RP |
3224 | Print more lines. If the last lines printed were printed with a |
3225 | @code{list} command, this prints lines following the last lines | |
70b88761 | 3226 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 3227 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 3228 | Stack}), this prints lines centered around that line. |
70b88761 RP |
3229 | |
3230 | @item list - | |
c338a2fd RP |
3231 | Print lines just before the lines last printed. |
3232 | @end table | |
3233 | ||
3234 | By default, _GDBN__ prints ten source lines with any of these forms of | |
3235 | the @code{list} command. You can change this using @code{set listsize}: | |
3236 | ||
3237 | @table @code | |
3238 | @item set listsize @var{count} | |
3239 | @kindex set listsize | |
3240 | Make the @code{list} command display @var{count} source lines (unless | |
3241 | the @code{list} argument explicitly specifies some other number). | |
3242 | ||
3243 | @item show listsize | |
3244 | @kindex show listsize | |
3245 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 3246 | default. |
70b88761 RP |
3247 | @end table |
3248 | ||
3249 | Repeating a @code{list} command with @key{RET} discards the argument, | |
3250 | so it is equivalent to typing just @code{list}. This is more useful | |
3251 | than listing the same lines again. An exception is made for an | |
3252 | argument of @samp{-}; that argument is preserved in repetition so that | |
3253 | each repetition moves up in the source file. | |
3254 | ||
3255 | @cindex linespec | |
3256 | In general, the @code{list} command expects you to supply zero, one or two | |
3257 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
3258 | of writing them but the effect is always to specify some source line. | |
3259 | Here is a complete description of the possible arguments for @code{list}: | |
3260 | ||
3261 | @table @code | |
3262 | @item list @var{linespec} | |
c338a2fd | 3263 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
3264 | |
3265 | @item list @var{first},@var{last} | |
3266 | Print lines from @var{first} to @var{last}. Both arguments are | |
3267 | linespecs. | |
3268 | ||
3269 | @item list ,@var{last} | |
c338a2fd | 3270 | Print lines ending with @var{last}. |
70b88761 RP |
3271 | |
3272 | @item list @var{first}, | |
c338a2fd | 3273 | Print lines starting with @var{first}. |
70b88761 RP |
3274 | |
3275 | @item list + | |
c338a2fd | 3276 | Print lines just after the lines last printed. |
70b88761 RP |
3277 | |
3278 | @item list - | |
c338a2fd | 3279 | Print lines just before the lines last printed. |
70b88761 RP |
3280 | |
3281 | @item list | |
3282 | As described in the preceding table. | |
3283 | @end table | |
3284 | ||
3285 | Here are the ways of specifying a single source line---all the | |
3286 | kinds of linespec. | |
3287 | ||
3288 | @table @code | |
3289 | @item @var{number} | |
3290 | Specifies line @var{number} of the current source file. | |
3291 | When a @code{list} command has two linespecs, this refers to | |
3292 | the same source file as the first linespec. | |
3293 | ||
3294 | @item +@var{offset} | |
3295 | Specifies the line @var{offset} lines after the last line printed. | |
3296 | When used as the second linespec in a @code{list} command that has | |
3297 | two, this specifies the line @var{offset} lines down from the | |
3298 | first linespec. | |
3299 | ||
3300 | @item -@var{offset} | |
3301 | Specifies the line @var{offset} lines before the last line printed. | |
3302 | ||
3303 | @item @var{filename}:@var{number} | |
3304 | Specifies line @var{number} in the source file @var{filename}. | |
3305 | ||
3306 | @item @var{function} | |
3307 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
3308 | Specifies the line of the open-brace that begins the body of the | |
3309 | function @var{function}. | |
3310 | ||
3311 | @item @var{filename}:@var{function} | |
3312 | Specifies the line of the open-brace that begins the body of the | |
3313 | function @var{function} in the file @var{filename}. You only need the | |
3314 | file name with a function name to avoid ambiguity when there are | |
3315 | identically named functions in different source files. | |
3316 | ||
3317 | @item *@var{address} | |
3318 | Specifies the line containing the program address @var{address}. | |
3319 | @var{address} may be any expression. | |
3320 | @end table | |
3321 | ||
3322 | @node Search, Source Path, List, Source | |
3323 | @section Searching Source Files | |
3324 | @cindex searching | |
3325 | @kindex reverse-search | |
3326 | ||
3327 | There are two commands for searching through the current source file for a | |
3328 | regular expression. | |
3329 | ||
3330 | @table @code | |
3331 | @item forward-search @var{regexp} | |
3332 | @itemx search @var{regexp} | |
3333 | @kindex search | |
3334 | @kindex forward-search | |
1041a570 RP |
3335 | The command @samp{forward-search @var{regexp}} checks each line, |
3336 | starting with the one following the last line listed, for a match for | |
3337 | @var{regexp}. It lists the line that is found. You can use | |
3338 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3339 | @code{fo}. | |
70b88761 RP |
3340 | |
3341 | @item reverse-search @var{regexp} | |
3342 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3343 | with the one before the last line listed and going backward, for a match | |
3344 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3345 | this command as @code{rev}. | |
3346 | @end table | |
3347 | ||
3348 | @node Source Path, Machine Code, Search, Source | |
3349 | @section Specifying Source Directories | |
3350 | ||
3351 | @cindex source path | |
3352 | @cindex directories for source files | |
3353 | Executable programs sometimes do not record the directories of the source | |
3354 | files from which they were compiled, just the names. Even when they do, | |
3355 | the directories could be moved between the compilation and your debugging | |
3356 | session. _GDBN__ has a list of directories to search for source files; | |
3357 | this is called the @dfn{source path}. Each time _GDBN__ wants a source file, | |
3358 | it tries all the directories in the list, in the order they are present | |
3359 | in the list, until it finds a file with the desired name. Note that | |
3360 | the executable search path is @emph{not} used for this purpose. Neither is | |
3361 | the current working directory, unless it happens to be in the source | |
3362 | path. | |
3363 | ||
29a2b744 | 3364 | If _GDBN__ cannot find a source file in the source path, and the object |
70b88761 RP |
3365 | program records a directory, _GDBN__ tries that directory too. If the |
3366 | source path is empty, and there is no record of the compilation | |
3367 | directory, _GDBN__ will, as a last resort, look in the current | |
3368 | directory. | |
3369 | ||
3370 | Whenever you reset or rearrange the source path, _GDBN__ will clear out | |
3371 | any information it has cached about where source files are found, where | |
3372 | each line is in the file, etc. | |
3373 | ||
3374 | @kindex directory | |
3375 | When you start _GDBN__, its source path is empty. | |
3376 | To add other directories, use the @code{directory} command. | |
3377 | ||
3378 | @table @code | |
3379 | @item directory @var{dirname} @dots{} | |
3380 | Add directory @var{dirname} to the front of the source path. Several | |
3381 | directory names may be given to this command, separated by @samp{:} or | |
3382 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 3383 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
3384 | |
3385 | You can use the string @samp{$cdir} to refer to the compilation | |
3386 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3387 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
3388 | tracks the current working directory as it changes during your _GDBN__ | |
3389 | session, while the latter is immediately expanded to the current | |
3390 | directory at the time you add an entry to the source path. | |
70b88761 RP |
3391 | |
3392 | @item directory | |
3393 | Reset the source path to empty again. This requires confirmation. | |
3394 | ||
3395 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 3396 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
3397 | |
3398 | @item show directories | |
3399 | @kindex show directories | |
3400 | Print the source path: show which directories it contains. | |
3401 | @end table | |
3402 | ||
3403 | If your source path is cluttered with directories that are no longer of | |
3404 | interest, _GDBN__ may sometimes cause confusion by finding the wrong | |
3405 | versions of source. You can correct the situation as follows: | |
3406 | ||
3407 | @enumerate | |
3408 | @item | |
3409 | Use @code{directory} with no argument to reset the source path to empty. | |
3410 | ||
3411 | @item | |
3412 | Use @code{directory} with suitable arguments to reinstall the | |
3413 | directories you want in the source path. You can add all the | |
3414 | directories in one command. | |
3415 | @end enumerate | |
3416 | ||
3417 | @node Machine Code, , Source Path, Source | |
3418 | @section Source and Machine Code | |
1041a570 | 3419 | |
70b88761 RP |
3420 | You can use the command @code{info line} to map source lines to program |
3421 | addresses (and viceversa), and the command @code{disassemble} to display | |
3422 | a range of addresses as machine instructions. | |
3423 | ||
3424 | @table @code | |
3425 | @item info line @var{linespec} | |
3426 | @kindex info line | |
3427 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
3428 | source line @var{linespec}. You can specify source lines in any of |
3429 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
3430 | Source Lines}). | |
70b88761 RP |
3431 | @end table |
3432 | ||
1041a570 RP |
3433 | For example, we can use @code{info line} to discover the location of |
3434 | the object code for the first line of function | |
3435 | @code{m4_changequote}: | |
3436 | ||
70b88761 RP |
3437 | @smallexample |
3438 | (_GDBP__) info line m4_changecom | |
3439 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
3440 | @end smallexample | |
3441 | ||
3442 | @noindent | |
3443 | We can also inquire (using @code{*@var{addr}} as the form for | |
3444 | @var{linespec}) what source line covers a particular address: | |
3445 | @smallexample | |
3446 | (_GDBP__) info line *0x63ff | |
3447 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
3448 | @end smallexample | |
3449 | ||
c338a2fd | 3450 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
3451 | After @code{info line}, the default address for the @code{x} command |
3452 | is changed to the starting address of the line, so that @samp{x/i} is | |
3453 | sufficient to begin examining the machine code (@pxref{Memory, | |
3454 | ,Examining Memory}). Also, this address is saved as the value of the | |
3455 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
3456 | Variables}). | |
70b88761 RP |
3457 | |
3458 | @table @code | |
3459 | @kindex disassemble | |
3460 | @item disassemble | |
e94b4a2b RP |
3461 | This specialized command dumps a range of memory as machine |
3462 | instructions. The default memory range is the function surrounding the | |
3463 | program counter of the selected frame. A single argument to this | |
3464 | command is a program counter value; the function surrounding this value | |
3465 | will be dumped. Two arguments specify a range of addresses (first | |
3466 | inclusive, second exclusive) to dump. | |
70b88761 RP |
3467 | @end table |
3468 | ||
3469 | We can use @code{disassemble} to inspect the object code | |
3470 | range shown in the last @code{info line} example: | |
3471 | ||
3472 | @smallexample | |
3473 | (_GDBP__) disas 0x63e4 0x6404 | |
3474 | Dump of assembler code from 0x63e4 to 0x6404: | |
b80282d5 RP |
3475 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
3476 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
3477 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
3478 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
3479 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
3480 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
3481 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 3482 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 3483 | End of assembler dump. |
70b88761 RP |
3484 | @end smallexample |
3485 | ||
c2bbbb22 | 3486 | @node Data, Languages, Source, Top |
70b88761 RP |
3487 | @chapter Examining Data |
3488 | ||
3489 | @cindex printing data | |
3490 | @cindex examining data | |
3491 | @kindex print | |
3492 | @kindex inspect | |
1041a570 | 3493 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 3494 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
3495 | @c different window or something like that. |
3496 | The usual way to examine data in your program is with the @code{print} | |
3497 | command (abbreviated @code{p}), or its synonym @code{inspect}. It | |
b80282d5 | 3498 | evaluates and prints the value of an expression of the language your |
1041a570 RP |
3499 | program is written in (@pxref{Languages, ,Using _GDBN__ with Different |
3500 | Languages}). | |
70b88761 | 3501 | |
e0dacfd1 RP |
3502 | @table @code |
3503 | @item print @var{exp} | |
3504 | @itemx print /@var{f} @var{exp} | |
3505 | @var{exp} is an expression (in the source language). By default | |
70b88761 | 3506 | the value of @var{exp} is printed in a format appropriate to its data |
e0dacfd1 RP |
3507 | type; you can choose a different format by specifying @samp{/@var{f}}, |
3508 | where @var{f} is a letter specifying the format; @pxref{Output formats}. | |
3509 | ||
3510 | @item print | |
3511 | @itemx print /@var{f} | |
3512 | If you omit @var{exp}, _GDBN__ displays the last value again (from the | |
1041a570 | 3513 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to |
e0dacfd1 RP |
3514 | conveniently inspect the same value in an alternative format. |
3515 | @end table | |
70b88761 RP |
3516 | |
3517 | A more low-level way of examining data is with the @code{x} command. | |
3518 | It examines data in memory at a specified address and prints it in a | |
29a2b744 | 3519 | specified format. @xref{Memory, ,Examining Memory}. |
70b88761 | 3520 | |
29a2b744 | 3521 | If you are interested in information about types, or about how the fields |
b80282d5 | 3522 | of a struct or class are declared, use the @code{ptype @var{exp}} |
1041a570 | 3523 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 | 3524 | |
70b88761 | 3525 | @menu |
b80282d5 RP |
3526 | * Expressions:: Expressions |
3527 | * Variables:: Program Variables | |
3528 | * Arrays:: Artificial Arrays | |
3529 | * Output formats:: Output formats | |
3530 | * Memory:: Examining Memory | |
3531 | * Auto Display:: Automatic Display | |
3532 | * Print Settings:: Print Settings | |
3533 | * Value History:: Value History | |
3534 | * Convenience Vars:: Convenience Variables | |
3535 | * Registers:: Registers | |
3536 | * Floating Point Hardware:: Floating Point Hardware | |
70b88761 RP |
3537 | @end menu |
3538 | ||
3539 | @node Expressions, Variables, Data, Data | |
3540 | @section Expressions | |
3541 | ||
3542 | @cindex expressions | |
3543 | @code{print} and many other _GDBN__ commands accept an expression and | |
3544 | compute its value. Any kind of constant, variable or operator defined | |
3545 | by the programming language you are using is legal in an expression in | |
3546 | _GDBN__. This includes conditional expressions, function calls, casts | |
3547 | and string constants. It unfortunately does not include symbols defined | |
b80282d5 | 3548 | by preprocessor @code{#define} commands. |
70b88761 | 3549 | |
c2bbbb22 | 3550 | Because C is so widespread, most of the expressions shown in examples in |
1041a570 | 3551 | this manual are in C. @xref{Languages, , Using _GDBN__ with Different |
c2bbbb22 | 3552 | Languages}, for information on how to use expressions in other |
e251e767 | 3553 | languages. |
c2bbbb22 RP |
3554 | |
3555 | In this section, we discuss operators that you can use in _GDBN__ | |
e251e767 | 3556 | expressions regardless of your programming language. |
c2bbbb22 | 3557 | |
70b88761 RP |
3558 | Casts are supported in all languages, not just in C, because it is so |
3559 | useful to cast a number into a pointer so as to examine a structure | |
3560 | at that address in memory. | |
c2bbbb22 | 3561 | @c FIXME: casts supported---Mod2 true? |
70b88761 | 3562 | |
c2bbbb22 | 3563 | _GDBN__ supports these operators in addition to those of programming |
70b88761 RP |
3564 | languages: |
3565 | ||
3566 | @table @code | |
3567 | @item @@ | |
3568 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
1041a570 | 3569 | @xref{Arrays, ,Artificial Arrays}, for more information. |
70b88761 RP |
3570 | |
3571 | @item :: | |
3572 | @samp{::} allows you to specify a variable in terms of the file or | |
1041a570 | 3573 | function where it is defined. @xref{Variables, ,Program Variables}. |
70b88761 RP |
3574 | |
3575 | @item @{@var{type}@} @var{addr} | |
3576 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3577 | memory. @var{addr} may be any expression whose value is an integer or | |
3578 | pointer (but parentheses are required around binary operators, just as in | |
3579 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 3580 | normally supposed to reside at @var{addr}. |
70b88761 RP |
3581 | @end table |
3582 | ||
3583 | @node Variables, Arrays, Expressions, Data | |
3584 | @section Program Variables | |
3585 | ||
3586 | The most common kind of expression to use is the name of a variable | |
3587 | in your program. | |
3588 | ||
3589 | Variables in expressions are understood in the selected stack frame | |
29a2b744 RP |
3590 | (@pxref{Selection, ,Selecting a Frame}); they must either be global |
3591 | (or static) or be visible according to the scope rules of the | |
3592 | programming language from the point of execution in that frame. This | |
3593 | means that in the function | |
70b88761 RP |
3594 | |
3595 | @example | |
3596 | foo (a) | |
3597 | int a; | |
3598 | @{ | |
3599 | bar (a); | |
3600 | @{ | |
3601 | int b = test (); | |
3602 | bar (b); | |
3603 | @} | |
3604 | @} | |
3605 | @end example | |
3606 | ||
3607 | @noindent | |
29a2b744 | 3608 | the variable @code{a} is usable whenever your program is executing |
70b88761 | 3609 | within the function @code{foo}, but the variable @code{b} is visible |
29a2b744 | 3610 | only while your program is executing inside the block in which @code{b} |
70b88761 RP |
3611 | is declared. |
3612 | ||
3613 | @cindex variable name conflict | |
3614 | There is an exception: you can refer to a variable or function whose | |
3615 | scope is a single source file even if the current execution point is not | |
3616 | in this file. But it is possible to have more than one such variable or | |
6ca72cc6 RP |
3617 | function with the same name (in different source files). If that |
3618 | happens, referring to that name has unpredictable effects. If you wish, | |
3619 | you can specify a static variable in a particular function or file, | |
3620 | using the colon-colon notation: | |
70b88761 RP |
3621 | |
3622 | @cindex colon-colon | |
a6d0b6d3 | 3623 | @iftex |
29a2b744 | 3624 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 3625 | @kindex :: |
a6d0b6d3 | 3626 | @end iftex |
70b88761 RP |
3627 | @example |
3628 | @var{file}::@var{variable} | |
6ca72cc6 | 3629 | @var{function}::@var{variable} |
70b88761 RP |
3630 | @end example |
3631 | ||
3632 | @noindent | |
6ca72cc6 RP |
3633 | Here @var{file} or @var{function} is the name of the context for the |
3634 | static @var{variable}. | |
70b88761 | 3635 | |
c2bbbb22 | 3636 | @cindex C++ scope resolution |
70b88761 RP |
3637 | This use of @samp{::} is very rarely in conflict with the very similar |
3638 | use of the same notation in C++. _GDBN__ also supports use of the C++ | |
c2bbbb22 | 3639 | scope resolution operator in _GDBN__ expressions. |
70b88761 | 3640 | |
3d3ab540 RP |
3641 | @cindex wrong values |
3642 | @cindex variable values, wrong | |
3643 | @quotation | |
3644 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
3645 | wrong value at certain points in a function---just after entry to the | |
29a2b744 | 3646 | function, and just before exit. You may see this problem when you are |
3d3ab540 RP |
3647 | stepping by machine instructions. This is because on most machines, it |
3648 | takes more than one instruction to set up a stack frame (including local | |
29a2b744 | 3649 | variable definitions); if you are stepping by machine instructions, |
3d3ab540 RP |
3650 | variables may appear to have the wrong values until the stack frame is |
3651 | completely built. On function exit, it usually also takes more than one | |
3652 | machine instruction to destroy a stack frame; after you begin stepping | |
3653 | through that group of instructions, local variable definitions may be | |
3654 | gone. | |
3655 | @end quotation | |
3656 | ||
70b88761 RP |
3657 | @node Arrays, Output formats, Variables, Data |
3658 | @section Artificial Arrays | |
3659 | ||
3660 | @cindex artificial array | |
3661 | @kindex @@ | |
3662 | It is often useful to print out several successive objects of the | |
3663 | same type in memory; a section of an array, or an array of | |
3664 | dynamically determined size for which only a pointer exists in the | |
3665 | program. | |
3666 | ||
3667 | This can be done by constructing an @dfn{artificial array} with the | |
3668 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3669 | the first element of the desired array, as an individual object. | |
3670 | The right operand should be the desired length of the array. The result is | |
3671 | an array value whose elements are all of the type of the left argument. | |
3672 | The first element is actually the left argument; the second element | |
3673 | comes from bytes of memory immediately following those that hold the | |
3674 | first element, and so on. Here is an example. If a program says | |
3675 | ||
3676 | @example | |
3677 | int *array = (int *) malloc (len * sizeof (int)); | |
3678 | @end example | |
3679 | ||
3680 | @noindent | |
3681 | you can print the contents of @code{array} with | |
3682 | ||
3683 | @example | |
3684 | p *array@@len | |
3685 | @end example | |
3686 | ||
3687 | The left operand of @samp{@@} must reside in memory. Array values made | |
3688 | with @samp{@@} in this way behave just like other arrays in terms of | |
3689 | subscripting, and are coerced to pointers when used in expressions. | |
3690 | Artificial arrays most often appear in expressions via the value history | |
1041a570 | 3691 | (@pxref{Value History, ,Value History}), after printing one out.) |
70b88761 | 3692 | |
1041a570 | 3693 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 3694 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
3695 | actually be adjacent---for example, if you are interested in the values |
3696 | of pointers in an array. One useful work-around in this situation is | |
3697 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
3698 | Variables}) as a counter in an expression that prints the first | |
3699 | interesting value, and then repeat that expression via @key{RET}. For | |
3700 | instance, suppose you have an array @code{dtab} of pointers to | |
3701 | structures, and you are interested in the values of a field @code{fv} | |
3702 | in each structure. Here is an example of what you might type: | |
3703 | ||
3d3ab540 RP |
3704 | @example |
3705 | set $i = 0 | |
3706 | p dtab[$i++]->fv | |
3707 | @key{RET} | |
3708 | @key{RET} | |
3709 | @dots{} | |
3710 | @end example | |
3711 | ||
70b88761 RP |
3712 | @node Output formats, Memory, Arrays, Data |
3713 | @section Output formats | |
3714 | ||
3715 | @cindex formatted output | |
3716 | @cindex output formats | |
3717 | By default, _GDBN__ prints a value according to its data type. Sometimes | |
3718 | this is not what you want. For example, you might want to print a number | |
3719 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3720 | at a certain address as a character string or as an instruction. To do | |
3721 | these things, specify an @dfn{output format} when you print a value. | |
3722 | ||
3723 | The simplest use of output formats is to say how to print a value | |
3724 | already computed. This is done by starting the arguments of the | |
3725 | @code{print} command with a slash and a format letter. The format | |
3726 | letters supported are: | |
3727 | ||
3728 | @table @code | |
3729 | @item x | |
3730 | Regard the bits of the value as an integer, and print the integer in | |
3731 | hexadecimal. | |
3732 | ||
3733 | @item d | |
3734 | Print as integer in signed decimal. | |
3735 | ||
3736 | @item u | |
3737 | Print as integer in unsigned decimal. | |
3738 | ||
3739 | @item o | |
3740 | Print as integer in octal. | |
3741 | ||
3742 | @item t | |
3743 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3744 | ||
3745 | @item a | |
3746 | Print as an address, both absolute in hex and as an offset from the | |
3747 | nearest preceding symbol. This format can be used to discover where (in | |
3748 | what function) an unknown address is located: | |
1041a570 | 3749 | |
70b88761 RP |
3750 | @example |
3751 | (_GDBP__) p/a 0x54320 | |
3752 | _0__$3 = 0x54320 <_initialize_vx+396>_1__ | |
3753 | @end example | |
3754 | ||
70b88761 RP |
3755 | @item c |
3756 | Regard as an integer and print it as a character constant. | |
3757 | ||
3758 | @item f | |
3759 | Regard the bits of the value as a floating point number and print | |
3760 | using typical floating point syntax. | |
3761 | @end table | |
3762 | ||
3763 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3764 | ||
3765 | @example | |
3766 | p/x $pc | |
3767 | @end example | |
3768 | ||
3769 | @noindent | |
3770 | Note that no space is required before the slash; this is because command | |
3771 | names in _GDBN__ cannot contain a slash. | |
3772 | ||
3773 | To reprint the last value in the value history with a different format, | |
3774 | you can use the @code{print} command with just a format and no | |
3775 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3776 | ||
3777 | @node Memory, Auto Display, Output formats, Data | |
3778 | @section Examining Memory | |
3779 | ||
1041a570 RP |
3780 | You can use the command @code{x} (for ``examine'') to examine memory in |
3781 | any of several formats, independently of your program's data types. | |
3782 | ||
70b88761 RP |
3783 | @cindex examining memory |
3784 | @table @code | |
3785 | @kindex x | |
cedaf8bc RP |
3786 | @item x/@var{nfu} @var{addr} |
3787 | @itemx x @var{addr} | |
3788 | @itemx x | |
1041a570 RP |
3789 | Use the command @code{x} to examine memory. |
3790 | @end table | |
3791 | ||
3792 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3793 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
3794 | expression giving the address where you want to start displaying memory. |
3795 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3796 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 3797 | |
1041a570 RP |
3798 | @table @r |
3799 | @item @var{n}, the repeat count | |
3800 | The repeat count is a decimal integer; the default is 1. It specifies | |
3801 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
3802 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
3803 | @c 4.1.2. | |
70b88761 | 3804 | |
1041a570 RP |
3805 | @item @var{f}, the display format |
3806 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
3807 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
3808 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3809 | last time you used either @code{x} or @code{print}. | |
70b88761 | 3810 | |
1041a570 RP |
3811 | @item @var{u}, the unit size |
3812 | The unit size is any of | |
70b88761 RP |
3813 | @table @code |
3814 | @item b | |
cedaf8bc | 3815 | Bytes. |
70b88761 | 3816 | @item h |
cedaf8bc | 3817 | Halfwords (two bytes). |
70b88761 | 3818 | @item w |
cedaf8bc | 3819 | Words (four bytes). This is the initial default. |
70b88761 | 3820 | @item g |
cedaf8bc | 3821 | Giant words (eight bytes). |
70b88761 RP |
3822 | @end table |
3823 | ||
cedaf8bc RP |
3824 | Each time you specify a unit size with @code{x}, that size becomes the |
3825 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3826 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3827 | ||
1041a570 | 3828 | @item @var{addr}, starting display address |
cedaf8bc RP |
3829 | @var{addr} is the address where you want _GDBN__ to begin displaying |
3830 | memory. The expression need not have a pointer value (though it may); | |
3831 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 3832 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
3833 | @var{addr} is usually just after the last address examined---but several |
3834 | other commands also set the default address: @code{info breakpoints} (to | |
3835 | the address of the last breakpoint listed), @code{info line} (to the | |
3836 | starting address of a line), and @code{print} (if you use it to display | |
3837 | a value from memory). | |
1041a570 | 3838 | @end table |
70b88761 | 3839 | |
cedaf8bc RP |
3840 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
3841 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3842 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3843 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3844 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 3845 | |
cedaf8bc | 3846 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 3847 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
3848 | unit size or format comes first; either order will work. The output |
3849 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3850 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3851 | ||
3852 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3853 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3854 | @samp{3i} specifies that you want to see three machine instructions, | |
3855 | including any operands. The command @code{disassemble} gives an | |
3856 | alternative way of inspecting machine instructions; @pxref{Machine | |
3857 | Code}. | |
3858 | ||
3859 | All the defaults for the arguments to @code{x} are designed to make it | |
3860 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 3861 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
3862 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
3863 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3864 | the repeat count @var{n} is used again; the other arguments default as | |
3865 | for successive uses of @code{x}. | |
70b88761 | 3866 | |
c338a2fd | 3867 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 3868 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 RP |
3869 | in the value history because there is often too much of them and they |
3870 | would get in the way. Instead, _GDBN__ makes these values available for | |
3871 | subsequent use in expressions as values of the convenience variables | |
3872 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3873 | examined is available for use in expressions in the convenience variable | |
3874 | @code{$_}. The contents of that address, as examined, are available in | |
3875 | the convenience variable @code{$__}. | |
3876 | ||
3877 | If the @code{x} command has a repeat count, the address and contents saved | |
3878 | are from the last memory unit printed; this is not the same as the last | |
3879 | address printed if several units were printed on the last line of output. | |
3880 | ||
3881 | @node Auto Display, Print Settings, Memory, Data | |
3882 | @section Automatic Display | |
3883 | @cindex automatic display | |
3884 | @cindex display of expressions | |
3885 | ||
3886 | If you find that you want to print the value of an expression frequently | |
3887 | (to see how it changes), you might want to add it to the @dfn{automatic | |
29a2b744 | 3888 | display list} so that _GDBN__ will print its value each time your program stops. |
70b88761 RP |
3889 | Each expression added to the list is given a number to identify it; |
3890 | to remove an expression from the list, you specify that number. | |
3891 | The automatic display looks like this: | |
3892 | ||
3893 | @example | |
3894 | 2: foo = 38 | |
3895 | 3: bar[5] = (struct hack *) 0x3804 | |
3896 | @end example | |
3897 | ||
3898 | @noindent | |
3899 | showing item numbers, expressions and their current values. As with | |
3900 | displays you request manually using @code{x} or @code{print}, you can | |
3901 | specify the output format you prefer; in fact, @code{display} decides | |
3902 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3903 | format specification is---it uses @code{x} if you specify a unit size, | |
3904 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3905 | supported by @code{x}; otherwise it uses @code{print}. | |
3906 | ||
3907 | @table @code | |
3908 | @item display @var{exp} | |
3909 | @kindex display | |
3910 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 3911 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3912 | |
3913 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3914 | ||
3915 | @item display/@var{fmt} @var{exp} | |
3916 | For @var{fmt} specifying only a display format and not a size or | |
3917 | count, add the expression @var{exp} to the auto-display list but | |
3918 | arranges to display it each time in the specified format @var{fmt}. | |
3919 | @xref{Output formats}. | |
3920 | ||
3921 | @item display/@var{fmt} @var{addr} | |
3922 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3923 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 RP |
3924 | be examined each time your program stops. Examining means in effect |
3925 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
70b88761 RP |
3926 | @end table |
3927 | ||
3928 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3929 | instruction about to be executed each time execution stops (@samp{$pc} | |
3930 | is a common name for the program counter; @pxref{Registers}). | |
3931 | ||
3932 | @table @code | |
3933 | @item undisplay @var{dnums}@dots{} | |
3934 | @itemx delete display @var{dnums}@dots{} | |
3935 | @kindex delete display | |
3936 | @kindex undisplay | |
3937 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3938 | ||
3939 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3940 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3941 | ||
3942 | @item disable display @var{dnums}@dots{} | |
3943 | @kindex disable display | |
3944 | Disable the display of item numbers @var{dnums}. A disabled display | |
3945 | item is not printed automatically, but is not forgotten. It may be | |
3946 | enabled again later. | |
3947 | ||
3948 | @item enable display @var{dnums}@dots{} | |
3949 | @kindex enable display | |
3950 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3951 | again in auto display of its expression, until you specify otherwise. | |
3952 | ||
3953 | @item display | |
3954 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 3955 | done when your program stops. |
70b88761 RP |
3956 | |
3957 | @item info display | |
3958 | @kindex info display | |
3959 | Print the list of expressions previously set up to display | |
3960 | automatically, each one with its item number, but without showing the | |
3961 | values. This includes disabled expressions, which are marked as such. | |
3962 | It also includes expressions which would not be displayed right now | |
3963 | because they refer to automatic variables not currently available. | |
3964 | @end table | |
3965 | ||
3966 | If a display expression refers to local variables, then it does not make | |
3967 | sense outside the lexical context for which it was set up. Such an | |
3968 | expression is disabled when execution enters a context where one of its | |
3969 | variables is not defined. For example, if you give the command | |
3970 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 3971 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
3972 | continues to stop inside that function. When it stops elsewhere---where |
3973 | there is no variable @code{last_char}---display is disabled. The next time | |
3974 | your program stops where @code{last_char} is meaningful, you can enable the | |
3975 | display expression once again. | |
3976 | ||
3977 | @node Print Settings, Value History, Auto Display, Data | |
3978 | @section Print Settings | |
3979 | ||
3980 | @cindex format options | |
3981 | @cindex print settings | |
3982 | _GDBN__ provides the following ways to control how arrays, structures, | |
e251e767 | 3983 | and symbols are printed. |
70b88761 RP |
3984 | |
3985 | @noindent | |
3986 | These settings are useful for debugging programs in any language: | |
3987 | ||
3988 | @table @code | |
3989 | @item set print address | |
3990 | @item set print address on | |
3991 | @kindex set print address | |
3992 | _GDBN__ will print memory addresses showing the location of stack | |
3993 | traces, structure values, pointer values, breakpoints, and so forth, | |
3994 | even when it also displays the contents of those addresses. The default | |
3995 | is on. For example, this is what a stack frame display looks like, with | |
3996 | @code{set print address on}: | |
1041a570 | 3997 | |
70b88761 | 3998 | @smallexample |
1041a570 | 3999 | @group |
70b88761 | 4000 | (_GDBP__) f |
e251e767 | 4001 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 4002 | at input.c:530 |
b80282d5 | 4003 | 530 if (lquote != def_lquote) |
1041a570 | 4004 | @end group |
70b88761 RP |
4005 | @end smallexample |
4006 | ||
4007 | @item set print address off | |
4008 | Do not print addresses when displaying their contents. For example, | |
4009 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 4010 | |
70b88761 | 4011 | @example |
1041a570 | 4012 | @group |
70b88761 RP |
4013 | (_GDBP__) set print addr off |
4014 | (_GDBP__) f | |
4015 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
b80282d5 | 4016 | 530 if (lquote != def_lquote) |
1041a570 | 4017 | @end group |
70b88761 RP |
4018 | @end example |
4019 | ||
4020 | @item show print address | |
4021 | @kindex show print address | |
4022 | Show whether or not addresses are to be printed. | |
4023 | ||
4024 | @item set print array | |
4025 | @itemx set print array on | |
4026 | @kindex set print array | |
4027 | _GDBN__ will pretty print arrays. This format is more convenient to read, | |
4028 | but uses more space. The default is off. | |
4029 | ||
4030 | @item set print array off. | |
4031 | Return to compressed format for arrays. | |
4032 | ||
4033 | @item show print array | |
4034 | @kindex show print array | |
4035 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 4036 | arrays. |
70b88761 RP |
4037 | |
4038 | @item set print elements @var{number-of-elements} | |
4039 | @kindex set print elements | |
4040 | If _GDBN__ is printing a large array, it will stop printing after it has | |
4041 | printed the number of elements set by the @code{set print elements} command. | |
4042 | This limit also applies to the display of strings. | |
4043 | ||
4044 | @item show print elements | |
4045 | @kindex show print elements | |
4046 | Display the number of elements of a large array that _GDBN__ will print | |
4047 | before losing patience. | |
4048 | ||
4049 | @item set print pretty on | |
4050 | @kindex set print pretty | |
4051 | Cause _GDBN__ to print structures in an indented format with one member per | |
4052 | line, like this: | |
4053 | ||
4054 | @example | |
1041a570 | 4055 | @group |
70b88761 RP |
4056 | $1 = @{ |
4057 | next = 0x0, | |
4058 | flags = @{ | |
4059 | sweet = 1, | |
4060 | sour = 1 | |
4061 | @}, | |
4062 | meat = 0x54 "Pork" | |
4063 | @} | |
1041a570 | 4064 | @end group |
70b88761 RP |
4065 | @end example |
4066 | ||
4067 | @item set print pretty off | |
4068 | Cause _GDBN__ to print structures in a compact format, like this: | |
4069 | ||
4070 | @smallexample | |
1041a570 | 4071 | @group |
38962738 RP |
4072 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \ |
4073 | meat = 0x54 "Pork"@} | |
1041a570 | 4074 | @end group |
70b88761 RP |
4075 | @end smallexample |
4076 | ||
4077 | @noindent | |
4078 | This is the default format. | |
4079 | ||
4080 | @item show print pretty | |
4081 | @kindex show print pretty | |
4082 | Show which format _GDBN__ will use to print structures. | |
4083 | ||
4084 | @item set print sevenbit-strings on | |
f2857bd9 | 4085 | @kindex set print sevenbit-strings |
e251e767 | 4086 | Print using only seven-bit characters; if this option is set, |
70b88761 RP |
4087 | _GDBN__ will display any eight-bit characters (in strings or character |
4088 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
4089 | displayed as @code{\341}. | |
4090 | ||
4091 | @item set print sevenbit-strings off | |
4092 | Print using either seven-bit or eight-bit characters, as required. This | |
4093 | is the default. | |
4094 | ||
4095 | @item show print sevenbit-strings | |
f2857bd9 | 4096 | @kindex show print sevenbit-strings |
70b88761 RP |
4097 | Show whether or not _GDBN__ will print only seven-bit characters. |
4098 | ||
4099 | @item set print union on | |
4100 | @kindex set print union | |
4101 | Tell _GDBN__ to print unions which are contained in structures. This is the | |
4102 | default setting. | |
4103 | ||
4104 | @item set print union off | |
4105 | Tell _GDBN__ not to print unions which are contained in structures. | |
4106 | ||
4107 | @item show print union | |
4108 | @kindex show print union | |
4109 | Ask _GDBN__ whether or not it will print unions which are contained in | |
e251e767 | 4110 | structures. |
70b88761 RP |
4111 | |
4112 | For example, given the declarations | |
4113 | ||
4114 | @smallexample | |
4115 | typedef enum @{Tree, Bug@} Species; | |
4116 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
4117 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
4118 | Bug_forms; | |
70b88761 RP |
4119 | |
4120 | struct thing @{ | |
4121 | Species it; | |
4122 | union @{ | |
4123 | Tree_forms tree; | |
4124 | Bug_forms bug; | |
4125 | @} form; | |
4126 | @}; | |
4127 | ||
4128 | struct thing foo = @{Tree, @{Acorn@}@}; | |
4129 | @end smallexample | |
4130 | ||
4131 | @noindent | |
4132 | with @code{set print union on} in effect @samp{p foo} would print | |
4133 | ||
4134 | @smallexample | |
4135 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
4136 | @end smallexample | |
4137 | ||
4138 | @noindent | |
4139 | and with @code{set print union off} in effect it would print | |
4140 | ||
4141 | @smallexample | |
4142 | $1 = @{it = Tree, form = @{...@}@} | |
4143 | @end smallexample | |
4144 | @end table | |
4145 | ||
4146 | @noindent | |
4147 | These settings are of interest when debugging C++ programs: | |
4148 | ||
4149 | @table @code | |
e251e767 RP |
4150 | @item set print demangle |
4151 | @itemx set print demangle on | |
70b88761 RP |
4152 | @kindex set print demangle |
4153 | Print C++ names in their source form rather than in the mangled form | |
4154 | in which they are passed to the assembler and linker for type-safe linkage. | |
4155 | The default is on. | |
4156 | ||
4157 | @item show print demangle | |
4158 | @kindex show print demangle | |
4159 | Show whether C++ names will be printed in mangled or demangled form. | |
4160 | ||
e251e767 RP |
4161 | @item set print asm-demangle |
4162 | @itemx set print asm-demangle on | |
70b88761 RP |
4163 | @kindex set print asm-demangle |
4164 | Print C++ names in their source form rather than their mangled form, even | |
4165 | in assembler code printouts such as instruction disassemblies. | |
4166 | The default is off. | |
4167 | ||
4168 | @item show print asm-demangle | |
4169 | @kindex show print asm-demangle | |
4170 | Show whether C++ names in assembly listings will be printed in mangled | |
4171 | or demangled form. | |
4172 | ||
4173 | @item set print object | |
4174 | @itemx set print object on | |
4175 | @kindex set print object | |
4176 | When displaying a pointer to an object, identify the @emph{actual} | |
4177 | (derived) type of the object rather than the @emph{declared} type, using | |
4178 | the virtual function table. | |
4179 | ||
4180 | @item set print object off | |
4181 | Display only the declared type of objects, without reference to the | |
4182 | virtual function table. This is the default setting. | |
4183 | ||
4184 | @item show print object | |
4185 | @kindex show print object | |
4186 | Show whether actual, or declared, object types will be displayed. | |
4187 | ||
e251e767 RP |
4188 | @item set print vtbl |
4189 | @itemx set print vtbl on | |
70b88761 RP |
4190 | @kindex set print vtbl |
4191 | Pretty print C++ virtual function tables. The default is off. | |
4192 | ||
4193 | @item set print vtbl off | |
4194 | Do not pretty print C++ virtual function tables. | |
4195 | ||
4196 | @item show print vtbl | |
4197 | @kindex show print vtbl | |
4198 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 RP |
4199 | @end table |
4200 | ||
4201 | @node Value History, Convenience Vars, Print Settings, Data | |
4202 | @section Value History | |
4203 | ||
4204 | @cindex value history | |
4205 | Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value | |
4206 | history} so that you can refer to them in other expressions. Values are | |
4207 | kept until the symbol table is re-read or discarded (for example with | |
4208 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
4209 | changes, the value history is discarded, since the values may contain | |
4210 | pointers back to the types defined in the symbol table. | |
4211 | ||
4212 | @cindex @code{$} | |
4213 | @cindex @code{$$} | |
4214 | @cindex history number | |
4215 | The values printed are given @dfn{history numbers} for you to refer to them | |
4216 | by. These are successive integers starting with one. @code{print} shows you | |
4217 | the history number assigned to a value by printing @samp{$@var{num} = } | |
4218 | before the value; here @var{num} is the history number. | |
4219 | ||
4220 | To refer to any previous value, use @samp{$} followed by the value's | |
4221 | history number. The way @code{print} labels its output is designed to | |
4222 | remind you of this. Just @code{$} refers to the most recent value in | |
4223 | the history, and @code{$$} refers to the value before that. | |
4224 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
4225 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
4226 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
4227 | ||
4228 | For example, suppose you have just printed a pointer to a structure and | |
4229 | want to see the contents of the structure. It suffices to type | |
4230 | ||
4231 | @example | |
4232 | p *$ | |
4233 | @end example | |
4234 | ||
4235 | If you have a chain of structures where the component @code{next} points | |
4236 | to the next one, you can print the contents of the next one with this: | |
4237 | ||
4238 | @example | |
4239 | p *$.next | |
4240 | @end example | |
4241 | ||
4242 | @noindent | |
4243 | You can print successive links in the chain by repeating this | |
4244 | command---which you can do by just typing @key{RET}. | |
4245 | ||
4246 | Note that the history records values, not expressions. If the value of | |
4247 | @code{x} is 4 and you type these commands: | |
4248 | ||
4249 | @example | |
4250 | print x | |
4251 | set x=5 | |
4252 | @end example | |
4253 | ||
4254 | @noindent | |
4255 | then the value recorded in the value history by the @code{print} command | |
4256 | remains 4 even though the value of @code{x} has changed. | |
4257 | ||
4258 | @table @code | |
4259 | @kindex show values | |
4260 | @item show values | |
4261 | Print the last ten values in the value history, with their item numbers. | |
4262 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
4263 | values} does not change the history. | |
4264 | ||
4265 | @item show values @var{n} | |
4266 | Print ten history values centered on history item number @var{n}. | |
4267 | ||
4268 | @item show values + | |
4269 | Print ten history values just after the values last printed. If no more | |
4270 | values are available, produces no display. | |
4271 | @end table | |
4272 | ||
4273 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 4274 | same effect as @samp{show values +}. |
70b88761 RP |
4275 | |
4276 | @node Convenience Vars, Registers, Value History, Data | |
4277 | @section Convenience Variables | |
4278 | ||
4279 | @cindex convenience variables | |
4280 | _GDBN__ provides @dfn{convenience variables} that you can use within | |
4281 | _GDBN__ to hold on to a value and refer to it later. These variables | |
4282 | exist entirely within _GDBN__; they are not part of your program, and | |
4283 | setting a convenience variable has no direct effect on further execution | |
1041a570 | 4284 | of your program. That is why you can use them freely. |
70b88761 RP |
4285 | |
4286 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
4287 | @samp{$} can be used for a convenience variable, unless it is one of | |
4288 | the predefined machine-specific register names (@pxref{Registers}). | |
4289 | (Value history references, in contrast, are @emph{numbers} preceded | |
1041a570 | 4290 | by @samp{$}. @xref{Value History, ,Value History}.) |
70b88761 RP |
4291 | |
4292 | You can save a value in a convenience variable with an assignment | |
4293 | expression, just as you would set a variable in your program. Example: | |
4294 | ||
4295 | @example | |
4296 | set $foo = *object_ptr | |
4297 | @end example | |
4298 | ||
4299 | @noindent | |
4300 | would save in @code{$foo} the value contained in the object pointed to by | |
4301 | @code{object_ptr}. | |
4302 | ||
4303 | Using a convenience variable for the first time creates it; but its value | |
4304 | is @code{void} until you assign a new value. You can alter the value with | |
4305 | another assignment at any time. | |
4306 | ||
4307 | Convenience variables have no fixed types. You can assign a convenience | |
4308 | variable any type of value, including structures and arrays, even if | |
4309 | that variable already has a value of a different type. The convenience | |
4310 | variable, when used as an expression, has the type of its current value. | |
4311 | ||
4312 | @table @code | |
4313 | @item show convenience | |
4314 | @kindex show convenience | |
4315 | Print a list of convenience variables used so far, and their values. | |
4316 | Abbreviated @code{show con}. | |
4317 | @end table | |
4318 | ||
4319 | One of the ways to use a convenience variable is as a counter to be | |
4320 | incremented or a pointer to be advanced. For example, to print | |
4321 | a field from successive elements of an array of structures: | |
4322 | ||
4323 | _0__@example | |
4324 | set $i = 0 | |
4325 | print bar[$i++]->contents | |
4326 | @i{@dots{} repeat that command by typing @key{RET}.} | |
4327 | _1__@end example | |
4328 | ||
4329 | Some convenience variables are created automatically by _GDBN__ and given | |
4330 | values likely to be useful. | |
4331 | ||
4332 | @table @code | |
4333 | @item $_ | |
c338a2fd | 4334 | @kindex $_ |
70b88761 | 4335 | The variable @code{$_} is automatically set by the @code{x} command to |
29a2b744 RP |
4336 | the last address examined (@pxref{Memory, ,Examining Memory}). Other |
4337 | commands which provide a default address for @code{x} to examine also | |
4338 | set @code{$_} to that address; these commands include @code{info line} | |
4339 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4340 | except when set by the @code{x} command, in which case it is a pointer | |
4341 | to the type of @code{$__}. | |
70b88761 RP |
4342 | |
4343 | @item $__ | |
c338a2fd | 4344 | @kindex $__ |
70b88761 | 4345 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
4346 | to the value found in the last address examined. Its type is chosen |
4347 | to match the format in which the data was printed. | |
70b88761 RP |
4348 | @end table |
4349 | ||
4350 | @node Registers, Floating Point Hardware, Convenience Vars, Data | |
4351 | @section Registers | |
4352 | ||
4353 | @cindex registers | |
b80282d5 | 4354 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
4355 | with names starting with @samp{$}. The names of registers are different |
4356 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 4357 | your machine. |
70b88761 RP |
4358 | |
4359 | @table @code | |
4360 | @item info registers | |
4361 | @kindex info registers | |
b80282d5 RP |
4362 | Print the names and values of all registers except floating-point |
4363 | registers (in the selected stack frame). | |
4364 | ||
4365 | @item info all-registers | |
4366 | @kindex info all-registers | |
4367 | @cindex floating point registers | |
4368 | Print the names and values of all registers, including floating-point | |
4369 | registers. | |
70b88761 RP |
4370 | |
4371 | @item info registers @var{regname} | |
4372 | Print the relativized value of register @var{regname}. @var{regname} | |
4373 | may be any register name valid on the machine you are using, with | |
4374 | or without the initial @samp{$}. | |
4375 | @end table | |
4376 | ||
09267865 | 4377 | _GDBN__ has four ``standard'' register names that are available (in |
29a2b744 | 4378 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
4379 | architecture's canonical mnemonics for registers. The register names |
4380 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4381 | the stack pointer. @code{$fp} is used for a register that contains a | |
4382 | pointer to the current stack frame, and @code{$ps} is used for a | |
4383 | register that contains the processor status. For example, | |
70b88761 | 4384 | you could print the program counter in hex with |
1041a570 | 4385 | |
70b88761 RP |
4386 | @example |
4387 | p/x $pc | |
4388 | @end example | |
4389 | ||
4390 | @noindent | |
4391 | or print the instruction to be executed next with | |
1041a570 | 4392 | |
70b88761 RP |
4393 | @example |
4394 | x/i $pc | |
4395 | @end example | |
4396 | ||
4397 | @noindent | |
29a2b744 RP |
4398 | or add four to the stack pointer @footnote{This is a way of removing |
4399 | one word from the stack, on machines where stacks grow downward in | |
4400 | memory (most machines, nowadays). This assumes that the innermost | |
4401 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4402 | stack frames are selected. To pop entire frames off the stack, | |
4403 | regardless of machine architecture, use @code{return}; | |
1041a570 RP |
4404 | @pxref{Returning, ,Returning from a Function}.} with |
4405 | ||
70b88761 RP |
4406 | @example |
4407 | set $sp += 4 | |
4408 | @end example | |
4409 | ||
09267865 RP |
4410 | Whenever possible, these four standard register names are available on |
4411 | your machine even though the machine has different canonical mnemonics, | |
4412 | so long as there is no conflict. The @code{info registers} command | |
4413 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
4414 | registers} displays the processor status register as @code{$psr} but you |
4415 | can also refer to it as @code{$ps}. | |
4416 | ||
4417 | _GDBN__ always considers the contents of an ordinary register as an | |
4418 | integer when the register is examined in this way. Some machines have | |
4419 | special registers which can hold nothing but floating point; these | |
4420 | registers are considered to have floating point values. There is no way | |
4421 | to refer to the contents of an ordinary register as floating point value | |
4422 | (although you can @emph{print} it as a floating point value with | |
4423 | @samp{print/f $@var{regname}}). | |
4424 | ||
4425 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4426 | means that the data format in which the register contents are saved by | |
4427 | the operating system is not the same one that your program normally | |
4428 | sees. For example, the registers of the 68881 floating point | |
4429 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4430 | programs expect to work with ``double'' (virtual) format. In such | |
4431 | cases, _GDBN__ normally works with the virtual format only (the format that | |
4432 | makes sense for your program), but the @code{info registers} command | |
4433 | prints the data in both formats. | |
4434 | ||
4435 | Normally, register values are relative to the selected stack frame | |
29a2b744 RP |
4436 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the |
4437 | value that the register would contain if all stack frames farther in | |
4438 | were exited and their saved registers restored. In order to see the | |
4439 | true contents of hardware registers, you must select the innermost | |
4440 | frame (with @samp{frame 0}). | |
70b88761 RP |
4441 | |
4442 | However, _GDBN__ must deduce where registers are saved, from the machine | |
4443 | code generated by your compiler. If some registers are not saved, or if | |
4444 | _GDBN__ is unable to locate the saved registers, the selected stack | |
4445 | frame will make no difference. | |
4446 | ||
d8a68b28 | 4447 | _if__(_AMD29K__) |
03a77779 | 4448 | @table @code |
d8a68b28 JG |
4449 | @item set rstack_high_address @var{address} |
4450 | @kindex set rstack_high_address | |
03a77779 RP |
4451 | @cindex AMD 29K register stack |
4452 | @cindex register stack, AMD29K | |
4453 | On AMD 29000 family processors, registers are saved in a separate | |
4454 | ``register stack''. There is no way for _GDBN__ to determine the extent | |
4455 | of this stack. Normally, _GDBN__ just assumes that the stack is ``large | |
4456 | enough''. This may result in _GDBN__ referencing memory locations that | |
4457 | don't exist. If necessary, you can get around this problem by | |
4458 | specifying the ending address of the register stack with the @code{set | |
4459 | rstack_high_address} command. The argument should be an address, which | |
4460 | you will probably want to precede with @samp{0x} to specify in | |
4461 | hexadecimal. | |
d8a68b28 JG |
4462 | |
4463 | @item show rstack_high_address | |
4464 | @kindex show rstack_high_address | |
03a77779 RP |
4465 | Display the current limit of the register stack, on AMD 29000 family |
4466 | processors. | |
4467 | @end table | |
d8a68b28 JG |
4468 | _fi__(_AMD29K__) |
4469 | ||
70b88761 RP |
4470 | @node Floating Point Hardware, , Registers, Data |
4471 | @section Floating Point Hardware | |
4472 | @cindex floating point | |
1041a570 | 4473 | |
70b88761 RP |
4474 | Depending on the host machine architecture, _GDBN__ may be able to give |
4475 | you more information about the status of the floating point hardware. | |
4476 | ||
4477 | @table @code | |
4478 | @item info float | |
4479 | @kindex info float | |
4480 | If available, provides hardware-dependent information about the floating | |
4481 | point unit. The exact contents and layout vary depending on the | |
4482 | floating point chip. | |
4483 | @end table | |
4484 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
4485 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
4486 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 RP |
4487 | @c FIXME... at that point. |
4488 | ||
c2bbbb22 RP |
4489 | @node Languages, Symbols, Data, Top |
4490 | @chapter Using _GDBN__ with Different Languages | |
4491 | @cindex languages | |
4492 | ||
4493 | Although programming languages generally have common aspects, they are | |
4494 | rarely expressed in the same manner. For instance, in ANSI C, | |
4495 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4496 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4497 | represented (and displayed) differently. Hex numbers in C are written | |
4498 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4499 | ||
4500 | @cindex working language | |
4501 | Language-specific information is built into _GDBN__ for some languages, | |
29a2b744 | 4502 | allowing you to express operations like the above in your program's |
c2bbbb22 | 4503 | native language, and allowing _GDBN__ to output values in a manner |
29a2b744 | 4504 | consistent with the syntax of your program's native language. The |
c2bbbb22 RP |
4505 | language you use to build expressions, called the @dfn{working |
4506 | language}, can be selected manually, or _GDBN__ can set it | |
4507 | automatically. | |
4508 | ||
4509 | @menu | |
4510 | * Setting:: Switching between source languages | |
4511 | * Show:: Displaying the language | |
4512 | * Checks:: Type and Range checks | |
4513 | * Support:: Supported languages | |
4514 | @end menu | |
4515 | ||
4516 | @node Setting, Show, Languages, Languages | |
4517 | @section Switching between source languages | |
4518 | ||
4519 | There are two ways to control the working language---either have _GDBN__ | |
4520 | set it automatically, or select it manually yourself. You can use the | |
4521 | @code{set language} command for either purpose. On startup, _GDBN__ | |
4522 | defaults to setting the language automatically. | |
4523 | ||
4524 | @menu | |
4525 | * Manually:: Setting the working language manually | |
4526 | * Automatically:: Having _GDBN__ infer the source language | |
4527 | @end menu | |
4528 | ||
4529 | @node Manually, Automatically, Setting, Setting | |
4530 | @subsection Setting the working language | |
4531 | ||
4532 | @kindex set language | |
4533 | To set the language, issue the command @samp{set language @var{lang}}, | |
c338a2fd RP |
4534 | where @var{lang} is the name of a language: @code{c} or @code{modula-2}. |
4535 | For a list of the supported languages, type @samp{set language}. | |
c2bbbb22 RP |
4536 | |
4537 | Setting the language manually prevents _GDBN__ from updating the working | |
4538 | language automatically. This can lead to confusion if you try | |
4539 | to debug a program when the working language is not the same as the | |
4540 | source language, when an expression is acceptable to both | |
4541 | languages---but means different things. For instance, if the current | |
4542 | source file were written in C, and _GDBN__ was parsing Modula-2, a | |
4543 | command such as: | |
4544 | ||
4545 | @example | |
4546 | print a = b + c | |
4547 | @end example | |
4548 | ||
4549 | @noindent | |
4550 | might not have the effect you intended. In C, this means to add | |
4551 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4552 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4553 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4554 | ||
4555 | If you allow _GDBN__ to set the language automatically, then | |
4556 | you can count on expressions evaluating the same way in your debugging | |
4557 | session and in your program. | |
4558 | ||
4559 | @node Automatically, , Manually, Setting | |
4560 | @subsection Having _GDBN__ infer the source language | |
4561 | ||
4562 | To have _GDBN__ set the working language automatically, use @samp{set | |
4563 | language local} or @samp{set language auto}. _GDBN__ then infers the | |
4564 | language that a program was written in by looking at the name of its | |
4565 | source files, and examining their extensions: | |
4566 | ||
4567 | @table @file | |
4568 | @item *.mod | |
4569 | Modula-2 source file | |
4570 | ||
4571 | @item *.c | |
4572 | @itemx *.cc | |
4573 | C or C++ source file. | |
4574 | @end table | |
4575 | ||
4576 | This information is recorded for each function or procedure in a source | |
4577 | file. When your program stops in a frame (usually by encountering a | |
4578 | breakpoint), _GDBN__ sets the working language to the language recorded | |
4579 | for the function in that frame. If the language for a frame is unknown | |
4580 | (that is, if the function or block corresponding to the frame was | |
4581 | defined in a source file that does not have a recognized extension), the | |
4582 | current working language is not changed, and _GDBN__ issues a warning. | |
4583 | ||
4584 | This may not seem necessary for most programs, which are written | |
4585 | entirely in one source language. However, program modules and libraries | |
4586 | written in one source language can be used by a main program written in | |
4587 | a different source language. Using @samp{set language auto} in this | |
4588 | case frees you from having to set the working language manually. | |
4589 | ||
4590 | @node Show, Checks, Setting, Languages | |
4591 | @section Displaying the language | |
4592 | ||
4593 | The following commands will help you find out which language is the | |
4594 | working language, and also what language source files were written in. | |
4595 | ||
4596 | @kindex show language | |
4597 | @kindex info frame | |
4598 | @kindex info source | |
4599 | @table @code | |
4600 | @item show language | |
4601 | Display the current working language. This is the | |
4602 | language you can use with commands such as @code{print} to | |
29a2b744 | 4603 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
4604 | |
4605 | @item info frame | |
1041a570 | 4606 | Among the other information listed here (@pxref{Frame Info, ,Information |
c2bbbb22 RP |
4607 | about a Frame}) is the source language for this frame. This is the |
4608 | language that will become the working language if you ever use an | |
4609 | identifier that is in this frame. | |
4610 | ||
4611 | @item info source | |
1041a570 | 4612 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 4613 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
4614 | @end table |
4615 | ||
4616 | @node Checks, Support, Show, Languages | |
4617 | @section Type and range Checking | |
4618 | ||
4619 | @quotation | |
4620 | @emph{Warning:} In this release, the _GDBN__ commands for type and range | |
4621 | checking are included, but they do not yet have any effect. This | |
4622 | section documents the intended facilities. | |
4623 | @end quotation | |
4624 | @c FIXME remove warning when type/range code added | |
4625 | ||
4626 | Some languages are designed to guard you against making seemingly common | |
4627 | errors through a series of compile- and run-time checks. These include | |
4628 | checking the type of arguments to functions and operators, and making | |
4629 | sure mathematical overflows are caught at run time. Checks such as | |
4630 | these help to ensure a program's correctness once it has been compiled | |
4631 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 4632 | errors when your program is running. |
c2bbbb22 | 4633 | |
1041a570 RP |
4634 | _GDBN__ can check for conditions like the above if you wish. |
4635 | Although _GDBN__ will not check the statements in your program, it | |
4636 | can check expressions entered directly into _GDBN__ for evaluation via | |
4637 | the @code{print} command, for example. As with the working language, | |
c2bbbb22 | 4638 | _GDBN__ can also decide whether or not to check automatically based on |
1041a570 RP |
4639 | your program's source language. @xref{Support, ,Supported Languages}, |
4640 | for the default settings of supported languages. | |
c2bbbb22 RP |
4641 | |
4642 | @menu | |
4643 | * Type Checking:: An overview of type checking | |
4644 | * Range Checking:: An overview of range checking | |
4645 | @end menu | |
4646 | ||
4647 | @cindex type checking | |
4648 | @cindex checks, type | |
4649 | @node Type Checking, Range Checking, Checks, Checks | |
4650 | @subsection An overview of type checking | |
4651 | ||
4652 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4653 | arguments to operators and functions have to be of the correct type, | |
4654 | otherwise an error occurs. These checks prevent type mismatch | |
4655 | errors from ever causing any run-time problems. For example, | |
4656 | ||
4657 | @example | |
4658 | 1 + 2 @result{} 3 | |
1041a570 | 4659 | @exdent but |
c2bbbb22 RP |
4660 | @error{} 1 + 2.3 |
4661 | @end example | |
4662 | ||
4663 | The second example fails because the @code{CARDINAL} 1 is not | |
4664 | type-compatible with the @code{REAL} 2.3. | |
4665 | ||
4666 | For expressions you use in _GDBN__ commands, you can tell the _GDBN__ | |
4667 | type checker to skip checking; to treat any mismatches as errors and | |
4668 | abandon the expression; or only issue warnings when type mismatches | |
4669 | occur, but evaluate the expression anyway. When you choose the last of | |
4670 | these, _GDBN__ evaluates expressions like the second example above, but | |
4671 | also issues a warning. | |
4672 | ||
4673 | Even though you may turn type checking off, other type-based reasons may | |
4674 | prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not | |
4675 | know how to add an @code{int} and a @code{struct foo}. These particular | |
4676 | type errors have nothing to do with the language in use, and usually | |
4677 | arise from expressions, such as the one described above, which make | |
4678 | little sense to evaluate anyway. | |
4679 | ||
4680 | Each language defines to what degree it is strict about type. For | |
4681 | instance, both Modula-2 and C require the arguments to arithmetical | |
4682 | operators to be numbers. In C, enumerated types and pointers can be | |
4683 | represented as numbers, so that they are valid arguments to mathematical | |
1041a570 | 4684 | operators. @xref{Support, ,Supported Languages}, for further |
c2bbbb22 RP |
4685 | details on specific languages. |
4686 | ||
4687 | _GDBN__ provides some additional commands for controlling the type checker: | |
4688 | ||
4689 | @kindex set check | |
4690 | @kindex set check type | |
4691 | @kindex show check type | |
4692 | @table @code | |
4693 | @item set check type auto | |
e251e767 | 4694 | Set type checking on or off based on the current working language. |
1041a570 | 4695 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4696 | each language. |
4697 | ||
4698 | @item set check type on | |
4699 | @itemx set check type off | |
4700 | Set type checking on or off, overriding the default setting for the | |
4701 | current working language. Issue a warning if the setting does not | |
4702 | match the language's default. If any type mismatches occur in | |
4703 | evaluating an expression while typechecking is on, _GDBN__ prints a | |
4704 | message and aborts evaluation of the expression. | |
4705 | ||
4706 | @item set check type warn | |
4707 | Cause the type checker to issue warnings, but to always attempt to | |
4708 | evaluate the expression. Evaluating the expression may still | |
4709 | be impossible for other reasons. For example, _GDBN__ cannot add | |
4710 | numbers and structures. | |
4711 | ||
4712 | @item show type | |
e251e767 | 4713 | Show the current setting of the type checker, and whether or not _GDBN__ is |
c2bbbb22 RP |
4714 | setting it automatically. |
4715 | @end table | |
4716 | ||
4717 | @cindex range checking | |
4718 | @cindex checks, range | |
4719 | @node Range Checking, , Type Checking, Checks | |
4720 | @subsection An overview of Range Checking | |
4721 | ||
4722 | In some languages (such as Modula-2), it is an error to exceed the | |
4723 | bounds of a type; this is enforced with run-time checks. Such range | |
4724 | checking is meant to ensure program correctness by making sure | |
4725 | computations do not overflow, or indices on an array element access do | |
4726 | not exceed the bounds of the array. | |
4727 | ||
4728 | For expressions you use in _GDBN__ commands, you can tell _GDBN__ to | |
4729 | ignore range errors; to always treat them as errors and abandon the | |
4730 | expression; or to issue warnings when a range error occurs but evaluate | |
4731 | the expression anyway. | |
4732 | ||
4733 | A range error can result from numerical overflow, from exceeding an | |
4734 | array index bound, or when you type in a constant that is not a member | |
4735 | of any type. Some languages, however, do not treat overflows as an | |
4736 | error. In many implementations of C, mathematical overflow causes the | |
4737 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4738 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 4739 | |
c2bbbb22 RP |
4740 | @example |
4741 | @var{m} + 1 @result{} @var{s} | |
4742 | @end example | |
4743 | ||
4744 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 4745 | specific to individual compilers or machines. @xref{Support, , |
c2bbbb22 RP |
4746 | Supported Languages}, for further details on specific languages. |
4747 | ||
4748 | _GDBN__ provides some additional commands for controlling the range checker: | |
4749 | ||
4750 | @kindex set check | |
4751 | @kindex set check range | |
4752 | @kindex show check range | |
4753 | @table @code | |
4754 | @item set check range auto | |
e251e767 | 4755 | Set range checking on or off based on the current working language. |
1041a570 | 4756 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4757 | each language. |
4758 | ||
4759 | @item set check range on | |
4760 | @itemx set check range off | |
4761 | Set range checking on or off, overriding the default setting for the | |
4762 | current working language. A warning is issued if the setting does not | |
4763 | match the language's default. If a range error occurs, then a message | |
4764 | is printed and evaluation of the expression is aborted. | |
4765 | ||
4766 | @item set check range warn | |
4767 | Output messages when the _GDBN__ range checker detects a range error, | |
4768 | but attempt to evaluate the expression anyway. Evaluating the | |
4769 | expression may still be impossible for other reasons, such as accessing | |
4770 | memory that the process does not own (a typical example from many UNIX | |
4771 | systems). | |
4772 | ||
4773 | @item show range | |
e251e767 | 4774 | Show the current setting of the range checker, and whether or not it is |
c2bbbb22 RP |
4775 | being set automatically by _GDBN__. |
4776 | @end table | |
4777 | ||
4778 | @node Support, , Checks, Languages | |
4779 | @section Supported Languages | |
4780 | ||
1041a570 RP |
4781 | _GDBN__ 4 supports C, C++, and Modula-2. The syntax for C and C++ is so |
4782 | closely related that _GDBN__ does not distinguish the two. Some _GDBN__ | |
4783 | features may be used in expressions regardless of the language you | |
4784 | use: the _GDBN__ @code{@@} and @code{::} operators, and the | |
4785 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be | |
4786 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
4787 | |
4788 | The following sections detail to what degree each of these | |
4789 | source languages is supported by _GDBN__. These sections are | |
4790 | not meant to be language tutorials or references, but serve only as a | |
4791 | reference guide to what the _GDBN__ expression parser will accept, and | |
4792 | what input and output formats should look like for different languages. | |
4793 | There are many good books written on each of these languages; please | |
4794 | look to these for a language reference or tutorial. | |
4795 | ||
4796 | @menu | |
4797 | * C:: C and C++ | |
4798 | * Modula-2:: Modula-2 | |
4799 | @end menu | |
4800 | ||
4801 | @node C, Modula-2, Support, Support | |
4802 | @subsection C and C++ | |
4803 | @cindex C and C++ | |
4804 | ||
4805 | @cindex expressions in C or C++ | |
4806 | Since C and C++ are so closely related, _GDBN__ does not distinguish | |
4807 | between them when interpreting the expressions recognized in _GDBN__ | |
e251e767 | 4808 | commands. |
b80282d5 RP |
4809 | |
4810 | @cindex C++ | |
4811 | @kindex g++ | |
4812 | @cindex GNU C++ | |
c2bbbb22 RP |
4813 | The C++ debugging facilities are jointly implemented by the GNU C++ |
4814 | compiler and _GDBN__. Therefore, to debug your C++ code effectively, | |
4815 | you must compile your C++ programs with the GNU C++ compiler, | |
4816 | @code{g++}. | |
4817 | ||
b80282d5 | 4818 | @menu |
c2bbbb22 RP |
4819 | * C Operators:: C and C++ Operators |
4820 | * C Constants:: C and C++ Constants | |
4821 | * Cplusplus expressions:: C++ Expressions | |
4822 | * C Defaults:: Default settings for C and C++ | |
4823 | * C Checks:: C and C++ Type and Range Checks | |
4824 | * Debugging C:: _GDBN__ and C | |
4825 | * Debugging C plus plus:: Special features for C++ | |
b80282d5 RP |
4826 | @end menu |
4827 | ||
c2bbbb22 RP |
4828 | @cindex C and C++ operators |
4829 | @node C Operators, C Constants, C, C | |
4830 | @subsubsection C and C++ Operators | |
4831 | ||
4832 | Operators must be defined on values of specific types. For instance, | |
4833 | @code{+} is defined on numbers, but not on structures. Operators are | |
4834 | often defined on groups of types. For the purposes of C and C++, the | |
4835 | following definitions hold: | |
4836 | ||
4837 | @itemize @bullet | |
e251e767 | 4838 | @item |
c2bbbb22 RP |
4839 | @emph{Integral types} include @code{int} with any of its storage-class |
4840 | specifiers, @code{char}, and @code{enum}s. | |
4841 | ||
4842 | @item | |
4843 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4844 | ||
4845 | @item | |
4846 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4847 | *)}. | |
4848 | ||
e251e767 | 4849 | @item |
c2bbbb22 | 4850 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
4851 | @end itemize |
4852 | ||
4853 | @noindent | |
4854 | The following operators are supported. They are listed here | |
4855 | in order of increasing precedence: | |
4856 | ||
4857 | @table @code | |
1041a570 | 4858 | _0__@item , |
c2bbbb22 RP |
4859 | The comma or sequencing operator. Expressions in a comma-separated list |
4860 | are evaluated from left to right, with the result of the entire | |
4861 | expression being the last expression evaluated. | |
4862 | ||
4863 | @item = | |
4864 | Assignment. The value of an assignment expression is the value | |
4865 | assigned. Defined on scalar types. | |
4866 | ||
4867 | @item @var{op}= | |
1041a570 RP |
4868 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
4869 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
4870 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
4871 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
4872 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
4873 | |
4874 | @item ?: | |
4875 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
4876 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
4877 | integral type. | |
4878 | ||
4879 | @item || | |
1041a570 | 4880 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4881 | |
4882 | @item && | |
1041a570 | 4883 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4884 | |
4885 | @item | | |
1041a570 | 4886 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4887 | |
4888 | @item ^ | |
1041a570 | 4889 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
4890 | |
4891 | @item & | |
1041a570 | 4892 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4893 | |
4894 | @item ==@r{, }!= | |
4895 | Equality and inequality. Defined on scalar types. The value of these | |
4896 | expressions is 0 for false and non-zero for true. | |
4897 | ||
4898 | @item <@r{, }>@r{, }<=@r{, }>= | |
4899 | Less than, greater than, less than or equal, greater than or equal. | |
4900 | Defined on scalar types. The value of these expressions is 0 for false | |
4901 | and non-zero for true. | |
4902 | ||
4903 | @item <<@r{, }>> | |
4904 | left shift, and right shift. Defined on integral types. | |
4905 | ||
e251e767 | 4906 | @item @@ |
1041a570 | 4907 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
4908 | |
4909 | @item +@r{, }- | |
4910 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 4911 | pointer types. |
c2bbbb22 RP |
4912 | |
4913 | @item *@r{, }/@r{, }% | |
4914 | Multiplication, division, and modulus. Multiplication and division are | |
4915 | defined on integral and floating-point types. Modulus is defined on | |
4916 | integral types. | |
4917 | ||
4918 | @item ++@r{, }-- | |
4919 | Increment and decrement. When appearing before a variable, the | |
4920 | operation is performed before the variable is used in an expression; | |
4921 | when appearing after it, the variable's value is used before the | |
4922 | operation takes place. | |
4923 | ||
4924 | @item * | |
4925 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
4926 | @code{++}. | |
4927 | ||
4928 | @item & | |
4929 | Address operator. Defined on variables. Same precedence as @code{++}. | |
4930 | ||
6ca72cc6 RP |
4931 | For debugging C++, _GDBN__ implements a use of @samp{&} beyond what's |
4932 | allowed in the C++ language itself: you can use @samp{&(&@var{ref})} | |
4933 | (or, if you prefer, simply @samp{&&@var{ref}} to examine the address | |
4934 | where a C++ reference variable (declared with @samp{&@var{ref}}) is | |
4935 | stored. | |
4936 | ||
c2bbbb22 RP |
4937 | @item - |
4938 | Negative. Defined on integral and floating-point types. Same | |
4939 | precedence as @code{++}. | |
4940 | ||
4941 | @item ! | |
4942 | Logical negation. Defined on integral types. Same precedence as | |
4943 | @code{++}. | |
4944 | ||
4945 | @item ~ | |
4946 | Bitwise complement operator. Defined on integral types. Same precedence as | |
4947 | @code{++}. | |
4948 | ||
4949 | @item .@r{, }-> | |
4950 | Structure member, and pointer-to-structure member. For convenience, | |
4951 | _GDBN__ regards the two as equivalent, choosing whether to dereference a | |
e251e767 | 4952 | pointer based on the stored type information. |
c2bbbb22 RP |
4953 | Defined on @code{struct}s and @code{union}s. |
4954 | ||
4955 | @item [] | |
4956 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
4957 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
4958 | ||
4959 | @item () | |
4960 | Function parameter list. Same precedence as @code{->}. | |
4961 | ||
4962 | @item :: | |
4963 | C++ scope resolution operator. Defined on | |
4964 | @code{struct}, @code{union}, and @code{class} types. | |
4965 | ||
4966 | @item :: | |
1041a570 RP |
4967 | The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}). Same precedence as |
4968 | @code{::}, above._1__ | |
c2bbbb22 RP |
4969 | @end table |
4970 | ||
4971 | @cindex C and C++ constants | |
4972 | @node C Constants, Cplusplus expressions, C Operators, C | |
4973 | @subsubsection C and C++ Constants | |
4974 | ||
4975 | _GDBN__ allows you to express the constants of C and C++ in the | |
4976 | following ways: | |
4977 | ||
4978 | @itemize @bullet | |
c2bbbb22 RP |
4979 | @item |
4980 | Integer constants are a sequence of digits. Octal constants are | |
4981 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 4982 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
4983 | @samp{l}, specifying that the constant should be treated as a |
4984 | @code{long} value. | |
4985 | ||
4986 | @item | |
4987 | Floating point constants are a sequence of digits, followed by a decimal | |
4988 | point, followed by a sequence of digits, and optionally followed by an | |
4989 | exponent. An exponent is of the form: | |
4990 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
4991 | sequence of digits. The @samp{+} is optional for positive exponents. | |
4992 | ||
4993 | @item | |
4994 | Enumerated constants consist of enumerated identifiers, or their | |
4995 | integral equivalents. | |
4996 | ||
4997 | @item | |
4998 | Character constants are a single character surrounded by single quotes | |
4999 | (@code{'}), or a number---the ordinal value of the corresponding character | |
5000 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
5001 | be represented by a letter or by @dfn{escape sequences}, which are of | |
5002 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
5003 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
5004 | @samp{@var{x}} is a predefined special character---for example, | |
5005 | @samp{\n} for newline. | |
5006 | ||
5007 | @item | |
5008 | String constants are a sequence of character constants surrounded | |
5009 | by double quotes (@code{"}). | |
5010 | ||
5011 | @item | |
5012 | Pointer constants are an integral value. | |
c2bbbb22 RP |
5013 | @end itemize |
5014 | ||
c2bbbb22 RP |
5015 | @node Cplusplus expressions, C Defaults, C Constants, C |
5016 | @subsubsection C++ Expressions | |
b80282d5 RP |
5017 | |
5018 | @cindex expressions in C++ | |
b1385986 RP |
5019 | _GDBN__'s expression handling has a number of extensions to |
5020 | interpret a significant subset of C++ expressions. | |
5021 | ||
5022 | @cindex C++ support, not in @sc{coff} | |
5023 | @cindex @sc{coff} versus C++ | |
5024 | @cindex C++ and object formats | |
5025 | @cindex object formats and C++ | |
5026 | @cindex a.out and C++ | |
5027 | @cindex @sc{ecoff} and C++ | |
5028 | @cindex @sc{xcoff} and C++ | |
5029 | @cindex @sc{elf}/stabs and C++ | |
5030 | @cindex @sc{elf}/@sc{dwarf} and C++ | |
5031 | @quotation | |
5032 | @emph{Warning:} Most of these extensions depend on the use of additional | |
5033 | debugging information in the symbol table, and thus require a rich, | |
5034 | extendable object code format. In particular, if your system uses | |
5035 | a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs | |
5036 | extensions to the symbol table, these facilities are all available. | |
5037 | Where the object code format is standard @sc{coff}, on the other hand, | |
5038 | most of the C++ support in _GDBN__ will @emph{not} work, nor can it. | |
5039 | For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the | |
5040 | standard is still evolving, so the C++ support in _GDBN__ is still | |
5041 | fragile; when this debugging format stabilizes, however, C++ support | |
5042 | will also be available on systems that use it. | |
5043 | @end quotation | |
b80282d5 RP |
5044 | |
5045 | @enumerate | |
5046 | ||
5047 | @cindex member functions | |
e251e767 | 5048 | @item |
b80282d5 | 5049 | Member function calls are allowed; you can use expressions like |
1041a570 | 5050 | |
b80282d5 RP |
5051 | @example |
5052 | count = aml->GetOriginal(x, y) | |
5053 | @end example | |
5054 | ||
5055 | @kindex this | |
5056 | @cindex namespace in C++ | |
e251e767 | 5057 | @item |
b80282d5 RP |
5058 | While a member function is active (in the selected stack frame), your |
5059 | expressions have the same namespace available as the member function; | |
5060 | that is, _GDBN__ allows implicit references to the class instance | |
5061 | pointer @code{this} following the same rules as C++. | |
5062 | ||
5063 | @cindex call overloaded functions | |
5064 | @cindex type conversions in C++ | |
e251e767 | 5065 | @item |
b80282d5 RP |
5066 | You can call overloaded functions; _GDBN__ will resolve the function |
5067 | call to the right definition, with one restriction---you must use | |
5068 | arguments of the type required by the function that you want to call. | |
5069 | _GDBN__ will not perform conversions requiring constructors or | |
5070 | user-defined type operators. | |
5071 | ||
5072 | @cindex reference declarations | |
5073 | @item | |
5074 | _GDBN__ understands variables declared as C++ references; you can use them in | |
5075 | expressions just as you do in C++ source---they are automatically | |
e251e767 | 5076 | dereferenced. |
b80282d5 RP |
5077 | |
5078 | In the parameter list shown when _GDBN__ displays a frame, the values of | |
5079 | reference variables are not displayed (unlike other variables); this | |
5080 | avoids clutter, since references are often used for large structures. | |
5081 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 5082 | you have specified @samp{set print address off}. |
b80282d5 RP |
5083 | |
5084 | @item | |
5085 | _GDBN__ supports the C++ name resolution operator @code{::}---your | |
c2bbbb22 RP |
5086 | expressions can use it just as expressions in your program do. Since |
5087 | one scope may be defined in another, you can use @code{::} repeatedly if | |
5088 | necessary, for example in an expression like | |
5089 | @samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows | |
5090 | resolving name scope by reference to source files, in both C and C++ | |
1041a570 | 5091 | debugging (@pxref{Variables, ,Program Variables}). |
b80282d5 RP |
5092 | @end enumerate |
5093 | ||
c2bbbb22 RP |
5094 | @node C Defaults, C Checks, Cplusplus expressions, C |
5095 | @subsubsection C and C++ Defaults | |
5096 | @cindex C and C++ defaults | |
5097 | ||
e251e767 RP |
5098 | If you allow _GDBN__ to set type and range checking automatically, they |
5099 | both default to @code{off} whenever the working language changes to | |
c2bbbb22 RP |
5100 | C/C++. This happens regardless of whether you, or _GDBN__, |
5101 | selected the working language. | |
5102 | ||
5103 | If you allow _GDBN__ to set the language automatically, it sets the | |
5104 | working language to C/C++ on entering code compiled from a source file | |
5105 | whose name ends with @file{.c} or @file{.cc}. | |
1041a570 | 5106 | @xref{Automatically, ,Having _GDBN__ infer the source language}, for |
c2bbbb22 RP |
5107 | further details. |
5108 | ||
5109 | @node C Checks, Debugging C, C Defaults, C | |
5110 | @subsubsection C and C++ Type and Range Checks | |
5111 | @cindex C and C++ checks | |
5112 | ||
5113 | @quotation | |
5114 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5115 | range checking. | |
5116 | @end quotation | |
5117 | @c FIXME remove warning when type/range checks added | |
5118 | ||
5119 | By default, when _GDBN__ parses C or C++ expressions, type checking | |
5120 | is not used. However, if you turn type checking on, _GDBN__ will | |
5121 | consider two variables type equivalent if: | |
5122 | ||
5123 | @itemize @bullet | |
5124 | @item | |
5125 | The two variables are structured and have the same structure, union, or | |
5126 | enumerated tag. | |
5127 | ||
e251e767 | 5128 | @item |
c2bbbb22 RP |
5129 | Two two variables have the same type name, or types that have been |
5130 | declared equivalent through @code{typedef}. | |
5131 | ||
5132 | @ignore | |
5133 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
5134 | @c FIXME--beers? | |
5135 | @item | |
5136 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
5137 | declared in the same declaration. (Note: this may not be true for all C | |
5138 | compilers.) | |
5139 | @end ignore | |
c2bbbb22 RP |
5140 | @end itemize |
5141 | ||
5142 | Range checking, if turned on, is done on mathematical operations. Array | |
5143 | indices are not checked, since they are often used to index a pointer | |
5144 | that is not itself an array. | |
5145 | ||
5146 | @node Debugging C, Debugging C plus plus, C Checks, C | |
5147 | @subsubsection _GDBN__ and C | |
5148 | ||
5149 | The @code{set print union} and @code{show print union} commands apply to | |
5150 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
5151 | inside a @code{struct} or @code{class} will also be printed. | |
5152 | Otherwise, it will appear as @samp{@{...@}}. | |
5153 | ||
5154 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
1041a570 | 5155 | with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
5156 | |
5157 | @node Debugging C plus plus, , Debugging C, C | |
6f3ec223 | 5158 | @subsubsection _GDBN__ Features for C++ |
b80282d5 RP |
5159 | |
5160 | @cindex commands for C++ | |
5161 | Some _GDBN__ commands are particularly useful with C++, and some are | |
5162 | designed specifically for use with C++. Here is a summary: | |
5163 | ||
5164 | @table @code | |
5165 | @cindex break in overloaded functions | |
5166 | @item @r{breakpoint menus} | |
5167 | When you want a breakpoint in a function whose name is overloaded, | |
5168 | _GDBN__'s breakpoint menus help you specify which function definition | |
5169 | you want. @xref{Breakpoint Menus}. | |
5170 | ||
5171 | @cindex overloading in C++ | |
5172 | @item rbreak @var{regex} | |
5173 | Setting breakpoints using regular expressions is helpful for setting | |
5174 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 5175 | classes. |
29a2b744 | 5176 | @xref{Set Breaks, ,Setting Breakpoints}. |
b80282d5 RP |
5177 | |
5178 | @cindex C++ exception handling | |
5179 | @item catch @var{exceptions} | |
5180 | @itemx info catch | |
29a2b744 | 5181 | Debug C++ exception handling using these commands. @xref{Exception |
1041a570 | 5182 | Handling, ,Breakpoints and Exceptions}. |
b80282d5 | 5183 | |
e251e767 | 5184 | @cindex inheritance |
b80282d5 RP |
5185 | @item ptype @var{typename} |
5186 | Print inheritance relationships as well as other information for type | |
e251e767 | 5187 | @var{typename}. |
1041a570 | 5188 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
5189 | |
5190 | @cindex C++ symbol display | |
5191 | @item set print demangle | |
5192 | @itemx show print demangle | |
5193 | @itemx set print asm-demangle | |
5194 | @itemx show print asm-demangle | |
5195 | Control whether C++ symbols display in their source form, both when | |
5196 | displaying code as C++ source and when displaying disassemblies. | |
1041a570 | 5197 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5198 | |
5199 | @item set print object | |
5200 | @itemx show print object | |
e251e767 | 5201 | Choose whether to print derived (actual) or declared types of objects. |
1041a570 | 5202 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5203 | |
5204 | @item set print vtbl | |
5205 | @itemx show print vtbl | |
5206 | Control the format for printing virtual function tables. | |
1041a570 | 5207 | @xref{Print Settings, ,Print Settings}. |
6f3ec223 RP |
5208 | |
5209 | @item @r{Overloaded symbol names} | |
5210 | You can specify a particular definition of an overloaded symbol, using | |
5211 | the same notation that's used to declare such symbols in C++: type | |
5212 | @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can | |
5213 | also use _GDBN__'s command-line word completion facilities to list the | |
5214 | available choices, or to finish the type list for you. | |
5215 | @xref{Completion,, Command Completion}, for details on how to do this. | |
b80282d5 RP |
5216 | @end table |
5217 | ||
c2bbbb22 RP |
5218 | @node Modula-2, , C, Support |
5219 | @subsection Modula-2 | |
5220 | @cindex Modula-2 | |
5221 | ||
5222 | The extensions made to _GDBN__ to support Modula-2 support output | |
5223 | from the GNU Modula-2 compiler (which is currently being developed). | |
5224 | Other Modula-2 compilers are not currently supported, and attempting to | |
5225 | debug executables produced by them will most likely result in an error | |
5226 | as _GDBN__ reads in the executable's symbol table. | |
5227 | ||
5228 | @cindex expressions in Modula-2 | |
5229 | @menu | |
5230 | * M2 Operators:: Built-in operators | |
29a2b744 | 5231 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
5232 | * M2 Constants:: Modula-2 Constants |
5233 | * M2 Defaults:: Default settings for Modula-2 | |
5234 | * Deviations:: Deviations from standard Modula-2 | |
5235 | * M2 Checks:: Modula-2 Type and Range Checks | |
5236 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
5237 | * GDB/M2:: _GDBN__ and Modula-2 | |
5238 | @end menu | |
5239 | ||
29a2b744 | 5240 | @node M2 Operators, Built-In Func/Proc, Modula-2, Modula-2 |
c2bbbb22 RP |
5241 | @subsubsection Operators |
5242 | @cindex Modula-2 operators | |
5243 | ||
5244 | Operators must be defined on values of specific types. For instance, | |
5245 | @code{+} is defined on numbers, but not on structures. Operators are | |
5246 | often defined on groups of types. For the purposes of Modula-2, the | |
5247 | following definitions hold: | |
5248 | ||
5249 | @itemize @bullet | |
5250 | ||
5251 | @item | |
5252 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
5253 | their subranges. | |
5254 | ||
5255 | @item | |
5256 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
5257 | ||
5258 | @item | |
5259 | @emph{Floating-point types} consist of @code{REAL}. | |
5260 | ||
5261 | @item | |
5262 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
5263 | @var{type}}. | |
5264 | ||
5265 | @item | |
5266 | @emph{Scalar types} consist of all of the above. | |
5267 | ||
5268 | @item | |
5269 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
5270 | ||
5271 | @item | |
5272 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
5273 | @end itemize |
5274 | ||
5275 | @noindent | |
5276 | The following operators are supported, and appear in order of | |
5277 | increasing precedence: | |
5278 | ||
5279 | @table @code | |
c2bbbb22 RP |
5280 | @item , |
5281 | Function argument or array index separator. | |
1041a570 | 5282 | _0__ |
c2bbbb22 RP |
5283 | @item := |
5284 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
5285 | @var{value}. | |
5286 | ||
5287 | @item <@r{, }> | |
5288 | Less than, greater than on integral, floating-point, or enumerated | |
5289 | types. | |
5290 | ||
5291 | @item <=@r{, }>= | |
5292 | Less than, greater than, less than or equal to, greater than or equal to | |
5293 | on integral, floating-point and enumerated types, or set inclusion on | |
5294 | set types. Same precedence as @code{<}. | |
5295 | ||
5296 | @item =@r{, }<>@r{, }# | |
5297 | Equality and two ways of expressing inequality, valid on scalar types. | |
5298 | Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is | |
5299 | available for inequality, since @code{#} conflicts with the script | |
5300 | comment character. | |
5301 | ||
5302 | @item IN | |
5303 | Set membership. Defined on set types and the types of their members. | |
5304 | Same precedence as @code{<}. | |
5305 | ||
5306 | @item OR | |
5307 | Boolean disjunction. Defined on boolean types. | |
5308 | ||
5309 | @item AND@r{, }& | |
5310 | Boolean conjuction. Defined on boolean types. | |
5311 | ||
5312 | @item @@ | |
1041a570 | 5313 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5314 | |
5315 | @item +@r{, }- | |
5316 | Addition and subtraction on integral and floating-point types, or union | |
5317 | and difference on set types. | |
5318 | ||
5319 | @item * | |
5320 | Multiplication on integral and floating-point types, or set intersection | |
5321 | on set types. | |
5322 | ||
5323 | @item / | |
5324 | Division on floating-point types, or symmetric set difference on set | |
5325 | types. Same precedence as @code{*}. | |
5326 | ||
5327 | @item DIV@r{, }MOD | |
5328 | Integer division and remainder. Defined on integral types. Same | |
5329 | precedence as @code{*}. | |
5330 | ||
5331 | @item - | |
5332 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
5333 | ||
5334 | @item ^ | |
e251e767 | 5335 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
5336 | |
5337 | @item NOT | |
5338 | Boolean negation. Defined on boolean types. Same precedence as | |
5339 | @code{^}. | |
5340 | ||
5341 | @item . | |
5342 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
5343 | precedence as @code{^}. | |
5344 | ||
5345 | @item [] | |
5346 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
5347 | ||
5348 | @item () | |
5349 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
5350 | as @code{^}. | |
5351 | ||
5352 | @item ::@r{, }. | |
5353 | _GDBN__ and Modula-2 scope operators. | |
c2bbbb22 RP |
5354 | @end table |
5355 | ||
5356 | @quotation | |
5357 | @emph{Warning:} Sets and their operations are not yet supported, so _GDBN__ | |
5358 | will treat the use of the operator @code{IN}, or the use of operators | |
5359 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
5360 | @code{<=}, and @code{>=} on sets as an error. | |
5361 | @end quotation | |
5362 | _1__ | |
29a2b744 RP |
5363 | @cindex Modula-2 built-ins |
5364 | @node Built-In Func/Proc, M2 Constants, M2 Operators, Modula-2 | |
c2bbbb22 RP |
5365 | @subsubsection Built-in Functions and Procedures |
5366 | ||
5367 | Modula-2 also makes available several built-in procedures and functions. | |
5368 | In describing these, the following metavariables are used: | |
5369 | ||
5370 | @table @var | |
5371 | ||
5372 | @item a | |
5373 | represents an @code{ARRAY} variable. | |
5374 | ||
5375 | @item c | |
5376 | represents a @code{CHAR} constant or variable. | |
5377 | ||
5378 | @item i | |
5379 | represents a variable or constant of integral type. | |
5380 | ||
5381 | @item m | |
5382 | represents an identifier that belongs to a set. Generally used in the | |
5383 | same function with the metavariable @var{s}. The type of @var{s} should | |
5384 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
5385 | ||
5386 | @item n | |
5387 | represents a variable or constant of integral or floating-point type. | |
5388 | ||
5389 | @item r | |
5390 | represents a variable or constant of floating-point type. | |
5391 | ||
5392 | @item t | |
5393 | represents a type. | |
5394 | ||
5395 | @item v | |
5396 | represents a variable. | |
5397 | ||
5398 | @item x | |
5399 | represents a variable or constant of one of many types. See the | |
5400 | explanation of the function for details. | |
c2bbbb22 RP |
5401 | @end table |
5402 | ||
5403 | All Modula-2 built-in procedures also return a result, described below. | |
5404 | ||
5405 | @table @code | |
5406 | @item ABS(@var{n}) | |
5407 | Returns the absolute value of @var{n}. | |
5408 | ||
5409 | @item CAP(@var{c}) | |
5410 | If @var{c} is a lower case letter, it returns its upper case | |
5411 | equivalent, otherwise it returns its argument | |
5412 | ||
5413 | @item CHR(@var{i}) | |
5414 | Returns the character whose ordinal value is @var{i}. | |
5415 | ||
5416 | @item DEC(@var{v}) | |
5417 | Decrements the value in the variable @var{v}. Returns the new value. | |
5418 | ||
5419 | @item DEC(@var{v},@var{i}) | |
5420 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5421 | new value. | |
5422 | ||
5423 | @item EXCL(@var{m},@var{s}) | |
5424 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5425 | set. | |
5426 | ||
5427 | @item FLOAT(@var{i}) | |
5428 | Returns the floating point equivalent of the integer @var{i}. | |
5429 | ||
5430 | @item HIGH(@var{a}) | |
5431 | Returns the index of the last member of @var{a}. | |
5432 | ||
5433 | @item INC(@var{v}) | |
5434 | Increments the value in the variable @var{v}. Returns the new value. | |
5435 | ||
5436 | @item INC(@var{v},@var{i}) | |
5437 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5438 | new value. | |
5439 | ||
5440 | @item INCL(@var{m},@var{s}) | |
5441 | Adds the element @var{m} to the set @var{s} if it is not already | |
5442 | there. Returns the new set. | |
5443 | ||
5444 | @item MAX(@var{t}) | |
5445 | Returns the maximum value of the type @var{t}. | |
5446 | ||
5447 | @item MIN(@var{t}) | |
5448 | Returns the minimum value of the type @var{t}. | |
5449 | ||
5450 | @item ODD(@var{i}) | |
5451 | Returns boolean TRUE if @var{i} is an odd number. | |
5452 | ||
5453 | @item ORD(@var{x}) | |
5454 | Returns the ordinal value of its argument. For example, the ordinal | |
5455 | value of a character is its ASCII value (on machines supporting the | |
5456 | ASCII character set). @var{x} must be of an ordered type, which include | |
5457 | integral, character and enumerated types. | |
5458 | ||
5459 | @item SIZE(@var{x}) | |
5460 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5461 | ||
5462 | @item TRUNC(@var{r}) | |
5463 | Returns the integral part of @var{r}. | |
5464 | ||
5465 | @item VAL(@var{t},@var{i}) | |
5466 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5467 | @end table | |
5468 | ||
5469 | @quotation | |
5470 | @emph{Warning:} Sets and their operations are not yet supported, so | |
5471 | _GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as | |
5472 | an error. | |
5473 | @end quotation | |
5474 | ||
5475 | @cindex Modula-2 constants | |
29a2b744 | 5476 | @node M2 Constants, M2 Defaults, Built-In Func/Proc, Modula-2 |
c2bbbb22 RP |
5477 | @subsubsection Constants |
5478 | ||
5479 | _GDBN__ allows you to express the constants of Modula-2 in the following | |
5480 | ways: | |
5481 | ||
5482 | @itemize @bullet | |
5483 | ||
5484 | @item | |
5485 | Integer constants are simply a sequence of digits. When used in an | |
5486 | expression, a constant is interpreted to be type-compatible with the | |
5487 | rest of the expression. Hexadecimal integers are specified by a | |
5488 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5489 | ||
5490 | @item | |
5491 | Floating point constants appear as a sequence of digits, followed by a | |
5492 | decimal point and another sequence of digits. An optional exponent can | |
5493 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5494 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5495 | digits of the floating point constant must be valid decimal (base 10) | |
5496 | digits. | |
5497 | ||
5498 | @item | |
5499 | Character constants consist of a single character enclosed by a pair of | |
5500 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5501 | also be expressed by their ordinal value (their ASCII value, usually) | |
5502 | followed by a @samp{C}. | |
5503 | ||
5504 | @item | |
1041a570 RP |
5505 | String constants consist of a sequence of characters enclosed by a |
5506 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5507 | Escape sequences in the style of C are also allowed. @xref{C | |
5508 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
5509 | sequences. | |
c2bbbb22 RP |
5510 | |
5511 | @item | |
5512 | Enumerated constants consist of an enumerated identifier. | |
5513 | ||
5514 | @item | |
5515 | Boolean constants consist of the identifiers @code{TRUE} and | |
5516 | @code{FALSE}. | |
5517 | ||
5518 | @item | |
5519 | Pointer constants consist of integral values only. | |
5520 | ||
5521 | @item | |
5522 | Set constants are not yet supported. | |
c2bbbb22 RP |
5523 | @end itemize |
5524 | ||
5525 | @node M2 Defaults, Deviations, M2 Constants, Modula-2 | |
5526 | @subsubsection Modula-2 Defaults | |
5527 | @cindex Modula-2 defaults | |
5528 | ||
e251e767 RP |
5529 | If type and range checking are set automatically by _GDBN__, they |
5530 | both default to @code{on} whenever the working language changes to | |
c2bbbb22 RP |
5531 | Modula-2. This happens regardless of whether you, or _GDBN__, |
5532 | selected the working language. | |
5533 | ||
5534 | If you allow _GDBN__ to set the language automatically, then entering | |
5535 | code compiled from a file whose name ends with @file{.mod} will set the | |
1041a570 | 5536 | working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set |
c2bbbb22 RP |
5537 | the language automatically}, for further details. |
5538 | ||
5539 | @node Deviations, M2 Checks, M2 Defaults, Modula-2 | |
5540 | @subsubsection Deviations from Standard Modula-2 | |
5541 | @cindex Modula-2, deviations from | |
5542 | ||
5543 | A few changes have been made to make Modula-2 programs easier to debug. | |
5544 | This is done primarily via loosening its type strictness: | |
5545 | ||
5546 | @itemize @bullet | |
e251e767 | 5547 | @item |
c2bbbb22 RP |
5548 | Unlike in standard Modula-2, pointer constants can be formed by |
5549 | integers. This allows you to modify pointer variables during | |
5550 | debugging. (In standard Modula-2, the actual address contained in a | |
5551 | pointer variable is hidden from you; it can only be modified | |
5552 | through direct assignment to another pointer variable or expression that | |
5553 | returned a pointer.) | |
5554 | ||
e251e767 | 5555 | @item |
c2bbbb22 RP |
5556 | C escape sequences can be used in strings and characters to represent |
5557 | non-printable characters. _GDBN__ will print out strings with these | |
5558 | escape sequences embedded. Single non-printable characters are | |
5559 | printed using the @samp{CHR(@var{nnn})} format. | |
5560 | ||
5561 | @item | |
5562 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5563 | argument. | |
5564 | ||
5565 | @item | |
29a2b744 | 5566 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 5567 | @end itemize |
c2bbbb22 RP |
5568 | |
5569 | @node M2 Checks, M2 Scope, Deviations, Modula-2 | |
5570 | @subsubsection Modula-2 Type and Range Checks | |
5571 | @cindex Modula-2 checks | |
5572 | ||
5573 | @quotation | |
5574 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5575 | range checking. | |
5576 | @end quotation | |
5577 | @c FIXME remove warning when type/range checks added | |
5578 | ||
5579 | _GDBN__ considers two Modula-2 variables type equivalent if: | |
5580 | ||
5581 | @itemize @bullet | |
5582 | @item | |
5583 | They are of types that have been declared equivalent via a @code{TYPE | |
5584 | @var{t1} = @var{t2}} statement | |
5585 | ||
5586 | @item | |
5587 | They have been declared on the same line. (Note: This is true of the | |
5588 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
5589 | @end itemize |
5590 | ||
5591 | As long as type checking is enabled, any attempt to combine variables | |
5592 | whose types are not equivalent is an error. | |
5593 | ||
5594 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 5595 | index bounds, and all built-in functions and procedures. |
c2bbbb22 RP |
5596 | |
5597 | @node M2 Scope, GDB/M2, M2 Checks, Modula-2 | |
5598 | @subsubsection The scope operators @code{::} and @code{.} | |
5599 | @cindex scope | |
5600 | @kindex . | |
e94b4a2b | 5601 | @cindex colon, doubled as scope operator |
1041a570 RP |
5602 | @ifinfo |
5603 | @kindex colon-colon | |
5604 | @c Info cannot handoe :: but TeX can. | |
5605 | @end ifinfo | |
5606 | @iftex | |
c2bbbb22 | 5607 | @kindex :: |
1041a570 | 5608 | @end iftex |
c2bbbb22 RP |
5609 | |
5610 | There are a few subtle differences between the Modula-2 scope operator | |
5611 | (@code{.}) and the _GDBN__ scope operator (@code{::}). The two have | |
5612 | similar syntax: | |
5613 | ||
5614 | @example | |
5615 | ||
5616 | @var{module} . @var{id} | |
5617 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
5618 | @end example |
5619 | ||
5620 | @noindent | |
5621 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
5622 | @var{module} the name of a module, and @var{id} is any declared |
5623 | identifier within your program, except another module. | |
c2bbbb22 RP |
5624 | |
5625 | Using the @code{::} operator makes _GDBN__ search the scope | |
5626 | specified by @var{scope} for the identifier @var{id}. If it is not | |
5627 | found in the specified scope, then _GDBN__ will search all scopes | |
5628 | enclosing the one specified by @var{scope}. | |
5629 | ||
5630 | Using the @code{.} operator makes _GDBN__ search the current scope for | |
5631 | the identifier specified by @var{id} that was imported from the | |
5632 | definition module specified by @var{module}. With this operator, it is | |
5633 | an error if the identifier @var{id} was not imported from definition | |
5634 | module @var{module}, or if @var{id} is not an identifier in | |
5635 | @var{module}. | |
5636 | ||
5637 | @node GDB/M2, , M2 Scope, Modula-2 | |
5638 | @subsubsection _GDBN__ and Modula-2 | |
5639 | ||
5640 | Some _GDBN__ commands have little use when debugging Modula-2 programs. | |
5641 | Five subcommands of @code{set print} and @code{show print} apply | |
5642 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5643 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
5644 | apply to C++, and the last to C's @code{union} type, which has no direct | |
5645 | analogue in Modula-2. | |
5646 | ||
1041a570 | 5647 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
5648 | while using any language, is not useful with Modula-2. Its |
5649 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5650 | created in Modula-2 as they can in C or C++. However, because an | |
5651 | address can be specified by an integral constant, the construct | |
1041a570 | 5652 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
5653 | _0__ |
5654 | @cindex @code{#} in Modula-2 | |
5655 | In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is | |
5656 | interpreted as the beginning of a comment. Use @code{<>} instead. | |
5657 | _1__ | |
c2bbbb22 | 5658 | @node Symbols, Altering, Languages, Top |
70b88761 RP |
5659 | @chapter Examining the Symbol Table |
5660 | ||
5661 | The commands described in this section allow you to inquire about the | |
5662 | symbols (names of variables, functions and types) defined in your | |
5663 | program. This information is inherent in the text of your program and | |
29a2b744 | 5664 | does not change as your program executes. _GDBN__ finds it in your |
e251e767 | 5665 | program's symbol table, in the file indicated when you started _GDBN__ |
1041a570 RP |
5666 | (@pxref{File Options, ,Choosing Files}), or by one of the |
5667 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
70b88761 RP |
5668 | |
5669 | @table @code | |
5670 | @item info address @var{symbol} | |
5671 | @kindex info address | |
5672 | Describe where the data for @var{symbol} is stored. For a register | |
5673 | variable, this says which register it is kept in. For a non-register | |
5674 | local variable, this prints the stack-frame offset at which the variable | |
5675 | is always stored. | |
5676 | ||
5677 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5678 | at all for a register variables, and for a stack local variable prints | |
5679 | the exact address of the current instantiation of the variable. | |
5680 | ||
5681 | @item whatis @var{exp} | |
5682 | @kindex whatis | |
5683 | Print the data type of expression @var{exp}. @var{exp} is not | |
5684 | actually evaluated, and any side-effecting operations (such as | |
5685 | assignments or function calls) inside it do not take place. | |
1041a570 | 5686 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
5687 | |
5688 | @item whatis | |
5689 | Print the data type of @code{$}, the last value in the value history. | |
5690 | ||
5691 | @item ptype @var{typename} | |
5692 | @kindex ptype | |
5693 | Print a description of data type @var{typename}. @var{typename} may be | |
5694 | the name of a type, or for C code it may have the form | |
5695 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 5696 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
5697 | |
5698 | @item ptype @var{exp} | |
e0dacfd1 | 5699 | @itemx ptype |
70b88761 | 5700 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 RP |
5701 | differs from @code{whatis} by printing a detailed description, instead |
5702 | of just the name of the type. For example, if your program declares a | |
5703 | variable as | |
5704 | ||
70b88761 RP |
5705 | @example |
5706 | struct complex @{double real; double imag;@} v; | |
5707 | @end example | |
1041a570 | 5708 | |
70b88761 RP |
5709 | @noindent |
5710 | compare the output of the two commands: | |
1041a570 | 5711 | |
70b88761 | 5712 | @example |
1041a570 | 5713 | @group |
70b88761 RP |
5714 | (_GDBP__) whatis v |
5715 | type = struct complex | |
5716 | (_GDBP__) ptype v | |
5717 | type = struct complex @{ | |
5718 | double real; | |
5719 | double imag; | |
5720 | @} | |
1041a570 | 5721 | @end group |
70b88761 | 5722 | @end example |
1041a570 | 5723 | |
e0dacfd1 RP |
5724 | @noindent |
5725 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5726 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
5727 | |
5728 | @item info types @var{regexp} | |
5729 | @itemx info types | |
e251e767 | 5730 | @kindex info types |
70b88761 RP |
5731 | Print a brief description of all types whose name matches @var{regexp} |
5732 | (or all types in your program, if you supply no argument). Each | |
5733 | complete typename is matched as though it were a complete line; thus, | |
5734 | @samp{i type value} gives information on all types in your program whose | |
5735 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5736 | information only on types whose complete name is @code{value}. | |
5737 | ||
5738 | This command differs from @code{ptype} in two ways: first, like | |
5739 | @code{whatis}, it does not print a detailed description; second, it | |
5740 | lists all source files where a type is defined. | |
5741 | ||
5742 | @item info source | |
5743 | @kindex info source | |
5744 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
5745 | the function containing the current point of execution---and the language |
5746 | it was written in. | |
70b88761 RP |
5747 | |
5748 | @item info sources | |
5749 | @kindex info sources | |
29a2b744 | 5750 | Print the names of all source files in your program for which there is |
b80282d5 RP |
5751 | debugging information, organized into two lists: files whose symbols |
5752 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
5753 | |
5754 | @item info functions | |
5755 | @kindex info functions | |
5756 | Print the names and data types of all defined functions. | |
5757 | ||
5758 | @item info functions @var{regexp} | |
5759 | Print the names and data types of all defined functions | |
5760 | whose names contain a match for regular expression @var{regexp}. | |
5761 | Thus, @samp{info fun step} finds all functions whose names | |
5762 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5763 | start with @code{step}. | |
5764 | ||
5765 | @item info variables | |
5766 | @kindex info variables | |
5767 | Print the names and data types of all variables that are declared | |
5768 | outside of functions (i.e., excluding local variables). | |
5769 | ||
5770 | @item info variables @var{regexp} | |
5771 | Print the names and data types of all variables (except for local | |
5772 | variables) whose names contain a match for regular expression | |
5773 | @var{regexp}. | |
5774 | ||
70b88761 RP |
5775 | @ignore |
5776 | This was never implemented. | |
5777 | @item info methods | |
5778 | @itemx info methods @var{regexp} | |
5779 | @kindex info methods | |
5780 | The @code{info methods} command permits the user to examine all defined | |
5781 | methods within C++ program, or (with the @var{regexp} argument) a | |
5782 | specific set of methods found in the various C++ classes. Many | |
5783 | C++ classes provide a large number of methods. Thus, the output | |
5784 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5785 | @code{info-methods} command filters the methods, printing only those | |
5786 | which match the regular-expression @var{regexp}. | |
5787 | @end ignore | |
5788 | ||
5789 | @item printsyms @var{filename} | |
440d9834 | 5790 | @itemx printpsyms @var{filename} |
d24e0922 | 5791 | @itemx printmsyms @var{filename} |
70b88761 | 5792 | @kindex printsyms |
440d9834 RP |
5793 | @cindex symbol dump |
5794 | @kindex printsyms | |
5795 | @cindex partial symbol dump | |
5796 | Write a dump of debugging symbol data into the file @var{filename}. | |
e0dacfd1 RP |
5797 | These commands are used to debug the _GDBN__ symbol-reading code. Only |
5798 | symbols with debugging data are included. If you use @code{printsyms}, | |
5799 | _GDBN__ includes all the symbols for which it has already collected full | |
5800 | details: that is, @var{filename} reflects symbols for only those files | |
5801 | whose symbols _GDBN__ has read. You can use the command @code{info | |
5802 | sources} to find out which files these are. If you use | |
d24e0922 | 5803 | @code{printpsyms} instead, the dump shows information about symbols that |
e0dacfd1 | 5804 | _GDBN__ only knows partially---that is, symbols defined in files that |
d24e0922 | 5805 | _GDBN__ has skimmed, but not yet read completely. Finally, |
717b47f4 | 5806 | @code{printmsyms} dumps just the minimal symbol information required for |
d24e0922 RP |
5807 | each object file from which _GDBN__ has read some symbols. The description of |
5808 | @code{symbol-file} explains how _GDBN__ reads symbols; both @code{info | |
5809 | source} and @code{symbol-file} are described in @ref{Files, ,Commands | |
5810 | to Specify Files}. | |
70b88761 RP |
5811 | @end table |
5812 | ||
5813 | @node Altering, _GDBN__ Files, Symbols, Top | |
5814 | @chapter Altering Execution | |
5815 | ||
29a2b744 | 5816 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
5817 | find out for certain whether correcting the apparent error would lead to |
5818 | correct results in the rest of the run. You can find the answer by | |
5819 | experiment, using the _GDBN__ features for altering execution of the | |
5820 | program. | |
5821 | ||
5822 | For example, you can store new values into variables or memory | |
29a2b744 | 5823 | locations, give your program a signal, restart it at a different address, |
70b88761 RP |
5824 | or even return prematurely from a function to its caller. |
5825 | ||
5826 | @menu | |
b80282d5 RP |
5827 | * Assignment:: Assignment to Variables |
5828 | * Jumping:: Continuing at a Different Address | |
29a2b744 | 5829 | * Signaling:: Giving your program a Signal |
b80282d5 RP |
5830 | * Returning:: Returning from a Function |
5831 | * Calling:: Calling your Program's Functions | |
c338a2fd | 5832 | * Patching:: Patching your Program |
70b88761 RP |
5833 | @end menu |
5834 | ||
5835 | @node Assignment, Jumping, Altering, Altering | |
5836 | @section Assignment to Variables | |
5837 | ||
5838 | @cindex assignment | |
5839 | @cindex setting variables | |
5840 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 5841 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
5842 | |
5843 | @example | |
5844 | print x=4 | |
5845 | @end example | |
5846 | ||
5847 | @noindent | |
1041a570 RP |
5848 | stores the value 4 into the variable @code{x}, and then prints the |
5849 | value of the assignment expression (which is 4). @xref{Languages, | |
5850 | ,Using _GDBN__ with Different Languages}, for more information on | |
5851 | operators in supported languages. | |
70b88761 | 5852 | |
70b88761 RP |
5853 | @kindex set variable |
5854 | @cindex variables, setting | |
5855 | If you are not interested in seeing the value of the assignment, use the | |
5856 | @code{set} command instead of the @code{print} command. @code{set} is | |
5857 | really the same as @code{print} except that the expression's value is not | |
1041a570 | 5858 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The |
70b88761 RP |
5859 | expression is evaluated only for its effects. |
5860 | ||
5861 | If the beginning of the argument string of the @code{set} command | |
5862 | appears identical to a @code{set} subcommand, use the @code{set | |
5863 | variable} command instead of just @code{set}. This command is identical | |
5864 | to @code{set} except for its lack of subcommands. For example, a | |
5865 | program might well have a variable @code{width}---which leads to | |
5866 | an error if we try to set a new value with just @samp{set width=13}, as | |
1041a570 RP |
5867 | we might if @code{set width} did not happen to be a _GDBN__ command: |
5868 | ||
70b88761 RP |
5869 | @example |
5870 | (_GDBP__) whatis width | |
5871 | type = double | |
5872 | (_GDBP__) p width | |
5873 | $4 = 13 | |
5874 | (_GDBP__) set width=47 | |
5875 | Invalid syntax in expression. | |
5876 | @end example | |
1041a570 | 5877 | |
70b88761 RP |
5878 | @noindent |
5879 | The invalid expression, of course, is @samp{=47}. What we can do in | |
e251e767 | 5880 | order to actually set our program's variable @code{width} is |
1041a570 | 5881 | |
70b88761 RP |
5882 | @example |
5883 | (_GDBP__) set var width=47 | |
5884 | @end example | |
5885 | ||
1041a570 RP |
5886 | _GDBN__ allows more implicit conversions in assignments than C; you can |
5887 | freely store an integer value into a pointer variable or vice versa, | |
5888 | and any structure can be converted to any other structure that is the | |
5889 | same length or shorter. | |
e251e767 | 5890 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
5891 | @comment /[email protected] 18dec1990 |
5892 | ||
5893 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
5894 | construct to generate a value of specified type at a specified address | |
1041a570 | 5895 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
5896 | to memory location @code{0x83040} as an integer (which implies a certain size |
5897 | and representation in memory), and | |
5898 | ||
5899 | @example | |
5900 | set @{int@}0x83040 = 4 | |
5901 | @end example | |
5902 | ||
5903 | @noindent | |
5904 | stores the value 4 into that memory location. | |
5905 | ||
5906 | @node Jumping, Signaling, Assignment, Altering | |
5907 | @section Continuing at a Different Address | |
5908 | ||
29a2b744 | 5909 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
5910 | it stopped, with the @code{continue} command. You can instead continue at |
5911 | an address of your own choosing, with the following commands: | |
5912 | ||
5913 | @table @code | |
5914 | @item jump @var{linespec} | |
5915 | @kindex jump | |
5916 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 RP |
5917 | immediately if there is a breakpoint there. @xref{List, ,Printing |
5918 | Source Lines}, for a description of the different forms of | |
5919 | @var{linespec}. | |
70b88761 RP |
5920 | |
5921 | The @code{jump} command does not change the current stack frame, or | |
5922 | the stack pointer, or the contents of any memory location or any | |
5923 | register other than the program counter. If line @var{linespec} is in | |
5924 | a different function from the one currently executing, the results may | |
5925 | be bizarre if the two functions expect different patterns of arguments or | |
5926 | of local variables. For this reason, the @code{jump} command requests | |
5927 | confirmation if the specified line is not in the function currently | |
5928 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 5929 | well acquainted with the machine-language code of your program. |
70b88761 RP |
5930 | |
5931 | @item jump *@var{address} | |
5932 | Resume execution at the instruction at address @var{address}. | |
5933 | @end table | |
5934 | ||
5935 | You can get much the same effect as the @code{jump} command by storing a | |
5936 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 5937 | does not start your program running; it only changes the address where it |
70b88761 RP |
5938 | @emph{will} run when it is continued. For example, |
5939 | ||
5940 | @example | |
5941 | set $pc = 0x485 | |
5942 | @end example | |
5943 | ||
5944 | @noindent | |
5945 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 RP |
5946 | address @code{0x485}, rather than at the address where your program stopped. |
5947 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
70b88761 RP |
5948 | |
5949 | The most common occasion to use the @code{jump} command is to back up, | |
5950 | perhaps with more breakpoints set, over a portion of a program that has | |
5951 | already executed, in order to examine its execution in more detail. | |
5952 | ||
5953 | @node Signaling, Returning, Jumping, Altering | |
5954 | @c @group | |
29a2b744 | 5955 | @section Giving your program a Signal |
70b88761 RP |
5956 | |
5957 | @table @code | |
5958 | @item signal @var{signalnum} | |
5959 | @kindex signal | |
29a2b744 | 5960 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
5961 | signal number @var{signalnum}. |
5962 | ||
5963 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 5964 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
5965 | a signal and would ordinary see the signal when resumed with the |
5966 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
5967 | signal. | |
5968 | ||
5969 | @code{signal} does not repeat when you press @key{RET} a second time | |
5970 | after executing the command. | |
5971 | @end table | |
5972 | @c @end group | |
5973 | ||
5974 | @node Returning, Calling, Signaling, Altering | |
5975 | @section Returning from a Function | |
5976 | ||
5977 | @table @code | |
5978 | @item return | |
5979 | @itemx return @var{expression} | |
5980 | @cindex returning from a function | |
5981 | @kindex return | |
5982 | You can cancel execution of a function call with the @code{return} | |
5983 | command. If you give an | |
5984 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 5985 | value. |
70b88761 RP |
5986 | @end table |
5987 | ||
5988 | When you use @code{return}, _GDBN__ discards the selected stack frame | |
5989 | (and all frames within it). You can think of this as making the | |
5990 | discarded frame return prematurely. If you wish to specify a value to | |
5991 | be returned, give that value as the argument to @code{return}. | |
5992 | ||
29a2b744 RP |
5993 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
5994 | Frame}), and any other frames inside of it, leaving its caller as the | |
5995 | innermost remaining frame. That frame becomes selected. The | |
5996 | specified value is stored in the registers used for returning values | |
5997 | of functions. | |
70b88761 RP |
5998 | |
5999 | The @code{return} command does not resume execution; it leaves the | |
6000 | program stopped in the state that would exist if the function had just | |
1041a570 RP |
6001 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
6002 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
6003 | selected stack frame returns naturally. | |
70b88761 | 6004 | |
c338a2fd | 6005 | @node Calling, Patching, Returning, Altering |
70b88761 RP |
6006 | @section Calling your Program's Functions |
6007 | ||
6008 | @cindex calling functions | |
6009 | @kindex call | |
6010 | @table @code | |
6011 | @item call @var{expr} | |
6012 | Evaluate the expression @var{expr} without displaying @code{void} | |
6013 | returned values. | |
6014 | @end table | |
6015 | ||
6016 | You can use this variant of the @code{print} command if you want to | |
6017 | execute a function from your program, but without cluttering the output | |
6018 | with @code{void} returned values. The result is printed and saved in | |
6019 | the value history, if it is not void. | |
6020 | ||
c338a2fd RP |
6021 | @node Patching, , Calling, Altering |
6022 | @section Patching your Program | |
6023 | @cindex patching binaries | |
6024 | @cindex writing into executables | |
6025 | @cindex writing into corefiles | |
1041a570 | 6026 | |
c338a2fd RP |
6027 | By default, _GDBN__ opens the file containing your program's executable |
6028 | code (or the corefile) read-only. This prevents accidental alterations | |
6029 | to machine code; but it also prevents you from intentionally patching | |
6030 | your program's binary. | |
6031 | ||
6032 | If you'd like to be able to patch the binary, you can specify that | |
6033 | explicitly with the @code{set write} command. For example, you might | |
6034 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 6035 | repairs. |
c338a2fd RP |
6036 | |
6037 | @table @code | |
6038 | @item set write on | |
6039 | @itemx set write off | |
6040 | @kindex set write | |
6041 | If you specify @samp{set write on}, _GDBN__ will open executable and | |
6042 | core files for both reading and writing; if you specify @samp{set write | |
6043 | off} (the default), _GDBN__ will open them read-only. | |
6044 | ||
1041a570 | 6045 | If you have already loaded a file, you must load it |
c338a2fd RP |
6046 | again (using the @code{exec-file} or @code{core-file} command) after |
6047 | changing @code{set write}, for your new setting to take effect. | |
6048 | ||
6049 | @item show write | |
7d7ff5f6 | 6050 | @kindex show write |
c338a2fd RP |
6051 | Display whether executable files and core files will be opened for |
6052 | writing as well as reading. | |
c338a2fd RP |
6053 | @end table |
6054 | ||
70b88761 RP |
6055 | @node _GDBN__ Files, Targets, Altering, Top |
6056 | @chapter _GDBN__'s Files | |
6057 | ||
1041a570 RP |
6058 | _GDBN__ needs to know the file name of the program to be debugged, both in |
6059 | order to read its symbol table and in order to start your program. To | |
6060 | debug a core dump of a previous run, _GDBN__ must be told the file name of | |
6061 | the core dump. | |
6062 | ||
70b88761 | 6063 | @menu |
b80282d5 RP |
6064 | * Files:: Commands to Specify Files |
6065 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 RP |
6066 | @end menu |
6067 | ||
6068 | @node Files, Symbol Errors, _GDBN__ Files, _GDBN__ Files | |
6069 | @section Commands to Specify Files | |
6070 | @cindex core dump file | |
6071 | @cindex symbol table | |
70b88761 | 6072 | |
1041a570 RP |
6073 | The usual way to specify executable and core dump file names is with |
6074 | the command arguments given when you start _GDBN__, (@pxref{Invocation, | |
6075 | ,Getting In and Out of _GDBN__}. | |
70b88761 RP |
6076 | |
6077 | Occasionally it is necessary to change to a different file during a | |
6078 | _GDBN__ session. Or you may run _GDBN__ and forget to specify the files you | |
6079 | want to use. In these situations the _GDBN__ commands to specify new files | |
6080 | are useful. | |
6081 | ||
6082 | @table @code | |
6083 | @item file @var{filename} | |
6084 | @cindex executable file | |
6085 | @kindex file | |
6086 | Use @var{filename} as the program to be debugged. It is read for its | |
6087 | symbols and for the contents of pure memory. It is also the program | |
6088 | executed when you use the @code{run} command. If you do not specify a | |
1041a570 RP |
6089 | directory and the file is not found in _GDBN__'s working directory, _GDBN__ |
6090 | uses the environment variable @code{PATH} as a list of directories to | |
6091 | search, just as the shell does when looking for a program to run. You | |
6092 | can change the value of this variable, for both _GDBN__ and your program, | |
6093 | using the @code{path} command. | |
70b88761 | 6094 | |
14d01801 RP |
6095 | On systems with memory-mapped files, an auxiliary symbol table file |
6096 | @file{@var{filename}.syms} may be available for @var{filename}. If it | |
6097 | is, _GDBN__ will map in the symbol table from | |
6098 | @file{@var{filename}.syms}, starting up more quickly. See the | |
95d5ceb9 | 6099 | descriptions of the options @samp{-mapped} and @samp{-readnow} (available |
77b46d13 JG |
6100 | on the command line, and with the commands @code{file}, @code{symbol-file}, |
6101 | or @code{add-symbol-file}), for more information. | |
14d01801 | 6102 | |
e0dacfd1 | 6103 | @item file |
70b88761 RP |
6104 | @code{file} with no argument makes _GDBN__ discard any information it |
6105 | has on both executable file and the symbol table. | |
6106 | ||
e0dacfd1 | 6107 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6108 | @kindex exec-file |
6109 | Specify that the program to be run (but not the symbol table) is found | |
6110 | in @var{filename}. _GDBN__ will search the environment variable @code{PATH} | |
29a2b744 | 6111 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 6112 | discard information on the executable file. |
70b88761 | 6113 | |
e0dacfd1 | 6114 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6115 | @kindex symbol-file |
6116 | Read symbol table information from file @var{filename}. @code{PATH} is | |
6117 | searched when necessary. Use the @code{file} command to get both symbol | |
6118 | table and program to run from the same file. | |
6119 | ||
6120 | @code{symbol-file} with no argument clears out _GDBN__'s information on your | |
6121 | program's symbol table. | |
6122 | ||
6123 | The @code{symbol-file} command causes _GDBN__ to forget the contents of its | |
6124 | convenience variables, the value history, and all breakpoints and | |
6125 | auto-display expressions. This is because they may contain pointers to | |
6126 | the internal data recording symbols and data types, which are part of | |
6127 | the old symbol table data being discarded inside _GDBN__. | |
6128 | ||
6129 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
6130 | executing it once. | |
6131 | ||
14d01801 RP |
6132 | When _GDBN__ is configured for a particular environment, it will |
6133 | understand debugging information in whatever format is the standard | |
6134 | generated for that environment; you may use either a GNU compiler, or | |
6135 | other compilers that adhere to the local conventions. Best results are | |
6136 | usually obtained from GNU compilers; for example, using @code{_GCC__} | |
6137 | you can generate debugging information for optimized code. | |
6138 | ||
70b88761 | 6139 | On some kinds of object files, the @code{symbol-file} command does not |
14d01801 | 6140 | normally read the symbol table in full right away. Instead, it scans |
70b88761 RP |
6141 | the symbol table quickly to find which source files and which symbols |
6142 | are present. The details are read later, one source file at a time, | |
1041a570 | 6143 | as they are needed. |
70b88761 RP |
6144 | |
6145 | The purpose of this two-stage reading strategy is to make _GDBN__ start up | |
1041a570 RP |
6146 | faster. For the most part, it is invisible except for occasional |
6147 | pauses while the symbol table details for a particular source file are | |
6148 | being read. (The @code{set verbose} command can turn these pauses | |
6149 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings | |
6150 | and Messages}.) | |
70b88761 RP |
6151 | |
6152 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
1041a570 | 6153 | read the symbol table data in full right away. We have not implemented |
70b88761 RP |
6154 | the two-stage strategy for COFF yet. |
6155 | ||
95d5ceb9 RP |
6156 | @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
6157 | @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} | |
14d01801 RP |
6158 | @kindex readnow |
6159 | @cindex reading symbols immediately | |
6160 | @cindex symbols, reading immediately | |
6161 | @kindex mapped | |
6162 | @cindex memory-mapped symbol file | |
38962738 | 6163 | @cindex saving symbol table |
14d01801 | 6164 | You can override the _GDBN__ two-stage strategy for reading symbol |
95d5ceb9 | 6165 | tables by using the @samp{-readnow} option with any of the commands that |
14d01801 RP |
6166 | load symbol table information, if you want to be sure _GDBN__ has the |
6167 | entire symbol table available. | |
6168 | ||
6169 | If memory-mapped files are available on your system through the | |
95d5ceb9 | 6170 | @code{mmap} system call, you can use another option, @samp{-mapped}, to |
77b46d13 JG |
6171 | cause _GDBN__ to write the symbols for your program into a reusable |
6172 | file. Future _GDBN__ debugging sessions will map in symbol information | |
6173 | from this auxiliary symbol file (if the program hasn't changed), rather | |
6174 | than spending time reading the symbol table from the executable | |
6175 | program. Using the @samp{-mapped} option has the same effect as | |
6176 | starting _GDBN__ with the @samp{-mapped} command-line option. | |
14d01801 | 6177 | |
95d5ceb9 | 6178 | You can use both options together, to make sure the auxiliary symbol |
14d01801 RP |
6179 | file has all the symbol information for your program. |
6180 | ||
77b46d13 JG |
6181 | The @code{.syms} file is specific to the host machine on which GDB is run. |
6182 | It holds an exact image of GDB's internal symbol table. It cannot be | |
6183 | shared across multiple host platforms. | |
6184 | ||
14d01801 RP |
6185 | The auxiliary symbol file for a program called @var{myprog} is called |
6186 | @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer | |
6187 | than the corresponding executable), _GDBN__ will always attempt to use | |
6188 | it when you debug @var{myprog}; no special options or commands are | |
6189 | needed. | |
6190 | @c FIXME: for now no mention of directories, since this seems to be in | |
6191 | @c flux. 13mar1992 status is that in theory GDB would look either in | |
6192 | @c current dir or in same dir as myprog; but issues like competing | |
6193 | @c GDB's, or clutter in system dirs, mean that in practice right now | |
6194 | @c only current dir is used. FFish says maybe a special GDB hierarchy | |
6195 | @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol | |
6196 | @c files. | |
70b88761 | 6197 | |
e0dacfd1 | 6198 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6199 | @kindex core |
6200 | @kindex core-file | |
6201 | Specify the whereabouts of a core dump file to be used as the ``contents | |
6202 | of memory''. Traditionally, core files contain only some parts of the | |
6203 | address space of the process that generated them; _GDBN__ can access the | |
6204 | executable file itself for other parts. | |
6205 | ||
6206 | @code{core-file} with no argument specifies that no core file is | |
6207 | to be used. | |
6208 | ||
6209 | Note that the core file is ignored when your program is actually running | |
29a2b744 | 6210 | under _GDBN__. So, if you have been running your program and you wish to |
70b88761 RP |
6211 | debug a core file instead, you must kill the subprocess in which the |
6212 | program is running. To do this, use the @code{kill} command | |
1041a570 | 6213 | (@pxref{Kill Process, ,Killing the Child Process}). |
70b88761 RP |
6214 | |
6215 | @item load @var{filename} | |
6216 | @kindex load | |
6217 | _if__(_GENERIC__) | |
6218 | Depending on what remote debugging facilities are configured into | |
6219 | _GDBN__, the @code{load} command may be available. Where it exists, it | |
6220 | is meant to make @var{filename} (an executable) available for debugging | |
6221 | on the remote system---by downloading, or dynamic linking, for example. | |
6222 | @code{load} also records @var{filename}'s symbol table in _GDBN__, like | |
6223 | the @code{add-symbol-file} command. | |
6224 | ||
6225 | If @code{load} is not available on your _GDBN__, attempting to execute | |
6226 | it gets the error message ``@code{You can't do that when your target is | |
e251e767 | 6227 | @dots{}}'' |
70b88761 RP |
6228 | _fi__(_GENERIC__) |
6229 | ||
e251e767 | 6230 | _if__(_VXWORKS__) |
70b88761 RP |
6231 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
6232 | current target system as well as adding its symbols in _GDBN__. | |
6233 | _fi__(_VXWORKS__) | |
6234 | ||
6235 | _if__(_I960__) | |
6236 | @cindex download to Nindy-960 | |
6237 | With the Nindy interface to an Intel 960 board, @code{load} will | |
6238 | download @var{filename} to the 960 as well as adding its symbols in | |
e251e767 | 6239 | _GDBN__. |
70b88761 RP |
6240 | _fi__(_I960__) |
6241 | ||
c7cb8acb RP |
6242 | _if__(_H8__) |
6243 | @cindex download to H8/300 | |
6244 | @cindex H8/300 download | |
6245 | When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi | |
6246 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}), the | |
6247 | @code{load} command downloads your program to the H8/300 and also opens | |
6248 | it as the current executable target for _GDBN__ on your host (like the | |
6249 | @code{file} command). | |
6250 | _fi__(_H8__) | |
6251 | ||
70b88761 RP |
6252 | @code{load} will not repeat if you press @key{RET} again after using it. |
6253 | ||
6254 | @item add-symbol-file @var{filename} @var{address} | |
95d5ceb9 | 6255 | @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
70b88761 RP |
6256 | @kindex add-symbol-file |
6257 | @cindex dynamic linking | |
6258 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 6259 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
6260 | has been dynamically loaded (by some other means) into the program that |
6261 | is running. @var{address} should be the memory address at which the | |
6262 | file has been loaded; _GDBN__ cannot figure this out for itself. | |
6263 | ||
6264 | The symbol table of the file @var{filename} is added to the symbol table | |
6265 | originally read with the @code{symbol-file} command. You can use the | |
6266 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
6267 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 6268 | use the @code{symbol-file} command. |
70b88761 RP |
6269 | |
6270 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
6271 | ||
95d5ceb9 RP |
6272 | You can use the @samp{-mapped} and @samp{-readnow} options just as with |
6273 | the @code{symbol-file} command, to change how _GDBN__ manages the symbol | |
6274 | tabl einformation for @var{filename}. | |
6275 | ||
70b88761 RP |
6276 | @item info files |
6277 | @itemx info target | |
6278 | @kindex info files | |
6279 | @kindex info target | |
1041a570 RP |
6280 | @code{info files} and @code{info target} are synonymous; both print |
6281 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
6282 | including the names of the executable and core dump files currently in | |
6283 | use by _GDBN__, and the files from which symbols were loaded. The command | |
6284 | @code{help targets} lists all possible targets rather than current | |
6285 | ones. | |
70b88761 RP |
6286 | |
6287 | @end table | |
6288 | ||
6289 | All file-specifying commands allow both absolute and relative file names | |
6290 | as arguments. _GDBN__ always converts the file name to an absolute path | |
6291 | name and remembers it that way. | |
6292 | ||
70b88761 RP |
6293 | @cindex shared libraries |
6294 | ||
77b46d13 JG |
6295 | _GDBN__ supports SunOS, SVR4, and IBM RS/6000 shared libraries. |
6296 | _GDBN__ automatically loads symbol definitions from shared libraries | |
6297 | when you use the @code{run} command, or when you examine a core file. | |
6298 | (Before you issue the @code{run} command, _GDBN__ will not understand | |
6299 | references to a function in a shared library, however---unless you are | |
6300 | debugging a core file). | |
c338a2fd | 6301 | @c FIXME: next _GDBN__ release should permit some refs to undef |
1041a570 | 6302 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
6303 | |
6304 | @table @code | |
70b88761 RP |
6305 | @item info share |
6306 | @itemx info sharedlibrary | |
6307 | @kindex info sharedlibrary | |
6308 | @kindex info share | |
c338a2fd | 6309 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 6310 | |
c338a2fd RP |
6311 | @item sharedlibrary @var{regex} |
6312 | @itemx share @var{regex} | |
6313 | @kindex sharedlibrary | |
6314 | @kindex share | |
6315 | This is an obsolescent command; you can use it to explicitly | |
6316 | load shared object library symbols for files matching a UNIX regular | |
6317 | expression, but as with files loaded automatically, it will only load | |
6318 | shared libraries required by your program for a core file or after | |
6319 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
6320 | required by your program are loaded. | |
6321 | @end table | |
70b88761 RP |
6322 | |
6323 | @node Symbol Errors, , Files, _GDBN__ Files | |
6324 | @section Errors Reading Symbol Files | |
1041a570 RP |
6325 | |
6326 | While reading a symbol file, _GDBN__ will occasionally encounter problems, | |
6327 | such as symbol types it does not recognize, or known bugs in compiler | |
6328 | output. By default, _GDBN__ does not notify you of such problems, since | |
6329 | they are relatively common and primarily of interest to people | |
6330 | debugging compilers. If you are interested in seeing information | |
b80282d5 RP |
6331 | about ill-constructed symbol tables, you can either ask _GDBN__ to print |
6332 | only one message about each such type of problem, no matter how many | |
6333 | times the problem occurs; or you can ask _GDBN__ to print more messages, | |
1041a570 RP |
6334 | to see how many times the problems occur, with the @code{set |
6335 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
6336 | Messages}). | |
70b88761 RP |
6337 | |
6338 | The messages currently printed, and their meanings, are: | |
6339 | ||
6340 | @table @code | |
6341 | @item inner block not inside outer block in @var{symbol} | |
6342 | ||
6343 | The symbol information shows where symbol scopes begin and end | |
6344 | (such as at the start of a function or a block of statements). This | |
6345 | error indicates that an inner scope block is not fully contained | |
e251e767 | 6346 | in its outer scope blocks. |
70b88761 RP |
6347 | |
6348 | _GDBN__ circumvents the problem by treating the inner block as if it had | |
6349 | the same scope as the outer block. In the error message, @var{symbol} | |
6350 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
6351 | function. | |
6352 | ||
6353 | @item block at @var{address} out of order | |
6354 | ||
e251e767 | 6355 | The symbol information for symbol scope blocks should occur in |
70b88761 | 6356 | order of increasing addresses. This error indicates that it does not |
e251e767 | 6357 | do so. |
70b88761 RP |
6358 | |
6359 | _GDBN__ does not circumvent this problem, and will have trouble locating | |
6360 | symbols in the source file whose symbols being read. (You can often | |
6361 | determine what source file is affected by specifying @code{set verbose | |
29a2b744 | 6362 | on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.) |
70b88761 RP |
6363 | |
6364 | @item bad block start address patched | |
6365 | ||
6366 | The symbol information for a symbol scope block has a start address | |
6367 | smaller than the address of the preceding source line. This is known | |
e251e767 | 6368 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 RP |
6369 | |
6370 | _GDBN__ circumvents the problem by treating the symbol scope block as | |
6371 | starting on the previous source line. | |
6372 | ||
70b88761 RP |
6373 | @item bad string table offset in symbol @var{n} |
6374 | ||
6375 | @cindex foo | |
6376 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 6377 | larger than the size of the string table. |
70b88761 RP |
6378 | |
6379 | _GDBN__ circumvents the problem by considering the symbol to have the | |
6380 | name @code{foo}, which may cause other problems if many symbols end up | |
6381 | with this name. | |
6382 | ||
6383 | @item unknown symbol type @code{0x@var{nn}} | |
6384 | ||
6385 | The symbol information contains new data types that _GDBN__ does not yet | |
6386 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
e251e767 | 6387 | information, in hexadecimal. |
70b88761 RP |
6388 | |
6389 | _GDBN__ circumvents the error by ignoring this symbol information. This | |
29a2b744 | 6390 | will usually allow your program to be debugged, though certain symbols |
70b88761 RP |
6391 | will not be accessible. If you encounter such a problem and feel like |
6392 | debugging it, you can debug @code{_GDBP__} with itself, breakpoint on | |
6393 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
6394 | examine @code{*bufp} to see the symbol. | |
6395 | ||
6396 | @item stub type has NULL name | |
e251e767 | 6397 | _GDBN__ could not find the full definition for a struct or class. |
70b88761 | 6398 | |
440d9834 | 6399 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
6400 | |
6401 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
6402 | information that recent versions of the compiler should have output |
6403 | for it. | |
70b88761 | 6404 | |
440d9834 | 6405 | @item info mismatch between compiler and debugger |
70b88761 | 6406 | |
440d9834 | 6407 | _GDBN__ could not parse a type specification output by the compiler. |
70b88761 RP |
6408 | @end table |
6409 | ||
6410 | @node Targets, Controlling _GDBN__, _GDBN__ Files, Top | |
e251e767 | 6411 | @chapter Specifying a Debugging Target |
70b88761 RP |
6412 | @cindex debugging target |
6413 | @kindex target | |
1041a570 | 6414 | |
cedaf8bc | 6415 | A @dfn{target} is the execution environment occupied by your program. |
1041a570 RP |
6416 | Often, _GDBN__ runs in the same host environment as your program; in |
6417 | that case, the debugging target is specified as a side effect when you | |
6418 | use the @code{file} or @code{core} commands. When you need more | |
6419 | flexibility---for example, running _GDBN__ on a physically separate | |
6420 | host, or controlling a standalone system over a serial port or a | |
6421 | realtime system over a TCP/IP connection---you can use the @code{target} | |
6422 | command to specify one of the target types configured for _GDBN__ | |
6423 | (@pxref{Target Commands, ,Commands for Managing Targets}). | |
70b88761 RP |
6424 | |
6425 | @menu | |
b80282d5 RP |
6426 | * Active Targets:: Active Targets |
6427 | * Target Commands:: Commands for Managing Targets | |
6428 | * Remote:: Remote Debugging | |
70b88761 RP |
6429 | @end menu |
6430 | ||
6431 | @node Active Targets, Target Commands, Targets, Targets | |
6432 | @section Active Targets | |
6433 | @cindex stacking targets | |
6434 | @cindex active targets | |
6435 | @cindex multiple targets | |
6436 | ||
cedaf8bc RP |
6437 | There are three classes of targets: processes, core files, and |
6438 | executable files. _GDBN__ can work concurrently on up to three active | |
6439 | targets, one in each class. This allows you to (for example) start a | |
6440 | process and inspect its activity without abandoning your work on a core | |
6441 | file. | |
70b88761 | 6442 | |
cedaf8bc RP |
6443 | If, for example, you execute @samp{gdb a.out}, then the executable file |
6444 | @code{a.out} is the only active target. If you designate a core file as | |
6445 | well---presumably from a prior run that crashed and coredumped---then | |
6446 | _GDBN__ has two active targets and will use them in tandem, looking | |
6447 | first in the corefile target, then in the executable file, to satisfy | |
6448 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 6449 | are complementary, since core files contain only a program's |
cedaf8bc RP |
6450 | read-write memory---variables and so on---plus machine status, while |
6451 | executable files contain only the program text and initialized data.) | |
6452 | ||
6453 | When you type @code{run}, your executable file becomes an active process | |
6454 | target as well. When a process target is active, all _GDBN__ commands | |
6455 | requesting memory addresses refer to that target; addresses in an active | |
6456 | core file or executable file target are obscured while the process | |
6457 | target is active. | |
6458 | ||
1041a570 RP |
6459 | Use the @code{core-file} and @code{exec-file} commands to select a |
6460 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
6461 | Files}). To specify as a target a process that is already running, use | |
6462 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
6463 | Already-Running Process}.). | |
70b88761 RP |
6464 | |
6465 | @node Target Commands, Remote, Active Targets, Targets | |
6466 | @section Commands for Managing Targets | |
6467 | ||
6468 | @table @code | |
6469 | @item target @var{type} @var{parameters} | |
6470 | Connects the _GDBN__ host environment to a target machine or process. A | |
6471 | target is typically a protocol for talking to debugging facilities. You | |
6472 | use the argument @var{type} to specify the type or protocol of the | |
6473 | target machine. | |
6474 | ||
6475 | Further @var{parameters} are interpreted by the target protocol, but | |
6476 | typically include things like device names or host names to connect | |
e251e767 | 6477 | with, process numbers, and baud rates. |
70b88761 RP |
6478 | |
6479 | The @code{target} command will not repeat if you press @key{RET} again | |
6480 | after executing the command. | |
6481 | ||
6482 | @item help target | |
6483 | @kindex help target | |
6484 | Displays the names of all targets available. To display targets | |
6485 | currently selected, use either @code{info target} or @code{info files} | |
29a2b744 | 6486 | (@pxref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6487 | |
6488 | @item help target @var{name} | |
6489 | Describe a particular target, including any parameters necessary to | |
6490 | select it. | |
6491 | @end table | |
6492 | ||
c7cb8acb | 6493 | Here are some common targets (available, or not, depending on the GDB |
70b88761 RP |
6494 | configuration): |
6495 | ||
6496 | @table @code | |
6497 | @item target exec @var{prog} | |
6498 | @kindex target exec | |
6499 | An executable file. @samp{target exec @var{prog}} is the same as | |
6500 | @samp{exec-file @var{prog}}. | |
6501 | ||
6502 | @item target core @var{filename} | |
6503 | @kindex target core | |
6504 | A core dump file. @samp{target core @var{filename}} is the same as | |
6505 | @samp{core-file @var{filename}}. | |
6506 | ||
6507 | @item target remote @var{dev} | |
6508 | @kindex target remote | |
c7cb8acb | 6509 | Remote serial target in GDB-specific protocol. The argument @var{dev} |
70b88761 | 6510 | specifies what serial device to use for the connection (e.g. |
1041a570 | 6511 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. |
70b88761 RP |
6512 | |
6513 | _if__(_AMD29K__) | |
6514 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
6515 | @kindex target amd-eb | |
6516 | @cindex AMD EB29K | |
6517 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6518 | @var{dev} is the serial device, as for @code{target remote}; | |
6519 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6520 | name of the program to be debugged, as it appears to DOS on the PC. | |
1041a570 | 6521 | @xref{EB29K Remote, ,GDB with a Remote EB29K}. |
70b88761 RP |
6522 | |
6523 | _fi__(_AMD29K__) | |
c7cb8acb RP |
6524 | _if__(_H8__) |
6525 | @item target hms | |
6526 | @kindex target hms | |
6527 | A Hitachi H8/300 board, attached via serial line to your host. Use | |
6528 | special commands @code{device} and @code{speed} to control the serial | |
6529 | line and the communications speed used. @xref{Hitachi H8/300 | |
6530 | Remote,,_GDBN__ and the Hitachi H8/300}. | |
6531 | ||
6532 | _fi__(_H8__) | |
70b88761 RP |
6533 | _if__(_I960__) |
6534 | @item target nindy @var{devicename} | |
6535 | @kindex target nindy | |
6536 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6537 | the name of the serial device to use for the connection, e.g. | |
1041a570 | 6538 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}. |
70b88761 RP |
6539 | |
6540 | _fi__(_I960__) | |
6541 | _if__(_VXWORKS__) | |
6542 | @item target vxworks @var{machinename} | |
6543 | @kindex target vxworks | |
6544 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6545 | is the target system's machine name or IP address. | |
1041a570 | 6546 | @xref{VxWorks Remote, ,_GDBN__ and VxWorks}. |
70b88761 RP |
6547 | _fi__(_VXWORKS__) |
6548 | @end table | |
6549 | ||
6550 | _if__(_GENERIC__) | |
6551 | Different targets are available on different configurations of _GDBN__; your | |
6552 | configuration may have more or fewer targets. | |
6553 | _fi__(_GENERIC__) | |
6554 | ||
6555 | @node Remote, , Target Commands, Targets | |
6556 | @section Remote Debugging | |
6557 | @cindex remote debugging | |
6558 | ||
29a2b744 | 6559 | If you are trying to debug a program running on a machine that cannot run |
c7cb8acb | 6560 | GDB in the usual way, it is often useful to use remote debugging. For |
70b88761 RP |
6561 | example, you might use remote debugging on an operating system kernel, or on |
6562 | a small system which does not have a general purpose operating system | |
e251e767 | 6563 | powerful enough to run a full-featured debugger. |
70b88761 | 6564 | |
c7cb8acb | 6565 | Some configurations of GDB have special serial or TCP/IP interfaces |
70b88761 | 6566 | to make this work with particular debugging targets. In addition, |
c7cb8acb | 6567 | GDB comes with a generic serial protocol (specific to GDB, but |
70b88761 RP |
6568 | not specific to any particular target system) which you can use if you |
6569 | write the remote stubs---the code that will run on the remote system to | |
c7cb8acb | 6570 | communicate with GDB. |
70b88761 | 6571 | |
c7cb8acb | 6572 | To use the GDB remote serial protocol, the program to be debugged on |
70b88761 | 6573 | the remote machine needs to contain a debugging stub which talks to |
c7cb8acb RP |
6574 | GDB over the serial line. Several working remote stubs are |
6575 | distributed with GDB; see the @file{README} file in the GDB | |
70b88761 RP |
6576 | distribution for more information. |
6577 | ||
6578 | For details of this communication protocol, see the comments in the | |
c7cb8acb | 6579 | GDB source file @file{remote.c}. |
70b88761 | 6580 | |
c7cb8acb RP |
6581 | To start remote debugging, first run GDB and specify as an executable file |
6582 | the program that is running in the remote machine. This tells GDB how | |
29a2b744 | 6583 | to find your program's symbols and the contents of its pure text. Then |
70b88761 RP |
6584 | establish communication using the @code{target remote} command with a device |
6585 | name as an argument. For example: | |
6586 | ||
6587 | @example | |
6588 | target remote /dev/ttyb | |
6589 | @end example | |
6590 | ||
6591 | @noindent | |
6592 | if the serial line is connected to the device named @file{/dev/ttyb}. This | |
6593 | will stop the remote machine if it is not already stopped. | |
6594 | ||
6595 | Now you can use all the usual commands to examine and change data and to | |
6596 | step and continue the remote program. | |
6597 | ||
6598 | To resume the remote program and stop debugging it, use the @code{detach} | |
6599 | command. | |
6600 | ||
d8a68b28 JG |
6601 | @kindex set remotedebug |
6602 | @kindex show remotedebug | |
6a8cb0e7 RP |
6603 | @cindex packets, reporting on stdout |
6604 | @cindex serial connections, debugging | |
6605 | If you have trouble with the serial connection, you can use the command | |
6606 | @code{set remotedebug}. This makes _GDBN__ report on all packets sent | |
6607 | back and forth across the serial line to the remote machine. The | |
6608 | packet-debugging information is printed on the _GDBN__ standard output | |
6609 | stream. @code{set remotedebug off} turns it off, and @code{show | |
6610 | remotedebug} will show you its current state. | |
d8a68b28 | 6611 | |
70b88761 | 6612 | Other remote targets may be available in your |
c7cb8acb | 6613 | configuration of GDB; use @code{help targets} to list them. |
70b88761 RP |
6614 | |
6615 | _if__(_GENERIC__) | |
1041a570 RP |
6616 | _dnl__ Text on starting up GDB in various specific cases; it goes up front |
6617 | _dnl__ in manuals configured for any of those particular situations, here | |
6618 | _dnl__ otherwise. | |
6619 | @menu | |
6620 | _include__(gdbinv-m.m4)<>_dnl__ | |
6621 | @end menu | |
70b88761 RP |
6622 | _include__(gdbinv-s.m4) |
6623 | _fi__(_GENERIC__) | |
6624 | ||
6625 | @node Controlling _GDBN__, Sequences, Targets, Top | |
6626 | @chapter Controlling _GDBN__ | |
6627 | ||
6628 | You can alter many aspects of _GDBN__'s interaction with you by using | |
6629 | the @code{set} command. For commands controlling how _GDBN__ displays | |
1041a570 | 6630 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. |
70b88761 RP |
6631 | |
6632 | @menu | |
b80282d5 RP |
6633 | * Prompt:: Prompt |
6634 | * Editing:: Command Editing | |
6635 | * History:: Command History | |
6636 | * Screen Size:: Screen Size | |
6637 | * Numbers:: Numbers | |
6638 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
6639 | @end menu |
6640 | ||
6641 | @node Prompt, Editing, Controlling _GDBN__, Controlling _GDBN__ | |
6642 | @section Prompt | |
6643 | @cindex prompt | |
1041a570 | 6644 | |
70b88761 RP |
6645 | _GDBN__ indicates its readiness to read a command by printing a string |
6646 | called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You | |
6647 | can change the prompt string with the @code{set prompt} command. For | |
6648 | instance, when debugging _GDBN__ with _GDBN__, it is useful to change | |
6649 | the prompt in one of the _GDBN__<>s so that you can always tell which | |
6650 | one you are talking to. | |
6651 | ||
6652 | @table @code | |
6653 | @item set prompt @var{newprompt} | |
6654 | @kindex set prompt | |
6655 | Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth. | |
6656 | @kindex show prompt | |
6657 | @item show prompt | |
6658 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6659 | @end table | |
6660 | ||
6661 | @node Editing, History, Prompt, Controlling _GDBN__ | |
6662 | @section Command Editing | |
6663 | @cindex readline | |
6664 | @cindex command line editing | |
1041a570 | 6665 | |
70b88761 RP |
6666 | _GDBN__ reads its input commands via the @dfn{readline} interface. This |
6667 | GNU library provides consistent behavior for programs which provide a | |
6668 | command line interface to the user. Advantages are @code{emacs}-style | |
6669 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6670 | substitution, and a storage and recall of command history across | |
6671 | debugging sessions. | |
6672 | ||
6673 | You may control the behavior of command line editing in _GDBN__ with the | |
e251e767 | 6674 | command @code{set}. |
70b88761 RP |
6675 | |
6676 | @table @code | |
6677 | @kindex set editing | |
6678 | @cindex editing | |
6679 | @item set editing | |
6680 | @itemx set editing on | |
6681 | Enable command line editing (enabled by default). | |
6682 | ||
6683 | @item set editing off | |
6684 | Disable command line editing. | |
6685 | ||
6686 | @kindex show editing | |
6687 | @item show editing | |
6688 | Show whether command line editing is enabled. | |
6689 | @end table | |
6690 | ||
6691 | @node History, Screen Size, Editing, Controlling _GDBN__ | |
6692 | @section Command History | |
1041a570 | 6693 | |
70b88761 RP |
6694 | @table @code |
6695 | @cindex history substitution | |
6696 | @cindex history file | |
6697 | @kindex set history filename | |
6698 | @item set history filename @var{fname} | |
6699 | Set the name of the _GDBN__ command history file to @var{fname}. This is | |
6700 | the file from which _GDBN__ will read an initial command history | |
6701 | list or to which it will write this list when it exits. This list is | |
6702 | accessed through history expansion or through the history | |
6703 | command editing characters listed below. This file defaults to the | |
6704 | value of the environment variable @code{GDBHISTFILE}, or to | |
6705 | @file{./.gdb_history} if this variable is not set. | |
6706 | ||
6707 | @cindex history save | |
6708 | @kindex set history save | |
6709 | @item set history save | |
6710 | @itemx set history save on | |
6711 | Record command history in a file, whose name may be specified with the | |
6712 | @code{set history filename} command. By default, this option is disabled. | |
6713 | ||
6714 | @item set history save off | |
6715 | Stop recording command history in a file. | |
6716 | ||
6717 | @cindex history size | |
6718 | @kindex set history size | |
6719 | @item set history size @var{size} | |
6720 | Set the number of commands which _GDBN__ will keep in its history list. | |
6721 | This defaults to the value of the environment variable | |
6722 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6723 | @end table | |
6724 | ||
6725 | @cindex history expansion | |
6726 | History expansion assigns special meaning to the character @kbd{!}. | |
6727 | @iftex | |
1041a570 | 6728 | @xref{Event Designators}. |
70b88761 RP |
6729 | @end iftex |
6730 | Since @kbd{!} is also the logical not operator in C, history expansion | |
6731 | is off by default. If you decide to enable history expansion with the | |
6732 | @code{set history expansion on} command, you may sometimes need to | |
6733 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
6734 | a space or a tab to prevent it from being expanded. The readline | |
6735 | history facilities will not attempt substitution on the strings | |
6736 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
6737 | ||
6738 | The commands to control history expansion are: | |
6739 | ||
6740 | @table @code | |
6741 | ||
6742 | @kindex set history expansion | |
6743 | @item set history expansion on | |
6744 | @itemx set history expansion | |
6745 | Enable history expansion. History expansion is off by default. | |
6746 | ||
6747 | @item set history expansion off | |
6748 | Disable history expansion. | |
6749 | ||
6750 | The readline code comes with more complete documentation of | |
6751 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 6752 | or @code{vi} may wish to read it. |
70b88761 RP |
6753 | @iftex |
6754 | @xref{Command Line Editing}. | |
6755 | @end iftex | |
6756 | ||
6757 | @c @group | |
6758 | @kindex show history | |
6759 | @item show history | |
6760 | @itemx show history filename | |
6761 | @itemx show history save | |
6762 | @itemx show history size | |
6763 | @itemx show history expansion | |
6764 | These commands display the state of the _GDBN__ history parameters. | |
6765 | @code{show history} by itself displays all four states. | |
6766 | @c @end group | |
70b88761 RP |
6767 | @end table |
6768 | ||
6769 | @table @code | |
6770 | @kindex show commands | |
6771 | @item show commands | |
6772 | Display the last ten commands in the command history. | |
6773 | ||
6774 | @item show commands @var{n} | |
6775 | Print ten commands centered on command number @var{n}. | |
6776 | ||
6777 | @item show commands + | |
6778 | Print ten commands just after the commands last printed. | |
70b88761 RP |
6779 | @end table |
6780 | ||
6781 | @node Screen Size, Numbers, History, Controlling _GDBN__ | |
6782 | @section Screen Size | |
6783 | @cindex size of screen | |
6784 | @cindex pauses in output | |
1041a570 | 6785 | |
70b88761 RP |
6786 | Certain commands to _GDBN__ may produce large amounts of information |
6787 | output to the screen. To help you read all of it, _GDBN__ pauses and | |
6788 | asks you for input at the end of each page of output. Type @key{RET} | |
6789 | when you want to continue the output. _GDBN__ also uses the screen | |
6790 | width setting to determine when to wrap lines of output. Depending on | |
6791 | what is being printed, it tries to break the line at a readable place, | |
6792 | rather than simply letting it overflow onto the following line. | |
6793 | ||
6794 | Normally _GDBN__ knows the size of the screen from the termcap data base | |
6795 | together with the value of the @code{TERM} environment variable and the | |
6796 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
6797 | you can override it with the @code{set height} and @code{set | |
6798 | width} commands: | |
6799 | ||
6800 | @table @code | |
6801 | @item set height @var{lpp} | |
6802 | @itemx show height | |
6803 | @itemx set width @var{cpl} | |
6804 | @itemx show width | |
6805 | @kindex set height | |
6806 | @kindex set width | |
6807 | @kindex show width | |
6808 | @kindex show height | |
6809 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
6810 | a screen width of @var{cpl} characters. The associated @code{show} | |
6811 | commands display the current settings. | |
6812 | ||
6813 | If you specify a height of zero lines, _GDBN__ will not pause during output | |
6814 | no matter how long the output is. This is useful if output is to a file | |
6815 | or to an editor buffer. | |
6816 | @end table | |
6817 | ||
6818 | @node Numbers, Messages/Warnings, Screen Size, Controlling _GDBN__ | |
6819 | @section Numbers | |
6820 | @cindex number representation | |
6821 | @cindex entering numbers | |
1041a570 | 6822 | |
70b88761 RP |
6823 | You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by |
6824 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
6825 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
6826 | Numbers that begin with none of these are, by default, entered in base | |
6827 | 10; likewise, the default display for numbers---when no particular | |
6828 | format is specified---is base 10. You can change the default base for | |
6829 | both input and output with the @code{set radix} command. | |
6830 | ||
6831 | @table @code | |
6832 | @kindex set radix | |
6833 | @item set radix @var{base} | |
6834 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 6835 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
6836 | specified either unambiguously or using the current default radix; for |
6837 | example, any of | |
6838 | ||
6839 | @example | |
c2bbbb22 | 6840 | set radix 1010 |
70b88761 RP |
6841 | set radix 012 |
6842 | set radix 10. | |
6843 | set radix 0xa | |
6844 | @end example | |
6845 | ||
6846 | @noindent | |
6847 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
6848 | will leave the radix unchanged no matter what it was. | |
6849 | ||
6850 | @kindex show radix | |
6851 | @item show radix | |
6852 | Display the current default base for numeric input and display. | |
70b88761 RP |
6853 | @end table |
6854 | ||
c2bbbb22 | 6855 | @node Messages/Warnings, , Numbers, Controlling _GDBN__ |
70b88761 | 6856 | @section Optional Warnings and Messages |
1041a570 | 6857 | |
70b88761 RP |
6858 | By default, _GDBN__ is silent about its inner workings. If you are running |
6859 | on a slow machine, you may want to use the @code{set verbose} command. | |
6860 | It will make _GDBN__ tell you when it does a lengthy internal operation, so | |
1041a570 | 6861 | you will not think it has crashed. |
70b88761 | 6862 | |
1041a570 RP |
6863 | Currently, the messages controlled by @code{set verbose} are those |
6864 | which announce that the symbol table for a source file is being read | |
6865 | (@pxref{Files, ,Commands to Specify Files}, in the description of the | |
6866 | command @code{symbol-file}). | |
29a2b744 | 6867 | @c The following is the right way to do it, but emacs 18.55 does not support |
70b88761 | 6868 | @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo |
e251e767 | 6869 | @c is released. |
70b88761 | 6870 | @ignore |
29a2b744 | 6871 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6872 | @end ignore |
6873 | ||
6874 | @table @code | |
6875 | @kindex set verbose | |
6876 | @item set verbose on | |
6877 | Enables _GDBN__'s output of certain informational messages. | |
6878 | ||
6879 | @item set verbose off | |
6880 | Disables _GDBN__'s output of certain informational messages. | |
6881 | ||
6882 | @kindex show verbose | |
6883 | @item show verbose | |
6884 | Displays whether @code{set verbose} is on or off. | |
6885 | @end table | |
6886 | ||
b80282d5 RP |
6887 | By default, if _GDBN__ encounters bugs in the symbol table of an object |
6888 | file, it is silent; but if you are debugging a compiler, you may find | |
1041a570 | 6889 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). |
70b88761 RP |
6890 | |
6891 | @table @code | |
6892 | @kindex set complaints | |
6893 | @item set complaints @var{limit} | |
6894 | Permits _GDBN__ to output @var{limit} complaints about each type of unusual | |
6895 | symbols before becoming silent about the problem. Set @var{limit} to | |
6896 | zero to suppress all complaints; set it to a large number to prevent | |
6897 | complaints from being suppressed. | |
6898 | ||
6899 | @kindex show complaints | |
6900 | @item show complaints | |
6901 | Displays how many symbol complaints _GDBN__ is permitted to produce. | |
6902 | @end table | |
6903 | ||
6904 | By default, _GDBN__ is cautious, and asks what sometimes seem to be a | |
6905 | lot of stupid questions to confirm certain commands. For example, if | |
6906 | you try to run a program which is already running: | |
1041a570 | 6907 | |
70b88761 RP |
6908 | @example |
6909 | (_GDBP__) run | |
6910 | The program being debugged has been started already. | |
e251e767 | 6911 | Start it from the beginning? (y or n) |
70b88761 RP |
6912 | @end example |
6913 | ||
29a2b744 | 6914 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
6915 | commands, you can disable this ``feature'': |
6916 | ||
6917 | @table @code | |
6918 | @kindex set confirm | |
6919 | @cindex flinching | |
6920 | @cindex confirmation | |
6921 | @cindex stupid questions | |
6922 | @item set confirm off | |
6923 | Disables confirmation requests. | |
6924 | ||
6925 | @item set confirm on | |
6926 | Enables confirmation requests (the default). | |
6927 | ||
6928 | @item show confirm | |
6929 | @kindex show confirm | |
6930 | Displays state of confirmation requests. | |
6931 | @end table | |
6932 | ||
29a2b744 | 6933 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
6934 | @cindex reloading symbols |
6935 | Some systems allow individual object files that make up your program to | |
6936 | be replaced without stopping and restarting your program. | |
6937 | _if__(_VXWORKS__) | |
6938 | For example, in VxWorks you can simply recompile a defective object file | |
6939 | and keep on running. | |
6940 | _fi__(_VXWORKS__) | |
29a2b744 | 6941 | If you are running on one of these systems, you can allow _GDBN__ to |
1041a570 RP |
6942 | reload the symbols for automatically relinked modules: |
6943 | ||
b80282d5 RP |
6944 | @table @code |
6945 | @kindex set symbol-reloading | |
6946 | @item set symbol-reloading on | |
6947 | Replace symbol definitions for the corresponding source file when an | |
6948 | object file with a particular name is seen again. | |
6949 | ||
6950 | @item set symbol-reloading off | |
1041a570 | 6951 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 6952 | the same name. This is the default state; if you are not running on a |
b80282d5 RP |
6953 | system that permits automatically relinking modules, you should leave |
6954 | @code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols | |
6955 | when linking large programs, that may contain several modules (from | |
6956 | different directories or libraries) with the same name. | |
6957 | ||
6958 | @item show symbol-reloading | |
6959 | Show the current @code{on} or @code{off} setting. | |
6960 | @end table | |
6961 | ||
70b88761 RP |
6962 | @node Sequences, Emacs, Controlling _GDBN__, Top |
6963 | @chapter Canned Sequences of Commands | |
6964 | ||
29a2b744 | 6965 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
1041a570 RP |
6966 | Command Lists}), _GDBN__ provides two ways to store sequences of commands |
6967 | for execution as a unit: user-defined commands and command files. | |
70b88761 RP |
6968 | |
6969 | @menu | |
b80282d5 RP |
6970 | * Define:: User-Defined Commands |
6971 | * Command Files:: Command Files | |
6972 | * Output:: Commands for Controlled Output | |
70b88761 RP |
6973 | @end menu |
6974 | ||
6975 | @node Define, Command Files, Sequences, Sequences | |
6976 | @section User-Defined Commands | |
6977 | ||
6978 | @cindex user-defined command | |
6979 | A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you | |
6980 | assign a new name as a command. This is done with the @code{define} | |
6981 | command. | |
6982 | ||
6983 | @table @code | |
6984 | @item define @var{commandname} | |
6985 | @kindex define | |
6986 | Define a command named @var{commandname}. If there is already a command | |
6987 | by that name, you are asked to confirm that you want to redefine it. | |
6988 | ||
6989 | The definition of the command is made up of other _GDBN__ command lines, | |
6990 | which are given following the @code{define} command. The end of these | |
6991 | commands is marked by a line containing @code{end}. | |
6992 | ||
6993 | @item document @var{commandname} | |
6994 | @kindex document | |
6995 | Give documentation to the user-defined command @var{commandname}. The | |
6996 | command @var{commandname} must already be defined. This command reads | |
6997 | lines of documentation just as @code{define} reads the lines of the | |
6998 | command definition, ending with @code{end}. After the @code{document} | |
6999 | command is finished, @code{help} on command @var{commandname} will print | |
7000 | the documentation you have specified. | |
7001 | ||
7002 | You may use the @code{document} command again to change the | |
7003 | documentation of a command. Redefining the command with @code{define} | |
7004 | does not change the documentation. | |
7005 | ||
7006 | @item help user-defined | |
7007 | @kindex help user-defined | |
7008 | List all user-defined commands, with the first line of the documentation | |
7009 | (if any) for each. | |
7010 | ||
4768ba62 JG |
7011 | @item show user |
7012 | @itemx show user @var{commandname} | |
7013 | @kindex show user | |
70b88761 RP |
7014 | Display the _GDBN__ commands used to define @var{commandname} (but not its |
7015 | documentation). If no @var{commandname} is given, display the | |
7016 | definitions for all user-defined commands. | |
7017 | @end table | |
7018 | ||
7019 | User-defined commands do not take arguments. When they are executed, the | |
7020 | commands of the definition are not printed. An error in any command | |
7021 | stops execution of the user-defined command. | |
7022 | ||
7023 | Commands that would ask for confirmation if used interactively proceed | |
7024 | without asking when used inside a user-defined command. Many _GDBN__ commands | |
7025 | that normally print messages to say what they are doing omit the messages | |
7026 | when used in a user-defined command. | |
7027 | ||
7028 | @node Command Files, Output, Define, Sequences | |
7029 | @section Command Files | |
7030 | ||
7031 | @cindex command files | |
7032 | A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments | |
7033 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
7034 | command file does nothing; it does not mean to repeat the last command, as | |
7035 | it would from the terminal. | |
7036 | ||
7037 | @cindex init file | |
7038 | @cindex @file{_GDBINIT__} | |
7039 | When you start _GDBN__, it automatically executes commands from its | |
1041a570 RP |
7040 | @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads |
7041 | the init file (if any) in your home directory and then the init file | |
7042 | (if any) in the current working directory. (The init files are not | |
7043 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
7044 | ,Choosing Modes}.) You can also request the execution of a command | |
7045 | file with the @code{source} command: | |
70b88761 RP |
7046 | |
7047 | @table @code | |
7048 | @item source @var{filename} | |
7049 | @kindex source | |
7050 | Execute the command file @var{filename}. | |
7051 | @end table | |
7052 | ||
7053 | The lines in a command file are executed sequentially. They are not | |
7054 | printed as they are executed. An error in any command terminates execution | |
7055 | of the command file. | |
7056 | ||
7057 | Commands that would ask for confirmation if used interactively proceed | |
7058 | without asking when used in a command file. Many _GDBN__ commands that | |
7059 | normally print messages to say what they are doing omit the messages | |
7060 | when called from command files. | |
7061 | ||
7062 | @node Output, , Command Files, Sequences | |
7063 | @section Commands for Controlled Output | |
7064 | ||
7065 | During the execution of a command file or a user-defined command, normal | |
7066 | _GDBN__ output is suppressed; the only output that appears is what is | |
7067 | explicitly printed by the commands in the definition. This section | |
7068 | describes three commands useful for generating exactly the output you | |
7069 | want. | |
7070 | ||
7071 | @table @code | |
7072 | @item echo @var{text} | |
7073 | @kindex echo | |
29a2b744 RP |
7074 | @c I do not consider backslash-space a standard C escape sequence |
7075 | @c because it is not in ANSI. | |
1041a570 RP |
7076 | Print @var{text}. Nonprinting characters can be included in |
7077 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
7078 | newline. @strong{No newline will be printed unless you specify one.} | |
7079 | In addition to the standard C escape sequences, a backslash followed | |
7080 | by a space stands for a space. This is useful for outputting a | |
7081 | string with spaces at the beginning or the end, since leading and | |
7082 | trailing spaces are otherwise trimmed from all arguments. | |
7083 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
7084 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
7085 | |
7086 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7087 | the command onto subsequent lines. For example, | |
7088 | ||
7089 | @example | |
7090 | echo This is some text\n\ | |
7091 | which is continued\n\ | |
7092 | onto several lines.\n | |
7093 | @end example | |
7094 | ||
7095 | produces the same output as | |
7096 | ||
7097 | @example | |
7098 | echo This is some text\n | |
7099 | echo which is continued\n | |
7100 | echo onto several lines.\n | |
7101 | @end example | |
7102 | ||
7103 | @item output @var{expression} | |
7104 | @kindex output | |
7105 | Print the value of @var{expression} and nothing but that value: no | |
7106 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 7107 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 7108 | expressions. |
70b88761 RP |
7109 | |
7110 | @item output/@var{fmt} @var{expression} | |
7111 | Print the value of @var{expression} in format @var{fmt}. You can use | |
7112 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
7113 | information. | |
7114 | ||
7115 | @item printf @var{string}, @var{expressions}@dots{} | |
7116 | @kindex printf | |
7117 | Print the values of the @var{expressions} under the control of | |
7118 | @var{string}. The @var{expressions} are separated by commas and may | |
7119 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 7120 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
7121 | |
7122 | @example | |
7123 | printf (@var{string}, @var{expressions}@dots{}); | |
7124 | @end example | |
7125 | ||
7126 | For example, you can print two values in hex like this: | |
7127 | ||
0fd24984 | 7128 | @smallexample |
70b88761 | 7129 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo |
0fd24984 | 7130 | @end smallexample |
70b88761 RP |
7131 | |
7132 | The only backslash-escape sequences that you can use in the format | |
7133 | string are the simple ones that consist of backslash followed by a | |
7134 | letter. | |
7135 | @end table | |
7136 | ||
6ca72cc6 RP |
7137 | _if__(_LUCID__) |
7138 | @node Emacs, Energize, Sequences, Top | |
7139 | _fi__(_LUCID__) | |
7140 | _if__(!_LUCID__) | |
70b88761 | 7141 | @node Emacs, _GDBN__ Bugs, Sequences, Top |
6ca72cc6 | 7142 | _fi__(!_LUCID__) |
70b88761 RP |
7143 | @chapter Using _GDBN__ under GNU Emacs |
7144 | ||
7145 | @cindex emacs | |
7146 | A special interface allows you to use GNU Emacs to view (and | |
7147 | edit) the source files for the program you are debugging with | |
7148 | _GDBN__. | |
7149 | ||
7150 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
7151 | executable file you want to debug as an argument. This command starts | |
7152 | _GDBN__ as a subprocess of Emacs, with input and output through a newly | |
7153 | created Emacs buffer. | |
7154 | ||
7155 | Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two | |
7156 | things: | |
7157 | ||
7158 | @itemize @bullet | |
7159 | @item | |
e251e767 | 7160 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
7161 | @end itemize |
7162 | ||
7163 | This applies both to _GDBN__ commands and their output, and to the input | |
7164 | and output done by the program you are debugging. | |
7165 | ||
7166 | This is useful because it means that you can copy the text of previous | |
7167 | commands and input them again; you can even use parts of the output | |
7168 | in this way. | |
7169 | ||
3d3ab540 RP |
7170 | All the facilities of Emacs' Shell mode are available for interacting |
7171 | with your program. In particular, you can send signals the usual | |
7172 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
7173 | stop. | |
70b88761 RP |
7174 | |
7175 | @itemize @bullet | |
7176 | @item | |
e251e767 | 7177 | _GDBN__ displays source code through Emacs. |
70b88761 RP |
7178 | @end itemize |
7179 | ||
7180 | Each time _GDBN__ displays a stack frame, Emacs automatically finds the | |
7181 | source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the | |
7182 | left margin of the current line. Emacs uses a separate buffer for | |
7183 | source display, and splits the window to show both your _GDBN__ session | |
7184 | and the source. | |
7185 | ||
7186 | Explicit _GDBN__ @code{list} or search commands still produce output as | |
7187 | usual, but you probably will have no reason to use them. | |
7188 | ||
7189 | @quotation | |
7190 | @emph{Warning:} If the directory where your program resides is not your | |
7191 | current directory, it can be easy to confuse Emacs about the location of | |
7192 | the source files, in which case the auxiliary display buffer will not | |
7193 | appear to show your source. _GDBN__ can find programs by searching your | |
7194 | environment's @code{PATH} variable, so the _GDBN__ input and output | |
29a2b744 | 7195 | session will proceed normally; but Emacs does not get enough information |
70b88761 RP |
7196 | back from _GDBN__ to locate the source files in this situation. To |
7197 | avoid this problem, either start _GDBN__ mode from the directory where | |
7198 | your program resides, or specify a full path name when prompted for the | |
7199 | @kbd{M-x gdb} argument. | |
7200 | ||
7201 | A similar confusion can result if you use the _GDBN__ @code{file} command to | |
7202 | switch to debugging a program in some other location, from an existing | |
7203 | _GDBN__ buffer in Emacs. | |
7204 | @end quotation | |
7205 | ||
7206 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
7207 | you need to call _GDBN__ by a different name (for example, if you keep | |
7208 | several configurations around, with different names) you can set the | |
7209 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 7210 | |
70b88761 RP |
7211 | @example |
7212 | (setq gdb-command-name "mygdb") | |
7213 | @end example | |
1041a570 | 7214 | |
70b88761 RP |
7215 | @noindent |
7216 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
7217 | in your @file{.emacs} file) will make Emacs call the program named | |
7218 | ``@code{mygdb}'' instead. | |
7219 | ||
7220 | In the _GDBN__ I/O buffer, you can use these special Emacs commands in | |
7221 | addition to the standard Shell mode commands: | |
7222 | ||
7223 | @table @kbd | |
7224 | @item C-h m | |
7225 | Describe the features of Emacs' _GDBN__ Mode. | |
7226 | ||
7227 | @item M-s | |
7228 | Execute to another source line, like the _GDBN__ @code{step} command; also | |
7229 | update the display window to show the current file and location. | |
7230 | ||
7231 | @item M-n | |
7232 | Execute to next source line in this function, skipping all function | |
7233 | calls, like the _GDBN__ @code{next} command. Then update the display window | |
7234 | to show the current file and location. | |
7235 | ||
7236 | @item M-i | |
7237 | Execute one instruction, like the _GDBN__ @code{stepi} command; update | |
7238 | display window accordingly. | |
7239 | ||
7240 | @item M-x gdb-nexti | |
7241 | Execute to next instruction, using the _GDBN__ @code{nexti} command; update | |
7242 | display window accordingly. | |
7243 | ||
7244 | @item C-c C-f | |
7245 | Execute until exit from the selected stack frame, like the _GDBN__ | |
7246 | @code{finish} command. | |
7247 | ||
7248 | @item M-c | |
29a2b744 | 7249 | Continue execution of your program, like the _GDBN__ @code{continue} |
1041a570 | 7250 | command. |
203eea5d RP |
7251 | |
7252 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
7253 | |
7254 | @item M-u | |
7255 | Go up the number of frames indicated by the numeric argument | |
7256 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
1041a570 | 7257 | like the _GDBN__ @code{up} command. |
203eea5d | 7258 | |
1041a570 | 7259 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
7260 | |
7261 | @item M-d | |
7262 | Go down the number of frames indicated by the numeric argument, like the | |
1041a570 | 7263 | _GDBN__ @code{down} command. |
203eea5d RP |
7264 | |
7265 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
7266 | |
7267 | @item C-x & | |
7268 | Read the number where the cursor is positioned, and insert it at the end | |
7269 | of the _GDBN__ I/O buffer. For example, if you wish to disassemble code | |
7270 | around an address that was displayed earlier, type @kbd{disassemble}; | |
7271 | then move the cursor to the address display, and pick up the | |
e251e767 | 7272 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 RP |
7273 | |
7274 | You can customize this further on the fly by defining elements of the list | |
7275 | @code{gdb-print-command}; once it is defined, you can format or | |
7276 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 7277 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
7278 | wish special formatting, and act as an index to pick an element of the |
7279 | list. If the list element is a string, the number to be inserted is | |
7280 | formatted using the Emacs function @code{format}; otherwise the number | |
7281 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
7282 | @end table |
7283 | ||
7284 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
7285 | tells _GDBN__ to set a breakpoint on the source line point is on. | |
7286 | ||
7287 | If you accidentally delete the source-display buffer, an easy way to get | |
7288 | it back is to type the command @code{f} in the _GDBN__ buffer, to | |
7289 | request a frame display; when you run under Emacs, this will recreate | |
7290 | the source buffer if necessary to show you the context of the current | |
7291 | frame. | |
7292 | ||
7293 | The source files displayed in Emacs are in ordinary Emacs buffers | |
7294 | which are visiting the source files in the usual way. You can edit | |
7295 | the files with these buffers if you wish; but keep in mind that _GDBN__ | |
7296 | communicates with Emacs in terms of line numbers. If you add or | |
7297 | delete lines from the text, the line numbers that _GDBN__ knows will cease | |
7298 | to correspond properly to the code. | |
7299 | ||
7300 | @c The following dropped because Epoch is nonstandard. Reactivate | |
7301 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
7302 | @ignore | |
e251e767 | 7303 | @kindex emacs epoch environment |
70b88761 RP |
7304 | @kindex epoch |
7305 | @kindex inspect | |
7306 | ||
7307 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
7308 | environment. Users of this environment can use a new command, | |
7309 | @code{inspect} which performs identically to @code{print} except that | |
7310 | each value is printed in its own window. | |
7311 | @end ignore | |
7312 | ||
6ca72cc6 RP |
7313 | _if__(_LUCID__) |
7314 | @node Energize, _GDBN__ Bugs, Emacs, Top | |
7315 | @chapter Using _GDBN__ with Energize | |
7316 | ||
7317 | @cindex Energize | |
7318 | The Energize Programming System is an integrated development environment | |
7319 | that includes a point-and-click interface to many programming tools. | |
7320 | When you use _GDBN__ in this environment, you can use the standard | |
7321 | Energize graphical interface to drive _GDBN__; you can also, if you | |
7322 | choose, type _GDBN__ commands as usual in a debugging window. Even if | |
7323 | you use the graphical interface, the debugging window (which uses Emacs, | |
7324 | and resembles the standard Emacs interface to _GDBN__) displays the | |
7325 | equivalent commands, so that the history of your debugging session is | |
7326 | properly reflected. | |
7327 | ||
7328 | When Energize starts up a _GDBN__ session, it uses one of the | |
7329 | command-line options @samp{-energize} or @samp{-cadillac} (``cadillac'' | |
7330 | is the name of the communications protocol used by the Energize system). | |
7331 | This option makes _GDBN__ run as one of the tools in the Energize Tool | |
7332 | Set: it sends all output to the Energize kernel, and accept input from | |
7333 | it as well. | |
7334 | ||
7335 | See the user manual for the Energize Programming System for | |
7336 | information on how to use the Energize graphical interface and the other | |
7337 | development tools that Energize integrates with _GDBN__. | |
7338 | ||
7339 | @node _GDBN__ Bugs, Renamed Commands, Energize, Top | |
7340 | _fi__(_LUCID__) | |
7341 | _if__(!_LUCID__) | |
70b88761 | 7342 | @node _GDBN__ Bugs, Renamed Commands, Emacs, Top |
6ca72cc6 | 7343 | _fi__(!_LUCID__) |
70b88761 RP |
7344 | @chapter Reporting Bugs in _GDBN__ |
7345 | @cindex Bugs in _GDBN__ | |
7346 | @cindex Reporting Bugs in _GDBN__ | |
7347 | ||
7348 | Your bug reports play an essential role in making _GDBN__ reliable. | |
7349 | ||
7350 | Reporting a bug may help you by bringing a solution to your problem, or it | |
7351 | may not. But in any case the principal function of a bug report is to help | |
7352 | the entire community by making the next version of _GDBN__ work better. Bug | |
7353 | reports are your contribution to the maintenance of _GDBN__. | |
7354 | ||
7355 | In order for a bug report to serve its purpose, you must include the | |
7356 | information that enables us to fix the bug. | |
7357 | ||
7358 | @menu | |
b80282d5 RP |
7359 | * Bug Criteria:: Have You Found a Bug? |
7360 | * Bug Reporting:: How to Report Bugs | |
70b88761 RP |
7361 | @end menu |
7362 | ||
7363 | @node Bug Criteria, Bug Reporting, _GDBN__ Bugs, _GDBN__ Bugs | |
7364 | @section Have You Found a Bug? | |
7365 | @cindex Bug Criteria | |
7366 | ||
7367 | If you are not sure whether you have found a bug, here are some guidelines: | |
7368 | ||
7369 | @itemize @bullet | |
7370 | @item | |
7371 | @cindex Fatal Signal | |
7372 | @cindex Core Dump | |
7373 | If the debugger gets a fatal signal, for any input whatever, that is a | |
7374 | _GDBN__ bug. Reliable debuggers never crash. | |
7375 | ||
7376 | @item | |
7377 | @cindex error on Valid Input | |
7378 | If _GDBN__ produces an error message for valid input, that is a bug. | |
7379 | ||
7380 | @item | |
7381 | @cindex Invalid Input | |
7382 | If _GDBN__ does not produce an error message for invalid input, | |
7383 | that is a bug. However, you should note that your idea of | |
7384 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
7385 | for traditional practice''. | |
7386 | ||
7387 | @item | |
7388 | If you are an experienced user of debugging tools, your suggestions | |
7389 | for improvement of _GDBN__ are welcome in any case. | |
7390 | @end itemize | |
7391 | ||
7392 | @node Bug Reporting, , Bug Criteria, _GDBN__ Bugs | |
7393 | @section How to Report Bugs | |
7394 | @cindex Bug Reports | |
3d3ab540 | 7395 | @cindex _GDBN__ Bugs, Reporting |
70b88761 RP |
7396 | |
7397 | A number of companies and individuals offer support for GNU products. | |
7398 | If you obtained _GDBN__ from a support organization, we recommend you | |
e251e767 | 7399 | contact that organization first. |
70b88761 RP |
7400 | |
7401 | Contact information for many support companies and individuals is | |
7402 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
7403 | ||
7404 | In any event, we also recommend that you send bug reports for _GDBN__ to one | |
7405 | of these addresses: | |
7406 | ||
7407 | @example | |
7408 | bug-gdb@@prep.ai.mit.edu | |
7409 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
7410 | @end example | |
7411 | ||
7412 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
7413 | @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to | |
7414 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
7415 | ||
3d3ab540 RP |
7416 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
7417 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
7418 | the same messages. Often people think of posting bug reports to the | |
7419 | newsgroup instead of mailing them. This appears to work, but it has one | |
7420 | problem which can be crucial: a newsgroup posting often lacks a mail | |
7421 | path back to the sender. Thus, if we need to ask for more information, | |
7422 | we may be unable to reach you. For this reason, it is better to send | |
7423 | bug reports to the mailing list. | |
70b88761 RP |
7424 | |
7425 | As a last resort, send bug reports on paper to: | |
7426 | ||
7427 | @example | |
7428 | GNU Debugger Bugs | |
3d3ab540 | 7429 | Free Software Foundation |
70b88761 RP |
7430 | 545 Tech Square |
7431 | Cambridge, MA 02139 | |
7432 | @end example | |
7433 | ||
7434 | The fundamental principle of reporting bugs usefully is this: | |
7435 | @strong{report all the facts}. If you are not sure whether to state a | |
7436 | fact or leave it out, state it! | |
7437 | ||
7438 | Often people omit facts because they think they know what causes the | |
29a2b744 | 7439 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 7440 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 7441 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
7442 | stray memory reference which happens to fetch from the location where that |
7443 | name is stored in memory; perhaps, if the name were different, the contents | |
7444 | of that location would fool the debugger into doing the right thing despite | |
7445 | the bug. Play it safe and give a specific, complete example. That is the | |
7446 | easiest thing for you to do, and the most helpful. | |
7447 | ||
7448 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 7449 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
7450 | the bug is already known. Therefore, always write your bug reports on |
7451 | the assumption that the bug has not been reported previously. | |
7452 | ||
7453 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
7454 | bell?'' Those bug reports are useless, and we urge everyone to | |
7455 | @emph{refuse to respond to them} except to chide the sender to report | |
7456 | bugs properly. | |
7457 | ||
7458 | To enable us to fix the bug, you should include all these things: | |
7459 | ||
7460 | @itemize @bullet | |
7461 | @item | |
7462 | The version of _GDBN__. _GDBN__ announces it if you start with no | |
7463 | arguments; you can also print it at any time using @code{show version}. | |
7464 | ||
1041a570 | 7465 | Without this, we will not know whether there is any point in looking for |
70b88761 RP |
7466 | the bug in the current version of _GDBN__. |
7467 | ||
7468 | @item | |
ddf21240 JG |
7469 | The type of machine you are using, and the operating system name and |
7470 | version number. | |
70b88761 RP |
7471 | |
7472 | @item | |
7473 | What compiler (and its version) was used to compile _GDBN__---e.g. | |
c7cb8acb | 7474 | ``_GCC__-2.0''. |
70b88761 | 7475 | |
ddf21240 JG |
7476 | @item |
7477 | What compiler (and its version) was used to compile the program you | |
c7cb8acb | 7478 | are debugging---e.g. ``_GCC__-2.0''. |
ddf21240 | 7479 | |
70b88761 RP |
7480 | @item |
7481 | The command arguments you gave the compiler to compile your example and | |
7482 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 7483 | you will not omit something important, list them all. A copy of the |
ddf21240 | 7484 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
7485 | |
7486 | If we were to try to guess the arguments, we would probably guess wrong | |
7487 | and then we might not encounter the bug. | |
7488 | ||
7489 | @item | |
ddf21240 JG |
7490 | A complete input script, and all necessary source files, that will |
7491 | reproduce the bug. | |
70b88761 RP |
7492 | |
7493 | @item | |
7494 | A description of what behavior you observe that you believe is | |
7495 | incorrect. For example, ``It gets a fatal signal.'' | |
7496 | ||
7497 | Of course, if the bug is that _GDBN__ gets a fatal signal, then we will | |
7498 | certainly notice it. But if the bug is incorrect output, we might not | |
7499 | notice unless it is glaringly wrong. We are human, after all. You | |
7500 | might as well not give us a chance to make a mistake. | |
7501 | ||
7502 | Even if the problem you experience is a fatal signal, you should still | |
7503 | say so explicitly. Suppose something strange is going on, such as, | |
7504 | your copy of _GDBN__ is out of synch, or you have encountered a | |
7505 | bug in the C library on your system. (This has happened!) Your copy | |
7506 | might crash and ours would not. If you told us to expect a crash, | |
7507 | then when ours fails to crash, we would know that the bug was not | |
7508 | happening for us. If you had not told us to expect a crash, then we | |
7509 | would not be able to draw any conclusion from our observations. | |
7510 | ||
7511 | @item | |
7512 | If you wish to suggest changes to the _GDBN__ source, send us context | |
7513 | diffs. If you even discuss something in the _GDBN__ source, refer to | |
7514 | it by context, not by line number. | |
7515 | ||
1041a570 | 7516 | The line numbers in our development sources will not match those in your |
70b88761 | 7517 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
7518 | @end itemize |
7519 | ||
7520 | Here are some things that are not necessary: | |
7521 | ||
7522 | @itemize @bullet | |
7523 | @item | |
7524 | A description of the envelope of the bug. | |
7525 | ||
7526 | Often people who encounter a bug spend a lot of time investigating | |
7527 | which changes to the input file will make the bug go away and which | |
7528 | changes will not affect it. | |
7529 | ||
7530 | This is often time consuming and not very useful, because the way we | |
7531 | will find the bug is by running a single example under the debugger | |
7532 | with breakpoints, not by pure deduction from a series of examples. | |
7533 | We recommend that you save your time for something else. | |
7534 | ||
7535 | Of course, if you can find a simpler example to report @emph{instead} | |
7536 | of the original one, that is a convenience for us. Errors in the | |
7537 | output will be easier to spot, running under the debugger will take | |
e251e767 | 7538 | less time, etc. |
70b88761 | 7539 | |
29a2b744 | 7540 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
7541 | report the bug anyway and send us the entire test case you used. |
7542 | ||
7543 | @item | |
7544 | A patch for the bug. | |
7545 | ||
29a2b744 | 7546 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
7547 | the necessary information, such as the test case, on the assumption that |
7548 | a patch is all we need. We might see problems with your patch and decide | |
7549 | to fix the problem another way, or we might not understand it at all. | |
7550 | ||
7551 | Sometimes with a program as complicated as _GDBN__ it is very hard to | |
7552 | construct an example that will make the program follow a certain path | |
1041a570 RP |
7553 | through the code. If you do not send us the example, we will not be able |
7554 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 7555 | |
29a2b744 | 7556 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 7557 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
7558 | help us to understand. |
7559 | ||
7560 | @item | |
7561 | A guess about what the bug is or what it depends on. | |
7562 | ||
29a2b744 | 7563 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
7564 | things without first using the debugger to find the facts. |
7565 | @end itemize | |
7566 | ||
1041a570 RP |
7567 | @c Note: no need to update nodes for rdl-apps.texi since it appears |
7568 | @c *only* in the TeX version of the manual. | |
7569 | @c Note: eventually, make a cross reference to the readline Info nodes. | |
70b88761 | 7570 | @iftex |
cacf5942 RP |
7571 | @c appendices describing GNU readline. Distributed with readline code. |
7572 | @include rluser.texinfo | |
7573 | @include inc-hist.texi | |
70b88761 RP |
7574 | @end iftex |
7575 | ||
77b46d13 | 7576 | @node Renamed Commands, Formatting Documentation, _GDBN__ Bugs, Top |
70b88761 RP |
7577 | @appendix Renamed Commands |
7578 | ||
c7cb8acb | 7579 | The following commands were renamed in GDB 4, in order to make the |
70b88761 RP |
7580 | command set as a whole more consistent and easier to use and remember: |
7581 | ||
e251e767 RP |
7582 | @kindex add-syms |
7583 | @kindex delete environment | |
7584 | @kindex info copying | |
7585 | @kindex info convenience | |
7586 | @kindex info directories | |
7587 | @kindex info editing | |
7588 | @kindex info history | |
7589 | @kindex info targets | |
7590 | @kindex info values | |
7591 | @kindex info version | |
7592 | @kindex info warranty | |
7593 | @kindex set addressprint | |
7594 | @kindex set arrayprint | |
7595 | @kindex set prettyprint | |
7596 | @kindex set screen-height | |
7597 | @kindex set screen-width | |
7598 | @kindex set unionprint | |
7599 | @kindex set vtblprint | |
7600 | @kindex set demangle | |
7601 | @kindex set asm-demangle | |
7602 | @kindex set sevenbit-strings | |
7603 | @kindex set array-max | |
7604 | @kindex set caution | |
7605 | @kindex set history write | |
7606 | @kindex show addressprint | |
7607 | @kindex show arrayprint | |
7608 | @kindex show prettyprint | |
7609 | @kindex show screen-height | |
7610 | @kindex show screen-width | |
7611 | @kindex show unionprint | |
7612 | @kindex show vtblprint | |
7613 | @kindex show demangle | |
7614 | @kindex show asm-demangle | |
7615 | @kindex show sevenbit-strings | |
7616 | @kindex show array-max | |
7617 | @kindex show caution | |
7618 | @kindex show history write | |
7619 | @kindex unset | |
70b88761 | 7620 | |
92b73793 | 7621 | @c TEXI2ROFF-KILL |
70b88761 | 7622 | @ifinfo |
92b73793 | 7623 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7624 | @example |
7625 | OLD COMMAND NEW COMMAND | |
92b73793 | 7626 | @c TEXI2ROFF-KILL |
cf496415 | 7627 | --------------- ------------------------------- |
92b73793 | 7628 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7629 | add-syms add-symbol-file |
7630 | delete environment unset environment | |
7631 | info convenience show convenience | |
7632 | info copying show copying | |
e251e767 | 7633 | info directories show directories |
cf496415 RP |
7634 | info editing show commands |
7635 | info history show values | |
7636 | info targets help target | |
7637 | info values show values | |
7638 | info version show version | |
7639 | info warranty show warranty | |
7640 | set/show addressprint set/show print address | |
7641 | set/show array-max set/show print elements | |
7642 | set/show arrayprint set/show print array | |
7643 | set/show asm-demangle set/show print asm-demangle | |
7644 | set/show caution set/show confirm | |
7645 | set/show demangle set/show print demangle | |
7646 | set/show history write set/show history save | |
7647 | set/show prettyprint set/show print pretty | |
7648 | set/show screen-height set/show height | |
7649 | set/show screen-width set/show width | |
7650 | set/show sevenbit-strings set/show print sevenbit-strings | |
7651 | set/show unionprint set/show print union | |
7652 | set/show vtblprint set/show print vtbl | |
7653 | ||
7654 | unset [No longer an alias for delete] | |
7655 | @end example | |
92b73793 | 7656 | @c TEXI2ROFF-KILL |
70b88761 RP |
7657 | @end ifinfo |
7658 | ||
7659 | @tex | |
7660 | \vskip \parskip\vskip \baselineskip | |
7661 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
7662 | {\bf Old Command} &&{\bf New Command}\cr | |
7663 | add-syms &&add-symbol-file\cr | |
7664 | delete environment &&unset environment\cr | |
7665 | info convenience &&show convenience\cr | |
7666 | info copying &&show copying\cr | |
7667 | info directories &&show directories \cr | |
7668 | info editing &&show commands\cr | |
7669 | info history &&show values\cr | |
7670 | info targets &&help target\cr | |
7671 | info values &&show values\cr | |
7672 | info version &&show version\cr | |
7673 | info warranty &&show warranty\cr | |
7674 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
7675 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
7676 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
7677 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
7678 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
7679 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
7680 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
7681 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
7682 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
7683 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
7684 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
7685 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
7686 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
7687 | \cr | |
7688 | unset &&\rm(No longer an alias for delete)\cr | |
7689 | } | |
7690 | @end tex | |
92b73793 | 7691 | @c END TEXI2ROFF-KILL |
70b88761 | 7692 | |
77b46d13 JG |
7693 | @node Formatting Documentation, Installing GDB, Renamed Commands, Top |
7694 | @appendix Formatting the Documentation | |
7695 | ||
7696 | @cindex GDB reference card | |
7697 | @cindex reference card | |
7698 | The GDB 4 release includes an already-formatted reference card, ready | |
b1385986 | 7699 | for printing with PostScript or GhostScript, in the @file{gdb} |
77b46d13 | 7700 | subdirectory of the main source directory---in |
b1385986 RP |
7701 | @file{gdb-_GDB_VN__/gdb/refcard.ps} of the version _GDB_VN__ release. |
7702 | If you can use PostScript or GhostScript with your printer, you can | |
7703 | print the reference card immediately with @file{refcard.ps}. | |
77b46d13 JG |
7704 | |
7705 | The release also includes the source for the reference card. You | |
7706 | can format it, using @TeX{}, by typing: | |
7707 | ||
7708 | @example | |
7709 | make refcard.dvi | |
7710 | @end example | |
7711 | ||
7712 | The GDB reference card is designed to print in landscape mode on US | |
7713 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
7714 | high. You will need to specify this form of printing as an option to | |
7715 | your @sc{dvi} output program. | |
7716 | ||
7717 | @cindex documentation | |
7718 | ||
7719 | All the documentation for GDB comes as part of the machine-readable | |
7720 | distribution. The documentation is written in Texinfo format, which is | |
7721 | a documentation system that uses a single source file to produce both | |
7722 | on-line information and a printed manual. You can use one of the Info | |
7723 | formatting commands to create the on-line version of the documentation | |
7724 | and @TeX{} (or @code{texi2roff}) to typeset the printed version. | |
7725 | ||
7726 | GDB includes an already formatted copy of the on-line Info version of | |
7727 | this manual in the @file{gdb} subdirectory. The main Info file is | |
7728 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
a89f94c2 RP |
7729 | subordinate files matching @samp{gdb.info*} in the same directory. If |
7730 | necessary, you can print out these files, or read them with any editor; | |
7731 | but they are easier to read using the @code{info} subsystem in GNU Emacs | |
7732 | or the standalone @code{info} program, available as part of the GNU | |
7733 | Texinfo distribution. | |
77b46d13 JG |
7734 | |
7735 | If you want to format these Info files yourself, you need one of the | |
7736 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
7737 | @code{makeinfo}. | |
7738 | ||
7739 | If you have @code{makeinfo} installed, and are in the top level GDB | |
7740 | source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can | |
7741 | make the Info file by typing: | |
7742 | ||
7743 | @example | |
7744 | cd gdb | |
7745 | make gdb.info | |
7746 | @end example | |
7747 | ||
7748 | If you want to typeset and print copies of this manual, you need | |
7749 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
7750 | the Texinfo definitions file. | |
7751 | ||
7752 | @TeX{} is typesetting program; it does not print files directly, but | |
7753 | produces output files called @sc{dvi} files. To print a typeset | |
7754 | document, you need a program to print @sc{dvi} files. If your system | |
7755 | has @TeX{} installed, chances are it has such a program. The precise | |
7756 | command to use depends on your system; @kbd{lpr -d} is common; another | |
7757 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
7758 | without any extension or a @samp{.dvi} extension. | |
7759 | ||
7760 | @TeX{} also requires a macro definitions file called | |
7761 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
7762 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
7763 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
7764 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
7765 | directory. | |
7766 | ||
7767 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
7768 | typeset and print this manual. First switch to the the @file{gdb} | |
7769 | subdirectory of the main source directory (for example, to | |
7770 | @file{gdb-_GDB_VN__/gdb}) and then type: | |
7771 | ||
7772 | @example | |
7773 | make gdb.dvi | |
7774 | @end example | |
7775 | ||
7776 | @node Installing GDB, Copying, Formatting Documentation, Top | |
c7cb8acb RP |
7777 | @appendix Installing GDB |
7778 | @cindex configuring GDB | |
70b88761 RP |
7779 | @cindex installation |
7780 | ||
f672bb7f RP |
7781 | @iftex |
7782 | @c irrelevant in info file; it's as current as the code it lives with. | |
7783 | @quotation | |
7784 | @emph{Warning:} These installation instructions are current as of | |
c7cb8acb RP |
7785 | GDB version _GDB_VN__. If you're installing a more recent release |
7786 | of GDB, we may have improved the installation procedures since | |
f672bb7f RP |
7787 | printing this manual; see the @file{README} file included in your |
7788 | release for the most recent instructions. | |
7789 | @end quotation | |
7790 | @end iftex | |
7791 | ||
c7cb8acb RP |
7792 | GDB comes with a @code{configure} script that automates the process |
7793 | of preparing GDB for installation; you can then use @code{make} to | |
7794 | build the program. | |
b80282d5 | 7795 | |
c7cb8acb | 7796 | The GDB distribution includes all the source code you need for GDB in |
1041a570 RP |
7797 | a single directory, whose name is usually composed by appending the |
7798 | version number to @samp{gdb}. | |
7799 | ||
c7cb8acb | 7800 | For example, the GDB version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__} |
1041a570 | 7801 | directory. That directory contains: |
b80282d5 | 7802 | |
3d3ab540 | 7803 | @table @code |
c7637ea6 | 7804 | @item gdb-_GDB_VN__/configure @r{(and supporting files)} |
c7cb8acb | 7805 | script for configuring GDB and all its supporting libraries. |
b80282d5 | 7806 | |
3e0d0a27 | 7807 | @item gdb-_GDB_VN__/gdb |
c7cb8acb | 7808 | the source specific to GDB itself |
3d3ab540 | 7809 | |
3e0d0a27 | 7810 | @item gdb-_GDB_VN__/bfd |
77b46d13 | 7811 | source for the Binary File Descriptor library |
3d3ab540 | 7812 | |
3e0d0a27 | 7813 | @item gdb-_GDB_VN__/include |
b80282d5 | 7814 | GNU include files |
3d3ab540 | 7815 | |
3e0d0a27 | 7816 | @item gdb-_GDB_VN__/libiberty |
3d3ab540 RP |
7817 | source for the @samp{-liberty} free software library |
7818 | ||
3e0d0a27 | 7819 | @item gdb-_GDB_VN__/readline |
b80282d5 | 7820 | source for the GNU command-line interface |
77b46d13 JG |
7821 | |
7822 | @item gdb-_GDB_VN__/glob | |
7823 | source for the GNU filename pattern-matching subroutine | |
7824 | ||
7825 | @item gdb-_GDB_VN__/mmalloc | |
7826 | source for the GNU memory-mapped malloc package | |
3d3ab540 | 7827 | @end table |
1041a570 | 7828 | |
c7cb8acb | 7829 | The simplest way to configure and build GDB is to run @code{configure} |
1041a570 RP |
7830 | from the @file{gdb-@var{version-number}} source directory, which in |
7831 | this example is the @file{gdb-_GDB_VN__} directory. | |
7832 | ||
7833 | First switch to the @file{gdb-@var{version-number}} source directory | |
7834 | if you are not already in it; then run @code{configure}. Pass the | |
c7cb8acb | 7835 | identifier for the platform on which GDB will run as an |
1041a570 RP |
7836 | argument. |
7837 | ||
7838 | For example: | |
7839 | ||
7463aadd | 7840 | @example |
3e0d0a27 | 7841 | cd gdb-_GDB_VN__ |
3d3ab540 | 7842 | ./configure @var{host} |
7463aadd RP |
7843 | make |
7844 | @end example | |
1041a570 | 7845 | |
7463aadd | 7846 | @noindent |
1041a570 | 7847 | where @var{host} is an identifier such as @samp{sun4} or |
c7cb8acb | 7848 | @samp{decstation}, that identifies the platform where GDB will run. |
1041a570 | 7849 | |
38962738 RP |
7850 | Running @samp{configure @var{host}} followed by @code{make} builds the |
7851 | @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty} | |
7852 | libraries, then @code{gdb} itself. The configured source files, and the | |
7853 | binaries, are left in the corresponding source directories. | |
3d3ab540 | 7854 | |
e251e767 | 7855 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 7856 | system does not recognize this automatically when you run a different |
1041a570 RP |
7857 | shell, you may need to run @code{sh} on it explicitly: |
7858 | ||
7859 | @example | |
7860 | sh configure @var{host} | |
7861 | @end example | |
e251e767 | 7862 | |
f672bb7f RP |
7863 | If you run @code{configure} from a directory that contains source |
7864 | directories for multiple libraries or programs, such as the | |
7865 | @file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure} | |
7866 | creates configuration files for every directory level underneath (unless | |
98349959 | 7867 | you tell it not to, with the @samp{--norecursion} option). |
f672bb7f RP |
7868 | |
7869 | You can run the @code{configure} script from any of the | |
c7cb8acb | 7870 | subordinate directories in the GDB distribution, if you only want to |
1041a570 RP |
7871 | configure that subdirectory; but be sure to specify a path to it. |
7872 | ||
7873 | For example, with version _GDB_VN__, type the following to configure only | |
7874 | the @code{bfd} subdirectory: | |
7875 | ||
e251e767 | 7876 | @example |
203eea5d | 7877 | @group |
e251e767 RP |
7878 | cd gdb-_GDB_VN__/bfd |
7879 | ../configure @var{host} | |
203eea5d | 7880 | @end group |
e251e767 RP |
7881 | @end example |
7882 | ||
1041a570 RP |
7883 | You can install @code{_GDBP__} anywhere; it has no hardwired paths. |
7884 | However, you should make sure that the shell on your path (named by | |
7885 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
c7cb8acb RP |
7886 | that GDB uses the shell to start your program---some systems refuse to |
7887 | let GDB debug child processes whose programs are not readable. | |
3d3ab540 RP |
7888 | |
7889 | @menu | |
c7cb8acb | 7890 | * Separate Objdir:: Compiling GDB in another directory |
b80282d5 RP |
7891 | * Config Names:: Specifying names for hosts and targets |
7892 | * configure Options:: Summary of options for configure | |
3d3ab540 RP |
7893 | @end menu |
7894 | ||
c7cb8acb RP |
7895 | @node Separate Objdir, Config Names, Installing GDB, Installing GDB |
7896 | @section Compiling GDB in Another Directory | |
1041a570 | 7897 | |
c7cb8acb RP |
7898 | If you want to run GDB versions for several host or target machines, |
7899 | you'll need a different @code{gdb} compiled for each combination of | |
1041a570 | 7900 | host and target. @code{configure} is designed to make this easy by |
f672bb7f RP |
7901 | allowing you to generate each configuration in a separate subdirectory, |
7902 | rather than in the source directory. If your @code{make} program | |
7903 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
c7cb8acb | 7904 | @code{make} in each of these directories then builds the @code{gdb} |
f672bb7f | 7905 | program specified there. |
b80282d5 | 7906 | |
c7cb8acb | 7907 | To build @code{gdb} in a separate directory, run @code{configure} |
f672bb7f | 7908 | with the @samp{--srcdir} option to specify where to find the source. |
77b46d13 JG |
7909 | (You'll also need to specify a path to find @code{configure} |
7910 | itself from your working directory. If the path to @code{configure} | |
7911 | would be the same as the argument to @samp{--srcdir}, you can leave out | |
7912 | the @samp{--srcdir} option; it will be assumed.) | |
1041a570 | 7913 | |
c7cb8acb | 7914 | For example, with version _GDB_VN__, you can build GDB in a separate |
f672bb7f | 7915 | directory for a Sun 4 like this: |
70b88761 RP |
7916 | |
7917 | @example | |
3d3ab540 | 7918 | @group |
3e0d0a27 | 7919 | cd gdb-_GDB_VN__ |
f672bb7f RP |
7920 | mkdir ../gdb-sun4 |
7921 | cd ../gdb-sun4 | |
77b46d13 | 7922 | ../gdb-_GDB_VN__/configure sun4 |
70b88761 | 7923 | make |
3d3ab540 | 7924 | @end group |
70b88761 RP |
7925 | @end example |
7926 | ||
f672bb7f RP |
7927 | When @code{configure} builds a configuration using a remote source |
7928 | directory, it creates a tree for the binaries with the same structure | |
7929 | (and using the same names) as the tree under the source directory. In | |
7930 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
c7cb8acb | 7931 | directory @file{gdb-sun4/libiberty}, and GDB itself in |
f672bb7f | 7932 | @file{gdb-sun4/gdb}. |
1041a570 | 7933 | |
38962738 | 7934 | One popular reason to build several GDB configurations in separate |
c7cb8acb | 7935 | directories is to configure GDB for cross-compiling (where GDB |
f672bb7f RP |
7936 | runs on one machine---the host---while debugging programs that run on |
7937 | another machine---the target). You specify a cross-debugging target by | |
7938 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
c7637ea6 | 7939 | |
1041a570 | 7940 | When you run @code{make} to build a program or library, you must run |
f672bb7f RP |
7941 | it in a configured directory---whatever directory you were in when you |
7942 | called @code{configure} (or one of its subdirectories). | |
c7637ea6 RP |
7943 | |
7944 | The @code{Makefile} generated by @code{configure} for each source | |
f672bb7f RP |
7945 | directory also runs recursively. If you type @code{make} in a source |
7946 | directory such as @file{gdb-_GDB_VN__} (or in a separate configured | |
7947 | directory configured with @samp{--srcdir=@var{path}/gdb-_GDB_VN__}), you | |
c7cb8acb | 7948 | will build all the required libraries, then build GDB. |
3d3ab540 | 7949 | |
f672bb7f RP |
7950 | When you have multiple hosts or targets configured in separate |
7951 | directories, you can run @code{make} on them in parallel (for example, | |
7952 | if they are NFS-mounted on each of the hosts); they will not interfere | |
7953 | with each other. | |
3d3ab540 | 7954 | |
c7cb8acb | 7955 | @node Config Names, configure Options, Separate Objdir, Installing GDB |
b80282d5 RP |
7956 | @section Specifying Names for Hosts and Targets |
7957 | ||
7958 | The specifications used for hosts and targets in the @code{configure} | |
7959 | script are based on a three-part naming scheme, but some short predefined | |
7960 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 7961 | of information in the following pattern: |
1041a570 | 7962 | |
b80282d5 RP |
7963 | @example |
7964 | @var{architecture}-@var{vendor}-@var{os} | |
7965 | @end example | |
7966 | ||
7967 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
5e3186ab | 7968 | or in a @code{--target=@var{target}} option, but the equivalent full name |
e251e767 | 7969 | is @samp{sparc-sun-sunos4}. |
b80282d5 | 7970 | |
c7cb8acb | 7971 | The @code{configure} script accompanying GDB does not provide |
b80282d5 RP |
7972 | any query facility to list all supported host and target names or |
7973 | aliases. @code{configure} calls the Bourne shell script | |
7974 | @code{config.sub} to map abbreviations to full names; you can read the | |
7975 | script, if you wish, or you can use it to test your guesses on | |
7976 | abbreviations---for example: | |
1041a570 | 7977 | |
b1385986 | 7978 | @smallexample |
b80282d5 | 7979 | % sh config.sub sun4 |
6a8cb0e7 | 7980 | sparc-sun-sunos411 |
b80282d5 | 7981 | % sh config.sub sun3 |
6a8cb0e7 | 7982 | m68k-sun-sunos411 |
b80282d5 | 7983 | % sh config.sub decstation |
6a8cb0e7 | 7984 | mips-dec-ultrix42 |
b80282d5 RP |
7985 | % sh config.sub hp300bsd |
7986 | m68k-hp-bsd | |
7987 | % sh config.sub i386v | |
6a8cb0e7 | 7988 | i386-unknown-sysv |
e94b4a2b | 7989 | % sh config.sub i786v |
6a8cb0e7 | 7990 | Invalid configuration `i786v': machine `i786v' not recognized |
b1385986 | 7991 | @end smallexample |
1041a570 | 7992 | |
c7637ea6 | 7993 | @noindent |
1041a570 RP |
7994 | @code{config.sub} is also distributed in the GDB source |
7995 | directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__). | |
b80282d5 | 7996 | |
77b46d13 | 7997 | @node configure Options, , Config Names, Installing GDB |
3d3ab540 | 7998 | @section @code{configure} Options |
7463aadd RP |
7999 | |
8000 | Here is a summary of all the @code{configure} options and arguments that | |
c7cb8acb | 8001 | you might use for building GDB: |
7463aadd RP |
8002 | |
8003 | @example | |
77b46d13 | 8004 | configure @r{[}--srcdir=@var{path}@r{]} |
f672bb7f RP |
8005 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} |
8006 | @r{[}--target=@var{target}@r{]} @var{host} | |
7463aadd | 8007 | @end example |
1041a570 | 8008 | |
3d3ab540 | 8009 | @noindent |
f672bb7f RP |
8010 | You may introduce options with a single @samp{-} rather than |
8011 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
8012 | @samp{--}. | |
70b88761 RP |
8013 | |
8014 | @table @code | |
f672bb7f | 8015 | @item --srcdir=@var{path} |
6ca72cc6 RP |
8016 | @strong{Warning: using this option requires GNU @code{make}, or another |
8017 | @code{make} that implements the @code{VPATH} feature.}@* | |
f672bb7f | 8018 | Use this option to make configurations in directories separate from the |
c7cb8acb | 8019 | GDB source directories. Among other things, you can use this to |
f672bb7f RP |
8020 | build (or maintain) several configurations simultaneously, in separate |
8021 | directories. @code{configure} writes configuration specific files in | |
8022 | the current directory, but arranges for them to use the source in the | |
8023 | directory @var{path}. @code{configure} will create directories under | |
8024 | the working directory in parallel to the source directories below | |
8025 | @var{path}. | |
8026 | ||
8027 | @item --norecursion | |
8028 | Configure only the directory level where @code{configure} is executed; do not | |
7463aadd RP |
8029 | propagate configuration to subdirectories. |
8030 | ||
f672bb7f | 8031 | @item --rm |
b80282d5 | 8032 | Remove the configuration that the other arguments specify. |
7463aadd | 8033 | |
29a2b744 | 8034 | @c This does not work (yet if ever). FIXME. |
f672bb7f | 8035 | @c @item --parse=@var{lang} @dots{} |
c7cb8acb RP |
8036 | @c Configure the GDB expression parser to parse the listed languages. |
8037 | @c @samp{all} configures GDB for all supported languages. To get a | |
d7b569d5 | 8038 | @c list of all supported languages, omit the argument. Without this |
c7cb8acb | 8039 | @c option, GDB is configured to parse all supported languages. |
c2bbbb22 | 8040 | |
f672bb7f | 8041 | @item --target=@var{target} |
c7cb8acb RP |
8042 | Configure GDB for cross-debugging programs running on the specified |
8043 | @var{target}. Without this option, GDB is configured to debug | |
8044 | programs that run on the same machine (@var{host}) as GDB itself. | |
b80282d5 RP |
8045 | |
8046 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
8047 | |
8048 | @item @var{host} @dots{} | |
c7cb8acb | 8049 | Configure GDB to run on the specified @var{host}. |
b80282d5 RP |
8050 | |
8051 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
8052 | @end table |
8053 | ||
3d3ab540 RP |
8054 | @noindent |
8055 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 8056 | configuring other GNU tools recursively; but these are the only |
c7cb8acb | 8057 | options that affect GDB or its supporting libraries. |
3d3ab540 | 8058 | |
c7cb8acb | 8059 | @node Copying, Index, Installing GDB, Top |
70b88761 | 8060 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 8061 | @center Version 2, June 1991 |
70b88761 RP |
8062 | |
8063 | @display | |
7463aadd | 8064 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
8065 | 675 Mass Ave, Cambridge, MA 02139, USA |
8066 | ||
8067 | Everyone is permitted to copy and distribute verbatim copies | |
8068 | of this license document, but changing it is not allowed. | |
8069 | @end display | |
8070 | ||
8071 | @unnumberedsec Preamble | |
8072 | ||
7463aadd RP |
8073 | The licenses for most software are designed to take away your |
8074 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 8075 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
8076 | software---to make sure the software is free for all its users. This |
8077 | General Public License applies to most of the Free Software | |
8078 | Foundation's software and to any other program whose authors commit to | |
8079 | using it. (Some other Free Software Foundation software is covered by | |
8080 | the GNU Library General Public License instead.) You can apply it to | |
8081 | your programs, too. | |
70b88761 RP |
8082 | |
8083 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
8084 | price. Our General Public Licenses are designed to make sure that you |
8085 | have the freedom to distribute copies of free software (and charge for | |
8086 | this service if you wish), that you receive source code or can get it | |
8087 | if you want it, that you can change the software or use pieces of it | |
8088 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
8089 | |
8090 | To protect your rights, we need to make restrictions that forbid | |
8091 | anyone to deny you these rights or to ask you to surrender the rights. | |
8092 | These restrictions translate to certain responsibilities for you if you | |
8093 | distribute copies of the software, or if you modify it. | |
8094 | ||
7463aadd | 8095 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
8096 | gratis or for a fee, you must give the recipients all the rights that |
8097 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
8098 | source code. And you must show them these terms so they know their |
8099 | rights. | |
70b88761 RP |
8100 | |
8101 | We protect your rights with two steps: (1) copyright the software, and | |
8102 | (2) offer you this license which gives you legal permission to copy, | |
8103 | distribute and/or modify the software. | |
8104 | ||
8105 | Also, for each author's protection and ours, we want to make certain | |
8106 | that everyone understands that there is no warranty for this free | |
8107 | software. If the software is modified by someone else and passed on, we | |
8108 | want its recipients to know that what they have is not the original, so | |
8109 | that any problems introduced by others will not reflect on the original | |
8110 | authors' reputations. | |
8111 | ||
7463aadd RP |
8112 | Finally, any free program is threatened constantly by software |
8113 | patents. We wish to avoid the danger that redistributors of a free | |
8114 | program will individually obtain patent licenses, in effect making the | |
8115 | program proprietary. To prevent this, we have made it clear that any | |
8116 | patent must be licensed for everyone's free use or not licensed at all. | |
8117 | ||
70b88761 RP |
8118 | The precise terms and conditions for copying, distribution and |
8119 | modification follow. | |
8120 | ||
8121 | @iftex | |
7463aadd | 8122 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8123 | @end iftex |
8124 | @ifinfo | |
7463aadd | 8125 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8126 | @end ifinfo |
8127 | ||
8128 | @enumerate | |
8129 | @item | |
7463aadd RP |
8130 | This License applies to any program or other work which contains |
8131 | a notice placed by the copyright holder saying it may be distributed | |
8132 | under the terms of this General Public License. The ``Program'', below, | |
8133 | refers to any such program or work, and a ``work based on the Program'' | |
8134 | means either the Program or any derivative work under copyright law: | |
8135 | that is to say, a work containing the Program or a portion of it, | |
8136 | either verbatim or with modifications and/or translated into another | |
8137 | language. (Hereinafter, translation is included without limitation in | |
8138 | the term ``modification''.) Each licensee is addressed as ``you''. | |
8139 | ||
8140 | Activities other than copying, distribution and modification are not | |
8141 | covered by this License; they are outside its scope. The act of | |
8142 | running the Program is not restricted, and the output from the Program | |
8143 | is covered only if its contents constitute a work based on the | |
8144 | Program (independent of having been made by running the Program). | |
8145 | Whether that is true depends on what the Program does. | |
70b88761 RP |
8146 | |
8147 | @item | |
7463aadd RP |
8148 | You may copy and distribute verbatim copies of the Program's |
8149 | source code as you receive it, in any medium, provided that you | |
8150 | conspicuously and appropriately publish on each copy an appropriate | |
8151 | copyright notice and disclaimer of warranty; keep intact all the | |
8152 | notices that refer to this License and to the absence of any warranty; | |
8153 | and give any other recipients of the Program a copy of this License | |
8154 | along with the Program. | |
70b88761 | 8155 | |
7463aadd RP |
8156 | You may charge a fee for the physical act of transferring a copy, and |
8157 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 8158 | |
70b88761 | 8159 | @item |
7463aadd RP |
8160 | You may modify your copy or copies of the Program or any portion |
8161 | of it, thus forming a work based on the Program, and copy and | |
8162 | distribute such modifications or work under the terms of Section 1 | |
8163 | above, provided that you also meet all of these conditions: | |
70b88761 | 8164 | |
1041a570 | 8165 | @enumerate a |
70b88761 | 8166 | @item |
7463aadd RP |
8167 | You must cause the modified files to carry prominent notices |
8168 | stating that you changed the files and the date of any change. | |
70b88761 RP |
8169 | |
8170 | @item | |
7463aadd RP |
8171 | You must cause any work that you distribute or publish, that in |
8172 | whole or in part contains or is derived from the Program or any | |
8173 | part thereof, to be licensed as a whole at no charge to all third | |
8174 | parties under the terms of this License. | |
70b88761 RP |
8175 | |
8176 | @item | |
7463aadd RP |
8177 | If the modified program normally reads commands interactively |
8178 | when run, you must cause it, when started running for such | |
8179 | interactive use in the most ordinary way, to print or display an | |
8180 | announcement including an appropriate copyright notice and a | |
8181 | notice that there is no warranty (or else, saying that you provide | |
8182 | a warranty) and that users may redistribute the program under | |
8183 | these conditions, and telling the user how to view a copy of this | |
8184 | License. (Exception: if the Program itself is interactive but | |
8185 | does not normally print such an announcement, your work based on | |
8186 | the Program is not required to print an announcement.) | |
1041a570 | 8187 | @end enumerate |
7463aadd RP |
8188 | |
8189 | These requirements apply to the modified work as a whole. If | |
8190 | identifiable sections of that work are not derived from the Program, | |
8191 | and can be reasonably considered independent and separate works in | |
8192 | themselves, then this License, and its terms, do not apply to those | |
8193 | sections when you distribute them as separate works. But when you | |
8194 | distribute the same sections as part of a whole which is a work based | |
8195 | on the Program, the distribution of the whole must be on the terms of | |
8196 | this License, whose permissions for other licensees extend to the | |
8197 | entire whole, and thus to each and every part regardless of who wrote it. | |
8198 | ||
8199 | Thus, it is not the intent of this section to claim rights or contest | |
8200 | your rights to work written entirely by you; rather, the intent is to | |
8201 | exercise the right to control the distribution of derivative or | |
8202 | collective works based on the Program. | |
8203 | ||
8204 | In addition, mere aggregation of another work not based on the Program | |
8205 | with the Program (or with a work based on the Program) on a volume of | |
8206 | a storage or distribution medium does not bring the other work under | |
8207 | the scope of this License. | |
70b88761 RP |
8208 | |
8209 | @item | |
7463aadd RP |
8210 | You may copy and distribute the Program (or a work based on it, |
8211 | under Section 2) in object code or executable form under the terms of | |
8212 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 8213 | |
1041a570 | 8214 | @enumerate a |
70b88761 | 8215 | @item |
7463aadd RP |
8216 | Accompany it with the complete corresponding machine-readable |
8217 | source code, which must be distributed under the terms of Sections | |
8218 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
8219 | |
8220 | @item | |
7463aadd RP |
8221 | Accompany it with a written offer, valid for at least three |
8222 | years, to give any third party, for a charge no more than your | |
8223 | cost of physically performing source distribution, a complete | |
8224 | machine-readable copy of the corresponding source code, to be | |
8225 | distributed under the terms of Sections 1 and 2 above on a medium | |
8226 | customarily used for software interchange; or, | |
70b88761 RP |
8227 | |
8228 | @item | |
7463aadd RP |
8229 | Accompany it with the information you received as to the offer |
8230 | to distribute corresponding source code. (This alternative is | |
70b88761 | 8231 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
8232 | received the program in object code or executable form with such |
8233 | an offer, in accord with Subsection b above.) | |
1041a570 | 8234 | @end enumerate |
7463aadd RP |
8235 | |
8236 | The source code for a work means the preferred form of the work for | |
8237 | making modifications to it. For an executable work, complete source | |
8238 | code means all the source code for all modules it contains, plus any | |
8239 | associated interface definition files, plus the scripts used to | |
8240 | control compilation and installation of the executable. However, as a | |
8241 | special exception, the source code distributed need not include | |
8242 | anything that is normally distributed (in either source or binary | |
8243 | form) with the major components (compiler, kernel, and so on) of the | |
8244 | operating system on which the executable runs, unless that component | |
8245 | itself accompanies the executable. | |
8246 | ||
8247 | If distribution of executable or object code is made by offering | |
8248 | access to copy from a designated place, then offering equivalent | |
8249 | access to copy the source code from the same place counts as | |
8250 | distribution of the source code, even though third parties are not | |
8251 | compelled to copy the source along with the object code. | |
70b88761 RP |
8252 | |
8253 | @item | |
7463aadd RP |
8254 | You may not copy, modify, sublicense, or distribute the Program |
8255 | except as expressly provided under this License. Any attempt | |
8256 | otherwise to copy, modify, sublicense or distribute the Program is | |
8257 | void, and will automatically terminate your rights under this License. | |
8258 | However, parties who have received copies, or rights, from you under | |
8259 | this License will not have their licenses terminated so long as such | |
8260 | parties remain in full compliance. | |
70b88761 RP |
8261 | |
8262 | @item | |
7463aadd RP |
8263 | You are not required to accept this License, since you have not |
8264 | signed it. However, nothing else grants you permission to modify or | |
8265 | distribute the Program or its derivative works. These actions are | |
8266 | prohibited by law if you do not accept this License. Therefore, by | |
8267 | modifying or distributing the Program (or any work based on the | |
8268 | Program), you indicate your acceptance of this License to do so, and | |
8269 | all its terms and conditions for copying, distributing or modifying | |
8270 | the Program or works based on it. | |
70b88761 RP |
8271 | |
8272 | @item | |
8273 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
8274 | Program), the recipient automatically receives a license from the |
8275 | original licensor to copy, distribute or modify the Program subject to | |
8276 | these terms and conditions. You may not impose any further | |
8277 | restrictions on the recipients' exercise of the rights granted herein. | |
8278 | You are not responsible for enforcing compliance by third parties to | |
8279 | this License. | |
8280 | ||
8281 | @item | |
8282 | If, as a consequence of a court judgment or allegation of patent | |
8283 | infringement or for any other reason (not limited to patent issues), | |
8284 | conditions are imposed on you (whether by court order, agreement or | |
8285 | otherwise) that contradict the conditions of this License, they do not | |
8286 | excuse you from the conditions of this License. If you cannot | |
8287 | distribute so as to satisfy simultaneously your obligations under this | |
8288 | License and any other pertinent obligations, then as a consequence you | |
8289 | may not distribute the Program at all. For example, if a patent | |
8290 | license would not permit royalty-free redistribution of the Program by | |
8291 | all those who receive copies directly or indirectly through you, then | |
8292 | the only way you could satisfy both it and this License would be to | |
8293 | refrain entirely from distribution of the Program. | |
8294 | ||
8295 | If any portion of this section is held invalid or unenforceable under | |
8296 | any particular circumstance, the balance of the section is intended to | |
8297 | apply and the section as a whole is intended to apply in other | |
8298 | circumstances. | |
8299 | ||
8300 | It is not the purpose of this section to induce you to infringe any | |
8301 | patents or other property right claims or to contest validity of any | |
8302 | such claims; this section has the sole purpose of protecting the | |
8303 | integrity of the free software distribution system, which is | |
8304 | implemented by public license practices. Many people have made | |
8305 | generous contributions to the wide range of software distributed | |
8306 | through that system in reliance on consistent application of that | |
8307 | system; it is up to the author/donor to decide if he or she is willing | |
8308 | to distribute software through any other system and a licensee cannot | |
8309 | impose that choice. | |
8310 | ||
8311 | This section is intended to make thoroughly clear what is believed to | |
8312 | be a consequence of the rest of this License. | |
8313 | ||
8314 | @item | |
8315 | If the distribution and/or use of the Program is restricted in | |
8316 | certain countries either by patents or by copyrighted interfaces, the | |
8317 | original copyright holder who places the Program under this License | |
8318 | may add an explicit geographical distribution limitation excluding | |
8319 | those countries, so that distribution is permitted only in or among | |
8320 | countries not thus excluded. In such case, this License incorporates | |
8321 | the limitation as if written in the body of this License. | |
70b88761 RP |
8322 | |
8323 | @item | |
8324 | The Free Software Foundation may publish revised and/or new versions | |
8325 | of the General Public License from time to time. Such new versions will | |
8326 | be similar in spirit to the present version, but may differ in detail to | |
8327 | address new problems or concerns. | |
8328 | ||
8329 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 8330 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
8331 | later version'', you have the option of following the terms and conditions |
8332 | either of that version or of any later version published by the Free | |
8333 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 8334 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
8335 | Foundation. |
8336 | ||
8337 | @item | |
8338 | If you wish to incorporate parts of the Program into other free | |
8339 | programs whose distribution conditions are different, write to the author | |
8340 | to ask for permission. For software which is copyrighted by the Free | |
8341 | Software Foundation, write to the Free Software Foundation; we sometimes | |
8342 | make exceptions for this. Our decision will be guided by the two goals | |
8343 | of preserving the free status of all derivatives of our free software and | |
8344 | of promoting the sharing and reuse of software generally. | |
8345 | ||
8346 | @iftex | |
8347 | @heading NO WARRANTY | |
8348 | @end iftex | |
8349 | @ifinfo | |
8350 | @center NO WARRANTY | |
8351 | @end ifinfo | |
8352 | ||
8353 | @item | |
8354 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
8355 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
8356 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
8357 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
8358 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
8359 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
8360 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
8361 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
8362 | REPAIR OR CORRECTION. | |
8363 | ||
8364 | @item | |
7463aadd RP |
8365 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
8366 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 8367 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
8368 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
8369 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
8370 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
8371 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
8372 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
8373 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
8374 | @end enumerate |
8375 | ||
8376 | @iftex | |
8377 | @heading END OF TERMS AND CONDITIONS | |
8378 | @end iftex | |
8379 | @ifinfo | |
8380 | @center END OF TERMS AND CONDITIONS | |
8381 | @end ifinfo | |
8382 | ||
8383 | @page | |
54e6b3c3 | 8384 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
8385 | |
8386 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
8387 | possible use to the public, the best way to achieve this is to make it |
8388 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 8389 | |
7463aadd RP |
8390 | To do so, attach the following notices to the program. It is safest |
8391 | to attach them to the start of each source file to most effectively | |
8392 | convey the exclusion of warranty; and each file should have at least | |
8393 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
8394 | |
8395 | @smallexample | |
203eea5d | 8396 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
8397 | Copyright (C) 19@var{yy} @var{name of author} |
8398 | ||
203eea5d RP |
8399 | This program is free software; you can redistribute it and/or |
8400 | modify it under the terms of the GNU General Public License | |
8401 | as published by the Free Software Foundation; either version 2 | |
8402 | of the License, or (at your option) any later version. | |
70b88761 RP |
8403 | |
8404 | This program is distributed in the hope that it will be useful, | |
8405 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8406 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8407 | GNU General Public License for more details. | |
8408 | ||
8409 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
8410 | along with this program; if not, write to the |
8411 | Free Software Foundation, Inc., 675 Mass Ave, | |
8412 | Cambridge, MA 02139, USA. | |
70b88761 RP |
8413 | @end smallexample |
8414 | ||
8415 | Also add information on how to contact you by electronic and paper mail. | |
8416 | ||
8417 | If the program is interactive, make it output a short notice like this | |
8418 | when it starts in an interactive mode: | |
8419 | ||
8420 | @smallexample | |
8421 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
8422 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
8423 | type `show w'. This is free software, and you are welcome | |
8424 | to redistribute it under certain conditions; type `show c' | |
8425 | for details. | |
70b88761 RP |
8426 | @end smallexample |
8427 | ||
7463aadd RP |
8428 | The hypothetical commands @samp{show w} and @samp{show c} should show |
8429 | the appropriate parts of the General Public License. Of course, the | |
8430 | commands you use may be called something other than @samp{show w} and | |
8431 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8432 | suits your program. | |
70b88761 RP |
8433 | |
8434 | You should also get your employer (if you work as a programmer) or your | |
8435 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8436 | necessary. Here is a sample; alter the names: | |
8437 | ||
1041a570 RP |
8438 | @example |
8439 | Yoyodyne, Inc., hereby disclaims all copyright | |
8440 | interest in the program `Gnomovision' | |
8441 | (which makes passes at compilers) written | |
8442 | by James Hacker. | |
70b88761 RP |
8443 | |
8444 | @var{signature of Ty Coon}, 1 April 1989 | |
8445 | Ty Coon, President of Vice | |
1041a570 | 8446 | @end example |
7463aadd RP |
8447 | |
8448 | This General Public License does not permit incorporating your program into | |
8449 | proprietary programs. If your program is a subroutine library, you may | |
8450 | consider it more useful to permit linking proprietary applications with the | |
8451 | library. If this is what you want to do, use the GNU Library General | |
8452 | Public License instead of this License. | |
70b88761 | 8453 | |
9c3ad547 | 8454 | @node Index, , Copying, Top |
d2e08421 | 8455 | @unnumbered Index |
e91b87a3 | 8456 | |
8457 | @printindex cp | |
8458 | ||
fe3f5fc8 RP |
8459 | @tex |
8460 | % I think something like @colophon should be in texinfo. In the | |
8461 | % meantime: | |
8462 | \long\def\colophon{\hbox to0pt{}\vfill | |
8463 | \centerline{The body of this manual is set in} | |
8464 | \centerline{\fontname\tenrm,} | |
8465 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8466 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
8467 | \centerline{{\it\fontname\tenit\/},} |
8468 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
8469 | \centerline{{\sl\fontname\tensl\/}} |
8470 | \centerline{are used for emphasis.}\vfill} | |
8471 | \page\colophon | |
a6d0b6d3 | 8472 | % Blame: [email protected], 1991. |
fe3f5fc8 RP |
8473 | @end tex |
8474 | ||
e91b87a3 | 8475 | @contents |
8476 | @bye |