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