]>
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 |
a37d76c9 | 67 | This is Edition 4.06, October 1992, |
a6463583 | 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 | 106 | @subtitle Edition 4.06, for _GDBN__ version _GDB_VN__ |
a37d76c9 | 107 | @subtitle October 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 | |
a37d76c9 | 147 | This is Edition 4.06, October 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__) |
0f153e74 | 155 | _if__(!_BARE__) |
95d5ceb9 | 156 | * Sample Session:: A sample _GDBN__ session |
0f153e74 | 157 | _fi__(!_BARE__) |
29a2b744 RP |
158 | * Invocation:: Getting in and out of _GDBN__ |
159 | * Commands:: _GDBN__ commands | |
160 | * Running:: Running programs under _GDBN__ | |
161 | * Stopping:: Stopping and continuing | |
162 | * Stack:: Examining the stack | |
163 | * Source:: Examining source files | |
164 | * Data:: Examining data | |
4eb4cf57 | 165 | _if__(!_CONLY__) |
29a2b744 | 166 | * Languages:: Using _GDBN__ with different languages |
4eb4cf57 RP |
167 | _fi__(!_CONLY__) |
168 | _if__(_CONLY__) | |
169 | * C:: C and C++ | |
170 | _fi__(_CONLY__) | |
29a2b744 RP |
171 | * Symbols:: Examining the symbol table |
172 | * Altering:: Altering execution | |
173 | * _GDBN__ Files:: _GDBN__'s files | |
174 | * Targets:: Specifying a debugging target | |
c2bbbb22 | 175 | * Controlling _GDBN__:: Controlling _GDBN__ |
29a2b744 | 176 | * Sequences:: Canned sequences of commands |
4eb4cf57 | 177 | _if__(!_DOSHOST__) |
b80282d5 | 178 | * Emacs:: Using _GDBN__ under GNU Emacs |
4eb4cf57 | 179 | _fi__(!_DOSHOST__) |
29a2b744 | 180 | * _GDBN__ Bugs:: Reporting bugs in _GDBN__ |
77fe5411 | 181 | _if__(_GENERIC__||!_H8__) |
e251e767 | 182 | * Renamed Commands:: |
77fe5411 | 183 | _fi__(_GENERIC__||!_H8__) |
77b46d13 | 184 | * Formatting Documentation:: How to format and print GDB documentation |
c7cb8acb | 185 | * Installing GDB:: Installing GDB |
b80282d5 RP |
186 | * Copying:: GNU GENERAL PUBLIC LICENSE |
187 | * Index:: Index | |
70b88761 RP |
188 | @end menu |
189 | ||
4eb4cf57 | 190 | @node Summary |
70b88761 RP |
191 | @unnumbered Summary of _GDBN__ |
192 | ||
193 | The purpose of a debugger such as _GDBN__ is to allow you to see what is | |
194 | going on ``inside'' another program while it executes---or what another | |
1041a570 | 195 | program was doing at the moment it crashed. |
70b88761 RP |
196 | |
197 | _GDBN__ can do four main kinds of things (plus other things in support of | |
1041a570 | 198 | these) to help you catch bugs in the act: |
70b88761 RP |
199 | |
200 | @itemize @bullet | |
201 | @item | |
202 | Start your program, specifying anything that might affect its behavior. | |
203 | ||
204 | @item | |
205 | Make your program stop on specified conditions. | |
206 | ||
207 | @item | |
208 | Examine what has happened, when your program has stopped. | |
209 | ||
210 | @item | |
211 | Change things in your program, so you can experiment with correcting the | |
212 | effects of one bug and go on to learn about another. | |
213 | @end itemize | |
214 | ||
0f153e74 | 215 | _if__(!_CONLY__) |
c2bbbb22 RP |
216 | You can use _GDBN__ to debug programs written in C, C++, and Modula-2. |
217 | Fortran support will be added when a GNU Fortran compiler is ready. | |
0f153e74 | 218 | _fi__(!_CONLY__) |
70b88761 RP |
219 | |
220 | @menu | |
b80282d5 RP |
221 | * Free Software:: Free Software |
222 | * Contributors:: Contributors to GDB | |
70b88761 RP |
223 | @end menu |
224 | ||
4eb4cf57 | 225 | @node Free Software |
70b88761 | 226 | @unnumberedsec Free Software |
1041a570 RP |
227 | |
228 | _GDBN__ is @dfn{free software}, protected by the GNU General Public License | |
229 | (GPL). The GPL gives you the freedom to copy or adapt a licensed | |
70b88761 RP |
230 | program---but every person getting a copy also gets with it the |
231 | freedom to modify that copy (which means that they must get access to | |
232 | the source code), and the freedom to distribute further copies. | |
233 | Typical software companies use copyrights to limit your freedoms; the | |
234 | Free Software Foundation uses the GPL to preserve these freedoms. | |
235 | ||
236 | Fundamentally, the General Public License is a license which says that | |
29a2b744 | 237 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
238 | from anyone else. |
239 | ||
0f153e74 | 240 | _if__(!_AGGLOMERATION__) |
29a2b744 | 241 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
0f153e74 | 242 | _fi__(!_AGGLOMERATION__) |
1041a570 | 243 | |
4eb4cf57 | 244 | @node Contributors |
70b88761 RP |
245 | @unnumberedsec Contributors to GDB |
246 | ||
247 | Richard Stallman was the original author of GDB, and of many other GNU | |
248 | programs. Many others have contributed to its development. This | |
249 | section attempts to credit major contributors. One of the virtues of | |
250 | free software is that everyone is free to contribute to it; with | |
251 | regret, we cannot actually acknowledge everyone here. The file | |
252 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
253 | account. | |
254 | ||
255 | Changes much prior to version 2.0 are lost in the mists of time. | |
256 | ||
257 | @quotation | |
258 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
259 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
260 | omitted from this list, we would like to add your names! | |
261 | @end quotation | |
262 | ||
263 | So that they may not regard their long labor as thankless, we | |
69bbcf05 | 264 | particularly thank those who shepherded GDB through major releases: Stu |
6f3ec223 RP |
265 | Grossman and John Gilmore (releases 4.6, 4.5, 4.4), John Gilmore |
266 | (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, | |
267 | 3.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of | |
268 | GDB for some period, each contributed significantly to the structure, | |
269 | stability, and capabilities of the entire debugger. | |
70b88761 RP |
270 | |
271 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
272 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
273 | ||
274 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
275 | with significant additional contributions from Per Bothner. James | |
276 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
277 | TerMaat (who also did much general update work leading to release 3.0). | |
278 | ||
1041a570 RP |
279 | GDB 4 uses the BFD subroutine library to examine multiple |
280 | object-file formats; BFD was a joint project of David V. | |
281 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
70b88761 | 282 | |
1041a570 RP |
283 | David Johnson wrote the original COFF support; Pace Willison did |
284 | the original support for encapsulated COFF. | |
70b88761 RP |
285 | |
286 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
287 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
288 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris |
289 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
290 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
291 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
292 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
293 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
294 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
295 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
296 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
297 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
298 | support. | |
70b88761 | 299 | |
c338a2fd RP |
300 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
301 | libraries. | |
70b88761 RP |
302 | |
303 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
304 | several machine instruction sets. | |
305 | ||
1041a570 RP |
306 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped |
307 | develop remote debugging. Intel Corporation and Wind River Systems | |
308 | contributed remote debugging modules for their products. | |
70b88761 | 309 | |
1041a570 RP |
310 | Brian Fox is the author of the readline libraries providing |
311 | command-line editing and command history. | |
70b88761 | 312 | |
1041a570 RP |
313 | Andrew Beers of SUNY Buffalo wrote the language-switching code and |
314 | the Modula-2 support, and contributed the Languages chapter of this | |
315 | manual. | |
c2bbbb22 | 316 | |
6f3ec223 RP |
317 | Fred Fish wrote most of the support for Unix System Vr4, and enhanced |
318 | the command-completion support to cover C++ overloaded symbols. | |
14d01801 | 319 | |
4eb4cf57 RP |
320 | _if__(_GENERIC__ || !_H8__) |
321 | @node New Features | |
c7cb8acb | 322 | @unnumbered New Features since GDB version 3.5 |
70b88761 RP |
323 | |
324 | @table @emph | |
325 | @item Targets | |
326 | Using the new command @code{target}, you can select at runtime whether | |
327 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
328 | a serial port, realtime systems over a TCP/IP connection, etc. The |
329 | command @code{load} can download programs into a remote system. Serial | |
b21b18e1 RP |
330 | stubs are available for Motorola 680x0, Intel 80386, and Sparc remote |
331 | systems; GDB also supports debugging realtime processes running under | |
b80282d5 | 332 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a |
b21b18e1 RP |
333 | debugger stub on the target system. Internally, GDB now uses a function |
334 | vector to mediate access to different targets; if you need to add your | |
335 | own support for a remote protocol, this makes it much easier. | |
70b88761 RP |
336 | |
337 | @item Watchpoints | |
c7cb8acb | 338 | GDB now sports watchpoints as well as breakpoints. You can use a |
70b88761 RP |
339 | watchpoint to stop execution whenever the value of an expression |
340 | changes, without having to predict a particular place in your program | |
341 | where this may happen. | |
342 | ||
b80282d5 RP |
343 | @item Wide Output |
344 | Commands that issue wide output now insert newlines at places designed | |
345 | to make the output more readable. | |
346 | ||
70b88761 | 347 | @item Object Code Formats |
c7cb8acb | 348 | GDB uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
349 | Library to permit it to switch dynamically, without reconfiguration or |
350 | recompilation, between different object-file formats. Formats currently | |
351 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
352 | .o's, archive libraries, or core dumps. BFD is available as a | |
353 | subroutine library so that other programs may take advantage of it, and | |
354 | the other GNU binary utilities are being converted to use it. | |
70b88761 | 355 | |
b80282d5 | 356 | @item Configuration and Ports |
70b88761 | 357 | Compile-time configuration (to select a particular architecture and |
7463aadd | 358 | operating system) is much easier. The script @code{configure} now |
c7cb8acb RP |
359 | allows you to configure GDB as either a native debugger or a |
360 | cross-debugger. @xref{Installing GDB}, for details on how to | |
6a8cb0e7 | 361 | configure. |
70b88761 RP |
362 | |
363 | @item Interaction | |
c7cb8acb | 364 | The user interface to GDB's control variables has been simplified |
70b88761 RP |
365 | and consolidated in two commands, @code{set} and @code{show}. Output |
366 | lines are now broken at readable places, rather than overflowing onto | |
367 | the next line. You can suppress output of machine-level addresses, | |
368 | displaying only source language information. | |
369 | ||
b80282d5 | 370 | @item C++ |
c7cb8acb | 371 | GDB now supports C++ multiple inheritance (if used with a GCC |
b80282d5 | 372 | version 2 compiler), and also has limited support for C++ exception |
c7cb8acb | 373 | handling, with the commands @code{catch} and @code{info catch}: GDB |
b80282d5 RP |
374 | can break when an exception is raised, before the stack is peeled back |
375 | to the exception handler's context. | |
70b88761 | 376 | |
c2bbbb22 | 377 | @item Modula-2 |
c7cb8acb | 378 | GDB now has preliminary support for the GNU Modula-2 compiler, |
c2bbbb22 | 379 | currently under development at the State University of New York at |
c7cb8acb | 380 | Buffalo. Coordinated development of both GDB and the GNU Modula-2 |
5b0fdf7b RP |
381 | compiler will continue into 1992. Other Modula-2 compilers are |
382 | currently not supported, and attempting to debug programs compiled with | |
383 | them will likely result in an error as the symbol table of the | |
384 | executable is read in. | |
c2bbbb22 | 385 | |
70b88761 | 386 | @item Command Rationalization |
c7cb8acb | 387 | Many GDB commands have been renamed to make them easier to remember |
70b88761 RP |
388 | and use. In particular, the subcommands of @code{info} and |
389 | @code{show}/@code{set} are grouped to make the former refer to the state | |
c7cb8acb | 390 | of your program, and the latter refer to the state of GDB itself. |
70b88761 RP |
391 | @xref{Renamed Commands}, for details on what commands were renamed. |
392 | ||
70b88761 | 393 | @item Shared Libraries |
77b46d13 JG |
394 | GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000 |
395 | shared libraries. | |
b80282d5 RP |
396 | |
397 | @item Reference Card | |
6f3ec223 RP |
398 | GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting |
399 | the Documentation}, for instructions to print it. | |
70b88761 RP |
400 | |
401 | @item Work in Progress | |
402 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
403 | support. | |
70b88761 | 404 | @end table |
4eb4cf57 | 405 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 406 | |
0f153e74 | 407 | _if__(!_BARE__) |
4eb4cf57 | 408 | @node Sample Session |
70b88761 RP |
409 | @chapter A Sample _GDBN__ Session |
410 | ||
411 | You can use this manual at your leisure to read all about _GDBN__. | |
412 | However, a handful of commands are enough to get started using the | |
413 | debugger. This chapter illustrates these commands. | |
414 | ||
415 | @iftex | |
6ca72cc6 | 416 | In this sample session, we emphasize user input like this: @b{input}, |
70b88761 RP |
417 | to make it easier to pick out from the surrounding output. |
418 | @end iftex | |
419 | ||
420 | @c FIXME: this example may not be appropriate for some configs, where | |
421 | @c FIXME...primary interest is in remote use. | |
422 | _0__ | |
423 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
424 | processor) exhibits the following bug: sometimes, when we change its | |
425 | quote strings from the default, the commands used to capture one macro's | |
426 | definition in another stop working. In the following short @code{m4} | |
427 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
29a2b744 | 428 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
429 | same thing. However, when we change the open quote string to |
430 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
431 | procedure fails to define a new synonym @code{baz}: | |
432 | ||
433 | @smallexample | |
6ca72cc6 RP |
434 | $ @b{cd gnu/m4} |
435 | $ @b{./m4} | |
436 | @b{define(foo,0000)} | |
70b88761 | 437 | |
6ca72cc6 | 438 | @b{foo} |
70b88761 | 439 | 0000 |
6ca72cc6 | 440 | @b{define(bar,defn(`foo'))} |
70b88761 | 441 | |
6ca72cc6 | 442 | @b{bar} |
70b88761 | 443 | 0000 |
6ca72cc6 | 444 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 445 | |
6ca72cc6 RP |
446 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
447 | @b{baz} | |
448 | @b{C-d} | |
70b88761 RP |
449 | m4: End of input: 0: fatal error: EOF in string |
450 | @end smallexample | |
451 | ||
452 | @noindent | |
453 | Let's use _GDBN__ to try to see what's going on. | |
454 | ||
455 | @smallexample | |
6ca72cc6 | 456 | $ @b{_GDBP__ m4} |
203eea5d RP |
457 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
458 | @c FIXME... format to come out better. | |
459 | GDB is free software and you are welcome to distribute copies | |
460 | of it under certain conditions; type "show copying" to see | |
461 | the conditions. | |
462 | There is absolutely no warranty for GDB; type "show warranty" | |
463 | for details. | |
5b0fdf7b | 464 | GDB _GDB_VN__, Copyright 1992 Free Software Foundation, Inc... |
e251e767 | 465 | (_GDBP__) |
70b88761 RP |
466 | @end smallexample |
467 | ||
468 | @noindent | |
1041a570 RP |
469 | _GDBN__ reads only enough symbol data to know where to find the rest when |
470 | needed; as a result, the first prompt comes up very quickly. We now | |
471 | tell _GDBN__ to use a narrower display width than usual, so that examples | |
472 | will fit in this manual. | |
70b88761 RP |
473 | |
474 | @smallexample | |
6ca72cc6 | 475 | (_GDBP__) @b{set width 70} |
70b88761 RP |
476 | @end smallexample |
477 | ||
e251e767 | 478 | @noindent |
29a2b744 | 479 | Let's see how the @code{m4} built-in @code{changequote} works. |
70b88761 RP |
480 | Having looked at the source, we know the relevant subroutine is |
481 | @code{m4_changequote}, so we set a breakpoint there with _GDBN__'s | |
482 | @code{break} command. | |
483 | ||
484 | @smallexample | |
6ca72cc6 | 485 | (_GDBP__) @b{break m4_changequote} |
70b88761 RP |
486 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. |
487 | @end smallexample | |
488 | ||
489 | @noindent | |
490 | Using the @code{run} command, we start @code{m4} running under _GDBN__ | |
491 | control; as long as control does not reach the @code{m4_changequote} | |
492 | subroutine, the program runs as usual: | |
493 | ||
494 | @smallexample | |
6ca72cc6 | 495 | (_GDBP__) @b{run} |
e251e767 | 496 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
6ca72cc6 | 497 | @b{define(foo,0000)} |
70b88761 | 498 | |
6ca72cc6 | 499 | @b{foo} |
70b88761 RP |
500 | 0000 |
501 | @end smallexample | |
502 | ||
503 | @noindent | |
504 | To trigger the breakpoint, we call @code{changequote}. _GDBN__ | |
505 | suspends execution of @code{m4}, displaying information about the | |
506 | context where it stops. | |
507 | ||
508 | @smallexample | |
6ca72cc6 | 509 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 510 | |
203eea5d RP |
511 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
512 | at builtin.c:879 | |
38962738 | 513 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) |
70b88761 RP |
514 | @end smallexample |
515 | ||
516 | @noindent | |
517 | Now we use the command @code{n} (@code{next}) to advance execution to | |
518 | the next line of the current function. | |
519 | ||
520 | @smallexample | |
6ca72cc6 | 521 | (_GDBP__) @b{n} |
203eea5d RP |
522 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
523 | : nil, | |
70b88761 RP |
524 | @end smallexample |
525 | ||
526 | @noindent | |
527 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
528 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
529 | @code{step} goes to the next line to be executed in @emph{any} | |
e251e767 | 530 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
531 | |
532 | @smallexample | |
6ca72cc6 | 533 | (_GDBP__) @b{s} |
70b88761 RP |
534 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
535 | at input.c:530 | |
536 | 530 if (lquote != def_lquote) | |
537 | @end smallexample | |
538 | ||
539 | @noindent | |
29a2b744 RP |
540 | The display that shows the subroutine where @code{m4} is now |
541 | suspended (and its arguments) is called a stack frame display. It | |
542 | shows a summary of the stack. We can use the @code{backtrace} | |
543 | command (which can also be spelled @code{bt}), to see where we are | |
544 | in the stack as a whole: the @code{backtrace} command displays a | |
545 | stack frame for each active subroutine. | |
70b88761 RP |
546 | |
547 | @smallexample | |
6ca72cc6 | 548 | (_GDBP__) @b{bt} |
70b88761 RP |
549 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
550 | at input.c:530 | |
203eea5d RP |
551 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
552 | at builtin.c:882 | |
70b88761 RP |
553 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
554 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
555 | at macro.c:71 | |
556 | #4 0x79dc in expand_input () at macro.c:40 | |
557 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
558 | @end smallexample | |
559 | ||
560 | @noindent | |
561 | Let's step through a few more lines to see what happens. The first two | |
562 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
563 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 564 | |
70b88761 | 565 | @smallexample |
6ca72cc6 | 566 | (_GDBP__) @b{s} |
70b88761 | 567 | 0x3b5c 532 if (rquote != def_rquote) |
6ca72cc6 | 568 | (_GDBP__) @b{s} |
203eea5d RP |
569 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
570 | def_lquote : xstrdup(lq); | |
6ca72cc6 | 571 | (_GDBP__) @b{n} |
203eea5d RP |
572 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
573 | : xstrdup(rq); | |
6ca72cc6 | 574 | (_GDBP__) @b{n} |
70b88761 RP |
575 | 538 len_lquote = strlen(rquote); |
576 | @end smallexample | |
577 | ||
578 | @noindent | |
579 | The last line displayed looks a little odd; let's examine the variables | |
580 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
581 | and right quotes we specified. We can use the command @code{p} | |
582 | (@code{print}) to see their values. | |
583 | ||
584 | @smallexample | |
6ca72cc6 | 585 | (_GDBP__) @b{p lquote} |
70b88761 | 586 | $1 = 0x35d40 "<QUOTE>" |
6ca72cc6 | 587 | (_GDBP__) @b{p rquote} |
70b88761 RP |
588 | $2 = 0x35d50 "<UNQUOTE>" |
589 | @end smallexample | |
590 | ||
591 | @noindent | |
592 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
593 | Let's look at some context; we can display ten lines of source | |
594 | surrounding the current line, with the @code{l} (@code{list}) command. | |
595 | ||
596 | @smallexample | |
6ca72cc6 | 597 | (_GDBP__) @b{l} |
70b88761 | 598 | 533 xfree(rquote); |
e251e767 | 599 | 534 |
203eea5d RP |
600 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
601 | : xstrdup (lq); | |
602 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
603 | : xstrdup (rq); | |
e251e767 | 604 | 537 |
70b88761 RP |
605 | 538 len_lquote = strlen(rquote); |
606 | 539 len_rquote = strlen(lquote); | |
607 | 540 @} | |
e251e767 | 608 | 541 |
70b88761 RP |
609 | 542 void |
610 | @end smallexample | |
611 | ||
612 | @noindent | |
613 | Let's step past the two lines that set @code{len_lquote} and | |
614 | @code{len_rquote}, and then examine the values of those variables. | |
615 | ||
616 | @smallexample | |
6ca72cc6 | 617 | (_GDBP__) @b{n} |
70b88761 | 618 | 539 len_rquote = strlen(lquote); |
6ca72cc6 | 619 | (_GDBP__) @b{n} |
70b88761 | 620 | 540 @} |
6ca72cc6 | 621 | (_GDBP__) @b{p len_lquote} |
70b88761 | 622 | $3 = 9 |
6ca72cc6 | 623 | (_GDBP__) @b{p len_rquote} |
70b88761 RP |
624 | $4 = 7 |
625 | @end smallexample | |
626 | ||
627 | @noindent | |
628 | That certainly looks wrong, assuming @code{len_lquote} and | |
629 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
630 | @code{rquote} respectively. Let's try setting them to better values. | |
631 | We can use the @code{p} command for this, since it'll print the value of | |
632 | any expression---and that expression can include subroutine calls and | |
e251e767 | 633 | assignments. |
70b88761 RP |
634 | |
635 | @smallexample | |
6ca72cc6 | 636 | (_GDBP__) @b{p len_lquote=strlen(lquote)} |
70b88761 | 637 | $5 = 7 |
6ca72cc6 | 638 | (_GDBP__) @b{p len_rquote=strlen(rquote)} |
70b88761 RP |
639 | $6 = 9 |
640 | @end smallexample | |
641 | ||
642 | @noindent | |
643 | Let's see if that fixes the problem of using the new quotes with the | |
644 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
645 | executing with the @code{c} (@code{continue}) command, and then try the | |
646 | example that caused trouble initially: | |
647 | ||
648 | @smallexample | |
6ca72cc6 | 649 | (_GDBP__) @b{c} |
70b88761 RP |
650 | Continuing. |
651 | ||
6ca72cc6 | 652 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
70b88761 RP |
653 | |
654 | baz | |
655 | 0000 | |
656 | @end smallexample | |
657 | ||
658 | @noindent | |
659 | Success! The new quotes now work just as well as the default ones. The | |
660 | problem seems to have been just the two typos defining the wrong | |
661 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
662 | ||
663 | @smallexample | |
6ca72cc6 | 664 | @b{C-d} |
70b88761 RP |
665 | Program exited normally. |
666 | @end smallexample | |
667 | ||
e251e767 | 668 | @noindent |
70b88761 RP |
669 | The message @samp{Program exited normally.} is from _GDBN__; it |
670 | indicates @code{m4} has finished executing. We can end our _GDBN__ | |
671 | session with the _GDBN__ @code{quit} command. | |
672 | ||
673 | @smallexample | |
6ca72cc6 | 674 | (_GDBP__) @b{quit} |
70b88761 | 675 | _1__@end smallexample |
0f153e74 | 676 | _fi__(!_BARE__) |
70b88761 | 677 | |
4eb4cf57 | 678 | @node Invocation |
70b88761 RP |
679 | @chapter Getting In and Out of _GDBN__ |
680 | ||
c7cb8acb RP |
681 | This chapter discusses how to start _GDBN__, and how to get out of it. |
682 | (The essentials: type @samp{_GDBP__} to start GDB, and type @kbd{quit} | |
683 | or @kbd{C-d} to exit.) | |
29a2b744 | 684 | |
70b88761 | 685 | @menu |
29a2b744 | 686 | * Invoking _GDBN__:: Starting _GDBN__ |
c2bbbb22 | 687 | * Leaving _GDBN__:: Leaving _GDBN__ |
4eb4cf57 | 688 | _if__(!_BARE__) |
b80282d5 | 689 | * Shell Commands:: Shell Commands |
4eb4cf57 | 690 | _fi__(!_BARE__) |
70b88761 RP |
691 | @end menu |
692 | ||
4eb4cf57 | 693 | @node Invoking _GDBN__ |
70b88761 RP |
694 | @section Starting _GDBN__ |
695 | ||
4eb4cf57 RP |
696 | _if__(_H8__) |
697 | For details on starting up _GDBP__ as a | |
698 | remote debugger attached to a Hitachi H8/300 board, see @ref{Hitachi | |
699 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}. | |
700 | _fi__(_H8__) | |
701 | ||
702 | Start _GDBN__ by running the program @code{_GDBP__}. Once it's running, | |
1041a570 | 703 | _GDBN__ reads commands from the terminal until you tell it to exit. |
70b88761 | 704 | |
c7cb8acb RP |
705 | You can also run @code{_GDBP__} with a variety of arguments and options, |
706 | to specify more of your debugging environment at the outset. | |
707 | ||
0005054f | 708 | _if__(_GENERIC__) |
c7cb8acb RP |
709 | The command-line options described here are designed |
710 | to cover a variety of situations; in some environments, some of these | |
711 | options may effectively be unavailable. | |
0005054f | 712 | _fi__(_GENERIC__) |
c7cb8acb | 713 | |
4eb4cf57 RP |
714 | The most usual way to start _GDBN__ is with one argument, |
715 | specifying an executable program: | |
1041a570 | 716 | |
70b88761 | 717 | @example |
29a2b744 | 718 | _GDBP__ @var{program} |
70b88761 | 719 | @end example |
1041a570 | 720 | |
4eb4cf57 | 721 | _if__(!_BARE__) |
70b88761 | 722 | @noindent |
29a2b744 RP |
723 | You can also start with both an executable program and a core file |
724 | specified: | |
1041a570 | 725 | |
70b88761 | 726 | @example |
29a2b744 | 727 | _GDBP__ @var{program} @var{core} |
70b88761 RP |
728 | @end example |
729 | ||
b80282d5 RP |
730 | You can, instead, specify a process ID as a second argument, if you want |
731 | to debug a running process: | |
1041a570 | 732 | |
b80282d5 | 733 | @example |
29a2b744 | 734 | _GDBP__ @var{program} 1234 |
b80282d5 | 735 | @end example |
1041a570 | 736 | |
b80282d5 RP |
737 | @noindent |
738 | would attach _GDBN__ to process @code{1234} (unless you also have a file | |
739 | named @file{1234}; _GDBN__ does check for a core file first). | |
740 | ||
c7cb8acb RP |
741 | Taking advantage of the second command-line argument requires a fairly |
742 | complete operating system; when you use _GDBN__ as a remote debugger | |
743 | attached to a bare board, there may not be any notion of ``process'', | |
744 | and there is often no way to get a core dump. | |
4eb4cf57 | 745 | _fi__(!_BARE__) |
c7cb8acb | 746 | |
70b88761 RP |
747 | @noindent |
748 | You can further control how _GDBN__ starts up by using command-line | |
29a2b744 RP |
749 | options. _GDBN__ itself can remind you of the options available. |
750 | ||
751 | @noindent | |
752 | Type | |
753 | ||
70b88761 RP |
754 | @example |
755 | _GDBP__ -help | |
756 | @end example | |
29a2b744 | 757 | |
70b88761 | 758 | @noindent |
29a2b744 | 759 | to display all available options and briefly describe their use |
70b88761 RP |
760 | (@samp{_GDBP__ -h} is a shorter equivalent). |
761 | ||
762 | All options and command line arguments you give are processed | |
763 | in sequential order. The order makes a difference when the | |
e251e767 | 764 | @samp{-x} option is used. |
70b88761 RP |
765 | |
766 | @menu | |
70b88761 RP |
767 | _if__(!_GENERIC__) |
768 | _include__(gdbinv-m.m4)_dnl__ | |
769 | _fi__(!_GENERIC__) | |
4eb4cf57 RP |
770 | * File Options:: Choosing Files |
771 | * Mode Options:: Choosing Modes | |
70b88761 RP |
772 | @end menu |
773 | ||
4eb4cf57 RP |
774 | _if__(!_GENERIC__) |
775 | _include__(gdbinv-s.m4) | |
776 | _fi__(!_GENERIC__) | |
777 | ||
778 | @node File Options | |
70b88761 RP |
779 | @subsection Choosing Files |
780 | ||
4eb4cf57 | 781 | _if__(!_BARE__) |
29a2b744 RP |
782 | When _GDBN__ starts, it reads any arguments other than options as |
783 | specifying an executable file and core file (or process ID). This is | |
784 | the same as if the arguments were specified by the @samp{-se} and | |
785 | @samp{-c} options respectively. (_GDBN__ reads the first argument | |
786 | that does not have an associated option flag as equivalent to the | |
787 | @samp{-se} option followed by that argument; and the second argument | |
788 | that does not have an associated option flag, if any, as equivalent to | |
789 | the @samp{-c} option followed by that argument.) | |
4eb4cf57 RP |
790 | _fi__(!_BARE__) |
791 | _if__(_BARE__) | |
792 | When _GDBN__ starts, it reads any argument other than options as | |
793 | specifying an executable file. This is the same as if the argument was | |
794 | specified by the @samp{-se} option. | |
795 | _fi__(_BARE__) | |
29a2b744 RP |
796 | |
797 | Many options have both long and short forms; both are shown in the | |
798 | following list. _GDBN__ also recognizes the long forms if you truncate | |
799 | them, so long as enough of the option is present to be unambiguous. | |
800 | (If you prefer, you can flag option arguments with @samp{--} rather | |
801 | than @samp{-}, though we illustrate the more usual convention.) | |
70b88761 RP |
802 | |
803 | @table @code | |
804 | @item -symbols=@var{file} | |
805 | @itemx -s @var{file} | |
806 | Read symbol table from file @var{file}. | |
807 | ||
808 | @item -exec=@var{file} | |
809 | @itemx -e @var{file} | |
810 | Use file @var{file} as the executable file to execute when | |
811 | appropriate, and for examining pure data in conjunction with a core | |
812 | dump. | |
813 | ||
3d3ab540 | 814 | @item -se=@var{file} |
70b88761 RP |
815 | Read symbol table from file @var{file} and use it as the executable |
816 | file. | |
817 | ||
4eb4cf57 | 818 | _if__(!_BARE__) |
70b88761 RP |
819 | @item -core=@var{file} |
820 | @itemx -c @var{file} | |
821 | Use file @var{file} as a core dump to examine. | |
4eb4cf57 | 822 | _fi__(!_BARE__) |
70b88761 RP |
823 | |
824 | @item -command=@var{file} | |
825 | @itemx -x @var{file} | |
826 | Execute _GDBN__ commands from file @var{file}. @xref{Command Files}. | |
827 | ||
828 | @item -directory=@var{directory} | |
829 | @itemx -d @var{directory} | |
830 | Add @var{directory} to the path to search for source files. | |
14d01801 | 831 | |
4eb4cf57 | 832 | _if__(!_BARE__) |
14d01801 RP |
833 | @item -m |
834 | @itemx -mapped | |
835 | @emph{Warning: this option depends on operating system facilities that are not | |
836 | supported on all systems.}@* | |
77b46d13 JG |
837 | If memory-mapped files are available on your system through the @code{mmap} |
838 | system call, you can use this option | |
5a2c1d85 | 839 | to have _GDBN__ write the symbols from your |
77b46d13 JG |
840 | program into a reusable file in the current directory. If the program you are debugging is |
841 | called @file{/tmp/fred}, the mapped symbol file will be @file{./fred.syms}. | |
842 | Future _GDBN__ debugging sessions will notice the presence of this file, | |
843 | and will quickly map in symbol information from it, rather than reading | |
844 | the symbol table from the executable program. | |
845 | ||
846 | The @file{.syms} file is specific to the host machine on which _GDBN__ is run. | |
847 | It holds an exact image of _GDBN__'s internal symbol table. It cannot be | |
848 | shared across multiple host platforms. | |
4eb4cf57 | 849 | _fi__(!_BARE__) |
77b46d13 JG |
850 | |
851 | @item -r | |
852 | @itemx -readnow | |
853 | Read each symbol file's entire symbol table immediately, rather than | |
854 | the default, which is to read it incrementally as it is needed. | |
855 | This makes startup slower, but makes future operations faster. | |
70b88761 RP |
856 | @end table |
857 | ||
4eb4cf57 | 858 | _if__(!_BARE__) |
77b46d13 JG |
859 | The @code{-mapped} and @code{-readnow} options are typically combined in order to |
860 | build a @file{.syms} file that contains complete symbol information. | |
861 | A simple GDB invocation to do nothing but build a @file{.syms} file for future | |
862 | use is: | |
863 | ||
864 | @example | |
865 | gdb -batch -nx -mapped -readnow programname | |
866 | @end example | |
4eb4cf57 | 867 | _fi__(!_BARE__) |
77b46d13 | 868 | |
4eb4cf57 | 869 | @node Mode Options |
1041a570 RP |
870 | @subsection Choosing Modes |
871 | ||
29a2b744 RP |
872 | You can run _GDBN__ in various alternative modes---for example, in |
873 | batch mode or quiet mode. | |
70b88761 RP |
874 | |
875 | @table @code | |
876 | @item -nx | |
877 | @itemx -n | |
878 | Do not execute commands from any @file{_GDBINIT__} initialization files. | |
879 | Normally, the commands in these files are executed after all the | |
e251e767 | 880 | command options and arguments have been processed. |
c728f1f0 | 881 | @xref{Command Files}. |
70b88761 RP |
882 | |
883 | @item -quiet | |
884 | @itemx -q | |
885 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 886 | messages are also suppressed in batch mode. |
70b88761 RP |
887 | |
888 | @item -batch | |
889 | Run in batch mode. Exit with status @code{0} after processing all the command | |
890 | files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited). | |
891 | Exit with nonzero status if an error occurs in executing the _GDBN__ | |
e251e767 | 892 | commands in the command files. |
70b88761 RP |
893 | |
894 | Batch mode may be useful for running _GDBN__ as a filter, for example to | |
895 | download and run a program on another computer; in order to make this | |
e251e767 | 896 | more useful, the message |
1041a570 | 897 | |
70b88761 RP |
898 | @example |
899 | Program exited normally. | |
900 | @end example | |
1041a570 | 901 | |
70b88761 RP |
902 | @noindent |
903 | (which is ordinarily issued whenever a program running under _GDBN__ control | |
904 | terminates) is not issued when running in batch mode. | |
905 | ||
3d3ab540 | 906 | @item -cd=@var{directory} |
70b88761 RP |
907 | Run _GDBN__ using @var{directory} as its working directory, |
908 | instead of the current directory. | |
909 | ||
6ca72cc6 | 910 | _if__(_LUCID__) |
45c53080 | 911 | @item -context @var{authentication} |
6ca72cc6 RP |
912 | When the Energize programming system starts up _GDBN__, it uses this |
913 | option to trigger an alternate mode of interaction. | |
914 | @var{authentication} is a pair of numeric codes that identify _GDBN__ | |
915 | as a client in the Energize environment. Avoid this option when you run | |
916 | _GDBN__ directly from the command line. See @ref{Energize,,Using | |
917 | _GDBN__ with Energize} for more discussion of using _GDBN__ with Energize. | |
918 | _fi__(_LUCID__) | |
919 | ||
70b88761 RP |
920 | @item -fullname |
921 | @itemx -f | |
922 | Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ | |
923 | to output the full file name and line number in a standard, | |
924 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 925 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
926 | like two @samp{\032} characters, followed by the file name, line number |
927 | and character position separated by colons, and a newline. The | |
928 | Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as | |
929 | a signal to display the source code for the frame. | |
930 | ||
4eb4cf57 | 931 | _if__(_GENERIC__ || !_H8__) |
70b88761 RP |
932 | @item -b @var{bps} |
933 | Set the line speed (baud rate or bits per second) of any serial | |
934 | interface used by _GDBN__ for remote debugging. | |
935 | ||
3d3ab540 | 936 | @item -tty=@var{device} |
70b88761 | 937 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 938 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
4eb4cf57 | 939 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
940 | @end table |
941 | ||
4eb4cf57 | 942 | @node Leaving _GDBN__ |
70b88761 RP |
943 | @section Leaving _GDBN__ |
944 | @cindex exiting _GDBN__ | |
1041a570 | 945 | |
70b88761 RP |
946 | @table @code |
947 | @item quit | |
948 | @kindex quit | |
949 | @kindex q | |
950 | To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type | |
e251e767 | 951 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
952 | @end table |
953 | ||
954 | @cindex interrupt | |
955 | An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather | |
956 | will terminate the action of any _GDBN__ command that is in progress and | |
957 | return to _GDBN__ command level. It is safe to type the interrupt | |
958 | character at any time because _GDBN__ does not allow it to take effect | |
959 | until a time when it is safe. | |
960 | ||
4eb4cf57 | 961 | _if__(!_BARE__) |
1041a570 RP |
962 | If you have been using _GDBN__ to control an attached process or device, you |
963 | can release it with the @code{detach} command; @pxref{Attach, | |
964 | ,Debugging an Already-Running Process}.. | |
4eb4cf57 | 965 | _fi__(!_BARE__) |
70b88761 | 966 | |
4eb4cf57 RP |
967 | _if__(!_BARE__) |
968 | @node Shell Commands | |
70b88761 | 969 | @section Shell Commands |
1041a570 | 970 | |
70b88761 | 971 | If you need to execute occasional shell commands during your |
29a2b744 | 972 | debugging session, there is no need to leave or suspend _GDBN__; you can |
70b88761 RP |
973 | just use the @code{shell} command. |
974 | ||
975 | @table @code | |
976 | @item shell @var{command string} | |
977 | @kindex shell | |
978 | @cindex shell escape | |
979 | Directs _GDBN__ to invoke an inferior shell to execute @var{command | |
980 | string}. If it exists, the environment variable @code{SHELL} is used | |
981 | for the name of the shell to run. Otherwise _GDBN__ uses | |
982 | @code{/bin/sh}. | |
983 | @end table | |
984 | ||
985 | The utility @code{make} is often needed in development environments. | |
29a2b744 | 986 | You do not have to use the @code{shell} command for this purpose in _GDBN__: |
70b88761 RP |
987 | |
988 | @table @code | |
989 | @item make @var{make-args} | |
990 | @kindex make | |
991 | @cindex calling make | |
992 | Causes _GDBN__ to execute an inferior @code{make} program with the specified | |
993 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
994 | @end table | |
4eb4cf57 | 995 | _fi__(!_BARE__) |
70b88761 | 996 | |
4eb4cf57 | 997 | @node Commands |
70b88761 RP |
998 | @chapter _GDBN__ Commands |
999 | ||
6f3ec223 RP |
1000 | You can abbreviate a _GDBN__ command to the first few letters of the command |
1001 | name, if that abbreviation is unambiguous; and you can repeat certain | |
84c2fcad | 1002 | _GDBN__ commands by typing just @key{RET}. You can also use the @key{TAB} |
6f3ec223 RP |
1003 | key to get _GDBN__ to fill out the rest of a word in a command (or to |
1004 | show you the alternatives available, if there's more than one possibility). | |
29a2b744 | 1005 | |
70b88761 | 1006 | @menu |
b80282d5 | 1007 | * Command Syntax:: Command Syntax |
6f3ec223 | 1008 | * Completion:: Command Completion |
b80282d5 | 1009 | * Help:: Getting Help |
70b88761 RP |
1010 | @end menu |
1011 | ||
4eb4cf57 | 1012 | @node Command Syntax |
70b88761 | 1013 | @section Command Syntax |
1041a570 | 1014 | |
70b88761 RP |
1015 | A _GDBN__ command is a single line of input. There is no limit on how long |
1016 | it can be. It starts with a command name, which is followed by arguments | |
1017 | whose meaning depends on the command name. For example, the command | |
1018 | @code{step} accepts an argument which is the number of times to step, | |
1019 | as in @samp{step 5}. You can also use the @code{step} command with | |
1020 | no arguments. Some command names do not allow any arguments. | |
1021 | ||
1022 | @cindex abbreviation | |
1023 | _GDBN__ command names may always be truncated if that abbreviation is | |
1024 | unambiguous. Other possible command abbreviations are listed in the | |
1025 | documentation for individual commands. In some cases, even ambiguous | |
1026 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1027 | equivalent to @code{step} even though there are other commands whose | |
1028 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1029 | arguments to the @code{help} command. |
70b88761 | 1030 | |
e251e767 | 1031 | @cindex repeating commands |
70b88761 RP |
1032 | @kindex RET |
1033 | A blank line as input to _GDBN__ (typing just @key{RET}) means to | |
1034 | repeat the previous command. Certain commands (for example, @code{run}) | |
1035 | will not repeat this way; these are commands for which unintentional | |
1036 | repetition might cause trouble and which you are unlikely to want to | |
1037 | repeat. | |
1038 | ||
1039 | The @code{list} and @code{x} commands, when you repeat them with | |
1040 | @key{RET}, construct new arguments rather than repeating | |
1041 | exactly as typed. This permits easy scanning of source or memory. | |
1042 | ||
b80282d5 RP |
1043 | _GDBN__ can also use @key{RET} in another way: to partition lengthy |
1044 | output, in a way similar to the common utility @code{more} | |
29a2b744 | 1045 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many |
b80282d5 RP |
1046 | in this situation, _GDBN__ disables command repetition after any command |
1047 | that generates this sort of display. | |
1048 | ||
70b88761 RP |
1049 | @kindex # |
1050 | @cindex comment | |
1051 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
29a2b744 | 1052 | This is useful mainly in command files (@pxref{Command Files}). |
70b88761 | 1053 | |
4eb4cf57 | 1054 | @node Completion |
6f3ec223 RP |
1055 | @section Command Completion |
1056 | ||
1057 | @cindex completion | |
1058 | @cindex word completion | |
1059 | _GDBN__ can fill in the rest of a word in a command for you, if there's | |
1060 | only one possibility; it can also show you what the valid possibilities | |
1061 | are for the next word in a command, at any time. This works for _GDBN__ | |
1062 | commands, _GDBN__ subcommands, and the names of symbols in your program. | |
1063 | ||
1064 | Press the @key{TAB} key whenever you want _GDBN__ to fill out the rest | |
1065 | of a word. If there's only one possibility, _GDBN__ will fill in the | |
1066 | word, and wait for you to finish the command (or press @key{RET} to | |
1067 | enter it). For example, if you type | |
1068 | ||
0fdc6e27 RP |
1069 | @c FIXME "@key" doesn't distinguish its argument sufficiently to permit |
1070 | @c complete accuracy in these examples; space introduced for clarity. | |
1071 | @c If texinfo enhancements make it unnecessary, it would be nice to | |
1072 | @c replace " @key" by "@key" in the following... | |
6f3ec223 | 1073 | @example |
0fdc6e27 | 1074 | (_GDBP__) info bre @key{TAB} |
6f3ec223 RP |
1075 | @end example |
1076 | ||
1077 | @noindent | |
1078 | _GDBN__ fills in the rest of the word @samp{breakpoints}, since that's | |
1079 | the only @code{info} subcommand beginning with @samp{bre}: | |
1080 | ||
1081 | @example | |
1082 | (_GDBP__) info breakpoints | |
1083 | @end example | |
1084 | ||
1085 | @noindent | |
1086 | You can either press @key{RET} at this point, to run the @code{info | |
1087 | breakpoints} command, or backspace and enter something else, if | |
1088 | @samp{breakpoints} doesn't look like the command you expected. (If you | |
1089 | were sure you wanted @code{info breakpoints} in the first place, you | |
1090 | might as well just type @key{RET} immediately after @samp{info bre}, | |
1091 | to exploit command abbreviations rather than command completion). | |
1092 | ||
1093 | If there is more than one possibility for the next word when you press | |
1094 | @key{TAB}, _GDBN__ will sound a bell. You can either supply more | |
1095 | characters and try again, or just press @key{TAB} a second time, and | |
1096 | _GDBN__ will display all the possible completions for that word. For | |
1097 | example, you might want to set a breakpoint on a subroutine whose name | |
b1385986 | 1098 | begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} _GDBN__ |
6f3ec223 RP |
1099 | just sounds the bell. Typing @key{TAB} again will display all the |
1100 | function names in your program that begin with those characters, for | |
1101 | example: | |
1102 | ||
1103 | @example | |
0fdc6e27 | 1104 | (_GDBP__) b make_ @key{TAB} |
b1385986 | 1105 | @exdent _GDBN__ sounds bell; press @key{TAB} again, to see: |
6f3ec223 RP |
1106 | make_a_section_from_file make_environ |
1107 | make_abs_section make_function_type | |
1108 | make_blockvector make_pointer_type | |
1109 | make_cleanup make_reference_type | |
1110 | make_command make_symbol_completion_list | |
b1385986 | 1111 | (GDBP__) b make_ |
6f3ec223 RP |
1112 | @end example |
1113 | ||
1114 | @noindent | |
1115 | After displaying the available possibilities, _GDBN__ copies your | |
b1385986 | 1116 | partial input (@samp{b make_} in the example) so you can finish the |
6f3ec223 RP |
1117 | command. |
1118 | ||
1119 | If you just want to see the list of alternatives in the first place, you | |
b1385986 | 1120 | can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?} |
0f153e74 RP |
1121 | means @kbd{@key{META} ?}. You can type this |
1122 | _if__(_GENERIC__||!_DOSHOST__) | |
1123 | either by holding down a | |
b1385986 | 1124 | key designated as the @key{META} shift on your keyboard (if there is |
0f153e74 RP |
1125 | one) while typing @kbd{?}, or |
1126 | _fi__(_GENERIC__||!_DOSHOST__) | |
1127 | as @key{ESC} followed by @kbd{?}. | |
6f3ec223 RP |
1128 | |
1129 | @cindex quotes in commands | |
1130 | @cindex completion of quoted strings | |
1131 | Sometimes the string you need, while logically a ``word'', may contain | |
1132 | parentheses or other characters that _GDBN__ normally excludes from its | |
1133 | notion of a word. To permit word completion to work in this situation, | |
1134 | you may enclose words in @code{'} (single quote marks) in _GDBN__ commands. | |
1135 | ||
1136 | The most likely situation where you might need this is in typing the | |
1137 | name of a C++ function. This is because C++ allows function overloading | |
1138 | (multiple definitions of the same function, distinguished by argument | |
b1385986 RP |
1139 | type). For example, when you want to set a breakpoint you may need to |
1140 | distinguish whether you mean the version of @code{name} that takes an | |
1141 | @code{int} parameter, @code{name(int)}, or the version that takes a | |
1142 | @code{float} parameter, @code{name(float)}. To use the word-completion | |
1143 | facilities in this situation, type a single quote @code{'} at the | |
1144 | beginning of the function name. This alerts _GDBN__ that it may need to | |
1145 | consider more information than usual when you press @key{TAB} or | |
1146 | @kbd{M-?} to request word completion: | |
6f3ec223 RP |
1147 | |
1148 | @example | |
0fdc6e27 RP |
1149 | (_GDBP__) b 'bubble( @key{M-?} |
1150 | bubble(double,double) bubble(int,int) | |
1151 | (_GDBP__) b 'bubble( | |
6f3ec223 RP |
1152 | @end example |
1153 | ||
0fdc6e27 RP |
1154 | In some cases, _GDBN__ can tell that completing a name will require |
1155 | quotes. When this happens, _GDBN__ will insert the quote for you (while | |
1156 | completing as much as it can) if you do not type the quote in the first | |
1157 | place: | |
1158 | ||
1159 | @example | |
1160 | (_GDBP__) b bub @key{TAB} | |
1161 | @exdent _GDBN__ alters your input line to the following, and rings a bell: | |
1162 | (_GDBP__) b 'bubble( | |
1163 | @end example | |
1164 | ||
1165 | @noindent | |
1166 | In general, _GDBN__ can tell that a quote is needed (and inserts it) if | |
1167 | you have not yet started typing the argument list when you ask for | |
1168 | completion on an overloaded symbol. | |
1169 | ||
1170 | ||
4eb4cf57 | 1171 | @node Help |
70b88761 RP |
1172 | @section Getting Help |
1173 | @cindex online documentation | |
1174 | @kindex help | |
1041a570 | 1175 | |
70b88761 | 1176 | You can always ask _GDBN__ itself for information on its commands, using the |
e251e767 | 1177 | command @code{help}. |
70b88761 RP |
1178 | |
1179 | @table @code | |
1180 | @item help | |
1181 | @itemx h | |
1182 | @kindex h | |
1183 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1184 | display a short list of named classes of commands: | |
1041a570 | 1185 | |
70b88761 RP |
1186 | @smallexample |
1187 | (_GDBP__) help | |
1188 | List of classes of commands: | |
1189 | ||
1190 | running -- Running the program | |
1191 | stack -- Examining the stack | |
1192 | data -- Examining data | |
1193 | breakpoints -- Making program stop at certain points | |
1194 | files -- Specifying and examining files | |
1195 | status -- Status inquiries | |
1196 | support -- Support facilities | |
1197 | user-defined -- User-defined commands | |
1198 | aliases -- Aliases of other commands | |
1199 | obscure -- Obscure features | |
1200 | ||
203eea5d RP |
1201 | Type "help" followed by a class name for a list of |
1202 | commands in that class. | |
1203 | Type "help" followed by command name for full | |
1204 | documentation. | |
70b88761 | 1205 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1206 | (_GDBP__) |
70b88761 RP |
1207 | @end smallexample |
1208 | ||
1209 | @item help @var{class} | |
1210 | Using one of the general help classes as an argument, you can get a | |
1211 | list of the individual commands in that class. For example, here is the | |
1212 | help display for the class @code{status}: | |
1041a570 | 1213 | |
70b88761 RP |
1214 | @smallexample |
1215 | (_GDBP__) help status | |
1216 | Status inquiries. | |
1217 | ||
1218 | List of commands: | |
1219 | ||
1220 | show -- Generic command for showing things set with "set" | |
1221 | info -- Generic command for printing status | |
1222 | ||
203eea5d RP |
1223 | Type "help" followed by command name for full |
1224 | documentation. | |
70b88761 | 1225 | Command name abbreviations are allowed if unambiguous. |
e251e767 | 1226 | (_GDBP__) |
70b88761 RP |
1227 | @end smallexample |
1228 | ||
1229 | @item help @var{command} | |
1230 | With a command name as @code{help} argument, _GDBN__ will display a | |
e251e767 | 1231 | short paragraph on how to use that command. |
70b88761 RP |
1232 | @end table |
1233 | ||
1234 | In addition to @code{help}, you can use the _GDBN__ commands @code{info} | |
1235 | and @code{show} to inquire about the state of your program, or the state | |
1236 | of _GDBN__ itself. Each command supports many topics of inquiry; this | |
1237 | manual introduces each of them in the appropriate context. The listings | |
1238 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1239 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1240 | |
1241 | @c @group | |
1242 | @table @code | |
1243 | @item info | |
1244 | @kindex info | |
1245 | @kindex i | |
1246 | This command (abbreviated @code{i}) is for describing the state of your | |
1247 | program; for example, it can list the arguments given to your program | |
1248 | (@code{info args}), the registers currently in use (@code{info | |
1041a570 | 1249 | registers}), or the breakpoints you have set (@code{info breakpoints}). |
70b88761 RP |
1250 | You can get a complete list of the @code{info} sub-commands with |
1251 | @w{@code{help info}}. | |
1252 | ||
1253 | @kindex show | |
1254 | @item show | |
1255 | In contrast, @code{show} is for describing the state of _GDBN__ itself. | |
1256 | You can change most of the things you can @code{show}, by using the | |
1257 | related command @code{set}; for example, you can control what number | |
1258 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1259 | which is currently in use with @code{show radix}. |
70b88761 RP |
1260 | |
1261 | @kindex info set | |
1262 | To display all the settable parameters and their current | |
1263 | values, you can use @code{show} with no arguments; you may also use | |
1264 | @code{info set}. Both commands produce the same display. | |
1265 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1266 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1267 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1268 | @end table | |
1269 | @c @end group | |
1270 | ||
1271 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1272 | exceptional in lacking corresponding @code{set} commands: | |
1273 | ||
1274 | @table @code | |
1275 | @kindex show version | |
3d3ab540 | 1276 | @cindex version number |
70b88761 RP |
1277 | @item show version |
1278 | Show what version of _GDBN__ is running. You should include this | |
1041a570 RP |
1279 | information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are in |
1280 | use at your site, you may occasionally want to make sure what version | |
1281 | of _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced, | |
1282 | and old ones may wither away. The version number is also announced | |
1283 | when you start _GDBN__ with no arguments. | |
70b88761 RP |
1284 | |
1285 | @kindex show copying | |
1286 | @item show copying | |
1287 | Display information about permission for copying _GDBN__. | |
1288 | ||
1289 | @kindex show warranty | |
1290 | @item show warranty | |
1291 | Display the GNU ``NO WARRANTY'' statement. | |
1292 | @end table | |
1293 | ||
4eb4cf57 | 1294 | @node Running |
70b88761 RP |
1295 | @chapter Running Programs Under _GDBN__ |
1296 | ||
1041a570 RP |
1297 | To debug a program, you must run it under _GDBN__. |
1298 | ||
70b88761 | 1299 | @menu |
b80282d5 RP |
1300 | * Compilation:: Compiling for Debugging |
1301 | * Starting:: Starting your Program | |
4eb4cf57 | 1302 | _if__(!_BARE__) |
b80282d5 RP |
1303 | * Arguments:: Your Program's Arguments |
1304 | * Environment:: Your Program's Environment | |
1305 | * Working Directory:: Your Program's Working Directory | |
1306 | * Input/Output:: Your Program's Input and Output | |
1307 | * Attach:: Debugging an Already-Running Process | |
1308 | * Kill Process:: Killing the Child Process | |
d24e0922 | 1309 | * Process Information:: Additional Process Information |
4eb4cf57 | 1310 | _fi__(!_BARE__) |
70b88761 RP |
1311 | @end menu |
1312 | ||
4eb4cf57 | 1313 | @node Compilation |
70b88761 RP |
1314 | @section Compiling for Debugging |
1315 | ||
1316 | In order to debug a program effectively, you need to generate | |
1317 | debugging information when you compile it. This debugging information | |
1318 | is stored in the object file; it describes the data type of each | |
1319 | variable or function and the correspondence between source line numbers | |
1320 | and addresses in the executable code. | |
1321 | ||
1322 | To request debugging information, specify the @samp{-g} option when you run | |
1323 | the compiler. | |
1324 | ||
1325 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1326 | options together. Using those compilers, you cannot generate optimized | |
1327 | executables containing debugging information. | |
1328 | ||
c7cb8acb RP |
1329 | _GCC__, the GNU C compiler, supports @samp{-g} with or without |
1330 | @samp{-O}, making it possible to debug optimized code. We recommend | |
1331 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1332 | You may think your program is correct, but there is no sense in pushing | |
1333 | your luck. | |
70b88761 | 1334 | |
6ca72cc6 RP |
1335 | @cindex optimized code, debugging |
1336 | @cindex debugging optimized code | |
1337 | When you debug a program compiled with @samp{-g -O}, remember that the | |
1338 | optimizer is rearranging your code; the debugger will show you what's | |
1339 | really there. Don't be too surprised when the execution path doesn't | |
1340 | exactly match your source file! An extreme example: if you define a | |
1341 | variable, but never use it, _GDBN__ will never see that | |
1342 | variable---because the compiler optimizes it out of existence. | |
1343 | ||
70b88761 RP |
1344 | Some things do not work as well with @samp{-g -O} as with just |
1345 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1346 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1347 | please report it as a bug (including a test case!). | |
1348 | ||
1349 | Older versions of the GNU C compiler permitted a variant option | |
c7cb8acb | 1350 | @w{@samp{-gg}} for debugging information. _GDBN__ no longer supports this |
70b88761 RP |
1351 | format; if your GNU C compiler has this option, do not use it. |
1352 | ||
1353 | @ignore | |
1354 | @comment As far as I know, there are no cases in which _GDBN__ will | |
1355 | @comment produce strange output in this case. (but no promises). | |
1356 | If your program includes archives made with the @code{ar} program, and | |
1357 | if the object files used as input to @code{ar} were compiled without the | |
1358 | @samp{-g} option and have names longer than 15 characters, _GDBN__ will get | |
29a2b744 | 1359 | confused reading your program's symbol table. No error message will be |
70b88761 RP |
1360 | given, but _GDBN__ may behave strangely. The reason for this problem is a |
1361 | deficiency in the Unix archive file format, which cannot represent file | |
1362 | names longer than 15 characters. | |
1363 | ||
1364 | To avoid this problem, compile the archive members with the @samp{-g} | |
1365 | option or use shorter file names. Alternatively, use a version of GNU | |
1366 | @code{ar} dated more recently than August 1989. | |
1367 | @end ignore | |
1368 | ||
4eb4cf57 | 1369 | @node Starting |
70b88761 RP |
1370 | @section Starting your Program |
1371 | @cindex starting | |
1372 | @cindex running | |
1041a570 | 1373 | |
70b88761 RP |
1374 | @table @code |
1375 | @item run | |
1376 | @itemx r | |
1377 | @kindex run | |
1041a570 RP |
1378 | Use the @code{run} command to start your program under _GDBN__. You must |
1379 | first specify the program name | |
e251e767 | 1380 | _if__(_VXWORKS__) |
7463aadd | 1381 | (except on VxWorks) |
70b88761 | 1382 | _fi__(_VXWORKS__) |
1041a570 RP |
1383 | with an argument to |
1384 | _GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the | |
1385 | @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to | |
1386 | Specify Files}). | |
1387 | ||
70b88761 RP |
1388 | @end table |
1389 | ||
4eb4cf57 | 1390 | _if__(!_BARE__) |
29a2b744 RP |
1391 | If you are running your program in an execution environment that |
1392 | supports processes, @code{run} creates an inferior process and makes | |
1393 | that process run your program. (In environments without processes, | |
1394 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
1395 | |
1396 | The execution of a program is affected by certain information it | |
1397 | receives from its superior. _GDBN__ provides ways to specify this | |
6ca72cc6 | 1398 | information, which you must do @emph{before} starting your program. (You |
29a2b744 RP |
1399 | can change it after starting your program, but such changes will only affect |
1400 | your program the next time you start it.) This information may be | |
70b88761 RP |
1401 | divided into four categories: |
1402 | ||
1403 | @table @asis | |
6ca72cc6 | 1404 | @item The @emph{arguments.} |
29a2b744 | 1405 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
1406 | @code{run} command. If a shell is available on your target, the shell |
1407 | is used to pass the arguments, so that you may use normal conventions | |
1408 | (such as wildcard expansion or variable substitution) in describing | |
1409 | the arguments. In Unix systems, you can control which shell is used | |
1410 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
1411 | Program's Arguments}. | |
70b88761 | 1412 | |
6ca72cc6 | 1413 | @item The @emph{environment.} |
70b88761 RP |
1414 | Your program normally inherits its environment from _GDBN__, but you can |
1415 | use the _GDBN__ commands @code{set environment} and @code{unset | |
1416 | environment} to change parts of the environment that will be given to | |
1041a570 | 1417 | your program. @xref{Environment, ,Your Program's Environment}. |
70b88761 | 1418 | |
6ca72cc6 | 1419 | @item The @emph{working directory.} |
70b88761 RP |
1420 | Your program inherits its working directory from _GDBN__. You can set |
1421 | _GDBN__'s working directory with the @code{cd} command in _GDBN__. | |
29a2b744 | 1422 | @xref{Working Directory, ,Your Program's Working Directory}. |
70b88761 | 1423 | |
6ca72cc6 | 1424 | @item The @emph{standard input and output.} |
70b88761 RP |
1425 | Your program normally uses the same device for standard input and |
1426 | standard output as _GDBN__ is using. You can redirect input and output | |
1427 | in the @code{run} command line, or you can use the @code{tty} command to | |
1428 | set a different device for your program. | |
1041a570 | 1429 | @xref{Input/Output, ,Your Program's Input and Output}. |
3d3ab540 RP |
1430 | |
1431 | @cindex pipes | |
29a2b744 RP |
1432 | @emph{Warning:} While input and output redirection work, you cannot use |
1433 | pipes to pass the output of the program you are debugging to another | |
3d3ab540 RP |
1434 | program; if you attempt this, _GDBN__ is likely to wind up debugging the |
1435 | wrong program. | |
70b88761 | 1436 | @end table |
4eb4cf57 | 1437 | _fi__(!_BARE__) |
70b88761 | 1438 | |
1041a570 | 1439 | When you issue the @code{run} command, your program begins to execute |
4eb4cf57 RP |
1440 | immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion |
1441 | of how to arrange for your program to stop. Once your program has | |
1442 | stopped, you may calls functions in your program, using the @code{print} | |
1443 | or @code{call} commands. @xref{Data, ,Examining Data}. | |
70b88761 | 1444 | |
29a2b744 | 1445 | If the modification time of your symbol file has changed since the |
1041a570 RP |
1446 | last time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and |
1447 | re-read it. When it does this, _GDBN__ tries to retain your current | |
1448 | breakpoints. | |
70b88761 | 1449 | |
4eb4cf57 RP |
1450 | _if__(!_BARE__) |
1451 | @node Arguments | |
70b88761 RP |
1452 | @section Your Program's Arguments |
1453 | ||
1454 | @cindex arguments (to your program) | |
1455 | The arguments to your program can be specified by the arguments of the | |
1456 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 1457 | characters and performs redirection of I/O, and thence to your program. |
70b88761 RP |
1458 | _GDBN__ uses the shell indicated by your environment variable |
1459 | @code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}. | |
1460 | ||
1461 | @code{run} with no arguments uses the same arguments used by the previous | |
1462 | @code{run}, or those set by the @code{set args} command. | |
1463 | ||
1464 | @kindex set args | |
1465 | @table @code | |
1466 | @item set args | |
1467 | Specify the arguments to be used the next time your program is run. If | |
1468 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 1469 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
1470 | using @code{set args} before the next @code{run} is the only way to run |
1471 | it again without arguments. | |
1472 | ||
1473 | @item show args | |
1474 | @kindex show args | |
1475 | Show the arguments to give your program when it is started. | |
1476 | @end table | |
1477 | ||
4eb4cf57 | 1478 | @node Environment |
70b88761 RP |
1479 | @section Your Program's Environment |
1480 | ||
1481 | @cindex environment (of your program) | |
1482 | The @dfn{environment} consists of a set of environment variables and | |
1483 | their values. Environment variables conventionally record such things as | |
1484 | your user name, your home directory, your terminal type, and your search | |
1485 | path for programs to run. Usually you set up environment variables with | |
1486 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 1487 | debugging, it can be useful to try running your program with a modified |
70b88761 RP |
1488 | environment without having to start _GDBN__ over again. |
1489 | ||
1490 | @table @code | |
1491 | @item path @var{directory} | |
1492 | @kindex path | |
1493 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1494 | (the search path for executables), for both _GDBN__ and your program. | |
1495 | You may specify several directory names, separated by @samp{:} or | |
1496 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 1497 | the front, so it will be searched sooner. |
7463aadd RP |
1498 | |
1499 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1500 | working directory at the time _GDBN__ searches the path. If you use | |
1501 | @samp{.} instead, it refers to the directory where you executed the | |
1502 | @code{path} command. _GDBN__ fills in the current path where needed in | |
1503 | the @var{directory} argument, before adding it to the search path. | |
29a2b744 | 1504 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
1505 | @c document that, since repeating it would be a no-op. |
1506 | ||
1507 | @item show paths | |
1508 | @kindex show paths | |
1509 | Display the list of search paths for executables (the @code{PATH} | |
1510 | environment variable). | |
1511 | ||
1512 | @item show environment @r{[}@var{varname}@r{]} | |
1513 | @kindex show environment | |
1514 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 1515 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
1516 | print the names and values of all environment variables to be given to |
1517 | your program. You can abbreviate @code{environment} as @code{env}. | |
1518 | ||
7463aadd | 1519 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 RP |
1520 | @kindex set environment |
1521 | Sets environment variable @var{varname} to @var{value}. The value | |
1522 | changes for your program only, not for _GDBN__ itself. @var{value} may | |
1523 | be any string; the values of environment variables are just strings, and | |
1524 | any interpretation is supplied by your program itself. The @var{value} | |
1525 | parameter is optional; if it is eliminated, the variable is set to a | |
1526 | null value. | |
29a2b744 | 1527 | @c "any string" here does not include leading, trailing |
70b88761 RP |
1528 | @c blanks. Gnu asks: does anyone care? |
1529 | ||
1530 | For example, this command: | |
1531 | ||
1532 | @example | |
1533 | set env USER = foo | |
1534 | @end example | |
1535 | ||
1536 | @noindent | |
1537 | tells a Unix program, when subsequently run, that its user is named | |
1538 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1539 | are not actually required.) | |
1540 | ||
1541 | @item unset environment @var{varname} | |
1542 | @kindex unset environment | |
1543 | Remove variable @var{varname} from the environment to be passed to your | |
1544 | program. This is different from @samp{set env @var{varname} =}; | |
1545 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 1546 | rather than assigning it an empty value. |
70b88761 RP |
1547 | @end table |
1548 | ||
4eb4cf57 | 1549 | @node Working Directory |
70b88761 RP |
1550 | @section Your Program's Working Directory |
1551 | ||
1552 | @cindex working directory (of your program) | |
1553 | Each time you start your program with @code{run}, it inherits its | |
1554 | working directory from the current working directory of _GDBN__. _GDBN__'s | |
1555 | working directory is initially whatever it inherited from its parent | |
1556 | process (typically the shell), but you can specify a new working | |
1557 | directory in _GDBN__ with the @code{cd} command. | |
1558 | ||
1559 | The _GDBN__ working directory also serves as a default for the commands | |
1041a570 RP |
1560 | that specify files for _GDBN__ to operate on. @xref{Files, ,Commands to |
1561 | Specify Files}. | |
70b88761 RP |
1562 | |
1563 | @table @code | |
1564 | @item cd @var{directory} | |
1565 | @kindex cd | |
1566 | Set _GDBN__'s working directory to @var{directory}. | |
1567 | ||
1568 | @item pwd | |
1569 | @kindex pwd | |
1570 | Print _GDBN__'s working directory. | |
1571 | @end table | |
1572 | ||
4eb4cf57 | 1573 | @node Input/Output |
70b88761 RP |
1574 | @section Your Program's Input and Output |
1575 | ||
1576 | @cindex redirection | |
1577 | @cindex i/o | |
1578 | @cindex terminal | |
1579 | By default, the program you run under _GDBN__ does input and output to | |
1580 | the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to | |
1581 | its own terminal modes to interact with you, but it records the terminal | |
1582 | modes your program was using and switches back to them when you continue | |
1583 | running your program. | |
1584 | ||
1585 | @table @code | |
1586 | @item info terminal | |
1587 | @kindex info terminal | |
1588 | Displays _GDBN__'s recorded information about the terminal modes your | |
1589 | program is using. | |
1590 | @end table | |
1591 | ||
29a2b744 | 1592 | You can redirect your program's input and/or output using shell |
70b88761 RP |
1593 | redirection with the @code{run} command. For example, |
1594 | ||
1595 | _0__@example | |
1596 | run > outfile | |
1597 | _1__@end example | |
1598 | ||
1599 | @noindent | |
29a2b744 | 1600 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
1601 | |
1602 | @kindex tty | |
1603 | @cindex controlling terminal | |
29a2b744 | 1604 | Another way to specify where your program should do input and output is |
70b88761 RP |
1605 | with the @code{tty} command. This command accepts a file name as |
1606 | argument, and causes this file to be the default for future @code{run} | |
1607 | commands. It also resets the controlling terminal for the child | |
1608 | process, for future @code{run} commands. For example, | |
1609 | ||
1610 | @example | |
1611 | tty /dev/ttyb | |
1612 | @end example | |
1613 | ||
1614 | @noindent | |
1615 | directs that processes started with subsequent @code{run} commands | |
1616 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1617 | that as their controlling terminal. | |
1618 | ||
1619 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1620 | effect on the input/output device, but not its effect on the controlling | |
1621 | terminal. | |
1622 | ||
1623 | When you use the @code{tty} command or redirect input in the @code{run} | |
1624 | command, only the input @emph{for your program} is affected. The input | |
1625 | for _GDBN__ still comes from your terminal. | |
1626 | ||
4eb4cf57 | 1627 | @node Attach |
70b88761 RP |
1628 | @section Debugging an Already-Running Process |
1629 | @kindex attach | |
1630 | @cindex attach | |
1631 | ||
1632 | @table @code | |
1633 | @item attach @var{process-id} | |
1634 | This command | |
1635 | attaches to a running process---one that was started outside _GDBN__. | |
1636 | (@code{info files} will show your active targets.) The command takes as | |
1637 | argument a process ID. The usual way to find out the process-id of | |
1638 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
e251e767 | 1639 | shell command. |
70b88761 RP |
1640 | |
1641 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1642 | executing the command. | |
1643 | @end table | |
1644 | ||
1645 | To use @code{attach}, you must be debugging in an environment which | |
1646 | supports processes. You must also have permission to send the process a | |
1647 | signal, and it must have the same effective user ID as the _GDBN__ | |
1648 | process. | |
1649 | ||
1650 | When using @code{attach}, you should first use the @code{file} command | |
1651 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 1652 | @xref{Files, ,Commands to Specify Files}. |
70b88761 RP |
1653 | |
1654 | The first thing _GDBN__ does after arranging to debug the specified | |
1655 | process is to stop it. You can examine and modify an attached process | |
1656 | with all the _GDBN__ commands that are ordinarily available when you start | |
1657 | processes with @code{run}. You can insert breakpoints; you can step and | |
1658 | continue; you can modify storage. If you would rather the process | |
1659 | continue running, you may use the @code{continue} command after | |
1660 | attaching _GDBN__ to the process. | |
1661 | ||
1662 | @table @code | |
1663 | @item detach | |
1664 | @kindex detach | |
1665 | When you have finished debugging the attached process, you can use the | |
1666 | @code{detach} command to release it from _GDBN__'s control. Detaching | |
1667 | the process continues its execution. After the @code{detach} command, | |
1668 | that process and _GDBN__ become completely independent once more, and you | |
1669 | are ready to @code{attach} another process or start one with @code{run}. | |
1670 | @code{detach} will not repeat if you press @key{RET} again after | |
1671 | executing the command. | |
1672 | @end table | |
1673 | ||
1674 | If you exit _GDBN__ or use the @code{run} command while you have an attached | |
1675 | process, you kill that process. By default, you will be asked for | |
1676 | confirmation if you try to do either of these things; you can control | |
1677 | whether or not you need to confirm by using the @code{set confirm} command | |
29a2b744 | 1678 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). |
70b88761 | 1679 | |
4eb4cf57 | 1680 | @node Kill Process |
70b88761 RP |
1681 | @c @group |
1682 | @section Killing the Child Process | |
1683 | ||
1684 | @table @code | |
1685 | @item kill | |
1686 | @kindex kill | |
1687 | Kill the child process in which your program is running under _GDBN__. | |
1688 | @end table | |
1689 | ||
1690 | This command is useful if you wish to debug a core dump instead of a | |
1691 | running process. _GDBN__ ignores any core dump file while your program | |
1692 | is running. | |
1693 | @c @end group | |
1694 | ||
29a2b744 | 1695 | On some operating systems, a program cannot be executed outside _GDBN__ |
70b88761 | 1696 | while you have breakpoints set on it inside _GDBN__. You can use the |
29a2b744 | 1697 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
1698 | outside the debugger. |
1699 | ||
1700 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 1701 | relink your program, since on many systems it is impossible to modify an |
70b88761 RP |
1702 | executable file while it is running in a process. In this case, when you |
1703 | next type @code{run}, _GDBN__ will notice that the file has changed, and | |
1704 | will re-read the symbol table (while trying to preserve your current | |
1705 | breakpoint settings). | |
1706 | ||
4eb4cf57 | 1707 | @node Process Information |
d24e0922 RP |
1708 | @section Additional Process Information |
1709 | ||
1710 | @kindex /proc | |
1711 | @cindex process image | |
1712 | Some operating systems provide a facility called @samp{/proc} that can | |
cc9bc574 RP |
1713 | be used to examine the image of a running process using file-system |
1714 | subroutines. If _GDBN__ is configured for an operating system with this | |
1715 | facility, the command @code{info proc} is available to report on several | |
1716 | kinds of information about the process running your program. | |
d24e0922 RP |
1717 | |
1718 | @table @code | |
1719 | @item info proc | |
1720 | @kindex info proc | |
1721 | Summarize available information about the process. | |
1722 | ||
1723 | @item info proc mappings | |
1724 | @kindex info proc mappings | |
1725 | Report on the address ranges accessible in the program, with information | |
1726 | on whether your program may read, write, or execute each range. | |
1727 | ||
1728 | @item info proc times | |
1729 | @kindex info proc times | |
1730 | Starting time, user CPU time, and system CPU time for your program and | |
1731 | its children. | |
1732 | ||
1733 | @item info proc id | |
1734 | @kindex info proc id | |
1735 | Report on the process ID's related to your program: its own process id, | |
1736 | the id of its parent, the process group id, and the session id. | |
1737 | ||
1738 | @item info proc status | |
1739 | @kindex info proc status | |
1740 | General information on the state of the process. If the process is | |
1741 | stopped, this report includes the reason for stopping, and any signal | |
1742 | received. | |
cc9bc574 RP |
1743 | |
1744 | @item info proc all | |
1745 | Show all the above information about the process. | |
d24e0922 | 1746 | @end table |
4eb4cf57 | 1747 | _fi__(!_BARE__) |
d24e0922 | 1748 | |
4eb4cf57 | 1749 | @node Stopping |
70b88761 RP |
1750 | @chapter Stopping and Continuing |
1751 | ||
1752 | The principal purpose of using a debugger is so that you can stop your | |
29a2b744 | 1753 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
1754 | trouble, you can investigate and find out why. |
1755 | ||
1756 | Inside _GDBN__, your program may stop for any of several reasons, such | |
1757 | as a signal, a breakpoint, or reaching a new line after a _GDBN__ | |
1758 | command such as @code{step}. You may then examine and change | |
1759 | variables, set new breakpoints or remove old ones, and then continue | |
1760 | execution. Usually, the messages shown by _GDBN__ provide ample | |
1761 | explanation of the status of your program---but you can also explicitly | |
1762 | request this information at any time. | |
1763 | ||
1764 | @table @code | |
1765 | @item info program | |
1766 | @kindex info program | |
1767 | Display information about the status of your program: whether it is | |
1768 | running or not, what process it is, and why it stopped. | |
1769 | @end table | |
1770 | ||
1771 | @menu | |
0f153e74 | 1772 | _if__(!_CONLY__) |
b80282d5 | 1773 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions |
0f153e74 RP |
1774 | _fi__(!_CONLY__) |
1775 | _if__(_CONLY__) | |
1776 | * Breakpoints:: Breakpoints and Watchpoints | |
1777 | _fi__(_CONLY__) | |
b80282d5 | 1778 | * Continuing and Stepping:: Resuming Execution |
4eb4cf57 | 1779 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 1780 | * Signals:: Signals |
4eb4cf57 | 1781 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
1782 | @end menu |
1783 | ||
4eb4cf57 | 1784 | @node Breakpoints |
0f153e74 | 1785 | _if__(!_CONLY__) |
70b88761 | 1786 | @section Breakpoints, Watchpoints, and Exceptions |
0f153e74 RP |
1787 | _fi__(!_CONLY__) |
1788 | _if__(_CONLY__) | |
1789 | @section Breakpoints and Watchpoints | |
1790 | _fi__(_CONLY__) | |
70b88761 RP |
1791 | |
1792 | @cindex breakpoints | |
1793 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 1794 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 1795 | conditions to control in finer detail whether your program will stop. |
70b88761 | 1796 | You can set breakpoints with the @code{break} command and its variants |
29a2b744 RP |
1797 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where |
1798 | your program should stop by line number, function name or exact address | |
0f153e74 RP |
1799 | in the program. |
1800 | _if__(!_CONLY__) | |
1801 | In languages with exception handling (such as GNU C++), you can also set | |
1802 | breakpoints where an exception is raised (@pxref{Exception Handling, | |
1803 | ,Breakpoints and Exceptions}). | |
1804 | _fi__(!_CONLY__) | |
70b88761 RP |
1805 | |
1806 | @cindex watchpoints | |
6ca72cc6 RP |
1807 | @cindex memory tracing |
1808 | @cindex breakpoint on memory address | |
1809 | @cindex breakpoint on variable modification | |
29a2b744 RP |
1810 | A @dfn{watchpoint} is a special breakpoint that stops your program |
1811 | when the value of an expression changes. You must use a different | |
1812 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
1813 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
1814 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1041a570 | 1815 | and watchpoints using the same commands. |
70b88761 | 1816 | |
6ca72cc6 RP |
1817 | @cindex breakpoint numbers |
1818 | @cindex numbers for breakpoints | |
1819 | _GDBN__ assigns a number to each breakpoint or watchpoint when you | |
1820 | create it; these numbers are successive integers starting with one. In | |
1821 | many of the commands for controlling various features of breakpoints you | |
1822 | use the breakpoint number to say which breakpoint you want to change. | |
1823 | Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 1824 | no effect on your program until you enable it again. |
70b88761 RP |
1825 | |
1826 | @menu | |
b80282d5 RP |
1827 | * Set Breaks:: Setting Breakpoints |
1828 | * Set Watchpoints:: Setting Watchpoints | |
1829 | * Exception Handling:: Breakpoints and Exceptions | |
1830 | * Delete Breaks:: Deleting Breakpoints | |
1831 | * Disabling:: Disabling Breakpoints | |
1832 | * Conditions:: Break Conditions | |
1833 | * Break Commands:: Breakpoint Command Lists | |
1834 | * Breakpoint Menus:: Breakpoint Menus | |
e251e767 | 1835 | * Error in Breakpoints:: |
70b88761 RP |
1836 | @end menu |
1837 | ||
4eb4cf57 | 1838 | @node Set Breaks |
70b88761 RP |
1839 | @subsection Setting Breakpoints |
1840 | ||
4906534f RP |
1841 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
1842 | @c consider in particular declaration with/without initialization. | |
1843 | @c | |
1844 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1845 | ||
70b88761 RP |
1846 | @kindex break |
1847 | @kindex b | |
6ca72cc6 RP |
1848 | @kindex $bpnum |
1849 | @cindex latest breakpoint | |
1850 | Breakpoints are set with the @code{break} command (abbreviated | |
1851 | @code{b}). The debugger convenience variable @samp{$bpnum} records the | |
1852 | number of the beakpoint you've set most recently; see @ref{Convenience | |
d24e0922 | 1853 | Vars,, Convenience Variables}, for a discussion of what you can do with |
6ca72cc6 | 1854 | convenience variables. |
70b88761 RP |
1855 | |
1856 | You have several ways to say where the breakpoint should go. | |
1857 | ||
1858 | @table @code | |
1859 | @item break @var{function} | |
0f153e74 RP |
1860 | Set a breakpoint at entry to function @var{function}. |
1861 | _if__(!_CONLY__) | |
1862 | When using source languages that permit overloading of symbols, such as | |
1863 | C++, @var{function} may refer to more than one possible place to break. | |
70b88761 | 1864 | @xref{Breakpoint Menus}, for a discussion of that situation. |
0f153e74 | 1865 | _fi__(!_CONLY__) |
70b88761 RP |
1866 | |
1867 | @item break +@var{offset} | |
1868 | @itemx break -@var{offset} | |
1869 | Set a breakpoint some number of lines forward or back from the position | |
1870 | at which execution stopped in the currently selected frame. | |
1871 | ||
1872 | @item break @var{linenum} | |
1873 | Set a breakpoint at line @var{linenum} in the current source file. | |
1874 | That file is the last file whose source text was printed. This | |
29a2b744 | 1875 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
1876 | code on that line. |
1877 | ||
1878 | @item break @var{filename}:@var{linenum} | |
1879 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1880 | ||
1881 | @item break @var{filename}:@var{function} | |
1882 | Set a breakpoint at entry to function @var{function} found in file | |
1883 | @var{filename}. Specifying a file name as well as a function name is | |
1884 | superfluous except when multiple files contain similarly named | |
1885 | functions. | |
1886 | ||
1887 | @item break *@var{address} | |
1888 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 1889 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
1890 | information or source files. |
1891 | ||
1892 | @item break | |
29a2b744 RP |
1893 | When called without any arguments, @code{break} sets a breakpoint at |
1894 | the next instruction to be executed in the selected stack frame | |
1895 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
1896 | innermost, this will cause your program to stop as soon as control | |
1897 | returns to that frame. This is similar to the effect of a | |
1898 | @code{finish} command in the frame inside the selected frame---except | |
1899 | that @code{finish} does not leave an active breakpoint. If you use | |
1041a570 RP |
1900 | @code{break} without an argument in the innermost frame, _GDBN__ will stop |
1901 | the next time it reaches the current location; this may be useful | |
1902 | inside loops. | |
70b88761 RP |
1903 | |
1904 | _GDBN__ normally ignores breakpoints when it resumes execution, until at | |
1905 | least one instruction has been executed. If it did not do this, you | |
1906 | would be unable to proceed past a breakpoint without first disabling the | |
1907 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 1908 | existed when your program stopped. |
70b88761 RP |
1909 | |
1910 | @item break @dots{} if @var{cond} | |
1911 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1912 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 1913 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
1914 | @samp{@dots{}} stands for one of the possible arguments described |
1915 | above (or no argument) specifying where to break. @xref{Conditions, | |
1916 | ,Break Conditions}, for more information on breakpoint conditions. | |
70b88761 RP |
1917 | |
1918 | @item tbreak @var{args} | |
1919 | @kindex tbreak | |
1920 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1921 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 RP |
1922 | way, but the breakpoint is automatically disabled after the first time your |
1923 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
70b88761 RP |
1924 | |
1925 | @item rbreak @var{regex} | |
1926 | @kindex rbreak | |
1927 | @cindex regular expression | |
4906534f | 1928 | @c FIXME what kind of regexp? |
70b88761 | 1929 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 1930 | @var{regex}. This command |
70b88761 RP |
1931 | sets an unconditional breakpoint on all matches, printing a list of all |
1932 | breakpoints it set. Once these breakpoints are set, they are treated | |
1933 | just like the breakpoints set with the @code{break} command. They can | |
1934 | be deleted, disabled, made conditional, etc., in the standard ways. | |
1935 | ||
0f153e74 | 1936 | _if__(!_CONLY__) |
b80282d5 RP |
1937 | When debugging C++ programs, @code{rbreak} is useful for setting |
1938 | breakpoints on overloaded functions that are not members of any special | |
1939 | classes. | |
0f153e74 | 1940 | _fi__(!_CONLY__) |
b80282d5 | 1941 | |
70b88761 | 1942 | @kindex info breakpoints |
c338a2fd | 1943 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 | 1944 | @item info breakpoints @r{[}@var{n}@r{]} |
6ca72cc6 RP |
1945 | @itemx info break @r{[}@var{n}@r{]} |
1946 | @itemx info watchpoints @r{[}@var{n}@r{]} | |
1947 | Print a table of all breakpoints and watchpoints set and not | |
1948 | deleted, with the following columns for each breakpoint: | |
1949 | ||
1950 | @table @emph | |
1951 | @item Breakpoint Numbers | |
1952 | @item Type | |
1953 | Breakpoint or watchpoint. | |
1954 | @item Disposition | |
1955 | Whether the breakpoint is marked to be disabled or deleted when hit. | |
1956 | @item Enabled or Disabled | |
d24e0922 | 1957 | Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints |
6ca72cc6 RP |
1958 | that are not enabled. |
1959 | @item Address | |
1960 | Where the breakpoint is in your program, as a memory address | |
1961 | @item What | |
1962 | Where the breakpoint is in the source for your program, as a file and | |
1963 | line number. | |
1964 | @end table | |
1965 | ||
1966 | @noindent | |
1967 | Breakpoint commands, if any, are listed after the line for the | |
1968 | corresponding breakpoint. | |
1969 | ||
1970 | @noindent | |
1971 | @code{info break} with a breakpoint | |
29a2b744 RP |
1972 | number @var{n} as argument lists only that breakpoint. The |
1973 | convenience variable @code{$_} and the default examining-address for | |
1974 | the @code{x} command are set to the address of the last breakpoint | |
6ca72cc6 | 1975 | listed (@pxref{Memory, ,Examining Memory}). |
1041a570 | 1976 | @end table |
70b88761 | 1977 | |
1041a570 RP |
1978 | _GDBN__ allows you to set any number of breakpoints at the same place in |
1979 | your program. There is nothing silly or meaningless about this. When | |
1980 | the breakpoints are conditional, this is even useful | |
29a2b744 | 1981 | (@pxref{Conditions, ,Break Conditions}). |
70b88761 | 1982 | |
6ca72cc6 RP |
1983 | @cindex negative breakpoint numbers |
1984 | @cindex internal _GDBN__ breakpoints | |
1985 | _GDBN__ itself sometimes sets breakpoints in your program for special | |
1986 | purposes, such as proper handling of @code{longjmp} (in C programs). | |
1987 | These internal breakpoints are assigned negative numbers, starting with | |
5a2c1d85 | 1988 | @code{-1}; @samp{info breakpoints} does not display them. |
d48da190 | 1989 | |
5a2c1d85 RP |
1990 | You can see these breakpoints with the _GDBN__ maintenance command |
1991 | @samp{maint info breakpoints}. | |
6ca72cc6 RP |
1992 | |
1993 | @table @code | |
d48da190 RP |
1994 | @kindex maint info breakpoints |
1995 | @item maint info breakpoints | |
6ca72cc6 RP |
1996 | Using the same format as @samp{info breakpoints}, display both the |
1997 | breakpoints you've set explicitly, and those _GDBN__ is using for | |
1998 | internal purposes. Internal breakpoints are shown with negative | |
1999 | breakpoint numbers. The type column identifies what kind of breakpoint | |
2000 | is shown: | |
2001 | ||
2002 | @table @code | |
2003 | @item breakpoint | |
2004 | Normal, explicitly set breakpoint. | |
2005 | ||
2006 | @item watchpoint | |
2007 | Normal, explicitly set watchpoint. | |
2008 | ||
2009 | @item longjmp | |
2010 | Internal breakpoint, used to handle correctly stepping through | |
2011 | @code{longjmp} calls. | |
2012 | ||
2013 | @item longjmp resume | |
2014 | Internal breakpoint at the target of a @code{longjmp}. | |
2015 | ||
2016 | @item until | |
2017 | Temporary internal breakpoint used by the _GDBN__ @code{until} command. | |
2018 | ||
2019 | @item finish | |
2020 | Temporary internal breakpoint used by the _GDBN__ @code{finish} command. | |
2021 | @end table | |
2022 | ||
2023 | @end table | |
2024 | ||
2025 | ||
4eb4cf57 | 2026 | @node Set Watchpoints |
70b88761 RP |
2027 | @subsection Setting Watchpoints |
2028 | @cindex setting watchpoints | |
1041a570 | 2029 | |
70b88761 | 2030 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 2031 | expression changes, without having to predict a particular place |
70b88761 RP |
2032 | where this may happen. |
2033 | ||
2034 | Watchpoints currently execute two orders of magnitude more slowly than | |
2035 | other breakpoints, but this can well be worth it to catch errors where | |
2036 | you have no clue what part of your program is the culprit. Some | |
2037 | processors provide special hardware to support watchpoint evaluation; future | |
2038 | releases of _GDBN__ will use such hardware if it is available. | |
2039 | ||
2040 | @table @code | |
e251e767 | 2041 | @kindex watch |
70b88761 RP |
2042 | @item watch @var{expr} |
2043 | Set a watchpoint for an expression. | |
2044 | ||
2045 | @kindex info watchpoints | |
2046 | @item info watchpoints | |
6ca72cc6 RP |
2047 | This command prints a list of watchpoints and breakpoints; it is the |
2048 | same as @code{info break}. | |
70b88761 RP |
2049 | @end table |
2050 | ||
4eb4cf57 | 2051 | @node Exception Handling |
70b88761 RP |
2052 | @subsection Breakpoints and Exceptions |
2053 | @cindex exception handlers | |
2054 | ||
b80282d5 | 2055 | Some languages, such as GNU C++, implement exception handling. You can |
29a2b744 RP |
2056 | use _GDBN__ to examine what caused your program to raise an exception, |
2057 | and to list the exceptions your program is prepared to handle at a | |
70b88761 RP |
2058 | given point in time. |
2059 | ||
2060 | @table @code | |
2061 | @item catch @var{exceptions} | |
2062 | @kindex catch | |
2063 | You can set breakpoints at active exception handlers by using the | |
2064 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
2065 | to catch. | |
2066 | @end table | |
2067 | ||
29a2b744 RP |
2068 | You can use @code{info catch} to list active exception handlers. |
2069 | @xref{Frame Info, ,Information About a Frame}. | |
70b88761 RP |
2070 | |
2071 | There are currently some limitations to exception handling in _GDBN__. | |
2072 | These will be corrected in a future release. | |
2073 | ||
2074 | @itemize @bullet | |
2075 | @item | |
2076 | If you call a function interactively, _GDBN__ normally returns | |
2077 | control to you when the function has finished executing. If the call | |
2078 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 2079 | returns control to you and cause your program to simply continue |
70b88761 RP |
2080 | running until it hits a breakpoint, catches a signal that _GDBN__ is |
2081 | listening for, or exits. | |
2082 | @item | |
2083 | You cannot raise an exception interactively. | |
2084 | @item | |
2085 | You cannot interactively install an exception handler. | |
2086 | @end itemize | |
2087 | ||
2088 | @cindex raise exceptions | |
2089 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 2090 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
2091 | stop @emph{before} the exception handler is called, since that way you |
2092 | can see the stack before any unwinding takes place. If you set a | |
2093 | breakpoint in an exception handler instead, it may not be easy to find | |
2094 | out where the exception was raised. | |
2095 | ||
2096 | To stop just before an exception handler is called, you need some | |
b80282d5 | 2097 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
2098 | raised by calling a library function named @code{__raise_exception} |
2099 | which has the following ANSI C interface: | |
2100 | ||
2101 | @example | |
b80282d5 | 2102 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
2103 | ID is the exception identifier. */ |
2104 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
2105 | @end example | |
2106 | ||
2107 | @noindent | |
2108 | To make the debugger catch all exceptions before any stack | |
2109 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
29a2b744 | 2110 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). |
70b88761 | 2111 | |
29a2b744 RP |
2112 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) |
2113 | that depends on the value of @var{id}, you can stop your program when | |
2114 | a specific exception is raised. You can use multiple conditional | |
2115 | breakpoints to stop your program when any of a number of exceptions are | |
2116 | raised. | |
70b88761 | 2117 | |
4eb4cf57 | 2118 | @node Delete Breaks |
70b88761 RP |
2119 | @subsection Deleting Breakpoints |
2120 | ||
2121 | @cindex clearing breakpoints, watchpoints | |
2122 | @cindex deleting breakpoints, watchpoints | |
2123 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 2124 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
2125 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
2126 | deleted no longer exists; it is forgotten. | |
2127 | ||
2128 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 2129 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
2130 | delete individual breakpoints or watchpoints by specifying their |
2131 | breakpoint numbers. | |
2132 | ||
2133 | It is not necessary to delete a breakpoint to proceed past it. _GDBN__ | |
2134 | automatically ignores breakpoints on the first instruction to be executed | |
2135 | when you continue execution without changing the execution address. | |
2136 | ||
2137 | @table @code | |
2138 | @item clear | |
2139 | @kindex clear | |
2140 | Delete any breakpoints at the next instruction to be executed in the | |
29a2b744 RP |
2141 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When |
2142 | the innermost frame is selected, this is a good way to delete a | |
2143 | breakpoint where your program just stopped. | |
70b88761 RP |
2144 | |
2145 | @item clear @var{function} | |
2146 | @itemx clear @var{filename}:@var{function} | |
2147 | Delete any breakpoints set at entry to the function @var{function}. | |
2148 | ||
2149 | @item clear @var{linenum} | |
2150 | @itemx clear @var{filename}:@var{linenum} | |
2151 | Delete any breakpoints set at or within the code of the specified line. | |
2152 | ||
2153 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2154 | @cindex delete breakpoints | |
2155 | @kindex delete | |
2156 | @kindex d | |
2157 | Delete the breakpoints or watchpoints of the numbers specified as | |
2158 | arguments. If no argument is specified, delete all breakpoints (_GDBN__ | |
1041a570 | 2159 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
2160 | can abbreviate this command as @code{d}. |
2161 | @end table | |
2162 | ||
4eb4cf57 | 2163 | @node Disabling |
70b88761 RP |
2164 | @subsection Disabling Breakpoints |
2165 | ||
2166 | @cindex disabled breakpoints | |
2167 | @cindex enabled breakpoints | |
2168 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
2169 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
2170 | been deleted, but remembers the information on the breakpoint so that | |
2171 | you can @dfn{enable} it again later. | |
2172 | ||
2173 | You disable and enable breakpoints and watchpoints with the | |
2174 | @code{enable} and @code{disable} commands, optionally specifying one or | |
2175 | more breakpoint numbers as arguments. Use @code{info break} or | |
2176 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 2177 | do not know which numbers to use. |
70b88761 RP |
2178 | |
2179 | A breakpoint or watchpoint can have any of four different states of | |
2180 | enablement: | |
2181 | ||
2182 | @itemize @bullet | |
2183 | @item | |
29a2b744 | 2184 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2185 | with the @code{break} command starts out in this state. |
2186 | @item | |
29a2b744 | 2187 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2188 | @item |
29a2b744 | 2189 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2190 | when it does so it will become disabled. A breakpoint set |
2191 | with the @code{tbreak} command starts out in this state. | |
2192 | @item | |
29a2b744 | 2193 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2194 | immediately after it does so it will be deleted permanently. |
2195 | @end itemize | |
2196 | ||
2197 | You can use the following commands to enable or disable breakpoints and | |
2198 | watchpoints: | |
2199 | ||
2200 | @table @code | |
2201 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2202 | @kindex disable breakpoints | |
2203 | @kindex disable | |
2204 | @kindex dis | |
2205 | Disable the specified breakpoints---or all breakpoints, if none are | |
2206 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2207 | options such as ignore-counts, conditions and commands are remembered in | |
2208 | case the breakpoint is enabled again later. You may abbreviate | |
2209 | @code{disable} as @code{dis}. | |
2210 | ||
2211 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2212 | @kindex enable breakpoints | |
2213 | @kindex enable | |
2214 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2215 | become effective once again in stopping your program. |
70b88761 RP |
2216 | |
2217 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2218 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2219 | again the next time it stops your program. |
70b88761 RP |
2220 | |
2221 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2222 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2223 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2224 | @end table |
2225 | ||
29a2b744 RP |
2226 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
2227 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2228 | enabled; subsequently, they become disabled or enabled only when you | |
2229 | use one of the commands above. (The command @code{until} can set and | |
2230 | delete a breakpoint of its own, but it will not change the state of | |
98fe4566 | 2231 | your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.) |
70b88761 | 2232 | |
4eb4cf57 | 2233 | @node Conditions |
70b88761 RP |
2234 | @subsection Break Conditions |
2235 | @cindex conditional breakpoints | |
2236 | @cindex breakpoint conditions | |
2237 | ||
4906534f RP |
2238 | @c FIXME what is scope of break condition expr? Context where wanted? |
2239 | @c in particular for a watchpoint? | |
29a2b744 | 2240 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2241 | specified place. You can also specify a @dfn{condition} for a |
2242 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2243 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2244 | a condition evaluates the expression each time your program reaches it, | |
2245 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2246 | |
2247 | This is the converse of using assertions for program validation; in that | |
2248 | situation, you want to stop when the assertion is violated---that is, | |
2249 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2250 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2251 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2252 | |
2253 | Conditions are also accepted for watchpoints; you may not need them, | |
2254 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2255 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2256 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2257 | one. |
70b88761 | 2258 | |
29a2b744 | 2259 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2260 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2261 | that log program progress, or to use your own print functions to |
2262 | format special data structures. The effects are completely predictable | |
2263 | unless there is another enabled breakpoint at the same address. (In | |
2264 | that case, _GDBN__ might see the other breakpoint first and stop your | |
2265 | program without checking the condition of this one.) Note that | |
2266 | breakpoint commands are usually more convenient and flexible for the | |
2267 | purpose of performing side effects when a breakpoint is reached | |
2268 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
70b88761 RP |
2269 | |
2270 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 RP |
2271 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
2272 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2273 | with the @code{condition} command. The @code{watch} command does not | |
2274 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2275 | impose a further condition on a watchpoint. | |
70b88761 | 2276 | |
e251e767 RP |
2277 | @table @code |
2278 | @item condition @var{bnum} @var{expression} | |
2279 | @kindex condition | |
70b88761 RP |
2280 | Specify @var{expression} as the break condition for breakpoint or |
2281 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2282 | your program only if the value of @var{expression} is true (nonzero, in |
70b88761 RP |
2283 | C). When you use @code{condition}, _GDBN__ checks @var{expression} |
2284 | immediately for syntactic correctness, and to determine whether symbols | |
1041a570 | 2285 | in it have referents in the context of your breakpoint. |
29a2b744 | 2286 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f RP |
2287 | @c about watchpoints? |
2288 | _GDBN__ does | |
70b88761 | 2289 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 2290 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
2291 | |
2292 | @item condition @var{bnum} | |
2293 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2294 | an ordinary unconditional breakpoint. | |
2295 | @end table | |
2296 | ||
2297 | @cindex ignore count (of breakpoint) | |
2298 | A special case of a breakpoint condition is to stop only when the | |
2299 | breakpoint has been reached a certain number of times. This is so | |
2300 | useful that there is a special way to do it, using the @dfn{ignore | |
2301 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2302 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 2303 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
2304 | ignore count is positive, then instead of stopping, it just decrements |
2305 | the ignore count by one and continues. As a result, if the ignore count | |
2306 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2307 | is reached. | |
2308 | ||
2309 | @table @code | |
2310 | @item ignore @var{bnum} @var{count} | |
2311 | @kindex ignore | |
2312 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2313 | The next @var{count} times the breakpoint is reached, your program's | |
2314 | execution will not stop; other than to decrement the ignore count, _GDBN__ | |
2315 | takes no action. | |
2316 | ||
2317 | To make the breakpoint stop the next time it is reached, specify | |
2318 | a count of zero. | |
2319 | ||
2320 | @item continue @var{count} | |
2321 | @itemx c @var{count} | |
2322 | @itemx fg @var{count} | |
2323 | @kindex continue @var{count} | |
29a2b744 RP |
2324 | Continue execution of your program, setting the ignore count of the |
2325 | breakpoint where your program stopped to @var{count} minus one. | |
2326 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
2327 | @var{count}'th time it is reached. |
2328 | ||
29a2b744 | 2329 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
2330 | due to a breakpoint. At other times, the argument to @code{continue} is |
2331 | ignored. | |
2332 | ||
2333 | The synonym @code{fg} is provided purely for convenience, and has | |
2334 | exactly the same behavior as other forms of the command. | |
2335 | @end table | |
2336 | ||
2337 | If a breakpoint has a positive ignore count and a condition, the condition | |
2338 | is not checked. Once the ignore count reaches zero, the condition will | |
2339 | be checked. | |
2340 | ||
29a2b744 | 2341 | You could achieve the effect of the ignore count with a condition such |
1041a570 RP |
2342 | as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience variable that |
2343 | is decremented each time. @xref{Convenience Vars, ,Convenience | |
2344 | Variables}. | |
70b88761 | 2345 | |
4eb4cf57 | 2346 | @node Break Commands |
70b88761 RP |
2347 | @subsection Breakpoint Command Lists |
2348 | ||
2349 | @cindex breakpoint commands | |
2350 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 2351 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
2352 | might want to print the values of certain expressions, or enable other |
2353 | breakpoints. | |
2354 | ||
2355 | @table @code | |
2356 | @item commands @r{[}@var{bnum}@r{]} | |
2357 | @itemx @dots{} @var{command-list} @dots{} | |
2358 | @itemx end | |
2359 | @kindex commands | |
2360 | @kindex end | |
2361 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2362 | themselves appear on the following lines. Type a line containing just | |
2363 | @code{end} to terminate the commands. | |
2364 | ||
203eea5d RP |
2365 | To remove all commands from a breakpoint, type @code{commands} and |
2366 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
2367 | |
2368 | With no @var{bnum} argument, @code{commands} refers to the last | |
2369 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2370 | encountered). | |
2371 | @end table | |
2372 | ||
2373 | Pressing @key{RET} as a means of repeating the last _GDBN__ command is | |
2374 | disabled within a @var{command-list}. | |
2375 | ||
29a2b744 | 2376 | You can use breakpoint commands to start your program up again. Simply |
70b88761 RP |
2377 | use the @code{continue} command, or @code{step}, or any other command |
2378 | that resumes execution. Subsequent commands in the command list are | |
2379 | ignored. | |
2380 | ||
2381 | @kindex silent | |
2382 | If the first command specified is @code{silent}, the usual message about | |
2383 | stopping at a breakpoint is not printed. This may be desirable for | |
2384 | breakpoints that are to print a specific message and then continue. | |
2385 | If the remaining commands too print nothing, you will see no sign that | |
e251e767 | 2386 | the breakpoint was reached at all. @code{silent} is meaningful only |
70b88761 RP |
2387 | at the beginning of a breakpoint command list. |
2388 | ||
29a2b744 RP |
2389 | The commands @code{echo} and @code{output} that allow you to print |
2390 | precisely controlled output are often useful in silent breakpoints. | |
2391 | @xref{Output, ,Commands for Controlled Output}. | |
70b88761 RP |
2392 | |
2393 | For example, here is how you could use breakpoint commands to print the | |
2394 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2395 | ||
2396 | _0__@example | |
2397 | break foo if x>0 | |
2398 | commands | |
2399 | silent | |
2400 | echo x is\040 | |
2401 | output x | |
2402 | echo \n | |
2403 | cont | |
2404 | end | |
2405 | _1__@end example | |
2406 | ||
2407 | One application for breakpoint commands is to compensate for one bug so | |
2408 | you can test for another. Put a breakpoint just after the erroneous line | |
2409 | of code, give it a condition to detect the case in which something | |
2410 | erroneous has been done, and give it commands to assign correct values | |
2411 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 2412 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
2413 | command so that no output is produced. Here is an example: |
2414 | ||
2415 | @example | |
2416 | break 403 | |
2417 | commands | |
2418 | silent | |
2419 | set x = y + 4 | |
2420 | cont | |
2421 | end | |
2422 | @end example | |
2423 | ||
2424 | @cindex lost output | |
2425 | One deficiency in the operation of automatically continuing breakpoints | |
2426 | under Unix appears when your program uses raw mode for the terminal. | |
2427 | _GDBN__ switches back to its own terminal modes (not raw) before executing | |
2428 | commands, and then must switch back to raw mode when your program is | |
e251e767 | 2429 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
2430 | @c FIXME: revisit below when GNU sys avail. |
2431 | @c In the GNU system, this will be fixed by changing the behavior of | |
2432 | @c terminal modes. | |
2433 | ||
2434 | Under Unix, you can get around this problem by writing actions into | |
2435 | the breakpoint condition rather than in commands. For example | |
2436 | ||
2437 | @example | |
2438 | condition 5 (x = y + 4), 0 | |
2439 | @end example | |
2440 | ||
2441 | @noindent | |
1041a570 RP |
2442 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
2443 | change @code{x} as needed, then always have the value zero so your | |
2444 | program will not stop. No input is lost here, because _GDBN__ evaluates | |
2445 | break conditions without changing the terminal modes. When you want | |
2446 | to have nontrivial conditions for performing the side effects, the | |
2447 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 | 2448 | |
4eb4cf57 | 2449 | @node Breakpoint Menus |
70b88761 | 2450 | @subsection Breakpoint Menus |
b80282d5 | 2451 | @cindex overloading |
e251e767 | 2452 | @cindex symbol overloading |
70b88761 RP |
2453 | |
2454 | Some programming languages (notably C++) permit a single function name | |
2455 | to be defined several times, for application in different contexts. | |
2456 | This is called @dfn{overloading}. When a function name is overloaded, | |
6f3ec223 RP |
2457 | @samp{break @var{function}} is not enough to tell _GDBN__ where you want |
2458 | a breakpoint. If you realize this will be a problem, you can use | |
2459 | something like @samp{break @var{function}(@var{types})} to specify which | |
2460 | particular version of the function you want. Otherwise, _GDBN__ offers | |
2461 | you a menu of numbered choices for different possible breakpoints, and | |
2462 | waits for your selection with the prompt @samp{>}. The first two | |
2463 | options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1} | |
2464 | sets a breakpoint at each definition of @var{function}, and typing | |
2465 | @kbd{0} aborts the @code{break} command without setting any new | |
2466 | breakpoints. | |
70b88761 RP |
2467 | |
2468 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 2469 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
2470 | We choose three particular definitions of that function name: |
2471 | ||
6f3ec223 | 2472 | @c FIXME! This is likely to change to show arg type lists, at least |
70b88761 RP |
2473 | @example |
2474 | (_GDBP__) b String::after | |
2475 | [0] cancel | |
2476 | [1] all | |
2477 | [2] file:String.cc; line number:867 | |
2478 | [3] file:String.cc; line number:860 | |
2479 | [4] file:String.cc; line number:875 | |
2480 | [5] file:String.cc; line number:853 | |
2481 | [6] file:String.cc; line number:846 | |
2482 | [7] file:String.cc; line number:735 | |
2483 | > 2 4 6 | |
2484 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2485 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2486 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2487 | Multiple breakpoints were set. | |
2488 | Use the "delete" command to delete unwanted breakpoints. | |
e251e767 | 2489 | (_GDBP__) |
70b88761 RP |
2490 | @end example |
2491 | ||
4eb4cf57 | 2492 | @node Error in Breakpoints |
70b88761 RP |
2493 | @subsection ``Cannot Insert Breakpoints'' |
2494 | ||
e251e767 | 2495 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 2496 | @c Q in pending mail to Gilmore. [email protected], 26mar91 |
e251e767 | 2497 | @c some light may be shed by looking at instances of |
d24e0922 | 2498 | @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise |
c338a2fd | 2499 | @c too. pesch, 20sep91 |
70b88761 RP |
2500 | Under some operating systems, breakpoints cannot be used in a program if |
2501 | any other process is running that program. In this situation, | |
2502 | attempting to run or continue a program with a breakpoint causes _GDBN__ | |
2503 | to stop the other process. | |
2504 | ||
2505 | When this happens, you have three ways to proceed: | |
2506 | ||
2507 | @enumerate | |
2508 | @item | |
2509 | Remove or disable the breakpoints, then continue. | |
2510 | ||
2511 | @item | |
29a2b744 | 2512 | Suspend _GDBN__, and copy the file containing your program to a new name. |
70b88761 | 2513 | Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__ |
29a2b744 | 2514 | should run your program under that name. Then start your program again. |
70b88761 RP |
2515 | |
2516 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2517 | @c explains the first FIXME: in this section... | |
2518 | ||
2519 | @item | |
29a2b744 | 2520 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
2521 | linker option @samp{-N}. The operating system limitation may not apply |
2522 | to nonsharable executables. | |
2523 | @end enumerate | |
2524 | ||
4eb4cf57 | 2525 | @node Continuing and Stepping |
3d3ab540 | 2526 | @section Continuing and Stepping |
70b88761 RP |
2527 | |
2528 | @cindex stepping | |
7463aadd RP |
2529 | @cindex continuing |
2530 | @cindex resuming execution | |
3d3ab540 | 2531 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
2532 | completes normally. In contrast, @dfn{stepping} means executing just |
2533 | one more ``step'' of your program, where ``step'' may mean either one | |
2534 | line of source code, or one machine instruction (depending on what | |
2535 | particular command you use). Either when continuing | |
4eb4cf57 RP |
2536 | or when stepping, your program may stop even sooner, due to |
2537 | _if__(_BARE__) | |
2538 | a breakpoint. | |
2539 | _fi__(_BARE__) | |
2540 | _if__(!_BARE__) | |
2541 | a breakpoint or to a signal. (If due to a signal, you may want to use | |
2542 | @code{handle}, or use @samp{signal 0} to resume execution. | |
2543 | @xref{Signals, ,Signals}.) | |
2544 | _fi__(!_BARE__) | |
3d3ab540 RP |
2545 | |
2546 | @table @code | |
2547 | @item continue @r{[}@var{ignore-count}@r{]} | |
2548 | @kindex continue | |
29a2b744 | 2549 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
2550 | any breakpoints set at that address are bypassed. The optional argument |
2551 | @var{ignore-count} allows you to specify a further number of times to | |
2552 | ignore a breakpoint at this location; its effect is like that of | |
29a2b744 | 2553 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). |
3d3ab540 RP |
2554 | |
2555 | To resume execution at a different place, you can use @code{return} | |
29a2b744 RP |
2556 | (@pxref{Returning, ,Returning from a Function}) to go back to the |
2557 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
1041a570 | 2558 | Different Address}) to go to an arbitrary location in your program. |
3d3ab540 | 2559 | @end table |
7463aadd RP |
2560 | |
2561 | A typical technique for using stepping is to set a breakpoint | |
29a2b744 RP |
2562 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the |
2563 | beginning of the function or the section of your program where a | |
2564 | problem is believed to lie, run your program until it stops at that | |
2565 | breakpoint, and then step through the suspect area, examining the | |
2566 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
2567 | |
2568 | @table @code | |
2569 | @item step | |
2570 | @kindex step | |
2571 | @kindex s | |
29a2b744 | 2572 | Continue running your program until control reaches a different source |
7463aadd | 2573 | line, then stop it and return control to _GDBN__. This command is |
70b88761 RP |
2574 | abbreviated @code{s}. |
2575 | ||
3d3ab540 RP |
2576 | @quotation |
2577 | @emph{Warning:} If you use the @code{step} command while control is | |
2578 | within a function that was compiled without debugging information, | |
2579 | execution will proceed until control reaches another function. | |
2580 | @end quotation | |
70b88761 RP |
2581 | |
2582 | @item step @var{count} | |
2583 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2584 | breakpoint is reached or a signal not related to stepping occurs before | |
2585 | @var{count} steps, stepping stops right away. | |
2586 | ||
7463aadd | 2587 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2588 | @kindex next |
2589 | @kindex n | |
7463aadd RP |
2590 | Continue to the next source line in the current (innermost) stack frame. |
2591 | Similar to @code{step}, but any function calls appearing within the line | |
2592 | of code are executed without stopping. Execution stops when control | |
2593 | reaches a different line of code at the stack level which was executing | |
2594 | when the @code{next} command was given. This command is abbreviated | |
2595 | @code{n}. | |
70b88761 | 2596 | |
7463aadd | 2597 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2598 | |
2599 | @code{next} within a function that lacks debugging information acts like | |
2600 | @code{step}, but any function calls appearing within the code of the | |
2601 | function are executed without stopping. | |
2602 | ||
2603 | @item finish | |
2604 | @kindex finish | |
7463aadd RP |
2605 | Continue running until just after function in the selected stack frame |
2606 | returns. Print the returned value (if any). | |
70b88761 | 2607 | |
29a2b744 | 2608 | Contrast this with the @code{return} command (@pxref{Returning, |
1041a570 | 2609 | ,Returning from a Function}). |
70b88761 RP |
2610 | |
2611 | @item until | |
2612 | @kindex until | |
2613 | @item u | |
2614 | @kindex u | |
2615 | Continue running until a source line past the current line, in the | |
2616 | current stack frame, is reached. This command is used to avoid single | |
2617 | stepping through a loop more than once. It is like the @code{next} | |
2618 | command, except that when @code{until} encounters a jump, it | |
2619 | automatically continues execution until the program counter is greater | |
2620 | than the address of the jump. | |
2621 | ||
2622 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 2623 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
2624 | until the loop is exited. In contrast, a @code{next} command at the end |
2625 | of a loop will simply step back to the beginning of the loop, which | |
2626 | would force you to step through the next iteration. | |
2627 | ||
29a2b744 | 2628 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
2629 | stack frame. |
2630 | ||
2631 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2632 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2633 | example, in the following excerpt from a debugging session, the @code{f} |
2634 | (@code{frame}) command shows that execution is stopped at line | |
2635 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2636 | ||
2637 | @example | |
2638 | (_GDBP__) f | |
2639 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
b80282d5 | 2640 | 206 expand_input(); |
70b88761 | 2641 | (_GDBP__) until |
b80282d5 | 2642 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
2643 | @end example |
2644 | ||
7463aadd RP |
2645 | This happened because, for execution efficiency, the compiler had |
2646 | generated code for the loop closure test at the end, rather than the | |
2647 | start, of the loop---even though the test in a C @code{for}-loop is | |
2648 | written before the body of the loop. The @code{until} command appeared | |
2649 | to step back to the beginning of the loop when it advanced to this | |
2650 | expression; however, it has not really gone to an earlier | |
2651 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2652 | |
2653 | @code{until} with no argument works by means of single | |
2654 | instruction stepping, and hence is slower than @code{until} with an | |
2655 | argument. | |
2656 | ||
2657 | @item until @var{location} | |
2658 | @item u @var{location} | |
29a2b744 RP |
2659 | Continue running your program until either the specified location is |
2660 | reached, or the current stack frame returns. @var{location} is any of | |
2661 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
2662 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
1041a570 | 2663 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
2664 | |
2665 | @item stepi | |
2666 | @itemx si | |
2667 | @kindex stepi | |
2668 | @kindex si | |
2669 | Execute one machine instruction, then stop and return to the debugger. | |
2670 | ||
2671 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2672 | instructions. This will cause the next instruction to be executed to | |
29a2b744 RP |
2673 | be displayed automatically at each stop. @xref{Auto Display, |
2674 | ,Automatic Display}. | |
70b88761 RP |
2675 | |
2676 | An argument is a repeat count, as in @code{step}. | |
2677 | ||
2678 | @item nexti | |
2679 | @itemx ni | |
2680 | @kindex nexti | |
2681 | @kindex ni | |
2682 | Execute one machine instruction, but if it is a function call, | |
2683 | proceed until the function returns. | |
2684 | ||
2685 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
2686 | @end table |
2687 | ||
4eb4cf57 RP |
2688 | _if__(_GENERIC__ || !_H8__) |
2689 | @node Signals | |
70b88761 RP |
2690 | @section Signals |
2691 | @cindex signals | |
2692 | ||
2693 | A signal is an asynchronous event that can happen in a program. The | |
2694 | operating system defines the possible kinds of signals, and gives each | |
2695 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2696 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2697 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2698 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 2699 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
2700 | requested an alarm). |
2701 | ||
2702 | @cindex fatal signals | |
2703 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
2704 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
2705 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 2706 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 2707 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
2708 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
2709 | ||
29a2b744 RP |
2710 | _GDBN__ has the ability to detect any occurrence of a signal in your |
2711 | program. You can tell _GDBN__ in advance what to do for each kind of | |
2712 | signal. | |
70b88761 RP |
2713 | |
2714 | @cindex handling signals | |
2715 | Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM} | |
29a2b744 RP |
2716 | (so as not to interfere with their role in the functioning of your program) |
2717 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
2718 | You can change these settings with the @code{handle} command. |
2719 | ||
2720 | @table @code | |
2721 | @item info signals | |
2722 | @kindex info signals | |
2723 | Print a table of all the kinds of signals and how _GDBN__ has been told to | |
2724 | handle each one. You can use this to see the signal numbers of all | |
2725 | the defined types of signals. | |
2726 | ||
2727 | @item handle @var{signal} @var{keywords}@dots{} | |
2728 | @kindex handle | |
2729 | Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the | |
2730 | number of a signal or its name (with or without the @samp{SIG} at the | |
2731 | beginning). The @var{keywords} say what change to make. | |
2732 | @end table | |
2733 | ||
2734 | @c @group | |
2735 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2736 | Their full names are: | |
2737 | ||
2738 | @table @code | |
2739 | @item nostop | |
29a2b744 | 2740 | _GDBN__ should not stop your program when this signal happens. It may |
70b88761 RP |
2741 | still print a message telling you that the signal has come in. |
2742 | ||
2743 | @item stop | |
29a2b744 | 2744 | _GDBN__ should stop your program when this signal happens. This implies |
70b88761 RP |
2745 | the @code{print} keyword as well. |
2746 | ||
2747 | @item print | |
2748 | _GDBN__ should print a message when this signal happens. | |
2749 | ||
2750 | @item noprint | |
2751 | _GDBN__ should not mention the occurrence of the signal at all. This | |
2752 | implies the @code{nostop} keyword as well. | |
2753 | ||
2754 | @item pass | |
29a2b744 | 2755 | _GDBN__ should allow your program to see this signal; your program will be |
70b88761 RP |
2756 | able to handle the signal, or may be terminated if the signal is fatal |
2757 | and not handled. | |
2758 | ||
2759 | @item nopass | |
29a2b744 | 2760 | _GDBN__ should not allow your program to see this signal. |
70b88761 RP |
2761 | @end table |
2762 | @c @end group | |
2763 | ||
29a2b744 | 2764 | When a signal has been set to stop your program, your program cannot see the |
70b88761 | 2765 | signal until you continue. It will see the signal then, if @code{pass} is |
6ca72cc6 | 2766 | in effect for the signal in question @emph{at that time}. In other words, |
70b88761 RP |
2767 | after _GDBN__ reports a signal, you can use the @code{handle} command with |
2768 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
29a2b744 | 2769 | your program when you later continue it. |
70b88761 | 2770 | |
29a2b744 | 2771 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 2772 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 2773 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
2774 | due to some sort of memory reference error, you might store correct |
2775 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
2776 | execution; but your program would probably terminate immediately as |
2777 | a result of the fatal signal once it saw the signal. To prevent this, | |
2778 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
2779 | Program a Signal}. | |
4eb4cf57 | 2780 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 2781 | |
4eb4cf57 | 2782 | @node Stack |
70b88761 RP |
2783 | @chapter Examining the Stack |
2784 | ||
2785 | When your program has stopped, the first thing you need to know is where it | |
2786 | stopped and how it got there. | |
2787 | ||
2788 | @cindex call stack | |
2789 | Each time your program performs a function call, the information about | |
29a2b744 | 2790 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
2791 | called a @dfn{stack frame}. The frame also contains the arguments of the |
2792 | call and the local variables of the function that was called. All the | |
2793 | stack frames are allocated in a region of memory called the @dfn{call | |
2794 | stack}. | |
2795 | ||
2796 | When your program stops, the _GDBN__ commands for examining the stack allow you | |
2797 | to see all of this information. | |
2798 | ||
2799 | @cindex selected frame | |
2800 | One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands | |
2801 | refer implicitly to the selected frame. In particular, whenever you ask | |
29a2b744 | 2802 | _GDBN__ for the value of a variable in your program, the value is found in the |
70b88761 RP |
2803 | selected frame. There are special _GDBN__ commands to select whichever frame |
2804 | you are interested in. | |
2805 | ||
29a2b744 | 2806 | When your program stops, _GDBN__ automatically selects the currently executing |
70b88761 | 2807 | frame and describes it briefly as the @code{frame} command does |
29a2b744 | 2808 | (@pxref{Frame Info, ,Information About a Frame}). |
70b88761 RP |
2809 | |
2810 | @menu | |
b80282d5 RP |
2811 | * Frames:: Stack Frames |
2812 | * Backtrace:: Backtraces | |
2813 | * Selection:: Selecting a Frame | |
2814 | * Frame Info:: Information on a Frame | |
70b88761 RP |
2815 | @end menu |
2816 | ||
4eb4cf57 | 2817 | @node Frames |
70b88761 RP |
2818 | @section Stack Frames |
2819 | ||
2820 | @cindex frame | |
2821 | @cindex stack frame | |
2822 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2823 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2824 | with one call to one function. The frame contains the arguments given | |
2825 | to the function, the function's local variables, and the address at | |
2826 | which the function is executing. | |
2827 | ||
2828 | @cindex initial frame | |
2829 | @cindex outermost frame | |
2830 | @cindex innermost frame | |
2831 | When your program is started, the stack has only one frame, that of the | |
2832 | function @code{main}. This is called the @dfn{initial} frame or the | |
2833 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2834 | made. Each time a function returns, the frame for that function invocation | |
2835 | is eliminated. If a function is recursive, there can be many frames for | |
2836 | the same function. The frame for the function in which execution is | |
2837 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2838 | recently created of all the stack frames that still exist. | |
2839 | ||
2840 | @cindex frame pointer | |
2841 | Inside your program, stack frames are identified by their addresses. A | |
2842 | stack frame consists of many bytes, each of which has its own address; each | |
2843 | kind of computer has a convention for choosing one of those bytes whose | |
2844 | address serves as the address of the frame. Usually this address is kept | |
2845 | in a register called the @dfn{frame pointer register} while execution is | |
2846 | going on in that frame. | |
2847 | ||
2848 | @cindex frame number | |
2849 | _GDBN__ assigns numbers to all existing stack frames, starting with | |
2850 | zero for the innermost frame, one for the frame that called it, | |
2851 | and so on upward. These numbers do not really exist in your program; | |
2852 | they are assigned by _GDBN__ to give you a way of designating stack | |
2853 | frames in _GDBN__ commands. | |
2854 | ||
2855 | @cindex frameless execution | |
2856 | Some compilers allow functions to be compiled so that they operate | |
2857 | without stack frames. (For example, the @code{_GCC__} option | |
2858 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2859 | This is occasionally done with heavily used library functions to save | |
2860 | the frame setup time. _GDBN__ has limited facilities for dealing with | |
2861 | these function invocations. If the innermost function invocation has no | |
2862 | stack frame, _GDBN__ will nevertheless regard it as though it had a | |
2863 | separate frame, which is numbered zero as usual, allowing correct | |
2864 | tracing of the function call chain. However, _GDBN__ has no provision | |
2865 | for frameless functions elsewhere in the stack. | |
2866 | ||
4eb4cf57 | 2867 | @node Backtrace |
70b88761 RP |
2868 | @section Backtraces |
2869 | ||
29a2b744 | 2870 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
2871 | line per frame, for many frames, starting with the currently executing |
2872 | frame (frame zero), followed by its caller (frame one), and on up the | |
2873 | stack. | |
2874 | ||
2875 | @table @code | |
2876 | @item backtrace | |
2877 | @itemx bt | |
2878 | @kindex backtrace | |
2879 | @kindex bt | |
2880 | Print a backtrace of the entire stack: one line per frame for all | |
2881 | frames in the stack. | |
2882 | ||
2883 | You can stop the backtrace at any time by typing the system interrupt | |
2884 | character, normally @kbd{C-c}. | |
2885 | ||
2886 | @item backtrace @var{n} | |
2887 | @itemx bt @var{n} | |
2888 | Similar, but print only the innermost @var{n} frames. | |
2889 | ||
2890 | @item backtrace -@var{n} | |
2891 | @itemx bt -@var{n} | |
2892 | Similar, but print only the outermost @var{n} frames. | |
2893 | @end table | |
2894 | ||
2895 | @kindex where | |
2896 | @kindex info stack | |
2897 | @kindex info s | |
2898 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
2899 | are additional aliases for @code{backtrace}. | |
2900 | ||
2901 | Each line in the backtrace shows the frame number and the function name. | |
2902 | The program counter value is also shown---unless you use @code{set | |
2903 | print address off}. The backtrace also shows the source file name and | |
2904 | line number, as well as the arguments to the function. The program | |
2905 | counter value is omitted if it is at the beginning of the code for that | |
2906 | line number. | |
2907 | ||
2908 | Here is an example of a backtrace. It was made with the command | |
2909 | @samp{bt 3}, so it shows the innermost three frames. | |
2910 | ||
2911 | @smallexample | |
2912 | @group | |
203eea5d RP |
2913 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
2914 | at builtin.c:993 | |
70b88761 RP |
2915 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
2916 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
2917 | at macro.c:71 | |
2918 | (More stack frames follow...) | |
2919 | @end group | |
2920 | @end smallexample | |
2921 | ||
2922 | @noindent | |
29a2b744 RP |
2923 | The display for frame zero does not begin with a program counter |
2924 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
2925 | code for line @code{993} of @code{builtin.c}. |
2926 | ||
4eb4cf57 | 2927 | @node Selection |
70b88761 RP |
2928 | @section Selecting a Frame |
2929 | ||
29a2b744 | 2930 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
2931 | whichever stack frame is selected at the moment. Here are the commands for |
2932 | selecting a stack frame; all of them finish by printing a brief description | |
2933 | of the stack frame just selected. | |
2934 | ||
2935 | @table @code | |
2936 | @item frame @var{n} | |
2937 | @itemx f @var{n} | |
2938 | @kindex frame | |
2939 | @kindex f | |
2940 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2941 | (currently executing) frame, frame one is the frame that called the | |
2942 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2943 | frame. | |
2944 | ||
2945 | @item frame @var{addr} | |
2946 | @itemx f @var{addr} | |
2947 | Select the frame at address @var{addr}. This is useful mainly if the | |
2948 | chaining of stack frames has been damaged by a bug, making it | |
2949 | impossible for _GDBN__ to assign numbers properly to all frames. In | |
29a2b744 | 2950 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
2951 | switches between them. |
2952 | ||
c728f1f0 | 2953 | _if__(_SPARC__) |
70b88761 | 2954 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 2955 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
2956 | @c note to future updaters: this is conditioned on a flag |
2957 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
2958 | @c by SPARC, hence the specific attribution. Generalize or list all | |
2959 | @c possibilities if more supported machines start doing this. | |
c728f1f0 | 2960 | _fi__(_SPARC__) |
70b88761 RP |
2961 | |
2962 | @item up @var{n} | |
2963 | @kindex up | |
2964 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
2965 | advances toward the outermost frame, to higher frame numbers, to frames | |
2966 | that have existed longer. @var{n} defaults to one. | |
2967 | ||
2968 | @item down @var{n} | |
2969 | @kindex down | |
2970 | @kindex do | |
2971 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
2972 | advances toward the innermost frame, to lower frame numbers, to frames | |
2973 | that were created more recently. @var{n} defaults to one. You may | |
2974 | abbreviate @code{down} as @code{do}. | |
2975 | @end table | |
2976 | ||
2977 | All of these commands end by printing two lines of output describing the | |
2978 | frame. The first line shows the frame number, the function name, the | |
2979 | arguments, and the source file and line number of execution in that | |
2980 | frame. The second line shows the text of that source line. For | |
2981 | example: | |
2982 | ||
2983 | @smallexample | |
29a2b744 | 2984 | @group |
70b88761 | 2985 | (_GDBP__) up |
203eea5d RP |
2986 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
2987 | at env.c:10 | |
70b88761 | 2988 | 10 read_input_file (argv[i]); |
29a2b744 | 2989 | @end group |
70b88761 RP |
2990 | @end smallexample |
2991 | ||
29a2b744 RP |
2992 | After such a printout, the @code{list} command with no arguments will |
2993 | print ten lines centered on the point of execution in the frame. | |
2994 | @xref{List, ,Printing Source Lines}. | |
70b88761 RP |
2995 | |
2996 | @table @code | |
2997 | @item up-silently @var{n} | |
2998 | @itemx down-silently @var{n} | |
2999 | @kindex down-silently | |
3000 | @kindex up-silently | |
3001 | These two commands are variants of @code{up} and @code{down}, | |
3002 | respectively; they differ in that they do their work silently, without | |
3003 | causing display of the new frame. They are intended primarily for use | |
3004 | in _GDBN__ command scripts, where the output might be unnecessary and | |
e251e767 | 3005 | distracting. |
70b88761 RP |
3006 | @end table |
3007 | ||
4eb4cf57 | 3008 | @node Frame Info |
70b88761 RP |
3009 | @section Information About a Frame |
3010 | ||
3011 | There are several other commands to print information about the selected | |
3012 | stack frame. | |
3013 | ||
3014 | @table @code | |
3015 | @item frame | |
3016 | @itemx f | |
29a2b744 RP |
3017 | When used without any argument, this command does not change which |
3018 | frame is selected, but prints a brief description of the currently | |
70b88761 | 3019 | selected stack frame. It can be abbreviated @code{f}. With an |
29a2b744 RP |
3020 | argument, this command is used to select a stack frame |
3021 | (@pxref{Selection, ,Selecting a Frame}). | |
70b88761 RP |
3022 | |
3023 | @item info frame | |
70b88761 | 3024 | @itemx info f |
29a2b744 | 3025 | @kindex info frame |
70b88761 RP |
3026 | @kindex info f |
3027 | This command prints a verbose description of the selected stack frame, | |
3028 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
3029 | (called by this frame) and the next frame up (caller of this frame), the |
3030 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
3031 | the address of the frame's arguments, the program counter saved in it |
3032 | (the address of execution in the caller frame), and which registers | |
3033 | were saved in the frame. The verbose description is useful when | |
3034 | something has gone wrong that has made the stack format fail to fit | |
3035 | the usual conventions. | |
3036 | ||
3037 | @item info frame @var{addr} | |
3038 | @itemx info f @var{addr} | |
3039 | Print a verbose description of the frame at address @var{addr}, | |
3040 | without selecting that frame. The selected frame remains unchanged by | |
3041 | this command. | |
3042 | ||
3043 | @item info args | |
3044 | @kindex info args | |
3045 | Print the arguments of the selected frame, each on a separate line. | |
3046 | ||
3047 | @item info locals | |
3048 | @kindex info locals | |
3049 | Print the local variables of the selected frame, each on a separate | |
3050 | line. These are all variables declared static or automatic within all | |
3051 | program blocks that execution in this frame is currently inside of. | |
3052 | ||
3053 | @item info catch | |
3054 | @kindex info catch | |
3055 | @cindex catch exceptions | |
3056 | @cindex exception handlers | |
3057 | Print a list of all the exception handlers that are active in the | |
3058 | current stack frame at the current point of execution. To see other | |
3059 | exception handlers, visit the associated frame (using the @code{up}, | |
3060 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
1041a570 | 3061 | @xref{Exception Handling, ,Breakpoints and Exceptions}. |
70b88761 RP |
3062 | @end table |
3063 | ||
4eb4cf57 | 3064 | @node Source |
70b88761 RP |
3065 | @chapter Examining Source Files |
3066 | ||
3067 | _GDBN__ can print parts of your program's source, since the debugging | |
1041a570 RP |
3068 | information recorded in your program tells _GDBN__ what source files were |
3069 | used to build it. When your program stops, _GDBN__ spontaneously prints | |
3070 | the line where it stopped. Likewise, when you select a stack frame | |
3071 | (@pxref{Selection, ,Selecting a Frame}), _GDBN__ prints the line where | |
3072 | execution in that frame has stopped. You can print other portions of | |
3073 | source files by explicit command. | |
70b88761 | 3074 | |
4eb4cf57 | 3075 | _if__(!_DOSHOST__) |
1041a570 RP |
3076 | If you use _GDBN__ through its GNU Emacs interface, you may prefer to use |
3077 | Emacs facilities to view source; @pxref{Emacs, ,Using _GDBN__ under GNU | |
3078 | Emacs}. | |
4eb4cf57 | 3079 | _fi__(!_DOSHOST__) |
70b88761 RP |
3080 | |
3081 | @menu | |
b80282d5 | 3082 | * List:: Printing Source Lines |
6f28dd0b | 3083 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 3084 | * Search:: Searching Source Files |
6f28dd0b | 3085 | _fi__(_GENERIC__ || !_H8__) |
b80282d5 RP |
3086 | * Source Path:: Specifying Source Directories |
3087 | * Machine Code:: Source and Machine Code | |
70b88761 RP |
3088 | @end menu |
3089 | ||
4eb4cf57 | 3090 | @node List |
70b88761 RP |
3091 | @section Printing Source Lines |
3092 | ||
3093 | @kindex list | |
3094 | @kindex l | |
3095 | To print lines from a source file, use the @code{list} command | |
3096 | (abbreviated @code{l}). There are several ways to specify what part | |
3097 | of the file you want to print. | |
3098 | ||
3099 | Here are the forms of the @code{list} command most commonly used: | |
3100 | ||
3101 | @table @code | |
3102 | @item list @var{linenum} | |
c338a2fd | 3103 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
3104 | current source file. |
3105 | ||
3106 | @item list @var{function} | |
c338a2fd | 3107 | Print lines centered around the beginning of function |
70b88761 RP |
3108 | @var{function}. |
3109 | ||
3110 | @item list | |
c338a2fd RP |
3111 | Print more lines. If the last lines printed were printed with a |
3112 | @code{list} command, this prints lines following the last lines | |
70b88761 | 3113 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 3114 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 3115 | Stack}), this prints lines centered around that line. |
70b88761 RP |
3116 | |
3117 | @item list - | |
c338a2fd RP |
3118 | Print lines just before the lines last printed. |
3119 | @end table | |
3120 | ||
3121 | By default, _GDBN__ prints ten source lines with any of these forms of | |
3122 | the @code{list} command. You can change this using @code{set listsize}: | |
3123 | ||
3124 | @table @code | |
3125 | @item set listsize @var{count} | |
3126 | @kindex set listsize | |
3127 | Make the @code{list} command display @var{count} source lines (unless | |
3128 | the @code{list} argument explicitly specifies some other number). | |
3129 | ||
3130 | @item show listsize | |
3131 | @kindex show listsize | |
3132 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 3133 | default. |
70b88761 RP |
3134 | @end table |
3135 | ||
3136 | Repeating a @code{list} command with @key{RET} discards the argument, | |
3137 | so it is equivalent to typing just @code{list}. This is more useful | |
3138 | than listing the same lines again. An exception is made for an | |
3139 | argument of @samp{-}; that argument is preserved in repetition so that | |
3140 | each repetition moves up in the source file. | |
3141 | ||
3142 | @cindex linespec | |
3143 | In general, the @code{list} command expects you to supply zero, one or two | |
3144 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
3145 | of writing them but the effect is always to specify some source line. | |
3146 | Here is a complete description of the possible arguments for @code{list}: | |
3147 | ||
3148 | @table @code | |
3149 | @item list @var{linespec} | |
c338a2fd | 3150 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
3151 | |
3152 | @item list @var{first},@var{last} | |
3153 | Print lines from @var{first} to @var{last}. Both arguments are | |
3154 | linespecs. | |
3155 | ||
3156 | @item list ,@var{last} | |
c338a2fd | 3157 | Print lines ending with @var{last}. |
70b88761 RP |
3158 | |
3159 | @item list @var{first}, | |
c338a2fd | 3160 | Print lines starting with @var{first}. |
70b88761 RP |
3161 | |
3162 | @item list + | |
c338a2fd | 3163 | Print lines just after the lines last printed. |
70b88761 RP |
3164 | |
3165 | @item list - | |
c338a2fd | 3166 | Print lines just before the lines last printed. |
70b88761 RP |
3167 | |
3168 | @item list | |
3169 | As described in the preceding table. | |
3170 | @end table | |
3171 | ||
3172 | Here are the ways of specifying a single source line---all the | |
3173 | kinds of linespec. | |
3174 | ||
3175 | @table @code | |
3176 | @item @var{number} | |
3177 | Specifies line @var{number} of the current source file. | |
3178 | When a @code{list} command has two linespecs, this refers to | |
3179 | the same source file as the first linespec. | |
3180 | ||
3181 | @item +@var{offset} | |
3182 | Specifies the line @var{offset} lines after the last line printed. | |
3183 | When used as the second linespec in a @code{list} command that has | |
3184 | two, this specifies the line @var{offset} lines down from the | |
3185 | first linespec. | |
3186 | ||
3187 | @item -@var{offset} | |
3188 | Specifies the line @var{offset} lines before the last line printed. | |
3189 | ||
3190 | @item @var{filename}:@var{number} | |
3191 | Specifies line @var{number} in the source file @var{filename}. | |
3192 | ||
3193 | @item @var{function} | |
3194 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
3195 | Specifies the line of the open-brace that begins the body of the | |
3196 | function @var{function}. | |
3197 | ||
3198 | @item @var{filename}:@var{function} | |
3199 | Specifies the line of the open-brace that begins the body of the | |
3200 | function @var{function} in the file @var{filename}. You only need the | |
3201 | file name with a function name to avoid ambiguity when there are | |
3202 | identically named functions in different source files. | |
3203 | ||
3204 | @item *@var{address} | |
3205 | Specifies the line containing the program address @var{address}. | |
3206 | @var{address} may be any expression. | |
3207 | @end table | |
3208 | ||
6f28dd0b | 3209 | _if__(_GENERIC__ || !_H8__) |
4eb4cf57 | 3210 | @node Search |
70b88761 RP |
3211 | @section Searching Source Files |
3212 | @cindex searching | |
3213 | @kindex reverse-search | |
3214 | ||
3215 | There are two commands for searching through the current source file for a | |
3216 | regular expression. | |
3217 | ||
3218 | @table @code | |
3219 | @item forward-search @var{regexp} | |
3220 | @itemx search @var{regexp} | |
3221 | @kindex search | |
3222 | @kindex forward-search | |
1041a570 RP |
3223 | The command @samp{forward-search @var{regexp}} checks each line, |
3224 | starting with the one following the last line listed, for a match for | |
3225 | @var{regexp}. It lists the line that is found. You can use | |
3226 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3227 | @code{fo}. | |
70b88761 RP |
3228 | |
3229 | @item reverse-search @var{regexp} | |
3230 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3231 | with the one before the last line listed and going backward, for a match | |
3232 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3233 | this command as @code{rev}. | |
3234 | @end table | |
6f28dd0b | 3235 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 3236 | |
4eb4cf57 | 3237 | @node Source Path |
70b88761 RP |
3238 | @section Specifying Source Directories |
3239 | ||
3240 | @cindex source path | |
3241 | @cindex directories for source files | |
3242 | Executable programs sometimes do not record the directories of the source | |
3243 | files from which they were compiled, just the names. Even when they do, | |
3244 | the directories could be moved between the compilation and your debugging | |
3245 | session. _GDBN__ has a list of directories to search for source files; | |
3246 | this is called the @dfn{source path}. Each time _GDBN__ wants a source file, | |
3247 | it tries all the directories in the list, in the order they are present | |
3248 | in the list, until it finds a file with the desired name. Note that | |
3249 | the executable search path is @emph{not} used for this purpose. Neither is | |
3250 | the current working directory, unless it happens to be in the source | |
3251 | path. | |
3252 | ||
29a2b744 | 3253 | If _GDBN__ cannot find a source file in the source path, and the object |
70b88761 RP |
3254 | program records a directory, _GDBN__ tries that directory too. If the |
3255 | source path is empty, and there is no record of the compilation | |
3256 | directory, _GDBN__ will, as a last resort, look in the current | |
3257 | directory. | |
3258 | ||
3259 | Whenever you reset or rearrange the source path, _GDBN__ will clear out | |
3260 | any information it has cached about where source files are found, where | |
3261 | each line is in the file, etc. | |
3262 | ||
3263 | @kindex directory | |
3264 | When you start _GDBN__, its source path is empty. | |
3265 | To add other directories, use the @code{directory} command. | |
3266 | ||
3267 | @table @code | |
3268 | @item directory @var{dirname} @dots{} | |
3269 | Add directory @var{dirname} to the front of the source path. Several | |
3270 | directory names may be given to this command, separated by @samp{:} or | |
3271 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 3272 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
3273 | |
3274 | You can use the string @samp{$cdir} to refer to the compilation | |
3275 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3276 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
3277 | tracks the current working directory as it changes during your _GDBN__ | |
3278 | session, while the latter is immediately expanded to the current | |
3279 | directory at the time you add an entry to the source path. | |
70b88761 RP |
3280 | |
3281 | @item directory | |
3282 | Reset the source path to empty again. This requires confirmation. | |
3283 | ||
3284 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 3285 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
3286 | |
3287 | @item show directories | |
3288 | @kindex show directories | |
3289 | Print the source path: show which directories it contains. | |
3290 | @end table | |
3291 | ||
3292 | If your source path is cluttered with directories that are no longer of | |
3293 | interest, _GDBN__ may sometimes cause confusion by finding the wrong | |
3294 | versions of source. You can correct the situation as follows: | |
3295 | ||
3296 | @enumerate | |
3297 | @item | |
3298 | Use @code{directory} with no argument to reset the source path to empty. | |
3299 | ||
3300 | @item | |
3301 | Use @code{directory} with suitable arguments to reinstall the | |
3302 | directories you want in the source path. You can add all the | |
3303 | directories in one command. | |
3304 | @end enumerate | |
3305 | ||
4eb4cf57 | 3306 | @node Machine Code |
70b88761 | 3307 | @section Source and Machine Code |
1041a570 | 3308 | |
70b88761 RP |
3309 | You can use the command @code{info line} to map source lines to program |
3310 | addresses (and viceversa), and the command @code{disassemble} to display | |
3311 | a range of addresses as machine instructions. | |
3312 | ||
3313 | @table @code | |
3314 | @item info line @var{linespec} | |
3315 | @kindex info line | |
3316 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
3317 | source line @var{linespec}. You can specify source lines in any of |
3318 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
3319 | Source Lines}). | |
70b88761 RP |
3320 | @end table |
3321 | ||
1041a570 RP |
3322 | For example, we can use @code{info line} to discover the location of |
3323 | the object code for the first line of function | |
3324 | @code{m4_changequote}: | |
3325 | ||
70b88761 RP |
3326 | @smallexample |
3327 | (_GDBP__) info line m4_changecom | |
3328 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
3329 | @end smallexample | |
3330 | ||
3331 | @noindent | |
3332 | We can also inquire (using @code{*@var{addr}} as the form for | |
3333 | @var{linespec}) what source line covers a particular address: | |
3334 | @smallexample | |
3335 | (_GDBP__) info line *0x63ff | |
3336 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
3337 | @end smallexample | |
3338 | ||
c338a2fd | 3339 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
3340 | After @code{info line}, the default address for the @code{x} command |
3341 | is changed to the starting address of the line, so that @samp{x/i} is | |
3342 | sufficient to begin examining the machine code (@pxref{Memory, | |
3343 | ,Examining Memory}). Also, this address is saved as the value of the | |
3344 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
3345 | Variables}). | |
70b88761 RP |
3346 | |
3347 | @table @code | |
3348 | @kindex disassemble | |
3349 | @item disassemble | |
e94b4a2b RP |
3350 | This specialized command dumps a range of memory as machine |
3351 | instructions. The default memory range is the function surrounding the | |
3352 | program counter of the selected frame. A single argument to this | |
3353 | command is a program counter value; the function surrounding this value | |
3354 | will be dumped. Two arguments specify a range of addresses (first | |
3355 | inclusive, second exclusive) to dump. | |
70b88761 RP |
3356 | @end table |
3357 | ||
4eb4cf57 | 3358 | _if__(_GENERIC__||!_H8__) |
70b88761 | 3359 | We can use @code{disassemble} to inspect the object code |
4eb4cf57 RP |
3360 | range shown in the last @code{info line} example (the example |
3361 | shows SPARC machine instructions): | |
70b88761 | 3362 | |
4eb4cf57 | 3363 | _0__ |
70b88761 RP |
3364 | @smallexample |
3365 | (_GDBP__) disas 0x63e4 0x6404 | |
3366 | Dump of assembler code from 0x63e4 to 0x6404: | |
b80282d5 RP |
3367 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
3368 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
3369 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
3370 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
3371 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
3372 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
3373 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 3374 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 3375 | End of assembler dump. |
70b88761 | 3376 | @end smallexample |
4eb4cf57 RP |
3377 | _1__ |
3378 | _fi__(_GENERIC__||!_H8__) | |
3379 | ||
3380 | _if__(!_GENERIC__||_H8__) | |
3381 | For example, here is the beginning of the output for the | |
3382 | disassembly of a function @code{fact}: | |
70b88761 | 3383 | |
4eb4cf57 RP |
3384 | _0__ |
3385 | @smallexample | |
3386 | (_GDBP__) disas fact | |
3387 | Dump of assembler code for function fact: | |
3388 | to 0x808c: | |
3389 | 0x802c <fact>: 6d f2 mov.w r2,@@-r7 | |
3390 | 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7 | |
3391 | 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7 | |
3392 | 0x8032 <fact+6>: 0d 76 mov.w r7,r6 | |
3393 | 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0 | |
3394 | 0x8038 <fact+12> 19 11 sub.w r1,r1 | |
3395 | . | |
3396 | . | |
3397 | . | |
3398 | @end smallexample | |
3399 | _1__ | |
3400 | _fi__(!_GENERIC__||_H8__) | |
3401 | ||
3402 | ||
3403 | @node Data | |
70b88761 RP |
3404 | @chapter Examining Data |
3405 | ||
3406 | @cindex printing data | |
3407 | @cindex examining data | |
3408 | @kindex print | |
3409 | @kindex inspect | |
1041a570 | 3410 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 3411 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
3412 | @c different window or something like that. |
3413 | The usual way to examine data in your program is with the @code{print} | |
4eb4cf57 RP |
3414 | command (abbreviated @code{p}), or its synonym @code{inspect}. |
3415 | _if__(!_CONLY__) | |
3416 | It evaluates and prints the value of an expression of the language your | |
1041a570 | 3417 | program is written in (@pxref{Languages, ,Using _GDBN__ with Different |
4eb4cf57 RP |
3418 | Languages}). |
3419 | _fi__(!_CONLY__) | |
70b88761 | 3420 | |
e0dacfd1 RP |
3421 | @table @code |
3422 | @item print @var{exp} | |
3423 | @itemx print /@var{f} @var{exp} | |
3424 | @var{exp} is an expression (in the source language). By default | |
70b88761 | 3425 | the value of @var{exp} is printed in a format appropriate to its data |
e0dacfd1 RP |
3426 | type; you can choose a different format by specifying @samp{/@var{f}}, |
3427 | where @var{f} is a letter specifying the format; @pxref{Output formats}. | |
3428 | ||
3429 | @item print | |
3430 | @itemx print /@var{f} | |
3431 | If you omit @var{exp}, _GDBN__ displays the last value again (from the | |
1041a570 | 3432 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to |
e0dacfd1 RP |
3433 | conveniently inspect the same value in an alternative format. |
3434 | @end table | |
70b88761 RP |
3435 | |
3436 | A more low-level way of examining data is with the @code{x} command. | |
3437 | It examines data in memory at a specified address and prints it in a | |
29a2b744 | 3438 | specified format. @xref{Memory, ,Examining Memory}. |
70b88761 | 3439 | |
29a2b744 | 3440 | If you are interested in information about types, or about how the fields |
b80282d5 | 3441 | of a struct or class are declared, use the @code{ptype @var{exp}} |
1041a570 | 3442 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 | 3443 | |
70b88761 | 3444 | @menu |
b80282d5 RP |
3445 | * Expressions:: Expressions |
3446 | * Variables:: Program Variables | |
3447 | * Arrays:: Artificial Arrays | |
3448 | * Output formats:: Output formats | |
3449 | * Memory:: Examining Memory | |
3450 | * Auto Display:: Automatic Display | |
3451 | * Print Settings:: Print Settings | |
3452 | * Value History:: Value History | |
3453 | * Convenience Vars:: Convenience Variables | |
3454 | * Registers:: Registers | |
4eb4cf57 | 3455 | _if__(_GENERIC__ || !_H8__) |
b80282d5 | 3456 | * Floating Point Hardware:: Floating Point Hardware |
4eb4cf57 | 3457 | _fi__(_GENERIC__ || !_H8__) |
70b88761 RP |
3458 | @end menu |
3459 | ||
4eb4cf57 | 3460 | @node Expressions |
70b88761 RP |
3461 | @section Expressions |
3462 | ||
3463 | @cindex expressions | |
3464 | @code{print} and many other _GDBN__ commands accept an expression and | |
3465 | compute its value. Any kind of constant, variable or operator defined | |
3466 | by the programming language you are using is legal in an expression in | |
3467 | _GDBN__. This includes conditional expressions, function calls, casts | |
3468 | and string constants. It unfortunately does not include symbols defined | |
b80282d5 | 3469 | by preprocessor @code{#define} commands. |
70b88761 | 3470 | |
4eb4cf57 | 3471 | _if__(!_CONLY__) |
c2bbbb22 | 3472 | Because C is so widespread, most of the expressions shown in examples in |
1041a570 | 3473 | this manual are in C. @xref{Languages, , Using _GDBN__ with Different |
c2bbbb22 | 3474 | Languages}, for information on how to use expressions in other |
e251e767 | 3475 | languages. |
c2bbbb22 RP |
3476 | |
3477 | In this section, we discuss operators that you can use in _GDBN__ | |
e251e767 | 3478 | expressions regardless of your programming language. |
c2bbbb22 | 3479 | |
70b88761 RP |
3480 | Casts are supported in all languages, not just in C, because it is so |
3481 | useful to cast a number into a pointer so as to examine a structure | |
3482 | at that address in memory. | |
c2bbbb22 | 3483 | @c FIXME: casts supported---Mod2 true? |
4eb4cf57 | 3484 | _fi__(!_CONLY__) |
70b88761 | 3485 | |
c2bbbb22 | 3486 | _GDBN__ supports these operators in addition to those of programming |
70b88761 RP |
3487 | languages: |
3488 | ||
3489 | @table @code | |
3490 | @item @@ | |
3491 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
1041a570 | 3492 | @xref{Arrays, ,Artificial Arrays}, for more information. |
70b88761 RP |
3493 | |
3494 | @item :: | |
3495 | @samp{::} allows you to specify a variable in terms of the file or | |
1041a570 | 3496 | function where it is defined. @xref{Variables, ,Program Variables}. |
70b88761 RP |
3497 | |
3498 | @item @{@var{type}@} @var{addr} | |
3499 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3500 | memory. @var{addr} may be any expression whose value is an integer or | |
3501 | pointer (but parentheses are required around binary operators, just as in | |
3502 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 3503 | normally supposed to reside at @var{addr}. |
70b88761 RP |
3504 | @end table |
3505 | ||
4eb4cf57 | 3506 | @node Variables |
70b88761 RP |
3507 | @section Program Variables |
3508 | ||
3509 | The most common kind of expression to use is the name of a variable | |
3510 | in your program. | |
3511 | ||
3512 | Variables in expressions are understood in the selected stack frame | |
29a2b744 RP |
3513 | (@pxref{Selection, ,Selecting a Frame}); they must either be global |
3514 | (or static) or be visible according to the scope rules of the | |
3515 | programming language from the point of execution in that frame. This | |
3516 | means that in the function | |
70b88761 RP |
3517 | |
3518 | @example | |
3519 | foo (a) | |
3520 | int a; | |
3521 | @{ | |
3522 | bar (a); | |
3523 | @{ | |
3524 | int b = test (); | |
3525 | bar (b); | |
3526 | @} | |
3527 | @} | |
3528 | @end example | |
3529 | ||
3530 | @noindent | |
29a2b744 | 3531 | the variable @code{a} is usable whenever your program is executing |
70b88761 | 3532 | within the function @code{foo}, but the variable @code{b} is visible |
29a2b744 | 3533 | only while your program is executing inside the block in which @code{b} |
70b88761 RP |
3534 | is declared. |
3535 | ||
3536 | @cindex variable name conflict | |
3537 | There is an exception: you can refer to a variable or function whose | |
3538 | scope is a single source file even if the current execution point is not | |
3539 | in this file. But it is possible to have more than one such variable or | |
6ca72cc6 RP |
3540 | function with the same name (in different source files). If that |
3541 | happens, referring to that name has unpredictable effects. If you wish, | |
3542 | you can specify a static variable in a particular function or file, | |
3543 | using the colon-colon notation: | |
70b88761 RP |
3544 | |
3545 | @cindex colon-colon | |
a6d0b6d3 | 3546 | @iftex |
29a2b744 | 3547 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 3548 | @kindex :: |
a6d0b6d3 | 3549 | @end iftex |
70b88761 RP |
3550 | @example |
3551 | @var{file}::@var{variable} | |
6ca72cc6 | 3552 | @var{function}::@var{variable} |
70b88761 RP |
3553 | @end example |
3554 | ||
3555 | @noindent | |
6ca72cc6 | 3556 | Here @var{file} or @var{function} is the name of the context for the |
6c380b13 RP |
3557 | static @var{variable}. In the case of file names, you can use quotes to |
3558 | make sure _GDBN__ parses the file name as a single word---for example, | |
3559 | to print a global value of @code{x} defined in @file{f2.c}: | |
3560 | ||
3561 | @example | |
3562 | (_GDBP__) p 'f2.c'::x | |
3563 | @end example | |
70b88761 | 3564 | |
0f153e74 | 3565 | _if__(!_CONLY__) |
c2bbbb22 | 3566 | @cindex C++ scope resolution |
70b88761 RP |
3567 | This use of @samp{::} is very rarely in conflict with the very similar |
3568 | use of the same notation in C++. _GDBN__ also supports use of the C++ | |
c2bbbb22 | 3569 | scope resolution operator in _GDBN__ expressions. |
0f153e74 | 3570 | _fi__(!_CONLY__) |
70b88761 | 3571 | |
3d3ab540 RP |
3572 | @cindex wrong values |
3573 | @cindex variable values, wrong | |
3574 | @quotation | |
3575 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
3576 | wrong value at certain points in a function---just after entry to the | |
29a2b744 | 3577 | function, and just before exit. You may see this problem when you are |
3d3ab540 RP |
3578 | stepping by machine instructions. This is because on most machines, it |
3579 | takes more than one instruction to set up a stack frame (including local | |
29a2b744 | 3580 | variable definitions); if you are stepping by machine instructions, |
3d3ab540 RP |
3581 | variables may appear to have the wrong values until the stack frame is |
3582 | completely built. On function exit, it usually also takes more than one | |
3583 | machine instruction to destroy a stack frame; after you begin stepping | |
3584 | through that group of instructions, local variable definitions may be | |
3585 | gone. | |
3586 | @end quotation | |
3587 | ||
4eb4cf57 | 3588 | @node Arrays |
70b88761 RP |
3589 | @section Artificial Arrays |
3590 | ||
3591 | @cindex artificial array | |
3592 | @kindex @@ | |
3593 | It is often useful to print out several successive objects of the | |
3594 | same type in memory; a section of an array, or an array of | |
3595 | dynamically determined size for which only a pointer exists in the | |
3596 | program. | |
3597 | ||
3598 | This can be done by constructing an @dfn{artificial array} with the | |
3599 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3600 | the first element of the desired array, as an individual object. | |
3601 | The right operand should be the desired length of the array. The result is | |
3602 | an array value whose elements are all of the type of the left argument. | |
3603 | The first element is actually the left argument; the second element | |
3604 | comes from bytes of memory immediately following those that hold the | |
3605 | first element, and so on. Here is an example. If a program says | |
3606 | ||
3607 | @example | |
3608 | int *array = (int *) malloc (len * sizeof (int)); | |
3609 | @end example | |
3610 | ||
3611 | @noindent | |
3612 | you can print the contents of @code{array} with | |
3613 | ||
3614 | @example | |
3615 | p *array@@len | |
3616 | @end example | |
3617 | ||
3618 | The left operand of @samp{@@} must reside in memory. Array values made | |
3619 | with @samp{@@} in this way behave just like other arrays in terms of | |
3620 | subscripting, and are coerced to pointers when used in expressions. | |
3621 | Artificial arrays most often appear in expressions via the value history | |
1041a570 | 3622 | (@pxref{Value History, ,Value History}), after printing one out.) |
70b88761 | 3623 | |
1041a570 | 3624 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 3625 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
3626 | actually be adjacent---for example, if you are interested in the values |
3627 | of pointers in an array. One useful work-around in this situation is | |
3628 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
3629 | Variables}) as a counter in an expression that prints the first | |
3630 | interesting value, and then repeat that expression via @key{RET}. For | |
3631 | instance, suppose you have an array @code{dtab} of pointers to | |
3632 | structures, and you are interested in the values of a field @code{fv} | |
3633 | in each structure. Here is an example of what you might type: | |
3634 | ||
3d3ab540 RP |
3635 | @example |
3636 | set $i = 0 | |
3637 | p dtab[$i++]->fv | |
3638 | @key{RET} | |
3639 | @key{RET} | |
3640 | @dots{} | |
3641 | @end example | |
3642 | ||
4eb4cf57 | 3643 | @node Output formats |
70b88761 RP |
3644 | @section Output formats |
3645 | ||
3646 | @cindex formatted output | |
3647 | @cindex output formats | |
3648 | By default, _GDBN__ prints a value according to its data type. Sometimes | |
3649 | this is not what you want. For example, you might want to print a number | |
3650 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3651 | at a certain address as a character string or as an instruction. To do | |
3652 | these things, specify an @dfn{output format} when you print a value. | |
3653 | ||
3654 | The simplest use of output formats is to say how to print a value | |
3655 | already computed. This is done by starting the arguments of the | |
3656 | @code{print} command with a slash and a format letter. The format | |
3657 | letters supported are: | |
3658 | ||
3659 | @table @code | |
3660 | @item x | |
3661 | Regard the bits of the value as an integer, and print the integer in | |
3662 | hexadecimal. | |
3663 | ||
3664 | @item d | |
3665 | Print as integer in signed decimal. | |
3666 | ||
3667 | @item u | |
3668 | Print as integer in unsigned decimal. | |
3669 | ||
3670 | @item o | |
3671 | Print as integer in octal. | |
3672 | ||
3673 | @item t | |
3674 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3675 | ||
3676 | @item a | |
3677 | Print as an address, both absolute in hex and as an offset from the | |
3678 | nearest preceding symbol. This format can be used to discover where (in | |
3679 | what function) an unknown address is located: | |
1041a570 | 3680 | |
70b88761 RP |
3681 | @example |
3682 | (_GDBP__) p/a 0x54320 | |
3683 | _0__$3 = 0x54320 <_initialize_vx+396>_1__ | |
3684 | @end example | |
3685 | ||
70b88761 RP |
3686 | @item c |
3687 | Regard as an integer and print it as a character constant. | |
3688 | ||
3689 | @item f | |
3690 | Regard the bits of the value as a floating point number and print | |
3691 | using typical floating point syntax. | |
3692 | @end table | |
3693 | ||
3694 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3695 | ||
3696 | @example | |
3697 | p/x $pc | |
3698 | @end example | |
3699 | ||
3700 | @noindent | |
3701 | Note that no space is required before the slash; this is because command | |
3702 | names in _GDBN__ cannot contain a slash. | |
3703 | ||
3704 | To reprint the last value in the value history with a different format, | |
3705 | you can use the @code{print} command with just a format and no | |
3706 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3707 | ||
4eb4cf57 | 3708 | @node Memory |
70b88761 RP |
3709 | @section Examining Memory |
3710 | ||
1041a570 RP |
3711 | You can use the command @code{x} (for ``examine'') to examine memory in |
3712 | any of several formats, independently of your program's data types. | |
3713 | ||
70b88761 RP |
3714 | @cindex examining memory |
3715 | @table @code | |
3716 | @kindex x | |
cedaf8bc RP |
3717 | @item x/@var{nfu} @var{addr} |
3718 | @itemx x @var{addr} | |
3719 | @itemx x | |
1041a570 RP |
3720 | Use the command @code{x} to examine memory. |
3721 | @end table | |
3722 | ||
3723 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3724 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
3725 | expression giving the address where you want to start displaying memory. |
3726 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3727 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 3728 | |
1041a570 RP |
3729 | @table @r |
3730 | @item @var{n}, the repeat count | |
3731 | The repeat count is a decimal integer; the default is 1. It specifies | |
3732 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
3733 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
3734 | @c 4.1.2. | |
70b88761 | 3735 | |
1041a570 RP |
3736 | @item @var{f}, the display format |
3737 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
3738 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
3739 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3740 | last time you used either @code{x} or @code{print}. | |
70b88761 | 3741 | |
1041a570 RP |
3742 | @item @var{u}, the unit size |
3743 | The unit size is any of | |
70b88761 RP |
3744 | @table @code |
3745 | @item b | |
cedaf8bc | 3746 | Bytes. |
70b88761 | 3747 | @item h |
cedaf8bc | 3748 | Halfwords (two bytes). |
70b88761 | 3749 | @item w |
cedaf8bc | 3750 | Words (four bytes). This is the initial default. |
70b88761 | 3751 | @item g |
cedaf8bc | 3752 | Giant words (eight bytes). |
70b88761 RP |
3753 | @end table |
3754 | ||
cedaf8bc RP |
3755 | Each time you specify a unit size with @code{x}, that size becomes the |
3756 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3757 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3758 | ||
1041a570 | 3759 | @item @var{addr}, starting display address |
cedaf8bc RP |
3760 | @var{addr} is the address where you want _GDBN__ to begin displaying |
3761 | memory. The expression need not have a pointer value (though it may); | |
3762 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 3763 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
3764 | @var{addr} is usually just after the last address examined---but several |
3765 | other commands also set the default address: @code{info breakpoints} (to | |
3766 | the address of the last breakpoint listed), @code{info line} (to the | |
3767 | starting address of a line), and @code{print} (if you use it to display | |
3768 | a value from memory). | |
1041a570 | 3769 | @end table |
70b88761 | 3770 | |
cedaf8bc RP |
3771 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
3772 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3773 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3774 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3775 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 3776 | |
cedaf8bc | 3777 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 3778 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
3779 | unit size or format comes first; either order will work. The output |
3780 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3781 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3782 | ||
3783 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3784 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3785 | @samp{3i} specifies that you want to see three machine instructions, | |
3786 | including any operands. The command @code{disassemble} gives an | |
3787 | alternative way of inspecting machine instructions; @pxref{Machine | |
3788 | Code}. | |
3789 | ||
3790 | All the defaults for the arguments to @code{x} are designed to make it | |
3791 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 3792 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
3793 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
3794 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3795 | the repeat count @var{n} is used again; the other arguments default as | |
3796 | for successive uses of @code{x}. | |
70b88761 | 3797 | |
c338a2fd | 3798 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 3799 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 RP |
3800 | in the value history because there is often too much of them and they |
3801 | would get in the way. Instead, _GDBN__ makes these values available for | |
3802 | subsequent use in expressions as values of the convenience variables | |
3803 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3804 | examined is available for use in expressions in the convenience variable | |
3805 | @code{$_}. The contents of that address, as examined, are available in | |
3806 | the convenience variable @code{$__}. | |
3807 | ||
3808 | If the @code{x} command has a repeat count, the address and contents saved | |
3809 | are from the last memory unit printed; this is not the same as the last | |
3810 | address printed if several units were printed on the last line of output. | |
3811 | ||
4eb4cf57 | 3812 | @node Auto Display |
70b88761 RP |
3813 | @section Automatic Display |
3814 | @cindex automatic display | |
3815 | @cindex display of expressions | |
3816 | ||
3817 | If you find that you want to print the value of an expression frequently | |
3818 | (to see how it changes), you might want to add it to the @dfn{automatic | |
29a2b744 | 3819 | display list} so that _GDBN__ will print its value each time your program stops. |
70b88761 RP |
3820 | Each expression added to the list is given a number to identify it; |
3821 | to remove an expression from the list, you specify that number. | |
3822 | The automatic display looks like this: | |
3823 | ||
3824 | @example | |
3825 | 2: foo = 38 | |
3826 | 3: bar[5] = (struct hack *) 0x3804 | |
3827 | @end example | |
3828 | ||
3829 | @noindent | |
3830 | showing item numbers, expressions and their current values. As with | |
3831 | displays you request manually using @code{x} or @code{print}, you can | |
3832 | specify the output format you prefer; in fact, @code{display} decides | |
3833 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3834 | format specification is---it uses @code{x} if you specify a unit size, | |
3835 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3836 | supported by @code{x}; otherwise it uses @code{print}. | |
3837 | ||
3838 | @table @code | |
3839 | @item display @var{exp} | |
3840 | @kindex display | |
3841 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 3842 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3843 | |
3844 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3845 | ||
3846 | @item display/@var{fmt} @var{exp} | |
3847 | For @var{fmt} specifying only a display format and not a size or | |
3848 | count, add the expression @var{exp} to the auto-display list but | |
3849 | arranges to display it each time in the specified format @var{fmt}. | |
3850 | @xref{Output formats}. | |
3851 | ||
3852 | @item display/@var{fmt} @var{addr} | |
3853 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3854 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 RP |
3855 | be examined each time your program stops. Examining means in effect |
3856 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
70b88761 RP |
3857 | @end table |
3858 | ||
3859 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3860 | instruction about to be executed each time execution stops (@samp{$pc} | |
3861 | is a common name for the program counter; @pxref{Registers}). | |
3862 | ||
3863 | @table @code | |
3864 | @item undisplay @var{dnums}@dots{} | |
3865 | @itemx delete display @var{dnums}@dots{} | |
3866 | @kindex delete display | |
3867 | @kindex undisplay | |
3868 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3869 | ||
3870 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3871 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3872 | ||
3873 | @item disable display @var{dnums}@dots{} | |
3874 | @kindex disable display | |
3875 | Disable the display of item numbers @var{dnums}. A disabled display | |
3876 | item is not printed automatically, but is not forgotten. It may be | |
3877 | enabled again later. | |
3878 | ||
3879 | @item enable display @var{dnums}@dots{} | |
3880 | @kindex enable display | |
3881 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3882 | again in auto display of its expression, until you specify otherwise. | |
3883 | ||
3884 | @item display | |
3885 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 3886 | done when your program stops. |
70b88761 RP |
3887 | |
3888 | @item info display | |
3889 | @kindex info display | |
3890 | Print the list of expressions previously set up to display | |
3891 | automatically, each one with its item number, but without showing the | |
3892 | values. This includes disabled expressions, which are marked as such. | |
3893 | It also includes expressions which would not be displayed right now | |
3894 | because they refer to automatic variables not currently available. | |
3895 | @end table | |
3896 | ||
3897 | If a display expression refers to local variables, then it does not make | |
3898 | sense outside the lexical context for which it was set up. Such an | |
3899 | expression is disabled when execution enters a context where one of its | |
3900 | variables is not defined. For example, if you give the command | |
3901 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 3902 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
3903 | continues to stop inside that function. When it stops elsewhere---where |
3904 | there is no variable @code{last_char}---display is disabled. The next time | |
3905 | your program stops where @code{last_char} is meaningful, you can enable the | |
3906 | display expression once again. | |
3907 | ||
4eb4cf57 | 3908 | @node Print Settings |
70b88761 RP |
3909 | @section Print Settings |
3910 | ||
3911 | @cindex format options | |
3912 | @cindex print settings | |
3913 | _GDBN__ provides the following ways to control how arrays, structures, | |
e251e767 | 3914 | and symbols are printed. |
70b88761 RP |
3915 | |
3916 | @noindent | |
3917 | These settings are useful for debugging programs in any language: | |
3918 | ||
3919 | @table @code | |
3920 | @item set print address | |
3921 | @item set print address on | |
3922 | @kindex set print address | |
3923 | _GDBN__ will print memory addresses showing the location of stack | |
3924 | traces, structure values, pointer values, breakpoints, and so forth, | |
3925 | even when it also displays the contents of those addresses. The default | |
3926 | is on. For example, this is what a stack frame display looks like, with | |
3927 | @code{set print address on}: | |
1041a570 | 3928 | |
70b88761 | 3929 | @smallexample |
1041a570 | 3930 | @group |
70b88761 | 3931 | (_GDBP__) f |
e251e767 | 3932 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 3933 | at input.c:530 |
b80282d5 | 3934 | 530 if (lquote != def_lquote) |
1041a570 | 3935 | @end group |
70b88761 RP |
3936 | @end smallexample |
3937 | ||
3938 | @item set print address off | |
3939 | Do not print addresses when displaying their contents. For example, | |
3940 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 3941 | |
70b88761 | 3942 | @example |
1041a570 | 3943 | @group |
70b88761 RP |
3944 | (_GDBP__) set print addr off |
3945 | (_GDBP__) f | |
3946 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
b80282d5 | 3947 | 530 if (lquote != def_lquote) |
1041a570 | 3948 | @end group |
70b88761 RP |
3949 | @end example |
3950 | ||
3951 | @item show print address | |
3952 | @kindex show print address | |
3953 | Show whether or not addresses are to be printed. | |
3954 | ||
3955 | @item set print array | |
3956 | @itemx set print array on | |
3957 | @kindex set print array | |
3958 | _GDBN__ will pretty print arrays. This format is more convenient to read, | |
3959 | but uses more space. The default is off. | |
3960 | ||
3961 | @item set print array off. | |
3962 | Return to compressed format for arrays. | |
3963 | ||
3964 | @item show print array | |
3965 | @kindex show print array | |
3966 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 3967 | arrays. |
70b88761 RP |
3968 | |
3969 | @item set print elements @var{number-of-elements} | |
3970 | @kindex set print elements | |
3971 | If _GDBN__ is printing a large array, it will stop printing after it has | |
3972 | printed the number of elements set by the @code{set print elements} command. | |
3973 | This limit also applies to the display of strings. | |
3974 | ||
3975 | @item show print elements | |
3976 | @kindex show print elements | |
3977 | Display the number of elements of a large array that _GDBN__ will print | |
3978 | before losing patience. | |
3979 | ||
3980 | @item set print pretty on | |
3981 | @kindex set print pretty | |
3982 | Cause _GDBN__ to print structures in an indented format with one member per | |
3983 | line, like this: | |
3984 | ||
3985 | @example | |
1041a570 | 3986 | @group |
70b88761 RP |
3987 | $1 = @{ |
3988 | next = 0x0, | |
3989 | flags = @{ | |
3990 | sweet = 1, | |
3991 | sour = 1 | |
3992 | @}, | |
3993 | meat = 0x54 "Pork" | |
3994 | @} | |
1041a570 | 3995 | @end group |
70b88761 RP |
3996 | @end example |
3997 | ||
3998 | @item set print pretty off | |
3999 | Cause _GDBN__ to print structures in a compact format, like this: | |
4000 | ||
4001 | @smallexample | |
1041a570 | 4002 | @group |
38962738 RP |
4003 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \ |
4004 | meat = 0x54 "Pork"@} | |
1041a570 | 4005 | @end group |
70b88761 RP |
4006 | @end smallexample |
4007 | ||
4008 | @noindent | |
4009 | This is the default format. | |
4010 | ||
4011 | @item show print pretty | |
4012 | @kindex show print pretty | |
4013 | Show which format _GDBN__ will use to print structures. | |
4014 | ||
4015 | @item set print sevenbit-strings on | |
f2857bd9 | 4016 | @kindex set print sevenbit-strings |
e251e767 | 4017 | Print using only seven-bit characters; if this option is set, |
70b88761 RP |
4018 | _GDBN__ will display any eight-bit characters (in strings or character |
4019 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
4020 | displayed as @code{\341}. | |
4021 | ||
4022 | @item set print sevenbit-strings off | |
4023 | Print using either seven-bit or eight-bit characters, as required. This | |
4024 | is the default. | |
4025 | ||
4026 | @item show print sevenbit-strings | |
f2857bd9 | 4027 | @kindex show print sevenbit-strings |
70b88761 RP |
4028 | Show whether or not _GDBN__ will print only seven-bit characters. |
4029 | ||
4030 | @item set print union on | |
4031 | @kindex set print union | |
4032 | Tell _GDBN__ to print unions which are contained in structures. This is the | |
4033 | default setting. | |
4034 | ||
4035 | @item set print union off | |
4036 | Tell _GDBN__ not to print unions which are contained in structures. | |
4037 | ||
4038 | @item show print union | |
4039 | @kindex show print union | |
4040 | Ask _GDBN__ whether or not it will print unions which are contained in | |
e251e767 | 4041 | structures. |
70b88761 RP |
4042 | |
4043 | For example, given the declarations | |
4044 | ||
4045 | @smallexample | |
4046 | typedef enum @{Tree, Bug@} Species; | |
4047 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
4048 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
4049 | Bug_forms; | |
70b88761 RP |
4050 | |
4051 | struct thing @{ | |
4052 | Species it; | |
4053 | union @{ | |
4054 | Tree_forms tree; | |
4055 | Bug_forms bug; | |
4056 | @} form; | |
4057 | @}; | |
4058 | ||
4059 | struct thing foo = @{Tree, @{Acorn@}@}; | |
4060 | @end smallexample | |
4061 | ||
4062 | @noindent | |
4063 | with @code{set print union on} in effect @samp{p foo} would print | |
4064 | ||
4065 | @smallexample | |
4066 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
4067 | @end smallexample | |
4068 | ||
4069 | @noindent | |
4070 | and with @code{set print union off} in effect it would print | |
4071 | ||
4072 | @smallexample | |
4073 | $1 = @{it = Tree, form = @{...@}@} | |
4074 | @end smallexample | |
4075 | @end table | |
4076 | ||
4077 | @noindent | |
4078 | These settings are of interest when debugging C++ programs: | |
4079 | ||
4080 | @table @code | |
e251e767 RP |
4081 | @item set print demangle |
4082 | @itemx set print demangle on | |
70b88761 RP |
4083 | @kindex set print demangle |
4084 | Print C++ names in their source form rather than in the mangled form | |
4085 | in which they are passed to the assembler and linker for type-safe linkage. | |
4086 | The default is on. | |
4087 | ||
4088 | @item show print demangle | |
4089 | @kindex show print demangle | |
4090 | Show whether C++ names will be printed in mangled or demangled form. | |
4091 | ||
e251e767 RP |
4092 | @item set print asm-demangle |
4093 | @itemx set print asm-demangle on | |
70b88761 RP |
4094 | @kindex set print asm-demangle |
4095 | Print C++ names in their source form rather than their mangled form, even | |
4096 | in assembler code printouts such as instruction disassemblies. | |
4097 | The default is off. | |
4098 | ||
4099 | @item show print asm-demangle | |
4100 | @kindex show print asm-demangle | |
4101 | Show whether C++ names in assembly listings will be printed in mangled | |
4102 | or demangled form. | |
4103 | ||
4104 | @item set print object | |
4105 | @itemx set print object on | |
4106 | @kindex set print object | |
4107 | When displaying a pointer to an object, identify the @emph{actual} | |
4108 | (derived) type of the object rather than the @emph{declared} type, using | |
4109 | the virtual function table. | |
4110 | ||
4111 | @item set print object off | |
4112 | Display only the declared type of objects, without reference to the | |
4113 | virtual function table. This is the default setting. | |
4114 | ||
4115 | @item show print object | |
4116 | @kindex show print object | |
4117 | Show whether actual, or declared, object types will be displayed. | |
4118 | ||
e251e767 RP |
4119 | @item set print vtbl |
4120 | @itemx set print vtbl on | |
70b88761 RP |
4121 | @kindex set print vtbl |
4122 | Pretty print C++ virtual function tables. The default is off. | |
4123 | ||
4124 | @item set print vtbl off | |
4125 | Do not pretty print C++ virtual function tables. | |
4126 | ||
4127 | @item show print vtbl | |
4128 | @kindex show print vtbl | |
4129 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 RP |
4130 | @end table |
4131 | ||
4eb4cf57 | 4132 | @node Value History |
70b88761 RP |
4133 | @section Value History |
4134 | ||
4135 | @cindex value history | |
4136 | Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value | |
4137 | history} so that you can refer to them in other expressions. Values are | |
4138 | kept until the symbol table is re-read or discarded (for example with | |
4139 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
4140 | changes, the value history is discarded, since the values may contain | |
4141 | pointers back to the types defined in the symbol table. | |
4142 | ||
4143 | @cindex @code{$} | |
4144 | @cindex @code{$$} | |
4145 | @cindex history number | |
4146 | The values printed are given @dfn{history numbers} for you to refer to them | |
4147 | by. These are successive integers starting with one. @code{print} shows you | |
4148 | the history number assigned to a value by printing @samp{$@var{num} = } | |
4149 | before the value; here @var{num} is the history number. | |
4150 | ||
4151 | To refer to any previous value, use @samp{$} followed by the value's | |
4152 | history number. The way @code{print} labels its output is designed to | |
4153 | remind you of this. Just @code{$} refers to the most recent value in | |
4154 | the history, and @code{$$} refers to the value before that. | |
4155 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
4156 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
4157 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
4158 | ||
4159 | For example, suppose you have just printed a pointer to a structure and | |
4160 | want to see the contents of the structure. It suffices to type | |
4161 | ||
4162 | @example | |
4163 | p *$ | |
4164 | @end example | |
4165 | ||
4166 | If you have a chain of structures where the component @code{next} points | |
4167 | to the next one, you can print the contents of the next one with this: | |
4168 | ||
4169 | @example | |
4170 | p *$.next | |
4171 | @end example | |
4172 | ||
4173 | @noindent | |
4174 | You can print successive links in the chain by repeating this | |
4175 | command---which you can do by just typing @key{RET}. | |
4176 | ||
4177 | Note that the history records values, not expressions. If the value of | |
4178 | @code{x} is 4 and you type these commands: | |
4179 | ||
4180 | @example | |
4181 | print x | |
4182 | set x=5 | |
4183 | @end example | |
4184 | ||
4185 | @noindent | |
4186 | then the value recorded in the value history by the @code{print} command | |
4187 | remains 4 even though the value of @code{x} has changed. | |
4188 | ||
4189 | @table @code | |
4190 | @kindex show values | |
4191 | @item show values | |
4192 | Print the last ten values in the value history, with their item numbers. | |
4193 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
4194 | values} does not change the history. | |
4195 | ||
4196 | @item show values @var{n} | |
4197 | Print ten history values centered on history item number @var{n}. | |
4198 | ||
4199 | @item show values + | |
4200 | Print ten history values just after the values last printed. If no more | |
4201 | values are available, produces no display. | |
4202 | @end table | |
4203 | ||
4204 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 4205 | same effect as @samp{show values +}. |
70b88761 | 4206 | |
4eb4cf57 | 4207 | @node Convenience Vars |
70b88761 RP |
4208 | @section Convenience Variables |
4209 | ||
4210 | @cindex convenience variables | |
4211 | _GDBN__ provides @dfn{convenience variables} that you can use within | |
4212 | _GDBN__ to hold on to a value and refer to it later. These variables | |
4213 | exist entirely within _GDBN__; they are not part of your program, and | |
4214 | setting a convenience variable has no direct effect on further execution | |
1041a570 | 4215 | of your program. That is why you can use them freely. |
70b88761 RP |
4216 | |
4217 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
4218 | @samp{$} can be used for a convenience variable, unless it is one of | |
4219 | the predefined machine-specific register names (@pxref{Registers}). | |
4220 | (Value history references, in contrast, are @emph{numbers} preceded | |
1041a570 | 4221 | by @samp{$}. @xref{Value History, ,Value History}.) |
70b88761 RP |
4222 | |
4223 | You can save a value in a convenience variable with an assignment | |
4224 | expression, just as you would set a variable in your program. Example: | |
4225 | ||
4226 | @example | |
4227 | set $foo = *object_ptr | |
4228 | @end example | |
4229 | ||
4230 | @noindent | |
4231 | would save in @code{$foo} the value contained in the object pointed to by | |
4232 | @code{object_ptr}. | |
4233 | ||
4234 | Using a convenience variable for the first time creates it; but its value | |
4235 | is @code{void} until you assign a new value. You can alter the value with | |
4236 | another assignment at any time. | |
4237 | ||
4238 | Convenience variables have no fixed types. You can assign a convenience | |
4239 | variable any type of value, including structures and arrays, even if | |
4240 | that variable already has a value of a different type. The convenience | |
4241 | variable, when used as an expression, has the type of its current value. | |
4242 | ||
4243 | @table @code | |
4244 | @item show convenience | |
4245 | @kindex show convenience | |
4246 | Print a list of convenience variables used so far, and their values. | |
4247 | Abbreviated @code{show con}. | |
4248 | @end table | |
4249 | ||
4250 | One of the ways to use a convenience variable is as a counter to be | |
4251 | incremented or a pointer to be advanced. For example, to print | |
4252 | a field from successive elements of an array of structures: | |
4253 | ||
4254 | _0__@example | |
4255 | set $i = 0 | |
4256 | print bar[$i++]->contents | |
4257 | @i{@dots{} repeat that command by typing @key{RET}.} | |
4258 | _1__@end example | |
4259 | ||
4260 | Some convenience variables are created automatically by _GDBN__ and given | |
4261 | values likely to be useful. | |
4262 | ||
4263 | @table @code | |
4264 | @item $_ | |
c338a2fd | 4265 | @kindex $_ |
70b88761 | 4266 | The variable @code{$_} is automatically set by the @code{x} command to |
29a2b744 RP |
4267 | the last address examined (@pxref{Memory, ,Examining Memory}). Other |
4268 | commands which provide a default address for @code{x} to examine also | |
4269 | set @code{$_} to that address; these commands include @code{info line} | |
4270 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4271 | except when set by the @code{x} command, in which case it is a pointer | |
4272 | to the type of @code{$__}. | |
70b88761 RP |
4273 | |
4274 | @item $__ | |
c338a2fd | 4275 | @kindex $__ |
70b88761 | 4276 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
4277 | to the value found in the last address examined. Its type is chosen |
4278 | to match the format in which the data was printed. | |
70b88761 RP |
4279 | @end table |
4280 | ||
4eb4cf57 | 4281 | @node Registers |
70b88761 RP |
4282 | @section Registers |
4283 | ||
4284 | @cindex registers | |
b80282d5 | 4285 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
4286 | with names starting with @samp{$}. The names of registers are different |
4287 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 4288 | your machine. |
70b88761 RP |
4289 | |
4290 | @table @code | |
4291 | @item info registers | |
4292 | @kindex info registers | |
b80282d5 RP |
4293 | Print the names and values of all registers except floating-point |
4294 | registers (in the selected stack frame). | |
4295 | ||
4296 | @item info all-registers | |
4297 | @kindex info all-registers | |
4298 | @cindex floating point registers | |
4299 | Print the names and values of all registers, including floating-point | |
4300 | registers. | |
70b88761 | 4301 | |
4eb4cf57 | 4302 | @item info registers @var{regname} @dots{} |
0d1cd01e JG |
4303 | Print the relativized value of each specified register @var{regname}. |
4304 | @var{regname} may be any register name valid on the machine you are using, with | |
70b88761 RP |
4305 | or without the initial @samp{$}. |
4306 | @end table | |
4307 | ||
09267865 | 4308 | _GDBN__ has four ``standard'' register names that are available (in |
29a2b744 | 4309 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
4310 | architecture's canonical mnemonics for registers. The register names |
4311 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4312 | the stack pointer. @code{$fp} is used for a register that contains a | |
4313 | pointer to the current stack frame, and @code{$ps} is used for a | |
4314 | register that contains the processor status. For example, | |
70b88761 | 4315 | you could print the program counter in hex with |
1041a570 | 4316 | |
70b88761 RP |
4317 | @example |
4318 | p/x $pc | |
4319 | @end example | |
4320 | ||
4321 | @noindent | |
4322 | or print the instruction to be executed next with | |
1041a570 | 4323 | |
70b88761 RP |
4324 | @example |
4325 | x/i $pc | |
4326 | @end example | |
4327 | ||
4328 | @noindent | |
29a2b744 RP |
4329 | or add four to the stack pointer @footnote{This is a way of removing |
4330 | one word from the stack, on machines where stacks grow downward in | |
4331 | memory (most machines, nowadays). This assumes that the innermost | |
4332 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4333 | stack frames are selected. To pop entire frames off the stack, | |
4334 | regardless of machine architecture, use @code{return}; | |
1041a570 RP |
4335 | @pxref{Returning, ,Returning from a Function}.} with |
4336 | ||
70b88761 RP |
4337 | @example |
4338 | set $sp += 4 | |
4339 | @end example | |
4340 | ||
09267865 RP |
4341 | Whenever possible, these four standard register names are available on |
4342 | your machine even though the machine has different canonical mnemonics, | |
4343 | so long as there is no conflict. The @code{info registers} command | |
4344 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
4345 | registers} displays the processor status register as @code{$psr} but you |
4346 | can also refer to it as @code{$ps}. | |
4347 | ||
4348 | _GDBN__ always considers the contents of an ordinary register as an | |
4349 | integer when the register is examined in this way. Some machines have | |
4350 | special registers which can hold nothing but floating point; these | |
4351 | registers are considered to have floating point values. There is no way | |
4352 | to refer to the contents of an ordinary register as floating point value | |
4353 | (although you can @emph{print} it as a floating point value with | |
4354 | @samp{print/f $@var{regname}}). | |
4355 | ||
4356 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4357 | means that the data format in which the register contents are saved by | |
4358 | the operating system is not the same one that your program normally | |
4359 | sees. For example, the registers of the 68881 floating point | |
4360 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4361 | programs expect to work with ``double'' (virtual) format. In such | |
4362 | cases, _GDBN__ normally works with the virtual format only (the format that | |
4363 | makes sense for your program), but the @code{info registers} command | |
4364 | prints the data in both formats. | |
4365 | ||
4366 | Normally, register values are relative to the selected stack frame | |
29a2b744 RP |
4367 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the |
4368 | value that the register would contain if all stack frames farther in | |
4369 | were exited and their saved registers restored. In order to see the | |
4370 | true contents of hardware registers, you must select the innermost | |
4371 | frame (with @samp{frame 0}). | |
70b88761 RP |
4372 | |
4373 | However, _GDBN__ must deduce where registers are saved, from the machine | |
4374 | code generated by your compiler. If some registers are not saved, or if | |
4375 | _GDBN__ is unable to locate the saved registers, the selected stack | |
4376 | frame will make no difference. | |
4377 | ||
d8a68b28 | 4378 | _if__(_AMD29K__) |
03a77779 | 4379 | @table @code |
d8a68b28 JG |
4380 | @item set rstack_high_address @var{address} |
4381 | @kindex set rstack_high_address | |
03a77779 RP |
4382 | @cindex AMD 29K register stack |
4383 | @cindex register stack, AMD29K | |
4384 | On AMD 29000 family processors, registers are saved in a separate | |
4385 | ``register stack''. There is no way for _GDBN__ to determine the extent | |
4386 | of this stack. Normally, _GDBN__ just assumes that the stack is ``large | |
4387 | enough''. This may result in _GDBN__ referencing memory locations that | |
4388 | don't exist. If necessary, you can get around this problem by | |
4389 | specifying the ending address of the register stack with the @code{set | |
4390 | rstack_high_address} command. The argument should be an address, which | |
4391 | you will probably want to precede with @samp{0x} to specify in | |
4392 | hexadecimal. | |
d8a68b28 JG |
4393 | |
4394 | @item show rstack_high_address | |
4395 | @kindex show rstack_high_address | |
03a77779 RP |
4396 | Display the current limit of the register stack, on AMD 29000 family |
4397 | processors. | |
4398 | @end table | |
d8a68b28 JG |
4399 | _fi__(_AMD29K__) |
4400 | ||
4eb4cf57 RP |
4401 | _if__(_GENERIC__ || !_H8__) |
4402 | @node Floating Point Hardware | |
70b88761 RP |
4403 | @section Floating Point Hardware |
4404 | @cindex floating point | |
1041a570 | 4405 | |
70b88761 RP |
4406 | Depending on the host machine architecture, _GDBN__ may be able to give |
4407 | you more information about the status of the floating point hardware. | |
4408 | ||
4409 | @table @code | |
4410 | @item info float | |
4411 | @kindex info float | |
4412 | If available, provides hardware-dependent information about the floating | |
4413 | point unit. The exact contents and layout vary depending on the | |
4414 | floating point chip. | |
4415 | @end table | |
4416 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
4417 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
4418 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 | 4419 | @c FIXME... at that point. |
4eb4cf57 | 4420 | _fi__(_GENERIC__ || !_H8__) |
70b88761 | 4421 | |
4eb4cf57 RP |
4422 | _if__(!_CONLY__) |
4423 | @node Languages | |
c2bbbb22 RP |
4424 | @chapter Using _GDBN__ with Different Languages |
4425 | @cindex languages | |
4426 | ||
4427 | Although programming languages generally have common aspects, they are | |
4428 | rarely expressed in the same manner. For instance, in ANSI C, | |
4429 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4430 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4431 | represented (and displayed) differently. Hex numbers in C are written | |
4432 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4433 | ||
4434 | @cindex working language | |
4435 | Language-specific information is built into _GDBN__ for some languages, | |
29a2b744 | 4436 | allowing you to express operations like the above in your program's |
c2bbbb22 | 4437 | native language, and allowing _GDBN__ to output values in a manner |
29a2b744 | 4438 | consistent with the syntax of your program's native language. The |
c2bbbb22 RP |
4439 | language you use to build expressions, called the @dfn{working |
4440 | language}, can be selected manually, or _GDBN__ can set it | |
4441 | automatically. | |
4442 | ||
4443 | @menu | |
4444 | * Setting:: Switching between source languages | |
4445 | * Show:: Displaying the language | |
4446 | * Checks:: Type and Range checks | |
4447 | * Support:: Supported languages | |
4448 | @end menu | |
4449 | ||
4eb4cf57 | 4450 | @node Setting |
c2bbbb22 RP |
4451 | @section Switching between source languages |
4452 | ||
4453 | There are two ways to control the working language---either have _GDBN__ | |
4454 | set it automatically, or select it manually yourself. You can use the | |
4455 | @code{set language} command for either purpose. On startup, _GDBN__ | |
4456 | defaults to setting the language automatically. | |
4457 | ||
4458 | @menu | |
4459 | * Manually:: Setting the working language manually | |
4460 | * Automatically:: Having _GDBN__ infer the source language | |
4461 | @end menu | |
4462 | ||
4eb4cf57 | 4463 | @node Manually |
c2bbbb22 RP |
4464 | @subsection Setting the working language |
4465 | ||
4466 | @kindex set language | |
4467 | To set the language, issue the command @samp{set language @var{lang}}, | |
c338a2fd RP |
4468 | where @var{lang} is the name of a language: @code{c} or @code{modula-2}. |
4469 | For a list of the supported languages, type @samp{set language}. | |
c2bbbb22 RP |
4470 | |
4471 | Setting the language manually prevents _GDBN__ from updating the working | |
4472 | language automatically. This can lead to confusion if you try | |
4473 | to debug a program when the working language is not the same as the | |
4474 | source language, when an expression is acceptable to both | |
4475 | languages---but means different things. For instance, if the current | |
4476 | source file were written in C, and _GDBN__ was parsing Modula-2, a | |
4477 | command such as: | |
4478 | ||
4479 | @example | |
4480 | print a = b + c | |
4481 | @end example | |
4482 | ||
4483 | @noindent | |
4484 | might not have the effect you intended. In C, this means to add | |
4485 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4486 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4487 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4488 | ||
4489 | If you allow _GDBN__ to set the language automatically, then | |
4490 | you can count on expressions evaluating the same way in your debugging | |
4491 | session and in your program. | |
4492 | ||
4eb4cf57 | 4493 | @node Automatically |
c2bbbb22 RP |
4494 | @subsection Having _GDBN__ infer the source language |
4495 | ||
4496 | To have _GDBN__ set the working language automatically, use @samp{set | |
4497 | language local} or @samp{set language auto}. _GDBN__ then infers the | |
4498 | language that a program was written in by looking at the name of its | |
4499 | source files, and examining their extensions: | |
4500 | ||
4501 | @table @file | |
4502 | @item *.mod | |
4503 | Modula-2 source file | |
4504 | ||
4505 | @item *.c | |
5a2c1d85 RP |
4506 | C source file |
4507 | ||
4508 | @item *.C | |
c2bbbb22 | 4509 | @itemx *.cc |
5a2c1d85 | 4510 | C++ source file |
c2bbbb22 RP |
4511 | @end table |
4512 | ||
4513 | This information is recorded for each function or procedure in a source | |
4514 | file. When your program stops in a frame (usually by encountering a | |
4515 | breakpoint), _GDBN__ sets the working language to the language recorded | |
4516 | for the function in that frame. If the language for a frame is unknown | |
4517 | (that is, if the function or block corresponding to the frame was | |
4518 | defined in a source file that does not have a recognized extension), the | |
4519 | current working language is not changed, and _GDBN__ issues a warning. | |
4520 | ||
4521 | This may not seem necessary for most programs, which are written | |
4522 | entirely in one source language. However, program modules and libraries | |
4523 | written in one source language can be used by a main program written in | |
4524 | a different source language. Using @samp{set language auto} in this | |
4525 | case frees you from having to set the working language manually. | |
4526 | ||
4eb4cf57 | 4527 | @node Show |
c2bbbb22 RP |
4528 | @section Displaying the language |
4529 | ||
4530 | The following commands will help you find out which language is the | |
4531 | working language, and also what language source files were written in. | |
4532 | ||
4533 | @kindex show language | |
4534 | @kindex info frame | |
4535 | @kindex info source | |
4536 | @table @code | |
4537 | @item show language | |
4538 | Display the current working language. This is the | |
4539 | language you can use with commands such as @code{print} to | |
29a2b744 | 4540 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
4541 | |
4542 | @item info frame | |
1041a570 | 4543 | Among the other information listed here (@pxref{Frame Info, ,Information |
c2bbbb22 RP |
4544 | about a Frame}) is the source language for this frame. This is the |
4545 | language that will become the working language if you ever use an | |
4546 | identifier that is in this frame. | |
4547 | ||
4548 | @item info source | |
1041a570 | 4549 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 4550 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
4551 | @end table |
4552 | ||
4eb4cf57 | 4553 | @node Checks |
c2bbbb22 RP |
4554 | @section Type and range Checking |
4555 | ||
4556 | @quotation | |
4557 | @emph{Warning:} In this release, the _GDBN__ commands for type and range | |
4558 | checking are included, but they do not yet have any effect. This | |
4559 | section documents the intended facilities. | |
4560 | @end quotation | |
4561 | @c FIXME remove warning when type/range code added | |
4562 | ||
4563 | Some languages are designed to guard you against making seemingly common | |
4564 | errors through a series of compile- and run-time checks. These include | |
4565 | checking the type of arguments to functions and operators, and making | |
4566 | sure mathematical overflows are caught at run time. Checks such as | |
4567 | these help to ensure a program's correctness once it has been compiled | |
4568 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 4569 | errors when your program is running. |
c2bbbb22 | 4570 | |
1041a570 RP |
4571 | _GDBN__ can check for conditions like the above if you wish. |
4572 | Although _GDBN__ will not check the statements in your program, it | |
4573 | can check expressions entered directly into _GDBN__ for evaluation via | |
4574 | the @code{print} command, for example. As with the working language, | |
c2bbbb22 | 4575 | _GDBN__ can also decide whether or not to check automatically based on |
1041a570 RP |
4576 | your program's source language. @xref{Support, ,Supported Languages}, |
4577 | for the default settings of supported languages. | |
c2bbbb22 RP |
4578 | |
4579 | @menu | |
4580 | * Type Checking:: An overview of type checking | |
4581 | * Range Checking:: An overview of range checking | |
4582 | @end menu | |
4583 | ||
4584 | @cindex type checking | |
4585 | @cindex checks, type | |
4eb4cf57 | 4586 | @node Type Checking |
c2bbbb22 RP |
4587 | @subsection An overview of type checking |
4588 | ||
4589 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4590 | arguments to operators and functions have to be of the correct type, | |
4591 | otherwise an error occurs. These checks prevent type mismatch | |
4592 | errors from ever causing any run-time problems. For example, | |
4593 | ||
4594 | @example | |
4595 | 1 + 2 @result{} 3 | |
1041a570 | 4596 | @exdent but |
c2bbbb22 RP |
4597 | @error{} 1 + 2.3 |
4598 | @end example | |
4599 | ||
4600 | The second example fails because the @code{CARDINAL} 1 is not | |
4601 | type-compatible with the @code{REAL} 2.3. | |
4602 | ||
4603 | For expressions you use in _GDBN__ commands, you can tell the _GDBN__ | |
4604 | type checker to skip checking; to treat any mismatches as errors and | |
4605 | abandon the expression; or only issue warnings when type mismatches | |
4606 | occur, but evaluate the expression anyway. When you choose the last of | |
4607 | these, _GDBN__ evaluates expressions like the second example above, but | |
4608 | also issues a warning. | |
4609 | ||
4610 | Even though you may turn type checking off, other type-based reasons may | |
4611 | prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not | |
4612 | know how to add an @code{int} and a @code{struct foo}. These particular | |
4613 | type errors have nothing to do with the language in use, and usually | |
4614 | arise from expressions, such as the one described above, which make | |
4615 | little sense to evaluate anyway. | |
4616 | ||
4617 | Each language defines to what degree it is strict about type. For | |
4618 | instance, both Modula-2 and C require the arguments to arithmetical | |
4619 | operators to be numbers. In C, enumerated types and pointers can be | |
4620 | represented as numbers, so that they are valid arguments to mathematical | |
1041a570 | 4621 | operators. @xref{Support, ,Supported Languages}, for further |
c2bbbb22 RP |
4622 | details on specific languages. |
4623 | ||
4624 | _GDBN__ provides some additional commands for controlling the type checker: | |
4625 | ||
4626 | @kindex set check | |
4627 | @kindex set check type | |
4628 | @kindex show check type | |
4629 | @table @code | |
4630 | @item set check type auto | |
e251e767 | 4631 | Set type checking on or off based on the current working language. |
1041a570 | 4632 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4633 | each language. |
4634 | ||
4635 | @item set check type on | |
4636 | @itemx set check type off | |
4637 | Set type checking on or off, overriding the default setting for the | |
4638 | current working language. Issue a warning if the setting does not | |
4639 | match the language's default. If any type mismatches occur in | |
4640 | evaluating an expression while typechecking is on, _GDBN__ prints a | |
4641 | message and aborts evaluation of the expression. | |
4642 | ||
4643 | @item set check type warn | |
4644 | Cause the type checker to issue warnings, but to always attempt to | |
4645 | evaluate the expression. Evaluating the expression may still | |
4646 | be impossible for other reasons. For example, _GDBN__ cannot add | |
4647 | numbers and structures. | |
4648 | ||
4649 | @item show type | |
e251e767 | 4650 | Show the current setting of the type checker, and whether or not _GDBN__ is |
c2bbbb22 RP |
4651 | setting it automatically. |
4652 | @end table | |
4653 | ||
4654 | @cindex range checking | |
4655 | @cindex checks, range | |
4eb4cf57 | 4656 | @node Range Checking |
c2bbbb22 RP |
4657 | @subsection An overview of Range Checking |
4658 | ||
4659 | In some languages (such as Modula-2), it is an error to exceed the | |
4660 | bounds of a type; this is enforced with run-time checks. Such range | |
4661 | checking is meant to ensure program correctness by making sure | |
4662 | computations do not overflow, or indices on an array element access do | |
4663 | not exceed the bounds of the array. | |
4664 | ||
4665 | For expressions you use in _GDBN__ commands, you can tell _GDBN__ to | |
4666 | ignore range errors; to always treat them as errors and abandon the | |
4667 | expression; or to issue warnings when a range error occurs but evaluate | |
4668 | the expression anyway. | |
4669 | ||
4670 | A range error can result from numerical overflow, from exceeding an | |
4671 | array index bound, or when you type in a constant that is not a member | |
4672 | of any type. Some languages, however, do not treat overflows as an | |
4673 | error. In many implementations of C, mathematical overflow causes the | |
4674 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4675 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 4676 | |
c2bbbb22 RP |
4677 | @example |
4678 | @var{m} + 1 @result{} @var{s} | |
4679 | @end example | |
4680 | ||
4681 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 4682 | specific to individual compilers or machines. @xref{Support, , |
c2bbbb22 RP |
4683 | Supported Languages}, for further details on specific languages. |
4684 | ||
4685 | _GDBN__ provides some additional commands for controlling the range checker: | |
4686 | ||
4687 | @kindex set check | |
4688 | @kindex set check range | |
4689 | @kindex show check range | |
4690 | @table @code | |
4691 | @item set check range auto | |
e251e767 | 4692 | Set range checking on or off based on the current working language. |
1041a570 | 4693 | @xref{Support, ,Supported Languages}, for the default settings for |
c2bbbb22 RP |
4694 | each language. |
4695 | ||
4696 | @item set check range on | |
4697 | @itemx set check range off | |
4698 | Set range checking on or off, overriding the default setting for the | |
4699 | current working language. A warning is issued if the setting does not | |
4700 | match the language's default. If a range error occurs, then a message | |
4701 | is printed and evaluation of the expression is aborted. | |
4702 | ||
4703 | @item set check range warn | |
4704 | Output messages when the _GDBN__ range checker detects a range error, | |
4705 | but attempt to evaluate the expression anyway. Evaluating the | |
4706 | expression may still be impossible for other reasons, such as accessing | |
4707 | memory that the process does not own (a typical example from many UNIX | |
4708 | systems). | |
4709 | ||
4710 | @item show range | |
e251e767 | 4711 | Show the current setting of the range checker, and whether or not it is |
c2bbbb22 RP |
4712 | being set automatically by _GDBN__. |
4713 | @end table | |
4714 | ||
4eb4cf57 | 4715 | @node Support |
c2bbbb22 RP |
4716 | @section Supported Languages |
4717 | ||
5a2c1d85 | 4718 | _GDBN__ 4 supports C, C++, and Modula-2. Some _GDBN__ |
1041a570 RP |
4719 | features may be used in expressions regardless of the language you |
4720 | use: the _GDBN__ @code{@@} and @code{::} operators, and the | |
4721 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be | |
4722 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
4723 | |
4724 | The following sections detail to what degree each of these | |
4725 | source languages is supported by _GDBN__. These sections are | |
4726 | not meant to be language tutorials or references, but serve only as a | |
4727 | reference guide to what the _GDBN__ expression parser will accept, and | |
4728 | what input and output formats should look like for different languages. | |
4729 | There are many good books written on each of these languages; please | |
4730 | look to these for a language reference or tutorial. | |
4731 | ||
4732 | @menu | |
4733 | * C:: C and C++ | |
4734 | * Modula-2:: Modula-2 | |
4735 | @end menu | |
4736 | ||
4eb4cf57 | 4737 | @node C |
c2bbbb22 RP |
4738 | @subsection C and C++ |
4739 | @cindex C and C++ | |
c2bbbb22 | 4740 | @cindex expressions in C or C++ |
0f153e74 | 4741 | |
5a2c1d85 RP |
4742 | Since C and C++ are so closely related, many features of _GDBN__ apply |
4743 | to both languages. Whenever this is the case, we discuss both languages | |
4744 | together. | |
b80282d5 RP |
4745 | |
4746 | @cindex C++ | |
4747 | @kindex g++ | |
4748 | @cindex GNU C++ | |
c2bbbb22 RP |
4749 | The C++ debugging facilities are jointly implemented by the GNU C++ |
4750 | compiler and _GDBN__. Therefore, to debug your C++ code effectively, | |
4751 | you must compile your C++ programs with the GNU C++ compiler, | |
4752 | @code{g++}. | |
0f153e74 RP |
4753 | _fi__(!_CONLY__) |
4754 | _if__(_CONLY__) | |
4755 | @node C | |
4756 | @chapter C Language Support | |
4757 | @cindex C language | |
4758 | @cindex expressions in C | |
4759 | ||
4760 | Information specific to the C language is built into _GDBN__ so that you | |
4761 | can use C expressions while degugging. This also permits _GDBN__ to | |
4762 | output values in a manner consistent with C conventions. | |
c2bbbb22 | 4763 | |
0f153e74 RP |
4764 | @menu |
4765 | * C Operators:: C Operators | |
4766 | * C Constants:: C Constants | |
4767 | * Debugging C:: _GDBN__ and C | |
4768 | @end menu | |
4769 | _fi__(_CONLY__) | |
4770 | _if__(!_CONLY__) | |
b80282d5 | 4771 | @menu |
c2bbbb22 RP |
4772 | * C Operators:: C and C++ Operators |
4773 | * C Constants:: C and C++ Constants | |
4774 | * Cplusplus expressions:: C++ Expressions | |
4775 | * C Defaults:: Default settings for C and C++ | |
4776 | * C Checks:: C and C++ Type and Range Checks | |
4777 | * Debugging C:: _GDBN__ and C | |
4778 | * Debugging C plus plus:: Special features for C++ | |
b80282d5 | 4779 | @end menu |
0f153e74 | 4780 | _fi__(!_CONLY__) |
b80282d5 | 4781 | |
0f153e74 | 4782 | _if__(!_CONLY__) |
c2bbbb22 | 4783 | @cindex C and C++ operators |
4eb4cf57 | 4784 | @node C Operators |
c2bbbb22 | 4785 | @subsubsection C and C++ Operators |
4eb4cf57 RP |
4786 | _fi__(!_CONLY__) |
4787 | _if__(_CONLY__) | |
0f153e74 RP |
4788 | @cindex C operators |
4789 | @node C Operators | |
4790 | @section C Operators | |
4eb4cf57 | 4791 | _fi__(_CONLY__) |
c2bbbb22 RP |
4792 | |
4793 | Operators must be defined on values of specific types. For instance, | |
4794 | @code{+} is defined on numbers, but not on structures. Operators are | |
0f153e74 RP |
4795 | often defined on groups of types. |
4796 | ||
4797 | _if__(!_CONLY__) | |
4798 | For the purposes of C and C++, the following definitions hold: | |
4799 | _fi__(!_CONLY__) | |
c2bbbb22 RP |
4800 | |
4801 | @itemize @bullet | |
e251e767 | 4802 | @item |
c2bbbb22 RP |
4803 | @emph{Integral types} include @code{int} with any of its storage-class |
4804 | specifiers, @code{char}, and @code{enum}s. | |
4805 | ||
4806 | @item | |
4807 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4808 | ||
4809 | @item | |
4810 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4811 | *)}. | |
4812 | ||
e251e767 | 4813 | @item |
c2bbbb22 | 4814 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
4815 | @end itemize |
4816 | ||
4817 | @noindent | |
4818 | The following operators are supported. They are listed here | |
4819 | in order of increasing precedence: | |
4820 | ||
4821 | @table @code | |
1041a570 | 4822 | _0__@item , |
c2bbbb22 RP |
4823 | The comma or sequencing operator. Expressions in a comma-separated list |
4824 | are evaluated from left to right, with the result of the entire | |
4825 | expression being the last expression evaluated. | |
4826 | ||
4827 | @item = | |
4828 | Assignment. The value of an assignment expression is the value | |
4829 | assigned. Defined on scalar types. | |
4830 | ||
4831 | @item @var{op}= | |
1041a570 RP |
4832 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
4833 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
4834 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
4835 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
4836 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
4837 | |
4838 | @item ?: | |
4839 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
4840 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
4841 | integral type. | |
4842 | ||
4843 | @item || | |
1041a570 | 4844 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4845 | |
4846 | @item && | |
1041a570 | 4847 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4848 | |
4849 | @item | | |
1041a570 | 4850 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
4851 | |
4852 | @item ^ | |
1041a570 | 4853 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
4854 | |
4855 | @item & | |
1041a570 | 4856 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
4857 | |
4858 | @item ==@r{, }!= | |
4859 | Equality and inequality. Defined on scalar types. The value of these | |
4860 | expressions is 0 for false and non-zero for true. | |
4861 | ||
4862 | @item <@r{, }>@r{, }<=@r{, }>= | |
4863 | Less than, greater than, less than or equal, greater than or equal. | |
4864 | Defined on scalar types. The value of these expressions is 0 for false | |
4865 | and non-zero for true. | |
4866 | ||
4867 | @item <<@r{, }>> | |
0f153e74 | 4868 | left shift, and right shift. Defined on integral types._1__ |
c2bbbb22 | 4869 | |
e251e767 | 4870 | @item @@ |
1041a570 | 4871 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
4872 | |
4873 | @item +@r{, }- | |
4874 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 4875 | pointer types. |
c2bbbb22 RP |
4876 | |
4877 | @item *@r{, }/@r{, }% | |
4878 | Multiplication, division, and modulus. Multiplication and division are | |
4879 | defined on integral and floating-point types. Modulus is defined on | |
4880 | integral types. | |
4881 | ||
4882 | @item ++@r{, }-- | |
4883 | Increment and decrement. When appearing before a variable, the | |
4884 | operation is performed before the variable is used in an expression; | |
4885 | when appearing after it, the variable's value is used before the | |
4886 | operation takes place. | |
4887 | ||
4888 | @item * | |
4889 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
4890 | @code{++}. | |
4891 | ||
4892 | @item & | |
4893 | Address operator. Defined on variables. Same precedence as @code{++}. | |
4894 | ||
0f153e74 | 4895 | _if__(!_CONLY__) |
6ca72cc6 RP |
4896 | For debugging C++, _GDBN__ implements a use of @samp{&} beyond what's |
4897 | allowed in the C++ language itself: you can use @samp{&(&@var{ref})} | |
4898 | (or, if you prefer, simply @samp{&&@var{ref}} to examine the address | |
4899 | where a C++ reference variable (declared with @samp{&@var{ref}}) is | |
4900 | stored. | |
0f153e74 | 4901 | _fi__(!_CONLY__) |
6ca72cc6 | 4902 | |
c2bbbb22 RP |
4903 | @item - |
4904 | Negative. Defined on integral and floating-point types. Same | |
4905 | precedence as @code{++}. | |
4906 | ||
4907 | @item ! | |
4908 | Logical negation. Defined on integral types. Same precedence as | |
4909 | @code{++}. | |
4910 | ||
4911 | @item ~ | |
4912 | Bitwise complement operator. Defined on integral types. Same precedence as | |
4913 | @code{++}. | |
4914 | ||
0f153e74 | 4915 | _0__ |
c2bbbb22 RP |
4916 | @item .@r{, }-> |
4917 | Structure member, and pointer-to-structure member. For convenience, | |
4918 | _GDBN__ regards the two as equivalent, choosing whether to dereference a | |
e251e767 | 4919 | pointer based on the stored type information. |
c2bbbb22 RP |
4920 | Defined on @code{struct}s and @code{union}s. |
4921 | ||
4922 | @item [] | |
4923 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
4924 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
4925 | ||
4926 | @item () | |
0f153e74 | 4927 | Function parameter list. Same precedence as @code{->}._1__ |
c2bbbb22 | 4928 | |
0f153e74 | 4929 | _if__(!_CONLY__) |
c2bbbb22 RP |
4930 | @item :: |
4931 | C++ scope resolution operator. Defined on | |
4932 | @code{struct}, @code{union}, and @code{class} types. | |
0f153e74 | 4933 | _fi__(!_CONLY__) |
c2bbbb22 RP |
4934 | |
4935 | @item :: | |
0f153e74 RP |
4936 | The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}). |
4937 | _if__(!_CONLY__) | |
4938 | Same precedence as @code{::}, above. | |
4939 | _fi__(!_CONLY__) | |
c2bbbb22 RP |
4940 | @end table |
4941 | ||
0f153e74 | 4942 | _if__(!_CONLY__) |
c2bbbb22 | 4943 | @cindex C and C++ constants |
4eb4cf57 | 4944 | @node C Constants |
c2bbbb22 | 4945 | @subsubsection C and C++ Constants |
0f153e74 RP |
4946 | |
4947 | _GDBN__ allows you to express the constants of C and C++ in the | |
4948 | following ways: | |
4eb4cf57 RP |
4949 | _fi__(!_CONLY__) |
4950 | _if__(_CONLY__) | |
0f153e74 RP |
4951 | @cindex C constants |
4952 | @node C Constants | |
4953 | @section C Constants | |
c2bbbb22 | 4954 | |
0f153e74 | 4955 | _GDBN__ allows you to express the constants of C in the |
c2bbbb22 | 4956 | following ways: |
0f153e74 | 4957 | _fi__(_CONLY__) |
c2bbbb22 RP |
4958 | |
4959 | @itemize @bullet | |
c2bbbb22 RP |
4960 | @item |
4961 | Integer constants are a sequence of digits. Octal constants are | |
4962 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 4963 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
4964 | @samp{l}, specifying that the constant should be treated as a |
4965 | @code{long} value. | |
4966 | ||
4967 | @item | |
4968 | Floating point constants are a sequence of digits, followed by a decimal | |
4969 | point, followed by a sequence of digits, and optionally followed by an | |
4970 | exponent. An exponent is of the form: | |
4971 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
4972 | sequence of digits. The @samp{+} is optional for positive exponents. | |
4973 | ||
4974 | @item | |
4975 | Enumerated constants consist of enumerated identifiers, or their | |
4976 | integral equivalents. | |
4977 | ||
4978 | @item | |
4979 | Character constants are a single character surrounded by single quotes | |
4980 | (@code{'}), or a number---the ordinal value of the corresponding character | |
4981 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
4982 | be represented by a letter or by @dfn{escape sequences}, which are of | |
4983 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
4984 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
4985 | @samp{@var{x}} is a predefined special character---for example, | |
4986 | @samp{\n} for newline. | |
4987 | ||
4988 | @item | |
4989 | String constants are a sequence of character constants surrounded | |
4990 | by double quotes (@code{"}). | |
4991 | ||
4992 | @item | |
4993 | Pointer constants are an integral value. | |
c2bbbb22 RP |
4994 | @end itemize |
4995 | ||
4eb4cf57 | 4996 | _if__(!_CONLY__) |
0f153e74 | 4997 | @node Cplusplus expressions |
c2bbbb22 | 4998 | @subsubsection C++ Expressions |
b80282d5 RP |
4999 | |
5000 | @cindex expressions in C++ | |
b1385986 RP |
5001 | _GDBN__'s expression handling has a number of extensions to |
5002 | interpret a significant subset of C++ expressions. | |
5003 | ||
5004 | @cindex C++ support, not in @sc{coff} | |
5005 | @cindex @sc{coff} versus C++ | |
5006 | @cindex C++ and object formats | |
5007 | @cindex object formats and C++ | |
5008 | @cindex a.out and C++ | |
5009 | @cindex @sc{ecoff} and C++ | |
5010 | @cindex @sc{xcoff} and C++ | |
5011 | @cindex @sc{elf}/stabs and C++ | |
5012 | @cindex @sc{elf}/@sc{dwarf} and C++ | |
5013 | @quotation | |
5014 | @emph{Warning:} Most of these extensions depend on the use of additional | |
5015 | debugging information in the symbol table, and thus require a rich, | |
5016 | extendable object code format. In particular, if your system uses | |
5017 | a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs | |
5018 | extensions to the symbol table, these facilities are all available. | |
5019 | Where the object code format is standard @sc{coff}, on the other hand, | |
5020 | most of the C++ support in _GDBN__ will @emph{not} work, nor can it. | |
5021 | For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the | |
5022 | standard is still evolving, so the C++ support in _GDBN__ is still | |
5023 | fragile; when this debugging format stabilizes, however, C++ support | |
5024 | will also be available on systems that use it. | |
5025 | @end quotation | |
b80282d5 RP |
5026 | |
5027 | @enumerate | |
5028 | ||
5029 | @cindex member functions | |
e251e767 | 5030 | @item |
b80282d5 | 5031 | Member function calls are allowed; you can use expressions like |
1041a570 | 5032 | |
b80282d5 RP |
5033 | @example |
5034 | count = aml->GetOriginal(x, y) | |
5035 | @end example | |
5036 | ||
5037 | @kindex this | |
5038 | @cindex namespace in C++ | |
e251e767 | 5039 | @item |
b80282d5 RP |
5040 | While a member function is active (in the selected stack frame), your |
5041 | expressions have the same namespace available as the member function; | |
5042 | that is, _GDBN__ allows implicit references to the class instance | |
5043 | pointer @code{this} following the same rules as C++. | |
5044 | ||
5045 | @cindex call overloaded functions | |
5046 | @cindex type conversions in C++ | |
e251e767 | 5047 | @item |
b80282d5 RP |
5048 | You can call overloaded functions; _GDBN__ will resolve the function |
5049 | call to the right definition, with one restriction---you must use | |
5050 | arguments of the type required by the function that you want to call. | |
5051 | _GDBN__ will not perform conversions requiring constructors or | |
5052 | user-defined type operators. | |
5053 | ||
5054 | @cindex reference declarations | |
5055 | @item | |
5056 | _GDBN__ understands variables declared as C++ references; you can use them in | |
5057 | expressions just as you do in C++ source---they are automatically | |
e251e767 | 5058 | dereferenced. |
b80282d5 RP |
5059 | |
5060 | In the parameter list shown when _GDBN__ displays a frame, the values of | |
5061 | reference variables are not displayed (unlike other variables); this | |
5062 | avoids clutter, since references are often used for large structures. | |
5063 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 5064 | you have specified @samp{set print address off}. |
b80282d5 RP |
5065 | |
5066 | @item | |
5067 | _GDBN__ supports the C++ name resolution operator @code{::}---your | |
c2bbbb22 RP |
5068 | expressions can use it just as expressions in your program do. Since |
5069 | one scope may be defined in another, you can use @code{::} repeatedly if | |
5070 | necessary, for example in an expression like | |
5071 | @samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows | |
5072 | resolving name scope by reference to source files, in both C and C++ | |
1041a570 | 5073 | debugging (@pxref{Variables, ,Program Variables}). |
b80282d5 RP |
5074 | @end enumerate |
5075 | ||
4eb4cf57 | 5076 | @node C Defaults |
c2bbbb22 RP |
5077 | @subsubsection C and C++ Defaults |
5078 | @cindex C and C++ defaults | |
5079 | ||
e251e767 RP |
5080 | If you allow _GDBN__ to set type and range checking automatically, they |
5081 | both default to @code{off} whenever the working language changes to | |
5a2c1d85 | 5082 | C or C++. This happens regardless of whether you, or _GDBN__, |
c2bbbb22 RP |
5083 | selected the working language. |
5084 | ||
5085 | If you allow _GDBN__ to set the language automatically, it sets the | |
5a2c1d85 RP |
5086 | working language to C or C++ on entering code compiled from a source file |
5087 | whose name ends with @file{.c}, @file{.C}, or @file{.cc}. | |
1041a570 | 5088 | @xref{Automatically, ,Having _GDBN__ infer the source language}, for |
c2bbbb22 RP |
5089 | further details. |
5090 | ||
4eb4cf57 | 5091 | @node C Checks |
c2bbbb22 RP |
5092 | @subsubsection C and C++ Type and Range Checks |
5093 | @cindex C and C++ checks | |
5094 | ||
5095 | @quotation | |
5096 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5097 | range checking. | |
5098 | @end quotation | |
5099 | @c FIXME remove warning when type/range checks added | |
5100 | ||
5101 | By default, when _GDBN__ parses C or C++ expressions, type checking | |
5102 | is not used. However, if you turn type checking on, _GDBN__ will | |
5103 | consider two variables type equivalent if: | |
5104 | ||
5105 | @itemize @bullet | |
5106 | @item | |
5107 | The two variables are structured and have the same structure, union, or | |
5108 | enumerated tag. | |
5109 | ||
e251e767 | 5110 | @item |
c2bbbb22 RP |
5111 | Two two variables have the same type name, or types that have been |
5112 | declared equivalent through @code{typedef}. | |
5113 | ||
5114 | @ignore | |
5115 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
5116 | @c FIXME--beers? | |
5117 | @item | |
5118 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
5119 | declared in the same declaration. (Note: this may not be true for all C | |
5120 | compilers.) | |
5121 | @end ignore | |
c2bbbb22 RP |
5122 | @end itemize |
5123 | ||
5124 | Range checking, if turned on, is done on mathematical operations. Array | |
5125 | indices are not checked, since they are often used to index a pointer | |
5126 | that is not itself an array. | |
0f153e74 | 5127 | _fi__(!_CONLY__) |
c2bbbb22 | 5128 | |
4eb4cf57 RP |
5129 | @node Debugging C |
5130 | _if__(!_CONLY__) | |
c2bbbb22 | 5131 | @subsubsection _GDBN__ and C |
4eb4cf57 RP |
5132 | _fi__(!_CONLY__) |
5133 | _if__(_CONLY__) | |
5134 | @section _GDBN__ and C | |
5135 | _fi__(_CONLY__) | |
c2bbbb22 RP |
5136 | |
5137 | The @code{set print union} and @code{show print union} commands apply to | |
5138 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
5139 | inside a @code{struct} or @code{class} will also be printed. | |
5140 | Otherwise, it will appear as @samp{@{...@}}. | |
5141 | ||
5142 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
1041a570 | 5143 | with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 | 5144 | |
0f153e74 | 5145 | _if__(!_CONLY__) |
4eb4cf57 RP |
5146 | @node Debugging C plus plus |
5147 | _if__(!_CONLY__) | |
6f3ec223 | 5148 | @subsubsection _GDBN__ Features for C++ |
4eb4cf57 RP |
5149 | _fi__(!_CONLY__) |
5150 | _if__(_CONLY__) | |
5151 | @section _GDBN__ Features for C++ | |
5152 | _fi__(_CONLY__) | |
b80282d5 RP |
5153 | |
5154 | @cindex commands for C++ | |
5155 | Some _GDBN__ commands are particularly useful with C++, and some are | |
5156 | designed specifically for use with C++. Here is a summary: | |
5157 | ||
5158 | @table @code | |
5159 | @cindex break in overloaded functions | |
5160 | @item @r{breakpoint menus} | |
5161 | When you want a breakpoint in a function whose name is overloaded, | |
5162 | _GDBN__'s breakpoint menus help you specify which function definition | |
5163 | you want. @xref{Breakpoint Menus}. | |
5164 | ||
5165 | @cindex overloading in C++ | |
5166 | @item rbreak @var{regex} | |
5167 | Setting breakpoints using regular expressions is helpful for setting | |
5168 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 5169 | classes. |
29a2b744 | 5170 | @xref{Set Breaks, ,Setting Breakpoints}. |
b80282d5 RP |
5171 | |
5172 | @cindex C++ exception handling | |
5173 | @item catch @var{exceptions} | |
5174 | @itemx info catch | |
29a2b744 | 5175 | Debug C++ exception handling using these commands. @xref{Exception |
1041a570 | 5176 | Handling, ,Breakpoints and Exceptions}. |
b80282d5 | 5177 | |
e251e767 | 5178 | @cindex inheritance |
b80282d5 RP |
5179 | @item ptype @var{typename} |
5180 | Print inheritance relationships as well as other information for type | |
e251e767 | 5181 | @var{typename}. |
1041a570 | 5182 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
5183 | |
5184 | @cindex C++ symbol display | |
5185 | @item set print demangle | |
5186 | @itemx show print demangle | |
5187 | @itemx set print asm-demangle | |
5188 | @itemx show print asm-demangle | |
5189 | Control whether C++ symbols display in their source form, both when | |
5190 | displaying code as C++ source and when displaying disassemblies. | |
1041a570 | 5191 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5192 | |
5193 | @item set print object | |
5194 | @itemx show print object | |
e251e767 | 5195 | Choose whether to print derived (actual) or declared types of objects. |
1041a570 | 5196 | @xref{Print Settings, ,Print Settings}. |
b80282d5 RP |
5197 | |
5198 | @item set print vtbl | |
5199 | @itemx show print vtbl | |
5200 | Control the format for printing virtual function tables. | |
1041a570 | 5201 | @xref{Print Settings, ,Print Settings}. |
6f3ec223 RP |
5202 | |
5203 | @item @r{Overloaded symbol names} | |
5204 | You can specify a particular definition of an overloaded symbol, using | |
5205 | the same notation that's used to declare such symbols in C++: type | |
5206 | @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can | |
5207 | also use _GDBN__'s command-line word completion facilities to list the | |
5208 | available choices, or to finish the type list for you. | |
5209 | @xref{Completion,, Command Completion}, for details on how to do this. | |
b80282d5 RP |
5210 | @end table |
5211 | ||
4eb4cf57 | 5212 | @node Modula-2 |
c2bbbb22 RP |
5213 | @subsection Modula-2 |
5214 | @cindex Modula-2 | |
5215 | ||
5216 | The extensions made to _GDBN__ to support Modula-2 support output | |
5217 | from the GNU Modula-2 compiler (which is currently being developed). | |
5218 | Other Modula-2 compilers are not currently supported, and attempting to | |
5219 | debug executables produced by them will most likely result in an error | |
5220 | as _GDBN__ reads in the executable's symbol table. | |
5221 | ||
5222 | @cindex expressions in Modula-2 | |
5223 | @menu | |
5224 | * M2 Operators:: Built-in operators | |
29a2b744 | 5225 | * Built-In Func/Proc:: Built-in Functions and Procedures |
c2bbbb22 RP |
5226 | * M2 Constants:: Modula-2 Constants |
5227 | * M2 Defaults:: Default settings for Modula-2 | |
5228 | * Deviations:: Deviations from standard Modula-2 | |
5229 | * M2 Checks:: Modula-2 Type and Range Checks | |
5230 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
5231 | * GDB/M2:: _GDBN__ and Modula-2 | |
5232 | @end menu | |
5233 | ||
4eb4cf57 | 5234 | @node M2 Operators |
c2bbbb22 RP |
5235 | @subsubsection Operators |
5236 | @cindex Modula-2 operators | |
5237 | ||
5238 | Operators must be defined on values of specific types. For instance, | |
5239 | @code{+} is defined on numbers, but not on structures. Operators are | |
5240 | often defined on groups of types. For the purposes of Modula-2, the | |
5241 | following definitions hold: | |
5242 | ||
5243 | @itemize @bullet | |
5244 | ||
5245 | @item | |
5246 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
5247 | their subranges. | |
5248 | ||
5249 | @item | |
5250 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
5251 | ||
5252 | @item | |
5253 | @emph{Floating-point types} consist of @code{REAL}. | |
5254 | ||
5255 | @item | |
5256 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
5257 | @var{type}}. | |
5258 | ||
5259 | @item | |
5260 | @emph{Scalar types} consist of all of the above. | |
5261 | ||
5262 | @item | |
5263 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
5264 | ||
5265 | @item | |
5266 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
5267 | @end itemize |
5268 | ||
5269 | @noindent | |
5270 | The following operators are supported, and appear in order of | |
5271 | increasing precedence: | |
5272 | ||
5273 | @table @code | |
c2bbbb22 RP |
5274 | @item , |
5275 | Function argument or array index separator. | |
1041a570 | 5276 | _0__ |
c2bbbb22 RP |
5277 | @item := |
5278 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
5279 | @var{value}. | |
5280 | ||
5281 | @item <@r{, }> | |
5282 | Less than, greater than on integral, floating-point, or enumerated | |
5283 | types. | |
5284 | ||
5285 | @item <=@r{, }>= | |
5286 | Less than, greater than, less than or equal to, greater than or equal to | |
5287 | on integral, floating-point and enumerated types, or set inclusion on | |
5288 | set types. Same precedence as @code{<}. | |
5289 | ||
5290 | @item =@r{, }<>@r{, }# | |
5291 | Equality and two ways of expressing inequality, valid on scalar types. | |
5292 | Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is | |
5293 | available for inequality, since @code{#} conflicts with the script | |
5294 | comment character. | |
5295 | ||
5296 | @item IN | |
5297 | Set membership. Defined on set types and the types of their members. | |
5298 | Same precedence as @code{<}. | |
5299 | ||
5300 | @item OR | |
5301 | Boolean disjunction. Defined on boolean types. | |
5302 | ||
5303 | @item AND@r{, }& | |
5304 | Boolean conjuction. Defined on boolean types. | |
5305 | ||
5306 | @item @@ | |
1041a570 | 5307 | The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5308 | |
5309 | @item +@r{, }- | |
5310 | Addition and subtraction on integral and floating-point types, or union | |
5311 | and difference on set types. | |
5312 | ||
5313 | @item * | |
5314 | Multiplication on integral and floating-point types, or set intersection | |
5315 | on set types. | |
5316 | ||
5317 | @item / | |
5318 | Division on floating-point types, or symmetric set difference on set | |
5319 | types. Same precedence as @code{*}. | |
5320 | ||
5321 | @item DIV@r{, }MOD | |
5322 | Integer division and remainder. Defined on integral types. Same | |
5323 | precedence as @code{*}. | |
5324 | ||
5325 | @item - | |
5326 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
5327 | ||
5328 | @item ^ | |
e251e767 | 5329 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
5330 | |
5331 | @item NOT | |
5332 | Boolean negation. Defined on boolean types. Same precedence as | |
5333 | @code{^}. | |
5334 | ||
5335 | @item . | |
5336 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
5337 | precedence as @code{^}. | |
5338 | ||
5339 | @item [] | |
5340 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
5341 | ||
5342 | @item () | |
5343 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
5344 | as @code{^}. | |
5345 | ||
5346 | @item ::@r{, }. | |
5347 | _GDBN__ and Modula-2 scope operators. | |
c2bbbb22 RP |
5348 | @end table |
5349 | ||
5350 | @quotation | |
5351 | @emph{Warning:} Sets and their operations are not yet supported, so _GDBN__ | |
5352 | will treat the use of the operator @code{IN}, or the use of operators | |
5353 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
5354 | @code{<=}, and @code{>=} on sets as an error. | |
5355 | @end quotation | |
5356 | _1__ | |
29a2b744 | 5357 | @cindex Modula-2 built-ins |
4eb4cf57 | 5358 | @node Built-In Func/Proc |
c2bbbb22 RP |
5359 | @subsubsection Built-in Functions and Procedures |
5360 | ||
5361 | Modula-2 also makes available several built-in procedures and functions. | |
5362 | In describing these, the following metavariables are used: | |
5363 | ||
5364 | @table @var | |
5365 | ||
5366 | @item a | |
5367 | represents an @code{ARRAY} variable. | |
5368 | ||
5369 | @item c | |
5370 | represents a @code{CHAR} constant or variable. | |
5371 | ||
5372 | @item i | |
5373 | represents a variable or constant of integral type. | |
5374 | ||
5375 | @item m | |
5376 | represents an identifier that belongs to a set. Generally used in the | |
5377 | same function with the metavariable @var{s}. The type of @var{s} should | |
5378 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
5379 | ||
5380 | @item n | |
5381 | represents a variable or constant of integral or floating-point type. | |
5382 | ||
5383 | @item r | |
5384 | represents a variable or constant of floating-point type. | |
5385 | ||
5386 | @item t | |
5387 | represents a type. | |
5388 | ||
5389 | @item v | |
5390 | represents a variable. | |
5391 | ||
5392 | @item x | |
5393 | represents a variable or constant of one of many types. See the | |
5394 | explanation of the function for details. | |
c2bbbb22 RP |
5395 | @end table |
5396 | ||
5397 | All Modula-2 built-in procedures also return a result, described below. | |
5398 | ||
5399 | @table @code | |
5400 | @item ABS(@var{n}) | |
5401 | Returns the absolute value of @var{n}. | |
5402 | ||
5403 | @item CAP(@var{c}) | |
5404 | If @var{c} is a lower case letter, it returns its upper case | |
5405 | equivalent, otherwise it returns its argument | |
5406 | ||
5407 | @item CHR(@var{i}) | |
5408 | Returns the character whose ordinal value is @var{i}. | |
5409 | ||
5410 | @item DEC(@var{v}) | |
5411 | Decrements the value in the variable @var{v}. Returns the new value. | |
5412 | ||
5413 | @item DEC(@var{v},@var{i}) | |
5414 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5415 | new value. | |
5416 | ||
5417 | @item EXCL(@var{m},@var{s}) | |
5418 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5419 | set. | |
5420 | ||
5421 | @item FLOAT(@var{i}) | |
5422 | Returns the floating point equivalent of the integer @var{i}. | |
5423 | ||
5424 | @item HIGH(@var{a}) | |
5425 | Returns the index of the last member of @var{a}. | |
5426 | ||
5427 | @item INC(@var{v}) | |
5428 | Increments the value in the variable @var{v}. Returns the new value. | |
5429 | ||
5430 | @item INC(@var{v},@var{i}) | |
5431 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5432 | new value. | |
5433 | ||
5434 | @item INCL(@var{m},@var{s}) | |
5435 | Adds the element @var{m} to the set @var{s} if it is not already | |
5436 | there. Returns the new set. | |
5437 | ||
5438 | @item MAX(@var{t}) | |
5439 | Returns the maximum value of the type @var{t}. | |
5440 | ||
5441 | @item MIN(@var{t}) | |
5442 | Returns the minimum value of the type @var{t}. | |
5443 | ||
5444 | @item ODD(@var{i}) | |
5445 | Returns boolean TRUE if @var{i} is an odd number. | |
5446 | ||
5447 | @item ORD(@var{x}) | |
5448 | Returns the ordinal value of its argument. For example, the ordinal | |
5449 | value of a character is its ASCII value (on machines supporting the | |
5450 | ASCII character set). @var{x} must be of an ordered type, which include | |
5451 | integral, character and enumerated types. | |
5452 | ||
5453 | @item SIZE(@var{x}) | |
5454 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5455 | ||
5456 | @item TRUNC(@var{r}) | |
5457 | Returns the integral part of @var{r}. | |
5458 | ||
5459 | @item VAL(@var{t},@var{i}) | |
5460 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5461 | @end table | |
5462 | ||
5463 | @quotation | |
5464 | @emph{Warning:} Sets and their operations are not yet supported, so | |
5465 | _GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as | |
5466 | an error. | |
5467 | @end quotation | |
5468 | ||
5469 | @cindex Modula-2 constants | |
4eb4cf57 | 5470 | @node M2 Constants |
c2bbbb22 RP |
5471 | @subsubsection Constants |
5472 | ||
5473 | _GDBN__ allows you to express the constants of Modula-2 in the following | |
5474 | ways: | |
5475 | ||
5476 | @itemize @bullet | |
5477 | ||
5478 | @item | |
5479 | Integer constants are simply a sequence of digits. When used in an | |
5480 | expression, a constant is interpreted to be type-compatible with the | |
5481 | rest of the expression. Hexadecimal integers are specified by a | |
5482 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5483 | ||
5484 | @item | |
5485 | Floating point constants appear as a sequence of digits, followed by a | |
5486 | decimal point and another sequence of digits. An optional exponent can | |
5487 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5488 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5489 | digits of the floating point constant must be valid decimal (base 10) | |
5490 | digits. | |
5491 | ||
5492 | @item | |
5493 | Character constants consist of a single character enclosed by a pair of | |
5494 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5495 | also be expressed by their ordinal value (their ASCII value, usually) | |
5496 | followed by a @samp{C}. | |
5497 | ||
5498 | @item | |
1041a570 RP |
5499 | String constants consist of a sequence of characters enclosed by a |
5500 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5501 | Escape sequences in the style of C are also allowed. @xref{C | |
5502 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
5503 | sequences. | |
c2bbbb22 RP |
5504 | |
5505 | @item | |
5506 | Enumerated constants consist of an enumerated identifier. | |
5507 | ||
5508 | @item | |
5509 | Boolean constants consist of the identifiers @code{TRUE} and | |
5510 | @code{FALSE}. | |
5511 | ||
5512 | @item | |
5513 | Pointer constants consist of integral values only. | |
5514 | ||
5515 | @item | |
5516 | Set constants are not yet supported. | |
c2bbbb22 RP |
5517 | @end itemize |
5518 | ||
4eb4cf57 | 5519 | @node M2 Defaults |
c2bbbb22 RP |
5520 | @subsubsection Modula-2 Defaults |
5521 | @cindex Modula-2 defaults | |
5522 | ||
e251e767 RP |
5523 | If type and range checking are set automatically by _GDBN__, they |
5524 | both default to @code{on} whenever the working language changes to | |
c2bbbb22 RP |
5525 | Modula-2. This happens regardless of whether you, or _GDBN__, |
5526 | selected the working language. | |
5527 | ||
5528 | If you allow _GDBN__ to set the language automatically, then entering | |
5529 | code compiled from a file whose name ends with @file{.mod} will set the | |
1041a570 | 5530 | working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set |
c2bbbb22 RP |
5531 | the language automatically}, for further details. |
5532 | ||
4eb4cf57 | 5533 | @node Deviations |
c2bbbb22 RP |
5534 | @subsubsection Deviations from Standard Modula-2 |
5535 | @cindex Modula-2, deviations from | |
5536 | ||
5537 | A few changes have been made to make Modula-2 programs easier to debug. | |
5538 | This is done primarily via loosening its type strictness: | |
5539 | ||
5540 | @itemize @bullet | |
e251e767 | 5541 | @item |
c2bbbb22 RP |
5542 | Unlike in standard Modula-2, pointer constants can be formed by |
5543 | integers. This allows you to modify pointer variables during | |
5544 | debugging. (In standard Modula-2, the actual address contained in a | |
5545 | pointer variable is hidden from you; it can only be modified | |
5546 | through direct assignment to another pointer variable or expression that | |
5547 | returned a pointer.) | |
5548 | ||
e251e767 | 5549 | @item |
c2bbbb22 RP |
5550 | C escape sequences can be used in strings and characters to represent |
5551 | non-printable characters. _GDBN__ will print out strings with these | |
5552 | escape sequences embedded. Single non-printable characters are | |
5553 | printed using the @samp{CHR(@var{nnn})} format. | |
5554 | ||
5555 | @item | |
5556 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5557 | argument. | |
5558 | ||
5559 | @item | |
29a2b744 | 5560 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 5561 | @end itemize |
c2bbbb22 | 5562 | |
4eb4cf57 | 5563 | @node M2 Checks |
c2bbbb22 RP |
5564 | @subsubsection Modula-2 Type and Range Checks |
5565 | @cindex Modula-2 checks | |
5566 | ||
5567 | @quotation | |
5568 | @emph{Warning:} in this release, _GDBN__ does not yet perform type or | |
5569 | range checking. | |
5570 | @end quotation | |
5571 | @c FIXME remove warning when type/range checks added | |
5572 | ||
5573 | _GDBN__ considers two Modula-2 variables type equivalent if: | |
5574 | ||
5575 | @itemize @bullet | |
5576 | @item | |
5577 | They are of types that have been declared equivalent via a @code{TYPE | |
5578 | @var{t1} = @var{t2}} statement | |
5579 | ||
5580 | @item | |
5581 | They have been declared on the same line. (Note: This is true of the | |
5582 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
5583 | @end itemize |
5584 | ||
5585 | As long as type checking is enabled, any attempt to combine variables | |
5586 | whose types are not equivalent is an error. | |
5587 | ||
5588 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 5589 | index bounds, and all built-in functions and procedures. |
c2bbbb22 | 5590 | |
4eb4cf57 | 5591 | @node M2 Scope |
c2bbbb22 RP |
5592 | @subsubsection The scope operators @code{::} and @code{.} |
5593 | @cindex scope | |
5594 | @kindex . | |
e94b4a2b | 5595 | @cindex colon, doubled as scope operator |
1041a570 RP |
5596 | @ifinfo |
5597 | @kindex colon-colon | |
5598 | @c Info cannot handoe :: but TeX can. | |
5599 | @end ifinfo | |
5600 | @iftex | |
c2bbbb22 | 5601 | @kindex :: |
1041a570 | 5602 | @end iftex |
c2bbbb22 RP |
5603 | |
5604 | There are a few subtle differences between the Modula-2 scope operator | |
5605 | (@code{.}) and the _GDBN__ scope operator (@code{::}). The two have | |
5606 | similar syntax: | |
5607 | ||
5608 | @example | |
5609 | ||
5610 | @var{module} . @var{id} | |
5611 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
5612 | @end example |
5613 | ||
5614 | @noindent | |
5615 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
5616 | @var{module} the name of a module, and @var{id} is any declared |
5617 | identifier within your program, except another module. | |
c2bbbb22 RP |
5618 | |
5619 | Using the @code{::} operator makes _GDBN__ search the scope | |
5620 | specified by @var{scope} for the identifier @var{id}. If it is not | |
5621 | found in the specified scope, then _GDBN__ will search all scopes | |
5622 | enclosing the one specified by @var{scope}. | |
5623 | ||
5624 | Using the @code{.} operator makes _GDBN__ search the current scope for | |
5625 | the identifier specified by @var{id} that was imported from the | |
5626 | definition module specified by @var{module}. With this operator, it is | |
5627 | an error if the identifier @var{id} was not imported from definition | |
5628 | module @var{module}, or if @var{id} is not an identifier in | |
5629 | @var{module}. | |
5630 | ||
4eb4cf57 | 5631 | @node GDB/M2 |
c2bbbb22 RP |
5632 | @subsubsection _GDBN__ and Modula-2 |
5633 | ||
5634 | Some _GDBN__ commands have little use when debugging Modula-2 programs. | |
5635 | Five subcommands of @code{set print} and @code{show print} apply | |
5636 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5637 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
5638 | apply to C++, and the last to C's @code{union} type, which has no direct | |
5639 | analogue in Modula-2. | |
5640 | ||
1041a570 | 5641 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
5642 | while using any language, is not useful with Modula-2. Its |
5643 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5644 | created in Modula-2 as they can in C or C++. However, because an | |
5645 | address can be specified by an integral constant, the construct | |
1041a570 | 5646 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
c2bbbb22 RP |
5647 | _0__ |
5648 | @cindex @code{#} in Modula-2 | |
5649 | In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is | |
5650 | interpreted as the beginning of a comment. Use @code{<>} instead. | |
5651 | _1__ | |
4eb4cf57 RP |
5652 | _fi__(!_CONLY__) |
5653 | ||
5654 | @node Symbols | |
70b88761 RP |
5655 | @chapter Examining the Symbol Table |
5656 | ||
5657 | The commands described in this section allow you to inquire about the | |
5658 | symbols (names of variables, functions and types) defined in your | |
5659 | program. This information is inherent in the text of your program and | |
29a2b744 | 5660 | does not change as your program executes. _GDBN__ finds it in your |
e251e767 | 5661 | program's symbol table, in the file indicated when you started _GDBN__ |
1041a570 RP |
5662 | (@pxref{File Options, ,Choosing Files}), or by one of the |
5663 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
70b88761 | 5664 | |
6c380b13 RP |
5665 | @c FIXME! This might be intentionally specific to C and C++; if so, move |
5666 | @c to someplace in C section of lang chapter. | |
5667 | @cindex symbol names | |
5668 | @cindex names of symbols | |
5669 | @cindex quoting names | |
5670 | Occasionally, you may need to refer to symbols that contain unusual | |
5671 | characters, which _GDBN__ ordinarily treats as word delimiters. The | |
5672 | most frequent case is in referring to static variables in other | |
5673 | source files (@pxref{Variables,,Program Variables}). File names | |
5674 | are recorded in object files as debugging symbols, but _GDBN__ would | |
5675 | ordinarily parse a typical file name, like @file{foo.c}, as the three words | |
5676 | @samp{foo} @samp{.} @samp{c}. To allow _GDBN__ to recognize | |
5677 | @samp{foo.c} as a single symbol, enclose it in single quotes; for example, | |
5678 | ||
5679 | @example | |
5680 | p 'foo.c'::x | |
5681 | @end example | |
5682 | ||
5683 | @noindent | |
5684 | looks up the value of @code{x} in the scope of the file @file{foo.c}. | |
5685 | ||
70b88761 RP |
5686 | @table @code |
5687 | @item info address @var{symbol} | |
5688 | @kindex info address | |
5689 | Describe where the data for @var{symbol} is stored. For a register | |
5690 | variable, this says which register it is kept in. For a non-register | |
5691 | local variable, this prints the stack-frame offset at which the variable | |
5692 | is always stored. | |
5693 | ||
5694 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5695 | at all for a register variables, and for a stack local variable prints | |
5696 | the exact address of the current instantiation of the variable. | |
5697 | ||
5698 | @item whatis @var{exp} | |
5699 | @kindex whatis | |
5700 | Print the data type of expression @var{exp}. @var{exp} is not | |
5701 | actually evaluated, and any side-effecting operations (such as | |
5702 | assignments or function calls) inside it do not take place. | |
1041a570 | 5703 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
5704 | |
5705 | @item whatis | |
5706 | Print the data type of @code{$}, the last value in the value history. | |
5707 | ||
5708 | @item ptype @var{typename} | |
5709 | @kindex ptype | |
5710 | Print a description of data type @var{typename}. @var{typename} may be | |
5711 | the name of a type, or for C code it may have the form | |
5712 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 5713 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
5714 | |
5715 | @item ptype @var{exp} | |
e0dacfd1 | 5716 | @itemx ptype |
70b88761 | 5717 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 RP |
5718 | differs from @code{whatis} by printing a detailed description, instead |
5719 | of just the name of the type. For example, if your program declares a | |
5720 | variable as | |
5721 | ||
70b88761 RP |
5722 | @example |
5723 | struct complex @{double real; double imag;@} v; | |
5724 | @end example | |
1041a570 | 5725 | |
70b88761 RP |
5726 | @noindent |
5727 | compare the output of the two commands: | |
1041a570 | 5728 | |
70b88761 | 5729 | @example |
1041a570 | 5730 | @group |
70b88761 RP |
5731 | (_GDBP__) whatis v |
5732 | type = struct complex | |
5733 | (_GDBP__) ptype v | |
5734 | type = struct complex @{ | |
5735 | double real; | |
5736 | double imag; | |
5737 | @} | |
1041a570 | 5738 | @end group |
70b88761 | 5739 | @end example |
1041a570 | 5740 | |
e0dacfd1 RP |
5741 | @noindent |
5742 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5743 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
5744 | |
5745 | @item info types @var{regexp} | |
5746 | @itemx info types | |
e251e767 | 5747 | @kindex info types |
70b88761 RP |
5748 | Print a brief description of all types whose name matches @var{regexp} |
5749 | (or all types in your program, if you supply no argument). Each | |
5750 | complete typename is matched as though it were a complete line; thus, | |
5751 | @samp{i type value} gives information on all types in your program whose | |
5752 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5753 | information only on types whose complete name is @code{value}. | |
5754 | ||
5755 | This command differs from @code{ptype} in two ways: first, like | |
5756 | @code{whatis}, it does not print a detailed description; second, it | |
5757 | lists all source files where a type is defined. | |
5758 | ||
5759 | @item info source | |
5760 | @kindex info source | |
5761 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
5762 | the function containing the current point of execution---and the language |
5763 | it was written in. | |
70b88761 RP |
5764 | |
5765 | @item info sources | |
5766 | @kindex info sources | |
29a2b744 | 5767 | Print the names of all source files in your program for which there is |
b80282d5 RP |
5768 | debugging information, organized into two lists: files whose symbols |
5769 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
5770 | |
5771 | @item info functions | |
5772 | @kindex info functions | |
5773 | Print the names and data types of all defined functions. | |
5774 | ||
5775 | @item info functions @var{regexp} | |
5776 | Print the names and data types of all defined functions | |
5777 | whose names contain a match for regular expression @var{regexp}. | |
5778 | Thus, @samp{info fun step} finds all functions whose names | |
5779 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5780 | start with @code{step}. | |
5781 | ||
5782 | @item info variables | |
5783 | @kindex info variables | |
5784 | Print the names and data types of all variables that are declared | |
5785 | outside of functions (i.e., excluding local variables). | |
5786 | ||
5787 | @item info variables @var{regexp} | |
5788 | Print the names and data types of all variables (except for local | |
5789 | variables) whose names contain a match for regular expression | |
5790 | @var{regexp}. | |
5791 | ||
70b88761 RP |
5792 | @ignore |
5793 | This was never implemented. | |
5794 | @item info methods | |
5795 | @itemx info methods @var{regexp} | |
5796 | @kindex info methods | |
5797 | The @code{info methods} command permits the user to examine all defined | |
5798 | methods within C++ program, or (with the @var{regexp} argument) a | |
5799 | specific set of methods found in the various C++ classes. Many | |
5800 | C++ classes provide a large number of methods. Thus, the output | |
5801 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5802 | @code{info-methods} command filters the methods, printing only those | |
5803 | which match the regular-expression @var{regexp}. | |
5804 | @end ignore | |
5805 | ||
d48da190 RP |
5806 | @item maint print symbols @var{filename} |
5807 | @itemx maint print psymbols @var{filename} | |
5808 | @itemx maint print msymbols @var{filename} | |
5809 | @kindex maint print symbols | |
440d9834 | 5810 | @cindex symbol dump |
d48da190 | 5811 | @kindex maint print psymbols |
440d9834 RP |
5812 | @cindex partial symbol dump |
5813 | Write a dump of debugging symbol data into the file @var{filename}. | |
e0dacfd1 | 5814 | These commands are used to debug the _GDBN__ symbol-reading code. Only |
d48da190 RP |
5815 | symbols with debugging data are included. If you use @samp{maint print |
5816 | symbols}, _GDBN__ includes all the symbols for which it has already | |
5817 | collected full details: that is, @var{filename} reflects symbols for | |
5818 | only those files whose symbols _GDBN__ has read. You can use the | |
5819 | command @code{info sources} to find out which files these are. If you | |
5820 | use @samp{maint print psymbols} instead, the dump shows information about | |
5821 | symbols that _GDBN__ only knows partially---that is, symbols defined in | |
5822 | files that _GDBN__ has skimmed, but not yet read completely. Finally, | |
5823 | @samp{maint print msymbols} dumps just the minimal symbol information | |
5824 | required for each object file from which _GDBN__ has read some symbols. | |
5825 | The description of @code{symbol-file} explains how _GDBN__ reads | |
5826 | symbols; both @code{info source} and @code{symbol-file} are described in | |
5827 | @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
5828 | @end table |
5829 | ||
4eb4cf57 | 5830 | @node Altering |
70b88761 RP |
5831 | @chapter Altering Execution |
5832 | ||
29a2b744 | 5833 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
5834 | find out for certain whether correcting the apparent error would lead to |
5835 | correct results in the rest of the run. You can find the answer by | |
5836 | experiment, using the _GDBN__ features for altering execution of the | |
5837 | program. | |
5838 | ||
5839 | For example, you can store new values into variables or memory | |
29a2b744 | 5840 | locations, give your program a signal, restart it at a different address, |
70b88761 RP |
5841 | or even return prematurely from a function to its caller. |
5842 | ||
5843 | @menu | |
b80282d5 RP |
5844 | * Assignment:: Assignment to Variables |
5845 | * Jumping:: Continuing at a Different Address | |
4eb4cf57 | 5846 | _if__(!_BARE__) |
29a2b744 | 5847 | * Signaling:: Giving your program a Signal |
4eb4cf57 | 5848 | _fi__(!_BARE__) |
b80282d5 RP |
5849 | * Returning:: Returning from a Function |
5850 | * Calling:: Calling your Program's Functions | |
c338a2fd | 5851 | * Patching:: Patching your Program |
70b88761 RP |
5852 | @end menu |
5853 | ||
4eb4cf57 | 5854 | @node Assignment |
70b88761 RP |
5855 | @section Assignment to Variables |
5856 | ||
5857 | @cindex assignment | |
5858 | @cindex setting variables | |
5859 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 5860 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
5861 | |
5862 | @example | |
5863 | print x=4 | |
5864 | @end example | |
5865 | ||
5866 | @noindent | |
1041a570 | 5867 | stores the value 4 into the variable @code{x}, and then prints the |
4eb4cf57 RP |
5868 | value of the assignment expression (which is 4). |
5869 | _if__(!_CONLY__) | |
5870 | @xref{Languages, ,Using _GDBN__ with Different Languages}, for more | |
5871 | information on operators in supported languages. | |
5872 | _fi__(!_CONLY__) | |
70b88761 | 5873 | |
70b88761 RP |
5874 | @kindex set variable |
5875 | @cindex variables, setting | |
5876 | If you are not interested in seeing the value of the assignment, use the | |
5877 | @code{set} command instead of the @code{print} command. @code{set} is | |
5878 | really the same as @code{print} except that the expression's value is not | |
1041a570 | 5879 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The |
70b88761 RP |
5880 | expression is evaluated only for its effects. |
5881 | ||
5882 | If the beginning of the argument string of the @code{set} command | |
5883 | appears identical to a @code{set} subcommand, use the @code{set | |
5884 | variable} command instead of just @code{set}. This command is identical | |
5885 | to @code{set} except for its lack of subcommands. For example, a | |
5886 | program might well have a variable @code{width}---which leads to | |
5887 | an error if we try to set a new value with just @samp{set width=13}, as | |
1041a570 RP |
5888 | we might if @code{set width} did not happen to be a _GDBN__ command: |
5889 | ||
70b88761 RP |
5890 | @example |
5891 | (_GDBP__) whatis width | |
5892 | type = double | |
5893 | (_GDBP__) p width | |
5894 | $4 = 13 | |
5895 | (_GDBP__) set width=47 | |
5896 | Invalid syntax in expression. | |
5897 | @end example | |
1041a570 | 5898 | |
70b88761 RP |
5899 | @noindent |
5900 | The invalid expression, of course, is @samp{=47}. What we can do in | |
e251e767 | 5901 | order to actually set our program's variable @code{width} is |
1041a570 | 5902 | |
70b88761 RP |
5903 | @example |
5904 | (_GDBP__) set var width=47 | |
5905 | @end example | |
5906 | ||
1041a570 RP |
5907 | _GDBN__ allows more implicit conversions in assignments than C; you can |
5908 | freely store an integer value into a pointer variable or vice versa, | |
5909 | and any structure can be converted to any other structure that is the | |
5910 | same length or shorter. | |
e251e767 | 5911 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
5912 | @comment /[email protected] 18dec1990 |
5913 | ||
5914 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
5915 | construct to generate a value of specified type at a specified address | |
1041a570 | 5916 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
5917 | to memory location @code{0x83040} as an integer (which implies a certain size |
5918 | and representation in memory), and | |
5919 | ||
5920 | @example | |
5921 | set @{int@}0x83040 = 4 | |
5922 | @end example | |
5923 | ||
5924 | @noindent | |
5925 | stores the value 4 into that memory location. | |
5926 | ||
4eb4cf57 | 5927 | @node Jumping |
70b88761 RP |
5928 | @section Continuing at a Different Address |
5929 | ||
29a2b744 | 5930 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
5931 | it stopped, with the @code{continue} command. You can instead continue at |
5932 | an address of your own choosing, with the following commands: | |
5933 | ||
5934 | @table @code | |
5935 | @item jump @var{linespec} | |
5936 | @kindex jump | |
5937 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 RP |
5938 | immediately if there is a breakpoint there. @xref{List, ,Printing |
5939 | Source Lines}, for a description of the different forms of | |
5940 | @var{linespec}. | |
70b88761 RP |
5941 | |
5942 | The @code{jump} command does not change the current stack frame, or | |
5943 | the stack pointer, or the contents of any memory location or any | |
5944 | register other than the program counter. If line @var{linespec} is in | |
5945 | a different function from the one currently executing, the results may | |
5946 | be bizarre if the two functions expect different patterns of arguments or | |
5947 | of local variables. For this reason, the @code{jump} command requests | |
5948 | confirmation if the specified line is not in the function currently | |
5949 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 5950 | well acquainted with the machine-language code of your program. |
70b88761 RP |
5951 | |
5952 | @item jump *@var{address} | |
5953 | Resume execution at the instruction at address @var{address}. | |
5954 | @end table | |
5955 | ||
5956 | You can get much the same effect as the @code{jump} command by storing a | |
5957 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 5958 | does not start your program running; it only changes the address where it |
70b88761 RP |
5959 | @emph{will} run when it is continued. For example, |
5960 | ||
5961 | @example | |
5962 | set $pc = 0x485 | |
5963 | @end example | |
5964 | ||
5965 | @noindent | |
5966 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 RP |
5967 | address @code{0x485}, rather than at the address where your program stopped. |
5968 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
70b88761 RP |
5969 | |
5970 | The most common occasion to use the @code{jump} command is to back up, | |
5971 | perhaps with more breakpoints set, over a portion of a program that has | |
5972 | already executed, in order to examine its execution in more detail. | |
5973 | ||
4eb4cf57 RP |
5974 | _if__(!_BARE__) |
5975 | @node Signaling | |
70b88761 | 5976 | @c @group |
29a2b744 | 5977 | @section Giving your program a Signal |
70b88761 RP |
5978 | |
5979 | @table @code | |
5980 | @item signal @var{signalnum} | |
5981 | @kindex signal | |
29a2b744 | 5982 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
5983 | signal number @var{signalnum}. |
5984 | ||
5985 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 5986 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
5987 | a signal and would ordinary see the signal when resumed with the |
5988 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
5989 | signal. | |
5990 | ||
5991 | @code{signal} does not repeat when you press @key{RET} a second time | |
5992 | after executing the command. | |
5993 | @end table | |
5994 | @c @end group | |
4eb4cf57 | 5995 | _fi__(!_BARE__) |
70b88761 | 5996 | |
4eb4cf57 | 5997 | @node Returning |
70b88761 RP |
5998 | @section Returning from a Function |
5999 | ||
6000 | @table @code | |
6001 | @item return | |
6002 | @itemx return @var{expression} | |
6003 | @cindex returning from a function | |
6004 | @kindex return | |
6005 | You can cancel execution of a function call with the @code{return} | |
6006 | command. If you give an | |
6007 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 6008 | value. |
70b88761 RP |
6009 | @end table |
6010 | ||
6011 | When you use @code{return}, _GDBN__ discards the selected stack frame | |
6012 | (and all frames within it). You can think of this as making the | |
6013 | discarded frame return prematurely. If you wish to specify a value to | |
6014 | be returned, give that value as the argument to @code{return}. | |
6015 | ||
29a2b744 RP |
6016 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
6017 | Frame}), and any other frames inside of it, leaving its caller as the | |
6018 | innermost remaining frame. That frame becomes selected. The | |
6019 | specified value is stored in the registers used for returning values | |
6020 | of functions. | |
70b88761 RP |
6021 | |
6022 | The @code{return} command does not resume execution; it leaves the | |
6023 | program stopped in the state that would exist if the function had just | |
1041a570 RP |
6024 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
6025 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
6026 | selected stack frame returns naturally. | |
70b88761 | 6027 | |
4eb4cf57 | 6028 | @node Calling |
70b88761 RP |
6029 | @section Calling your Program's Functions |
6030 | ||
6031 | @cindex calling functions | |
6032 | @kindex call | |
6033 | @table @code | |
6034 | @item call @var{expr} | |
6035 | Evaluate the expression @var{expr} without displaying @code{void} | |
6036 | returned values. | |
6037 | @end table | |
6038 | ||
6039 | You can use this variant of the @code{print} command if you want to | |
6040 | execute a function from your program, but without cluttering the output | |
6041 | with @code{void} returned values. The result is printed and saved in | |
6042 | the value history, if it is not void. | |
6043 | ||
4eb4cf57 | 6044 | @node Patching |
c338a2fd RP |
6045 | @section Patching your Program |
6046 | @cindex patching binaries | |
6047 | @cindex writing into executables | |
6048 | @cindex writing into corefiles | |
1041a570 | 6049 | |
c338a2fd RP |
6050 | By default, _GDBN__ opens the file containing your program's executable |
6051 | code (or the corefile) read-only. This prevents accidental alterations | |
6052 | to machine code; but it also prevents you from intentionally patching | |
6053 | your program's binary. | |
6054 | ||
6055 | If you'd like to be able to patch the binary, you can specify that | |
6056 | explicitly with the @code{set write} command. For example, you might | |
6057 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 6058 | repairs. |
c338a2fd RP |
6059 | |
6060 | @table @code | |
6061 | @item set write on | |
6062 | @itemx set write off | |
6063 | @kindex set write | |
0f153e74 RP |
6064 | If you specify @samp{set write on}, _GDBN__ will open executable |
6065 | _if__(!_BARE__) | |
6066 | and core | |
6067 | _fi__(!_BARE__) | |
6068 | files for both reading and writing; if you specify @samp{set write | |
c338a2fd RP |
6069 | off} (the default), _GDBN__ will open them read-only. |
6070 | ||
1041a570 | 6071 | If you have already loaded a file, you must load it |
c338a2fd RP |
6072 | again (using the @code{exec-file} or @code{core-file} command) after |
6073 | changing @code{set write}, for your new setting to take effect. | |
6074 | ||
6075 | @item show write | |
7d7ff5f6 | 6076 | @kindex show write |
0f153e74 RP |
6077 | Display whether executable files |
6078 | _if__(!_BARE__) | |
6079 | and core files | |
6080 | _fi__(!_BARE__) | |
6081 | will be opened for writing as well as reading. | |
c338a2fd RP |
6082 | @end table |
6083 | ||
4eb4cf57 | 6084 | @node _GDBN__ Files |
70b88761 RP |
6085 | @chapter _GDBN__'s Files |
6086 | ||
1041a570 | 6087 | _GDBN__ needs to know the file name of the program to be debugged, both in |
4eb4cf57 RP |
6088 | order to read its symbol table and in order to start your program. |
6089 | _if__(!_BARE__) | |
6090 | To debug a core dump of a previous run, _GDBN__ must be told the file | |
6091 | name of the core dump. | |
6092 | _fi__(!_BARE__) | |
1041a570 | 6093 | |
70b88761 | 6094 | @menu |
b80282d5 RP |
6095 | * Files:: Commands to Specify Files |
6096 | * Symbol Errors:: Errors Reading Symbol Files | |
70b88761 RP |
6097 | @end menu |
6098 | ||
4eb4cf57 | 6099 | @node Files |
70b88761 | 6100 | @section Commands to Specify Files |
70b88761 | 6101 | @cindex symbol table |
70b88761 | 6102 | |
4eb4cf57 | 6103 | _if__(!_BARE__) |
0f153e74 | 6104 | @cindex core dump file |
1041a570 RP |
6105 | The usual way to specify executable and core dump file names is with |
6106 | the command arguments given when you start _GDBN__, (@pxref{Invocation, | |
6107 | ,Getting In and Out of _GDBN__}. | |
4eb4cf57 RP |
6108 | _fi__(!_BARE__) |
6109 | _if__(_BARE__) | |
6110 | The usual way to specify an executable file name is with | |
6111 | the command argument given when you start _GDBN__, (@pxref{Invocation, | |
6112 | ,Getting In and Out of _GDBN__}. | |
6113 | _fi__(_BARE__) | |
70b88761 RP |
6114 | |
6115 | Occasionally it is necessary to change to a different file during a | |
4eb4cf57 | 6116 | _GDBN__ session. Or you may run _GDBN__ and forget to specify a file you |
70b88761 RP |
6117 | want to use. In these situations the _GDBN__ commands to specify new files |
6118 | are useful. | |
6119 | ||
6120 | @table @code | |
6121 | @item file @var{filename} | |
6122 | @cindex executable file | |
6123 | @kindex file | |
6124 | Use @var{filename} as the program to be debugged. It is read for its | |
6125 | symbols and for the contents of pure memory. It is also the program | |
6126 | executed when you use the @code{run} command. If you do not specify a | |
1041a570 RP |
6127 | directory and the file is not found in _GDBN__'s working directory, _GDBN__ |
6128 | uses the environment variable @code{PATH} as a list of directories to | |
6129 | search, just as the shell does when looking for a program to run. You | |
6130 | can change the value of this variable, for both _GDBN__ and your program, | |
6131 | using the @code{path} command. | |
70b88761 | 6132 | |
14d01801 RP |
6133 | On systems with memory-mapped files, an auxiliary symbol table file |
6134 | @file{@var{filename}.syms} may be available for @var{filename}. If it | |
6135 | is, _GDBN__ will map in the symbol table from | |
6136 | @file{@var{filename}.syms}, starting up more quickly. See the | |
95d5ceb9 | 6137 | descriptions of the options @samp{-mapped} and @samp{-readnow} (available |
77b46d13 JG |
6138 | on the command line, and with the commands @code{file}, @code{symbol-file}, |
6139 | or @code{add-symbol-file}), for more information. | |
14d01801 | 6140 | |
e0dacfd1 | 6141 | @item file |
70b88761 RP |
6142 | @code{file} with no argument makes _GDBN__ discard any information it |
6143 | has on both executable file and the symbol table. | |
6144 | ||
e0dacfd1 | 6145 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6146 | @kindex exec-file |
6147 | Specify that the program to be run (but not the symbol table) is found | |
6148 | in @var{filename}. _GDBN__ will search the environment variable @code{PATH} | |
29a2b744 | 6149 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 6150 | discard information on the executable file. |
70b88761 | 6151 | |
e0dacfd1 | 6152 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6153 | @kindex symbol-file |
6154 | Read symbol table information from file @var{filename}. @code{PATH} is | |
6155 | searched when necessary. Use the @code{file} command to get both symbol | |
6156 | table and program to run from the same file. | |
6157 | ||
6158 | @code{symbol-file} with no argument clears out _GDBN__'s information on your | |
6159 | program's symbol table. | |
6160 | ||
6161 | The @code{symbol-file} command causes _GDBN__ to forget the contents of its | |
6162 | convenience variables, the value history, and all breakpoints and | |
6163 | auto-display expressions. This is because they may contain pointers to | |
6164 | the internal data recording symbols and data types, which are part of | |
6165 | the old symbol table data being discarded inside _GDBN__. | |
6166 | ||
6167 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
6168 | executing it once. | |
6169 | ||
14d01801 RP |
6170 | When _GDBN__ is configured for a particular environment, it will |
6171 | understand debugging information in whatever format is the standard | |
6172 | generated for that environment; you may use either a GNU compiler, or | |
6173 | other compilers that adhere to the local conventions. Best results are | |
6174 | usually obtained from GNU compilers; for example, using @code{_GCC__} | |
6175 | you can generate debugging information for optimized code. | |
6176 | ||
70b88761 | 6177 | On some kinds of object files, the @code{symbol-file} command does not |
14d01801 | 6178 | normally read the symbol table in full right away. Instead, it scans |
70b88761 RP |
6179 | the symbol table quickly to find which source files and which symbols |
6180 | are present. The details are read later, one source file at a time, | |
1041a570 | 6181 | as they are needed. |
70b88761 RP |
6182 | |
6183 | The purpose of this two-stage reading strategy is to make _GDBN__ start up | |
1041a570 RP |
6184 | faster. For the most part, it is invisible except for occasional |
6185 | pauses while the symbol table details for a particular source file are | |
6186 | being read. (The @code{set verbose} command can turn these pauses | |
6187 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings | |
6188 | and Messages}.) | |
70b88761 RP |
6189 | |
6190 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
1041a570 | 6191 | read the symbol table data in full right away. We have not implemented |
70b88761 RP |
6192 | the two-stage strategy for COFF yet. |
6193 | ||
95d5ceb9 RP |
6194 | @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
6195 | @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} | |
14d01801 RP |
6196 | @kindex readnow |
6197 | @cindex reading symbols immediately | |
6198 | @cindex symbols, reading immediately | |
6199 | @kindex mapped | |
6200 | @cindex memory-mapped symbol file | |
38962738 | 6201 | @cindex saving symbol table |
14d01801 | 6202 | You can override the _GDBN__ two-stage strategy for reading symbol |
95d5ceb9 | 6203 | tables by using the @samp{-readnow} option with any of the commands that |
14d01801 RP |
6204 | load symbol table information, if you want to be sure _GDBN__ has the |
6205 | entire symbol table available. | |
6206 | ||
4eb4cf57 | 6207 | _if__(!_BARE__) |
14d01801 | 6208 | If memory-mapped files are available on your system through the |
95d5ceb9 | 6209 | @code{mmap} system call, you can use another option, @samp{-mapped}, to |
77b46d13 JG |
6210 | cause _GDBN__ to write the symbols for your program into a reusable |
6211 | file. Future _GDBN__ debugging sessions will map in symbol information | |
6212 | from this auxiliary symbol file (if the program hasn't changed), rather | |
6213 | than spending time reading the symbol table from the executable | |
6214 | program. Using the @samp{-mapped} option has the same effect as | |
6215 | starting _GDBN__ with the @samp{-mapped} command-line option. | |
14d01801 | 6216 | |
95d5ceb9 | 6217 | You can use both options together, to make sure the auxiliary symbol |
14d01801 RP |
6218 | file has all the symbol information for your program. |
6219 | ||
77b46d13 JG |
6220 | The @code{.syms} file is specific to the host machine on which GDB is run. |
6221 | It holds an exact image of GDB's internal symbol table. It cannot be | |
6222 | shared across multiple host platforms. | |
6223 | ||
14d01801 RP |
6224 | The auxiliary symbol file for a program called @var{myprog} is called |
6225 | @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer | |
6226 | than the corresponding executable), _GDBN__ will always attempt to use | |
6227 | it when you debug @var{myprog}; no special options or commands are | |
6228 | needed. | |
6229 | @c FIXME: for now no mention of directories, since this seems to be in | |
6230 | @c flux. 13mar1992 status is that in theory GDB would look either in | |
6231 | @c current dir or in same dir as myprog; but issues like competing | |
6232 | @c GDB's, or clutter in system dirs, mean that in practice right now | |
6233 | @c only current dir is used. FFish says maybe a special GDB hierarchy | |
6234 | @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol | |
6235 | @c files. | |
70b88761 | 6236 | |
e0dacfd1 | 6237 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6238 | @kindex core |
6239 | @kindex core-file | |
6240 | Specify the whereabouts of a core dump file to be used as the ``contents | |
6241 | of memory''. Traditionally, core files contain only some parts of the | |
6242 | address space of the process that generated them; _GDBN__ can access the | |
6243 | executable file itself for other parts. | |
6244 | ||
6245 | @code{core-file} with no argument specifies that no core file is | |
6246 | to be used. | |
6247 | ||
6248 | Note that the core file is ignored when your program is actually running | |
29a2b744 | 6249 | under _GDBN__. So, if you have been running your program and you wish to |
70b88761 RP |
6250 | debug a core file instead, you must kill the subprocess in which the |
6251 | program is running. To do this, use the @code{kill} command | |
1041a570 | 6252 | (@pxref{Kill Process, ,Killing the Child Process}). |
4eb4cf57 | 6253 | _fi__(!_BARE__) |
70b88761 RP |
6254 | |
6255 | @item load @var{filename} | |
6256 | @kindex load | |
6257 | _if__(_GENERIC__) | |
6258 | Depending on what remote debugging facilities are configured into | |
6259 | _GDBN__, the @code{load} command may be available. Where it exists, it | |
6260 | is meant to make @var{filename} (an executable) available for debugging | |
6261 | on the remote system---by downloading, or dynamic linking, for example. | |
6262 | @code{load} also records @var{filename}'s symbol table in _GDBN__, like | |
6263 | the @code{add-symbol-file} command. | |
6264 | ||
6265 | If @code{load} is not available on your _GDBN__, attempting to execute | |
6266 | it gets the error message ``@code{You can't do that when your target is | |
e251e767 | 6267 | @dots{}}'' |
70b88761 RP |
6268 | _fi__(_GENERIC__) |
6269 | ||
e251e767 | 6270 | _if__(_VXWORKS__) |
70b88761 RP |
6271 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
6272 | current target system as well as adding its symbols in _GDBN__. | |
6273 | _fi__(_VXWORKS__) | |
6274 | ||
6275 | _if__(_I960__) | |
6276 | @cindex download to Nindy-960 | |
6277 | With the Nindy interface to an Intel 960 board, @code{load} will | |
6278 | download @var{filename} to the 960 as well as adding its symbols in | |
e251e767 | 6279 | _GDBN__. |
70b88761 RP |
6280 | _fi__(_I960__) |
6281 | ||
c7cb8acb RP |
6282 | _if__(_H8__) |
6283 | @cindex download to H8/300 | |
6284 | @cindex H8/300 download | |
6285 | When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi | |
6286 | H8/300 Remote,,_GDBN__ and the Hitachi H8/300}), the | |
6287 | @code{load} command downloads your program to the H8/300 and also opens | |
6288 | it as the current executable target for _GDBN__ on your host (like the | |
6289 | @code{file} command). | |
6290 | _fi__(_H8__) | |
6291 | ||
70b88761 RP |
6292 | @code{load} will not repeat if you press @key{RET} again after using it. |
6293 | ||
0f153e74 | 6294 | _if__(!_BARE__) |
70b88761 | 6295 | @item add-symbol-file @var{filename} @var{address} |
95d5ceb9 | 6296 | @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
70b88761 RP |
6297 | @kindex add-symbol-file |
6298 | @cindex dynamic linking | |
6299 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 6300 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
6301 | has been dynamically loaded (by some other means) into the program that |
6302 | is running. @var{address} should be the memory address at which the | |
6303 | file has been loaded; _GDBN__ cannot figure this out for itself. | |
6304 | ||
6305 | The symbol table of the file @var{filename} is added to the symbol table | |
6306 | originally read with the @code{symbol-file} command. You can use the | |
6307 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
6308 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 6309 | use the @code{symbol-file} command. |
70b88761 RP |
6310 | |
6311 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
6312 | ||
95d5ceb9 RP |
6313 | You can use the @samp{-mapped} and @samp{-readnow} options just as with |
6314 | the @code{symbol-file} command, to change how _GDBN__ manages the symbol | |
0f153e74 RP |
6315 | table information for @var{filename}. |
6316 | _fi__(!_BARE__) | |
95d5ceb9 | 6317 | |
70b88761 RP |
6318 | @item info files |
6319 | @itemx info target | |
6320 | @kindex info files | |
6321 | @kindex info target | |
1041a570 RP |
6322 | @code{info files} and @code{info target} are synonymous; both print |
6323 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
6324 | including the names of the executable and core dump files currently in | |
6325 | use by _GDBN__, and the files from which symbols were loaded. The command | |
6326 | @code{help targets} lists all possible targets rather than current | |
6327 | ones. | |
70b88761 RP |
6328 | |
6329 | @end table | |
6330 | ||
6331 | All file-specifying commands allow both absolute and relative file names | |
6332 | as arguments. _GDBN__ always converts the file name to an absolute path | |
6333 | name and remembers it that way. | |
6334 | ||
4eb4cf57 | 6335 | _if__(!_BARE__) |
70b88761 | 6336 | @cindex shared libraries |
77b46d13 JG |
6337 | _GDBN__ supports SunOS, SVR4, and IBM RS/6000 shared libraries. |
6338 | _GDBN__ automatically loads symbol definitions from shared libraries | |
6339 | when you use the @code{run} command, or when you examine a core file. | |
6340 | (Before you issue the @code{run} command, _GDBN__ will not understand | |
6341 | references to a function in a shared library, however---unless you are | |
6342 | debugging a core file). | |
c338a2fd | 6343 | @c FIXME: next _GDBN__ release should permit some refs to undef |
1041a570 | 6344 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
6345 | |
6346 | @table @code | |
70b88761 RP |
6347 | @item info share |
6348 | @itemx info sharedlibrary | |
6349 | @kindex info sharedlibrary | |
6350 | @kindex info share | |
c338a2fd | 6351 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 6352 | |
c338a2fd RP |
6353 | @item sharedlibrary @var{regex} |
6354 | @itemx share @var{regex} | |
6355 | @kindex sharedlibrary | |
6356 | @kindex share | |
6357 | This is an obsolescent command; you can use it to explicitly | |
6358 | load shared object library symbols for files matching a UNIX regular | |
6359 | expression, but as with files loaded automatically, it will only load | |
6360 | shared libraries required by your program for a core file or after | |
6361 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
6362 | required by your program are loaded. | |
6363 | @end table | |
4eb4cf57 | 6364 | _fi__(!_BARE__) |
70b88761 | 6365 | |
4eb4cf57 | 6366 | @node Symbol Errors |
70b88761 | 6367 | @section Errors Reading Symbol Files |
1041a570 RP |
6368 | |
6369 | While reading a symbol file, _GDBN__ will occasionally encounter problems, | |
6370 | such as symbol types it does not recognize, or known bugs in compiler | |
6371 | output. By default, _GDBN__ does not notify you of such problems, since | |
6372 | they are relatively common and primarily of interest to people | |
6373 | debugging compilers. If you are interested in seeing information | |
b80282d5 RP |
6374 | about ill-constructed symbol tables, you can either ask _GDBN__ to print |
6375 | only one message about each such type of problem, no matter how many | |
6376 | times the problem occurs; or you can ask _GDBN__ to print more messages, | |
1041a570 RP |
6377 | to see how many times the problems occur, with the @code{set |
6378 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
6379 | Messages}). | |
70b88761 RP |
6380 | |
6381 | The messages currently printed, and their meanings, are: | |
6382 | ||
6383 | @table @code | |
6384 | @item inner block not inside outer block in @var{symbol} | |
6385 | ||
6386 | The symbol information shows where symbol scopes begin and end | |
6387 | (such as at the start of a function or a block of statements). This | |
6388 | error indicates that an inner scope block is not fully contained | |
e251e767 | 6389 | in its outer scope blocks. |
70b88761 RP |
6390 | |
6391 | _GDBN__ circumvents the problem by treating the inner block as if it had | |
6392 | the same scope as the outer block. In the error message, @var{symbol} | |
6393 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
6394 | function. | |
6395 | ||
6396 | @item block at @var{address} out of order | |
6397 | ||
e251e767 | 6398 | The symbol information for symbol scope blocks should occur in |
70b88761 | 6399 | order of increasing addresses. This error indicates that it does not |
e251e767 | 6400 | do so. |
70b88761 RP |
6401 | |
6402 | _GDBN__ does not circumvent this problem, and will have trouble locating | |
6403 | symbols in the source file whose symbols being read. (You can often | |
6404 | determine what source file is affected by specifying @code{set verbose | |
29a2b744 | 6405 | on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.) |
70b88761 RP |
6406 | |
6407 | @item bad block start address patched | |
6408 | ||
6409 | The symbol information for a symbol scope block has a start address | |
6410 | smaller than the address of the preceding source line. This is known | |
e251e767 | 6411 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 RP |
6412 | |
6413 | _GDBN__ circumvents the problem by treating the symbol scope block as | |
6414 | starting on the previous source line. | |
6415 | ||
70b88761 RP |
6416 | @item bad string table offset in symbol @var{n} |
6417 | ||
6418 | @cindex foo | |
6419 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 6420 | larger than the size of the string table. |
70b88761 RP |
6421 | |
6422 | _GDBN__ circumvents the problem by considering the symbol to have the | |
6423 | name @code{foo}, which may cause other problems if many symbols end up | |
6424 | with this name. | |
6425 | ||
6426 | @item unknown symbol type @code{0x@var{nn}} | |
6427 | ||
6428 | The symbol information contains new data types that _GDBN__ does not yet | |
6429 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
e251e767 | 6430 | information, in hexadecimal. |
70b88761 RP |
6431 | |
6432 | _GDBN__ circumvents the error by ignoring this symbol information. This | |
29a2b744 | 6433 | will usually allow your program to be debugged, though certain symbols |
70b88761 RP |
6434 | will not be accessible. If you encounter such a problem and feel like |
6435 | debugging it, you can debug @code{_GDBP__} with itself, breakpoint on | |
6436 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
6437 | examine @code{*bufp} to see the symbol. | |
6438 | ||
6439 | @item stub type has NULL name | |
e251e767 | 6440 | _GDBN__ could not find the full definition for a struct or class. |
70b88761 | 6441 | |
440d9834 | 6442 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
6443 | |
6444 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
6445 | information that recent versions of the compiler should have output |
6446 | for it. | |
70b88761 | 6447 | |
440d9834 | 6448 | @item info mismatch between compiler and debugger |
70b88761 | 6449 | |
440d9834 | 6450 | _GDBN__ could not parse a type specification output by the compiler. |
70b88761 RP |
6451 | @end table |
6452 | ||
4eb4cf57 | 6453 | @node Targets |
e251e767 | 6454 | @chapter Specifying a Debugging Target |
70b88761 RP |
6455 | @cindex debugging target |
6456 | @kindex target | |
1041a570 | 6457 | |
cedaf8bc | 6458 | A @dfn{target} is the execution environment occupied by your program. |
0f153e74 | 6459 | _if__(!_BARE__) |
1041a570 RP |
6460 | Often, _GDBN__ runs in the same host environment as your program; in |
6461 | that case, the debugging target is specified as a side effect when you | |
6462 | use the @code{file} or @code{core} commands. When you need more | |
6463 | flexibility---for example, running _GDBN__ on a physically separate | |
6464 | host, or controlling a standalone system over a serial port or a | |
0f153e74 RP |
6465 | realtime system over a TCP/IP connection---you |
6466 | _fi__(!_BARE__) | |
6467 | _if__(_BARE__) | |
6468 | You | |
6469 | _fi__(_BARE__) | |
6470 | can use the @code{target} command to specify one of the target types | |
6471 | configured for _GDBN__ (@pxref{Target Commands, ,Commands for Managing | |
6472 | Targets}). | |
70b88761 RP |
6473 | |
6474 | @menu | |
b80282d5 RP |
6475 | * Active Targets:: Active Targets |
6476 | * Target Commands:: Commands for Managing Targets | |
6477 | * Remote:: Remote Debugging | |
70b88761 RP |
6478 | @end menu |
6479 | ||
4eb4cf57 | 6480 | @node Active Targets |
70b88761 RP |
6481 | @section Active Targets |
6482 | @cindex stacking targets | |
6483 | @cindex active targets | |
6484 | @cindex multiple targets | |
6485 | ||
0f153e74 | 6486 | _if__(!_BARE__) |
cedaf8bc RP |
6487 | There are three classes of targets: processes, core files, and |
6488 | executable files. _GDBN__ can work concurrently on up to three active | |
6489 | targets, one in each class. This allows you to (for example) start a | |
6490 | process and inspect its activity without abandoning your work on a core | |
6491 | file. | |
70b88761 | 6492 | |
cedaf8bc RP |
6493 | If, for example, you execute @samp{gdb a.out}, then the executable file |
6494 | @code{a.out} is the only active target. If you designate a core file as | |
6495 | well---presumably from a prior run that crashed and coredumped---then | |
6496 | _GDBN__ has two active targets and will use them in tandem, looking | |
6497 | first in the corefile target, then in the executable file, to satisfy | |
6498 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 6499 | are complementary, since core files contain only a program's |
cedaf8bc RP |
6500 | read-write memory---variables and so on---plus machine status, while |
6501 | executable files contain only the program text and initialized data.) | |
0f153e74 | 6502 | _fi__(!_BARE__) |
cedaf8bc RP |
6503 | |
6504 | When you type @code{run}, your executable file becomes an active process | |
6505 | target as well. When a process target is active, all _GDBN__ commands | |
0f153e74 RP |
6506 | requesting memory addresses refer to that target; addresses in an |
6507 | _if__(!_BARE__) | |
6508 | active core file or | |
6509 | _fi__(!_BARE__) | |
6510 | executable file target are obscured while the process | |
cedaf8bc RP |
6511 | target is active. |
6512 | ||
4eb4cf57 RP |
6513 | _if__(_BARE__) |
6514 | Use the @code{exec-file} command to select a | |
6515 | new executable target (@pxref{Files, ,Commands to Specify | |
6516 | Files}). | |
6517 | _fi__(_BARE__) | |
6518 | _if__(!_BARE__) | |
1041a570 RP |
6519 | Use the @code{core-file} and @code{exec-file} commands to select a |
6520 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
6521 | Files}). To specify as a target a process that is already running, use | |
6522 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
6523 | Already-Running Process}.). | |
4eb4cf57 | 6524 | _fi__(!_BARE__) |
70b88761 | 6525 | |
4eb4cf57 | 6526 | @node Target Commands |
70b88761 RP |
6527 | @section Commands for Managing Targets |
6528 | ||
6529 | @table @code | |
6530 | @item target @var{type} @var{parameters} | |
6531 | Connects the _GDBN__ host environment to a target machine or process. A | |
6532 | target is typically a protocol for talking to debugging facilities. You | |
6533 | use the argument @var{type} to specify the type or protocol of the | |
6534 | target machine. | |
6535 | ||
6536 | Further @var{parameters} are interpreted by the target protocol, but | |
6537 | typically include things like device names or host names to connect | |
e251e767 | 6538 | with, process numbers, and baud rates. |
70b88761 RP |
6539 | |
6540 | The @code{target} command will not repeat if you press @key{RET} again | |
6541 | after executing the command. | |
6542 | ||
6543 | @item help target | |
6544 | @kindex help target | |
6545 | Displays the names of all targets available. To display targets | |
6546 | currently selected, use either @code{info target} or @code{info files} | |
29a2b744 | 6547 | (@pxref{Files, ,Commands to Specify Files}). |
70b88761 RP |
6548 | |
6549 | @item help target @var{name} | |
6550 | Describe a particular target, including any parameters necessary to | |
6551 | select it. | |
6552 | @end table | |
6553 | ||
c7cb8acb | 6554 | Here are some common targets (available, or not, depending on the GDB |
70b88761 RP |
6555 | configuration): |
6556 | ||
6557 | @table @code | |
6558 | @item target exec @var{prog} | |
6559 | @kindex target exec | |
6560 | An executable file. @samp{target exec @var{prog}} is the same as | |
6561 | @samp{exec-file @var{prog}}. | |
6562 | ||
6563 | @item target core @var{filename} | |
6564 | @kindex target core | |
6565 | A core dump file. @samp{target core @var{filename}} is the same as | |
6566 | @samp{core-file @var{filename}}. | |
6567 | ||
0f153e74 | 6568 | _if__(_REMOTESTUB__) |
70b88761 RP |
6569 | @item target remote @var{dev} |
6570 | @kindex target remote | |
c7cb8acb | 6571 | Remote serial target in GDB-specific protocol. The argument @var{dev} |
70b88761 | 6572 | specifies what serial device to use for the connection (e.g. |
1041a570 | 6573 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. |
0f153e74 | 6574 | _fi__(_REMOTESTUB__) |
70b88761 RP |
6575 | |
6576 | _if__(_AMD29K__) | |
6577 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
6578 | @kindex target amd-eb | |
6579 | @cindex AMD EB29K | |
6580 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6581 | @var{dev} is the serial device, as for @code{target remote}; | |
6582 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6583 | name of the program to be debugged, as it appears to DOS on the PC. | |
77fe5411 RP |
6584 | @xref{EB29K Remote, ,_GDBN__ with a Remote EB29K}. |
6585 | ||
70b88761 | 6586 | _fi__(_AMD29K__) |
c7cb8acb RP |
6587 | _if__(_H8__) |
6588 | @item target hms | |
6589 | @kindex target hms | |
6590 | A Hitachi H8/300 board, attached via serial line to your host. Use | |
6591 | special commands @code{device} and @code{speed} to control the serial | |
6592 | line and the communications speed used. @xref{Hitachi H8/300 | |
6593 | Remote,,_GDBN__ and the Hitachi H8/300}. | |
6594 | ||
6595 | _fi__(_H8__) | |
70b88761 RP |
6596 | _if__(_I960__) |
6597 | @item target nindy @var{devicename} | |
6598 | @kindex target nindy | |
6599 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6600 | the name of the serial device to use for the connection, e.g. | |
1041a570 | 6601 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}. |
70b88761 RP |
6602 | |
6603 | _fi__(_I960__) | |
77fe5411 RP |
6604 | _if__(_ST2000__) |
6605 | @item target st2000 @var{dev} @var{speed} | |
6606 | @kindex target st2000 | |
6607 | A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev} | |
6608 | is the name of the device attached to the ST2000 serial line; | |
6609 | @var{speed} is the communication line speed. The arguments are not used | |
6610 | if _GDBN__ is configured to connect to the ST2000 using TCP or Telnet. | |
6611 | @xref{ST2000 Remote,,_GDBN__ with a Tandem ST2000}. | |
6612 | ||
6613 | _fi__(_ST2000__) | |
70b88761 RP |
6614 | _if__(_VXWORKS__) |
6615 | @item target vxworks @var{machinename} | |
6616 | @kindex target vxworks | |
6617 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6618 | is the target system's machine name or IP address. | |
1041a570 | 6619 | @xref{VxWorks Remote, ,_GDBN__ and VxWorks}. |
70b88761 RP |
6620 | _fi__(_VXWORKS__) |
6621 | @end table | |
6622 | ||
6623 | _if__(_GENERIC__) | |
6624 | Different targets are available on different configurations of _GDBN__; your | |
6625 | configuration may have more or fewer targets. | |
6626 | _fi__(_GENERIC__) | |
6627 | ||
4eb4cf57 | 6628 | @node Remote |
70b88761 RP |
6629 | @section Remote Debugging |
6630 | @cindex remote debugging | |
6631 | ||
29a2b744 | 6632 | If you are trying to debug a program running on a machine that cannot run |
c7cb8acb | 6633 | GDB in the usual way, it is often useful to use remote debugging. For |
70b88761 RP |
6634 | example, you might use remote debugging on an operating system kernel, or on |
6635 | a small system which does not have a general purpose operating system | |
e251e767 | 6636 | powerful enough to run a full-featured debugger. |
70b88761 | 6637 | |
c7cb8acb | 6638 | Some configurations of GDB have special serial or TCP/IP interfaces |
70b88761 | 6639 | to make this work with particular debugging targets. In addition, |
c7cb8acb | 6640 | GDB comes with a generic serial protocol (specific to GDB, but |
70b88761 RP |
6641 | not specific to any particular target system) which you can use if you |
6642 | write the remote stubs---the code that will run on the remote system to | |
c7cb8acb | 6643 | communicate with GDB. |
70b88761 | 6644 | |
70b88761 | 6645 | Other remote targets may be available in your |
c7cb8acb | 6646 | configuration of GDB; use @code{help targets} to list them. |
70b88761 RP |
6647 | |
6648 | _if__(_GENERIC__) | |
1041a570 RP |
6649 | _dnl__ Text on starting up GDB in various specific cases; it goes up front |
6650 | _dnl__ in manuals configured for any of those particular situations, here | |
6651 | _dnl__ otherwise. | |
6652 | @menu | |
6653 | _include__(gdbinv-m.m4)<>_dnl__ | |
6654 | @end menu | |
70b88761 RP |
6655 | _include__(gdbinv-s.m4) |
6656 | _fi__(_GENERIC__) | |
6657 | ||
4eb4cf57 | 6658 | @node Controlling _GDBN__ |
70b88761 RP |
6659 | @chapter Controlling _GDBN__ |
6660 | ||
6661 | You can alter many aspects of _GDBN__'s interaction with you by using | |
6662 | the @code{set} command. For commands controlling how _GDBN__ displays | |
1041a570 | 6663 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. |
70b88761 RP |
6664 | |
6665 | @menu | |
b80282d5 RP |
6666 | * Prompt:: Prompt |
6667 | * Editing:: Command Editing | |
6668 | * History:: Command History | |
6669 | * Screen Size:: Screen Size | |
6670 | * Numbers:: Numbers | |
6671 | * Messages/Warnings:: Optional Warnings and Messages | |
70b88761 RP |
6672 | @end menu |
6673 | ||
4eb4cf57 | 6674 | @node Prompt |
70b88761 RP |
6675 | @section Prompt |
6676 | @cindex prompt | |
1041a570 | 6677 | |
70b88761 RP |
6678 | _GDBN__ indicates its readiness to read a command by printing a string |
6679 | called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You | |
6680 | can change the prompt string with the @code{set prompt} command. For | |
6681 | instance, when debugging _GDBN__ with _GDBN__, it is useful to change | |
6682 | the prompt in one of the _GDBN__<>s so that you can always tell which | |
6683 | one you are talking to. | |
6684 | ||
6685 | @table @code | |
6686 | @item set prompt @var{newprompt} | |
6687 | @kindex set prompt | |
6688 | Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth. | |
6689 | @kindex show prompt | |
6690 | @item show prompt | |
6691 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6692 | @end table | |
6693 | ||
4eb4cf57 | 6694 | @node Editing |
70b88761 RP |
6695 | @section Command Editing |
6696 | @cindex readline | |
6697 | @cindex command line editing | |
1041a570 | 6698 | |
70b88761 RP |
6699 | _GDBN__ reads its input commands via the @dfn{readline} interface. This |
6700 | GNU library provides consistent behavior for programs which provide a | |
6701 | command line interface to the user. Advantages are @code{emacs}-style | |
6702 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6703 | substitution, and a storage and recall of command history across | |
6704 | debugging sessions. | |
6705 | ||
6706 | You may control the behavior of command line editing in _GDBN__ with the | |
e251e767 | 6707 | command @code{set}. |
70b88761 RP |
6708 | |
6709 | @table @code | |
6710 | @kindex set editing | |
6711 | @cindex editing | |
6712 | @item set editing | |
6713 | @itemx set editing on | |
6714 | Enable command line editing (enabled by default). | |
6715 | ||
6716 | @item set editing off | |
6717 | Disable command line editing. | |
6718 | ||
6719 | @kindex show editing | |
6720 | @item show editing | |
6721 | Show whether command line editing is enabled. | |
6722 | @end table | |
6723 | ||
4eb4cf57 | 6724 | @node History |
70b88761 | 6725 | @section Command History |
1041a570 | 6726 | |
70b88761 RP |
6727 | @table @code |
6728 | @cindex history substitution | |
6729 | @cindex history file | |
6730 | @kindex set history filename | |
6731 | @item set history filename @var{fname} | |
6732 | Set the name of the _GDBN__ command history file to @var{fname}. This is | |
6733 | the file from which _GDBN__ will read an initial command history | |
6734 | list or to which it will write this list when it exits. This list is | |
6735 | accessed through history expansion or through the history | |
6736 | command editing characters listed below. This file defaults to the | |
6737 | value of the environment variable @code{GDBHISTFILE}, or to | |
6738 | @file{./.gdb_history} if this variable is not set. | |
6739 | ||
6740 | @cindex history save | |
6741 | @kindex set history save | |
6742 | @item set history save | |
6743 | @itemx set history save on | |
6744 | Record command history in a file, whose name may be specified with the | |
6745 | @code{set history filename} command. By default, this option is disabled. | |
6746 | ||
6747 | @item set history save off | |
6748 | Stop recording command history in a file. | |
6749 | ||
6750 | @cindex history size | |
6751 | @kindex set history size | |
6752 | @item set history size @var{size} | |
6753 | Set the number of commands which _GDBN__ will keep in its history list. | |
6754 | This defaults to the value of the environment variable | |
6755 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6756 | @end table | |
6757 | ||
6758 | @cindex history expansion | |
6759 | History expansion assigns special meaning to the character @kbd{!}. | |
6760 | @iftex | |
1041a570 | 6761 | @xref{Event Designators}. |
70b88761 RP |
6762 | @end iftex |
6763 | Since @kbd{!} is also the logical not operator in C, history expansion | |
6764 | is off by default. If you decide to enable history expansion with the | |
6765 | @code{set history expansion on} command, you may sometimes need to | |
6766 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
6767 | a space or a tab to prevent it from being expanded. The readline | |
6768 | history facilities will not attempt substitution on the strings | |
6769 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
6770 | ||
6771 | The commands to control history expansion are: | |
6772 | ||
6773 | @table @code | |
6774 | ||
6775 | @kindex set history expansion | |
6776 | @item set history expansion on | |
6777 | @itemx set history expansion | |
6778 | Enable history expansion. History expansion is off by default. | |
6779 | ||
6780 | @item set history expansion off | |
6781 | Disable history expansion. | |
6782 | ||
6783 | The readline code comes with more complete documentation of | |
6784 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 6785 | or @code{vi} may wish to read it. |
70b88761 RP |
6786 | @iftex |
6787 | @xref{Command Line Editing}. | |
6788 | @end iftex | |
6789 | ||
6790 | @c @group | |
6791 | @kindex show history | |
6792 | @item show history | |
6793 | @itemx show history filename | |
6794 | @itemx show history save | |
6795 | @itemx show history size | |
6796 | @itemx show history expansion | |
6797 | These commands display the state of the _GDBN__ history parameters. | |
6798 | @code{show history} by itself displays all four states. | |
6799 | @c @end group | |
70b88761 RP |
6800 | @end table |
6801 | ||
6802 | @table @code | |
6803 | @kindex show commands | |
6804 | @item show commands | |
6805 | Display the last ten commands in the command history. | |
6806 | ||
6807 | @item show commands @var{n} | |
6808 | Print ten commands centered on command number @var{n}. | |
6809 | ||
6810 | @item show commands + | |
6811 | Print ten commands just after the commands last printed. | |
70b88761 RP |
6812 | @end table |
6813 | ||
4eb4cf57 | 6814 | @node Screen Size |
70b88761 RP |
6815 | @section Screen Size |
6816 | @cindex size of screen | |
6817 | @cindex pauses in output | |
1041a570 | 6818 | |
70b88761 RP |
6819 | Certain commands to _GDBN__ may produce large amounts of information |
6820 | output to the screen. To help you read all of it, _GDBN__ pauses and | |
6821 | asks you for input at the end of each page of output. Type @key{RET} | |
6822 | when you want to continue the output. _GDBN__ also uses the screen | |
6823 | width setting to determine when to wrap lines of output. Depending on | |
6824 | what is being printed, it tries to break the line at a readable place, | |
6825 | rather than simply letting it overflow onto the following line. | |
6826 | ||
6827 | Normally _GDBN__ knows the size of the screen from the termcap data base | |
6828 | together with the value of the @code{TERM} environment variable and the | |
6829 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
6830 | you can override it with the @code{set height} and @code{set | |
6831 | width} commands: | |
6832 | ||
6833 | @table @code | |
6834 | @item set height @var{lpp} | |
6835 | @itemx show height | |
6836 | @itemx set width @var{cpl} | |
6837 | @itemx show width | |
6838 | @kindex set height | |
6839 | @kindex set width | |
6840 | @kindex show width | |
6841 | @kindex show height | |
6842 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
6843 | a screen width of @var{cpl} characters. The associated @code{show} | |
6844 | commands display the current settings. | |
6845 | ||
6846 | If you specify a height of zero lines, _GDBN__ will not pause during output | |
6847 | no matter how long the output is. This is useful if output is to a file | |
6848 | or to an editor buffer. | |
6849 | @end table | |
6850 | ||
4eb4cf57 | 6851 | @node Numbers |
70b88761 RP |
6852 | @section Numbers |
6853 | @cindex number representation | |
6854 | @cindex entering numbers | |
1041a570 | 6855 | |
70b88761 RP |
6856 | You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by |
6857 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
6858 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
6859 | Numbers that begin with none of these are, by default, entered in base | |
6860 | 10; likewise, the default display for numbers---when no particular | |
6861 | format is specified---is base 10. You can change the default base for | |
6862 | both input and output with the @code{set radix} command. | |
6863 | ||
6864 | @table @code | |
6865 | @kindex set radix | |
6866 | @item set radix @var{base} | |
6867 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 6868 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
6869 | specified either unambiguously or using the current default radix; for |
6870 | example, any of | |
6871 | ||
6872 | @example | |
c2bbbb22 | 6873 | set radix 1010 |
70b88761 RP |
6874 | set radix 012 |
6875 | set radix 10. | |
6876 | set radix 0xa | |
6877 | @end example | |
6878 | ||
6879 | @noindent | |
6880 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
6881 | will leave the radix unchanged no matter what it was. | |
6882 | ||
6883 | @kindex show radix | |
6884 | @item show radix | |
6885 | Display the current default base for numeric input and display. | |
70b88761 RP |
6886 | @end table |
6887 | ||
4eb4cf57 | 6888 | @node Messages/Warnings |
70b88761 | 6889 | @section Optional Warnings and Messages |
1041a570 | 6890 | |
70b88761 RP |
6891 | By default, _GDBN__ is silent about its inner workings. If you are running |
6892 | on a slow machine, you may want to use the @code{set verbose} command. | |
6893 | It will make _GDBN__ tell you when it does a lengthy internal operation, so | |
1041a570 | 6894 | you will not think it has crashed. |
70b88761 | 6895 | |
1041a570 | 6896 | Currently, the messages controlled by @code{set verbose} are those |
d48da190 RP |
6897 | which announce that the symbol table for a source file is being read; |
6898 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}. | |
70b88761 RP |
6899 | |
6900 | @table @code | |
6901 | @kindex set verbose | |
6902 | @item set verbose on | |
6903 | Enables _GDBN__'s output of certain informational messages. | |
6904 | ||
6905 | @item set verbose off | |
6906 | Disables _GDBN__'s output of certain informational messages. | |
6907 | ||
6908 | @kindex show verbose | |
6909 | @item show verbose | |
6910 | Displays whether @code{set verbose} is on or off. | |
6911 | @end table | |
6912 | ||
b80282d5 RP |
6913 | By default, if _GDBN__ encounters bugs in the symbol table of an object |
6914 | file, it is silent; but if you are debugging a compiler, you may find | |
1041a570 | 6915 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). |
70b88761 RP |
6916 | |
6917 | @table @code | |
6918 | @kindex set complaints | |
6919 | @item set complaints @var{limit} | |
6920 | Permits _GDBN__ to output @var{limit} complaints about each type of unusual | |
6921 | symbols before becoming silent about the problem. Set @var{limit} to | |
6922 | zero to suppress all complaints; set it to a large number to prevent | |
6923 | complaints from being suppressed. | |
6924 | ||
6925 | @kindex show complaints | |
6926 | @item show complaints | |
6927 | Displays how many symbol complaints _GDBN__ is permitted to produce. | |
6928 | @end table | |
6929 | ||
b21b18e1 | 6930 | By default, _GDBN__ is cautious, and asks what sometimes seems to be a |
70b88761 RP |
6931 | lot of stupid questions to confirm certain commands. For example, if |
6932 | you try to run a program which is already running: | |
1041a570 | 6933 | |
70b88761 RP |
6934 | @example |
6935 | (_GDBP__) run | |
6936 | The program being debugged has been started already. | |
e251e767 | 6937 | Start it from the beginning? (y or n) |
70b88761 RP |
6938 | @end example |
6939 | ||
29a2b744 | 6940 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
6941 | commands, you can disable this ``feature'': |
6942 | ||
6943 | @table @code | |
6944 | @kindex set confirm | |
6945 | @cindex flinching | |
6946 | @cindex confirmation | |
6947 | @cindex stupid questions | |
6948 | @item set confirm off | |
6949 | Disables confirmation requests. | |
6950 | ||
6951 | @item set confirm on | |
6952 | Enables confirmation requests (the default). | |
6953 | ||
6954 | @item show confirm | |
6955 | @kindex show confirm | |
6956 | Displays state of confirmation requests. | |
6957 | @end table | |
6958 | ||
29a2b744 | 6959 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
6960 | @cindex reloading symbols |
6961 | Some systems allow individual object files that make up your program to | |
6962 | be replaced without stopping and restarting your program. | |
6963 | _if__(_VXWORKS__) | |
6964 | For example, in VxWorks you can simply recompile a defective object file | |
6965 | and keep on running. | |
6966 | _fi__(_VXWORKS__) | |
29a2b744 | 6967 | If you are running on one of these systems, you can allow _GDBN__ to |
1041a570 RP |
6968 | reload the symbols for automatically relinked modules: |
6969 | ||
b80282d5 RP |
6970 | @table @code |
6971 | @kindex set symbol-reloading | |
6972 | @item set symbol-reloading on | |
6973 | Replace symbol definitions for the corresponding source file when an | |
6974 | object file with a particular name is seen again. | |
6975 | ||
6976 | @item set symbol-reloading off | |
1041a570 | 6977 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 6978 | the same name. This is the default state; if you are not running on a |
b80282d5 RP |
6979 | system that permits automatically relinking modules, you should leave |
6980 | @code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols | |
6981 | when linking large programs, that may contain several modules (from | |
6982 | different directories or libraries) with the same name. | |
6983 | ||
6984 | @item show symbol-reloading | |
6985 | Show the current @code{on} or @code{off} setting. | |
6986 | @end table | |
6987 | ||
4eb4cf57 | 6988 | @node Sequences |
70b88761 RP |
6989 | @chapter Canned Sequences of Commands |
6990 | ||
29a2b744 | 6991 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
1041a570 RP |
6992 | Command Lists}), _GDBN__ provides two ways to store sequences of commands |
6993 | for execution as a unit: user-defined commands and command files. | |
70b88761 RP |
6994 | |
6995 | @menu | |
b80282d5 | 6996 | * Define:: User-Defined Commands |
35a15d60 | 6997 | * Hooks:: User-Defined Command Hooks |
b80282d5 RP |
6998 | * Command Files:: Command Files |
6999 | * Output:: Commands for Controlled Output | |
70b88761 RP |
7000 | @end menu |
7001 | ||
4eb4cf57 | 7002 | @node Define |
70b88761 RP |
7003 | @section User-Defined Commands |
7004 | ||
7005 | @cindex user-defined command | |
7006 | A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you | |
7007 | assign a new name as a command. This is done with the @code{define} | |
7008 | command. | |
7009 | ||
7010 | @table @code | |
7011 | @item define @var{commandname} | |
7012 | @kindex define | |
7013 | Define a command named @var{commandname}. If there is already a command | |
7014 | by that name, you are asked to confirm that you want to redefine it. | |
7015 | ||
7016 | The definition of the command is made up of other _GDBN__ command lines, | |
7017 | which are given following the @code{define} command. The end of these | |
7018 | commands is marked by a line containing @code{end}. | |
7019 | ||
7020 | @item document @var{commandname} | |
7021 | @kindex document | |
7022 | Give documentation to the user-defined command @var{commandname}. The | |
7023 | command @var{commandname} must already be defined. This command reads | |
7024 | lines of documentation just as @code{define} reads the lines of the | |
7025 | command definition, ending with @code{end}. After the @code{document} | |
7026 | command is finished, @code{help} on command @var{commandname} will print | |
7027 | the documentation you have specified. | |
7028 | ||
7029 | You may use the @code{document} command again to change the | |
7030 | documentation of a command. Redefining the command with @code{define} | |
7031 | does not change the documentation. | |
7032 | ||
7033 | @item help user-defined | |
7034 | @kindex help user-defined | |
7035 | List all user-defined commands, with the first line of the documentation | |
7036 | (if any) for each. | |
7037 | ||
4768ba62 JG |
7038 | @item show user |
7039 | @itemx show user @var{commandname} | |
7040 | @kindex show user | |
70b88761 RP |
7041 | Display the _GDBN__ commands used to define @var{commandname} (but not its |
7042 | documentation). If no @var{commandname} is given, display the | |
7043 | definitions for all user-defined commands. | |
7044 | @end table | |
7045 | ||
7046 | User-defined commands do not take arguments. When they are executed, the | |
7047 | commands of the definition are not printed. An error in any command | |
7048 | stops execution of the user-defined command. | |
7049 | ||
7050 | Commands that would ask for confirmation if used interactively proceed | |
7051 | without asking when used inside a user-defined command. Many _GDBN__ commands | |
7052 | that normally print messages to say what they are doing omit the messages | |
7053 | when used in a user-defined command. | |
7054 | ||
35a15d60 JG |
7055 | @node Hooks |
7056 | @section User-Defined Command Hooks | |
7057 | @cindex command files | |
7058 | ||
7059 | You may define @emph{hooks}, which are a special kind of user-defined | |
7060 | command. Whenever you run the command @samp{foo}, if the user-defined | |
7061 | command @samp{hook-foo} exists, it is executed (with no arguments) | |
7062 | before that command. | |
7063 | ||
7064 | In addition, a pseudo-command, @samp{stop} exists. Hooking this command | |
7065 | will cause your hook to be executed every time execution stops in the | |
7066 | inferior program, before breakpoint commands are run, displays are | |
7067 | printed, or the stack frame is printed. | |
7068 | ||
7069 | For example, to cause @code{SIGALRM} signals to be ignored while | |
7070 | single-stepping, but cause them to be resumed during normal execution, | |
7071 | you could do: | |
7072 | ||
7073 | @example | |
7074 | define hook-stop | |
7075 | handle SIGALRM nopass | |
7076 | end | |
7077 | ||
7078 | define hook-run | |
7079 | handle SIGALRM pass | |
7080 | end | |
7081 | ||
7082 | define hook-continue | |
7083 | handle SIGLARM pass | |
7084 | end | |
7085 | @end example | |
7086 | ||
7087 | Any single-word command in GDB can be hooked. Aliases for other commands | |
7088 | cannot be hooked (you should hook the basic command name, e.g. @code{backtrace} | |
7089 | rather than @code{bt}). If an error occurs during the execution of your | |
7090 | hook, execution of GDB commands stops and you are returned to the GDB | |
7091 | prompt (before the command that you actually typed had a chance to run). | |
7092 | ||
7093 | If you try to define a hook which doesn't match any known command, you | |
7094 | will get a warning from the @code{define} command. | |
7095 | ||
4eb4cf57 | 7096 | @node Command Files |
70b88761 RP |
7097 | @section Command Files |
7098 | ||
7099 | @cindex command files | |
7100 | A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments | |
7101 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
7102 | command file does nothing; it does not mean to repeat the last command, as | |
7103 | it would from the terminal. | |
7104 | ||
7105 | @cindex init file | |
7106 | @cindex @file{_GDBINIT__} | |
7107 | When you start _GDBN__, it automatically executes commands from its | |
1041a570 RP |
7108 | @dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads |
7109 | the init file (if any) in your home directory and then the init file | |
7110 | (if any) in the current working directory. (The init files are not | |
7111 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
7112 | ,Choosing Modes}.) You can also request the execution of a command | |
7113 | file with the @code{source} command: | |
70b88761 RP |
7114 | |
7115 | @table @code | |
7116 | @item source @var{filename} | |
7117 | @kindex source | |
7118 | Execute the command file @var{filename}. | |
7119 | @end table | |
7120 | ||
7121 | The lines in a command file are executed sequentially. They are not | |
7122 | printed as they are executed. An error in any command terminates execution | |
7123 | of the command file. | |
7124 | ||
7125 | Commands that would ask for confirmation if used interactively proceed | |
7126 | without asking when used in a command file. Many _GDBN__ commands that | |
7127 | normally print messages to say what they are doing omit the messages | |
7128 | when called from command files. | |
7129 | ||
4eb4cf57 | 7130 | @node Output |
70b88761 RP |
7131 | @section Commands for Controlled Output |
7132 | ||
7133 | During the execution of a command file or a user-defined command, normal | |
7134 | _GDBN__ output is suppressed; the only output that appears is what is | |
7135 | explicitly printed by the commands in the definition. This section | |
7136 | describes three commands useful for generating exactly the output you | |
7137 | want. | |
7138 | ||
7139 | @table @code | |
7140 | @item echo @var{text} | |
7141 | @kindex echo | |
29a2b744 RP |
7142 | @c I do not consider backslash-space a standard C escape sequence |
7143 | @c because it is not in ANSI. | |
1041a570 RP |
7144 | Print @var{text}. Nonprinting characters can be included in |
7145 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
7146 | newline. @strong{No newline will be printed unless you specify one.} | |
7147 | In addition to the standard C escape sequences, a backslash followed | |
7148 | by a space stands for a space. This is useful for outputting a | |
7149 | string with spaces at the beginning or the end, since leading and | |
7150 | trailing spaces are otherwise trimmed from all arguments. | |
7151 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
7152 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
7153 | |
7154 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7155 | the command onto subsequent lines. For example, | |
7156 | ||
7157 | @example | |
7158 | echo This is some text\n\ | |
7159 | which is continued\n\ | |
7160 | onto several lines.\n | |
7161 | @end example | |
7162 | ||
7163 | produces the same output as | |
7164 | ||
7165 | @example | |
7166 | echo This is some text\n | |
7167 | echo which is continued\n | |
7168 | echo onto several lines.\n | |
7169 | @end example | |
7170 | ||
7171 | @item output @var{expression} | |
7172 | @kindex output | |
7173 | Print the value of @var{expression} and nothing but that value: no | |
7174 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 7175 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 7176 | expressions. |
70b88761 RP |
7177 | |
7178 | @item output/@var{fmt} @var{expression} | |
7179 | Print the value of @var{expression} in format @var{fmt}. You can use | |
7180 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
7181 | information. | |
7182 | ||
7183 | @item printf @var{string}, @var{expressions}@dots{} | |
7184 | @kindex printf | |
7185 | Print the values of the @var{expressions} under the control of | |
7186 | @var{string}. The @var{expressions} are separated by commas and may | |
7187 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 7188 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
7189 | |
7190 | @example | |
7191 | printf (@var{string}, @var{expressions}@dots{}); | |
7192 | @end example | |
7193 | ||
7194 | For example, you can print two values in hex like this: | |
7195 | ||
0fd24984 | 7196 | @smallexample |
70b88761 | 7197 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo |
0fd24984 | 7198 | @end smallexample |
70b88761 RP |
7199 | |
7200 | The only backslash-escape sequences that you can use in the format | |
7201 | string are the simple ones that consist of backslash followed by a | |
7202 | letter. | |
7203 | @end table | |
7204 | ||
4eb4cf57 RP |
7205 | _if__(!_DOSHOST__) |
7206 | @node Emacs | |
70b88761 RP |
7207 | @chapter Using _GDBN__ under GNU Emacs |
7208 | ||
7209 | @cindex emacs | |
7210 | A special interface allows you to use GNU Emacs to view (and | |
7211 | edit) the source files for the program you are debugging with | |
7212 | _GDBN__. | |
7213 | ||
7214 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
7215 | executable file you want to debug as an argument. This command starts | |
7216 | _GDBN__ as a subprocess of Emacs, with input and output through a newly | |
7217 | created Emacs buffer. | |
7218 | ||
7219 | Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two | |
7220 | things: | |
7221 | ||
7222 | @itemize @bullet | |
7223 | @item | |
e251e767 | 7224 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
7225 | @end itemize |
7226 | ||
7227 | This applies both to _GDBN__ commands and their output, and to the input | |
7228 | and output done by the program you are debugging. | |
7229 | ||
7230 | This is useful because it means that you can copy the text of previous | |
7231 | commands and input them again; you can even use parts of the output | |
7232 | in this way. | |
7233 | ||
3d3ab540 RP |
7234 | All the facilities of Emacs' Shell mode are available for interacting |
7235 | with your program. In particular, you can send signals the usual | |
7236 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
7237 | stop. | |
70b88761 RP |
7238 | |
7239 | @itemize @bullet | |
7240 | @item | |
e251e767 | 7241 | _GDBN__ displays source code through Emacs. |
70b88761 RP |
7242 | @end itemize |
7243 | ||
7244 | Each time _GDBN__ displays a stack frame, Emacs automatically finds the | |
7245 | source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the | |
7246 | left margin of the current line. Emacs uses a separate buffer for | |
7247 | source display, and splits the window to show both your _GDBN__ session | |
7248 | and the source. | |
7249 | ||
7250 | Explicit _GDBN__ @code{list} or search commands still produce output as | |
7251 | usual, but you probably will have no reason to use them. | |
7252 | ||
7253 | @quotation | |
7254 | @emph{Warning:} If the directory where your program resides is not your | |
7255 | current directory, it can be easy to confuse Emacs about the location of | |
7256 | the source files, in which case the auxiliary display buffer will not | |
7257 | appear to show your source. _GDBN__ can find programs by searching your | |
7258 | environment's @code{PATH} variable, so the _GDBN__ input and output | |
29a2b744 | 7259 | session will proceed normally; but Emacs does not get enough information |
70b88761 RP |
7260 | back from _GDBN__ to locate the source files in this situation. To |
7261 | avoid this problem, either start _GDBN__ mode from the directory where | |
7262 | your program resides, or specify a full path name when prompted for the | |
7263 | @kbd{M-x gdb} argument. | |
7264 | ||
7265 | A similar confusion can result if you use the _GDBN__ @code{file} command to | |
7266 | switch to debugging a program in some other location, from an existing | |
7267 | _GDBN__ buffer in Emacs. | |
7268 | @end quotation | |
7269 | ||
7270 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
7271 | you need to call _GDBN__ by a different name (for example, if you keep | |
7272 | several configurations around, with different names) you can set the | |
7273 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 7274 | |
70b88761 RP |
7275 | @example |
7276 | (setq gdb-command-name "mygdb") | |
7277 | @end example | |
1041a570 | 7278 | |
70b88761 RP |
7279 | @noindent |
7280 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
7281 | in your @file{.emacs} file) will make Emacs call the program named | |
7282 | ``@code{mygdb}'' instead. | |
7283 | ||
7284 | In the _GDBN__ I/O buffer, you can use these special Emacs commands in | |
7285 | addition to the standard Shell mode commands: | |
7286 | ||
7287 | @table @kbd | |
7288 | @item C-h m | |
7289 | Describe the features of Emacs' _GDBN__ Mode. | |
7290 | ||
7291 | @item M-s | |
7292 | Execute to another source line, like the _GDBN__ @code{step} command; also | |
7293 | update the display window to show the current file and location. | |
7294 | ||
7295 | @item M-n | |
7296 | Execute to next source line in this function, skipping all function | |
7297 | calls, like the _GDBN__ @code{next} command. Then update the display window | |
7298 | to show the current file and location. | |
7299 | ||
7300 | @item M-i | |
7301 | Execute one instruction, like the _GDBN__ @code{stepi} command; update | |
7302 | display window accordingly. | |
7303 | ||
7304 | @item M-x gdb-nexti | |
7305 | Execute to next instruction, using the _GDBN__ @code{nexti} command; update | |
7306 | display window accordingly. | |
7307 | ||
7308 | @item C-c C-f | |
7309 | Execute until exit from the selected stack frame, like the _GDBN__ | |
7310 | @code{finish} command. | |
7311 | ||
7312 | @item M-c | |
29a2b744 | 7313 | Continue execution of your program, like the _GDBN__ @code{continue} |
1041a570 | 7314 | command. |
203eea5d RP |
7315 | |
7316 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
7317 | |
7318 | @item M-u | |
7319 | Go up the number of frames indicated by the numeric argument | |
7320 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
1041a570 | 7321 | like the _GDBN__ @code{up} command. |
203eea5d | 7322 | |
1041a570 | 7323 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
7324 | |
7325 | @item M-d | |
7326 | Go down the number of frames indicated by the numeric argument, like the | |
1041a570 | 7327 | _GDBN__ @code{down} command. |
203eea5d RP |
7328 | |
7329 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
7330 | |
7331 | @item C-x & | |
7332 | Read the number where the cursor is positioned, and insert it at the end | |
7333 | of the _GDBN__ I/O buffer. For example, if you wish to disassemble code | |
7334 | around an address that was displayed earlier, type @kbd{disassemble}; | |
7335 | then move the cursor to the address display, and pick up the | |
e251e767 | 7336 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 RP |
7337 | |
7338 | You can customize this further on the fly by defining elements of the list | |
7339 | @code{gdb-print-command}; once it is defined, you can format or | |
7340 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 7341 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
7342 | wish special formatting, and act as an index to pick an element of the |
7343 | list. If the list element is a string, the number to be inserted is | |
7344 | formatted using the Emacs function @code{format}; otherwise the number | |
7345 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
7346 | @end table |
7347 | ||
7348 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
7349 | tells _GDBN__ to set a breakpoint on the source line point is on. | |
7350 | ||
7351 | If you accidentally delete the source-display buffer, an easy way to get | |
7352 | it back is to type the command @code{f} in the _GDBN__ buffer, to | |
7353 | request a frame display; when you run under Emacs, this will recreate | |
7354 | the source buffer if necessary to show you the context of the current | |
7355 | frame. | |
7356 | ||
7357 | The source files displayed in Emacs are in ordinary Emacs buffers | |
7358 | which are visiting the source files in the usual way. You can edit | |
7359 | the files with these buffers if you wish; but keep in mind that _GDBN__ | |
7360 | communicates with Emacs in terms of line numbers. If you add or | |
7361 | delete lines from the text, the line numbers that _GDBN__ knows will cease | |
7362 | to correspond properly to the code. | |
7363 | ||
7364 | @c The following dropped because Epoch is nonstandard. Reactivate | |
7365 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
7366 | @ignore | |
e251e767 | 7367 | @kindex emacs epoch environment |
70b88761 RP |
7368 | @kindex epoch |
7369 | @kindex inspect | |
7370 | ||
7371 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
7372 | environment. Users of this environment can use a new command, | |
7373 | @code{inspect} which performs identically to @code{print} except that | |
7374 | each value is printed in its own window. | |
7375 | @end ignore | |
4eb4cf57 | 7376 | _fi__(!_DOSHOST__) |
70b88761 | 7377 | |
6ca72cc6 | 7378 | _if__(_LUCID__) |
4eb4cf57 | 7379 | @node Energize |
6ca72cc6 RP |
7380 | @chapter Using _GDBN__ with Energize |
7381 | ||
7382 | @cindex Energize | |
7383 | The Energize Programming System is an integrated development environment | |
7384 | that includes a point-and-click interface to many programming tools. | |
7385 | When you use _GDBN__ in this environment, you can use the standard | |
7386 | Energize graphical interface to drive _GDBN__; you can also, if you | |
7387 | choose, type _GDBN__ commands as usual in a debugging window. Even if | |
7388 | you use the graphical interface, the debugging window (which uses Emacs, | |
7389 | and resembles the standard Emacs interface to _GDBN__) displays the | |
7390 | equivalent commands, so that the history of your debugging session is | |
7391 | properly reflected. | |
7392 | ||
7393 | When Energize starts up a _GDBN__ session, it uses one of the | |
7394 | command-line options @samp{-energize} or @samp{-cadillac} (``cadillac'' | |
7395 | is the name of the communications protocol used by the Energize system). | |
7396 | This option makes _GDBN__ run as one of the tools in the Energize Tool | |
7397 | Set: it sends all output to the Energize kernel, and accept input from | |
7398 | it as well. | |
7399 | ||
7400 | See the user manual for the Energize Programming System for | |
7401 | information on how to use the Energize graphical interface and the other | |
7402 | development tools that Energize integrates with _GDBN__. | |
7403 | ||
6ca72cc6 | 7404 | _fi__(_LUCID__) |
4eb4cf57 RP |
7405 | |
7406 | @node _GDBN__ Bugs | |
70b88761 RP |
7407 | @chapter Reporting Bugs in _GDBN__ |
7408 | @cindex Bugs in _GDBN__ | |
7409 | @cindex Reporting Bugs in _GDBN__ | |
7410 | ||
7411 | Your bug reports play an essential role in making _GDBN__ reliable. | |
7412 | ||
7413 | Reporting a bug may help you by bringing a solution to your problem, or it | |
7414 | may not. But in any case the principal function of a bug report is to help | |
7415 | the entire community by making the next version of _GDBN__ work better. Bug | |
7416 | reports are your contribution to the maintenance of _GDBN__. | |
7417 | ||
7418 | In order for a bug report to serve its purpose, you must include the | |
7419 | information that enables us to fix the bug. | |
7420 | ||
7421 | @menu | |
b80282d5 RP |
7422 | * Bug Criteria:: Have You Found a Bug? |
7423 | * Bug Reporting:: How to Report Bugs | |
70b88761 RP |
7424 | @end menu |
7425 | ||
4eb4cf57 | 7426 | @node Bug Criteria |
70b88761 RP |
7427 | @section Have You Found a Bug? |
7428 | @cindex Bug Criteria | |
7429 | ||
7430 | If you are not sure whether you have found a bug, here are some guidelines: | |
7431 | ||
7432 | @itemize @bullet | |
7433 | @item | |
0f153e74 RP |
7434 | @cindex fatal signal |
7435 | @cindex core dump | |
70b88761 RP |
7436 | If the debugger gets a fatal signal, for any input whatever, that is a |
7437 | _GDBN__ bug. Reliable debuggers never crash. | |
7438 | ||
7439 | @item | |
0f153e74 | 7440 | @cindex error on valid input |
70b88761 RP |
7441 | If _GDBN__ produces an error message for valid input, that is a bug. |
7442 | ||
7443 | @item | |
7444 | @cindex Invalid Input | |
7445 | If _GDBN__ does not produce an error message for invalid input, | |
7446 | that is a bug. However, you should note that your idea of | |
7447 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
7448 | for traditional practice''. | |
7449 | ||
7450 | @item | |
7451 | If you are an experienced user of debugging tools, your suggestions | |
7452 | for improvement of _GDBN__ are welcome in any case. | |
7453 | @end itemize | |
7454 | ||
4eb4cf57 | 7455 | @node Bug Reporting |
70b88761 | 7456 | @section How to Report Bugs |
0f153e74 RP |
7457 | @cindex bug reports |
7458 | @cindex _GDBN__ bugs, reporting | |
70b88761 RP |
7459 | |
7460 | A number of companies and individuals offer support for GNU products. | |
7461 | If you obtained _GDBN__ from a support organization, we recommend you | |
e251e767 | 7462 | contact that organization first. |
70b88761 RP |
7463 | |
7464 | Contact information for many support companies and individuals is | |
7465 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
7466 | ||
7467 | In any event, we also recommend that you send bug reports for _GDBN__ to one | |
7468 | of these addresses: | |
7469 | ||
7470 | @example | |
7471 | bug-gdb@@prep.ai.mit.edu | |
7472 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
7473 | @end example | |
7474 | ||
7475 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
7476 | @samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to | |
7477 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
7478 | ||
3d3ab540 RP |
7479 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
7480 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
7481 | the same messages. Often people think of posting bug reports to the | |
7482 | newsgroup instead of mailing them. This appears to work, but it has one | |
7483 | problem which can be crucial: a newsgroup posting often lacks a mail | |
7484 | path back to the sender. Thus, if we need to ask for more information, | |
7485 | we may be unable to reach you. For this reason, it is better to send | |
7486 | bug reports to the mailing list. | |
70b88761 RP |
7487 | |
7488 | As a last resort, send bug reports on paper to: | |
7489 | ||
7490 | @example | |
7491 | GNU Debugger Bugs | |
3d3ab540 | 7492 | Free Software Foundation |
70b88761 RP |
7493 | 545 Tech Square |
7494 | Cambridge, MA 02139 | |
7495 | @end example | |
7496 | ||
7497 | The fundamental principle of reporting bugs usefully is this: | |
7498 | @strong{report all the facts}. If you are not sure whether to state a | |
7499 | fact or leave it out, state it! | |
7500 | ||
7501 | Often people omit facts because they think they know what causes the | |
29a2b744 | 7502 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 7503 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 7504 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
7505 | stray memory reference which happens to fetch from the location where that |
7506 | name is stored in memory; perhaps, if the name were different, the contents | |
7507 | of that location would fool the debugger into doing the right thing despite | |
7508 | the bug. Play it safe and give a specific, complete example. That is the | |
7509 | easiest thing for you to do, and the most helpful. | |
7510 | ||
7511 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 7512 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
7513 | the bug is already known. Therefore, always write your bug reports on |
7514 | the assumption that the bug has not been reported previously. | |
7515 | ||
7516 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
7517 | bell?'' Those bug reports are useless, and we urge everyone to | |
7518 | @emph{refuse to respond to them} except to chide the sender to report | |
7519 | bugs properly. | |
7520 | ||
7521 | To enable us to fix the bug, you should include all these things: | |
7522 | ||
7523 | @itemize @bullet | |
7524 | @item | |
7525 | The version of _GDBN__. _GDBN__ announces it if you start with no | |
7526 | arguments; you can also print it at any time using @code{show version}. | |
7527 | ||
1041a570 | 7528 | Without this, we will not know whether there is any point in looking for |
70b88761 RP |
7529 | the bug in the current version of _GDBN__. |
7530 | ||
7531 | @item | |
ddf21240 JG |
7532 | The type of machine you are using, and the operating system name and |
7533 | version number. | |
70b88761 RP |
7534 | |
7535 | @item | |
7536 | What compiler (and its version) was used to compile _GDBN__---e.g. | |
c7cb8acb | 7537 | ``_GCC__-2.0''. |
70b88761 | 7538 | |
ddf21240 JG |
7539 | @item |
7540 | What compiler (and its version) was used to compile the program you | |
c7cb8acb | 7541 | are debugging---e.g. ``_GCC__-2.0''. |
ddf21240 | 7542 | |
70b88761 RP |
7543 | @item |
7544 | The command arguments you gave the compiler to compile your example and | |
7545 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 7546 | you will not omit something important, list them all. A copy of the |
ddf21240 | 7547 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
7548 | |
7549 | If we were to try to guess the arguments, we would probably guess wrong | |
7550 | and then we might not encounter the bug. | |
7551 | ||
7552 | @item | |
ddf21240 JG |
7553 | A complete input script, and all necessary source files, that will |
7554 | reproduce the bug. | |
70b88761 RP |
7555 | |
7556 | @item | |
7557 | A description of what behavior you observe that you believe is | |
7558 | incorrect. For example, ``It gets a fatal signal.'' | |
7559 | ||
7560 | Of course, if the bug is that _GDBN__ gets a fatal signal, then we will | |
7561 | certainly notice it. But if the bug is incorrect output, we might not | |
7562 | notice unless it is glaringly wrong. We are human, after all. You | |
7563 | might as well not give us a chance to make a mistake. | |
7564 | ||
7565 | Even if the problem you experience is a fatal signal, you should still | |
7566 | say so explicitly. Suppose something strange is going on, such as, | |
7567 | your copy of _GDBN__ is out of synch, or you have encountered a | |
7568 | bug in the C library on your system. (This has happened!) Your copy | |
7569 | might crash and ours would not. If you told us to expect a crash, | |
7570 | then when ours fails to crash, we would know that the bug was not | |
7571 | happening for us. If you had not told us to expect a crash, then we | |
7572 | would not be able to draw any conclusion from our observations. | |
7573 | ||
7574 | @item | |
7575 | If you wish to suggest changes to the _GDBN__ source, send us context | |
7576 | diffs. If you even discuss something in the _GDBN__ source, refer to | |
7577 | it by context, not by line number. | |
7578 | ||
1041a570 | 7579 | The line numbers in our development sources will not match those in your |
70b88761 | 7580 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
7581 | @end itemize |
7582 | ||
7583 | Here are some things that are not necessary: | |
7584 | ||
7585 | @itemize @bullet | |
7586 | @item | |
7587 | A description of the envelope of the bug. | |
7588 | ||
7589 | Often people who encounter a bug spend a lot of time investigating | |
7590 | which changes to the input file will make the bug go away and which | |
7591 | changes will not affect it. | |
7592 | ||
7593 | This is often time consuming and not very useful, because the way we | |
7594 | will find the bug is by running a single example under the debugger | |
7595 | with breakpoints, not by pure deduction from a series of examples. | |
7596 | We recommend that you save your time for something else. | |
7597 | ||
7598 | Of course, if you can find a simpler example to report @emph{instead} | |
7599 | of the original one, that is a convenience for us. Errors in the | |
7600 | output will be easier to spot, running under the debugger will take | |
e251e767 | 7601 | less time, etc. |
70b88761 | 7602 | |
29a2b744 | 7603 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
7604 | report the bug anyway and send us the entire test case you used. |
7605 | ||
7606 | @item | |
7607 | A patch for the bug. | |
7608 | ||
29a2b744 | 7609 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
7610 | the necessary information, such as the test case, on the assumption that |
7611 | a patch is all we need. We might see problems with your patch and decide | |
7612 | to fix the problem another way, or we might not understand it at all. | |
7613 | ||
7614 | Sometimes with a program as complicated as _GDBN__ it is very hard to | |
7615 | construct an example that will make the program follow a certain path | |
1041a570 RP |
7616 | through the code. If you do not send us the example, we will not be able |
7617 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 7618 | |
29a2b744 | 7619 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 7620 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
7621 | help us to understand. |
7622 | ||
7623 | @item | |
7624 | A guess about what the bug is or what it depends on. | |
7625 | ||
29a2b744 | 7626 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
7627 | things without first using the debugger to find the facts. |
7628 | @end itemize | |
7629 | ||
1041a570 RP |
7630 | @c Note: no need to update nodes for rdl-apps.texi since it appears |
7631 | @c *only* in the TeX version of the manual. | |
7632 | @c Note: eventually, make a cross reference to the readline Info nodes. | |
70b88761 | 7633 | @iftex |
cacf5942 RP |
7634 | @c appendices describing GNU readline. Distributed with readline code. |
7635 | @include rluser.texinfo | |
7636 | @include inc-hist.texi | |
70b88761 RP |
7637 | @end iftex |
7638 | ||
4eb4cf57 RP |
7639 | _if__(_GENERIC__||!_H8__) |
7640 | @node Renamed Commands | |
70b88761 RP |
7641 | @appendix Renamed Commands |
7642 | ||
c7cb8acb | 7643 | The following commands were renamed in GDB 4, in order to make the |
70b88761 RP |
7644 | command set as a whole more consistent and easier to use and remember: |
7645 | ||
e251e767 RP |
7646 | @kindex add-syms |
7647 | @kindex delete environment | |
7648 | @kindex info copying | |
7649 | @kindex info convenience | |
7650 | @kindex info directories | |
7651 | @kindex info editing | |
7652 | @kindex info history | |
7653 | @kindex info targets | |
7654 | @kindex info values | |
7655 | @kindex info version | |
7656 | @kindex info warranty | |
7657 | @kindex set addressprint | |
7658 | @kindex set arrayprint | |
7659 | @kindex set prettyprint | |
7660 | @kindex set screen-height | |
7661 | @kindex set screen-width | |
7662 | @kindex set unionprint | |
7663 | @kindex set vtblprint | |
7664 | @kindex set demangle | |
7665 | @kindex set asm-demangle | |
7666 | @kindex set sevenbit-strings | |
7667 | @kindex set array-max | |
7668 | @kindex set caution | |
7669 | @kindex set history write | |
7670 | @kindex show addressprint | |
7671 | @kindex show arrayprint | |
7672 | @kindex show prettyprint | |
7673 | @kindex show screen-height | |
7674 | @kindex show screen-width | |
7675 | @kindex show unionprint | |
7676 | @kindex show vtblprint | |
7677 | @kindex show demangle | |
7678 | @kindex show asm-demangle | |
7679 | @kindex show sevenbit-strings | |
7680 | @kindex show array-max | |
7681 | @kindex show caution | |
7682 | @kindex show history write | |
7683 | @kindex unset | |
70b88761 | 7684 | |
92b73793 | 7685 | @c TEXI2ROFF-KILL |
70b88761 | 7686 | @ifinfo |
92b73793 | 7687 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7688 | @example |
7689 | OLD COMMAND NEW COMMAND | |
92b73793 | 7690 | @c TEXI2ROFF-KILL |
cf496415 | 7691 | --------------- ------------------------------- |
92b73793 | 7692 | @c END TEXI2ROFF-KILL |
cf496415 RP |
7693 | add-syms add-symbol-file |
7694 | delete environment unset environment | |
7695 | info convenience show convenience | |
7696 | info copying show copying | |
e251e767 | 7697 | info directories show directories |
cf496415 RP |
7698 | info editing show commands |
7699 | info history show values | |
7700 | info targets help target | |
7701 | info values show values | |
7702 | info version show version | |
7703 | info warranty show warranty | |
7704 | set/show addressprint set/show print address | |
7705 | set/show array-max set/show print elements | |
7706 | set/show arrayprint set/show print array | |
7707 | set/show asm-demangle set/show print asm-demangle | |
7708 | set/show caution set/show confirm | |
7709 | set/show demangle set/show print demangle | |
7710 | set/show history write set/show history save | |
7711 | set/show prettyprint set/show print pretty | |
7712 | set/show screen-height set/show height | |
7713 | set/show screen-width set/show width | |
7714 | set/show sevenbit-strings set/show print sevenbit-strings | |
7715 | set/show unionprint set/show print union | |
7716 | set/show vtblprint set/show print vtbl | |
7717 | ||
7718 | unset [No longer an alias for delete] | |
7719 | @end example | |
92b73793 | 7720 | @c TEXI2ROFF-KILL |
70b88761 RP |
7721 | @end ifinfo |
7722 | ||
7723 | @tex | |
7724 | \vskip \parskip\vskip \baselineskip | |
7725 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
7726 | {\bf Old Command} &&{\bf New Command}\cr | |
7727 | add-syms &&add-symbol-file\cr | |
7728 | delete environment &&unset environment\cr | |
7729 | info convenience &&show convenience\cr | |
7730 | info copying &&show copying\cr | |
7731 | info directories &&show directories \cr | |
7732 | info editing &&show commands\cr | |
7733 | info history &&show values\cr | |
7734 | info targets &&help target\cr | |
7735 | info values &&show values\cr | |
7736 | info version &&show version\cr | |
7737 | info warranty &&show warranty\cr | |
7738 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
7739 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
7740 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
7741 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
7742 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
7743 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
7744 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
7745 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
7746 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
7747 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
7748 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
7749 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
7750 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
7751 | \cr | |
7752 | unset &&\rm(No longer an alias for delete)\cr | |
7753 | } | |
7754 | @end tex | |
92b73793 | 7755 | @c END TEXI2ROFF-KILL |
4eb4cf57 | 7756 | _fi__(_GENERIC__||!_H8__) |
70b88761 | 7757 | |
0f153e74 | 7758 | _if__(!_PRECONFIGURED__) |
4eb4cf57 | 7759 | @node Formatting Documentation |
77b46d13 JG |
7760 | @appendix Formatting the Documentation |
7761 | ||
7762 | @cindex GDB reference card | |
7763 | @cindex reference card | |
7764 | The GDB 4 release includes an already-formatted reference card, ready | |
b1385986 | 7765 | for printing with PostScript or GhostScript, in the @file{gdb} |
77b46d13 | 7766 | subdirectory of the main source directory---in |
b1385986 RP |
7767 | @file{gdb-_GDB_VN__/gdb/refcard.ps} of the version _GDB_VN__ release. |
7768 | If you can use PostScript or GhostScript with your printer, you can | |
7769 | print the reference card immediately with @file{refcard.ps}. | |
77b46d13 JG |
7770 | |
7771 | The release also includes the source for the reference card. You | |
7772 | can format it, using @TeX{}, by typing: | |
7773 | ||
7774 | @example | |
7775 | make refcard.dvi | |
7776 | @end example | |
7777 | ||
7778 | The GDB reference card is designed to print in landscape mode on US | |
7779 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
7780 | high. You will need to specify this form of printing as an option to | |
7781 | your @sc{dvi} output program. | |
7782 | ||
7783 | @cindex documentation | |
7784 | ||
7785 | All the documentation for GDB comes as part of the machine-readable | |
7786 | distribution. The documentation is written in Texinfo format, which is | |
7787 | a documentation system that uses a single source file to produce both | |
7788 | on-line information and a printed manual. You can use one of the Info | |
7789 | formatting commands to create the on-line version of the documentation | |
7790 | and @TeX{} (or @code{texi2roff}) to typeset the printed version. | |
7791 | ||
7792 | GDB includes an already formatted copy of the on-line Info version of | |
7793 | this manual in the @file{gdb} subdirectory. The main Info file is | |
7794 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
a89f94c2 RP |
7795 | subordinate files matching @samp{gdb.info*} in the same directory. If |
7796 | necessary, you can print out these files, or read them with any editor; | |
7797 | but they are easier to read using the @code{info} subsystem in GNU Emacs | |
7798 | or the standalone @code{info} program, available as part of the GNU | |
7799 | Texinfo distribution. | |
77b46d13 JG |
7800 | |
7801 | If you want to format these Info files yourself, you need one of the | |
7802 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
7803 | @code{makeinfo}. | |
7804 | ||
7805 | If you have @code{makeinfo} installed, and are in the top level GDB | |
7806 | source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can | |
7807 | make the Info file by typing: | |
7808 | ||
7809 | @example | |
7810 | cd gdb | |
7811 | make gdb.info | |
7812 | @end example | |
7813 | ||
7814 | If you want to typeset and print copies of this manual, you need | |
7815 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
7816 | the Texinfo definitions file. | |
7817 | ||
7818 | @TeX{} is typesetting program; it does not print files directly, but | |
7819 | produces output files called @sc{dvi} files. To print a typeset | |
7820 | document, you need a program to print @sc{dvi} files. If your system | |
7821 | has @TeX{} installed, chances are it has such a program. The precise | |
7822 | command to use depends on your system; @kbd{lpr -d} is common; another | |
7823 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
7824 | without any extension or a @samp{.dvi} extension. | |
7825 | ||
7826 | @TeX{} also requires a macro definitions file called | |
7827 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
7828 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
7829 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
7830 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
7831 | directory. | |
7832 | ||
7833 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
7834 | typeset and print this manual. First switch to the the @file{gdb} | |
7835 | subdirectory of the main source directory (for example, to | |
7836 | @file{gdb-_GDB_VN__/gdb}) and then type: | |
7837 | ||
7838 | @example | |
7839 | make gdb.dvi | |
7840 | @end example | |
7841 | ||
4eb4cf57 | 7842 | @node Installing GDB |
c7cb8acb RP |
7843 | @appendix Installing GDB |
7844 | @cindex configuring GDB | |
70b88761 RP |
7845 | @cindex installation |
7846 | ||
f672bb7f RP |
7847 | @iftex |
7848 | @c irrelevant in info file; it's as current as the code it lives with. | |
7849 | @quotation | |
7850 | @emph{Warning:} These installation instructions are current as of | |
c7cb8acb RP |
7851 | GDB version _GDB_VN__. If you're installing a more recent release |
7852 | of GDB, we may have improved the installation procedures since | |
f672bb7f RP |
7853 | printing this manual; see the @file{README} file included in your |
7854 | release for the most recent instructions. | |
7855 | @end quotation | |
7856 | @end iftex | |
7857 | ||
c7cb8acb RP |
7858 | GDB comes with a @code{configure} script that automates the process |
7859 | of preparing GDB for installation; you can then use @code{make} to | |
7860 | build the program. | |
b80282d5 | 7861 | |
c7cb8acb | 7862 | The GDB distribution includes all the source code you need for GDB in |
1041a570 RP |
7863 | a single directory, whose name is usually composed by appending the |
7864 | version number to @samp{gdb}. | |
7865 | ||
c7cb8acb | 7866 | For example, the GDB version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__} |
1041a570 | 7867 | directory. That directory contains: |
b80282d5 | 7868 | |
3d3ab540 | 7869 | @table @code |
c7637ea6 | 7870 | @item gdb-_GDB_VN__/configure @r{(and supporting files)} |
c7cb8acb | 7871 | script for configuring GDB and all its supporting libraries. |
b80282d5 | 7872 | |
3e0d0a27 | 7873 | @item gdb-_GDB_VN__/gdb |
c7cb8acb | 7874 | the source specific to GDB itself |
3d3ab540 | 7875 | |
3e0d0a27 | 7876 | @item gdb-_GDB_VN__/bfd |
77b46d13 | 7877 | source for the Binary File Descriptor library |
3d3ab540 | 7878 | |
3e0d0a27 | 7879 | @item gdb-_GDB_VN__/include |
b80282d5 | 7880 | GNU include files |
3d3ab540 | 7881 | |
3e0d0a27 | 7882 | @item gdb-_GDB_VN__/libiberty |
3d3ab540 RP |
7883 | source for the @samp{-liberty} free software library |
7884 | ||
3214c51c JG |
7885 | @item gdb-_GDB_VN__/opcodes |
7886 | source for the library of opcode tables and disassemblers | |
7887 | ||
3e0d0a27 | 7888 | @item gdb-_GDB_VN__/readline |
b80282d5 | 7889 | source for the GNU command-line interface |
77b46d13 JG |
7890 | |
7891 | @item gdb-_GDB_VN__/glob | |
7892 | source for the GNU filename pattern-matching subroutine | |
7893 | ||
7894 | @item gdb-_GDB_VN__/mmalloc | |
7895 | source for the GNU memory-mapped malloc package | |
3d3ab540 | 7896 | @end table |
1041a570 | 7897 | |
c7cb8acb | 7898 | The simplest way to configure and build GDB is to run @code{configure} |
1041a570 RP |
7899 | from the @file{gdb-@var{version-number}} source directory, which in |
7900 | this example is the @file{gdb-_GDB_VN__} directory. | |
7901 | ||
7902 | First switch to the @file{gdb-@var{version-number}} source directory | |
7903 | if you are not already in it; then run @code{configure}. Pass the | |
c7cb8acb | 7904 | identifier for the platform on which GDB will run as an |
1041a570 RP |
7905 | argument. |
7906 | ||
7907 | For example: | |
7908 | ||
7463aadd | 7909 | @example |
3e0d0a27 | 7910 | cd gdb-_GDB_VN__ |
3d3ab540 | 7911 | ./configure @var{host} |
7463aadd RP |
7912 | make |
7913 | @end example | |
1041a570 | 7914 | |
7463aadd | 7915 | @noindent |
1041a570 | 7916 | where @var{host} is an identifier such as @samp{sun4} or |
c7cb8acb | 7917 | @samp{decstation}, that identifies the platform where GDB will run. |
1041a570 | 7918 | |
38962738 RP |
7919 | Running @samp{configure @var{host}} followed by @code{make} builds the |
7920 | @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty} | |
7921 | libraries, then @code{gdb} itself. The configured source files, and the | |
7922 | binaries, are left in the corresponding source directories. | |
3d3ab540 | 7923 | |
e251e767 | 7924 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 7925 | system does not recognize this automatically when you run a different |
1041a570 RP |
7926 | shell, you may need to run @code{sh} on it explicitly: |
7927 | ||
7928 | @example | |
7929 | sh configure @var{host} | |
7930 | @end example | |
e251e767 | 7931 | |
f672bb7f RP |
7932 | If you run @code{configure} from a directory that contains source |
7933 | directories for multiple libraries or programs, such as the | |
7934 | @file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure} | |
7935 | creates configuration files for every directory level underneath (unless | |
98349959 | 7936 | you tell it not to, with the @samp{--norecursion} option). |
f672bb7f RP |
7937 | |
7938 | You can run the @code{configure} script from any of the | |
c7cb8acb | 7939 | subordinate directories in the GDB distribution, if you only want to |
1041a570 RP |
7940 | configure that subdirectory; but be sure to specify a path to it. |
7941 | ||
7942 | For example, with version _GDB_VN__, type the following to configure only | |
7943 | the @code{bfd} subdirectory: | |
7944 | ||
e251e767 | 7945 | @example |
203eea5d | 7946 | @group |
e251e767 RP |
7947 | cd gdb-_GDB_VN__/bfd |
7948 | ../configure @var{host} | |
203eea5d | 7949 | @end group |
e251e767 RP |
7950 | @end example |
7951 | ||
1041a570 RP |
7952 | You can install @code{_GDBP__} anywhere; it has no hardwired paths. |
7953 | However, you should make sure that the shell on your path (named by | |
7954 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
c7cb8acb RP |
7955 | that GDB uses the shell to start your program---some systems refuse to |
7956 | let GDB debug child processes whose programs are not readable. | |
3d3ab540 RP |
7957 | |
7958 | @menu | |
c7cb8acb | 7959 | * Separate Objdir:: Compiling GDB in another directory |
b80282d5 RP |
7960 | * Config Names:: Specifying names for hosts and targets |
7961 | * configure Options:: Summary of options for configure | |
3d3ab540 RP |
7962 | @end menu |
7963 | ||
4eb4cf57 | 7964 | @node Separate Objdir |
c7cb8acb | 7965 | @section Compiling GDB in Another Directory |
1041a570 | 7966 | |
c7cb8acb RP |
7967 | If you want to run GDB versions for several host or target machines, |
7968 | you'll need a different @code{gdb} compiled for each combination of | |
1041a570 | 7969 | host and target. @code{configure} is designed to make this easy by |
f672bb7f RP |
7970 | allowing you to generate each configuration in a separate subdirectory, |
7971 | rather than in the source directory. If your @code{make} program | |
7972 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
c7cb8acb | 7973 | @code{make} in each of these directories then builds the @code{gdb} |
f672bb7f | 7974 | program specified there. |
b80282d5 | 7975 | |
c7cb8acb | 7976 | To build @code{gdb} in a separate directory, run @code{configure} |
f672bb7f | 7977 | with the @samp{--srcdir} option to specify where to find the source. |
77b46d13 JG |
7978 | (You'll also need to specify a path to find @code{configure} |
7979 | itself from your working directory. If the path to @code{configure} | |
7980 | would be the same as the argument to @samp{--srcdir}, you can leave out | |
7981 | the @samp{--srcdir} option; it will be assumed.) | |
1041a570 | 7982 | |
c7cb8acb | 7983 | For example, with version _GDB_VN__, you can build GDB in a separate |
f672bb7f | 7984 | directory for a Sun 4 like this: |
70b88761 RP |
7985 | |
7986 | @example | |
3d3ab540 | 7987 | @group |
3e0d0a27 | 7988 | cd gdb-_GDB_VN__ |
f672bb7f RP |
7989 | mkdir ../gdb-sun4 |
7990 | cd ../gdb-sun4 | |
77b46d13 | 7991 | ../gdb-_GDB_VN__/configure sun4 |
70b88761 | 7992 | make |
3d3ab540 | 7993 | @end group |
70b88761 RP |
7994 | @end example |
7995 | ||
f672bb7f RP |
7996 | When @code{configure} builds a configuration using a remote source |
7997 | directory, it creates a tree for the binaries with the same structure | |
7998 | (and using the same names) as the tree under the source directory. In | |
7999 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
c7cb8acb | 8000 | directory @file{gdb-sun4/libiberty}, and GDB itself in |
f672bb7f | 8001 | @file{gdb-sun4/gdb}. |
1041a570 | 8002 | |
38962738 | 8003 | One popular reason to build several GDB configurations in separate |
c7cb8acb | 8004 | directories is to configure GDB for cross-compiling (where GDB |
f672bb7f RP |
8005 | runs on one machine---the host---while debugging programs that run on |
8006 | another machine---the target). You specify a cross-debugging target by | |
8007 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
c7637ea6 | 8008 | |
1041a570 | 8009 | When you run @code{make} to build a program or library, you must run |
f672bb7f RP |
8010 | it in a configured directory---whatever directory you were in when you |
8011 | called @code{configure} (or one of its subdirectories). | |
c7637ea6 RP |
8012 | |
8013 | The @code{Makefile} generated by @code{configure} for each source | |
f672bb7f RP |
8014 | directory also runs recursively. If you type @code{make} in a source |
8015 | directory such as @file{gdb-_GDB_VN__} (or in a separate configured | |
8016 | directory configured with @samp{--srcdir=@var{path}/gdb-_GDB_VN__}), you | |
c7cb8acb | 8017 | will build all the required libraries, then build GDB. |
3d3ab540 | 8018 | |
f672bb7f RP |
8019 | When you have multiple hosts or targets configured in separate |
8020 | directories, you can run @code{make} on them in parallel (for example, | |
8021 | if they are NFS-mounted on each of the hosts); they will not interfere | |
8022 | with each other. | |
3d3ab540 | 8023 | |
4eb4cf57 | 8024 | @node Config Names |
b80282d5 RP |
8025 | @section Specifying Names for Hosts and Targets |
8026 | ||
8027 | The specifications used for hosts and targets in the @code{configure} | |
8028 | script are based on a three-part naming scheme, but some short predefined | |
8029 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 8030 | of information in the following pattern: |
1041a570 | 8031 | |
b80282d5 RP |
8032 | @example |
8033 | @var{architecture}-@var{vendor}-@var{os} | |
8034 | @end example | |
8035 | ||
8036 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
5e3186ab | 8037 | or in a @code{--target=@var{target}} option, but the equivalent full name |
e251e767 | 8038 | is @samp{sparc-sun-sunos4}. |
b80282d5 | 8039 | |
c7cb8acb | 8040 | The @code{configure} script accompanying GDB does not provide |
b80282d5 RP |
8041 | any query facility to list all supported host and target names or |
8042 | aliases. @code{configure} calls the Bourne shell script | |
8043 | @code{config.sub} to map abbreviations to full names; you can read the | |
8044 | script, if you wish, or you can use it to test your guesses on | |
8045 | abbreviations---for example: | |
1041a570 | 8046 | |
b1385986 | 8047 | @smallexample |
b80282d5 | 8048 | % sh config.sub sun4 |
6a8cb0e7 | 8049 | sparc-sun-sunos411 |
b80282d5 | 8050 | % sh config.sub sun3 |
6a8cb0e7 | 8051 | m68k-sun-sunos411 |
b80282d5 | 8052 | % sh config.sub decstation |
6a8cb0e7 | 8053 | mips-dec-ultrix42 |
b80282d5 RP |
8054 | % sh config.sub hp300bsd |
8055 | m68k-hp-bsd | |
8056 | % sh config.sub i386v | |
6a8cb0e7 | 8057 | i386-unknown-sysv |
e94b4a2b | 8058 | % sh config.sub i786v |
6a8cb0e7 | 8059 | Invalid configuration `i786v': machine `i786v' not recognized |
b1385986 | 8060 | @end smallexample |
1041a570 | 8061 | |
c7637ea6 | 8062 | @noindent |
1041a570 RP |
8063 | @code{config.sub} is also distributed in the GDB source |
8064 | directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__). | |
b80282d5 | 8065 | |
4eb4cf57 | 8066 | @node configure Options |
3d3ab540 | 8067 | @section @code{configure} Options |
7463aadd | 8068 | |
d48da190 RP |
8069 | Here is a summary of the @code{configure} options and arguments that |
8070 | are most often useful for building _GDBN__. @code{configure} also has | |
8071 | several other options not listed here. @inforef{What Configure | |
8072 | Does,,configure.info}, for a full explanation of @code{configure}. | |
8073 | @c FIXME: Would this be more, or less, useful as an xref (ref to printed | |
8074 | @c manual in the printed manual, ref to info file only from the info file)? | |
7463aadd RP |
8075 | |
8076 | @example | |
d48da190 RP |
8077 | configure @r{[}--help@r{]} |
8078 | @r{[}--prefix=@var{dir}@r{]} | |
8079 | @r{[}--srcdir=@var{path}@r{]} | |
f672bb7f RP |
8080 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} |
8081 | @r{[}--target=@var{target}@r{]} @var{host} | |
7463aadd | 8082 | @end example |
1041a570 | 8083 | |
3d3ab540 | 8084 | @noindent |
f672bb7f RP |
8085 | You may introduce options with a single @samp{-} rather than |
8086 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
8087 | @samp{--}. | |
70b88761 RP |
8088 | |
8089 | @table @code | |
d48da190 RP |
8090 | @item --help |
8091 | Display a quick summary of how to invoke @code{configure}. | |
8092 | ||
8093 | @item -prefix=@var{dir} | |
8094 | Configure the source to install programs and files under directory | |
8095 | @file{@var{dir}}. | |
8096 | ||
f672bb7f | 8097 | @item --srcdir=@var{path} |
6ca72cc6 RP |
8098 | @strong{Warning: using this option requires GNU @code{make}, or another |
8099 | @code{make} that implements the @code{VPATH} feature.}@* | |
f672bb7f | 8100 | Use this option to make configurations in directories separate from the |
c7cb8acb | 8101 | GDB source directories. Among other things, you can use this to |
f672bb7f RP |
8102 | build (or maintain) several configurations simultaneously, in separate |
8103 | directories. @code{configure} writes configuration specific files in | |
8104 | the current directory, but arranges for them to use the source in the | |
8105 | directory @var{path}. @code{configure} will create directories under | |
8106 | the working directory in parallel to the source directories below | |
8107 | @var{path}. | |
8108 | ||
8109 | @item --norecursion | |
8110 | Configure only the directory level where @code{configure} is executed; do not | |
7463aadd RP |
8111 | propagate configuration to subdirectories. |
8112 | ||
f672bb7f | 8113 | @item --rm |
b80282d5 | 8114 | Remove the configuration that the other arguments specify. |
7463aadd | 8115 | |
29a2b744 | 8116 | @c This does not work (yet if ever). FIXME. |
f672bb7f | 8117 | @c @item --parse=@var{lang} @dots{} |
c7cb8acb RP |
8118 | @c Configure the GDB expression parser to parse the listed languages. |
8119 | @c @samp{all} configures GDB for all supported languages. To get a | |
d7b569d5 | 8120 | @c list of all supported languages, omit the argument. Without this |
c7cb8acb | 8121 | @c option, GDB is configured to parse all supported languages. |
c2bbbb22 | 8122 | |
f672bb7f | 8123 | @item --target=@var{target} |
c7cb8acb RP |
8124 | Configure GDB for cross-debugging programs running on the specified |
8125 | @var{target}. Without this option, GDB is configured to debug | |
8126 | programs that run on the same machine (@var{host}) as GDB itself. | |
b80282d5 RP |
8127 | |
8128 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
8129 | |
8130 | @item @var{host} @dots{} | |
c7cb8acb | 8131 | Configure GDB to run on the specified @var{host}. |
b80282d5 RP |
8132 | |
8133 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
8134 | @end table |
8135 | ||
3d3ab540 RP |
8136 | @noindent |
8137 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 8138 | configuring other GNU tools recursively; but these are the only |
c7cb8acb | 8139 | options that affect GDB or its supporting libraries. |
0f153e74 | 8140 | _fi__(!_PRECONFIGURED__) |
3d3ab540 | 8141 | |
0f153e74 | 8142 | _if__(!_AGGLOMERATION__) |
4eb4cf57 | 8143 | @node Copying |
70b88761 | 8144 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 8145 | @center Version 2, June 1991 |
70b88761 RP |
8146 | |
8147 | @display | |
7463aadd | 8148 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
8149 | 675 Mass Ave, Cambridge, MA 02139, USA |
8150 | ||
8151 | Everyone is permitted to copy and distribute verbatim copies | |
8152 | of this license document, but changing it is not allowed. | |
8153 | @end display | |
8154 | ||
8155 | @unnumberedsec Preamble | |
8156 | ||
7463aadd RP |
8157 | The licenses for most software are designed to take away your |
8158 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 8159 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
8160 | software---to make sure the software is free for all its users. This |
8161 | General Public License applies to most of the Free Software | |
8162 | Foundation's software and to any other program whose authors commit to | |
8163 | using it. (Some other Free Software Foundation software is covered by | |
8164 | the GNU Library General Public License instead.) You can apply it to | |
8165 | your programs, too. | |
70b88761 RP |
8166 | |
8167 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
8168 | price. Our General Public Licenses are designed to make sure that you |
8169 | have the freedom to distribute copies of free software (and charge for | |
8170 | this service if you wish), that you receive source code or can get it | |
8171 | if you want it, that you can change the software or use pieces of it | |
8172 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
8173 | |
8174 | To protect your rights, we need to make restrictions that forbid | |
8175 | anyone to deny you these rights or to ask you to surrender the rights. | |
8176 | These restrictions translate to certain responsibilities for you if you | |
8177 | distribute copies of the software, or if you modify it. | |
8178 | ||
7463aadd | 8179 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
8180 | gratis or for a fee, you must give the recipients all the rights that |
8181 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
8182 | source code. And you must show them these terms so they know their |
8183 | rights. | |
70b88761 RP |
8184 | |
8185 | We protect your rights with two steps: (1) copyright the software, and | |
8186 | (2) offer you this license which gives you legal permission to copy, | |
8187 | distribute and/or modify the software. | |
8188 | ||
8189 | Also, for each author's protection and ours, we want to make certain | |
8190 | that everyone understands that there is no warranty for this free | |
8191 | software. If the software is modified by someone else and passed on, we | |
8192 | want its recipients to know that what they have is not the original, so | |
8193 | that any problems introduced by others will not reflect on the original | |
8194 | authors' reputations. | |
8195 | ||
7463aadd RP |
8196 | Finally, any free program is threatened constantly by software |
8197 | patents. We wish to avoid the danger that redistributors of a free | |
8198 | program will individually obtain patent licenses, in effect making the | |
8199 | program proprietary. To prevent this, we have made it clear that any | |
8200 | patent must be licensed for everyone's free use or not licensed at all. | |
8201 | ||
70b88761 RP |
8202 | The precise terms and conditions for copying, distribution and |
8203 | modification follow. | |
8204 | ||
8205 | @iftex | |
7463aadd | 8206 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8207 | @end iftex |
8208 | @ifinfo | |
7463aadd | 8209 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8210 | @end ifinfo |
8211 | ||
8212 | @enumerate | |
8213 | @item | |
7463aadd RP |
8214 | This License applies to any program or other work which contains |
8215 | a notice placed by the copyright holder saying it may be distributed | |
8216 | under the terms of this General Public License. The ``Program'', below, | |
8217 | refers to any such program or work, and a ``work based on the Program'' | |
8218 | means either the Program or any derivative work under copyright law: | |
8219 | that is to say, a work containing the Program or a portion of it, | |
8220 | either verbatim or with modifications and/or translated into another | |
8221 | language. (Hereinafter, translation is included without limitation in | |
8222 | the term ``modification''.) Each licensee is addressed as ``you''. | |
8223 | ||
8224 | Activities other than copying, distribution and modification are not | |
8225 | covered by this License; they are outside its scope. The act of | |
8226 | running the Program is not restricted, and the output from the Program | |
8227 | is covered only if its contents constitute a work based on the | |
8228 | Program (independent of having been made by running the Program). | |
8229 | Whether that is true depends on what the Program does. | |
70b88761 RP |
8230 | |
8231 | @item | |
7463aadd RP |
8232 | You may copy and distribute verbatim copies of the Program's |
8233 | source code as you receive it, in any medium, provided that you | |
8234 | conspicuously and appropriately publish on each copy an appropriate | |
8235 | copyright notice and disclaimer of warranty; keep intact all the | |
8236 | notices that refer to this License and to the absence of any warranty; | |
8237 | and give any other recipients of the Program a copy of this License | |
8238 | along with the Program. | |
70b88761 | 8239 | |
7463aadd RP |
8240 | You may charge a fee for the physical act of transferring a copy, and |
8241 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 8242 | |
70b88761 | 8243 | @item |
7463aadd RP |
8244 | You may modify your copy or copies of the Program or any portion |
8245 | of it, thus forming a work based on the Program, and copy and | |
8246 | distribute such modifications or work under the terms of Section 1 | |
8247 | above, provided that you also meet all of these conditions: | |
70b88761 | 8248 | |
1041a570 | 8249 | @enumerate a |
70b88761 | 8250 | @item |
7463aadd RP |
8251 | You must cause the modified files to carry prominent notices |
8252 | stating that you changed the files and the date of any change. | |
70b88761 RP |
8253 | |
8254 | @item | |
7463aadd RP |
8255 | You must cause any work that you distribute or publish, that in |
8256 | whole or in part contains or is derived from the Program or any | |
8257 | part thereof, to be licensed as a whole at no charge to all third | |
8258 | parties under the terms of this License. | |
70b88761 RP |
8259 | |
8260 | @item | |
7463aadd RP |
8261 | If the modified program normally reads commands interactively |
8262 | when run, you must cause it, when started running for such | |
8263 | interactive use in the most ordinary way, to print or display an | |
8264 | announcement including an appropriate copyright notice and a | |
8265 | notice that there is no warranty (or else, saying that you provide | |
8266 | a warranty) and that users may redistribute the program under | |
8267 | these conditions, and telling the user how to view a copy of this | |
8268 | License. (Exception: if the Program itself is interactive but | |
8269 | does not normally print such an announcement, your work based on | |
8270 | the Program is not required to print an announcement.) | |
1041a570 | 8271 | @end enumerate |
7463aadd RP |
8272 | |
8273 | These requirements apply to the modified work as a whole. If | |
8274 | identifiable sections of that work are not derived from the Program, | |
8275 | and can be reasonably considered independent and separate works in | |
8276 | themselves, then this License, and its terms, do not apply to those | |
8277 | sections when you distribute them as separate works. But when you | |
8278 | distribute the same sections as part of a whole which is a work based | |
8279 | on the Program, the distribution of the whole must be on the terms of | |
8280 | this License, whose permissions for other licensees extend to the | |
8281 | entire whole, and thus to each and every part regardless of who wrote it. | |
8282 | ||
8283 | Thus, it is not the intent of this section to claim rights or contest | |
8284 | your rights to work written entirely by you; rather, the intent is to | |
8285 | exercise the right to control the distribution of derivative or | |
8286 | collective works based on the Program. | |
8287 | ||
8288 | In addition, mere aggregation of another work not based on the Program | |
8289 | with the Program (or with a work based on the Program) on a volume of | |
8290 | a storage or distribution medium does not bring the other work under | |
8291 | the scope of this License. | |
70b88761 RP |
8292 | |
8293 | @item | |
7463aadd RP |
8294 | You may copy and distribute the Program (or a work based on it, |
8295 | under Section 2) in object code or executable form under the terms of | |
8296 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 8297 | |
1041a570 | 8298 | @enumerate a |
70b88761 | 8299 | @item |
7463aadd RP |
8300 | Accompany it with the complete corresponding machine-readable |
8301 | source code, which must be distributed under the terms of Sections | |
8302 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
8303 | |
8304 | @item | |
7463aadd RP |
8305 | Accompany it with a written offer, valid for at least three |
8306 | years, to give any third party, for a charge no more than your | |
8307 | cost of physically performing source distribution, a complete | |
8308 | machine-readable copy of the corresponding source code, to be | |
8309 | distributed under the terms of Sections 1 and 2 above on a medium | |
8310 | customarily used for software interchange; or, | |
70b88761 RP |
8311 | |
8312 | @item | |
7463aadd RP |
8313 | Accompany it with the information you received as to the offer |
8314 | to distribute corresponding source code. (This alternative is | |
70b88761 | 8315 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
8316 | received the program in object code or executable form with such |
8317 | an offer, in accord with Subsection b above.) | |
1041a570 | 8318 | @end enumerate |
7463aadd RP |
8319 | |
8320 | The source code for a work means the preferred form of the work for | |
8321 | making modifications to it. For an executable work, complete source | |
8322 | code means all the source code for all modules it contains, plus any | |
8323 | associated interface definition files, plus the scripts used to | |
8324 | control compilation and installation of the executable. However, as a | |
8325 | special exception, the source code distributed need not include | |
8326 | anything that is normally distributed (in either source or binary | |
8327 | form) with the major components (compiler, kernel, and so on) of the | |
8328 | operating system on which the executable runs, unless that component | |
8329 | itself accompanies the executable. | |
8330 | ||
8331 | If distribution of executable or object code is made by offering | |
8332 | access to copy from a designated place, then offering equivalent | |
8333 | access to copy the source code from the same place counts as | |
8334 | distribution of the source code, even though third parties are not | |
8335 | compelled to copy the source along with the object code. | |
70b88761 RP |
8336 | |
8337 | @item | |
7463aadd RP |
8338 | You may not copy, modify, sublicense, or distribute the Program |
8339 | except as expressly provided under this License. Any attempt | |
8340 | otherwise to copy, modify, sublicense or distribute the Program is | |
8341 | void, and will automatically terminate your rights under this License. | |
8342 | However, parties who have received copies, or rights, from you under | |
8343 | this License will not have their licenses terminated so long as such | |
8344 | parties remain in full compliance. | |
70b88761 RP |
8345 | |
8346 | @item | |
7463aadd RP |
8347 | You are not required to accept this License, since you have not |
8348 | signed it. However, nothing else grants you permission to modify or | |
8349 | distribute the Program or its derivative works. These actions are | |
8350 | prohibited by law if you do not accept this License. Therefore, by | |
8351 | modifying or distributing the Program (or any work based on the | |
8352 | Program), you indicate your acceptance of this License to do so, and | |
8353 | all its terms and conditions for copying, distributing or modifying | |
8354 | the Program or works based on it. | |
70b88761 RP |
8355 | |
8356 | @item | |
8357 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
8358 | Program), the recipient automatically receives a license from the |
8359 | original licensor to copy, distribute or modify the Program subject to | |
8360 | these terms and conditions. You may not impose any further | |
8361 | restrictions on the recipients' exercise of the rights granted herein. | |
8362 | You are not responsible for enforcing compliance by third parties to | |
8363 | this License. | |
8364 | ||
8365 | @item | |
8366 | If, as a consequence of a court judgment or allegation of patent | |
8367 | infringement or for any other reason (not limited to patent issues), | |
8368 | conditions are imposed on you (whether by court order, agreement or | |
8369 | otherwise) that contradict the conditions of this License, they do not | |
8370 | excuse you from the conditions of this License. If you cannot | |
8371 | distribute so as to satisfy simultaneously your obligations under this | |
8372 | License and any other pertinent obligations, then as a consequence you | |
8373 | may not distribute the Program at all. For example, if a patent | |
8374 | license would not permit royalty-free redistribution of the Program by | |
8375 | all those who receive copies directly or indirectly through you, then | |
8376 | the only way you could satisfy both it and this License would be to | |
8377 | refrain entirely from distribution of the Program. | |
8378 | ||
8379 | If any portion of this section is held invalid or unenforceable under | |
8380 | any particular circumstance, the balance of the section is intended to | |
8381 | apply and the section as a whole is intended to apply in other | |
8382 | circumstances. | |
8383 | ||
8384 | It is not the purpose of this section to induce you to infringe any | |
8385 | patents or other property right claims or to contest validity of any | |
8386 | such claims; this section has the sole purpose of protecting the | |
8387 | integrity of the free software distribution system, which is | |
8388 | implemented by public license practices. Many people have made | |
8389 | generous contributions to the wide range of software distributed | |
8390 | through that system in reliance on consistent application of that | |
8391 | system; it is up to the author/donor to decide if he or she is willing | |
8392 | to distribute software through any other system and a licensee cannot | |
8393 | impose that choice. | |
8394 | ||
8395 | This section is intended to make thoroughly clear what is believed to | |
8396 | be a consequence of the rest of this License. | |
8397 | ||
8398 | @item | |
8399 | If the distribution and/or use of the Program is restricted in | |
8400 | certain countries either by patents or by copyrighted interfaces, the | |
8401 | original copyright holder who places the Program under this License | |
8402 | may add an explicit geographical distribution limitation excluding | |
8403 | those countries, so that distribution is permitted only in or among | |
8404 | countries not thus excluded. In such case, this License incorporates | |
8405 | the limitation as if written in the body of this License. | |
70b88761 RP |
8406 | |
8407 | @item | |
8408 | The Free Software Foundation may publish revised and/or new versions | |
8409 | of the General Public License from time to time. Such new versions will | |
8410 | be similar in spirit to the present version, but may differ in detail to | |
8411 | address new problems or concerns. | |
8412 | ||
8413 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 8414 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
8415 | later version'', you have the option of following the terms and conditions |
8416 | either of that version or of any later version published by the Free | |
8417 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 8418 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
8419 | Foundation. |
8420 | ||
8421 | @item | |
8422 | If you wish to incorporate parts of the Program into other free | |
8423 | programs whose distribution conditions are different, write to the author | |
8424 | to ask for permission. For software which is copyrighted by the Free | |
8425 | Software Foundation, write to the Free Software Foundation; we sometimes | |
8426 | make exceptions for this. Our decision will be guided by the two goals | |
8427 | of preserving the free status of all derivatives of our free software and | |
8428 | of promoting the sharing and reuse of software generally. | |
8429 | ||
8430 | @iftex | |
8431 | @heading NO WARRANTY | |
8432 | @end iftex | |
8433 | @ifinfo | |
8434 | @center NO WARRANTY | |
8435 | @end ifinfo | |
8436 | ||
8437 | @item | |
8438 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
8439 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
8440 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
8441 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
8442 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
8443 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
8444 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
8445 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
8446 | REPAIR OR CORRECTION. | |
8447 | ||
8448 | @item | |
7463aadd RP |
8449 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
8450 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 8451 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
8452 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
8453 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
8454 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
8455 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
8456 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
8457 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
8458 | @end enumerate |
8459 | ||
8460 | @iftex | |
8461 | @heading END OF TERMS AND CONDITIONS | |
8462 | @end iftex | |
8463 | @ifinfo | |
8464 | @center END OF TERMS AND CONDITIONS | |
8465 | @end ifinfo | |
8466 | ||
8467 | @page | |
54e6b3c3 | 8468 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
8469 | |
8470 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
8471 | possible use to the public, the best way to achieve this is to make it |
8472 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 8473 | |
7463aadd RP |
8474 | To do so, attach the following notices to the program. It is safest |
8475 | to attach them to the start of each source file to most effectively | |
8476 | convey the exclusion of warranty; and each file should have at least | |
8477 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
8478 | |
8479 | @smallexample | |
203eea5d | 8480 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
8481 | Copyright (C) 19@var{yy} @var{name of author} |
8482 | ||
203eea5d RP |
8483 | This program is free software; you can redistribute it and/or |
8484 | modify it under the terms of the GNU General Public License | |
8485 | as published by the Free Software Foundation; either version 2 | |
8486 | of the License, or (at your option) any later version. | |
70b88761 RP |
8487 | |
8488 | This program is distributed in the hope that it will be useful, | |
8489 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8490 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8491 | GNU General Public License for more details. | |
8492 | ||
8493 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
8494 | along with this program; if not, write to the |
8495 | Free Software Foundation, Inc., 675 Mass Ave, | |
8496 | Cambridge, MA 02139, USA. | |
70b88761 RP |
8497 | @end smallexample |
8498 | ||
8499 | Also add information on how to contact you by electronic and paper mail. | |
8500 | ||
8501 | If the program is interactive, make it output a short notice like this | |
8502 | when it starts in an interactive mode: | |
8503 | ||
8504 | @smallexample | |
8505 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
8506 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
8507 | type `show w'. This is free software, and you are welcome | |
8508 | to redistribute it under certain conditions; type `show c' | |
8509 | for details. | |
70b88761 RP |
8510 | @end smallexample |
8511 | ||
7463aadd RP |
8512 | The hypothetical commands @samp{show w} and @samp{show c} should show |
8513 | the appropriate parts of the General Public License. Of course, the | |
8514 | commands you use may be called something other than @samp{show w} and | |
8515 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8516 | suits your program. | |
70b88761 RP |
8517 | |
8518 | You should also get your employer (if you work as a programmer) or your | |
8519 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8520 | necessary. Here is a sample; alter the names: | |
8521 | ||
1041a570 RP |
8522 | @example |
8523 | Yoyodyne, Inc., hereby disclaims all copyright | |
8524 | interest in the program `Gnomovision' | |
8525 | (which makes passes at compilers) written | |
8526 | by James Hacker. | |
70b88761 RP |
8527 | |
8528 | @var{signature of Ty Coon}, 1 April 1989 | |
8529 | Ty Coon, President of Vice | |
1041a570 | 8530 | @end example |
7463aadd RP |
8531 | |
8532 | This General Public License does not permit incorporating your program into | |
8533 | proprietary programs. If your program is a subroutine library, you may | |
8534 | consider it more useful to permit linking proprietary applications with the | |
8535 | library. If this is what you want to do, use the GNU Library General | |
8536 | Public License instead of this License. | |
0f153e74 | 8537 | _fi__(!_AGGLOMERATION__) |
70b88761 | 8538 | |
4eb4cf57 | 8539 | @node Index |
d2e08421 | 8540 | @unnumbered Index |
e91b87a3 | 8541 | |
8542 | @printindex cp | |
8543 | ||
fe3f5fc8 RP |
8544 | @tex |
8545 | % I think something like @colophon should be in texinfo. In the | |
8546 | % meantime: | |
8547 | \long\def\colophon{\hbox to0pt{}\vfill | |
8548 | \centerline{The body of this manual is set in} | |
8549 | \centerline{\fontname\tenrm,} | |
8550 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8551 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
8552 | \centerline{{\it\fontname\tenit\/},} |
8553 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
8554 | \centerline{{\sl\fontname\tensl\/}} |
8555 | \centerline{are used for emphasis.}\vfill} | |
8556 | \page\colophon | |
a6d0b6d3 | 8557 | % Blame: [email protected], 1991. |
fe3f5fc8 RP |
8558 | @end tex |
8559 | ||
e91b87a3 | 8560 | @contents |
8561 | @bye |