Commit | Line | Data |
---|---|---|
b80282d5 | 1 | _dnl__ -*-Texinfo-*- |
1041a570 | 2 | _dnl__ Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc. |
b21b18e1 | 3 | _dnl__ $Id$<>_dnl__ |
29a2b744 | 4 | \input texinfo @c -*-texinfo-*- |
1041a570 | 5 | @c Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc. |
29a2b744 | 6 | @c %**start of header |
5a131cc7 | 7 | @setfilename _GDBP__.info |
29a2b744 | 8 | _if__(_GENERIC__) |
a6463583 | 9 | @settitle Debugging with _GDBN__ |
29a2b744 RP |
10 | _fi__(_GENERIC__) |
11 | _if__(!_GENERIC__) | |
a6463583 | 12 | @settitle Debugging with _GDBN__ (_HOST__) |
29a2b744 RP |
13 | _fi__(!_GENERIC__) |
14 | @setchapternewpage odd | |
fb4bb43e RP |
15 | @c @smallbook |
16 | @c @cropmarks | |
29a2b744 RP |
17 | @c %**end of header |
18 | ||
19 | @finalout | |
20 | @syncodeindex ky cp | |
21 | ||
22 | _0__@c ===> NOTE! <==_1__ | |
23 | @c Determine the edition number in *three* places by hand: | |
24 | @c 1. First ifinfo section 2. title page 3. top node | |
25 | @c To find the locations, search for !!set | |
26 | ||
27 | @c The following is for Pesch for his RCS system. | |
28 | @c This revision number *not* the same as the Edition number. | |
29 | @tex | |
30 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
31 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
32 | @end tex | |
33 | ||
d24e0922 | 34 | @c GDB CHANGELOG CONSULTED BETWEEN: |
29a2b744 RP |
35 | @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com) |
36 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
37 | ||
9c3ad547 | 38 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. |
29a2b744 | 39 | |
b7becc8f RP |
40 | @ifinfo |
41 | @format | |
42 | START-INFO-DIR-ENTRY | |
29a2b744 | 43 | * Gdb: (gdb). The GNU debugger. |
b7becc8f RP |
44 | END-INFO-DIR-ENTRY |
45 | @end format | |
46 | @end ifinfo | |
5a131cc7 RP |
47 | _if__(0) |
48 | ||
a6d0b6d3 RP |
49 | NOTE: this manual is marked up for preprocessing with a collection |
50 | of m4 macros called "pretex.m4". | |
51 | ||
9bcc06ef RP |
52 | THIS IS THE SOURCE PRIOR TO PREPROCESSING. The full source needs to |
53 | be run through m4 before either tex- or info- formatting: for example, | |
08665207 | 54 | _0__ |
3e0d0a27 | 55 | m4 pretex.m4 none.m4 all.m4 gdb.texinfo >gdb-all.texinfo |
70b88761 | 56 | will produce (assuming your path finds either GNU m4 >= 0.84, or SysV |
1041a570 | 57 | m4; Berkeley will not do) a file suitable for formatting. See the text in |
70b88761 | 58 | "pretex.m4" for a fuller explanation (and the macro definitions). |
29a2b744 | 59 | _1__ |
e91b87a3 | 60 | |
9bcc06ef | 61 | _fi__(0) |
70b88761 | 62 | @c |
70b88761 RP |
63 | @ifinfo |
64 | This file documents the GNU debugger _GDBN__. | |
65 | ||
29a2b744 | 66 | @c !!set edition, date, version |
a6463583 RP |
67 | This is Edition 4.06, July 1992, |
68 | of @cite{Debugging with _GDBN__: the GNU Source-Level Debugger} | |
29a2b744 RP |
69 | for GDB Version _GDB_VN__. |
70 | ||
95d5ceb9 | 71 | Copyright (C) 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. |
70b88761 RP |
72 | |
73 | Permission is granted to make and distribute verbatim copies of | |
74 | this manual provided the copyright notice and this permission notice | |
75 | are preserved on all copies. | |
76 | ||
77 | @ignore | |
78 | Permission is granted to process this file through TeX and print the | |
79 | results, provided the printed document carries copying permission | |
80 | notice identical to this one except for the removal of this paragraph | |
81 | (this paragraph not being relevant to the printed manual). | |
82 | ||
83 | @end ignore | |
84 | Permission is granted to copy and distribute modified versions of this | |
85 | manual under the conditions for verbatim copying, provided also that the | |
86 | section entitled ``GNU General Public License'' is included exactly as | |
87 | in the original, and provided that the entire resulting derived work is | |
88 | distributed under the terms of a permission notice identical to this | |
89 | one. | |
90 | ||
91 | Permission is granted to copy and distribute translations of this manual | |
92 | into another language, under the above conditions for modified versions, | |
93 | except that the section entitled ``GNU General Public License'' may be | |
94 | included in a translation approved by the Free Software Foundation | |
95 | instead of in the original English. | |
96 | @end ifinfo | |
1041a570 | 97 | |
70b88761 | 98 | @titlepage |
a6463583 | 99 | @title Debugging with _GDBN__ |
95d5ceb9 | 100 | @subtitle The GNU Source-Level Debugger |
70b88761 | 101 | _if__(!_GENERIC__) |
c7cb8acb | 102 | @subtitle on _HOST__ Systems |
70b88761 RP |
103 | _fi__(!_GENERIC__) |
104 | @sp 1 | |
29a2b744 | 105 | @c !!set edition, date, version |
a6463583 RP |
106 | @subtitle Edition 4.06, for _GDBN__ version _GDB_VN__ |
107 | @subtitle July 1992 | |
29a2b744 | 108 | @author by Richard M. Stallman and Roland H. Pesch |
70b88761 RP |
109 | @page |
110 | @tex | |
111 | {\parskip=0pt | |
93ac5532 | 112 | \hfill pesch\@cygnus.com\par |
a6463583 | 113 | \hfill {\it Debugging with _GDBN__}, \manvers\par |
70b88761 RP |
114 | \hfill \TeX{}info \texinfoversion\par |
115 | } | |
116 | @end tex | |
117 | ||
118 | @vskip 0pt plus 1filll | |
1041a570 | 119 | Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. |
70b88761 RP |
120 | |
121 | Permission is granted to make and distribute verbatim copies of | |
122 | this manual provided the copyright notice and this permission notice | |
123 | are preserved on all copies. | |
124 | ||
125 | Permission is granted to copy and distribute modified versions of this | |
126 | manual under the conditions for verbatim copying, provided also that the | |
127 | section entitled ``GNU General Public License'' is included exactly as | |
128 | in the original, and provided that the entire resulting derived work is | |
129 | distributed under the terms of a permission notice identical to this | |
130 | one. | |
131 | ||
132 | Permission is granted to copy and distribute translations of this manual | |
133 | into another language, under the above conditions for modified versions, | |
134 | except that the section entitled ``GNU General Public License'' may be | |
135 | included in a translation approved by the Free Software Foundation | |
136 | instead of in the original English. | |
137 | @end titlepage | |
138 | @page | |
139 | ||
70b88761 | 140 | @ifinfo |
4eb4cf57 | 141 | @node Top |
a6463583 | 142 | @top Debugging with _GDBN__ |
29a2b744 RP |
143 | |
144 | This file describes _GDBN__, the GNU symbolic debugger. | |
145 | ||
146 | @c !!set edition, date, version | |
a6463583 | 147 | This is Edition 4.06, July 1992, for GDB Version _GDB_VN__. |
70b88761 RP |
148 | @end ifinfo |
149 | ||
150 | @menu | |
b80282d5 | 151 | * Summary:: Summary of _GDBN__ |
4eb4cf57 | 152 | _if__(_GENERIC__ || !_H8__) |
c7cb8acb | 153 | * New Features:: New features since GDB version 3.5 |
4eb4cf57 | 154 | _fi__(_GENERIC__ || !_H8__) |
95d5ceb9 | 155 | * Sample Session:: A sample _GDBN__ session |
29a2b744 RP |
156 | * Invocation:: Getting in and out of _GDBN__ |
157 | * Commands:: _GDBN__ commands | |
158 | * Running:: Running programs under _GDBN__ | |
159 | * Stopping:: Stopping and continuing | |
160 | * Stack:: Examining the stack | |
161 | * Source:: Examining source files | |
162 | * Data:: Examining data | |
4eb4cf57 | 163 | _if__(!_CONLY__) |
29a2b744 | 164 | * Languages:: Using _GDBN__ with different languages |
4eb4cf57 RP |
165 | _fi__(!_CONLY__) |
166 | _if__(_CONLY__) | |
167 | * C:: C and C++ | |
168 | _fi__(_CONLY__) | |
29a2b744 RP |
169 | * Symbols:: Examining the symbol table |
170 | * Altering:: Altering execution | |
171 | * _GDBN__ Files:: _GDBN__'s files | |
172 | * Targets:: Specifying a debugging target | |
c2bbbb22 | 173 | * Controlling _GDBN__:: Controlling _GDBN__ |
29a2b744 | 174 | * Sequences:: Canned sequences of commands |
4eb4cf57 | 175 | _if__(!_DOSHOST__) |
b80282d5 | 176 | * Emacs:: Using _GDBN__ under GNU Emacs |
4eb4cf57 | 177 | _fi__(!_DOSHOST__) |
29a2b744 | 178 | * _GDBN__ Bugs:: Reporting bugs in _GDBN__ |
77fe5411 | 179 | _if__(_GENERIC__||!_H8__) |
e251e767 | 180 | * Renamed Commands:: |
77fe5411 | 181 | _fi__(_GENERIC__||!_H8__) |
77b46d13 | 182 | * Formatting Documentation:: How to format and print GDB documentation |
c7cb8acb | 183 | * Installing GDB:: Installing GDB |
b80282d5 RP |
184 | * Copying:: GNU GENERAL PUBLIC LICENSE |
185 | * Index:: Index | |
70b88761 RP |
186 | @end menu |
187 | ||
4eb4cf57 | 188 | @node Summary |
70b88761 RP |
189 | @unnumbered Summary of _GDBN__ |
190 | ||
191 | The purpose of a debugger such as _GDBN__ is to allow you to see what is | |
192 | going on ``inside'' another program while it executes---or what another | |
1041a570 | 193 | program was doing at the moment it crashed. |
70b88761 RP |
194 | |
195 | _GDBN__ can do four main kinds of things (plus other things in support of | |
1041a570 | 196 | these) to help you catch bugs in the act: |
70b88761 RP |
197 | |
198 | @itemize @bullet | |
199 | @item | |
200 | Start your program, specifying anything that might affect its behavior. | |
201 | ||
202 | @item | |
203 | Make your program stop on specified conditions. | |
204 | ||
205 | @item | |
206 | Examine what has happened, when your program has stopped. | |
207 | ||
208 | @item | |
209 | Change things in your program, so you can experiment with correcting the | |
210 | effects of one bug and go on to learn about another. | |
211 | @end itemize | |
212 | ||
c2bbbb22 RP |
213 | You can use _GDBN__ to debug programs written in C, C++, and Modula-2. |
214 | Fortran support will be added when a GNU Fortran compiler is ready. | |
70b88761 RP |
215 | |
216 | @menu | |
b80282d5 RP |
217 | * Free Software:: Free Software |
218 | * Contributors:: Contributors to GDB | |
70b88761 RP |
219 | @end menu |
220 | ||
4eb4cf57 | 221 | @node Free Software |
70b88761 | 222 | @unnumberedsec Free Software |
1041a570 RP |
223 | |
224 | _GDBN__ is @dfn{free software}, protected by the GNU General Public License | |
225 | (GPL). The GPL gives you the freedom to copy or adapt a licensed | |
70b88761 RP |
226 | program---but every person getting a copy also gets with it the |
227 | freedom to modify that copy (which means that they must get access to | |
228 | the source code), and the freedom to distribute further copies. | |
229 | Typical software companies use copyrights to limit your freedoms; the | |
230 | Free Software Foundation uses the GPL to preserve these freedoms. | |
231 | ||
232 | Fundamentally, the General Public License is a license which says that | |
29a2b744 | 233 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
234 | from anyone else. |
235 | ||
29a2b744 | 236 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
1041a570 | 237 | |
4eb4cf57 | 238 | @node Contributors |
70b88761 RP |
239 | @unnumberedsec Contributors to GDB |
240 | ||
241 | Richard Stallman was the original author of GDB, and of many other GNU | |
242 | programs. Many others have contributed to its development. This | |
243 | section attempts to credit major contributors. One of the virtues of | |
244 | free software is that everyone is free to contribute to it; with | |
245 | regret, we cannot actually acknowledge everyone here. The file | |
246 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
247 | account. | |
248 | ||
249 | Changes much prior to version 2.0 are lost in the mists of time. | |
250 | ||
251 | @quotation | |
252 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
253 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
254 | omitted from this list, we would like to add your names! | |
255 | @end quotation | |
256 | ||
257 | So that they may not regard their long labor as thankless, we | |
69bbcf05 | 258 | particularly thank those who shepherded GDB through major releases: Stu |
6f3ec223 RP |
259 | Grossman and John Gilmore (releases 4.6, 4.5, 4.4), John Gilmore |
260 | (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, | |
261 | 3.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of | |
262 | GDB for some period, each contributed significantly to the structure, | |
263 | stability, and capabilities of the entire debugger. | |
70b88761 RP |
264 | |
265 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
266 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
267 | ||
268 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
269 | with significant additional contributions from Per Bothner. James | |
270 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
271 | TerMaat (who also did much general update work leading to release 3.0). | |
272 | ||
1041a570 RP |
273 | GDB 4 uses the BFD subroutine library to examine multiple |
274 | object-file formats; BFD was a joint project of David V. | |
275 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
70b88761 | 276 | |
1041a570 RP |
277 | David Johnson wrote the original COFF support; Pace Willison did |
278 | the original support for encapsulated COFF. | |
70b88761 RP |
279 | |
280 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
281 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
282 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris |
283 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
284 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
285 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
286 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
287 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
288 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
289 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
290 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
291 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
292 | support. | |
70b88761 | 293 | |
c338a2fd RP |
294 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
295 | libraries. | |
70b88761 RP |
296 | |
297 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
298 | several machine instruction sets. | |
299 | ||
1041a570 RP |
300 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped |
301 | develop remote debugging. Intel Corporation and Wind River Systems | |
302 | contributed remote debugging modules for their products. | |
70b88761 | 303 | |
1041a570 RP |
304 | Brian Fox is the author of the readline libraries providing |
305 | command-line editing and command history. | |
70b88761 | 306 | |
1041a570 RP |
307 | Andrew Beers of SUNY Buffalo wrote the language-switching code and |
308 | the Modula-2 support, and contributed the Languages chapter of this | |
309 | manual. | |
c2bbbb22 | 310 | |
6f3ec223 RP |
311 | Fred Fish wrote most of the support for Unix System Vr4, and enhanced |
312 | the command-completion support to cover C++ overloaded symbols. | |
14d01801 | 313 | |
4eb4cf57 RP |
314 | _if__(_GENERIC__ || !_H8__) |
315 | @node New Features | |
c7cb8acb | 316 | @unnumbered New Features since GDB version 3.5 |
70b88761 RP |
317 | |
318 | @table @emph | |
319 | @item Targets | |
320 | Using the new command @code{target}, you can select at runtime whether | |
321 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
322 | a serial port, realtime systems over a TCP/IP connection, etc. The |
323 | command @code{load} can download programs into a remote system. Serial | |
b21b18e1 RP |
324 | stubs are available for Motorola 680x0, Intel 80386, and Sparc remote |
325 | systems; GDB also supports debugging realtime processes running under | |
b80282d5 | 326 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a |
b21b18e1 RP |
327 | debugger stub on the target system. Internally, GDB now uses a function |
328 | vector to mediate access to different targets; if you need to add your | |
329 | own support for a remote protocol, this makes it much easier. | |
70b88761 RP |
330 | |
331 | @item Watchpoints | |
c7cb8acb | 332 | GDB now sports watchpoints as well as breakpoints. You can use a |
70b88761 RP |
333 | watchpoint to stop execution whenever the value of an expression |
334 | changes, without having to predict a particular place in your program | |
335 | where this may happen. | |
336 | ||
b80282d5 RP |
337 | @item Wide Output |
338 | Commands that issue wide output now insert newlines at places designed | |
339 | to make the output more readable. | |
340 | ||
70b88761 | 341 | @item Object Code Formats |
c7cb8acb | 342 | GDB uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
343 | Library to permit it to switch dynamically, without reconfiguration or |
344 | recompilation, between different object-file formats. Formats currently | |
345 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
346 | .o's, archive libraries, or core dumps. BFD is available as a | |
347 | subroutine library so that other programs may take advantage of it, and | |
348 | the other GNU binary utilities are being converted to use it. | |
70b88761 | 349 | |
b80282d5 | 350 | @item Configuration and Ports |
70b88761 | 351 | Compile-time configuration (to select a particular architecture and |
7463aadd | 352 | operating system) is much easier. The script @code{configure} now |
c7cb8acb RP |
353 | allows you to configure GDB as either a native debugger or a |
354 | cross-debugger. @xref{Installing GDB}, for details on how to | |
6a8cb0e7 | 355 | configure. |
70b88761 RP |
356 | |
357 | @item Interaction | |
c7cb8acb | 358 | The user interface to GDB's control variables has been simplified |
70b88761 RP |
359 | and consolidated in two commands, @code{set} and @code{show}. Output |
360 | lines are now broken at readable places, rather than overflowing onto | |
361 | the next line. You can suppress output of machine-level addresses, | |
362 | displaying only source language information. | |
363 | ||
b80282d5 | 364 | @item C++ |
c7cb8acb | 365 | GDB now supports C++ multiple inheritance (if used with a GCC |
b80282d5 | 366 | version 2 compiler), and also has limited support for C++ exception |
c7cb8acb | 367 | handling, with the commands @code{catch} and @code{info catch}: GDB |
b80282d5 RP |
368 | can break when an exception is raised, before the stack is peeled back |
369 | to the exception handler's context. | |
70b88761 | 370 | |
c2bbbb22 | 371 | @item Modula-2 |
c7cb8acb | 372 | GDB now has preliminary support for the GNU Modula-2 compiler, |
c2bbbb22 | 373 | currently under development at the State University of New York at |
c7cb8acb | 374 | Buffalo. Coordinated development of both GDB and the GNU Modula-2 |
5b0fdf7b RP |
375 | compiler will continue into 1992. Other Modula-2 compilers are |
376 | currently not supported, and attempting to debug programs compiled with | |
377 | them will likely result in an error as the symbol table of the | |
378 | executable is read in. | |
c2bbbb22 | 379 | |
70b88761 | 380 | @item Command Rationalization |
c7cb8acb | 381 | Many GDB commands have been renamed to make them easier to remember |
70b88761 RP |
382 | and use. In particular, the subcommands of @code{info} and |
383 | @code{show}/@code{set} are grouped to make the former refer to the state | |
c7cb8acb | 384 | of your program, and the latter refer to the state of GDB itself. |
70b88761 RP |
385 | @xref{Renamed Commands}, for details on what commands were renamed. |
386 | ||
70b88761 | 387 | @item Shared Libraries |
77b46d13 JG |
388 | GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000 |
389 | shared libraries. | |
b80282d5 RP |
390 | |
391 | @item Reference Card | |
6f3ec223 RP |
392 | GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting |
393 | the Documentation}, for instructions to print it. | |
70b88761 RP |
394 | |
395 | @item Work in Progress | |
396 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
397 | support. | |
70b88761 | 398 | @end table |
4eb4cf57 | 399 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 400 | |
4eb4cf57 | 401 | @node Sample Session |
70b88761 RP |
402 | @chapter A Sample _GDBN__ Session |
403 | ||
404 | You can use this manual at your leisure to read all about _GDBN__. | |
405 | However, a handful of commands are enough to get started using the | |
406 | debugger. This chapter illustrates these commands. | |
407 | ||
408 | @iftex | |
6ca72cc6 | 409 | In this sample session, we emphasize user input like this: @b{input}, |
70b88761 RP |
410 | to make it easier to pick out from the surrounding output. |
411 | @end iftex | |
412 | ||
413 | @c FIXME: this example may not be appropriate for some configs, where | |
414 | @c FIXME...primary interest is in remote use. | |
415 | _0__ | |
416 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
417 | processor) exhibits the following bug: sometimes, when we change its | |
418 | quote strings from the default, the commands used to capture one macro's | |
419 | definition in another stop working. In the following short @code{m4} | |
420 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
29a2b744 | 421 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
422 | same thing. However, when we change the open quote string to |
423 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
424 | procedure fails to define a new synonym @code{baz}: | |
425 | ||
426 | @smallexample | |
6ca72cc6 RP |
427 | $ @b{cd gnu/m4} |
428 | $ @b{./m4} | |
429 | @b{define(foo,0000)} | |
70b88761 | 430 | |
6ca72cc6 | 431 | @b{foo} |
70b88761 | 432 | 0000 |
6ca72cc6 | 433 | @b{define(bar,defn(`foo'))} |
70b88761 | 434 | |
6ca72cc6 | 435 | @b{bar} |
70b88761 | 436 | 0000 |
6ca72cc6 | 437 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 438 | |
6ca72cc6 RP |
439 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
440 | @b{baz} | |
441 | @b{C-d} | |
70b88761 RP |
442 | m4: End of input: 0: fatal error: EOF in string |
443 | @end smallexample | |
444 | ||
445 | @noindent | |
446 | Let's use _GDBN__ to try to see what's going on. | |
447 | ||
448 | @smallexample | |
6ca72cc6 | 449 | $ @b{_GDBP__ m4} |
203eea5d RP |
450 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
451 | @c FIXME... format to come out better. | |
452 | GDB is free software and you are welcome to distribute copies | |
453 | of it under certain conditions; type "show copying" to see | |
454 | the conditions. | |
455 | There is absolutely no warranty for GDB; type "show warranty" | |
456 | for details. | |
5b0fdf7b | 457 | GDB _GDB_VN__, Copyright 1992 Free Software Foundation, Inc... |
e251e767 | 458 | (_GDBP__) |
70b88761 RP |
459 | @end smallexample |
460 | ||
461 | @noindent | |
1041a570 RP |
462 | _GDBN__ reads only enough symbol data to know where to find the rest when |
463 | needed; as a result, the first prompt comes up very quickly. We now | |
464 | tell _GDBN__ to use a narrower display width than usual, so that examples | |
465 | will fit in this manual. | |
70b88761 RP |
466 | |
467 | @smallexample | |
6ca72cc6 | 468 | (_GDBP__) @b{set width 70} |
70b88761 RP |
469 | @end smallexample |
470 | ||
e251e767 | 471 | @noindent |
29a2b744 | 472 | Let's see how the @code{m4} built-in @code{changequote} works. |
70b88761 RP |
473 | Having looked at the source, we know the relevant subroutine is |
474 | @code{m4_changequote}, so we set a breakpoint there with _GDBN__'s | |
475 | @code{break} command. | |
476 | ||
477 | @smallexample | |
6ca72cc6 | 478 | (_GDBP__) @b{break m4_changequote} |
70b88761 RP |
479 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. |
480 | @end smallexample | |
481 | ||
482 | @noindent | |
483 | Using the @code{run} command, we start @code{m4} running under _GDBN__ | |
484 | control; as long as control does not reach the @code{m4_changequote} | |
485 | subroutine, the program runs as usual: | |
486 | ||
487 | @smallexample | |
6ca72cc6 | 488 | (_GDBP__) @b{run} |
e251e767 | 489 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
6ca72cc6 | 490 | @b{define(foo,0000)} |
70b88761 | 491 | |
6ca72cc6 | 492 | @b{foo} |
70b88761 RP |
493 | 0000 |
494 | @end smallexample | |
495 | ||
496 | @noindent | |
497 | To trigger the breakpoint, we call @code{changequote}. _GDBN__ | |
498 | suspends execution of @code{m4}, displaying information about the | |
499 | context where it stops. | |
500 | ||
501 | @smallexample | |
6ca72cc6 | 502 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 503 | |
203eea5d RP |
504 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
505 | at builtin.c:879 | |
38962738 | 506 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) |
70b88761 RP |
507 | @end smallexample |
508 | ||
509 | @noindent | |
510 | Now we use the command @code{n} (@code{next}) to advance execution to | |
511 | the next line of the current function. | |
512 | ||
513 | @smallexample | |
6ca72cc6 | 514 | (_GDBP__) @b{n} |
203eea5d RP |
515 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
516 | : nil, | |
70b88761 RP |
517 | @end smallexample |
518 | ||
519 | @noindent | |
520 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
521 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
522 | @code{step} goes to the next line to be executed in @emph{any} | |
e251e767 | 523 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
524 | |
525 | @smallexample | |
6ca72cc6 | 526 | (_GDBP__) @b{s} |
70b88761 RP |
527 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
528 | at input.c:530 | |
529 | 530 if (lquote != def_lquote) | |
530 | @end smallexample | |
531 | ||
532 | @noindent | |
29a2b744 RP |
533 | The display that shows the subroutine where @code{m4} is now |
534 | suspended (and its arguments) is called a stack frame display. It | |
535 | shows a summary of the stack. We can use the @code{backtrace} | |
536 | command (which can also be spelled @code{bt}), to see where we are | |
537 | in the stack as a whole: the @code{backtrace} command displays a | |
538 | stack frame for each active subroutine. | |
70b88761 RP |
539 | |
540 | @smallexample | |
6ca72cc6 | 541 | (_GDBP__) @b{bt} |
70b88761 RP |
542 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
543 | at input.c:530 | |
203eea5d RP |
544 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
545 | at builtin.c:882 | |
70b88761 RP |
546 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
547 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
548 | at macro.c:71 | |
549 | #4 0x79dc in expand_input () at macro.c:40 | |
550 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
551 | @end smallexample | |
552 | ||
553 | @noindent | |
554 | Let's step through a few more lines to see what happens. The first two | |
555 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
556 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 557 | |
70b88761 | 558 | @smallexample |
6ca72cc6 | 559 | (_GDBP__) @b{s} |
70b88761 | 560 | 0x3b5c 532 if (rquote != def_rquote) |
6ca72cc6 | 561 | (_GDBP__) @b{s} |
203eea5d RP |
562 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
563 | def_lquote : xstrdup(lq); | |
6ca72cc6 | 564 | (_GDBP__) @b{n} |
203eea5d RP |
565 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
566 | : xstrdup(rq); | |
6ca72cc6 | 567 | (_GDBP__) @b{n} |
70b88761 RP |
568 | 538 len_lquote = strlen(rquote); |
569 | @end smallexample | |
570 | ||
571 | @noindent | |
572 | The last line displayed looks a little odd; let's examine the variables | |
573 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
574 | and right quotes we specified. We can use the command @code{p} | |
575 | (@code{print}) to see their values. | |
576 | ||
577 | @smallexample | |
6ca72cc6 | 578 | (_GDBP__) @b{p lquote} |
70b88761 | 579 | $1 = 0x35d40 "<QUOTE>" |
6ca72cc6 | 580 | (_GDBP__) @b{p rquote} |
70b88761 RP |
581 | $2 = 0x35d50 "<UNQUOTE>" |
582 | @end smallexample | |
583 | ||
584 | @noindent | |
585 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
586 | Let's look at some context; we can display ten lines of source | |
587 | surrounding the current line, with the @code{l} (@code{list}) command. | |
588 | ||
589 | @smallexample | |
6ca72cc6 | 590 | (_GDBP__) @b{l} |
70b88761 | 591 | 533 xfree(rquote); |
e251e767 | 592 | 534 |
203eea5d RP |
593 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
594 | : xstrdup (lq); | |
595 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
596 | : xstrdup (rq); | |
e251e767 | 597 | 537 |
70b88761 RP |
598 | 538 len_lquote = strlen(rquote); |
599 | 539 len_rquote = strlen(lquote); | |
600 | 540 @} | |
e251e767 | 601 | 541 |
70b88761 RP |
602 | 542 void |
603 | @end smallexample | |
604 | ||
605 | @noindent | |
606 | Let's step past the two lines that set @code{len_lquote} and | |
607 | @code{len_rquote}, and then examine the values of those variables. | |
608 | ||
609 | @smallexample | |
6ca72cc6 | 610 | (_GDBP__) @b{n} |
70b88761 | 611 | 539 len_rquote = strlen(lquote); |
6ca72cc6 | 612 | (_GDBP__) @b{n} |
70b88761 | 613 | 540 @} |
6ca72cc6 | 614 | (_GDBP__) @b{p len_lquote} |
70b88761 | 615 | $3 = 9 |
6ca72cc6 | 616 | (_GDBP__) @b{p len_rquote} |
70b88761 RP |
617 | $4 = 7 |
618 | @end smallexample | |
619 | ||
620 | @noindent | |
621 | That certainly looks wrong, assuming @code{len_lquote} and | |
622 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
623 | @code{rquote} respectively. Let's try setting them to better values. | |
624 | We can use the @code{p} command for this, since it'll print the value of | |
625 | any expression---and that expression can include subroutine calls and | |
e251e767 | 626 | assignments. |
70b88761 RP |
627 | |
628 | @smallexample | |
6ca72cc6 | 629 | (_GDBP__) @b{p len_lquote=strlen(lquote)} |
70b88761 | 630 | $5 = 7 |
6ca72cc6 | 631 | (_GDBP__) @b{p len_rquote=strlen(rquote)} |
70b88761 RP |
632 | $6 = 9 |
633 | @end smallexample | |
634 | ||
635 | @noindent | |
636 | Let's see if that fixes the problem of using the new quotes with the | |
637 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
638 | executing with the @code{c} (@code{continue}) command, and then try the | |
639 | example that caused trouble initially: | |
640 | ||
641 | @smallexample | |
6ca72cc6 | 642 | (_GDBP__) @b{c} |
70b88761 RP |
643 | Continuing. |
644 | ||
6ca72cc6 | 645 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
70b88761 RP |
646 | |
647 | baz | |
648 | 0000 | |
649 | @end smallexample | |
650 | ||
651 | @noindent | |
652 | Success! The new quotes now work just as well as the default ones. The | |
653 | problem seems to have been just the two typos defining the wrong | |
654 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
655 | ||
656 | @smallexample | |
6ca72cc6 | 657 | @b{C-d} |
70b88761 RP |
658 | Program exited normally. |
659 | @end smallexample | |
660 | ||
e251e767 | 661 | @noindent |
70b88761 RP |
662 | The message @samp{Program exited normally.} is from _GDBN__; it |
663 | indicates @code{m4} has finished executing. We can end our _GDBN__ | |
664 | session with the _GDBN__ @code{quit} command. | |
665 | ||
666 | @smallexample | |
6ca72cc6 | 667 | (_GDBP__) @b{quit} |
70b88761 RP |
668 | _1__@end smallexample |
669 | ||
4eb4cf57 | 670 | @node Invocation |
70b88761 RP |
671 | @chapter Getting In and Out of _GDBN__ |
672 | ||
c7cb8acb RP |
673 | This chapter discusses how to start _GDBN__, and how to get out of it. |
674 | (The essentials: type @samp{_GDBP__} to start GDB, and type @kbd{quit} | |
675 | or @kbd{C-d} to exit.) | |
29a2b744 | 676 | |
70b88761 | 677 | @menu |
29a2b744 | 678 | * Invoking _GDBN__:: Starting _GDBN__ |
c2bbbb22 | 679 | * Leaving _GDBN__:: Leaving _GDBN__ |
4eb4cf57 | 680 | _if__(!_BARE__) |
b80282d5 | 681 | * Shell Commands:: Shell Commands |
4eb4cf57 | 682 | _fi__(!_BARE__) |
70b88761 RP |
683 | @end menu |
684 | ||
4eb4cf57 | 685 | @node Invoking _GDBN__ |
70b88761 RP |
686 | @section Starting _GDBN__ |
687 | ||
4eb4cf57 RP |
688 | _if__(_H8__) |
689 | For details on starting up _GDBP__ as a | |
690 | remote debugger attached to a Hitachi H8/300 board, see @ref{Hitachi | |
691 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}. | |
692 | _fi__(_H8__) | |
693 | ||
694 | Start _GDBN__ by running the program @code{_GDBP__}. Once it's running, | |
1041a570 | 695 | _GDBN__ reads commands from the terminal until you tell it to exit. |
70b88761 | 696 | |
c7cb8acb RP |
697 | You can also run @code{_GDBP__} with a variety of arguments and options, |
698 | to specify more of your debugging environment at the outset. | |
699 | ||
0005054f | 700 | _if__(_GENERIC__) |
c7cb8acb RP |
701 | The command-line options described here are designed |
702 | to cover a variety of situations; in some environments, some of these | |
703 | options may effectively be unavailable. | |
0005054f | 704 | _fi__(_GENERIC__) |
c7cb8acb | 705 | |
4eb4cf57 RP |
706 | The most usual way to start _GDBN__ is with one argument, |
707 | specifying an executable program: | |
1041a570 | 708 | |
70b88761 | 709 | @example |
29a2b744 | 710 | _GDBP__ @var{program} |
70b88761 | 711 | @end example |
1041a570 | 712 | |
4eb4cf57 | 713 | _if__(!_BARE__) |
70b88761 | 714 | @noindent |
29a2b744 RP |
715 | You can also start with both an executable program and a core file |
716 | specified: | |
1041a570 | 717 | |
70b88761 | 718 | @example |
29a2b744 | 719 | _GDBP__ @var{program} @var{core} |
70b88761 RP |
720 | @end example |
721 | ||
b80282d5 RP |
722 | You can, instead, specify a process ID as a second argument, if you want |
723 | to debug a running process: | |
1041a570 | 724 | |
b80282d5 | 725 | @example |
29a2b744 | 726 | _GDBP__ @var{program} 1234 |
b80282d5 | 727 | @end example |
1041a570 | 728 | |
b80282d5 RP |
729 | @noindent |
730 | would attach _GDBN__ to process @code{1234} (unless you also have a file | |
731 | named @file{1234}; _GDBN__ does check for a core file first). | |
732 | ||
c7cb8acb RP |
733 | Taking advantage of the second command-line argument requires a fairly |
734 | complete operating system; when you use _GDBN__ as a remote debugger | |
735 | attached to a bare board, there may not be any notion of ``process'', | |
736 | and there is often no way to get a core dump. | |
4eb4cf57 | 737 | _fi__(!_BARE__) |
c7cb8acb | 738 | |
70b88761 RP |
739 | @noindent |
740 | You can further control how _GDBN__ starts up by using command-line | |
29a2b744 RP |
741 | options. _GDBN__ itself can remind you of the options available. |
742 | ||
743 | @noindent | |
744 | Type | |
745 | ||
70b88761 RP |
746 | @example |
747 | _GDBP__ -help | |
748 | @end example | |
29a2b744 | 749 | |
70b88761 | 750 | @noindent |
29a2b744 | 751 | to display all available options and briefly describe their use |
70b88761 RP |
752 | (@samp{_GDBP__ -h} is a shorter equivalent). |
753 | ||
754 | All options and command line arguments you give are processed | |
755 | in sequential order. The order makes a difference when the | |
e251e767 | 756 | @samp{-x} option is used. |
70b88761 RP |
757 | |
758 | @menu | |
70b88761 RP |
759 | _if__(!_GENERIC__) |
760 | _include__(gdbinv-m.m4)_dnl__ | |
761 | _fi__(!_GENERIC__) | |
4eb4cf57 RP |
762 | * File Options:: Choosing Files |
763 | * Mode Options:: Choosing Modes | |
70b88761 RP |
764 | @end menu |
765 | ||
4eb4cf57 RP |
766 | _if__(!_GENERIC__) |
767 | _include__(gdbinv-s.m4) | |
768 | _fi__(!_GENERIC__) | |
769 | ||
770 | @node File Options | |
70b88761 RP |
771 | @subsection Choosing Files |
772 | ||
4eb4cf57 | 773 | _if__(!_BARE__) |
29a2b744 RP |
774 | When _GDBN__ starts, it reads any arguments other than options as |
775 | specifying an executable file and core file (or process ID). This is | |
776 | the same as if the arguments were specified by the @samp{-se} and | |
777 | @samp{-c} options respectively. (_GDBN__ reads the first argument | |
778 | that does not have an associated option flag as equivalent to the | |
779 | @samp{-se} option followed by that argument; and the second argument | |
780 | that does not have an associated option flag, if any, as equivalent to | |
781 | the @samp{-c} option followed by that argument.) | |
4eb4cf57 RP |
782 | _fi__(!_BARE__) |
783 | _if__(_BARE__) | |
784 | When _GDBN__ starts, it reads any argument other than options as | |
785 | specifying an executable file. This is the same as if the argument was | |
786 | specified by the @samp{-se} option. | |
787 | _fi__(_BARE__) | |
29a2b744 RP |
788 | |
789 | Many options have both long and short forms; both are shown in the | |
790 | following list. _GDBN__ also recognizes the long forms if you truncate | |
791 | them, so long as enough of the option is present to be unambiguous. | |
792 | (If you prefer, you can flag option arguments with @samp{--} rather | |
793 | than @samp{-}, though we illustrate the more usual convention.) | |
70b88761 RP |
794 | |
795 | @table @code | |
796 | @item -symbols=@var{file} | |
797 | @itemx -s @var{file} | |
798 | Read symbol table from file @var{file}. | |
799 | ||
800 | @item -exec=@var{file} | |
801 | @itemx -e @var{file} | |
802 | Use file @var{file} as the executable file to execute when | |
803 | appropriate, and for examining pure data in conjunction with a core | |
804 | dump. | |
805 | ||
3d3ab540 | 806 | @item -se=@var{file} |
70b88761 RP |
807 | Read symbol table from file @var{file} and use it as the executable |
808 | file. | |
809 | ||
4eb4cf57 | 810 | _if__(!_BARE__) |
70b88761 RP |
811 | @item -core=@var{file} |
812 | @itemx -c @var{file} | |
813 | Use file @var{file} as a core dump to examine. | |
4eb4cf57 | 814 | _fi__(!_BARE__) |
70b88761 RP |
815 | |
816 | @item -command=@var{file} | |
817 | @itemx -x @var{file} | |
818 | Execute _GDBN__ commands from file @var{file}. @xref{Command Files}. | |
819 | ||
820 | @item -directory=@var{directory} | |
821 | @itemx -d @var{directory} | |
822 | Add @var{directory} to the path to search for source files. | |
14d01801 | 823 | |
4eb4cf57 | 824 | _if__(!_BARE__) |
14d01801 RP |
825 | @item -m |
826 | @itemx -mapped | |
827 | @emph{Warning: this option depends on operating system facilities that are not | |
828 | supported on all systems.}@* | |
77b46d13 JG |
829 | If memory-mapped files are available on your system through the @code{mmap} |
830 | system call, you can use this option | |
5a2c1d85 | 831 | to have _GDBN__ write the symbols from your |
77b46d13 JG |
832 | program into a reusable file in the current directory. If the program you are debugging is |
833 | called @file{/tmp/fred}, the mapped symbol file will be @file{./fred.syms}. | |
834 | Future _GDBN__ debugging sessions will notice the presence of this file, | |
835 | and will quickly map in symbol information from it, rather than reading | |
836 | the symbol table from the executable program. | |
837 | ||
838 | The @file{.syms} file is specific to the host machine on which _GDBN__ is run. | |
839 | It holds an exact image of _GDBN__'s internal symbol table. It cannot be | |
840 | shared across multiple host platforms. | |
4eb4cf57 | 841 | _fi__(!_BARE__) |
77b46d13 JG |
842 | |
843 | @item -r | |
844 | @itemx -readnow | |
845 | Read each symbol file's entire symbol table immediately, rather than | |
846 | the default, which is to read it incrementally as it is needed. | |
847 | This makes startup slower, but makes future operations faster. | |
70b88761 RP |
848 | @end table |
849 | ||
4eb4cf57 | 850 | _if__(!_BARE__) |
77b46d13 JG |
851 | The @code{-mapped} and @code{-readnow} options are typically combined in order to |
852 | build a @file{.syms} file that contains complete symbol information. | |
853 | A simple GDB invocation to do nothing but build a @file{.syms} file for future | |
854 | use is: | |
855 | ||
856 | @example | |
857 | gdb -batch -nx -mapped -readnow programname | |
858 | @end example | |
4eb4cf57 | 859 | _fi__(!_BARE__) |
77b46d13 | 860 | |
4eb4cf57 | 861 | @node Mode Options |
1041a570 RP |
862 | @subsection Choosing Modes |
863 | ||
29a2b744 RP |
864 | You can run _GDBN__ in various alternative modes---for example, in |
865 | batch mode or quiet mode. | |
70b88761 RP |
866 | |
867 | @table @code | |
868 | @item -nx | |
869 | @itemx -n | |
870 | Do not execute commands from any @file{_GDBINIT__} initialization files. | |
871 | Normally, the commands in these files are executed after all the | |
e251e767 | 872 | command options and arguments have been processed. |
c728f1f0 | 873 | @xref{Command Files}. |
70b88761 RP |
874 | |
875 | @item -quiet | |
876 | @itemx -q | |
877 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 878 | messages are also suppressed in batch mode. |
70b88761 RP |
879 | |
880 | @item -batch | |
881 | Run in batch mode. Exit with status @code{0} after processing all the command | |
882 | files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited). | |
883 | Exit with nonzero status if an error occurs in executing the _GDBN__ | |
e251e767 | 884 | commands in the command files. |
70b88761 RP |
885 | |
886 | Batch mode may be useful for running _GDBN__ as a filter, for example to | |
887 | download and run a program on another computer; in order to make this | |
e251e767 | 888 | more useful, the message |
1041a570 | 889 | |
70b88761 RP |
890 | @example |
891 | Program exited normally. | |
892 | @end example | |
1041a570 | 893 | |
70b88761 RP |
894 | @noindent |
895 | (which is ordinarily issued whenever a program running under _GDBN__ control | |
896 | terminates) is not issued when running in batch mode. | |
897 | ||
3d3ab540 | 898 | @item -cd=@var{directory} |
70b88761 RP |
899 | Run _GDBN__ using @var{directory} as its working directory, |
900 | instead of the current directory. | |
901 | ||
6ca72cc6 | 902 | _if__(_LUCID__) |
45c53080 | 903 | @item -context @var{authentication} |
6ca72cc6 RP |
904 | When the Energize programming system starts up _GDBN__, it uses this |
905 | option to trigger an alternate mode of interaction. | |
906 | @var{authentication} is a pair of numeric codes that identify _GDBN__ | |
907 | as a client in the Energize environment. Avoid this option when you run | |
908 | _GDBN__ directly from the command line. See @ref{Energize,,Using | |
909 | _GDBN__ with Energize} for more discussion of using _GDBN__ with Energize. | |
910 | _fi__(_LUCID__) | |
911 | ||
70b88761 RP |
912 | @item -fullname |
913 | @itemx -f | |
914 | Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ | |
915 | to output the full file name and line number in a standard, | |
916 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 917 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
918 | like two @samp{\032} characters, followed by the file name, line number |
919 | and character position separated by colons, and a newline. The | |
920 | Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as | |
921 | a signal to display the source code for the frame. | |
922 | ||
4eb4cf57 | 923 | _if__(_GENERIC__ || !_H8__) |
70b88761 RP |
924 | @item -b @var{bps} |
925 | Set the line speed (baud rate or bits per second) of any serial | |
926 | interface used by _GDBN__ for remote debugging. | |
927 | ||
3d3ab540 | 928 | @item -tty=@var{device} |
70b88761 | 929 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 930 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
4eb4cf57 | 931 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
932 | @end table |
933 | ||
4eb4cf57 | 934 | @node Leaving _GDBN__ |
70b88761 RP |
935 | @section Leaving _GDBN__ |
936 | @cindex exiting _GDBN__ | |
1041a570 | 937 | |
70b88761 RP |
938 | @table @code |
939 | @item quit | |
940 | @kindex quit | |
941 | @kindex q | |
942 | To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type | |
e251e767 | 943 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
944 | @end table |
945 | ||
946 | @cindex interrupt | |
947 | An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather | |
948 | will terminate the action of any _GDBN__ command that is in progress and | |
949 | return to _GDBN__ command level. It is safe to type the interrupt | |
950 | character at any time because _GDBN__ does not allow it to take effect | |
951 | until a time when it is safe. | |
952 | ||
4eb4cf57 | 953 | _if__(!_BARE__) |
1041a570 RP |
954 | If you have been using _GDBN__ to control an attached process or device, you |
955 | can release it with the @code{detach} command; @pxref{Attach, | |
956 | ,Debugging an Already-Running Process}.. | |
4eb4cf57 | 957 | _fi__(!_BARE__) |
70b88761 | 958 | |
4eb4cf57 RP |
959 | _if__(!_BARE__) |
960 | @node Shell Commands | |
70b88761 | 961 | @section Shell Commands |
1041a570 | 962 | |
70b88761 | 963 | If you need to execute occasional shell commands during your |
29a2b744 | 964 | debugging session, there is no need to leave or suspend _GDBN__; you can |
70b88761 RP |
965 | just use the @code{shell} command. |
966 | ||
967 | @table @code | |
968 | @item shell @var{command string} | |
969 | @kindex shell | |
970 | @cindex shell escape | |
971 | Directs _GDBN__ to invoke an inferior shell to execute @var{command | |
972 | string}. If it exists, the environment variable @code{SHELL} is used | |
973 | for the name of the shell to run. Otherwise _GDBN__ uses | |
974 | @code{/bin/sh}. | |
975 | @end table | |
976 | ||
977 | The utility @code{make} is often needed in development environments. | |
29a2b744 | 978 | You do not have to use the @code{shell} command for this purpose in _GDBN__: |
70b88761 RP |
979 | |
980 | @table @code | |
981 | @item make @var{make-args} | |
982 | @kindex make | |
983 | @cindex calling make | |
984 | Causes _GDBN__ to execute an inferior @code{make} program with the specified | |
985 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
986 | @end table | |
4eb4cf57 | 987 | _fi__(!_BARE__) |
70b88761 | 988 | |
4eb4cf57 | 989 | @node Commands |
70b88761 RP |
990 | @chapter _GDBN__ Commands |
991 | ||
6f3ec223 RP |
992 | You can abbreviate a _GDBN__ command to the first few letters of the command |
993 | name, if that abbreviation is unambiguous; and you can repeat certain | |
84c2fcad | 994 | _GDBN__ commands by typing just @key{RET}. You can also use the @key{TAB} |
6f3ec223 RP |
995 | key to get _GDBN__ to fill out the rest of a word in a command (or to |
996 | show you the alternatives available, if there's more than one possibility). | |
29a2b744 | 997 | |
70b88761 | 998 | @menu |
b80282d5 | 999 | * Command Syntax:: Command Syntax |
6f3ec223 | 1000 | * Completion:: Command Completion |
b80282d5 | 1001 | * Help:: Getting Help |
70b88761 RP |
1002 | @end menu |
1003 | ||
4eb4cf57 | 1004 | @node Command Syntax |
70b88761 | 1005 | @section Command Syntax |
1041a570 | 1006 | |
70b88761 RP |
1007 | A _GDBN__ command is a single line of input. There is no limit on how long |
1008 | it can be. It starts with a command name, which is followed by arguments | |
1009 | whose meaning depends on the command name. For example, the command | |
1010 | @code{step} accepts an argument which is the number of times to step, | |
1011 | as in @samp{step 5}. You can also use the @code{step} command with | |
1012 | no arguments. Some command names do not allow any arguments. | |
1013 | ||
1014 | @cindex abbreviation | |
1015 | _GDBN__ command names may always be truncated if that abbreviation is | |
1016 | unambiguous. Other possible command abbreviations are listed in the | |
1017 | documentation for individual commands. In some cases, even ambiguous | |
1018 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1019 | equivalent to @code{step} even though there are other commands whose | |
1020 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1021 | arguments to the @code{help} command. |
70b88761 | 1022 | |
e251e767 | 1023 | @cindex repeating commands |
70b88761 RP |
1024 | @kindex RET |
1025 | A blank line as input to _GDBN__ (typing just @key{RET}) means to | |
1026 | repeat the previous command. Certain commands (for example, @code{run}) | |
1027 | will not repeat this way; these are commands for which unintentional | |
1028 | repetition might cause trouble and which you are unlikely to want to | |
1029 | repeat. | |
1030 | ||
1031 | The @code{list} and @code{x} commands, when you repeat them with | |
1032 | @key{RET}, construct new arguments rather than repeating | |
1033 | exactly as typed. This permits easy scanning of source or memory. | |
1034 | ||
b80282d5 RP |
1035 | _GDBN__ can also use @key{RET} in another way: to partition lengthy |
1036 | output, in a way similar to the common utility @code{more} | |
29a2b744 | 1037 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many |
b80282d5 RP |
1038 | in this situation, _GDBN__ disables command repetition after any command |
1039 | that generates this sort of display. | |
1040 | ||
70b88761 RP |
1041 | @kindex # |
1042 | @cindex comment | |
1043 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
29a2b744 | 1044 | This is useful mainly in command files (@pxref{Command Files}). |
70b88761 | 1045 | |
4eb4cf57 | 1046 | @node Completion |
6f3ec223 RP |
1047 | @section Command Completion |
1048 | ||
1049 | @cindex completion | |
1050 | @cindex word completion | |
1051 | _GDBN__ can fill in the rest of a word in a command for you, if there's | |
1052 | only one possibility; it can also show you what the valid possibilities | |
1053 | are for the next word in a command, at any time. This works for _GDBN__ | |
1054 | commands, _GDBN__ subcommands, and the names of symbols in your program. | |
1055 | ||
1056 | Press the @key{TAB} key whenever you want _GDBN__ to fill out the rest | |
1057 | of a word. If there's only one possibility, _GDBN__ will fill in the | |
1058 | word, and wait for you to finish the command (or press @key{RET} to | |
1059 | enter it). For example, if you type | |
1060 | ||
0fdc6e27 RP |
1061 | @c FIXME "@key" doesn't distinguish its argument sufficiently to permit |
1062 | @c complete accuracy in these examples; space introduced for clarity. | |
1063 | @c If texinfo enhancements make it unnecessary, it would be nice to | |
1064 | @c replace " @key" by "@key" in the following... | |
6f3ec223 | 1065 | @example |
0fdc6e27 | 1066 | (_GDBP__) info bre @key{TAB} |
6f3ec223 RP |
1067 | @end example |
1068 | ||
1069 | @noindent | |
1070 | _GDBN__ fills in the rest of the word @samp{breakpoints}, since that's | |
1071 | the only @code{info} subcommand beginning with @samp{bre}: | |
1072 | ||
1073 | @example | |
1074 | (_GDBP__) info breakpoints | |
1075 | @end example | |
1076 | ||
1077 | @noindent | |
1078 | You can either press @key{RET} at this point, to run the @code{info | |
1079 | breakpoints} command, or backspace and enter something else, if | |
1080 | @samp{breakpoints} doesn't look like the command you expected. (If you | |
1081 | were sure you wanted @code{info breakpoints} in the first place, you | |
1082 | might as well just type @key{RET} immediately after @samp{info bre}, | |
1083 | to exploit command abbreviations rather than command completion). | |
1084 | ||
1085 | If there is more than one possibility for the next word when you press | |
1086 | @key{TAB}, _GDBN__ will sound a bell. You can either supply more | |
1087 | characters and try again, or just press @key{TAB} a second time, and | |
1088 | _GDBN__ will display all the possible completions for that word. For | |
1089 | example, you might want to set a breakpoint on a subroutine whose name | |
b1385986 | 1090 | begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} _GDBN__ |
6f3ec223 RP |
1091 | just sounds the bell. Typing @key{TAB} again will display all the |
1092 | function names in your program that begin with those characters, for | |
1093 | example: | |
1094 | ||
1095 | @example | |
0fdc6e27 | 1096 | (_GDBP__) b make_ @key{TAB} |
b1385986 | 1097 | @exdent _GDBN__ sounds bell; press @key{TAB} again, to see: |
6f3ec223 RP |
1098 | make_a_section_from_file make_environ |
1099 | make_abs_section make_function_type | |
1100 | make_blockvector make_pointer_type | |
1101 | make_cleanup make_reference_type | |
1102 | make_command make_symbol_completion_list | |
b1385986 | 1103 | (GDBP__) b make_ |
6f3ec223 RP |
1104 | @end example |
1105 | ||
1106 | @noindent | |
1107 | After displaying the available possibilities, _GDBN__ copies your | |
b1385986 | 1108 | partial input (@samp{b make_} in the example) so you can finish the |
6f3ec223 RP |
1109 | command. |
1110 | ||
1111 | If you just want to see the list of alternatives in the first place, you | |
b1385986 RP |
1112 | can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?} |
1113 | means @kbd{@key{META} ?}. You can type this either by holding down a | |
1114 | key designated as the @key{META} shift on your keyboard (if there is | |
1115 | one) while typing @kbd{?}, or by typing @key{ESC} followed by @kbd{?}. | |
6f3ec223 RP |
1116 | |
1117 | @cindex quotes in commands | |
1118 | @cindex completion of quoted strings | |
1119 | Sometimes the string you need, while logically a ``word'', may contain | |
1120 | parentheses or other characters that _GDBN__ normally excludes from its | |
1121 | notion of a word. To permit word completion to work in this situation, | |
1122 | you may enclose words in @code{'} (single quote marks) in _GDBN__ commands. | |
1123 | ||
1124 | The most likely situation where you might need this is in typing the | |
1125 | name of a C++ function. This is because C++ allows function overloading | |
1126 | (multiple definitions of the same function, distinguished by argument | |
b1385986 RP |
1127 | type). For example, when you want to set a breakpoint you may need to |
1128 | distinguish whether you mean the version of @code{name} that takes an | |
1129 | @code{int} parameter, @code{name(int)}, or the version that takes a | |
1130 | @code{float} parameter, @code{name(float)}. To use the word-completion | |
1131 | facilities in this situation, type a single quote @code{'} at the | |
1132 | beginning of the function name. This alerts _GDBN__ that it may need to | |
1133 | consider more information than usual when you press @key{TAB} or | |
1134 | @kbd{M-?} to request word completion: | |
6f3ec223 RP |
1135 | |
1136 | @example | |
0fdc6e27 RP |
1137 | (_GDBP__) b 'bubble( @key{M-?} |
1138 | bubble(double,double) bubble(int,int) | |
1139 | (_GDBP__) b 'bubble( | |
6f3ec223 RP |
1140 | @end example |
1141 | ||
0fdc6e27 RP |
1142 | In some cases, _GDBN__ can tell that completing a name will require |
1143 | quotes. When this happens, _GDBN__ will insert the quote for you (while | |
1144 | completing as much as it can) if you do not type the quote in the first | |
1145 | place: | |
1146 | ||
1147 | @example | |
1148 | (_GDBP__) b bub @key{TAB} | |
1149 | @exdent _GDBN__ alters your input line to the following, and rings a bell: | |
1150 | (_GDBP__) b 'bubble( | |
1151 | @end example | |
1152 | ||
1153 | @noindent | |
1154 | In general, _GDBN__ can tell that a quote is needed (and inserts it) if | |
1155 | you have not yet started typing the argument list when you ask for | |
1156 | completion on an overloaded symbol. | |
1157 | ||
1158 | ||
4eb4cf57 | 1159 | @node Help |
70b88761 RP |
1160 | @section Getting Help |
1161 | @cindex online documentation | |
1162 | @kindex help | |
1041a570 | 1163 | |
70b88761 | 1164 | You can always ask _GDBN__ itself for information on its commands, using the |
e251e767 | 1165 | command @code{help}. |
70b88761 RP |
1166 | |
1167 | @table @code | |
1168 | @item help | |
1169 | @itemx h | |
1170 | @kindex h | |
1171 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1172 | display a short list of named classes of commands: | |
1041a570 | 1173 | |
70b88761 RP |
1174 | @smallexample |
1175 | (_GDBP__) help | |
1176 | List of classes of commands: | |
1177 | ||
1178 | running -- Running the program | |
1179 | stack -- Examining the stack | |
1180 | data -- Examining data | |
1181 | breakpoints -- Making program stop at certain points | |
1182 | files -- Specifying and examining files | |
1183 | status -- Status inquiries | |
1184 | support -- Support facilities | |
1185 | user-defined -- User-defined commands | |
1186 | aliases -- Aliases of other commands | |
1187 | obscure -- Obscure features | |
1188 | ||
203eea5d RP |
1189 | Type "help" followed by a class name for a list of |
1190 | commands in that class. | |
1191 | Type "help" followed by command name for full | |
1192 | documentation. | |
70b88761 | 1193 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1194 | (_GDBP__) |
70b88761 RP |
1195 | @end smallexample |
1196 | ||
1197 | @item help @var{class} | |
1198 | Using one of the general help classes as an argument, you can get a | |
1199 | list of the individual commands in that class. For example, here is the | |
1200 | help display for the class @code{status}: | |
1041a570 | 1201 | |
70b88761 RP |
1202 | @smallexample |
1203 | (_GDBP__) help status | |
1204 | Status inquiries. | |
1205 | ||
1206 | List of commands: | |
1207 | ||
1208 | show -- Generic command for showing things set with "set" | |
1209 | info -- Generic command for printing status | |
1210 | ||
203eea5d RP |
1211 | Type "help" followed by command name for full |
1212 | documentation. | |
70b88761 | 1213 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1214 | (_GDBP__) |
70b88761 RP |
1215 | @end smallexample |
1216 | ||
1217 | @item help @var{command} | |
1218 | With a command name as @code{help} argument, _GDBN__ will display a | |
e251e767 | 1219 | short paragraph on how to use that command. |
70b88761 RP |
1220 | @end table |
1221 | ||
1222 | In addition to @code{help}, you can use the _GDBN__ commands @code{info} | |
1223 | and @code{show} to inquire about the state of your program, or the state | |
1224 | of _GDBN__ itself. Each command supports many topics of inquiry; this | |
1225 | manual introduces each of them in the appropriate context. The listings | |
1226 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1227 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1228 | |
1229 | @c @group | |
1230 | @table @code | |
1231 | @item info | |
1232 | @kindex info | |
1233 | @kindex i | |
1234 | This command (abbreviated @code{i}) is for describing the state of your | |
1235 | program; for example, it can list the arguments given to your program | |
1236 | (@code{info args}), the registers currently in use (@code{info | |
1041a570 | 1237 | registers}), or the breakpoints you have set (@code{info breakpoints}). |
70b88761 RP |
1238 | You can get a complete list of the @code{info} sub-commands with |
1239 | @w{@code{help info}}. | |
1240 | ||
1241 | @kindex show | |
1242 | @item show | |
1243 | In contrast, @code{show} is for describing the state of _GDBN__ itself. | |
1244 | You can change most of the things you can @code{show}, by using the | |
1245 | related command @code{set}; for example, you can control what number | |
1246 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1247 | which is currently in use with @code{show radix}. |
70b88761 RP |
1248 | |
1249 | @kindex info set | |
1250 | To display all the settable parameters and their current | |
1251 | values, you can use @code{show} with no arguments; you may also use | |
1252 | @code{info set}. Both commands produce the same display. | |
1253 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1254 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1255 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1256 | @end table | |
1257 | @c @end group | |
1258 | ||
1259 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1260 | exceptional in lacking corresponding @code{set} commands: | |
1261 | ||
1262 | @table @code | |
1263 | @kindex show version | |
3d3ab540 | 1264 | @cindex version number |
70b88761 RP |
1265 | @item show version |
1266 | Show what version of _GDBN__ is running. You should include this | |
1041a570 RP |
1267 | information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are in |
1268 | use at your site, you may occasionally want to make sure what version | |
1269 | of _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced, | |
1270 | and old ones may wither away. The version number is also announced | |
1271 | when you start _GDBN__ with no arguments. | |
70b88761 RP |
1272 | |
1273 | @kindex show copying | |
1274 | @item show copying | |
1275 | Display information about permission for copying _GDBN__. | |
1276 | ||
1277 | @kindex show warranty | |
1278 | @item show warranty | |
1279 | Display the GNU ``NO WARRANTY'' statement. | |
1280 | @end table | |
1281 | ||
4eb4cf57 | 1282 | @node Running |
70b88761 RP |
1283 | @chapter Running Programs Under _GDBN__ |
1284 | ||
1041a570 RP |
1285 | To debug a program, you must run it under _GDBN__. |
1286 | ||
70b88761 | 1287 | @menu |
b80282d5 RP |
1288 | * Compilation:: Compiling for Debugging |
1289 | * Starting:: Starting your Program | |
4eb4cf57 | 1290 | _if__(!_BARE__) |
b80282d5 RP |
1291 | * Arguments:: Your Program's Arguments |
1292 | * Environment:: Your Program's Environment | |
1293 | * Working Directory:: Your Program's Working Directory | |
1294 | * Input/Output:: Your Program's Input and Output | |
1295 | * Attach:: Debugging an Already-Running Process | |
1296 | * Kill Process:: Killing the Child Process | |
d24e0922 | 1297 | * Process Information:: Additional Process Information |
4eb4cf57 | 1298 | _fi__(!_BARE__) |
70b88761 RP |
1299 | @end menu |
1300 | ||
4eb4cf57 | 1301 | @node Compilation |
70b88761 RP |
1302 | @section Compiling for Debugging |
1303 | ||
1304 | In order to debug a program effectively, you need to generate | |
1305 | debugging information when you compile it. This debugging information | |
1306 | is stored in the object file; it describes the data type of each | |
1307 | variable or function and the correspondence between source line numbers | |
1308 | and addresses in the executable code. | |
1309 | ||
1310 | To request debugging information, specify the @samp{-g} option when you run | |
1311 | the compiler. | |
1312 | ||
1313 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1314 | options together. Using those compilers, you cannot generate optimized | |
1315 | executables containing debugging information. | |
1316 | ||
c7cb8acb RP |
1317 | _GCC__, the GNU C compiler, supports @samp{-g} with or without |
1318 | @samp{-O}, making it possible to debug optimized code. We recommend | |
1319 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1320 | You may think your program is correct, but there is no sense in pushing | |
1321 | your luck. | |
70b88761 | 1322 | |
6ca72cc6 RP |
1323 | @cindex optimized code, debugging |
1324 | @cindex debugging optimized code | |
1325 | When you debug a program compiled with @samp{-g -O}, remember that the | |
1326 | optimizer is rearranging your code; the debugger will show you what's | |
1327 | really there. Don't be too surprised when the execution path doesn't | |
1328 | exactly match your source file! An extreme example: if you define a | |
1329 | variable, but never use it, _GDBN__ will never see that | |
1330 | variable---because the compiler optimizes it out of existence. | |
1331 | ||
70b88761 RP |
1332 | Some things do not work as well with @samp{-g -O} as with just |
1333 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1334 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1335 | please report it as a bug (including a test case!). | |
1336 | ||
1337 | Older versions of the GNU C compiler permitted a variant option | |
c7cb8acb | 1338 | @w{@samp{-gg}} for debugging information. _GDBN__ no longer supports this |
70b88761 RP |
1339 | format; if your GNU C compiler has this option, do not use it. |
1340 | ||
1341 | @ignore | |
1342 | @comment As far as I know, there are no cases in which _GDBN__ will | |
1343 | @comment produce strange output in this case. (but no promises). | |
1344 | If your program includes archives made with the @code{ar} program, and | |
1345 | if the object files used as input to @code{ar} were compiled without the | |
1346 | @samp{-g} option and have names longer than 15 characters, _GDBN__ will get | |
29a2b744 | 1347 | confused reading your program's symbol table. No error message will be |
70b88761 RP |
1348 | given, but _GDBN__ may behave strangely. The reason for this problem is a |
1349 | deficiency in the Unix archive file format, which cannot represent file | |
1350 | names longer than 15 characters. | |
1351 | ||
1352 | To avoid this problem, compile the archive members with the @samp{-g} | |
1353 | option or use shorter file names. Alternatively, use a version of GNU | |
1354 | @code{ar} dated more recently than August 1989. | |
1355 | @end ignore | |
1356 | ||
4eb4cf57 | 1357 | @node Starting |
70b88761 RP |
1358 | @section Starting your Program |
1359 | @cindex starting | |
1360 | @cindex running | |
1041a570 | 1361 | |
70b88761 RP |
1362 | @table @code |
1363 | @item run | |
1364 | @itemx r | |
1365 | @kindex run | |
1041a570 RP |
1366 | Use the @code{run} command to start your program under _GDBN__. You must |
1367 | first specify the program name | |
e251e767 | 1368 | _if__(_VXWORKS__) |
7463aadd | 1369 | (except on VxWorks) |
70b88761 | 1370 | _fi__(_VXWORKS__) |
1041a570 RP |
1371 | with an argument to |
1372 | _GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the | |
1373 | @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to | |
1374 | Specify Files}). | |
1375 | ||
70b88761 RP |
1376 | @end table |
1377 | ||
4eb4cf57 | 1378 | _if__(!_BARE__) |
29a2b744 RP |
1379 | If you are running your program in an execution environment that |
1380 | supports processes, @code{run} creates an inferior process and makes | |
1381 | that process run your program. (In environments without processes, | |
1382 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
1383 | |
1384 | The execution of a program is affected by certain information it | |
1385 | receives from its superior. _GDBN__ provides ways to specify this | |
6ca72cc6 | 1386 | information, which you must do @emph{before} starting your program. (You |
29a2b744 RP |
1387 | can change it after starting your program, but such changes will only affect |
1388 | your program the next time you start it.) This information may be | |
70b88761 RP |
1389 | divided into four categories: |
1390 | ||
1391 | @table @asis | |
6ca72cc6 | 1392 | @item The @emph{arguments.} |
29a2b744 | 1393 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
1394 | @code{run} command. If a shell is available on your target, the shell |
1395 | is used to pass the arguments, so that you may use normal conventions | |
1396 | (such as wildcard expansion or variable substitution) in describing | |
1397 | the arguments. In Unix systems, you can control which shell is used | |
1398 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
1399 | Program's Arguments}. | |
70b88761 | 1400 | |
6ca72cc6 | 1401 | @item The @emph{environment.} |
70b88761 RP |
1402 | Your program normally inherits its environment from _GDBN__, but you can |
1403 | use the _GDBN__ commands @code{set environment} and @code{unset | |
1404 | environment} to change parts of the environment that will be given to | |
1041a570 | 1405 | your program. @xref{Environment, ,Your Program's Environment}. |
70b88761 | 1406 | |
6ca72cc6 | 1407 | @item The @emph{working directory.} |
70b88761 RP |
1408 | Your program inherits its working directory from _GDBN__. You can set |
1409 | _GDBN__'s working directory with the @code{cd} command in _GDBN__. | |
29a2b744 | 1410 | @xref{Working Directory, ,Your Program's Working Directory}. |
70b88761 | 1411 | |
6ca72cc6 | 1412 | @item The @emph{standard input and output.} |
70b88761 RP |
1413 | Your program normally uses the same device for standard input and |
1414 | standard output as _GDBN__ is using. You can redirect input and output | |
1415 | in the @code{run} command line, or you can use the @code{tty} command to | |
1416 | set a different device for your program. | |
1041a570 | 1417 | @xref{Input/Output, ,Your Program's Input and Output}. |
3d3ab540 RP |
1418 | |
1419 | @cindex pipes | |
29a2b744 RP |
1420 | @emph{Warning:} While input and output redirection work, you cannot use |
1421 | pipes to pass the output of the program you are debugging to another | |
3d3ab540 RP |
1422 | program; if you attempt this, _GDBN__ is likely to wind up debugging the |
1423 | wrong program. | |
70b88761 | 1424 | @end table |
4eb4cf57 | 1425 | _fi__(!_BARE__) |
70b88761 | 1426 | |
1041a570 | 1427 | When you issue the @code{run} command, your program begins to execute |
4eb4cf57 RP |
1428 | immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion |
1429 | of how to arrange for your program to stop. Once your program has | |
1430 | stopped, you may calls functions in your program, using the @code{print} | |
1431 | or @code{call} commands. @xref{Data, ,Examining Data}. | |
70b88761 | 1432 | |
29a2b744 | 1433 | If the modification time of your symbol file has changed since the |
1041a570 RP |
1434 | last time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and |
1435 | re-read it. When it does this, _GDBN__ tries to retain your current | |
1436 | breakpoints. | |
70b88761 | 1437 | |
4eb4cf57 RP |
1438 | _if__(!_BARE__) |
1439 | @node Arguments | |
70b88761 RP |
1440 | @section Your Program's Arguments |
1441 | ||
1442 | @cindex arguments (to your program) | |
1443 | The arguments to your program can be specified by the arguments of the | |
1444 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 1445 | characters and performs redirection of I/O, and thence to your program. |
70b88761 RP |
1446 | _GDBN__ uses the shell indicated by your environment variable |
1447 | @code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}. | |
1448 | ||
1449 | @code{run} with no arguments uses the same arguments used by the previous | |
1450 | @code{run}, or those set by the @code{set args} command. | |
1451 | ||
1452 | @kindex set args | |
1453 | @table @code | |
1454 | @item set args | |
1455 | Specify the arguments to be used the next time your program is run. If | |
1456 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 1457 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
1458 | using @code{set args} before the next @code{run} is the only way to run |
1459 | it again without arguments. | |
1460 | ||
1461 | @item show args | |
1462 | @kindex show args | |
1463 | Show the arguments to give your program when it is started. | |
1464 | @end table | |
1465 | ||
4eb4cf57 | 1466 | @node Environment |
70b88761 RP |
1467 | @section Your Program's Environment |
1468 | ||
1469 | @cindex environment (of your program) | |
1470 | The @dfn{environment} consists of a set of environment variables and | |
1471 | their values. Environment variables conventionally record such things as | |
1472 | your user name, your home directory, your terminal type, and your search | |
1473 | path for programs to run. Usually you set up environment variables with | |
1474 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 1475 | debugging, it can be useful to try running your program with a modified |
70b88761 RP |
1476 | environment without having to start _GDBN__ over again. |
1477 | ||
1478 | @table @code | |
1479 | @item path @var{directory} | |
1480 | @kindex path | |
1481 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1482 | (the search path for executables), for both _GDBN__ and your program. | |
1483 | You may specify several directory names, separated by @samp{:} or | |
1484 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 1485 | the front, so it will be searched sooner. |
7463aadd RP |
1486 | |
1487 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1488 | working directory at the time _GDBN__ searches the path. If you use | |
1489 | @samp{.} instead, it refers to the directory where you executed the | |
1490 | @code{path} command. _GDBN__ fills in the current path where needed in | |
1491 | the @var{directory} argument, before adding it to the search path. | |
29a2b744 | 1492 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
1493 | @c document that, since repeating it would be a no-op. |
1494 | ||
1495 | @item show paths | |
1496 | @kindex show paths | |
1497 | Display the list of search paths for executables (the @code{PATH} | |
1498 | environment variable). | |
1499 | ||
1500 | @item show environment @r{[}@var{varname}@r{]} | |
1501 | @kindex show environment | |
1502 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 1503 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
1504 | print the names and values of all environment variables to be given to |
1505 | your program. You can abbreviate @code{environment} as @code{env}. | |
1506 | ||
7463aadd | 1507 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 RP |
1508 | @kindex set environment |
1509 | Sets environment variable @var{varname} to @var{value}. The value | |
1510 | changes for your program only, not for _GDBN__ itself. @var{value} may | |
1511 | be any string; the values of environment variables are just strings, and | |
1512 | any interpretation is supplied by your program itself. The @var{value} | |
1513 | parameter is optional; if it is eliminated, the variable is set to a | |
1514 | null value. | |
29a2b744 | 1515 | @c "any string" here does not include leading, trailing |
70b88761 RP |
1516 | @c blanks. Gnu asks: does anyone care? |
1517 | ||
1518 | For example, this command: | |
1519 | ||
1520 | @example | |
1521 | set env USER = foo | |
1522 | @end example | |
1523 | ||
1524 | @noindent | |
1525 | tells a Unix program, when subsequently run, that its user is named | |
1526 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1527 | are not actually required.) | |
1528 | ||
1529 | @item unset environment @var{varname} | |
1530 | @kindex unset environment | |
1531 | Remove variable @var{varname} from the environment to be passed to your | |
1532 | program. This is different from @samp{set env @var{varname} =}; | |
1533 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 1534 | rather than assigning it an empty value. |
70b88761 RP |
1535 | @end table |
1536 | ||
4eb4cf57 | 1537 | @node Working Directory |
70b88761 RP |
1538 | @section Your Program's Working Directory |
1539 | ||
1540 | @cindex working directory (of your program) | |
1541 | Each time you start your program with @code{run}, it inherits its | |
1542 | working directory from the current working directory of _GDBN__. _GDBN__'s | |
1543 | working directory is initially whatever it inherited from its parent | |
1544 | process (typically the shell), but you can specify a new working | |
1545 | directory in _GDBN__ with the @code{cd} command. | |
1546 | ||
1547 | The _GDBN__ working directory also serves as a default for the commands | |
1041a570 RP |
1548 | that specify files for _GDBN__ to operate on. @xref{Files, ,Commands to |
1549 | Specify Files}. | |
70b88761 RP |
1550 | |
1551 | @table @code | |
1552 | @item cd @var{directory} | |
1553 | @kindex cd | |
1554 | Set _GDBN__'s working directory to @var{directory}. | |
1555 | ||
1556 | @item pwd | |
1557 | @kindex pwd | |
1558 | Print _GDBN__'s working directory. | |
1559 | @end table | |
1560 | ||
4eb4cf57 | 1561 | @node Input/Output |
70b88761 RP |
1562 | @section Your Program's Input and Output |
1563 | ||
1564 | @cindex redirection | |
1565 | @cindex i/o | |
1566 | @cindex terminal | |
1567 | By default, the program you run under _GDBN__ does input and output to | |
1568 | the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to | |
1569 | its own terminal modes to interact with you, but it records the terminal | |
1570 | modes your program was using and switches back to them when you continue | |
1571 | running your program. | |
1572 | ||
1573 | @table @code | |
1574 | @item info terminal | |
1575 | @kindex info terminal | |
1576 | Displays _GDBN__'s recorded information about the terminal modes your | |
1577 | program is using. | |
1578 | @end table | |
1579 | ||
29a2b744 | 1580 | You can redirect your program's input and/or output using shell |
70b88761 RP |
1581 | redirection with the @code{run} command. For example, |
1582 | ||
1583 | _0__@example | |
1584 | run > outfile | |
1585 | _1__@end example | |
1586 | ||
1587 | @noindent | |
29a2b744 | 1588 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
1589 | |
1590 | @kindex tty | |
1591 | @cindex controlling terminal | |
29a2b744 | 1592 | Another way to specify where your program should do input and output is |
70b88761 RP |
1593 | with the @code{tty} command. This command accepts a file name as |
1594 | argument, and causes this file to be the default for future @code{run} | |
1595 | commands. It also resets the controlling terminal for the child | |
1596 | process, for future @code{run} commands. For example, | |
1597 | ||
1598 | @example | |
1599 | tty /dev/ttyb | |
1600 | @end example | |
1601 | ||
1602 | @noindent | |
1603 | directs that processes started with subsequent @code{run} commands | |
1604 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1605 | that as their controlling terminal. | |
1606 | ||
1607 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1608 | effect on the input/output device, but not its effect on the controlling | |
1609 | terminal. | |
1610 | ||
1611 | When you use the @code{tty} command or redirect input in the @code{run} | |
1612 | command, only the input @emph{for your program} is affected. The input | |
1613 | for _GDBN__ still comes from your terminal. | |
1614 | ||
4eb4cf57 | 1615 | @node Attach |
70b88761 RP |
1616 | @section Debugging an Already-Running Process |
1617 | @kindex attach | |
1618 | @cindex attach | |
1619 | ||
1620 | @table @code | |
1621 | @item attach @var{process-id} | |
1622 | This command | |
1623 | attaches to a running process---one that was started outside _GDBN__. | |
1624 | (@code{info files} will show your active targets.) The command takes as | |
1625 | argument a process ID. The usual way to find out the process-id of | |
1626 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
e251e767 | 1627 | shell command. |
70b88761 RP |
1628 | |
1629 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1630 | executing the command. | |
1631 | @end table | |
1632 | ||
1633 | To use @code{attach}, you must be debugging in an environment which | |
1634 | supports processes. You must also have permission to send the process a | |
1635 | signal, and it must have the same effective user ID as the _GDBN__ | |
1636 | process. | |
1637 | ||
1638 | When using @code{attach}, you should first use the @code{file} command | |
1639 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 1640 | @xref{Files, ,Commands to Specify Files}. |
70b88761 RP |
1641 | |
1642 | The first thing _GDBN__ does after arranging to debug the specified | |
1643 | process is to stop it. You can examine and modify an attached process | |
1644 | with all the _GDBN__ commands that are ordinarily available when you start | |
1645 | processes with @code{run}. You can insert breakpoints; you can step and | |
1646 | continue; you can modify storage. If you would rather the process | |
1647 | continue running, you may use the @code{continue} command after | |
1648 | attaching _GDBN__ to the process. | |
1649 | ||
1650 | @table @code | |
1651 | @item detach | |
1652 | @kindex detach | |
1653 | When you have finished debugging the attached process, you can use the | |
1654 | @code{detach} command to release it from _GDBN__'s control. Detaching | |
1655 | the process continues its execution. After the @code{detach} command, | |
1656 | that process and _GDBN__ become completely independent once more, and you | |
1657 | are ready to @code{attach} another process or start one with @code{run}. | |
1658 | @code{detach} will not repeat if you press @key{RET} again after | |
1659 | executing the command. | |
1660 | @end table | |
1661 | ||
1662 | If you exit _GDBN__ or use the @code{run} command while you have an attached | |
1663 | process, you kill that process. By default, you will be asked for | |
1664 | confirmation if you try to do either of these things; you can control | |
1665 | whether or not you need to confirm by using the @code{set confirm} command | |
29a2b744 | 1666 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). |
70b88761 | 1667 | |
4eb4cf57 | 1668 | @node Kill Process |
70b88761 RP |
1669 | @c @group |
1670 | @section Killing the Child Process | |
1671 | ||
1672 | @table @code | |
1673 | @item kill | |
1674 | @kindex kill | |
1675 | Kill the child process in which your program is running under _GDBN__. | |
1676 | @end table | |
1677 | ||
1678 | This command is useful if you wish to debug a core dump instead of a | |
1679 | running process. _GDBN__ ignores any core dump file while your program | |
1680 | is running. | |
1681 | @c @end group | |
1682 | ||
29a2b744 | 1683 | On some operating systems, a program cannot be executed outside _GDBN__ |
70b88761 | 1684 | while you have breakpoints set on it inside _GDBN__. You can use the |
29a2b744 | 1685 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
1686 | outside the debugger. |
1687 | ||
1688 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 1689 | relink your program, since on many systems it is impossible to modify an |
70b88761 RP |
1690 | executable file while it is running in a process. In this case, when you |
1691 | next type @code{run}, _GDBN__ will notice that the file has changed, and | |
1692 | will re-read the symbol table (while trying to preserve your current | |
1693 | breakpoint settings). | |
1694 | ||
4eb4cf57 | 1695 | @node Process Information |
d24e0922 RP |
1696 | @section Additional Process Information |
1697 | ||
1698 | @kindex /proc | |
1699 | @cindex process image | |
1700 | Some operating systems provide a facility called @samp{/proc} that can | |
cc9bc574 RP |
1701 | be used to examine the image of a running process using file-system |
1702 | subroutines. If _GDBN__ is configured for an operating system with this | |
1703 | facility, the command @code{info proc} is available to report on several | |
1704 | kinds of information about the process running your program. | |
d24e0922 RP |
1705 | |
1706 | @table @code | |
1707 | @item info proc | |
1708 | @kindex info proc | |
1709 | Summarize available information about the process. | |
1710 | ||
1711 | @item info proc mappings | |
1712 | @kindex info proc mappings | |
1713 | Report on the address ranges accessible in the program, with information | |
1714 | on whether your program may read, write, or execute each range. | |
1715 | ||
1716 | @item info proc times | |
1717 | @kindex info proc times | |
1718 | Starting time, user CPU time, and system CPU time for your program and | |
1719 | its children. | |
1720 | ||
1721 | @item info proc id | |
1722 | @kindex info proc id | |
1723 | Report on the process ID's related to your program: its own process id, | |
1724 | the id of its parent, the process group id, and the session id. | |
1725 | ||
1726 | @item info proc status | |
1727 | @kindex info proc status | |
1728 | General information on the state of the process. If the process is | |
1729 | stopped, this report includes the reason for stopping, and any signal | |
1730 | received. | |
cc9bc574 RP |
1731 | |
1732 | @item info proc all | |
1733 | Show all the above information about the process. | |
d24e0922 | 1734 | @end table |
4eb4cf57 | 1735 | _fi__(!_BARE__) |
d24e0922 | 1736 | |
4eb4cf57 | 1737 | @node Stopping |
70b88761 RP |
1738 | @chapter Stopping and Continuing |
1739 | ||
1740 | The principal purpose of using a debugger is so that you can stop your | |
29a2b744 | 1741 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
1742 | trouble, you can investigate and find out why. |
1743 | ||
1744 | Inside _GDBN__, your program may stop for any of several reasons, such | |
1745 | as a signal, a breakpoint, or reaching a new line after a _GDBN__ | |
1746 | command such as @code{step}. You may then examine and change | |
1747 | variables, set new breakpoints or remove old ones, and then continue | |
1748 | execution. Usually, the messages shown by _GDBN__ provide ample | |
1749 | explanation of the status of your program---but you can also explicitly | |
1750 | request this information at any time. | |
1751 | ||
1752 | @table @code | |
1753 | @item info program | |
1754 | @kindex info program | |
1755 | Display information about the status of your program: whether it is | |
1756 | running or not, what process it is, and why it stopped. | |
1757 | @end table | |
1758 | ||
1759 | @menu | |
b80282d5 RP |
1760 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
1761 | * Continuing and Stepping:: Resuming Execution | |
4eb4cf57 | 1762 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 1763 | * Signals:: Signals |
4eb4cf57 | 1764 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
1765 | @end menu |
1766 | ||
4eb4cf57 | 1767 | @node Breakpoints |
70b88761 RP |
1768 | @section Breakpoints, Watchpoints, and Exceptions |
1769 | ||
1770 | @cindex breakpoints | |
1771 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 1772 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 1773 | conditions to control in finer detail whether your program will stop. |
70b88761 | 1774 | You can set breakpoints with the @code{break} command and its variants |
29a2b744 RP |
1775 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where |
1776 | your program should stop by line number, function name or exact address | |
1041a570 | 1777 | in the program. In languages with exception handling (such as GNU |
29a2b744 | 1778 | C++), you can also set breakpoints where an exception is raised |
1041a570 | 1779 | (@pxref{Exception Handling, ,Breakpoints and Exceptions}). |
70b88761 RP |
1780 | |
1781 | @cindex watchpoints | |
6ca72cc6 RP |
1782 | @cindex memory tracing |
1783 | @cindex breakpoint on memory address | |
1784 | @cindex breakpoint on variable modification | |
29a2b744 RP |
1785 | A @dfn{watchpoint} is a special breakpoint that stops your program |
1786 | when the value of an expression changes. You must use a different | |
1787 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
1788 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
1789 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1041a570 | 1790 | and watchpoints using the same commands. |
70b88761 | 1791 | |
6ca72cc6 RP |
1792 | @cindex breakpoint numbers |
1793 | @cindex numbers for breakpoints | |
1794 | _GDBN__ assigns a number to each breakpoint or watchpoint when you | |
1795 | create it; these numbers are successive integers starting with one. In | |
1796 | many of the commands for controlling various features of breakpoints you | |
1797 | use the breakpoint number to say which breakpoint you want to change. | |
1798 | Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 1799 | no effect on your program until you enable it again. |
70b88761 RP |
1800 | |
1801 | @menu | |
b80282d5 RP |
1802 | * Set Breaks:: Setting Breakpoints |
1803 | * Set Watchpoints:: Setting Watchpoints | |
1804 | * Exception Handling:: Breakpoints and Exceptions | |
1805 | * Delete Breaks:: Deleting Breakpoints | |
1806 | * Disabling:: Disabling Breakpoints | |
1807 | * Conditions:: Break Conditions | |
1808 | * Break Commands:: Breakpoint Command Lists | |
1809 | * Breakpoint Menus:: Breakpoint Menus | |
e251e767 | 1810 | * Error in Breakpoints:: |
70b88761 RP |
1811 | @end menu |
1812 | ||
4eb4cf57 | 1813 | @node Set Breaks |
70b88761 RP |
1814 | @subsection Setting Breakpoints |
1815 | ||
4906534f RP |
1816 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
1817 | @c consider in particular declaration with/without initialization. | |
1818 | @c | |
1819 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1820 | ||
70b88761 RP |
1821 | @kindex break |
1822 | @kindex b | |
6ca72cc6 RP |
1823 | @kindex $bpnum |
1824 | @cindex latest breakpoint | |
1825 | Breakpoints are set with the @code{break} command (abbreviated | |
1826 | @code{b}). The debugger convenience variable @samp{$bpnum} records the | |
1827 | number of the beakpoint you've set most recently; see @ref{Convenience | |
d24e0922 | 1828 | Vars,, Convenience Variables}, for a discussion of what you can do with |
6ca72cc6 | 1829 | convenience variables. |
70b88761 RP |
1830 | |
1831 | You have several ways to say where the breakpoint should go. | |
1832 | ||
1833 | @table @code | |
1834 | @item break @var{function} | |
1835 | Set a breakpoint at entry to function @var{function}. When using source | |
1836 | languages that permit overloading of symbols, such as C++, | |
1837 | @var{function} may refer to more than one possible place to break. | |
1838 | @xref{Breakpoint Menus}, for a discussion of that situation. | |
1839 | ||
1840 | @item break +@var{offset} | |
1841 | @itemx break -@var{offset} | |
1842 | Set a breakpoint some number of lines forward or back from the position | |
1843 | at which execution stopped in the currently selected frame. | |
1844 | ||
1845 | @item break @var{linenum} | |
1846 | Set a breakpoint at line @var{linenum} in the current source file. | |
1847 | That file is the last file whose source text was printed. This | |
29a2b744 | 1848 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
1849 | code on that line. |
1850 | ||
1851 | @item break @var{filename}:@var{linenum} | |
1852 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1853 | ||
1854 | @item break @var{filename}:@var{function} | |
1855 | Set a breakpoint at entry to function @var{function} found in file | |
1856 | @var{filename}. Specifying a file name as well as a function name is | |
1857 | superfluous except when multiple files contain similarly named | |
1858 | functions. | |
1859 | ||
1860 | @item break *@var{address} | |
1861 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 1862 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
1863 | information or source files. |
1864 | ||
1865 | @item break | |
29a2b744 RP |
1866 | When called without any arguments, @code{break} sets a breakpoint at |
1867 | the next instruction to be executed in the selected stack frame | |
1868 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
1869 | innermost, this will cause your program to stop as soon as control | |
1870 | returns to that frame. This is similar to the effect of a | |
1871 | @code{finish} command in the frame inside the selected frame---except | |
1872 | that @code{finish} does not leave an active breakpoint. If you use | |
1041a570 RP |
1873 | @code{break} without an argument in the innermost frame, _GDBN__ will stop |
1874 | the next time it reaches the current location; this may be useful | |
1875 | inside loops. | |
70b88761 RP |
1876 | |
1877 | _GDBN__ normally ignores breakpoints when it resumes execution, until at | |
1878 | least one instruction has been executed. If it did not do this, you | |
1879 | would be unable to proceed past a breakpoint without first disabling the | |
1880 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 1881 | existed when your program stopped. |
70b88761 RP |
1882 | |
1883 | @item break @dots{} if @var{cond} | |
1884 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1885 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 1886 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
1887 | @samp{@dots{}} stands for one of the possible arguments described |
1888 | above (or no argument) specifying where to break. @xref{Conditions, | |
1889 | ,Break Conditions}, for more information on breakpoint conditions. | |
70b88761 RP |
1890 | |
1891 | @item tbreak @var{args} | |
1892 | @kindex tbreak | |
1893 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1894 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 RP |
1895 | way, but the breakpoint is automatically disabled after the first time your |
1896 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
70b88761 RP |
1897 | |
1898 | @item rbreak @var{regex} | |
1899 | @kindex rbreak | |
1900 | @cindex regular expression | |
4906534f | 1901 | @c FIXME what kind of regexp? |
70b88761 | 1902 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 1903 | @var{regex}. This command |
70b88761 RP |
1904 | sets an unconditional breakpoint on all matches, printing a list of all |
1905 | breakpoints it set. Once these breakpoints are set, they are treated | |
1906 | just like the breakpoints set with the @code{break} command. They can | |
1907 | be deleted, disabled, made conditional, etc., in the standard ways. | |
1908 | ||
b80282d5 RP |
1909 | When debugging C++ programs, @code{rbreak} is useful for setting |
1910 | breakpoints on overloaded functions that are not members of any special | |
1911 | classes. | |
1912 | ||
70b88761 | 1913 | @kindex info breakpoints |
c338a2fd | 1914 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 | 1915 | @item info breakpoints @r{[}@var{n}@r{]} |
6ca72cc6 RP |
1916 | @itemx info break @r{[}@var{n}@r{]} |
1917 | @itemx info watchpoints @r{[}@var{n}@r{]} | |
1918 | Print a table of all breakpoints and watchpoints set and not | |
1919 | deleted, with the following columns for each breakpoint: | |
1920 | ||
1921 | @table @emph | |
1922 | @item Breakpoint Numbers | |
1923 | @item Type | |
1924 | Breakpoint or watchpoint. | |
1925 | @item Disposition | |
1926 | Whether the breakpoint is marked to be disabled or deleted when hit. | |
1927 | @item Enabled or Disabled | |
d24e0922 | 1928 | Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints |
6ca72cc6 RP |
1929 | that are not enabled. |
1930 | @item Address | |
1931 | Where the breakpoint is in your program, as a memory address | |
1932 | @item What | |
1933 | Where the breakpoint is in the source for your program, as a file and | |
1934 | line number. | |
1935 | @end table | |
1936 | ||
1937 | @noindent | |
1938 | Breakpoint commands, if any, are listed after the line for the | |
1939 | corresponding breakpoint. | |
1940 | ||
1941 | @noindent | |
1942 | @code{info break} with a breakpoint | |
29a2b744 RP |
1943 | number @var{n} as argument lists only that breakpoint. The |
1944 | convenience variable @code{$_} and the default examining-address for | |
1945 | the @code{x} command are set to the address of the last breakpoint | |
6ca72cc6 | 1946 | listed (@pxref{Memory, ,Examining Memory}). |
1041a570 | 1947 | @end table |
70b88761 | 1948 | |
1041a570 RP |
1949 | _GDBN__ allows you to set any number of breakpoints at the same place in |
1950 | your program. There is nothing silly or meaningless about this. When | |
1951 | the breakpoints are conditional, this is even useful | |
29a2b744 | 1952 | (@pxref{Conditions, ,Break Conditions}). |
70b88761 | 1953 | |
6ca72cc6 RP |
1954 | @cindex negative breakpoint numbers |
1955 | @cindex internal _GDBN__ breakpoints | |
1956 | _GDBN__ itself sometimes sets breakpoints in your program for special | |
1957 | purposes, such as proper handling of @code{longjmp} (in C programs). | |
1958 | These internal breakpoints are assigned negative numbers, starting with | |
5a2c1d85 | 1959 | @code{-1}; @samp{info breakpoints} does not display them. |
d48da190 | 1960 | |
5a2c1d85 RP |
1961 | You can see these breakpoints with the _GDBN__ maintenance command |
1962 | @samp{maint info breakpoints}. | |
6ca72cc6 RP |
1963 | |
1964 | @table @code | |
d48da190 RP |
1965 | @kindex maint info breakpoints |
1966 | @item maint info breakpoints | |
6ca72cc6 RP |
1967 | Using the same format as @samp{info breakpoints}, display both the |
1968 | breakpoints you've set explicitly, and those _GDBN__ is using for | |
1969 | internal purposes. Internal breakpoints are shown with negative | |
1970 | breakpoint numbers. The type column identifies what kind of breakpoint | |
1971 | is shown: | |
1972 | ||
1973 | @table @code | |
1974 | @item breakpoint | |
1975 | Normal, explicitly set breakpoint. | |
1976 | ||
1977 | @item watchpoint | |
1978 | Normal, explicitly set watchpoint. | |
1979 | ||
1980 | @item longjmp | |
1981 | Internal breakpoint, used to handle correctly stepping through | |
1982 | @code{longjmp} calls. | |
1983 | ||
1984 | @item longjmp resume | |
1985 | Internal breakpoint at the target of a @code{longjmp}. | |
1986 | ||
1987 | @item until | |
1988 | Temporary internal breakpoint used by the _GDBN__ @code{until} command. | |
1989 | ||
1990 | @item finish | |
1991 | Temporary internal breakpoint used by the _GDBN__ @code{finish} command. | |
1992 | @end table | |
1993 | ||
1994 | @end table | |
1995 | ||
1996 | ||
4eb4cf57 | 1997 | @node Set Watchpoints |
70b88761 RP |
1998 | @subsection Setting Watchpoints |
1999 | @cindex setting watchpoints | |
1041a570 | 2000 | |
70b88761 | 2001 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 2002 | expression changes, without having to predict a particular place |
70b88761 RP |
2003 | where this may happen. |
2004 | ||
2005 | Watchpoints currently execute two orders of magnitude more slowly than | |
2006 | other breakpoints, but this can well be worth it to catch errors where | |
2007 | you have no clue what part of your program is the culprit. Some | |
2008 | processors provide special hardware to support watchpoint evaluation; future | |
2009 | releases of _GDBN__ will use such hardware if it is available. | |
2010 | ||
2011 | @table @code | |
e251e767 | 2012 | @kindex watch |
70b88761 RP |
2013 | @item watch @var{expr} |
2014 | Set a watchpoint for an expression. | |
2015 | ||
2016 | @kindex info watchpoints | |
2017 | @item info watchpoints | |
6ca72cc6 RP |
2018 | This command prints a list of watchpoints and breakpoints; it is the |
2019 | same as @code{info break}. | |
70b88761 RP |
2020 | @end table |
2021 | ||
4eb4cf57 | 2022 | @node Exception Handling |
70b88761 RP |
2023 | @subsection Breakpoints and Exceptions |
2024 | @cindex exception handlers | |
2025 | ||
b80282d5 | 2026 | Some languages, such as GNU C++, implement exception handling. You can |
29a2b744 RP |
2027 | use _GDBN__ to examine what caused your program to raise an exception, |
2028 | and to list the exceptions your program is prepared to handle at a | |
70b88761 RP |
2029 | given point in time. |
2030 | ||
2031 | @table @code | |
2032 | @item catch @var{exceptions} | |
2033 | @kindex catch | |
2034 | You can set breakpoints at active exception handlers by using the | |
2035 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
2036 | to catch. | |
2037 | @end table | |
2038 | ||
29a2b744 RP |
2039 | You can use @code{info catch} to list active exception handlers. |
2040 | @xref{Frame Info, ,Information About a Frame}. | |
70b88761 RP |
2041 | |
2042 | There are currently some limitations to exception handling in _GDBN__. | |
2043 | These will be corrected in a future release. | |
2044 | ||
2045 | @itemize @bullet | |
2046 | @item | |
2047 | If you call a function interactively, _GDBN__ normally returns | |
2048 | control to you when the function has finished executing. If the call | |
2049 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 2050 | returns control to you and cause your program to simply continue |
70b88761 RP |
2051 | running until it hits a breakpoint, catches a signal that _GDBN__ is |
2052 | listening for, or exits. | |
2053 | @item | |
2054 | You cannot raise an exception interactively. | |
2055 | @item | |
2056 | You cannot interactively install an exception handler. | |
2057 | @end itemize | |
2058 | ||
2059 | @cindex raise exceptions | |
2060 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 2061 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
2062 | stop @emph{before} the exception handler is called, since that way you |
2063 | can see the stack before any unwinding takes place. If you set a | |
2064 | breakpoint in an exception handler instead, it may not be easy to find | |
2065 | out where the exception was raised. | |
2066 | ||
2067 | To stop just before an exception handler is called, you need some | |
b80282d5 | 2068 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
2069 | raised by calling a library function named @code{__raise_exception} |
2070 | which has the following ANSI C interface: | |
2071 | ||
2072 | @example | |
b80282d5 | 2073 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
2074 | ID is the exception identifier. */ |
2075 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
2076 | @end example | |
2077 | ||
2078 | @noindent | |
2079 | To make the debugger catch all exceptions before any stack | |
2080 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
29a2b744 | 2081 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). |
70b88761 | 2082 | |
29a2b744 RP |
2083 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) |
2084 | that depends on the value of @var{id}, you can stop your program when | |
2085 | a specific exception is raised. You can use multiple conditional | |
2086 | breakpoints to stop your program when any of a number of exceptions are | |
2087 | raised. | |
70b88761 | 2088 | |
4eb4cf57 | 2089 | @node Delete Breaks |
70b88761 RP |
2090 | @subsection Deleting Breakpoints |
2091 | ||
2092 | @cindex clearing breakpoints, watchpoints | |
2093 | @cindex deleting breakpoints, watchpoints | |
2094 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 2095 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
2096 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
2097 | deleted no longer exists; it is forgotten. | |
2098 | ||
2099 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 2100 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
2101 | delete individual breakpoints or watchpoints by specifying their |
2102 | breakpoint numbers. | |
2103 | ||
2104 | It is not necessary to delete a breakpoint to proceed past it. _GDBN__ | |
2105 | automatically ignores breakpoints on the first instruction to be executed | |
2106 | when you continue execution without changing the execution address. | |
2107 | ||
2108 | @table @code | |
2109 | @item clear | |
2110 | @kindex clear | |
2111 | Delete any breakpoints at the next instruction to be executed in the | |
29a2b744 RP |
2112 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When |
2113 | the innermost frame is selected, this is a good way to delete a | |
2114 | breakpoint where your program just stopped. | |
70b88761 RP |
2115 | |
2116 | @item clear @var{function} | |
2117 | @itemx clear @var{filename}:@var{function} | |
2118 | Delete any breakpoints set at entry to the function @var{function}. | |
2119 | ||
2120 | @item clear @var{linenum} | |
2121 | @itemx clear @var{filename}:@var{linenum} | |
2122 | Delete any breakpoints set at or within the code of the specified line. | |
2123 | ||
2124 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2125 | @cindex delete breakpoints | |
2126 | @kindex delete | |
2127 | @kindex d | |
2128 | Delete the breakpoints or watchpoints of the numbers specified as | |
2129 | arguments. If no argument is specified, delete all breakpoints (_GDBN__ | |
1041a570 | 2130 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
2131 | can abbreviate this command as @code{d}. |
2132 | @end table | |
2133 | ||
4eb4cf57 | 2134 | @node Disabling |
70b88761 RP |
2135 | @subsection Disabling Breakpoints |
2136 | ||
2137 | @cindex disabled breakpoints | |
2138 | @cindex enabled breakpoints | |
2139 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
2140 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
2141 | been deleted, but remembers the information on the breakpoint so that | |
2142 | you can @dfn{enable} it again later. | |
2143 | ||
2144 | You disable and enable breakpoints and watchpoints with the | |
2145 | @code{enable} and @code{disable} commands, optionally specifying one or | |
2146 | more breakpoint numbers as arguments. Use @code{info break} or | |
2147 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 2148 | do not know which numbers to use. |
70b88761 RP |
2149 | |
2150 | A breakpoint or watchpoint can have any of four different states of | |
2151 | enablement: | |
2152 | ||
2153 | @itemize @bullet | |
2154 | @item | |
29a2b744 | 2155 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2156 | with the @code{break} command starts out in this state. |
2157 | @item | |
29a2b744 | 2158 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2159 | @item |
29a2b744 | 2160 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2161 | when it does so it will become disabled. A breakpoint set |
2162 | with the @code{tbreak} command starts out in this state. | |
2163 | @item | |
29a2b744 | 2164 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2165 | immediately after it does so it will be deleted permanently. |
2166 | @end itemize | |
2167 | ||
2168 | You can use the following commands to enable or disable breakpoints and | |
2169 | watchpoints: | |
2170 | ||
2171 | @table @code | |
2172 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2173 | @kindex disable breakpoints | |
2174 | @kindex disable | |
2175 | @kindex dis | |
2176 | Disable the specified breakpoints---or all breakpoints, if none are | |
2177 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2178 | options such as ignore-counts, conditions and commands are remembered in | |
2179 | case the breakpoint is enabled again later. You may abbreviate | |
2180 | @code{disable} as @code{dis}. | |
2181 | ||
2182 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2183 | @kindex enable breakpoints | |
2184 | @kindex enable | |
2185 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2186 | become effective once again in stopping your program. |
70b88761 RP |
2187 | |
2188 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2189 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2190 | again the next time it stops your program. |
70b88761 RP |
2191 | |
2192 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2193 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2194 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2195 | @end table |
2196 | ||
29a2b744 RP |
2197 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
2198 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2199 | enabled; subsequently, they become disabled or enabled only when you | |
2200 | use one of the commands above. (The command @code{until} can set and | |
2201 | delete a breakpoint of its own, but it will not change the state of | |
98fe4566 | 2202 | your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.) |
70b88761 | 2203 | |
4eb4cf57 | 2204 | @node Conditions |
70b88761 RP |
2205 | @subsection Break Conditions |
2206 | @cindex conditional breakpoints | |
2207 | @cindex breakpoint conditions | |
2208 | ||
4906534f RP |
2209 | @c FIXME what is scope of break condition expr? Context where wanted? |
2210 | @c in particular for a watchpoint? | |
29a2b744 | 2211 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2212 | specified place. You can also specify a @dfn{condition} for a |
2213 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2214 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2215 | a condition evaluates the expression each time your program reaches it, | |
2216 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2217 | |
2218 | This is the converse of using assertions for program validation; in that | |
2219 | situation, you want to stop when the assertion is violated---that is, | |
2220 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2221 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2222 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2223 | |
2224 | Conditions are also accepted for watchpoints; you may not need them, | |
2225 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2226 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2227 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2228 | one. |
70b88761 | 2229 | |
29a2b744 | 2230 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2231 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2232 | that log program progress, or to use your own print functions to |
2233 | format special data structures. The effects are completely predictable | |
2234 | unless there is another enabled breakpoint at the same address. (In | |
2235 | that case, _GDBN__ might see the other breakpoint first and stop your | |
2236 | program without checking the condition of this one.) Note that | |
2237 | breakpoint commands are usually more convenient and flexible for the | |
2238 | purpose of performing side effects when a breakpoint is reached | |
2239 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
70b88761 RP |
2240 | |
2241 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 RP |
2242 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
2243 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2244 | with the @code{condition} command. The @code{watch} command does not | |
2245 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2246 | impose a further condition on a watchpoint. | |
70b88761 | 2247 | |
e251e767 RP |
2248 | @table @code |
2249 | @item condition @var{bnum} @var{expression} | |
2250 | @kindex condition | |
70b88761 RP |
2251 | Specify @var{expression} as the break condition for breakpoint or |
2252 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2253 | your program only if the value of @var{expression} is true (nonzero, in |
70b88761 RP |
2254 | C). When you use @code{condition}, _GDBN__ checks @var{expression} |
2255 | immediately for syntactic correctness, and to determine whether symbols | |
1041a570 | 2256 | in it have referents in the context of your breakpoint. |
29a2b744 | 2257 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f RP |
2258 | @c about watchpoints? |
2259 | _GDBN__ does | |
70b88761 | 2260 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 2261 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
2262 | |
2263 | @item condition @var{bnum} | |
2264 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2265 | an ordinary unconditional breakpoint. | |
2266 | @end table | |
2267 | ||
2268 | @cindex ignore count (of breakpoint) | |
2269 | A special case of a breakpoint condition is to stop only when the | |
2270 | breakpoint has been reached a certain number of times. This is so | |
2271 | useful that there is a special way to do it, using the @dfn{ignore | |
2272 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2273 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 2274 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
2275 | ignore count is positive, then instead of stopping, it just decrements |
2276 | the ignore count by one and continues. As a result, if the ignore count | |
2277 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2278 | is reached. | |
2279 | ||
2280 | @table @code | |
2281 | @item ignore @var{bnum} @var{count} | |
2282 | @kindex ignore | |
2283 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2284 | The next @var{count} times the breakpoint is reached, your program's | |
2285 | execution will not stop; other than to decrement the ignore count, _GDBN__ | |
2286 | takes no action. | |
2287 | ||
2288 | To make the breakpoint stop the next time it is reached, specify | |
2289 | a count of zero. | |
2290 | ||
2291 | @item continue @var{count} | |
2292 | @itemx c @var{count} | |
2293 | @itemx fg @var{count} | |
2294 | @kindex continue @var{count} | |
29a2b744 RP |
2295 | Continue execution of your program, setting the ignore count of the |
2296 | breakpoint where your program stopped to @var{count} minus one. | |
2297 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
2298 | @var{count}'th time it is reached. |
2299 | ||
29a2b744 | 2300 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
2301 | due to a breakpoint. At other times, the argument to @code{continue} is |
2302 | ignored. | |
2303 | ||
2304 | The synonym @code{fg} is provided purely for convenience, and has | |
2305 | exactly the same behavior as other forms of the command. | |
2306 | @end table | |
2307 | ||
2308 | If a breakpoint has a positive ignore count and a condition, the condition | |
2309 | is not checked. Once the ignore count reaches zero, the condition will | |
2310 | be checked. | |
2311 | ||
29a2b744 | 2312 | You could achieve the effect of the ignore count with a condition such |
1041a570 RP |
2313 | as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience variable that |
2314 | is decremented each time. @xref{Convenience Vars, ,Convenience | |
2315 | Variables}. | |
70b88761 | 2316 | |
4eb4cf57 | 2317 | @node Break Commands |
70b88761 RP |
2318 | @subsection Breakpoint Command Lists |
2319 | ||
2320 | @cindex breakpoint commands | |
2321 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 2322 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
2323 | might want to print the values of certain expressions, or enable other |
2324 | breakpoints. | |
2325 | ||
2326 | @table @code | |
2327 | @item commands @r{[}@var{bnum}@r{]} | |
2328 | @itemx @dots{} @var{command-list} @dots{} | |
2329 | @itemx end | |
2330 | @kindex commands | |
2331 | @kindex end | |
2332 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2333 | themselves appear on the following lines. Type a line containing just | |
2334 | @code{end} to terminate the commands. | |
2335 | ||
203eea5d RP |
2336 | To remove all commands from a breakpoint, type @code{commands} and |
2337 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
2338 | |
2339 | With no @var{bnum} argument, @code{commands} refers to the last | |
2340 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2341 | encountered). | |
2342 | @end table | |
2343 | ||
2344 | Pressing @key{RET} as a means of repeating the last _GDBN__ command is | |
2345 | disabled within a @var{command-list}. | |
2346 | ||
29a2b744 | 2347 | You can use breakpoint commands to start your program up again. Simply |
70b88761 RP |
2348 | use the @code{continue} command, or @code{step}, or any other command |
2349 | that resumes execution. Subsequent commands in the command list are | |
2350 | ignored. | |
2351 | ||
2352 | @kindex silent | |
2353 | If the first command specified is @code{silent}, the usual message about | |
2354 | stopping at a breakpoint is not printed. This may be desirable for | |
2355 | breakpoints that are to print a specific message and then continue. | |
2356 | If the remaining commands too print nothing, you will see no sign that | |
e251e767 | 2357 | the breakpoint was reached at all. @code{silent} is meaningful only |
70b88761 RP |
2358 | at the beginning of a breakpoint command list. |
2359 | ||
29a2b744 RP |
2360 | The commands @code{echo} and @code{output} that allow you to print |
2361 | precisely controlled output are often useful in silent breakpoints. | |
2362 | @xref{Output, ,Commands for Controlled Output}. | |
70b88761 RP |
2363 | |
2364 | For example, here is how you could use breakpoint commands to print the | |
2365 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2366 | ||
2367 | _0__@example | |
2368 | break foo if x>0 | |
2369 | commands | |
2370 | silent | |
2371 | echo x is\040 | |
2372 | output x | |
2373 | echo \n | |
2374 | cont | |
2375 | end | |
2376 | _1__@end example | |
2377 | ||
2378 | One application for breakpoint commands is to compensate for one bug so | |
2379 | you can test for another. Put a breakpoint just after the erroneous line | |
2380 | of code, give it a condition to detect the case in which something | |
2381 | erroneous has been done, and give it commands to assign correct values | |
2382 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 2383 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
2384 | command so that no output is produced. Here is an example: |
2385 | ||
2386 | @example | |
2387 | break 403 | |
2388 | commands | |
2389 | silent | |
2390 | set x = y + 4 | |
2391 | cont | |
2392 | end | |
2393 | @end example | |
2394 | ||
2395 | @cindex lost output | |
2396 | One deficiency in the operation of automatically continuing breakpoints | |
2397 | under Unix appears when your program uses raw mode for the terminal. | |
2398 | _GDBN__ switches back to its own terminal modes (not raw) before executing | |
2399 | commands, and then must switch back to raw mode when your program is | |
e251e767 | 2400 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
2401 | @c FIXME: revisit below when GNU sys avail. |
2402 | @c In the GNU system, this will be fixed by changing the behavior of | |
2403 | @c terminal modes. | |
2404 | ||
2405 | Under Unix, you can get around this problem by writing actions into | |
2406 | the breakpoint condition rather than in commands. For example | |
2407 | ||
2408 | @example | |
2409 | condition 5 (x = y + 4), 0 | |
2410 | @end example | |
2411 | ||
2412 | @noindent | |
1041a570 RP |
2413 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
2414 | change @code{x} as needed, then always have the value zero so your | |
2415 | program will not stop. No input is lost here, because _GDBN__ evaluates | |
2416 | break conditions without changing the terminal modes. When you want | |
2417 | to have nontrivial conditions for performing the side effects, the | |
2418 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 | 2419 | |
4eb4cf57 | 2420 | @node Breakpoint Menus |
70b88761 | 2421 | @subsection Breakpoint Menus |
b80282d5 | 2422 | @cindex overloading |
e251e767 | 2423 | @cindex symbol overloading |
70b88761 RP |
2424 | |
2425 | Some programming languages (notably C++) permit a single function name | |
2426 | to be defined several times, for application in different contexts. | |
2427 | This is called @dfn{overloading}. When a function name is overloaded, | |
6f3ec223 RP |
2428 | @samp{break @var{function}} is not enough to tell _GDBN__ where you want |
2429 | a breakpoint. If you realize this will be a problem, you can use | |
2430 | something like @samp{break @var{function}(@var{types})} to specify which | |
2431 | particular version of the function you want. Otherwise, _GDBN__ offers | |
2432 | you a menu of numbered choices for different possible breakpoints, and | |
2433 | waits for your selection with the prompt @samp{>}. The first two | |
2434 | options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1} | |
2435 | sets a breakpoint at each definition of @var{function}, and typing | |
2436 | @kbd{0} aborts the @code{break} command without setting any new | |
2437 | breakpoints. | |
70b88761 RP |
2438 | |
2439 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 2440 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
2441 | We choose three particular definitions of that function name: |
2442 | ||
6f3ec223 | 2443 | @c FIXME! This is likely to change to show arg type lists, at least |
70b88761 RP |
2444 | @example |
2445 | (_GDBP__) b String::after | |
2446 | [0] cancel | |
2447 | [1] all | |
2448 | [2] file:String.cc; line number:867 | |
2449 | [3] file:String.cc; line number:860 | |
2450 | [4] file:String.cc; line number:875 | |
2451 | [5] file:String.cc; line number:853 | |
2452 | [6] file:String.cc; line number:846 | |
2453 | [7] file:String.cc; line number:735 | |
2454 | > 2 4 6 | |
2455 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2456 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2457 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2458 | Multiple breakpoints were set. | |
2459 | Use the "delete" command to delete unwanted breakpoints. | |
e251e767 | 2460 | (_GDBP__) |
70b88761 RP |
2461 | @end example |
2462 | ||
4eb4cf57 | 2463 | @node Error in Breakpoints |
70b88761 RP |
2464 | @subsection ``Cannot Insert Breakpoints'' |
2465 | ||
e251e767 | 2466 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 2467 | @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91 |
e251e767 | 2468 | @c some light may be shed by looking at instances of |
d24e0922 | 2469 | @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise |
c338a2fd | 2470 | @c too. pesch, 20sep91 |
70b88761 RP |
2471 | Under some operating systems, breakpoints cannot be used in a program if |
2472 | any other process is running that program. In this situation, | |
2473 | attempting to run or continue a program with a breakpoint causes _GDBN__ | |
2474 | to stop the other process. | |
2475 | ||
2476 | When this happens, you have three ways to proceed: | |
2477 | ||
2478 | @enumerate | |
2479 | @item | |
2480 | Remove or disable the breakpoints, then continue. | |
2481 | ||
2482 | @item | |
29a2b744 | 2483 | Suspend _GDBN__, and copy the file containing your program to a new name. |
70b88761 | 2484 | Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__ |
29a2b744 | 2485 | should run your program under that name. Then start your program again. |
70b88761 RP |
2486 | |
2487 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2488 | @c explains the first FIXME: in this section... | |
2489 | ||
2490 | @item | |
29a2b744 | 2491 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
2492 | linker option @samp{-N}. The operating system limitation may not apply |
2493 | to nonsharable executables. | |
2494 | @end enumerate | |
2495 | ||
4eb4cf57 | 2496 | @node Continuing and Stepping |
3d3ab540 | 2497 | @section Continuing and Stepping |
70b88761 RP |
2498 | |
2499 | @cindex stepping | |
7463aadd RP |
2500 | @cindex continuing |
2501 | @cindex resuming execution | |
3d3ab540 | 2502 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
2503 | completes normally. In contrast, @dfn{stepping} means executing just |
2504 | one more ``step'' of your program, where ``step'' may mean either one | |
2505 | line of source code, or one machine instruction (depending on what | |
2506 | particular command you use). Either when continuing | |
4eb4cf57 RP |
2507 | or when stepping, your program may stop even sooner, due to |
2508 | _if__(_BARE__) | |
2509 | a breakpoint. | |
2510 | _fi__(_BARE__) | |
2511 | _if__(!_BARE__) | |
2512 | a breakpoint or to a signal. (If due to a signal, you may want to use | |
2513 | @code{handle}, or use @samp{signal 0} to resume execution. | |
2514 | @xref{Signals, ,Signals}.) | |
2515 | _fi__(!_BARE__) | |
3d3ab540 RP |
2516 | |
2517 | @table @code | |
2518 | @item continue @r{[}@var{ignore-count}@r{]} | |
2519 | @kindex continue | |
29a2b744 | 2520 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
2521 | any breakpoints set at that address are bypassed. The optional argument |
2522 | @var{ignore-count} allows you to specify a further number of times to | |
2523 | ignore a breakpoint at this location; its effect is like that of | |
29a2b744 | 2524 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). |
3d3ab540 RP |
2525 | |
2526 | To resume execution at a different place, you can use @code{return} | |
29a2b744 RP |
2527 | (@pxref{Returning, ,Returning from a Function}) to go back to the |
2528 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
1041a570 | 2529 | Different Address}) to go to an arbitrary location in your program. |
3d3ab540 | 2530 | @end table |
7463aadd RP |
2531 | |
2532 | A typical technique for using stepping is to set a breakpoint | |
29a2b744 RP |
2533 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the |
2534 | beginning of the function or the section of your program where a | |
2535 | problem is believed to lie, run your program until it stops at that | |
2536 | breakpoint, and then step through the suspect area, examining the | |
2537 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
2538 | |
2539 | @table @code | |
2540 | @item step | |
2541 | @kindex step | |
2542 | @kindex s | |
29a2b744 | 2543 | Continue running your program until control reaches a different source |
7463aadd | 2544 | line, then stop it and return control to _GDBN__. This command is |
70b88761 RP |
2545 | abbreviated @code{s}. |
2546 | ||
3d3ab540 RP |
2547 | @quotation |
2548 | @emph{Warning:} If you use the @code{step} command while control is | |
2549 | within a function that was compiled without debugging information, | |
2550 | execution will proceed until control reaches another function. | |
2551 | @end quotation | |
70b88761 RP |
2552 | |
2553 | @item step @var{count} | |
2554 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2555 | breakpoint is reached or a signal not related to stepping occurs before | |
2556 | @var{count} steps, stepping stops right away. | |
2557 | ||
7463aadd | 2558 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2559 | @kindex next |
2560 | @kindex n | |
7463aadd RP |
2561 | Continue to the next source line in the current (innermost) stack frame. |
2562 | Similar to @code{step}, but any function calls appearing within the line | |
2563 | of code are executed without stopping. Execution stops when control | |
2564 | reaches a different line of code at the stack level which was executing | |
2565 | when the @code{next} command was given. This command is abbreviated | |
2566 | @code{n}. | |
70b88761 | 2567 | |
7463aadd | 2568 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2569 | |
2570 | @code{next} within a function that lacks debugging information acts like | |
2571 | @code{step}, but any function calls appearing within the code of the | |
2572 | function are executed without stopping. | |
2573 | ||
2574 | @item finish | |
2575 | @kindex finish | |
7463aadd RP |
2576 | Continue running until just after function in the selected stack frame |
2577 | returns. Print the returned value (if any). | |
70b88761 | 2578 | |
29a2b744 | 2579 | Contrast this with the @code{return} command (@pxref{Returning, |
1041a570 | 2580 | ,Returning from a Function}). |
70b88761 RP |
2581 | |
2582 | @item until | |
2583 | @kindex until | |
2584 | @item u | |
2585 | @kindex u | |
2586 | Continue running until a source line past the current line, in the | |
2587 | current stack frame, is reached. This command is used to avoid single | |
2588 | stepping through a loop more than once. It is like the @code{next} | |
2589 | command, except that when @code{until} encounters a jump, it | |
2590 | automatically continues execution until the program counter is greater | |
2591 | than the address of the jump. | |
2592 | ||
2593 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 2594 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
2595 | until the loop is exited. In contrast, a @code{next} command at the end |
2596 | of a loop will simply step back to the beginning of the loop, which | |
2597 | would force you to step through the next iteration. | |
2598 | ||
29a2b744 | 2599 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
2600 | stack frame. |
2601 | ||
2602 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2603 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2604 | example, in the following excerpt from a debugging session, the @code{f} |
2605 | (@code{frame}) command shows that execution is stopped at line | |
2606 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2607 | ||
2608 | @example | |
2609 | (_GDBP__) f | |
2610 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
b80282d5 | 2611 | 206 expand_input(); |
70b88761 | 2612 | (_GDBP__) until |
b80282d5 | 2613 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
2614 | @end example |
2615 | ||
7463aadd RP |
2616 | This happened because, for execution efficiency, the compiler had |
2617 | generated code for the loop closure test at the end, rather than the | |
2618 | start, of the loop---even though the test in a C @code{for}-loop is | |
2619 | written before the body of the loop. The @code{until} command appeared | |
2620 | to step back to the beginning of the loop when it advanced to this | |
2621 | expression; however, it has not really gone to an earlier | |
2622 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2623 | |
2624 | @code{until} with no argument works by means of single | |
2625 | instruction stepping, and hence is slower than @code{until} with an | |
2626 | argument. | |
2627 | ||
2628 | @item until @var{location} | |
2629 | @item u @var{location} | |
29a2b744 RP |
2630 | Continue running your program until either the specified location is |
2631 | reached, or the current stack frame returns. @var{location} is any of | |
2632 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
2633 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
1041a570 | 2634 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
2635 | |
2636 | @item stepi | |
2637 | @itemx si | |
2638 | @kindex stepi | |
2639 | @kindex si | |
2640 | Execute one machine instruction, then stop and return to the debugger. | |
2641 | ||
2642 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2643 | instructions. This will cause the next instruction to be executed to | |
29a2b744 RP |
2644 | be displayed automatically at each stop. @xref{Auto Display, |
2645 | ,Automatic Display}. | |
70b88761 RP |
2646 | |
2647 | An argument is a repeat count, as in @code{step}. | |
2648 | ||
2649 | @item nexti | |
2650 | @itemx ni | |
2651 | @kindex nexti | |
2652 | @kindex ni | |
2653 | Execute one machine instruction, but if it is a function call, | |
2654 | proceed until the function returns. | |
2655 | ||
2656 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
2657 | @end table |
2658 | ||
4eb4cf57 RP |
2659 | _if__(_GENERIC__ || !_H8__) |
2660 | @node Signals | |
70b88761 RP |
2661 | @section Signals |
2662 | @cindex signals | |
2663 | ||
2664 | A signal is an asynchronous event that can happen in a program. The | |
2665 | operating system defines the possible kinds of signals, and gives each | |
2666 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2667 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2668 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2669 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 2670 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
2671 | requested an alarm). |
2672 | ||
2673 | @cindex fatal signals | |
2674 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
2675 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
2676 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 2677 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 2678 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
2679 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
2680 | ||
29a2b744 RP |
2681 | _GDBN__ has the ability to detect any occurrence of a signal in your |
2682 | program. You can tell _GDBN__ in advance what to do for each kind of | |
2683 | signal. | |
70b88761 RP |
2684 | |
2685 | @cindex handling signals | |
2686 | Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM} | |
29a2b744 RP |
2687 | (so as not to interfere with their role in the functioning of your program) |
2688 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
2689 | You can change these settings with the @code{handle} command. |
2690 | ||
2691 | @table @code | |
2692 | @item info signals | |
2693 | @kindex info signals | |
2694 | Print a table of all the kinds of signals and how _GDBN__ has been told to | |
2695 | handle each one. You can use this to see the signal numbers of all | |
2696 | the defined types of signals. | |
2697 | ||
2698 | @item handle @var{signal} @var{keywords}@dots{} | |
2699 | @kindex handle | |
2700 | Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the | |
2701 | number of a signal or its name (with or without the @samp{SIG} at the | |
2702 | beginning). The @var{keywords} say what change to make. | |
2703 | @end table | |
2704 | ||
2705 | @c @group | |
2706 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2707 | Their full names are: | |
2708 | ||
2709 | @table @code | |
2710 | @item nostop | |
29a2b744 | 2711 | _GDBN__ should not stop your program when this signal happens. It may |
70b88761 RP |
2712 | still print a message telling you that the signal has come in. |
2713 | ||
2714 | @item stop | |
29a2b744 | 2715 | _GDBN__ should stop your program when this signal happens. This implies |
70b88761 RP |
2716 | the @code{print} keyword as well. |
2717 | ||
2718 | @item print | |
2719 | _GDBN__ should print a message when this signal happens. | |
2720 | ||
2721 | @item noprint | |
2722 | _GDBN__ should not mention the occurrence of the signal at all. This | |
2723 | implies the @code{nostop} keyword as well. | |
2724 | ||
2725 | @item pass | |
29a2b744 | 2726 | _GDBN__ should allow your program to see this signal; your program will be |
70b88761 RP |
2727 | able to handle the signal, or may be terminated if the signal is fatal |
2728 | and not handled. | |
2729 | ||
2730 | @item nopass | |
29a2b744 | 2731 | _GDBN__ should not allow your program to see this signal. |
70b88761 RP |
2732 | @end table |
2733 | @c @end group | |
2734 | ||
29a2b744 | 2735 | When a signal has been set to stop your program, your program cannot see the |
70b88761 | 2736 | signal until you continue. It will see the signal then, if @code{pass} is |
6ca72cc6 | 2737 | in effect for the signal in question @emph{at that time}. In other words, |
70b88761 RP |
2738 | after _GDBN__ reports a signal, you can use the @code{handle} command with |
2739 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
29a2b744 | 2740 | your program when you later continue it. |
70b88761 | 2741 | |
29a2b744 | 2742 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 2743 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 2744 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
2745 | due to some sort of memory reference error, you might store correct |
2746 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
2747 | execution; but your program would probably terminate immediately as |
2748 | a result of the fatal signal once it saw the signal. To prevent this, | |
2749 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
2750 | Program a Signal}. | |
4eb4cf57 | 2751 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 2752 | |
4eb4cf57 | 2753 | @node Stack |
70b88761 RP |
2754 | @chapter Examining the Stack |
2755 | ||
2756 | When your program has stopped, the first thing you need to know is where it | |
2757 | stopped and how it got there. | |
2758 | ||
2759 | @cindex call stack | |
2760 | Each time your program performs a function call, the information about | |
29a2b744 | 2761 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
2762 | called a @dfn{stack frame}. The frame also contains the arguments of the |
2763 | call and the local variables of the function that was called. All the | |
2764 | stack frames are allocated in a region of memory called the @dfn{call | |
2765 | stack}. | |
2766 | ||
2767 | When your program stops, the _GDBN__ commands for examining the stack allow you | |
2768 | to see all of this information. | |
2769 | ||
2770 | @cindex selected frame | |
2771 | One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands | |
2772 | refer implicitly to the selected frame. In particular, whenever you ask | |
29a2b744 | 2773 | _GDBN__ for the value of a variable in your program, the value is found in the |
70b88761 RP |
2774 | selected frame. There are special _GDBN__ commands to select whichever frame |
2775 | you are interested in. | |
2776 | ||
29a2b744 | 2777 | When your program stops, _GDBN__ automatically selects the currently executing |
70b88761 | 2778 | frame and describes it briefly as the @code{frame} command does |
29a2b744 | 2779 | (@pxref{Frame Info, ,Information About a Frame}). |
70b88761 RP |
2780 | |
2781 | @menu | |
b80282d5 RP |
2782 | * Frames:: Stack Frames |
2783 | * Backtrace:: Backtraces | |
2784 | * Selection:: Selecting a Frame | |
2785 | * Frame Info:: Information on a Frame | |
70b88761 RP |
2786 | @end menu |
2787 | ||
4eb4cf57 | 2788 | @node Frames |
70b88761 RP |
2789 | @section Stack Frames |
2790 | ||
2791 | @cindex frame | |
2792 | @cindex stack frame | |
2793 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2794 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2795 | with one call to one function. The frame contains the arguments given | |
2796 | to the function, the function's local variables, and the address at | |
2797 | which the function is executing. | |
2798 | ||
2799 | @cindex initial frame | |
2800 | @cindex outermost frame | |
2801 | @cindex innermost frame | |
2802 | When your program is started, the stack has only one frame, that of the | |
2803 | function @code{main}. This is called the @dfn{initial} frame or the | |
2804 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2805 | made. Each time a function returns, the frame for that function invocation | |
2806 | is eliminated. If a function is recursive, there can be many frames for | |
2807 | the same function. The frame for the function in which execution is | |
2808 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2809 | recently created of all the stack frames that still exist. | |
2810 | ||
2811 | @cindex frame pointer | |
2812 | Inside your program, stack frames are identified by their addresses. A | |
2813 | stack frame consists of many bytes, each of which has its own address; each | |
2814 | kind of computer has a convention for choosing one of those bytes whose | |
2815 | address serves as the address of the frame. Usually this address is kept | |
2816 | in a register called the @dfn{frame pointer register} while execution is | |
2817 | going on in that frame. | |
2818 | ||
2819 | @cindex frame number | |
2820 | _GDBN__ assigns numbers to all existing stack frames, starting with | |
2821 | zero for the innermost frame, one for the frame that called it, | |
2822 | and so on upward. These numbers do not really exist in your program; | |
2823 | they are assigned by _GDBN__ to give you a way of designating stack | |
2824 | frames in _GDBN__ commands. | |
2825 | ||
2826 | @cindex frameless execution | |
2827 | Some compilers allow functions to be compiled so that they operate | |
2828 | without stack frames. (For example, the @code{_GCC__} option | |
2829 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2830 | This is occasionally done with heavily used library functions to save | |
2831 | the frame setup time. _GDBN__ has limited facilities for dealing with | |
2832 | these function invocations. If the innermost function invocation has no | |
2833 | stack frame, _GDBN__ will nevertheless regard it as though it had a | |
2834 | separate frame, which is numbered zero as usual, allowing correct | |
2835 | tracing of the function call chain. However, _GDBN__ has no provision | |
2836 | for frameless functions elsewhere in the stack. | |
2837 | ||
4eb4cf57 | 2838 | @node Backtrace |
70b88761 RP |
2839 | @section Backtraces |
2840 | ||
29a2b744 | 2841 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
2842 | line per frame, for many frames, starting with the currently executing |
2843 | frame (frame zero), followed by its caller (frame one), and on up the | |
2844 | stack. | |
2845 | ||
2846 | @table @code | |
2847 | @item backtrace | |
2848 | @itemx bt | |
2849 | @kindex backtrace | |
2850 | @kindex bt | |
2851 | Print a backtrace of the entire stack: one line per frame for all | |
2852 | frames in the stack. | |
2853 | ||
2854 | You can stop the backtrace at any time by typing the system interrupt | |
2855 | character, normally @kbd{C-c}. | |
2856 | ||
2857 | @item backtrace @var{n} | |
2858 | @itemx bt @var{n} | |
2859 | Similar, but print only the innermost @var{n} frames. | |
2860 | ||
2861 | @item backtrace -@var{n} | |
2862 | @itemx bt -@var{n} | |
2863 | Similar, but print only the outermost @var{n} frames. | |
2864 | @end table | |
2865 | ||
2866 | @kindex where | |
2867 | @kindex info stack | |
2868 | @kindex info s | |
2869 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
2870 | are additional aliases for @code{backtrace}. | |
2871 | ||
2872 | Each line in the backtrace shows the frame number and the function name. | |
2873 | The program counter value is also shown---unless you use @code{set | |
2874 | print address off}. The backtrace also shows the source file name and | |
2875 | line number, as well as the arguments to the function. The program | |
2876 | counter value is omitted if it is at the beginning of the code for that | |
2877 | line number. | |
2878 | ||
2879 | Here is an example of a backtrace. It was made with the command | |
2880 | @samp{bt 3}, so it shows the innermost three frames. | |
2881 | ||
2882 | @smallexample | |
2883 | @group | |
203eea5d RP |
2884 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
2885 | at builtin.c:993 | |
70b88761 RP |
2886 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
2887 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
2888 | at macro.c:71 | |
2889 | (More stack frames follow...) | |
2890 | @end group | |
2891 | @end smallexample | |
2892 | ||
2893 | @noindent | |
29a2b744 RP |
2894 | The display for frame zero does not begin with a program counter |
2895 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
2896 | code for line @code{993} of @code{builtin.c}. |
2897 | ||
4eb4cf57 | 2898 | @node Selection |
70b88761 RP |
2899 | @section Selecting a Frame |
2900 | ||
29a2b744 | 2901 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
2902 | whichever stack frame is selected at the moment. Here are the commands for |
2903 | selecting a stack frame; all of them finish by printing a brief description | |
2904 | of the stack frame just selected. | |
2905 | ||
2906 | @table @code | |
2907 | @item frame @var{n} | |
2908 | @itemx f @var{n} | |
2909 | @kindex frame | |
2910 | @kindex f | |
2911 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2912 | (currently executing) frame, frame one is the frame that called the | |
2913 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2914 | frame. | |
2915 | ||
2916 | @item frame @var{addr} | |
2917 | @itemx f @var{addr} | |
2918 | Select the frame at address @var{addr}. This is useful mainly if the | |
2919 | chaining of stack frames has been damaged by a bug, making it | |
2920 | impossible for _GDBN__ to assign numbers properly to all frames. In | |
29a2b744 | 2921 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
2922 | switches between them. |
2923 | ||
c728f1f0 | 2924 | _if__(_SPARC__) |
70b88761 | 2925 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 2926 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
2927 | @c note to future updaters: this is conditioned on a flag |
2928 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
2929 | @c by SPARC, hence the specific attribution. Generalize or list all | |
2930 | @c possibilities if more supported machines start doing this. | |
c728f1f0 | 2931 | _fi__(_SPARC__) |
70b88761 RP |
2932 | |
2933 | @item up @var{n} | |
2934 | @kindex up | |
2935 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
2936 | advances toward the outermost frame, to higher frame numbers, to frames | |
2937 | that have existed longer. @var{n} defaults to one. | |
2938 | ||
2939 | @item down @var{n} | |
2940 | @kindex down | |
2941 | @kindex do | |
2942 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
2943 | advances toward the innermost frame, to lower frame numbers, to frames | |
2944 | that were created more recently. @var{n} defaults to one. You may | |
2945 | abbreviate @code{down} as @code{do}. | |
2946 | @end table | |
2947 | ||
2948 | All of these commands end by printing two lines of output describing the | |
2949 | frame. The first line shows the frame number, the function name, the | |
2950 | arguments, and the source file and line number of execution in that | |
2951 | frame. The second line shows the text of that source line. For | |
2952 | example: | |
2953 | ||
2954 | @smallexample | |
29a2b744 | 2955 | @group |
70b88761 | 2956 | (_GDBP__) up |
203eea5d RP |
2957 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
2958 | at env.c:10 | |
70b88761 | 2959 | 10 read_input_file (argv[i]); |
29a2b744 | 2960 | @end group |
70b88761 RP |
2961 | @end smallexample |
2962 | ||
29a2b744 RP |
2963 | After such a printout, the @code{list} command with no arguments will |
2964 | print ten lines centered on the point of execution in the frame. | |
2965 | @xref{List, ,Printing Source Lines}. | |
70b88761 RP |
2966 | |
2967 | @table @code | |
2968 | @item up-silently @var{n} | |
2969 | @itemx down-silently @var{n} | |
2970 | @kindex down-silently | |
2971 | @kindex up-silently | |
2972 | These two commands are variants of @code{up} and @code{down}, | |
2973 | respectively; they differ in that they do their work silently, without | |
2974 | causing display of the new frame. They are intended primarily for use | |
2975 | in _GDBN__ command scripts, where the output might be unnecessary and | |
e251e767 | 2976 | distracting. |
70b88761 RP |
2977 | @end table |
2978 | ||
4eb4cf57 | 2979 | @node Frame Info |
70b88761 RP |
2980 | @section Information About a Frame |
2981 | ||
2982 | There are several other commands to print information about the selected | |
2983 | stack frame. | |
2984 | ||
2985 | @table @code | |
2986 | @item frame | |
2987 | @itemx f | |
29a2b744 RP |
2988 | When used without any argument, this command does not change which |
2989 | frame is selected, but prints a brief description of the currently | |
70b88761 | 2990 | selected stack frame. It can be abbreviated @code{f}. With an |
29a2b744 RP |
2991 | argument, this command is used to select a stack frame |
2992 | (@pxref{Selection, ,Selecting a Frame}). | |
70b88761 RP |
2993 | |
2994 | @item info frame | |
70b88761 | 2995 | @itemx info f |
29a2b744 | 2996 | @kindex info frame |
70b88761 RP |
2997 | @kindex info f |
2998 | This command prints a verbose description of the selected stack frame, | |
2999 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
3000 | (called by this frame) and the next frame up (caller of this frame), the |
3001 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
3002 | the address of the frame's arguments, the program counter saved in it |
3003 | (the address of execution in the caller frame), and which registers | |
3004 | were saved in the frame. The verbose description is useful when | |
3005 | something has gone wrong that has made the stack format fail to fit | |
3006 | the usual conventions. | |
3007 | ||
3008 | @item info frame @var{addr} | |
3009 | @itemx info f @var{addr} | |
3010 | Print a verbose description of the frame at address @var{addr}, | |
3011 | without selecting that frame. The selected frame remains unchanged by | |
3012 | this command. | |
3013 | ||
3014 | @item info args | |
3015 | @kindex info args | |
3016 | Print the arguments of the selected frame, each on a separate line. | |
3017 | ||
3018 | @item info locals | |
3019 | @kindex info locals | |
3020 | Print the local variables of the selected frame, each on a separate | |
3021 | line. These are all variables declared static or automatic within all | |
3022 | program blocks that execution in this frame is currently inside of. | |
3023 | ||
3024 | @item info catch | |
3025 | @kindex info catch | |
3026 | @cindex catch exceptions | |
3027 | @cindex exception handlers | |
3028 | Print a list of all the exception handlers that are active in the | |
3029 | current stack frame at the current point of execution. To see other | |
3030 | exception handlers, visit the associated frame (using the @code{up}, | |
3031 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
1041a570 | 3032 | @xref{Exception Handling, ,Breakpoints and Exceptions}. |
70b88761 RP |
3033 | @end table |
3034 | ||
4eb4cf57 | 3035 | @node Source |
70b88761 RP |
3036 | @chapter Examining Source Files |
3037 | ||
3038 | _GDBN__ can print parts of your program's source, since the debugging | |
1041a570 RP |
3039 | information recorded in your program tells _GDBN__ what source files were |
3040 | used to build it. When your program stops, _GDBN__ spontaneously prints | |
3041 | the line where it stopped. Likewise, when you select a stack frame | |
3042 | (@pxref{Selection, ,Selecting a Frame}), _GDBN__ prints the line where | |
3043 | execution in that frame has stopped. You can print other portions of | |
3044 | source files by explicit command. | |
70b88761 | 3045 | |
4eb4cf57 | 3046 | _if__(!_DOSHOST__) |
1041a570 RP |
3047 | If you use _GDBN__ through its GNU Emacs interface, you may prefer to use |
3048 | Emacs facilities to view source; @pxref{Emacs, ,Using _GDBN__ under GNU | |
3049 | Emacs}. | |
4eb4cf57 | 3050 | _fi__(!_DOSHOST__) |
70b88761 RP |
3051 | |
3052 | @menu | |
b80282d5 | 3053 | * List:: Printing Source Lines |
6f28dd0b | 3054 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 3055 | * Search:: Searching Source Files |
6f28dd0b | 3056 | _fi__(_GENERIC__ || !_H8__) |
b80282d5 RP |
3057 | * Source Path:: Specifying Source Directories |
3058 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
3059 | @end menu |
3060 | ||
4eb4cf57 | 3061 | @node List |
70b88761 RP |
3062 | @section Printing Source Lines |
3063 | ||
3064 | @kindex list | |
3065 | @kindex l | |
3066 | To print lines from a source file, use the @code{list} command | |
3067 | (abbreviated @code{l}). There are several ways to specify what part | |
3068 | of the file you want to print. | |
3069 | ||
3070 | Here are the forms of the @code{list} command most commonly used: | |
3071 | ||
3072 | @table @code | |
3073 | @item list @var{linenum} | |
c338a2fd | 3074 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
3075 | current source file. |
3076 | ||
3077 | @item list @var{function} | |
c338a2fd | 3078 | Print lines centered around the beginning of function |
70b88761 RP |
3079 | @var{function}. |
3080 | ||
3081 | @item list | |
c338a2fd RP |
3082 | Print more lines. If the last lines printed were printed with a |
3083 | @code{list} command, this prints lines following the last lines | |
70b88761 | 3084 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 3085 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 3086 | Stack}), this prints lines centered around that line. |
70b88761 RP |
3087 | |
3088 | @item list - | |
c338a2fd RP |
3089 | Print lines just before the lines last printed. |
3090 | @end table | |
3091 | ||
3092 | By default, _GDBN__ prints ten source lines with any of these forms of | |
3093 | the @code{list} command. You can change this using @code{set listsize}: | |
3094 | ||
3095 | @table @code | |
3096 | @item set listsize @var{count} | |
3097 | @kindex set listsize | |
3098 | Make the @code{list} command display @var{count} source lines (unless | |
3099 | the @code{list} argument explicitly specifies some other number). | |
3100 | ||
3101 | @item show listsize | |
3102 | @kindex show listsize | |
3103 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 3104 | default. |
70b88761 RP |
3105 | @end table |
3106 | ||
3107 | Repeating a @code{list} command with @key{RET} discards the argument, | |
3108 | so it is equivalent to typing just @code{list}. This is more useful | |
3109 | than listing the same lines again. An exception is made for an | |
3110 | argument of @samp{-}; that argument is preserved in repetition so that | |
3111 | each repetition moves up in the source file. | |
3112 | ||
3113 | @cindex linespec | |
3114 | In general, the @code{list} command expects you to supply zero, one or two | |
3115 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
3116 | of writing them but the effect is always to specify some source line. | |
3117 | Here is a complete description of the possible arguments for @code{list}: | |
3118 | ||
3119 | @table @code | |
3120 | @item list @var{linespec} | |
c338a2fd | 3121 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
3122 | |
3123 | @item list @var{first},@var{last} | |
3124 | Print lines from @var{first} to @var{last}. Both arguments are | |
3125 | linespecs. | |
3126 | ||
3127 | @item list ,@var{last} | |
c338a2fd | 3128 | Print lines ending with @var{last}. |
70b88761 RP |
3129 | |
3130 | @item list @var{first}, | |
c338a2fd | 3131 | Print lines starting with @var{first}. |
70b88761 RP |
3132 | |
3133 | @item list + | |
c338a2fd | 3134 | Print lines just after the lines last printed. |
70b88761 RP |
3135 | |
3136 | @item list - | |
c338a2fd | 3137 | Print lines just before the lines last printed. |
70b88761 RP |
3138 | |
3139 | @item list | |
3140 | As described in the preceding table. | |
3141 | @end table | |
3142 | ||
3143 | Here are the ways of specifying a single source line---all the | |
3144 | kinds of linespec. | |
3145 | ||
3146 | @table @code | |
3147 | @item @var{number} | |
3148 | Specifies line @var{number} of the current source file. | |
3149 | When a @code{list} command has two linespecs, this refers to | |
3150 | the same source file as the first linespec. | |
3151 | ||
3152 | @item +@var{offset} | |
3153 | Specifies the line @var{offset} lines after the last line printed. | |
3154 | When used as the second linespec in a @code{list} command that has | |
3155 | two, this specifies the line @var{offset} lines down from the | |
3156 | first linespec. | |
3157 | ||
3158 | @item -@var{offset} | |
3159 | Specifies the line @var{offset} lines before the last line printed. | |
3160 | ||
3161 | @item @var{filename}:@var{number} | |
3162 | Specifies line @var{number} in the source file @var{filename}. | |
3163 | ||
3164 | @item @var{function} | |
3165 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
3166 | Specifies the line of the open-brace that begins the body of the | |
3167 | function @var{function}. | |
3168 | ||
3169 | @item @var{filename}:@var{function} | |
3170 | Specifies the line of the open-brace that begins the body of the | |
3171 | function @var{function} in the file @var{filename}. You only need the | |
3172 | file name with a function name to avoid ambiguity when there are | |
3173 | identically named functions in different source files. | |
3174 | ||
3175 | @item *@var{address} | |
3176 | Specifies the line containing the program address @var{address}. | |
3177 | @var{address} may be any expression. | |
3178 | @end table | |
3179 | ||
6f28dd0b | 3180 | _if__(_GENERIC__ || !_H8__) |
4eb4cf57 | 3181 | @node Search |
70b88761 RP |
3182 | @section Searching Source Files |
3183 | @cindex searching | |
3184 | @kindex reverse-search | |
3185 | ||
3186 | There are two commands for searching through the current source file for a | |
3187 | regular expression. | |
3188 | ||
3189 | @table @code | |
3190 | @item forward-search @var{regexp} | |
3191 | @itemx search @var{regexp} | |
3192 | @kindex search | |
3193 | @kindex forward-search | |
1041a570 RP |
3194 | The command @samp{forward-search @var{regexp}} checks each line, |
3195 | starting with the one following the last line listed, for a match for | |
3196 | @var{regexp}. It lists the line that is found. You can use | |
3197 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3198 | @code{fo}. | |
70b88761 RP |
3199 | |
3200 | @item reverse-search @var{regexp} | |
3201 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3202 | with the one before the last line listed and going backward, for a match | |
3203 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3204 | this command as @code{rev}. | |
3205 | @end table | |
6f28dd0b | 3206 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 3207 | |
4eb4cf57 | 3208 | @node Source Path |
70b88761 RP |
3209 | @section Specifying Source Directories |
3210 | ||
3211 | @cindex source path | |
3212 | @cindex directories for source files | |
3213 | Executable programs sometimes do not record the directories of the source | |
3214 | files from which they were compiled, just the names. Even when they do, | |
3215 | the directories could be moved between the compilation and your debugging | |
3216 | session. _GDBN__ has a list of directories to search for source files; | |
3217 | this is called the @dfn{source path}. Each time _GDBN__ wants a source file, | |
3218 | it tries all the directories in the list, in the order they are present | |
3219 | in the list, until it finds a file with the desired name. Note that | |
3220 | the executable search path is @emph{not} used for this purpose. Neither is | |
3221 | the current working directory, unless it happens to be in the source | |
3222 | path. | |
3223 | ||
29a2b744 | 3224 | If _GDBN__ cannot find a source file in the source path, and the object |
70b88761 RP |
3225 | program records a directory, _GDBN__ tries that directory too. If the |
3226 | source path is empty, and there is no record of the compilation | |
3227 | directory, _GDBN__ will, as a last resort, look in the current | |
3228 | directory. | |
3229 | ||
3230 | Whenever you reset or rearrange the source path, _GDBN__ will clear out | |
3231 | any information it has cached about where source files are found, where | |
3232 | each line is in the file, etc. | |
3233 | ||
3234 | @kindex directory | |
3235 | When you start _GDBN__, its source path is empty. | |
3236 | To add other directories, use the @code{directory} command. | |
3237 | ||
3238 | @table @code | |
3239 | @item directory @var{dirname} @dots{} | |
3240 | Add directory @var{dirname} to the front of the source path. Several | |
3241 | directory names may be given to this command, separated by @samp{:} or | |
3242 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 3243 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
3244 | |
3245 | You can use the string @samp{$cdir} to refer to the compilation | |
3246 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3247 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
3248 | tracks the current working directory as it changes during your _GDBN__ | |
3249 | session, while the latter is immediately expanded to the current | |
3250 | directory at the time you add an entry to the source path. | |
70b88761 RP |
3251 | |
3252 | @item directory | |
3253 | Reset the source path to empty again. This requires confirmation. | |
3254 | ||
3255 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 3256 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
3257 | |
3258 | @item show directories | |
3259 | @kindex show directories | |
3260 | Print the source path: show which directories it contains. | |
3261 | @end table | |
3262 | ||
3263 | If your source path is cluttered with directories that are no longer of | |
3264 | interest, _GDBN__ may sometimes cause confusion by finding the wrong | |
3265 | versions of source. You can correct the situation as follows: | |
3266 | ||
3267 | @enumerate | |
3268 | @item | |
3269 | Use @code{directory} with no argument to reset the source path to empty. | |
3270 | ||
3271 | @item | |
3272 | Use @code{directory} with suitable arguments to reinstall the | |
3273 | directories you want in the source path. You can add all the | |
3274 | directories in one command. | |
3275 | @end enumerate | |
3276 | ||
4eb4cf57 | 3277 | @node Machine Code |
70b88761 | 3278 | @section Source and Machine Code |
1041a570 | 3279 | |
70b88761 RP |
3280 | You can use the command @code{info line} to map source lines to program |
3281 | addresses (and viceversa), and the command @code{disassemble} to display | |
3282 | a range of addresses as machine instructions. | |
3283 | ||
3284 | @table @code | |
3285 | @item info line @var{linespec} | |
3286 | @kindex info line | |
3287 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
3288 | source line @var{linespec}. You can specify source lines in any of |
3289 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
3290 | Source Lines}). | |
70b88761 RP |
3291 | @end table |
3292 | ||
1041a570 RP |
3293 | For example, we can use @code{info line} to discover the location of |
3294 | the object code for the first line of function | |
3295 | @code{m4_changequote}: | |
3296 | ||
70b88761 RP |
3297 | @smallexample |
3298 | (_GDBP__) info line m4_changecom | |
3299 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
3300 | @end smallexample | |
3301 | ||
3302 | @noindent | |
3303 | We can also inquire (using @code{*@var{addr}} as the form for | |
3304 | @var{linespec}) what source line covers a particular address: | |
3305 | @smallexample | |
3306 | (_GDBP__) info line *0x63ff | |
3307 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
3308 | @end smallexample | |
3309 | ||
c338a2fd | 3310 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
3311 | After @code{info line}, the default address for the @code{x} command |
3312 | is changed to the starting address of the line, so that @samp{x/i} is | |
3313 | sufficient to begin examining the machine code (@pxref{Memory, | |
3314 | ,Examining Memory}). Also, this address is saved as the value of the | |
3315 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
3316 | Variables}). | |
70b88761 RP |
3317 | |
3318 | @table @code | |
3319 | @kindex disassemble | |
3320 | @item disassemble | |
e94b4a2b RP |
3321 | This specialized command dumps a range of memory as machine |
3322 | instructions. The default memory range is the function surrounding the | |
3323 | program counter of the selected frame. A single argument to this | |
3324 | command is a program counter value; the function surrounding this value | |
3325 | will be dumped. Two arguments specify a range of addresses (first | |
3326 | inclusive, second exclusive) to dump. | |
70b88761 RP |
3327 | @end table |
3328 | ||
4eb4cf57 | 3329 | _if__(_GENERIC__||!_H8__) |
70b88761 | 3330 | We can use @code{disassemble} to inspect the object code |
4eb4cf57 RP |
3331 | range shown in the last @code{info line} example (the example |
3332 | shows SPARC machine instructions): | |
70b88761 | 3333 | |
4eb4cf57 | 3334 | _0__ |
70b88761 RP |
3335 | @smallexample |
3336 | (_GDBP__) disas 0x63e4 0x6404 | |
3337 | Dump of assembler code from 0x63e4 to 0x6404: | |
b80282d5 RP |
3338 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
3339 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
3340 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
3341 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
3342 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
3343 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
3344 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 3345 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 3346 | End of assembler dump. |
70b88761 | 3347 | @end smallexample |
4eb4cf57 RP |
3348 | _1__ |
3349 | _fi__(_GENERIC__||!_H8__) | |
3350 | ||
3351 | _if__(!_GENERIC__||_H8__) | |
3352 | For example, here is the beginning of the output for the | |
3353 | disassembly of a function @code{fact}: | |
70b88761 | 3354 | |
4eb4cf57 RP |
3355 | _0__ |
3356 | @smallexample | |
3357 | (_GDBP__) disas fact | |
3358 | Dump of assembler code for function fact: | |
3359 | to 0x808c: | |
3360 | 0x802c <fact>: 6d f2 mov.w r2,@@-r7 | |
3361 | 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7 | |
3362 | 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7 | |
3363 | 0x8032 <fact+6>: 0d 76 mov.w r7,r6 | |
3364 | 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0 | |
3365 | 0x8038 <fact+12> 19 11 sub.w r1,r1 | |
3366 | . | |
3367 | . | |
3368 | . | |
3369 | @end smallexample | |
3370 | _1__ | |
3371 | _fi__(!_GENERIC__||_H8__) | |
3372 | ||
3373 | ||
3374 | @node Data | |
70b88761 RP |
3375 | @chapter Examining Data |
3376 | ||
3377 | @cindex printing data | |
3378 | @cindex examining data | |
3379 | @kindex print | |
3380 | @kindex inspect | |
1041a570 | 3381 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 3382 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
3383 | @c different window or something like that. |
3384 | The usual way to examine data in your program is with the @code{print} | |
4eb4cf57 RP |
3385 | command (abbreviated @code{p}), or its synonym @code{inspect}. |
3386 | _if__(!_CONLY__) | |
3387 | It evaluates and prints the value of an expression of the language your | |
1041a570 | 3388 | program is written in (@pxref{Languages, ,Using _GDBN__ with Different |
4eb4cf57 RP |
3389 | Languages}). |
3390 | _fi__(!_CONLY__) | |
70b88761 | 3391 | |
e0dacfd1 RP |
3392 | @table @code |
3393 | @item print @var{exp} | |
3394 | @itemx print /@var{f} @var{exp} | |
3395 | @var{exp} is an expression (in the source language). By default | |
70b88761 | 3396 | the value of @var{exp} is printed in a format appropriate to its data |
e0dacfd1 RP |
3397 | type; you can choose a different format by specifying @samp{/@var{f}}, |
3398 | where @var{f} is a letter specifying the format; @pxref{Output formats}. | |
3399 | ||
3400 | @item print | |
3401 | @itemx print /@var{f} | |
3402 | If you omit @var{exp}, _GDBN__ displays the last value again (from the | |
1041a570 | 3403 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to |
e0dacfd1 RP |
3404 | conveniently inspect the same value in an alternative format. |
3405 | @end table | |
70b88761 RP |
3406 | |
3407 | A more low-level way of examining data is with the @code{x} command. | |
3408 | It examines data in memory at a specified address and prints it in a | |
29a2b744 | 3409 | specified format. @xref{Memory, ,Examining Memory}. |
70b88761 | 3410 | |
29a2b744 | 3411 | If you are interested in information about types, or about how the fields |
b80282d5 | 3412 | of a struct or class are declared, use the @code{ptype @var{exp}} |
1041a570 | 3413 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 | 3414 | |
70b88761 | 3415 | @menu |
b80282d5 RP |
3416 | * Expressions:: Expressions |
3417 | * Variables:: Program Variables | |
3418 | * Arrays:: Artificial Arrays | |
3419 | * Output formats:: Output formats | |
3420 | * Memory:: Examining Memory | |
3421 | * Auto Display:: Automatic Display | |
3422 | * Print Settings:: Print Settings | |
3423 | * Value History:: Value History | |
3424 | * Convenience Vars:: Convenience Variables | |
3425 | * Registers:: Registers | |
4eb4cf57 | 3426 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 3427 | * Floating Point Hardware:: Floating Point Hardware |
4eb4cf57 | 3428 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
3429 | @end menu |
3430 | ||
4eb4cf57 | 3431 | @node Expressions |
70b88761 RP |
3432 | @section Expressions |
3433 | ||
3434 | @cindex expressions | |
3435 | @code{print} and many other _GDBN__ commands accept an expression and | |
3436 | compute its value. Any kind of constant, variable or operator defined | |
3437 | by the programming language you are using is legal in an expression in | |
3438 | _GDBN__. This includes conditional expressions, function calls, casts | |
3439 | and string constants. It unfortunately does not include symbols defined | |
b80282d5 | 3440 | by preprocessor @code{#define} commands. |
70b88761 | 3441 | |
4eb4cf57 | 3442 | _if__(!_CONLY__) |
c2bbbb22 | 3443 | Because C is so widespread, most of the expressions shown in examples in |
1041a570 | 3444 | this manual are in C. @xref{Languages, , Using _GDBN__ with Different |
c2bbbb22 | 3445 | Languages}, for information on how to use expressions in other |
e251e767 | 3446 | languages. |
c2bbbb22 RP |
3447 | |
3448 | In this section, we discuss operators that you can use in _GDBN__ | |
e251e767 | 3449 | expressions regardless of your programming language. |
c2bbbb22 | 3450 | |
70b88761 RP |
3451 | Casts are supported in all languages, not just in C, because it is so |
3452 | useful to cast a number into a pointer so as to examine a structure | |
3453 | at that address in memory. | |
c2bbbb22 | 3454 | @c FIXME: casts supported---Mod2 true? |
4eb4cf57 | 3455 | _fi__(!_CONLY__) |
70b88761 | 3456 | |
c2bbbb22 | 3457 | _GDBN__ supports these operators in addition to those of programming |
70b88761 RP |
3458 | languages: |
3459 | ||
3460 | @table @code | |
3461 | @item @@ | |
3462 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
1041a570 | 3463 | @xref{Arrays, ,Artificial Arrays}, for more information. |
70b88761 RP |
3464 | |
3465 | @item :: | |
3466 | @samp{::} allows you to specify a variable in terms of the file or | |
1041a570 | 3467 | function where it is defined. @xref{Variables, ,Program Variables}. |
70b88761 RP |
3468 | |
3469 | @item @{@var{type}@} @var{addr} | |
3470 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3471 | memory. @var{addr} may be any expression whose value is an integer or | |
3472 | pointer (but parentheses are required around binary operators, just as in | |
3473 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 3474 | normally supposed to reside at @var{addr}. |
70b88761 RP |
3475 | @end table |
3476 | ||
4eb4cf57 | 3477 | @node Variables |
70b88761 RP |
3478 | @section Program Variables |
3479 | ||
3480 | The most common kind of expression to use is the name of a variable | |
3481 | in your program. | |
3482 | ||
3483 | Variables in expressions are understood in the selected stack frame | |
29a2b744 RP |
3484 | (@pxref{Selection, ,Selecting a Frame}); they must either be global |
3485 | (or static) or be visible according to the scope rules of the | |
3486 | programming language from the point of execution in that frame. This | |
3487 | means that in the function | |
70b88761 RP |
3488 | |
3489 | @example | |
3490 | foo (a) | |
3491 | int a; | |
3492 | @{ | |
3493 | bar (a); | |
3494 | @{ | |
3495 | int b = test (); | |
3496 | bar (b); | |
3497 | @} | |
3498 | @} | |
3499 | @end example | |
3500 | ||
3501 | @noindent | |
29a2b744 | 3502 | the variable @code{a} is usable whenever your program is executing |
70b88761 | 3503 | within the function @code{foo}, but the variable @code{b} is visible |
29a2b744 | 3504 | only while your program is executing inside the block in which @code{b} |
70b88761 RP |
3505 | is declared. |
3506 | ||
3507 | @cindex variable name conflict | |
3508 | There is an exception: you can refer to a variable or function whose | |
3509 | scope is a single source file even if the current execution point is not | |
3510 | in this file. But it is possible to have more than one such variable or | |
6ca72cc6 RP |
3511 | function with the same name (in different source files). If that |
3512 | happens, referring to that name has unpredictable effects. If you wish, | |
3513 | you can specify a static variable in a particular function or file, | |
3514 | using the colon-colon notation: | |
70b88761 RP |
3515 | |
3516 | @cindex colon-colon | |
a6d0b6d3 | 3517 | @iftex |
29a2b744 | 3518 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 3519 | @kindex :: |
a6d0b6d3 | 3520 | @end iftex |
70b88761 RP |
3521 | @example |
3522 | @var{file}::@var{variable} | |
6ca72cc6 | 3523 | @var{function}::@var{variable} |
70b88761 RP |
3524 | @end example |
3525 | ||
3526 | @noindent | |
6ca72cc6 | 3527 | Here @var{file} or @var{function} is the name of the context for the |
6c380b13 RP |
3528 | static @var{variable}. In the case of file names, you can use quotes to |
3529 | make sure _GDBN__ parses the file name as a single word---for example, | |
3530 | to print a global value of @code{x} defined in @file{f2.c}: | |
3531 | ||
3532 | @example | |
3533 | (_GDBP__) p 'f2.c'::x | |
3534 | @end example | |
70b88761 | 3535 | |
c2bbbb22 | 3536 | @cindex C++ scope resolution |
70b88761 RP |
3537 | This use of @samp{::} is very rarely in conflict with the very similar |
3538 | use of the same notation in C++. _GDBN__ also supports use of the C++ | |
c2bbbb22 | 3539 | scope resolution operator in _GDBN__ expressions. |
70b88761 | 3540 | |
3d3ab540 RP |
3541 | @cindex wrong values |
3542 | @cindex variable values, wrong | |
3543 | @quotation | |
3544 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
3545 | wrong value at certain points in a function---just after entry to the | |
29a2b744 | 3546 | function, and just before exit. You may see this problem when you are |
3d3ab540 RP |
3547 | stepping by machine instructions. This is because on most machines, it |
3548 | takes more than one instruction to set up a stack frame (including local | |
29a2b744 | 3549 | variable definitions); if you are stepping by machine instructions, |
3d3ab540 RP |
3550 | variables may appear to have the wrong values until the stack frame is |
3551 | completely built. On function exit, it usually also takes more than one | |
3552 | machine instruction to destroy a stack frame; after you begin stepping | |
3553 | through that group of instructions, local variable definitions may be | |
3554 | gone. | |
3555 | @end quotation | |
3556 | ||
4eb4cf57 | 3557 | @node Arrays |
70b88761 RP |
3558 | @section Artificial Arrays |
3559 | ||
3560 | @cindex artificial array | |
3561 | @kindex @@ | |
3562 | It is often useful to print out several successive objects of the | |
3563 | same type in memory; a section of an array, or an array of | |
3564 | dynamically determined size for which only a pointer exists in the | |
3565 | program. | |
3566 | ||
3567 | This can be done by constructing an @dfn{artificial array} with the | |
3568 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3569 | the first element of the desired array, as an individual object. | |
3570 | The right operand should be the desired length of the array. The result is | |
3571 | an array value whose elements are all of the type of the left argument. | |
3572 | The first element is actually the left argument; the second element | |
3573 | comes from bytes of memory immediately following those that hold the | |
3574 | first element, and so on. Here is an example. If a program says | |
3575 | ||
3576 | @example | |
3577 | int *array = (int *) malloc (len * sizeof (int)); | |
3578 | @end example | |
3579 | ||
3580 | @noindent | |
3581 | you can print the contents of @code{array} with | |
3582 | ||
3583 | @example | |
3584 | p *array@@len | |
3585 | @end example | |
3586 | ||
3587 | The left operand of @samp{@@} must reside in memory. Array values made | |
3588 | with @samp{@@} in this way behave just like other arrays in terms of | |
3589 | subscripting, and are coerced to pointers when used in expressions. | |
3590 | Artificial arrays most often appear in expressions via the value history | |
1041a570 | 3591 | (@pxref{Value History, ,Value History}), after printing one out.) |
70b88761 | 3592 | |
1041a570 | 3593 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 3594 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
3595 | actually be adjacent---for example, if you are interested in the values |
3596 | of pointers in an array. One useful work-around in this situation is | |
3597 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
3598 | Variables}) as a counter in an expression that prints the first | |
3599 | interesting value, and then repeat that expression via @key{RET}. For | |
3600 | instance, suppose you have an array @code{dtab} of pointers to | |
3601 | structures, and you are interested in the values of a field @code{fv} | |
3602 | in each structure. Here is an example of what you might type: | |
3603 | ||
3d3ab540 RP |
3604 | @example |
3605 | set $i = 0 | |
3606 | p dtab[$i++]->fv | |
3607 | @key{RET} | |
3608 | @key{RET} | |
3609 | @dots{} | |
3610 | @end example | |
3611 | ||
4eb4cf57 | 3612 | @node Output formats |
70b88761 RP |
3613 | @section Output formats |
3614 | ||
3615 | @cindex formatted output | |
3616 | @cindex output formats | |
3617 | By default, _GDBN__ prints a value according to its data type. Sometimes | |
3618 | this is not what you want. For example, you might want to print a number | |
3619 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3620 | at a certain address as a character string or as an instruction. To do | |
3621 | these things, specify an @dfn{output format} when you print a value. | |
3622 | ||
3623 | The simplest use of output formats is to say how to print a value | |
3624 | already computed. This is done by starting the arguments of the | |
3625 | @code{print} command with a slash and a format letter. The format | |
3626 | letters supported are: | |
3627 | ||
3628 | @table @code | |
3629 | @item x | |
3630 | Regard the bits of the value as an integer, and print the integer in | |
3631 | hexadecimal. | |
3632 | ||
3633 | @item d | |
3634 | Print as integer in signed decimal. | |
3635 | ||
3636 | @item u | |
3637 | Print as integer in unsigned decimal. | |
3638 | ||
3639 | @item o | |
3640 | Print as integer in octal. | |
3641 | ||
3642 | @item t | |
3643 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3644 | ||
3645 | @item a | |
3646 | Print as an address, both absolute in hex and as an offset from the | |
3647 | nearest preceding symbol. This format can be used to discover where (in | |
3648 | what function) an unknown address is located: | |
1041a570 | 3649 | |
70b88761 RP |
3650 | @example |
3651 | (_GDBP__) p/a 0x54320 | |
3652 | _0__$3 = 0x54320 <_initialize_vx+396>_1__ | |
3653 | @end example | |
3654 | ||
70b88761 RP |
3655 | @item c |
3656 | Regard as an integer and print it as a character constant. | |
3657 | ||
3658 | @item f | |
3659 | Regard the bits of the value as a floating point number and print | |
3660 | using typical floating point syntax. | |
3661 | @end table | |
3662 | ||
3663 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3664 | ||
3665 | @example | |
3666 | p/x $pc | |
3667 | @end example | |
3668 | ||
3669 | @noindent | |
3670 | Note that no space is required before the slash; this is because command | |
3671 | names in _GDBN__ cannot contain a slash. | |
3672 | ||
3673 | To reprint the last value in the value history with a different format, | |
3674 | you can use the @code{print} command with just a format and no | |
3675 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3676 | ||
4eb4cf57 | 3677 | @node Memory |
70b88761 RP |
3678 | @section Examining Memory |
3679 | ||
1041a570 RP |
3680 | You can use the command @code{x} (for ``examine'') to examine memory in |
3681 | any of several formats, independently of your program's data types. | |
3682 | ||
70b88761 RP |
3683 | @cindex examining memory |
3684 | @table @code | |
3685 | @kindex x | |
cedaf8bc RP |
3686 | @item x/@var{nfu} @var{addr} |
3687 | @itemx x @var{addr} | |
3688 | @itemx x | |
1041a570 RP |
3689 | Use the command @code{x} to examine memory. |
3690 | @end table | |
3691 | ||
3692 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3693 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
3694 | expression giving the address where you want to start displaying memory. |
3695 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3696 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 3697 | |
1041a570 RP |
3698 | @table @r |
3699 | @item @var{n}, the repeat count | |
3700 | The repeat count is a decimal integer; the default is 1. It specifies | |
3701 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
3702 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
3703 | @c 4.1.2. | |
70b88761 | 3704 | |
1041a570 RP |
3705 | @item @var{f}, the display format |
3706 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
3707 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
3708 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3709 | last time you used either @code{x} or @code{print}. | |
70b88761 | 3710 | |
1041a570 RP |
3711 | @item @var{u}, the unit size |
3712 | The unit size is any of | |
70b88761 RP |
3713 | @table @code |
3714 | @item b | |
cedaf8bc | 3715 | Bytes. |
70b88761 | 3716 | @item h |
cedaf8bc | 3717 | Halfwords (two bytes). |
70b88761 | 3718 | @item w |
cedaf8bc | 3719 | Words (four bytes). This is the initial default. |
70b88761 | 3720 | @item g |
cedaf8bc | 3721 | Giant words (eight bytes). |
70b88761 RP |
3722 | @end table |
3723 | ||
cedaf8bc RP |
3724 | Each time you specify a unit size with @code{x}, that size becomes the |
3725 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3726 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3727 | ||
1041a570 | 3728 | @item @var{addr}, starting display address |
cedaf8bc RP |
3729 | @var{addr} is the address where you want _GDBN__ to begin displaying |
3730 | memory. The expression need not have a pointer value (though it may); | |
3731 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 3732 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
3733 | @var{addr} is usually just after the last address examined---but several |
3734 | other commands also set the default address: @code{info breakpoints} (to | |
3735 | the address of the last breakpoint listed), @code{info line} (to the | |
3736 | starting address of a line), and @code{print} (if you use it to display | |
3737 | a value from memory). | |
1041a570 | 3738 | @end table |
70b88761 | 3739 | |
cedaf8bc RP |
3740 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
3741 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3742 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3743 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3744 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 3745 | |
cedaf8bc | 3746 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 3747 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
3748 | unit size or format comes first; either order will work. The output |
3749 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3750 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3751 | ||
3752 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3753 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3754 | @samp{3i} specifies that you want to see three machine instructions, | |
3755 | including any operands. The command @code{disassemble} gives an | |
3756 | alternative way of inspecting machine instructions; @pxref{Machine | |
3757 | Code}. | |
3758 | ||
3759 | All the defaults for the arguments to @code{x} are designed to make it | |
3760 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 3761 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
3762 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
3763 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3764 | the repeat count @var{n} is used again; the other arguments default as | |
3765 | for successive uses of @code{x}. | |
70b88761 | 3766 | |
c338a2fd | 3767 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 3768 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 RP |
3769 | in the value history because there is often too much of them and they |
3770 | would get in the way. Instead, _GDBN__ makes these values available for | |
3771 | subsequent use in expressions as values of the convenience variables | |
3772 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3773 | examined is available for use in expressions in the convenience variable | |
3774 | @code{$_}. The contents of that address, as examined, are available in | |
3775 | the convenience variable @code{$__}. | |
3776 | ||
3777 | If the @code{x} command has a repeat count, the address and contents saved | |
3778 | are from the last memory unit printed; this is not the same as the last | |
3779 | address printed if several units were printed on the last line of output. | |
3780 | ||
4eb4cf57 | 3781 | @node Auto Display |
70b88761 RP |
3782 | @section Automatic Display |
3783 | @cindex automatic display | |
3784 | @cindex display of expressions | |
3785 | ||
3786 | If you find that you want to print the value of an expression frequently | |
3787 | (to see how it changes), you might want to add it to the @dfn{automatic | |
29a2b744 | 3788 | display list} so that _GDBN__ will print its value each time your program stops. |
70b88761 RP |
3789 | Each expression added to the list is given a number to identify it; |
3790 | to remove an expression from the list, you specify that number. | |
3791 | The automatic display looks like this: | |
3792 | ||
3793 | @example | |
3794 | 2: foo = 38 | |
3795 | 3: bar[5] = (struct hack *) 0x3804 | |
3796 | @end example | |
3797 | ||
3798 | @noindent | |
3799 | showing item numbers, expressions and their current values. As with | |
3800 | displays you request manually using @code{x} or @code{print}, you can | |
3801 | specify the output format you prefer; in fact, @code{display} decides | |
3802 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3803 | format specification is---it uses @code{x} if you specify a unit size, | |
3804 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3805 | supported by @code{x}; otherwise it uses @code{print}. | |
3806 | ||
3807 | @table @code | |
3808 | @item display @var{exp} | |
3809 | @kindex display | |
3810 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 3811 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3812 | |
3813 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3814 | ||
3815 | @item display/@var{fmt} @var{exp} | |
3816 | For @var{fmt} specifying only a display format and not a size or | |
3817 | count, add the expression @var{exp} to the auto-display list but | |
3818 | arranges to display it each time in the specified format @var{fmt}. | |
3819 | @xref{Output formats}. | |
3820 | ||
3821 | @item display/@var{fmt} @var{addr} | |
3822 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3823 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 RP |
3824 | be examined each time your program stops. Examining means in effect |
3825 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
70b88761 RP |
3826 | @end table |
3827 | ||
3828 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3829 | instruction about to be executed each time execution stops (@samp{$pc} | |
3830 | is a common name for the program counter; @pxref{Registers}). | |
3831 | ||
3832 | @table @code | |
3833 | @item undisplay @var{dnums}@dots{} | |
3834 | @itemx delete display @var{dnums}@dots{} | |
3835 | @kindex delete display | |
3836 | @kindex undisplay | |
3837 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3838 | ||
3839 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3840 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3841 | ||
3842 | @item disable display @var{dnums}@dots{} | |
3843 | @kindex disable display | |
3844 | Disable the display of item numbers @var{dnums}. A disabled display | |
3845 | item is not printed automatically, but is not forgotten. It may be | |
3846 | enabled again later. | |
3847 | ||
3848 | @item enable display @var{dnums}@dots{} | |
3849 | @kindex enable display | |
3850 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3851 | again in auto display of its expression, until you specify otherwise. | |
3852 | ||
3853 | @item display | |
3854 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 3855 | done when your program stops. |
70b88761 RP |
3856 | |
3857 | @item info display | |
3858 | @kindex info display | |
3859 | Print the list of expressions previously set up to display | |
3860 | automatically, each one with its item number, but without showing the | |
3861 | values. This includes disabled expressions, which are marked as such. | |
3862 | It also includes expressions which would not be displayed right now | |
3863 | because they refer to automatic variables not currently available. | |
3864 | @end table | |
3865 | ||
3866 | If a display expression refers to local variables, then it does not make | |
3867 | sense outside the lexical context for which it was set up. Such an | |
3868 | expression is disabled when execution enters a context where one of its | |
3869 | variables is not defined. For example, if you give the command | |
3870 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 3871 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
3872 | continues to stop inside that function. When it stops elsewhere---where |
3873 | there is no variable @code{last_char}---display is disabled. The next time | |
3874 | your program stops where @code{last_char} is meaningful, you can enable the | |
3875 | display expression once again. | |
3876 | ||
4eb4cf57 | 3877 | @node Print Settings |
70b88761 RP |
3878 | @section Print Settings |
3879 | ||
3880 | @cindex format options | |
3881 | @cindex print settings | |
3882 | _GDBN__ provides the following ways to control how arrays, structures, | |
e251e767 | 3883 | and symbols are printed. |
70b88761 RP |
3884 | |
3885 | @noindent | |
3886 | These settings are useful for debugging programs in any language: | |
3887 | ||
3888 | @table @code | |
3889 | @item set print address | |
3890 | @item set print address on | |
3891 | @kindex set print address | |
3892 | _GDBN__ will print memory addresses showing the location of stack | |
3893 | traces, structure values, pointer values, breakpoints, and so forth, | |
3894 | even when it also displays the contents of those addresses. The default | |
3895 | is on. For example, this is what a stack frame display looks like, with | |
3896 | @code{set print address on}: | |
1041a570 | 3897 | |
70b88761 | 3898 | @smallexample |
1041a570 | 3899 | @group |
70b88761 | 3900 | (_GDBP__) f |
e251e767 | 3901 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 3902 | at input.c:530 |
b80282d5 | 3903 | 530 if (lquote != def_lquote) |
1041a570 | 3904 | @end group |
70b88761 RP |
3905 | @end smallexample |
3906 | ||
3907 | @item set print address off | |
3908 | Do not print addresses when displaying their contents. For example, | |
3909 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 3910 | |
70b88761 | 3911 | @example |
1041a570 | 3912 | @group |
70b88761 RP |
3913 | (_GDBP__) set print addr off |
3914 | (_GDBP__) f | |
3915 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
b80282d5 | 3916 | 530 if (lquote != def_lquote) |
1041a570 | 3917 | @end group |
70b88761 RP |
3918 | @end example |
3919 | ||
3920 | @item show print address | |
3921 | @kindex show print address | |
3922 | Show whether or not addresses are to be printed. | |
3923 | ||
3924 | @item set print array | |
3925 | @itemx set print array on | |
3926 | @kindex set print array | |
3927 | _GDBN__ will pretty print arrays. This format is more convenient to read, | |
3928 | but uses more space. The default is off. | |
3929 | ||
3930 | @item set print array off. | |
3931 | Return to compressed format for arrays. | |
3932 | ||
3933 | @item show print array | |
3934 | @kindex show print array | |
3935 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 3936 | arrays. |
70b88761 RP |
3937 | |
3938 | @item set print elements @var{number-of-elements} | |
3939 | @kindex set print elements | |
3940 | If _GDBN__ is printing a large array, it will stop printing after it has | |
3941 | printed the number of elements set by the @code{set print elements} command. | |
3942 | This limit also applies to the display of strings. | |
3943 | ||
3944 | @item show print elements | |
3945 | @kindex show print elements | |
3946 | Display the number of elements of a large array that _GDBN__ will print | |
3947 | before losing patience. | |
3948 | ||
3949 | @item set print pretty on | |
3950 | @kindex set print pretty | |
3951 | Cause _GDBN__ to print structures in an indented format with one member per | |
3952 | line, like this: | |
3953 | ||
3954 | @example | |
1041a570 | 3955 | @group |
70b88761 RP |
3956 | $1 = @{ |
3957 | next = 0x0, | |
3958 | flags = @{ | |
3959 | sweet = 1, | |
3960 | sour = 1 | |
3961 | @}, | |
3962 | meat = 0x54 "Pork" | |
3963 | @} | |
1041a570 | 3964 | @end group |
70b88761 RP |
3965 | @end example |
3966 | ||
3967 | @item set print pretty off | |
3968 | Cause _GDBN__ to print structures in a compact format, like this: | |
3969 | ||
3970 | @smallexample | |
1041a570 | 3971 | @group |
38962738 RP |
3972 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \ |
3973 | meat = 0x54 "Pork"@} | |
1041a570 | 3974 | @end group |
70b88761 RP |
3975 | @end smallexample |
3976 | ||
3977 | @noindent | |
3978 | This is the default format. | |
3979 | ||
3980 | @item show print pretty | |
3981 | @kindex show print pretty | |
3982 | Show which format _GDBN__ will use to print structures. | |
3983 | ||
3984 | @item set print sevenbit-strings on | |
f2857bd9 | 3985 | @kindex set print sevenbit-strings |
e251e767 | 3986 | Print using only seven-bit characters; if this option is set, |
70b88761 RP |
3987 | _GDBN__ will display any eight-bit characters (in strings or character |
3988 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
3989 | displayed as @code{\341}. | |
3990 | ||
3991 | @item set print sevenbit-strings off | |
3992 | Print using either seven-bit or eight-bit characters, as required. This | |
3993 | is the default. | |
3994 | ||
3995 | @item show print sevenbit-strings | |
f2857bd9 | 3996 | @kindex show print sevenbit-strings |
70b88761 RP |
3997 | Show whether or not _GDBN__ will print only seven-bit characters. |
3998 | ||
3999 | @item set print union on | |
4000 | @kindex set print union | |
4001 | Tell _GDBN__ to print unions which are contained in structures. This is the | |
4002 | default setting. | |
4003 | ||
4004 | @item set print union off | |
4005 | Tell _GDBN__ not to print unions which are contained in structures. | |
4006 | ||
4007 | @item show print union | |
4008 | @kindex show print union | |
4009 | Ask _GDBN__ whether or not it will print unions which are contained in | |
e251e767 | 4010 | structures. |
70b88761 RP |
4011 | |
4012 | For example, given the declarations | |
4013 | ||
4014 | @smallexample | |
4015 | typedef enum @{Tree, Bug@} Species; | |
4016 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
4017 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
4018 | Bug_forms; | |
70b88761 RP |
4019 | |
4020 | struct thing @{ | |
4021 | Species it; | |
4022 | union @{ | |
4023 | Tree_forms tree; | |
4024 | Bug_forms bug; | |
4025 | @} form; | |
4026 | @}; | |
4027 | ||
4028 | struct thing foo = @{Tree, @{Acorn@}@}; | |
4029 | @end smallexample | |
4030 | ||
4031 | @noindent | |
4032 | with @code{set print union on} in effect @samp{p foo} would print | |
4033 | ||
4034 | @smallexample | |
4035 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
4036 | @end smallexample | |
4037 | ||
4038 | @noindent | |
4039 | and with @code{set print union off} in effect it would print | |
4040 | ||
4041 | @smallexample | |
4042 | $1 = @{it = Tree, form = @{...@}@} | |
4043 | @end smallexample | |
4044 | @end table | |
4045 | ||
4046 | @noindent | |
4047 | These settings are of interest when debugging C++ programs: | |
4048 | ||
4049 | @table @code | |
e251e767 RP |
4050 | @item set print demangle |
4051 | @itemx set print demangle on | |
70b88761 RP |
4052 | @kindex set print demangle |
4053 | Print C++ names in their source form rather than in the mangled form | |
4054 | in which they are passed to the assembler and linker for type-safe linkage. | |
4055 | The default is on. | |
4056 | ||
4057 | @item show print demangle | |
4058 | @kindex show print demangle | |
4059 | Show whether C++ names will be printed in mangled or demangled form. | |
4060 | ||
e251e767 RP |
4061 | @item set print asm-demangle |
4062 | @itemx set print asm-demangle on | |
70b88761 RP |
4063 | @kindex set print asm-demangle |
4064 | Print C++ names in their source form rather than their mangled form, even | |
4065 | in assembler code printouts such as instruction disassemblies. | |
4066 | The default is off. | |
4067 | ||
4068 | @item show print asm-demangle | |
4069 | @kindex show print asm-demangle | |
4070 | Show whether C++ names in assembly listings will be printed in mangled | |
4071 | or demangled form. | |
4072 | ||
4073 | @item set print object | |
4074 | @itemx set print object on | |
4075 | @kindex set print object | |
4076 | When displaying a pointer to an object, identify the @emph{actual} | |
4077 | (derived) type of the object rather than the @emph{declared} type, using | |
4078 | the virtual function table. | |
4079 | ||
4080 | @item set print object off | |
4081 | Display only the declared type of objects, without reference to the | |
4082 | virtual function table. This is the default setting. | |
4083 | ||
4084 | @item show print object | |
4085 | @kindex show print object | |
4086 | Show whether actual, or declared, object types will be displayed. | |
4087 | ||
e251e767 RP |
4088 | @item set print vtbl |
4089 | @itemx set print vtbl on | |
70b88761 RP |
4090 | @kindex set print vtbl |
4091 | Pretty print C++ virtual function tables. The default is off. | |
4092 | ||
4093 | @item set print vtbl off | |
4094 | Do not pretty print C++ virtual function tables. | |
4095 | ||
4096 | @item show print vtbl | |
4097 | @kindex show print vtbl | |
4098 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 RP |
4099 | @end table |
4100 | ||
4eb4cf57 | 4101 | @node Value History |
70b88761 RP |
4102 | @section Value History |
4103 | ||
4104 | @cindex value history | |
4105 | Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value | |
4106 | history} so that you can refer to them in other expressions. Values are | |
4107 | kept until the symbol table is re-read or discarded (for example with | |
4108 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
4109 | changes, the value history is discarded, since the values may contain | |
4110 | pointers back to the types defined in the symbol table. | |
4111 | ||
4112 | @cindex @code{$} | |
4113 | @cindex @code{$$} | |
4114 | @cindex history number | |
4115 | The values printed are given @dfn{history numbers} for you to refer to them | |
4116 | by. These are successive integers starting with one. @code{print} shows you | |
4117 | the history number assigned to a value by printing @samp{$@var{num} = } | |
4118 | before the value; here @var{num} is the history number. | |
4119 | ||
4120 | To refer to any previous value, use @samp{$} followed by the value's | |
4121 | history number. The way @code{print} labels its output is designed to | |
4122 | remind you of this. Just @code{$} refers to the most recent value in | |
4123 | the history, and @code{$$} refers to the value before that. | |
4124 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
4125 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
4126 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
4127 | ||
4128 | For example, suppose you have just printed a pointer to a structure and | |
4129 | want to see the contents of the structure. It suffices to type | |
4130 | ||
4131 | @example | |
4132 | p *$ | |
4133 | @end example | |
4134 | ||
4135 | If you have a chain of structures where the component @code{next} points | |
4136 | to the next one, you can print the contents of the next one with this: | |
4137 | ||
4138 | @example | |
4139 | p *$.next | |
4140 | @end example | |
4141 | ||
4142 | @noindent | |
4143 | You can print successive links in the chain by repeating this | |
4144 | command---which you can do by just typing @key{RET}. | |
4145 | ||
4146 | Note that the history records values, not expressions. If the value of | |
4147 | @code{x} is 4 and you type these commands: | |
4148 | ||
4149 | @example | |
4150 | print x | |
4151 | set x=5 | |
4152 | @end example | |
4153 | ||
4154 | @noindent | |
4155 | then the value recorded in the value history by the @code{print} command | |
4156 | remains 4 even though the value of @code{x} has changed. | |
4157 | ||
4158 | @table @code | |
4159 | @kindex show values | |
4160 | @item show values | |
4161 | Print the last ten values in the value history, with their item numbers. | |
4162 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
4163 | values} does not change the history. | |
4164 | ||
4165 | @item show values @var{n} | |
4166 | Print ten history values centered on history item number @var{n}. | |
4167 | ||
4168 | @item show values + | |
4169 | Print ten history values just after the values last printed. If no more | |
4170 | values are available, produces no display. | |
4171 | @end table | |
4172 | ||
4173 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 4174 | same effect as @samp{show values +}. |
70b88761 | 4175 | |
4eb4cf57 | 4176 | @node Convenience Vars |
70b88761 RP |
4177 | @section Convenience Variables |
4178 | ||
4179 | @cindex convenience variables | |
4180 | _GDBN__ provides @dfn{convenience variables} that you can use within | |
4181 | _GDBN__ to hold on to a value and refer to it later. These variables | |
4182 | exist entirely within _GDBN__; they are not part of your program, and | |
4183 | setting a convenience variable has no direct effect on further execution | |
1041a570 | 4184 | of your program. That is why you can use them freely. |
70b88761 RP |
4185 | |
4186 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
4187 | @samp{$} can be used for a convenience variable, unless it is one of | |
4188 | the predefined machine-specific register names (@pxref{Registers}). | |
4189 | (Value history references, in contrast, are @emph{numbers} preceded | |
1041a570 | 4190 | by @samp{$}. @xref{Value History, ,Value History}.) |
70b88761 RP |
4191 | |
4192 | You can save a value in a convenience variable with an assignment | |
4193 | expression, just as you would set a variable in your program. Example: | |
4194 | ||
4195 | @example | |
4196 | set $foo = *object_ptr | |
4197 | @end example | |
4198 | ||
4199 | @noindent | |
4200 | would save in @code{$foo} the value contained in the object pointed to by | |
4201 | @code{object_ptr}. | |
4202 | ||
4203 | Using a convenience variable for the first time creates it; but its value | |
4204 | is @code{void} until you assign a new value. You can alter the value with | |
4205 | another assignment at any time. | |
4206 | ||
4207 | Convenience variables have no fixed types. You can assign a convenience | |
4208 | variable any type of value, including structures and arrays, even if | |
4209 | that variable already has a value of a different type. The convenience | |
4210 | variable, when used as an expression, has the type of its current value. | |
4211 | ||
4212 | @table @code | |
4213 | @item show convenience | |
4214 | @kindex show convenience | |
4215 | Print a list of convenience variables used so far, and their values. | |
4216 | Abbreviated @code{show con}. | |
4217 | @end table | |
4218 | ||
4219 | One of the ways to use a convenience variable is as a counter to be | |
4220 | incremented or a pointer to be advanced. For example, to print | |
4221 | a field from successive elements of an array of structures: | |
4222 | ||
4223 | _0__@example | |
4224 | set $i = 0 | |
4225 | print bar[$i++]->contents | |
4226 | @i{@dots{} repeat that command by typing @key{RET}.} | |
4227 | _1__@end example | |
4228 | ||
4229 | Some convenience variables are created automatically by _GDBN__ and given | |
4230 | values likely to be useful. | |
4231 | ||
4232 | @table @code | |
4233 | @item $_ | |
c338a2fd | 4234 | @kindex $_ |
70b88761 | 4235 | The variable @code{$_} is automatically set by the @code{x} command to |
29a2b744 RP |
4236 | the last address examined (@pxref{Memory, ,Examining Memory}). Other |
4237 | commands which provide a default address for @code{x} to examine also | |
4238 | set @code{$_} to that address; these commands include @code{info line} | |
4239 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4240 | except when set by the @code{x} command, in which case it is a pointer | |
4241 | to the type of @code{$__}. | |
70b88761 RP |
4242 | |
4243 | @item $__ | |
c338a2fd | 4244 | @kindex $__ |
70b88761 | 4245 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
4246 | to the value found in the last address examined. Its type is chosen |
4247 | to match the format in which the data was printed. | |
70b88761 RP |
4248 | @end table |
4249 | ||
4eb4cf57 | 4250 | @node Registers |
70b88761 RP |
4251 | @section Registers |
4252 | ||
4253 | @cindex registers | |
b80282d5 | 4254 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
4255 | with names starting with @samp{$}. The names of registers are different |
4256 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 4257 | your machine. |
70b88761 RP |
4258 | |
4259 | @table @code | |
4260 | @item info registers | |
4261 | @kindex info registers | |
b80282d5 RP |
4262 | Print the names and values of all registers except floating-point |
4263 | registers (in the selected stack frame). | |
4264 | ||
4265 | @item info all-registers | |
4266 | @kindex info all-registers | |
4267 | @cindex floating point registers | |
4268 | Print the names and values of all registers, including floating-point | |
4269 | registers. | |
70b88761 | 4270 | |
4eb4cf57 | 4271 | @item info registers @var{regname} @dots{} |
0d1cd01e JG |
4272 | Print the relativized value of each specified register @var{regname}. |
4273 | @var{regname} may be any register name valid on the machine you are using, with | |
70b88761 RP |
4274 | or without the initial @samp{$}. |
4275 | @end table | |
4276 | ||
09267865 | 4277 | _GDBN__ has four ``standard'' register names that are available (in |
29a2b744 | 4278 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
4279 | architecture's canonical mnemonics for registers. The register names |
4280 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4281 | the stack pointer. @code{$fp} is used for a register that contains a | |
4282 | pointer to the current stack frame, and @code{$ps} is used for a | |
4283 | register that contains the processor status. For example, | |
70b88761 | 4284 | you could print the program counter in hex with |
1041a570 | 4285 | |
70b88761 RP |
4286 | @example |
4287 | p/x $pc | |
4288 | @end example | |
4289 | ||
4290 | @noindent | |
4291 | or print the instruction to be executed next with | |
1041a570 | 4292 | |
70b88761 RP |
4293 | @example |
4294 | x/i $pc | |
4295 | @end example | |
4296 | ||
4297 | @noindent | |
29a2b744 RP |
4298 | or add four to the stack pointer @footnote{This is a way of removing |
4299 | one word from the stack, on machines where stacks grow downward in | |
4300 | memory (most machines, nowadays). This assumes that the innermost | |
4301 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4302 | stack frames are selected. To pop entire frames off the stack, | |
4303 | regardless of machine architecture, use @code{return}; | |
1041a570 RP |
4304 | @pxref{Returning, ,Returning from a Function}.} with |
4305 | ||
70b88761 RP |
4306 | @example |
4307 | set $sp += 4 | |
4308 | @end example | |
4309 | ||
09267865 RP |
4310 | Whenever possible, these four standard register names are available on |
4311 | your machine even though the machine has different canonical mnemonics, | |
4312 | so long as there is no conflict. The @code{info registers} command | |
4313 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
4314 | registers} displays the processor status register as @code{$psr} but you |
4315 | can also refer to it as @code{$ps}. | |
4316 | ||
4317 | _GDBN__ always considers the contents of an ordinary register as an | |
4318 | integer when the register is examined in this way. Some machines have | |
4319 | special registers which can hold nothing but floating point; these | |
4320 | registers are considered to have floating point values. There is no way | |
4321 | to refer to the contents of an ordinary register as floating point value | |
4322 | (although you can @emph{print} it as a floating point value with | |
4323 | @samp{print/f $@var{regname}}). | |
4324 | ||
4325 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4326 | means that the data format in which the register contents are saved by | |
4327 | the operating system is not the same one that your program normally | |
4328 | sees. For example, the registers of the 68881 floating point | |
4329 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4330 | programs expect to work with ``double'' (virtual) format. In such | |
4331 | cases, _GDBN__ normally works with the virtual format only (the format that | |
4332 | makes sense for your program), but the @code{info registers} command | |
4333 | prints the data in both formats. | |
4334 | ||
4335 | Normally, register values are relative to the selected stack frame | |
29a2b744 RP |
4336 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the |
4337 | value that the register would contain if all stack frames farther in | |
4338 | were exited and their saved registers restored. In order to see the | |
4339 | true contents of hardware registers, you must select the innermost | |
4340 | frame (with @samp{frame 0}). | |
70b88761 RP |
4341 | |
4342 | However, _GDBN__ must deduce where registers are saved, from the machine | |
4343 | code generated by your compiler. If some registers are not saved, or if | |
4344 | _GDBN__ is unable to locate the saved registers, the selected stack | |
4345 | frame will make no difference. | |
4346 | ||
d8a68b28 | 4347 | _if__(_AMD29K__) |
03a77779 | 4348 | @table @code |
d8a68b28 JG |
4349 | @item set rstack_high_address @var{address} |
4350 | @kindex set rstack_high_address | |
03a77779 RP |
4351 | @cindex AMD 29K register stack |
4352 | @cindex register stack, AMD29K | |
4353 | On AMD 29000 family processors, registers are saved in a separate | |
4354 | ``register stack''. There is no way for _GDBN__ to determine the extent | |
4355 | of this stack. Normally, _GDBN__ just assumes that the stack is ``large | |
4356 | enough''. This may result in _GDBN__ referencing memory locations that | |
4357 | don't exist. If necessary, you can get around this problem by | |
4358 | specifying the ending address of the register stack with the @code{set | |
4359 | rstack_high_address} command. The argument should be an address, which | |
4360 | you will probably want to precede with @samp{0x} to specify in | |
4361 | hexadecimal. | |
d8a68b28 JG |
4362 | |
4363 | @item show rstack_high_address | |
4364 | @kindex show rstack_high_address | |
03a77779 RP |
4365 | Display the current limit of the register stack, on AMD 29000 family |
4366 | processors. | |
4367 | @end table | |
d8a68b28 JG |
4368 | _fi__(_AMD29K__) |
4369 | ||
4eb4cf57 RP |
4370 | _if__(_GENERIC__ || !_H8__) |
4371 | @node Floating Point Hardware | |
70b88761 RP |
4372 | @section Floating Point Hardware |
4373 | @cindex floating point | |
1041a570 | 4374 | |
70b88761 RP |
4375 | Depending on the host machine architecture, _GDBN__ may be able to give |
4376 | you more information about the status of the floating point hardware. | |
4377 | ||
4378 | @table @code | |
4379 | @item info float | |
4380 | @kindex info float | |
4381 | If available, provides hardware-dependent information about the floating | |
4382 | point unit. The exact contents and layout vary depending on the | |
4383 | floating point chip. | |
4384 | @end table | |
4385 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
4386 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
4387 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 | 4388 | @c FIXME... at that point. |
4eb4cf57 | 4389 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 4390 | |
4eb4cf57 RP |
4391 | _if__(!_CONLY__) |
4392 | @node Languages | |
c2bbbb22 RP |
4393 | @chapter Using _GDBN__ with Different Languages |
4394 | @cindex languages | |
4395 | ||
4396 | Although programming languages generally have common aspects, they are | |
4397 | rarely expressed in the same manner. For instance, in ANSI C, | |
4398 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4399 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4400 | represented (and displayed) differently. Hex numbers in C are written | |
4401 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4402 | ||
4403 | @cindex working language | |
4404 | Language-specific information is built into _GDBN__ for some languages, | |
29a2b744 | 4405 | allowing you to express operations like the above in your program's |
c2bbbb22 | 4406 | native language, and allowing _GDBN__ to output values in a manner |
29a2b744 | 4407 | consistent with the syntax of your program's native language. The |
c2bbbb22 RP |
4408 | language you use to build expressions, called the @dfn{working |
4409 | language}, can be selected manually, or _GDBN__ can set it | |
4410 | automatically. | |
4411 | ||
4412 | @menu | |
4413 | * Setting:: Switching between source languages | |
4414 | * Show:: Displaying the language | |
4415 | * Checks:: Type and Range checks | |
4416 | * Support:: Supported languages | |
4417 | @end menu | |
4418 | ||
4eb4cf57 | 4419 | @node Setting |
c2bbbb22 RP |
4420 | @section Switching between source languages |
4421 | ||
4422 | There are two ways to control the working language---either have _GDBN__ | |
4423 | set it automatically, or select it manually yourself. You can use the | |
4424 | @code{set language} command for either purpose. On startup, _GDBN__ | |
4425 | defaults to setting the language automatically. | |
4426 | ||
4427 | @menu | |
4428 | * Manually:: Setting the working language manually | |
4429 | * Automatically:: Having _GDBN__ infer the source language | |
4430 | @end menu | |
4431 | ||
4eb4cf57 | 4432 | @node Manually |
c2bbbb22 RP |
4433 | @subsection Setting the working language |
4434 | ||
4435 | @kindex set language | |
4436 | To set the language, issue the command @samp{set language @var{lang}}, | |
c338a2fd RP |
4437 | where @var{lang} is the name of a language: @code{c} or @code{modula-2}. |
4438 | For a list of the supported languages, type @samp{set language}. | |
c2bbbb22 RP |
4439 | |
4440 | Setting the language manually prevents _GDBN__ from updating the working | |
4441 | language automatically. This can lead to confusion if you try | |
4442 | to debug a program when the working language is not the same as the | |
4443 | source language, when an expression is acceptable to both | |
4444 | languages---but means different things. For instance, if the current | |
4445 | source file were written in C, and _GDBN__ was parsing Modula-2, a | |
4446 | command such as: | |
4447 | ||
4448 | @example | |
4449 | print a = b + c | |
4450 | @end example | |
4451 | ||
4452 | @noindent | |
4453 | might not have the effect you intended. In C, this means to add | |
4454 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4455 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4456 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4457 | ||
4458 | If you allow _GDBN__ to set the language automatically, then | |
4459 | you can count on expressions evaluating the same way in your debugging | |
4460 | session and in your program. | |
4461 | ||
4eb4cf57 | 4462 | @node Automatically |
c2bbbb22 RP |
4463 | @subsection Having _GDBN__ infer the source language |
4464 | ||
4465 | To have _GDBN__ set the working language automatically, use @samp{set | |
4466 | language local} or @samp{set language auto}. _GDBN__ then infers the | |
4467 | language that a program was written in by looking at the name of its | |
4468 | source files, and examining their extensions: | |
4469 | ||
4470 | @table @file | |
4471 | @item *.mod | |
4472 | Modula-2 source file | |
4473 | ||
4474 | @item *.c | |
5a2c1d85 RP |
4475 | C source file |
4476 | ||
4477 | @item *.C | |
c2bbbb22 | 4478 | @itemx *.cc |
5a2c1d85 | 4479 | C++ source file |
c2bbbb22 RP |
4480 | @end table |
4481 | ||
4482 | This information is recorded for each function or procedure in a source | |
4483 | file. When your program stops in a frame (usually by encountering a | |
4484 | breakpoint), _GDBN__ sets the working language to the language recorded | |
4485 | for the function in that frame. If the language for a frame is unknown | |
4486 | (that is, if the function or block corresponding to the frame was | |
4487 | defined in a source file that does not have a recognized extension), the | |
4488 | current working language is not changed, and _GDBN__ issues a warning. | |
4489 | ||
4490 | This may not seem necessary for most programs, which are written | |
4491 | entirely in one source language. However, program modules and libraries | |
4492 | written in one source language can be used by a main program written in | |
4493 | a different source language. Using @samp{set language auto} in this | |
4494 | case frees you from having to set the working language manually. | |
4495 | ||
4eb4cf57 | 4496 | @node Show |
c2bbbb22 RP |
4497 | @section Displaying the language |
4498 | ||
4499 | The following commands will help you find out which language is the | |
4500 | working language, and also what language source files were written in. | |
4501 | ||
4502 | @kindex show language | |
4503 | @kindex info frame | |
4504 | @kindex info source | |
4505 | @table @code | |
4506 | @item show language | |
4507 | Display the current working language. This is the | |
4508 | language you can use with commands such as @code{print} to | |
29a2b744 | 4509 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
4510 | |
4511 | @item info frame | |
1041a570 | 4512 | Among the other information listed here (@pxref{Frame Info, ,Information |
c2bbbb22 RP |
4513 | about a Frame}) is the source language for this frame. This is the |
4514 | language that will become the working language if you ever use an | |
4515 | identifier that is in this frame. | |
4516 | ||
4517 | @item info source | |
1041a570 | 4518 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 4519 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
4520 | @end table |
4521 | ||
4eb4cf57 | 4522 | @node Checks |
c2bbbb22 RP |
4523 | @section Type and range Checking |
4524 | ||
4525 | @quotation | |
4526 | @emph{Warning:} In this release, the _GDBN__ commands for type and range | |
4527 | checking are included, but they do not yet have any effect. This | |
4528 | section documents the intended facilities. | |
4529 | @end quotation | |
4530 | @c FIXME remove warning when type/range code added | |
4531 | ||
4532 | Some languages are designed to guard you against making seemingly common | |
4533 | errors through a series of compile- and run-time checks. These include | |
4534 | checking the type of arguments to functions and operators, and making | |
4535 | sure mathematical overflows are caught at run time. Checks such as | |
4536 | these help to ensure a program's correctness once it has been compiled | |
4537 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 4538 | errors when your program is running. |
c2bbbb22 | 4539 | |
1041a570 RP |
4540 | _GDBN__ can check for conditions like the above if you wish. |
4541 | Although _GDBN__ will not check the statements in your program, it | |
4542 | can check expressions entered directly into _GDBN__ for evaluation via | |
4543 | the @code{print} command, for example. As with the working language, | |
c2bbbb22 | 4544 | _GDBN__ can also decide whether or not to check automatically based on |
1041a570 RP |
4545 | your program's source language. @xref{Support, ,Supported Languages}, |
4546 | for the default settings of supported languages. | |
c2bbbb22 RP |
4547 | |
4548 | @menu | |
4549 | * Type Checking:: An overview of type checking | |
4550 | * Range Checking:: An overview of range checking | |
4551 | @end menu | |
4552 | ||
4553 | @cindex type checking | |
4554 | @cindex checks, type | |
4eb4cf57 | 4555 | @node Type Checking |
c2bbbb22 RP |
4556 | @subsection An overview of type checking |
4557 | ||
4558 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4559 | arguments to operators and functions have to be of the correct type, | |
4560 | otherwise an error occurs. These checks prevent type mismatch | |
4561 | errors from ever causing any run-time problems. For example, | |
4562 | ||
4563 | @example | |
4564 | 1 + 2 @result{} 3 | |
1041a570 | 4565 | @exdent but |
c2bbbb22 RP |
4566 | @error{} 1 + 2.3 |
4567 | @end example | |
4568 | ||
4569 | The second example fails because the @code{CARDINAL} 1 is not | |
4570 | type-compatible with the @code{REAL} 2.3. | |
4571 | ||
4572 | For expressions you use in _GDBN__ commands, you can tell the _GDBN__ | |
4573 | type checker to skip checking; to treat any mismatches as errors and | |
4574 | abandon the expression; or only issue warnings when type mismatches | |
4575 | occur, but evaluate the expression anyway. When you choose the last of | |
4576 | these, _GDBN__ evaluates expressions like the second example above, but | |
4577 | also issues a warning. | |
4578 | ||
4579 | Even though you may turn type checking off, other type-based reasons may | |
4580 | prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not | |
4581 | know how to add an @code{int} and a @code{struct foo}. These particular | |
4582 | type errors have nothing to do with the language in use, and usually | |
4583 | arise from expressions, such as the one described above, which make | |
4584 | little sense to evaluate anyway. | |
4585 | ||
4586 | Each language defines to what degree it is strict about type. For | |
4587 | instance, both Modula-2 and C require the arguments to arithmetical | |
4588 | operators to be numbers. In C, enumerated types and pointers can be | |
4589 | represented as numbers, so that they are valid arguments to mathematical | |
1041a570 | 4590 | operators. @xref{Support, ,Supported Languages}, for further |
c2bbbb22 RP |
4591 | details on specific languages. |
4592 | ||
4593 | _GDBN__ provides some additional commands for controlling the type checker: | |
4594 | ||
4595 | @kindex set check | |
4596 | @kindex set check type | |
4597 | @kindex show check type | |
4598 | @table @code | |
4599 | @item set check type auto | |
e251e767 | 4600 | Set type checking on or off based on the current working language. |
1041a570 | 4601 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4602 | each language. |
4603 | ||
4604 | @item set check type on | |
4605 | @itemx set check type off | |
4606 | Set type checking on or off, overriding the default setting for the | |
4607 | current working language. Issue a warning if the setting does not | |
4608 | match the language's default. If any type mismatches occur in | |
4609 | evaluating an expression while typechecking is on, _GDBN__ prints a | |
4610 | message and aborts evaluation of the expression. | |
4611 | ||
4612 | @item set check type warn | |
4613 | Cause the type checker to issue warnings, but to always attempt to | |
4614 | evaluate the expression. Evaluating the expression may still | |
4615 | be impossible for other reasons. For example, _GDBN__ cannot add | |
4616 | numbers and structures. | |
4617 | ||
4618 | @item show type | |
e251e767 | 4619 | Show the current setting of the type checker, and whether or not _GDBN__ is |
c2bbbb22 RP |
4620 | setting it automatically. |
4621 | @end table | |
4622 | ||
4623 | @cindex range checking | |
4624 | @cindex checks, range | |
4eb4cf57 | 4625 | @node Range Checking |
c2bbbb22 RP |
4626 | @subsection An overview of Range Checking |
4627 | ||
4628 | In some languages (such as Modula-2), it is an error to exceed the | |
4629 | bounds of a type; this is enforced with run-time checks. Such range | |
4630 | checking is meant to ensure program correctness by making sure | |
4631 | computations do not overflow, or indices on an array element access do | |
4632 | not exceed the bounds of the array. | |
4633 | ||
4634 | For expressions you use in _GDBN__ commands, you can tell _GDBN__ to | |
4635 | ignore range errors; to always treat them as errors and abandon the | |
4636 | expression; or to issue warnings when a range error occurs but evaluate | |
4637 | the expression anyway. | |
4638 | ||
4639 | A range error can result from numerical overflow, from exceeding an | |
4640 | array index bound, or when you type in a constant that is not a member | |
4641 | of any type. Some languages, however, do not treat overflows as an | |
4642 | error. In many implementations of C, mathematical overflow causes the | |
4643 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4644 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 4645 | |
c2bbbb22 RP |
4646 | @example |
4647 | @var{m} + 1 @result{} @var{s} | |
4648 | @end example | |
4649 | ||
4650 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 4651 | specific to individual compilers or machines. @xref{Support, , |
c2bbbb22 RP |
4652 | Supported Languages}, for further details on specific languages. |
4653 | ||
4654 | _GDBN__ provides some additional commands for controlling the range checker: | |
4655 | ||
4656 | @kindex set check | |
4657 | @kindex set check range | |
4658 | @kindex show check range | |
4659 | @table @code | |
4660 | @item set check range auto | |
e251e767 | 4661 | Set range checking on or off based on the current working language. |
1041a570 | 4662 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4663 | each language. |
4664 | ||
4665 | @item set check range on | |
4666 | @itemx set check range off | |
4667 | Set range checking on or off, overriding the default setting for the | |
4668 | current working language. A warning is issued if the setting does not | |
4669 | match the language's default. If a range error occurs, then a message | |
4670 | is printed and evaluation of the expression is aborted. | |
4671 | ||
4672 | @item set check range warn | |
4673 | Output messages when the _GDBN__ range checker detects a range error, | |
4674 | but attempt to evaluate the expression anyway. Evaluating the | |
4675 | expression may still be impossible for other reasons, such as accessing | |
4676 | memory that the process does not own (a typical example from many UNIX | |
4677 | systems). | |
4678 | ||
4679 | @item show range | |
e251e767 | 4680 | Show the current setting of the range checker, and whether or not it is |
c2bbbb22 RP |
4681 | being set automatically by _GDBN__. |
4682 | @end table | |
4683 | ||
4eb4cf57 | 4684 | @node Support |
c2bbbb22 RP |
4685 | @section Supported Languages |
4686 | ||
5a2c1d85 | 4687 | _GDBN__ 4 supports C, C++, and Modula-2. Some _GDBN__ |
1041a570 RP |
4688 | features may be used in expressions regardless of the language you |
4689 | use: the _GDBN__ @code{@@} and @code{::} operators, and the | |
4690 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be | |
4691 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
4692 | |
4693 | The following sections detail to what degree each of these | |
4694 | source languages is supported by _GDBN__. These sections are | |
4695 | not meant to be language tutorials or references, but serve only as a | |
4696 | reference guide to what the _GDBN__ expression parser will accept, and | |
4697 | what input and output formats should look like for different languages. | |
4698 | There are many good books written on each of these languages; please | |
4699 | look to these for a language reference or tutorial. | |
4700 | ||
4701 | @menu | |
4702 | * C:: C and C++ | |
4703 | * Modula-2:: Modula-2 | |
4704 | @end menu | |
4705 | ||
4eb4cf57 | 4706 | @node C |
c2bbbb22 | 4707 | @subsection C and C++ |
4eb4cf57 RP |
4708 | _fi__(!_CONLY__) |
4709 | _if__(_CONLY__) | |
4710 | @node C | |
4711 | @chapter C and C++ | |
4712 | _fi__(_CONLY__) | |
c2bbbb22 RP |
4713 | @cindex C and C++ |
4714 | ||
4715 | @cindex expressions in C or C++ | |
5a2c1d85 RP |
4716 | Since C and C++ are so closely related, many features of _GDBN__ apply |
4717 | to both languages. Whenever this is the case, we discuss both languages | |
4718 | together. | |
b80282d5 RP |
4719 | |
4720 | @cindex C++ | |
4721 | @kindex g++ | |
4722 | @cindex GNU C++ | |
c2bbbb22 RP |
4723 | The C++ debugging facilities are jointly implemented by the GNU C++ |
4724 | compiler and _GDBN__. Therefore, to debug your C++ code effectively, | |
4725 | you must compile your C++ programs with the GNU C++ compiler, | |
4726 | @code{g++}. | |
4727 | ||
b80282d5 | 4728 | @menu |
c2bbbb22 RP |
4729 | * C Operators:: C and C++ Operators |
4730 | * C Constants:: C and C++ Constants | |
4731 | * Cplusplus expressions:: C++ Expressions | |
4eb4cf57 | 4732 | _if__(!_CONLY__) |
c2bbbb22 | 4733 | * C Defaults:: Default settings for C and C++ |
4eb4cf57 | 4734 | _fi__(!_CONLY__) |
c2bbbb22 RP |
4735 | * C Checks:: C and C++ Type and Range Checks |
4736 | * Debugging C:: _GDBN__ and C | |
4737 | * Debugging C plus plus:: Special features for C++ | |
b80282d5 RP |
4738 | @end menu |
4739 | ||
c2bbbb22 | 4740 | @cindex C and C++ operators |
4eb4cf57 RP |
4741 | @node C Operators |
4742 | _if__(!_CONLY__) | |
c2bbbb22 | 4743 | @subsubsection C and C++ Operators |
4eb4cf57 RP |
4744 | _fi__(!_CONLY__) |
4745 | _if__(_CONLY__) | |
4746 | @section C and C++ Operators | |
4747 | _fi__(_CONLY__) | |
c2bbbb22 RP |
4748 | |
4749 | Operators must be defined on values of specific types. For instance, | |
4750 | @code{+} is defined on numbers, but not on structures. Operators are | |
4751 | often defined on groups of types. For the purposes of C and C++, the | |
4752 | following definitions hold: | |
4753 | ||
4754 | @itemize @bullet | |
e251e767 | 4755 | @item |
c2bbbb22 RP |
4756 | @emph{Integral types} include @code{int} with any of its storage-class |
4757 | specifiers, @code{char}, and @code{enum}s. | |
4758 | ||
4759 | @item | |
4760 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4761 | ||
4762 | @item | |
4763 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4764 | *)}. | |
4765 | ||
e251e767 | 4766 | @item |
c2bbbb22 | 4767 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
4768 | @end itemize |
4769 | ||
4770 | @noindent | |
4771 | The following operators are supported. They are listed here | |
4772 | in order of increasing precedence: | |
4773 | ||
4774 | @table @code | |
1041a570 | 4775 | _0__@item , |
c2bbbb22 RP |
4776 | The comma or sequencing operator. Expressions in a comma-separated list |
4777 | are evaluated from left to right, with the result of the entire | |
4778 | expression being the last expression evaluated. | |
4779 | ||
4780 | @item = | |
4781 | Assignment. The value of an assignment expression is the value | |
4782 | assigned. Defined on scalar types. | |
4783 | ||
4784 | @item @var{op}= | |
1041a570 RP |
4785 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
4786 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
4787 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
4788 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
4789 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
4790 | |
4791 | @item ?: | |
4792 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
4793 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
4794 | integral type. | |
4795 | ||
4796 | @item || | |
1041a570 | 4797 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4798 | |
4799 | @item && | |
1041a570 | 4800 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4801 | |
4802 | @item | | |
1041a570 | 4803 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4804 | |
4805 | @item ^ | |
1041a570 | 4806 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
4807 | |
4808 | @item & | |
1041a570 | 4809 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4810 | |
4811 | @item ==@r{, }!= | |
4812 | Equality and inequality. Defined on scalar types. The value of these | |
4813 | expressions is 0 for false and non-zero for true. | |
4814 | ||
4815 | @item <@r{, }>@r{, }<=@r{, }>= | |
4816 | Less than, greater than, less than or equal, greater than or equal. | |
4817 | Defined on scalar types. The value of these expressions is 0 for false | |
4818 | and non-zero for true. | |
4819 | ||
4820 | @item <<@r{, }>> | |
4821 | left shift, and right shift. Defined on integral types. | |
4822 | ||
e251e767 | 4823 | @item @@ |
1041a570 | 4824 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
4825 | |
4826 | @item +@r{, }- | |
4827 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 4828 | pointer types. |
c2bbbb22 RP |
4829 | |
4830 | @item *@r{, }/@r{, }% | |
4831 | Multiplication, division, and modulus. Multiplication and division are | |
4832 | defined on integral and floating-point types. Modulus is defined on | |
4833 | integral types. | |
4834 | ||
4835 | @item ++@r{, }-- | |
4836 | Increment and decrement. When appearing before a variable, the | |
4837 | operation is performed before the variable is used in an expression; | |
4838 | when appearing after it, the variable's value is used before the | |
4839 | operation takes place. | |
4840 | ||
4841 | @item * | |
4842 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
4843 | @code{++}. | |
4844 | ||
4845 | @item & | |
4846 | Address operator. Defined on variables. Same precedence as @code{++}. | |
4847 | ||
6ca72cc6 RP |
4848 | For debugging C++, _GDBN__ implements a use of @samp{&} beyond what's |
4849 | allowed in the C++ language itself: you can use @samp{&(&@var{ref})} | |
4850 | (or, if you prefer, simply @samp{&&@var{ref}} to examine the address | |
4851 | where a C++ reference variable (declared with @samp{&@var{ref}}) is | |
4852 | stored. | |
4853 | ||
c2bbbb22 RP |
4854 | @item - |
4855 | Negative. Defined on integral and floating-point types. Same | |
4856 | precedence as @code{++}. | |
4857 | ||
4858 | @item ! | |
4859 | Logical negation. Defined on integral types. Same precedence as | |
4860 | @code{++}. | |
4861 | ||
4862 | @item ~ | |
4863 | Bitwise complement operator. Defined on integral types. Same precedence as | |
4864 | @code{++}. | |
4865 | ||
4866 | @item .@r{, }-> | |
4867 | Structure member, and pointer-to-structure member. For convenience, | |
4868 | _GDBN__ regards the two as equivalent, choosing whether to dereference a | |
e251e767 | 4869 | pointer based on the stored type information. |
c2bbbb22 RP |
4870 | Defined on @code{struct}s and @code{union}s. |
4871 | ||
4872 | @item [] | |
4873 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
4874 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
4875 | ||
4876 | @item () | |
4877 | Function parameter list. Same precedence as @code{->}. | |
4878 | ||
4879 | @item :: | |
4880 | C++ scope resolution operator. Defined on | |
4881 | @code{struct}, @code{union}, and @code{class} types. | |
4882 | ||
4883 | @item :: | |
1041a570 RP |
4884 | The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}). Same precedence as |
4885 | @code{::}, above._1__ | |
c2bbbb22 RP |
4886 | @end table |
4887 | ||
4888 | @cindex C and C++ constants | |
4eb4cf57 RP |
4889 | @node C Constants |
4890 | _if__(!_CONLY__) | |
c2bbbb22 | 4891 | @subsubsection C and C++ Constants |
4eb4cf57 RP |
4892 | _fi__(!_CONLY__) |
4893 | _if__(_CONLY__) | |
4894 | @section C and C++ Constants | |
4895 | _fi__(_CONLY__) | |
c2bbbb22 RP |
4896 | |
4897 | _GDBN__ allows you to express the constants of C and C++ in the | |
4898 | following ways: | |
4899 | ||
4900 | @itemize @bullet | |
c2bbbb22 RP |
4901 | @item |
4902 | Integer constants are a sequence of digits. Octal constants are | |
4903 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 4904 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
4905 | @samp{l}, specifying that the constant should be treated as a |
4906 | @code{long} value. | |
4907 | ||
4908 | @item | |
4909 | Floating point constants are a sequence of digits, followed by a decimal | |
4910 | point, followed by a sequence of digits, and optionally followed by an | |
4911 | exponent. An exponent is of the form: | |
4912 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
4913 | sequence of digits. The @samp{+} is optional for positive exponents. | |
4914 | ||
4915 | @item | |
4916 | Enumerated constants consist of enumerated identifiers, or their | |
4917 | integral equivalents. | |
4918 | ||
4919 | @item | |
4920 | Character constants are a single character surrounded by single quotes | |
4921 | (@code{'}), or a number---the ordinal value of the corresponding character | |
4922 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
4923 | be represented by a letter or by @dfn{escape sequences}, which are of | |
4924 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
4925 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
4926 | @samp{@var{x}} is a predefined special character---for example, | |
4927 | @samp{\n} for newline. | |
4928 | ||
4929 | @item | |
4930 | String constants are a sequence of character constants surrounded | |
4931 | by double quotes (@code{"}). | |
4932 | ||
4933 | @item | |
4934 | Pointer constants are an integral value. | |
c2bbbb22 RP |
4935 | @end itemize |
4936 | ||
4eb4cf57 RP |
4937 | @node Cplusplus expressions |
4938 | _if__(!_CONLY__) | |
c2bbbb22 | 4939 | @subsubsection C++ Expressions |
4eb4cf57 RP |
4940 | _fi__(!_CONLY__) |
4941 | _if__(_CONLY__) | |
4942 | @section C++ Expressions | |
4943 | _fi__(_CONLY__) | |
b80282d5 RP |
4944 | |
4945 | @cindex expressions in C++ | |
b1385986 RP |
4946 | _GDBN__'s expression handling has a number of extensions to |
4947 | interpret a significant subset of C++ expressions. | |
4948 | ||
4949 | @cindex C++ support, not in @sc{coff} | |
4950 | @cindex @sc{coff} versus C++ | |
4951 | @cindex C++ and object formats | |
4952 | @cindex object formats and C++ | |
4953 | @cindex a.out and C++ | |
4954 | @cindex @sc{ecoff} and C++ | |
4955 | @cindex @sc{xcoff} and C++ | |
4956 | @cindex @sc{elf}/stabs and C++ | |
4957 | @cindex @sc{elf}/@sc{dwarf} and C++ | |
4958 | @quotation | |
4959 | @emph{Warning:} Most of these extensions depend on the use of additional | |
4960 | debugging information in the symbol table, and thus require a rich, | |
4961 | extendable object code format. In particular, if your system uses | |
4962 | a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs | |
4963 | extensions to the symbol table, these facilities are all available. | |
4964 | Where the object code format is standard @sc{coff}, on the other hand, | |
4965 | most of the C++ support in _GDBN__ will @emph{not} work, nor can it. | |
4966 | For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the | |
4967 | standard is still evolving, so the C++ support in _GDBN__ is still | |
4968 | fragile; when this debugging format stabilizes, however, C++ support | |
4969 | will also be available on systems that use it. | |
4970 | @end quotation | |
b80282d5 RP |
4971 | |
4972 | @enumerate | |
4973 | ||
4974 | @cindex member functions | |
e251e767 | 4975 | @item |
b80282d5 | 4976 | Member function calls are allowed; you can use expressions like |
1041a570 | 4977 | |
b80282d5 RP |
4978 | @example |
4979 | count = aml->GetOriginal(x, y) | |
4980 | @end example | |
4981 | ||
4982 | @kindex this | |
4983 | @cindex namespace in C++ | |
e251e767 | 4984 | @item |
b80282d5 RP |
4985 | While a member function is active (in the selected stack frame), your |
4986 | expressions have the same namespace available as the member function; | |
4987 | that is, _GDBN__ allows implicit references to the class instance | |
4988 | pointer @code{this} following the same rules as C++. | |
4989 | ||
4990 | @cindex call overloaded functions | |
4991 | @cindex type conversions in C++ | |
e251e767 | 4992 | @item |
b80282d5 RP |
4993 | You can call overloaded functions; _GDBN__ will resolve the function |
4994 | call to the right definition, with one restriction---you must use | |
4995 | arguments of the type required by the function that you want to call. | |
4996 | _GDBN__ will not perform conversions requiring constructors or | |
4997 | user-defined type operators. | |
4998 | ||
4999 | @cindex reference declarations | |
5000 | @item | |
5001 | _GDBN__ understands variables declared as C++ references; you can use them in | |
5002 | expressions just as you do in C++ source---they are automatically | |
e251e767 | 5003 | dereferenced. |
b80282d5 RP |
5004 | |
5005 | In the parameter list shown when _GDBN__ displays a frame, the values of | |
5006 | reference variables are not displayed (unlike other variables); this | |
5007 | avoids clutter, since references are often used for large structures. | |
5008 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 5009 | you have specified @samp{set print address off}. |
b80282d5 RP |
5010 | |
5011 | @item | |
5012 | _GDBN__ supports the C++ name resolution operator @code{::}---your | |
c2bbbb22 RP |
5013 | expressions can use it just as expressions in your program do. Since |
5014 | one scope may be defined in another, you can use @code{::} repeatedly if | |
5015 | necessary, for example in an expression like | |
5016 | @samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows | |
5017 | resolving name scope by reference to source files, in both C and C++ | |
1041a570 | 5018 | debugging (@pxref{Variables, ,Program Variables}). |
b80282d5 RP |
5019 | @end enumerate |
5020 | ||
4eb4cf57 RP |
5021 | _if__(!_CONLY__) |
5022 | @node C Defaults | |
c2bbbb22 RP |
5023 | @subsubsection C and C++ Defaults |
5024 | @cindex C and C++ defaults | |
5025 | ||
e251e767 RP |
5026 | If you allow _GDBN__ to set type and range checking automatically, they |
5027 | both default to @code{off} whenever the working language changes to | |
5a2c1d85 | 5028 | C or C++. This happens regardless of whether you, or _GDBN__, |
c2bbbb22 RP |
5029 | selected the working language. |
5030 | ||
5031 | If you allow _GDBN__ to set the language automatically, it sets the | |
5a2c1d85 RP |
5032 | working language to C or C++ on entering code compiled from a source file |
5033 | whose name ends with @file{.c}, @file{.C}, or @file{.cc}. | |
1041a570 | 5034 | @xref{Automatically, ,Having _GDBN__ infer the source language}, for |
c2bbbb22 | 5035 | further details. |
4eb4cf57 | 5036 | _fi__(!_CONLY__) |
c2bbbb22 | 5037 | |
4eb4cf57 RP |
5038 | @node C Checks |
5039 | _if__(!_CONLY__) | |
c2bbbb22 | 5040 | @subsubsection C and C++ Type and Range Checks |
4eb4cf57 RP |
5041 | _fi__(!_CONLY__) |
5042 | _if__(_CONLY__) | |
5043 | @section C and C++ Type and Range Checks | |
5044 | _fi__(_CONLY__) | |
c2bbbb22 RP |
5045 | @cindex C and C++ checks |
5046 | ||
5047 | @quotation | |
5048 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5049 | range checking. | |
5050 | @end quotation | |
5051 | @c FIXME remove warning when type/range checks added | |
5052 | ||
5053 | By default, when _GDBN__ parses C or C++ expressions, type checking | |
5054 | is not used. However, if you turn type checking on, _GDBN__ will | |
5055 | consider two variables type equivalent if: | |
5056 | ||
5057 | @itemize @bullet | |
5058 | @item | |
5059 | The two variables are structured and have the same structure, union, or | |
5060 | enumerated tag. | |
5061 | ||
e251e767 | 5062 | @item |
c2bbbb22 RP |
5063 | Two two variables have the same type name, or types that have been |
5064 | declared equivalent through @code{typedef}. | |
5065 | ||
5066 | @ignore | |
5067 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
5068 | @c FIXME--beers? | |
5069 | @item | |
5070 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
5071 | declared in the same declaration. (Note: this may not be true for all C | |
5072 | compilers.) | |
5073 | @end ignore | |
c2bbbb22 RP |
5074 | @end itemize |
5075 | ||
5076 | Range checking, if turned on, is done on mathematical operations. Array | |
5077 | indices are not checked, since they are often used to index a pointer | |
5078 | that is not itself an array. | |
5079 | ||
4eb4cf57 RP |
5080 | @node Debugging C |
5081 | _if__(!_CONLY__) | |
c2bbbb22 | 5082 | @subsubsection _GDBN__ and C |
4eb4cf57 RP |
5083 | _fi__(!_CONLY__) |
5084 | _if__(_CONLY__) | |
5085 | @section _GDBN__ and C | |
5086 | _fi__(_CONLY__) | |
c2bbbb22 RP |
5087 | |
5088 | The @code{set print union} and @code{show print union} commands apply to | |
5089 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
5090 | inside a @code{struct} or @code{class} will also be printed. | |
5091 | Otherwise, it will appear as @samp{@{...@}}. | |
5092 | ||
5093 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
1041a570 | 5094 | with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 | 5095 | |
4eb4cf57 RP |
5096 | @node Debugging C plus plus |
5097 | _if__(!_CONLY__) | |
6f3ec223 | 5098 | @subsubsection _GDBN__ Features for C++ |
4eb4cf57 RP |
5099 | _fi__(!_CONLY__) |
5100 | _if__(_CONLY__) | |
5101 | @section _GDBN__ Features for C++ | |
5102 | _fi__(_CONLY__) | |
b80282d5 RP |
5103 | |
5104 | @cindex commands for C++ | |
5105 | Some _GDBN__ commands are particularly useful with C++, and some are | |
5106 | designed specifically for use with C++. Here is a summary: | |
5107 | ||
5108 | @table @code | |
5109 | @cindex break in overloaded functions | |
5110 | @item @r{breakpoint menus} | |
5111 | When you want a breakpoint in a function whose name is overloaded, | |
5112 | _GDBN__'s breakpoint menus help you specify which function definition | |
5113 | you want. @xref{Breakpoint Menus}. | |
5114 | ||
5115 | @cindex overloading in C++ | |
5116 | @item rbreak @var{regex} | |
5117 | Setting breakpoints using regular expressions is helpful for setting | |
5118 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 5119 | classes. |
29a2b744 | 5120 | @xref{Set Breaks, ,Setting Breakpoints}. |
b80282d5 RP |
5121 | |
5122 | @cindex C++ exception handling | |
5123 | @item catch @var{exceptions} | |
5124 | @itemx info catch | |
29a2b744 | 5125 | Debug C++ exception handling using these commands. @xref{Exception |
1041a570 | 5126 | Handling, ,Breakpoints and Exceptions}. |
b80282d5 | 5127 | |
e251e767 | 5128 | @cindex inheritance |
b80282d5 RP |
5129 | @item ptype @var{typename} |
5130 | Print inheritance relationships as well as other information for type | |
e251e767 | 5131 | @var{typename}. |
1041a570 | 5132 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
5133 | |
5134 | @cindex C++ symbol display | |
5135 | @item set print demangle | |
5136 | @itemx show print demangle | |
5137 | @itemx set print asm-demangle | |
5138 | @itemx show print asm-demangle | |
5139 | Control whether C++ symbols display in their source form, both when | |
5140 | displaying code as C++ source and when displaying disassemblies. | |
1041a570 | 5141 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5142 | |
5143 | @item set print object | |
5144 | @itemx show print object | |
e251e767 | 5145 | Choose whether to print derived (actual) or declared types of objects. |
1041a570 | 5146 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5147 | |
5148 | @item set print vtbl | |
5149 | @itemx show print vtbl | |
5150 | Control the format for printing virtual function tables. | |
1041a570 | 5151 | @xref{Print Settings, ,Print Settings}. |
6f3ec223 RP |
5152 | |
5153 | @item @r{Overloaded symbol names} | |
5154 | You can specify a particular definition of an overloaded symbol, using | |
5155 | the same notation that's used to declare such symbols in C++: type | |
5156 | @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can | |
5157 | also use _GDBN__'s command-line word completion facilities to list the | |
5158 | available choices, or to finish the type list for you. | |
5159 | @xref{Completion,, Command Completion}, for details on how to do this. | |
b80282d5 RP |
5160 | @end table |
5161 | ||
4eb4cf57 RP |
5162 | _if__(!_CONLY__) |
5163 | @node Modula-2 | |
c2bbbb22 RP |
5164 | @subsection Modula-2 |
5165 | @cindex Modula-2 | |
5166 | ||
5167 | The extensions made to _GDBN__ to support Modula-2 support output | |
5168 | from the GNU Modula-2 compiler (which is currently being developed). | |
5169 | Other Modula-2 compilers are not currently supported, and attempting to | |
5170 | debug executables produced by them will most likely result in an error | |
5171 | as _GDBN__ reads in the executable's symbol table. | |
5172 | ||
5173 | @cindex expressions in Modula-2 | |
5174 | @menu | |
5175 | * M2 Operators:: Built-in operators | |
29a2b744 | 5176 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
5177 | * M2 Constants:: Modula-2 Constants |
5178 | * M2 Defaults:: Default settings for Modula-2 | |
5179 | * Deviations:: Deviations from standard Modula-2 | |
5180 | * M2 Checks:: Modula-2 Type and Range Checks | |
5181 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
5182 | * GDB/M2:: _GDBN__ and Modula-2 | |
5183 | @end menu | |
5184 | ||
4eb4cf57 | 5185 | @node M2 Operators |
c2bbbb22 RP |
5186 | @subsubsection Operators |
5187 | @cindex Modula-2 operators | |
5188 | ||
5189 | Operators must be defined on values of specific types. For instance, | |
5190 | @code{+} is defined on numbers, but not on structures. Operators are | |
5191 | often defined on groups of types. For the purposes of Modula-2, the | |
5192 | following definitions hold: | |
5193 | ||
5194 | @itemize @bullet | |
5195 | ||
5196 | @item | |
5197 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
5198 | their subranges. | |
5199 | ||
5200 | @item | |
5201 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
5202 | ||
5203 | @item | |
5204 | @emph{Floating-point types} consist of @code{REAL}. | |
5205 | ||
5206 | @item | |
5207 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
5208 | @var{type}}. | |
5209 | ||
5210 | @item | |
5211 | @emph{Scalar types} consist of all of the above. | |
5212 | ||
5213 | @item | |
5214 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
5215 | ||
5216 | @item | |
5217 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
5218 | @end itemize |
5219 | ||
5220 | @noindent | |
5221 | The following operators are supported, and appear in order of | |
5222 | increasing precedence: | |
5223 | ||
5224 | @table @code | |
c2bbbb22 RP |
5225 | @item , |
5226 | Function argument or array index separator. | |
1041a570 | 5227 | _0__ |
c2bbbb22 RP |
5228 | @item := |
5229 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
5230 | @var{value}. | |
5231 | ||
5232 | @item <@r{, }> | |
5233 | Less than, greater than on integral, floating-point, or enumerated | |
5234 | types. | |
5235 | ||
5236 | @item <=@r{, }>= | |
5237 | Less than, greater than, less than or equal to, greater than or equal to | |
5238 | on integral, floating-point and enumerated types, or set inclusion on | |
5239 | set types. Same precedence as @code{<}. | |
5240 | ||
5241 | @item =@r{, }<>@r{, }# | |
5242 | Equality and two ways of expressing inequality, valid on scalar types. | |
5243 | Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is | |
5244 | available for inequality, since @code{#} conflicts with the script | |
5245 | comment character. | |
5246 | ||
5247 | @item IN | |
5248 | Set membership. Defined on set types and the types of their members. | |
5249 | Same precedence as @code{<}. | |
5250 | ||
5251 | @item OR | |
5252 | Boolean disjunction. Defined on boolean types. | |
5253 | ||
5254 | @item AND@r{, }& | |
5255 | Boolean conjuction. Defined on boolean types. | |
5256 | ||
5257 | @item @@ | |
1041a570 | 5258 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5259 | |
5260 | @item +@r{, }- | |
5261 | Addition and subtraction on integral and floating-point types, or union | |
5262 | and difference on set types. | |
5263 | ||
5264 | @item * | |
5265 | Multiplication on integral and floating-point types, or set intersection | |
5266 | on set types. | |
5267 | ||
5268 | @item / | |
5269 | Division on floating-point types, or symmetric set difference on set | |
5270 | types. Same precedence as @code{*}. | |
5271 | ||
5272 | @item DIV@r{, }MOD | |
5273 | Integer division and remainder. Defined on integral types. Same | |
5274 | precedence as @code{*}. | |
5275 | ||
5276 | @item - | |
5277 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
5278 | ||
5279 | @item ^ | |
e251e767 | 5280 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
5281 | |
5282 | @item NOT | |
5283 | Boolean negation. Defined on boolean types. Same precedence as | |
5284 | @code{^}. | |
5285 | ||
5286 | @item . | |
5287 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
5288 | precedence as @code{^}. | |
5289 | ||
5290 | @item [] | |
5291 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
5292 | ||
5293 | @item () | |
5294 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
5295 | as @code{^}. | |
5296 | ||
5297 | @item ::@r{, }. | |
5298 | _GDBN__ and Modula-2 scope operators. | |
c2bbbb22 RP |
5299 | @end table |
5300 | ||
5301 | @quotation | |
5302 | @emph{Warning:} Sets and their operations are not yet supported, so _GDBN__ | |
5303 | will treat the use of the operator @code{IN}, or the use of operators | |
5304 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
5305 | @code{<=}, and @code{>=} on sets as an error. | |
5306 | @end quotation | |
5307 | _1__ | |
29a2b744 | 5308 | @cindex Modula-2 built-ins |
4eb4cf57 | 5309 | @node Built-In Func/Proc |
c2bbbb22 RP |
5310 | @subsubsection Built-in Functions and Procedures |
5311 | ||
5312 | Modula-2 also makes available several built-in procedures and functions. | |
5313 | In describing these, the following metavariables are used: | |
5314 | ||
5315 | @table @var | |
5316 | ||
5317 | @item a | |
5318 | represents an @code{ARRAY} variable. | |
5319 | ||
5320 | @item c | |
5321 | represents a @code{CHAR} constant or variable. | |
5322 | ||
5323 | @item i | |
5324 | represents a variable or constant of integral type. | |
5325 | ||
5326 | @item m | |
5327 | represents an identifier that belongs to a set. Generally used in the | |
5328 | same function with the metavariable @var{s}. The type of @var{s} should | |
5329 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
5330 | ||
5331 | @item n | |
5332 | represents a variable or constant of integral or floating-point type. | |
5333 | ||
5334 | @item r | |
5335 | represents a variable or constant of floating-point type. | |
5336 | ||
5337 | @item t | |
5338 | represents a type. | |
5339 | ||
5340 | @item v | |
5341 | represents a variable. | |
5342 | ||
5343 | @item x | |
5344 | represents a variable or constant of one of many types. See the | |
5345 | explanation of the function for details. | |
c2bbbb22 RP |
5346 | @end table |
5347 | ||
5348 | All Modula-2 built-in procedures also return a result, described below. | |
5349 | ||
5350 | @table @code | |
5351 | @item ABS(@var{n}) | |
5352 | Returns the absolute value of @var{n}. | |
5353 | ||
5354 | @item CAP(@var{c}) | |
5355 | If @var{c} is a lower case letter, it returns its upper case | |
5356 | equivalent, otherwise it returns its argument | |
5357 | ||
5358 | @item CHR(@var{i}) | |
5359 | Returns the character whose ordinal value is @var{i}. | |
5360 | ||
5361 | @item DEC(@var{v}) | |
5362 | Decrements the value in the variable @var{v}. Returns the new value. | |
5363 | ||
5364 | @item DEC(@var{v},@var{i}) | |
5365 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5366 | new value. | |
5367 | ||
5368 | @item EXCL(@var{m},@var{s}) | |
5369 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5370 | set. | |
5371 | ||
5372 | @item FLOAT(@var{i}) | |
5373 | Returns the floating point equivalent of the integer @var{i}. | |
5374 | ||
5375 | @item HIGH(@var{a}) | |
5376 | Returns the index of the last member of @var{a}. | |
5377 | ||
5378 | @item INC(@var{v}) | |
5379 | Increments the value in the variable @var{v}. Returns the new value. | |
5380 | ||
5381 | @item INC(@var{v},@var{i}) | |
5382 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5383 | new value. | |
5384 | ||
5385 | @item INCL(@var{m},@var{s}) | |
5386 | Adds the element @var{m} to the set @var{s} if it is not already | |
5387 | there. Returns the new set. | |
5388 | ||
5389 | @item MAX(@var{t}) | |
5390 | Returns the maximum value of the type @var{t}. | |
5391 | ||
5392 | @item MIN(@var{t}) | |
5393 | Returns the minimum value of the type @var{t}. | |
5394 | ||
5395 | @item ODD(@var{i}) | |
5396 | Returns boolean TRUE if @var{i} is an odd number. | |
5397 | ||
5398 | @item ORD(@var{x}) | |
5399 | Returns the ordinal value of its argument. For example, the ordinal | |
5400 | value of a character is its ASCII value (on machines supporting the | |
5401 | ASCII character set). @var{x} must be of an ordered type, which include | |
5402 | integral, character and enumerated types. | |
5403 | ||
5404 | @item SIZE(@var{x}) | |
5405 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5406 | ||
5407 | @item TRUNC(@var{r}) | |
5408 | Returns the integral part of @var{r}. | |
5409 | ||
5410 | @item VAL(@var{t},@var{i}) | |
5411 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5412 | @end table | |
5413 | ||
5414 | @quotation | |
5415 | @emph{Warning:} Sets and their operations are not yet supported, so | |
5416 | _GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as | |
5417 | an error. | |
5418 | @end quotation | |
5419 | ||
5420 | @cindex Modula-2 constants | |
4eb4cf57 | 5421 | @node M2 Constants |
c2bbbb22 RP |
5422 | @subsubsection Constants |
5423 | ||
5424 | _GDBN__ allows you to express the constants of Modula-2 in the following | |
5425 | ways: | |
5426 | ||
5427 | @itemize @bullet | |
5428 | ||
5429 | @item | |
5430 | Integer constants are simply a sequence of digits. When used in an | |
5431 | expression, a constant is interpreted to be type-compatible with the | |
5432 | rest of the expression. Hexadecimal integers are specified by a | |
5433 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5434 | ||
5435 | @item | |
5436 | Floating point constants appear as a sequence of digits, followed by a | |
5437 | decimal point and another sequence of digits. An optional exponent can | |
5438 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5439 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5440 | digits of the floating point constant must be valid decimal (base 10) | |
5441 | digits. | |
5442 | ||
5443 | @item | |
5444 | Character constants consist of a single character enclosed by a pair of | |
5445 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5446 | also be expressed by their ordinal value (their ASCII value, usually) | |
5447 | followed by a @samp{C}. | |
5448 | ||
5449 | @item | |
1041a570 RP |
5450 | String constants consist of a sequence of characters enclosed by a |
5451 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5452 | Escape sequences in the style of C are also allowed. @xref{C | |
5453 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
5454 | sequences. | |
c2bbbb22 RP |
5455 | |
5456 | @item | |
5457 | Enumerated constants consist of an enumerated identifier. | |
5458 | ||
5459 | @item | |
5460 | Boolean constants consist of the identifiers @code{TRUE} and | |
5461 | @code{FALSE}. | |
5462 | ||
5463 | @item | |
5464 | Pointer constants consist of integral values only. | |
5465 | ||
5466 | @item | |
5467 | Set constants are not yet supported. | |
c2bbbb22 RP |
5468 | @end itemize |
5469 | ||
4eb4cf57 | 5470 | @node M2 Defaults |
c2bbbb22 RP |
5471 | @subsubsection Modula-2 Defaults |
5472 | @cindex Modula-2 defaults | |
5473 | ||
e251e767 RP |
5474 | If type and range checking are set automatically by _GDBN__, they |
5475 | both default to @code{on} whenever the working language changes to | |
c2bbbb22 RP |
5476 | Modula-2. This happens regardless of whether you, or _GDBN__, |
5477 | selected the working language. | |
5478 | ||
5479 | If you allow _GDBN__ to set the language automatically, then entering | |
5480 | code compiled from a file whose name ends with @file{.mod} will set the | |
1041a570 | 5481 | working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set |
c2bbbb22 RP |
5482 | the language automatically}, for further details. |
5483 | ||
4eb4cf57 | 5484 | @node Deviations |
c2bbbb22 RP |
5485 | @subsubsection Deviations from Standard Modula-2 |
5486 | @cindex Modula-2, deviations from | |
5487 | ||
5488 | A few changes have been made to make Modula-2 programs easier to debug. | |
5489 | This is done primarily via loosening its type strictness: | |
5490 | ||
5491 | @itemize @bullet | |
e251e767 | 5492 | @item |
c2bbbb22 RP |
5493 | Unlike in standard Modula-2, pointer constants can be formed by |
5494 | integers. This allows you to modify pointer variables during | |
5495 | debugging. (In standard Modula-2, the actual address contained in a | |
5496 | pointer variable is hidden from you; it can only be modified | |
5497 | through direct assignment to another pointer variable or expression that | |
5498 | returned a pointer.) | |
5499 | ||
e251e767 | 5500 | @item |
c2bbbb22 RP |
5501 | C escape sequences can be used in strings and characters to represent |
5502 | non-printable characters. _GDBN__ will print out strings with these | |
5503 | escape sequences embedded. Single non-printable characters are | |
5504 | printed using the @samp{CHR(@var{nnn})} format. | |
5505 | ||
5506 | @item | |
5507 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5508 | argument. | |
5509 | ||
5510 | @item | |
29a2b744 | 5511 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 5512 | @end itemize |
c2bbbb22 | 5513 | |
4eb4cf57 | 5514 | @node M2 Checks |
c2bbbb22 RP |
5515 | @subsubsection Modula-2 Type and Range Checks |
5516 | @cindex Modula-2 checks | |
5517 | ||
5518 | @quotation | |
5519 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5520 | range checking. | |
5521 | @end quotation | |
5522 | @c FIXME remove warning when type/range checks added | |
5523 | ||
5524 | _GDBN__ considers two Modula-2 variables type equivalent if: | |
5525 | ||
5526 | @itemize @bullet | |
5527 | @item | |
5528 | They are of types that have been declared equivalent via a @code{TYPE | |
5529 | @var{t1} = @var{t2}} statement | |
5530 | ||
5531 | @item | |
5532 | They have been declared on the same line. (Note: This is true of the | |
5533 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
5534 | @end itemize |
5535 | ||
5536 | As long as type checking is enabled, any attempt to combine variables | |
5537 | whose types are not equivalent is an error. | |
5538 | ||
5539 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 5540 | index bounds, and all built-in functions and procedures. |
c2bbbb22 | 5541 | |
4eb4cf57 | 5542 | @node M2 Scope |
c2bbbb22 RP |
5543 | @subsubsection The scope operators @code{::} and @code{.} |
5544 | @cindex scope | |
5545 | @kindex . | |
e94b4a2b | 5546 | @cindex colon, doubled as scope operator |
1041a570 RP |
5547 | @ifinfo |
5548 | @kindex colon-colon | |
5549 | @c Info cannot handoe :: but TeX can. | |
5550 | @end ifinfo | |
5551 | @iftex | |
c2bbbb22 | 5552 | @kindex :: |
1041a570 | 5553 | @end iftex |
c2bbbb22 RP |
5554 | |
5555 | There are a few subtle differences between the Modula-2 scope operator | |
5556 | (@code{.}) and the _GDBN__ scope operator (@code{::}). The two have | |
5557 | similar syntax: | |
5558 | ||
5559 | @example | |
5560 | ||
5561 | @var{module} . @var{id} | |
5562 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
5563 | @end example |
5564 | ||
5565 | @noindent | |
5566 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
5567 | @var{module} the name of a module, and @var{id} is any declared |
5568 | identifier within your program, except another module. | |
c2bbbb22 RP |
5569 | |
5570 | Using the @code{::} operator makes _GDBN__ search the scope | |
5571 | specified by @var{scope} for the identifier @var{id}. If it is not | |
5572 | found in the specified scope, then _GDBN__ will search all scopes | |
5573 | enclosing the one specified by @var{scope}. | |
5574 | ||
5575 | Using the @code{.} operator makes _GDBN__ search the current scope for | |
5576 | the identifier specified by @var{id} that was imported from the | |
5577 | definition module specified by @var{module}. With this operator, it is | |
5578 | an error if the identifier @var{id} was not imported from definition | |
5579 | module @var{module}, or if @var{id} is not an identifier in | |
5580 | @var{module}. | |
5581 | ||
4eb4cf57 | 5582 | @node GDB/M2 |
c2bbbb22 RP |
5583 | @subsubsection _GDBN__ and Modula-2 |
5584 | ||
5585 | Some _GDBN__ commands have little use when debugging Modula-2 programs. | |
5586 | Five subcommands of @code{set print} and @code{show print} apply | |
5587 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5588 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
5589 | apply to C++, and the last to C's @code{union} type, which has no direct | |
5590 | analogue in Modula-2. | |
5591 | ||
1041a570 | 5592 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
5593 | while using any language, is not useful with Modula-2. Its |
5594 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5595 | created in Modula-2 as they can in C or C++. However, because an | |
5596 | address can be specified by an integral constant, the construct | |
1041a570 | 5597 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
5598 | _0__ |
5599 | @cindex @code{#} in Modula-2 | |
5600 | In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is | |
5601 | interpreted as the beginning of a comment. Use @code{<>} instead. | |
5602 | _1__ | |
4eb4cf57 RP |
5603 | _fi__(!_CONLY__) |
5604 | ||
5605 | @node Symbols | |
70b88761 RP |
5606 | @chapter Examining the Symbol Table |
5607 | ||
5608 | The commands described in this section allow you to inquire about the | |
5609 | symbols (names of variables, functions and types) defined in your | |
5610 | program. This information is inherent in the text of your program and | |
29a2b744 | 5611 | does not change as your program executes. _GDBN__ finds it in your |
e251e767 | 5612 | program's symbol table, in the file indicated when you started _GDBN__ |
1041a570 RP |
5613 | (@pxref{File Options, ,Choosing Files}), or by one of the |
5614 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
70b88761 | 5615 | |
6c380b13 RP |
5616 | @c FIXME! This might be intentionally specific to C and C++; if so, move |
5617 | @c to someplace in C section of lang chapter. | |
5618 | @cindex symbol names | |
5619 | @cindex names of symbols | |
5620 | @cindex quoting names | |
5621 | Occasionally, you may need to refer to symbols that contain unusual | |
5622 | characters, which _GDBN__ ordinarily treats as word delimiters. The | |
5623 | most frequent case is in referring to static variables in other | |
5624 | source files (@pxref{Variables,,Program Variables}). File names | |
5625 | are recorded in object files as debugging symbols, but _GDBN__ would | |
5626 | ordinarily parse a typical file name, like @file{foo.c}, as the three words | |
5627 | @samp{foo} @samp{.} @samp{c}. To allow _GDBN__ to recognize | |
5628 | @samp{foo.c} as a single symbol, enclose it in single quotes; for example, | |
5629 | ||
5630 | @example | |
5631 | p 'foo.c'::x | |
5632 | @end example | |
5633 | ||
5634 | @noindent | |
5635 | looks up the value of @code{x} in the scope of the file @file{foo.c}. | |
5636 | ||
70b88761 RP |
5637 | @table @code |
5638 | @item info address @var{symbol} | |
5639 | @kindex info address | |
5640 | Describe where the data for @var{symbol} is stored. For a register | |
5641 | variable, this says which register it is kept in. For a non-register | |
5642 | local variable, this prints the stack-frame offset at which the variable | |
5643 | is always stored. | |
5644 | ||
5645 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5646 | at all for a register variables, and for a stack local variable prints | |
5647 | the exact address of the current instantiation of the variable. | |
5648 | ||
5649 | @item whatis @var{exp} | |
5650 | @kindex whatis | |
5651 | Print the data type of expression @var{exp}. @var{exp} is not | |
5652 | actually evaluated, and any side-effecting operations (such as | |
5653 | assignments or function calls) inside it do not take place. | |
1041a570 | 5654 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
5655 | |
5656 | @item whatis | |
5657 | Print the data type of @code{$}, the last value in the value history. | |
5658 | ||
5659 | @item ptype @var{typename} | |
5660 | @kindex ptype | |
5661 | Print a description of data type @var{typename}. @var{typename} may be | |
5662 | the name of a type, or for C code it may have the form | |
5663 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 5664 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
5665 | |
5666 | @item ptype @var{exp} | |
e0dacfd1 | 5667 | @itemx ptype |
70b88761 | 5668 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 RP |
5669 | differs from @code{whatis} by printing a detailed description, instead |
5670 | of just the name of the type. For example, if your program declares a | |
5671 | variable as | |
5672 | ||
70b88761 RP |
5673 | @example |
5674 | struct complex @{double real; double imag;@} v; | |
5675 | @end example | |
1041a570 | 5676 | |
70b88761 RP |
5677 | @noindent |
5678 | compare the output of the two commands: | |
1041a570 | 5679 | |
70b88761 | 5680 | @example |
1041a570 | 5681 | @group |
70b88761 RP |
5682 | (_GDBP__) whatis v |
5683 | type = struct complex | |
5684 | (_GDBP__) ptype v | |
5685 | type = struct complex @{ | |
5686 | double real; | |
5687 | double imag; | |
5688 | @} | |
1041a570 | 5689 | @end group |
70b88761 | 5690 | @end example |
1041a570 | 5691 | |
e0dacfd1 RP |
5692 | @noindent |
5693 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5694 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
5695 | |
5696 | @item info types @var{regexp} | |
5697 | @itemx info types | |
e251e767 | 5698 | @kindex info types |
70b88761 RP |
5699 | Print a brief description of all types whose name matches @var{regexp} |
5700 | (or all types in your program, if you supply no argument). Each | |
5701 | complete typename is matched as though it were a complete line; thus, | |
5702 | @samp{i type value} gives information on all types in your program whose | |
5703 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5704 | information only on types whose complete name is @code{value}. | |
5705 | ||
5706 | This command differs from @code{ptype} in two ways: first, like | |
5707 | @code{whatis}, it does not print a detailed description; second, it | |
5708 | lists all source files where a type is defined. | |
5709 | ||
5710 | @item info source | |
5711 | @kindex info source | |
5712 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
5713 | the function containing the current point of execution---and the language |
5714 | it was written in. | |
70b88761 RP |
5715 | |
5716 | @item info sources | |
5717 | @kindex info sources | |
29a2b744 | 5718 | Print the names of all source files in your program for which there is |
b80282d5 RP |
5719 | debugging information, organized into two lists: files whose symbols |
5720 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
5721 | |
5722 | @item info functions | |
5723 | @kindex info functions | |
5724 | Print the names and data types of all defined functions. | |
5725 | ||
5726 | @item info functions @var{regexp} | |
5727 | Print the names and data types of all defined functions | |
5728 | whose names contain a match for regular expression @var{regexp}. | |
5729 | Thus, @samp{info fun step} finds all functions whose names | |
5730 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5731 | start with @code{step}. | |
5732 | ||
5733 | @item info variables | |
5734 | @kindex info variables | |
5735 | Print the names and data types of all variables that are declared | |
5736 | outside of functions (i.e., excluding local variables). | |
5737 | ||
5738 | @item info variables @var{regexp} | |
5739 | Print the names and data types of all variables (except for local | |
5740 | variables) whose names contain a match for regular expression | |
5741 | @var{regexp}. | |
5742 | ||
70b88761 RP |
5743 | @ignore |
5744 | This was never implemented. | |
5745 | @item info methods | |
5746 | @itemx info methods @var{regexp} | |
5747 | @kindex info methods | |
5748 | The @code{info methods} command permits the user to examine all defined | |
5749 | methods within C++ program, or (with the @var{regexp} argument) a | |
5750 | specific set of methods found in the various C++ classes. Many | |
5751 | C++ classes provide a large number of methods. Thus, the output | |
5752 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5753 | @code{info-methods} command filters the methods, printing only those | |
5754 | which match the regular-expression @var{regexp}. | |
5755 | @end ignore | |
5756 | ||
d48da190 RP |
5757 | @item maint print symbols @var{filename} |
5758 | @itemx maint print psymbols @var{filename} | |
5759 | @itemx maint print msymbols @var{filename} | |
5760 | @kindex maint print symbols | |
440d9834 | 5761 | @cindex symbol dump |
d48da190 | 5762 | @kindex maint print psymbols |
440d9834 RP |
5763 | @cindex partial symbol dump |
5764 | Write a dump of debugging symbol data into the file @var{filename}. | |
e0dacfd1 | 5765 | These commands are used to debug the _GDBN__ symbol-reading code. Only |
d48da190 RP |
5766 | symbols with debugging data are included. If you use @samp{maint print |
5767 | symbols}, _GDBN__ includes all the symbols for which it has already | |
5768 | collected full details: that is, @var{filename} reflects symbols for | |
5769 | only those files whose symbols _GDBN__ has read. You can use the | |
5770 | command @code{info sources} to find out which files these are. If you | |
5771 | use @samp{maint print psymbols} instead, the dump shows information about | |
5772 | symbols that _GDBN__ only knows partially---that is, symbols defined in | |
5773 | files that _GDBN__ has skimmed, but not yet read completely. Finally, | |
5774 | @samp{maint print msymbols} dumps just the minimal symbol information | |
5775 | required for each object file from which _GDBN__ has read some symbols. | |
5776 | The description of @code{symbol-file} explains how _GDBN__ reads | |
5777 | symbols; both @code{info source} and @code{symbol-file} are described in | |
5778 | @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
5779 | @end table |
5780 | ||
4eb4cf57 | 5781 | @node Altering |
70b88761 RP |
5782 | @chapter Altering Execution |
5783 | ||
29a2b744 | 5784 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
5785 | find out for certain whether correcting the apparent error would lead to |
5786 | correct results in the rest of the run. You can find the answer by | |
5787 | experiment, using the _GDBN__ features for altering execution of the | |
5788 | program. | |
5789 | ||
5790 | For example, you can store new values into variables or memory | |
29a2b744 | 5791 | locations, give your program a signal, restart it at a different address, |
70b88761 RP |
5792 | or even return prematurely from a function to its caller. |
5793 | ||
5794 | @menu | |
b80282d5 RP |
5795 | * Assignment:: Assignment to Variables |
5796 | * Jumping:: Continuing at a Different Address | |
4eb4cf57 | 5797 | _if__(!_BARE__) |
29a2b744 | 5798 | * Signaling:: Giving your program a Signal |
4eb4cf57 | 5799 | _fi__(!_BARE__) |
b80282d5 RP |
5800 | * Returning:: Returning from a Function |
5801 | * Calling:: Calling your Program's Functions | |
c338a2fd | 5802 | * Patching:: Patching your Program |
70b88761 RP |
5803 | @end menu |
5804 | ||
4eb4cf57 | 5805 | @node Assignment |
70b88761 RP |
5806 | @section Assignment to Variables |
5807 | ||
5808 | @cindex assignment | |
5809 | @cindex setting variables | |
5810 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 5811 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
5812 | |
5813 | @example | |
5814 | print x=4 | |
5815 | @end example | |
5816 | ||
5817 | @noindent | |
1041a570 | 5818 | stores the value 4 into the variable @code{x}, and then prints the |
4eb4cf57 RP |
5819 | value of the assignment expression (which is 4). |
5820 | _if__(!_CONLY__) | |
5821 | @xref{Languages, ,Using _GDBN__ with Different Languages}, for more | |
5822 | information on operators in supported languages. | |
5823 | _fi__(!_CONLY__) | |
70b88761 | 5824 | |
70b88761 RP |
5825 | @kindex set variable |
5826 | @cindex variables, setting | |
5827 | If you are not interested in seeing the value of the assignment, use the | |
5828 | @code{set} command instead of the @code{print} command. @code{set} is | |
5829 | really the same as @code{print} except that the expression's value is not | |
1041a570 | 5830 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The |
70b88761 RP |
5831 | expression is evaluated only for its effects. |
5832 | ||
5833 | If the beginning of the argument string of the @code{set} command | |
5834 | appears identical to a @code{set} subcommand, use the @code{set | |
5835 | variable} command instead of just @code{set}. This command is identical | |
5836 | to @code{set} except for its lack of subcommands. For example, a | |
5837 | program might well have a variable @code{width}---which leads to | |
5838 | an error if we try to set a new value with just @samp{set width=13}, as | |
1041a570 RP |
5839 | we might if @code{set width} did not happen to be a _GDBN__ command: |
5840 | ||
70b88761 RP |
5841 | @example |
5842 | (_GDBP__) whatis width | |
5843 | type = double | |
5844 | (_GDBP__) p width | |
5845 | $4 = 13 | |
5846 | (_GDBP__) set width=47 | |
5847 | Invalid syntax in expression. | |
5848 | @end example | |
1041a570 | 5849 | |
70b88761 RP |
5850 | @noindent |
5851 | The invalid expression, of course, is @samp{=47}. What we can do in | |
e251e767 | 5852 | order to actually set our program's variable @code{width} is |
1041a570 | 5853 | |
70b88761 RP |
5854 | @example |
5855 | (_GDBP__) set var width=47 | |
5856 | @end example | |
5857 | ||
1041a570 RP |
5858 | _GDBN__ allows more implicit conversions in assignments than C; you can |
5859 | freely store an integer value into a pointer variable or vice versa, | |
5860 | and any structure can be converted to any other structure that is the | |
5861 | same length or shorter. | |
e251e767 | 5862 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
5863 | @comment /pesch@cygnus.com 18dec1990 |
5864 | ||
5865 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
5866 | construct to generate a value of specified type at a specified address | |
1041a570 | 5867 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
5868 | to memory location @code{0x83040} as an integer (which implies a certain size |
5869 | and representation in memory), and | |
5870 | ||
5871 | @example | |
5872 | set @{int@}0x83040 = 4 | |
5873 | @end example | |
5874 | ||
5875 | @noindent | |
5876 | stores the value 4 into that memory location. | |
5877 | ||
4eb4cf57 | 5878 | @node Jumping |
70b88761 RP |
5879 | @section Continuing at a Different Address |
5880 | ||
29a2b744 | 5881 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
5882 | it stopped, with the @code{continue} command. You can instead continue at |
5883 | an address of your own choosing, with the following commands: | |
5884 | ||
5885 | @table @code | |
5886 | @item jump @var{linespec} | |
5887 | @kindex jump | |
5888 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 RP |
5889 | immediately if there is a breakpoint there. @xref{List, ,Printing |
5890 | Source Lines}, for a description of the different forms of | |
5891 | @var{linespec}. | |
70b88761 RP |
5892 | |
5893 | The @code{jump} command does not change the current stack frame, or | |
5894 | the stack pointer, or the contents of any memory location or any | |
5895 | register other than the program counter. If line @var{linespec} is in | |
5896 | a different function from the one currently executing, the results may | |
5897 | be bizarre if the two functions expect different patterns of arguments or | |
5898 | of local variables. For this reason, the @code{jump} command requests | |
5899 | confirmation if the specified line is not in the function currently | |
5900 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 5901 | well acquainted with the machine-language code of your program. |
70b88761 RP |
5902 | |
5903 | @item jump *@var{address} | |
5904 | Resume execution at the instruction at address @var{address}. | |
5905 | @end table | |
5906 | ||
5907 | You can get much the same effect as the @code{jump} command by storing a | |
5908 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 5909 | does not start your program running; it only changes the address where it |
70b88761 RP |
5910 | @emph{will} run when it is continued. For example, |
5911 | ||
5912 | @example | |
5913 | set $pc = 0x485 | |
5914 | @end example | |
5915 | ||
5916 | @noindent | |
5917 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 RP |
5918 | address @code{0x485}, rather than at the address where your program stopped. |
5919 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
70b88761 RP |
5920 | |
5921 | The most common occasion to use the @code{jump} command is to back up, | |
5922 | perhaps with more breakpoints set, over a portion of a program that has | |
5923 | already executed, in order to examine its execution in more detail. | |
5924 | ||
4eb4cf57 RP |
5925 | _if__(!_BARE__) |
5926 | @node Signaling | |
70b88761 | 5927 | @c @group |
29a2b744 | 5928 | @section Giving your program a Signal |
70b88761 RP |
5929 | |
5930 | @table @code | |
5931 | @item signal @var{signalnum} | |
5932 | @kindex signal | |
29a2b744 | 5933 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
5934 | signal number @var{signalnum}. |
5935 | ||
5936 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 5937 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
5938 | a signal and would ordinary see the signal when resumed with the |
5939 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
5940 | signal. | |
5941 | ||
5942 | @code{signal} does not repeat when you press @key{RET} a second time | |
5943 | after executing the command. | |
5944 | @end table | |
5945 | @c @end group | |
4eb4cf57 | 5946 | _fi__(!_BARE__) |
70b88761 | 5947 | |
4eb4cf57 | 5948 | @node Returning |
70b88761 RP |
5949 | @section Returning from a Function |
5950 | ||
5951 | @table @code | |
5952 | @item return | |
5953 | @itemx return @var{expression} | |
5954 | @cindex returning from a function | |
5955 | @kindex return | |
5956 | You can cancel execution of a function call with the @code{return} | |
5957 | command. If you give an | |
5958 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 5959 | value. |
70b88761 RP |
5960 | @end table |
5961 | ||
5962 | When you use @code{return}, _GDBN__ discards the selected stack frame | |
5963 | (and all frames within it). You can think of this as making the | |
5964 | discarded frame return prematurely. If you wish to specify a value to | |
5965 | be returned, give that value as the argument to @code{return}. | |
5966 | ||
29a2b744 RP |
5967 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
5968 | Frame}), and any other frames inside of it, leaving its caller as the | |
5969 | innermost remaining frame. That frame becomes selected. The | |
5970 | specified value is stored in the registers used for returning values | |
5971 | of functions. | |
70b88761 RP |
5972 | |
5973 | The @code{return} command does not resume execution; it leaves the | |
5974 | program stopped in the state that would exist if the function had just | |
1041a570 RP |
5975 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
5976 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
5977 | selected stack frame returns naturally. | |
70b88761 | 5978 | |
4eb4cf57 | 5979 | @node Calling |
70b88761 RP |
5980 | @section Calling your Program's Functions |
5981 | ||
5982 | @cindex calling functions | |
5983 | @kindex call | |
5984 | @table @code | |
5985 | @item call @var{expr} | |
5986 | Evaluate the expression @var{expr} without displaying @code{void} | |
5987 | returned values. | |
5988 | @end table | |
5989 | ||
5990 | You can use this variant of the @code{print} command if you want to | |
5991 | execute a function from your program, but without cluttering the output | |
5992 | with @code{void} returned values. The result is printed and saved in | |
5993 | the value history, if it is not void. | |
5994 | ||
4eb4cf57 | 5995 | @node Patching |
c338a2fd RP |
5996 | @section Patching your Program |
5997 | @cindex patching binaries | |
5998 | @cindex writing into executables | |
5999 | @cindex writing into corefiles | |
1041a570 | 6000 | |
c338a2fd RP |
6001 | By default, _GDBN__ opens the file containing your program's executable |
6002 | code (or the corefile) read-only. This prevents accidental alterations | |
6003 | to machine code; but it also prevents you from intentionally patching | |
6004 | your program's binary. | |
6005 | ||
6006 | If you'd like to be able to patch the binary, you can specify that | |
6007 | explicitly with the @code{set write} command. For example, you might | |
6008 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 6009 | repairs. |
c338a2fd RP |
6010 | |
6011 | @table @code | |
6012 | @item set write on | |
6013 | @itemx set write off | |
6014 | @kindex set write | |
6015 | If you specify @samp{set write on}, _GDBN__ will open executable and | |
6016 | core files for both reading and writing; if you specify @samp{set write | |
6017 | off} (the default), _GDBN__ will open them read-only. | |
6018 | ||
1041a570 | 6019 | If you have already loaded a file, you must load it |
c338a2fd RP |
6020 | again (using the @code{exec-file} or @code{core-file} command) after |
6021 | changing @code{set write}, for your new setting to take effect. | |
6022 | ||
6023 | @item show write | |
7d7ff5f6 | 6024 | @kindex show write |
c338a2fd RP |
6025 | Display whether executable files and core files will be opened for |
6026 | writing as well as reading. | |
c338a2fd RP |
6027 | @end table |
6028 | ||
4eb4cf57 | 6029 | @node _GDBN__ Files |
70b88761 RP |
6030 | @chapter _GDBN__'s Files |
6031 | ||
1041a570 | 6032 | _GDBN__ needs to know the file name of the program to be debugged, both in |
4eb4cf57 RP |
6033 | order to read its symbol table and in order to start your program. |
6034 | _if__(!_BARE__) | |
6035 | To debug a core dump of a previous run, _GDBN__ must be told the file | |
6036 | name of the core dump. | |
6037 | _fi__(!_BARE__) | |
1041a570 | 6038 | |
70b88761 | 6039 | @menu |
b80282d5 RP |
6040 | * Files:: Commands to Specify Files |
6041 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 RP |
6042 | @end menu |
6043 | ||
4eb4cf57 | 6044 | @node Files |
70b88761 RP |
6045 | @section Commands to Specify Files |
6046 | @cindex core dump file | |
6047 | @cindex symbol table | |
70b88761 | 6048 | |
4eb4cf57 | 6049 | _if__(!_BARE__) |
1041a570 RP |
6050 | The usual way to specify executable and core dump file names is with |
6051 | the command arguments given when you start _GDBN__, (@pxref{Invocation, | |
6052 | ,Getting In and Out of _GDBN__}. | |
4eb4cf57 RP |
6053 | _fi__(!_BARE__) |
6054 | _if__(_BARE__) | |
6055 | The usual way to specify an executable file name is with | |
6056 | the command argument given when you start _GDBN__, (@pxref{Invocation, | |
6057 | ,Getting In and Out of _GDBN__}. | |
6058 | _fi__(_BARE__) | |
70b88761 RP |
6059 | |
6060 | Occasionally it is necessary to change to a different file during a | |
4eb4cf57 | 6061 | _GDBN__ session. Or you may run _GDBN__ and forget to specify a file you |
70b88761 RP |
6062 | want to use. In these situations the _GDBN__ commands to specify new files |
6063 | are useful. | |
6064 | ||
6065 | @table @code | |
6066 | @item file @var{filename} | |
6067 | @cindex executable file | |
6068 | @kindex file | |
6069 | Use @var{filename} as the program to be debugged. It is read for its | |
6070 | symbols and for the contents of pure memory. It is also the program | |
6071 | executed when you use the @code{run} command. If you do not specify a | |
1041a570 RP |
6072 | directory and the file is not found in _GDBN__'s working directory, _GDBN__ |
6073 | uses the environment variable @code{PATH} as a list of directories to | |
6074 | search, just as the shell does when looking for a program to run. You | |
6075 | can change the value of this variable, for both _GDBN__ and your program, | |
6076 | using the @code{path} command. | |
70b88761 | 6077 | |
14d01801 RP |
6078 | On systems with memory-mapped files, an auxiliary symbol table file |
6079 | @file{@var{filename}.syms} may be available for @var{filename}. If it | |
6080 | is, _GDBN__ will map in the symbol table from | |
6081 | @file{@var{filename}.syms}, starting up more quickly. See the | |
95d5ceb9 | 6082 | descriptions of the options @samp{-mapped} and @samp{-readnow} (available |
77b46d13 JG |
6083 | on the command line, and with the commands @code{file}, @code{symbol-file}, |
6084 | or @code{add-symbol-file}), for more information. | |
14d01801 | 6085 | |
e0dacfd1 | 6086 | @item file |
70b88761 RP |
6087 | @code{file} with no argument makes _GDBN__ discard any information it |
6088 | has on both executable file and the symbol table. | |
6089 | ||
e0dacfd1 | 6090 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6091 | @kindex exec-file |
6092 | Specify that the program to be run (but not the symbol table) is found | |
6093 | in @var{filename}. _GDBN__ will search the environment variable @code{PATH} | |
29a2b744 | 6094 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 6095 | discard information on the executable file. |
70b88761 | 6096 | |
e0dacfd1 | 6097 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6098 | @kindex symbol-file |
6099 | Read symbol table information from file @var{filename}. @code{PATH} is | |
6100 | searched when necessary. Use the @code{file} command to get both symbol | |
6101 | table and program to run from the same file. | |
6102 | ||
6103 | @code{symbol-file} with no argument clears out _GDBN__'s information on your | |
6104 | program's symbol table. | |
6105 | ||
6106 | The @code{symbol-file} command causes _GDBN__ to forget the contents of its | |
6107 | convenience variables, the value history, and all breakpoints and | |
6108 | auto-display expressions. This is because they may contain pointers to | |
6109 | the internal data recording symbols and data types, which are part of | |
6110 | the old symbol table data being discarded inside _GDBN__. | |
6111 | ||
6112 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
6113 | executing it once. | |
6114 | ||
14d01801 RP |
6115 | When _GDBN__ is configured for a particular environment, it will |
6116 | understand debugging information in whatever format is the standard | |
6117 | generated for that environment; you may use either a GNU compiler, or | |
6118 | other compilers that adhere to the local conventions. Best results are | |
6119 | usually obtained from GNU compilers; for example, using @code{_GCC__} | |
6120 | you can generate debugging information for optimized code. | |
6121 | ||
70b88761 | 6122 | On some kinds of object files, the @code{symbol-file} command does not |
14d01801 | 6123 | normally read the symbol table in full right away. Instead, it scans |
70b88761 RP |
6124 | the symbol table quickly to find which source files and which symbols |
6125 | are present. The details are read later, one source file at a time, | |
1041a570 | 6126 | as they are needed. |
70b88761 RP |
6127 | |
6128 | The purpose of this two-stage reading strategy is to make _GDBN__ start up | |
1041a570 RP |
6129 | faster. For the most part, it is invisible except for occasional |
6130 | pauses while the symbol table details for a particular source file are | |
6131 | being read. (The @code{set verbose} command can turn these pauses | |
6132 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings | |
6133 | and Messages}.) | |
70b88761 RP |
6134 | |
6135 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
1041a570 | 6136 | read the symbol table data in full right away. We have not implemented |
70b88761 RP |
6137 | the two-stage strategy for COFF yet. |
6138 | ||
95d5ceb9 RP |
6139 | @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
6140 | @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} | |
14d01801 RP |
6141 | @kindex readnow |
6142 | @cindex reading symbols immediately | |
6143 | @cindex symbols, reading immediately | |
6144 | @kindex mapped | |
6145 | @cindex memory-mapped symbol file | |
38962738 | 6146 | @cindex saving symbol table |
14d01801 | 6147 | You can override the _GDBN__ two-stage strategy for reading symbol |
95d5ceb9 | 6148 | tables by using the @samp{-readnow} option with any of the commands that |
14d01801 RP |
6149 | load symbol table information, if you want to be sure _GDBN__ has the |
6150 | entire symbol table available. | |
6151 | ||
4eb4cf57 | 6152 | _if__(!_BARE__) |
14d01801 | 6153 | If memory-mapped files are available on your system through the |
95d5ceb9 | 6154 | @code{mmap} system call, you can use another option, @samp{-mapped}, to |
77b46d13 JG |
6155 | cause _GDBN__ to write the symbols for your program into a reusable |
6156 | file. Future _GDBN__ debugging sessions will map in symbol information | |
6157 | from this auxiliary symbol file (if the program hasn't changed), rather | |
6158 | than spending time reading the symbol table from the executable | |
6159 | program. Using the @samp{-mapped} option has the same effect as | |
6160 | starting _GDBN__ with the @samp{-mapped} command-line option. | |
14d01801 | 6161 | |
95d5ceb9 | 6162 | You can use both options together, to make sure the auxiliary symbol |
14d01801 RP |
6163 | file has all the symbol information for your program. |
6164 | ||
77b46d13 JG |
6165 | The @code{.syms} file is specific to the host machine on which GDB is run. |
6166 | It holds an exact image of GDB's internal symbol table. It cannot be | |
6167 | shared across multiple host platforms. | |
6168 | ||
14d01801 RP |
6169 | The auxiliary symbol file for a program called @var{myprog} is called |
6170 | @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer | |
6171 | than the corresponding executable), _GDBN__ will always attempt to use | |
6172 | it when you debug @var{myprog}; no special options or commands are | |
6173 | needed. | |
6174 | @c FIXME: for now no mention of directories, since this seems to be in | |
6175 | @c flux. 13mar1992 status is that in theory GDB would look either in | |
6176 | @c current dir or in same dir as myprog; but issues like competing | |
6177 | @c GDB's, or clutter in system dirs, mean that in practice right now | |
6178 | @c only current dir is used. FFish says maybe a special GDB hierarchy | |
6179 | @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol | |
6180 | @c files. | |
70b88761 | 6181 | |
e0dacfd1 | 6182 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6183 | @kindex core |
6184 | @kindex core-file | |
6185 | Specify the whereabouts of a core dump file to be used as the ``contents | |
6186 | of memory''. Traditionally, core files contain only some parts of the | |
6187 | address space of the process that generated them; _GDBN__ can access the | |
6188 | executable file itself for other parts. | |
6189 | ||
6190 | @code{core-file} with no argument specifies that no core file is | |
6191 | to be used. | |
6192 | ||
6193 | Note that the core file is ignored when your program is actually running | |
29a2b744 | 6194 | under _GDBN__. So, if you have been running your program and you wish to |
70b88761 RP |
6195 | debug a core file instead, you must kill the subprocess in which the |
6196 | program is running. To do this, use the @code{kill} command | |
1041a570 | 6197 | (@pxref{Kill Process, ,Killing the Child Process}). |
4eb4cf57 | 6198 | _fi__(!_BARE__) |
70b88761 RP |
6199 | |
6200 | @item load @var{filename} | |
6201 | @kindex load | |
6202 | _if__(_GENERIC__) | |
6203 | Depending on what remote debugging facilities are configured into | |
6204 | _GDBN__, the @code{load} command may be available. Where it exists, it | |
6205 | is meant to make @var{filename} (an executable) available for debugging | |
6206 | on the remote system---by downloading, or dynamic linking, for example. | |
6207 | @code{load} also records @var{filename}'s symbol table in _GDBN__, like | |
6208 | the @code{add-symbol-file} command. | |
6209 | ||
6210 | If @code{load} is not available on your _GDBN__, attempting to execute | |
6211 | it gets the error message ``@code{You can't do that when your target is | |
e251e767 | 6212 | @dots{}}'' |
70b88761 RP |
6213 | _fi__(_GENERIC__) |
6214 | ||
e251e767 | 6215 | _if__(_VXWORKS__) |
70b88761 RP |
6216 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
6217 | current target system as well as adding its symbols in _GDBN__. | |
6218 | _fi__(_VXWORKS__) | |
6219 | ||
6220 | _if__(_I960__) | |
6221 | @cindex download to Nindy-960 | |
6222 | With the Nindy interface to an Intel 960 board, @code{load} will | |
6223 | download @var{filename} to the 960 as well as adding its symbols in | |
e251e767 | 6224 | _GDBN__. |
70b88761 RP |
6225 | _fi__(_I960__) |
6226 | ||
c7cb8acb RP |
6227 | _if__(_H8__) |
6228 | @cindex download to H8/300 | |
6229 | @cindex H8/300 download | |
6230 | When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi | |
6231 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}), the | |
6232 | @code{load} command downloads your program to the H8/300 and also opens | |
6233 | it as the current executable target for _GDBN__ on your host (like the | |
6234 | @code{file} command). | |
6235 | _fi__(_H8__) | |
6236 | ||
70b88761 RP |
6237 | @code{load} will not repeat if you press @key{RET} again after using it. |
6238 | ||
6239 | @item add-symbol-file @var{filename} @var{address} | |
95d5ceb9 | 6240 | @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
70b88761 RP |
6241 | @kindex add-symbol-file |
6242 | @cindex dynamic linking | |
6243 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 6244 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
6245 | has been dynamically loaded (by some other means) into the program that |
6246 | is running. @var{address} should be the memory address at which the | |
6247 | file has been loaded; _GDBN__ cannot figure this out for itself. | |
6248 | ||
6249 | The symbol table of the file @var{filename} is added to the symbol table | |
6250 | originally read with the @code{symbol-file} command. You can use the | |
6251 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
6252 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 6253 | use the @code{symbol-file} command. |
70b88761 RP |
6254 | |
6255 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
6256 | ||
95d5ceb9 RP |
6257 | You can use the @samp{-mapped} and @samp{-readnow} options just as with |
6258 | the @code{symbol-file} command, to change how _GDBN__ manages the symbol | |
6259 | tabl einformation for @var{filename}. | |
6260 | ||
70b88761 RP |
6261 | @item info files |
6262 | @itemx info target | |
6263 | @kindex info files | |
6264 | @kindex info target | |
1041a570 RP |
6265 | @code{info files} and @code{info target} are synonymous; both print |
6266 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
6267 | including the names of the executable and core dump files currently in | |
6268 | use by _GDBN__, and the files from which symbols were loaded. The command | |
6269 | @code{help targets} lists all possible targets rather than current | |
6270 | ones. | |
70b88761 RP |
6271 | |
6272 | @end table | |
6273 | ||
6274 | All file-specifying commands allow both absolute and relative file names | |
6275 | as arguments. _GDBN__ always converts the file name to an absolute path | |
6276 | name and remembers it that way. | |
6277 | ||
4eb4cf57 | 6278 | _if__(!_BARE__) |
70b88761 | 6279 | @cindex shared libraries |
77b46d13 JG |
6280 | _GDBN__ supports SunOS, SVR4, and IBM RS/6000 shared libraries. |
6281 | _GDBN__ automatically loads symbol definitions from shared libraries | |
6282 | when you use the @code{run} command, or when you examine a core file. | |
6283 | (Before you issue the @code{run} command, _GDBN__ will not understand | |
6284 | references to a function in a shared library, however---unless you are | |
6285 | debugging a core file). | |
c338a2fd | 6286 | @c FIXME: next _GDBN__ release should permit some refs to undef |
1041a570 | 6287 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
6288 | |
6289 | @table @code | |
70b88761 RP |
6290 | @item info share |
6291 | @itemx info sharedlibrary | |
6292 | @kindex info sharedlibrary | |
6293 | @kindex info share | |
c338a2fd | 6294 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 6295 | |
c338a2fd RP |
6296 | @item sharedlibrary @var{regex} |
6297 | @itemx share @var{regex} | |
6298 | @kindex sharedlibrary | |
6299 | @kindex share | |
6300 | This is an obsolescent command; you can use it to explicitly | |
6301 | load shared object library symbols for files matching a UNIX regular | |
6302 | expression, but as with files loaded automatically, it will only load | |
6303 | shared libraries required by your program for a core file or after | |
6304 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
6305 | required by your program are loaded. | |
6306 | @end table | |
4eb4cf57 | 6307 | _fi__(!_BARE__) |
70b88761 | 6308 | |
4eb4cf57 | 6309 | @node Symbol Errors |
70b88761 | 6310 | @section Errors Reading Symbol Files |
1041a570 RP |
6311 | |
6312 | While reading a symbol file, _GDBN__ will occasionally encounter problems, | |
6313 | such as symbol types it does not recognize, or known bugs in compiler | |
6314 | output. By default, _GDBN__ does not notify you of such problems, since | |
6315 | they are relatively common and primarily of interest to people | |
6316 | debugging compilers. If you are interested in seeing information | |
b80282d5 RP |
6317 | about ill-constructed symbol tables, you can either ask _GDBN__ to print |
6318 | only one message about each such type of problem, no matter how many | |
6319 | times the problem occurs; or you can ask _GDBN__ to print more messages, | |
1041a570 RP |
6320 | to see how many times the problems occur, with the @code{set |
6321 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
6322 | Messages}). | |
70b88761 RP |
6323 | |
6324 | The messages currently printed, and their meanings, are: | |
6325 | ||
6326 | @table @code | |
6327 | @item inner block not inside outer block in @var{symbol} | |
6328 | ||
6329 | The symbol information shows where symbol scopes begin and end | |
6330 | (such as at the start of a function or a block of statements). This | |
6331 | error indicates that an inner scope block is not fully contained | |
e251e767 | 6332 | in its outer scope blocks. |
70b88761 RP |
6333 | |
6334 | _GDBN__ circumvents the problem by treating the inner block as if it had | |
6335 | the same scope as the outer block. In the error message, @var{symbol} | |
6336 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
6337 | function. | |
6338 | ||
6339 | @item block at @var{address} out of order | |
6340 | ||
e251e767 | 6341 | The symbol information for symbol scope blocks should occur in |
70b88761 | 6342 | order of increasing addresses. This error indicates that it does not |
e251e767 | 6343 | do so. |
70b88761 RP |
6344 | |
6345 | _GDBN__ does not circumvent this problem, and will have trouble locating | |
6346 | symbols in the source file whose symbols being read. (You can often | |
6347 | determine what source file is affected by specifying @code{set verbose | |
29a2b744 | 6348 | on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.) |
70b88761 RP |
6349 | |
6350 | @item bad block start address patched | |
6351 | ||
6352 | The symbol information for a symbol scope block has a start address | |
6353 | smaller than the address of the preceding source line. This is known | |
e251e767 | 6354 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 RP |
6355 | |
6356 | _GDBN__ circumvents the problem by treating the symbol scope block as | |
6357 | starting on the previous source line. | |
6358 | ||
70b88761 RP |
6359 | @item bad string table offset in symbol @var{n} |
6360 | ||
6361 | @cindex foo | |
6362 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 6363 | larger than the size of the string table. |
70b88761 RP |
6364 | |
6365 | _GDBN__ circumvents the problem by considering the symbol to have the | |
6366 | name @code{foo}, which may cause other problems if many symbols end up | |
6367 | with this name. | |
6368 | ||
6369 | @item unknown symbol type @code{0x@var{nn}} | |
6370 | ||
6371 | The symbol information contains new data types that _GDBN__ does not yet | |
6372 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
e251e767 | 6373 | information, in hexadecimal. |
70b88761 RP |
6374 | |
6375 | _GDBN__ circumvents the error by ignoring this symbol information. This | |
29a2b744 | 6376 | will usually allow your program to be debugged, though certain symbols |
70b88761 RP |
6377 | will not be accessible. If you encounter such a problem and feel like |
6378 | debugging it, you can debug @code{_GDBP__} with itself, breakpoint on | |
6379 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
6380 | examine @code{*bufp} to see the symbol. | |
6381 | ||
6382 | @item stub type has NULL name | |
e251e767 | 6383 | _GDBN__ could not find the full definition for a struct or class. |
70b88761 | 6384 | |
440d9834 | 6385 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
6386 | |
6387 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
6388 | information that recent versions of the compiler should have output |
6389 | for it. | |
70b88761 | 6390 | |
440d9834 | 6391 | @item info mismatch between compiler and debugger |
70b88761 | 6392 | |
440d9834 | 6393 | _GDBN__ could not parse a type specification output by the compiler. |
70b88761 RP |
6394 | @end table |
6395 | ||
4eb4cf57 | 6396 | @node Targets |
e251e767 | 6397 | @chapter Specifying a Debugging Target |
70b88761 RP |
6398 | @cindex debugging target |
6399 | @kindex target | |
1041a570 | 6400 | |
cedaf8bc | 6401 | A @dfn{target} is the execution environment occupied by your program. |
1041a570 RP |
6402 | Often, _GDBN__ runs in the same host environment as your program; in |
6403 | that case, the debugging target is specified as a side effect when you | |
6404 | use the @code{file} or @code{core} commands. When you need more | |
6405 | flexibility---for example, running _GDBN__ on a physically separate | |
6406 | host, or controlling a standalone system over a serial port or a | |
6407 | realtime system over a TCP/IP connection---you can use the @code{target} | |
6408 | command to specify one of the target types configured for _GDBN__ | |
6409 | (@pxref{Target Commands, ,Commands for Managing Targets}). | |
70b88761 RP |
6410 | |
6411 | @menu | |
b80282d5 RP |
6412 | * Active Targets:: Active Targets |
6413 | * Target Commands:: Commands for Managing Targets | |
6414 | * Remote:: Remote Debugging | |
70b88761 RP |
6415 | @end menu |
6416 | ||
4eb4cf57 | 6417 | @node Active Targets |
70b88761 RP |
6418 | @section Active Targets |
6419 | @cindex stacking targets | |
6420 | @cindex active targets | |
6421 | @cindex multiple targets | |
6422 | ||
cedaf8bc RP |
6423 | There are three classes of targets: processes, core files, and |
6424 | executable files. _GDBN__ can work concurrently on up to three active | |
6425 | targets, one in each class. This allows you to (for example) start a | |
6426 | process and inspect its activity without abandoning your work on a core | |
6427 | file. | |
70b88761 | 6428 | |
cedaf8bc RP |
6429 | If, for example, you execute @samp{gdb a.out}, then the executable file |
6430 | @code{a.out} is the only active target. If you designate a core file as | |
6431 | well---presumably from a prior run that crashed and coredumped---then | |
6432 | _GDBN__ has two active targets and will use them in tandem, looking | |
6433 | first in the corefile target, then in the executable file, to satisfy | |
6434 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 6435 | are complementary, since core files contain only a program's |
cedaf8bc RP |
6436 | read-write memory---variables and so on---plus machine status, while |
6437 | executable files contain only the program text and initialized data.) | |
6438 | ||
6439 | When you type @code{run}, your executable file becomes an active process | |
6440 | target as well. When a process target is active, all _GDBN__ commands | |
6441 | requesting memory addresses refer to that target; addresses in an active | |
6442 | core file or executable file target are obscured while the process | |
6443 | target is active. | |
6444 | ||
4eb4cf57 RP |
6445 | _if__(_BARE__) |
6446 | Use the @code{exec-file} command to select a | |
6447 | new executable target (@pxref{Files, ,Commands to Specify | |
6448 | Files}). | |
6449 | _fi__(_BARE__) | |
6450 | _if__(!_BARE__) | |
1041a570 RP |
6451 | Use the @code{core-file} and @code{exec-file} commands to select a |
6452 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
6453 | Files}). To specify as a target a process that is already running, use | |
6454 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
6455 | Already-Running Process}.). | |
4eb4cf57 | 6456 | _fi__(!_BARE__) |
70b88761 | 6457 | |
4eb4cf57 | 6458 | @node Target Commands |
70b88761 RP |
6459 | @section Commands for Managing Targets |
6460 | ||
6461 | @table @code | |
6462 | @item target @var{type} @var{parameters} | |
6463 | Connects the _GDBN__ host environment to a target machine or process. A | |
6464 | target is typically a protocol for talking to debugging facilities. You | |
6465 | use the argument @var{type} to specify the type or protocol of the | |
6466 | target machine. | |
6467 | ||
6468 | Further @var{parameters} are interpreted by the target protocol, but | |
6469 | typically include things like device names or host names to connect | |
e251e767 | 6470 | with, process numbers, and baud rates. |
70b88761 RP |
6471 | |
6472 | The @code{target} command will not repeat if you press @key{RET} again | |
6473 | after executing the command. | |
6474 | ||
6475 | @item help target | |
6476 | @kindex help target | |
6477 | Displays the names of all targets available. To display targets | |
6478 | currently selected, use either @code{info target} or @code{info files} | |
29a2b744 | 6479 | (@pxref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6480 | |
6481 | @item help target @var{name} | |
6482 | Describe a particular target, including any parameters necessary to | |
6483 | select it. | |
6484 | @end table | |
6485 | ||
c7cb8acb | 6486 | Here are some common targets (available, or not, depending on the GDB |
70b88761 RP |
6487 | configuration): |
6488 | ||
6489 | @table @code | |
6490 | @item target exec @var{prog} | |
6491 | @kindex target exec | |
6492 | An executable file. @samp{target exec @var{prog}} is the same as | |
6493 | @samp{exec-file @var{prog}}. | |
6494 | ||
6495 | @item target core @var{filename} | |
6496 | @kindex target core | |
6497 | A core dump file. @samp{target core @var{filename}} is the same as | |
6498 | @samp{core-file @var{filename}}. | |
6499 | ||
6500 | @item target remote @var{dev} | |
6501 | @kindex target remote | |
c7cb8acb | 6502 | Remote serial target in GDB-specific protocol. The argument @var{dev} |
70b88761 | 6503 | specifies what serial device to use for the connection (e.g. |
1041a570 | 6504 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. |
70b88761 RP |
6505 | |
6506 | _if__(_AMD29K__) | |
6507 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
6508 | @kindex target amd-eb | |
6509 | @cindex AMD EB29K | |
6510 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6511 | @var{dev} is the serial device, as for @code{target remote}; | |
6512 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6513 | name of the program to be debugged, as it appears to DOS on the PC. | |
77fe5411 RP |
6514 | @xref{EB29K Remote, ,_GDBN__ with a Remote EB29K}. |
6515 | ||
6516 | @item target udi | |
6517 | @kindex target udi | |
6518 | @cindex UDI interface to 29K | |
6519 | @cindex AMD UDI-29K | |
6520 | Remote AMD 29K board, attached over the AMD ``Universal Debug | |
6521 | Interface'', a protocol based on TCP/IP. @xref{UDI29K Remote,,_GDBN__ | |
6522 | and the UDI 29K protocol}. | |
70b88761 | 6523 | _fi__(_AMD29K__) |
c7cb8acb RP |
6524 | _if__(_H8__) |
6525 | @item target hms | |
6526 | @kindex target hms | |
6527 | A Hitachi H8/300 board, attached via serial line to your host. Use | |
6528 | special commands @code{device} and @code{speed} to control the serial | |
6529 | line and the communications speed used. @xref{Hitachi H8/300 | |
6530 | Remote,,_GDBN__ and the Hitachi H8/300}. | |
6531 | ||
6532 | _fi__(_H8__) | |
70b88761 RP |
6533 | _if__(_I960__) |
6534 | @item target nindy @var{devicename} | |
6535 | @kindex target nindy | |
6536 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6537 | the name of the serial device to use for the connection, e.g. | |
1041a570 | 6538 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}. |
70b88761 RP |
6539 | |
6540 | _fi__(_I960__) | |
77fe5411 RP |
6541 | _if__(_ST2000__) |
6542 | @item target st2000 @var{dev} @var{speed} | |
6543 | @kindex target st2000 | |
6544 | A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev} | |
6545 | is the name of the device attached to the ST2000 serial line; | |
6546 | @var{speed} is the communication line speed. The arguments are not used | |
6547 | if _GDBN__ is configured to connect to the ST2000 using TCP or Telnet. | |
6548 | @xref{ST2000 Remote,,_GDBN__ with a Tandem ST2000}. | |
6549 | ||
6550 | _fi__(_ST2000__) | |
70b88761 RP |
6551 | _if__(_VXWORKS__) |
6552 | @item target vxworks @var{machinename} | |
6553 | @kindex target vxworks | |
6554 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6555 | is the target system's machine name or IP address. | |
1041a570 | 6556 | @xref{VxWorks Remote, ,_GDBN__ and VxWorks}. |
70b88761 RP |
6557 | _fi__(_VXWORKS__) |
6558 | @end table | |
6559 | ||
6560 | _if__(_GENERIC__) | |
6561 | Different targets are available on different configurations of _GDBN__; your | |
6562 | configuration may have more or fewer targets. | |
6563 | _fi__(_GENERIC__) | |
6564 | ||
4eb4cf57 | 6565 | @node Remote |
70b88761 RP |
6566 | @section Remote Debugging |
6567 | @cindex remote debugging | |
6568 | ||
29a2b744 | 6569 | If you are trying to debug a program running on a machine that cannot run |
c7cb8acb | 6570 | GDB in the usual way, it is often useful to use remote debugging. For |
70b88761 RP |
6571 | example, you might use remote debugging on an operating system kernel, or on |
6572 | a small system which does not have a general purpose operating system | |
e251e767 | 6573 | powerful enough to run a full-featured debugger. |
70b88761 | 6574 | |
c7cb8acb | 6575 | Some configurations of GDB have special serial or TCP/IP interfaces |
70b88761 | 6576 | to make this work with particular debugging targets. In addition, |
c7cb8acb | 6577 | GDB comes with a generic serial protocol (specific to GDB, but |
70b88761 RP |
6578 | not specific to any particular target system) which you can use if you |
6579 | write the remote stubs---the code that will run on the remote system to | |
c7cb8acb | 6580 | communicate with GDB. |
70b88761 | 6581 | |
70b88761 | 6582 | Other remote targets may be available in your |
c7cb8acb | 6583 | configuration of GDB; use @code{help targets} to list them. |
70b88761 RP |
6584 | |
6585 | _if__(_GENERIC__) | |
1041a570 RP |
6586 | _dnl__ Text on starting up GDB in various specific cases; it goes up front |
6587 | _dnl__ in manuals configured for any of those particular situations, here | |
6588 | _dnl__ otherwise. | |
6589 | @menu | |
6590 | _include__(gdbinv-m.m4)<>_dnl__ | |
6591 | @end menu | |
70b88761 RP |
6592 | _include__(gdbinv-s.m4) |
6593 | _fi__(_GENERIC__) | |
6594 | ||
4eb4cf57 | 6595 | @node Controlling _GDBN__ |
70b88761 RP |
6596 | @chapter Controlling _GDBN__ |
6597 | ||
6598 | You can alter many aspects of _GDBN__'s interaction with you by using | |
6599 | the @code{set} command. For commands controlling how _GDBN__ displays | |
1041a570 | 6600 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. |
70b88761 RP |
6601 | |
6602 | @menu | |
b80282d5 RP |
6603 | * Prompt:: Prompt |
6604 | * Editing:: Command Editing | |
6605 | * History:: Command History | |
6606 | * Screen Size:: Screen Size | |
6607 | * Numbers:: Numbers | |
6608 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
6609 | @end menu |
6610 | ||
4eb4cf57 | 6611 | @node Prompt |
70b88761 RP |
6612 | @section Prompt |
6613 | @cindex prompt | |
1041a570 | 6614 | |
70b88761 RP |
6615 | _GDBN__ indicates its readiness to read a command by printing a string |
6616 | called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You | |
6617 | can change the prompt string with the @code{set prompt} command. For | |
6618 | instance, when debugging _GDBN__ with _GDBN__, it is useful to change | |
6619 | the prompt in one of the _GDBN__<>s so that you can always tell which | |
6620 | one you are talking to. | |
6621 | ||
6622 | @table @code | |
6623 | @item set prompt @var{newprompt} | |
6624 | @kindex set prompt | |
6625 | Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth. | |
6626 | @kindex show prompt | |
6627 | @item show prompt | |
6628 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6629 | @end table | |
6630 | ||
4eb4cf57 | 6631 | @node Editing |
70b88761 RP |
6632 | @section Command Editing |
6633 | @cindex readline | |
6634 | @cindex command line editing | |
1041a570 | 6635 | |
70b88761 RP |
6636 | _GDBN__ reads its input commands via the @dfn{readline} interface. This |
6637 | GNU library provides consistent behavior for programs which provide a | |
6638 | command line interface to the user. Advantages are @code{emacs}-style | |
6639 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6640 | substitution, and a storage and recall of command history across | |
6641 | debugging sessions. | |
6642 | ||
6643 | You may control the behavior of command line editing in _GDBN__ with the | |
e251e767 | 6644 | command @code{set}. |
70b88761 RP |
6645 | |
6646 | @table @code | |
6647 | @kindex set editing | |
6648 | @cindex editing | |
6649 | @item set editing | |
6650 | @itemx set editing on | |
6651 | Enable command line editing (enabled by default). | |
6652 | ||
6653 | @item set editing off | |
6654 | Disable command line editing. | |
6655 | ||
6656 | @kindex show editing | |
6657 | @item show editing | |
6658 | Show whether command line editing is enabled. | |
6659 | @end table | |
6660 | ||
4eb4cf57 | 6661 | @node History |
70b88761 | 6662 | @section Command History |
1041a570 | 6663 | |
70b88761 RP |
6664 | @table @code |
6665 | @cindex history substitution | |
6666 | @cindex history file | |
6667 | @kindex set history filename | |
6668 | @item set history filename @var{fname} | |
6669 | Set the name of the _GDBN__ command history file to @var{fname}. This is | |
6670 | the file from which _GDBN__ will read an initial command history | |
6671 | list or to which it will write this list when it exits. This list is | |
6672 | accessed through history expansion or through the history | |
6673 | command editing characters listed below. This file defaults to the | |
6674 | value of the environment variable @code{GDBHISTFILE}, or to | |
6675 | @file{./.gdb_history} if this variable is not set. | |
6676 | ||
6677 | @cindex history save | |
6678 | @kindex set history save | |
6679 | @item set history save | |
6680 | @itemx set history save on | |
6681 | Record command history in a file, whose name may be specified with the | |
6682 | @code{set history filename} command. By default, this option is disabled. | |
6683 | ||
6684 | @item set history save off | |
6685 | Stop recording command history in a file. | |
6686 | ||
6687 | @cindex history size | |
6688 | @kindex set history size | |
6689 | @item set history size @var{size} | |
6690 | Set the number of commands which _GDBN__ will keep in its history list. | |
6691 | This defaults to the value of the environment variable | |
6692 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6693 | @end table | |
6694 | ||
6695 | @cindex history expansion | |
6696 | History expansion assigns special meaning to the character @kbd{!}. | |
6697 | @iftex | |
1041a570 | 6698 | @xref{Event Designators}. |
70b88761 RP |
6699 | @end iftex |
6700 | Since @kbd{!} is also the logical not operator in C, history expansion | |
6701 | is off by default. If you decide to enable history expansion with the | |
6702 | @code{set history expansion on} command, you may sometimes need to | |
6703 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
6704 | a space or a tab to prevent it from being expanded. The readline | |
6705 | history facilities will not attempt substitution on the strings | |
6706 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
6707 | ||
6708 | The commands to control history expansion are: | |
6709 | ||
6710 | @table @code | |
6711 | ||
6712 | @kindex set history expansion | |
6713 | @item set history expansion on | |
6714 | @itemx set history expansion | |
6715 | Enable history expansion. History expansion is off by default. | |
6716 | ||
6717 | @item set history expansion off | |
6718 | Disable history expansion. | |
6719 | ||
6720 | The readline code comes with more complete documentation of | |
6721 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 6722 | or @code{vi} may wish to read it. |
70b88761 RP |
6723 | @iftex |
6724 | @xref{Command Line Editing}. | |
6725 | @end iftex | |
6726 | ||
6727 | @c @group | |
6728 | @kindex show history | |
6729 | @item show history | |
6730 | @itemx show history filename | |
6731 | @itemx show history save | |
6732 | @itemx show history size | |
6733 | @itemx show history expansion | |
6734 | These commands display the state of the _GDBN__ history parameters. | |
6735 | @code{show history} by itself displays all four states. | |
6736 | @c @end group | |
70b88761 RP |
6737 | @end table |
6738 | ||
6739 | @table @code | |
6740 | @kindex show commands | |
6741 | @item show commands | |
6742 | Display the last ten commands in the command history. | |
6743 | ||
6744 | @item show commands @var{n} | |
6745 | Print ten commands centered on command number @var{n}. | |
6746 | ||
6747 | @item show commands + | |
6748 | Print ten commands just after the commands last printed. | |
70b88761 RP |
6749 | @end table |
6750 | ||
4eb4cf57 | 6751 | @node Screen Size |
70b88761 RP |
6752 | @section Screen Size |
6753 | @cindex size of screen | |
6754 | @cindex pauses in output | |
1041a570 | 6755 | |
70b88761 RP |
6756 | Certain commands to _GDBN__ may produce large amounts of information |
6757 | output to the screen. To help you read all of it, _GDBN__ pauses and | |
6758 | asks you for input at the end of each page of output. Type @key{RET} | |
6759 | when you want to continue the output. _GDBN__ also uses the screen | |
6760 | width setting to determine when to wrap lines of output. Depending on | |
6761 | what is being printed, it tries to break the line at a readable place, | |
6762 | rather than simply letting it overflow onto the following line. | |
6763 | ||
6764 | Normally _GDBN__ knows the size of the screen from the termcap data base | |
6765 | together with the value of the @code{TERM} environment variable and the | |
6766 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
6767 | you can override it with the @code{set height} and @code{set | |
6768 | width} commands: | |
6769 | ||
6770 | @table @code | |
6771 | @item set height @var{lpp} | |
6772 | @itemx show height | |
6773 | @itemx set width @var{cpl} | |
6774 | @itemx show width | |
6775 | @kindex set height | |
6776 | @kindex set width | |
6777 | @kindex show width | |
6778 | @kindex show height | |
6779 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
6780 | a screen width of @var{cpl} characters. The associated @code{show} | |
6781 | commands display the current settings. | |
6782 | ||
6783 | If you specify a height of zero lines, _GDBN__ will not pause during output | |
6784 | no matter how long the output is. This is useful if output is to a file | |
6785 | or to an editor buffer. | |
6786 | @end table | |
6787 | ||
4eb4cf57 | 6788 | @node Numbers |
70b88761 RP |
6789 | @section Numbers |
6790 | @cindex number representation | |
6791 | @cindex entering numbers | |
1041a570 | 6792 | |
70b88761 RP |
6793 | You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by |
6794 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
6795 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
6796 | Numbers that begin with none of these are, by default, entered in base | |
6797 | 10; likewise, the default display for numbers---when no particular | |
6798 | format is specified---is base 10. You can change the default base for | |
6799 | both input and output with the @code{set radix} command. | |
6800 | ||
6801 | @table @code | |
6802 | @kindex set radix | |
6803 | @item set radix @var{base} | |
6804 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 6805 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
6806 | specified either unambiguously or using the current default radix; for |
6807 | example, any of | |
6808 | ||
6809 | @example | |
c2bbbb22 | 6810 | set radix 1010 |
70b88761 RP |
6811 | set radix 012 |
6812 | set radix 10. | |
6813 | set radix 0xa | |
6814 | @end example | |
6815 | ||
6816 | @noindent | |
6817 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
6818 | will leave the radix unchanged no matter what it was. | |
6819 | ||
6820 | @kindex show radix | |
6821 | @item show radix | |
6822 | Display the current default base for numeric input and display. | |
70b88761 RP |
6823 | @end table |
6824 | ||
4eb4cf57 | 6825 | @node Messages/Warnings |
70b88761 | 6826 | @section Optional Warnings and Messages |
1041a570 | 6827 | |
70b88761 RP |
6828 | By default, _GDBN__ is silent about its inner workings. If you are running |
6829 | on a slow machine, you may want to use the @code{set verbose} command. | |
6830 | It will make _GDBN__ tell you when it does a lengthy internal operation, so | |
1041a570 | 6831 | you will not think it has crashed. |
70b88761 | 6832 | |
1041a570 | 6833 | Currently, the messages controlled by @code{set verbose} are those |
d48da190 RP |
6834 | which announce that the symbol table for a source file is being read; |
6835 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
6836 | |
6837 | @table @code | |
6838 | @kindex set verbose | |
6839 | @item set verbose on | |
6840 | Enables _GDBN__'s output of certain informational messages. | |
6841 | ||
6842 | @item set verbose off | |
6843 | Disables _GDBN__'s output of certain informational messages. | |
6844 | ||
6845 | @kindex show verbose | |
6846 | @item show verbose | |
6847 | Displays whether @code{set verbose} is on or off. | |
6848 | @end table | |
6849 | ||
b80282d5 RP |
6850 | By default, if _GDBN__ encounters bugs in the symbol table of an object |
6851 | file, it is silent; but if you are debugging a compiler, you may find | |
1041a570 | 6852 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). |
70b88761 RP |
6853 | |
6854 | @table @code | |
6855 | @kindex set complaints | |
6856 | @item set complaints @var{limit} | |
6857 | Permits _GDBN__ to output @var{limit} complaints about each type of unusual | |
6858 | symbols before becoming silent about the problem. Set @var{limit} to | |
6859 | zero to suppress all complaints; set it to a large number to prevent | |
6860 | complaints from being suppressed. | |
6861 | ||
6862 | @kindex show complaints | |
6863 | @item show complaints | |
6864 | Displays how many symbol complaints _GDBN__ is permitted to produce. | |
6865 | @end table | |
6866 | ||
b21b18e1 | 6867 | By default, _GDBN__ is cautious, and asks what sometimes seems to be a |
70b88761 RP |
6868 | lot of stupid questions to confirm certain commands. For example, if |
6869 | you try to run a program which is already running: | |
1041a570 | 6870 | |
70b88761 RP |
6871 | @example |
6872 | (_GDBP__) run | |
6873 | The program being debugged has been started already. | |
e251e767 | 6874 | Start it from the beginning? (y or n) |
70b88761 RP |
6875 | @end example |
6876 | ||
29a2b744 | 6877 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
6878 | commands, you can disable this ``feature'': |
6879 | ||
6880 | @table @code | |
6881 | @kindex set confirm | |
6882 | @cindex flinching | |
6883 | @cindex confirmation | |
6884 | @cindex stupid questions | |
6885 | @item set confirm off | |
6886 | Disables confirmation requests. | |
6887 | ||
6888 | @item set confirm on | |
6889 | Enables confirmation requests (the default). | |
6890 | ||
6891 | @item show confirm | |
6892 | @kindex show confirm | |
6893 | Displays state of confirmation requests. | |
6894 | @end table | |
6895 | ||
29a2b744 | 6896 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
6897 | @cindex reloading symbols |
6898 | Some systems allow individual object files that make up your program to | |
6899 | be replaced without stopping and restarting your program. | |
6900 | _if__(_VXWORKS__) | |
6901 | For example, in VxWorks you can simply recompile a defective object file | |
6902 | and keep on running. | |
6903 | _fi__(_VXWORKS__) | |
29a2b744 | 6904 | If you are running on one of these systems, you can allow _GDBN__ to |
1041a570 RP |
6905 | reload the symbols for automatically relinked modules: |
6906 | ||
b80282d5 RP |
6907 | @table @code |
6908 | @kindex set symbol-reloading | |
6909 | @item set symbol-reloading on | |
6910 | Replace symbol definitions for the corresponding source file when an | |
6911 | object file with a particular name is seen again. | |
6912 | ||
6913 | @item set symbol-reloading off | |
1041a570 | 6914 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 6915 | the same name. This is the default state; if you are not running on a |
b80282d5 RP |
6916 | system that permits automatically relinking modules, you should leave |
6917 | @code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols | |
6918 | when linking large programs, that may contain several modules (from | |
6919 | different directories or libraries) with the same name. | |
6920 | ||
6921 | @item show symbol-reloading | |
6922 | Show the current @code{on} or @code{off} setting. | |
6923 | @end table | |
6924 | ||
4eb4cf57 | 6925 | @node Sequences |
70b88761 RP |
6926 | @chapter Canned Sequences of Commands |
6927 | ||
29a2b744 | 6928 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
1041a570 RP |
6929 | Command Lists}), _GDBN__ provides two ways to store sequences of commands |
6930 | for execution as a unit: user-defined commands and command files. | |
70b88761 RP |
6931 | |
6932 | @menu | |
b80282d5 RP |
6933 | * Define:: User-Defined Commands |
6934 | * Command Files:: Command Files | |
6935 | * Output:: Commands for Controlled Output | |
70b88761 RP |
6936 | @end menu |
6937 | ||
4eb4cf57 | 6938 | @node Define |
70b88761 RP |
6939 | @section User-Defined Commands |
6940 | ||
6941 | @cindex user-defined command | |
6942 | A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you | |
6943 | assign a new name as a command. This is done with the @code{define} | |
6944 | command. | |
6945 | ||
6946 | @table @code | |
6947 | @item define @var{commandname} | |
6948 | @kindex define | |
6949 | Define a command named @var{commandname}. If there is already a command | |
6950 | by that name, you are asked to confirm that you want to redefine it. | |
6951 | ||
6952 | The definition of the command is made up of other _GDBN__ command lines, | |
6953 | which are given following the @code{define} command. The end of these | |
6954 | commands is marked by a line containing @code{end}. | |
6955 | ||
6956 | @item document @var{commandname} | |
6957 | @kindex document | |
6958 | Give documentation to the user-defined command @var{commandname}. The | |
6959 | command @var{commandname} must already be defined. This command reads | |
6960 | lines of documentation just as @code{define} reads the lines of the | |
6961 | command definition, ending with @code{end}. After the @code{document} | |
6962 | command is finished, @code{help} on command @var{commandname} will print | |
6963 | the documentation you have specified. | |
6964 | ||
6965 | You may use the @code{document} command again to change the | |
6966 | documentation of a command. Redefining the command with @code{define} | |
6967 | does not change the documentation. | |
6968 | ||
6969 | @item help user-defined | |
6970 | @kindex help user-defined | |
6971 | List all user-defined commands, with the first line of the documentation | |
6972 | (if any) for each. | |
6973 | ||
4768ba62 JG |
6974 | @item show user |
6975 | @itemx show user @var{commandname} | |
6976 | @kindex show user | |
70b88761 RP |
6977 | Display the _GDBN__ commands used to define @var{commandname} (but not its |
6978 | documentation). If no @var{commandname} is given, display the | |
6979 | definitions for all user-defined commands. | |
6980 | @end table | |
6981 | ||
6982 | User-defined commands do not take arguments. When they are executed, the | |
6983 | commands of the definition are not printed. An error in any command | |
6984 | stops execution of the user-defined command. | |
6985 | ||
6986 | Commands that would ask for confirmation if used interactively proceed | |
6987 | without asking when used inside a user-defined command. Many _GDBN__ commands | |
6988 | that normally print messages to say what they are doing omit the messages | |
6989 | when used in a user-defined command. | |
6990 | ||
4eb4cf57 | 6991 | @node Command Files |
70b88761 RP |
6992 | @section Command Files |
6993 | ||
6994 | @cindex command files | |
6995 | A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments | |
6996 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
6997 | command file does nothing; it does not mean to repeat the last command, as | |
6998 | it would from the terminal. | |
6999 | ||
7000 | @cindex init file | |
7001 | @cindex @file{_GDBINIT__} | |
7002 | When you start _GDBN__, it automatically executes commands from its | |
1041a570 RP |
7003 | @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads |
7004 | the init file (if any) in your home directory and then the init file | |
7005 | (if any) in the current working directory. (The init files are not | |
7006 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
7007 | ,Choosing Modes}.) You can also request the execution of a command | |
7008 | file with the @code{source} command: | |
70b88761 RP |
7009 | |
7010 | @table @code | |
7011 | @item source @var{filename} | |
7012 | @kindex source | |
7013 | Execute the command file @var{filename}. | |
7014 | @end table | |
7015 | ||
7016 | The lines in a command file are executed sequentially. They are not | |
7017 | printed as they are executed. An error in any command terminates execution | |
7018 | of the command file. | |
7019 | ||
7020 | Commands that would ask for confirmation if used interactively proceed | |
7021 | without asking when used in a command file. Many _GDBN__ commands that | |
7022 | normally print messages to say what they are doing omit the messages | |
7023 | when called from command files. | |
7024 | ||
4eb4cf57 | 7025 | @node Output |
70b88761 RP |
7026 | @section Commands for Controlled Output |
7027 | ||
7028 | During the execution of a command file or a user-defined command, normal | |
7029 | _GDBN__ output is suppressed; the only output that appears is what is | |
7030 | explicitly printed by the commands in the definition. This section | |
7031 | describes three commands useful for generating exactly the output you | |
7032 | want. | |
7033 | ||
7034 | @table @code | |
7035 | @item echo @var{text} | |
7036 | @kindex echo | |
29a2b744 RP |
7037 | @c I do not consider backslash-space a standard C escape sequence |
7038 | @c because it is not in ANSI. | |
1041a570 RP |
7039 | Print @var{text}. Nonprinting characters can be included in |
7040 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
7041 | newline. @strong{No newline will be printed unless you specify one.} | |
7042 | In addition to the standard C escape sequences, a backslash followed | |
7043 | by a space stands for a space. This is useful for outputting a | |
7044 | string with spaces at the beginning or the end, since leading and | |
7045 | trailing spaces are otherwise trimmed from all arguments. | |
7046 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
7047 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
7048 | |
7049 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7050 | the command onto subsequent lines. For example, | |
7051 | ||
7052 | @example | |
7053 | echo This is some text\n\ | |
7054 | which is continued\n\ | |
7055 | onto several lines.\n | |
7056 | @end example | |
7057 | ||
7058 | produces the same output as | |
7059 | ||
7060 | @example | |
7061 | echo This is some text\n | |
7062 | echo which is continued\n | |
7063 | echo onto several lines.\n | |
7064 | @end example | |
7065 | ||
7066 | @item output @var{expression} | |
7067 | @kindex output | |
7068 | Print the value of @var{expression} and nothing but that value: no | |
7069 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 7070 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 7071 | expressions. |
70b88761 RP |
7072 | |
7073 | @item output/@var{fmt} @var{expression} | |
7074 | Print the value of @var{expression} in format @var{fmt}. You can use | |
7075 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
7076 | information. | |
7077 | ||
7078 | @item printf @var{string}, @var{expressions}@dots{} | |
7079 | @kindex printf | |
7080 | Print the values of the @var{expressions} under the control of | |
7081 | @var{string}. The @var{expressions} are separated by commas and may | |
7082 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 7083 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
7084 | |
7085 | @example | |
7086 | printf (@var{string}, @var{expressions}@dots{}); | |
7087 | @end example | |
7088 | ||
7089 | For example, you can print two values in hex like this: | |
7090 | ||
0fd24984 | 7091 | @smallexample |
70b88761 | 7092 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo |
0fd24984 | 7093 | @end smallexample |
70b88761 RP |
7094 | |
7095 | The only backslash-escape sequences that you can use in the format | |
7096 | string are the simple ones that consist of backslash followed by a | |
7097 | letter. | |
7098 | @end table | |
7099 | ||
4eb4cf57 RP |
7100 | _if__(!_DOSHOST__) |
7101 | @node Emacs | |
70b88761 RP |
7102 | @chapter Using _GDBN__ under GNU Emacs |
7103 | ||
7104 | @cindex emacs | |
7105 | A special interface allows you to use GNU Emacs to view (and | |
7106 | edit) the source files for the program you are debugging with | |
7107 | _GDBN__. | |
7108 | ||
7109 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
7110 | executable file you want to debug as an argument. This command starts | |
7111 | _GDBN__ as a subprocess of Emacs, with input and output through a newly | |
7112 | created Emacs buffer. | |
7113 | ||
7114 | Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two | |
7115 | things: | |
7116 | ||
7117 | @itemize @bullet | |
7118 | @item | |
e251e767 | 7119 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
7120 | @end itemize |
7121 | ||
7122 | This applies both to _GDBN__ commands and their output, and to the input | |
7123 | and output done by the program you are debugging. | |
7124 | ||
7125 | This is useful because it means that you can copy the text of previous | |
7126 | commands and input them again; you can even use parts of the output | |
7127 | in this way. | |
7128 | ||
3d3ab540 RP |
7129 | All the facilities of Emacs' Shell mode are available for interacting |
7130 | with your program. In particular, you can send signals the usual | |
7131 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
7132 | stop. | |
70b88761 RP |
7133 | |
7134 | @itemize @bullet | |
7135 | @item | |
e251e767 | 7136 | _GDBN__ displays source code through Emacs. |
70b88761 RP |
7137 | @end itemize |
7138 | ||
7139 | Each time _GDBN__ displays a stack frame, Emacs automatically finds the | |
7140 | source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the | |
7141 | left margin of the current line. Emacs uses a separate buffer for | |
7142 | source display, and splits the window to show both your _GDBN__ session | |
7143 | and the source. | |
7144 | ||
7145 | Explicit _GDBN__ @code{list} or search commands still produce output as | |
7146 | usual, but you probably will have no reason to use them. | |
7147 | ||
7148 | @quotation | |
7149 | @emph{Warning:} If the directory where your program resides is not your | |
7150 | current directory, it can be easy to confuse Emacs about the location of | |
7151 | the source files, in which case the auxiliary display buffer will not | |
7152 | appear to show your source. _GDBN__ can find programs by searching your | |
7153 | environment's @code{PATH} variable, so the _GDBN__ input and output | |
29a2b744 | 7154 | session will proceed normally; but Emacs does not get enough information |
70b88761 RP |
7155 | back from _GDBN__ to locate the source files in this situation. To |
7156 | avoid this problem, either start _GDBN__ mode from the directory where | |
7157 | your program resides, or specify a full path name when prompted for the | |
7158 | @kbd{M-x gdb} argument. | |
7159 | ||
7160 | A similar confusion can result if you use the _GDBN__ @code{file} command to | |
7161 | switch to debugging a program in some other location, from an existing | |
7162 | _GDBN__ buffer in Emacs. | |
7163 | @end quotation | |
7164 | ||
7165 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
7166 | you need to call _GDBN__ by a different name (for example, if you keep | |
7167 | several configurations around, with different names) you can set the | |
7168 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 7169 | |
70b88761 RP |
7170 | @example |
7171 | (setq gdb-command-name "mygdb") | |
7172 | @end example | |
1041a570 | 7173 | |
70b88761 RP |
7174 | @noindent |
7175 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
7176 | in your @file{.emacs} file) will make Emacs call the program named | |
7177 | ``@code{mygdb}'' instead. | |
7178 | ||
7179 | In the _GDBN__ I/O buffer, you can use these special Emacs commands in | |
7180 | addition to the standard Shell mode commands: | |
7181 | ||
7182 | @table @kbd | |
7183 | @item C-h m | |
7184 | Describe the features of Emacs' _GDBN__ Mode. | |
7185 | ||
7186 | @item M-s | |
7187 | Execute to another source line, like the _GDBN__ @code{step} command; also | |
7188 | update the display window to show the current file and location. | |
7189 | ||
7190 | @item M-n | |
7191 | Execute to next source line in this function, skipping all function | |
7192 | calls, like the _GDBN__ @code{next} command. Then update the display window | |
7193 | to show the current file and location. | |
7194 | ||
7195 | @item M-i | |
7196 | Execute one instruction, like the _GDBN__ @code{stepi} command; update | |
7197 | display window accordingly. | |
7198 | ||
7199 | @item M-x gdb-nexti | |
7200 | Execute to next instruction, using the _GDBN__ @code{nexti} command; update | |
7201 | display window accordingly. | |
7202 | ||
7203 | @item C-c C-f | |
7204 | Execute until exit from the selected stack frame, like the _GDBN__ | |
7205 | @code{finish} command. | |
7206 | ||
7207 | @item M-c | |
29a2b744 | 7208 | Continue execution of your program, like the _GDBN__ @code{continue} |
1041a570 | 7209 | command. |
203eea5d RP |
7210 | |
7211 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
7212 | |
7213 | @item M-u | |
7214 | Go up the number of frames indicated by the numeric argument | |
7215 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
1041a570 | 7216 | like the _GDBN__ @code{up} command. |
203eea5d | 7217 | |
1041a570 | 7218 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
7219 | |
7220 | @item M-d | |
7221 | Go down the number of frames indicated by the numeric argument, like the | |
1041a570 | 7222 | _GDBN__ @code{down} command. |
203eea5d RP |
7223 | |
7224 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
7225 | |
7226 | @item C-x & | |
7227 | Read the number where the cursor is positioned, and insert it at the end | |
7228 | of the _GDBN__ I/O buffer. For example, if you wish to disassemble code | |
7229 | around an address that was displayed earlier, type @kbd{disassemble}; | |
7230 | then move the cursor to the address display, and pick up the | |
e251e767 | 7231 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 RP |
7232 | |
7233 | You can customize this further on the fly by defining elements of the list | |
7234 | @code{gdb-print-command}; once it is defined, you can format or | |
7235 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 7236 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
7237 | wish special formatting, and act as an index to pick an element of the |
7238 | list. If the list element is a string, the number to be inserted is | |
7239 | formatted using the Emacs function @code{format}; otherwise the number | |
7240 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
7241 | @end table |
7242 | ||
7243 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
7244 | tells _GDBN__ to set a breakpoint on the source line point is on. | |
7245 | ||
7246 | If you accidentally delete the source-display buffer, an easy way to get | |
7247 | it back is to type the command @code{f} in the _GDBN__ buffer, to | |
7248 | request a frame display; when you run under Emacs, this will recreate | |
7249 | the source buffer if necessary to show you the context of the current | |
7250 | frame. | |
7251 | ||
7252 | The source files displayed in Emacs are in ordinary Emacs buffers | |
7253 | which are visiting the source files in the usual way. You can edit | |
7254 | the files with these buffers if you wish; but keep in mind that _GDBN__ | |
7255 | communicates with Emacs in terms of line numbers. If you add or | |
7256 | delete lines from the text, the line numbers that _GDBN__ knows will cease | |
7257 | to correspond properly to the code. | |
7258 | ||
7259 | @c The following dropped because Epoch is nonstandard. Reactivate | |
7260 | @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990 | |
7261 | @ignore | |
e251e767 | 7262 | @kindex emacs epoch environment |
70b88761 RP |
7263 | @kindex epoch |
7264 | @kindex inspect | |
7265 | ||
7266 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
7267 | environment. Users of this environment can use a new command, | |
7268 | @code{inspect} which performs identically to @code{print} except that | |
7269 | each value is printed in its own window. | |
7270 | @end ignore | |
4eb4cf57 | 7271 | _fi__(!_DOSHOST__) |
70b88761 | 7272 | |
6ca72cc6 | 7273 | _if__(_LUCID__) |
4eb4cf57 | 7274 | @node Energize |
6ca72cc6 RP |
7275 | @chapter Using _GDBN__ with Energize |
7276 | ||
7277 | @cindex Energize | |
7278 | The Energize Programming System is an integrated development environment | |
7279 | that includes a point-and-click interface to many programming tools. | |
7280 | When you use _GDBN__ in this environment, you can use the standard | |
7281 | Energize graphical interface to drive _GDBN__; you can also, if you | |
7282 | choose, type _GDBN__ commands as usual in a debugging window. Even if | |
7283 | you use the graphical interface, the debugging window (which uses Emacs, | |
7284 | and resembles the standard Emacs interface to _GDBN__) displays the | |
7285 | equivalent commands, so that the history of your debugging session is | |
7286 | properly reflected. | |
7287 | ||
7288 | When Energize starts up a _GDBN__ session, it uses one of the | |
7289 | command-line options @samp{-energize} or @samp{-cadillac} (``cadillac'' | |
7290 | is the name of the communications protocol used by the Energize system). | |
7291 | This option makes _GDBN__ run as one of the tools in the Energize Tool | |
7292 | Set: it sends all output to the Energize kernel, and accept input from | |
7293 | it as well. | |
7294 | ||
7295 | See the user manual for the Energize Programming System for | |
7296 | information on how to use the Energize graphical interface and the other | |
7297 | development tools that Energize integrates with _GDBN__. | |
7298 | ||
6ca72cc6 | 7299 | _fi__(_LUCID__) |
4eb4cf57 RP |
7300 | |
7301 | @node _GDBN__ Bugs | |
70b88761 RP |
7302 | @chapter Reporting Bugs in _GDBN__ |
7303 | @cindex Bugs in _GDBN__ | |
7304 | @cindex Reporting Bugs in _GDBN__ | |
7305 | ||
7306 | Your bug reports play an essential role in making _GDBN__ reliable. | |
7307 | ||
7308 | Reporting a bug may help you by bringing a solution to your problem, or it | |
7309 | may not. But in any case the principal function of a bug report is to help | |
7310 | the entire community by making the next version of _GDBN__ work better. Bug | |
7311 | reports are your contribution to the maintenance of _GDBN__. | |
7312 | ||
7313 | In order for a bug report to serve its purpose, you must include the | |
7314 | information that enables us to fix the bug. | |
7315 | ||
7316 | @menu | |
b80282d5 RP |
7317 | * Bug Criteria:: Have You Found a Bug? |
7318 | * Bug Reporting:: How to Report Bugs | |
70b88761 RP |
7319 | @end menu |
7320 | ||
4eb4cf57 | 7321 | @node Bug Criteria |
70b88761 RP |
7322 | @section Have You Found a Bug? |
7323 | @cindex Bug Criteria | |
7324 | ||
7325 | If you are not sure whether you have found a bug, here are some guidelines: | |
7326 | ||
7327 | @itemize @bullet | |
7328 | @item | |
7329 | @cindex Fatal Signal | |
7330 | @cindex Core Dump | |
7331 | If the debugger gets a fatal signal, for any input whatever, that is a | |
7332 | _GDBN__ bug. Reliable debuggers never crash. | |
7333 | ||
7334 | @item | |
7335 | @cindex error on Valid Input | |
7336 | If _GDBN__ produces an error message for valid input, that is a bug. | |
7337 | ||
7338 | @item | |
7339 | @cindex Invalid Input | |
7340 | If _GDBN__ does not produce an error message for invalid input, | |
7341 | that is a bug. However, you should note that your idea of | |
7342 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
7343 | for traditional practice''. | |
7344 | ||
7345 | @item | |
7346 | If you are an experienced user of debugging tools, your suggestions | |
7347 | for improvement of _GDBN__ are welcome in any case. | |
7348 | @end itemize | |
7349 | ||
4eb4cf57 | 7350 | @node Bug Reporting |
70b88761 RP |
7351 | @section How to Report Bugs |
7352 | @cindex Bug Reports | |
3d3ab540 | 7353 | @cindex _GDBN__ Bugs, Reporting |
70b88761 RP |
7354 | |
7355 | A number of companies and individuals offer support for GNU products. | |
7356 | If you obtained _GDBN__ from a support organization, we recommend you | |
e251e767 | 7357 | contact that organization first. |
70b88761 RP |
7358 | |
7359 | Contact information for many support companies and individuals is | |
7360 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
7361 | ||
7362 | In any event, we also recommend that you send bug reports for _GDBN__ to one | |
7363 | of these addresses: | |
7364 | ||
7365 | @example | |
7366 | bug-gdb@@prep.ai.mit.edu | |
7367 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
7368 | @end example | |
7369 | ||
7370 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
7371 | @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to | |
7372 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
7373 | ||
3d3ab540 RP |
7374 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
7375 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
7376 | the same messages. Often people think of posting bug reports to the | |
7377 | newsgroup instead of mailing them. This appears to work, but it has one | |
7378 | problem which can be crucial: a newsgroup posting often lacks a mail | |
7379 | path back to the sender. Thus, if we need to ask for more information, | |
7380 | we may be unable to reach you. For this reason, it is better to send | |
7381 | bug reports to the mailing list. | |
70b88761 RP |
7382 | |
7383 | As a last resort, send bug reports on paper to: | |
7384 | ||
7385 | @example | |
7386 | GNU Debugger Bugs | |
3d3ab540 | 7387 | Free Software Foundation |
70b88761 RP |
7388 | 545 Tech Square |
7389 | Cambridge, MA 02139 | |
7390 | @end example | |
7391 | ||
7392 | The fundamental principle of reporting bugs usefully is this: | |
7393 | @strong{report all the facts}. If you are not sure whether to state a | |
7394 | fact or leave it out, state it! | |
7395 | ||
7396 | Often people omit facts because they think they know what causes the | |
29a2b744 | 7397 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 7398 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 7399 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
7400 | stray memory reference which happens to fetch from the location where that |
7401 | name is stored in memory; perhaps, if the name were different, the contents | |
7402 | of that location would fool the debugger into doing the right thing despite | |
7403 | the bug. Play it safe and give a specific, complete example. That is the | |
7404 | easiest thing for you to do, and the most helpful. | |
7405 | ||
7406 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 7407 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
7408 | the bug is already known. Therefore, always write your bug reports on |
7409 | the assumption that the bug has not been reported previously. | |
7410 | ||
7411 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
7412 | bell?'' Those bug reports are useless, and we urge everyone to | |
7413 | @emph{refuse to respond to them} except to chide the sender to report | |
7414 | bugs properly. | |
7415 | ||
7416 | To enable us to fix the bug, you should include all these things: | |
7417 | ||
7418 | @itemize @bullet | |
7419 | @item | |
7420 | The version of _GDBN__. _GDBN__ announces it if you start with no | |
7421 | arguments; you can also print it at any time using @code{show version}. | |
7422 | ||
1041a570 | 7423 | Without this, we will not know whether there is any point in looking for |
70b88761 RP |
7424 | the bug in the current version of _GDBN__. |
7425 | ||
7426 | @item | |
ddf21240 JG |
7427 | The type of machine you are using, and the operating system name and |
7428 | version number. | |
70b88761 RP |
7429 | |
7430 | @item | |
7431 | What compiler (and its version) was used to compile _GDBN__---e.g. | |
c7cb8acb | 7432 | ``_GCC__-2.0''. |
70b88761 | 7433 | |
ddf21240 JG |
7434 | @item |
7435 | What compiler (and its version) was used to compile the program you | |
c7cb8acb | 7436 | are debugging---e.g. ``_GCC__-2.0''. |
ddf21240 | 7437 | |
70b88761 RP |
7438 | @item |
7439 | The command arguments you gave the compiler to compile your example and | |
7440 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 7441 | you will not omit something important, list them all. A copy of the |
ddf21240 | 7442 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
7443 | |
7444 | If we were to try to guess the arguments, we would probably guess wrong | |
7445 | and then we might not encounter the bug. | |
7446 | ||
7447 | @item | |
ddf21240 JG |
7448 | A complete input script, and all necessary source files, that will |
7449 | reproduce the bug. | |
70b88761 RP |
7450 | |
7451 | @item | |
7452 | A description of what behavior you observe that you believe is | |
7453 | incorrect. For example, ``It gets a fatal signal.'' | |
7454 | ||
7455 | Of course, if the bug is that _GDBN__ gets a fatal signal, then we will | |
7456 | certainly notice it. But if the bug is incorrect output, we might not | |
7457 | notice unless it is glaringly wrong. We are human, after all. You | |
7458 | might as well not give us a chance to make a mistake. | |
7459 | ||
7460 | Even if the problem you experience is a fatal signal, you should still | |
7461 | say so explicitly. Suppose something strange is going on, such as, | |
7462 | your copy of _GDBN__ is out of synch, or you have encountered a | |
7463 | bug in the C library on your system. (This has happened!) Your copy | |
7464 | might crash and ours would not. If you told us to expect a crash, | |
7465 | then when ours fails to crash, we would know that the bug was not | |
7466 | happening for us. If you had not told us to expect a crash, then we | |
7467 | would not be able to draw any conclusion from our observations. | |
7468 | ||
7469 | @item | |
7470 | If you wish to suggest changes to the _GDBN__ source, send us context | |
7471 | diffs. If you even discuss something in the _GDBN__ source, refer to | |
7472 | it by context, not by line number. | |
7473 | ||
1041a570 | 7474 | The line numbers in our development sources will not match those in your |
70b88761 | 7475 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
7476 | @end itemize |
7477 | ||
7478 | Here are some things that are not necessary: | |
7479 | ||
7480 | @itemize @bullet | |
7481 | @item | |
7482 | A description of the envelope of the bug. | |
7483 | ||
7484 | Often people who encounter a bug spend a lot of time investigating | |
7485 | which changes to the input file will make the bug go away and which | |
7486 | changes will not affect it. | |
7487 | ||
7488 | This is often time consuming and not very useful, because the way we | |
7489 | will find the bug is by running a single example under the debugger | |
7490 | with breakpoints, not by pure deduction from a series of examples. | |
7491 | We recommend that you save your time for something else. | |
7492 | ||
7493 | Of course, if you can find a simpler example to report @emph{instead} | |
7494 | of the original one, that is a convenience for us. Errors in the | |
7495 | output will be easier to spot, running under the debugger will take | |
e251e767 | 7496 | less time, etc. |
70b88761 | 7497 | |
29a2b744 | 7498 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
7499 | report the bug anyway and send us the entire test case you used. |
7500 | ||
7501 | @item | |
7502 | A patch for the bug. | |
7503 | ||
29a2b744 | 7504 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
7505 | the necessary information, such as the test case, on the assumption that |
7506 | a patch is all we need. We might see problems with your patch and decide | |
7507 | to fix the problem another way, or we might not understand it at all. | |
7508 | ||
7509 | Sometimes with a program as complicated as _GDBN__ it is very hard to | |
7510 | construct an example that will make the program follow a certain path | |
1041a570 RP |
7511 | through the code. If you do not send us the example, we will not be able |
7512 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 7513 | |
29a2b744 | 7514 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 7515 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
7516 | help us to understand. |
7517 | ||
7518 | @item | |
7519 | A guess about what the bug is or what it depends on. | |
7520 | ||
29a2b744 | 7521 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
7522 | things without first using the debugger to find the facts. |
7523 | @end itemize | |
7524 | ||
1041a570 RP |
7525 | @c Note: no need to update nodes for rdl-apps.texi since it appears |
7526 | @c *only* in the TeX version of the manual. | |
7527 | @c Note: eventually, make a cross reference to the readline Info nodes. | |
70b88761 | 7528 | @iftex |
cacf5942 RP |
7529 | @c appendices describing GNU readline. Distributed with readline code. |
7530 | @include rluser.texinfo | |
7531 | @include inc-hist.texi | |
70b88761 RP |
7532 | @end iftex |
7533 | ||
4eb4cf57 RP |
7534 | _if__(_GENERIC__||!_H8__) |
7535 | @node Renamed Commands | |
70b88761 RP |
7536 | @appendix Renamed Commands |
7537 | ||
c7cb8acb | 7538 | The following commands were renamed in GDB 4, in order to make the |
70b88761 RP |
7539 | command set as a whole more consistent and easier to use and remember: |
7540 | ||
e251e767 RP |
7541 | @kindex add-syms |
7542 | @kindex delete environment | |
7543 | @kindex info copying | |
7544 | @kindex info convenience | |
7545 | @kindex info directories | |
7546 | @kindex info editing | |
7547 | @kindex info history | |
7548 | @kindex info targets | |
7549 | @kindex info values | |
7550 | @kindex info version | |
7551 | @kindex info warranty | |
7552 | @kindex set addressprint | |
7553 | @kindex set arrayprint | |
7554 | @kindex set prettyprint | |
7555 | @kindex set screen-height | |
7556 | @kindex set screen-width | |
7557 | @kindex set unionprint | |
7558 | @kindex set vtblprint | |
7559 | @kindex set demangle | |
7560 | @kindex set asm-demangle | |
7561 | @kindex set sevenbit-strings | |
7562 | @kindex set array-max | |
7563 | @kindex set caution | |
7564 | @kindex set history write | |
7565 | @kindex show addressprint | |
7566 | @kindex show arrayprint | |
7567 | @kindex show prettyprint | |
7568 | @kindex show screen-height | |
7569 | @kindex show screen-width | |
7570 | @kindex show unionprint | |
7571 | @kindex show vtblprint | |
7572 | @kindex show demangle | |
7573 | @kindex show asm-demangle | |
7574 | @kindex show sevenbit-strings | |
7575 | @kindex show array-max | |
7576 | @kindex show caution | |
7577 | @kindex show history write | |
7578 | @kindex unset | |
70b88761 | 7579 | |
92b73793 | 7580 | @c TEXI2ROFF-KILL |
70b88761 | 7581 | @ifinfo |
92b73793 | 7582 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7583 | @example |
7584 | OLD COMMAND NEW COMMAND | |
92b73793 | 7585 | @c TEXI2ROFF-KILL |
cf496415 | 7586 | --------------- ------------------------------- |
92b73793 | 7587 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7588 | add-syms add-symbol-file |
7589 | delete environment unset environment | |
7590 | info convenience show convenience | |
7591 | info copying show copying | |
e251e767 | 7592 | info directories show directories |
cf496415 RP |
7593 | info editing show commands |
7594 | info history show values | |
7595 | info targets help target | |
7596 | info values show values | |
7597 | info version show version | |
7598 | info warranty show warranty | |
7599 | set/show addressprint set/show print address | |
7600 | set/show array-max set/show print elements | |
7601 | set/show arrayprint set/show print array | |
7602 | set/show asm-demangle set/show print asm-demangle | |
7603 | set/show caution set/show confirm | |
7604 | set/show demangle set/show print demangle | |
7605 | set/show history write set/show history save | |
7606 | set/show prettyprint set/show print pretty | |
7607 | set/show screen-height set/show height | |
7608 | set/show screen-width set/show width | |
7609 | set/show sevenbit-strings set/show print sevenbit-strings | |
7610 | set/show unionprint set/show print union | |
7611 | set/show vtblprint set/show print vtbl | |
7612 | ||
7613 | unset [No longer an alias for delete] | |
7614 | @end example | |
92b73793 | 7615 | @c TEXI2ROFF-KILL |
70b88761 RP |
7616 | @end ifinfo |
7617 | ||
7618 | @tex | |
7619 | \vskip \parskip\vskip \baselineskip | |
7620 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
7621 | {\bf Old Command} &&{\bf New Command}\cr | |
7622 | add-syms &&add-symbol-file\cr | |
7623 | delete environment &&unset environment\cr | |
7624 | info convenience &&show convenience\cr | |
7625 | info copying &&show copying\cr | |
7626 | info directories &&show directories \cr | |
7627 | info editing &&show commands\cr | |
7628 | info history &&show values\cr | |
7629 | info targets &&help target\cr | |
7630 | info values &&show values\cr | |
7631 | info version &&show version\cr | |
7632 | info warranty &&show warranty\cr | |
7633 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
7634 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
7635 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
7636 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
7637 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
7638 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
7639 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
7640 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
7641 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
7642 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
7643 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
7644 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
7645 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
7646 | \cr | |
7647 | unset &&\rm(No longer an alias for delete)\cr | |
7648 | } | |
7649 | @end tex | |
92b73793 | 7650 | @c END TEXI2ROFF-KILL |
4eb4cf57 | 7651 | _fi__(_GENERIC__||!_H8__) |
70b88761 | 7652 | |
4eb4cf57 | 7653 | @node Formatting Documentation |
77b46d13 JG |
7654 | @appendix Formatting the Documentation |
7655 | ||
7656 | @cindex GDB reference card | |
7657 | @cindex reference card | |
7658 | The GDB 4 release includes an already-formatted reference card, ready | |
b1385986 | 7659 | for printing with PostScript or GhostScript, in the @file{gdb} |
77b46d13 | 7660 | subdirectory of the main source directory---in |
b1385986 RP |
7661 | @file{gdb-_GDB_VN__/gdb/refcard.ps} of the version _GDB_VN__ release. |
7662 | If you can use PostScript or GhostScript with your printer, you can | |
7663 | print the reference card immediately with @file{refcard.ps}. | |
77b46d13 JG |
7664 | |
7665 | The release also includes the source for the reference card. You | |
7666 | can format it, using @TeX{}, by typing: | |
7667 | ||
7668 | @example | |
7669 | make refcard.dvi | |
7670 | @end example | |
7671 | ||
7672 | The GDB reference card is designed to print in landscape mode on US | |
7673 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
7674 | high. You will need to specify this form of printing as an option to | |
7675 | your @sc{dvi} output program. | |
7676 | ||
7677 | @cindex documentation | |
7678 | ||
7679 | All the documentation for GDB comes as part of the machine-readable | |
7680 | distribution. The documentation is written in Texinfo format, which is | |
7681 | a documentation system that uses a single source file to produce both | |
7682 | on-line information and a printed manual. You can use one of the Info | |
7683 | formatting commands to create the on-line version of the documentation | |
7684 | and @TeX{} (or @code{texi2roff}) to typeset the printed version. | |
7685 | ||
7686 | GDB includes an already formatted copy of the on-line Info version of | |
7687 | this manual in the @file{gdb} subdirectory. The main Info file is | |
7688 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
a89f94c2 RP |
7689 | subordinate files matching @samp{gdb.info*} in the same directory. If |
7690 | necessary, you can print out these files, or read them with any editor; | |
7691 | but they are easier to read using the @code{info} subsystem in GNU Emacs | |
7692 | or the standalone @code{info} program, available as part of the GNU | |
7693 | Texinfo distribution. | |
77b46d13 JG |
7694 | |
7695 | If you want to format these Info files yourself, you need one of the | |
7696 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
7697 | @code{makeinfo}. | |
7698 | ||
7699 | If you have @code{makeinfo} installed, and are in the top level GDB | |
7700 | source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can | |
7701 | make the Info file by typing: | |
7702 | ||
7703 | @example | |
7704 | cd gdb | |
7705 | make gdb.info | |
7706 | @end example | |
7707 | ||
7708 | If you want to typeset and print copies of this manual, you need | |
7709 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
7710 | the Texinfo definitions file. | |
7711 | ||
7712 | @TeX{} is typesetting program; it does not print files directly, but | |
7713 | produces output files called @sc{dvi} files. To print a typeset | |
7714 | document, you need a program to print @sc{dvi} files. If your system | |
7715 | has @TeX{} installed, chances are it has such a program. The precise | |
7716 | command to use depends on your system; @kbd{lpr -d} is common; another | |
7717 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
7718 | without any extension or a @samp{.dvi} extension. | |
7719 | ||
7720 | @TeX{} also requires a macro definitions file called | |
7721 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
7722 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
7723 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
7724 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
7725 | directory. | |
7726 | ||
7727 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
7728 | typeset and print this manual. First switch to the the @file{gdb} | |
7729 | subdirectory of the main source directory (for example, to | |
7730 | @file{gdb-_GDB_VN__/gdb}) and then type: | |
7731 | ||
7732 | @example | |
7733 | make gdb.dvi | |
7734 | @end example | |
7735 | ||
4eb4cf57 | 7736 | @node Installing GDB |
c7cb8acb RP |
7737 | @appendix Installing GDB |
7738 | @cindex configuring GDB | |
70b88761 RP |
7739 | @cindex installation |
7740 | ||
f672bb7f RP |
7741 | @iftex |
7742 | @c irrelevant in info file; it's as current as the code it lives with. | |
7743 | @quotation | |
7744 | @emph{Warning:} These installation instructions are current as of | |
c7cb8acb RP |
7745 | GDB version _GDB_VN__. If you're installing a more recent release |
7746 | of GDB, we may have improved the installation procedures since | |
f672bb7f RP |
7747 | printing this manual; see the @file{README} file included in your |
7748 | release for the most recent instructions. | |
7749 | @end quotation | |
7750 | @end iftex | |
7751 | ||
c7cb8acb RP |
7752 | GDB comes with a @code{configure} script that automates the process |
7753 | of preparing GDB for installation; you can then use @code{make} to | |
7754 | build the program. | |
b80282d5 | 7755 | |
c7cb8acb | 7756 | The GDB distribution includes all the source code you need for GDB in |
1041a570 RP |
7757 | a single directory, whose name is usually composed by appending the |
7758 | version number to @samp{gdb}. | |
7759 | ||
c7cb8acb | 7760 | For example, the GDB version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__} |
1041a570 | 7761 | directory. That directory contains: |
b80282d5 | 7762 | |
3d3ab540 | 7763 | @table @code |
c7637ea6 | 7764 | @item gdb-_GDB_VN__/configure @r{(and supporting files)} |
c7cb8acb | 7765 | script for configuring GDB and all its supporting libraries. |
b80282d5 | 7766 | |
3e0d0a27 | 7767 | @item gdb-_GDB_VN__/gdb |
c7cb8acb | 7768 | the source specific to GDB itself |
3d3ab540 | 7769 | |
3e0d0a27 | 7770 | @item gdb-_GDB_VN__/bfd |
77b46d13 | 7771 | source for the Binary File Descriptor library |
3d3ab540 | 7772 | |
3e0d0a27 | 7773 | @item gdb-_GDB_VN__/include |
b80282d5 | 7774 | GNU include files |
3d3ab540 | 7775 | |
3e0d0a27 | 7776 | @item gdb-_GDB_VN__/libiberty |
3d3ab540 RP |
7777 | source for the @samp{-liberty} free software library |
7778 | ||
3e0d0a27 | 7779 | @item gdb-_GDB_VN__/readline |
b80282d5 | 7780 | source for the GNU command-line interface |
77b46d13 JG |
7781 | |
7782 | @item gdb-_GDB_VN__/glob | |
7783 | source for the GNU filename pattern-matching subroutine | |
7784 | ||
7785 | @item gdb-_GDB_VN__/mmalloc | |
7786 | source for the GNU memory-mapped malloc package | |
3d3ab540 | 7787 | @end table |
1041a570 | 7788 | |
c7cb8acb | 7789 | The simplest way to configure and build GDB is to run @code{configure} |
1041a570 RP |
7790 | from the @file{gdb-@var{version-number}} source directory, which in |
7791 | this example is the @file{gdb-_GDB_VN__} directory. | |
7792 | ||
7793 | First switch to the @file{gdb-@var{version-number}} source directory | |
7794 | if you are not already in it; then run @code{configure}. Pass the | |
c7cb8acb | 7795 | identifier for the platform on which GDB will run as an |
1041a570 RP |
7796 | argument. |
7797 | ||
7798 | For example: | |
7799 | ||
7463aadd | 7800 | @example |
3e0d0a27 | 7801 | cd gdb-_GDB_VN__ |
3d3ab540 | 7802 | ./configure @var{host} |
7463aadd RP |
7803 | make |
7804 | @end example | |
1041a570 | 7805 | |
7463aadd | 7806 | @noindent |
1041a570 | 7807 | where @var{host} is an identifier such as @samp{sun4} or |
c7cb8acb | 7808 | @samp{decstation}, that identifies the platform where GDB will run. |
1041a570 | 7809 | |
38962738 RP |
7810 | Running @samp{configure @var{host}} followed by @code{make} builds the |
7811 | @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty} | |
7812 | libraries, then @code{gdb} itself. The configured source files, and the | |
7813 | binaries, are left in the corresponding source directories. | |
3d3ab540 | 7814 | |
e251e767 | 7815 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 7816 | system does not recognize this automatically when you run a different |
1041a570 RP |
7817 | shell, you may need to run @code{sh} on it explicitly: |
7818 | ||
7819 | @example | |
7820 | sh configure @var{host} | |
7821 | @end example | |
e251e767 | 7822 | |
f672bb7f RP |
7823 | If you run @code{configure} from a directory that contains source |
7824 | directories for multiple libraries or programs, such as the | |
7825 | @file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure} | |
7826 | creates configuration files for every directory level underneath (unless | |
98349959 | 7827 | you tell it not to, with the @samp{--norecursion} option). |
f672bb7f RP |
7828 | |
7829 | You can run the @code{configure} script from any of the | |
c7cb8acb | 7830 | subordinate directories in the GDB distribution, if you only want to |
1041a570 RP |
7831 | configure that subdirectory; but be sure to specify a path to it. |
7832 | ||
7833 | For example, with version _GDB_VN__, type the following to configure only | |
7834 | the @code{bfd} subdirectory: | |
7835 | ||
e251e767 | 7836 | @example |
203eea5d | 7837 | @group |
e251e767 RP |
7838 | cd gdb-_GDB_VN__/bfd |
7839 | ../configure @var{host} | |
203eea5d | 7840 | @end group |
e251e767 RP |
7841 | @end example |
7842 | ||
1041a570 RP |
7843 | You can install @code{_GDBP__} anywhere; it has no hardwired paths. |
7844 | However, you should make sure that the shell on your path (named by | |
7845 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
c7cb8acb RP |
7846 | that GDB uses the shell to start your program---some systems refuse to |
7847 | let GDB debug child processes whose programs are not readable. | |
3d3ab540 RP |
7848 | |
7849 | @menu | |
c7cb8acb | 7850 | * Separate Objdir:: Compiling GDB in another directory |
b80282d5 RP |
7851 | * Config Names:: Specifying names for hosts and targets |
7852 | * configure Options:: Summary of options for configure | |
3d3ab540 RP |
7853 | @end menu |
7854 | ||
4eb4cf57 | 7855 | @node Separate Objdir |
c7cb8acb | 7856 | @section Compiling GDB in Another Directory |
1041a570 | 7857 | |
c7cb8acb RP |
7858 | If you want to run GDB versions for several host or target machines, |
7859 | you'll need a different @code{gdb} compiled for each combination of | |
1041a570 | 7860 | host and target. @code{configure} is designed to make this easy by |
f672bb7f RP |
7861 | allowing you to generate each configuration in a separate subdirectory, |
7862 | rather than in the source directory. If your @code{make} program | |
7863 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
c7cb8acb | 7864 | @code{make} in each of these directories then builds the @code{gdb} |
f672bb7f | 7865 | program specified there. |
b80282d5 | 7866 | |
c7cb8acb | 7867 | To build @code{gdb} in a separate directory, run @code{configure} |
f672bb7f | 7868 | with the @samp{--srcdir} option to specify where to find the source. |
77b46d13 JG |
7869 | (You'll also need to specify a path to find @code{configure} |
7870 | itself from your working directory. If the path to @code{configure} | |
7871 | would be the same as the argument to @samp{--srcdir}, you can leave out | |
7872 | the @samp{--srcdir} option; it will be assumed.) | |
1041a570 | 7873 | |
c7cb8acb | 7874 | For example, with version _GDB_VN__, you can build GDB in a separate |
f672bb7f | 7875 | directory for a Sun 4 like this: |
70b88761 RP |
7876 | |
7877 | @example | |
3d3ab540 | 7878 | @group |
3e0d0a27 | 7879 | cd gdb-_GDB_VN__ |
f672bb7f RP |
7880 | mkdir ../gdb-sun4 |
7881 | cd ../gdb-sun4 | |
77b46d13 | 7882 | ../gdb-_GDB_VN__/configure sun4 |
70b88761 | 7883 | make |
3d3ab540 | 7884 | @end group |
70b88761 RP |
7885 | @end example |
7886 | ||
f672bb7f RP |
7887 | When @code{configure} builds a configuration using a remote source |
7888 | directory, it creates a tree for the binaries with the same structure | |
7889 | (and using the same names) as the tree under the source directory. In | |
7890 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
c7cb8acb | 7891 | directory @file{gdb-sun4/libiberty}, and GDB itself in |
f672bb7f | 7892 | @file{gdb-sun4/gdb}. |
1041a570 | 7893 | |
38962738 | 7894 | One popular reason to build several GDB configurations in separate |
c7cb8acb | 7895 | directories is to configure GDB for cross-compiling (where GDB |
f672bb7f RP |
7896 | runs on one machine---the host---while debugging programs that run on |
7897 | another machine---the target). You specify a cross-debugging target by | |
7898 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
c7637ea6 | 7899 | |
1041a570 | 7900 | When you run @code{make} to build a program or library, you must run |
f672bb7f RP |
7901 | it in a configured directory---whatever directory you were in when you |
7902 | called @code{configure} (or one of its subdirectories). | |
c7637ea6 RP |
7903 | |
7904 | The @code{Makefile} generated by @code{configure} for each source | |
f672bb7f RP |
7905 | directory also runs recursively. If you type @code{make} in a source |
7906 | directory such as @file{gdb-_GDB_VN__} (or in a separate configured | |
7907 | directory configured with @samp{--srcdir=@var{path}/gdb-_GDB_VN__}), you | |
c7cb8acb | 7908 | will build all the required libraries, then build GDB. |
3d3ab540 | 7909 | |
f672bb7f RP |
7910 | When you have multiple hosts or targets configured in separate |
7911 | directories, you can run @code{make} on them in parallel (for example, | |
7912 | if they are NFS-mounted on each of the hosts); they will not interfere | |
7913 | with each other. | |
3d3ab540 | 7914 | |
4eb4cf57 | 7915 | @node Config Names |
b80282d5 RP |
7916 | @section Specifying Names for Hosts and Targets |
7917 | ||
7918 | The specifications used for hosts and targets in the @code{configure} | |
7919 | script are based on a three-part naming scheme, but some short predefined | |
7920 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 7921 | of information in the following pattern: |
1041a570 | 7922 | |
b80282d5 RP |
7923 | @example |
7924 | @var{architecture}-@var{vendor}-@var{os} | |
7925 | @end example | |
7926 | ||
7927 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
5e3186ab | 7928 | or in a @code{--target=@var{target}} option, but the equivalent full name |
e251e767 | 7929 | is @samp{sparc-sun-sunos4}. |
b80282d5 | 7930 | |
c7cb8acb | 7931 | The @code{configure} script accompanying GDB does not provide |
b80282d5 RP |
7932 | any query facility to list all supported host and target names or |
7933 | aliases. @code{configure} calls the Bourne shell script | |
7934 | @code{config.sub} to map abbreviations to full names; you can read the | |
7935 | script, if you wish, or you can use it to test your guesses on | |
7936 | abbreviations---for example: | |
1041a570 | 7937 | |
b1385986 | 7938 | @smallexample |
b80282d5 | 7939 | % sh config.sub sun4 |
6a8cb0e7 | 7940 | sparc-sun-sunos411 |
b80282d5 | 7941 | % sh config.sub sun3 |
6a8cb0e7 | 7942 | m68k-sun-sunos411 |
b80282d5 | 7943 | % sh config.sub decstation |
6a8cb0e7 | 7944 | mips-dec-ultrix42 |
b80282d5 RP |
7945 | % sh config.sub hp300bsd |
7946 | m68k-hp-bsd | |
7947 | % sh config.sub i386v | |
6a8cb0e7 | 7948 | i386-unknown-sysv |
e94b4a2b | 7949 | % sh config.sub i786v |
6a8cb0e7 | 7950 | Invalid configuration `i786v': machine `i786v' not recognized |
b1385986 | 7951 | @end smallexample |
1041a570 | 7952 | |
c7637ea6 | 7953 | @noindent |
1041a570 RP |
7954 | @code{config.sub} is also distributed in the GDB source |
7955 | directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__). | |
b80282d5 | 7956 | |
4eb4cf57 | 7957 | @node configure Options |
3d3ab540 | 7958 | @section @code{configure} Options |
7463aadd | 7959 | |
d48da190 RP |
7960 | Here is a summary of the @code{configure} options and arguments that |
7961 | are most often useful for building _GDBN__. @code{configure} also has | |
7962 | several other options not listed here. @inforef{What Configure | |
7963 | Does,,configure.info}, for a full explanation of @code{configure}. | |
7964 | @c FIXME: Would this be more, or less, useful as an xref (ref to printed | |
7965 | @c manual in the printed manual, ref to info file only from the info file)? | |
7463aadd RP |
7966 | |
7967 | @example | |
d48da190 RP |
7968 | configure @r{[}--help@r{]} |
7969 | @r{[}--prefix=@var{dir}@r{]} | |
7970 | @r{[}--srcdir=@var{path}@r{]} | |
f672bb7f RP |
7971 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} |
7972 | @r{[}--target=@var{target}@r{]} @var{host} | |
7463aadd | 7973 | @end example |
1041a570 | 7974 | |
3d3ab540 | 7975 | @noindent |
f672bb7f RP |
7976 | You may introduce options with a single @samp{-} rather than |
7977 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
7978 | @samp{--}. | |
70b88761 RP |
7979 | |
7980 | @table @code | |
d48da190 RP |
7981 | @item --help |
7982 | Display a quick summary of how to invoke @code{configure}. | |
7983 | ||
7984 | @item -prefix=@var{dir} | |
7985 | Configure the source to install programs and files under directory | |
7986 | @file{@var{dir}}. | |
7987 | ||
f672bb7f | 7988 | @item --srcdir=@var{path} |
6ca72cc6 RP |
7989 | @strong{Warning: using this option requires GNU @code{make}, or another |
7990 | @code{make} that implements the @code{VPATH} feature.}@* | |
f672bb7f | 7991 | Use this option to make configurations in directories separate from the |
c7cb8acb | 7992 | GDB source directories. Among other things, you can use this to |
f672bb7f RP |
7993 | build (or maintain) several configurations simultaneously, in separate |
7994 | directories. @code{configure} writes configuration specific files in | |
7995 | the current directory, but arranges for them to use the source in the | |
7996 | directory @var{path}. @code{configure} will create directories under | |
7997 | the working directory in parallel to the source directories below | |
7998 | @var{path}. | |
7999 | ||
8000 | @item --norecursion | |
8001 | Configure only the directory level where @code{configure} is executed; do not | |
7463aadd RP |
8002 | propagate configuration to subdirectories. |
8003 | ||
f672bb7f | 8004 | @item --rm |
b80282d5 | 8005 | Remove the configuration that the other arguments specify. |
7463aadd | 8006 | |
29a2b744 | 8007 | @c This does not work (yet if ever). FIXME. |
f672bb7f | 8008 | @c @item --parse=@var{lang} @dots{} |
c7cb8acb RP |
8009 | @c Configure the GDB expression parser to parse the listed languages. |
8010 | @c @samp{all} configures GDB for all supported languages. To get a | |
d7b569d5 | 8011 | @c list of all supported languages, omit the argument. Without this |
c7cb8acb | 8012 | @c option, GDB is configured to parse all supported languages. |
c2bbbb22 | 8013 | |
f672bb7f | 8014 | @item --target=@var{target} |
c7cb8acb RP |
8015 | Configure GDB for cross-debugging programs running on the specified |
8016 | @var{target}. Without this option, GDB is configured to debug | |
8017 | programs that run on the same machine (@var{host}) as GDB itself. | |
b80282d5 RP |
8018 | |
8019 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
8020 | |
8021 | @item @var{host} @dots{} | |
c7cb8acb | 8022 | Configure GDB to run on the specified @var{host}. |
b80282d5 RP |
8023 | |
8024 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
8025 | @end table |
8026 | ||
3d3ab540 RP |
8027 | @noindent |
8028 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 8029 | configuring other GNU tools recursively; but these are the only |
c7cb8acb | 8030 | options that affect GDB or its supporting libraries. |
3d3ab540 | 8031 | |
4eb4cf57 | 8032 | @node Copying |
70b88761 | 8033 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 8034 | @center Version 2, June 1991 |
70b88761 RP |
8035 | |
8036 | @display | |
7463aadd | 8037 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
8038 | 675 Mass Ave, Cambridge, MA 02139, USA |
8039 | ||
8040 | Everyone is permitted to copy and distribute verbatim copies | |
8041 | of this license document, but changing it is not allowed. | |
8042 | @end display | |
8043 | ||
8044 | @unnumberedsec Preamble | |
8045 | ||
7463aadd RP |
8046 | The licenses for most software are designed to take away your |
8047 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 8048 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
8049 | software---to make sure the software is free for all its users. This |
8050 | General Public License applies to most of the Free Software | |
8051 | Foundation's software and to any other program whose authors commit to | |
8052 | using it. (Some other Free Software Foundation software is covered by | |
8053 | the GNU Library General Public License instead.) You can apply it to | |
8054 | your programs, too. | |
70b88761 RP |
8055 | |
8056 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
8057 | price. Our General Public Licenses are designed to make sure that you |
8058 | have the freedom to distribute copies of free software (and charge for | |
8059 | this service if you wish), that you receive source code or can get it | |
8060 | if you want it, that you can change the software or use pieces of it | |
8061 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
8062 | |
8063 | To protect your rights, we need to make restrictions that forbid | |
8064 | anyone to deny you these rights or to ask you to surrender the rights. | |
8065 | These restrictions translate to certain responsibilities for you if you | |
8066 | distribute copies of the software, or if you modify it. | |
8067 | ||
7463aadd | 8068 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
8069 | gratis or for a fee, you must give the recipients all the rights that |
8070 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
8071 | source code. And you must show them these terms so they know their |
8072 | rights. | |
70b88761 RP |
8073 | |
8074 | We protect your rights with two steps: (1) copyright the software, and | |
8075 | (2) offer you this license which gives you legal permission to copy, | |
8076 | distribute and/or modify the software. | |
8077 | ||
8078 | Also, for each author's protection and ours, we want to make certain | |
8079 | that everyone understands that there is no warranty for this free | |
8080 | software. If the software is modified by someone else and passed on, we | |
8081 | want its recipients to know that what they have is not the original, so | |
8082 | that any problems introduced by others will not reflect on the original | |
8083 | authors' reputations. | |
8084 | ||
7463aadd RP |
8085 | Finally, any free program is threatened constantly by software |
8086 | patents. We wish to avoid the danger that redistributors of a free | |
8087 | program will individually obtain patent licenses, in effect making the | |
8088 | program proprietary. To prevent this, we have made it clear that any | |
8089 | patent must be licensed for everyone's free use or not licensed at all. | |
8090 | ||
70b88761 RP |
8091 | The precise terms and conditions for copying, distribution and |
8092 | modification follow. | |
8093 | ||
8094 | @iftex | |
7463aadd | 8095 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8096 | @end iftex |
8097 | @ifinfo | |
7463aadd | 8098 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8099 | @end ifinfo |
8100 | ||
8101 | @enumerate | |
8102 | @item | |
7463aadd RP |
8103 | This License applies to any program or other work which contains |
8104 | a notice placed by the copyright holder saying it may be distributed | |
8105 | under the terms of this General Public License. The ``Program'', below, | |
8106 | refers to any such program or work, and a ``work based on the Program'' | |
8107 | means either the Program or any derivative work under copyright law: | |
8108 | that is to say, a work containing the Program or a portion of it, | |
8109 | either verbatim or with modifications and/or translated into another | |
8110 | language. (Hereinafter, translation is included without limitation in | |
8111 | the term ``modification''.) Each licensee is addressed as ``you''. | |
8112 | ||
8113 | Activities other than copying, distribution and modification are not | |
8114 | covered by this License; they are outside its scope. The act of | |
8115 | running the Program is not restricted, and the output from the Program | |
8116 | is covered only if its contents constitute a work based on the | |
8117 | Program (independent of having been made by running the Program). | |
8118 | Whether that is true depends on what the Program does. | |
70b88761 RP |
8119 | |
8120 | @item | |
7463aadd RP |
8121 | You may copy and distribute verbatim copies of the Program's |
8122 | source code as you receive it, in any medium, provided that you | |
8123 | conspicuously and appropriately publish on each copy an appropriate | |
8124 | copyright notice and disclaimer of warranty; keep intact all the | |
8125 | notices that refer to this License and to the absence of any warranty; | |
8126 | and give any other recipients of the Program a copy of this License | |
8127 | along with the Program. | |
70b88761 | 8128 | |
7463aadd RP |
8129 | You may charge a fee for the physical act of transferring a copy, and |
8130 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 8131 | |
70b88761 | 8132 | @item |
7463aadd RP |
8133 | You may modify your copy or copies of the Program or any portion |
8134 | of it, thus forming a work based on the Program, and copy and | |
8135 | distribute such modifications or work under the terms of Section 1 | |
8136 | above, provided that you also meet all of these conditions: | |
70b88761 | 8137 | |
1041a570 | 8138 | @enumerate a |
70b88761 | 8139 | @item |
7463aadd RP |
8140 | You must cause the modified files to carry prominent notices |
8141 | stating that you changed the files and the date of any change. | |
70b88761 RP |
8142 | |
8143 | @item | |
7463aadd RP |
8144 | You must cause any work that you distribute or publish, that in |
8145 | whole or in part contains or is derived from the Program or any | |
8146 | part thereof, to be licensed as a whole at no charge to all third | |
8147 | parties under the terms of this License. | |
70b88761 RP |
8148 | |
8149 | @item | |
7463aadd RP |
8150 | If the modified program normally reads commands interactively |
8151 | when run, you must cause it, when started running for such | |
8152 | interactive use in the most ordinary way, to print or display an | |
8153 | announcement including an appropriate copyright notice and a | |
8154 | notice that there is no warranty (or else, saying that you provide | |
8155 | a warranty) and that users may redistribute the program under | |
8156 | these conditions, and telling the user how to view a copy of this | |
8157 | License. (Exception: if the Program itself is interactive but | |
8158 | does not normally print such an announcement, your work based on | |
8159 | the Program is not required to print an announcement.) | |
1041a570 | 8160 | @end enumerate |
7463aadd RP |
8161 | |
8162 | These requirements apply to the modified work as a whole. If | |
8163 | identifiable sections of that work are not derived from the Program, | |
8164 | and can be reasonably considered independent and separate works in | |
8165 | themselves, then this License, and its terms, do not apply to those | |
8166 | sections when you distribute them as separate works. But when you | |
8167 | distribute the same sections as part of a whole which is a work based | |
8168 | on the Program, the distribution of the whole must be on the terms of | |
8169 | this License, whose permissions for other licensees extend to the | |
8170 | entire whole, and thus to each and every part regardless of who wrote it. | |
8171 | ||
8172 | Thus, it is not the intent of this section to claim rights or contest | |
8173 | your rights to work written entirely by you; rather, the intent is to | |
8174 | exercise the right to control the distribution of derivative or | |
8175 | collective works based on the Program. | |
8176 | ||
8177 | In addition, mere aggregation of another work not based on the Program | |
8178 | with the Program (or with a work based on the Program) on a volume of | |
8179 | a storage or distribution medium does not bring the other work under | |
8180 | the scope of this License. | |
70b88761 RP |
8181 | |
8182 | @item | |
7463aadd RP |
8183 | You may copy and distribute the Program (or a work based on it, |
8184 | under Section 2) in object code or executable form under the terms of | |
8185 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 8186 | |
1041a570 | 8187 | @enumerate a |
70b88761 | 8188 | @item |
7463aadd RP |
8189 | Accompany it with the complete corresponding machine-readable |
8190 | source code, which must be distributed under the terms of Sections | |
8191 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
8192 | |
8193 | @item | |
7463aadd RP |
8194 | Accompany it with a written offer, valid for at least three |
8195 | years, to give any third party, for a charge no more than your | |
8196 | cost of physically performing source distribution, a complete | |
8197 | machine-readable copy of the corresponding source code, to be | |
8198 | distributed under the terms of Sections 1 and 2 above on a medium | |
8199 | customarily used for software interchange; or, | |
70b88761 RP |
8200 | |
8201 | @item | |
7463aadd RP |
8202 | Accompany it with the information you received as to the offer |
8203 | to distribute corresponding source code. (This alternative is | |
70b88761 | 8204 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
8205 | received the program in object code or executable form with such |
8206 | an offer, in accord with Subsection b above.) | |
1041a570 | 8207 | @end enumerate |
7463aadd RP |
8208 | |
8209 | The source code for a work means the preferred form of the work for | |
8210 | making modifications to it. For an executable work, complete source | |
8211 | code means all the source code for all modules it contains, plus any | |
8212 | associated interface definition files, plus the scripts used to | |
8213 | control compilation and installation of the executable. However, as a | |
8214 | special exception, the source code distributed need not include | |
8215 | anything that is normally distributed (in either source or binary | |
8216 | form) with the major components (compiler, kernel, and so on) of the | |
8217 | operating system on which the executable runs, unless that component | |
8218 | itself accompanies the executable. | |
8219 | ||
8220 | If distribution of executable or object code is made by offering | |
8221 | access to copy from a designated place, then offering equivalent | |
8222 | access to copy the source code from the same place counts as | |
8223 | distribution of the source code, even though third parties are not | |
8224 | compelled to copy the source along with the object code. | |
70b88761 RP |
8225 | |
8226 | @item | |
7463aadd RP |
8227 | You may not copy, modify, sublicense, or distribute the Program |
8228 | except as expressly provided under this License. Any attempt | |
8229 | otherwise to copy, modify, sublicense or distribute the Program is | |
8230 | void, and will automatically terminate your rights under this License. | |
8231 | However, parties who have received copies, or rights, from you under | |
8232 | this License will not have their licenses terminated so long as such | |
8233 | parties remain in full compliance. | |
70b88761 RP |
8234 | |
8235 | @item | |
7463aadd RP |
8236 | You are not required to accept this License, since you have not |
8237 | signed it. However, nothing else grants you permission to modify or | |
8238 | distribute the Program or its derivative works. These actions are | |
8239 | prohibited by law if you do not accept this License. Therefore, by | |
8240 | modifying or distributing the Program (or any work based on the | |
8241 | Program), you indicate your acceptance of this License to do so, and | |
8242 | all its terms and conditions for copying, distributing or modifying | |
8243 | the Program or works based on it. | |
70b88761 RP |
8244 | |
8245 | @item | |
8246 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
8247 | Program), the recipient automatically receives a license from the |
8248 | original licensor to copy, distribute or modify the Program subject to | |
8249 | these terms and conditions. You may not impose any further | |
8250 | restrictions on the recipients' exercise of the rights granted herein. | |
8251 | You are not responsible for enforcing compliance by third parties to | |
8252 | this License. | |
8253 | ||
8254 | @item | |
8255 | If, as a consequence of a court judgment or allegation of patent | |
8256 | infringement or for any other reason (not limited to patent issues), | |
8257 | conditions are imposed on you (whether by court order, agreement or | |
8258 | otherwise) that contradict the conditions of this License, they do not | |
8259 | excuse you from the conditions of this License. If you cannot | |
8260 | distribute so as to satisfy simultaneously your obligations under this | |
8261 | License and any other pertinent obligations, then as a consequence you | |
8262 | may not distribute the Program at all. For example, if a patent | |
8263 | license would not permit royalty-free redistribution of the Program by | |
8264 | all those who receive copies directly or indirectly through you, then | |
8265 | the only way you could satisfy both it and this License would be to | |
8266 | refrain entirely from distribution of the Program. | |
8267 | ||
8268 | If any portion of this section is held invalid or unenforceable under | |
8269 | any particular circumstance, the balance of the section is intended to | |
8270 | apply and the section as a whole is intended to apply in other | |
8271 | circumstances. | |
8272 | ||
8273 | It is not the purpose of this section to induce you to infringe any | |
8274 | patents or other property right claims or to contest validity of any | |
8275 | such claims; this section has the sole purpose of protecting the | |
8276 | integrity of the free software distribution system, which is | |
8277 | implemented by public license practices. Many people have made | |
8278 | generous contributions to the wide range of software distributed | |
8279 | through that system in reliance on consistent application of that | |
8280 | system; it is up to the author/donor to decide if he or she is willing | |
8281 | to distribute software through any other system and a licensee cannot | |
8282 | impose that choice. | |
8283 | ||
8284 | This section is intended to make thoroughly clear what is believed to | |
8285 | be a consequence of the rest of this License. | |
8286 | ||
8287 | @item | |
8288 | If the distribution and/or use of the Program is restricted in | |
8289 | certain countries either by patents or by copyrighted interfaces, the | |
8290 | original copyright holder who places the Program under this License | |
8291 | may add an explicit geographical distribution limitation excluding | |
8292 | those countries, so that distribution is permitted only in or among | |
8293 | countries not thus excluded. In such case, this License incorporates | |
8294 | the limitation as if written in the body of this License. | |
70b88761 RP |
8295 | |
8296 | @item | |
8297 | The Free Software Foundation may publish revised and/or new versions | |
8298 | of the General Public License from time to time. Such new versions will | |
8299 | be similar in spirit to the present version, but may differ in detail to | |
8300 | address new problems or concerns. | |
8301 | ||
8302 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 8303 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
8304 | later version'', you have the option of following the terms and conditions |
8305 | either of that version or of any later version published by the Free | |
8306 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 8307 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
8308 | Foundation. |
8309 | ||
8310 | @item | |
8311 | If you wish to incorporate parts of the Program into other free | |
8312 | programs whose distribution conditions are different, write to the author | |
8313 | to ask for permission. For software which is copyrighted by the Free | |
8314 | Software Foundation, write to the Free Software Foundation; we sometimes | |
8315 | make exceptions for this. Our decision will be guided by the two goals | |
8316 | of preserving the free status of all derivatives of our free software and | |
8317 | of promoting the sharing and reuse of software generally. | |
8318 | ||
8319 | @iftex | |
8320 | @heading NO WARRANTY | |
8321 | @end iftex | |
8322 | @ifinfo | |
8323 | @center NO WARRANTY | |
8324 | @end ifinfo | |
8325 | ||
8326 | @item | |
8327 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
8328 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
8329 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
8330 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
8331 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
8332 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
8333 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
8334 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
8335 | REPAIR OR CORRECTION. | |
8336 | ||
8337 | @item | |
7463aadd RP |
8338 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
8339 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 8340 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
8341 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
8342 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
8343 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
8344 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
8345 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
8346 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
8347 | @end enumerate |
8348 | ||
8349 | @iftex | |
8350 | @heading END OF TERMS AND CONDITIONS | |
8351 | @end iftex | |
8352 | @ifinfo | |
8353 | @center END OF TERMS AND CONDITIONS | |
8354 | @end ifinfo | |
8355 | ||
8356 | @page | |
54e6b3c3 | 8357 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
8358 | |
8359 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
8360 | possible use to the public, the best way to achieve this is to make it |
8361 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 8362 | |
7463aadd RP |
8363 | To do so, attach the following notices to the program. It is safest |
8364 | to attach them to the start of each source file to most effectively | |
8365 | convey the exclusion of warranty; and each file should have at least | |
8366 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
8367 | |
8368 | @smallexample | |
203eea5d | 8369 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
8370 | Copyright (C) 19@var{yy} @var{name of author} |
8371 | ||
203eea5d RP |
8372 | This program is free software; you can redistribute it and/or |
8373 | modify it under the terms of the GNU General Public License | |
8374 | as published by the Free Software Foundation; either version 2 | |
8375 | of the License, or (at your option) any later version. | |
70b88761 RP |
8376 | |
8377 | This program is distributed in the hope that it will be useful, | |
8378 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8379 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8380 | GNU General Public License for more details. | |
8381 | ||
8382 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
8383 | along with this program; if not, write to the |
8384 | Free Software Foundation, Inc., 675 Mass Ave, | |
8385 | Cambridge, MA 02139, USA. | |
70b88761 RP |
8386 | @end smallexample |
8387 | ||
8388 | Also add information on how to contact you by electronic and paper mail. | |
8389 | ||
8390 | If the program is interactive, make it output a short notice like this | |
8391 | when it starts in an interactive mode: | |
8392 | ||
8393 | @smallexample | |
8394 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
8395 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
8396 | type `show w'. This is free software, and you are welcome | |
8397 | to redistribute it under certain conditions; type `show c' | |
8398 | for details. | |
70b88761 RP |
8399 | @end smallexample |
8400 | ||
7463aadd RP |
8401 | The hypothetical commands @samp{show w} and @samp{show c} should show |
8402 | the appropriate parts of the General Public License. Of course, the | |
8403 | commands you use may be called something other than @samp{show w} and | |
8404 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8405 | suits your program. | |
70b88761 RP |
8406 | |
8407 | You should also get your employer (if you work as a programmer) or your | |
8408 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8409 | necessary. Here is a sample; alter the names: | |
8410 | ||
1041a570 RP |
8411 | @example |
8412 | Yoyodyne, Inc., hereby disclaims all copyright | |
8413 | interest in the program `Gnomovision' | |
8414 | (which makes passes at compilers) written | |
8415 | by James Hacker. | |
70b88761 RP |
8416 | |
8417 | @var{signature of Ty Coon}, 1 April 1989 | |
8418 | Ty Coon, President of Vice | |
1041a570 | 8419 | @end example |
7463aadd RP |
8420 | |
8421 | This General Public License does not permit incorporating your program into | |
8422 | proprietary programs. If your program is a subroutine library, you may | |
8423 | consider it more useful to permit linking proprietary applications with the | |
8424 | library. If this is what you want to do, use the GNU Library General | |
8425 | Public License instead of this License. | |
70b88761 | 8426 | |
4eb4cf57 | 8427 | @node Index |
d2e08421 | 8428 | @unnumbered Index |
e91b87a3 | 8429 | |
8430 | @printindex cp | |
8431 | ||
fe3f5fc8 RP |
8432 | @tex |
8433 | % I think something like @colophon should be in texinfo. In the | |
8434 | % meantime: | |
8435 | \long\def\colophon{\hbox to0pt{}\vfill | |
8436 | \centerline{The body of this manual is set in} | |
8437 | \centerline{\fontname\tenrm,} | |
8438 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8439 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
8440 | \centerline{{\it\fontname\tenit\/},} |
8441 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
8442 | \centerline{{\sl\fontname\tensl\/}} |
8443 | \centerline{are used for emphasis.}\vfill} | |
8444 | \page\colophon | |
a6d0b6d3 | 8445 | % Blame: pesch@cygnus.com, 1991. |
fe3f5fc8 RP |
8446 | @end tex |
8447 | ||
e91b87a3 | 8448 | @contents |
8449 | @bye |