Commit | Line | Data |
---|---|---|
9bcc06ef RP |
1 | _dnl__ -*-Texinfo-*- |
2 | _dnl__ Copyright (c) 1988 1989 1990 1991 Free Software Foundation, Inc. | |
e91b87a3 | 3 | \input texinfo |
5a131cc7 | 4 | @setfilename _GDBP__.info |
8734fc33 | 5 | @c $Id$ |
9c3ad547 | 6 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. |
5a131cc7 RP |
7 | @c |
8 | @c NOTE: this manual is marked up for preprocessing with a collection | |
9 | @c of m4 macros called "pretex.m4". If you see <_if__> and <_fi__> | |
10 | @c scattered around the source, you have the full source before | |
11 | @c preprocessing; if you don't, you have the source configured for | |
12 | @c _HOST__ architectures (and you can of course get the full source, | |
13 | @c with all configurations, from wherever you got this). | |
14 | _if__(0) | |
15 | ||
9bcc06ef RP |
16 | THIS IS THE SOURCE PRIOR TO PREPROCESSING. The full source needs to |
17 | be run through m4 before either tex- or info- formatting: for example, | |
08665207 | 18 | _0__ |
8734fc33 | 19 | m4 pretex.m4 none.m4 m680x0.m4 gdb.texinfo >gdb-680x0.texinfo |
08665207 | 20 | _1__ |
70b88761 RP |
21 | will produce (assuming your path finds either GNU m4 >= 0.84, or SysV |
22 | m4; Berkeley won't do) a file suitable for formatting. See the text in | |
23 | "pretex.m4" for a fuller explanation (and the macro definitions). | |
e91b87a3 | 24 | |
9bcc06ef | 25 | _fi__(0) |
0e0fa7ce RP |
26 | @tex |
27 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
28 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
0e0fa7ce | 29 | @end tex |
70b88761 RP |
30 | @c |
31 | @syncodeindex ky cp | |
32 | @c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN: | |
33 | @c Sun May 19 05:36:59 1991 John Gilmore (gnu at cygint.cygnus.com) | |
34 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
35 | @ifinfo | |
36 | This file documents the GNU debugger _GDBN__. | |
37 | ||
38 | Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc. | |
39 | ||
40 | Permission is granted to make and distribute verbatim copies of | |
41 | this manual provided the copyright notice and this permission notice | |
42 | are preserved on all copies. | |
43 | ||
44 | @ignore | |
45 | Permission is granted to process this file through TeX and print the | |
46 | results, provided the printed document carries copying permission | |
47 | notice identical to this one except for the removal of this paragraph | |
48 | (this paragraph not being relevant to the printed manual). | |
49 | ||
50 | @end ignore | |
51 | Permission is granted to copy and distribute modified versions of this | |
52 | manual under the conditions for verbatim copying, provided also that the | |
53 | section entitled ``GNU General Public License'' is included exactly as | |
54 | in the original, and provided that the entire resulting derived work is | |
55 | distributed under the terms of a permission notice identical to this | |
56 | one. | |
57 | ||
58 | Permission is granted to copy and distribute translations of this manual | |
59 | into another language, under the above conditions for modified versions, | |
60 | except that the section entitled ``GNU General Public License'' may be | |
61 | included in a translation approved by the Free Software Foundation | |
62 | instead of in the original English. | |
63 | @end ifinfo | |
64 | @smallbook | |
65 | @setchapternewpage odd | |
66 | _if__(_GENERIC__) | |
67 | @settitle Using _GDBN__ (v4.0) | |
68 | _fi__(_GENERIC__) | |
69 | _if__(!_GENERIC__) | |
70 | @settitle Using _GDBN__ v4.0 (_HOST__) | |
71 | _fi__(!_GENERIC__) | |
72 | @iftex | |
73 | @finalout | |
74 | @end iftex | |
75 | @titlepage | |
76 | @title{Using _GDBN__} | |
77 | @subtitle{A Guide to the GNU Source-Level Debugger} | |
78 | _if__(!_GENERIC__) | |
79 | @subtitle{On _HOST__ Systems} | |
80 | _fi__(!_GENERIC__) | |
81 | @sp 1 | |
82 | @c Maybe crank this up to "Fourth Edition" when released at FSF | |
83 | @c @subtitle Third Edition---_GDBN__ version 4.0 | |
84 | @subtitle _GDBN__ version 4.0 | |
85 | @subtitle May 1991 | |
86 | @author{Richard M. Stallman@qquad @hfill Free Software Foundation} | |
87 | @author{Roland H. Pesch@qquad @hfill Cygnus Support} | |
88 | @page | |
89 | @tex | |
90 | {\parskip=0pt | |
91 | \hfill rms\@ai.mit.edu, pesch\@cygnus.com\par | |
92 | \hfill {\it Using _GDBN__}, \manvers\par | |
93 | \hfill \TeX{}info \texinfoversion\par | |
94 | } | |
95 | @end tex | |
96 | ||
97 | @vskip 0pt plus 1filll | |
98 | Copyright @copyright{} 1988, 1989, 1990, 1991 Free Software Foundation, Inc. | |
99 | ||
100 | Permission is granted to make and distribute verbatim copies of | |
101 | this manual provided the copyright notice and this permission notice | |
102 | are preserved on all copies. | |
103 | ||
104 | Permission is granted to copy and distribute modified versions of this | |
105 | manual under the conditions for verbatim copying, provided also that the | |
106 | section entitled ``GNU General Public License'' is included exactly as | |
107 | in the original, and provided that the entire resulting derived work is | |
108 | distributed under the terms of a permission notice identical to this | |
109 | one. | |
110 | ||
111 | Permission is granted to copy and distribute translations of this manual | |
112 | into another language, under the above conditions for modified versions, | |
113 | except that the section entitled ``GNU General Public License'' may be | |
114 | included in a translation approved by the Free Software Foundation | |
115 | instead of in the original English. | |
116 | @end titlepage | |
117 | @page | |
118 | ||
119 | @node Top, Summary, (dir), (dir) | |
120 | @ifinfo | |
121 | This file describes version 4.0 of GDB, the GNU symbolic debugger. | |
122 | @end ifinfo | |
123 | ||
124 | @menu | |
125 | * Summary:: Summary of _GDBN__ | |
126 | * New Features:: New Features in _GDBN__ version 4.0 | |
127 | * Sample Session:: A Sample _GDBN__ Session | |
128 | * Invocation:: Getting In and Out of _GDBN__ | |
129 | * Commands:: | |
130 | * Running:: Running Programs Under _GDBN__ | |
131 | * Stopping:: Stopping and Continuing | |
132 | * Stack:: Examining the Stack | |
133 | * Source:: Examining Source Files | |
134 | * Data:: Examining Data | |
135 | * Symbols:: Examining the Symbol Table | |
136 | * Altering:: Altering Execution | |
137 | * _GDBN__ Files:: | |
138 | * Targets:: Specifying a Debugging Target | |
139 | * Controlling _GDBN__:: Controlling _GDBN__ | |
140 | * Sequences:: Canned Sequences of Commands | |
141 | * Emacs:: Using _GDBN__ under GNU Emacs | |
142 | * _GDBN__ Bugs:: Reporting Bugs in _GDBN__ | |
143 | * Renamed Commands:: | |
144 | * Installing _GDBN__:: Installing _GDBN__ | |
145 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
146 | * Index:: Index | |
147 | --- The Detailed Node Listing --- | |
148 | ||
149 | Summary of _GDBN__ | |
150 | ||
151 | * Free Software:: Free Software | |
152 | * Contributors:: Contributors to _GDBN__ | |
153 | ||
154 | Getting In and Out of _GDBN__ | |
155 | ||
156 | * Starting _GDBN__:: Starting _GDBN__ | |
157 | * Leaving _GDBN__:: Leaving _GDBN__ | |
158 | * Shell Commands:: Shell Commands | |
159 | ||
160 | Starting _GDBN__ | |
161 | ||
162 | * File Options:: Choosing Files | |
163 | * Mode Options:: Choosing Modes | |
164 | ||
165 | _GDBN__ Commands | |
166 | ||
167 | * Command Syntax:: Command Syntax | |
168 | * Help:: Getting Help | |
169 | ||
170 | Running Programs Under _GDBN__ | |
171 | ||
172 | * Compilation:: Compiling for Debugging | |
173 | * Starting:: Starting your Program | |
174 | * Arguments:: Your Program's Arguments | |
175 | * Environment:: Your Program's Environment | |
176 | * Working Directory:: Your Program's Working Directory | |
177 | * Input/Output:: Your Program's Input and Output | |
178 | * Attach:: Debugging an Already-Running Process | |
179 | * Kill Process:: Killing the Child Process | |
180 | ||
181 | Stopping and Continuing | |
182 | ||
183 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions | |
184 | * Stepping:: Stepping | |
185 | * Continuing:: Continuing | |
186 | * Signals:: Signals | |
187 | ||
188 | Breakpoints, Watchpoints, and Exceptions | |
189 | ||
190 | * Set Breaks:: Setting Breakpoints | |
191 | * Set Watchpoints:: Setting Watchpoints | |
192 | * Exception Handling:: Breakpoints and Exceptions | |
193 | * Delete Breaks:: Deleting Breakpoints | |
194 | * Disabling:: Disabling Breakpoints | |
195 | * Conditions:: Break Conditions | |
196 | * Break Commands:: Breakpoint Command Lists | |
197 | * Breakpoint Menus:: Breakpoint Menus | |
198 | * Error in Breakpoints:: | |
199 | ||
200 | Examining the Stack | |
201 | ||
202 | * Frames:: Stack Frames | |
203 | * Backtrace:: Backtraces | |
204 | * Selection:: Selecting a Frame | |
205 | * Frame Info:: Information on a Frame | |
206 | ||
207 | Examining Source Files | |
208 | ||
209 | * List:: Printing Source Lines | |
210 | * Search:: Searching Source Files | |
211 | * Source Path:: Specifying Source Directories | |
212 | * Machine Code:: Source and Machine Code | |
213 | ||
214 | Examining Data | |
215 | ||
216 | * Expressions:: Expressions | |
217 | * Variables:: Program Variables | |
218 | * Arrays:: Artificial Arrays | |
219 | * Output formats:: Output formats | |
220 | * Memory:: Examining Memory | |
221 | * Auto Display:: Automatic Display | |
222 | * Print Settings:: Print Settings | |
223 | * Value History:: Value History | |
224 | * Convenience Vars:: Convenience Variables | |
225 | * Registers:: Registers | |
226 | * Floating Point Hardware:: Floating Point Hardware | |
227 | ||
228 | Altering Execution | |
229 | ||
230 | * Assignment:: Assignment to Variables | |
231 | * Jumping:: Continuing at a Different Address | |
232 | * Signaling:: Giving the Program a Signal | |
233 | * Returning:: Returning from a Function | |
234 | * Calling:: Calling your Program's Functions | |
235 | ||
236 | _GDBN__'s Files | |
237 | ||
238 | * Files:: Commands to Specify Files | |
239 | * Symbol Errors:: Errors Reading Symbol Files | |
240 | ||
241 | Specifying a Debugging Target | |
242 | ||
243 | * Active Targets:: Active Targets | |
244 | * Target Commands:: Commands for Managing Targets | |
245 | * Remote:: Remote Debugging | |
246 | ||
247 | Remote Debugging | |
248 | ||
249 | * i960-Nindy Remote:: | |
250 | * EB29K Remote:: | |
251 | * VxWorks Remote:: | |
252 | ||
253 | _GDBN__ with a Remote i960 (Nindy) | |
254 | ||
255 | * Nindy Startup:: Startup with Nindy | |
256 | * Nindy Options:: Options for Nindy | |
257 | * Nindy reset:: Nindy Reset Command | |
258 | ||
259 | _GDBN__ with a Remote EB29K | |
260 | ||
261 | * Comms (EB29K):: Communications Setup | |
262 | * gdb-EB29K:: EB29K cross-debugging | |
263 | * Remote Log:: Remote Log | |
264 | ||
265 | _GDBN__ and VxWorks | |
266 | ||
267 | * VxWorks connection:: Connecting to VxWorks | |
268 | * VxWorks download:: VxWorks Download | |
269 | * VxWorks attach:: Running Tasks | |
270 | ||
271 | Controlling _GDBN__ | |
272 | ||
273 | * Prompt:: Prompt | |
274 | * Editing:: Command Editing | |
275 | * History:: Command History | |
276 | * Screen Size:: Screen Size | |
277 | * Numbers:: Numbers | |
278 | * Messages/Warnings:: Optional Warnings and Messages | |
279 | ||
280 | Canned Sequences of Commands | |
281 | ||
282 | * Define:: User-Defined Commands | |
283 | * Command Files:: Command Files | |
284 | * Output:: Commands for Controlled Output | |
285 | ||
286 | Reporting Bugs in _GDBN__ | |
287 | ||
288 | * Bug Criteria:: Have You Found a Bug? | |
289 | * Bug Reporting:: How to Report Bugs | |
290 | @end menu | |
291 | ||
292 | @node Summary, New Features, Top, Top | |
293 | @unnumbered Summary of _GDBN__ | |
294 | ||
295 | The purpose of a debugger such as _GDBN__ is to allow you to see what is | |
296 | going on ``inside'' another program while it executes---or what another | |
297 | program was doing at the moment it crashed. | |
298 | ||
299 | _GDBN__ can do four main kinds of things (plus other things in support of | |
300 | these) to help you catch bugs in the act: | |
301 | ||
302 | @itemize @bullet | |
303 | @item | |
304 | Start your program, specifying anything that might affect its behavior. | |
305 | ||
306 | @item | |
307 | Make your program stop on specified conditions. | |
308 | ||
309 | @item | |
310 | Examine what has happened, when your program has stopped. | |
311 | ||
312 | @item | |
313 | Change things in your program, so you can experiment with correcting the | |
314 | effects of one bug and go on to learn about another. | |
315 | @end itemize | |
316 | ||
317 | _GDBN__ can be used to debug programs written in C and C++. Pascal support | |
318 | is being implemented, and Fortran support will be added when a GNU | |
319 | Fortran compiler is ready. | |
320 | ||
321 | @menu | |
322 | * Free Software:: Free Software | |
323 | * Contributors:: Contributors to GDB | |
324 | @end menu | |
325 | ||
326 | @node Free Software, Contributors, Summary, Summary | |
327 | @unnumberedsec Free Software | |
328 | _GDBN__ is @dfn{free software}, protected by the GNU General Public License (GPL). | |
329 | The GPL gives you the freedom to copy or adapt a licensed | |
330 | program---but every person getting a copy also gets with it the | |
331 | freedom to modify that copy (which means that they must get access to | |
332 | the source code), and the freedom to distribute further copies. | |
333 | Typical software companies use copyrights to limit your freedoms; the | |
334 | Free Software Foundation uses the GPL to preserve these freedoms. | |
335 | ||
336 | Fundamentally, the General Public License is a license which says that | |
337 | you have these freedoms and that you can't take these freedoms away | |
338 | from anyone else. | |
339 | ||
340 | @c FIXME: (passim) go through all xrefs, expanding to use text headings | |
341 | For full details, @pxref{Copying}. | |
342 | @node Contributors, , Free Software, Summary | |
343 | @unnumberedsec Contributors to GDB | |
344 | ||
345 | Richard Stallman was the original author of GDB, and of many other GNU | |
346 | programs. Many others have contributed to its development. This | |
347 | section attempts to credit major contributors. One of the virtues of | |
348 | free software is that everyone is free to contribute to it; with | |
349 | regret, we cannot actually acknowledge everyone here. The file | |
350 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
351 | account. | |
352 | ||
353 | Changes much prior to version 2.0 are lost in the mists of time. | |
354 | ||
355 | @quotation | |
356 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
357 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
358 | omitted from this list, we would like to add your names! | |
359 | @end quotation | |
360 | ||
361 | So that they may not regard their long labor as thankless, we | |
362 | particularly thank those who shepherded GDB through major releases: | |
363 | John Gilmore (release 4.0); Jim Kingdon (releases 3.9, 3.5, 3.4, 3.3); | |
364 | and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of GDB | |
365 | for some period, each contributed significantly to the structure, | |
366 | stability, and capabilities of the entire debugger. | |
367 | ||
368 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
369 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
370 | ||
371 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
372 | with significant additional contributions from Per Bothner. James | |
373 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
374 | TerMaat (who also did much general update work leading to release 3.0). | |
375 | ||
376 | GDB 4.0 uses the BFD subroutine library to examine multiple | |
377 | object-file formats; BFD was a joint project of V. Gumby | |
378 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
379 | ||
380 | David Johnson wrote the original COFF support; Pace Willison did | |
381 | the original support for encapsulated COFF. | |
382 | ||
383 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
384 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
385 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris | |
386 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
387 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
388 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
389 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
390 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
391 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
392 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
393 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
394 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
395 | support. | |
396 | ||
397 | Rich Schaefer helped with support of SunOS shared libraries. | |
398 | ||
399 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
400 | several machine instruction sets. | |
401 | ||
402 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped | |
403 | develop remote debugging. Intel Corporation and Wind River Systems | |
404 | contributed remote debugging modules for their products. | |
405 | ||
406 | Brian Fox is the author of the readline libraries providing | |
407 | command-line editing and command history. | |
408 | ||
409 | @node New Features, Sample Session, Summary, Top | |
410 | @unnumbered New Features since _GDBN__ version 3.5 | |
411 | ||
412 | @table @emph | |
413 | @item Targets | |
414 | Using the new command @code{target}, you can select at runtime whether | |
415 | you are debugging local files, local processes, standalone systems over | |
416 | a serial port, realtime systems over a TCP/IP connection, etc. | |
417 | Internally, _GDBN__ now uses a function vector to mediate access to | |
418 | different targets; if you need to add your own support for a remote | |
419 | protocol, this makes it much easier. | |
420 | ||
421 | @item Watchpoints | |
422 | _GDBN__ now sports watchpoints as well as breakpoints. You can use a | |
423 | watchpoint to stop execution whenever the value of an expression | |
424 | changes, without having to predict a particular place in your program | |
425 | where this may happen. | |
426 | ||
427 | @item Object Code Formats | |
428 | _GDBN__ uses a new scheme called Binary File Descriptors (BFD) to permit | |
429 | it to switch dynamically, without reconfiguration or recompilation, | |
430 | between different object-file formats. Formats currently supported are | |
431 | COFF, a.out, and the Intel 960 b.out; files may be read as .o's, archive | |
432 | libraries, or core dumps. BFD is available as a subroutine library so | |
433 | that other programs may take advantage of it, and the other GNU binary | |
434 | utilities are being converted to use it. | |
435 | ||
436 | @item Configuration | |
437 | Compile-time configuration (to select a particular architecture and | |
7463aadd | 438 | operating system) is much easier. The script @code{configure} now |
70b88761 RP |
439 | handles specification of separate host and target configurations. |
440 | ||
441 | @item Interaction | |
442 | The user interface to _GDBN__'s control variables has been simplified | |
443 | and consolidated in two commands, @code{set} and @code{show}. Output | |
444 | lines are now broken at readable places, rather than overflowing onto | |
445 | the next line. You can suppress output of machine-level addresses, | |
446 | displaying only source language information. | |
447 | ||
448 | ||
449 | @item Source Language | |
450 | _GDBN__ now has limited support for C++ exception handling: _GDBN__ can | |
451 | break when an exception is raised, before the stack is peeled back to | |
452 | the exception handler's context. | |
453 | ||
454 | @item Command Rationalization | |
455 | Many _GDBN__ commands have been renamed to make them easier to remember | |
456 | and use. In particular, the subcommands of @code{info} and | |
457 | @code{show}/@code{set} are grouped to make the former refer to the state | |
458 | of your program, and the latter refer to the state of _GDBN__ itself. | |
459 | @xref{Renamed Commands}, for details on what commands were renamed. | |
460 | ||
461 | @item Ports | |
462 | _GDBN__ has been ported to the following new architectures: AT&T 3b1, | |
463 | Acorn RISC machine, HP300 running HPUX, big- and little-endian MIPS | |
464 | machines, Motorola 88k, Sun 386i, and Sun 3 running SunOS 4. In | |
465 | addition, the following are supported as targets only: AMD 29k, Intel | |
466 | 960, and Wind River's VxWorks. | |
467 | ||
468 | @item Shared Libraries | |
469 | _GDBN__ 4.0 supports SunOS shared libraries. | |
470 | ||
471 | @item Work in Progress | |
472 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
473 | support. | |
474 | ||
475 | @end table | |
476 | ||
477 | @node Sample Session, Invocation, New Features, Top | |
478 | @chapter A Sample _GDBN__ Session | |
479 | ||
480 | You can use this manual at your leisure to read all about _GDBN__. | |
481 | However, a handful of commands are enough to get started using the | |
482 | debugger. This chapter illustrates these commands. | |
483 | ||
484 | @iftex | |
485 | In this sample session, we emphasize user input like this: @i{input}, | |
486 | to make it easier to pick out from the surrounding output. | |
487 | @end iftex | |
488 | ||
489 | @c FIXME: this example may not be appropriate for some configs, where | |
490 | @c FIXME...primary interest is in remote use. | |
491 | _0__ | |
492 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
493 | processor) exhibits the following bug: sometimes, when we change its | |
494 | quote strings from the default, the commands used to capture one macro's | |
495 | definition in another stop working. In the following short @code{m4} | |
496 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
497 | then use the @code{m4} builtin @code{defn} to define @code{bar} as the | |
498 | same thing. However, when we change the open quote string to | |
499 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
500 | procedure fails to define a new synonym @code{baz}: | |
501 | ||
502 | @smallexample | |
503 | $ @i{cd gnu/m4} | |
504 | $ @i{./m4} | |
505 | @i{define(foo,0000)} | |
506 | ||
507 | @i{foo} | |
508 | 0000 | |
509 | @i{define(bar,defn(`foo'))} | |
510 | ||
511 | @i{bar} | |
512 | 0000 | |
513 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
514 | ||
515 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
516 | @i{baz} | |
517 | @i{C-d} | |
518 | m4: End of input: 0: fatal error: EOF in string | |
519 | @end smallexample | |
520 | ||
521 | @noindent | |
522 | Let's use _GDBN__ to try to see what's going on. | |
523 | ||
524 | @smallexample | |
525 | $ @i{_GDBP__ m4} | |
526 | Reading symbol data from m4...done. | |
527 | (_GDBP__) | |
528 | @end smallexample | |
529 | ||
530 | @noindent | |
531 | _GDBN__ reads only enough symbol data to know where to find the rest | |
532 | when needed; as a result, the first prompt comes up very quickly. We | |
533 | then tell _GDBN__ to use a narrower display width than usual, so | |
534 | that examples will fit in this manual. | |
535 | ||
536 | @smallexample | |
537 | (_GDBP__) @i{set width 70} | |
538 | @end smallexample | |
539 | ||
540 | @noindent | |
541 | Let's see how the @code{m4} builtin @code{changequote} works. | |
542 | Having looked at the source, we know the relevant subroutine is | |
543 | @code{m4_changequote}, so we set a breakpoint there with _GDBN__'s | |
544 | @code{break} command. | |
545 | ||
546 | @smallexample | |
547 | (_GDBP__) @i{break m4_changequote} | |
548 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. | |
549 | @end smallexample | |
550 | ||
551 | @noindent | |
552 | Using the @code{run} command, we start @code{m4} running under _GDBN__ | |
553 | control; as long as control does not reach the @code{m4_changequote} | |
554 | subroutine, the program runs as usual: | |
555 | ||
556 | @smallexample | |
557 | (_GDBP__) @i{run} | |
558 | Starting program: /work/Editorial/gdb/gnu/m4/m4 | |
559 | @i{define(foo,0000)} | |
560 | ||
561 | @i{foo} | |
562 | 0000 | |
563 | @end smallexample | |
564 | ||
565 | @noindent | |
566 | To trigger the breakpoint, we call @code{changequote}. _GDBN__ | |
567 | suspends execution of @code{m4}, displaying information about the | |
568 | context where it stops. | |
569 | ||
570 | @smallexample | |
571 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
572 | ||
573 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) at builtin.c:879 | |
574 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3)) | |
575 | @end smallexample | |
576 | ||
577 | @noindent | |
578 | Now we use the command @code{n} (@code{next}) to advance execution to | |
579 | the next line of the current function. | |
580 | ||
581 | @smallexample | |
582 | (_GDBP__) @i{n} | |
583 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1]) : nil, | |
584 | @end smallexample | |
585 | ||
586 | @noindent | |
587 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
588 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
589 | @code{step} goes to the next line to be executed in @emph{any} | |
590 | subroutine, so it steps into @code{set_quotes}. | |
591 | ||
592 | @smallexample | |
593 | (_GDBP__) @i{s} | |
594 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
595 | at input.c:530 | |
596 | 530 if (lquote != def_lquote) | |
597 | @end smallexample | |
598 | ||
599 | @noindent | |
600 | The summary display showing the subroutine where @code{m4} is now | |
601 | suspended (and its arguments) is called a stack frame display. We can | |
602 | use the @code{backtrace} command (which can also be spelled @code{bt}), | |
603 | to see where we are in the stack: it displays a stack frame for each | |
604 | active subroutine. | |
605 | ||
606 | @smallexample | |
607 | (_GDBP__) @i{bt} | |
608 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
609 | at input.c:530 | |
610 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) at builtin.c:882 | |
611 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 | |
612 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
613 | at macro.c:71 | |
614 | #4 0x79dc in expand_input () at macro.c:40 | |
615 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
616 | @end smallexample | |
617 | ||
618 | @noindent | |
619 | Let's step through a few more lines to see what happens. The first two | |
620 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
621 | falling into the @code{xstrdup} subroutine. | |
622 | @smallexample | |
623 | (_GDBP__) @i{s} | |
624 | 0x3b5c 532 if (rquote != def_rquote) | |
625 | (_GDBP__) @i{s} | |
626 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? def_lquote :\ | |
627 | xstrdup(lq); | |
628 | (_GDBP__) @i{n} | |
629 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote : xstrdup\ | |
630 | (rq); | |
631 | (_GDBP__) @i{n} | |
632 | 538 len_lquote = strlen(rquote); | |
633 | @end smallexample | |
634 | ||
635 | @noindent | |
636 | The last line displayed looks a little odd; let's examine the variables | |
637 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
638 | and right quotes we specified. We can use the command @code{p} | |
639 | (@code{print}) to see their values. | |
640 | ||
641 | @smallexample | |
642 | (_GDBP__) @i{p lquote} | |
643 | $1 = 0x35d40 "<QUOTE>" | |
644 | (_GDBP__) @i{p rquote} | |
645 | $2 = 0x35d50 "<UNQUOTE>" | |
646 | @end smallexample | |
647 | ||
648 | @noindent | |
649 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
650 | Let's look at some context; we can display ten lines of source | |
651 | surrounding the current line, with the @code{l} (@code{list}) command. | |
652 | ||
653 | @smallexample | |
654 | (_GDBP__) @i{l} | |
655 | 533 xfree(rquote); | |
656 | 534 | |
657 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote : xstrdup\ | |
658 | (lq); | |
659 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote : xstrdup\ | |
660 | (rq); | |
661 | 537 | |
662 | 538 len_lquote = strlen(rquote); | |
663 | 539 len_rquote = strlen(lquote); | |
664 | 540 @} | |
665 | 541 | |
666 | 542 void | |
667 | @end smallexample | |
668 | ||
669 | @noindent | |
670 | Let's step past the two lines that set @code{len_lquote} and | |
671 | @code{len_rquote}, and then examine the values of those variables. | |
672 | ||
673 | @smallexample | |
674 | (_GDBP__) @i{n} | |
675 | 539 len_rquote = strlen(lquote); | |
676 | (_GDBP__) @i{n} | |
677 | 540 @} | |
678 | (_GDBP__) @i{p len_lquote} | |
679 | $3 = 9 | |
680 | (_GDBP__) @i{p len_rquote} | |
681 | $4 = 7 | |
682 | @end smallexample | |
683 | ||
684 | @noindent | |
685 | That certainly looks wrong, assuming @code{len_lquote} and | |
686 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
687 | @code{rquote} respectively. Let's try setting them to better values. | |
688 | We can use the @code{p} command for this, since it'll print the value of | |
689 | any expression---and that expression can include subroutine calls and | |
690 | assignments. | |
691 | ||
692 | @smallexample | |
693 | (_GDBP__) p len_lquote=strlen(lquote) | |
694 | $5 = 7 | |
695 | (_GDBP__) p len_rquote=strlen(rquote) | |
696 | $6 = 9 | |
697 | @end smallexample | |
698 | ||
699 | @noindent | |
700 | Let's see if that fixes the problem of using the new quotes with the | |
701 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
702 | executing with the @code{c} (@code{continue}) command, and then try the | |
703 | example that caused trouble initially: | |
704 | ||
705 | @smallexample | |
706 | (_GDBP__) @i{c} | |
707 | Continuing. | |
708 | ||
709 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
710 | ||
711 | baz | |
712 | 0000 | |
713 | @end smallexample | |
714 | ||
715 | @noindent | |
716 | Success! The new quotes now work just as well as the default ones. The | |
717 | problem seems to have been just the two typos defining the wrong | |
718 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
719 | ||
720 | @smallexample | |
721 | @i{C-d} | |
722 | Program exited normally. | |
723 | @end smallexample | |
724 | ||
725 | @noindent | |
726 | The message @samp{Program exited normally.} is from _GDBN__; it | |
727 | indicates @code{m4} has finished executing. We can end our _GDBN__ | |
728 | session with the _GDBN__ @code{quit} command. | |
729 | ||
730 | @smallexample | |
731 | (_GDBP__) @i{quit} | |
70b88761 RP |
732 | _1__@end smallexample |
733 | ||
734 | @node Invocation, Commands, Sample Session, Top | |
735 | @chapter Getting In and Out of _GDBN__ | |
736 | ||
737 | @menu | |
738 | * Starting _GDBN__:: Starting _GDBN__ | |
739 | * Leaving _GDBN__:: Leaving _GDBN__ | |
740 | * Shell Commands:: Shell Commands | |
741 | @end menu | |
742 | ||
743 | @node Starting _GDBN__, Leaving _GDBN__, Invocation, Invocation | |
744 | @section Starting _GDBN__ | |
745 | ||
746 | _GDBN__ is invoked with the shell command @code{_GDBP__}. Once started, | |
747 | it reads commands from the terminal until you tell it to exit. | |
748 | ||
749 | You can run @code{_GDBP__} with no arguments or options; but the most | |
750 | usual way to start _GDBN__ is with one argument or two, specifying an | |
751 | executable program as the argument: | |
752 | @example | |
753 | _GDBP__ program | |
754 | @end example | |
755 | @noindent | |
756 | You can also start with both an executable program and a core file specified: | |
757 | @example | |
758 | _GDBP__ program core | |
759 | @end example | |
760 | ||
761 | @noindent | |
762 | You can further control how _GDBN__ starts up by using command-line | |
763 | options. _GDBN__ itself can remind you of the options available: | |
764 | @example | |
765 | _GDBP__ -help | |
766 | @end example | |
767 | @noindent | |
768 | will display all available options and briefly describe their use | |
769 | (@samp{_GDBP__ -h} is a shorter equivalent). | |
770 | ||
771 | All options and command line arguments you give are processed | |
772 | in sequential order. The order makes a difference when the | |
773 | @samp{-x} option is used. | |
774 | ||
775 | @menu | |
776 | * File Options:: Choosing Files | |
777 | * Mode Options:: Choosing Modes | |
778 | _if__(!_GENERIC__) | |
779 | _include__(gdbinv-m.m4)_dnl__ | |
780 | _fi__(!_GENERIC__) | |
781 | @end menu | |
782 | ||
783 | @node File Options, Mode Options, Starting _GDBN__, Starting _GDBN__ | |
784 | @subsection Choosing Files | |
785 | ||
786 | As shown above, any arguments other than options specify an executable | |
787 | file and core file; that is, the first argument encountered with no | |
788 | associated option flag is equivalent to a @samp{-se} option, and the | |
789 | second, if any, is equivalent to a @samp{-c} option. Many options have | |
790 | both long and short forms; both are shown here. The long forms are also | |
791 | recognized if you truncate them, so long as enough of the option is | |
792 | present to be unambiguous. (If you prefer, you can flag option | |
793 | arguments with @samp{+} rather than @samp{-}, though we illustrate the | |
794 | more usual convention.) | |
795 | ||
796 | @table @code | |
797 | @item -symbols=@var{file} | |
798 | @itemx -s @var{file} | |
799 | Read symbol table from file @var{file}. | |
800 | ||
801 | @item -exec=@var{file} | |
802 | @itemx -e @var{file} | |
803 | Use file @var{file} as the executable file to execute when | |
804 | appropriate, and for examining pure data in conjunction with a core | |
805 | dump. | |
806 | ||
807 | @item -se @var{file} | |
808 | Read symbol table from file @var{file} and use it as the executable | |
809 | file. | |
810 | ||
811 | @item -core=@var{file} | |
812 | @itemx -c @var{file} | |
813 | Use file @var{file} as a core dump to examine. | |
814 | ||
815 | @item -command=@var{file} | |
816 | @itemx -x @var{file} | |
817 | Execute _GDBN__ commands from file @var{file}. @xref{Command Files}. | |
818 | ||
819 | @item -directory=@var{directory} | |
820 | @itemx -d @var{directory} | |
821 | Add @var{directory} to the path to search for source files. | |
822 | @end table | |
823 | ||
824 | _if__(!_GENERIC__) | |
825 | @node Mode Options, i960-Nindy Remote, File Options, Starting _GDBN__ | |
826 | _fi__(!_GENERIC__) | |
827 | _if__(_GENERIC__) | |
828 | @node Mode Options, , File Options, Starting _GDBN__ | |
829 | _fi__(_GENERIC__) | |
830 | @subsection Choosing Modes | |
831 | ||
832 | @table @code | |
833 | @item -nx | |
834 | @itemx -n | |
835 | Do not execute commands from any @file{_GDBINIT__} initialization files. | |
836 | Normally, the commands in these files are executed after all the | |
837 | command options and arguments have been processed. @xref{Command | |
838 | Files}. | |
839 | ||
840 | @item -quiet | |
841 | @itemx -q | |
842 | ``Quiet''. Do not print the introductory and copyright messages. These | |
843 | messages are also suppressed in batch mode, or if an executable file name is | |
844 | specified on the _GDBN__ command line. | |
845 | ||
846 | @item -batch | |
847 | Run in batch mode. Exit with status @code{0} after processing all the command | |
848 | files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited). | |
849 | Exit with nonzero status if an error occurs in executing the _GDBN__ | |
850 | commands in the command files. | |
851 | ||
852 | Batch mode may be useful for running _GDBN__ as a filter, for example to | |
853 | download and run a program on another computer; in order to make this | |
854 | more useful, the message | |
855 | @example | |
856 | Program exited normally. | |
857 | @end example | |
858 | @noindent | |
859 | (which is ordinarily issued whenever a program running under _GDBN__ control | |
860 | terminates) is not issued when running in batch mode. | |
861 | ||
862 | @item -cd @var{directory} | |
863 | Run _GDBN__ using @var{directory} as its working directory, | |
864 | instead of the current directory. | |
865 | ||
866 | @item -fullname | |
867 | @itemx -f | |
868 | Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ | |
869 | to output the full file name and line number in a standard, | |
870 | recognizable fashion each time a stack frame is displayed (which | |
871 | includes each time the program stops). This recognizable format looks | |
872 | like two @samp{\032} characters, followed by the file name, line number | |
873 | and character position separated by colons, and a newline. The | |
874 | Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as | |
875 | a signal to display the source code for the frame. | |
876 | ||
877 | @item -b @var{bps} | |
878 | Set the line speed (baud rate or bits per second) of any serial | |
879 | interface used by _GDBN__ for remote debugging. | |
880 | ||
881 | @item -tty @var{device} | |
882 | Run using @var{device} for your program's standard input and output. | |
883 | @c FIXME: kingdon thinks there's more to -tty. Investigate. | |
884 | @end table | |
885 | ||
886 | _if__(!_GENERIC__) | |
887 | _include__(gdbinv-s.m4) | |
888 | _fi__(!_GENERIC__) | |
889 | ||
890 | @node Leaving _GDBN__, Shell Commands, Starting _GDBN__, Invocation | |
891 | @section Leaving _GDBN__ | |
892 | @cindex exiting _GDBN__ | |
893 | @table @code | |
894 | @item quit | |
895 | @kindex quit | |
896 | @kindex q | |
897 | To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type | |
898 | an end-of-file character (usually @kbd{C-d}). | |
899 | @end table | |
900 | ||
901 | @cindex interrupt | |
902 | An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather | |
903 | will terminate the action of any _GDBN__ command that is in progress and | |
904 | return to _GDBN__ command level. It is safe to type the interrupt | |
905 | character at any time because _GDBN__ does not allow it to take effect | |
906 | until a time when it is safe. | |
907 | ||
908 | If you've been using _GDBN__ to control an attached process or device, | |
909 | you can release it with the @code{detach} command; @pxref{Attach}. | |
910 | ||
911 | @node Shell Commands, , Leaving _GDBN__, Invocation | |
912 | @section Shell Commands | |
913 | If you need to execute occasional shell commands during your | |
914 | debugging session, there's no need to leave or suspend _GDBN__; you can | |
915 | just use the @code{shell} command. | |
916 | ||
917 | @table @code | |
918 | @item shell @var{command string} | |
919 | @kindex shell | |
920 | @cindex shell escape | |
921 | Directs _GDBN__ to invoke an inferior shell to execute @var{command | |
922 | string}. If it exists, the environment variable @code{SHELL} is used | |
923 | for the name of the shell to run. Otherwise _GDBN__ uses | |
924 | @code{/bin/sh}. | |
925 | @end table | |
926 | ||
927 | The utility @code{make} is often needed in development environments. | |
928 | You don't have to use the @code{shell} command for this purpose in _GDBN__: | |
929 | ||
930 | @table @code | |
931 | @item make @var{make-args} | |
932 | @kindex make | |
933 | @cindex calling make | |
934 | Causes _GDBN__ to execute an inferior @code{make} program with the specified | |
935 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
936 | @end table | |
937 | ||
938 | @node Commands, Running, Invocation, Top | |
939 | @chapter _GDBN__ Commands | |
940 | ||
941 | @menu | |
942 | * Command Syntax:: Command Syntax | |
943 | * Help:: Getting Help | |
944 | @end menu | |
945 | ||
946 | @node Command Syntax, Help, Commands, Commands | |
947 | @section Command Syntax | |
948 | A _GDBN__ command is a single line of input. There is no limit on how long | |
949 | it can be. It starts with a command name, which is followed by arguments | |
950 | whose meaning depends on the command name. For example, the command | |
951 | @code{step} accepts an argument which is the number of times to step, | |
952 | as in @samp{step 5}. You can also use the @code{step} command with | |
953 | no arguments. Some command names do not allow any arguments. | |
954 | ||
955 | @cindex abbreviation | |
956 | _GDBN__ command names may always be truncated if that abbreviation is | |
957 | unambiguous. Other possible command abbreviations are listed in the | |
958 | documentation for individual commands. In some cases, even ambiguous | |
959 | abbreviations are allowed; for example, @code{s} is specially defined as | |
960 | equivalent to @code{step} even though there are other commands whose | |
961 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 962 | arguments to the @code{help} command. |
70b88761 RP |
963 | |
964 | @cindex repeating commands | |
965 | @kindex RET | |
966 | A blank line as input to _GDBN__ (typing just @key{RET}) means to | |
967 | repeat the previous command. Certain commands (for example, @code{run}) | |
968 | will not repeat this way; these are commands for which unintentional | |
969 | repetition might cause trouble and which you are unlikely to want to | |
970 | repeat. | |
971 | ||
972 | The @code{list} and @code{x} commands, when you repeat them with | |
973 | @key{RET}, construct new arguments rather than repeating | |
974 | exactly as typed. This permits easy scanning of source or memory. | |
975 | ||
976 | @kindex # | |
977 | @cindex comment | |
978 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
979 | This is useful mainly in command files (@xref{Command Files}). | |
980 | ||
981 | @node Help, , Command Syntax, Commands | |
982 | @section Getting Help | |
983 | @cindex online documentation | |
984 | @kindex help | |
985 | You can always ask _GDBN__ itself for information on its commands, using the | |
986 | command @code{help}. | |
987 | ||
988 | @table @code | |
989 | @item help | |
990 | @itemx h | |
991 | @kindex h | |
992 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
993 | display a short list of named classes of commands: | |
994 | @smallexample | |
995 | (_GDBP__) help | |
996 | List of classes of commands: | |
997 | ||
998 | running -- Running the program | |
999 | stack -- Examining the stack | |
1000 | data -- Examining data | |
1001 | breakpoints -- Making program stop at certain points | |
1002 | files -- Specifying and examining files | |
1003 | status -- Status inquiries | |
1004 | support -- Support facilities | |
1005 | user-defined -- User-defined commands | |
1006 | aliases -- Aliases of other commands | |
1007 | obscure -- Obscure features | |
1008 | ||
1009 | Type "help" followed by a class name for a list of commands in that class. | |
1010 | Type "help" followed by command name for full documentation. | |
1011 | Command name abbreviations are allowed if unambiguous. | |
1012 | (_GDBP__) | |
1013 | @end smallexample | |
1014 | ||
1015 | @item help @var{class} | |
1016 | Using one of the general help classes as an argument, you can get a | |
1017 | list of the individual commands in that class. For example, here is the | |
1018 | help display for the class @code{status}: | |
1019 | @smallexample | |
1020 | (_GDBP__) help status | |
1021 | Status inquiries. | |
1022 | ||
1023 | List of commands: | |
1024 | ||
1025 | show -- Generic command for showing things set with "set" | |
1026 | info -- Generic command for printing status | |
1027 | ||
1028 | Type "help" followed by command name for full documentation. | |
1029 | Command name abbreviations are allowed if unambiguous. | |
1030 | (_GDBP__) | |
1031 | @end smallexample | |
1032 | ||
1033 | @item help @var{command} | |
1034 | With a command name as @code{help} argument, _GDBN__ will display a | |
1035 | short paragraph on how to use that command. | |
1036 | @end table | |
1037 | ||
1038 | In addition to @code{help}, you can use the _GDBN__ commands @code{info} | |
1039 | and @code{show} to inquire about the state of your program, or the state | |
1040 | of _GDBN__ itself. Each command supports many topics of inquiry; this | |
1041 | manual introduces each of them in the appropriate context. The listings | |
1042 | under @code{info} and under @code{show} in the Index point to | |
1043 | all the sub-commands. | |
1044 | @c FIXME: @pxref{Index} used to be here, but even though it shows up in | |
1045 | @c FIXME...the 'aux' file with a pageno the xref can't find it. | |
1046 | ||
1047 | @c @group | |
1048 | @table @code | |
1049 | @item info | |
1050 | @kindex info | |
1051 | @kindex i | |
1052 | This command (abbreviated @code{i}) is for describing the state of your | |
1053 | program; for example, it can list the arguments given to your program | |
1054 | (@code{info args}), the registers currently in use (@code{info | |
1055 | registers}), or the breakpoints you've set (@code{info breakpoints}). | |
1056 | You can get a complete list of the @code{info} sub-commands with | |
1057 | @w{@code{help info}}. | |
1058 | ||
1059 | @kindex show | |
1060 | @item show | |
1061 | In contrast, @code{show} is for describing the state of _GDBN__ itself. | |
1062 | You can change most of the things you can @code{show}, by using the | |
1063 | related command @code{set}; for example, you can control what number | |
1064 | system is used for displays with @code{set radix}, or simply inquire | |
1065 | which is currently in use with @code{show radix}. | |
1066 | ||
1067 | @kindex info set | |
1068 | To display all the settable parameters and their current | |
1069 | values, you can use @code{show} with no arguments; you may also use | |
1070 | @code{info set}. Both commands produce the same display. | |
1071 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1072 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1073 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1074 | @end table | |
1075 | @c @end group | |
1076 | ||
1077 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1078 | exceptional in lacking corresponding @code{set} commands: | |
1079 | ||
1080 | @table @code | |
1081 | @kindex show version | |
1082 | @item show version | |
1083 | Show what version of _GDBN__ is running. You should include this | |
1084 | information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are | |
1085 | in use at your site, you may occasionally want to make sure what version | |
1086 | of _GDBN__ you're running; as _GDBN__ evolves, new commands are | |
1087 | introduced, and old ones may wither away. The version number is also | |
1088 | announced when you start _GDBN__ with no arguments. | |
1089 | ||
1090 | @kindex show copying | |
1091 | @item show copying | |
1092 | Display information about permission for copying _GDBN__. | |
1093 | ||
1094 | @kindex show warranty | |
1095 | @item show warranty | |
1096 | Display the GNU ``NO WARRANTY'' statement. | |
1097 | @end table | |
1098 | ||
1099 | @node Running, Stopping, Commands, Top | |
1100 | @chapter Running Programs Under _GDBN__ | |
1101 | ||
1102 | @menu | |
1103 | * Compilation:: Compiling for Debugging | |
1104 | * Starting:: Starting your Program | |
1105 | * Arguments:: Your Program's Arguments | |
1106 | * Environment:: Your Program's Environment | |
1107 | * Working Directory:: Your Program's Working Directory | |
1108 | * Input/Output:: Your Program's Input and Output | |
1109 | * Attach:: Debugging an Already-Running Process | |
1110 | * Kill Process:: Killing the Child Process | |
1111 | @end menu | |
1112 | ||
1113 | @node Compilation, Starting, Running, Running | |
1114 | @section Compiling for Debugging | |
1115 | ||
1116 | In order to debug a program effectively, you need to generate | |
1117 | debugging information when you compile it. This debugging information | |
1118 | is stored in the object file; it describes the data type of each | |
1119 | variable or function and the correspondence between source line numbers | |
1120 | and addresses in the executable code. | |
1121 | ||
1122 | To request debugging information, specify the @samp{-g} option when you run | |
1123 | the compiler. | |
1124 | ||
1125 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1126 | options together. Using those compilers, you cannot generate optimized | |
1127 | executables containing debugging information. | |
1128 | ||
1129 | The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it | |
1130 | possible to debug optimized code. We recommend that you @emph{always} use | |
1131 | @samp{-g} whenever you compile a program. You may think the program is | |
1132 | correct, but there's no sense in pushing your luck. | |
1133 | ||
1134 | Some things do not work as well with @samp{-g -O} as with just | |
1135 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1136 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1137 | please report it as a bug (including a test case!). | |
1138 | ||
1139 | Older versions of the GNU C compiler permitted a variant option | |
1140 | @samp{-gg} for debugging information. _GDBN__ no longer supports this | |
1141 | format; if your GNU C compiler has this option, do not use it. | |
1142 | ||
1143 | @ignore | |
1144 | @comment As far as I know, there are no cases in which _GDBN__ will | |
1145 | @comment produce strange output in this case. (but no promises). | |
1146 | If your program includes archives made with the @code{ar} program, and | |
1147 | if the object files used as input to @code{ar} were compiled without the | |
1148 | @samp{-g} option and have names longer than 15 characters, _GDBN__ will get | |
1149 | confused reading the program's symbol table. No error message will be | |
1150 | given, but _GDBN__ may behave strangely. The reason for this problem is a | |
1151 | deficiency in the Unix archive file format, which cannot represent file | |
1152 | names longer than 15 characters. | |
1153 | ||
1154 | To avoid this problem, compile the archive members with the @samp{-g} | |
1155 | option or use shorter file names. Alternatively, use a version of GNU | |
1156 | @code{ar} dated more recently than August 1989. | |
1157 | @end ignore | |
1158 | ||
1159 | ||
1160 | @node Starting, Arguments, Compilation, Running | |
1161 | @section Starting your Program | |
1162 | @cindex starting | |
1163 | @cindex running | |
1164 | @table @code | |
1165 | @item run | |
1166 | @itemx r | |
1167 | @kindex run | |
7463aadd RP |
1168 | Use the @code{run} command to start your program under _GDBN__. You |
1169 | must first specify the program name | |
1170 | _if__(_VXWORKS__) | |
1171 | (except on VxWorks) | |
70b88761 | 1172 | _fi__(_VXWORKS__) |
7463aadd | 1173 | with an argument to _GDBN__ |
70b88761 | 1174 | (@pxref{Invocation}), or using the @code{file} or @code{exec-file} |
7463aadd RP |
1175 | command (@pxref{Files}). |
1176 | @refill | |
70b88761 RP |
1177 | @end table |
1178 | ||
1179 | On targets that support processes, @code{run} creates an inferior | |
1180 | process and makes that process run your program. On other targets, | |
1181 | @code{run} jumps to the start of the program. | |
1182 | ||
1183 | The execution of a program is affected by certain information it | |
1184 | receives from its superior. _GDBN__ provides ways to specify this | |
1185 | information, which you must do @i{before} starting the program. (You | |
1186 | can change it after starting the program, but such changes will only affect | |
1187 | the program the next time you start it.) This information may be | |
1188 | divided into four categories: | |
1189 | ||
1190 | @table @asis | |
1191 | @item The @i{arguments.} | |
1192 | You specify the arguments to give your program as the arguments of the | |
1193 | @code{run} command. If a shell is available on your target, the shell | |
1194 | is used to pass the arguments, so that you may use normal conventions | |
1195 | (such as wildcard expansion or variable substitution) in | |
1196 | describing the arguments. In Unix systems, you can control which shell | |
1197 | is used with the @code{SHELL} environment variable. @xref{Arguments}.@refill | |
1198 | ||
1199 | @item The @i{environment.} | |
1200 | Your program normally inherits its environment from _GDBN__, but you can | |
1201 | use the _GDBN__ commands @code{set environment} and @code{unset | |
1202 | environment} to change parts of the environment that will be given to | |
1203 | the program. @xref{Environment}.@refill | |
1204 | ||
1205 | @item The @i{working directory.} | |
1206 | Your program inherits its working directory from _GDBN__. You can set | |
1207 | _GDBN__'s working directory with the @code{cd} command in _GDBN__. | |
1208 | @xref{Working Directory}. | |
1209 | ||
1210 | @item The @i{standard input and output.} | |
1211 | Your program normally uses the same device for standard input and | |
1212 | standard output as _GDBN__ is using. You can redirect input and output | |
1213 | in the @code{run} command line, or you can use the @code{tty} command to | |
1214 | set a different device for your program. | |
1215 | @xref{Input/Output}. | |
1216 | @end table | |
1217 | ||
1218 | When you issue the @code{run} command, your program begins to execute | |
1219 | immediately. @xref{Stopping}, for discussion of how to arrange for your | |
1220 | program to stop. Once your program has been started by the @code{run} | |
1221 | command (and then stopped), you may evaluate expressions that involve | |
1222 | calls to functions in the inferior, using the @code{print} or | |
1223 | @code{call} commands. @xref{Data}. | |
1224 | ||
1225 | If the modification time of your symbol file has changed since the last | |
1226 | time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and re-read | |
1227 | it. In this process, it tries to retain your current breakpoints. | |
1228 | ||
1229 | @node Arguments, Environment, Starting, Running | |
1230 | @section Your Program's Arguments | |
1231 | ||
1232 | @cindex arguments (to your program) | |
1233 | The arguments to your program can be specified by the arguments of the | |
1234 | @code{run} command. They are passed to a shell, which expands wildcard | |
1235 | characters and performs redirection of I/O, and thence to the program. | |
1236 | _GDBN__ uses the shell indicated by your environment variable | |
1237 | @code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}. | |
1238 | ||
1239 | @code{run} with no arguments uses the same arguments used by the previous | |
1240 | @code{run}, or those set by the @code{set args} command. | |
1241 | ||
1242 | @kindex set args | |
1243 | @table @code | |
1244 | @item set args | |
1245 | Specify the arguments to be used the next time your program is run. If | |
1246 | @code{set args} has no arguments, @code{run} will execute your program | |
1247 | with no arguments. Once you have run your program with arguments, | |
1248 | using @code{set args} before the next @code{run} is the only way to run | |
1249 | it again without arguments. | |
1250 | ||
1251 | @item show args | |
1252 | @kindex show args | |
1253 | Show the arguments to give your program when it is started. | |
1254 | @end table | |
1255 | ||
1256 | @node Environment, Working Directory, Arguments, Running | |
1257 | @section Your Program's Environment | |
1258 | ||
1259 | @cindex environment (of your program) | |
1260 | The @dfn{environment} consists of a set of environment variables and | |
1261 | their values. Environment variables conventionally record such things as | |
1262 | your user name, your home directory, your terminal type, and your search | |
1263 | path for programs to run. Usually you set up environment variables with | |
1264 | the shell and they are inherited by all the other programs you run. When | |
1265 | debugging, it can be useful to try running the program with a modified | |
1266 | environment without having to start _GDBN__ over again. | |
1267 | ||
1268 | @table @code | |
1269 | @item path @var{directory} | |
1270 | @kindex path | |
1271 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1272 | (the search path for executables), for both _GDBN__ and your program. | |
1273 | You may specify several directory names, separated by @samp{:} or | |
1274 | whitespace. If @var{directory} is already in the path, it is moved to | |
7463aadd RP |
1275 | the front, so it will be searched sooner. |
1276 | ||
1277 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1278 | working directory at the time _GDBN__ searches the path. If you use | |
1279 | @samp{.} instead, it refers to the directory where you executed the | |
1280 | @code{path} command. _GDBN__ fills in the current path where needed in | |
1281 | the @var{directory} argument, before adding it to the search path. | |
70b88761 RP |
1282 | @c 'path' is explicitly nonrepeatable, but RMS points out it's silly to |
1283 | @c document that, since repeating it would be a no-op. | |
1284 | ||
1285 | @item show paths | |
1286 | @kindex show paths | |
1287 | Display the list of search paths for executables (the @code{PATH} | |
1288 | environment variable). | |
1289 | ||
1290 | @item show environment @r{[}@var{varname}@r{]} | |
1291 | @kindex show environment | |
1292 | Print the value of environment variable @var{varname} to be given to | |
1293 | your program when it starts. If you don't supply @var{varname}, | |
1294 | print the names and values of all environment variables to be given to | |
1295 | your program. You can abbreviate @code{environment} as @code{env}. | |
1296 | ||
7463aadd | 1297 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 RP |
1298 | @kindex set environment |
1299 | Sets environment variable @var{varname} to @var{value}. The value | |
1300 | changes for your program only, not for _GDBN__ itself. @var{value} may | |
1301 | be any string; the values of environment variables are just strings, and | |
1302 | any interpretation is supplied by your program itself. The @var{value} | |
1303 | parameter is optional; if it is eliminated, the variable is set to a | |
1304 | null value. | |
1305 | @c "any string" here doesn't include leading, trailing | |
1306 | @c blanks. Gnu asks: does anyone care? | |
1307 | ||
1308 | For example, this command: | |
1309 | ||
1310 | @example | |
1311 | set env USER = foo | |
1312 | @end example | |
1313 | ||
1314 | @noindent | |
1315 | tells a Unix program, when subsequently run, that its user is named | |
1316 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1317 | are not actually required.) | |
1318 | ||
1319 | @item unset environment @var{varname} | |
1320 | @kindex unset environment | |
1321 | Remove variable @var{varname} from the environment to be passed to your | |
1322 | program. This is different from @samp{set env @var{varname} =}; | |
1323 | @code{unset environment} removes the variable from the environment, | |
1324 | rather than assigning it an empty value. | |
1325 | @end table | |
1326 | ||
1327 | @node Working Directory, Input/Output, Environment, Running | |
1328 | @section Your Program's Working Directory | |
1329 | ||
1330 | @cindex working directory (of your program) | |
1331 | Each time you start your program with @code{run}, it inherits its | |
1332 | working directory from the current working directory of _GDBN__. _GDBN__'s | |
1333 | working directory is initially whatever it inherited from its parent | |
1334 | process (typically the shell), but you can specify a new working | |
1335 | directory in _GDBN__ with the @code{cd} command. | |
1336 | ||
1337 | The _GDBN__ working directory also serves as a default for the commands | |
1338 | that specify files for _GDBN__ to operate on. @xref{Files}. | |
1339 | ||
1340 | @table @code | |
1341 | @item cd @var{directory} | |
1342 | @kindex cd | |
1343 | Set _GDBN__'s working directory to @var{directory}. | |
1344 | ||
1345 | @item pwd | |
1346 | @kindex pwd | |
1347 | Print _GDBN__'s working directory. | |
1348 | @end table | |
1349 | ||
1350 | @node Input/Output, Attach, Working Directory, Running | |
1351 | @section Your Program's Input and Output | |
1352 | ||
1353 | @cindex redirection | |
1354 | @cindex i/o | |
1355 | @cindex terminal | |
1356 | By default, the program you run under _GDBN__ does input and output to | |
1357 | the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to | |
1358 | its own terminal modes to interact with you, but it records the terminal | |
1359 | modes your program was using and switches back to them when you continue | |
1360 | running your program. | |
1361 | ||
1362 | @table @code | |
1363 | @item info terminal | |
1364 | @kindex info terminal | |
1365 | Displays _GDBN__'s recorded information about the terminal modes your | |
1366 | program is using. | |
1367 | @end table | |
1368 | ||
1369 | You can redirect the program's input and/or output using shell | |
1370 | redirection with the @code{run} command. For example, | |
1371 | ||
1372 | _0__@example | |
1373 | run > outfile | |
1374 | _1__@end example | |
1375 | ||
1376 | @noindent | |
1377 | starts the program, diverting its output to the file @file{outfile}. | |
1378 | ||
1379 | @kindex tty | |
1380 | @cindex controlling terminal | |
1381 | Another way to specify where the program should do input and output is | |
1382 | with the @code{tty} command. This command accepts a file name as | |
1383 | argument, and causes this file to be the default for future @code{run} | |
1384 | commands. It also resets the controlling terminal for the child | |
1385 | process, for future @code{run} commands. For example, | |
1386 | ||
1387 | @example | |
1388 | tty /dev/ttyb | |
1389 | @end example | |
1390 | ||
1391 | @noindent | |
1392 | directs that processes started with subsequent @code{run} commands | |
1393 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1394 | that as their controlling terminal. | |
1395 | ||
1396 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1397 | effect on the input/output device, but not its effect on the controlling | |
1398 | terminal. | |
1399 | ||
1400 | When you use the @code{tty} command or redirect input in the @code{run} | |
1401 | command, only the input @emph{for your program} is affected. The input | |
1402 | for _GDBN__ still comes from your terminal. | |
1403 | ||
1404 | @node Attach, Kill Process, Input/Output, Running | |
1405 | @section Debugging an Already-Running Process | |
1406 | @kindex attach | |
1407 | @cindex attach | |
1408 | ||
1409 | @table @code | |
1410 | @item attach @var{process-id} | |
1411 | This command | |
1412 | attaches to a running process---one that was started outside _GDBN__. | |
1413 | (@code{info files} will show your active targets.) The command takes as | |
1414 | argument a process ID. The usual way to find out the process-id of | |
1415 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
1416 | shell command. | |
1417 | ||
1418 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1419 | executing the command. | |
1420 | @end table | |
1421 | ||
1422 | To use @code{attach}, you must be debugging in an environment which | |
1423 | supports processes. You must also have permission to send the process a | |
1424 | signal, and it must have the same effective user ID as the _GDBN__ | |
1425 | process. | |
1426 | ||
1427 | When using @code{attach}, you should first use the @code{file} command | |
1428 | to specify the program running in the process and load its symbol table. | |
1429 | @xref{Files}. | |
1430 | ||
1431 | The first thing _GDBN__ does after arranging to debug the specified | |
1432 | process is to stop it. You can examine and modify an attached process | |
1433 | with all the _GDBN__ commands that are ordinarily available when you start | |
1434 | processes with @code{run}. You can insert breakpoints; you can step and | |
1435 | continue; you can modify storage. If you would rather the process | |
1436 | continue running, you may use the @code{continue} command after | |
1437 | attaching _GDBN__ to the process. | |
1438 | ||
1439 | @table @code | |
1440 | @item detach | |
1441 | @kindex detach | |
1442 | When you have finished debugging the attached process, you can use the | |
1443 | @code{detach} command to release it from _GDBN__'s control. Detaching | |
1444 | the process continues its execution. After the @code{detach} command, | |
1445 | that process and _GDBN__ become completely independent once more, and you | |
1446 | are ready to @code{attach} another process or start one with @code{run}. | |
1447 | @code{detach} will not repeat if you press @key{RET} again after | |
1448 | executing the command. | |
1449 | @end table | |
1450 | ||
1451 | If you exit _GDBN__ or use the @code{run} command while you have an attached | |
1452 | process, you kill that process. By default, you will be asked for | |
1453 | confirmation if you try to do either of these things; you can control | |
1454 | whether or not you need to confirm by using the @code{set confirm} command | |
1455 | (@pxref{Messages/Warnings}). | |
1456 | ||
1457 | @node Kill Process, , Attach, Running | |
1458 | @c @group | |
1459 | @section Killing the Child Process | |
1460 | ||
1461 | @table @code | |
1462 | @item kill | |
1463 | @kindex kill | |
1464 | Kill the child process in which your program is running under _GDBN__. | |
1465 | @end table | |
1466 | ||
1467 | This command is useful if you wish to debug a core dump instead of a | |
1468 | running process. _GDBN__ ignores any core dump file while your program | |
1469 | is running. | |
1470 | @c @end group | |
1471 | ||
1472 | On some operating systems, a program can't be executed outside _GDBN__ | |
1473 | while you have breakpoints set on it inside _GDBN__. You can use the | |
1474 | @code{kill} command in this situation to permit running the program | |
1475 | outside the debugger. | |
1476 | ||
1477 | The @code{kill} command is also useful if you wish to recompile and | |
1478 | relink the program, since on many systems it is impossible to modify an | |
1479 | executable file while it is running in a process. In this case, when you | |
1480 | next type @code{run}, _GDBN__ will notice that the file has changed, and | |
1481 | will re-read the symbol table (while trying to preserve your current | |
1482 | breakpoint settings). | |
1483 | ||
1484 | @node Stopping, Stack, Running, Top | |
1485 | @chapter Stopping and Continuing | |
1486 | ||
1487 | The principal purpose of using a debugger is so that you can stop your | |
1488 | program before it terminates; or so that, if the program runs into | |
1489 | trouble, you can investigate and find out why. | |
1490 | ||
1491 | Inside _GDBN__, your program may stop for any of several reasons, such | |
1492 | as a signal, a breakpoint, or reaching a new line after a _GDBN__ | |
1493 | command such as @code{step}. You may then examine and change | |
1494 | variables, set new breakpoints or remove old ones, and then continue | |
1495 | execution. Usually, the messages shown by _GDBN__ provide ample | |
1496 | explanation of the status of your program---but you can also explicitly | |
1497 | request this information at any time. | |
1498 | ||
1499 | @table @code | |
1500 | @item info program | |
1501 | @kindex info program | |
1502 | Display information about the status of your program: whether it is | |
1503 | running or not, what process it is, and why it stopped. | |
1504 | @end table | |
1505 | ||
1506 | @menu | |
1507 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions | |
7463aadd | 1508 | * Stepping and Continuing:: Stepping and Continuing |
70b88761 RP |
1509 | * Signals:: Signals |
1510 | @end menu | |
1511 | ||
1512 | @node Breakpoints, Stepping, Stopping, Stopping | |
1513 | @section Breakpoints, Watchpoints, and Exceptions | |
1514 | ||
1515 | @cindex breakpoints | |
1516 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1517 | the program is reached. For each breakpoint, you can add various | |
1518 | conditions to control in finer detail whether the program will stop. | |
1519 | You can set breakpoints with the @code{break} command and its variants | |
1520 | (@pxref{Set Breaks}), to specify the place where the program should stop | |
1521 | by line number, function name or exact address in the program. In | |
1522 | languages with exception handling (such as GNU C++), you can also set | |
1523 | breakpoints where an exception is raised (@pxref{Exception Handling}). | |
1524 | ||
1525 | @cindex watchpoints | |
1526 | A @dfn{watchpoint} is a special breakpoint that stops your program when | |
1527 | the value of an expression changes. You must use a different command to | |
1528 | set watchpoints (@pxref{Set Watchpoints}), but aside from that, you can | |
1529 | manage a watchpoint like any other breakpoint: you enable, disable, and | |
1530 | delete both breakpoints and watchpoints using the same commands. | |
1531 | ||
1532 | Each breakpoint or watchpoint is assigned a number when it is created; | |
1533 | these numbers are successive integers starting with one. In many of the | |
1534 | commands for controlling various features of breakpoints you use the | |
1535 | breakpoint number to say which breakpoint you want to change. Each | |
1536 | breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
1537 | no effect on the program until you enable it again. | |
1538 | ||
1539 | @menu | |
1540 | * Set Breaks:: Setting Breakpoints | |
1541 | * Set Watchpoints:: Setting Watchpoints | |
1542 | * Exception Handling:: Breakpoints and Exceptions | |
1543 | * Delete Breaks:: Deleting Breakpoints | |
1544 | * Disabling:: Disabling Breakpoints | |
1545 | * Conditions:: Break Conditions | |
1546 | * Break Commands:: Breakpoint Command Lists | |
1547 | * Breakpoint Menus:: Breakpoint Menus | |
1548 | * Error in Breakpoints:: | |
1549 | @end menu | |
1550 | ||
1551 | @node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints | |
1552 | @subsection Setting Breakpoints | |
1553 | ||
1554 | @kindex break | |
1555 | @kindex b | |
1556 | Breakpoints are set with the @code{break} command (abbreviated @code{b}). | |
1557 | ||
1558 | You have several ways to say where the breakpoint should go. | |
1559 | ||
1560 | @table @code | |
1561 | @item break @var{function} | |
1562 | Set a breakpoint at entry to function @var{function}. When using source | |
1563 | languages that permit overloading of symbols, such as C++, | |
1564 | @var{function} may refer to more than one possible place to break. | |
1565 | @xref{Breakpoint Menus}, for a discussion of that situation. | |
1566 | ||
1567 | @item break +@var{offset} | |
1568 | @itemx break -@var{offset} | |
1569 | Set a breakpoint some number of lines forward or back from the position | |
1570 | at which execution stopped in the currently selected frame. | |
1571 | ||
1572 | @item break @var{linenum} | |
1573 | Set a breakpoint at line @var{linenum} in the current source file. | |
1574 | That file is the last file whose source text was printed. This | |
1575 | breakpoint will stop the program just before it executes any of the | |
1576 | code on that line. | |
1577 | ||
1578 | @item break @var{filename}:@var{linenum} | |
1579 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1580 | ||
1581 | @item break @var{filename}:@var{function} | |
1582 | Set a breakpoint at entry to function @var{function} found in file | |
1583 | @var{filename}. Specifying a file name as well as a function name is | |
1584 | superfluous except when multiple files contain similarly named | |
1585 | functions. | |
1586 | ||
1587 | @item break *@var{address} | |
1588 | Set a breakpoint at address @var{address}. You can use this to set | |
1589 | breakpoints in parts of the program which do not have debugging | |
1590 | information or source files. | |
1591 | ||
1592 | @item break | |
1593 | When called without any arguments, @code{break} sets a breakpoint at the | |
1594 | next instruction to be executed in the selected stack frame | |
1595 | (@pxref{Stack}). In any selected frame but the innermost, this will | |
1596 | cause the program to stop as soon as control returns to that frame. | |
1597 | This is similar to the effect of a @code{finish} command in the frame | |
1598 | inside the selected frame---except that @code{finish} doesn't leave an | |
1599 | active breakpoint. If you use @code{break} without an argument in the | |
1600 | innermost frame, _GDBN__ will stop the next time it reaches the current | |
1601 | location; this may be useful inside loops. | |
1602 | ||
1603 | _GDBN__ normally ignores breakpoints when it resumes execution, until at | |
1604 | least one instruction has been executed. If it did not do this, you | |
1605 | would be unable to proceed past a breakpoint without first disabling the | |
1606 | breakpoint. This rule applies whether or not the breakpoint already | |
1607 | existed when the program stopped. | |
1608 | ||
1609 | @item break @dots{} if @var{cond} | |
1610 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1611 | @var{cond} each time the breakpoint is reached, and stop only if the | |
1612 | value is nonzero. @samp{@dots{}} stands for one of the possible | |
1613 | arguments described above (or no argument) specifying where to break. | |
1614 | @xref{Conditions}, for more information on breakpoint conditions. | |
1615 | ||
1616 | @item tbreak @var{args} | |
1617 | @kindex tbreak | |
1618 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1619 | same as for the @code{break} command, and the breakpoint is set in the same | |
1620 | way, but the breakpoint is automatically disabled the first time it | |
1621 | is hit. @xref{Disabling}. | |
1622 | ||
1623 | @item rbreak @var{regex} | |
1624 | @kindex rbreak | |
1625 | @cindex regular expression | |
1626 | @c FIXME: 2nd sentence below C++ only? | |
1627 | Set breakpoints on all functions matching the regular expression | |
1628 | @var{regex}. This is useful for setting breakpoints on overloaded | |
1629 | functions that are not members of any special classes. This command | |
1630 | sets an unconditional breakpoint on all matches, printing a list of all | |
1631 | breakpoints it set. Once these breakpoints are set, they are treated | |
1632 | just like the breakpoints set with the @code{break} command. They can | |
1633 | be deleted, disabled, made conditional, etc., in the standard ways. | |
1634 | ||
1635 | @kindex info breakpoints | |
1636 | @kindex $_ | |
1637 | @item info breakpoints @r{[}@var{n}@r{]} | |
1638 | @item info break @r{[}@var{n}@r{]} | |
1639 | Print a list of all breakpoints (but not watchpoints) set and not | |
1640 | deleted, showing their numbers, where in the program they are, and any | |
1641 | special features in use for them. Disabled breakpoints are included in | |
1642 | the list, but marked as disabled. @code{info break} with a breakpoint | |
1643 | number @var{n} as argument lists only that breakpoint. The convenience | |
1644 | variable @code{$_} and the default examining-address for the @code{x} | |
1645 | command are set to the address of the last breakpoint listed | |
1646 | (@pxref{Memory}). The equivalent command for watchpoints is @code{info | |
1647 | watch}. @end table | |
1648 | ||
1649 | _GDBN__ allows you to set any number of breakpoints at the same place in the | |
1650 | program. There is nothing silly or meaningless about this. When the | |
1651 | breakpoints are conditional, this is even useful (@pxref{Conditions}). | |
1652 | ||
1653 | @node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints | |
1654 | @subsection Setting Watchpoints | |
1655 | @cindex setting watchpoints | |
1656 | You can use a watchpoint to stop execution whenever the value of an | |
1657 | expression changes, without having to predict a particular place | |
1658 | where this may happen. | |
1659 | ||
1660 | Watchpoints currently execute two orders of magnitude more slowly than | |
1661 | other breakpoints, but this can well be worth it to catch errors where | |
1662 | you have no clue what part of your program is the culprit. Some | |
1663 | processors provide special hardware to support watchpoint evaluation; future | |
1664 | releases of _GDBN__ will use such hardware if it is available. | |
1665 | ||
1666 | @table @code | |
1667 | @kindex watch | |
1668 | @item watch @var{expr} | |
1669 | Set a watchpoint for an expression. | |
1670 | ||
1671 | @kindex info watchpoints | |
1672 | @item info watchpoints | |
1673 | This command prints a list of watchpoints; it is otherwise similar to | |
1674 | @code{info break}. | |
1675 | @end table | |
1676 | ||
1677 | @node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints | |
1678 | @subsection Breakpoints and Exceptions | |
1679 | @cindex exception handlers | |
1680 | ||
1681 | Some languages, such as GNU C++, implement exception handling. _GDBN__ | |
1682 | can be used to examine what caused the program to raise an exception | |
1683 | and to list the exceptions the program is prepared to handle at a | |
1684 | given point in time. | |
1685 | ||
1686 | @table @code | |
1687 | @item catch @var{exceptions} | |
1688 | @kindex catch | |
1689 | You can set breakpoints at active exception handlers by using the | |
1690 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
1691 | to catch. | |
1692 | @end table | |
1693 | ||
1694 | You can use @code{info catch} to list active exception handlers; | |
1695 | @pxref{Frame Info}. | |
1696 | ||
1697 | There are currently some limitations to exception handling in _GDBN__. | |
1698 | These will be corrected in a future release. | |
1699 | ||
1700 | @itemize @bullet | |
1701 | @item | |
1702 | If you call a function interactively, _GDBN__ normally returns | |
1703 | control to you when the function has finished executing. If the call | |
1704 | raises an exception, however, the call may bypass the mechanism that | |
1705 | returns control to the user and cause the program to simply continue | |
1706 | running until it hits a breakpoint, catches a signal that _GDBN__ is | |
1707 | listening for, or exits. | |
1708 | @item | |
1709 | You cannot raise an exception interactively. | |
1710 | @item | |
1711 | You cannot interactively install an exception handler. | |
1712 | @end itemize | |
1713 | ||
1714 | @cindex raise exceptions | |
1715 | Sometimes @code{catch} is not the best way to debug exception handling: | |
1716 | if you need to know exactly where an exception is raised, it's better to | |
1717 | stop @emph{before} the exception handler is called, since that way you | |
1718 | can see the stack before any unwinding takes place. If you set a | |
1719 | breakpoint in an exception handler instead, it may not be easy to find | |
1720 | out where the exception was raised. | |
1721 | ||
1722 | To stop just before an exception handler is called, you need some | |
1723 | knowledge of the implementation. In the case of GNU C++ exceptions are | |
1724 | raised by calling a library function named @code{__raise_exception} | |
1725 | which has the following ANSI C interface: | |
1726 | ||
1727 | @example | |
1728 | /* ADDR is where the exception identifier is stored. | |
1729 | ID is the exception identifier. */ | |
1730 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
1731 | @end example | |
1732 | ||
1733 | @noindent | |
1734 | To make the debugger catch all exceptions before any stack | |
1735 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
1736 | (@pxref{Breakpoints}). | |
1737 | ||
1738 | With a conditional breakpoint (@xref{Conditions}) that depends on the | |
1739 | value of @var{id}, you can stop your program when a specific exception | |
1740 | is raised. You can use multiple conditional breakpoints to stop the | |
1741 | program when any of a number of exceptions are raised. | |
1742 | ||
1743 | @node Delete Breaks, Disabling, Exception Handling, Breakpoints | |
1744 | @subsection Deleting Breakpoints | |
1745 | ||
1746 | @cindex clearing breakpoints, watchpoints | |
1747 | @cindex deleting breakpoints, watchpoints | |
1748 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
1749 | has done its job and you no longer want the program to stop there. This | |
1750 | is called @dfn{deleting} the breakpoint. A breakpoint that has been | |
1751 | deleted no longer exists; it is forgotten. | |
1752 | ||
1753 | With the @code{clear} command you can delete breakpoints according to | |
1754 | where they are in the program. With the @code{delete} command you can | |
1755 | delete individual breakpoints or watchpoints by specifying their | |
1756 | breakpoint numbers. | |
1757 | ||
1758 | It is not necessary to delete a breakpoint to proceed past it. _GDBN__ | |
1759 | automatically ignores breakpoints on the first instruction to be executed | |
1760 | when you continue execution without changing the execution address. | |
1761 | ||
1762 | @table @code | |
1763 | @item clear | |
1764 | @kindex clear | |
1765 | Delete any breakpoints at the next instruction to be executed in the | |
1766 | selected stack frame (@pxref{Selection}). When the innermost frame | |
1767 | is selected, this is a good way to delete a breakpoint that the program | |
1768 | just stopped at. | |
1769 | ||
1770 | @item clear @var{function} | |
1771 | @itemx clear @var{filename}:@var{function} | |
1772 | Delete any breakpoints set at entry to the function @var{function}. | |
1773 | ||
1774 | @item clear @var{linenum} | |
1775 | @itemx clear @var{filename}:@var{linenum} | |
1776 | Delete any breakpoints set at or within the code of the specified line. | |
1777 | ||
1778 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1779 | @cindex delete breakpoints | |
1780 | @kindex delete | |
1781 | @kindex d | |
1782 | Delete the breakpoints or watchpoints of the numbers specified as | |
1783 | arguments. If no argument is specified, delete all breakpoints (_GDBN__ | |
1784 | asks confirmation, unless you've @code{set confirm off}). You | |
1785 | can abbreviate this command as @code{d}. | |
1786 | @end table | |
1787 | ||
1788 | @node Disabling, Conditions, Delete Breaks, Breakpoints | |
1789 | @subsection Disabling Breakpoints | |
1790 | ||
1791 | @cindex disabled breakpoints | |
1792 | @cindex enabled breakpoints | |
1793 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
1794 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
1795 | been deleted, but remembers the information on the breakpoint so that | |
1796 | you can @dfn{enable} it again later. | |
1797 | ||
1798 | You disable and enable breakpoints and watchpoints with the | |
1799 | @code{enable} and @code{disable} commands, optionally specifying one or | |
1800 | more breakpoint numbers as arguments. Use @code{info break} or | |
1801 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
1802 | don't know which numbers to use. | |
1803 | ||
1804 | A breakpoint or watchpoint can have any of four different states of | |
1805 | enablement: | |
1806 | ||
1807 | @itemize @bullet | |
1808 | @item | |
1809 | Enabled. The breakpoint will stop the program. A breakpoint set | |
1810 | with the @code{break} command starts out in this state. | |
1811 | @item | |
1812 | Disabled. The breakpoint has no effect on the program. | |
1813 | @item | |
1814 | Enabled once. The breakpoint will stop the program, but | |
1815 | when it does so it will become disabled. A breakpoint set | |
1816 | with the @code{tbreak} command starts out in this state. | |
1817 | @item | |
1818 | Enabled for deletion. The breakpoint will stop the program, but | |
1819 | immediately after it does so it will be deleted permanently. | |
1820 | @end itemize | |
1821 | ||
1822 | You can use the following commands to enable or disable breakpoints and | |
1823 | watchpoints: | |
1824 | ||
1825 | @table @code | |
1826 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1827 | @kindex disable breakpoints | |
1828 | @kindex disable | |
1829 | @kindex dis | |
1830 | Disable the specified breakpoints---or all breakpoints, if none are | |
1831 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
1832 | options such as ignore-counts, conditions and commands are remembered in | |
1833 | case the breakpoint is enabled again later. You may abbreviate | |
1834 | @code{disable} as @code{dis}. | |
1835 | ||
1836 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1837 | @kindex enable breakpoints | |
1838 | @kindex enable | |
1839 | Enable the specified breakpoints (or all defined breakpoints). They | |
1840 | become effective once again in stopping the program. | |
1841 | ||
1842 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
1843 | Enable the specified breakpoints temporarily. Each will be disabled | |
1844 | again the next time it stops the program. | |
1845 | ||
1846 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
1847 | Enable the specified breakpoints to work once and then die. Each of | |
1848 | the breakpoints will be deleted the next time it stops the program. | |
1849 | @end table | |
1850 | ||
1851 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks}), | |
1852 | breakpoints that you set are initially enabled; subsequently, they become | |
1853 | disabled or enabled only when you use one of the commands above. (The | |
1854 | command @code{until} can set and delete a breakpoint of its own, but it | |
1855 | will not change the state of your other breakpoints; | |
1856 | @pxref{Stepping}.) | |
1857 | ||
1858 | @node Conditions, Break Commands, Disabling, Breakpoints | |
1859 | @subsection Break Conditions | |
1860 | @cindex conditional breakpoints | |
1861 | @cindex breakpoint conditions | |
1862 | ||
1863 | The simplest sort of breakpoint breaks every time the program reaches a | |
1864 | specified place. You can also specify a @dfn{condition} for a | |
1865 | breakpoint. A condition is just a Boolean expression in your | |
1866 | programming language. (@xref{Expressions}). A breakpoint with a | |
1867 | condition evaluates the expression each time the program reaches it, and | |
1868 | the program stops only if the condition is true. | |
1869 | ||
1870 | Conditions are also accepted for watchpoints; you may not need them, | |
1871 | since a watchpoint is inspecting the value of an expression anyhow---but | |
1872 | it might be simpler, say, to just set a watchpoint on a variable name, | |
1873 | and specify a condition that tests whether the new value is an interesting | |
1874 | one. | |
1875 | ||
1876 | Break conditions ca have side effects, and may even call functions in | |
1877 | your program. This can be useful, for example, to activate functions | |
1878 | that log program progress, or to use your own print functions to format | |
1879 | special data structures. The effects are completely predictable unless | |
1880 | there is another enabled breakpoint at the same address. (In that | |
1881 | case, _GDBN__ might see the other breakpoint first and stop the program | |
1882 | without checking the condition of this one.) Note that breakpoint | |
1883 | commands are usually more convenient and flexible for the purpose of | |
1884 | performing side effects when a breakpoint is reached (@pxref{Break | |
1885 | Commands}). | |
1886 | ||
1887 | Break conditions can be specified when a breakpoint is set, by using | |
1888 | @samp{if} in the arguments to the @code{break} command. @xref{Set Breaks}. | |
1889 | They can also be changed at any time with the @code{condition} command. | |
1890 | The @code{watch} command doesn't recognize the @code{if} keyword; | |
1891 | @code{condition} is the only way to impose a further condition on a | |
1892 | watchpoint. | |
1893 | ||
1894 | @table @code | |
1895 | @item condition @var{bnum} @var{expression} | |
1896 | @kindex condition | |
1897 | Specify @var{expression} as the break condition for breakpoint or | |
1898 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
1899 | the program only if the value of @var{expression} is true (nonzero, in | |
1900 | C). When you use @code{condition}, _GDBN__ checks @var{expression} | |
1901 | immediately for syntactic correctness, and to determine whether symbols | |
1902 | in it have referents in the context of your breakpoint. _GDBN__ does | |
1903 | not actually evaluate @var{expression} at the time the @code{condition} | |
1904 | command is given, however. @xref{Expressions}. | |
1905 | ||
1906 | @item condition @var{bnum} | |
1907 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
1908 | an ordinary unconditional breakpoint. | |
1909 | @end table | |
1910 | ||
1911 | @cindex ignore count (of breakpoint) | |
1912 | A special case of a breakpoint condition is to stop only when the | |
1913 | breakpoint has been reached a certain number of times. This is so | |
1914 | useful that there is a special way to do it, using the @dfn{ignore | |
1915 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
1916 | is an integer. Most of the time, the ignore count is zero, and | |
1917 | therefore has no effect. But if the program reaches a breakpoint whose | |
1918 | ignore count is positive, then instead of stopping, it just decrements | |
1919 | the ignore count by one and continues. As a result, if the ignore count | |
1920 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
1921 | is reached. | |
1922 | ||
1923 | @table @code | |
1924 | @item ignore @var{bnum} @var{count} | |
1925 | @kindex ignore | |
1926 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
1927 | The next @var{count} times the breakpoint is reached, your program's | |
1928 | execution will not stop; other than to decrement the ignore count, _GDBN__ | |
1929 | takes no action. | |
1930 | ||
1931 | To make the breakpoint stop the next time it is reached, specify | |
1932 | a count of zero. | |
1933 | ||
1934 | @item continue @var{count} | |
1935 | @itemx c @var{count} | |
1936 | @itemx fg @var{count} | |
1937 | @kindex continue @var{count} | |
1938 | Continue execution of the program, setting the ignore count of the | |
1939 | breakpoint that the program stopped at to @var{count} minus one. | |
1940 | Thus, the program will not stop at this breakpoint until the | |
1941 | @var{count}'th time it is reached. | |
1942 | ||
1943 | An argument to this command is meaningful only when the program stopped | |
1944 | due to a breakpoint. At other times, the argument to @code{continue} is | |
1945 | ignored. | |
1946 | ||
1947 | The synonym @code{fg} is provided purely for convenience, and has | |
1948 | exactly the same behavior as other forms of the command. | |
1949 | @end table | |
1950 | ||
1951 | If a breakpoint has a positive ignore count and a condition, the condition | |
1952 | is not checked. Once the ignore count reaches zero, the condition will | |
1953 | be checked. | |
1954 | ||
1955 | You could achieve the effect of the ignore count with a | |
1956 | condition such as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience | |
1957 | variable that is decremented each time. @xref{Convenience Vars}. | |
1958 | ||
1959 | @node Break Commands, Breakpoint Menus, Conditions, Breakpoints | |
1960 | @subsection Breakpoint Command Lists | |
1961 | ||
1962 | @cindex breakpoint commands | |
1963 | You can give any breakpoint (or watchpoint) a series of commands to | |
1964 | execute when the program stops due to that breakpoint. For example, you | |
1965 | might want to print the values of certain expressions, or enable other | |
1966 | breakpoints. | |
1967 | ||
1968 | @table @code | |
1969 | @item commands @r{[}@var{bnum}@r{]} | |
1970 | @itemx @dots{} @var{command-list} @dots{} | |
1971 | @itemx end | |
1972 | @kindex commands | |
1973 | @kindex end | |
1974 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
1975 | themselves appear on the following lines. Type a line containing just | |
1976 | @code{end} to terminate the commands. | |
1977 | ||
1978 | To remove all commands from a breakpoint, type @code{commands} followed | |
1979 | immediately by @code{end}; that is, give no commands. | |
1980 | ||
1981 | With no @var{bnum} argument, @code{commands} refers to the last | |
1982 | breakpoint or watchpoint set (not to the breakpoint most recently | |
1983 | encountered). | |
1984 | @end table | |
1985 | ||
1986 | Pressing @key{RET} as a means of repeating the last _GDBN__ command is | |
1987 | disabled within a @var{command-list}. | |
1988 | ||
1989 | You can use breakpoint commands to start the program up again. Simply | |
1990 | use the @code{continue} command, or @code{step}, or any other command | |
1991 | that resumes execution. Subsequent commands in the command list are | |
1992 | ignored. | |
1993 | ||
1994 | @kindex silent | |
1995 | If the first command specified is @code{silent}, the usual message about | |
1996 | stopping at a breakpoint is not printed. This may be desirable for | |
1997 | breakpoints that are to print a specific message and then continue. | |
1998 | If the remaining commands too print nothing, you will see no sign that | |
1999 | the breakpoint was reached at all. @code{silent} is meaningful only | |
2000 | at the beginning of a breakpoint command list. | |
2001 | ||
2002 | The commands @code{echo} and @code{output} that allow you to print precisely | |
2003 | controlled output are often useful in silent breakpoints. @xref{Output}. | |
2004 | ||
2005 | For example, here is how you could use breakpoint commands to print the | |
2006 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2007 | ||
2008 | _0__@example | |
2009 | break foo if x>0 | |
2010 | commands | |
2011 | silent | |
2012 | echo x is\040 | |
2013 | output x | |
2014 | echo \n | |
2015 | cont | |
2016 | end | |
2017 | _1__@end example | |
2018 | ||
2019 | One application for breakpoint commands is to compensate for one bug so | |
2020 | you can test for another. Put a breakpoint just after the erroneous line | |
2021 | of code, give it a condition to detect the case in which something | |
2022 | erroneous has been done, and give it commands to assign correct values | |
2023 | to any variables that need them. End with the @code{continue} command | |
2024 | so that the program does not stop, and start with the @code{silent} | |
2025 | command so that no output is produced. Here is an example: | |
2026 | ||
2027 | @example | |
2028 | break 403 | |
2029 | commands | |
2030 | silent | |
2031 | set x = y + 4 | |
2032 | cont | |
2033 | end | |
2034 | @end example | |
2035 | ||
2036 | @cindex lost output | |
2037 | One deficiency in the operation of automatically continuing breakpoints | |
2038 | under Unix appears when your program uses raw mode for the terminal. | |
2039 | _GDBN__ switches back to its own terminal modes (not raw) before executing | |
2040 | commands, and then must switch back to raw mode when your program is | |
2041 | continued. This causes any pending terminal input to be lost. | |
2042 | @c FIXME: revisit below when GNU sys avail. | |
2043 | @c In the GNU system, this will be fixed by changing the behavior of | |
2044 | @c terminal modes. | |
2045 | ||
2046 | Under Unix, you can get around this problem by writing actions into | |
2047 | the breakpoint condition rather than in commands. For example | |
2048 | ||
2049 | @example | |
2050 | condition 5 (x = y + 4), 0 | |
2051 | @end example | |
2052 | ||
2053 | @noindent | |
2054 | specifies a condition expression (@xref{Expressions}) that will change | |
2055 | @code{x} as needed, then always have the value zero so the program will | |
2056 | not stop. No input is lost here, because _GDBN__ evaluates break | |
2057 | conditions without changing the terminal modes. When you want to have | |
2058 | nontrivial conditions for performing the side effects, the operators | |
2059 | @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
2060 | ||
2061 | @node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints | |
2062 | @subsection Breakpoint Menus | |
2063 | @cindex C++ overloading | |
2064 | @cindex symbol overloading | |
2065 | ||
2066 | Some programming languages (notably C++) permit a single function name | |
2067 | to be defined several times, for application in different contexts. | |
2068 | This is called @dfn{overloading}. When a function name is overloaded, | |
2069 | @samp{break @var{function}} is not enough to tell _GDBN__ where you | |
2070 | want a breakpoint. _GDBN__ offers you a menu of numbered choices for | |
2071 | different possible breakpoints, and waits for your selection with the | |
2072 | prompt @samp{>}. The first two options are always @samp{[0] cancel} | |
2073 | and @samp{[1] all}. Typing @kbd{1} sets a breakpoint at each | |
2074 | definition of @var{function}, and typing @kbd{0} aborts the | |
2075 | @code{break} command without setting any new breakpoints. | |
2076 | ||
2077 | For example, the following session excerpt shows an attempt to set a | |
2078 | breakpoint at the overloaded symbol @code{String::after}. | |
2079 | We choose three particular definitions of that function name: | |
2080 | ||
2081 | @example | |
2082 | (_GDBP__) b String::after | |
2083 | [0] cancel | |
2084 | [1] all | |
2085 | [2] file:String.cc; line number:867 | |
2086 | [3] file:String.cc; line number:860 | |
2087 | [4] file:String.cc; line number:875 | |
2088 | [5] file:String.cc; line number:853 | |
2089 | [6] file:String.cc; line number:846 | |
2090 | [7] file:String.cc; line number:735 | |
2091 | > 2 4 6 | |
2092 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2093 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2094 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2095 | Multiple breakpoints were set. | |
2096 | Use the "delete" command to delete unwanted breakpoints. | |
2097 | (_GDBP__) | |
2098 | @end example | |
2099 | ||
2100 | ||
2101 | @node Error in Breakpoints, , Breakpoint Menus, Breakpoints | |
2102 | @subsection ``Cannot Insert Breakpoints'' | |
2103 | ||
2104 | @c FIXME: "cannot insert breakpoints" error, v unclear. | |
2105 | @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91 | |
2106 | Under some operating systems, breakpoints cannot be used in a program if | |
2107 | any other process is running that program. In this situation, | |
2108 | attempting to run or continue a program with a breakpoint causes _GDBN__ | |
2109 | to stop the other process. | |
2110 | ||
2111 | When this happens, you have three ways to proceed: | |
2112 | ||
2113 | @enumerate | |
2114 | @item | |
2115 | Remove or disable the breakpoints, then continue. | |
2116 | ||
2117 | @item | |
2118 | Suspend _GDBN__, and copy the file containing the program to a new name. | |
2119 | Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__ | |
2120 | should run the program under that name. Then start the program again. | |
2121 | ||
2122 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2123 | @c explains the first FIXME: in this section... | |
2124 | ||
2125 | @item | |
2126 | Relink the program so that the text segment is nonsharable, using the | |
2127 | linker option @samp{-N}. The operating system limitation may not apply | |
2128 | to nonsharable executables. | |
2129 | @end enumerate | |
2130 | ||
7463aadd RP |
2131 | @node Stepping and Continuing, Signals, Breakpoints, Stopping |
2132 | @section Stepping and Continuing | |
70b88761 RP |
2133 | |
2134 | @cindex stepping | |
7463aadd RP |
2135 | @cindex continuing |
2136 | @cindex resuming execution | |
2137 | @dfn{Stepping} means resuming program execution for a very limited time: | |
2138 | one line of source code, or one machine instruction. @dfn {Continuing} | |
2139 | means resuming program execution until the program completes normally. | |
2140 | In either case, the program may stop even sooner, due to a breakpoint or | |
2141 | to a signal. (If due to a signal, you may want to use @code{handle}, or | |
2142 | use @samp{signal 0} to resume execution; @pxref{Signals}.) | |
2143 | ||
2144 | A typical technique for using stepping is to set a breakpoint | |
70b88761 RP |
2145 | (@pxref{Breakpoints}) at the beginning of the function or the section of |
2146 | the program in which a problem is believed to lie, run the program until | |
2147 | it stops at that breakpoint, and then step through the suspect area, | |
2148 | examining the variables that are interesting, until you see the problem | |
2149 | happen. | |
2150 | ||
2151 | @table @code | |
2152 | @item step | |
2153 | @kindex step | |
2154 | @kindex s | |
2155 | Continue running the program until control reaches a different source | |
7463aadd | 2156 | line, then stop it and return control to _GDBN__. This command is |
70b88761 RP |
2157 | abbreviated @code{s}. |
2158 | ||
7463aadd RP |
2159 | You may use the @code{step} command even when control is within a function |
2160 | compiled without debugging information. In that case, execution | |
70b88761 RP |
2161 | will proceed until control reaches a different function, or is about to |
2162 | return from this function. | |
2163 | ||
2164 | @item step @var{count} | |
2165 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2166 | breakpoint is reached or a signal not related to stepping occurs before | |
2167 | @var{count} steps, stepping stops right away. | |
2168 | ||
7463aadd | 2169 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2170 | @kindex next |
2171 | @kindex n | |
7463aadd RP |
2172 | Continue to the next source line in the current (innermost) stack frame. |
2173 | Similar to @code{step}, but any function calls appearing within the line | |
2174 | of code are executed without stopping. Execution stops when control | |
2175 | reaches a different line of code at the stack level which was executing | |
2176 | when the @code{next} command was given. This command is abbreviated | |
2177 | @code{n}. | |
70b88761 | 2178 | |
7463aadd | 2179 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2180 | |
2181 | @code{next} within a function that lacks debugging information acts like | |
2182 | @code{step}, but any function calls appearing within the code of the | |
2183 | function are executed without stopping. | |
2184 | ||
2185 | @item finish | |
2186 | @kindex finish | |
7463aadd RP |
2187 | Continue running until just after function in the selected stack frame |
2188 | returns. Print the returned value (if any). | |
70b88761 RP |
2189 | |
2190 | Contrast this with the @code{return} command (@pxref{Returning}). | |
2191 | ||
2192 | @item until | |
2193 | @kindex until | |
2194 | @item u | |
2195 | @kindex u | |
2196 | Continue running until a source line past the current line, in the | |
2197 | current stack frame, is reached. This command is used to avoid single | |
2198 | stepping through a loop more than once. It is like the @code{next} | |
2199 | command, except that when @code{until} encounters a jump, it | |
2200 | automatically continues execution until the program counter is greater | |
2201 | than the address of the jump. | |
2202 | ||
2203 | This means that when you reach the end of a loop after single stepping | |
2204 | though it, @code{until} will cause the program to continue execution | |
2205 | until the loop is exited. In contrast, a @code{next} command at the end | |
2206 | of a loop will simply step back to the beginning of the loop, which | |
2207 | would force you to step through the next iteration. | |
2208 | ||
2209 | @code{until} always stops the program if it attempts to exit the current | |
2210 | stack frame. | |
2211 | ||
2212 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2213 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2214 | example, in the following excerpt from a debugging session, the @code{f} |
2215 | (@code{frame}) command shows that execution is stopped at line | |
2216 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2217 | ||
2218 | @example | |
2219 | (_GDBP__) f | |
2220 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
2221 | 206 expand_input(); | |
2222 | (_GDBP__) until | |
2223 | 195 for ( ; argc > 0; NEXTARG) @{ | |
2224 | @end example | |
2225 | ||
7463aadd RP |
2226 | This happened because, for execution efficiency, the compiler had |
2227 | generated code for the loop closure test at the end, rather than the | |
2228 | start, of the loop---even though the test in a C @code{for}-loop is | |
2229 | written before the body of the loop. The @code{until} command appeared | |
2230 | to step back to the beginning of the loop when it advanced to this | |
2231 | expression; however, it has not really gone to an earlier | |
2232 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2233 | |
2234 | @code{until} with no argument works by means of single | |
2235 | instruction stepping, and hence is slower than @code{until} with an | |
2236 | argument. | |
2237 | ||
2238 | @item until @var{location} | |
2239 | @item u @var{location} | |
2240 | Continue running the program until either the specified location is | |
7463aadd | 2241 | reached, or the current stack frame returns. @var{location} |
70b88761 RP |
2242 | is any of the forms of argument acceptable to @code{break} (@pxref{Set |
2243 | Breaks}). This form of the command uses breakpoints, and hence is | |
2244 | quicker than @code{until} without an argument. | |
2245 | ||
2246 | @item stepi | |
2247 | @itemx si | |
2248 | @kindex stepi | |
2249 | @kindex si | |
2250 | Execute one machine instruction, then stop and return to the debugger. | |
2251 | ||
2252 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2253 | instructions. This will cause the next instruction to be executed to | |
2254 | be displayed automatically at each stop. @xref{Auto Display}. | |
2255 | ||
2256 | An argument is a repeat count, as in @code{step}. | |
2257 | ||
2258 | @item nexti | |
2259 | @itemx ni | |
2260 | @kindex nexti | |
2261 | @kindex ni | |
2262 | Execute one machine instruction, but if it is a function call, | |
2263 | proceed until the function returns. | |
2264 | ||
2265 | An argument is a repeat count, as in @code{next}. | |
70b88761 | 2266 | |
7463aadd RP |
2267 | @item continue @r{[}@var{ignore-count}@r{]} |
2268 | @kindex continue | |
2269 | Resume program execution, at the address where the program last stopped; | |
2270 | any breakpoints set at that address are bypassed. The optional argument | |
2271 | @var{ignore-count} allows you to specify a further number of times to | |
2272 | ignore a breakpoint at this location; its effect is like that of | |
2273 | @code{ignore} (@pxref{Conditions}). | |
70b88761 | 2274 | |
7463aadd RP |
2275 | To resume execution at a different place, you can use @code{return} |
2276 | (@pxref{Returning}) to go back to the calling function; or @code{jump} | |
2277 | (@pxref{Jumping}) to go to an arbitrary location in your program. | |
70b88761 | 2278 | |
70b88761 RP |
2279 | @end table |
2280 | ||
70b88761 | 2281 | |
7463aadd | 2282 | @node Signals, , Stepping and Continuing, Stopping |
70b88761 RP |
2283 | @section Signals |
2284 | @cindex signals | |
2285 | ||
2286 | A signal is an asynchronous event that can happen in a program. The | |
2287 | operating system defines the possible kinds of signals, and gives each | |
2288 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2289 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2290 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2291 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
2292 | the alarm clock timer goes off (which happens only if the program has | |
2293 | requested an alarm). | |
2294 | ||
2295 | @cindex fatal signals | |
2296 | Some signals, including @code{SIGALRM}, are a normal part of the | |
2297 | functioning of the program. Others, such as @code{SIGSEGV}, indicate | |
2298 | errors; these signals are @dfn{fatal} (kill the program immediately) if the | |
2299 | program has not specified in advance some other way to handle the signal. | |
2300 | @code{SIGINT} does not indicate an error in the program, but it is normally | |
2301 | fatal so it can carry out the purpose of the interrupt: to kill the program. | |
2302 | ||
2303 | _GDBN__ has the ability to detect any occurrence of a signal in the program | |
2304 | running under _GDBN__'s control. You can tell _GDBN__ in advance what to do for | |
2305 | each kind of signal. | |
2306 | ||
2307 | @cindex handling signals | |
2308 | Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM} | |
2309 | (so as not to interfere with their role in the functioning of the program) | |
2310 | but to stop the program immediately whenever an error signal happens. | |
2311 | You can change these settings with the @code{handle} command. | |
2312 | ||
2313 | @table @code | |
2314 | @item info signals | |
2315 | @kindex info signals | |
2316 | Print a table of all the kinds of signals and how _GDBN__ has been told to | |
2317 | handle each one. You can use this to see the signal numbers of all | |
2318 | the defined types of signals. | |
2319 | ||
2320 | @item handle @var{signal} @var{keywords}@dots{} | |
2321 | @kindex handle | |
2322 | Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the | |
2323 | number of a signal or its name (with or without the @samp{SIG} at the | |
2324 | beginning). The @var{keywords} say what change to make. | |
2325 | @end table | |
2326 | ||
2327 | @c @group | |
2328 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2329 | Their full names are: | |
2330 | ||
2331 | @table @code | |
2332 | @item nostop | |
2333 | _GDBN__ should not stop the program when this signal happens. It may | |
2334 | still print a message telling you that the signal has come in. | |
2335 | ||
2336 | @item stop | |
2337 | _GDBN__ should stop the program when this signal happens. This implies | |
2338 | the @code{print} keyword as well. | |
2339 | ||
2340 | @item print | |
2341 | _GDBN__ should print a message when this signal happens. | |
2342 | ||
2343 | @item noprint | |
2344 | _GDBN__ should not mention the occurrence of the signal at all. This | |
2345 | implies the @code{nostop} keyword as well. | |
2346 | ||
2347 | @item pass | |
2348 | _GDBN__ should allow the program to see this signal; the program will be | |
2349 | able to handle the signal, or may be terminated if the signal is fatal | |
2350 | and not handled. | |
2351 | ||
2352 | @item nopass | |
2353 | _GDBN__ should not allow the program to see this signal. | |
2354 | @end table | |
2355 | @c @end group | |
2356 | ||
2357 | When a signal has been set to stop the program, the program cannot see the | |
2358 | signal until you continue. It will see the signal then, if @code{pass} is | |
2359 | in effect for the signal in question @i{at that time}. In other words, | |
2360 | after _GDBN__ reports a signal, you can use the @code{handle} command with | |
2361 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
2362 | the program when you later continue it. | |
2363 | ||
2364 | You can also use the @code{signal} command to prevent the program from | |
2365 | seeing a signal, or cause it to see a signal it normally would not see, | |
7463aadd RP |
2366 | or to give it any signal at any time. For example, if the program stopped |
2367 | due to some sort of memory reference error, you might store correct | |
2368 | values into the erroneous variables and continue, hoping to see more | |
2369 | execution; but the program would probably terminate immediately as | |
2370 | a result of the fatal signal once it sees the signal. To prevent this, | |
2371 | you can continue with @samp{signal 0}. @xref{Signaling}. | |
70b88761 RP |
2372 | |
2373 | @node Stack, Source, Stopping, Top | |
2374 | @chapter Examining the Stack | |
2375 | ||
2376 | When your program has stopped, the first thing you need to know is where it | |
2377 | stopped and how it got there. | |
2378 | ||
2379 | @cindex call stack | |
2380 | Each time your program performs a function call, the information about | |
2381 | where in the program the call was made from is saved in a block of data | |
2382 | called a @dfn{stack frame}. The frame also contains the arguments of the | |
2383 | call and the local variables of the function that was called. All the | |
2384 | stack frames are allocated in a region of memory called the @dfn{call | |
2385 | stack}. | |
2386 | ||
2387 | When your program stops, the _GDBN__ commands for examining the stack allow you | |
2388 | to see all of this information. | |
2389 | ||
2390 | @cindex selected frame | |
2391 | One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands | |
2392 | refer implicitly to the selected frame. In particular, whenever you ask | |
2393 | _GDBN__ for the value of a variable in the program, the value is found in the | |
2394 | selected frame. There are special _GDBN__ commands to select whichever frame | |
2395 | you are interested in. | |
2396 | ||
2397 | When the program stops, _GDBN__ automatically selects the currently executing | |
2398 | frame and describes it briefly as the @code{frame} command does | |
2399 | (@pxref{Frame Info, Info}). | |
2400 | ||
2401 | @menu | |
2402 | * Frames:: Stack Frames | |
2403 | * Backtrace:: Backtraces | |
2404 | * Selection:: Selecting a Frame | |
2405 | * Frame Info:: Information on a Frame | |
2406 | @end menu | |
2407 | ||
2408 | @node Frames, Backtrace, Stack, Stack | |
2409 | @section Stack Frames | |
2410 | ||
2411 | @cindex frame | |
2412 | @cindex stack frame | |
2413 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2414 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2415 | with one call to one function. The frame contains the arguments given | |
2416 | to the function, the function's local variables, and the address at | |
2417 | which the function is executing. | |
2418 | ||
2419 | @cindex initial frame | |
2420 | @cindex outermost frame | |
2421 | @cindex innermost frame | |
2422 | When your program is started, the stack has only one frame, that of the | |
2423 | function @code{main}. This is called the @dfn{initial} frame or the | |
2424 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2425 | made. Each time a function returns, the frame for that function invocation | |
2426 | is eliminated. If a function is recursive, there can be many frames for | |
2427 | the same function. The frame for the function in which execution is | |
2428 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2429 | recently created of all the stack frames that still exist. | |
2430 | ||
2431 | @cindex frame pointer | |
2432 | Inside your program, stack frames are identified by their addresses. A | |
2433 | stack frame consists of many bytes, each of which has its own address; each | |
2434 | kind of computer has a convention for choosing one of those bytes whose | |
2435 | address serves as the address of the frame. Usually this address is kept | |
2436 | in a register called the @dfn{frame pointer register} while execution is | |
2437 | going on in that frame. | |
2438 | ||
2439 | @cindex frame number | |
2440 | _GDBN__ assigns numbers to all existing stack frames, starting with | |
2441 | zero for the innermost frame, one for the frame that called it, | |
2442 | and so on upward. These numbers do not really exist in your program; | |
2443 | they are assigned by _GDBN__ to give you a way of designating stack | |
2444 | frames in _GDBN__ commands. | |
2445 | ||
2446 | @cindex frameless execution | |
2447 | Some compilers allow functions to be compiled so that they operate | |
2448 | without stack frames. (For example, the @code{_GCC__} option | |
2449 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2450 | This is occasionally done with heavily used library functions to save | |
2451 | the frame setup time. _GDBN__ has limited facilities for dealing with | |
2452 | these function invocations. If the innermost function invocation has no | |
2453 | stack frame, _GDBN__ will nevertheless regard it as though it had a | |
2454 | separate frame, which is numbered zero as usual, allowing correct | |
2455 | tracing of the function call chain. However, _GDBN__ has no provision | |
2456 | for frameless functions elsewhere in the stack. | |
2457 | ||
2458 | @node Backtrace, Selection, Frames, Stack | |
2459 | @section Backtraces | |
2460 | ||
2461 | A backtrace is a summary of how the program got where it is. It shows one | |
2462 | line per frame, for many frames, starting with the currently executing | |
2463 | frame (frame zero), followed by its caller (frame one), and on up the | |
2464 | stack. | |
2465 | ||
2466 | @table @code | |
2467 | @item backtrace | |
2468 | @itemx bt | |
2469 | @kindex backtrace | |
2470 | @kindex bt | |
2471 | Print a backtrace of the entire stack: one line per frame for all | |
2472 | frames in the stack. | |
2473 | ||
2474 | You can stop the backtrace at any time by typing the system interrupt | |
2475 | character, normally @kbd{C-c}. | |
2476 | ||
2477 | @item backtrace @var{n} | |
2478 | @itemx bt @var{n} | |
2479 | Similar, but print only the innermost @var{n} frames. | |
2480 | ||
2481 | @item backtrace -@var{n} | |
2482 | @itemx bt -@var{n} | |
2483 | Similar, but print only the outermost @var{n} frames. | |
2484 | @end table | |
2485 | ||
2486 | @kindex where | |
2487 | @kindex info stack | |
2488 | @kindex info s | |
2489 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
2490 | are additional aliases for @code{backtrace}. | |
2491 | ||
2492 | Each line in the backtrace shows the frame number and the function name. | |
2493 | The program counter value is also shown---unless you use @code{set | |
2494 | print address off}. The backtrace also shows the source file name and | |
2495 | line number, as well as the arguments to the function. The program | |
2496 | counter value is omitted if it is at the beginning of the code for that | |
2497 | line number. | |
2498 | ||
2499 | Here is an example of a backtrace. It was made with the command | |
2500 | @samp{bt 3}, so it shows the innermost three frames. | |
2501 | ||
2502 | @smallexample | |
2503 | @group | |
2504 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) at builtin.c:993 | |
2505 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 | |
2506 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
2507 | at macro.c:71 | |
2508 | (More stack frames follow...) | |
2509 | @end group | |
2510 | @end smallexample | |
2511 | ||
2512 | @noindent | |
2513 | The display for frame zero doesn't begin with a program counter | |
2514 | value, indicating that the program has stopped at the beginning of the | |
2515 | code for line @code{993} of @code{builtin.c}. | |
2516 | ||
2517 | @node Selection, Frame Info, Backtrace, Stack | |
2518 | @section Selecting a Frame | |
2519 | ||
2520 | Most commands for examining the stack and other data in the program work on | |
2521 | whichever stack frame is selected at the moment. Here are the commands for | |
2522 | selecting a stack frame; all of them finish by printing a brief description | |
2523 | of the stack frame just selected. | |
2524 | ||
2525 | @table @code | |
2526 | @item frame @var{n} | |
2527 | @itemx f @var{n} | |
2528 | @kindex frame | |
2529 | @kindex f | |
2530 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2531 | (currently executing) frame, frame one is the frame that called the | |
2532 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2533 | frame. | |
2534 | ||
2535 | @item frame @var{addr} | |
2536 | @itemx f @var{addr} | |
2537 | Select the frame at address @var{addr}. This is useful mainly if the | |
2538 | chaining of stack frames has been damaged by a bug, making it | |
2539 | impossible for _GDBN__ to assign numbers properly to all frames. In | |
2540 | addition, this can be useful when the program has multiple stacks and | |
2541 | switches between them. | |
2542 | ||
2543 | _if_(_SPARC__) | |
2544 | On the SPARC architecture, @code{frame} needs two addresses to | |
2545 | select an arbitrary frame: a frame pointer and a stack pointer. | |
2546 | @c note to future updaters: this is conditioned on a flag | |
2547 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
2548 | @c by SPARC, hence the specific attribution. Generalize or list all | |
2549 | @c possibilities if more supported machines start doing this. | |
2550 | _fi_(_SPARC__) | |
2551 | ||
2552 | @item up @var{n} | |
2553 | @kindex up | |
2554 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
2555 | advances toward the outermost frame, to higher frame numbers, to frames | |
2556 | that have existed longer. @var{n} defaults to one. | |
2557 | ||
2558 | @item down @var{n} | |
2559 | @kindex down | |
2560 | @kindex do | |
2561 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
2562 | advances toward the innermost frame, to lower frame numbers, to frames | |
2563 | that were created more recently. @var{n} defaults to one. You may | |
2564 | abbreviate @code{down} as @code{do}. | |
2565 | @end table | |
2566 | ||
2567 | All of these commands end by printing two lines of output describing the | |
2568 | frame. The first line shows the frame number, the function name, the | |
2569 | arguments, and the source file and line number of execution in that | |
2570 | frame. The second line shows the text of that source line. For | |
2571 | example: | |
2572 | ||
2573 | @smallexample | |
2574 | (_GDBP__) up | |
2575 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) at env.c:10 | |
2576 | 10 read_input_file (argv[i]); | |
2577 | @end smallexample | |
2578 | ||
2579 | After such a printout, the @code{list} command with no arguments will print | |
2580 | ten lines centered on the point of execution in the frame. @xref{List}. | |
2581 | ||
2582 | @table @code | |
2583 | @item up-silently @var{n} | |
2584 | @itemx down-silently @var{n} | |
2585 | @kindex down-silently | |
2586 | @kindex up-silently | |
2587 | These two commands are variants of @code{up} and @code{down}, | |
2588 | respectively; they differ in that they do their work silently, without | |
2589 | causing display of the new frame. They are intended primarily for use | |
2590 | in _GDBN__ command scripts, where the output might be unnecessary and | |
2591 | distracting. | |
2592 | ||
2593 | @end table | |
2594 | ||
2595 | @node Frame Info, , Selection, Stack | |
2596 | @section Information About a Frame | |
2597 | ||
2598 | There are several other commands to print information about the selected | |
2599 | stack frame. | |
2600 | ||
2601 | @table @code | |
2602 | @item frame | |
2603 | @itemx f | |
2604 | When used without any argument, this command does not change which frame | |
2605 | is selected, but prints a brief description of the currently | |
2606 | selected stack frame. It can be abbreviated @code{f}. With an | |
2607 | argument, this command is used to select a stack frame (@pxref{Selection}). | |
2608 | ||
2609 | @item info frame | |
2610 | @kindex info frame | |
2611 | @itemx info f | |
2612 | @kindex info f | |
2613 | This command prints a verbose description of the selected stack frame, | |
2614 | including the address of the frame, the addresses of the next frame down | |
2615 | (called by this frame) and the next frame up (caller of this frame), | |
2616 | the address of the frame's arguments, the program counter saved in it | |
2617 | (the address of execution in the caller frame), and which registers | |
2618 | were saved in the frame. The verbose description is useful when | |
2619 | something has gone wrong that has made the stack format fail to fit | |
2620 | the usual conventions. | |
2621 | ||
2622 | @item info frame @var{addr} | |
2623 | @itemx info f @var{addr} | |
2624 | Print a verbose description of the frame at address @var{addr}, | |
2625 | without selecting that frame. The selected frame remains unchanged by | |
2626 | this command. | |
2627 | ||
2628 | @item info args | |
2629 | @kindex info args | |
2630 | Print the arguments of the selected frame, each on a separate line. | |
2631 | ||
2632 | @item info locals | |
2633 | @kindex info locals | |
2634 | Print the local variables of the selected frame, each on a separate | |
2635 | line. These are all variables declared static or automatic within all | |
2636 | program blocks that execution in this frame is currently inside of. | |
2637 | ||
2638 | @item info catch | |
2639 | @kindex info catch | |
2640 | @cindex catch exceptions | |
2641 | @cindex exception handlers | |
2642 | Print a list of all the exception handlers that are active in the | |
2643 | current stack frame at the current point of execution. To see other | |
2644 | exception handlers, visit the associated frame (using the @code{up}, | |
2645 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
2646 | @xref{Exception Handling}. | |
2647 | @end table | |
2648 | ||
2649 | @node Source, Data, Stack, Top | |
2650 | @chapter Examining Source Files | |
2651 | ||
2652 | _GDBN__ can print parts of your program's source, since the debugging | |
2653 | information recorded in your program tells _GDBN__ what source files | |
2654 | were used to built it. When your program stops, _GDBN__ spontaneously | |
2655 | prints the line where it stopped. Likewise, when you select a stack | |
2656 | frame (@pxref{Selection}), _GDBN__ prints the line where execution in | |
2657 | that frame has stopped. You can print other portions of source files by | |
2658 | explicit command. | |
2659 | ||
2660 | If you use _GDBN__ through its GNU Emacs interface, you may prefer to | |
2661 | use Emacs facilities to view source; @pxref{Emacs}. | |
2662 | ||
2663 | @menu | |
2664 | * List:: Printing Source Lines | |
2665 | * Search:: Searching Source Files | |
2666 | * Source Path:: Specifying Source Directories | |
2667 | * Machine Code:: Source and Machine Code | |
2668 | @end menu | |
2669 | ||
2670 | @node List, Search, Source, Source | |
2671 | @section Printing Source Lines | |
2672 | ||
2673 | @kindex list | |
2674 | @kindex l | |
2675 | To print lines from a source file, use the @code{list} command | |
2676 | (abbreviated @code{l}). There are several ways to specify what part | |
2677 | of the file you want to print. | |
2678 | ||
2679 | Here are the forms of the @code{list} command most commonly used: | |
2680 | ||
2681 | @table @code | |
2682 | @item list @var{linenum} | |
2683 | Print ten lines centered around line number @var{linenum} in the | |
2684 | current source file. | |
2685 | ||
2686 | @item list @var{function} | |
2687 | Print ten lines centered around the beginning of function | |
2688 | @var{function}. | |
2689 | ||
2690 | @item list | |
2691 | Print ten more lines. If the last lines printed were printed with a | |
2692 | @code{list} command, this prints ten lines following the last lines | |
2693 | printed; however, if the last line printed was a solitary line printed | |
2694 | as part of displaying a stack frame (@pxref{Stack}), this prints ten | |
2695 | lines centered around that line. | |
2696 | ||
2697 | @item list - | |
2698 | Print ten lines just before the lines last printed. | |
2699 | @end table | |
2700 | ||
2701 | Repeating a @code{list} command with @key{RET} discards the argument, | |
2702 | so it is equivalent to typing just @code{list}. This is more useful | |
2703 | than listing the same lines again. An exception is made for an | |
2704 | argument of @samp{-}; that argument is preserved in repetition so that | |
2705 | each repetition moves up in the source file. | |
2706 | ||
2707 | @cindex linespec | |
2708 | In general, the @code{list} command expects you to supply zero, one or two | |
2709 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
2710 | of writing them but the effect is always to specify some source line. | |
2711 | Here is a complete description of the possible arguments for @code{list}: | |
2712 | ||
2713 | @table @code | |
2714 | @item list @var{linespec} | |
2715 | Print ten lines centered around the line specified by @var{linespec}. | |
2716 | ||
2717 | @item list @var{first},@var{last} | |
2718 | Print lines from @var{first} to @var{last}. Both arguments are | |
2719 | linespecs. | |
2720 | ||
2721 | @item list ,@var{last} | |
2722 | Print ten lines ending with @var{last}. | |
2723 | ||
2724 | @item list @var{first}, | |
2725 | Print ten lines starting with @var{first}. | |
2726 | ||
2727 | @item list + | |
2728 | Print ten lines just after the lines last printed. | |
2729 | ||
2730 | @item list - | |
2731 | Print ten lines just before the lines last printed. | |
2732 | ||
2733 | @item list | |
2734 | As described in the preceding table. | |
2735 | @end table | |
2736 | ||
2737 | Here are the ways of specifying a single source line---all the | |
2738 | kinds of linespec. | |
2739 | ||
2740 | @table @code | |
2741 | @item @var{number} | |
2742 | Specifies line @var{number} of the current source file. | |
2743 | When a @code{list} command has two linespecs, this refers to | |
2744 | the same source file as the first linespec. | |
2745 | ||
2746 | @item +@var{offset} | |
2747 | Specifies the line @var{offset} lines after the last line printed. | |
2748 | When used as the second linespec in a @code{list} command that has | |
2749 | two, this specifies the line @var{offset} lines down from the | |
2750 | first linespec. | |
2751 | ||
2752 | @item -@var{offset} | |
2753 | Specifies the line @var{offset} lines before the last line printed. | |
2754 | ||
2755 | @item @var{filename}:@var{number} | |
2756 | Specifies line @var{number} in the source file @var{filename}. | |
2757 | ||
2758 | @item @var{function} | |
2759 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
2760 | Specifies the line of the open-brace that begins the body of the | |
2761 | function @var{function}. | |
2762 | ||
2763 | @item @var{filename}:@var{function} | |
2764 | Specifies the line of the open-brace that begins the body of the | |
2765 | function @var{function} in the file @var{filename}. You only need the | |
2766 | file name with a function name to avoid ambiguity when there are | |
2767 | identically named functions in different source files. | |
2768 | ||
2769 | @item *@var{address} | |
2770 | Specifies the line containing the program address @var{address}. | |
2771 | @var{address} may be any expression. | |
2772 | @end table | |
2773 | ||
2774 | @node Search, Source Path, List, Source | |
2775 | @section Searching Source Files | |
2776 | @cindex searching | |
2777 | @kindex reverse-search | |
2778 | ||
2779 | There are two commands for searching through the current source file for a | |
2780 | regular expression. | |
2781 | ||
2782 | @table @code | |
2783 | @item forward-search @var{regexp} | |
2784 | @itemx search @var{regexp} | |
2785 | @kindex search | |
2786 | @kindex forward-search | |
2787 | The command @samp{forward-search @var{regexp}} checks each line, starting | |
2788 | with the one following the last line listed, for a match for @var{regexp}. | |
2789 | It lists the line that is found. You can abbreviate the command name | |
2790 | as @code{fo}. The synonym @samp{search @var{regexp}} is also supported. | |
2791 | ||
2792 | @item reverse-search @var{regexp} | |
2793 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
2794 | with the one before the last line listed and going backward, for a match | |
2795 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
2796 | this command as @code{rev}. | |
2797 | @end table | |
2798 | ||
2799 | @node Source Path, Machine Code, Search, Source | |
2800 | @section Specifying Source Directories | |
2801 | ||
2802 | @cindex source path | |
2803 | @cindex directories for source files | |
2804 | Executable programs sometimes do not record the directories of the source | |
2805 | files from which they were compiled, just the names. Even when they do, | |
2806 | the directories could be moved between the compilation and your debugging | |
2807 | session. _GDBN__ has a list of directories to search for source files; | |
2808 | this is called the @dfn{source path}. Each time _GDBN__ wants a source file, | |
2809 | it tries all the directories in the list, in the order they are present | |
2810 | in the list, until it finds a file with the desired name. Note that | |
2811 | the executable search path is @emph{not} used for this purpose. Neither is | |
2812 | the current working directory, unless it happens to be in the source | |
2813 | path. | |
2814 | ||
2815 | If _GDBN__ can't find a source file in the source path, and the object | |
2816 | program records a directory, _GDBN__ tries that directory too. If the | |
2817 | source path is empty, and there is no record of the compilation | |
2818 | directory, _GDBN__ will, as a last resort, look in the current | |
2819 | directory. | |
2820 | ||
2821 | Whenever you reset or rearrange the source path, _GDBN__ will clear out | |
2822 | any information it has cached about where source files are found, where | |
2823 | each line is in the file, etc. | |
2824 | ||
2825 | @kindex directory | |
2826 | When you start _GDBN__, its source path is empty. | |
2827 | To add other directories, use the @code{directory} command. | |
2828 | ||
2829 | @table @code | |
2830 | @item directory @var{dirname} @dots{} | |
2831 | Add directory @var{dirname} to the front of the source path. Several | |
2832 | directory names may be given to this command, separated by @samp{:} or | |
2833 | whitespace. You may specify a directory that is already in the source | |
7463aadd RP |
2834 | path; this moves it forward, so it will be searched sooner. |
2835 | ||
2836 | You can use the string @samp{$cdir} to refer to the compilation | |
2837 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
2838 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
2839 | tracks the current working directory as it changes during your _GDBN__ | |
2840 | session, while the latter is immediately expanded to the current | |
2841 | directory at the time you add an entry to the source path. | |
70b88761 RP |
2842 | |
2843 | @item directory | |
2844 | Reset the source path to empty again. This requires confirmation. | |
2845 | ||
2846 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
2847 | @c repeating it would be a no-op we don't say that. (thanks to RMS) | |
2848 | ||
2849 | @item show directories | |
2850 | @kindex show directories | |
2851 | Print the source path: show which directories it contains. | |
2852 | @end table | |
2853 | ||
2854 | If your source path is cluttered with directories that are no longer of | |
2855 | interest, _GDBN__ may sometimes cause confusion by finding the wrong | |
2856 | versions of source. You can correct the situation as follows: | |
2857 | ||
2858 | @enumerate | |
2859 | @item | |
2860 | Use @code{directory} with no argument to reset the source path to empty. | |
2861 | ||
2862 | @item | |
2863 | Use @code{directory} with suitable arguments to reinstall the | |
2864 | directories you want in the source path. You can add all the | |
2865 | directories in one command. | |
2866 | @end enumerate | |
2867 | ||
2868 | @node Machine Code, , Source Path, Source | |
2869 | @section Source and Machine Code | |
2870 | You can use the command @code{info line} to map source lines to program | |
2871 | addresses (and viceversa), and the command @code{disassemble} to display | |
2872 | a range of addresses as machine instructions. | |
2873 | ||
2874 | @table @code | |
2875 | @item info line @var{linespec} | |
2876 | @kindex info line | |
2877 | Print the starting and ending addresses of the compiled code for | |
2878 | source line @var{linespec}. You can specify source lines in any of the | |
2879 | ways understood by the @code{list} command (@pxref{List}). | |
2880 | @end table | |
2881 | ||
2882 | For example, we can use @code{info line} to inquire on where the object | |
2883 | code for the first line of function @code{m4_changequote} lies: | |
2884 | @smallexample | |
2885 | (_GDBP__) info line m4_changecom | |
2886 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
2887 | @end smallexample | |
2888 | ||
2889 | @noindent | |
2890 | We can also inquire (using @code{*@var{addr}} as the form for | |
2891 | @var{linespec}) what source line covers a particular address: | |
2892 | @smallexample | |
2893 | (_GDBP__) info line *0x63ff | |
2894 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
2895 | @end smallexample | |
2896 | ||
2897 | @kindex $_ | |
2898 | After @code{info line}, the default address for the @code{x} | |
2899 | command is changed to the starting address of the line, so that | |
2900 | @samp{x/i} is sufficient to begin examining the machine code | |
2901 | (@pxref{Memory}). Also, this address is saved as the value of the | |
2902 | convenience variable @code{$_} (@pxref{Convenience Vars}). | |
2903 | ||
2904 | @table @code | |
2905 | @kindex disassemble | |
2906 | @item disassemble | |
2907 | This specialized command is provided to dump a range of memory as | |
2908 | machine instructions. The default memory range is the function | |
2909 | surrounding the program counter of the selected frame. A single | |
2910 | argument to this command is a program counter value; the function | |
2911 | surrounding this value will be dumped. Two arguments (separated by one | |
2912 | or more spaces) specify a range of addresses (first inclusive, second | |
2913 | exclusive) to be dumped. | |
2914 | @end table | |
2915 | ||
2916 | We can use @code{disassemble} to inspect the object code | |
2917 | range shown in the last @code{info line} example: | |
2918 | ||
2919 | @smallexample | |
2920 | (_GDBP__) disas 0x63e4 0x6404 | |
2921 | Dump of assembler code from 0x63e4 to 0x6404: | |
2922 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> | |
2923 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
2924 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
2925 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
2926 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
2927 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
2928 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
2929 | 0x6400 <builtin_init+5368>: nop | |
2930 | End of assembler dump. | |
2931 | (_GDBP__) | |
2932 | ||
2933 | @end smallexample | |
2934 | ||
2935 | @node Data, Symbols, Source, Top | |
2936 | @chapter Examining Data | |
2937 | ||
2938 | @cindex printing data | |
2939 | @cindex examining data | |
2940 | @kindex print | |
2941 | @kindex inspect | |
2942 | @c "inspect" isn't quite a synonym if you're using Epoch, which we don't | |
2943 | @c document because it's nonstandard... Under Epoch it displays in a | |
2944 | @c different window or something like that. | |
2945 | The usual way to examine data in your program is with the @code{print} | |
2946 | command (abbreviated @code{p}), or its synonym @code{inspect}. It | |
2947 | evaluates and prints the value of any valid expression of the language | |
2948 | the program is written in (for now, C or C++). You type | |
2949 | ||
2950 | @example | |
2951 | print @var{exp} | |
2952 | @end example | |
2953 | ||
2954 | @noindent | |
2955 | where @var{exp} is any valid expression (in the source language), and | |
2956 | the value of @var{exp} is printed in a format appropriate to its data | |
2957 | type. | |
2958 | ||
2959 | A more low-level way of examining data is with the @code{x} command. | |
2960 | It examines data in memory at a specified address and prints it in a | |
2961 | specified format. @xref{Memory}. | |
2962 | ||
2963 | @menu | |
2964 | * Expressions:: Expressions | |
2965 | * Variables:: Program Variables | |
2966 | * Arrays:: Artificial Arrays | |
2967 | * Output formats:: Output formats | |
2968 | * Memory:: Examining Memory | |
2969 | * Auto Display:: Automatic Display | |
2970 | * Print Settings:: Print Settings | |
2971 | * Value History:: Value History | |
2972 | * Convenience Vars:: Convenience Variables | |
2973 | * Registers:: Registers | |
2974 | * Floating Point Hardware:: Floating Point Hardware | |
2975 | @end menu | |
2976 | ||
2977 | @node Expressions, Variables, Data, Data | |
2978 | @section Expressions | |
2979 | ||
2980 | @cindex expressions | |
2981 | @code{print} and many other _GDBN__ commands accept an expression and | |
2982 | compute its value. Any kind of constant, variable or operator defined | |
2983 | by the programming language you are using is legal in an expression in | |
2984 | _GDBN__. This includes conditional expressions, function calls, casts | |
2985 | and string constants. It unfortunately does not include symbols defined | |
2986 | by preprocessor @code{#define} commands, or C++ expressions involving | |
2987 | @samp{::}, the name resolution operator. | |
2988 | @c FIXME: actually C++ a::b works except in obscure circumstances where it | |
2989 | @c FIXME...can conflict with GDB's own name scope resolution. | |
2990 | ||
2991 | Casts are supported in all languages, not just in C, because it is so | |
2992 | useful to cast a number into a pointer so as to examine a structure | |
2993 | at that address in memory. | |
2994 | ||
2995 | _GDBN__ supports three kinds of operator in addition to those of programming | |
2996 | languages: | |
2997 | ||
2998 | @table @code | |
2999 | @item @@ | |
3000 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
3001 | @xref{Arrays}, for more information. | |
3002 | ||
3003 | @item :: | |
3004 | @samp{::} allows you to specify a variable in terms of the file or | |
3005 | function where it is defined. @xref{Variables}. | |
3006 | ||
3007 | @item @{@var{type}@} @var{addr} | |
3008 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3009 | memory. @var{addr} may be any expression whose value is an integer or | |
3010 | pointer (but parentheses are required around binary operators, just as in | |
3011 | a cast). This construct is allowed regardless of what kind of data is | |
3012 | normally supposed to reside at @var{addr}.@refill | |
3013 | @end table | |
3014 | ||
3015 | @node Variables, Arrays, Expressions, Data | |
3016 | @section Program Variables | |
3017 | ||
3018 | The most common kind of expression to use is the name of a variable | |
3019 | in your program. | |
3020 | ||
3021 | Variables in expressions are understood in the selected stack frame | |
3022 | (@pxref{Selection}); they must either be global (or static) or be visible | |
3023 | according to the scope rules of the programming language from the point of | |
3024 | execution in that frame. This means that in the function | |
3025 | ||
3026 | @example | |
3027 | foo (a) | |
3028 | int a; | |
3029 | @{ | |
3030 | bar (a); | |
3031 | @{ | |
3032 | int b = test (); | |
3033 | bar (b); | |
3034 | @} | |
3035 | @} | |
3036 | @end example | |
3037 | ||
3038 | @noindent | |
3039 | the variable @code{a} is usable whenever the program is executing | |
3040 | within the function @code{foo}, but the variable @code{b} is visible | |
3041 | only while the program is executing inside the block in which @code{b} | |
3042 | is declared. | |
3043 | ||
3044 | @cindex variable name conflict | |
3045 | There is an exception: you can refer to a variable or function whose | |
3046 | scope is a single source file even if the current execution point is not | |
3047 | in this file. But it is possible to have more than one such variable or | |
3048 | function with the same name (in different source files). If that happens, | |
3049 | referring to that name has unpredictable effects. If you wish, you can | |
3050 | specify a variable in a particular file, using the colon-colon notation: | |
3051 | ||
3052 | @cindex colon-colon | |
3053 | @kindex :: | |
3054 | @example | |
3055 | @var{file}::@var{variable} | |
3056 | @end example | |
3057 | ||
3058 | @noindent | |
3059 | Here @var{file} is the name of the source file whose variable you want. | |
3060 | ||
3061 | @cindex C++ name resolution | |
3062 | This use of @samp{::} is very rarely in conflict with the very similar | |
3063 | use of the same notation in C++. _GDBN__ also supports use of the C++ | |
3064 | name resolution operator in _GDBN__ expressions. | |
3065 | ||
3066 | @node Arrays, Output formats, Variables, Data | |
3067 | @section Artificial Arrays | |
3068 | ||
3069 | @cindex artificial array | |
3070 | @kindex @@ | |
3071 | It is often useful to print out several successive objects of the | |
3072 | same type in memory; a section of an array, or an array of | |
3073 | dynamically determined size for which only a pointer exists in the | |
3074 | program. | |
3075 | ||
3076 | This can be done by constructing an @dfn{artificial array} with the | |
3077 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3078 | the first element of the desired array, as an individual object. | |
3079 | The right operand should be the desired length of the array. The result is | |
3080 | an array value whose elements are all of the type of the left argument. | |
3081 | The first element is actually the left argument; the second element | |
3082 | comes from bytes of memory immediately following those that hold the | |
3083 | first element, and so on. Here is an example. If a program says | |
3084 | ||
3085 | @example | |
3086 | int *array = (int *) malloc (len * sizeof (int)); | |
3087 | @end example | |
3088 | ||
3089 | @noindent | |
3090 | you can print the contents of @code{array} with | |
3091 | ||
3092 | @example | |
3093 | p *array@@len | |
3094 | @end example | |
3095 | ||
3096 | The left operand of @samp{@@} must reside in memory. Array values made | |
3097 | with @samp{@@} in this way behave just like other arrays in terms of | |
3098 | subscripting, and are coerced to pointers when used in expressions. | |
3099 | Artificial arrays most often appear in expressions via the value history | |
3100 | (@pxref{Value History}), after printing one out.) | |
3101 | ||
3102 | @node Output formats, Memory, Arrays, Data | |
3103 | @section Output formats | |
3104 | ||
3105 | @cindex formatted output | |
3106 | @cindex output formats | |
3107 | By default, _GDBN__ prints a value according to its data type. Sometimes | |
3108 | this is not what you want. For example, you might want to print a number | |
3109 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3110 | at a certain address as a character string or as an instruction. To do | |
3111 | these things, specify an @dfn{output format} when you print a value. | |
3112 | ||
3113 | The simplest use of output formats is to say how to print a value | |
3114 | already computed. This is done by starting the arguments of the | |
3115 | @code{print} command with a slash and a format letter. The format | |
3116 | letters supported are: | |
3117 | ||
3118 | @table @code | |
3119 | @item x | |
3120 | Regard the bits of the value as an integer, and print the integer in | |
3121 | hexadecimal. | |
3122 | ||
3123 | @item d | |
3124 | Print as integer in signed decimal. | |
3125 | ||
3126 | @item u | |
3127 | Print as integer in unsigned decimal. | |
3128 | ||
3129 | @item o | |
3130 | Print as integer in octal. | |
3131 | ||
3132 | @item t | |
3133 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3134 | ||
3135 | @item a | |
3136 | Print as an address, both absolute in hex and as an offset from the | |
3137 | nearest preceding symbol. This format can be used to discover where (in | |
3138 | what function) an unknown address is located: | |
3139 | @example | |
3140 | (_GDBP__) p/a 0x54320 | |
3141 | _0__$3 = 0x54320 <_initialize_vx+396>_1__ | |
3142 | @end example | |
3143 | ||
3144 | ||
3145 | @item c | |
3146 | Regard as an integer and print it as a character constant. | |
3147 | ||
3148 | @item f | |
3149 | Regard the bits of the value as a floating point number and print | |
3150 | using typical floating point syntax. | |
3151 | @end table | |
3152 | ||
3153 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3154 | ||
3155 | @example | |
3156 | p/x $pc | |
3157 | @end example | |
3158 | ||
3159 | @noindent | |
3160 | Note that no space is required before the slash; this is because command | |
3161 | names in _GDBN__ cannot contain a slash. | |
3162 | ||
3163 | To reprint the last value in the value history with a different format, | |
3164 | you can use the @code{print} command with just a format and no | |
3165 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3166 | ||
3167 | @node Memory, Auto Display, Output formats, Data | |
3168 | @section Examining Memory | |
3169 | ||
3170 | @cindex examining memory | |
3171 | @table @code | |
3172 | @kindex x | |
3173 | @item x/@var{nfu} @var{expr} | |
3174 | The command @code{x} (for `examine') can be used to examine memory | |
3175 | without being constrained by your program's data types. You can specify | |
3176 | the unit size @var{u} of memory to inspect, and a repeat count @var{n} of how | |
3177 | many of those units to display. @code{x} understands the formats | |
3178 | @var{f} used by @code{print}; two additional formats, @samp{s} (string) | |
3179 | and @samp{i} (machine instruction) can be used without specifying a unit | |
3180 | size. | |
3181 | @end table | |
3182 | ||
3183 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords | |
3184 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3185 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3186 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3187 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
3188 | ||
3189 | Since the letters indicating unit sizes are all distinct from the | |
3190 | letters specifying output formats, you don't have to remember whether | |
3191 | unit size or format comes first; either order will work. The output | |
3192 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3193 | ||
3194 | After the format specification, you supply an expression for the address | |
3195 | where _GDBN__ is to begin reading from memory. The expression need not | |
3196 | have a pointer value (though it may); it is always interpreted as an | |
3197 | integer address of a byte of memory. @xref{Expressions} for more | |
3198 | information on expressions. | |
3199 | ||
3200 | These are the memory units @var{u} you can specify with the @code{x} | |
3201 | command: | |
3202 | ||
3203 | @table @code | |
3204 | @item b | |
3205 | Examine individual bytes. | |
3206 | ||
3207 | @item h | |
3208 | Examine halfwords (two bytes each). | |
3209 | ||
3210 | @item w | |
3211 | Examine words (four bytes each). | |
3212 | ||
3213 | @cindex word | |
3214 | Many assemblers and cpu designers still use `word' for a 16-bit quantity, | |
3215 | as a holdover from specific predecessor machines of the 1970's that really | |
3216 | did use two-byte words. But more generally the term `word' has always | |
3217 | referred to the size of quantity that a machine normally operates on and | |
3218 | stores in its registers. This is 32 bits for all the machines that _GDBN__ | |
3219 | runs on. | |
3220 | ||
3221 | @item g | |
3222 | Examine giant words (8 bytes). | |
3223 | @end table | |
3224 | ||
3225 | You can combine these unit specifications with any of the formats | |
3226 | described for @code{print}. @xref{Output formats}. | |
3227 | ||
3228 | @code{x} has two additional output specifications which derive the unit | |
3229 | size from the data inspected: | |
3230 | ||
3231 | @table @code | |
3232 | @item s | |
3233 | Print a null-terminated string of characters. Any explicitly specified | |
3234 | unit size is ignored; instead, the unit is however many bytes it takes | |
3235 | to reach a null character (including the null character). | |
3236 | ||
3237 | @item i | |
3238 | Print a machine instruction in assembler syntax (or nearly). Any | |
3239 | specified unit size is ignored; the number of bytes in an instruction | |
3240 | varies depending on the type of machine, the opcode and the addressing | |
3241 | modes used. The command @code{disassemble} gives an alternative way of | |
3242 | inspecting machine instructions. @xref{Machine Code}. | |
3243 | @end table | |
3244 | ||
3245 | If you omit either the format @var{f} or the unit size @var{u}, @code{x} | |
3246 | will use the same one that was used last. If you don't use any letters | |
3247 | or digits after the slash, you can omit the slash as well. | |
3248 | ||
3249 | You can also omit the address to examine. Then the address used is just | |
3250 | after the last unit examined. This is why string and instruction | |
3251 | formats actually compute a unit-size based on the data: so that the next | |
3252 | string or instruction examined will start in the right place. | |
3253 | ||
3254 | When the @code{print} command shows a value that resides in memory, | |
3255 | @code{print} also sets the default address for the @code{x} command. | |
3256 | @code{info line} also sets the default for @code{x}, to the address of | |
3257 | the start of the machine code for the specified line (@pxref{Machine | |
3258 | Code}), and @code{info breakpoints} sets it to the address of the last | |
3259 | breakpoint listed (@pxref{Set Breaks}). | |
3260 | ||
3261 | When you use @key{RET} to repeat an @code{x} command, the address | |
3262 | specified previously (if any) is ignored, so that the repeated command | |
3263 | examines the successive locations in memory rather than the same ones. | |
3264 | ||
3265 | You can examine several consecutive units of memory with one command by | |
3266 | writing a repeat-count after the slash (before the format letters, if | |
3267 | any). Omitting the repeat count @var{n} displays one unit of the | |
3268 | appropriate size. The repeat count must be a decimal integer. It has | |
3269 | the same effect as repeating the @code{x} command @var{n} times except | |
3270 | that the output may be more compact, with several units per line. For | |
3271 | example, | |
3272 | ||
3273 | @example | |
3274 | x/10i $pc | |
3275 | @end example | |
3276 | ||
3277 | @noindent | |
3278 | prints ten instructions starting with the one to be executed next in the | |
3279 | selected frame. After doing this, you could print a further seven | |
3280 | instructions with | |
3281 | ||
3282 | @example | |
3283 | x/7 | |
3284 | @end example | |
3285 | ||
3286 | @noindent | |
3287 | ---where the format and address are allowed to default. | |
3288 | ||
3289 | @kindex $_ | |
3290 | @kindex $__ | |
3291 | The addresses and contents printed by the @code{x} command are not put | |
3292 | in the value history because there is often too much of them and they | |
3293 | would get in the way. Instead, _GDBN__ makes these values available for | |
3294 | subsequent use in expressions as values of the convenience variables | |
3295 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3296 | examined is available for use in expressions in the convenience variable | |
3297 | @code{$_}. The contents of that address, as examined, are available in | |
3298 | the convenience variable @code{$__}. | |
3299 | ||
3300 | If the @code{x} command has a repeat count, the address and contents saved | |
3301 | are from the last memory unit printed; this is not the same as the last | |
3302 | address printed if several units were printed on the last line of output. | |
3303 | ||
3304 | @node Auto Display, Print Settings, Memory, Data | |
3305 | @section Automatic Display | |
3306 | @cindex automatic display | |
3307 | @cindex display of expressions | |
3308 | ||
3309 | If you find that you want to print the value of an expression frequently | |
3310 | (to see how it changes), you might want to add it to the @dfn{automatic | |
3311 | display list} so that _GDBN__ will print its value each time the program stops. | |
3312 | Each expression added to the list is given a number to identify it; | |
3313 | to remove an expression from the list, you specify that number. | |
3314 | The automatic display looks like this: | |
3315 | ||
3316 | @example | |
3317 | 2: foo = 38 | |
3318 | 3: bar[5] = (struct hack *) 0x3804 | |
3319 | @end example | |
3320 | ||
3321 | @noindent | |
3322 | showing item numbers, expressions and their current values. As with | |
3323 | displays you request manually using @code{x} or @code{print}, you can | |
3324 | specify the output format you prefer; in fact, @code{display} decides | |
3325 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3326 | format specification is---it uses @code{x} if you specify a unit size, | |
3327 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3328 | supported by @code{x}; otherwise it uses @code{print}. | |
3329 | ||
3330 | @table @code | |
3331 | @item display @var{exp} | |
3332 | @kindex display | |
3333 | Add the expression @var{exp} to the list of expressions to display | |
3334 | each time the program stops. @xref{Expressions}. | |
3335 | ||
3336 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3337 | ||
3338 | @item display/@var{fmt} @var{exp} | |
3339 | For @var{fmt} specifying only a display format and not a size or | |
3340 | count, add the expression @var{exp} to the auto-display list but | |
3341 | arranges to display it each time in the specified format @var{fmt}. | |
3342 | @xref{Output formats}. | |
3343 | ||
3344 | @item display/@var{fmt} @var{addr} | |
3345 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3346 | number of units, add the expression @var{addr} as a memory address to | |
3347 | be examined each time the program stops. Examining means in effect | |
3348 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}. | |
3349 | @end table | |
3350 | ||
3351 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3352 | instruction about to be executed each time execution stops (@samp{$pc} | |
3353 | is a common name for the program counter; @pxref{Registers}). | |
3354 | ||
3355 | @table @code | |
3356 | @item undisplay @var{dnums}@dots{} | |
3357 | @itemx delete display @var{dnums}@dots{} | |
3358 | @kindex delete display | |
3359 | @kindex undisplay | |
3360 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3361 | ||
3362 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3363 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3364 | ||
3365 | @item disable display @var{dnums}@dots{} | |
3366 | @kindex disable display | |
3367 | Disable the display of item numbers @var{dnums}. A disabled display | |
3368 | item is not printed automatically, but is not forgotten. It may be | |
3369 | enabled again later. | |
3370 | ||
3371 | @item enable display @var{dnums}@dots{} | |
3372 | @kindex enable display | |
3373 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3374 | again in auto display of its expression, until you specify otherwise. | |
3375 | ||
3376 | @item display | |
3377 | Display the current values of the expressions on the list, just as is | |
3378 | done when the program stops. | |
3379 | ||
3380 | @item info display | |
3381 | @kindex info display | |
3382 | Print the list of expressions previously set up to display | |
3383 | automatically, each one with its item number, but without showing the | |
3384 | values. This includes disabled expressions, which are marked as such. | |
3385 | It also includes expressions which would not be displayed right now | |
3386 | because they refer to automatic variables not currently available. | |
3387 | @end table | |
3388 | ||
3389 | If a display expression refers to local variables, then it does not make | |
3390 | sense outside the lexical context for which it was set up. Such an | |
3391 | expression is disabled when execution enters a context where one of its | |
3392 | variables is not defined. For example, if you give the command | |
3393 | @code{display last_char} while inside a function with an argument | |
3394 | @code{last_char}, then this argument will be displayed while the program | |
3395 | continues to stop inside that function. When it stops elsewhere---where | |
3396 | there is no variable @code{last_char}---display is disabled. The next time | |
3397 | your program stops where @code{last_char} is meaningful, you can enable the | |
3398 | display expression once again. | |
3399 | ||
3400 | @node Print Settings, Value History, Auto Display, Data | |
3401 | @section Print Settings | |
3402 | ||
3403 | @cindex format options | |
3404 | @cindex print settings | |
3405 | _GDBN__ provides the following ways to control how arrays, structures, | |
3406 | and symbols are printed. | |
3407 | ||
3408 | @noindent | |
3409 | These settings are useful for debugging programs in any language: | |
3410 | ||
3411 | @table @code | |
3412 | @item set print address | |
3413 | @item set print address on | |
3414 | @kindex set print address | |
3415 | _GDBN__ will print memory addresses showing the location of stack | |
3416 | traces, structure values, pointer values, breakpoints, and so forth, | |
3417 | even when it also displays the contents of those addresses. The default | |
3418 | is on. For example, this is what a stack frame display looks like, with | |
3419 | @code{set print address on}: | |
3420 | @smallexample | |
3421 | (_GDBP__) f | |
3422 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") | |
3423 | at input.c:530 | |
3424 | 530 if (lquote != def_lquote) | |
3425 | @end smallexample | |
3426 | ||
3427 | @item set print address off | |
3428 | Do not print addresses when displaying their contents. For example, | |
3429 | this is the same stack frame displayed with @code{set print address off}: | |
3430 | @example | |
3431 | (_GDBP__) set print addr off | |
3432 | (_GDBP__) f | |
3433 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
3434 | 530 if (lquote != def_lquote) | |
3435 | @end example | |
3436 | ||
3437 | @item show print address | |
3438 | @kindex show print address | |
3439 | Show whether or not addresses are to be printed. | |
3440 | ||
3441 | @item set print array | |
3442 | @itemx set print array on | |
3443 | @kindex set print array | |
3444 | _GDBN__ will pretty print arrays. This format is more convenient to read, | |
3445 | but uses more space. The default is off. | |
3446 | ||
3447 | @item set print array off. | |
3448 | Return to compressed format for arrays. | |
3449 | ||
3450 | @item show print array | |
3451 | @kindex show print array | |
3452 | Show whether compressed or pretty format is selected for displaying | |
3453 | arrays. | |
3454 | ||
3455 | @item set print elements @var{number-of-elements} | |
3456 | @kindex set print elements | |
3457 | If _GDBN__ is printing a large array, it will stop printing after it has | |
3458 | printed the number of elements set by the @code{set print elements} command. | |
3459 | This limit also applies to the display of strings. | |
3460 | ||
3461 | @item show print elements | |
3462 | @kindex show print elements | |
3463 | Display the number of elements of a large array that _GDBN__ will print | |
3464 | before losing patience. | |
3465 | ||
3466 | @item set print pretty on | |
3467 | @kindex set print pretty | |
3468 | Cause _GDBN__ to print structures in an indented format with one member per | |
3469 | line, like this: | |
3470 | ||
3471 | @example | |
3472 | $1 = @{ | |
3473 | next = 0x0, | |
3474 | flags = @{ | |
3475 | sweet = 1, | |
3476 | sour = 1 | |
3477 | @}, | |
3478 | meat = 0x54 "Pork" | |
3479 | @} | |
3480 | @end example | |
3481 | ||
3482 | @item set print pretty off | |
3483 | Cause _GDBN__ to print structures in a compact format, like this: | |
3484 | ||
3485 | @smallexample | |
3486 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \ | |
3487 | = 0x54 "Pork"@} | |
3488 | @end smallexample | |
3489 | ||
3490 | @noindent | |
3491 | This is the default format. | |
3492 | ||
3493 | @item show print pretty | |
3494 | @kindex show print pretty | |
3495 | Show which format _GDBN__ will use to print structures. | |
3496 | ||
3497 | @item set print sevenbit-strings on | |
3498 | Print using only seven-bit characters; if this option is set, | |
3499 | _GDBN__ will display any eight-bit characters (in strings or character | |
3500 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
3501 | displayed as @code{\341}. | |
3502 | ||
3503 | @item set print sevenbit-strings off | |
3504 | Print using either seven-bit or eight-bit characters, as required. This | |
3505 | is the default. | |
3506 | ||
3507 | @item show print sevenbit-strings | |
3508 | Show whether or not _GDBN__ will print only seven-bit characters. | |
3509 | ||
3510 | @item set print union on | |
3511 | @kindex set print union | |
3512 | Tell _GDBN__ to print unions which are contained in structures. This is the | |
3513 | default setting. | |
3514 | ||
3515 | @item set print union off | |
3516 | Tell _GDBN__ not to print unions which are contained in structures. | |
3517 | ||
3518 | @item show print union | |
3519 | @kindex show print union | |
3520 | Ask _GDBN__ whether or not it will print unions which are contained in | |
3521 | structures. | |
3522 | ||
3523 | For example, given the declarations | |
3524 | ||
3525 | @smallexample | |
3526 | typedef enum @{Tree, Bug@} Species; | |
3527 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
3528 | typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms; | |
3529 | ||
3530 | struct thing @{ | |
3531 | Species it; | |
3532 | union @{ | |
3533 | Tree_forms tree; | |
3534 | Bug_forms bug; | |
3535 | @} form; | |
3536 | @}; | |
3537 | ||
3538 | struct thing foo = @{Tree, @{Acorn@}@}; | |
3539 | @end smallexample | |
3540 | ||
3541 | @noindent | |
3542 | with @code{set print union on} in effect @samp{p foo} would print | |
3543 | ||
3544 | @smallexample | |
3545 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
3546 | @end smallexample | |
3547 | ||
3548 | @noindent | |
3549 | and with @code{set print union off} in effect it would print | |
3550 | ||
3551 | @smallexample | |
3552 | $1 = @{it = Tree, form = @{...@}@} | |
3553 | @end smallexample | |
3554 | @end table | |
3555 | ||
3556 | @noindent | |
3557 | These settings are of interest when debugging C++ programs: | |
3558 | ||
3559 | @table @code | |
3560 | @item set print demangle | |
3561 | @itemx set print demangle on | |
3562 | @kindex set print demangle | |
3563 | Print C++ names in their source form rather than in the mangled form | |
3564 | in which they are passed to the assembler and linker for type-safe linkage. | |
3565 | The default is on. | |
3566 | ||
3567 | @item show print demangle | |
3568 | @kindex show print demangle | |
3569 | Show whether C++ names will be printed in mangled or demangled form. | |
3570 | ||
3571 | @item set print asm-demangle | |
3572 | @itemx set print asm-demangle on | |
3573 | @kindex set print asm-demangle | |
3574 | Print C++ names in their source form rather than their mangled form, even | |
3575 | in assembler code printouts such as instruction disassemblies. | |
3576 | The default is off. | |
3577 | ||
3578 | @item show print asm-demangle | |
3579 | @kindex show print asm-demangle | |
3580 | Show whether C++ names in assembly listings will be printed in mangled | |
3581 | or demangled form. | |
3582 | ||
3583 | @item set print object | |
3584 | @itemx set print object on | |
3585 | @kindex set print object | |
3586 | When displaying a pointer to an object, identify the @emph{actual} | |
3587 | (derived) type of the object rather than the @emph{declared} type, using | |
3588 | the virtual function table. | |
3589 | ||
3590 | @item set print object off | |
3591 | Display only the declared type of objects, without reference to the | |
3592 | virtual function table. This is the default setting. | |
3593 | ||
3594 | @item show print object | |
3595 | @kindex show print object | |
3596 | Show whether actual, or declared, object types will be displayed. | |
3597 | ||
3598 | @item set print vtbl | |
3599 | @itemx set print vtbl on | |
3600 | @kindex set print vtbl | |
3601 | Pretty print C++ virtual function tables. The default is off. | |
3602 | ||
3603 | @item set print vtbl off | |
3604 | Do not pretty print C++ virtual function tables. | |
3605 | ||
3606 | @item show print vtbl | |
3607 | @kindex show print vtbl | |
3608 | Show whether C++ virtual function tables are pretty printed, or not. | |
3609 | ||
3610 | @end table | |
3611 | ||
3612 | @node Value History, Convenience Vars, Print Settings, Data | |
3613 | @section Value History | |
3614 | ||
3615 | @cindex value history | |
3616 | Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value | |
3617 | history} so that you can refer to them in other expressions. Values are | |
3618 | kept until the symbol table is re-read or discarded (for example with | |
3619 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
3620 | changes, the value history is discarded, since the values may contain | |
3621 | pointers back to the types defined in the symbol table. | |
3622 | ||
3623 | @cindex @code{$} | |
3624 | @cindex @code{$$} | |
3625 | @cindex history number | |
3626 | The values printed are given @dfn{history numbers} for you to refer to them | |
3627 | by. These are successive integers starting with one. @code{print} shows you | |
3628 | the history number assigned to a value by printing @samp{$@var{num} = } | |
3629 | before the value; here @var{num} is the history number. | |
3630 | ||
3631 | To refer to any previous value, use @samp{$} followed by the value's | |
3632 | history number. The way @code{print} labels its output is designed to | |
3633 | remind you of this. Just @code{$} refers to the most recent value in | |
3634 | the history, and @code{$$} refers to the value before that. | |
3635 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
3636 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
3637 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
3638 | ||
3639 | For example, suppose you have just printed a pointer to a structure and | |
3640 | want to see the contents of the structure. It suffices to type | |
3641 | ||
3642 | @example | |
3643 | p *$ | |
3644 | @end example | |
3645 | ||
3646 | If you have a chain of structures where the component @code{next} points | |
3647 | to the next one, you can print the contents of the next one with this: | |
3648 | ||
3649 | @example | |
3650 | p *$.next | |
3651 | @end example | |
3652 | ||
3653 | @noindent | |
3654 | You can print successive links in the chain by repeating this | |
3655 | command---which you can do by just typing @key{RET}. | |
3656 | ||
3657 | Note that the history records values, not expressions. If the value of | |
3658 | @code{x} is 4 and you type these commands: | |
3659 | ||
3660 | @example | |
3661 | print x | |
3662 | set x=5 | |
3663 | @end example | |
3664 | ||
3665 | @noindent | |
3666 | then the value recorded in the value history by the @code{print} command | |
3667 | remains 4 even though the value of @code{x} has changed. | |
3668 | ||
3669 | @table @code | |
3670 | @kindex show values | |
3671 | @item show values | |
3672 | Print the last ten values in the value history, with their item numbers. | |
3673 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
3674 | values} does not change the history. | |
3675 | ||
3676 | @item show values @var{n} | |
3677 | Print ten history values centered on history item number @var{n}. | |
3678 | ||
3679 | @item show values + | |
3680 | Print ten history values just after the values last printed. If no more | |
3681 | values are available, produces no display. | |
3682 | @end table | |
3683 | ||
3684 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
3685 | same effect as @samp{show values +}. | |
3686 | ||
3687 | @node Convenience Vars, Registers, Value History, Data | |
3688 | @section Convenience Variables | |
3689 | ||
3690 | @cindex convenience variables | |
3691 | _GDBN__ provides @dfn{convenience variables} that you can use within | |
3692 | _GDBN__ to hold on to a value and refer to it later. These variables | |
3693 | exist entirely within _GDBN__; they are not part of your program, and | |
3694 | setting a convenience variable has no direct effect on further execution | |
3695 | of your program. That's why you can use them freely. | |
3696 | ||
3697 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
3698 | @samp{$} can be used for a convenience variable, unless it is one of | |
3699 | the predefined machine-specific register names (@pxref{Registers}). | |
3700 | (Value history references, in contrast, are @emph{numbers} preceded | |
3701 | by @samp{$}. @xref{Value History}.) | |
3702 | ||
3703 | You can save a value in a convenience variable with an assignment | |
3704 | expression, just as you would set a variable in your program. Example: | |
3705 | ||
3706 | @example | |
3707 | set $foo = *object_ptr | |
3708 | @end example | |
3709 | ||
3710 | @noindent | |
3711 | would save in @code{$foo} the value contained in the object pointed to by | |
3712 | @code{object_ptr}. | |
3713 | ||
3714 | Using a convenience variable for the first time creates it; but its value | |
3715 | is @code{void} until you assign a new value. You can alter the value with | |
3716 | another assignment at any time. | |
3717 | ||
3718 | Convenience variables have no fixed types. You can assign a convenience | |
3719 | variable any type of value, including structures and arrays, even if | |
3720 | that variable already has a value of a different type. The convenience | |
3721 | variable, when used as an expression, has the type of its current value. | |
3722 | ||
3723 | @table @code | |
3724 | @item show convenience | |
3725 | @kindex show convenience | |
3726 | Print a list of convenience variables used so far, and their values. | |
3727 | Abbreviated @code{show con}. | |
3728 | @end table | |
3729 | ||
3730 | One of the ways to use a convenience variable is as a counter to be | |
3731 | incremented or a pointer to be advanced. For example, to print | |
3732 | a field from successive elements of an array of structures: | |
3733 | ||
3734 | _0__@example | |
3735 | set $i = 0 | |
3736 | print bar[$i++]->contents | |
3737 | @i{@dots{} repeat that command by typing @key{RET}.} | |
3738 | _1__@end example | |
3739 | ||
3740 | Some convenience variables are created automatically by _GDBN__ and given | |
3741 | values likely to be useful. | |
3742 | ||
3743 | @table @code | |
3744 | @item $_ | |
3745 | The variable @code{$_} is automatically set by the @code{x} command to | |
3746 | the last address examined (@pxref{Memory}). Other commands which | |
3747 | provide a default address for @code{x} to examine also set @code{$_} | |
3748 | to that address; these commands include @code{info line} and @code{info | |
3749 | breakpoint}. | |
3750 | ||
3751 | @item $__ | |
3752 | The variable @code{$__} is automatically set by the @code{x} command | |
3753 | to the value found in the last address examined. | |
3754 | @end table | |
3755 | ||
3756 | @node Registers, Floating Point Hardware, Convenience Vars, Data | |
3757 | @section Registers | |
3758 | ||
3759 | @cindex registers | |
3760 | Machine register contents can be referred to in expressions as variables | |
3761 | with names starting with @samp{$}. The names of registers are different | |
3762 | for each machine; use @code{info registers} to see the names used on | |
3763 | your machine. | |
3764 | ||
3765 | @table @code | |
3766 | @item info registers | |
3767 | @kindex info registers | |
3768 | Print the names and values of all registers (in the selected stack frame). | |
3769 | ||
3770 | @item info registers @var{regname} | |
3771 | Print the relativized value of register @var{regname}. @var{regname} | |
3772 | may be any register name valid on the machine you are using, with | |
3773 | or without the initial @samp{$}. | |
3774 | @end table | |
3775 | ||
3776 | The register names @code{$pc} and @code{$sp} are used on most machines | |
3777 | for the program counter register and the stack pointer. For example, | |
3778 | you could print the program counter in hex with | |
3779 | @example | |
3780 | p/x $pc | |
3781 | @end example | |
3782 | ||
3783 | @noindent | |
3784 | or print the instruction to be executed next with | |
3785 | @example | |
3786 | x/i $pc | |
3787 | @end example | |
3788 | ||
3789 | @noindent | |
3790 | or add four to the stack pointer with | |
3791 | @example | |
3792 | set $sp += 4 | |
3793 | @end example | |
3794 | ||
3795 | @noindent | |
3796 | The last is a way of removing one word from the stack, on machines where | |
3797 | stacks grow downward in memory (most machines, nowadays). This assumes | |
3798 | that the innermost stack frame is selected; setting @code{$sp} is | |
3799 | not allowed when other stack frames are selected. (To pop entire frames | |
3800 | off the stack, regardless of machine architecture, use @code{return}; | |
3801 | @pxref{Returning}.) | |
3802 | ||
3803 | Often @code{$fp} is used for a register that contains a pointer to the | |
3804 | current stack frame, and @code{$ps} is sometimes used for a register | |
3805 | that contains the processor status. These standard register names may | |
3806 | be available on your machine even though the @code{info registers} | |
3807 | command shows other names. For example, on the SPARC, @code{info | |
3808 | registers} displays the processor status register as @code{$psr} but you | |
3809 | can also refer to it as @code{$ps}. | |
3810 | ||
3811 | _GDBN__ always considers the contents of an ordinary register as an | |
3812 | integer when the register is examined in this way. Some machines have | |
3813 | special registers which can hold nothing but floating point; these | |
3814 | registers are considered to have floating point values. There is no way | |
3815 | to refer to the contents of an ordinary register as floating point value | |
3816 | (although you can @emph{print} it as a floating point value with | |
3817 | @samp{print/f $@var{regname}}). | |
3818 | ||
3819 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
3820 | means that the data format in which the register contents are saved by | |
3821 | the operating system is not the same one that your program normally | |
3822 | sees. For example, the registers of the 68881 floating point | |
3823 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
3824 | programs expect to work with ``double'' (virtual) format. In such | |
3825 | cases, _GDBN__ normally works with the virtual format only (the format that | |
3826 | makes sense for your program), but the @code{info registers} command | |
3827 | prints the data in both formats. | |
3828 | ||
3829 | Normally, register values are relative to the selected stack frame | |
3830 | (@pxref{Selection}). This means that you get the value that the | |
3831 | register would contain if all stack frames farther in were exited and | |
3832 | their saved registers restored. In order to see the true contents of | |
3833 | hardware registers, you must select the innermost frame (with | |
3834 | @samp{frame 0}). | |
3835 | ||
3836 | However, _GDBN__ must deduce where registers are saved, from the machine | |
3837 | code generated by your compiler. If some registers are not saved, or if | |
3838 | _GDBN__ is unable to locate the saved registers, the selected stack | |
3839 | frame will make no difference. | |
3840 | ||
3841 | @node Floating Point Hardware, , Registers, Data | |
3842 | @section Floating Point Hardware | |
3843 | @cindex floating point | |
3844 | Depending on the host machine architecture, _GDBN__ may be able to give | |
3845 | you more information about the status of the floating point hardware. | |
3846 | ||
3847 | @table @code | |
3848 | @item info float | |
3849 | @kindex info float | |
3850 | If available, provides hardware-dependent information about the floating | |
3851 | point unit. The exact contents and layout vary depending on the | |
3852 | floating point chip. | |
3853 | @end table | |
3854 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
3855 | @c FIXME...supported currently on arm's and 386's. Mark properly with | |
3856 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
3857 | @c FIXME... at that point. | |
3858 | ||
3859 | @node Symbols, Altering, Data, Top | |
3860 | @chapter Examining the Symbol Table | |
3861 | ||
3862 | The commands described in this section allow you to inquire about the | |
3863 | symbols (names of variables, functions and types) defined in your | |
3864 | program. This information is inherent in the text of your program and | |
3865 | does not change as the program executes. _GDBN__ finds it in your | |
3866 | program's symbol table, in the file indicated when you started _GDBN__ | |
3867 | (@pxref{File Options}), or by one of the file-management commands | |
3868 | (@pxref{Files}). | |
3869 | ||
3870 | @table @code | |
3871 | @item info address @var{symbol} | |
3872 | @kindex info address | |
3873 | Describe where the data for @var{symbol} is stored. For a register | |
3874 | variable, this says which register it is kept in. For a non-register | |
3875 | local variable, this prints the stack-frame offset at which the variable | |
3876 | is always stored. | |
3877 | ||
3878 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
3879 | at all for a register variables, and for a stack local variable prints | |
3880 | the exact address of the current instantiation of the variable. | |
3881 | ||
3882 | @item whatis @var{exp} | |
3883 | @kindex whatis | |
3884 | Print the data type of expression @var{exp}. @var{exp} is not | |
3885 | actually evaluated, and any side-effecting operations (such as | |
3886 | assignments or function calls) inside it do not take place. | |
3887 | @xref{Expressions}. | |
3888 | ||
3889 | @item whatis | |
3890 | Print the data type of @code{$}, the last value in the value history. | |
3891 | ||
3892 | @item ptype @var{typename} | |
3893 | @kindex ptype | |
3894 | Print a description of data type @var{typename}. @var{typename} may be | |
3895 | the name of a type, or for C code it may have the form | |
3896 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
3897 | @samp{enum @var{enum-tag}}.@refill | |
3898 | ||
3899 | @item ptype @var{exp} | |
3900 | Print a description of the type of expression @var{exp}. @code{ptype} | |
3901 | differs from @code{whatis} by printing a detailed description, instead of just | |
3902 | the name of the type. For example, if your program declares a variable | |
3903 | as | |
3904 | @example | |
3905 | struct complex @{double real; double imag;@} v; | |
3906 | @end example | |
3907 | @noindent | |
3908 | compare the output of the two commands: | |
3909 | @example | |
3910 | (_GDBP__) whatis v | |
3911 | type = struct complex | |
3912 | (_GDBP__) ptype v | |
3913 | type = struct complex @{ | |
3914 | double real; | |
3915 | double imag; | |
3916 | @} | |
3917 | @end example | |
3918 | ||
3919 | @item info types @var{regexp} | |
3920 | @itemx info types | |
3921 | @kindex info types | |
3922 | Print a brief description of all types whose name matches @var{regexp} | |
3923 | (or all types in your program, if you supply no argument). Each | |
3924 | complete typename is matched as though it were a complete line; thus, | |
3925 | @samp{i type value} gives information on all types in your program whose | |
3926 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
3927 | information only on types whose complete name is @code{value}. | |
3928 | ||
3929 | This command differs from @code{ptype} in two ways: first, like | |
3930 | @code{whatis}, it does not print a detailed description; second, it | |
3931 | lists all source files where a type is defined. | |
3932 | ||
3933 | @item info source | |
3934 | @kindex info source | |
3935 | Show the name of the current source file---that is, the source file for | |
3936 | the function containing the current point of execution. | |
3937 | ||
3938 | @item info sources | |
3939 | @kindex info sources | |
3940 | Print the names of all source files in the program for which there is | |
3941 | debugging information, organized into two lists: those for which symbols | |
3942 | have been read in, and those for which symbols will be read in on | |
3943 | demand. | |
3944 | @c FIXME: above passive AND awkward! | |
3945 | ||
3946 | @item info functions | |
3947 | @kindex info functions | |
3948 | Print the names and data types of all defined functions. | |
3949 | ||
3950 | @item info functions @var{regexp} | |
3951 | Print the names and data types of all defined functions | |
3952 | whose names contain a match for regular expression @var{regexp}. | |
3953 | Thus, @samp{info fun step} finds all functions whose names | |
3954 | include @code{step}; @samp{info fun ^step} finds those whose names | |
3955 | start with @code{step}. | |
3956 | ||
3957 | @item info variables | |
3958 | @kindex info variables | |
3959 | Print the names and data types of all variables that are declared | |
3960 | outside of functions (i.e., excluding local variables). | |
3961 | ||
3962 | @item info variables @var{regexp} | |
3963 | Print the names and data types of all variables (except for local | |
3964 | variables) whose names contain a match for regular expression | |
3965 | @var{regexp}. | |
3966 | ||
3967 | ||
3968 | @ignore | |
3969 | This was never implemented. | |
3970 | @item info methods | |
3971 | @itemx info methods @var{regexp} | |
3972 | @kindex info methods | |
3973 | The @code{info methods} command permits the user to examine all defined | |
3974 | methods within C++ program, or (with the @var{regexp} argument) a | |
3975 | specific set of methods found in the various C++ classes. Many | |
3976 | C++ classes provide a large number of methods. Thus, the output | |
3977 | from the @code{ptype} command can be overwhelming and hard to use. The | |
3978 | @code{info-methods} command filters the methods, printing only those | |
3979 | which match the regular-expression @var{regexp}. | |
3980 | @end ignore | |
3981 | ||
3982 | @item printsyms @var{filename} | |
3983 | @kindex printsyms | |
3984 | Write a complete dump of the debugger's symbol data into the | |
3985 | file @var{filename}. | |
3986 | @end table | |
3987 | ||
3988 | @node Altering, _GDBN__ Files, Symbols, Top | |
3989 | @chapter Altering Execution | |
3990 | ||
3991 | Once you think you have found an error in the program, you might want to | |
3992 | find out for certain whether correcting the apparent error would lead to | |
3993 | correct results in the rest of the run. You can find the answer by | |
3994 | experiment, using the _GDBN__ features for altering execution of the | |
3995 | program. | |
3996 | ||
3997 | For example, you can store new values into variables or memory | |
3998 | locations, give the program a signal, restart it at a different address, | |
3999 | or even return prematurely from a function to its caller. | |
4000 | ||
4001 | @menu | |
4002 | * Assignment:: Assignment to Variables | |
4003 | * Jumping:: Continuing at a Different Address | |
4004 | * Signaling:: Giving the Program a Signal | |
4005 | * Returning:: Returning from a Function | |
4006 | * Calling:: Calling your Program's Functions | |
4007 | @end menu | |
4008 | ||
4009 | @node Assignment, Jumping, Altering, Altering | |
4010 | @section Assignment to Variables | |
4011 | ||
4012 | @cindex assignment | |
4013 | @cindex setting variables | |
4014 | To alter the value of a variable, evaluate an assignment expression. | |
4015 | @xref{Expressions}. For example, | |
4016 | ||
4017 | @example | |
4018 | print x=4 | |
4019 | @end example | |
4020 | ||
4021 | @noindent | |
4022 | would store the value 4 into the variable @code{x}, and then print the | |
4023 | value of the assignment expression (which is 4). All the assignment | |
4024 | operators of C are supported, including the increment operators | |
4025 | @samp{++} and @samp{--}, and combining assignments such as @samp{+=} and | |
4026 | _0__@samp{<<=}_1__. | |
4027 | ||
4028 | @kindex set | |
4029 | @kindex set variable | |
4030 | @cindex variables, setting | |
4031 | If you are not interested in seeing the value of the assignment, use the | |
4032 | @code{set} command instead of the @code{print} command. @code{set} is | |
4033 | really the same as @code{print} except that the expression's value is not | |
4034 | printed and is not put in the value history (@pxref{Value History}). The | |
4035 | expression is evaluated only for its effects. | |
4036 | ||
4037 | If the beginning of the argument string of the @code{set} command | |
4038 | appears identical to a @code{set} subcommand, use the @code{set | |
4039 | variable} command instead of just @code{set}. This command is identical | |
4040 | to @code{set} except for its lack of subcommands. For example, a | |
4041 | program might well have a variable @code{width}---which leads to | |
4042 | an error if we try to set a new value with just @samp{set width=13}, as | |
4043 | we might if @code{set width} didn't happen to be a _GDBN__ command: | |
4044 | @example | |
4045 | (_GDBP__) whatis width | |
4046 | type = double | |
4047 | (_GDBP__) p width | |
4048 | $4 = 13 | |
4049 | (_GDBP__) set width=47 | |
4050 | Invalid syntax in expression. | |
4051 | @end example | |
4052 | @noindent | |
4053 | The invalid expression, of course, is @samp{=47}. What we can do in | |
4054 | order to actually set our program's variable @code{width} is | |
4055 | @example | |
4056 | (_GDBP__) set var width=47 | |
4057 | @end example | |
4058 | ||
4059 | _GDBN__ allows more implicit conversions in assignments than C does; you can | |
4060 | freely store an integer value into a pointer variable or vice versa, and | |
4061 | any structure can be converted to any other structure that is the same | |
4062 | length or shorter. | |
4063 | @comment FIXME: how do structs align/pad in these conversions? | |
4064 | @comment /pesch@cygnus.com 18dec1990 | |
4065 | ||
4066 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
4067 | construct to generate a value of specified type at a specified address | |
4068 | (@pxref{Expressions}). For example, @code{@{int@}0x83040} refers | |
4069 | to memory location @code{0x83040} as an integer (which implies a certain size | |
4070 | and representation in memory), and | |
4071 | ||
4072 | @example | |
4073 | set @{int@}0x83040 = 4 | |
4074 | @end example | |
4075 | ||
4076 | @noindent | |
4077 | stores the value 4 into that memory location. | |
4078 | ||
4079 | @node Jumping, Signaling, Assignment, Altering | |
4080 | @section Continuing at a Different Address | |
4081 | ||
4082 | Ordinarily, when you continue the program, you do so at the place where | |
4083 | it stopped, with the @code{continue} command. You can instead continue at | |
4084 | an address of your own choosing, with the following commands: | |
4085 | ||
4086 | @table @code | |
4087 | @item jump @var{linespec} | |
4088 | @kindex jump | |
4089 | Resume execution at line @var{linespec}. Execution will stop | |
4090 | immediately if there is a breakpoint there. @xref{List} for a | |
4091 | description of the different forms of @var{linespec}. | |
4092 | ||
4093 | The @code{jump} command does not change the current stack frame, or | |
4094 | the stack pointer, or the contents of any memory location or any | |
4095 | register other than the program counter. If line @var{linespec} is in | |
4096 | a different function from the one currently executing, the results may | |
4097 | be bizarre if the two functions expect different patterns of arguments or | |
4098 | of local variables. For this reason, the @code{jump} command requests | |
4099 | confirmation if the specified line is not in the function currently | |
4100 | executing. However, even bizarre results are predictable if you are | |
4101 | well acquainted with the machine-language code of the program. | |
4102 | ||
4103 | @item jump *@var{address} | |
4104 | Resume execution at the instruction at address @var{address}. | |
4105 | @end table | |
4106 | ||
4107 | You can get much the same effect as the @code{jump} command by storing a | |
4108 | new value into the register @code{$pc}. The difference is that this | |
4109 | does not start the program running; it only changes the address where it | |
4110 | @emph{will} run when it is continued. For example, | |
4111 | ||
4112 | @example | |
4113 | set $pc = 0x485 | |
4114 | @end example | |
4115 | ||
4116 | @noindent | |
4117 | causes the next @code{continue} command or stepping command to execute at | |
4118 | address 0x485, rather than at the address where the program stopped. | |
4119 | @xref{Stepping}. | |
4120 | ||
4121 | The most common occasion to use the @code{jump} command is to back up, | |
4122 | perhaps with more breakpoints set, over a portion of a program that has | |
4123 | already executed, in order to examine its execution in more detail. | |
4124 | ||
4125 | @node Signaling, Returning, Jumping, Altering | |
4126 | @c @group | |
4127 | @section Giving the Program a Signal | |
4128 | ||
4129 | @table @code | |
4130 | @item signal @var{signalnum} | |
4131 | @kindex signal | |
4132 | Resume execution where the program stopped, but give it immediately the | |
4133 | signal number @var{signalnum}. | |
4134 | ||
4135 | Alternatively, if @var{signalnum} is zero, continue execution without | |
4136 | giving a signal. This is useful when the program stopped on account of | |
4137 | a signal and would ordinary see the signal when resumed with the | |
4138 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
4139 | signal. | |
4140 | ||
4141 | @code{signal} does not repeat when you press @key{RET} a second time | |
4142 | after executing the command. | |
4143 | @end table | |
4144 | @c @end group | |
4145 | ||
4146 | @node Returning, Calling, Signaling, Altering | |
4147 | @section Returning from a Function | |
4148 | ||
4149 | @table @code | |
4150 | @item return | |
4151 | @itemx return @var{expression} | |
4152 | @cindex returning from a function | |
4153 | @kindex return | |
4154 | You can cancel execution of a function call with the @code{return} | |
4155 | command. If you give an | |
4156 | @var{expression} argument, its value is used as the function's return | |
4157 | value. | |
4158 | @end table | |
4159 | ||
4160 | When you use @code{return}, _GDBN__ discards the selected stack frame | |
4161 | (and all frames within it). You can think of this as making the | |
4162 | discarded frame return prematurely. If you wish to specify a value to | |
4163 | be returned, give that value as the argument to @code{return}. | |
4164 | ||
4165 | This pops the selected stack frame (@pxref{Selection}), and any other | |
4166 | frames inside of it, leaving its caller as the innermost remaining | |
4167 | frame. That frame becomes selected. The specified value is stored in | |
4168 | the registers used for returning values of functions. | |
4169 | ||
4170 | The @code{return} command does not resume execution; it leaves the | |
4171 | program stopped in the state that would exist if the function had just | |
4172 | returned. In contrast, the @code{finish} command (@pxref{Stepping}) | |
4173 | resumes execution until the selected stack frame returns naturally. | |
4174 | ||
4175 | @node Calling, , Returning, Altering | |
4176 | @section Calling your Program's Functions | |
4177 | ||
4178 | @cindex calling functions | |
4179 | @kindex call | |
4180 | @table @code | |
4181 | @item call @var{expr} | |
4182 | Evaluate the expression @var{expr} without displaying @code{void} | |
4183 | returned values. | |
4184 | @end table | |
4185 | ||
4186 | You can use this variant of the @code{print} command if you want to | |
4187 | execute a function from your program, but without cluttering the output | |
4188 | with @code{void} returned values. The result is printed and saved in | |
4189 | the value history, if it is not void. | |
4190 | ||
4191 | @node _GDBN__ Files, Targets, Altering, Top | |
4192 | @chapter _GDBN__'s Files | |
4193 | ||
4194 | @menu | |
4195 | * Files:: Commands to Specify Files | |
4196 | * Symbol Errors:: Errors Reading Symbol Files | |
4197 | @end menu | |
4198 | ||
4199 | @node Files, Symbol Errors, _GDBN__ Files, _GDBN__ Files | |
4200 | @section Commands to Specify Files | |
4201 | @cindex core dump file | |
4202 | @cindex symbol table | |
4203 | _GDBN__ needs to know the file name of the program to be debugged, both in | |
4204 | order to read its symbol table and in order to start the program. To | |
4205 | debug a core dump of a previous run, _GDBN__ must be told the file name of | |
4206 | the core dump. | |
4207 | ||
4208 | The usual way to specify the executable and core dump file names is with | |
4209 | the command arguments given when you start _GDBN__, as discussed in | |
4210 | @pxref{Invocation}. | |
4211 | ||
4212 | Occasionally it is necessary to change to a different file during a | |
4213 | _GDBN__ session. Or you may run _GDBN__ and forget to specify the files you | |
4214 | want to use. In these situations the _GDBN__ commands to specify new files | |
4215 | are useful. | |
4216 | ||
4217 | @table @code | |
4218 | @item file @var{filename} | |
4219 | @cindex executable file | |
4220 | @kindex file | |
4221 | Use @var{filename} as the program to be debugged. It is read for its | |
4222 | symbols and for the contents of pure memory. It is also the program | |
4223 | executed when you use the @code{run} command. If you do not specify a | |
4224 | directory and the file is not found in _GDBN__'s working directory, | |
4225 | ||
4226 | _GDBN__ uses the environment variable @code{PATH} as a list of | |
4227 | directories to search, just as the shell does when looking for a program | |
4228 | to run. You can change the value of this variable, for both _GDBN__ and | |
4229 | your program, using the @code{path} command. | |
4230 | ||
4231 | @code{file} with no argument makes _GDBN__ discard any information it | |
4232 | has on both executable file and the symbol table. | |
4233 | ||
4234 | @item exec-file @var{filename} | |
4235 | @kindex exec-file | |
4236 | Specify that the program to be run (but not the symbol table) is found | |
4237 | in @var{filename}. _GDBN__ will search the environment variable @code{PATH} | |
4238 | if necessary to locate the program. | |
4239 | ||
4240 | @item symbol-file @var{filename} | |
4241 | @kindex symbol-file | |
4242 | Read symbol table information from file @var{filename}. @code{PATH} is | |
4243 | searched when necessary. Use the @code{file} command to get both symbol | |
4244 | table and program to run from the same file. | |
4245 | ||
4246 | @code{symbol-file} with no argument clears out _GDBN__'s information on your | |
4247 | program's symbol table. | |
4248 | ||
4249 | The @code{symbol-file} command causes _GDBN__ to forget the contents of its | |
4250 | convenience variables, the value history, and all breakpoints and | |
4251 | auto-display expressions. This is because they may contain pointers to | |
4252 | the internal data recording symbols and data types, which are part of | |
4253 | the old symbol table data being discarded inside _GDBN__. | |
4254 | ||
4255 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
4256 | executing it once. | |
4257 | ||
4258 | On some kinds of object files, the @code{symbol-file} command does not | |
4259 | actually read the symbol table in full right away. Instead, it scans | |
4260 | the symbol table quickly to find which source files and which symbols | |
4261 | are present. The details are read later, one source file at a time, | |
4262 | when they are needed. | |
4263 | ||
4264 | The purpose of this two-stage reading strategy is to make _GDBN__ start up | |
4265 | faster. For the most part, it is invisible except for occasional pauses | |
4266 | while the symbol table details for a particular source file are being | |
4267 | read. (The @code{set verbose} command can turn these pauses into | |
4268 | messages if desired. @xref{Messages/Warnings}). | |
4269 | ||
4270 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
4271 | read the symbol table data in full right away. We haven't implemented | |
4272 | the two-stage strategy for COFF yet. | |
4273 | ||
4274 | When _GDBN__ is configured for a particular environment, it will | |
4275 | understand debugging information in whatever format is the standard | |
4276 | generated for that environment; you may use either a GNU compiler, or | |
4277 | other compilers that adhere to the local conventions. Best results are | |
4278 | usually obtained from GNU compilers; for example, using @code{_GCC__} | |
4279 | you can generate debugging information for optimized code. | |
4280 | ||
4281 | @item core-file @var{filename} | |
4282 | @itemx core @var{filename} | |
4283 | @kindex core | |
4284 | @kindex core-file | |
4285 | Specify the whereabouts of a core dump file to be used as the ``contents | |
4286 | of memory''. Traditionally, core files contain only some parts of the | |
4287 | address space of the process that generated them; _GDBN__ can access the | |
4288 | executable file itself for other parts. | |
4289 | ||
4290 | @code{core-file} with no argument specifies that no core file is | |
4291 | to be used. | |
4292 | ||
4293 | Note that the core file is ignored when your program is actually running | |
4294 | under _GDBN__. So, if you have been running the program and you wish to | |
4295 | debug a core file instead, you must kill the subprocess in which the | |
4296 | program is running. To do this, use the @code{kill} command | |
4297 | (@pxref{Kill Process}). | |
4298 | ||
4299 | @item load @var{filename} | |
4300 | @kindex load | |
4301 | _if__(_GENERIC__) | |
4302 | Depending on what remote debugging facilities are configured into | |
4303 | _GDBN__, the @code{load} command may be available. Where it exists, it | |
4304 | is meant to make @var{filename} (an executable) available for debugging | |
4305 | on the remote system---by downloading, or dynamic linking, for example. | |
4306 | @code{load} also records @var{filename}'s symbol table in _GDBN__, like | |
4307 | the @code{add-symbol-file} command. | |
4308 | ||
4309 | If @code{load} is not available on your _GDBN__, attempting to execute | |
4310 | it gets the error message ``@code{You can't do that when your target is | |
4311 | @dots{}}'' | |
4312 | _fi__(_GENERIC__) | |
4313 | ||
4314 | _if__(_VXWORKS__) | |
4315 | On VxWorks, @code{load} will dynamically link @var{filename} on the | |
4316 | current target system as well as adding its symbols in _GDBN__. | |
4317 | _fi__(_VXWORKS__) | |
4318 | ||
4319 | _if__(_I960__) | |
4320 | @cindex download to Nindy-960 | |
4321 | With the Nindy interface to an Intel 960 board, @code{load} will | |
4322 | download @var{filename} to the 960 as well as adding its symbols in | |
4323 | _GDBN__. | |
4324 | _fi__(_I960__) | |
4325 | ||
4326 | @code{load} will not repeat if you press @key{RET} again after using it. | |
4327 | ||
4328 | @item add-symbol-file @var{filename} @var{address} | |
4329 | @kindex add-symbol-file | |
4330 | @cindex dynamic linking | |
4331 | The @code{add-symbol-file} command reads additional symbol table information | |
4332 | from the file @var{filename}. You would use this command when that file | |
4333 | has been dynamically loaded (by some other means) into the program that | |
4334 | is running. @var{address} should be the memory address at which the | |
4335 | file has been loaded; _GDBN__ cannot figure this out for itself. | |
4336 | ||
4337 | The symbol table of the file @var{filename} is added to the symbol table | |
4338 | originally read with the @code{symbol-file} command. You can use the | |
4339 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
4340 | read keeps adding to the old. To discard all old symbol data instead, | |
4341 | use the @code{symbol-file} command. | |
4342 | ||
4343 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
4344 | ||
4345 | @item info files | |
4346 | @itemx info target | |
4347 | @kindex info files | |
4348 | @kindex info target | |
4349 | @code{info files} and @code{info target} are synonymous; both print the | |
4350 | current targets (@pxref{Targets}), including the names of the executable | |
4351 | and core dump files currently in use by _GDBN__, and the files from | |
4352 | which symbols were loaded. The command @code{help targets} lists all | |
4353 | possible targets rather than current ones. | |
4354 | ||
4355 | @end table | |
4356 | ||
4357 | All file-specifying commands allow both absolute and relative file names | |
4358 | as arguments. _GDBN__ always converts the file name to an absolute path | |
4359 | name and remembers it that way. | |
4360 | ||
4361 | @kindex sharedlibrary | |
4362 | @kindex share | |
4363 | @cindex shared libraries | |
4364 | ||
4365 | _GDBN__ supports the SunOS shared library format. Symbols from a shared | |
4366 | library cannot be referenced before the shared library has been linked | |
4367 | with the program. (That is to say, until after you type @code{run} and | |
4368 | the function @code{main} has been entered; or when examining core | |
4369 | files.) Once the shared library has been linked in, you can use the | |
4370 | following commands: | |
4371 | ||
4372 | @table @code | |
4373 | @item sharedlibrary @var{regex} | |
4374 | @itemx share @var{regex} | |
4375 | Load shared object library symbols for files matching a UNIX regular | |
4376 | expression. | |
4377 | ||
4378 | @item share | |
4379 | @itemx sharedlibrary | |
4380 | Load symbols for all shared libraries. | |
4381 | ||
4382 | @item info share | |
4383 | @itemx info sharedlibrary | |
4384 | @kindex info sharedlibrary | |
4385 | @kindex info share | |
4386 | Print the names of the shared libraries which you have loaded with the | |
4387 | @code{sharedlibrary} command. | |
4388 | @end table | |
4389 | ||
4390 | @code{sharedlibrary} does not repeat automatically when you press | |
4391 | @key{RET} after using it once. | |
4392 | ||
4393 | @node Symbol Errors, , Files, _GDBN__ Files | |
4394 | @section Errors Reading Symbol Files | |
4395 | While a symbol file is being read, _GDBN__ will occasionally encounter | |
4396 | problems, such as symbol types it does not recognize, or known bugs in | |
4397 | compiler output. By default, it prints one message about each such | |
4398 | type of problem, no matter how many times the problem occurs. You can | |
4399 | ask it to print more messages, to see how many times the problems occur, | |
4400 | or can shut the messages off entirely, with the @code{set | |
4401 | complaints} command (@xref{Messages/Warnings}). | |
4402 | ||
4403 | The messages currently printed, and their meanings, are: | |
4404 | ||
4405 | @table @code | |
4406 | @item inner block not inside outer block in @var{symbol} | |
4407 | ||
4408 | The symbol information shows where symbol scopes begin and end | |
4409 | (such as at the start of a function or a block of statements). This | |
4410 | error indicates that an inner scope block is not fully contained | |
4411 | in its outer scope blocks. | |
4412 | ||
4413 | _GDBN__ circumvents the problem by treating the inner block as if it had | |
4414 | the same scope as the outer block. In the error message, @var{symbol} | |
4415 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
4416 | function. | |
4417 | ||
4418 | @item block at @var{address} out of order | |
4419 | ||
4420 | The symbol information for symbol scope blocks should occur in | |
4421 | order of increasing addresses. This error indicates that it does not | |
4422 | do so. | |
4423 | ||
4424 | _GDBN__ does not circumvent this problem, and will have trouble locating | |
4425 | symbols in the source file whose symbols being read. (You can often | |
4426 | determine what source file is affected by specifying @code{set verbose | |
4427 | on}. @xref{Messages/Warnings}.) | |
4428 | ||
4429 | @item bad block start address patched | |
4430 | ||
4431 | The symbol information for a symbol scope block has a start address | |
4432 | smaller than the address of the preceding source line. This is known | |
4433 | to occur in the SunOS 4.1.1 (and earlier) C compiler. | |
4434 | ||
4435 | _GDBN__ circumvents the problem by treating the symbol scope block as | |
4436 | starting on the previous source line. | |
4437 | ||
4438 | @c @item{encountered DBX-style class variable debugging information. | |
4439 | @c You seem to have compiled your program with "g++ -g0" instead of "g++ -g". | |
4440 | @c Therefore _GDBN__ will not know about your class variables} | |
4441 | @c | |
4442 | @c This error indicates that the symbol information produced for a C++ | |
4443 | @c program includes zero-size fields, which indicated static fields in | |
4444 | @c a previous release of the G++ compiler. This message is probably | |
4445 | @c obsolete. | |
4446 | @c | |
4447 | @item bad string table offset in symbol @var{n} | |
4448 | ||
4449 | @cindex foo | |
4450 | Symbol number @var{n} contains a pointer into the string table which is | |
4451 | larger than the size of the string table. | |
4452 | ||
4453 | _GDBN__ circumvents the problem by considering the symbol to have the | |
4454 | name @code{foo}, which may cause other problems if many symbols end up | |
4455 | with this name. | |
4456 | ||
4457 | @item unknown symbol type @code{0x@var{nn}} | |
4458 | ||
4459 | The symbol information contains new data types that _GDBN__ does not yet | |
4460 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
4461 | information, in hexadecimal. | |
4462 | ||
4463 | _GDBN__ circumvents the error by ignoring this symbol information. This | |
4464 | will usually allow the program to be debugged, though certain symbols | |
4465 | will not be accessible. If you encounter such a problem and feel like | |
4466 | debugging it, you can debug @code{_GDBP__} with itself, breakpoint on | |
4467 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
4468 | examine @code{*bufp} to see the symbol. | |
4469 | ||
4470 | @item stub type has NULL name | |
4471 | _GDBN__ could not find the full definition for a struct or class. | |
4472 | ||
4473 | @ignore | |
4474 | @c this is #if 0'd in dbxread.c as of (at least!) 17 may 1991 | |
4475 | @item const/volatile indicator missing, got '@var{X}' | |
4476 | ||
4477 | The symbol information for a C++ member function is missing some | |
4478 | information that the compiler should have output for it. | |
4479 | @end ignore | |
4480 | ||
4481 | @item C++ type mismatch between compiler and debugger | |
4482 | ||
4483 | The debugger could not parse a type specification output by the compiler | |
4484 | for some C++ object. | |
4485 | ||
4486 | @end table | |
4487 | ||
4488 | @node Targets, Controlling _GDBN__, _GDBN__ Files, Top | |
4489 | @chapter Specifying a Debugging Target | |
4490 | @cindex debugging target | |
4491 | @kindex target | |
4492 | A @dfn{target} is an interface between the debugger and a particular | |
4493 | kind of file or process. | |
4494 | ||
4495 | Often, you will be able to run _GDBN__ in the same host environment as the | |
4496 | program you are debugging; in that case, the debugging target can just be | |
4497 | specified as a side effect of the @code{file} or @code{core} commands. | |
4498 | When you need more flexibility---for example, running _GDBN__ on a | |
4499 | physically separate host, controlling standalone systems over a | |
4500 | serial port, or realtime systems over a TCP/IP connection---you can use | |
4501 | the @code{target} command. | |
4502 | ||
4503 | @menu | |
4504 | * Active Targets:: Active Targets | |
4505 | * Target Commands:: Commands for Managing Targets | |
4506 | * Remote:: Remote Debugging | |
4507 | @end menu | |
4508 | ||
4509 | @node Active Targets, Target Commands, Targets, Targets | |
4510 | @section Active Targets | |
4511 | @cindex stacking targets | |
4512 | @cindex active targets | |
4513 | @cindex multiple targets | |
4514 | ||
4515 | Targets are managed in three @dfn{strata} that correspond to different | |
4516 | classes of target: processes, core files, and executable files. This | |
4517 | allows you to (for example) start a process and inspect its activity | |
4518 | without abandoning your work on a core file. | |
4519 | ||
4520 | More than one target can potentially respond to a request. In | |
4521 | particular, when you access memory _GDBN__ will examine the three strata of | |
4522 | targets until it finds a target that can handle that particular address. | |
4523 | Strata are always examined in a fixed order: first a process if there is | |
4524 | one, then a core file if there is one, and finally an executable file if | |
4525 | there is one of those. | |
4526 | ||
4527 | When you specify a new target in a given stratum, it replaces any target | |
4528 | previously in that stratum. | |
4529 | ||
4530 | To get rid of a target without replacing it, use the @code{detach} | |
4531 | command. The related command @code{attach} provides you with a way of | |
4532 | choosing a particular running process as a new target. @xref{Attach}. | |
4533 | ||
4534 | @node Target Commands, Remote, Active Targets, Targets | |
4535 | @section Commands for Managing Targets | |
4536 | ||
4537 | @table @code | |
4538 | @item target @var{type} @var{parameters} | |
4539 | Connects the _GDBN__ host environment to a target machine or process. A | |
4540 | target is typically a protocol for talking to debugging facilities. You | |
4541 | use the argument @var{type} to specify the type or protocol of the | |
4542 | target machine. | |
4543 | ||
4544 | Further @var{parameters} are interpreted by the target protocol, but | |
4545 | typically include things like device names or host names to connect | |
4546 | with, process numbers, and baud rates. | |
4547 | ||
4548 | The @code{target} command will not repeat if you press @key{RET} again | |
4549 | after executing the command. | |
4550 | ||
4551 | @item help target | |
4552 | @kindex help target | |
4553 | Displays the names of all targets available. To display targets | |
4554 | currently selected, use either @code{info target} or @code{info files} | |
4555 | (@pxref{Files}). | |
4556 | ||
4557 | @item help target @var{name} | |
4558 | Describe a particular target, including any parameters necessary to | |
4559 | select it. | |
4560 | @end table | |
4561 | ||
4562 | Here are some common targets (available, or not, depending on the _GDBN__ | |
4563 | configuration): | |
4564 | ||
4565 | @table @code | |
4566 | @item target exec @var{prog} | |
4567 | @kindex target exec | |
4568 | An executable file. @samp{target exec @var{prog}} is the same as | |
4569 | @samp{exec-file @var{prog}}. | |
4570 | ||
4571 | @item target core @var{filename} | |
4572 | @kindex target core | |
4573 | A core dump file. @samp{target core @var{filename}} is the same as | |
4574 | @samp{core-file @var{filename}}. | |
4575 | ||
4576 | @item target remote @var{dev} | |
4577 | @kindex target remote | |
4578 | Remote serial target in _GDBN__-specific protocol. The argument @var{dev} | |
4579 | specifies what serial device to use for the connection (e.g. | |
4580 | @file{/dev/ttya}). @xref{Remote}. | |
4581 | ||
4582 | _if__(_AMD29K__) | |
4583 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
4584 | @kindex target amd-eb | |
4585 | @cindex AMD EB29K | |
4586 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
4587 | @var{dev} is the serial device, as for @code{target remote}; | |
4588 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
4589 | name of the program to be debugged, as it appears to DOS on the PC. | |
4590 | @xref{EB29K Remote}. | |
4591 | ||
4592 | _fi__(_AMD29K__) | |
4593 | _if__(_I960__) | |
4594 | @item target nindy @var{devicename} | |
4595 | @kindex target nindy | |
4596 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
4597 | the name of the serial device to use for the connection, e.g. | |
4598 | @file{/dev/ttya}. @xref{i960-Nindy Remote}. | |
4599 | ||
4600 | _fi__(_I960__) | |
4601 | _if__(_VXWORKS__) | |
4602 | @item target vxworks @var{machinename} | |
4603 | @kindex target vxworks | |
4604 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
4605 | is the target system's machine name or IP address. | |
4606 | @xref{VxWorks Remote}. | |
4607 | _fi__(_VXWORKS__) | |
4608 | @end table | |
4609 | ||
4610 | _if__(_GENERIC__) | |
4611 | Different targets are available on different configurations of _GDBN__; your | |
4612 | configuration may have more or fewer targets. | |
4613 | _fi__(_GENERIC__) | |
4614 | ||
4615 | @node Remote, , Target Commands, Targets | |
4616 | @section Remote Debugging | |
4617 | @cindex remote debugging | |
4618 | ||
4619 | _if__(_GENERIC__) | |
4620 | @menu | |
4621 | _include__(gdbinv-m.m4)<>_dnl__ | |
4622 | @end menu | |
4623 | _fi__(_GENERIC__) | |
4624 | ||
4625 | If you are trying to debug a program running on a machine that can't run | |
4626 | _GDBN__ in the usual way, it is often useful to use remote debugging. For | |
4627 | example, you might use remote debugging on an operating system kernel, or on | |
4628 | a small system which does not have a general purpose operating system | |
4629 | powerful enough to run a full-featured debugger. | |
4630 | ||
4631 | Some configurations of _GDBN__ have special serial or TCP/IP interfaces | |
4632 | to make this work with particular debugging targets. In addition, | |
4633 | _GDBN__ comes with a generic serial protocol (specific to _GDBN__, but | |
4634 | not specific to any particular target system) which you can use if you | |
4635 | write the remote stubs---the code that will run on the remote system to | |
4636 | communicate with _GDBN__. | |
4637 | ||
4638 | To use the _GDBN__ remote serial protocol, the program to be debugged on | |
4639 | the remote machine needs to contain a debugging stub which talks to | |
4640 | _GDBN__ over the serial line. Several working remote stubs are | |
4641 | distributed with _GDBN__; see the @file{README} file in the _GDBN__ | |
4642 | distribution for more information. | |
4643 | ||
4644 | For details of this communication protocol, see the comments in the | |
4645 | _GDBN__ source file @file{remote.c}. | |
4646 | ||
4647 | To start remote debugging, first run _GDBN__ and specify as an executable file | |
4648 | the program that is running in the remote machine. This tells _GDBN__ how | |
4649 | to find the program's symbols and the contents of its pure text. Then | |
4650 | establish communication using the @code{target remote} command with a device | |
4651 | name as an argument. For example: | |
4652 | ||
4653 | @example | |
4654 | target remote /dev/ttyb | |
4655 | @end example | |
4656 | ||
4657 | @noindent | |
4658 | if the serial line is connected to the device named @file{/dev/ttyb}. This | |
4659 | will stop the remote machine if it is not already stopped. | |
4660 | ||
4661 | Now you can use all the usual commands to examine and change data and to | |
4662 | step and continue the remote program. | |
4663 | ||
4664 | To resume the remote program and stop debugging it, use the @code{detach} | |
4665 | command. | |
4666 | ||
4667 | Other remote targets may be available in your | |
4668 | configuration of _GDBN__; use @code{help targets} to list them. | |
4669 | ||
4670 | _if__(_GENERIC__) | |
4671 | @c Text on starting up GDB in various specific cases; it goes up front | |
4672 | @c in manuals configured for any of those particular situations, here | |
4673 | @c otherwise. | |
4674 | _include__(gdbinv-s.m4) | |
4675 | _fi__(_GENERIC__) | |
4676 | ||
4677 | @node Controlling _GDBN__, Sequences, Targets, Top | |
4678 | @chapter Controlling _GDBN__ | |
4679 | ||
4680 | You can alter many aspects of _GDBN__'s interaction with you by using | |
4681 | the @code{set} command. For commands controlling how _GDBN__ displays | |
4682 | data, @pxref{Print Settings}; other settings are described here. | |
4683 | ||
4684 | @menu | |
4685 | * Prompt:: Prompt | |
4686 | * Editing:: Command Editing | |
4687 | * History:: Command History | |
4688 | * Screen Size:: Screen Size | |
4689 | * Numbers:: Numbers | |
4690 | * Messages/Warnings:: Optional Warnings and Messages | |
4691 | @end menu | |
4692 | ||
4693 | @node Prompt, Editing, Controlling _GDBN__, Controlling _GDBN__ | |
4694 | @section Prompt | |
4695 | @cindex prompt | |
4696 | _GDBN__ indicates its readiness to read a command by printing a string | |
4697 | called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You | |
4698 | can change the prompt string with the @code{set prompt} command. For | |
4699 | instance, when debugging _GDBN__ with _GDBN__, it is useful to change | |
4700 | the prompt in one of the _GDBN__<>s so that you can always tell which | |
4701 | one you are talking to. | |
4702 | ||
4703 | @table @code | |
4704 | @item set prompt @var{newprompt} | |
4705 | @kindex set prompt | |
4706 | Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth. | |
4707 | @kindex show prompt | |
4708 | @item show prompt | |
4709 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
4710 | @end table | |
4711 | ||
4712 | @node Editing, History, Prompt, Controlling _GDBN__ | |
4713 | @section Command Editing | |
4714 | @cindex readline | |
4715 | @cindex command line editing | |
4716 | _GDBN__ reads its input commands via the @dfn{readline} interface. This | |
4717 | GNU library provides consistent behavior for programs which provide a | |
4718 | command line interface to the user. Advantages are @code{emacs}-style | |
4719 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
4720 | substitution, and a storage and recall of command history across | |
4721 | debugging sessions. | |
4722 | ||
4723 | You may control the behavior of command line editing in _GDBN__ with the | |
4724 | command @code{set}. | |
4725 | ||
4726 | @table @code | |
4727 | @kindex set editing | |
4728 | @cindex editing | |
4729 | @item set editing | |
4730 | @itemx set editing on | |
4731 | Enable command line editing (enabled by default). | |
4732 | ||
4733 | @item set editing off | |
4734 | Disable command line editing. | |
4735 | ||
4736 | @kindex show editing | |
4737 | @item show editing | |
4738 | Show whether command line editing is enabled. | |
4739 | @end table | |
4740 | ||
4741 | @node History, Screen Size, Editing, Controlling _GDBN__ | |
4742 | @section Command History | |
4743 | @table @code | |
4744 | @cindex history substitution | |
4745 | @cindex history file | |
4746 | @kindex set history filename | |
4747 | @item set history filename @var{fname} | |
4748 | Set the name of the _GDBN__ command history file to @var{fname}. This is | |
4749 | the file from which _GDBN__ will read an initial command history | |
4750 | list or to which it will write this list when it exits. This list is | |
4751 | accessed through history expansion or through the history | |
4752 | command editing characters listed below. This file defaults to the | |
4753 | value of the environment variable @code{GDBHISTFILE}, or to | |
4754 | @file{./.gdb_history} if this variable is not set. | |
4755 | ||
4756 | @cindex history save | |
4757 | @kindex set history save | |
4758 | @item set history save | |
4759 | @itemx set history save on | |
4760 | Record command history in a file, whose name may be specified with the | |
4761 | @code{set history filename} command. By default, this option is disabled. | |
4762 | ||
4763 | @item set history save off | |
4764 | Stop recording command history in a file. | |
4765 | ||
4766 | @cindex history size | |
4767 | @kindex set history size | |
4768 | @item set history size @var{size} | |
4769 | Set the number of commands which _GDBN__ will keep in its history list. | |
4770 | This defaults to the value of the environment variable | |
4771 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
4772 | @end table | |
4773 | ||
4774 | @cindex history expansion | |
4775 | History expansion assigns special meaning to the character @kbd{!}. | |
4776 | @iftex | |
4777 | (@xref{Event Designators}.) | |
4778 | @end iftex | |
4779 | Since @kbd{!} is also the logical not operator in C, history expansion | |
4780 | is off by default. If you decide to enable history expansion with the | |
4781 | @code{set history expansion on} command, you may sometimes need to | |
4782 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
4783 | a space or a tab to prevent it from being expanded. The readline | |
4784 | history facilities will not attempt substitution on the strings | |
4785 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
4786 | ||
4787 | The commands to control history expansion are: | |
4788 | ||
4789 | @table @code | |
4790 | ||
4791 | @kindex set history expansion | |
4792 | @item set history expansion on | |
4793 | @itemx set history expansion | |
4794 | Enable history expansion. History expansion is off by default. | |
4795 | ||
4796 | @item set history expansion off | |
4797 | Disable history expansion. | |
4798 | ||
4799 | The readline code comes with more complete documentation of | |
4800 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
4801 | or @code{vi} may wish to read it. | |
4802 | @iftex | |
4803 | @xref{Command Line Editing}. | |
4804 | @end iftex | |
4805 | ||
4806 | @c @group | |
4807 | @kindex show history | |
4808 | @item show history | |
4809 | @itemx show history filename | |
4810 | @itemx show history save | |
4811 | @itemx show history size | |
4812 | @itemx show history expansion | |
4813 | These commands display the state of the _GDBN__ history parameters. | |
4814 | @code{show history} by itself displays all four states. | |
4815 | @c @end group | |
4816 | ||
4817 | @end table | |
4818 | ||
4819 | @table @code | |
4820 | @kindex show commands | |
4821 | @item show commands | |
4822 | Display the last ten commands in the command history. | |
4823 | ||
4824 | @item show commands @var{n} | |
4825 | Print ten commands centered on command number @var{n}. | |
4826 | ||
4827 | @item show commands + | |
4828 | Print ten commands just after the commands last printed. | |
4829 | ||
4830 | @end table | |
4831 | ||
4832 | @node Screen Size, Numbers, History, Controlling _GDBN__ | |
4833 | @section Screen Size | |
4834 | @cindex size of screen | |
4835 | @cindex pauses in output | |
4836 | Certain commands to _GDBN__ may produce large amounts of information | |
4837 | output to the screen. To help you read all of it, _GDBN__ pauses and | |
4838 | asks you for input at the end of each page of output. Type @key{RET} | |
4839 | when you want to continue the output. _GDBN__ also uses the screen | |
4840 | width setting to determine when to wrap lines of output. Depending on | |
4841 | what is being printed, it tries to break the line at a readable place, | |
4842 | rather than simply letting it overflow onto the following line. | |
4843 | ||
4844 | Normally _GDBN__ knows the size of the screen from the termcap data base | |
4845 | together with the value of the @code{TERM} environment variable and the | |
4846 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
4847 | you can override it with the @code{set height} and @code{set | |
4848 | width} commands: | |
4849 | ||
4850 | @table @code | |
4851 | @item set height @var{lpp} | |
4852 | @itemx show height | |
4853 | @itemx set width @var{cpl} | |
4854 | @itemx show width | |
4855 | @kindex set height | |
4856 | @kindex set width | |
4857 | @kindex show width | |
4858 | @kindex show height | |
4859 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
4860 | a screen width of @var{cpl} characters. The associated @code{show} | |
4861 | commands display the current settings. | |
4862 | ||
4863 | If you specify a height of zero lines, _GDBN__ will not pause during output | |
4864 | no matter how long the output is. This is useful if output is to a file | |
4865 | or to an editor buffer. | |
4866 | @end table | |
4867 | ||
4868 | @node Numbers, Messages/Warnings, Screen Size, Controlling _GDBN__ | |
4869 | @section Numbers | |
4870 | @cindex number representation | |
4871 | @cindex entering numbers | |
4872 | You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by | |
4873 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
4874 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
4875 | Numbers that begin with none of these are, by default, entered in base | |
4876 | 10; likewise, the default display for numbers---when no particular | |
4877 | format is specified---is base 10. You can change the default base for | |
4878 | both input and output with the @code{set radix} command. | |
4879 | ||
4880 | @table @code | |
4881 | @kindex set radix | |
4882 | @item set radix @var{base} | |
4883 | Set the default base for numeric input and display. Supported choices | |
4884 | for @var{base} are decimal 8, 10, 16. @var{base} must itself be | |
4885 | specified either unambiguously or using the current default radix; for | |
4886 | example, any of | |
4887 | ||
4888 | @example | |
4889 | set radix 012 | |
4890 | set radix 10. | |
4891 | set radix 0xa | |
4892 | @end example | |
4893 | ||
4894 | @noindent | |
4895 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
4896 | will leave the radix unchanged no matter what it was. | |
4897 | ||
4898 | @kindex show radix | |
4899 | @item show radix | |
4900 | Display the current default base for numeric input and display. | |
4901 | ||
4902 | @end table | |
4903 | ||
4904 | @node Messages/Warnings, , Numbers, Controlling _GDBN__ | |
4905 | @section Optional Warnings and Messages | |
4906 | By default, _GDBN__ is silent about its inner workings. If you are running | |
4907 | on a slow machine, you may want to use the @code{set verbose} command. | |
4908 | It will make _GDBN__ tell you when it does a lengthy internal operation, so | |
4909 | you won't think it has crashed. | |
4910 | ||
4911 | Currently, the messages controlled by @code{set verbose} are those which | |
4912 | announce that the symbol table for a source file is being read | |
4913 | (@pxref{Files}, in the description of the command | |
4914 | @code{symbol-file}). | |
4915 | @c The following is the right way to do it, but emacs 18.55 doesn't support | |
4916 | @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo | |
4917 | @c is released. | |
4918 | @ignore | |
4919 | see @code{symbol-file} in @ref{Files}). | |
4920 | @end ignore | |
4921 | ||
4922 | @table @code | |
4923 | @kindex set verbose | |
4924 | @item set verbose on | |
4925 | Enables _GDBN__'s output of certain informational messages. | |
4926 | ||
4927 | @item set verbose off | |
4928 | Disables _GDBN__'s output of certain informational messages. | |
4929 | ||
4930 | @kindex show verbose | |
4931 | @item show verbose | |
4932 | Displays whether @code{set verbose} is on or off. | |
4933 | @end table | |
4934 | ||
4935 | By default, if _GDBN__ encounters bugs in the symbol table of an object file, | |
4936 | it prints a single message about each type of problem it finds, then | |
4937 | shuts up (@pxref{Symbol Errors}). You can suppress these messages, or allow more than one such | |
4938 | message to be printed if you want to see how frequent the problems are. | |
4939 | ||
4940 | @table @code | |
4941 | @kindex set complaints | |
4942 | @item set complaints @var{limit} | |
4943 | Permits _GDBN__ to output @var{limit} complaints about each type of unusual | |
4944 | symbols before becoming silent about the problem. Set @var{limit} to | |
4945 | zero to suppress all complaints; set it to a large number to prevent | |
4946 | complaints from being suppressed. | |
4947 | ||
4948 | @kindex show complaints | |
4949 | @item show complaints | |
4950 | Displays how many symbol complaints _GDBN__ is permitted to produce. | |
4951 | @end table | |
4952 | ||
4953 | By default, _GDBN__ is cautious, and asks what sometimes seem to be a | |
4954 | lot of stupid questions to confirm certain commands. For example, if | |
4955 | you try to run a program which is already running: | |
4956 | @example | |
4957 | (_GDBP__) run | |
4958 | The program being debugged has been started already. | |
4959 | Start it from the beginning? (y or n) | |
4960 | @end example | |
4961 | ||
4962 | If you're willing to unflinchingly face the consequences of your own | |
4963 | commands, you can disable this ``feature'': | |
4964 | ||
4965 | @table @code | |
4966 | @kindex set confirm | |
4967 | @cindex flinching | |
4968 | @cindex confirmation | |
4969 | @cindex stupid questions | |
4970 | @item set confirm off | |
4971 | Disables confirmation requests. | |
4972 | ||
4973 | @item set confirm on | |
4974 | Enables confirmation requests (the default). | |
4975 | ||
4976 | @item show confirm | |
4977 | @kindex show confirm | |
4978 | Displays state of confirmation requests. | |
4979 | @end table | |
4980 | ||
4981 | @node Sequences, Emacs, Controlling _GDBN__, Top | |
4982 | @chapter Canned Sequences of Commands | |
4983 | ||
4984 | Aside from breakpoint commands (@pxref{Break Commands}), _GDBN__ provides two | |
4985 | ways to store sequences of commands for execution as a unit: | |
4986 | user-defined commands and command files. | |
4987 | ||
4988 | @menu | |
4989 | * Define:: User-Defined Commands | |
4990 | * Command Files:: Command Files | |
4991 | * Output:: Commands for Controlled Output | |
4992 | @end menu | |
4993 | ||
4994 | @node Define, Command Files, Sequences, Sequences | |
4995 | @section User-Defined Commands | |
4996 | ||
4997 | @cindex user-defined command | |
4998 | A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you | |
4999 | assign a new name as a command. This is done with the @code{define} | |
5000 | command. | |
5001 | ||
5002 | @table @code | |
5003 | @item define @var{commandname} | |
5004 | @kindex define | |
5005 | Define a command named @var{commandname}. If there is already a command | |
5006 | by that name, you are asked to confirm that you want to redefine it. | |
5007 | ||
5008 | The definition of the command is made up of other _GDBN__ command lines, | |
5009 | which are given following the @code{define} command. The end of these | |
5010 | commands is marked by a line containing @code{end}. | |
5011 | ||
5012 | @item document @var{commandname} | |
5013 | @kindex document | |
5014 | Give documentation to the user-defined command @var{commandname}. The | |
5015 | command @var{commandname} must already be defined. This command reads | |
5016 | lines of documentation just as @code{define} reads the lines of the | |
5017 | command definition, ending with @code{end}. After the @code{document} | |
5018 | command is finished, @code{help} on command @var{commandname} will print | |
5019 | the documentation you have specified. | |
5020 | ||
5021 | You may use the @code{document} command again to change the | |
5022 | documentation of a command. Redefining the command with @code{define} | |
5023 | does not change the documentation. | |
5024 | ||
5025 | @item help user-defined | |
5026 | @kindex help user-defined | |
5027 | List all user-defined commands, with the first line of the documentation | |
5028 | (if any) for each. | |
5029 | ||
5030 | @item info user | |
5031 | @itemx info user @var{commandname} | |
5032 | @kindex info user | |
5033 | Display the _GDBN__ commands used to define @var{commandname} (but not its | |
5034 | documentation). If no @var{commandname} is given, display the | |
5035 | definitions for all user-defined commands. | |
5036 | @end table | |
5037 | ||
5038 | User-defined commands do not take arguments. When they are executed, the | |
5039 | commands of the definition are not printed. An error in any command | |
5040 | stops execution of the user-defined command. | |
5041 | ||
5042 | Commands that would ask for confirmation if used interactively proceed | |
5043 | without asking when used inside a user-defined command. Many _GDBN__ commands | |
5044 | that normally print messages to say what they are doing omit the messages | |
5045 | when used in a user-defined command. | |
5046 | ||
5047 | @node Command Files, Output, Define, Sequences | |
5048 | @section Command Files | |
5049 | ||
5050 | @cindex command files | |
5051 | A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments | |
5052 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
5053 | command file does nothing; it does not mean to repeat the last command, as | |
5054 | it would from the terminal. | |
5055 | ||
5056 | @cindex init file | |
5057 | @cindex @file{_GDBINIT__} | |
5058 | When you start _GDBN__, it automatically executes commands from its | |
5059 | @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ | |
5060 | reads the init file (if any) in your home directory and then the init | |
5061 | file (if any) in the current working directory. (The init files are not | |
5062 | executed if you use the @samp{-nx} option; @pxref{Mode Options}.) You | |
5063 | can also request the execution of a command file with the @code{source} | |
5064 | command: | |
5065 | ||
5066 | @table @code | |
5067 | @item source @var{filename} | |
5068 | @kindex source | |
5069 | Execute the command file @var{filename}. | |
5070 | @end table | |
5071 | ||
5072 | The lines in a command file are executed sequentially. They are not | |
5073 | printed as they are executed. An error in any command terminates execution | |
5074 | of the command file. | |
5075 | ||
5076 | Commands that would ask for confirmation if used interactively proceed | |
5077 | without asking when used in a command file. Many _GDBN__ commands that | |
5078 | normally print messages to say what they are doing omit the messages | |
5079 | when called from command files. | |
5080 | ||
5081 | @node Output, , Command Files, Sequences | |
5082 | @section Commands for Controlled Output | |
5083 | ||
5084 | During the execution of a command file or a user-defined command, normal | |
5085 | _GDBN__ output is suppressed; the only output that appears is what is | |
5086 | explicitly printed by the commands in the definition. This section | |
5087 | describes three commands useful for generating exactly the output you | |
5088 | want. | |
5089 | ||
5090 | @table @code | |
5091 | @item echo @var{text} | |
5092 | @kindex echo | |
5093 | @c I don't consider backslash-space a standard C escape sequence | |
5094 | @c because it's not in ANSI. | |
5095 | Print @var{text}. Nonprinting characters can be included in @var{text} | |
5096 | using C escape sequences, such as @samp{\n} to print a newline. @b{No | |
5097 | newline will be printed unless you specify one.} In addition to the | |
5098 | standard C escape sequences, a backslash followed by a space stands for a | |
5099 | space. This is useful for outputting a string with spaces at the | |
5100 | beginning or the end, since leading and trailing spaces are otherwise | |
5101 | trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the | |
5102 | command @samp{echo \@ and foo = \@ }. | |
5103 | @c FIXME: verify hard copy actually issues enspaces for '@ '! Will this | |
5104 | @c confuse texinfo? | |
5105 | ||
5106 | A backslash at the end of @var{text} can be used, as in C, to continue | |
5107 | the command onto subsequent lines. For example, | |
5108 | ||
5109 | @example | |
5110 | echo This is some text\n\ | |
5111 | which is continued\n\ | |
5112 | onto several lines.\n | |
5113 | @end example | |
5114 | ||
5115 | produces the same output as | |
5116 | ||
5117 | @example | |
5118 | echo This is some text\n | |
5119 | echo which is continued\n | |
5120 | echo onto several lines.\n | |
5121 | @end example | |
5122 | ||
5123 | @item output @var{expression} | |
5124 | @kindex output | |
5125 | Print the value of @var{expression} and nothing but that value: no | |
5126 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
5127 | value history either. @xref{Expressions} for more information on | |
5128 | expressions. | |
5129 | ||
5130 | @item output/@var{fmt} @var{expression} | |
5131 | Print the value of @var{expression} in format @var{fmt}. You can use | |
5132 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
5133 | information. | |
5134 | ||
5135 | @item printf @var{string}, @var{expressions}@dots{} | |
5136 | @kindex printf | |
5137 | Print the values of the @var{expressions} under the control of | |
5138 | @var{string}. The @var{expressions} are separated by commas and may | |
5139 | be either numbers or pointers. Their values are printed as specified | |
5140 | by @var{string}, exactly as if the program were to execute | |
5141 | ||
5142 | @example | |
5143 | printf (@var{string}, @var{expressions}@dots{}); | |
5144 | @end example | |
5145 | ||
5146 | For example, you can print two values in hex like this: | |
5147 | ||
5148 | @example | |
5149 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo | |
5150 | @end example | |
5151 | ||
5152 | The only backslash-escape sequences that you can use in the format | |
5153 | string are the simple ones that consist of backslash followed by a | |
5154 | letter. | |
5155 | @end table | |
5156 | ||
5157 | @node Emacs, _GDBN__ Bugs, Sequences, Top | |
5158 | @chapter Using _GDBN__ under GNU Emacs | |
5159 | ||
5160 | @cindex emacs | |
5161 | A special interface allows you to use GNU Emacs to view (and | |
5162 | edit) the source files for the program you are debugging with | |
5163 | _GDBN__. | |
5164 | ||
5165 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
5166 | executable file you want to debug as an argument. This command starts | |
5167 | _GDBN__ as a subprocess of Emacs, with input and output through a newly | |
5168 | created Emacs buffer. | |
5169 | ||
5170 | Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two | |
5171 | things: | |
5172 | ||
5173 | @itemize @bullet | |
5174 | @item | |
5175 | All ``terminal'' input and output goes through the Emacs buffer. | |
5176 | @end itemize | |
5177 | ||
5178 | This applies both to _GDBN__ commands and their output, and to the input | |
5179 | and output done by the program you are debugging. | |
5180 | ||
5181 | This is useful because it means that you can copy the text of previous | |
5182 | commands and input them again; you can even use parts of the output | |
5183 | in this way. | |
5184 | ||
5185 | All the facilities of Emacs' Shell mode are available for this purpose. | |
5186 | ||
5187 | @itemize @bullet | |
5188 | @item | |
5189 | _GDBN__ displays source code through Emacs. | |
5190 | @end itemize | |
5191 | ||
5192 | Each time _GDBN__ displays a stack frame, Emacs automatically finds the | |
5193 | source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the | |
5194 | left margin of the current line. Emacs uses a separate buffer for | |
5195 | source display, and splits the window to show both your _GDBN__ session | |
5196 | and the source. | |
5197 | ||
5198 | Explicit _GDBN__ @code{list} or search commands still produce output as | |
5199 | usual, but you probably will have no reason to use them. | |
5200 | ||
5201 | @quotation | |
5202 | @emph{Warning:} If the directory where your program resides is not your | |
5203 | current directory, it can be easy to confuse Emacs about the location of | |
5204 | the source files, in which case the auxiliary display buffer will not | |
5205 | appear to show your source. _GDBN__ can find programs by searching your | |
5206 | environment's @code{PATH} variable, so the _GDBN__ input and output | |
5207 | session will proceed normally; but Emacs doesn't get enough information | |
5208 | back from _GDBN__ to locate the source files in this situation. To | |
5209 | avoid this problem, either start _GDBN__ mode from the directory where | |
5210 | your program resides, or specify a full path name when prompted for the | |
5211 | @kbd{M-x gdb} argument. | |
5212 | ||
5213 | A similar confusion can result if you use the _GDBN__ @code{file} command to | |
5214 | switch to debugging a program in some other location, from an existing | |
5215 | _GDBN__ buffer in Emacs. | |
5216 | @end quotation | |
5217 | ||
5218 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
5219 | you need to call _GDBN__ by a different name (for example, if you keep | |
5220 | several configurations around, with different names) you can set the | |
5221 | Emacs variable @code{gdb-command-name}; for example, | |
5222 | @example | |
5223 | (setq gdb-command-name "mygdb") | |
5224 | @end example | |
5225 | @noindent | |
5226 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
5227 | in your @file{.emacs} file) will make Emacs call the program named | |
5228 | ``@code{mygdb}'' instead. | |
5229 | ||
5230 | In the _GDBN__ I/O buffer, you can use these special Emacs commands in | |
5231 | addition to the standard Shell mode commands: | |
5232 | ||
5233 | @table @kbd | |
5234 | @item C-h m | |
5235 | Describe the features of Emacs' _GDBN__ Mode. | |
5236 | ||
5237 | @item M-s | |
5238 | Execute to another source line, like the _GDBN__ @code{step} command; also | |
5239 | update the display window to show the current file and location. | |
5240 | ||
5241 | @item M-n | |
5242 | Execute to next source line in this function, skipping all function | |
5243 | calls, like the _GDBN__ @code{next} command. Then update the display window | |
5244 | to show the current file and location. | |
5245 | ||
5246 | @item M-i | |
5247 | Execute one instruction, like the _GDBN__ @code{stepi} command; update | |
5248 | display window accordingly. | |
5249 | ||
5250 | @item M-x gdb-nexti | |
5251 | Execute to next instruction, using the _GDBN__ @code{nexti} command; update | |
5252 | display window accordingly. | |
5253 | ||
5254 | @item C-c C-f | |
5255 | Execute until exit from the selected stack frame, like the _GDBN__ | |
5256 | @code{finish} command. | |
5257 | ||
5258 | @item M-c | |
5259 | Continue execution of the program, like the _GDBN__ @code{continue} | |
5260 | command. @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
5261 | ||
5262 | @item M-u | |
5263 | Go up the number of frames indicated by the numeric argument | |
5264 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
5265 | like the _GDBN__ @code{up} command. @emph{Warning:} In Emacs v19, this | |
5266 | command is @kbd{C-c C-u}.@refill | |
5267 | ||
5268 | @item M-d | |
5269 | Go down the number of frames indicated by the numeric argument, like the | |
5270 | _GDBN__ @code{down} command. @emph{Warning:} In Emacs v19, this command | |
5271 | is @kbd{C-c C-d}. | |
5272 | ||
5273 | @item C-x & | |
5274 | Read the number where the cursor is positioned, and insert it at the end | |
5275 | of the _GDBN__ I/O buffer. For example, if you wish to disassemble code | |
5276 | around an address that was displayed earlier, type @kbd{disassemble}; | |
5277 | then move the cursor to the address display, and pick up the | |
5278 | argument for @code{disassemble} by typing @kbd{C-x &}. | |
5279 | ||
5280 | You can customize this further on the fly by defining elements of the list | |
5281 | @code{gdb-print-command}; once it is defined, you can format or | |
5282 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
5283 | inserted. A numeric argument to @kbd{C-x &} will both flag that you | |
5284 | wish special formatting, and act as an index to pick an element of the | |
5285 | list. If the list element is a string, the number to be inserted is | |
5286 | formatted using the Emacs function @code{format}; otherwise the number | |
5287 | is passed as an argument to the corresponding list element. | |
5288 | ||
5289 | @end table | |
5290 | ||
5291 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
5292 | tells _GDBN__ to set a breakpoint on the source line point is on. | |
5293 | ||
5294 | If you accidentally delete the source-display buffer, an easy way to get | |
5295 | it back is to type the command @code{f} in the _GDBN__ buffer, to | |
5296 | request a frame display; when you run under Emacs, this will recreate | |
5297 | the source buffer if necessary to show you the context of the current | |
5298 | frame. | |
5299 | ||
5300 | The source files displayed in Emacs are in ordinary Emacs buffers | |
5301 | which are visiting the source files in the usual way. You can edit | |
5302 | the files with these buffers if you wish; but keep in mind that _GDBN__ | |
5303 | communicates with Emacs in terms of line numbers. If you add or | |
5304 | delete lines from the text, the line numbers that _GDBN__ knows will cease | |
5305 | to correspond properly to the code. | |
5306 | ||
5307 | @c The following dropped because Epoch is nonstandard. Reactivate | |
5308 | @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990 | |
5309 | @ignore | |
5310 | @kindex emacs epoch environment | |
5311 | @kindex epoch | |
5312 | @kindex inspect | |
5313 | ||
5314 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
5315 | environment. Users of this environment can use a new command, | |
5316 | @code{inspect} which performs identically to @code{print} except that | |
5317 | each value is printed in its own window. | |
5318 | @end ignore | |
5319 | ||
5320 | @node _GDBN__ Bugs, Renamed Commands, Emacs, Top | |
5321 | @chapter Reporting Bugs in _GDBN__ | |
5322 | @cindex Bugs in _GDBN__ | |
5323 | @cindex Reporting Bugs in _GDBN__ | |
5324 | ||
5325 | Your bug reports play an essential role in making _GDBN__ reliable. | |
5326 | ||
5327 | Reporting a bug may help you by bringing a solution to your problem, or it | |
5328 | may not. But in any case the principal function of a bug report is to help | |
5329 | the entire community by making the next version of _GDBN__ work better. Bug | |
5330 | reports are your contribution to the maintenance of _GDBN__. | |
5331 | ||
5332 | In order for a bug report to serve its purpose, you must include the | |
5333 | information that enables us to fix the bug. | |
5334 | ||
5335 | @menu | |
5336 | * Bug Criteria:: Have You Found a Bug? | |
5337 | * Bug Reporting:: How to Report Bugs | |
5338 | @end menu | |
5339 | ||
5340 | @node Bug Criteria, Bug Reporting, _GDBN__ Bugs, _GDBN__ Bugs | |
5341 | @section Have You Found a Bug? | |
5342 | @cindex Bug Criteria | |
5343 | ||
5344 | If you are not sure whether you have found a bug, here are some guidelines: | |
5345 | ||
5346 | @itemize @bullet | |
5347 | @item | |
5348 | @cindex Fatal Signal | |
5349 | @cindex Core Dump | |
5350 | If the debugger gets a fatal signal, for any input whatever, that is a | |
5351 | _GDBN__ bug. Reliable debuggers never crash. | |
5352 | ||
5353 | @item | |
5354 | @cindex error on Valid Input | |
5355 | If _GDBN__ produces an error message for valid input, that is a bug. | |
5356 | ||
5357 | @item | |
5358 | @cindex Invalid Input | |
5359 | If _GDBN__ does not produce an error message for invalid input, | |
5360 | that is a bug. However, you should note that your idea of | |
5361 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
5362 | for traditional practice''. | |
5363 | ||
5364 | @item | |
5365 | If you are an experienced user of debugging tools, your suggestions | |
5366 | for improvement of _GDBN__ are welcome in any case. | |
5367 | @end itemize | |
5368 | ||
5369 | @node Bug Reporting, , Bug Criteria, _GDBN__ Bugs | |
5370 | @section How to Report Bugs | |
5371 | @cindex Bug Reports | |
5372 | @cindex Compiler Bugs, Reporting | |
5373 | ||
5374 | A number of companies and individuals offer support for GNU products. | |
5375 | If you obtained _GDBN__ from a support organization, we recommend you | |
5376 | contact that organization first. | |
5377 | ||
5378 | Contact information for many support companies and individuals is | |
5379 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
5380 | ||
5381 | In any event, we also recommend that you send bug reports for _GDBN__ to one | |
5382 | of these addresses: | |
5383 | ||
5384 | @example | |
5385 | bug-gdb@@prep.ai.mit.edu | |
5386 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
5387 | @end example | |
5388 | ||
5389 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
5390 | @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to | |
5391 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
5392 | ||
5393 | The mailing list @samp{bug-gdb} has a newsgroup which serves as a | |
5394 | repeater. The mailing list and the newsgroup carry exactly the same | |
5395 | messages. Often people think of posting bug reports to the newsgroup | |
5396 | instead of mailing them. This appears to work, but it has one problem | |
5397 | which can be crucial: a newsgroup posting often lacks a mail path | |
5398 | back to the sender. Thus, if we need to ask for more information, we | |
5399 | may be unable to reach you. For this reason, it is better to send bug | |
5400 | reports to the mailing list. | |
5401 | ||
5402 | As a last resort, send bug reports on paper to: | |
5403 | ||
5404 | @example | |
5405 | GNU Debugger Bugs | |
5406 | 545 Tech Square | |
5407 | Cambridge, MA 02139 | |
5408 | @end example | |
5409 | ||
5410 | The fundamental principle of reporting bugs usefully is this: | |
5411 | @strong{report all the facts}. If you are not sure whether to state a | |
5412 | fact or leave it out, state it! | |
5413 | ||
5414 | Often people omit facts because they think they know what causes the | |
5415 | problem and assume that some details don't matter. Thus, you might | |
5416 | assume that the name of the variable you use in an example does not matter. | |
5417 | Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a | |
5418 | stray memory reference which happens to fetch from the location where that | |
5419 | name is stored in memory; perhaps, if the name were different, the contents | |
5420 | of that location would fool the debugger into doing the right thing despite | |
5421 | the bug. Play it safe and give a specific, complete example. That is the | |
5422 | easiest thing for you to do, and the most helpful. | |
5423 | ||
5424 | Keep in mind that the purpose of a bug report is to enable us to fix | |
5425 | the bug if it is new to us. It isn't as important what happens if | |
5426 | the bug is already known. Therefore, always write your bug reports on | |
5427 | the assumption that the bug has not been reported previously. | |
5428 | ||
5429 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
5430 | bell?'' Those bug reports are useless, and we urge everyone to | |
5431 | @emph{refuse to respond to them} except to chide the sender to report | |
5432 | bugs properly. | |
5433 | ||
5434 | To enable us to fix the bug, you should include all these things: | |
5435 | ||
5436 | @itemize @bullet | |
5437 | @item | |
5438 | The version of _GDBN__. _GDBN__ announces it if you start with no | |
5439 | arguments; you can also print it at any time using @code{show version}. | |
5440 | ||
5441 | Without this, we won't know whether there is any point in looking for | |
5442 | the bug in the current version of _GDBN__. | |
5443 | ||
5444 | @item | |
5445 | A complete input script, and all necessary source files, that will | |
5446 | reproduce the bug. | |
5447 | ||
5448 | @item | |
5449 | What compiler (and its version) was used to compile _GDBN__---e.g. | |
5450 | ``_GCC__-1.37.1''. | |
5451 | ||
5452 | @item | |
5453 | The command arguments you gave the compiler to compile your example and | |
5454 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
5455 | you won't omit something important, list them all. | |
5456 | ||
5457 | If we were to try to guess the arguments, we would probably guess wrong | |
5458 | and then we might not encounter the bug. | |
5459 | ||
5460 | @item | |
5461 | The type of machine you are using, and the operating system name and | |
5462 | version number. | |
5463 | ||
5464 | @item | |
5465 | A description of what behavior you observe that you believe is | |
5466 | incorrect. For example, ``It gets a fatal signal.'' | |
5467 | ||
5468 | Of course, if the bug is that _GDBN__ gets a fatal signal, then we will | |
5469 | certainly notice it. But if the bug is incorrect output, we might not | |
5470 | notice unless it is glaringly wrong. We are human, after all. You | |
5471 | might as well not give us a chance to make a mistake. | |
5472 | ||
5473 | Even if the problem you experience is a fatal signal, you should still | |
5474 | say so explicitly. Suppose something strange is going on, such as, | |
5475 | your copy of _GDBN__ is out of synch, or you have encountered a | |
5476 | bug in the C library on your system. (This has happened!) Your copy | |
5477 | might crash and ours would not. If you told us to expect a crash, | |
5478 | then when ours fails to crash, we would know that the bug was not | |
5479 | happening for us. If you had not told us to expect a crash, then we | |
5480 | would not be able to draw any conclusion from our observations. | |
5481 | ||
5482 | @item | |
5483 | If you wish to suggest changes to the _GDBN__ source, send us context | |
5484 | diffs. If you even discuss something in the _GDBN__ source, refer to | |
5485 | it by context, not by line number. | |
5486 | ||
5487 | The line numbers in our development sources won't match those in your | |
5488 | sources. Your line numbers would convey no useful information to us. | |
5489 | ||
5490 | @end itemize | |
5491 | ||
5492 | Here are some things that are not necessary: | |
5493 | ||
5494 | @itemize @bullet | |
5495 | @item | |
5496 | A description of the envelope of the bug. | |
5497 | ||
5498 | Often people who encounter a bug spend a lot of time investigating | |
5499 | which changes to the input file will make the bug go away and which | |
5500 | changes will not affect it. | |
5501 | ||
5502 | This is often time consuming and not very useful, because the way we | |
5503 | will find the bug is by running a single example under the debugger | |
5504 | with breakpoints, not by pure deduction from a series of examples. | |
5505 | We recommend that you save your time for something else. | |
5506 | ||
5507 | Of course, if you can find a simpler example to report @emph{instead} | |
5508 | of the original one, that is a convenience for us. Errors in the | |
5509 | output will be easier to spot, running under the debugger will take | |
5510 | less time, etc. | |
5511 | ||
5512 | However, simplification is not vital; if you don't want to do this, | |
5513 | report the bug anyway and send us the entire test case you used. | |
5514 | ||
5515 | @item | |
5516 | A patch for the bug. | |
5517 | ||
5518 | A patch for the bug does help us if it is a good one. But don't omit | |
5519 | the necessary information, such as the test case, on the assumption that | |
5520 | a patch is all we need. We might see problems with your patch and decide | |
5521 | to fix the problem another way, or we might not understand it at all. | |
5522 | ||
5523 | Sometimes with a program as complicated as _GDBN__ it is very hard to | |
5524 | construct an example that will make the program follow a certain path | |
5525 | through the code. If you don't send us the example, we won't be able | |
5526 | to construct one, so we won't be able to verify that the bug is fixed. | |
5527 | ||
5528 | And if we can't understand what bug you are trying to fix, or why your | |
5529 | patch should be an improvement, we won't install it. A test case will | |
5530 | help us to understand. | |
5531 | ||
5532 | @item | |
5533 | A guess about what the bug is or what it depends on. | |
5534 | ||
5535 | Such guesses are usually wrong. Even we can't guess right about such | |
5536 | things without first using the debugger to find the facts. | |
5537 | @end itemize | |
5538 | ||
5539 | @iftex | |
5540 | @include rdl-apps.texinfo | |
5541 | @end iftex | |
5542 | ||
5543 | @node Renamed Commands, Installing _GDBN__, _GDBN__ Bugs, Top | |
5544 | @appendix Renamed Commands | |
5545 | ||
5546 | The following commands were renamed in _GDBN__ 4.0, in order to make the | |
5547 | command set as a whole more consistent and easier to use and remember: | |
5548 | ||
5549 | @kindex add-syms | |
5550 | @kindex delete environment | |
5551 | @kindex info copying | |
5552 | @kindex info convenience | |
5553 | @kindex info directories | |
5554 | @kindex info editing | |
5555 | @kindex info history | |
5556 | @kindex info targets | |
5557 | @kindex info values | |
5558 | @kindex info version | |
5559 | @kindex info warranty | |
5560 | @kindex set addressprint | |
5561 | @kindex set arrayprint | |
5562 | @kindex set prettyprint | |
5563 | @kindex set screen-height | |
5564 | @kindex set screen-width | |
5565 | @kindex set unionprint | |
5566 | @kindex set vtblprint | |
5567 | @kindex set demangle | |
5568 | @kindex set asm-demangle | |
5569 | @kindex set sevenbit-strings | |
5570 | @kindex set array-max | |
5571 | @kindex set caution | |
5572 | @kindex set history write | |
5573 | @kindex show addressprint | |
5574 | @kindex show arrayprint | |
5575 | @kindex show prettyprint | |
5576 | @kindex show screen-height | |
5577 | @kindex show screen-width | |
5578 | @kindex show unionprint | |
5579 | @kindex show vtblprint | |
5580 | @kindex show demangle | |
5581 | @kindex show asm-demangle | |
5582 | @kindex show sevenbit-strings | |
5583 | @kindex show array-max | |
5584 | @kindex show caution | |
5585 | @kindex show history write | |
5586 | @kindex unset | |
5587 | ||
5588 | @ifinfo | |
5589 | OLD COMMAND NEW COMMAND | |
5590 | --------------- ---------------------------------- | |
5591 | add-syms add-symbol-file | |
5592 | delete environment unset environment | |
5593 | info convenience show convenience | |
5594 | info copying show copying | |
5595 | info directories show directories | |
5596 | info editing show commands | |
5597 | info history show values | |
5598 | info targets help target | |
5599 | info values show values | |
5600 | info version show version | |
5601 | info warranty show warranty | |
5602 | set/show addressprint set/show print address | |
5603 | set/show array-max set/show print elements | |
5604 | set/show arrayprint set/show print array | |
5605 | set/show asm-demangle set/show print asm-demangle | |
5606 | set/show caution set/show confirm | |
5607 | set/show demangle set/show print demangle | |
5608 | set/show history write set/show history save | |
5609 | set/show prettyprint set/show print pretty | |
5610 | set/show screen-height set/show height | |
5611 | set/show screen-width set/show width | |
5612 | set/show sevenbit-strings set/show print sevenbit-strings | |
5613 | set/show unionprint set/show print union | |
5614 | set/show vtblprint set/show print vtbl | |
5615 | ||
5616 | unset [ No longer an alias for delete ] | |
5617 | @end ifinfo | |
5618 | ||
5619 | @tex | |
5620 | \vskip \parskip\vskip \baselineskip | |
5621 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
5622 | {\bf Old Command} &&{\bf New Command}\cr | |
5623 | add-syms &&add-symbol-file\cr | |
5624 | delete environment &&unset environment\cr | |
5625 | info convenience &&show convenience\cr | |
5626 | info copying &&show copying\cr | |
5627 | info directories &&show directories \cr | |
5628 | info editing &&show commands\cr | |
5629 | info history &&show values\cr | |
5630 | info targets &&help target\cr | |
5631 | info values &&show values\cr | |
5632 | info version &&show version\cr | |
5633 | info warranty &&show warranty\cr | |
5634 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
5635 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
5636 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
5637 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
5638 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
5639 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
5640 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
5641 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
5642 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
5643 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
5644 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
5645 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
5646 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
5647 | \cr | |
5648 | unset &&\rm(No longer an alias for delete)\cr | |
5649 | } | |
5650 | @end tex | |
5651 | ||
5652 | @node Installing _GDBN__, Copying, Renamed Commands, Top | |
5653 | @appendix Installing _GDBN__ | |
5654 | @cindex configuring _GDBN__ | |
5655 | @cindex installation | |
5656 | ||
7463aadd RP |
5657 | _GDBN__ is distributed with a script @code{configure} that automates the |
5658 | process of preparing _GDBN__ for installation; you can then use | |
5659 | @code{make} to actually build it. | |
5660 | ||
5661 | You can find the @code{configure} script that's specific to _GDBN__ in | |
5662 | the main _GDBN__ source directory. However, @code{configure} is | |
5663 | designed to be called recursively, so it is most convenient to run the | |
5664 | version of @code{configure} for the @emph{parent} of that directory, | |
5665 | which should include not only @code{_GDBP__} but also other @sc{gnu} | |
5666 | tools and libraries. Building _GDBN__ requires some of these associated | |
5667 | directories; at a minimum, you need a source directory that includes the | |
5668 | directories | |
5669 | @example | |
5670 | bfd gdb include libiberty readline | |
5671 | @end example | |
5672 | @noindent | |
5673 | to build _GDBN__. It should also include @file{texinfo} if you want to | |
5674 | format and print copies of this manual. | |
5675 | ||
5676 | The simplest way to configure and build _GDBN__ is the following: | |
5677 | @example | |
5678 | cd @var{gnusrc} | |
5679 | ./configure @var{machine} | |
5680 | make | |
5681 | @end example | |
5682 | @noindent | |
5683 | where @var{gnusrc} is the directory containing both _GDBN__ source and | |
5684 | source for supporting libraries, in subdirectories; and @var{machine} is | |
5685 | something like @samp{sun4} or @samp{vax}, that identifies the platform | |
5686 | where _GDBN__ will run. | |
5687 | ||
5688 | The best way to build _GDBN__ is to use subdirectories that record the | |
70b88761 RP |
5689 | configuration options used; this gives you a clean way of building |
5690 | _GDBN__ binaries with several different configuration options. | |
7463aadd RP |
5691 | @code{configure} only requires this when you simultaneously create |
5692 | several configurations; but it's a good habit even for a single | |
5693 | configuration. You can specify the use of subdirectories using the | |
5694 | @samp{+forcesubdirs} option (abbreviated @samp{+f}). For example, | |
5695 | assuming the @sc{gnu} source directory that includes _GDBN__ source and | |
5696 | the supporting libraries is in a directory called @file{gnusrc}: | |
70b88761 RP |
5697 | |
5698 | @example | |
7463aadd RP |
5699 | cd gnusrc |
5700 | ./configure +f sun4 | |
5701 | cd Host-sun4/Target-sun4 | |
70b88761 RP |
5702 | make |
5703 | @end example | |
5704 | ||
5705 | @noindent | |
7463aadd RP |
5706 | will build _GDBN__ on a Sun 4. |
5707 | ||
5708 | Here is a summary of all the @code{configure} options and arguments that | |
5709 | you might use for building _GDBN__: | |
5710 | ||
5711 | @example | |
5712 | configure @rm{[}+destdir=@var{dir}@rm{]} @rm{[}+forcesubdirs@rm{]} @rm{[}+norecur@rm{]} @rm{[}+rm@rm{]} | |
5713 | @rm{[}+target=@var{machine}@dots{}@rm{]} @var{host}@dots{} | |
5714 | @end example | |
5715 | ||
5716 | You may introduce options with the character @samp{-} rather than | |
5717 | @samp{+} if you prefer; but options introduced with @samp{+} may be truncated. | |
5718 | @code{configure} accepts other options, for compatibility with | |
5719 | configuring other @sc{gnu} tools recursively; but these are the only | |
5720 | options that affect _GDBN__ or its supporting libraries. | |
70b88761 RP |
5721 | |
5722 | @table @code | |
7463aadd RP |
5723 | @item +destdir=@var{dir} |
5724 | @var{dir} is an installation directory for use by @code{make install}. | |
5725 | ||
5726 | @item +forcesubdirs | |
5727 | Build binaries in subdirectories of the form | |
5728 | @example | |
5729 | Host-@var{machine}/Target-@var{machine} | |
5730 | @end example | |
5731 | @noindent | |
5732 | Without this option, if you specify only one configuration for _GDBN__, | |
5733 | @code{configure} will use the same directory for source, configured | |
5734 | files, and binaries. This option is used automatically if you specify | |
5735 | more than one @var{host} or more than one @samp{+target=@var{machine}} | |
5736 | option on the @code{configure} command line. | |
5737 | ||
5738 | @item +norecur | |
5739 | Configure only the directory where @code{configure} is executed; do not | |
5740 | propagate configuration to subdirectories. | |
5741 | ||
5742 | @item +rm | |
5743 | Remove the configuration specified by other arguments. | |
5744 | ||
5745 | @item +target=@var{machine} @dots{} | |
5746 | Configure _GDBN__ for cross-debugging programs running on specified | |
5747 | @var{machine}s. You may specify as many @samp{+target} options as you | |
5748 | wish. To see a list of available targets, execute @samp{ls tconfig} in | |
5749 | the _GDBN__ source directory. Without this option, _GDBN__ is | |
5750 | configured to debug programs that run on the same machine (@var{host}) | |
5751 | as _GDBN__ itself. | |
5752 | ||
5753 | @item @var{host} @dots{} | |
5754 | Configure _GDBN__ to run on specified @var{host}s. You may specify as | |
5755 | many host names as you wish. To see a list of available hosts, execute | |
5756 | @samp{ls xconfig} in the _GDBN__ source directory. | |
70b88761 RP |
5757 | @end table |
5758 | ||
5759 | @node Copying, Index, Installing _GDBN__, Top | |
70b88761 | 5760 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 5761 | @center Version 2, June 1991 |
70b88761 RP |
5762 | |
5763 | @display | |
7463aadd | 5764 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
5765 | 675 Mass Ave, Cambridge, MA 02139, USA |
5766 | ||
5767 | Everyone is permitted to copy and distribute verbatim copies | |
5768 | of this license document, but changing it is not allowed. | |
5769 | @end display | |
5770 | ||
5771 | @unnumberedsec Preamble | |
5772 | ||
7463aadd RP |
5773 | The licenses for most software are designed to take away your |
5774 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 5775 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
5776 | software---to make sure the software is free for all its users. This |
5777 | General Public License applies to most of the Free Software | |
5778 | Foundation's software and to any other program whose authors commit to | |
5779 | using it. (Some other Free Software Foundation software is covered by | |
5780 | the GNU Library General Public License instead.) You can apply it to | |
5781 | your programs, too. | |
70b88761 RP |
5782 | |
5783 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
5784 | price. Our General Public Licenses are designed to make sure that you |
5785 | have the freedom to distribute copies of free software (and charge for | |
5786 | this service if you wish), that you receive source code or can get it | |
5787 | if you want it, that you can change the software or use pieces of it | |
5788 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
5789 | |
5790 | To protect your rights, we need to make restrictions that forbid | |
5791 | anyone to deny you these rights or to ask you to surrender the rights. | |
5792 | These restrictions translate to certain responsibilities for you if you | |
5793 | distribute copies of the software, or if you modify it. | |
5794 | ||
7463aadd | 5795 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
5796 | gratis or for a fee, you must give the recipients all the rights that |
5797 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
5798 | source code. And you must show them these terms so they know their |
5799 | rights. | |
70b88761 RP |
5800 | |
5801 | We protect your rights with two steps: (1) copyright the software, and | |
5802 | (2) offer you this license which gives you legal permission to copy, | |
5803 | distribute and/or modify the software. | |
5804 | ||
5805 | Also, for each author's protection and ours, we want to make certain | |
5806 | that everyone understands that there is no warranty for this free | |
5807 | software. If the software is modified by someone else and passed on, we | |
5808 | want its recipients to know that what they have is not the original, so | |
5809 | that any problems introduced by others will not reflect on the original | |
5810 | authors' reputations. | |
5811 | ||
7463aadd RP |
5812 | Finally, any free program is threatened constantly by software |
5813 | patents. We wish to avoid the danger that redistributors of a free | |
5814 | program will individually obtain patent licenses, in effect making the | |
5815 | program proprietary. To prevent this, we have made it clear that any | |
5816 | patent must be licensed for everyone's free use or not licensed at all. | |
5817 | ||
70b88761 RP |
5818 | The precise terms and conditions for copying, distribution and |
5819 | modification follow. | |
5820 | ||
5821 | @iftex | |
7463aadd | 5822 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
5823 | @end iftex |
5824 | @ifinfo | |
7463aadd | 5825 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
5826 | @end ifinfo |
5827 | ||
5828 | @enumerate | |
5829 | @item | |
7463aadd RP |
5830 | This License applies to any program or other work which contains |
5831 | a notice placed by the copyright holder saying it may be distributed | |
5832 | under the terms of this General Public License. The ``Program'', below, | |
5833 | refers to any such program or work, and a ``work based on the Program'' | |
5834 | means either the Program or any derivative work under copyright law: | |
5835 | that is to say, a work containing the Program or a portion of it, | |
5836 | either verbatim or with modifications and/or translated into another | |
5837 | language. (Hereinafter, translation is included without limitation in | |
5838 | the term ``modification''.) Each licensee is addressed as ``you''. | |
5839 | ||
5840 | Activities other than copying, distribution and modification are not | |
5841 | covered by this License; they are outside its scope. The act of | |
5842 | running the Program is not restricted, and the output from the Program | |
5843 | is covered only if its contents constitute a work based on the | |
5844 | Program (independent of having been made by running the Program). | |
5845 | Whether that is true depends on what the Program does. | |
70b88761 RP |
5846 | |
5847 | @item | |
7463aadd RP |
5848 | You may copy and distribute verbatim copies of the Program's |
5849 | source code as you receive it, in any medium, provided that you | |
5850 | conspicuously and appropriately publish on each copy an appropriate | |
5851 | copyright notice and disclaimer of warranty; keep intact all the | |
5852 | notices that refer to this License and to the absence of any warranty; | |
5853 | and give any other recipients of the Program a copy of this License | |
5854 | along with the Program. | |
70b88761 | 5855 | |
7463aadd RP |
5856 | You may charge a fee for the physical act of transferring a copy, and |
5857 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 5858 | |
70b88761 | 5859 | @item |
7463aadd RP |
5860 | You may modify your copy or copies of the Program or any portion |
5861 | of it, thus forming a work based on the Program, and copy and | |
5862 | distribute such modifications or work under the terms of Section 1 | |
5863 | above, provided that you also meet all of these conditions: | |
70b88761 | 5864 | |
7463aadd | 5865 | @alphaenumerate |
70b88761 | 5866 | @item |
7463aadd RP |
5867 | You must cause the modified files to carry prominent notices |
5868 | stating that you changed the files and the date of any change. | |
70b88761 RP |
5869 | |
5870 | @item | |
7463aadd RP |
5871 | You must cause any work that you distribute or publish, that in |
5872 | whole or in part contains or is derived from the Program or any | |
5873 | part thereof, to be licensed as a whole at no charge to all third | |
5874 | parties under the terms of this License. | |
70b88761 RP |
5875 | |
5876 | @item | |
7463aadd RP |
5877 | If the modified program normally reads commands interactively |
5878 | when run, you must cause it, when started running for such | |
5879 | interactive use in the most ordinary way, to print or display an | |
5880 | announcement including an appropriate copyright notice and a | |
5881 | notice that there is no warranty (or else, saying that you provide | |
5882 | a warranty) and that users may redistribute the program under | |
5883 | these conditions, and telling the user how to view a copy of this | |
5884 | License. (Exception: if the Program itself is interactive but | |
5885 | does not normally print such an announcement, your work based on | |
5886 | the Program is not required to print an announcement.) | |
5887 | @end alphaenumerate | |
5888 | ||
5889 | These requirements apply to the modified work as a whole. If | |
5890 | identifiable sections of that work are not derived from the Program, | |
5891 | and can be reasonably considered independent and separate works in | |
5892 | themselves, then this License, and its terms, do not apply to those | |
5893 | sections when you distribute them as separate works. But when you | |
5894 | distribute the same sections as part of a whole which is a work based | |
5895 | on the Program, the distribution of the whole must be on the terms of | |
5896 | this License, whose permissions for other licensees extend to the | |
5897 | entire whole, and thus to each and every part regardless of who wrote it. | |
5898 | ||
5899 | Thus, it is not the intent of this section to claim rights or contest | |
5900 | your rights to work written entirely by you; rather, the intent is to | |
5901 | exercise the right to control the distribution of derivative or | |
5902 | collective works based on the Program. | |
5903 | ||
5904 | In addition, mere aggregation of another work not based on the Program | |
5905 | with the Program (or with a work based on the Program) on a volume of | |
5906 | a storage or distribution medium does not bring the other work under | |
5907 | the scope of this License. | |
70b88761 RP |
5908 | |
5909 | @item | |
7463aadd RP |
5910 | You may copy and distribute the Program (or a work based on it, |
5911 | under Section 2) in object code or executable form under the terms of | |
5912 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 5913 | |
7463aadd | 5914 | @alphaenumerate |
70b88761 | 5915 | @item |
7463aadd RP |
5916 | Accompany it with the complete corresponding machine-readable |
5917 | source code, which must be distributed under the terms of Sections | |
5918 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
5919 | |
5920 | @item | |
7463aadd RP |
5921 | Accompany it with a written offer, valid for at least three |
5922 | years, to give any third party, for a charge no more than your | |
5923 | cost of physically performing source distribution, a complete | |
5924 | machine-readable copy of the corresponding source code, to be | |
5925 | distributed under the terms of Sections 1 and 2 above on a medium | |
5926 | customarily used for software interchange; or, | |
70b88761 RP |
5927 | |
5928 | @item | |
7463aadd RP |
5929 | Accompany it with the information you received as to the offer |
5930 | to distribute corresponding source code. (This alternative is | |
70b88761 | 5931 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
5932 | received the program in object code or executable form with such |
5933 | an offer, in accord with Subsection b above.) | |
5934 | @end alphaenumerate | |
5935 | ||
5936 | The source code for a work means the preferred form of the work for | |
5937 | making modifications to it. For an executable work, complete source | |
5938 | code means all the source code for all modules it contains, plus any | |
5939 | associated interface definition files, plus the scripts used to | |
5940 | control compilation and installation of the executable. However, as a | |
5941 | special exception, the source code distributed need not include | |
5942 | anything that is normally distributed (in either source or binary | |
5943 | form) with the major components (compiler, kernel, and so on) of the | |
5944 | operating system on which the executable runs, unless that component | |
5945 | itself accompanies the executable. | |
5946 | ||
5947 | If distribution of executable or object code is made by offering | |
5948 | access to copy from a designated place, then offering equivalent | |
5949 | access to copy the source code from the same place counts as | |
5950 | distribution of the source code, even though third parties are not | |
5951 | compelled to copy the source along with the object code. | |
70b88761 RP |
5952 | |
5953 | @item | |
7463aadd RP |
5954 | You may not copy, modify, sublicense, or distribute the Program |
5955 | except as expressly provided under this License. Any attempt | |
5956 | otherwise to copy, modify, sublicense or distribute the Program is | |
5957 | void, and will automatically terminate your rights under this License. | |
5958 | However, parties who have received copies, or rights, from you under | |
5959 | this License will not have their licenses terminated so long as such | |
5960 | parties remain in full compliance. | |
70b88761 RP |
5961 | |
5962 | @item | |
7463aadd RP |
5963 | You are not required to accept this License, since you have not |
5964 | signed it. However, nothing else grants you permission to modify or | |
5965 | distribute the Program or its derivative works. These actions are | |
5966 | prohibited by law if you do not accept this License. Therefore, by | |
5967 | modifying or distributing the Program (or any work based on the | |
5968 | Program), you indicate your acceptance of this License to do so, and | |
5969 | all its terms and conditions for copying, distributing or modifying | |
5970 | the Program or works based on it. | |
70b88761 RP |
5971 | |
5972 | @item | |
5973 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
5974 | Program), the recipient automatically receives a license from the |
5975 | original licensor to copy, distribute or modify the Program subject to | |
5976 | these terms and conditions. You may not impose any further | |
5977 | restrictions on the recipients' exercise of the rights granted herein. | |
5978 | You are not responsible for enforcing compliance by third parties to | |
5979 | this License. | |
5980 | ||
5981 | @item | |
5982 | If, as a consequence of a court judgment or allegation of patent | |
5983 | infringement or for any other reason (not limited to patent issues), | |
5984 | conditions are imposed on you (whether by court order, agreement or | |
5985 | otherwise) that contradict the conditions of this License, they do not | |
5986 | excuse you from the conditions of this License. If you cannot | |
5987 | distribute so as to satisfy simultaneously your obligations under this | |
5988 | License and any other pertinent obligations, then as a consequence you | |
5989 | may not distribute the Program at all. For example, if a patent | |
5990 | license would not permit royalty-free redistribution of the Program by | |
5991 | all those who receive copies directly or indirectly through you, then | |
5992 | the only way you could satisfy both it and this License would be to | |
5993 | refrain entirely from distribution of the Program. | |
5994 | ||
5995 | If any portion of this section is held invalid or unenforceable under | |
5996 | any particular circumstance, the balance of the section is intended to | |
5997 | apply and the section as a whole is intended to apply in other | |
5998 | circumstances. | |
5999 | ||
6000 | It is not the purpose of this section to induce you to infringe any | |
6001 | patents or other property right claims or to contest validity of any | |
6002 | such claims; this section has the sole purpose of protecting the | |
6003 | integrity of the free software distribution system, which is | |
6004 | implemented by public license practices. Many people have made | |
6005 | generous contributions to the wide range of software distributed | |
6006 | through that system in reliance on consistent application of that | |
6007 | system; it is up to the author/donor to decide if he or she is willing | |
6008 | to distribute software through any other system and a licensee cannot | |
6009 | impose that choice. | |
6010 | ||
6011 | This section is intended to make thoroughly clear what is believed to | |
6012 | be a consequence of the rest of this License. | |
6013 | ||
6014 | @item | |
6015 | If the distribution and/or use of the Program is restricted in | |
6016 | certain countries either by patents or by copyrighted interfaces, the | |
6017 | original copyright holder who places the Program under this License | |
6018 | may add an explicit geographical distribution limitation excluding | |
6019 | those countries, so that distribution is permitted only in or among | |
6020 | countries not thus excluded. In such case, this License incorporates | |
6021 | the limitation as if written in the body of this License. | |
70b88761 RP |
6022 | |
6023 | @item | |
6024 | The Free Software Foundation may publish revised and/or new versions | |
6025 | of the General Public License from time to time. Such new versions will | |
6026 | be similar in spirit to the present version, but may differ in detail to | |
6027 | address new problems or concerns. | |
6028 | ||
6029 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 6030 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
6031 | later version'', you have the option of following the terms and conditions |
6032 | either of that version or of any later version published by the Free | |
6033 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 6034 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
6035 | Foundation. |
6036 | ||
6037 | @item | |
6038 | If you wish to incorporate parts of the Program into other free | |
6039 | programs whose distribution conditions are different, write to the author | |
6040 | to ask for permission. For software which is copyrighted by the Free | |
6041 | Software Foundation, write to the Free Software Foundation; we sometimes | |
6042 | make exceptions for this. Our decision will be guided by the two goals | |
6043 | of preserving the free status of all derivatives of our free software and | |
6044 | of promoting the sharing and reuse of software generally. | |
6045 | ||
6046 | @iftex | |
6047 | @heading NO WARRANTY | |
6048 | @end iftex | |
6049 | @ifinfo | |
6050 | @center NO WARRANTY | |
6051 | @end ifinfo | |
6052 | ||
6053 | @item | |
6054 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
6055 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
6056 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
6057 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
6058 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
6059 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
6060 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
6061 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
6062 | REPAIR OR CORRECTION. | |
6063 | ||
6064 | @item | |
7463aadd RP |
6065 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
6066 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 6067 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
6068 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
6069 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
6070 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
6071 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
6072 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
6073 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
6074 | @end enumerate |
6075 | ||
6076 | @iftex | |
6077 | @heading END OF TERMS AND CONDITIONS | |
6078 | @end iftex | |
6079 | @ifinfo | |
6080 | @center END OF TERMS AND CONDITIONS | |
6081 | @end ifinfo | |
6082 | ||
6083 | @page | |
7463aadd | 6084 | @unnumberedsec Appendix: How to Apply These Terms to Your New Programs |
70b88761 RP |
6085 | |
6086 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
6087 | possible use to the public, the best way to achieve this is to make it |
6088 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 6089 | |
7463aadd RP |
6090 | To do so, attach the following notices to the program. It is safest |
6091 | to attach them to the start of each source file to most effectively | |
6092 | convey the exclusion of warranty; and each file should have at least | |
6093 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
6094 | |
6095 | @smallexample | |
6096 | @var{one line to give the program's name and a brief idea of what it does.} | |
6097 | Copyright (C) 19@var{yy} @var{name of author} | |
6098 | ||
6099 | This program is free software; you can redistribute it and/or modify | |
6100 | it under the terms of the GNU General Public License as published by | |
7463aadd RP |
6101 | the Free Software Foundation; either version 2 of the License, or |
6102 | (at your option) any later version. | |
70b88761 RP |
6103 | |
6104 | This program is distributed in the hope that it will be useful, | |
6105 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6106 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6107 | GNU General Public License for more details. | |
6108 | ||
6109 | You should have received a copy of the GNU General Public License | |
6110 | along with this program; if not, write to the Free Software | |
6111 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
6112 | @end smallexample | |
6113 | ||
6114 | Also add information on how to contact you by electronic and paper mail. | |
6115 | ||
6116 | If the program is interactive, make it output a short notice like this | |
6117 | when it starts in an interactive mode: | |
6118 | ||
6119 | @smallexample | |
6120 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
6121 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
6122 | This is free software, and you are welcome to redistribute it | |
6123 | under certain conditions; type `show c' for details. | |
6124 | @end smallexample | |
6125 | ||
7463aadd RP |
6126 | The hypothetical commands @samp{show w} and @samp{show c} should show |
6127 | the appropriate parts of the General Public License. Of course, the | |
6128 | commands you use may be called something other than @samp{show w} and | |
6129 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
6130 | suits your program. | |
70b88761 RP |
6131 | |
6132 | You should also get your employer (if you work as a programmer) or your | |
6133 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
6134 | necessary. Here is a sample; alter the names: | |
6135 | ||
7463aadd RP |
6136 | @example |
6137 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | |
6138 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | |
70b88761 RP |
6139 | |
6140 | @var{signature of Ty Coon}, 1 April 1989 | |
6141 | Ty Coon, President of Vice | |
7463aadd RP |
6142 | @end example |
6143 | ||
6144 | This General Public License does not permit incorporating your program into | |
6145 | proprietary programs. If your program is a subroutine library, you may | |
6146 | consider it more useful to permit linking proprietary applications with the | |
6147 | library. If this is what you want to do, use the GNU Library General | |
6148 | Public License instead of this License. | |
70b88761 | 6149 | |
d2e08421 | 6150 | |
9c3ad547 | 6151 | @node Index, , Copying, Top |
d2e08421 | 6152 | @unnumbered Index |
e91b87a3 | 6153 | |
6154 | @printindex cp | |
6155 | ||
fe3f5fc8 RP |
6156 | @tex |
6157 | % I think something like @colophon should be in texinfo. In the | |
6158 | % meantime: | |
6159 | \long\def\colophon{\hbox to0pt{}\vfill | |
6160 | \centerline{The body of this manual is set in} | |
6161 | \centerline{\fontname\tenrm,} | |
6162 | \centerline{with headings in {\bf\fontname\tenbf}} | |
6163 | \centerline{and examples in {\tt\fontname\tentt}.} | |
6164 | \centerline{{\it\fontname\tenit\/} and} | |
6165 | \centerline{{\sl\fontname\tensl\/}} | |
6166 | \centerline{are used for emphasis.}\vfill} | |
6167 | \page\colophon | |
6168 | % Blame: pesch@cygnus.com, 28mar91. | |
6169 | @end tex | |
6170 | ||
e91b87a3 | 6171 | @contents |
6172 | @bye |