]>
Commit | Line | Data |
---|---|---|
29a2b744 | 1 | \input texinfo @c -*-texinfo-*- |
ed447b95 | 2 | @c Copyright (c) 1988 1989 1990 1991 1992 1993 Free Software Foundation, Inc. |
18fae2a8 | 3 | @c |
29a2b744 | 4 | @c %**start of header |
18fae2a8 | 5 | @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use |
1d7c3357 | 6 | @c of @set vars. However, you can override filename with makeinfo -o. |
18fae2a8 RP |
7 | @setfilename gdb.info |
8 | @c | |
9 | @include gdb-config.texi | |
10 | @c | |
11 | @ifset GENERIC | |
12 | @settitle Debugging with @value{GDBN} | |
13 | @end ifset | |
14 | @ifclear GENERIC | |
1d7c3357 | 15 | @settitle Debugging with @value{GDBN} (@value{TARGET}) |
18fae2a8 | 16 | @end ifclear |
29a2b744 | 17 | @setchapternewpage odd |
29a2b744 RP |
18 | @c %**end of header |
19 | ||
ed447b95 | 20 | @iftex |
51b65b74 | 21 | @c @smallbook |
fe715d06 | 22 | @c @cropmarks |
ed447b95 RP |
23 | @end iftex |
24 | ||
25 | @c Include the readline documentation in the TeX output, | |
26 | @c but not in the Info output. | |
27 | @c Eventually, we should make a cross reference to the Readline Info | |
28 | @c nodes; but this requires that the nodes exist and be in an expected | |
29 | @c place. Wait for a standard, complete GNU distribution. Meanwhile, | |
30 | @c cross references are only in the printed TeX output, and only when | |
31 | @c `have-readline-appendices' is set. | |
32 | @c | |
33 | @c The readline documentation is distributed with the readline code | |
34 | @c and consists of the two following files: | |
35 | @c rluser.texinfo | |
36 | @c inc-hist.texi | |
37 | @iftex | |
38 | @set have-readline-appendices | |
39 | @end iftex | |
40 | @ifinfo | |
41 | @clear have-readline-appendices | |
42 | @end ifinfo | |
43 | ||
29a2b744 RP |
44 | @finalout |
45 | @syncodeindex ky cp | |
46 | ||
fe715d06 RP |
47 | @c readline appendices use @vindex |
48 | @syncodeindex vr cp | |
49 | ||
18fae2a8 | 50 | @c ===> NOTE! <== |
29a2b744 RP |
51 | @c Determine the edition number in *three* places by hand: |
52 | @c 1. First ifinfo section 2. title page 3. top node | |
53 | @c To find the locations, search for !!set | |
54 | ||
d24e0922 | 55 | @c GDB CHANGELOG CONSULTED BETWEEN: |
29a2b744 RP |
56 | @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com) |
57 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
58 | ||
9c3ad547 | 59 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. |
29a2b744 | 60 | |
b7becc8f | 61 | @ifinfo |
ed447b95 RP |
62 | @c This is a dir.info fragment to support semi-automated addition of |
63 | @c manuals to an info tree. [email protected] is developing this facility. | |
b7becc8f RP |
64 | @format |
65 | START-INFO-DIR-ENTRY | |
29a2b744 | 66 | * Gdb: (gdb). The GNU debugger. |
b7becc8f RP |
67 | END-INFO-DIR-ENTRY |
68 | @end format | |
69 | @end ifinfo | |
18fae2a8 | 70 | @c |
70b88761 | 71 | @c |
70b88761 | 72 | @ifinfo |
18fae2a8 | 73 | This file documents the GNU debugger @value{GDBN}. |
70b88761 | 74 | |
29a2b744 | 75 | @c !!set edition, date, version |
a64a6c2b | 76 | This is Edition 4.09, April 1993, |
18fae2a8 RP |
77 | of @cite{Debugging with @value{GDBN}: the GNU Source-Level Debugger} |
78 | for GDB Version @value{GDBVN}. | |
29a2b744 | 79 | |
ed447b95 | 80 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
70b88761 RP |
81 | |
82 | Permission is granted to make and distribute verbatim copies of | |
83 | this manual provided the copyright notice and this permission notice | |
84 | are preserved on all copies. | |
85 | ||
86 | @ignore | |
87 | Permission is granted to process this file through TeX and print the | |
88 | results, provided the printed document carries copying permission | |
89 | notice identical to this one except for the removal of this paragraph | |
90 | (this paragraph not being relevant to the printed manual). | |
91 | ||
92 | @end ignore | |
93 | Permission is granted to copy and distribute modified versions of this | |
94 | manual under the conditions for verbatim copying, provided also that the | |
95 | section entitled ``GNU General Public License'' is included exactly as | |
96 | in the original, and provided that the entire resulting derived work is | |
97 | distributed under the terms of a permission notice identical to this | |
98 | one. | |
99 | ||
100 | Permission is granted to copy and distribute translations of this manual | |
101 | into another language, under the above conditions for modified versions, | |
102 | except that the section entitled ``GNU General Public License'' may be | |
103 | included in a translation approved by the Free Software Foundation | |
104 | instead of in the original English. | |
105 | @end ifinfo | |
1041a570 | 106 | |
70b88761 | 107 | @titlepage |
18fae2a8 | 108 | @title Debugging with @value{GDBN} |
95d5ceb9 | 109 | @subtitle The GNU Source-Level Debugger |
18fae2a8 | 110 | @ifclear GENERIC |
a64a6c2b | 111 | @subtitle (@value{TARGET}) |
18fae2a8 | 112 | @end ifclear |
70b88761 | 113 | @sp 1 |
29a2b744 | 114 | @c !!set edition, date, version |
a64a6c2b RP |
115 | @subtitle Edition 4.09, for @value{GDBN} version @value{GDBVN} |
116 | @subtitle April 1993 | |
29a2b744 | 117 | @author by Richard M. Stallman and Roland H. Pesch |
70b88761 RP |
118 | @page |
119 | @tex | |
120 | {\parskip=0pt | |
18fae2a8 | 121 | \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@prep.ai.mit.edu.)\par |
ed447b95 | 122 | \hfill {\it Debugging with @value{GDBN}}\par |
70b88761 | 123 | \hfill \TeX{}info \texinfoversion\par |
ed447b95 | 124 | \hfill pesch\@cygnus.com\par |
70b88761 RP |
125 | } |
126 | @end tex | |
127 | ||
128 | @vskip 0pt plus 1filll | |
ed447b95 | 129 | Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
70b88761 RP |
130 | |
131 | Permission is granted to make and distribute verbatim copies of | |
132 | this manual provided the copyright notice and this permission notice | |
133 | are preserved on all copies. | |
134 | ||
135 | Permission is granted to copy and distribute modified versions of this | |
136 | manual under the conditions for verbatim copying, provided also that the | |
137 | section entitled ``GNU General Public License'' is included exactly as | |
138 | in the original, and provided that the entire resulting derived work is | |
139 | distributed under the terms of a permission notice identical to this | |
140 | one. | |
141 | ||
142 | Permission is granted to copy and distribute translations of this manual | |
143 | into another language, under the above conditions for modified versions, | |
144 | except that the section entitled ``GNU General Public License'' may be | |
145 | included in a translation approved by the Free Software Foundation | |
146 | instead of in the original English. | |
147 | @end titlepage | |
148 | @page | |
149 | ||
70b88761 | 150 | @ifinfo |
4eb4cf57 | 151 | @node Top |
18fae2a8 | 152 | @top Debugging with @value{GDBN} |
29a2b744 | 153 | |
18fae2a8 | 154 | This file describes @value{GDBN}, the GNU symbolic debugger. |
29a2b744 RP |
155 | |
156 | @c !!set edition, date, version | |
a64a6c2b | 157 | This is Edition 4.09, April 1993, for GDB Version @value{GDBVN}. |
70b88761 RP |
158 | |
159 | @menu | |
18fae2a8 RP |
160 | * Summary:: Summary of @value{GDBN} |
161 | @ifset NOVEL | |
c7cb8acb | 162 | * New Features:: New features since GDB version 3.5 |
18fae2a8 RP |
163 | @end ifset |
164 | @ifclear BARETARGET | |
165 | * Sample Session:: A sample @value{GDBN} session | |
166 | @end ifclear | |
b0157555 | 167 | |
18fae2a8 RP |
168 | * Invocation:: Getting in and out of @value{GDBN} |
169 | * Commands:: @value{GDBN} commands | |
170 | * Running:: Running programs under @value{GDBN} | |
29a2b744 RP |
171 | * Stopping:: Stopping and continuing |
172 | * Stack:: Examining the stack | |
173 | * Source:: Examining source files | |
174 | * Data:: Examining data | |
18fae2a8 RP |
175 | @ifclear CONLY |
176 | * Languages:: Using @value{GDBN} with different languages | |
177 | @end ifclear | |
178 | @ifset CONLY | |
1d7c3357 | 179 | * C:: C language support |
18fae2a8 | 180 | @end ifset |
1d7c3357 | 181 | @c remnant makeinfo bug, blank line needed after two end-ifs? |
18fae2a8 | 182 | |
18fae2a8 RP |
183 | * Symbols:: Examining the symbol table |
184 | * Altering:: Altering execution | |
93918348 | 185 | * GDB Files:: @value{GDBN} files |
18fae2a8 RP |
186 | * Targets:: Specifying a debugging target |
187 | * Controlling GDB:: Controlling @value{GDBN} | |
188 | * Sequences:: Canned sequences of commands | |
18fae2a8 | 189 | @ifclear DOSHOST |
18fae2a8 | 190 | * Emacs:: Using @value{GDBN} under GNU Emacs |
18fae2a8 | 191 | @end ifclear |
b0157555 | 192 | |
18fae2a8 | 193 | * GDB Bugs:: Reporting bugs in @value{GDBN} |
18fae2a8 | 194 | @ifset NOVEL |
18fae2a8 | 195 | * Renamed Commands:: |
18fae2a8 | 196 | @end ifset |
1d7c3357 | 197 | @ifclear PRECONFIGURED |
18fae2a8 RP |
198 | * Formatting Documentation:: How to format and print GDB documentation |
199 | * Installing GDB:: Installing GDB | |
18fae2a8 | 200 | @end ifclear |
1d7c3357 | 201 | @ifclear AGGLOMERATION |
18fae2a8 | 202 | * Copying:: GNU GENERAL PUBLIC LICENSE |
18fae2a8 | 203 | @end ifclear |
b0157555 | 204 | |
18fae2a8 RP |
205 | * Index:: Index |
206 | @end menu | |
18fae2a8 | 207 | @end ifinfo |
70b88761 | 208 | |
4eb4cf57 | 209 | @node Summary |
18fae2a8 | 210 | @unnumbered Summary of @value{GDBN} |
70b88761 | 211 | |
18fae2a8 | 212 | The purpose of a debugger such as @value{GDBN} is to allow you to see what is |
70b88761 | 213 | going on ``inside'' another program while it executes---or what another |
1041a570 | 214 | program was doing at the moment it crashed. |
70b88761 | 215 | |
18fae2a8 | 216 | @value{GDBN} can do four main kinds of things (plus other things in support of |
1041a570 | 217 | these) to help you catch bugs in the act: |
70b88761 RP |
218 | |
219 | @itemize @bullet | |
220 | @item | |
221 | Start your program, specifying anything that might affect its behavior. | |
222 | ||
223 | @item | |
224 | Make your program stop on specified conditions. | |
225 | ||
226 | @item | |
227 | Examine what has happened, when your program has stopped. | |
228 | ||
229 | @item | |
230 | Change things in your program, so you can experiment with correcting the | |
231 | effects of one bug and go on to learn about another. | |
232 | @end itemize | |
233 | ||
18fae2a8 RP |
234 | @ifclear CONLY |
235 | You can use @value{GDBN} to debug programs written in C, C++, and Modula-2. | |
c2bbbb22 | 236 | Fortran support will be added when a GNU Fortran compiler is ready. |
18fae2a8 | 237 | @end ifclear |
70b88761 RP |
238 | |
239 | @menu | |
ed447b95 | 240 | * Free Software:: Freely redistributable software |
b80282d5 | 241 | * Contributors:: Contributors to GDB |
70b88761 RP |
242 | @end menu |
243 | ||
4eb4cf57 | 244 | @node Free Software |
93928b60 | 245 | @unnumberedsec Free software |
1041a570 | 246 | |
18fae2a8 | 247 | @value{GDBN} is @dfn{free software}, protected by the GNU General Public License |
1041a570 | 248 | (GPL). The GPL gives you the freedom to copy or adapt a licensed |
70b88761 RP |
249 | program---but every person getting a copy also gets with it the |
250 | freedom to modify that copy (which means that they must get access to | |
251 | the source code), and the freedom to distribute further copies. | |
252 | Typical software companies use copyrights to limit your freedoms; the | |
253 | Free Software Foundation uses the GPL to preserve these freedoms. | |
254 | ||
255 | Fundamentally, the General Public License is a license which says that | |
29a2b744 | 256 | you have these freedoms and that you cannot take these freedoms away |
70b88761 RP |
257 | from anyone else. |
258 | ||
18fae2a8 | 259 | @ifclear AGGLOMERATION |
29a2b744 | 260 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. |
18fae2a8 | 261 | @end ifclear |
1041a570 | 262 | |
4eb4cf57 | 263 | @node Contributors |
70b88761 RP |
264 | @unnumberedsec Contributors to GDB |
265 | ||
266 | Richard Stallman was the original author of GDB, and of many other GNU | |
267 | programs. Many others have contributed to its development. This | |
268 | section attempts to credit major contributors. One of the virtues of | |
269 | free software is that everyone is free to contribute to it; with | |
270 | regret, we cannot actually acknowledge everyone here. The file | |
271 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
272 | account. | |
273 | ||
274 | Changes much prior to version 2.0 are lost in the mists of time. | |
275 | ||
276 | @quotation | |
277 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
93918348 | 278 | or your friends (or enemies, to be evenhanded) have been unfairly |
70b88761 RP |
279 | omitted from this list, we would like to add your names! |
280 | @end quotation | |
281 | ||
282 | So that they may not regard their long labor as thankless, we | |
69bbcf05 | 283 | particularly thank those who shepherded GDB through major releases: Stu |
93918348 | 284 | Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore |
6f3ec223 RP |
285 | (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, |
286 | 3.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of | |
287 | GDB for some period, each contributed significantly to the structure, | |
288 | stability, and capabilities of the entire debugger. | |
70b88761 RP |
289 | |
290 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
291 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
292 | ||
1d7c3357 | 293 | @ifclear CONLY |
70b88761 RP |
294 | Michael Tiemann is the author of most of the GNU C++ support in GDB, |
295 | with significant additional contributions from Per Bothner. James | |
296 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
297 | TerMaat (who also did much general update work leading to release 3.0). | |
1d7c3357 | 298 | @end ifclear |
70b88761 | 299 | |
1041a570 RP |
300 | GDB 4 uses the BFD subroutine library to examine multiple |
301 | object-file formats; BFD was a joint project of David V. | |
302 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
70b88761 | 303 | |
1041a570 RP |
304 | David Johnson wrote the original COFF support; Pace Willison did |
305 | the original support for encapsulated COFF. | |
70b88761 RP |
306 | |
307 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
308 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
1041a570 RP |
309 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris |
310 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
311 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
312 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
313 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
314 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
315 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
316 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
317 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
318 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
319 | support. | |
70b88761 | 320 | |
c338a2fd RP |
321 | Rich Schaefer and Peter Schauer helped with support of SunOS shared |
322 | libraries. | |
70b88761 RP |
323 | |
324 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
325 | several machine instruction sets. | |
326 | ||
1041a570 RP |
327 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped |
328 | develop remote debugging. Intel Corporation and Wind River Systems | |
329 | contributed remote debugging modules for their products. | |
70b88761 | 330 | |
1041a570 RP |
331 | Brian Fox is the author of the readline libraries providing |
332 | command-line editing and command history. | |
70b88761 | 333 | |
1041a570 RP |
334 | Andrew Beers of SUNY Buffalo wrote the language-switching code and |
335 | the Modula-2 support, and contributed the Languages chapter of this | |
336 | manual. | |
c2bbbb22 | 337 | |
1d7c3357 RP |
338 | Fred Fish wrote most of the support for Unix System Vr4. |
339 | @ifclear CONLY | |
340 | He also enhanced the command-completion support to cover C++ overloaded | |
341 | symbols. | |
342 | @end ifclear | |
343 | ||
a64a6c2b | 344 | Hitachi America, Ltd. sponsored the support for Hitachi microprocessors. |
14d01801 | 345 | |
18fae2a8 | 346 | @ifset NOVEL |
4eb4cf57 | 347 | @node New Features |
ed447b95 | 348 | @unnumbered New Features since GDB Version 3.5 |
70b88761 RP |
349 | |
350 | @table @emph | |
351 | @item Targets | |
352 | Using the new command @code{target}, you can select at runtime whether | |
353 | you are debugging local files, local processes, standalone systems over | |
b80282d5 RP |
354 | a serial port, realtime systems over a TCP/IP connection, etc. The |
355 | command @code{load} can download programs into a remote system. Serial | |
b21b18e1 RP |
356 | stubs are available for Motorola 680x0, Intel 80386, and Sparc remote |
357 | systems; GDB also supports debugging realtime processes running under | |
b80282d5 | 358 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a |
b21b18e1 RP |
359 | debugger stub on the target system. Internally, GDB now uses a function |
360 | vector to mediate access to different targets; if you need to add your | |
361 | own support for a remote protocol, this makes it much easier. | |
70b88761 RP |
362 | |
363 | @item Watchpoints | |
c7cb8acb | 364 | GDB now sports watchpoints as well as breakpoints. You can use a |
70b88761 RP |
365 | watchpoint to stop execution whenever the value of an expression |
366 | changes, without having to predict a particular place in your program | |
367 | where this may happen. | |
368 | ||
b80282d5 RP |
369 | @item Wide Output |
370 | Commands that issue wide output now insert newlines at places designed | |
371 | to make the output more readable. | |
372 | ||
70b88761 | 373 | @item Object Code Formats |
c7cb8acb | 374 | GDB uses a new library called the Binary File Descriptor (BFD) |
3d3ab540 RP |
375 | Library to permit it to switch dynamically, without reconfiguration or |
376 | recompilation, between different object-file formats. Formats currently | |
377 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
93918348 | 378 | .o files, archive libraries, or core dumps. BFD is available as a |
3d3ab540 RP |
379 | subroutine library so that other programs may take advantage of it, and |
380 | the other GNU binary utilities are being converted to use it. | |
70b88761 | 381 | |
b80282d5 | 382 | @item Configuration and Ports |
70b88761 | 383 | Compile-time configuration (to select a particular architecture and |
7463aadd | 384 | operating system) is much easier. The script @code{configure} now |
c7cb8acb RP |
385 | allows you to configure GDB as either a native debugger or a |
386 | cross-debugger. @xref{Installing GDB}, for details on how to | |
6a8cb0e7 | 387 | configure. |
70b88761 RP |
388 | |
389 | @item Interaction | |
93918348 RP |
390 | The user interface to the GDB control variables is simpler, |
391 | and is consolidated in two commands, @code{set} and @code{show}. Output | |
70b88761 RP |
392 | lines are now broken at readable places, rather than overflowing onto |
393 | the next line. You can suppress output of machine-level addresses, | |
394 | displaying only source language information. | |
395 | ||
b80282d5 | 396 | @item C++ |
c7cb8acb | 397 | GDB now supports C++ multiple inheritance (if used with a GCC |
b80282d5 | 398 | version 2 compiler), and also has limited support for C++ exception |
c7cb8acb | 399 | handling, with the commands @code{catch} and @code{info catch}: GDB |
b80282d5 RP |
400 | can break when an exception is raised, before the stack is peeled back |
401 | to the exception handler's context. | |
70b88761 | 402 | |
c2bbbb22 | 403 | @item Modula-2 |
ed447b95 RP |
404 | GDB now has preliminary support for the GNU Modula-2 compiler, currently |
405 | under development at the State University of New York at Buffalo. | |
406 | Coordinated development of both GDB and the GNU Modula-2 compiler will | |
407 | continue. Other Modula-2 compilers are currently not supported, and | |
408 | attempting to debug programs compiled with them will likely result in an | |
409 | error as the symbol table of the executable is read in. | |
c2bbbb22 | 410 | |
70b88761 | 411 | @item Command Rationalization |
c7cb8acb | 412 | Many GDB commands have been renamed to make them easier to remember |
70b88761 RP |
413 | and use. In particular, the subcommands of @code{info} and |
414 | @code{show}/@code{set} are grouped to make the former refer to the state | |
c7cb8acb | 415 | of your program, and the latter refer to the state of GDB itself. |
70b88761 RP |
416 | @xref{Renamed Commands}, for details on what commands were renamed. |
417 | ||
70b88761 | 418 | @item Shared Libraries |
77b46d13 JG |
419 | GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000 |
420 | shared libraries. | |
b80282d5 RP |
421 | |
422 | @item Reference Card | |
6f3ec223 | 423 | GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting |
ed447b95 | 424 | the Documentation}, for instructions about how to print it. |
70b88761 RP |
425 | |
426 | @item Work in Progress | |
427 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
428 | support. | |
70b88761 | 429 | @end table |
18fae2a8 | 430 | @end ifset |
70b88761 | 431 | |
18fae2a8 | 432 | @ifclear BARETARGET |
4eb4cf57 | 433 | @node Sample Session |
18fae2a8 | 434 | @chapter A Sample @value{GDBN} Session |
70b88761 | 435 | |
18fae2a8 | 436 | You can use this manual at your leisure to read all about @value{GDBN}. |
70b88761 | 437 | However, a handful of commands are enough to get started using the |
ed447b95 | 438 | debugger. This chapter illustrates those commands. |
70b88761 RP |
439 | |
440 | @iftex | |
6ca72cc6 | 441 | In this sample session, we emphasize user input like this: @b{input}, |
70b88761 RP |
442 | to make it easier to pick out from the surrounding output. |
443 | @end iftex | |
444 | ||
445 | @c FIXME: this example may not be appropriate for some configs, where | |
446 | @c FIXME...primary interest is in remote use. | |
18fae2a8 | 447 | |
70b88761 RP |
448 | One of the preliminary versions of GNU @code{m4} (a generic macro |
449 | processor) exhibits the following bug: sometimes, when we change its | |
93918348 RP |
450 | quote strings from the default, the commands used to capture one macro |
451 | definition within another stop working. In the following short @code{m4} | |
70b88761 | 452 | session, we define a macro @code{foo} which expands to @code{0000}; we |
29a2b744 | 453 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the |
70b88761 RP |
454 | same thing. However, when we change the open quote string to |
455 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
456 | procedure fails to define a new synonym @code{baz}: | |
457 | ||
458 | @smallexample | |
6ca72cc6 RP |
459 | $ @b{cd gnu/m4} |
460 | $ @b{./m4} | |
461 | @b{define(foo,0000)} | |
70b88761 | 462 | |
6ca72cc6 | 463 | @b{foo} |
70b88761 | 464 | 0000 |
6ca72cc6 | 465 | @b{define(bar,defn(`foo'))} |
70b88761 | 466 | |
6ca72cc6 | 467 | @b{bar} |
70b88761 | 468 | 0000 |
6ca72cc6 | 469 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 470 | |
6ca72cc6 RP |
471 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
472 | @b{baz} | |
473 | @b{C-d} | |
70b88761 RP |
474 | m4: End of input: 0: fatal error: EOF in string |
475 | @end smallexample | |
476 | ||
477 | @noindent | |
93918348 | 478 | Let us use @value{GDBN} to try to see what is going on. |
70b88761 RP |
479 | |
480 | @smallexample | |
18fae2a8 | 481 | $ @b{@value{GDBP} m4} |
203eea5d RP |
482 | @c FIXME: this falsifies the exact text played out, to permit smallbook |
483 | @c FIXME... format to come out better. | |
484 | GDB is free software and you are welcome to distribute copies | |
485 | of it under certain conditions; type "show copying" to see | |
486 | the conditions. | |
487 | There is absolutely no warranty for GDB; type "show warranty" | |
ed447b95 RP |
488 | for details. |
489 | GDB @value{GDBVN}, Copyright 1993 Free Software Foundation, Inc... | |
18fae2a8 | 490 | (@value{GDBP}) |
70b88761 RP |
491 | @end smallexample |
492 | ||
493 | @noindent | |
18fae2a8 | 494 | @value{GDBN} reads only enough symbol data to know where to find the rest when |
1041a570 | 495 | needed; as a result, the first prompt comes up very quickly. We now |
18fae2a8 | 496 | tell @value{GDBN} to use a narrower display width than usual, so that examples |
1041a570 | 497 | will fit in this manual. |
70b88761 RP |
498 | |
499 | @smallexample | |
18fae2a8 | 500 | (@value{GDBP}) @b{set width 70} |
70b88761 RP |
501 | @end smallexample |
502 | ||
e251e767 | 503 | @noindent |
93918348 | 504 | We need to see how the @code{m4} built-in @code{changequote} works. |
70b88761 | 505 | Having looked at the source, we know the relevant subroutine is |
93918348 | 506 | @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN} |
70b88761 RP |
507 | @code{break} command. |
508 | ||
509 | @smallexample | |
18fae2a8 | 510 | (@value{GDBP}) @b{break m4_changequote} |
70b88761 RP |
511 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. |
512 | @end smallexample | |
513 | ||
514 | @noindent | |
18fae2a8 | 515 | Using the @code{run} command, we start @code{m4} running under @value{GDBN} |
70b88761 RP |
516 | control; as long as control does not reach the @code{m4_changequote} |
517 | subroutine, the program runs as usual: | |
518 | ||
519 | @smallexample | |
18fae2a8 | 520 | (@value{GDBP}) @b{run} |
e251e767 | 521 | Starting program: /work/Editorial/gdb/gnu/m4/m4 |
6ca72cc6 | 522 | @b{define(foo,0000)} |
70b88761 | 523 | |
6ca72cc6 | 524 | @b{foo} |
70b88761 RP |
525 | 0000 |
526 | @end smallexample | |
527 | ||
528 | @noindent | |
18fae2a8 | 529 | To trigger the breakpoint, we call @code{changequote}. @value{GDBN} |
70b88761 RP |
530 | suspends execution of @code{m4}, displaying information about the |
531 | context where it stops. | |
532 | ||
533 | @smallexample | |
6ca72cc6 | 534 | @b{changequote(<QUOTE>,<UNQUOTE>)} |
70b88761 | 535 | |
203eea5d RP |
536 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) |
537 | at builtin.c:879 | |
38962738 | 538 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) |
70b88761 RP |
539 | @end smallexample |
540 | ||
541 | @noindent | |
542 | Now we use the command @code{n} (@code{next}) to advance execution to | |
543 | the next line of the current function. | |
544 | ||
545 | @smallexample | |
18fae2a8 | 546 | (@value{GDBP}) @b{n} |
203eea5d RP |
547 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ |
548 | : nil, | |
70b88761 RP |
549 | @end smallexample |
550 | ||
551 | @noindent | |
552 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
553 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
554 | @code{step} goes to the next line to be executed in @emph{any} | |
e251e767 | 555 | subroutine, so it steps into @code{set_quotes}. |
70b88761 RP |
556 | |
557 | @smallexample | |
18fae2a8 | 558 | (@value{GDBP}) @b{s} |
70b88761 RP |
559 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
560 | at input.c:530 | |
561 | 530 if (lquote != def_lquote) | |
562 | @end smallexample | |
563 | ||
564 | @noindent | |
29a2b744 RP |
565 | The display that shows the subroutine where @code{m4} is now |
566 | suspended (and its arguments) is called a stack frame display. It | |
567 | shows a summary of the stack. We can use the @code{backtrace} | |
568 | command (which can also be spelled @code{bt}), to see where we are | |
569 | in the stack as a whole: the @code{backtrace} command displays a | |
570 | stack frame for each active subroutine. | |
70b88761 RP |
571 | |
572 | @smallexample | |
18fae2a8 | 573 | (@value{GDBP}) @b{bt} |
70b88761 RP |
574 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") |
575 | at input.c:530 | |
203eea5d RP |
576 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) |
577 | at builtin.c:882 | |
70b88761 RP |
578 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 |
579 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
580 | at macro.c:71 | |
581 | #4 0x79dc in expand_input () at macro.c:40 | |
582 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
583 | @end smallexample | |
584 | ||
585 | @noindent | |
93918348 | 586 | We will step through a few more lines to see what happens. The first two |
70b88761 RP |
587 | times, we can use @samp{s}; the next two times we use @code{n} to avoid |
588 | falling into the @code{xstrdup} subroutine. | |
1041a570 | 589 | |
70b88761 | 590 | @smallexample |
18fae2a8 | 591 | (@value{GDBP}) @b{s} |
70b88761 | 592 | 0x3b5c 532 if (rquote != def_rquote) |
18fae2a8 | 593 | (@value{GDBP}) @b{s} |
203eea5d RP |
594 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ |
595 | def_lquote : xstrdup(lq); | |
18fae2a8 | 596 | (@value{GDBP}) @b{n} |
203eea5d RP |
597 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ |
598 | : xstrdup(rq); | |
18fae2a8 | 599 | (@value{GDBP}) @b{n} |
70b88761 RP |
600 | 538 len_lquote = strlen(rquote); |
601 | @end smallexample | |
602 | ||
603 | @noindent | |
93918348 | 604 | The last line displayed looks a little odd; we can examine the variables |
70b88761 | 605 | @code{lquote} and @code{rquote} to see if they are in fact the new left |
93918348 | 606 | and right quotes we specified. We use the command @code{p} |
70b88761 RP |
607 | (@code{print}) to see their values. |
608 | ||
609 | @smallexample | |
18fae2a8 | 610 | (@value{GDBP}) @b{p lquote} |
70b88761 | 611 | $1 = 0x35d40 "<QUOTE>" |
18fae2a8 | 612 | (@value{GDBP}) @b{p rquote} |
70b88761 RP |
613 | $2 = 0x35d50 "<UNQUOTE>" |
614 | @end smallexample | |
615 | ||
616 | @noindent | |
617 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
93918348 RP |
618 | To look at some context, we can display ten lines of source |
619 | surrounding the current line with the @code{l} (@code{list}) command. | |
70b88761 RP |
620 | |
621 | @smallexample | |
18fae2a8 | 622 | (@value{GDBP}) @b{l} |
70b88761 | 623 | 533 xfree(rquote); |
e251e767 | 624 | 534 |
203eea5d RP |
625 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ |
626 | : xstrdup (lq); | |
627 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
628 | : xstrdup (rq); | |
e251e767 | 629 | 537 |
70b88761 RP |
630 | 538 len_lquote = strlen(rquote); |
631 | 539 len_rquote = strlen(lquote); | |
632 | 540 @} | |
e251e767 | 633 | 541 |
70b88761 RP |
634 | 542 void |
635 | @end smallexample | |
636 | ||
637 | @noindent | |
93918348 | 638 | Let us step past the two lines that set @code{len_lquote} and |
70b88761 RP |
639 | @code{len_rquote}, and then examine the values of those variables. |
640 | ||
641 | @smallexample | |
18fae2a8 | 642 | (@value{GDBP}) @b{n} |
70b88761 | 643 | 539 len_rquote = strlen(lquote); |
18fae2a8 | 644 | (@value{GDBP}) @b{n} |
70b88761 | 645 | 540 @} |
18fae2a8 | 646 | (@value{GDBP}) @b{p len_lquote} |
70b88761 | 647 | $3 = 9 |
18fae2a8 | 648 | (@value{GDBP}) @b{p len_rquote} |
70b88761 RP |
649 | $4 = 7 |
650 | @end smallexample | |
651 | ||
652 | @noindent | |
653 | That certainly looks wrong, assuming @code{len_lquote} and | |
654 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
93918348 RP |
655 | @code{rquote} respectively. We can set them to better values using |
656 | the @code{p} command, since it can print the value of | |
70b88761 | 657 | any expression---and that expression can include subroutine calls and |
e251e767 | 658 | assignments. |
70b88761 RP |
659 | |
660 | @smallexample | |
18fae2a8 | 661 | (@value{GDBP}) @b{p len_lquote=strlen(lquote)} |
70b88761 | 662 | $5 = 7 |
18fae2a8 | 663 | (@value{GDBP}) @b{p len_rquote=strlen(rquote)} |
70b88761 RP |
664 | $6 = 9 |
665 | @end smallexample | |
666 | ||
667 | @noindent | |
93918348 RP |
668 | Is that enough to fix the problem of using the new quotes with the |
669 | @code{m4} built-in @code{defn}? We can allow @code{m4} to continue | |
70b88761 RP |
670 | executing with the @code{c} (@code{continue}) command, and then try the |
671 | example that caused trouble initially: | |
672 | ||
673 | @smallexample | |
18fae2a8 | 674 | (@value{GDBP}) @b{c} |
70b88761 RP |
675 | Continuing. |
676 | ||
6ca72cc6 | 677 | @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))} |
70b88761 RP |
678 | |
679 | baz | |
680 | 0000 | |
681 | @end smallexample | |
682 | ||
683 | @noindent | |
684 | Success! The new quotes now work just as well as the default ones. The | |
685 | problem seems to have been just the two typos defining the wrong | |
93918348 | 686 | lengths. We allow @code{m4} exit by giving it an EOF as input: |
70b88761 RP |
687 | |
688 | @smallexample | |
6ca72cc6 | 689 | @b{C-d} |
70b88761 RP |
690 | Program exited normally. |
691 | @end smallexample | |
692 | ||
e251e767 | 693 | @noindent |
18fae2a8 RP |
694 | The message @samp{Program exited normally.} is from @value{GDBN}; it |
695 | indicates @code{m4} has finished executing. We can end our @value{GDBN} | |
696 | session with the @value{GDBN} @code{quit} command. | |
70b88761 RP |
697 | |
698 | @smallexample | |
18fae2a8 RP |
699 | (@value{GDBP}) @b{quit} |
700 | @end smallexample | |
701 | @end ifclear | |
70b88761 | 702 | |
4eb4cf57 | 703 | @node Invocation |
18fae2a8 | 704 | @chapter Getting In and Out of @value{GDBN} |
70b88761 | 705 | |
18fae2a8 RP |
706 | This chapter discusses how to start @value{GDBN}, and how to get out of it. |
707 | (The essentials: type @samp{@value{GDBP}} to start GDB, and type @kbd{quit} | |
c7cb8acb | 708 | or @kbd{C-d} to exit.) |
29a2b744 | 709 | |
70b88761 | 710 | @menu |
ed447b95 RP |
711 | * Invoking GDB:: How to start @value{GDBN} |
712 | * Quitting GDB:: How to quit @value{GDBN} | |
ed447b95 | 713 | * Shell Commands:: How to use shell commands inside @value{GDBN} |
70b88761 | 714 | @end menu |
18fae2a8 RP |
715 | |
716 | @node Invoking GDB | |
ed447b95 | 717 | @section Invoking @value{GDBN} |
18fae2a8 | 718 | |
a64a6c2b | 719 | @ifset H8EXCLUSIVE |
18fae2a8 | 720 | For details on starting up @value{GDBP} as a |
a64a6c2b RP |
721 | remote debugger attached to a Hitachi microprocessor, see @ref{Hitachi |
722 | Remote,,@value{GDBN} and Hitachi Microprocessors}. | |
18fae2a8 | 723 | @end ifset |
4eb4cf57 | 724 | |
ed447b95 | 725 | Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started, |
18fae2a8 | 726 | @value{GDBN} reads commands from the terminal until you tell it to exit. |
70b88761 | 727 | |
18fae2a8 | 728 | You can also run @code{@value{GDBP}} with a variety of arguments and options, |
c7cb8acb RP |
729 | to specify more of your debugging environment at the outset. |
730 | ||
18fae2a8 | 731 | @ifset GENERIC |
c7cb8acb RP |
732 | The command-line options described here are designed |
733 | to cover a variety of situations; in some environments, some of these | |
734 | options may effectively be unavailable. | |
18fae2a8 | 735 | @end ifset |
c7cb8acb | 736 | |
18fae2a8 | 737 | The most usual way to start @value{GDBN} is with one argument, |
4eb4cf57 | 738 | specifying an executable program: |
1041a570 | 739 | |
70b88761 | 740 | @example |
18fae2a8 | 741 | @value{GDBP} @var{program} |
70b88761 | 742 | @end example |
1041a570 | 743 | |
18fae2a8 | 744 | @ifclear BARETARGET |
70b88761 | 745 | @noindent |
29a2b744 RP |
746 | You can also start with both an executable program and a core file |
747 | specified: | |
1041a570 | 748 | |
70b88761 | 749 | @example |
18fae2a8 | 750 | @value{GDBP} @var{program} @var{core} |
70b88761 RP |
751 | @end example |
752 | ||
b80282d5 RP |
753 | You can, instead, specify a process ID as a second argument, if you want |
754 | to debug a running process: | |
1041a570 | 755 | |
b80282d5 | 756 | @example |
18fae2a8 | 757 | @value{GDBP} @var{program} 1234 |
b80282d5 | 758 | @end example |
1041a570 | 759 | |
b80282d5 | 760 | @noindent |
18fae2a8 RP |
761 | would attach @value{GDBN} to process @code{1234} (unless you also have a file |
762 | named @file{1234}; @value{GDBN} does check for a core file first). | |
b80282d5 | 763 | |
c7cb8acb | 764 | Taking advantage of the second command-line argument requires a fairly |
18fae2a8 | 765 | complete operating system; when you use @value{GDBN} as a remote debugger |
c7cb8acb RP |
766 | attached to a bare board, there may not be any notion of ``process'', |
767 | and there is often no way to get a core dump. | |
18fae2a8 | 768 | @end ifclear |
c7cb8acb | 769 | |
70b88761 | 770 | @noindent |
18fae2a8 RP |
771 | You can further control how @value{GDBN} starts up by using command-line |
772 | options. @value{GDBN} itself can remind you of the options available. | |
29a2b744 RP |
773 | |
774 | @noindent | |
775 | Type | |
776 | ||
70b88761 | 777 | @example |
18fae2a8 | 778 | @value{GDBP} -help |
70b88761 | 779 | @end example |
29a2b744 | 780 | |
70b88761 | 781 | @noindent |
29a2b744 | 782 | to display all available options and briefly describe their use |
18fae2a8 | 783 | (@samp{@value{GDBP} -h} is a shorter equivalent). |
70b88761 RP |
784 | |
785 | All options and command line arguments you give are processed | |
786 | in sequential order. The order makes a difference when the | |
e251e767 | 787 | @samp{-x} option is used. |
70b88761 | 788 | |
18fae2a8 | 789 | |
70b88761 | 790 | @menu |
18fae2a8 RP |
791 | @ifclear GENERIC |
792 | @ifset REMOTESTUB | |
793 | * Remote Serial:: @value{GDBN} remote serial protocol | |
794 | @end ifset | |
a64a6c2b | 795 | @ifset I960 |
18fae2a8 RP |
796 | * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy) |
797 | @end ifset | |
a64a6c2b | 798 | @ifset AMD29K |
fe715d06 | 799 | * UDI29K Remote:: @value{GDBN} and the UDI protocol for AMD29K |
18fae2a8 RP |
800 | * EB29K Remote:: @value{GDBN} with a remote EB29K |
801 | @end ifset | |
802 | @ifset VXWORKS | |
803 | * VxWorks Remote:: @value{GDBN} and VxWorks | |
804 | @end ifset | |
a64a6c2b | 805 | @ifset ST2000 |
18fae2a8 RP |
806 | * ST2000 Remote:: @value{GDBN} with a Tandem ST2000 |
807 | @end ifset | |
a64a6c2b RP |
808 | @ifset H8 |
809 | * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors | |
18fae2a8 | 810 | @end ifset |
fe715d06 RP |
811 | @ifset SIMS |
812 | * Simulator:: Simulated CPU target | |
18fae2a8 RP |
813 | @end ifset |
814 | @end ifclear | |
1d7c3357 | 815 | @c remnant makeinfo bug requires this blank line after *two* end-ifblahs: |
18fae2a8 | 816 | |
ed447b95 RP |
817 | * File Options:: Choosing files |
818 | * Mode Options:: Choosing modes | |
18fae2a8 | 819 | @end menu |
18fae2a8 RP |
820 | |
821 | @ifclear GENERIC | |
822 | @include gdbinv-s.texi | |
823 | @end ifclear | |
4eb4cf57 RP |
824 | |
825 | @node File Options | |
93928b60 | 826 | @subsection Choosing files |
70b88761 | 827 | |
18fae2a8 RP |
828 | @ifclear BARETARGET |
829 | When @value{GDBN} starts, it reads any arguments other than options as | |
29a2b744 RP |
830 | specifying an executable file and core file (or process ID). This is |
831 | the same as if the arguments were specified by the @samp{-se} and | |
18fae2a8 | 832 | @samp{-c} options respectively. (@value{GDBN} reads the first argument |
29a2b744 RP |
833 | that does not have an associated option flag as equivalent to the |
834 | @samp{-se} option followed by that argument; and the second argument | |
835 | that does not have an associated option flag, if any, as equivalent to | |
836 | the @samp{-c} option followed by that argument.) | |
18fae2a8 RP |
837 | @end ifclear |
838 | @ifset BARETARGET | |
839 | When @value{GDBN} starts, it reads any argument other than options as | |
4eb4cf57 RP |
840 | specifying an executable file. This is the same as if the argument was |
841 | specified by the @samp{-se} option. | |
18fae2a8 | 842 | @end ifset |
29a2b744 RP |
843 | |
844 | Many options have both long and short forms; both are shown in the | |
18fae2a8 | 845 | following list. @value{GDBN} also recognizes the long forms if you truncate |
29a2b744 RP |
846 | them, so long as enough of the option is present to be unambiguous. |
847 | (If you prefer, you can flag option arguments with @samp{--} rather | |
848 | than @samp{-}, though we illustrate the more usual convention.) | |
70b88761 RP |
849 | |
850 | @table @code | |
851 | @item -symbols=@var{file} | |
852 | @itemx -s @var{file} | |
853 | Read symbol table from file @var{file}. | |
854 | ||
855 | @item -exec=@var{file} | |
856 | @itemx -e @var{file} | |
857 | Use file @var{file} as the executable file to execute when | |
1d7c3357 RP |
858 | @ifset BARETARGET |
859 | appropriate. | |
860 | @end ifset | |
861 | @ifclear BARETARGET | |
70b88761 RP |
862 | appropriate, and for examining pure data in conjunction with a core |
863 | dump. | |
1d7c3357 | 864 | @end ifclear |
70b88761 | 865 | |
3d3ab540 | 866 | @item -se=@var{file} |
70b88761 RP |
867 | Read symbol table from file @var{file} and use it as the executable |
868 | file. | |
869 | ||
18fae2a8 | 870 | @ifclear BARETARGET |
70b88761 RP |
871 | @item -core=@var{file} |
872 | @itemx -c @var{file} | |
873 | Use file @var{file} as a core dump to examine. | |
18fae2a8 | 874 | @end ifclear |
70b88761 RP |
875 | |
876 | @item -command=@var{file} | |
877 | @itemx -x @var{file} | |
93928b60 RP |
878 | Execute @value{GDBN} commands from file @var{file}. @xref{Command |
879 | Files,, Command files}. | |
70b88761 RP |
880 | |
881 | @item -directory=@var{directory} | |
882 | @itemx -d @var{directory} | |
883 | Add @var{directory} to the path to search for source files. | |
14d01801 | 884 | |
18fae2a8 | 885 | @ifclear BARETARGET |
14d01801 RP |
886 | @item -m |
887 | @itemx -mapped | |
888 | @emph{Warning: this option depends on operating system facilities that are not | |
889 | supported on all systems.}@* | |
77b46d13 JG |
890 | If memory-mapped files are available on your system through the @code{mmap} |
891 | system call, you can use this option | |
18fae2a8 | 892 | to have @value{GDBN} write the symbols from your |
77b46d13 JG |
893 | program into a reusable file in the current directory. If the program you are debugging is |
894 | called @file{/tmp/fred}, the mapped symbol file will be @file{./fred.syms}. | |
18fae2a8 | 895 | Future @value{GDBN} debugging sessions will notice the presence of this file, |
77b46d13 JG |
896 | and will quickly map in symbol information from it, rather than reading |
897 | the symbol table from the executable program. | |
898 | ||
1d7c3357 RP |
899 | @c FIXME! Really host, not target? |
900 | The @file{.syms} file is specific to the host machine where @value{GDBN} | |
901 | is run. It holds an exact image of the internal @value{GDBN} symbol | |
902 | table. It cannot be shared across multiple host platforms. | |
18fae2a8 | 903 | @end ifclear |
77b46d13 JG |
904 | |
905 | @item -r | |
906 | @itemx -readnow | |
907 | Read each symbol file's entire symbol table immediately, rather than | |
908 | the default, which is to read it incrementally as it is needed. | |
909 | This makes startup slower, but makes future operations faster. | |
70b88761 RP |
910 | @end table |
911 | ||
18fae2a8 | 912 | @ifclear BARETARGET |
93918348 RP |
913 | The @code{-mapped} and @code{-readnow} options are typically combined in |
914 | order to build a @file{.syms} file that contains complete symbol | |
93928b60 | 915 | information. (@xref{Files,,Commands to specify files}, for information |
93918348 RP |
916 | on @file{.syms} files.) A simple GDB invocation to do nothing but build |
917 | a @file{.syms} file for future use is: | |
77b46d13 JG |
918 | |
919 | @example | |
920 | gdb -batch -nx -mapped -readnow programname | |
921 | @end example | |
18fae2a8 | 922 | @end ifclear |
77b46d13 | 923 | |
4eb4cf57 | 924 | @node Mode Options |
93928b60 | 925 | @subsection Choosing modes |
1041a570 | 926 | |
18fae2a8 | 927 | You can run @value{GDBN} in various alternative modes---for example, in |
29a2b744 | 928 | batch mode or quiet mode. |
70b88761 RP |
929 | |
930 | @table @code | |
931 | @item -nx | |
932 | @itemx -n | |
18fae2a8 | 933 | Do not execute commands from any @file{@value{GDBINIT}} initialization files. |
70b88761 | 934 | Normally, the commands in these files are executed after all the |
e251e767 | 935 | command options and arguments have been processed. |
93928b60 | 936 | @xref{Command Files,,Command files}. |
70b88761 RP |
937 | |
938 | @item -quiet | |
939 | @itemx -q | |
940 | ``Quiet''. Do not print the introductory and copyright messages. These | |
c338a2fd | 941 | messages are also suppressed in batch mode. |
70b88761 RP |
942 | |
943 | @item -batch | |
944 | Run in batch mode. Exit with status @code{0} after processing all the command | |
18fae2a8 RP |
945 | files specified with @samp{-x} (and @file{@value{GDBINIT}}, if not inhibited). |
946 | Exit with nonzero status if an error occurs in executing the @value{GDBN} | |
e251e767 | 947 | commands in the command files. |
70b88761 | 948 | |
18fae2a8 | 949 | Batch mode may be useful for running @value{GDBN} as a filter, for example to |
70b88761 | 950 | download and run a program on another computer; in order to make this |
e251e767 | 951 | more useful, the message |
1041a570 | 952 | |
70b88761 RP |
953 | @example |
954 | Program exited normally. | |
955 | @end example | |
1041a570 | 956 | |
70b88761 | 957 | @noindent |
18fae2a8 | 958 | (which is ordinarily issued whenever a program running under @value{GDBN} control |
70b88761 RP |
959 | terminates) is not issued when running in batch mode. |
960 | ||
3d3ab540 | 961 | @item -cd=@var{directory} |
18fae2a8 | 962 | Run @value{GDBN} using @var{directory} as its working directory, |
70b88761 RP |
963 | instead of the current directory. |
964 | ||
18fae2a8 | 965 | @ifset LUCID |
45c53080 | 966 | @item -context @var{authentication} |
18fae2a8 | 967 | When the Energize programming system starts up @value{GDBN}, it uses this |
6ca72cc6 | 968 | option to trigger an alternate mode of interaction. |
18fae2a8 | 969 | @var{authentication} is a pair of numeric codes that identify @value{GDBN} |
6ca72cc6 | 970 | as a client in the Energize environment. Avoid this option when you run |
18fae2a8 RP |
971 | @value{GDBN} directly from the command line. See @ref{Energize,,Using |
972 | @value{GDBN} with Energize} for more discussion of using @value{GDBN} with Energize. | |
973 | @end ifset | |
6ca72cc6 | 974 | |
1d7c3357 | 975 | @ifclear DOSHOST |
70b88761 RP |
976 | @item -fullname |
977 | @itemx -f | |
18fae2a8 | 978 | Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells @value{GDBN} |
70b88761 RP |
979 | to output the full file name and line number in a standard, |
980 | recognizable fashion each time a stack frame is displayed (which | |
29a2b744 | 981 | includes each time your program stops). This recognizable format looks |
70b88761 RP |
982 | like two @samp{\032} characters, followed by the file name, line number |
983 | and character position separated by colons, and a newline. The | |
18fae2a8 | 984 | Emacs-to-@value{GDBN} interface program uses the two @samp{\032} characters as |
70b88761 | 985 | a signal to display the source code for the frame. |
1d7c3357 | 986 | @end ifclear |
70b88761 | 987 | |
18fae2a8 | 988 | @ifset SERIAL |
70b88761 RP |
989 | @item -b @var{bps} |
990 | Set the line speed (baud rate or bits per second) of any serial | |
18fae2a8 | 991 | interface used by @value{GDBN} for remote debugging. |
70b88761 | 992 | |
3d3ab540 | 993 | @item -tty=@var{device} |
70b88761 | 994 | Run using @var{device} for your program's standard input and output. |
29a2b744 | 995 | @c FIXME: kingdon thinks there is more to -tty. Investigate. |
18fae2a8 | 996 | @end ifset |
70b88761 RP |
997 | @end table |
998 | ||
ed447b95 RP |
999 | @node Quitting GDB |
1000 | @section Quitting @value{GDBN} | |
18fae2a8 | 1001 | @cindex exiting @value{GDBN} |
ed447b95 | 1002 | @cindex leaving @value{GDBN} |
1041a570 | 1003 | |
70b88761 RP |
1004 | @table @code |
1005 | @item quit | |
1006 | @kindex quit | |
1007 | @kindex q | |
18fae2a8 | 1008 | To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or type |
e251e767 | 1009 | an end-of-file character (usually @kbd{C-d}). |
70b88761 RP |
1010 | @end table |
1011 | ||
1012 | @cindex interrupt | |
18fae2a8 RP |
1013 | An interrupt (often @kbd{C-c}) will not exit from @value{GDBN}, but rather |
1014 | will terminate the action of any @value{GDBN} command that is in progress and | |
1015 | return to @value{GDBN} command level. It is safe to type the interrupt | |
1016 | character at any time because @value{GDBN} does not allow it to take effect | |
70b88761 RP |
1017 | until a time when it is safe. |
1018 | ||
18fae2a8 | 1019 | @ifclear BARETARGET |
ed447b95 RP |
1020 | If you have been using @value{GDBN} to control an attached process or |
1021 | device, you can release it with the @code{detach} command | |
93928b60 | 1022 | (@pxref{Attach, ,Debugging an already-running process}). |
18fae2a8 | 1023 | @end ifclear |
70b88761 | 1024 | |
4eb4cf57 | 1025 | @node Shell Commands |
93928b60 | 1026 | @section Shell commands |
1041a570 | 1027 | |
70b88761 | 1028 | If you need to execute occasional shell commands during your |
18fae2a8 | 1029 | debugging session, there is no need to leave or suspend @value{GDBN}; you can |
70b88761 RP |
1030 | just use the @code{shell} command. |
1031 | ||
1032 | @table @code | |
1033 | @item shell @var{command string} | |
1034 | @kindex shell | |
1035 | @cindex shell escape | |
a1eff6c2 RP |
1036 | Invoke a shell to execute @var{command string}. If it exists, the |
1037 | environment variable @code{SHELL} is used for the name of the shell to | |
1038 | run. | |
1039 | @ifclear DOSHOST | |
1040 | Otherwise @value{GDBN} uses @code{/bin/sh}. | |
1041 | @end ifclear | |
70b88761 RP |
1042 | @end table |
1043 | ||
1044 | The utility @code{make} is often needed in development environments. | |
a1eff6c2 RP |
1045 | You do not have to use the @code{shell} command for this purpose in |
1046 | @value{GDBN}: | |
70b88761 RP |
1047 | |
1048 | @table @code | |
1049 | @item make @var{make-args} | |
1050 | @kindex make | |
1051 | @cindex calling make | |
a1eff6c2 | 1052 | Execute the @code{make} program with the specified |
70b88761 RP |
1053 | arguments. This is equivalent to @samp{shell make @var{make-args}}. |
1054 | @end table | |
1055 | ||
4eb4cf57 | 1056 | @node Commands |
18fae2a8 | 1057 | @chapter @value{GDBN} Commands |
70b88761 | 1058 | |
18fae2a8 | 1059 | You can abbreviate a @value{GDBN} command to the first few letters of the command |
6f3ec223 | 1060 | name, if that abbreviation is unambiguous; and you can repeat certain |
18fae2a8 RP |
1061 | @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB} |
1062 | key to get @value{GDBN} to fill out the rest of a word in a command (or to | |
93918348 | 1063 | show you the alternatives available, if there is more than one possibility). |
29a2b744 | 1064 | |
70b88761 | 1065 | @menu |
ed447b95 RP |
1066 | * Command Syntax:: How to give commands to @value{GDBN} |
1067 | * Completion:: Command completion | |
1068 | * Help:: How to ask @value{GDBN} for help | |
70b88761 RP |
1069 | @end menu |
1070 | ||
4eb4cf57 | 1071 | @node Command Syntax |
93928b60 | 1072 | @section Command syntax |
1041a570 | 1073 | |
fe715d06 RP |
1074 | A @value{GDBN} command is a single line of input. There is no limit on |
1075 | how long it can be. It starts with a command name, which is followed by | |
1076 | arguments whose meaning depends on the command name. For example, the | |
1077 | command @code{step} accepts an argument which is the number of times to | |
1078 | step, as in @samp{step 5}. You can also use the @code{step} command | |
1079 | with no arguments. Some command names do not allow any arguments. | |
70b88761 RP |
1080 | |
1081 | @cindex abbreviation | |
18fae2a8 | 1082 | @value{GDBN} command names may always be truncated if that abbreviation is |
70b88761 RP |
1083 | unambiguous. Other possible command abbreviations are listed in the |
1084 | documentation for individual commands. In some cases, even ambiguous | |
1085 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1086 | equivalent to @code{step} even though there are other commands whose | |
1087 | names start with @code{s}. You can test abbreviations by using them as | |
7463aadd | 1088 | arguments to the @code{help} command. |
70b88761 | 1089 | |
e251e767 | 1090 | @cindex repeating commands |
70b88761 | 1091 | @kindex RET |
18fae2a8 | 1092 | A blank line as input to @value{GDBN} (typing just @key{RET}) means to |
70b88761 RP |
1093 | repeat the previous command. Certain commands (for example, @code{run}) |
1094 | will not repeat this way; these are commands for which unintentional | |
1095 | repetition might cause trouble and which you are unlikely to want to | |
1096 | repeat. | |
1097 | ||
1098 | The @code{list} and @code{x} commands, when you repeat them with | |
1099 | @key{RET}, construct new arguments rather than repeating | |
1100 | exactly as typed. This permits easy scanning of source or memory. | |
1101 | ||
18fae2a8 | 1102 | @value{GDBN} can also use @key{RET} in another way: to partition lengthy |
b80282d5 | 1103 | output, in a way similar to the common utility @code{more} |
93928b60 RP |
1104 | (@pxref{Screen Size,,Screen size}). Since it is easy to press one |
1105 | @key{RET} too many in this situation, @value{GDBN} disables command | |
1106 | repetition after any command that generates this sort of display. | |
b80282d5 | 1107 | |
70b88761 RP |
1108 | @kindex # |
1109 | @cindex comment | |
fe715d06 RP |
1110 | Any text from a @kbd{#} to the end of the line is a comment; it does |
1111 | nothing. This is useful mainly in command files (@pxref{Command | |
1112 | Files,,Command files}). | |
70b88761 | 1113 | |
4eb4cf57 | 1114 | @node Completion |
93928b60 | 1115 | @section Command completion |
6f3ec223 RP |
1116 | |
1117 | @cindex completion | |
1118 | @cindex word completion | |
93918348 | 1119 | @value{GDBN} can fill in the rest of a word in a command for you, if there is |
6f3ec223 | 1120 | only one possibility; it can also show you what the valid possibilities |
18fae2a8 RP |
1121 | are for the next word in a command, at any time. This works for @value{GDBN} |
1122 | commands, @value{GDBN} subcommands, and the names of symbols in your program. | |
6f3ec223 | 1123 | |
18fae2a8 | 1124 | Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest |
93918348 | 1125 | of a word. If there is only one possibility, @value{GDBN} will fill in the |
6f3ec223 RP |
1126 | word, and wait for you to finish the command (or press @key{RET} to |
1127 | enter it). For example, if you type | |
1128 | ||
93918348 | 1129 | @c FIXME "@key" does not distinguish its argument sufficiently to permit |
0fdc6e27 RP |
1130 | @c complete accuracy in these examples; space introduced for clarity. |
1131 | @c If texinfo enhancements make it unnecessary, it would be nice to | |
1132 | @c replace " @key" by "@key" in the following... | |
6f3ec223 | 1133 | @example |
18fae2a8 | 1134 | (@value{GDBP}) info bre @key{TAB} |
6f3ec223 RP |
1135 | @end example |
1136 | ||
1137 | @noindent | |
93918348 | 1138 | @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is |
6f3ec223 RP |
1139 | the only @code{info} subcommand beginning with @samp{bre}: |
1140 | ||
1141 | @example | |
18fae2a8 | 1142 | (@value{GDBP}) info breakpoints |
6f3ec223 RP |
1143 | @end example |
1144 | ||
1145 | @noindent | |
1146 | You can either press @key{RET} at this point, to run the @code{info | |
1147 | breakpoints} command, or backspace and enter something else, if | |
93918348 | 1148 | @samp{breakpoints} does not look like the command you expected. (If you |
6f3ec223 RP |
1149 | were sure you wanted @code{info breakpoints} in the first place, you |
1150 | might as well just type @key{RET} immediately after @samp{info bre}, | |
1151 | to exploit command abbreviations rather than command completion). | |
1152 | ||
1153 | If there is more than one possibility for the next word when you press | |
18fae2a8 | 1154 | @key{TAB}, @value{GDBN} will sound a bell. You can either supply more |
6f3ec223 | 1155 | characters and try again, or just press @key{TAB} a second time, and |
18fae2a8 | 1156 | @value{GDBN} will display all the possible completions for that word. For |
6f3ec223 | 1157 | example, you might want to set a breakpoint on a subroutine whose name |
18fae2a8 | 1158 | begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN} |
6f3ec223 RP |
1159 | just sounds the bell. Typing @key{TAB} again will display all the |
1160 | function names in your program that begin with those characters, for | |
1161 | example: | |
1162 | ||
1163 | @example | |
18fae2a8 RP |
1164 | (@value{GDBP}) b make_ @key{TAB} |
1165 | @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see: | |
6f3ec223 RP |
1166 | make_a_section_from_file make_environ |
1167 | make_abs_section make_function_type | |
1168 | make_blockvector make_pointer_type | |
1169 | make_cleanup make_reference_type | |
1170 | make_command make_symbol_completion_list | |
18fae2a8 | 1171 | (@value{GDBP}) b make_ |
6f3ec223 RP |
1172 | @end example |
1173 | ||
1174 | @noindent | |
18fae2a8 | 1175 | After displaying the available possibilities, @value{GDBN} copies your |
b1385986 | 1176 | partial input (@samp{b make_} in the example) so you can finish the |
6f3ec223 RP |
1177 | command. |
1178 | ||
1179 | If you just want to see the list of alternatives in the first place, you | |
b1385986 | 1180 | can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?} |
0f153e74 | 1181 | means @kbd{@key{META} ?}. You can type this |
18fae2a8 | 1182 | @ifclear DOSHOST |
0f153e74 | 1183 | either by holding down a |
b1385986 | 1184 | key designated as the @key{META} shift on your keyboard (if there is |
0f153e74 | 1185 | one) while typing @kbd{?}, or |
18fae2a8 | 1186 | @end ifclear |
0f153e74 | 1187 | as @key{ESC} followed by @kbd{?}. |
6f3ec223 RP |
1188 | |
1189 | @cindex quotes in commands | |
1190 | @cindex completion of quoted strings | |
1191 | Sometimes the string you need, while logically a ``word'', may contain | |
18fae2a8 | 1192 | parentheses or other characters that @value{GDBN} normally excludes from its |
6f3ec223 | 1193 | notion of a word. To permit word completion to work in this situation, |
18fae2a8 | 1194 | you may enclose words in @code{'} (single quote marks) in @value{GDBN} commands. |
6f3ec223 | 1195 | |
1d7c3357 | 1196 | @ifclear CONLY |
6f3ec223 RP |
1197 | The most likely situation where you might need this is in typing the |
1198 | name of a C++ function. This is because C++ allows function overloading | |
1199 | (multiple definitions of the same function, distinguished by argument | |
b1385986 RP |
1200 | type). For example, when you want to set a breakpoint you may need to |
1201 | distinguish whether you mean the version of @code{name} that takes an | |
1202 | @code{int} parameter, @code{name(int)}, or the version that takes a | |
1203 | @code{float} parameter, @code{name(float)}. To use the word-completion | |
1204 | facilities in this situation, type a single quote @code{'} at the | |
18fae2a8 | 1205 | beginning of the function name. This alerts @value{GDBN} that it may need to |
b1385986 RP |
1206 | consider more information than usual when you press @key{TAB} or |
1207 | @kbd{M-?} to request word completion: | |
6f3ec223 RP |
1208 | |
1209 | @example | |
18fae2a8 | 1210 | (@value{GDBP}) b 'bubble( @key{M-?} |
0fdc6e27 | 1211 | bubble(double,double) bubble(int,int) |
18fae2a8 | 1212 | (@value{GDBP}) b 'bubble( |
6f3ec223 RP |
1213 | @end example |
1214 | ||
18fae2a8 RP |
1215 | In some cases, @value{GDBN} can tell that completing a name will require |
1216 | quotes. When this happens, @value{GDBN} will insert the quote for you (while | |
0fdc6e27 RP |
1217 | completing as much as it can) if you do not type the quote in the first |
1218 | place: | |
1219 | ||
1220 | @example | |
18fae2a8 RP |
1221 | (@value{GDBP}) b bub @key{TAB} |
1222 | @exdent @value{GDBN} alters your input line to the following, and rings a bell: | |
1223 | (@value{GDBP}) b 'bubble( | |
0fdc6e27 RP |
1224 | @end example |
1225 | ||
1226 | @noindent | |
18fae2a8 | 1227 | In general, @value{GDBN} can tell that a quote is needed (and inserts it) if |
0fdc6e27 RP |
1228 | you have not yet started typing the argument list when you ask for |
1229 | completion on an overloaded symbol. | |
1d7c3357 | 1230 | @end ifclear |
0fdc6e27 RP |
1231 | |
1232 | ||
4eb4cf57 | 1233 | @node Help |
93928b60 | 1234 | @section Getting help |
70b88761 RP |
1235 | @cindex online documentation |
1236 | @kindex help | |
1041a570 | 1237 | |
18fae2a8 | 1238 | You can always ask @value{GDBN} itself for information on its commands, using the |
e251e767 | 1239 | command @code{help}. |
70b88761 RP |
1240 | |
1241 | @table @code | |
1242 | @item help | |
1243 | @itemx h | |
1244 | @kindex h | |
1245 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1246 | display a short list of named classes of commands: | |
1041a570 | 1247 | |
70b88761 | 1248 | @smallexample |
18fae2a8 | 1249 | (@value{GDBP}) help |
70b88761 RP |
1250 | List of classes of commands: |
1251 | ||
1252 | running -- Running the program | |
1253 | stack -- Examining the stack | |
1254 | data -- Examining data | |
1255 | breakpoints -- Making program stop at certain points | |
1256 | files -- Specifying and examining files | |
1257 | status -- Status inquiries | |
1258 | support -- Support facilities | |
1259 | user-defined -- User-defined commands | |
1260 | aliases -- Aliases of other commands | |
1261 | obscure -- Obscure features | |
1262 | ||
203eea5d RP |
1263 | Type "help" followed by a class name for a list of |
1264 | commands in that class. | |
1265 | Type "help" followed by command name for full | |
1266 | documentation. | |
70b88761 | 1267 | Command name abbreviations are allowed if unambiguous. |
18fae2a8 | 1268 | (@value{GDBP}) |
70b88761 RP |
1269 | @end smallexample |
1270 | ||
1271 | @item help @var{class} | |
1272 | Using one of the general help classes as an argument, you can get a | |
1273 | list of the individual commands in that class. For example, here is the | |
1274 | help display for the class @code{status}: | |
1041a570 | 1275 | |
70b88761 | 1276 | @smallexample |
18fae2a8 | 1277 | (@value{GDBP}) help status |
70b88761 RP |
1278 | Status inquiries. |
1279 | ||
1280 | List of commands: | |
1281 | ||
8c69096b RP |
1282 | @c Line break in "show" line falsifies real output, but needed |
1283 | @c to fit in smallbook page size. | |
1284 | show -- Generic command for showing things set | |
1285 | with "set" | |
70b88761 RP |
1286 | info -- Generic command for printing status |
1287 | ||
203eea5d RP |
1288 | Type "help" followed by command name for full |
1289 | documentation. | |
70b88761 | 1290 | Command name abbreviations are allowed if unambiguous. |
18fae2a8 | 1291 | (@value{GDBP}) |
70b88761 RP |
1292 | @end smallexample |
1293 | ||
1294 | @item help @var{command} | |
18fae2a8 | 1295 | With a command name as @code{help} argument, @value{GDBN} will display a |
e251e767 | 1296 | short paragraph on how to use that command. |
70b88761 RP |
1297 | @end table |
1298 | ||
18fae2a8 | 1299 | In addition to @code{help}, you can use the @value{GDBN} commands @code{info} |
70b88761 | 1300 | and @code{show} to inquire about the state of your program, or the state |
18fae2a8 | 1301 | of @value{GDBN} itself. Each command supports many topics of inquiry; this |
70b88761 RP |
1302 | manual introduces each of them in the appropriate context. The listings |
1303 | under @code{info} and under @code{show} in the Index point to | |
29a2b744 | 1304 | all the sub-commands. @xref{Index}. |
70b88761 RP |
1305 | |
1306 | @c @group | |
1307 | @table @code | |
1308 | @item info | |
1309 | @kindex info | |
1310 | @kindex i | |
1311 | This command (abbreviated @code{i}) is for describing the state of your | |
ed447b95 RP |
1312 | program. For example, you can list the arguments given to your program |
1313 | with @code{info args}, list the registers currently in use with @code{info | |
1314 | registers}, or list the breakpoints you have set with @code{info breakpoints}. | |
70b88761 RP |
1315 | You can get a complete list of the @code{info} sub-commands with |
1316 | @w{@code{help info}}. | |
1317 | ||
1318 | @kindex show | |
1319 | @item show | |
18fae2a8 | 1320 | In contrast, @code{show} is for describing the state of @value{GDBN} itself. |
70b88761 RP |
1321 | You can change most of the things you can @code{show}, by using the |
1322 | related command @code{set}; for example, you can control what number | |
1323 | system is used for displays with @code{set radix}, or simply inquire | |
e251e767 | 1324 | which is currently in use with @code{show radix}. |
70b88761 RP |
1325 | |
1326 | @kindex info set | |
1327 | To display all the settable parameters and their current | |
1328 | values, you can use @code{show} with no arguments; you may also use | |
1329 | @code{info set}. Both commands produce the same display. | |
1330 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1331 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1332 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1333 | @end table | |
1334 | @c @end group | |
1335 | ||
1336 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1337 | exceptional in lacking corresponding @code{set} commands: | |
1338 | ||
1339 | @table @code | |
1340 | @kindex show version | |
3d3ab540 | 1341 | @cindex version number |
70b88761 | 1342 | @item show version |
18fae2a8 RP |
1343 | Show what version of @value{GDBN} is running. You should include this |
1344 | information in @value{GDBN} bug-reports. If multiple versions of @value{GDBN} are in | |
ed447b95 | 1345 | use at your site, you may occasionally want to determine which version |
18fae2a8 | 1346 | of @value{GDBN} you are running; as @value{GDBN} evolves, new commands are introduced, |
1041a570 | 1347 | and old ones may wither away. The version number is also announced |
18fae2a8 | 1348 | when you start @value{GDBN} with no arguments. |
70b88761 RP |
1349 | |
1350 | @kindex show copying | |
1351 | @item show copying | |
18fae2a8 | 1352 | Display information about permission for copying @value{GDBN}. |
70b88761 RP |
1353 | |
1354 | @kindex show warranty | |
1355 | @item show warranty | |
1356 | Display the GNU ``NO WARRANTY'' statement. | |
1357 | @end table | |
1358 | ||
4eb4cf57 | 1359 | @node Running |
18fae2a8 | 1360 | @chapter Running Programs Under @value{GDBN} |
70b88761 | 1361 | |
ed447b95 | 1362 | When you run a program under @value{GDBN}, you must first generate |
1d7c3357 | 1363 | debugging information when you compile it. |
18fae2a8 | 1364 | @ifclear BARETARGET |
1d7c3357 RP |
1365 | You may start it with its arguments, if any, in an environment of your |
1366 | choice. You may redirect your program's input and output, debug an | |
1367 | already running process, or kill a child process. | |
18fae2a8 | 1368 | @end ifclear |
18fae2a8 | 1369 | |
18fae2a8 | 1370 | @menu |
ed447b95 RP |
1371 | * Compilation:: Compiling for debugging |
1372 | * Starting:: Starting your program | |
1d7c3357 | 1373 | @ifclear BARETARGET |
ed447b95 RP |
1374 | * Arguments:: Your program's arguments |
1375 | * Environment:: Your program's environment | |
1376 | * Working Directory:: Your program's working directory | |
1377 | * Input/Output:: Your program's input and output | |
1378 | * Attach:: Debugging an already-running process | |
1379 | * Kill Process:: Killing the child process | |
1380 | * Process Information:: Additional process information | |
18fae2a8 | 1381 | @end ifclear |
18fae2a8 | 1382 | @end menu |
70b88761 | 1383 | |
4eb4cf57 | 1384 | @node Compilation |
93928b60 | 1385 | @section Compiling for debugging |
70b88761 RP |
1386 | |
1387 | In order to debug a program effectively, you need to generate | |
1388 | debugging information when you compile it. This debugging information | |
1389 | is stored in the object file; it describes the data type of each | |
1390 | variable or function and the correspondence between source line numbers | |
1391 | and addresses in the executable code. | |
1392 | ||
1393 | To request debugging information, specify the @samp{-g} option when you run | |
1394 | the compiler. | |
1395 | ||
1396 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1397 | options together. Using those compilers, you cannot generate optimized | |
1398 | executables containing debugging information. | |
1399 | ||
18fae2a8 | 1400 | @value{NGCC}, the GNU C compiler, supports @samp{-g} with or without |
c7cb8acb RP |
1401 | @samp{-O}, making it possible to debug optimized code. We recommend |
1402 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1403 | You may think your program is correct, but there is no sense in pushing | |
1404 | your luck. | |
70b88761 | 1405 | |
6ca72cc6 RP |
1406 | @cindex optimized code, debugging |
1407 | @cindex debugging optimized code | |
1408 | When you debug a program compiled with @samp{-g -O}, remember that the | |
93918348 RP |
1409 | optimizer is rearranging your code; the debugger will show you what is |
1410 | really there. Do not be too surprised when the execution path does not | |
6ca72cc6 | 1411 | exactly match your source file! An extreme example: if you define a |
18fae2a8 | 1412 | variable, but never use it, @value{GDBN} will never see that |
6ca72cc6 RP |
1413 | variable---because the compiler optimizes it out of existence. |
1414 | ||
70b88761 RP |
1415 | Some things do not work as well with @samp{-g -O} as with just |
1416 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1417 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1418 | please report it as a bug (including a test case!). | |
1419 | ||
1420 | Older versions of the GNU C compiler permitted a variant option | |
18fae2a8 | 1421 | @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this |
70b88761 RP |
1422 | format; if your GNU C compiler has this option, do not use it. |
1423 | ||
1424 | @ignore | |
18fae2a8 | 1425 | @comment As far as I know, there are no cases in which @value{GDBN} will |
70b88761 RP |
1426 | @comment produce strange output in this case. (but no promises). |
1427 | If your program includes archives made with the @code{ar} program, and | |
1428 | if the object files used as input to @code{ar} were compiled without the | |
18fae2a8 | 1429 | @samp{-g} option and have names longer than 15 characters, @value{GDBN} will get |
29a2b744 | 1430 | confused reading your program's symbol table. No error message will be |
18fae2a8 | 1431 | given, but @value{GDBN} may behave strangely. The reason for this problem is a |
70b88761 RP |
1432 | deficiency in the Unix archive file format, which cannot represent file |
1433 | names longer than 15 characters. | |
1434 | ||
1435 | To avoid this problem, compile the archive members with the @samp{-g} | |
1436 | option or use shorter file names. Alternatively, use a version of GNU | |
1437 | @code{ar} dated more recently than August 1989. | |
1438 | @end ignore | |
1439 | ||
4eb4cf57 | 1440 | @node Starting |
93928b60 | 1441 | @section Starting your program |
70b88761 RP |
1442 | @cindex starting |
1443 | @cindex running | |
1041a570 | 1444 | |
70b88761 RP |
1445 | @table @code |
1446 | @item run | |
1447 | @itemx r | |
1448 | @kindex run | |
18fae2a8 | 1449 | Use the @code{run} command to start your program under @value{GDBN}. You must |
1041a570 | 1450 | first specify the program name |
18fae2a8 | 1451 | @ifset VXWORKS |
7463aadd | 1452 | (except on VxWorks) |
18fae2a8 | 1453 | @end ifset |
ed447b95 RP |
1454 | with an argument to @value{GDBN} (@pxref{Invocation, ,Getting In and |
1455 | Out of @value{GDBN}}), or by using the @code{file} or @code{exec-file} | |
93928b60 | 1456 | command (@pxref{Files, ,Commands to specify files}). |
1041a570 | 1457 | |
70b88761 RP |
1458 | @end table |
1459 | ||
18fae2a8 | 1460 | @ifclear BARETARGET |
29a2b744 RP |
1461 | If you are running your program in an execution environment that |
1462 | supports processes, @code{run} creates an inferior process and makes | |
1463 | that process run your program. (In environments without processes, | |
1464 | @code{run} jumps to the start of your program.) | |
70b88761 RP |
1465 | |
1466 | The execution of a program is affected by certain information it | |
18fae2a8 | 1467 | receives from its superior. @value{GDBN} provides ways to specify this |
6ca72cc6 | 1468 | information, which you must do @emph{before} starting your program. (You |
29a2b744 RP |
1469 | can change it after starting your program, but such changes will only affect |
1470 | your program the next time you start it.) This information may be | |
70b88761 RP |
1471 | divided into four categories: |
1472 | ||
1473 | @table @asis | |
6ca72cc6 | 1474 | @item The @emph{arguments.} |
29a2b744 | 1475 | Specify the arguments to give your program as the arguments of the |
1041a570 RP |
1476 | @code{run} command. If a shell is available on your target, the shell |
1477 | is used to pass the arguments, so that you may use normal conventions | |
1478 | (such as wildcard expansion or variable substitution) in describing | |
1479 | the arguments. In Unix systems, you can control which shell is used | |
1480 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
93928b60 | 1481 | program's arguments}. |
70b88761 | 1482 | |
6ca72cc6 | 1483 | @item The @emph{environment.} |
18fae2a8 RP |
1484 | Your program normally inherits its environment from @value{GDBN}, but you can |
1485 | use the @value{GDBN} commands @code{set environment} and @code{unset | |
70b88761 | 1486 | environment} to change parts of the environment that will be given to |
93928b60 | 1487 | your program. @xref{Environment, ,Your program's environment}. |
70b88761 | 1488 | |
6ca72cc6 | 1489 | @item The @emph{working directory.} |
18fae2a8 | 1490 | Your program inherits its working directory from @value{GDBN}. You can set |
93918348 | 1491 | the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}. |
93928b60 | 1492 | @xref{Working Directory, ,Your program's working directory}. |
70b88761 | 1493 | |
6ca72cc6 | 1494 | @item The @emph{standard input and output.} |
70b88761 | 1495 | Your program normally uses the same device for standard input and |
18fae2a8 | 1496 | standard output as @value{GDBN} is using. You can redirect input and output |
70b88761 RP |
1497 | in the @code{run} command line, or you can use the @code{tty} command to |
1498 | set a different device for your program. | |
93928b60 | 1499 | @xref{Input/Output, ,Your program's input and output}. |
3d3ab540 RP |
1500 | |
1501 | @cindex pipes | |
29a2b744 RP |
1502 | @emph{Warning:} While input and output redirection work, you cannot use |
1503 | pipes to pass the output of the program you are debugging to another | |
18fae2a8 | 1504 | program; if you attempt this, @value{GDBN} is likely to wind up debugging the |
3d3ab540 | 1505 | wrong program. |
70b88761 | 1506 | @end table |
18fae2a8 | 1507 | @end ifclear |
70b88761 | 1508 | |
1041a570 | 1509 | When you issue the @code{run} command, your program begins to execute |
93928b60 | 1510 | immediately. @xref{Stopping, ,Stopping and continuing}, for discussion |
4eb4cf57 RP |
1511 | of how to arrange for your program to stop. Once your program has |
1512 | stopped, you may calls functions in your program, using the @code{print} | |
1513 | or @code{call} commands. @xref{Data, ,Examining Data}. | |
70b88761 | 1514 | |
29a2b744 | 1515 | If the modification time of your symbol file has changed since the |
18fae2a8 RP |
1516 | last time @value{GDBN} read its symbols, @value{GDBN} will discard its symbol table and |
1517 | re-read it. When it does this, @value{GDBN} tries to retain your current | |
1041a570 | 1518 | breakpoints. |
70b88761 | 1519 | |
18fae2a8 | 1520 | @ifclear BARETARGET |
4eb4cf57 | 1521 | @node Arguments |
93928b60 | 1522 | @section Your program's arguments |
70b88761 RP |
1523 | |
1524 | @cindex arguments (to your program) | |
1525 | The arguments to your program can be specified by the arguments of the | |
1526 | @code{run} command. They are passed to a shell, which expands wildcard | |
29a2b744 | 1527 | characters and performs redirection of I/O, and thence to your program. |
ed447b95 RP |
1528 | @value{GDBN} uses the shell indicated by your @code{SHELL} environment |
1529 | variable if it exists; otherwise, @value{GDBN} uses @code{/bin/sh}. | |
70b88761 RP |
1530 | |
1531 | @code{run} with no arguments uses the same arguments used by the previous | |
1532 | @code{run}, or those set by the @code{set args} command. | |
1533 | ||
1534 | @kindex set args | |
1535 | @table @code | |
1536 | @item set args | |
1537 | Specify the arguments to be used the next time your program is run. If | |
1538 | @code{set args} has no arguments, @code{run} will execute your program | |
e251e767 | 1539 | with no arguments. Once you have run your program with arguments, |
70b88761 RP |
1540 | using @code{set args} before the next @code{run} is the only way to run |
1541 | it again without arguments. | |
1542 | ||
1543 | @item show args | |
1544 | @kindex show args | |
1545 | Show the arguments to give your program when it is started. | |
1546 | @end table | |
1547 | ||
4eb4cf57 | 1548 | @node Environment |
93928b60 | 1549 | @section Your program's environment |
70b88761 RP |
1550 | |
1551 | @cindex environment (of your program) | |
1552 | The @dfn{environment} consists of a set of environment variables and | |
1553 | their values. Environment variables conventionally record such things as | |
1554 | your user name, your home directory, your terminal type, and your search | |
1555 | path for programs to run. Usually you set up environment variables with | |
1556 | the shell and they are inherited by all the other programs you run. When | |
29a2b744 | 1557 | debugging, it can be useful to try running your program with a modified |
18fae2a8 | 1558 | environment without having to start @value{GDBN} over again. |
70b88761 RP |
1559 | |
1560 | @table @code | |
1561 | @item path @var{directory} | |
1562 | @kindex path | |
1563 | Add @var{directory} to the front of the @code{PATH} environment variable | |
18fae2a8 | 1564 | (the search path for executables), for both @value{GDBN} and your program. |
70b88761 RP |
1565 | You may specify several directory names, separated by @samp{:} or |
1566 | whitespace. If @var{directory} is already in the path, it is moved to | |
e251e767 | 1567 | the front, so it will be searched sooner. |
7463aadd RP |
1568 | |
1569 | You can use the string @samp{$cwd} to refer to whatever is the current | |
18fae2a8 | 1570 | working directory at the time @value{GDBN} searches the path. If you use |
7463aadd | 1571 | @samp{.} instead, it refers to the directory where you executed the |
18fae2a8 | 1572 | @code{path} command. @value{GDBN} fills in the current path where needed in |
7463aadd | 1573 | the @var{directory} argument, before adding it to the search path. |
29a2b744 | 1574 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to |
70b88761 RP |
1575 | @c document that, since repeating it would be a no-op. |
1576 | ||
1577 | @item show paths | |
1578 | @kindex show paths | |
1579 | Display the list of search paths for executables (the @code{PATH} | |
1580 | environment variable). | |
1581 | ||
1582 | @item show environment @r{[}@var{varname}@r{]} | |
1583 | @kindex show environment | |
1584 | Print the value of environment variable @var{varname} to be given to | |
29a2b744 | 1585 | your program when it starts. If you do not supply @var{varname}, |
70b88761 RP |
1586 | print the names and values of all environment variables to be given to |
1587 | your program. You can abbreviate @code{environment} as @code{env}. | |
1588 | ||
7463aadd | 1589 | @item set environment @var{varname} @r{[}=@r{]} @var{value} |
70b88761 | 1590 | @kindex set environment |
ed447b95 | 1591 | Set environment variable @var{varname} to @var{value}. The value |
18fae2a8 | 1592 | changes for your program only, not for @value{GDBN} itself. @var{value} may |
70b88761 RP |
1593 | be any string; the values of environment variables are just strings, and |
1594 | any interpretation is supplied by your program itself. The @var{value} | |
1595 | parameter is optional; if it is eliminated, the variable is set to a | |
1596 | null value. | |
29a2b744 | 1597 | @c "any string" here does not include leading, trailing |
70b88761 RP |
1598 | @c blanks. Gnu asks: does anyone care? |
1599 | ||
1600 | For example, this command: | |
1601 | ||
1602 | @example | |
1603 | set env USER = foo | |
1604 | @end example | |
1605 | ||
1606 | @noindent | |
1607 | tells a Unix program, when subsequently run, that its user is named | |
1608 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1609 | are not actually required.) | |
1610 | ||
1611 | @item unset environment @var{varname} | |
1612 | @kindex unset environment | |
1613 | Remove variable @var{varname} from the environment to be passed to your | |
1614 | program. This is different from @samp{set env @var{varname} =}; | |
1615 | @code{unset environment} removes the variable from the environment, | |
e251e767 | 1616 | rather than assigning it an empty value. |
70b88761 RP |
1617 | @end table |
1618 | ||
4eb4cf57 | 1619 | @node Working Directory |
93928b60 | 1620 | @section Your program's working directory |
70b88761 RP |
1621 | |
1622 | @cindex working directory (of your program) | |
1623 | Each time you start your program with @code{run}, it inherits its | |
93918348 RP |
1624 | working directory from the current working directory of @value{GDBN}. |
1625 | The @value{GDBN} working directory is initially whatever it inherited | |
1626 | from its parent process (typically the shell), but you can specify a new | |
1627 | working directory in @value{GDBN} with the @code{cd} command. | |
70b88761 | 1628 | |
18fae2a8 RP |
1629 | The @value{GDBN} working directory also serves as a default for the commands |
1630 | that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to | |
93928b60 | 1631 | specify files}. |
70b88761 RP |
1632 | |
1633 | @table @code | |
1634 | @item cd @var{directory} | |
1635 | @kindex cd | |
93918348 | 1636 | Set the @value{GDBN} working directory to @var{directory}. |
70b88761 RP |
1637 | |
1638 | @item pwd | |
1639 | @kindex pwd | |
93918348 | 1640 | Print the @value{GDBN} working directory. |
70b88761 RP |
1641 | @end table |
1642 | ||
4eb4cf57 | 1643 | @node Input/Output |
93928b60 | 1644 | @section Your program's input and output |
70b88761 RP |
1645 | |
1646 | @cindex redirection | |
1647 | @cindex i/o | |
1648 | @cindex terminal | |
18fae2a8 RP |
1649 | By default, the program you run under @value{GDBN} does input and output to |
1650 | the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal to | |
70b88761 RP |
1651 | its own terminal modes to interact with you, but it records the terminal |
1652 | modes your program was using and switches back to them when you continue | |
1653 | running your program. | |
1654 | ||
1655 | @table @code | |
1656 | @item info terminal | |
1657 | @kindex info terminal | |
93918348 | 1658 | Displays information recorded by @value{GDBN} about the terminal modes your |
70b88761 RP |
1659 | program is using. |
1660 | @end table | |
1661 | ||
29a2b744 | 1662 | You can redirect your program's input and/or output using shell |
70b88761 RP |
1663 | redirection with the @code{run} command. For example, |
1664 | ||
18fae2a8 | 1665 | @example |
70b88761 | 1666 | run > outfile |
18fae2a8 | 1667 | @end example |
70b88761 RP |
1668 | |
1669 | @noindent | |
29a2b744 | 1670 | starts your program, diverting its output to the file @file{outfile}. |
70b88761 RP |
1671 | |
1672 | @kindex tty | |
1673 | @cindex controlling terminal | |
29a2b744 | 1674 | Another way to specify where your program should do input and output is |
70b88761 RP |
1675 | with the @code{tty} command. This command accepts a file name as |
1676 | argument, and causes this file to be the default for future @code{run} | |
1677 | commands. It also resets the controlling terminal for the child | |
1678 | process, for future @code{run} commands. For example, | |
1679 | ||
1680 | @example | |
1681 | tty /dev/ttyb | |
1682 | @end example | |
1683 | ||
1684 | @noindent | |
1685 | directs that processes started with subsequent @code{run} commands | |
1686 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1687 | that as their controlling terminal. | |
1688 | ||
1689 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1690 | effect on the input/output device, but not its effect on the controlling | |
1691 | terminal. | |
1692 | ||
1693 | When you use the @code{tty} command or redirect input in the @code{run} | |
1694 | command, only the input @emph{for your program} is affected. The input | |
18fae2a8 | 1695 | for @value{GDBN} still comes from your terminal. |
70b88761 | 1696 | |
4eb4cf57 | 1697 | @node Attach |
93928b60 | 1698 | @section Debugging an already-running process |
70b88761 RP |
1699 | @kindex attach |
1700 | @cindex attach | |
1701 | ||
1702 | @table @code | |
1703 | @item attach @var{process-id} | |
1d7c3357 RP |
1704 | This command attaches to a running process---one that was started |
1705 | outside @value{GDBN}. (@code{info files} will show your active | |
1706 | targets.) The command takes as argument a process ID. The usual way to | |
1707 | find out the process-id of a Unix process is with the @code{ps} utility, | |
1708 | or with the @samp{jobs -l} shell command. | |
70b88761 RP |
1709 | |
1710 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1711 | executing the command. | |
1712 | @end table | |
1713 | ||
1714 | To use @code{attach}, you must be debugging in an environment which | |
1715 | supports processes. You must also have permission to send the process a | |
18fae2a8 | 1716 | signal, and it must have the same effective user ID as the @value{GDBN} |
70b88761 RP |
1717 | process. |
1718 | ||
1719 | When using @code{attach}, you should first use the @code{file} command | |
1720 | to specify the program running in the process and load its symbol table. | |
29a2b744 | 1721 | @xref{Files, ,Commands to Specify Files}. |
70b88761 | 1722 | |
18fae2a8 | 1723 | The first thing @value{GDBN} does after arranging to debug the specified |
70b88761 | 1724 | process is to stop it. You can examine and modify an attached process |
18fae2a8 | 1725 | with all the @value{GDBN} commands that are ordinarily available when you start |
70b88761 RP |
1726 | processes with @code{run}. You can insert breakpoints; you can step and |
1727 | continue; you can modify storage. If you would rather the process | |
1728 | continue running, you may use the @code{continue} command after | |
18fae2a8 | 1729 | attaching @value{GDBN} to the process. |
70b88761 RP |
1730 | |
1731 | @table @code | |
1732 | @item detach | |
1733 | @kindex detach | |
1734 | When you have finished debugging the attached process, you can use the | |
93918348 | 1735 | @code{detach} command to release it from @value{GDBN} control. Detaching |
70b88761 | 1736 | the process continues its execution. After the @code{detach} command, |
18fae2a8 | 1737 | that process and @value{GDBN} become completely independent once more, and you |
70b88761 RP |
1738 | are ready to @code{attach} another process or start one with @code{run}. |
1739 | @code{detach} will not repeat if you press @key{RET} again after | |
1740 | executing the command. | |
1741 | @end table | |
1742 | ||
18fae2a8 | 1743 | If you exit @value{GDBN} or use the @code{run} command while you have an attached |
70b88761 RP |
1744 | process, you kill that process. By default, you will be asked for |
1745 | confirmation if you try to do either of these things; you can control | |
1746 | whether or not you need to confirm by using the @code{set confirm} command | |
93928b60 | 1747 | (@pxref{Messages/Warnings, ,Optional warnings and messages}). |
70b88761 | 1748 | |
4eb4cf57 | 1749 | @node Kill Process |
70b88761 | 1750 | @c @group |
93928b60 | 1751 | @section Killing the child process |
70b88761 RP |
1752 | |
1753 | @table @code | |
1754 | @item kill | |
1755 | @kindex kill | |
18fae2a8 | 1756 | Kill the child process in which your program is running under @value{GDBN}. |
70b88761 RP |
1757 | @end table |
1758 | ||
1759 | This command is useful if you wish to debug a core dump instead of a | |
18fae2a8 | 1760 | running process. @value{GDBN} ignores any core dump file while your program |
70b88761 RP |
1761 | is running. |
1762 | @c @end group | |
1763 | ||
18fae2a8 RP |
1764 | On some operating systems, a program cannot be executed outside @value{GDBN} |
1765 | while you have breakpoints set on it inside @value{GDBN}. You can use the | |
29a2b744 | 1766 | @code{kill} command in this situation to permit running your program |
70b88761 RP |
1767 | outside the debugger. |
1768 | ||
1769 | The @code{kill} command is also useful if you wish to recompile and | |
29a2b744 | 1770 | relink your program, since on many systems it is impossible to modify an |
70b88761 | 1771 | executable file while it is running in a process. In this case, when you |
18fae2a8 | 1772 | next type @code{run}, @value{GDBN} will notice that the file has changed, and |
70b88761 RP |
1773 | will re-read the symbol table (while trying to preserve your current |
1774 | breakpoint settings). | |
1775 | ||
4eb4cf57 | 1776 | @node Process Information |
93928b60 | 1777 | @section Additional process information |
d24e0922 RP |
1778 | |
1779 | @kindex /proc | |
1780 | @cindex process image | |
1781 | Some operating systems provide a facility called @samp{/proc} that can | |
cc9bc574 | 1782 | be used to examine the image of a running process using file-system |
18fae2a8 | 1783 | subroutines. If @value{GDBN} is configured for an operating system with this |
cc9bc574 RP |
1784 | facility, the command @code{info proc} is available to report on several |
1785 | kinds of information about the process running your program. | |
d24e0922 RP |
1786 | |
1787 | @table @code | |
1788 | @item info proc | |
1789 | @kindex info proc | |
1790 | Summarize available information about the process. | |
1791 | ||
1792 | @item info proc mappings | |
1793 | @kindex info proc mappings | |
1794 | Report on the address ranges accessible in the program, with information | |
1795 | on whether your program may read, write, or execute each range. | |
1796 | ||
1797 | @item info proc times | |
1798 | @kindex info proc times | |
1799 | Starting time, user CPU time, and system CPU time for your program and | |
1800 | its children. | |
1801 | ||
1802 | @item info proc id | |
1803 | @kindex info proc id | |
93918348 RP |
1804 | Report on the process IDs related to your program: its own process ID, |
1805 | the ID of its parent, the process group ID, and the session ID. | |
d24e0922 RP |
1806 | |
1807 | @item info proc status | |
1808 | @kindex info proc status | |
1809 | General information on the state of the process. If the process is | |
1810 | stopped, this report includes the reason for stopping, and any signal | |
1811 | received. | |
cc9bc574 RP |
1812 | |
1813 | @item info proc all | |
1814 | Show all the above information about the process. | |
d24e0922 | 1815 | @end table |
18fae2a8 | 1816 | @end ifclear |
d24e0922 | 1817 | |
4eb4cf57 | 1818 | @node Stopping |
70b88761 RP |
1819 | @chapter Stopping and Continuing |
1820 | ||
ed447b95 | 1821 | The principal purposes of using a debugger are so that you can stop your |
29a2b744 | 1822 | program before it terminates; or so that, if your program runs into |
70b88761 RP |
1823 | trouble, you can investigate and find out why. |
1824 | ||
18fae2a8 | 1825 | Inside @value{GDBN}, your program may stop for any of several reasons, such |
1d7c3357 RP |
1826 | as |
1827 | @ifclear BARETARGET | |
1828 | a signal, | |
1829 | @end ifclear | |
1830 | a breakpoint, or reaching a new line after a @value{GDBN} | |
70b88761 RP |
1831 | command such as @code{step}. You may then examine and change |
1832 | variables, set new breakpoints or remove old ones, and then continue | |
18fae2a8 | 1833 | execution. Usually, the messages shown by @value{GDBN} provide ample |
70b88761 RP |
1834 | explanation of the status of your program---but you can also explicitly |
1835 | request this information at any time. | |
1836 | ||
1837 | @table @code | |
1838 | @item info program | |
1839 | @kindex info program | |
1840 | Display information about the status of your program: whether it is | |
1d7c3357 RP |
1841 | running or not, |
1842 | @ifclear BARETARGET | |
1843 | what process it is, | |
1844 | @end ifclear | |
1845 | and why it stopped. | |
70b88761 RP |
1846 | @end table |
1847 | ||
18fae2a8 RP |
1848 | @menu |
1849 | @ifclear CONLY | |
ed447b95 | 1850 | * Breakpoints:: Breakpoints, watchpoints, and exceptions |
18fae2a8 RP |
1851 | @end ifclear |
1852 | @ifset CONLY | |
ed447b95 | 1853 | * Breakpoints:: Breakpoints and watchpoints |
18fae2a8 | 1854 | @end ifset |
1d7c3357 | 1855 | @c Remnant makeinfo bug requires blank line after *successful* end-if in menu: |
18fae2a8 | 1856 | |
ed447b95 | 1857 | * Continuing and Stepping:: Resuming execution |
18fae2a8 | 1858 | @ifset POSIX |
b80282d5 | 1859 | * Signals:: Signals |
18fae2a8 | 1860 | @end ifset |
18fae2a8 | 1861 | @end menu |
70b88761 | 1862 | |
1d7c3357 | 1863 | @c makeinfo node-defaulting requires adjacency of @node and sectioning cmds |
18fae2a8 RP |
1864 | @c ...hence distribute @node Breakpoints over two possible @if expansions. |
1865 | @c | |
1866 | @ifclear CONLY | |
4eb4cf57 | 1867 | @node Breakpoints |
93928b60 | 1868 | @section Breakpoints, watchpoints, and exceptions |
18fae2a8 RP |
1869 | @end ifclear |
1870 | @ifset CONLY | |
1871 | @node Breakpoints | |
93928b60 | 1872 | @section Breakpoints and watchpoints |
18fae2a8 | 1873 | @end ifset |
70b88761 RP |
1874 | |
1875 | @cindex breakpoints | |
1876 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1041a570 | 1877 | the program is reached. For each breakpoint, you can add various |
29a2b744 | 1878 | conditions to control in finer detail whether your program will stop. |
70b88761 | 1879 | You can set breakpoints with the @code{break} command and its variants |
93928b60 | 1880 | (@pxref{Set Breaks, ,Setting breakpoints}), to specify the place where |
29a2b744 | 1881 | your program should stop by line number, function name or exact address |
0f153e74 | 1882 | in the program. |
18fae2a8 | 1883 | @ifclear CONLY |
0f153e74 RP |
1884 | In languages with exception handling (such as GNU C++), you can also set |
1885 | breakpoints where an exception is raised (@pxref{Exception Handling, | |
93928b60 | 1886 | ,Breakpoints and exceptions}). |
18fae2a8 | 1887 | @end ifclear |
70b88761 RP |
1888 | |
1889 | @cindex watchpoints | |
6ca72cc6 RP |
1890 | @cindex memory tracing |
1891 | @cindex breakpoint on memory address | |
1892 | @cindex breakpoint on variable modification | |
29a2b744 RP |
1893 | A @dfn{watchpoint} is a special breakpoint that stops your program |
1894 | when the value of an expression changes. You must use a different | |
1895 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
93928b60 | 1896 | watchpoints}), but aside from that, you can manage a watchpoint like |
29a2b744 | 1897 | any other breakpoint: you enable, disable, and delete both breakpoints |
1041a570 | 1898 | and watchpoints using the same commands. |
70b88761 | 1899 | |
fe715d06 RP |
1900 | You can arrange to have values from your program displayed automatically |
1901 | whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display, | |
1902 | ,Automatic display}. | |
1903 | ||
6ca72cc6 RP |
1904 | @cindex breakpoint numbers |
1905 | @cindex numbers for breakpoints | |
18fae2a8 | 1906 | @value{GDBN} assigns a number to each breakpoint or watchpoint when you |
6ca72cc6 RP |
1907 | create it; these numbers are successive integers starting with one. In |
1908 | many of the commands for controlling various features of breakpoints you | |
1909 | use the breakpoint number to say which breakpoint you want to change. | |
1910 | Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
29a2b744 | 1911 | no effect on your program until you enable it again. |
70b88761 RP |
1912 | |
1913 | @menu | |
ed447b95 RP |
1914 | * Set Breaks:: Setting breakpoints |
1915 | * Set Watchpoints:: Setting watchpoints | |
1d7c3357 | 1916 | @ifclear CONLY |
ed447b95 | 1917 | * Exception Handling:: Breakpoints and exceptions |
1d7c3357 | 1918 | @end ifclear |
b0157555 | 1919 | |
ed447b95 RP |
1920 | * Delete Breaks:: Deleting breakpoints |
1921 | * Disabling:: Disabling breakpoints | |
1922 | * Conditions:: Break conditions | |
1923 | * Break Commands:: Breakpoint command lists | |
1d7c3357 | 1924 | @ifclear CONLY |
ed447b95 | 1925 | * Breakpoint Menus:: Breakpoint menus |
1d7c3357 RP |
1926 | @end ifclear |
1927 | @ifclear BARETARGET | |
ed447b95 | 1928 | * Error in Breakpoints:: ``Cannot insert breakpoints'' |
1d7c3357 | 1929 | @end ifclear |
70b88761 RP |
1930 | @end menu |
1931 | ||
4eb4cf57 | 1932 | @node Set Breaks |
93928b60 | 1933 | @subsection Setting breakpoints |
70b88761 | 1934 | |
4906534f RP |
1935 | @c FIXME LMB what does GDB do if no code on line of breakpt? |
1936 | @c consider in particular declaration with/without initialization. | |
1937 | @c | |
1938 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1939 | ||
70b88761 RP |
1940 | @kindex break |
1941 | @kindex b | |
6ca72cc6 RP |
1942 | @kindex $bpnum |
1943 | @cindex latest breakpoint | |
1944 | Breakpoints are set with the @code{break} command (abbreviated | |
1945 | @code{b}). The debugger convenience variable @samp{$bpnum} records the | |
1946 | number of the beakpoint you've set most recently; see @ref{Convenience | |
93928b60 | 1947 | Vars,, Convenience variables}, for a discussion of what you can do with |
6ca72cc6 | 1948 | convenience variables. |
70b88761 RP |
1949 | |
1950 | You have several ways to say where the breakpoint should go. | |
1951 | ||
1952 | @table @code | |
1953 | @item break @var{function} | |
0f153e74 | 1954 | Set a breakpoint at entry to function @var{function}. |
18fae2a8 | 1955 | @ifclear CONLY |
0f153e74 RP |
1956 | When using source languages that permit overloading of symbols, such as |
1957 | C++, @var{function} may refer to more than one possible place to break. | |
93928b60 | 1958 | @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation. |
18fae2a8 | 1959 | @end ifclear |
70b88761 RP |
1960 | |
1961 | @item break +@var{offset} | |
1962 | @itemx break -@var{offset} | |
1963 | Set a breakpoint some number of lines forward or back from the position | |
1964 | at which execution stopped in the currently selected frame. | |
1965 | ||
1966 | @item break @var{linenum} | |
1967 | Set a breakpoint at line @var{linenum} in the current source file. | |
1968 | That file is the last file whose source text was printed. This | |
29a2b744 | 1969 | breakpoint will stop your program just before it executes any of the |
70b88761 RP |
1970 | code on that line. |
1971 | ||
1972 | @item break @var{filename}:@var{linenum} | |
1973 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1974 | ||
1975 | @item break @var{filename}:@var{function} | |
1976 | Set a breakpoint at entry to function @var{function} found in file | |
1977 | @var{filename}. Specifying a file name as well as a function name is | |
1978 | superfluous except when multiple files contain similarly named | |
1979 | functions. | |
1980 | ||
1981 | @item break *@var{address} | |
1982 | Set a breakpoint at address @var{address}. You can use this to set | |
29a2b744 | 1983 | breakpoints in parts of your program which do not have debugging |
70b88761 RP |
1984 | information or source files. |
1985 | ||
1986 | @item break | |
29a2b744 RP |
1987 | When called without any arguments, @code{break} sets a breakpoint at |
1988 | the next instruction to be executed in the selected stack frame | |
1989 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
1990 | innermost, this will cause your program to stop as soon as control | |
1991 | returns to that frame. This is similar to the effect of a | |
1992 | @code{finish} command in the frame inside the selected frame---except | |
1993 | that @code{finish} does not leave an active breakpoint. If you use | |
18fae2a8 | 1994 | @code{break} without an argument in the innermost frame, @value{GDBN} will stop |
1041a570 RP |
1995 | the next time it reaches the current location; this may be useful |
1996 | inside loops. | |
70b88761 | 1997 | |
18fae2a8 | 1998 | @value{GDBN} normally ignores breakpoints when it resumes execution, until at |
70b88761 RP |
1999 | least one instruction has been executed. If it did not do this, you |
2000 | would be unable to proceed past a breakpoint without first disabling the | |
2001 | breakpoint. This rule applies whether or not the breakpoint already | |
29a2b744 | 2002 | existed when your program stopped. |
70b88761 RP |
2003 | |
2004 | @item break @dots{} if @var{cond} | |
2005 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
2006 | @var{cond} each time the breakpoint is reached, and stop only if the | |
3d3ab540 | 2007 | value is nonzero---that is, if @var{cond} evaluates as true. |
1041a570 RP |
2008 | @samp{@dots{}} stands for one of the possible arguments described |
2009 | above (or no argument) specifying where to break. @xref{Conditions, | |
93928b60 | 2010 | ,Break conditions}, for more information on breakpoint conditions. |
70b88761 RP |
2011 | |
2012 | @item tbreak @var{args} | |
2013 | @kindex tbreak | |
2014 | Set a breakpoint enabled only for one stop. @var{args} are the | |
2015 | same as for the @code{break} command, and the breakpoint is set in the same | |
29a2b744 | 2016 | way, but the breakpoint is automatically disabled after the first time your |
93928b60 | 2017 | program stops there. @xref{Disabling, ,Disabling breakpoints}. |
70b88761 RP |
2018 | |
2019 | @item rbreak @var{regex} | |
2020 | @kindex rbreak | |
2021 | @cindex regular expression | |
4906534f | 2022 | @c FIXME what kind of regexp? |
70b88761 | 2023 | Set breakpoints on all functions matching the regular expression |
b80282d5 | 2024 | @var{regex}. This command |
70b88761 RP |
2025 | sets an unconditional breakpoint on all matches, printing a list of all |
2026 | breakpoints it set. Once these breakpoints are set, they are treated | |
2027 | just like the breakpoints set with the @code{break} command. They can | |
2028 | be deleted, disabled, made conditional, etc., in the standard ways. | |
2029 | ||
18fae2a8 | 2030 | @ifclear CONLY |
b80282d5 RP |
2031 | When debugging C++ programs, @code{rbreak} is useful for setting |
2032 | breakpoints on overloaded functions that are not members of any special | |
2033 | classes. | |
18fae2a8 | 2034 | @end ifclear |
b80282d5 | 2035 | |
70b88761 | 2036 | @kindex info breakpoints |
c338a2fd | 2037 | @cindex @code{$_} and @code{info breakpoints} |
70b88761 | 2038 | @item info breakpoints @r{[}@var{n}@r{]} |
6ca72cc6 RP |
2039 | @itemx info break @r{[}@var{n}@r{]} |
2040 | @itemx info watchpoints @r{[}@var{n}@r{]} | |
2041 | Print a table of all breakpoints and watchpoints set and not | |
2042 | deleted, with the following columns for each breakpoint: | |
2043 | ||
2044 | @table @emph | |
2045 | @item Breakpoint Numbers | |
2046 | @item Type | |
2047 | Breakpoint or watchpoint. | |
2048 | @item Disposition | |
2049 | Whether the breakpoint is marked to be disabled or deleted when hit. | |
2050 | @item Enabled or Disabled | |
d24e0922 | 2051 | Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints |
6ca72cc6 RP |
2052 | that are not enabled. |
2053 | @item Address | |
2054 | Where the breakpoint is in your program, as a memory address | |
2055 | @item What | |
2056 | Where the breakpoint is in the source for your program, as a file and | |
2057 | line number. | |
2058 | @end table | |
2059 | ||
2060 | @noindent | |
2061 | Breakpoint commands, if any, are listed after the line for the | |
2062 | corresponding breakpoint. | |
2063 | ||
2064 | @noindent | |
2065 | @code{info break} with a breakpoint | |
29a2b744 RP |
2066 | number @var{n} as argument lists only that breakpoint. The |
2067 | convenience variable @code{$_} and the default examining-address for | |
2068 | the @code{x} command are set to the address of the last breakpoint | |
93928b60 | 2069 | listed (@pxref{Memory, ,Examining memory}). |
1041a570 | 2070 | @end table |
70b88761 | 2071 | |
18fae2a8 | 2072 | @value{GDBN} allows you to set any number of breakpoints at the same place in |
1041a570 RP |
2073 | your program. There is nothing silly or meaningless about this. When |
2074 | the breakpoints are conditional, this is even useful | |
93928b60 | 2075 | (@pxref{Conditions, ,Break conditions}). |
70b88761 | 2076 | |
6ca72cc6 | 2077 | @cindex negative breakpoint numbers |
18fae2a8 RP |
2078 | @cindex internal @value{GDBN} breakpoints |
2079 | @value{GDBN} itself sometimes sets breakpoints in your program for special | |
6ca72cc6 RP |
2080 | purposes, such as proper handling of @code{longjmp} (in C programs). |
2081 | These internal breakpoints are assigned negative numbers, starting with | |
5a2c1d85 | 2082 | @code{-1}; @samp{info breakpoints} does not display them. |
d48da190 | 2083 | |
18fae2a8 | 2084 | You can see these breakpoints with the @value{GDBN} maintenance command |
5a2c1d85 | 2085 | @samp{maint info breakpoints}. |
6ca72cc6 RP |
2086 | |
2087 | @table @code | |
d48da190 RP |
2088 | @kindex maint info breakpoints |
2089 | @item maint info breakpoints | |
6ca72cc6 | 2090 | Using the same format as @samp{info breakpoints}, display both the |
18fae2a8 | 2091 | breakpoints you've set explicitly, and those @value{GDBN} is using for |
6ca72cc6 RP |
2092 | internal purposes. Internal breakpoints are shown with negative |
2093 | breakpoint numbers. The type column identifies what kind of breakpoint | |
2094 | is shown: | |
2095 | ||
2096 | @table @code | |
2097 | @item breakpoint | |
2098 | Normal, explicitly set breakpoint. | |
2099 | ||
2100 | @item watchpoint | |
2101 | Normal, explicitly set watchpoint. | |
2102 | ||
2103 | @item longjmp | |
2104 | Internal breakpoint, used to handle correctly stepping through | |
2105 | @code{longjmp} calls. | |
2106 | ||
2107 | @item longjmp resume | |
2108 | Internal breakpoint at the target of a @code{longjmp}. | |
2109 | ||
2110 | @item until | |
18fae2a8 | 2111 | Temporary internal breakpoint used by the @value{GDBN} @code{until} command. |
6ca72cc6 RP |
2112 | |
2113 | @item finish | |
18fae2a8 | 2114 | Temporary internal breakpoint used by the @value{GDBN} @code{finish} command. |
6ca72cc6 RP |
2115 | @end table |
2116 | ||
2117 | @end table | |
2118 | ||
2119 | ||
4eb4cf57 | 2120 | @node Set Watchpoints |
93928b60 | 2121 | @subsection Setting watchpoints |
70b88761 | 2122 | @cindex setting watchpoints |
1041a570 | 2123 | |
70b88761 | 2124 | You can use a watchpoint to stop execution whenever the value of an |
e251e767 | 2125 | expression changes, without having to predict a particular place |
70b88761 RP |
2126 | where this may happen. |
2127 | ||
2128 | Watchpoints currently execute two orders of magnitude more slowly than | |
2129 | other breakpoints, but this can well be worth it to catch errors where | |
2130 | you have no clue what part of your program is the culprit. Some | |
2131 | processors provide special hardware to support watchpoint evaluation; future | |
18fae2a8 | 2132 | releases of @value{GDBN} will use such hardware if it is available. |
70b88761 RP |
2133 | |
2134 | @table @code | |
e251e767 | 2135 | @kindex watch |
70b88761 RP |
2136 | @item watch @var{expr} |
2137 | Set a watchpoint for an expression. | |
2138 | ||
2139 | @kindex info watchpoints | |
2140 | @item info watchpoints | |
6ca72cc6 RP |
2141 | This command prints a list of watchpoints and breakpoints; it is the |
2142 | same as @code{info break}. | |
70b88761 RP |
2143 | @end table |
2144 | ||
1d7c3357 | 2145 | @ifclear CONLY |
4eb4cf57 | 2146 | @node Exception Handling |
93928b60 | 2147 | @subsection Breakpoints and exceptions |
70b88761 RP |
2148 | @cindex exception handlers |
2149 | ||
b80282d5 | 2150 | Some languages, such as GNU C++, implement exception handling. You can |
18fae2a8 | 2151 | use @value{GDBN} to examine what caused your program to raise an exception, |
29a2b744 | 2152 | and to list the exceptions your program is prepared to handle at a |
70b88761 RP |
2153 | given point in time. |
2154 | ||
2155 | @table @code | |
2156 | @item catch @var{exceptions} | |
2157 | @kindex catch | |
2158 | You can set breakpoints at active exception handlers by using the | |
2159 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
2160 | to catch. | |
2161 | @end table | |
2162 | ||
29a2b744 | 2163 | You can use @code{info catch} to list active exception handlers. |
93928b60 | 2164 | @xref{Frame Info, ,Information about a frame}. |
70b88761 | 2165 | |
18fae2a8 | 2166 | There are currently some limitations to exception handling in @value{GDBN}. |
70b88761 RP |
2167 | These will be corrected in a future release. |
2168 | ||
2169 | @itemize @bullet | |
2170 | @item | |
18fae2a8 | 2171 | If you call a function interactively, @value{GDBN} normally returns |
70b88761 RP |
2172 | control to you when the function has finished executing. If the call |
2173 | raises an exception, however, the call may bypass the mechanism that | |
29a2b744 | 2174 | returns control to you and cause your program to simply continue |
18fae2a8 | 2175 | running until it hits a breakpoint, catches a signal that @value{GDBN} is |
70b88761 RP |
2176 | listening for, or exits. |
2177 | @item | |
2178 | You cannot raise an exception interactively. | |
2179 | @item | |
2180 | You cannot interactively install an exception handler. | |
2181 | @end itemize | |
2182 | ||
2183 | @cindex raise exceptions | |
2184 | Sometimes @code{catch} is not the best way to debug exception handling: | |
29a2b744 | 2185 | if you need to know exactly where an exception is raised, it is better to |
70b88761 RP |
2186 | stop @emph{before} the exception handler is called, since that way you |
2187 | can see the stack before any unwinding takes place. If you set a | |
2188 | breakpoint in an exception handler instead, it may not be easy to find | |
2189 | out where the exception was raised. | |
2190 | ||
2191 | To stop just before an exception handler is called, you need some | |
b80282d5 | 2192 | knowledge of the implementation. In the case of GNU C++, exceptions are |
70b88761 RP |
2193 | raised by calling a library function named @code{__raise_exception} |
2194 | which has the following ANSI C interface: | |
2195 | ||
2196 | @example | |
b80282d5 | 2197 | /* @var{addr} is where the exception identifier is stored. |
70b88761 RP |
2198 | ID is the exception identifier. */ |
2199 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
2200 | @end example | |
2201 | ||
2202 | @noindent | |
2203 | To make the debugger catch all exceptions before any stack | |
2204 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
93928b60 | 2205 | (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}). |
70b88761 | 2206 | |
93928b60 | 2207 | With a conditional breakpoint (@pxref{Conditions, ,Break conditions}) |
29a2b744 RP |
2208 | that depends on the value of @var{id}, you can stop your program when |
2209 | a specific exception is raised. You can use multiple conditional | |
2210 | breakpoints to stop your program when any of a number of exceptions are | |
2211 | raised. | |
1d7c3357 | 2212 | @end ifclear |
70b88761 | 2213 | |
4eb4cf57 | 2214 | @node Delete Breaks |
93928b60 | 2215 | @subsection Deleting breakpoints |
70b88761 RP |
2216 | |
2217 | @cindex clearing breakpoints, watchpoints | |
2218 | @cindex deleting breakpoints, watchpoints | |
2219 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
29a2b744 | 2220 | has done its job and you no longer want your program to stop there. This |
70b88761 RP |
2221 | is called @dfn{deleting} the breakpoint. A breakpoint that has been |
2222 | deleted no longer exists; it is forgotten. | |
2223 | ||
2224 | With the @code{clear} command you can delete breakpoints according to | |
29a2b744 | 2225 | where they are in your program. With the @code{delete} command you can |
70b88761 RP |
2226 | delete individual breakpoints or watchpoints by specifying their |
2227 | breakpoint numbers. | |
2228 | ||
18fae2a8 | 2229 | It is not necessary to delete a breakpoint to proceed past it. @value{GDBN} |
70b88761 RP |
2230 | automatically ignores breakpoints on the first instruction to be executed |
2231 | when you continue execution without changing the execution address. | |
2232 | ||
2233 | @table @code | |
2234 | @item clear | |
2235 | @kindex clear | |
2236 | Delete any breakpoints at the next instruction to be executed in the | |
93928b60 | 2237 | selected stack frame (@pxref{Selection, ,Selecting a frame}). When |
29a2b744 RP |
2238 | the innermost frame is selected, this is a good way to delete a |
2239 | breakpoint where your program just stopped. | |
70b88761 RP |
2240 | |
2241 | @item clear @var{function} | |
2242 | @itemx clear @var{filename}:@var{function} | |
2243 | Delete any breakpoints set at entry to the function @var{function}. | |
2244 | ||
2245 | @item clear @var{linenum} | |
2246 | @itemx clear @var{filename}:@var{linenum} | |
2247 | Delete any breakpoints set at or within the code of the specified line. | |
2248 | ||
2249 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2250 | @cindex delete breakpoints | |
2251 | @kindex delete | |
2252 | @kindex d | |
2253 | Delete the breakpoints or watchpoints of the numbers specified as | |
18fae2a8 | 2254 | arguments. If no argument is specified, delete all breakpoints (@value{GDBN} |
1041a570 | 2255 | asks confirmation, unless you have @code{set confirm off}). You |
70b88761 RP |
2256 | can abbreviate this command as @code{d}. |
2257 | @end table | |
2258 | ||
4eb4cf57 | 2259 | @node Disabling |
93928b60 | 2260 | @subsection Disabling breakpoints |
70b88761 RP |
2261 | |
2262 | @cindex disabled breakpoints | |
2263 | @cindex enabled breakpoints | |
2264 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
2265 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
2266 | been deleted, but remembers the information on the breakpoint so that | |
2267 | you can @dfn{enable} it again later. | |
2268 | ||
2269 | You disable and enable breakpoints and watchpoints with the | |
2270 | @code{enable} and @code{disable} commands, optionally specifying one or | |
2271 | more breakpoint numbers as arguments. Use @code{info break} or | |
2272 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
29a2b744 | 2273 | do not know which numbers to use. |
70b88761 RP |
2274 | |
2275 | A breakpoint or watchpoint can have any of four different states of | |
2276 | enablement: | |
2277 | ||
2278 | @itemize @bullet | |
2279 | @item | |
29a2b744 | 2280 | Enabled. The breakpoint will stop your program. A breakpoint set |
70b88761 RP |
2281 | with the @code{break} command starts out in this state. |
2282 | @item | |
29a2b744 | 2283 | Disabled. The breakpoint has no effect on your program. |
70b88761 | 2284 | @item |
29a2b744 | 2285 | Enabled once. The breakpoint will stop your program, but |
70b88761 RP |
2286 | when it does so it will become disabled. A breakpoint set |
2287 | with the @code{tbreak} command starts out in this state. | |
2288 | @item | |
29a2b744 | 2289 | Enabled for deletion. The breakpoint will stop your program, but |
70b88761 RP |
2290 | immediately after it does so it will be deleted permanently. |
2291 | @end itemize | |
2292 | ||
2293 | You can use the following commands to enable or disable breakpoints and | |
2294 | watchpoints: | |
2295 | ||
2296 | @table @code | |
2297 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2298 | @kindex disable breakpoints | |
2299 | @kindex disable | |
2300 | @kindex dis | |
2301 | Disable the specified breakpoints---or all breakpoints, if none are | |
2302 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2303 | options such as ignore-counts, conditions and commands are remembered in | |
2304 | case the breakpoint is enabled again later. You may abbreviate | |
2305 | @code{disable} as @code{dis}. | |
2306 | ||
2307 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2308 | @kindex enable breakpoints | |
2309 | @kindex enable | |
2310 | Enable the specified breakpoints (or all defined breakpoints). They | |
29a2b744 | 2311 | become effective once again in stopping your program. |
70b88761 RP |
2312 | |
2313 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2314 | Enable the specified breakpoints temporarily. Each will be disabled | |
29a2b744 | 2315 | again the next time it stops your program. |
70b88761 RP |
2316 | |
2317 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2318 | Enable the specified breakpoints to work once and then die. Each of | |
29a2b744 | 2319 | the breakpoints will be deleted the next time it stops your program. |
70b88761 RP |
2320 | @end table |
2321 | ||
29a2b744 | 2322 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, |
93928b60 RP |
2323 | ,Setting breakpoints}), breakpoints that you set are initially enabled; |
2324 | subsequently, they become disabled or enabled only when you use one of | |
2325 | the commands above. (The command @code{until} can set and delete a | |
2326 | breakpoint of its own, but it will not change the state of your other | |
2327 | breakpoints; see @ref{Continuing and Stepping, ,Continuing and | |
2328 | stepping}.) | |
70b88761 | 2329 | |
4eb4cf57 | 2330 | @node Conditions |
93928b60 | 2331 | @subsection Break conditions |
70b88761 RP |
2332 | @cindex conditional breakpoints |
2333 | @cindex breakpoint conditions | |
2334 | ||
4906534f RP |
2335 | @c FIXME what is scope of break condition expr? Context where wanted? |
2336 | @c in particular for a watchpoint? | |
29a2b744 | 2337 | The simplest sort of breakpoint breaks every time your program reaches a |
70b88761 RP |
2338 | specified place. You can also specify a @dfn{condition} for a |
2339 | breakpoint. A condition is just a Boolean expression in your | |
1041a570 RP |
2340 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with |
2341 | a condition evaluates the expression each time your program reaches it, | |
2342 | and your program stops only if the condition is @emph{true}. | |
3d3ab540 RP |
2343 | |
2344 | This is the converse of using assertions for program validation; in that | |
2345 | situation, you want to stop when the assertion is violated---that is, | |
2346 | when the condition is false. In C, if you want to test an assertion expressed | |
e251e767 | 2347 | by the condition @var{assert}, you should set the condition |
3d3ab540 | 2348 | @samp{! @var{assert}} on the appropriate breakpoint. |
70b88761 RP |
2349 | |
2350 | Conditions are also accepted for watchpoints; you may not need them, | |
2351 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2352 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2353 | and specify a condition that tests whether the new value is an interesting | |
e251e767 | 2354 | one. |
70b88761 | 2355 | |
29a2b744 | 2356 | Break conditions can have side effects, and may even call functions in |
70b88761 | 2357 | your program. This can be useful, for example, to activate functions |
29a2b744 RP |
2358 | that log program progress, or to use your own print functions to |
2359 | format special data structures. The effects are completely predictable | |
2360 | unless there is another enabled breakpoint at the same address. (In | |
18fae2a8 | 2361 | that case, @value{GDBN} might see the other breakpoint first and stop your |
29a2b744 RP |
2362 | program without checking the condition of this one.) Note that |
2363 | breakpoint commands are usually more convenient and flexible for the | |
2364 | purpose of performing side effects when a breakpoint is reached | |
93928b60 | 2365 | (@pxref{Break Commands, ,Breakpoint command lists}). |
70b88761 RP |
2366 | |
2367 | Break conditions can be specified when a breakpoint is set, by using | |
29a2b744 | 2368 | @samp{if} in the arguments to the @code{break} command. @xref{Set |
93928b60 | 2369 | Breaks, ,Setting breakpoints}. They can also be changed at any time |
29a2b744 RP |
2370 | with the @code{condition} command. The @code{watch} command does not |
2371 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2372 | impose a further condition on a watchpoint. | |
70b88761 | 2373 | |
e251e767 RP |
2374 | @table @code |
2375 | @item condition @var{bnum} @var{expression} | |
2376 | @kindex condition | |
70b88761 RP |
2377 | Specify @var{expression} as the break condition for breakpoint or |
2378 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
29a2b744 | 2379 | your program only if the value of @var{expression} is true (nonzero, in |
18fae2a8 | 2380 | C). When you use @code{condition}, @value{GDBN} checks @var{expression} |
70b88761 | 2381 | immediately for syntactic correctness, and to determine whether symbols |
1041a570 | 2382 | in it have referents in the context of your breakpoint. |
29a2b744 | 2383 | @c FIXME so what does GDB do if there is no referent? Moreover, what |
4906534f | 2384 | @c about watchpoints? |
18fae2a8 | 2385 | @value{GDBN} does |
70b88761 | 2386 | not actually evaluate @var{expression} at the time the @code{condition} |
1041a570 | 2387 | command is given, however. @xref{Expressions, ,Expressions}. |
70b88761 RP |
2388 | |
2389 | @item condition @var{bnum} | |
2390 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2391 | an ordinary unconditional breakpoint. | |
2392 | @end table | |
2393 | ||
2394 | @cindex ignore count (of breakpoint) | |
2395 | A special case of a breakpoint condition is to stop only when the | |
2396 | breakpoint has been reached a certain number of times. This is so | |
2397 | useful that there is a special way to do it, using the @dfn{ignore | |
2398 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2399 | is an integer. Most of the time, the ignore count is zero, and | |
29a2b744 | 2400 | therefore has no effect. But if your program reaches a breakpoint whose |
70b88761 RP |
2401 | ignore count is positive, then instead of stopping, it just decrements |
2402 | the ignore count by one and continues. As a result, if the ignore count | |
2403 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2404 | is reached. | |
2405 | ||
2406 | @table @code | |
2407 | @item ignore @var{bnum} @var{count} | |
2408 | @kindex ignore | |
2409 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2410 | The next @var{count} times the breakpoint is reached, your program's | |
18fae2a8 | 2411 | execution will not stop; other than to decrement the ignore count, @value{GDBN} |
70b88761 RP |
2412 | takes no action. |
2413 | ||
2414 | To make the breakpoint stop the next time it is reached, specify | |
2415 | a count of zero. | |
2416 | ||
2417 | @item continue @var{count} | |
2418 | @itemx c @var{count} | |
2419 | @itemx fg @var{count} | |
2420 | @kindex continue @var{count} | |
29a2b744 RP |
2421 | Continue execution of your program, setting the ignore count of the |
2422 | breakpoint where your program stopped to @var{count} minus one. | |
2423 | Thus, your program will not stop at this breakpoint until the | |
70b88761 RP |
2424 | @var{count}'th time it is reached. |
2425 | ||
29a2b744 | 2426 | An argument to this command is meaningful only when your program stopped |
70b88761 RP |
2427 | due to a breakpoint. At other times, the argument to @code{continue} is |
2428 | ignored. | |
2429 | ||
2430 | The synonym @code{fg} is provided purely for convenience, and has | |
2431 | exactly the same behavior as other forms of the command. | |
2432 | @end table | |
2433 | ||
2434 | If a breakpoint has a positive ignore count and a condition, the condition | |
2435 | is not checked. Once the ignore count reaches zero, the condition will | |
2436 | be checked. | |
2437 | ||
29a2b744 | 2438 | You could achieve the effect of the ignore count with a condition such |
18fae2a8 | 2439 | as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that |
1041a570 | 2440 | is decremented each time. @xref{Convenience Vars, ,Convenience |
93928b60 | 2441 | variables}. |
70b88761 | 2442 | |
4eb4cf57 | 2443 | @node Break Commands |
93928b60 | 2444 | @subsection Breakpoint command lists |
70b88761 RP |
2445 | |
2446 | @cindex breakpoint commands | |
2447 | You can give any breakpoint (or watchpoint) a series of commands to | |
29a2b744 | 2448 | execute when your program stops due to that breakpoint. For example, you |
70b88761 RP |
2449 | might want to print the values of certain expressions, or enable other |
2450 | breakpoints. | |
2451 | ||
2452 | @table @code | |
2453 | @item commands @r{[}@var{bnum}@r{]} | |
2454 | @itemx @dots{} @var{command-list} @dots{} | |
2455 | @itemx end | |
2456 | @kindex commands | |
2457 | @kindex end | |
2458 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2459 | themselves appear on the following lines. Type a line containing just | |
2460 | @code{end} to terminate the commands. | |
2461 | ||
203eea5d RP |
2462 | To remove all commands from a breakpoint, type @code{commands} and |
2463 | follow it immediately with @code{end}; that is, give no commands. | |
70b88761 RP |
2464 | |
2465 | With no @var{bnum} argument, @code{commands} refers to the last | |
2466 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2467 | encountered). | |
2468 | @end table | |
2469 | ||
18fae2a8 | 2470 | Pressing @key{RET} as a means of repeating the last @value{GDBN} command is |
70b88761 RP |
2471 | disabled within a @var{command-list}. |
2472 | ||
29a2b744 | 2473 | You can use breakpoint commands to start your program up again. Simply |
70b88761 | 2474 | use the @code{continue} command, or @code{step}, or any other command |
fe715d06 RP |
2475 | that resumes execution. |
2476 | ||
2477 | Any other commands in the command list, after a command that resumes | |
2478 | execution, are ignored. This is because any time you resume execution | |
2479 | (even with a simple @code{next} or @code{step}), you may encounter | |
2480 | another breakpoint---which could have its own command list, leading to | |
2481 | ambiguities about which list to execute. | |
70b88761 RP |
2482 | |
2483 | @kindex silent | |
fe715d06 RP |
2484 | If the first command you specify in a command list is @code{silent}, the |
2485 | usual message about stopping at a breakpoint is not printed. This may | |
2486 | be desirable for breakpoints that are to print a specific message and | |
2487 | then continue. If none of the remaining commands print anything, you | |
2488 | will see no sign that the breakpoint was reached. @code{silent} is | |
2489 | meaningful only at the beginning of a breakpoint command list. | |
70b88761 | 2490 | |
29a2b744 RP |
2491 | The commands @code{echo} and @code{output} that allow you to print |
2492 | precisely controlled output are often useful in silent breakpoints. | |
93928b60 | 2493 | @xref{Output, ,Commands for controlled output}. |
70b88761 RP |
2494 | |
2495 | For example, here is how you could use breakpoint commands to print the | |
2496 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2497 | ||
18fae2a8 | 2498 | @example |
70b88761 RP |
2499 | break foo if x>0 |
2500 | commands | |
2501 | silent | |
2502 | echo x is\040 | |
2503 | output x | |
2504 | echo \n | |
2505 | cont | |
2506 | end | |
18fae2a8 | 2507 | @end example |
70b88761 RP |
2508 | |
2509 | One application for breakpoint commands is to compensate for one bug so | |
2510 | you can test for another. Put a breakpoint just after the erroneous line | |
2511 | of code, give it a condition to detect the case in which something | |
2512 | erroneous has been done, and give it commands to assign correct values | |
2513 | to any variables that need them. End with the @code{continue} command | |
29a2b744 | 2514 | so that your program does not stop, and start with the @code{silent} |
70b88761 RP |
2515 | command so that no output is produced. Here is an example: |
2516 | ||
2517 | @example | |
2518 | break 403 | |
2519 | commands | |
2520 | silent | |
2521 | set x = y + 4 | |
2522 | cont | |
2523 | end | |
2524 | @end example | |
2525 | ||
2526 | @cindex lost output | |
2527 | One deficiency in the operation of automatically continuing breakpoints | |
2528 | under Unix appears when your program uses raw mode for the terminal. | |
18fae2a8 | 2529 | @value{GDBN} switches back to its own terminal modes (not raw) before executing |
70b88761 | 2530 | commands, and then must switch back to raw mode when your program is |
e251e767 | 2531 | continued. This causes any pending terminal input to be lost. |
70b88761 RP |
2532 | @c FIXME: revisit below when GNU sys avail. |
2533 | @c In the GNU system, this will be fixed by changing the behavior of | |
2534 | @c terminal modes. | |
2535 | ||
2536 | Under Unix, you can get around this problem by writing actions into | |
ed447b95 | 2537 | the breakpoint condition rather than in commands. For example, |
70b88761 RP |
2538 | |
2539 | @example | |
2540 | condition 5 (x = y + 4), 0 | |
2541 | @end example | |
2542 | ||
2543 | @noindent | |
1041a570 RP |
2544 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will |
2545 | change @code{x} as needed, then always have the value zero so your | |
18fae2a8 | 2546 | program will not stop. No input is lost here, because @value{GDBN} evaluates |
1041a570 RP |
2547 | break conditions without changing the terminal modes. When you want |
2548 | to have nontrivial conditions for performing the side effects, the | |
2549 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
70b88761 | 2550 | |
1d7c3357 | 2551 | @ifclear CONLY |
4eb4cf57 | 2552 | @node Breakpoint Menus |
93928b60 | 2553 | @subsection Breakpoint menus |
b80282d5 | 2554 | @cindex overloading |
e251e767 | 2555 | @cindex symbol overloading |
70b88761 RP |
2556 | |
2557 | Some programming languages (notably C++) permit a single function name | |
2558 | to be defined several times, for application in different contexts. | |
2559 | This is called @dfn{overloading}. When a function name is overloaded, | |
18fae2a8 | 2560 | @samp{break @var{function}} is not enough to tell @value{GDBN} where you want |
6f3ec223 RP |
2561 | a breakpoint. If you realize this will be a problem, you can use |
2562 | something like @samp{break @var{function}(@var{types})} to specify which | |
18fae2a8 | 2563 | particular version of the function you want. Otherwise, @value{GDBN} offers |
6f3ec223 RP |
2564 | you a menu of numbered choices for different possible breakpoints, and |
2565 | waits for your selection with the prompt @samp{>}. The first two | |
2566 | options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1} | |
2567 | sets a breakpoint at each definition of @var{function}, and typing | |
2568 | @kbd{0} aborts the @code{break} command without setting any new | |
2569 | breakpoints. | |
70b88761 RP |
2570 | |
2571 | For example, the following session excerpt shows an attempt to set a | |
e251e767 | 2572 | breakpoint at the overloaded symbol @code{String::after}. |
70b88761 RP |
2573 | We choose three particular definitions of that function name: |
2574 | ||
6f3ec223 | 2575 | @c FIXME! This is likely to change to show arg type lists, at least |
70b88761 | 2576 | @example |
18fae2a8 | 2577 | (@value{GDBP}) b String::after |
70b88761 RP |
2578 | [0] cancel |
2579 | [1] all | |
2580 | [2] file:String.cc; line number:867 | |
2581 | [3] file:String.cc; line number:860 | |
2582 | [4] file:String.cc; line number:875 | |
2583 | [5] file:String.cc; line number:853 | |
2584 | [6] file:String.cc; line number:846 | |
2585 | [7] file:String.cc; line number:735 | |
2586 | > 2 4 6 | |
2587 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2588 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2589 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2590 | Multiple breakpoints were set. | |
2591 | Use the "delete" command to delete unwanted breakpoints. | |
18fae2a8 | 2592 | (@value{GDBP}) |
70b88761 | 2593 | @end example |
1d7c3357 | 2594 | @end ifclear |
70b88761 | 2595 | |
1d7c3357 | 2596 | @ifclear BARETARGET |
4eb4cf57 | 2597 | @node Error in Breakpoints |
93928b60 | 2598 | @subsection ``Cannot insert breakpoints'' |
70b88761 | 2599 | |
e251e767 | 2600 | @c FIXME: "cannot insert breakpoints" error, v unclear. |
70b88761 | 2601 | @c Q in pending mail to Gilmore. [email protected], 26mar91 |
e251e767 | 2602 | @c some light may be shed by looking at instances of |
d24e0922 | 2603 | @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise |
c338a2fd | 2604 | @c too. pesch, 20sep91 |
70b88761 RP |
2605 | Under some operating systems, breakpoints cannot be used in a program if |
2606 | any other process is running that program. In this situation, | |
18fae2a8 | 2607 | attempting to run or continue a program with a breakpoint causes @value{GDBN} |
70b88761 RP |
2608 | to stop the other process. |
2609 | ||
2610 | When this happens, you have three ways to proceed: | |
2611 | ||
2612 | @enumerate | |
2613 | @item | |
2614 | Remove or disable the breakpoints, then continue. | |
2615 | ||
2616 | @item | |
18fae2a8 RP |
2617 | Suspend @value{GDBN}, and copy the file containing your program to a new name. |
2618 | Resume @value{GDBN} and use the @code{exec-file} command to specify that @value{GDBN} | |
29a2b744 | 2619 | should run your program under that name. Then start your program again. |
70b88761 RP |
2620 | |
2621 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2622 | @c explains the first FIXME: in this section... | |
2623 | ||
2624 | @item | |
29a2b744 | 2625 | Relink your program so that the text segment is nonsharable, using the |
70b88761 RP |
2626 | linker option @samp{-N}. The operating system limitation may not apply |
2627 | to nonsharable executables. | |
2628 | @end enumerate | |
1d7c3357 | 2629 | @end ifclear |
70b88761 | 2630 | |
4eb4cf57 | 2631 | @node Continuing and Stepping |
93928b60 | 2632 | @section Continuing and stepping |
70b88761 RP |
2633 | |
2634 | @cindex stepping | |
7463aadd RP |
2635 | @cindex continuing |
2636 | @cindex resuming execution | |
3d3ab540 | 2637 | @dfn{Continuing} means resuming program execution until your program |
cedaf8bc RP |
2638 | completes normally. In contrast, @dfn{stepping} means executing just |
2639 | one more ``step'' of your program, where ``step'' may mean either one | |
2640 | line of source code, or one machine instruction (depending on what | |
2641 | particular command you use). Either when continuing | |
4eb4cf57 | 2642 | or when stepping, your program may stop even sooner, due to |
18fae2a8 | 2643 | @ifset BARETARGET |
4eb4cf57 | 2644 | a breakpoint. |
18fae2a8 RP |
2645 | @end ifset |
2646 | @ifclear BARETARGET | |
4eb4cf57 RP |
2647 | a breakpoint or to a signal. (If due to a signal, you may want to use |
2648 | @code{handle}, or use @samp{signal 0} to resume execution. | |
2649 | @xref{Signals, ,Signals}.) | |
18fae2a8 | 2650 | @end ifclear |
3d3ab540 RP |
2651 | |
2652 | @table @code | |
2653 | @item continue @r{[}@var{ignore-count}@r{]} | |
2654 | @kindex continue | |
29a2b744 | 2655 | Resume program execution, at the address where your program last stopped; |
3d3ab540 RP |
2656 | any breakpoints set at that address are bypassed. The optional argument |
2657 | @var{ignore-count} allows you to specify a further number of times to | |
2658 | ignore a breakpoint at this location; its effect is like that of | |
93928b60 | 2659 | @code{ignore} (@pxref{Conditions, ,Break conditions}). |
3d3ab540 RP |
2660 | |
2661 | To resume execution at a different place, you can use @code{return} | |
93928b60 | 2662 | (@pxref{Returning, ,Returning from a function}) to go back to the |
29a2b744 | 2663 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a |
93928b60 | 2664 | different address}) to go to an arbitrary location in your program. |
3d3ab540 | 2665 | @end table |
7463aadd RP |
2666 | |
2667 | A typical technique for using stepping is to set a breakpoint | |
93928b60 RP |
2668 | @ifclear CONLY |
2669 | (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}) | |
2670 | @end ifclear | |
2671 | @ifset CONLY | |
2672 | (@pxref{Breakpoints, ,Breakpoints and watchpoints}) | |
2673 | @end ifset | |
2674 | at the | |
29a2b744 RP |
2675 | beginning of the function or the section of your program where a |
2676 | problem is believed to lie, run your program until it stops at that | |
2677 | breakpoint, and then step through the suspect area, examining the | |
2678 | variables that are interesting, until you see the problem happen. | |
70b88761 RP |
2679 | |
2680 | @table @code | |
2681 | @item step | |
2682 | @kindex step | |
2683 | @kindex s | |
29a2b744 | 2684 | Continue running your program until control reaches a different source |
18fae2a8 | 2685 | line, then stop it and return control to @value{GDBN}. This command is |
70b88761 RP |
2686 | abbreviated @code{s}. |
2687 | ||
3d3ab540 RP |
2688 | @quotation |
2689 | @emph{Warning:} If you use the @code{step} command while control is | |
2690 | within a function that was compiled without debugging information, | |
2691 | execution will proceed until control reaches another function. | |
2692 | @end quotation | |
70b88761 RP |
2693 | |
2694 | @item step @var{count} | |
2695 | Continue running as in @code{step}, but do so @var{count} times. If a | |
1d7c3357 RP |
2696 | breakpoint is reached, |
2697 | @ifclear BARETARGET | |
2698 | or a signal not related to stepping occurs before @var{count} steps, | |
2699 | @end ifclear | |
2700 | stepping stops right away. | |
70b88761 | 2701 | |
7463aadd | 2702 | @item next @r{[}@var{count}@r{]} |
70b88761 RP |
2703 | @kindex next |
2704 | @kindex n | |
7463aadd RP |
2705 | Continue to the next source line in the current (innermost) stack frame. |
2706 | Similar to @code{step}, but any function calls appearing within the line | |
2707 | of code are executed without stopping. Execution stops when control | |
2708 | reaches a different line of code at the stack level which was executing | |
2709 | when the @code{next} command was given. This command is abbreviated | |
2710 | @code{n}. | |
70b88761 | 2711 | |
7463aadd | 2712 | An argument @var{count} is a repeat count, as for @code{step}. |
70b88761 RP |
2713 | |
2714 | @code{next} within a function that lacks debugging information acts like | |
2715 | @code{step}, but any function calls appearing within the code of the | |
2716 | function are executed without stopping. | |
2717 | ||
2718 | @item finish | |
2719 | @kindex finish | |
7463aadd RP |
2720 | Continue running until just after function in the selected stack frame |
2721 | returns. Print the returned value (if any). | |
70b88761 | 2722 | |
29a2b744 | 2723 | Contrast this with the @code{return} command (@pxref{Returning, |
93928b60 | 2724 | ,Returning from a function}). |
70b88761 RP |
2725 | |
2726 | @item until | |
2727 | @kindex until | |
2728 | @item u | |
2729 | @kindex u | |
2730 | Continue running until a source line past the current line, in the | |
2731 | current stack frame, is reached. This command is used to avoid single | |
2732 | stepping through a loop more than once. It is like the @code{next} | |
2733 | command, except that when @code{until} encounters a jump, it | |
2734 | automatically continues execution until the program counter is greater | |
2735 | than the address of the jump. | |
2736 | ||
2737 | This means that when you reach the end of a loop after single stepping | |
29a2b744 | 2738 | though it, @code{until} will cause your program to continue execution |
70b88761 RP |
2739 | until the loop is exited. In contrast, a @code{next} command at the end |
2740 | of a loop will simply step back to the beginning of the loop, which | |
2741 | would force you to step through the next iteration. | |
2742 | ||
29a2b744 | 2743 | @code{until} always stops your program if it attempts to exit the current |
70b88761 RP |
2744 | stack frame. |
2745 | ||
2746 | @code{until} may produce somewhat counterintuitive results if the order | |
7463aadd | 2747 | of machine code does not match the order of the source lines. For |
70b88761 RP |
2748 | example, in the following excerpt from a debugging session, the @code{f} |
2749 | (@code{frame}) command shows that execution is stopped at line | |
2750 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2751 | ||
2752 | @example | |
18fae2a8 | 2753 | (@value{GDBP}) f |
70b88761 | 2754 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 |
b80282d5 | 2755 | 206 expand_input(); |
18fae2a8 | 2756 | (@value{GDBP}) until |
b80282d5 | 2757 | 195 for ( ; argc > 0; NEXTARG) @{ |
70b88761 RP |
2758 | @end example |
2759 | ||
7463aadd RP |
2760 | This happened because, for execution efficiency, the compiler had |
2761 | generated code for the loop closure test at the end, rather than the | |
2762 | start, of the loop---even though the test in a C @code{for}-loop is | |
2763 | written before the body of the loop. The @code{until} command appeared | |
2764 | to step back to the beginning of the loop when it advanced to this | |
2765 | expression; however, it has not really gone to an earlier | |
2766 | statement---not in terms of the actual machine code. | |
70b88761 RP |
2767 | |
2768 | @code{until} with no argument works by means of single | |
2769 | instruction stepping, and hence is slower than @code{until} with an | |
2770 | argument. | |
2771 | ||
2772 | @item until @var{location} | |
2773 | @item u @var{location} | |
29a2b744 RP |
2774 | Continue running your program until either the specified location is |
2775 | reached, or the current stack frame returns. @var{location} is any of | |
2776 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
93928b60 | 2777 | ,Setting breakpoints}). This form of the command uses breakpoints, |
1041a570 | 2778 | and hence is quicker than @code{until} without an argument. |
70b88761 RP |
2779 | |
2780 | @item stepi | |
2781 | @itemx si | |
2782 | @kindex stepi | |
2783 | @kindex si | |
2784 | Execute one machine instruction, then stop and return to the debugger. | |
2785 | ||
2786 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2787 | instructions. This will cause the next instruction to be executed to | |
29a2b744 | 2788 | be displayed automatically at each stop. @xref{Auto Display, |
93928b60 | 2789 | ,Automatic display}. |
70b88761 RP |
2790 | |
2791 | An argument is a repeat count, as in @code{step}. | |
2792 | ||
ed447b95 | 2793 | @need 750 |
70b88761 RP |
2794 | @item nexti |
2795 | @itemx ni | |
2796 | @kindex nexti | |
2797 | @kindex ni | |
2798 | Execute one machine instruction, but if it is a function call, | |
2799 | proceed until the function returns. | |
2800 | ||
2801 | An argument is a repeat count, as in @code{next}. | |
70b88761 RP |
2802 | @end table |
2803 | ||
18fae2a8 | 2804 | @ifset POSIX |
4eb4cf57 | 2805 | @node Signals |
70b88761 RP |
2806 | @section Signals |
2807 | @cindex signals | |
2808 | ||
2809 | A signal is an asynchronous event that can happen in a program. The | |
2810 | operating system defines the possible kinds of signals, and gives each | |
2811 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2812 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2813 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2814 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
29a2b744 | 2815 | the alarm clock timer goes off (which happens only if your program has |
70b88761 RP |
2816 | requested an alarm). |
2817 | ||
2818 | @cindex fatal signals | |
2819 | Some signals, including @code{SIGALRM}, are a normal part of the | |
29a2b744 RP |
2820 | functioning of your program. Others, such as @code{SIGSEGV}, indicate |
2821 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
70b88761 | 2822 | program has not specified in advance some other way to handle the signal. |
29a2b744 | 2823 | @code{SIGINT} does not indicate an error in your program, but it is normally |
70b88761 RP |
2824 | fatal so it can carry out the purpose of the interrupt: to kill the program. |
2825 | ||
18fae2a8 RP |
2826 | @value{GDBN} has the ability to detect any occurrence of a signal in your |
2827 | program. You can tell @value{GDBN} in advance what to do for each kind of | |
29a2b744 | 2828 | signal. |
70b88761 RP |
2829 | |
2830 | @cindex handling signals | |
18fae2a8 | 2831 | Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM} |
29a2b744 RP |
2832 | (so as not to interfere with their role in the functioning of your program) |
2833 | but to stop your program immediately whenever an error signal happens. | |
70b88761 RP |
2834 | You can change these settings with the @code{handle} command. |
2835 | ||
2836 | @table @code | |
2837 | @item info signals | |
2838 | @kindex info signals | |
18fae2a8 | 2839 | Print a table of all the kinds of signals and how @value{GDBN} has been told to |
70b88761 RP |
2840 | handle each one. You can use this to see the signal numbers of all |
2841 | the defined types of signals. | |
2842 | ||
2843 | @item handle @var{signal} @var{keywords}@dots{} | |
2844 | @kindex handle | |
18fae2a8 | 2845 | Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can be the |
70b88761 RP |
2846 | number of a signal or its name (with or without the @samp{SIG} at the |
2847 | beginning). The @var{keywords} say what change to make. | |
2848 | @end table | |
2849 | ||
2850 | @c @group | |
2851 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2852 | Their full names are: | |
2853 | ||
2854 | @table @code | |
2855 | @item nostop | |
18fae2a8 | 2856 | @value{GDBN} should not stop your program when this signal happens. It may |
70b88761 RP |
2857 | still print a message telling you that the signal has come in. |
2858 | ||
2859 | @item stop | |
18fae2a8 | 2860 | @value{GDBN} should stop your program when this signal happens. This implies |
70b88761 RP |
2861 | the @code{print} keyword as well. |
2862 | ||
2863 | @item print | |
18fae2a8 | 2864 | @value{GDBN} should print a message when this signal happens. |
70b88761 RP |
2865 | |
2866 | @item noprint | |
18fae2a8 | 2867 | @value{GDBN} should not mention the occurrence of the signal at all. This |
70b88761 RP |
2868 | implies the @code{nostop} keyword as well. |
2869 | ||
2870 | @item pass | |
18fae2a8 | 2871 | @value{GDBN} should allow your program to see this signal; your program will be |
70b88761 RP |
2872 | able to handle the signal, or may be terminated if the signal is fatal |
2873 | and not handled. | |
2874 | ||
2875 | @item nopass | |
18fae2a8 | 2876 | @value{GDBN} should not allow your program to see this signal. |
70b88761 RP |
2877 | @end table |
2878 | @c @end group | |
2879 | ||
ed447b95 RP |
2880 | When a signal stops your program, the signal is not visible until you |
2881 | continue. Your program will see the signal then, if @code{pass} is in | |
2882 | effect for the signal in question @emph{at that time}. In other words, | |
2883 | after @value{GDBN} reports a signal, you can use the @code{handle} | |
2884 | command with @code{pass} or @code{nopass} to control whether that | |
2885 | signal will be seen by your program when you later continue it. | |
70b88761 | 2886 | |
29a2b744 | 2887 | You can also use the @code{signal} command to prevent your program from |
70b88761 | 2888 | seeing a signal, or cause it to see a signal it normally would not see, |
29a2b744 | 2889 | or to give it any signal at any time. For example, if your program stopped |
7463aadd RP |
2890 | due to some sort of memory reference error, you might store correct |
2891 | values into the erroneous variables and continue, hoping to see more | |
29a2b744 RP |
2892 | execution; but your program would probably terminate immediately as |
2893 | a result of the fatal signal once it saw the signal. To prevent this, | |
2894 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
93928b60 | 2895 | program a signal}. |
18fae2a8 | 2896 | @end ifset |
70b88761 | 2897 | |
4eb4cf57 | 2898 | @node Stack |
70b88761 RP |
2899 | @chapter Examining the Stack |
2900 | ||
2901 | When your program has stopped, the first thing you need to know is where it | |
2902 | stopped and how it got there. | |
2903 | ||
2904 | @cindex call stack | |
2905 | Each time your program performs a function call, the information about | |
29a2b744 | 2906 | where in your program the call was made from is saved in a block of data |
70b88761 RP |
2907 | called a @dfn{stack frame}. The frame also contains the arguments of the |
2908 | call and the local variables of the function that was called. All the | |
2909 | stack frames are allocated in a region of memory called the @dfn{call | |
2910 | stack}. | |
2911 | ||
93928b60 RP |
2912 | When your program stops, the @value{GDBN} commands for examining the |
2913 | stack allow you to see all of this information. | |
70b88761 RP |
2914 | |
2915 | @cindex selected frame | |
93928b60 RP |
2916 | One of the stack frames is @dfn{selected} by @value{GDBN} and many |
2917 | @value{GDBN} commands refer implicitly to the selected frame. In | |
2918 | particular, whenever you ask @value{GDBN} for the value of a variable in | |
2919 | your program, the value is found in the selected frame. There are | |
2920 | special @value{GDBN} commands to select whichever frame you are | |
2921 | interested in. | |
70b88761 | 2922 | |
93928b60 RP |
2923 | When your program stops, @value{GDBN} automatically selects the |
2924 | currently executing frame and describes it briefly as the @code{frame} | |
2925 | command does (@pxref{Frame Info, ,Information about a frame}). | |
70b88761 RP |
2926 | |
2927 | @menu | |
ed447b95 | 2928 | * Frames:: Stack frames |
b80282d5 | 2929 | * Backtrace:: Backtraces |
ed447b95 RP |
2930 | * Selection:: Selecting a frame |
2931 | * Frame Info:: Information on a frame | |
70b88761 RP |
2932 | @end menu |
2933 | ||
4eb4cf57 | 2934 | @node Frames |
93928b60 | 2935 | @section Stack frames |
70b88761 RP |
2936 | |
2937 | @cindex frame | |
2938 | @cindex stack frame | |
2939 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2940 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2941 | with one call to one function. The frame contains the arguments given | |
2942 | to the function, the function's local variables, and the address at | |
2943 | which the function is executing. | |
2944 | ||
2945 | @cindex initial frame | |
2946 | @cindex outermost frame | |
2947 | @cindex innermost frame | |
2948 | When your program is started, the stack has only one frame, that of the | |
2949 | function @code{main}. This is called the @dfn{initial} frame or the | |
2950 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2951 | made. Each time a function returns, the frame for that function invocation | |
2952 | is eliminated. If a function is recursive, there can be many frames for | |
2953 | the same function. The frame for the function in which execution is | |
2954 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2955 | recently created of all the stack frames that still exist. | |
2956 | ||
2957 | @cindex frame pointer | |
2958 | Inside your program, stack frames are identified by their addresses. A | |
2959 | stack frame consists of many bytes, each of which has its own address; each | |
2960 | kind of computer has a convention for choosing one of those bytes whose | |
2961 | address serves as the address of the frame. Usually this address is kept | |
2962 | in a register called the @dfn{frame pointer register} while execution is | |
2963 | going on in that frame. | |
2964 | ||
2965 | @cindex frame number | |
18fae2a8 | 2966 | @value{GDBN} assigns numbers to all existing stack frames, starting with |
70b88761 RP |
2967 | zero for the innermost frame, one for the frame that called it, |
2968 | and so on upward. These numbers do not really exist in your program; | |
18fae2a8 RP |
2969 | they are assigned by @value{GDBN} to give you a way of designating stack |
2970 | frames in @value{GDBN} commands. | |
70b88761 RP |
2971 | |
2972 | @cindex frameless execution | |
8c69096b | 2973 | Some compilers provide a way to compile functions so that they operate |
18fae2a8 | 2974 | without stack frames. (For example, the @code{@value{GCC}} option |
70b88761 RP |
2975 | @samp{-fomit-frame-pointer} will generate functions without a frame.) |
2976 | This is occasionally done with heavily used library functions to save | |
8c69096b RP |
2977 | the frame setup time. @value{GDBN} has limited facilities for dealing |
2978 | with these function invocations. If the innermost function invocation | |
2979 | has no stack frame, @value{GDBN} will nevertheless regard it as though | |
2980 | it had a separate frame, which is numbered zero as usual, allowing | |
2981 | correct tracing of the function call chain. However, @value{GDBN} has | |
2982 | no provision for frameless functions elsewhere in the stack. | |
70b88761 | 2983 | |
4eb4cf57 | 2984 | @node Backtrace |
70b88761 RP |
2985 | @section Backtraces |
2986 | ||
29a2b744 | 2987 | A backtrace is a summary of how your program got where it is. It shows one |
70b88761 RP |
2988 | line per frame, for many frames, starting with the currently executing |
2989 | frame (frame zero), followed by its caller (frame one), and on up the | |
2990 | stack. | |
2991 | ||
2992 | @table @code | |
2993 | @item backtrace | |
2994 | @itemx bt | |
2995 | @kindex backtrace | |
2996 | @kindex bt | |
2997 | Print a backtrace of the entire stack: one line per frame for all | |
2998 | frames in the stack. | |
2999 | ||
3000 | You can stop the backtrace at any time by typing the system interrupt | |
3001 | character, normally @kbd{C-c}. | |
3002 | ||
3003 | @item backtrace @var{n} | |
3004 | @itemx bt @var{n} | |
3005 | Similar, but print only the innermost @var{n} frames. | |
3006 | ||
3007 | @item backtrace -@var{n} | |
3008 | @itemx bt -@var{n} | |
3009 | Similar, but print only the outermost @var{n} frames. | |
3010 | @end table | |
3011 | ||
3012 | @kindex where | |
3013 | @kindex info stack | |
3014 | @kindex info s | |
3015 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
3016 | are additional aliases for @code{backtrace}. | |
3017 | ||
3018 | Each line in the backtrace shows the frame number and the function name. | |
3019 | The program counter value is also shown---unless you use @code{set | |
3020 | print address off}. The backtrace also shows the source file name and | |
3021 | line number, as well as the arguments to the function. The program | |
3022 | counter value is omitted if it is at the beginning of the code for that | |
3023 | line number. | |
3024 | ||
3025 | Here is an example of a backtrace. It was made with the command | |
3026 | @samp{bt 3}, so it shows the innermost three frames. | |
3027 | ||
3028 | @smallexample | |
3029 | @group | |
203eea5d RP |
3030 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) |
3031 | at builtin.c:993 | |
70b88761 RP |
3032 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 |
3033 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
3034 | at macro.c:71 | |
3035 | (More stack frames follow...) | |
3036 | @end group | |
3037 | @end smallexample | |
3038 | ||
3039 | @noindent | |
29a2b744 RP |
3040 | The display for frame zero does not begin with a program counter |
3041 | value, indicating that your program has stopped at the beginning of the | |
70b88761 RP |
3042 | code for line @code{993} of @code{builtin.c}. |
3043 | ||
4eb4cf57 | 3044 | @node Selection |
93928b60 | 3045 | @section Selecting a frame |
70b88761 | 3046 | |
29a2b744 | 3047 | Most commands for examining the stack and other data in your program work on |
70b88761 RP |
3048 | whichever stack frame is selected at the moment. Here are the commands for |
3049 | selecting a stack frame; all of them finish by printing a brief description | |
3050 | of the stack frame just selected. | |
3051 | ||
3052 | @table @code | |
3053 | @item frame @var{n} | |
3054 | @itemx f @var{n} | |
3055 | @kindex frame | |
3056 | @kindex f | |
3057 | Select frame number @var{n}. Recall that frame zero is the innermost | |
3058 | (currently executing) frame, frame one is the frame that called the | |
93918348 RP |
3059 | innermost one, and so on. The highest-numbered frame is the one for |
3060 | @code{main}. | |
70b88761 RP |
3061 | |
3062 | @item frame @var{addr} | |
3063 | @itemx f @var{addr} | |
3064 | Select the frame at address @var{addr}. This is useful mainly if the | |
3065 | chaining of stack frames has been damaged by a bug, making it | |
18fae2a8 | 3066 | impossible for @value{GDBN} to assign numbers properly to all frames. In |
29a2b744 | 3067 | addition, this can be useful when your program has multiple stacks and |
70b88761 RP |
3068 | switches between them. |
3069 | ||
18fae2a8 | 3070 | @ifset SPARC |
70b88761 | 3071 | On the SPARC architecture, @code{frame} needs two addresses to |
e251e767 | 3072 | select an arbitrary frame: a frame pointer and a stack pointer. |
70b88761 RP |
3073 | @c note to future updaters: this is conditioned on a flag |
3074 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
3075 | @c by SPARC, hence the specific attribution. Generalize or list all | |
3076 | @c possibilities if more supported machines start doing this. | |
18fae2a8 | 3077 | @end ifset |
70b88761 RP |
3078 | |
3079 | @item up @var{n} | |
3080 | @kindex up | |
3081 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
3082 | advances toward the outermost frame, to higher frame numbers, to frames | |
3083 | that have existed longer. @var{n} defaults to one. | |
3084 | ||
3085 | @item down @var{n} | |
3086 | @kindex down | |
3087 | @kindex do | |
3088 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
3089 | advances toward the innermost frame, to lower frame numbers, to frames | |
3090 | that were created more recently. @var{n} defaults to one. You may | |
3091 | abbreviate @code{down} as @code{do}. | |
3092 | @end table | |
3093 | ||
3094 | All of these commands end by printing two lines of output describing the | |
3095 | frame. The first line shows the frame number, the function name, the | |
3096 | arguments, and the source file and line number of execution in that | |
ed447b95 | 3097 | frame. The second line shows the text of that source line. |
70b88761 | 3098 | |
ed447b95 | 3099 | For example: |
70b88761 | 3100 | @smallexample |
29a2b744 | 3101 | @group |
18fae2a8 | 3102 | (@value{GDBP}) up |
203eea5d RP |
3103 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) |
3104 | at env.c:10 | |
70b88761 | 3105 | 10 read_input_file (argv[i]); |
29a2b744 | 3106 | @end group |
70b88761 RP |
3107 | @end smallexample |
3108 | ||
29a2b744 RP |
3109 | After such a printout, the @code{list} command with no arguments will |
3110 | print ten lines centered on the point of execution in the frame. | |
93928b60 | 3111 | @xref{List, ,Printing source lines}. |
70b88761 RP |
3112 | |
3113 | @table @code | |
3114 | @item up-silently @var{n} | |
3115 | @itemx down-silently @var{n} | |
3116 | @kindex down-silently | |
3117 | @kindex up-silently | |
3118 | These two commands are variants of @code{up} and @code{down}, | |
3119 | respectively; they differ in that they do their work silently, without | |
3120 | causing display of the new frame. They are intended primarily for use | |
18fae2a8 | 3121 | in @value{GDBN} command scripts, where the output might be unnecessary and |
e251e767 | 3122 | distracting. |
70b88761 RP |
3123 | @end table |
3124 | ||
4eb4cf57 | 3125 | @node Frame Info |
93928b60 | 3126 | @section Information about a frame |
70b88761 RP |
3127 | |
3128 | There are several other commands to print information about the selected | |
3129 | stack frame. | |
3130 | ||
3131 | @table @code | |
3132 | @item frame | |
3133 | @itemx f | |
29a2b744 RP |
3134 | When used without any argument, this command does not change which |
3135 | frame is selected, but prints a brief description of the currently | |
70b88761 | 3136 | selected stack frame. It can be abbreviated @code{f}. With an |
ed447b95 | 3137 | argument, this command is used to select a stack frame. |
93928b60 | 3138 | @xref{Selection, ,Selecting a frame}. |
70b88761 RP |
3139 | |
3140 | @item info frame | |
70b88761 | 3141 | @itemx info f |
29a2b744 | 3142 | @kindex info frame |
70b88761 RP |
3143 | @kindex info f |
3144 | This command prints a verbose description of the selected stack frame, | |
3145 | including the address of the frame, the addresses of the next frame down | |
c2bbbb22 RP |
3146 | (called by this frame) and the next frame up (caller of this frame), the |
3147 | language that the source code corresponding to this frame was written in, | |
70b88761 RP |
3148 | the address of the frame's arguments, the program counter saved in it |
3149 | (the address of execution in the caller frame), and which registers | |
3150 | were saved in the frame. The verbose description is useful when | |
3151 | something has gone wrong that has made the stack format fail to fit | |
3152 | the usual conventions. | |
3153 | ||
3154 | @item info frame @var{addr} | |
3155 | @itemx info f @var{addr} | |
3156 | Print a verbose description of the frame at address @var{addr}, | |
3157 | without selecting that frame. The selected frame remains unchanged by | |
3158 | this command. | |
3159 | ||
3160 | @item info args | |
3161 | @kindex info args | |
3162 | Print the arguments of the selected frame, each on a separate line. | |
3163 | ||
3164 | @item info locals | |
3165 | @kindex info locals | |
3166 | Print the local variables of the selected frame, each on a separate | |
ed447b95 RP |
3167 | line. These are all variables (declared either static or automatic) |
3168 | accessible at the point of execution of the selected frame. | |
70b88761 | 3169 | |
1d7c3357 | 3170 | @ifclear CONLY |
70b88761 RP |
3171 | @item info catch |
3172 | @kindex info catch | |
3173 | @cindex catch exceptions | |
3174 | @cindex exception handlers | |
3175 | Print a list of all the exception handlers that are active in the | |
3176 | current stack frame at the current point of execution. To see other | |
3177 | exception handlers, visit the associated frame (using the @code{up}, | |
3178 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
93928b60 | 3179 | @xref{Exception Handling, ,Breakpoints and exceptions}. |
1d7c3357 | 3180 | @end ifclear |
70b88761 RP |
3181 | @end table |
3182 | ||
4eb4cf57 | 3183 | @node Source |
70b88761 RP |
3184 | @chapter Examining Source Files |
3185 | ||
18fae2a8 | 3186 | @value{GDBN} can print parts of your program's source, since the debugging |
ed447b95 | 3187 | information recorded in the program tells @value{GDBN} what source files were |
18fae2a8 | 3188 | used to build it. When your program stops, @value{GDBN} spontaneously prints |
1041a570 | 3189 | the line where it stopped. Likewise, when you select a stack frame |
93928b60 | 3190 | (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where |
1041a570 RP |
3191 | execution in that frame has stopped. You can print other portions of |
3192 | source files by explicit command. | |
70b88761 | 3193 | |
18fae2a8 RP |
3194 | @ifclear DOSHOST |
3195 | If you use @value{GDBN} through its GNU Emacs interface, you may prefer to use | |
3196 | Emacs facilities to view source; @pxref{Emacs, ,Using @value{GDBN} under GNU | |
1041a570 | 3197 | Emacs}. |
18fae2a8 | 3198 | @end ifclear |
70b88761 RP |
3199 | |
3200 | @menu | |
ed447b95 | 3201 | * List:: Printing source lines |
18fae2a8 | 3202 | @ifclear DOSHOST |
ed447b95 | 3203 | * Search:: Searching source files |
18fae2a8 | 3204 | @end ifclear |
b0157555 | 3205 | |
ed447b95 RP |
3206 | * Source Path:: Specifying source directories |
3207 | * Machine Code:: Source and machine code | |
70b88761 RP |
3208 | @end menu |
3209 | ||
4eb4cf57 | 3210 | @node List |
93928b60 | 3211 | @section Printing source lines |
70b88761 RP |
3212 | |
3213 | @kindex list | |
3214 | @kindex l | |
3215 | To print lines from a source file, use the @code{list} command | |
3216 | (abbreviated @code{l}). There are several ways to specify what part | |
3217 | of the file you want to print. | |
3218 | ||
3219 | Here are the forms of the @code{list} command most commonly used: | |
3220 | ||
3221 | @table @code | |
3222 | @item list @var{linenum} | |
c338a2fd | 3223 | Print lines centered around line number @var{linenum} in the |
70b88761 RP |
3224 | current source file. |
3225 | ||
3226 | @item list @var{function} | |
c338a2fd | 3227 | Print lines centered around the beginning of function |
70b88761 RP |
3228 | @var{function}. |
3229 | ||
3230 | @item list | |
c338a2fd RP |
3231 | Print more lines. If the last lines printed were printed with a |
3232 | @code{list} command, this prints lines following the last lines | |
70b88761 | 3233 | printed; however, if the last line printed was a solitary line printed |
29a2b744 | 3234 | as part of displaying a stack frame (@pxref{Stack, ,Examining the |
1041a570 | 3235 | Stack}), this prints lines centered around that line. |
70b88761 RP |
3236 | |
3237 | @item list - | |
c338a2fd RP |
3238 | Print lines just before the lines last printed. |
3239 | @end table | |
3240 | ||
18fae2a8 | 3241 | By default, @value{GDBN} prints ten source lines with any of these forms of |
c338a2fd RP |
3242 | the @code{list} command. You can change this using @code{set listsize}: |
3243 | ||
3244 | @table @code | |
3245 | @item set listsize @var{count} | |
3246 | @kindex set listsize | |
3247 | Make the @code{list} command display @var{count} source lines (unless | |
3248 | the @code{list} argument explicitly specifies some other number). | |
3249 | ||
3250 | @item show listsize | |
3251 | @kindex show listsize | |
3252 | Display the number of lines that @code{list} will currently display by | |
e251e767 | 3253 | default. |
70b88761 RP |
3254 | @end table |
3255 | ||
3256 | Repeating a @code{list} command with @key{RET} discards the argument, | |
3257 | so it is equivalent to typing just @code{list}. This is more useful | |
3258 | than listing the same lines again. An exception is made for an | |
3259 | argument of @samp{-}; that argument is preserved in repetition so that | |
3260 | each repetition moves up in the source file. | |
3261 | ||
3262 | @cindex linespec | |
3263 | In general, the @code{list} command expects you to supply zero, one or two | |
3264 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
3265 | of writing them but the effect is always to specify some source line. | |
3266 | Here is a complete description of the possible arguments for @code{list}: | |
3267 | ||
3268 | @table @code | |
3269 | @item list @var{linespec} | |
c338a2fd | 3270 | Print lines centered around the line specified by @var{linespec}. |
70b88761 RP |
3271 | |
3272 | @item list @var{first},@var{last} | |
3273 | Print lines from @var{first} to @var{last}. Both arguments are | |
3274 | linespecs. | |
3275 | ||
3276 | @item list ,@var{last} | |
c338a2fd | 3277 | Print lines ending with @var{last}. |
70b88761 RP |
3278 | |
3279 | @item list @var{first}, | |
c338a2fd | 3280 | Print lines starting with @var{first}. |
70b88761 RP |
3281 | |
3282 | @item list + | |
c338a2fd | 3283 | Print lines just after the lines last printed. |
70b88761 RP |
3284 | |
3285 | @item list - | |
c338a2fd | 3286 | Print lines just before the lines last printed. |
70b88761 RP |
3287 | |
3288 | @item list | |
3289 | As described in the preceding table. | |
3290 | @end table | |
3291 | ||
3292 | Here are the ways of specifying a single source line---all the | |
3293 | kinds of linespec. | |
3294 | ||
3295 | @table @code | |
3296 | @item @var{number} | |
3297 | Specifies line @var{number} of the current source file. | |
3298 | When a @code{list} command has two linespecs, this refers to | |
3299 | the same source file as the first linespec. | |
3300 | ||
3301 | @item +@var{offset} | |
3302 | Specifies the line @var{offset} lines after the last line printed. | |
3303 | When used as the second linespec in a @code{list} command that has | |
3304 | two, this specifies the line @var{offset} lines down from the | |
3305 | first linespec. | |
3306 | ||
3307 | @item -@var{offset} | |
3308 | Specifies the line @var{offset} lines before the last line printed. | |
3309 | ||
3310 | @item @var{filename}:@var{number} | |
3311 | Specifies line @var{number} in the source file @var{filename}. | |
3312 | ||
3313 | @item @var{function} | |
3314 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
3315 | Specifies the line of the open-brace that begins the body of the | |
3316 | function @var{function}. | |
3317 | ||
3318 | @item @var{filename}:@var{function} | |
3319 | Specifies the line of the open-brace that begins the body of the | |
3320 | function @var{function} in the file @var{filename}. You only need the | |
3321 | file name with a function name to avoid ambiguity when there are | |
3322 | identically named functions in different source files. | |
3323 | ||
3324 | @item *@var{address} | |
3325 | Specifies the line containing the program address @var{address}. | |
3326 | @var{address} may be any expression. | |
3327 | @end table | |
3328 | ||
18fae2a8 | 3329 | @ifclear DOSHOST |
4eb4cf57 | 3330 | @node Search |
93928b60 | 3331 | @section Searching source files |
70b88761 RP |
3332 | @cindex searching |
3333 | @kindex reverse-search | |
3334 | ||
3335 | There are two commands for searching through the current source file for a | |
3336 | regular expression. | |
3337 | ||
3338 | @table @code | |
3339 | @item forward-search @var{regexp} | |
3340 | @itemx search @var{regexp} | |
3341 | @kindex search | |
3342 | @kindex forward-search | |
1041a570 RP |
3343 | The command @samp{forward-search @var{regexp}} checks each line, |
3344 | starting with the one following the last line listed, for a match for | |
3345 | @var{regexp}. It lists the line that is found. You can use | |
3346 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3347 | @code{fo}. | |
70b88761 RP |
3348 | |
3349 | @item reverse-search @var{regexp} | |
3350 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3351 | with the one before the last line listed and going backward, for a match | |
3352 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3353 | this command as @code{rev}. | |
3354 | @end table | |
18fae2a8 | 3355 | @end ifclear |
70b88761 | 3356 | |
4eb4cf57 | 3357 | @node Source Path |
93928b60 | 3358 | @section Specifying source directories |
70b88761 RP |
3359 | |
3360 | @cindex source path | |
3361 | @cindex directories for source files | |
3362 | Executable programs sometimes do not record the directories of the source | |
3363 | files from which they were compiled, just the names. Even when they do, | |
3364 | the directories could be moved between the compilation and your debugging | |
18fae2a8 RP |
3365 | session. @value{GDBN} has a list of directories to search for source files; |
3366 | this is called the @dfn{source path}. Each time @value{GDBN} wants a source file, | |
70b88761 RP |
3367 | it tries all the directories in the list, in the order they are present |
3368 | in the list, until it finds a file with the desired name. Note that | |
3369 | the executable search path is @emph{not} used for this purpose. Neither is | |
3370 | the current working directory, unless it happens to be in the source | |
3371 | path. | |
3372 | ||
18fae2a8 RP |
3373 | If @value{GDBN} cannot find a source file in the source path, and the object |
3374 | program records a directory, @value{GDBN} tries that directory too. If the | |
70b88761 | 3375 | source path is empty, and there is no record of the compilation |
18fae2a8 | 3376 | directory, @value{GDBN} will, as a last resort, look in the current |
70b88761 RP |
3377 | directory. |
3378 | ||
18fae2a8 | 3379 | Whenever you reset or rearrange the source path, @value{GDBN} will clear out |
70b88761 RP |
3380 | any information it has cached about where source files are found, where |
3381 | each line is in the file, etc. | |
3382 | ||
3383 | @kindex directory | |
18fae2a8 | 3384 | When you start @value{GDBN}, its source path is empty. |
70b88761 RP |
3385 | To add other directories, use the @code{directory} command. |
3386 | ||
3387 | @table @code | |
3388 | @item directory @var{dirname} @dots{} | |
3389 | Add directory @var{dirname} to the front of the source path. Several | |
3390 | directory names may be given to this command, separated by @samp{:} or | |
3391 | whitespace. You may specify a directory that is already in the source | |
e251e767 | 3392 | path; this moves it forward, so it will be searched sooner. |
7463aadd RP |
3393 | |
3394 | You can use the string @samp{$cdir} to refer to the compilation | |
3395 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3396 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
18fae2a8 | 3397 | tracks the current working directory as it changes during your @value{GDBN} |
7463aadd RP |
3398 | session, while the latter is immediately expanded to the current |
3399 | directory at the time you add an entry to the source path. | |
70b88761 RP |
3400 | |
3401 | @item directory | |
3402 | Reset the source path to empty again. This requires confirmation. | |
3403 | ||
3404 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
29a2b744 | 3405 | @c repeating it would be a no-op we do not say that. (thanks to RMS) |
70b88761 RP |
3406 | |
3407 | @item show directories | |
3408 | @kindex show directories | |
3409 | Print the source path: show which directories it contains. | |
3410 | @end table | |
3411 | ||
3412 | If your source path is cluttered with directories that are no longer of | |
18fae2a8 | 3413 | interest, @value{GDBN} may sometimes cause confusion by finding the wrong |
70b88761 RP |
3414 | versions of source. You can correct the situation as follows: |
3415 | ||
3416 | @enumerate | |
3417 | @item | |
3418 | Use @code{directory} with no argument to reset the source path to empty. | |
3419 | ||
3420 | @item | |
3421 | Use @code{directory} with suitable arguments to reinstall the | |
3422 | directories you want in the source path. You can add all the | |
3423 | directories in one command. | |
3424 | @end enumerate | |
3425 | ||
4eb4cf57 | 3426 | @node Machine Code |
93928b60 | 3427 | @section Source and machine code |
1041a570 | 3428 | |
70b88761 | 3429 | You can use the command @code{info line} to map source lines to program |
ed447b95 | 3430 | addresses (and vice versa), and the command @code{disassemble} to display |
70b88761 RP |
3431 | a range of addresses as machine instructions. |
3432 | ||
3433 | @table @code | |
3434 | @item info line @var{linespec} | |
3435 | @kindex info line | |
3436 | Print the starting and ending addresses of the compiled code for | |
1041a570 RP |
3437 | source line @var{linespec}. You can specify source lines in any of |
3438 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
93928b60 | 3439 | source lines}). |
70b88761 RP |
3440 | @end table |
3441 | ||
1041a570 RP |
3442 | For example, we can use @code{info line} to discover the location of |
3443 | the object code for the first line of function | |
3444 | @code{m4_changequote}: | |
3445 | ||
70b88761 | 3446 | @smallexample |
18fae2a8 | 3447 | (@value{GDBP}) info line m4_changecom |
70b88761 RP |
3448 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. |
3449 | @end smallexample | |
3450 | ||
3451 | @noindent | |
3452 | We can also inquire (using @code{*@var{addr}} as the form for | |
3453 | @var{linespec}) what source line covers a particular address: | |
3454 | @smallexample | |
18fae2a8 | 3455 | (@value{GDBP}) info line *0x63ff |
70b88761 RP |
3456 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. |
3457 | @end smallexample | |
3458 | ||
c338a2fd | 3459 | @cindex @code{$_} and @code{info line} |
29a2b744 RP |
3460 | After @code{info line}, the default address for the @code{x} command |
3461 | is changed to the starting address of the line, so that @samp{x/i} is | |
3462 | sufficient to begin examining the machine code (@pxref{Memory, | |
93928b60 | 3463 | ,Examining memory}). Also, this address is saved as the value of the |
29a2b744 | 3464 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience |
93928b60 | 3465 | variables}). |
70b88761 RP |
3466 | |
3467 | @table @code | |
3468 | @kindex disassemble | |
3469 | @item disassemble | |
e94b4a2b RP |
3470 | This specialized command dumps a range of memory as machine |
3471 | instructions. The default memory range is the function surrounding the | |
3472 | program counter of the selected frame. A single argument to this | |
3473 | command is a program counter value; the function surrounding this value | |
3474 | will be dumped. Two arguments specify a range of addresses (first | |
3475 | inclusive, second exclusive) to dump. | |
70b88761 RP |
3476 | @end table |
3477 | ||
a64a6c2b | 3478 | @ifclear H8EXCLUSIVE |
70b88761 | 3479 | We can use @code{disassemble} to inspect the object code |
4eb4cf57 RP |
3480 | range shown in the last @code{info line} example (the example |
3481 | shows SPARC machine instructions): | |
70b88761 | 3482 | |
18fae2a8 | 3483 | |
70b88761 | 3484 | @smallexample |
18fae2a8 | 3485 | (@value{GDBP}) disas 0x63e4 0x6404 |
70b88761 | 3486 | Dump of assembler code from 0x63e4 to 0x6404: |
b80282d5 RP |
3487 | 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360> |
3488 | 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0 | |
3489 | 0x63ec <builtin_init+5348>: ld [%i1+4], %o0 | |
3490 | 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364> | |
3491 | 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0 | |
3492 | 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0 | |
3493 | 0x63fc <builtin_init+5364>: call 0x9288 <path_search> | |
e251e767 | 3494 | 0x6400 <builtin_init+5368>: nop |
70b88761 | 3495 | End of assembler dump. |
70b88761 | 3496 | @end smallexample |
18fae2a8 | 3497 | @end ifclear |
4eb4cf57 | 3498 | |
a64a6c2b | 3499 | @ifset H8EXCLUSIVE |
4eb4cf57 RP |
3500 | For example, here is the beginning of the output for the |
3501 | disassembly of a function @code{fact}: | |
70b88761 | 3502 | |
18fae2a8 | 3503 | |
4eb4cf57 | 3504 | @smallexample |
18fae2a8 | 3505 | (@value{GDBP}) disas fact |
4eb4cf57 RP |
3506 | Dump of assembler code for function fact: |
3507 | to 0x808c: | |
3508 | 0x802c <fact>: 6d f2 mov.w r2,@@-r7 | |
3509 | 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7 | |
3510 | 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7 | |
3511 | 0x8032 <fact+6>: 0d 76 mov.w r7,r6 | |
3512 | 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0 | |
3513 | 0x8038 <fact+12> 19 11 sub.w r1,r1 | |
3514 | . | |
3515 | . | |
3516 | . | |
3517 | @end smallexample | |
18fae2a8 | 3518 | @end ifset |
4eb4cf57 RP |
3519 | |
3520 | @node Data | |
70b88761 RP |
3521 | @chapter Examining Data |
3522 | ||
3523 | @cindex printing data | |
3524 | @cindex examining data | |
3525 | @kindex print | |
3526 | @kindex inspect | |
1041a570 | 3527 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not |
29a2b744 | 3528 | @c document because it is nonstandard... Under Epoch it displays in a |
70b88761 RP |
3529 | @c different window or something like that. |
3530 | The usual way to examine data in your program is with the @code{print} | |
4eb4cf57 | 3531 | command (abbreviated @code{p}), or its synonym @code{inspect}. |
18fae2a8 | 3532 | @ifclear CONLY |
4eb4cf57 | 3533 | It evaluates and prints the value of an expression of the language your |
18fae2a8 | 3534 | program is written in (@pxref{Languages, ,Using @value{GDBN} with Different |
4eb4cf57 | 3535 | Languages}). |
18fae2a8 | 3536 | @end ifclear |
70b88761 | 3537 | |
e0dacfd1 RP |
3538 | @table @code |
3539 | @item print @var{exp} | |
3540 | @itemx print /@var{f} @var{exp} | |
93928b60 RP |
3541 | @var{exp} is an expression (in the source language). By default the |
3542 | value of @var{exp} is printed in a format appropriate to its data type; | |
3543 | you can choose a different format by specifying @samp{/@var{f}}, where | |
3544 | @var{f} is a letter specifying the format; @pxref{Output Formats,,Output | |
3545 | formats}. | |
e0dacfd1 RP |
3546 | |
3547 | @item print | |
3548 | @itemx print /@var{f} | |
18fae2a8 | 3549 | If you omit @var{exp}, @value{GDBN} displays the last value again (from the |
93928b60 | 3550 | @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to |
e0dacfd1 RP |
3551 | conveniently inspect the same value in an alternative format. |
3552 | @end table | |
70b88761 RP |
3553 | |
3554 | A more low-level way of examining data is with the @code{x} command. | |
3555 | It examines data in memory at a specified address and prints it in a | |
93928b60 | 3556 | specified format. @xref{Memory, ,Examining memory}. |
70b88761 | 3557 | |
29a2b744 | 3558 | If you are interested in information about types, or about how the fields |
1d7c3357 RP |
3559 | of a struct |
3560 | @ifclear CONLY | |
3561 | or class | |
18fae2a8 | 3562 | @end ifclear |
1d7c3357 RP |
3563 | are declared, use the @code{ptype @var{exp}} |
3564 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. | |
18fae2a8 | 3565 | |
70b88761 | 3566 | @menu |
b80282d5 | 3567 | * Expressions:: Expressions |
ed447b95 RP |
3568 | * Variables:: Program variables |
3569 | * Arrays:: Artificial arrays | |
eb7faec1 | 3570 | * Output Formats:: Output formats |
ed447b95 RP |
3571 | * Memory:: Examining memory |
3572 | * Auto Display:: Automatic display | |
3573 | * Print Settings:: Print settings | |
3574 | * Value History:: Value history | |
3575 | * Convenience Vars:: Convenience variables | |
b80282d5 | 3576 | * Registers:: Registers |
a64a6c2b | 3577 | @ifclear HAVE-FLOAT |
ed447b95 | 3578 | * Floating Point Hardware:: Floating point hardware |
18fae2a8 | 3579 | @end ifclear |
18fae2a8 | 3580 | @end menu |
70b88761 | 3581 | |
4eb4cf57 | 3582 | @node Expressions |
70b88761 RP |
3583 | @section Expressions |
3584 | ||
3585 | @cindex expressions | |
18fae2a8 | 3586 | @code{print} and many other @value{GDBN} commands accept an expression and |
70b88761 | 3587 | compute its value. Any kind of constant, variable or operator defined |
fe715d06 | 3588 | by the programming language you are using is valid in an expression in |
18fae2a8 | 3589 | @value{GDBN}. This includes conditional expressions, function calls, casts |
70b88761 | 3590 | and string constants. It unfortunately does not include symbols defined |
b80282d5 | 3591 | by preprocessor @code{#define} commands. |
70b88761 | 3592 | |
18fae2a8 | 3593 | @ifclear CONLY |
c2bbbb22 | 3594 | Because C is so widespread, most of the expressions shown in examples in |
18fae2a8 | 3595 | this manual are in C. @xref{Languages, , Using @value{GDBN} with Different |
c2bbbb22 | 3596 | Languages}, for information on how to use expressions in other |
e251e767 | 3597 | languages. |
c2bbbb22 | 3598 | |
18fae2a8 | 3599 | In this section, we discuss operators that you can use in @value{GDBN} |
e251e767 | 3600 | expressions regardless of your programming language. |
c2bbbb22 | 3601 | |
70b88761 RP |
3602 | Casts are supported in all languages, not just in C, because it is so |
3603 | useful to cast a number into a pointer so as to examine a structure | |
3604 | at that address in memory. | |
c2bbbb22 | 3605 | @c FIXME: casts supported---Mod2 true? |
18fae2a8 | 3606 | @end ifclear |
70b88761 | 3607 | |
18fae2a8 | 3608 | @value{GDBN} supports these operators in addition to those of programming |
70b88761 RP |
3609 | languages: |
3610 | ||
3611 | @table @code | |
3612 | @item @@ | |
3613 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
93928b60 | 3614 | @xref{Arrays, ,Artificial arrays}, for more information. |
70b88761 RP |
3615 | |
3616 | @item :: | |
3617 | @samp{::} allows you to specify a variable in terms of the file or | |
93928b60 | 3618 | function where it is defined. @xref{Variables, ,Program variables}. |
70b88761 RP |
3619 | |
3620 | @item @{@var{type}@} @var{addr} | |
fe715d06 RP |
3621 | @cindex @{@var{type}@} |
3622 | @cindex type casting memory | |
3623 | @cindex memory, viewing as typed object | |
3624 | @cindex casts, to view memory | |
70b88761 RP |
3625 | Refers to an object of type @var{type} stored at address @var{addr} in |
3626 | memory. @var{addr} may be any expression whose value is an integer or | |
3627 | pointer (but parentheses are required around binary operators, just as in | |
3628 | a cast). This construct is allowed regardless of what kind of data is | |
1041a570 | 3629 | normally supposed to reside at @var{addr}. |
70b88761 RP |
3630 | @end table |
3631 | ||
4eb4cf57 | 3632 | @node Variables |
93928b60 | 3633 | @section Program variables |
70b88761 RP |
3634 | |
3635 | The most common kind of expression to use is the name of a variable | |
3636 | in your program. | |
3637 | ||
3638 | Variables in expressions are understood in the selected stack frame | |
93928b60 | 3639 | (@pxref{Selection, ,Selecting a frame}); they must either be global |
29a2b744 RP |
3640 | (or static) or be visible according to the scope rules of the |
3641 | programming language from the point of execution in that frame. This | |
3642 | means that in the function | |
70b88761 RP |
3643 | |
3644 | @example | |
3645 | foo (a) | |
3646 | int a; | |
3647 | @{ | |
3648 | bar (a); | |
3649 | @{ | |
3650 | int b = test (); | |
3651 | bar (b); | |
3652 | @} | |
3653 | @} | |
3654 | @end example | |
3655 | ||
3656 | @noindent | |
ed447b95 RP |
3657 | you can examine and use the variable @code{a} whenever your program is |
3658 | executing within the function @code{foo}, but you can only use or | |
3659 | examine the variable @code{b} while your program is executing inside | |
3660 | the block where @code{b} is declared. | |
70b88761 RP |
3661 | |
3662 | @cindex variable name conflict | |
3663 | There is an exception: you can refer to a variable or function whose | |
3664 | scope is a single source file even if the current execution point is not | |
3665 | in this file. But it is possible to have more than one such variable or | |
6ca72cc6 RP |
3666 | function with the same name (in different source files). If that |
3667 | happens, referring to that name has unpredictable effects. If you wish, | |
3668 | you can specify a static variable in a particular function or file, | |
3669 | using the colon-colon notation: | |
70b88761 RP |
3670 | |
3671 | @cindex colon-colon | |
a6d0b6d3 | 3672 | @iftex |
29a2b744 | 3673 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? |
70b88761 | 3674 | @kindex :: |
a6d0b6d3 | 3675 | @end iftex |
70b88761 RP |
3676 | @example |
3677 | @var{file}::@var{variable} | |
6ca72cc6 | 3678 | @var{function}::@var{variable} |
70b88761 RP |
3679 | @end example |
3680 | ||
3681 | @noindent | |
6ca72cc6 | 3682 | Here @var{file} or @var{function} is the name of the context for the |
6c380b13 | 3683 | static @var{variable}. In the case of file names, you can use quotes to |
18fae2a8 | 3684 | make sure @value{GDBN} parses the file name as a single word---for example, |
6c380b13 RP |
3685 | to print a global value of @code{x} defined in @file{f2.c}: |
3686 | ||
3687 | @example | |
18fae2a8 | 3688 | (@value{GDBP}) p 'f2.c'::x |
6c380b13 | 3689 | @end example |
70b88761 | 3690 | |
18fae2a8 | 3691 | @ifclear CONLY |
c2bbbb22 | 3692 | @cindex C++ scope resolution |
70b88761 | 3693 | This use of @samp{::} is very rarely in conflict with the very similar |
18fae2a8 RP |
3694 | use of the same notation in C++. @value{GDBN} also supports use of the C++ |
3695 | scope resolution operator in @value{GDBN} expressions. | |
ed447b95 RP |
3696 | @c FIXME: Um, so what happens in one of those rare cases where it's in |
3697 | @c conflict?? --mew | |
18fae2a8 | 3698 | @end ifclear |
70b88761 | 3699 | |
3d3ab540 RP |
3700 | @cindex wrong values |
3701 | @cindex variable values, wrong | |
3702 | @quotation | |
3703 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
b0157555 RP |
3704 | wrong value at certain points in a function---just after entry to a new |
3705 | scope, and just before exit. | |
3d3ab540 | 3706 | @end quotation |
b0157555 RP |
3707 | You may see this problem when you are stepping by machine instructions. |
3708 | This is because on most machines, it takes more than one instruction to | |
3709 | set up a stack frame (including local variable definitions); if you are | |
3710 | stepping by machine instructions, variables may appear to have the wrong | |
3711 | values until the stack frame is completely built. On exit, it usually | |
3712 | also takes more than one machine instruction to destroy a stack frame; | |
3713 | after you begin stepping through that group of instructions, local | |
3714 | variable definitions may be gone. | |
3d3ab540 | 3715 | |
4eb4cf57 | 3716 | @node Arrays |
93928b60 | 3717 | @section Artificial arrays |
70b88761 RP |
3718 | |
3719 | @cindex artificial array | |
3720 | @kindex @@ | |
3721 | It is often useful to print out several successive objects of the | |
3722 | same type in memory; a section of an array, or an array of | |
3723 | dynamically determined size for which only a pointer exists in the | |
3724 | program. | |
3725 | ||
fe715d06 RP |
3726 | You can do this by referring to a contiguous span of memory as an |
3727 | @dfn{artificial array}, using the binary operator @samp{@@}. The left | |
3728 | operand of @samp{@@} should be the first element of the desired array, | |
3729 | as an individual object. The right operand should be the desired length | |
3730 | of the array. The result is an array value whose elements are all of | |
3731 | the type of the left argument. The first element is actually the left | |
3732 | argument; the second element comes from bytes of memory immediately | |
3733 | following those that hold the first element, and so on. Here is an | |
3734 | example. If a program says | |
70b88761 RP |
3735 | |
3736 | @example | |
3737 | int *array = (int *) malloc (len * sizeof (int)); | |
3738 | @end example | |
3739 | ||
3740 | @noindent | |
3741 | you can print the contents of @code{array} with | |
3742 | ||
3743 | @example | |
3744 | p *array@@len | |
3745 | @end example | |
3746 | ||
3747 | The left operand of @samp{@@} must reside in memory. Array values made | |
3748 | with @samp{@@} in this way behave just like other arrays in terms of | |
3749 | subscripting, and are coerced to pointers when used in expressions. | |
3750 | Artificial arrays most often appear in expressions via the value history | |
93928b60 | 3751 | (@pxref{Value History, ,Value history}), after printing one out.) |
70b88761 | 3752 | |
1041a570 | 3753 | Sometimes the artificial array mechanism is not quite enough; in |
3d3ab540 | 3754 | moderately complex data structures, the elements of interest may not |
1041a570 RP |
3755 | actually be adjacent---for example, if you are interested in the values |
3756 | of pointers in an array. One useful work-around in this situation is | |
3757 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
93928b60 | 3758 | variables}) as a counter in an expression that prints the first |
1041a570 RP |
3759 | interesting value, and then repeat that expression via @key{RET}. For |
3760 | instance, suppose you have an array @code{dtab} of pointers to | |
3761 | structures, and you are interested in the values of a field @code{fv} | |
3762 | in each structure. Here is an example of what you might type: | |
3763 | ||
3d3ab540 RP |
3764 | @example |
3765 | set $i = 0 | |
3766 | p dtab[$i++]->fv | |
3767 | @key{RET} | |
3768 | @key{RET} | |
3769 | @dots{} | |
3770 | @end example | |
3771 | ||
ed447b95 | 3772 | @node Output Formats |
70b88761 RP |
3773 | @section Output formats |
3774 | ||
3775 | @cindex formatted output | |
3776 | @cindex output formats | |
18fae2a8 | 3777 | By default, @value{GDBN} prints a value according to its data type. Sometimes |
70b88761 RP |
3778 | this is not what you want. For example, you might want to print a number |
3779 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3780 | at a certain address as a character string or as an instruction. To do | |
3781 | these things, specify an @dfn{output format} when you print a value. | |
3782 | ||
3783 | The simplest use of output formats is to say how to print a value | |
3784 | already computed. This is done by starting the arguments of the | |
3785 | @code{print} command with a slash and a format letter. The format | |
3786 | letters supported are: | |
3787 | ||
3788 | @table @code | |
3789 | @item x | |
3790 | Regard the bits of the value as an integer, and print the integer in | |
3791 | hexadecimal. | |
3792 | ||
3793 | @item d | |
3794 | Print as integer in signed decimal. | |
3795 | ||
3796 | @item u | |
3797 | Print as integer in unsigned decimal. | |
3798 | ||
3799 | @item o | |
3800 | Print as integer in octal. | |
3801 | ||
3802 | @item t | |
3803 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
fe715d06 RP |
3804 | @footnote{@samp{b} cannot be used because these format letters are also |
3805 | used with the @code{x} command, where @samp{b} stands for ``byte''; | |
3806 | @pxref{Memory,,Examining memory}.} | |
70b88761 RP |
3807 | |
3808 | @item a | |
3809 | Print as an address, both absolute in hex and as an offset from the | |
3810 | nearest preceding symbol. This format can be used to discover where (in | |
3811 | what function) an unknown address is located: | |
1041a570 | 3812 | |
70b88761 | 3813 | @example |
18fae2a8 RP |
3814 | (@value{GDBP}) p/a 0x54320 |
3815 | $3 = 0x54320 <_initialize_vx+396> | |
70b88761 RP |
3816 | @end example |
3817 | ||
70b88761 RP |
3818 | @item c |
3819 | Regard as an integer and print it as a character constant. | |
3820 | ||
3821 | @item f | |
3822 | Regard the bits of the value as a floating point number and print | |
3823 | using typical floating point syntax. | |
3824 | @end table | |
3825 | ||
3826 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3827 | ||
3828 | @example | |
3829 | p/x $pc | |
3830 | @end example | |
3831 | ||
3832 | @noindent | |
3833 | Note that no space is required before the slash; this is because command | |
18fae2a8 | 3834 | names in @value{GDBN} cannot contain a slash. |
70b88761 RP |
3835 | |
3836 | To reprint the last value in the value history with a different format, | |
3837 | you can use the @code{print} command with just a format and no | |
3838 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3839 | ||
4eb4cf57 | 3840 | @node Memory |
93928b60 | 3841 | @section Examining memory |
70b88761 | 3842 | |
1041a570 RP |
3843 | You can use the command @code{x} (for ``examine'') to examine memory in |
3844 | any of several formats, independently of your program's data types. | |
3845 | ||
70b88761 RP |
3846 | @cindex examining memory |
3847 | @table @code | |
3848 | @kindex x | |
cedaf8bc RP |
3849 | @item x/@var{nfu} @var{addr} |
3850 | @itemx x @var{addr} | |
3851 | @itemx x | |
ed447b95 | 3852 | Use the @code{x} command to examine memory. |
1041a570 RP |
3853 | @end table |
3854 | ||
3855 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3856 | much memory to display and how to format it; @var{addr} is an | |
cedaf8bc RP |
3857 | expression giving the address where you want to start displaying memory. |
3858 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3859 | Several commands set convenient defaults for @var{addr}. | |
70b88761 | 3860 | |
1041a570 RP |
3861 | @table @r |
3862 | @item @var{n}, the repeat count | |
3863 | The repeat count is a decimal integer; the default is 1. It specifies | |
3864 | how much memory (counting by units @var{u}) to display. | |
cedaf8bc RP |
3865 | @c This really is **decimal**; unaffected by 'set radix' as of GDB |
3866 | @c 4.1.2. | |
70b88761 | 3867 | |
1041a570 RP |
3868 | @item @var{f}, the display format |
3869 | The display format is one of the formats used by @code{print}, | |
cedaf8bc RP |
3870 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). |
3871 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3872 | last time you used either @code{x} or @code{print}. | |
70b88761 | 3873 | |
1041a570 RP |
3874 | @item @var{u}, the unit size |
3875 | The unit size is any of | |
ed447b95 | 3876 | |
70b88761 RP |
3877 | @table @code |
3878 | @item b | |
cedaf8bc | 3879 | Bytes. |
70b88761 | 3880 | @item h |
cedaf8bc | 3881 | Halfwords (two bytes). |
70b88761 | 3882 | @item w |
cedaf8bc | 3883 | Words (four bytes). This is the initial default. |
70b88761 | 3884 | @item g |
cedaf8bc | 3885 | Giant words (eight bytes). |
70b88761 RP |
3886 | @end table |
3887 | ||
cedaf8bc RP |
3888 | Each time you specify a unit size with @code{x}, that size becomes the |
3889 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3890 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3891 | ||
1041a570 | 3892 | @item @var{addr}, starting display address |
18fae2a8 | 3893 | @var{addr} is the address where you want @value{GDBN} to begin displaying |
cedaf8bc RP |
3894 | memory. The expression need not have a pointer value (though it may); |
3895 | it is always interpreted as an integer address of a byte of memory. | |
1041a570 | 3896 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for |
cedaf8bc RP |
3897 | @var{addr} is usually just after the last address examined---but several |
3898 | other commands also set the default address: @code{info breakpoints} (to | |
3899 | the address of the last breakpoint listed), @code{info line} (to the | |
3900 | starting address of a line), and @code{print} (if you use it to display | |
3901 | a value from memory). | |
1041a570 | 3902 | @end table |
70b88761 | 3903 | |
cedaf8bc RP |
3904 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords |
3905 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3906 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3907 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3908 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
70b88761 | 3909 | |
cedaf8bc | 3910 | Since the letters indicating unit sizes are all distinct from the |
29a2b744 | 3911 | letters specifying output formats, you do not have to remember whether |
cedaf8bc RP |
3912 | unit size or format comes first; either order will work. The output |
3913 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3914 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3915 | ||
3916 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3917 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3918 | @samp{3i} specifies that you want to see three machine instructions, | |
3919 | including any operands. The command @code{disassemble} gives an | |
3920 | alternative way of inspecting machine instructions; @pxref{Machine | |
93928b60 | 3921 | Code,,Source and machine code}. |
cedaf8bc RP |
3922 | |
3923 | All the defaults for the arguments to @code{x} are designed to make it | |
3924 | easy to continue scanning memory with minimal specifications each time | |
1041a570 | 3925 | you use @code{x}. For example, after you have inspected three machine |
cedaf8bc RP |
3926 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven |
3927 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3928 | the repeat count @var{n} is used again; the other arguments default as | |
3929 | for successive uses of @code{x}. | |
70b88761 | 3930 | |
c338a2fd | 3931 | @cindex @code{$_}, @code{$__}, and value history |
cedaf8bc | 3932 | The addresses and contents printed by the @code{x} command are not saved |
70b88761 | 3933 | in the value history because there is often too much of them and they |
18fae2a8 | 3934 | would get in the way. Instead, @value{GDBN} makes these values available for |
70b88761 RP |
3935 | subsequent use in expressions as values of the convenience variables |
3936 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3937 | examined is available for use in expressions in the convenience variable | |
3938 | @code{$_}. The contents of that address, as examined, are available in | |
3939 | the convenience variable @code{$__}. | |
3940 | ||
3941 | If the @code{x} command has a repeat count, the address and contents saved | |
3942 | are from the last memory unit printed; this is not the same as the last | |
3943 | address printed if several units were printed on the last line of output. | |
3944 | ||
4eb4cf57 | 3945 | @node Auto Display |
93928b60 | 3946 | @section Automatic display |
70b88761 RP |
3947 | @cindex automatic display |
3948 | @cindex display of expressions | |
3949 | ||
3950 | If you find that you want to print the value of an expression frequently | |
3951 | (to see how it changes), you might want to add it to the @dfn{automatic | |
18fae2a8 | 3952 | display list} so that @value{GDBN} will print its value each time your program stops. |
70b88761 RP |
3953 | Each expression added to the list is given a number to identify it; |
3954 | to remove an expression from the list, you specify that number. | |
3955 | The automatic display looks like this: | |
3956 | ||
3957 | @example | |
3958 | 2: foo = 38 | |
3959 | 3: bar[5] = (struct hack *) 0x3804 | |
3960 | @end example | |
3961 | ||
3962 | @noindent | |
ed447b95 | 3963 | This display shows item numbers, expressions and their current values. As with |
70b88761 RP |
3964 | displays you request manually using @code{x} or @code{print}, you can |
3965 | specify the output format you prefer; in fact, @code{display} decides | |
3966 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3967 | format specification is---it uses @code{x} if you specify a unit size, | |
3968 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3969 | supported by @code{x}; otherwise it uses @code{print}. | |
3970 | ||
3971 | @table @code | |
3972 | @item display @var{exp} | |
3973 | @kindex display | |
3974 | Add the expression @var{exp} to the list of expressions to display | |
1041a570 | 3975 | each time your program stops. @xref{Expressions, ,Expressions}. |
70b88761 RP |
3976 | |
3977 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3978 | ||
3979 | @item display/@var{fmt} @var{exp} | |
3980 | For @var{fmt} specifying only a display format and not a size or | |
3981 | count, add the expression @var{exp} to the auto-display list but | |
3982 | arranges to display it each time in the specified format @var{fmt}. | |
ed447b95 | 3983 | @xref{Output Formats,,Output formats}. |
70b88761 RP |
3984 | |
3985 | @item display/@var{fmt} @var{addr} | |
3986 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3987 | number of units, add the expression @var{addr} as a memory address to | |
29a2b744 | 3988 | be examined each time your program stops. Examining means in effect |
93928b60 | 3989 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}. |
70b88761 RP |
3990 | @end table |
3991 | ||
3992 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3993 | instruction about to be executed each time execution stops (@samp{$pc} | |
3994 | is a common name for the program counter; @pxref{Registers}). | |
3995 | ||
3996 | @table @code | |
3997 | @item undisplay @var{dnums}@dots{} | |
3998 | @itemx delete display @var{dnums}@dots{} | |
3999 | @kindex delete display | |
4000 | @kindex undisplay | |
4001 | Remove item numbers @var{dnums} from the list of expressions to display. | |
4002 | ||
4003 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
4004 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
4005 | ||
4006 | @item disable display @var{dnums}@dots{} | |
4007 | @kindex disable display | |
4008 | Disable the display of item numbers @var{dnums}. A disabled display | |
4009 | item is not printed automatically, but is not forgotten. It may be | |
4010 | enabled again later. | |
4011 | ||
4012 | @item enable display @var{dnums}@dots{} | |
4013 | @kindex enable display | |
4014 | Enable display of item numbers @var{dnums}. It becomes effective once | |
4015 | again in auto display of its expression, until you specify otherwise. | |
4016 | ||
4017 | @item display | |
4018 | Display the current values of the expressions on the list, just as is | |
29a2b744 | 4019 | done when your program stops. |
70b88761 RP |
4020 | |
4021 | @item info display | |
4022 | @kindex info display | |
4023 | Print the list of expressions previously set up to display | |
4024 | automatically, each one with its item number, but without showing the | |
4025 | values. This includes disabled expressions, which are marked as such. | |
4026 | It also includes expressions which would not be displayed right now | |
4027 | because they refer to automatic variables not currently available. | |
4028 | @end table | |
4029 | ||
4030 | If a display expression refers to local variables, then it does not make | |
4031 | sense outside the lexical context for which it was set up. Such an | |
4032 | expression is disabled when execution enters a context where one of its | |
4033 | variables is not defined. For example, if you give the command | |
4034 | @code{display last_char} while inside a function with an argument | |
29a2b744 | 4035 | @code{last_char}, then this argument will be displayed while your program |
70b88761 RP |
4036 | continues to stop inside that function. When it stops elsewhere---where |
4037 | there is no variable @code{last_char}---display is disabled. The next time | |
4038 | your program stops where @code{last_char} is meaningful, you can enable the | |
4039 | display expression once again. | |
4040 | ||
4eb4cf57 | 4041 | @node Print Settings |
93928b60 | 4042 | @section Print settings |
70b88761 RP |
4043 | |
4044 | @cindex format options | |
4045 | @cindex print settings | |
18fae2a8 | 4046 | @value{GDBN} provides the following ways to control how arrays, structures, |
e251e767 | 4047 | and symbols are printed. |
70b88761 RP |
4048 | |
4049 | @noindent | |
4050 | These settings are useful for debugging programs in any language: | |
4051 | ||
4052 | @table @code | |
4053 | @item set print address | |
4054 | @item set print address on | |
4055 | @kindex set print address | |
18fae2a8 | 4056 | @value{GDBN} will print memory addresses showing the location of stack |
70b88761 RP |
4057 | traces, structure values, pointer values, breakpoints, and so forth, |
4058 | even when it also displays the contents of those addresses. The default | |
4059 | is on. For example, this is what a stack frame display looks like, with | |
4060 | @code{set print address on}: | |
1041a570 | 4061 | |
70b88761 | 4062 | @smallexample |
1041a570 | 4063 | @group |
18fae2a8 | 4064 | (@value{GDBP}) f |
e251e767 | 4065 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") |
70b88761 | 4066 | at input.c:530 |
b80282d5 | 4067 | 530 if (lquote != def_lquote) |
1041a570 | 4068 | @end group |
70b88761 RP |
4069 | @end smallexample |
4070 | ||
4071 | @item set print address off | |
4072 | Do not print addresses when displaying their contents. For example, | |
4073 | this is the same stack frame displayed with @code{set print address off}: | |
1041a570 | 4074 | |
70b88761 | 4075 | @example |
1041a570 | 4076 | @group |
18fae2a8 RP |
4077 | (@value{GDBP}) set print addr off |
4078 | (@value{GDBP}) f | |
70b88761 | 4079 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 |
b80282d5 | 4080 | 530 if (lquote != def_lquote) |
1041a570 | 4081 | @end group |
70b88761 RP |
4082 | @end example |
4083 | ||
fe715d06 RP |
4084 | You can use @samp{set print address off} to eliminate all machine |
4085 | dependent displays from the @value{GDBN} interface. For example, with | |
4086 | @code{print address off}, you should get the same text for backtraces on | |
4087 | all machines---whether or not they involve pointer arguments. | |
4088 | ||
70b88761 RP |
4089 | @item show print address |
4090 | @kindex show print address | |
4091 | Show whether or not addresses are to be printed. | |
4092 | ||
4093 | @item set print array | |
4094 | @itemx set print array on | |
4095 | @kindex set print array | |
6344e2c7 | 4096 | @value{GDBN} will pretty-print arrays. This format is more convenient to read, |
70b88761 RP |
4097 | but uses more space. The default is off. |
4098 | ||
fe715d06 | 4099 | @item set print array off |
70b88761 RP |
4100 | Return to compressed format for arrays. |
4101 | ||
4102 | @item show print array | |
4103 | @kindex show print array | |
4104 | Show whether compressed or pretty format is selected for displaying | |
e251e767 | 4105 | arrays. |
70b88761 RP |
4106 | |
4107 | @item set print elements @var{number-of-elements} | |
4108 | @kindex set print elements | |
18fae2a8 | 4109 | If @value{GDBN} is printing a large array, it will stop printing after it has |
70b88761 RP |
4110 | printed the number of elements set by the @code{set print elements} command. |
4111 | This limit also applies to the display of strings. | |
4112 | ||
4113 | @item show print elements | |
4114 | @kindex show print elements | |
18fae2a8 | 4115 | Display the number of elements of a large array that @value{GDBN} will print |
70b88761 RP |
4116 | before losing patience. |
4117 | ||
4118 | @item set print pretty on | |
4119 | @kindex set print pretty | |
18fae2a8 | 4120 | Cause @value{GDBN} to print structures in an indented format with one member per |
70b88761 RP |
4121 | line, like this: |
4122 | ||
4123 | @example | |
1041a570 | 4124 | @group |
70b88761 RP |
4125 | $1 = @{ |
4126 | next = 0x0, | |
4127 | flags = @{ | |
4128 | sweet = 1, | |
4129 | sour = 1 | |
4130 | @}, | |
4131 | meat = 0x54 "Pork" | |
4132 | @} | |
1041a570 | 4133 | @end group |
70b88761 RP |
4134 | @end example |
4135 | ||
4136 | @item set print pretty off | |
18fae2a8 | 4137 | Cause @value{GDBN} to print structures in a compact format, like this: |
70b88761 RP |
4138 | |
4139 | @smallexample | |
1041a570 | 4140 | @group |
38962738 RP |
4141 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \ |
4142 | meat = 0x54 "Pork"@} | |
1041a570 | 4143 | @end group |
70b88761 RP |
4144 | @end smallexample |
4145 | ||
4146 | @noindent | |
4147 | This is the default format. | |
4148 | ||
4149 | @item show print pretty | |
4150 | @kindex show print pretty | |
18fae2a8 | 4151 | Show which format @value{GDBN} will use to print structures. |
70b88761 RP |
4152 | |
4153 | @item set print sevenbit-strings on | |
f2857bd9 | 4154 | @kindex set print sevenbit-strings |
e251e767 | 4155 | Print using only seven-bit characters; if this option is set, |
18fae2a8 | 4156 | @value{GDBN} will display any eight-bit characters (in strings or character |
70b88761 RP |
4157 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is |
4158 | displayed as @code{\341}. | |
4159 | ||
4160 | @item set print sevenbit-strings off | |
4161 | Print using either seven-bit or eight-bit characters, as required. This | |
4162 | is the default. | |
4163 | ||
4164 | @item show print sevenbit-strings | |
f2857bd9 | 4165 | @kindex show print sevenbit-strings |
18fae2a8 | 4166 | Show whether or not @value{GDBN} will print only seven-bit characters. |
70b88761 RP |
4167 | |
4168 | @item set print union on | |
4169 | @kindex set print union | |
18fae2a8 | 4170 | Tell @value{GDBN} to print unions which are contained in structures. This is the |
70b88761 RP |
4171 | default setting. |
4172 | ||
4173 | @item set print union off | |
18fae2a8 | 4174 | Tell @value{GDBN} not to print unions which are contained in structures. |
70b88761 RP |
4175 | |
4176 | @item show print union | |
4177 | @kindex show print union | |
18fae2a8 | 4178 | Ask @value{GDBN} whether or not it will print unions which are contained in |
e251e767 | 4179 | structures. |
70b88761 RP |
4180 | |
4181 | For example, given the declarations | |
4182 | ||
4183 | @smallexample | |
4184 | typedef enum @{Tree, Bug@} Species; | |
4185 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
203eea5d RP |
4186 | typedef enum @{Caterpillar, Cocoon, Butterfly@} |
4187 | Bug_forms; | |
70b88761 RP |
4188 | |
4189 | struct thing @{ | |
4190 | Species it; | |
4191 | union @{ | |
4192 | Tree_forms tree; | |
4193 | Bug_forms bug; | |
4194 | @} form; | |
4195 | @}; | |
4196 | ||
4197 | struct thing foo = @{Tree, @{Acorn@}@}; | |
4198 | @end smallexample | |
4199 | ||
4200 | @noindent | |
4201 | with @code{set print union on} in effect @samp{p foo} would print | |
4202 | ||
4203 | @smallexample | |
4204 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
4205 | @end smallexample | |
4206 | ||
4207 | @noindent | |
4208 | and with @code{set print union off} in effect it would print | |
4209 | ||
4210 | @smallexample | |
4211 | $1 = @{it = Tree, form = @{...@}@} | |
4212 | @end smallexample | |
6344e2c7 JG |
4213 | |
4214 | @item set print max-symbolic-offset @var{maxoff} | |
4215 | @kindex set print max-symbolic-offset | |
4216 | Tell @value{GDBN} to only display the symbolic form of an address if the | |
4217 | offset between the closest earlier symbol and the address is less than | |
4218 | @var{maxoff}. The default is 0, which means to always print the | |
4219 | symbolic form of an address, if any symbol precedes it. | |
4220 | ||
4221 | @item show print max-symbolic-offset | |
4222 | @kindex show print max-symbolic-offset | |
4223 | Ask how large the maximum offset is that @value{GDBN} will print in a | |
4224 | symbolic address. | |
4225 | ||
70b88761 RP |
4226 | @end table |
4227 | ||
1d7c3357 | 4228 | @ifclear CONLY |
70b88761 RP |
4229 | @noindent |
4230 | These settings are of interest when debugging C++ programs: | |
4231 | ||
4232 | @table @code | |
e251e767 RP |
4233 | @item set print demangle |
4234 | @itemx set print demangle on | |
70b88761 | 4235 | @kindex set print demangle |
fe715d06 RP |
4236 | Print C++ names in their source form rather than in the encoded |
4237 | (``mangled'') form passed to the assembler and linker for type-safe | |
4238 | linkage. The default is @samp{on}. | |
70b88761 RP |
4239 | |
4240 | @item show print demangle | |
4241 | @kindex show print demangle | |
4242 | Show whether C++ names will be printed in mangled or demangled form. | |
4243 | ||
e251e767 RP |
4244 | @item set print asm-demangle |
4245 | @itemx set print asm-demangle on | |
70b88761 RP |
4246 | @kindex set print asm-demangle |
4247 | Print C++ names in their source form rather than their mangled form, even | |
4248 | in assembler code printouts such as instruction disassemblies. | |
4249 | The default is off. | |
4250 | ||
4251 | @item show print asm-demangle | |
4252 | @kindex show print asm-demangle | |
4253 | Show whether C++ names in assembly listings will be printed in mangled | |
4254 | or demangled form. | |
4255 | ||
fe715d06 RP |
4256 | @item set demangle-style @var{style} |
4257 | @kindex set demangle-style | |
4258 | @cindex C++ symbol decoding style | |
4259 | @cindex symbol decoding style, C++ | |
4260 | Choose among several encoding schemes used by different compilers to | |
4261 | represent C++ names. The choices for @var{style} are currently: | |
4262 | ||
4263 | @table @code | |
4264 | @item auto | |
4265 | Allow @value{GDBN} to choose a decoding style by inspecting your program. | |
4266 | ||
4267 | @item gnu | |
4268 | Decode based on the GNU C++ compiler (@code{g++}) encoding algorithm. | |
4269 | ||
4270 | @item lucid | |
4271 | Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm. | |
4272 | ||
a1eff6c2 | 4273 | @item arm |
fe715d06 | 4274 | Decode using the algorithm in the @cite{C++ Annotated Reference Manual}. |
a1eff6c2 RP |
4275 | @strong{Warning:} this setting alone is not sufficient to allow |
4276 | debugging @code{cfront}-generated executables. @value{GDBN} would | |
4277 | require further enhancement to permit that. | |
fe715d06 RP |
4278 | @end table |
4279 | ||
4280 | @item show demangle-style | |
4281 | @kindex show demangle-style | |
4282 | Display the encoding style currently in use for decoding C++ symbols. | |
4283 | ||
70b88761 RP |
4284 | @item set print object |
4285 | @itemx set print object on | |
4286 | @kindex set print object | |
4287 | When displaying a pointer to an object, identify the @emph{actual} | |
4288 | (derived) type of the object rather than the @emph{declared} type, using | |
4289 | the virtual function table. | |
4290 | ||
4291 | @item set print object off | |
4292 | Display only the declared type of objects, without reference to the | |
4293 | virtual function table. This is the default setting. | |
4294 | ||
4295 | @item show print object | |
4296 | @kindex show print object | |
4297 | Show whether actual, or declared, object types will be displayed. | |
4298 | ||
e251e767 RP |
4299 | @item set print vtbl |
4300 | @itemx set print vtbl on | |
70b88761 RP |
4301 | @kindex set print vtbl |
4302 | Pretty print C++ virtual function tables. The default is off. | |
4303 | ||
4304 | @item set print vtbl off | |
4305 | Do not pretty print C++ virtual function tables. | |
4306 | ||
4307 | @item show print vtbl | |
4308 | @kindex show print vtbl | |
4309 | Show whether C++ virtual function tables are pretty printed, or not. | |
70b88761 | 4310 | @end table |
1d7c3357 | 4311 | @end ifclear |
70b88761 | 4312 | |
4eb4cf57 | 4313 | @node Value History |
93928b60 | 4314 | @section Value history |
70b88761 RP |
4315 | |
4316 | @cindex value history | |
93918348 | 4317 | Values printed by the @code{print} command are saved in the @value{GDBN} @dfn{value |
70b88761 RP |
4318 | history} so that you can refer to them in other expressions. Values are |
4319 | kept until the symbol table is re-read or discarded (for example with | |
4320 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
4321 | changes, the value history is discarded, since the values may contain | |
4322 | pointers back to the types defined in the symbol table. | |
4323 | ||
4324 | @cindex @code{$} | |
4325 | @cindex @code{$$} | |
4326 | @cindex history number | |
4327 | The values printed are given @dfn{history numbers} for you to refer to them | |
4328 | by. These are successive integers starting with one. @code{print} shows you | |
4329 | the history number assigned to a value by printing @samp{$@var{num} = } | |
4330 | before the value; here @var{num} is the history number. | |
4331 | ||
4332 | To refer to any previous value, use @samp{$} followed by the value's | |
4333 | history number. The way @code{print} labels its output is designed to | |
4334 | remind you of this. Just @code{$} refers to the most recent value in | |
4335 | the history, and @code{$$} refers to the value before that. | |
4336 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
4337 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
4338 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
4339 | ||
4340 | For example, suppose you have just printed a pointer to a structure and | |
4341 | want to see the contents of the structure. It suffices to type | |
4342 | ||
4343 | @example | |
4344 | p *$ | |
4345 | @end example | |
4346 | ||
4347 | If you have a chain of structures where the component @code{next} points | |
4348 | to the next one, you can print the contents of the next one with this: | |
4349 | ||
4350 | @example | |
4351 | p *$.next | |
4352 | @end example | |
4353 | ||
4354 | @noindent | |
4355 | You can print successive links in the chain by repeating this | |
4356 | command---which you can do by just typing @key{RET}. | |
4357 | ||
4358 | Note that the history records values, not expressions. If the value of | |
4359 | @code{x} is 4 and you type these commands: | |
4360 | ||
4361 | @example | |
4362 | print x | |
4363 | set x=5 | |
4364 | @end example | |
4365 | ||
4366 | @noindent | |
4367 | then the value recorded in the value history by the @code{print} command | |
4368 | remains 4 even though the value of @code{x} has changed. | |
4369 | ||
4370 | @table @code | |
4371 | @kindex show values | |
4372 | @item show values | |
4373 | Print the last ten values in the value history, with their item numbers. | |
4374 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
4375 | values} does not change the history. | |
4376 | ||
4377 | @item show values @var{n} | |
4378 | Print ten history values centered on history item number @var{n}. | |
4379 | ||
4380 | @item show values + | |
4381 | Print ten history values just after the values last printed. If no more | |
4382 | values are available, produces no display. | |
4383 | @end table | |
4384 | ||
4385 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
e251e767 | 4386 | same effect as @samp{show values +}. |
70b88761 | 4387 | |
4eb4cf57 | 4388 | @node Convenience Vars |
93928b60 | 4389 | @section Convenience variables |
70b88761 RP |
4390 | |
4391 | @cindex convenience variables | |
18fae2a8 RP |
4392 | @value{GDBN} provides @dfn{convenience variables} that you can use within |
4393 | @value{GDBN} to hold on to a value and refer to it later. These variables | |
4394 | exist entirely within @value{GDBN}; they are not part of your program, and | |
70b88761 | 4395 | setting a convenience variable has no direct effect on further execution |
1041a570 | 4396 | of your program. That is why you can use them freely. |
70b88761 RP |
4397 | |
4398 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
4399 | @samp{$} can be used for a convenience variable, unless it is one of | |
4400 | the predefined machine-specific register names (@pxref{Registers}). | |
4401 | (Value history references, in contrast, are @emph{numbers} preceded | |
93928b60 | 4402 | by @samp{$}. @xref{Value History, ,Value history}.) |
70b88761 RP |
4403 | |
4404 | You can save a value in a convenience variable with an assignment | |
ed447b95 RP |
4405 | expression, just as you would set a variable in your program. |
4406 | For example: | |
70b88761 RP |
4407 | |
4408 | @example | |
4409 | set $foo = *object_ptr | |
4410 | @end example | |
4411 | ||
4412 | @noindent | |
4413 | would save in @code{$foo} the value contained in the object pointed to by | |
4414 | @code{object_ptr}. | |
4415 | ||
4416 | Using a convenience variable for the first time creates it; but its value | |
4417 | is @code{void} until you assign a new value. You can alter the value with | |
4418 | another assignment at any time. | |
4419 | ||
4420 | Convenience variables have no fixed types. You can assign a convenience | |
4421 | variable any type of value, including structures and arrays, even if | |
4422 | that variable already has a value of a different type. The convenience | |
4423 | variable, when used as an expression, has the type of its current value. | |
4424 | ||
4425 | @table @code | |
4426 | @item show convenience | |
4427 | @kindex show convenience | |
4428 | Print a list of convenience variables used so far, and their values. | |
4429 | Abbreviated @code{show con}. | |
4430 | @end table | |
4431 | ||
4432 | One of the ways to use a convenience variable is as a counter to be | |
4433 | incremented or a pointer to be advanced. For example, to print | |
4434 | a field from successive elements of an array of structures: | |
4435 | ||
18fae2a8 | 4436 | @example |
70b88761 RP |
4437 | set $i = 0 |
4438 | print bar[$i++]->contents | |
4439 | @i{@dots{} repeat that command by typing @key{RET}.} | |
18fae2a8 | 4440 | @end example |
70b88761 | 4441 | |
18fae2a8 | 4442 | Some convenience variables are created automatically by @value{GDBN} and given |
70b88761 RP |
4443 | values likely to be useful. |
4444 | ||
4445 | @table @code | |
4446 | @item $_ | |
c338a2fd | 4447 | @kindex $_ |
70b88761 | 4448 | The variable @code{$_} is automatically set by the @code{x} command to |
93928b60 | 4449 | the last address examined (@pxref{Memory, ,Examining memory}). Other |
29a2b744 RP |
4450 | commands which provide a default address for @code{x} to examine also |
4451 | set @code{$_} to that address; these commands include @code{info line} | |
4452 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4453 | except when set by the @code{x} command, in which case it is a pointer | |
4454 | to the type of @code{$__}. | |
70b88761 RP |
4455 | |
4456 | @item $__ | |
c338a2fd | 4457 | @kindex $__ |
70b88761 | 4458 | The variable @code{$__} is automatically set by the @code{x} command |
c2bbbb22 RP |
4459 | to the value found in the last address examined. Its type is chosen |
4460 | to match the format in which the data was printed. | |
70b88761 RP |
4461 | @end table |
4462 | ||
4eb4cf57 | 4463 | @node Registers |
70b88761 RP |
4464 | @section Registers |
4465 | ||
4466 | @cindex registers | |
b80282d5 | 4467 | You can refer to machine register contents, in expressions, as variables |
70b88761 RP |
4468 | with names starting with @samp{$}. The names of registers are different |
4469 | for each machine; use @code{info registers} to see the names used on | |
e251e767 | 4470 | your machine. |
70b88761 RP |
4471 | |
4472 | @table @code | |
4473 | @item info registers | |
4474 | @kindex info registers | |
b80282d5 RP |
4475 | Print the names and values of all registers except floating-point |
4476 | registers (in the selected stack frame). | |
4477 | ||
4478 | @item info all-registers | |
4479 | @kindex info all-registers | |
4480 | @cindex floating point registers | |
4481 | Print the names and values of all registers, including floating-point | |
4482 | registers. | |
70b88761 | 4483 | |
4eb4cf57 | 4484 | @item info registers @var{regname} @dots{} |
0d1cd01e JG |
4485 | Print the relativized value of each specified register @var{regname}. |
4486 | @var{regname} may be any register name valid on the machine you are using, with | |
70b88761 RP |
4487 | or without the initial @samp{$}. |
4488 | @end table | |
4489 | ||
18fae2a8 | 4490 | @value{GDBN} has four ``standard'' register names that are available (in |
29a2b744 | 4491 | expressions) on most machines---whenever they do not conflict with an |
09267865 RP |
4492 | architecture's canonical mnemonics for registers. The register names |
4493 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4494 | the stack pointer. @code{$fp} is used for a register that contains a | |
4495 | pointer to the current stack frame, and @code{$ps} is used for a | |
4496 | register that contains the processor status. For example, | |
70b88761 | 4497 | you could print the program counter in hex with |
1041a570 | 4498 | |
70b88761 RP |
4499 | @example |
4500 | p/x $pc | |
4501 | @end example | |
4502 | ||
4503 | @noindent | |
4504 | or print the instruction to be executed next with | |
1041a570 | 4505 | |
70b88761 RP |
4506 | @example |
4507 | x/i $pc | |
4508 | @end example | |
4509 | ||
4510 | @noindent | |
ed447b95 | 4511 | or add four to the stack pointer@footnote{This is a way of removing |
29a2b744 RP |
4512 | one word from the stack, on machines where stacks grow downward in |
4513 | memory (most machines, nowadays). This assumes that the innermost | |
4514 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4515 | stack frames are selected. To pop entire frames off the stack, | |
4516 | regardless of machine architecture, use @code{return}; | |
93928b60 | 4517 | @pxref{Returning, ,Returning from a function}.} with |
1041a570 | 4518 | |
70b88761 RP |
4519 | @example |
4520 | set $sp += 4 | |
4521 | @end example | |
4522 | ||
09267865 RP |
4523 | Whenever possible, these four standard register names are available on |
4524 | your machine even though the machine has different canonical mnemonics, | |
4525 | so long as there is no conflict. The @code{info registers} command | |
4526 | shows the canonical names. For example, on the SPARC, @code{info | |
70b88761 RP |
4527 | registers} displays the processor status register as @code{$psr} but you |
4528 | can also refer to it as @code{$ps}. | |
4529 | ||
18fae2a8 | 4530 | @value{GDBN} always considers the contents of an ordinary register as an |
70b88761 RP |
4531 | integer when the register is examined in this way. Some machines have |
4532 | special registers which can hold nothing but floating point; these | |
4533 | registers are considered to have floating point values. There is no way | |
4534 | to refer to the contents of an ordinary register as floating point value | |
4535 | (although you can @emph{print} it as a floating point value with | |
4536 | @samp{print/f $@var{regname}}). | |
4537 | ||
4538 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4539 | means that the data format in which the register contents are saved by | |
4540 | the operating system is not the same one that your program normally | |
4541 | sees. For example, the registers of the 68881 floating point | |
4542 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4543 | programs expect to work with ``double'' (virtual) format. In such | |
18fae2a8 | 4544 | cases, @value{GDBN} normally works with the virtual format only (the format that |
70b88761 RP |
4545 | makes sense for your program), but the @code{info registers} command |
4546 | prints the data in both formats. | |
4547 | ||
4548 | Normally, register values are relative to the selected stack frame | |
93928b60 | 4549 | (@pxref{Selection, ,Selecting a frame}). This means that you get the |
29a2b744 RP |
4550 | value that the register would contain if all stack frames farther in |
4551 | were exited and their saved registers restored. In order to see the | |
4552 | true contents of hardware registers, you must select the innermost | |
4553 | frame (with @samp{frame 0}). | |
70b88761 | 4554 | |
18fae2a8 | 4555 | However, @value{GDBN} must deduce where registers are saved, from the machine |
70b88761 | 4556 | code generated by your compiler. If some registers are not saved, or if |
18fae2a8 | 4557 | @value{GDBN} is unable to locate the saved registers, the selected stack |
70b88761 RP |
4558 | frame will make no difference. |
4559 | ||
a64a6c2b | 4560 | @ifset AMD29K |
03a77779 | 4561 | @table @code |
d8a68b28 JG |
4562 | @item set rstack_high_address @var{address} |
4563 | @kindex set rstack_high_address | |
03a77779 RP |
4564 | @cindex AMD 29K register stack |
4565 | @cindex register stack, AMD29K | |
4566 | On AMD 29000 family processors, registers are saved in a separate | |
18fae2a8 RP |
4567 | ``register stack''. There is no way for @value{GDBN} to determine the extent |
4568 | of this stack. Normally, @value{GDBN} just assumes that the stack is ``large | |
4569 | enough''. This may result in @value{GDBN} referencing memory locations that | |
93918348 | 4570 | do not exist. If necessary, you can get around this problem by |
03a77779 RP |
4571 | specifying the ending address of the register stack with the @code{set |
4572 | rstack_high_address} command. The argument should be an address, which | |
4573 | you will probably want to precede with @samp{0x} to specify in | |
4574 | hexadecimal. | |
d8a68b28 JG |
4575 | |
4576 | @item show rstack_high_address | |
4577 | @kindex show rstack_high_address | |
03a77779 RP |
4578 | Display the current limit of the register stack, on AMD 29000 family |
4579 | processors. | |
4580 | @end table | |
18fae2a8 | 4581 | @end ifset |
d8a68b28 | 4582 | |
a64a6c2b | 4583 | @ifclear HAVE-FLOAT |
4eb4cf57 | 4584 | @node Floating Point Hardware |
93928b60 | 4585 | @section Floating point hardware |
70b88761 | 4586 | @cindex floating point |
1041a570 | 4587 | |
1d7c3357 | 4588 | @c FIXME! Really host, not target? |
18fae2a8 | 4589 | Depending on the host machine architecture, @value{GDBN} may be able to give |
70b88761 RP |
4590 | you more information about the status of the floating point hardware. |
4591 | ||
4592 | @table @code | |
4593 | @item info float | |
4594 | @kindex info float | |
8c69096b | 4595 | Display hardware-dependent information about the floating |
70b88761 | 4596 | point unit. The exact contents and layout vary depending on the |
8c69096b RP |
4597 | floating point chip; on some platforms, @samp{info float} is not |
4598 | available at all. | |
70b88761 RP |
4599 | @end table |
4600 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
e251e767 RP |
4601 | @c FIXME...supported currently on arm's and 386's. Mark properly with |
4602 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
70b88761 | 4603 | @c FIXME... at that point. |
18fae2a8 | 4604 | @end ifclear |
70b88761 | 4605 | |
18fae2a8 | 4606 | @ifclear CONLY |
4eb4cf57 | 4607 | @node Languages |
18fae2a8 | 4608 | @chapter Using @value{GDBN} with Different Languages |
c2bbbb22 RP |
4609 | @cindex languages |
4610 | ||
4611 | Although programming languages generally have common aspects, they are | |
4612 | rarely expressed in the same manner. For instance, in ANSI C, | |
4613 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4614 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4615 | represented (and displayed) differently. Hex numbers in C are written | |
4616 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4617 | ||
4618 | @cindex working language | |
18fae2a8 | 4619 | Language-specific information is built into @value{GDBN} for some languages, |
29a2b744 | 4620 | allowing you to express operations like the above in your program's |
18fae2a8 | 4621 | native language, and allowing @value{GDBN} to output values in a manner |
29a2b744 | 4622 | consistent with the syntax of your program's native language. The |
c2bbbb22 | 4623 | language you use to build expressions, called the @dfn{working |
18fae2a8 | 4624 | language}, can be selected manually, or @value{GDBN} can set it |
c2bbbb22 RP |
4625 | automatically. |
4626 | ||
4627 | @menu | |
4628 | * Setting:: Switching between source languages | |
4629 | * Show:: Displaying the language | |
ed447b95 | 4630 | * Checks:: Type and range checks |
c2bbbb22 RP |
4631 | * Support:: Supported languages |
4632 | @end menu | |
4633 | ||
4eb4cf57 | 4634 | @node Setting |
c2bbbb22 RP |
4635 | @section Switching between source languages |
4636 | ||
18fae2a8 | 4637 | There are two ways to control the working language---either have @value{GDBN} |
c2bbbb22 | 4638 | set it automatically, or select it manually yourself. You can use the |
18fae2a8 | 4639 | @code{set language} command for either purpose. On startup, @value{GDBN} |
c2bbbb22 RP |
4640 | defaults to setting the language automatically. |
4641 | ||
4642 | @menu | |
4643 | * Manually:: Setting the working language manually | |
18fae2a8 | 4644 | * Automatically:: Having @value{GDBN} infer the source language |
c2bbbb22 RP |
4645 | @end menu |
4646 | ||
4eb4cf57 | 4647 | @node Manually |
c2bbbb22 RP |
4648 | @subsection Setting the working language |
4649 | ||
ed447b95 RP |
4650 | If you allow @value{GDBN} to set the language automatically, |
4651 | expressions are interpreted the same way in your debugging session and | |
4652 | your program. | |
4653 | ||
c2bbbb22 | 4654 | @kindex set language |
ed447b95 RP |
4655 | If you wish, you may set the language manually. To do this, issue the |
4656 | command @samp{set language @var{lang}}, where @var{lang} is the name of | |
4657 | a language, such as @code{c} or @code{modula-2}. For a list of the supported | |
4658 | languages, type @samp{set language}. | |
4659 | @c FIXME: rms: eventually this command should be "help set language". | |
c2bbbb22 | 4660 | |
18fae2a8 | 4661 | Setting the language manually prevents @value{GDBN} from updating the working |
c2bbbb22 RP |
4662 | language automatically. This can lead to confusion if you try |
4663 | to debug a program when the working language is not the same as the | |
4664 | source language, when an expression is acceptable to both | |
4665 | languages---but means different things. For instance, if the current | |
18fae2a8 | 4666 | source file were written in C, and @value{GDBN} was parsing Modula-2, a |
c2bbbb22 RP |
4667 | command such as: |
4668 | ||
4669 | @example | |
4670 | print a = b + c | |
4671 | @end example | |
4672 | ||
4673 | @noindent | |
4674 | might not have the effect you intended. In C, this means to add | |
4675 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4676 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4677 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4678 | ||
4eb4cf57 | 4679 | @node Automatically |
18fae2a8 | 4680 | @subsection Having @value{GDBN} infer the source language |
c2bbbb22 | 4681 | |
18fae2a8 RP |
4682 | To have @value{GDBN} set the working language automatically, use @samp{set |
4683 | language local} or @samp{set language auto}. @value{GDBN} then infers the | |
c2bbbb22 RP |
4684 | language that a program was written in by looking at the name of its |
4685 | source files, and examining their extensions: | |
4686 | ||
4687 | @table @file | |
4688 | @item *.mod | |
4689 | Modula-2 source file | |
4690 | ||
4691 | @item *.c | |
5a2c1d85 RP |
4692 | C source file |
4693 | ||
4694 | @item *.C | |
c2bbbb22 | 4695 | @itemx *.cc |
5a2c1d85 | 4696 | C++ source file |
c2bbbb22 RP |
4697 | @end table |
4698 | ||
4699 | This information is recorded for each function or procedure in a source | |
4700 | file. When your program stops in a frame (usually by encountering a | |
18fae2a8 | 4701 | breakpoint), @value{GDBN} sets the working language to the language recorded |
c2bbbb22 RP |
4702 | for the function in that frame. If the language for a frame is unknown |
4703 | (that is, if the function or block corresponding to the frame was | |
4704 | defined in a source file that does not have a recognized extension), the | |
18fae2a8 | 4705 | current working language is not changed, and @value{GDBN} issues a warning. |
c2bbbb22 RP |
4706 | |
4707 | This may not seem necessary for most programs, which are written | |
4708 | entirely in one source language. However, program modules and libraries | |
4709 | written in one source language can be used by a main program written in | |
4710 | a different source language. Using @samp{set language auto} in this | |
4711 | case frees you from having to set the working language manually. | |
4712 | ||
4eb4cf57 | 4713 | @node Show |
c2bbbb22 RP |
4714 | @section Displaying the language |
4715 | ||
4716 | The following commands will help you find out which language is the | |
4717 | working language, and also what language source files were written in. | |
4718 | ||
4719 | @kindex show language | |
4720 | @kindex info frame | |
4721 | @kindex info source | |
4722 | @table @code | |
4723 | @item show language | |
4724 | Display the current working language. This is the | |
4725 | language you can use with commands such as @code{print} to | |
29a2b744 | 4726 | build and compute expressions that may involve variables in your program. |
c2bbbb22 RP |
4727 | |
4728 | @item info frame | |
1041a570 | 4729 | Among the other information listed here (@pxref{Frame Info, ,Information |
93928b60 | 4730 | about a frame}) is the source language for this frame. This is the |
c2bbbb22 RP |
4731 | language that will become the working language if you ever use an |
4732 | identifier that is in this frame. | |
4733 | ||
4734 | @item info source | |
1041a570 | 4735 | Among the other information listed here (@pxref{Symbols, ,Examining the |
c2bbbb22 | 4736 | Symbol Table}) is the source language of this source file. |
c2bbbb22 RP |
4737 | @end table |
4738 | ||
4eb4cf57 | 4739 | @node Checks |
93928b60 | 4740 | @section Type and range checking |
c2bbbb22 RP |
4741 | |
4742 | @quotation | |
18fae2a8 | 4743 | @emph{Warning:} In this release, the @value{GDBN} commands for type and range |
c2bbbb22 RP |
4744 | checking are included, but they do not yet have any effect. This |
4745 | section documents the intended facilities. | |
4746 | @end quotation | |
4747 | @c FIXME remove warning when type/range code added | |
4748 | ||
4749 | Some languages are designed to guard you against making seemingly common | |
4750 | errors through a series of compile- and run-time checks. These include | |
4751 | checking the type of arguments to functions and operators, and making | |
4752 | sure mathematical overflows are caught at run time. Checks such as | |
4753 | these help to ensure a program's correctness once it has been compiled | |
4754 | by eliminating type mismatches, and providing active checks for range | |
29a2b744 | 4755 | errors when your program is running. |
c2bbbb22 | 4756 | |
18fae2a8 RP |
4757 | @value{GDBN} can check for conditions like the above if you wish. |
4758 | Although @value{GDBN} will not check the statements in your program, it | |
4759 | can check expressions entered directly into @value{GDBN} for evaluation via | |
1041a570 | 4760 | the @code{print} command, for example. As with the working language, |
18fae2a8 | 4761 | @value{GDBN} can also decide whether or not to check automatically based on |
93928b60 | 4762 | your program's source language. @xref{Support, ,Supported languages}, |
1041a570 | 4763 | for the default settings of supported languages. |
c2bbbb22 RP |
4764 | |
4765 | @menu | |
4766 | * Type Checking:: An overview of type checking | |
4767 | * Range Checking:: An overview of range checking | |
4768 | @end menu | |
4769 | ||
4770 | @cindex type checking | |
4771 | @cindex checks, type | |
4eb4cf57 | 4772 | @node Type Checking |
c2bbbb22 RP |
4773 | @subsection An overview of type checking |
4774 | ||
4775 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4776 | arguments to operators and functions have to be of the correct type, | |
4777 | otherwise an error occurs. These checks prevent type mismatch | |
4778 | errors from ever causing any run-time problems. For example, | |
4779 | ||
4780 | @example | |
4781 | 1 + 2 @result{} 3 | |
1041a570 | 4782 | @exdent but |
c2bbbb22 RP |
4783 | @error{} 1 + 2.3 |
4784 | @end example | |
4785 | ||
4786 | The second example fails because the @code{CARDINAL} 1 is not | |
4787 | type-compatible with the @code{REAL} 2.3. | |
4788 | ||
18fae2a8 | 4789 | For expressions you use in @value{GDBN} commands, you can tell the @value{GDBN} |
c2bbbb22 RP |
4790 | type checker to skip checking; to treat any mismatches as errors and |
4791 | abandon the expression; or only issue warnings when type mismatches | |
4792 | occur, but evaluate the expression anyway. When you choose the last of | |
18fae2a8 | 4793 | these, @value{GDBN} evaluates expressions like the second example above, but |
c2bbbb22 RP |
4794 | also issues a warning. |
4795 | ||
4796 | Even though you may turn type checking off, other type-based reasons may | |
18fae2a8 | 4797 | prevent @value{GDBN} from evaluating an expression. For instance, @value{GDBN} does not |
c2bbbb22 RP |
4798 | know how to add an @code{int} and a @code{struct foo}. These particular |
4799 | type errors have nothing to do with the language in use, and usually | |
4800 | arise from expressions, such as the one described above, which make | |
4801 | little sense to evaluate anyway. | |
4802 | ||
4803 | Each language defines to what degree it is strict about type. For | |
4804 | instance, both Modula-2 and C require the arguments to arithmetical | |
4805 | operators to be numbers. In C, enumerated types and pointers can be | |
4806 | represented as numbers, so that they are valid arguments to mathematical | |
93928b60 | 4807 | operators. @xref{Support, ,Supported languages}, for further |
c2bbbb22 RP |
4808 | details on specific languages. |
4809 | ||
18fae2a8 | 4810 | @value{GDBN} provides some additional commands for controlling the type checker: |
c2bbbb22 RP |
4811 | |
4812 | @kindex set check | |
4813 | @kindex set check type | |
4814 | @kindex show check type | |
4815 | @table @code | |
4816 | @item set check type auto | |
e251e767 | 4817 | Set type checking on or off based on the current working language. |
93928b60 | 4818 | @xref{Support, ,Supported languages}, for the default settings for |
c2bbbb22 RP |
4819 | each language. |
4820 | ||
4821 | @item set check type on | |
4822 | @itemx set check type off | |
4823 | Set type checking on or off, overriding the default setting for the | |
4824 | current working language. Issue a warning if the setting does not | |
93918348 | 4825 | match the language default. If any type mismatches occur in |
18fae2a8 | 4826 | evaluating an expression while typechecking is on, @value{GDBN} prints a |
c2bbbb22 RP |
4827 | message and aborts evaluation of the expression. |
4828 | ||
4829 | @item set check type warn | |
4830 | Cause the type checker to issue warnings, but to always attempt to | |
4831 | evaluate the expression. Evaluating the expression may still | |
18fae2a8 | 4832 | be impossible for other reasons. For example, @value{GDBN} cannot add |
c2bbbb22 RP |
4833 | numbers and structures. |
4834 | ||
4835 | @item show type | |
18fae2a8 | 4836 | Show the current setting of the type checker, and whether or not @value{GDBN} is |
c2bbbb22 RP |
4837 | setting it automatically. |
4838 | @end table | |
4839 | ||
4840 | @cindex range checking | |
4841 | @cindex checks, range | |
4eb4cf57 | 4842 | @node Range Checking |
ed447b95 | 4843 | @subsection An overview of range checking |
c2bbbb22 RP |
4844 | |
4845 | In some languages (such as Modula-2), it is an error to exceed the | |
4846 | bounds of a type; this is enforced with run-time checks. Such range | |
4847 | checking is meant to ensure program correctness by making sure | |
4848 | computations do not overflow, or indices on an array element access do | |
4849 | not exceed the bounds of the array. | |
4850 | ||
ed447b95 RP |
4851 | For expressions you use in @value{GDBN} commands, you can tell |
4852 | @value{GDBN} to treat range errors in one of three ways: ignore them, | |
4853 | always treat them as errors and abandon the expression, or issue | |
4854 | warnings but evaluate the expression anyway. | |
c2bbbb22 RP |
4855 | |
4856 | A range error can result from numerical overflow, from exceeding an | |
ed447b95 | 4857 | array index bound, or when you type a constant that is not a member |
c2bbbb22 RP |
4858 | of any type. Some languages, however, do not treat overflows as an |
4859 | error. In many implementations of C, mathematical overflow causes the | |
4860 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4861 | the largest integer value, and @var{s} is the smallest, then | |
1041a570 | 4862 | |
c2bbbb22 RP |
4863 | @example |
4864 | @var{m} + 1 @result{} @var{s} | |
4865 | @end example | |
4866 | ||
4867 | This, too, is specific to individual languages, and in some cases | |
1041a570 | 4868 | specific to individual compilers or machines. @xref{Support, , |
93928b60 | 4869 | Supported languages}, for further details on specific languages. |
c2bbbb22 | 4870 | |
18fae2a8 | 4871 | @value{GDBN} provides some additional commands for controlling the range checker: |
c2bbbb22 RP |
4872 | |
4873 | @kindex set check | |
4874 | @kindex set check range | |
4875 | @kindex show check range | |
4876 | @table @code | |
4877 | @item set check range auto | |
e251e767 | 4878 | Set range checking on or off based on the current working language. |
93928b60 | 4879 | @xref{Support, ,Supported languages}, for the default settings for |
c2bbbb22 RP |
4880 | each language. |
4881 | ||
4882 | @item set check range on | |
4883 | @itemx set check range off | |
4884 | Set range checking on or off, overriding the default setting for the | |
4885 | current working language. A warning is issued if the setting does not | |
93918348 | 4886 | match the language default. If a range error occurs, then a message |
c2bbbb22 RP |
4887 | is printed and evaluation of the expression is aborted. |
4888 | ||
4889 | @item set check range warn | |
18fae2a8 | 4890 | Output messages when the @value{GDBN} range checker detects a range error, |
c2bbbb22 RP |
4891 | but attempt to evaluate the expression anyway. Evaluating the |
4892 | expression may still be impossible for other reasons, such as accessing | |
4893 | memory that the process does not own (a typical example from many UNIX | |
4894 | systems). | |
4895 | ||
4896 | @item show range | |
e251e767 | 4897 | Show the current setting of the range checker, and whether or not it is |
18fae2a8 | 4898 | being set automatically by @value{GDBN}. |
c2bbbb22 RP |
4899 | @end table |
4900 | ||
4eb4cf57 | 4901 | @node Support |
93928b60 | 4902 | @section Supported languages |
c2bbbb22 | 4903 | |
18fae2a8 | 4904 | @value{GDBN} 4 supports C, C++, and Modula-2. Some @value{GDBN} |
1041a570 | 4905 | features may be used in expressions regardless of the language you |
18fae2a8 | 4906 | use: the @value{GDBN} @code{@@} and @code{::} operators, and the |
1041a570 RP |
4907 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be |
4908 | used with the constructs of any of the supported languages. | |
c2bbbb22 RP |
4909 | |
4910 | The following sections detail to what degree each of these | |
18fae2a8 | 4911 | source languages is supported by @value{GDBN}. These sections are |
c2bbbb22 | 4912 | not meant to be language tutorials or references, but serve only as a |
18fae2a8 | 4913 | reference guide to what the @value{GDBN} expression parser will accept, and |
c2bbbb22 RP |
4914 | what input and output formats should look like for different languages. |
4915 | There are many good books written on each of these languages; please | |
4916 | look to these for a language reference or tutorial. | |
4917 | ||
4918 | @menu | |
4919 | * C:: C and C++ | |
4920 | * Modula-2:: Modula-2 | |
4921 | @end menu | |
4922 | ||
4eb4cf57 | 4923 | @node C |
c2bbbb22 RP |
4924 | @subsection C and C++ |
4925 | @cindex C and C++ | |
c2bbbb22 | 4926 | @cindex expressions in C or C++ |
0f153e74 | 4927 | |
18fae2a8 | 4928 | Since C and C++ are so closely related, many features of @value{GDBN} apply |
5a2c1d85 RP |
4929 | to both languages. Whenever this is the case, we discuss both languages |
4930 | together. | |
b80282d5 RP |
4931 | |
4932 | @cindex C++ | |
4933 | @kindex g++ | |
4934 | @cindex GNU C++ | |
c2bbbb22 | 4935 | The C++ debugging facilities are jointly implemented by the GNU C++ |
18fae2a8 | 4936 | compiler and @value{GDBN}. Therefore, to debug your C++ code effectively, |
c2bbbb22 RP |
4937 | you must compile your C++ programs with the GNU C++ compiler, |
4938 | @code{g++}. | |
18fae2a8 RP |
4939 | @end ifclear |
4940 | @ifset CONLY | |
0f153e74 RP |
4941 | @node C |
4942 | @chapter C Language Support | |
4943 | @cindex C language | |
4944 | @cindex expressions in C | |
4945 | ||
18fae2a8 RP |
4946 | Information specific to the C language is built into @value{GDBN} so that you |
4947 | can use C expressions while degugging. This also permits @value{GDBN} to | |
0f153e74 | 4948 | output values in a manner consistent with C conventions. |
c2bbbb22 | 4949 | |
0f153e74 | 4950 | @menu |
ed447b95 RP |
4951 | * C Operators:: C operators |
4952 | * C Constants:: C constants | |
18fae2a8 | 4953 | * Debugging C:: @value{GDBN} and C |
0f153e74 | 4954 | @end menu |
18fae2a8 RP |
4955 | @end ifset |
4956 | @ifclear CONLY | |
b80282d5 | 4957 | @menu |
ed447b95 RP |
4958 | * C Operators:: C and C++ operators |
4959 | * C Constants:: C and C++ constants | |
4960 | * Cplus expressions:: C++ expressions | |
c2bbbb22 | 4961 | * C Defaults:: Default settings for C and C++ |
ed447b95 | 4962 | * C Checks:: C and C++ type and range checks |
18fae2a8 | 4963 | * Debugging C:: @value{GDBN} and C |
c2bbbb22 | 4964 | * Debugging C plus plus:: Special features for C++ |
b80282d5 | 4965 | @end menu |
18fae2a8 | 4966 | @end ifclear |
b80282d5 | 4967 | |
18fae2a8 | 4968 | @ifclear CONLY |
c2bbbb22 | 4969 | @cindex C and C++ operators |
4eb4cf57 | 4970 | @node C Operators |
93928b60 | 4971 | @subsubsection C and C++ operators |
18fae2a8 RP |
4972 | @end ifclear |
4973 | @ifset CONLY | |
0f153e74 RP |
4974 | @cindex C operators |
4975 | @node C Operators | |
93928b60 | 4976 | @section C operators |
18fae2a8 | 4977 | @end ifset |
c2bbbb22 RP |
4978 | |
4979 | Operators must be defined on values of specific types. For instance, | |
4980 | @code{+} is defined on numbers, but not on structures. Operators are | |
0f153e74 RP |
4981 | often defined on groups of types. |
4982 | ||
18fae2a8 | 4983 | @ifclear CONLY |
0f153e74 | 4984 | For the purposes of C and C++, the following definitions hold: |
18fae2a8 | 4985 | @end ifclear |
c2bbbb22 RP |
4986 | |
4987 | @itemize @bullet | |
e251e767 | 4988 | @item |
c2bbbb22 | 4989 | @emph{Integral types} include @code{int} with any of its storage-class |
9aa964da | 4990 | specifiers; @code{char}; and @code{enum}. |
c2bbbb22 RP |
4991 | |
4992 | @item | |
4993 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4994 | ||
4995 | @item | |
4996 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4997 | *)}. | |
4998 | ||
e251e767 | 4999 | @item |
c2bbbb22 | 5000 | @emph{Scalar types} include all of the above. |
c2bbbb22 RP |
5001 | @end itemize |
5002 | ||
5003 | @noindent | |
5004 | The following operators are supported. They are listed here | |
5005 | in order of increasing precedence: | |
5006 | ||
5007 | @table @code | |
18fae2a8 | 5008 | @item , |
c2bbbb22 RP |
5009 | The comma or sequencing operator. Expressions in a comma-separated list |
5010 | are evaluated from left to right, with the result of the entire | |
5011 | expression being the last expression evaluated. | |
5012 | ||
5013 | @item = | |
5014 | Assignment. The value of an assignment expression is the value | |
5015 | assigned. Defined on scalar types. | |
5016 | ||
5017 | @item @var{op}= | |
1041a570 RP |
5018 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, |
5019 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
5020 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
5021 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
5022 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
c2bbbb22 RP |
5023 | |
5024 | @item ?: | |
5025 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
5026 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
5027 | integral type. | |
5028 | ||
5029 | @item || | |
1041a570 | 5030 | Logical @sc{or}. Defined on integral types. |
c2bbbb22 RP |
5031 | |
5032 | @item && | |
1041a570 | 5033 | Logical @sc{and}. Defined on integral types. |
c2bbbb22 RP |
5034 | |
5035 | @item | | |
1041a570 | 5036 | Bitwise @sc{or}. Defined on integral types. |
c2bbbb22 RP |
5037 | |
5038 | @item ^ | |
1041a570 | 5039 | Bitwise exclusive-@sc{or}. Defined on integral types. |
c2bbbb22 RP |
5040 | |
5041 | @item & | |
1041a570 | 5042 | Bitwise @sc{and}. Defined on integral types. |
c2bbbb22 RP |
5043 | |
5044 | @item ==@r{, }!= | |
5045 | Equality and inequality. Defined on scalar types. The value of these | |
5046 | expressions is 0 for false and non-zero for true. | |
5047 | ||
5048 | @item <@r{, }>@r{, }<=@r{, }>= | |
5049 | Less than, greater than, less than or equal, greater than or equal. | |
5050 | Defined on scalar types. The value of these expressions is 0 for false | |
5051 | and non-zero for true. | |
5052 | ||
5053 | @item <<@r{, }>> | |
18fae2a8 | 5054 | left shift, and right shift. Defined on integral types. |
c2bbbb22 | 5055 | |
e251e767 | 5056 | @item @@ |
18fae2a8 | 5057 | The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5058 | |
5059 | @item +@r{, }- | |
5060 | Addition and subtraction. Defined on integral types, floating-point types and | |
e251e767 | 5061 | pointer types. |
c2bbbb22 RP |
5062 | |
5063 | @item *@r{, }/@r{, }% | |
5064 | Multiplication, division, and modulus. Multiplication and division are | |
5065 | defined on integral and floating-point types. Modulus is defined on | |
5066 | integral types. | |
5067 | ||
5068 | @item ++@r{, }-- | |
5069 | Increment and decrement. When appearing before a variable, the | |
5070 | operation is performed before the variable is used in an expression; | |
5071 | when appearing after it, the variable's value is used before the | |
5072 | operation takes place. | |
5073 | ||
5074 | @item * | |
5075 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
5076 | @code{++}. | |
5077 | ||
5078 | @item & | |
5079 | Address operator. Defined on variables. Same precedence as @code{++}. | |
5080 | ||
18fae2a8 | 5081 | @ifclear CONLY |
93918348 | 5082 | For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is |
6ca72cc6 RP |
5083 | allowed in the C++ language itself: you can use @samp{&(&@var{ref})} |
5084 | (or, if you prefer, simply @samp{&&@var{ref}} to examine the address | |
5085 | where a C++ reference variable (declared with @samp{&@var{ref}}) is | |
5086 | stored. | |
18fae2a8 | 5087 | @end ifclear |
6ca72cc6 | 5088 | |
c2bbbb22 RP |
5089 | @item - |
5090 | Negative. Defined on integral and floating-point types. Same | |
5091 | precedence as @code{++}. | |
5092 | ||
5093 | @item ! | |
5094 | Logical negation. Defined on integral types. Same precedence as | |
5095 | @code{++}. | |
5096 | ||
5097 | @item ~ | |
5098 | Bitwise complement operator. Defined on integral types. Same precedence as | |
5099 | @code{++}. | |
5100 | ||
18fae2a8 | 5101 | |
c2bbbb22 RP |
5102 | @item .@r{, }-> |
5103 | Structure member, and pointer-to-structure member. For convenience, | |
18fae2a8 | 5104 | @value{GDBN} regards the two as equivalent, choosing whether to dereference a |
e251e767 | 5105 | pointer based on the stored type information. |
9aa964da | 5106 | Defined on @code{struct} and @code{union} data. |
c2bbbb22 RP |
5107 | |
5108 | @item [] | |
5109 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
5110 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
5111 | ||
5112 | @item () | |
18fae2a8 | 5113 | Function parameter list. Same precedence as @code{->}. |
c2bbbb22 | 5114 | |
18fae2a8 | 5115 | @ifclear CONLY |
c2bbbb22 RP |
5116 | @item :: |
5117 | C++ scope resolution operator. Defined on | |
5118 | @code{struct}, @code{union}, and @code{class} types. | |
18fae2a8 | 5119 | @end ifclear |
c2bbbb22 RP |
5120 | |
5121 | @item :: | |
ed447b95 RP |
5122 | Doubled colons |
5123 | @ifclear CONLY | |
5124 | also | |
5125 | @end ifclear | |
5126 | represent the @value{GDBN} scope operator (@pxref{Expressions, | |
5127 | ,Expressions}). | |
18fae2a8 | 5128 | @ifclear CONLY |
0f153e74 | 5129 | Same precedence as @code{::}, above. |
18fae2a8 | 5130 | @end ifclear |
c2bbbb22 RP |
5131 | @end table |
5132 | ||
18fae2a8 | 5133 | @ifclear CONLY |
c2bbbb22 | 5134 | @cindex C and C++ constants |
4eb4cf57 | 5135 | @node C Constants |
93928b60 | 5136 | @subsubsection C and C++ constants |
0f153e74 | 5137 | |
18fae2a8 | 5138 | @value{GDBN} allows you to express the constants of C and C++ in the |
0f153e74 | 5139 | following ways: |
18fae2a8 RP |
5140 | @end ifclear |
5141 | @ifset CONLY | |
0f153e74 RP |
5142 | @cindex C constants |
5143 | @node C Constants | |
93928b60 | 5144 | @section C constants |
c2bbbb22 | 5145 | |
18fae2a8 | 5146 | @value{GDBN} allows you to express the constants of C in the |
c2bbbb22 | 5147 | following ways: |
18fae2a8 | 5148 | @end ifset |
c2bbbb22 RP |
5149 | |
5150 | @itemize @bullet | |
c2bbbb22 RP |
5151 | @item |
5152 | Integer constants are a sequence of digits. Octal constants are | |
5153 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
1041a570 | 5154 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter |
c2bbbb22 RP |
5155 | @samp{l}, specifying that the constant should be treated as a |
5156 | @code{long} value. | |
5157 | ||
5158 | @item | |
5159 | Floating point constants are a sequence of digits, followed by a decimal | |
5160 | point, followed by a sequence of digits, and optionally followed by an | |
5161 | exponent. An exponent is of the form: | |
5162 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
5163 | sequence of digits. The @samp{+} is optional for positive exponents. | |
5164 | ||
5165 | @item | |
5166 | Enumerated constants consist of enumerated identifiers, or their | |
5167 | integral equivalents. | |
5168 | ||
5169 | @item | |
5170 | Character constants are a single character surrounded by single quotes | |
5171 | (@code{'}), or a number---the ordinal value of the corresponding character | |
5172 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
5173 | be represented by a letter or by @dfn{escape sequences}, which are of | |
5174 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
5175 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
5176 | @samp{@var{x}} is a predefined special character---for example, | |
5177 | @samp{\n} for newline. | |
5178 | ||
5179 | @item | |
5180 | String constants are a sequence of character constants surrounded | |
5181 | by double quotes (@code{"}). | |
5182 | ||
5183 | @item | |
fe715d06 RP |
5184 | Pointer constants are an integral value. You can also write pointers |
5185 | to constants using the C operator @samp{&}. | |
5186 | ||
5187 | @item | |
5188 | Array constants are comma-separated lists surrounded by braces @samp{@{} | |
5189 | and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of | |
5190 | integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array, | |
5191 | and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers. | |
c2bbbb22 RP |
5192 | @end itemize |
5193 | ||
18fae2a8 | 5194 | @ifclear CONLY |
ed447b95 | 5195 | @node Cplus expressions |
93928b60 | 5196 | @subsubsection C++ expressions |
b80282d5 RP |
5197 | |
5198 | @cindex expressions in C++ | |
93918348 | 5199 | @value{GDBN} expression handling has a number of extensions to |
b1385986 RP |
5200 | interpret a significant subset of C++ expressions. |
5201 | ||
5202 | @cindex C++ support, not in @sc{coff} | |
5203 | @cindex @sc{coff} versus C++ | |
5204 | @cindex C++ and object formats | |
5205 | @cindex object formats and C++ | |
5206 | @cindex a.out and C++ | |
5207 | @cindex @sc{ecoff} and C++ | |
5208 | @cindex @sc{xcoff} and C++ | |
5209 | @cindex @sc{elf}/stabs and C++ | |
5210 | @cindex @sc{elf}/@sc{dwarf} and C++ | |
5211 | @quotation | |
5212 | @emph{Warning:} Most of these extensions depend on the use of additional | |
5213 | debugging information in the symbol table, and thus require a rich, | |
5214 | extendable object code format. In particular, if your system uses | |
5215 | a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs | |
5216 | extensions to the symbol table, these facilities are all available. | |
5217 | Where the object code format is standard @sc{coff}, on the other hand, | |
18fae2a8 | 5218 | most of the C++ support in @value{GDBN} will @emph{not} work, nor can it. |
b1385986 | 5219 | For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the |
18fae2a8 | 5220 | standard is still evolving, so the C++ support in @value{GDBN} is still |
b1385986 RP |
5221 | fragile; when this debugging format stabilizes, however, C++ support |
5222 | will also be available on systems that use it. | |
5223 | @end quotation | |
b80282d5 RP |
5224 | |
5225 | @enumerate | |
5226 | ||
5227 | @cindex member functions | |
e251e767 | 5228 | @item |
b80282d5 | 5229 | Member function calls are allowed; you can use expressions like |
1041a570 | 5230 | |
b80282d5 RP |
5231 | @example |
5232 | count = aml->GetOriginal(x, y) | |
5233 | @end example | |
5234 | ||
5235 | @kindex this | |
5236 | @cindex namespace in C++ | |
e251e767 | 5237 | @item |
b80282d5 RP |
5238 | While a member function is active (in the selected stack frame), your |
5239 | expressions have the same namespace available as the member function; | |
18fae2a8 | 5240 | that is, @value{GDBN} allows implicit references to the class instance |
b80282d5 RP |
5241 | pointer @code{this} following the same rules as C++. |
5242 | ||
5243 | @cindex call overloaded functions | |
5244 | @cindex type conversions in C++ | |
e251e767 | 5245 | @item |
18fae2a8 | 5246 | You can call overloaded functions; @value{GDBN} will resolve the function |
b80282d5 RP |
5247 | call to the right definition, with one restriction---you must use |
5248 | arguments of the type required by the function that you want to call. | |
18fae2a8 | 5249 | @value{GDBN} will not perform conversions requiring constructors or |
b80282d5 RP |
5250 | user-defined type operators. |
5251 | ||
5252 | @cindex reference declarations | |
5253 | @item | |
18fae2a8 | 5254 | @value{GDBN} understands variables declared as C++ references; you can use them in |
b80282d5 | 5255 | expressions just as you do in C++ source---they are automatically |
e251e767 | 5256 | dereferenced. |
b80282d5 | 5257 | |
18fae2a8 | 5258 | In the parameter list shown when @value{GDBN} displays a frame, the values of |
b80282d5 RP |
5259 | reference variables are not displayed (unlike other variables); this |
5260 | avoids clutter, since references are often used for large structures. | |
5261 | The @emph{address} of a reference variable is always shown, unless | |
1041a570 | 5262 | you have specified @samp{set print address off}. |
b80282d5 RP |
5263 | |
5264 | @item | |
18fae2a8 | 5265 | @value{GDBN} supports the C++ name resolution operator @code{::}---your |
c2bbbb22 RP |
5266 | expressions can use it just as expressions in your program do. Since |
5267 | one scope may be defined in another, you can use @code{::} repeatedly if | |
5268 | necessary, for example in an expression like | |
18fae2a8 | 5269 | @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows |
c2bbbb22 | 5270 | resolving name scope by reference to source files, in both C and C++ |
93928b60 | 5271 | debugging (@pxref{Variables, ,Program variables}). |
b80282d5 RP |
5272 | @end enumerate |
5273 | ||
4eb4cf57 | 5274 | @node C Defaults |
93928b60 | 5275 | @subsubsection C and C++ defaults |
c2bbbb22 RP |
5276 | @cindex C and C++ defaults |
5277 | ||
18fae2a8 | 5278 | If you allow @value{GDBN} to set type and range checking automatically, they |
e251e767 | 5279 | both default to @code{off} whenever the working language changes to |
18fae2a8 | 5280 | C or C++. This happens regardless of whether you, or @value{GDBN}, |
c2bbbb22 RP |
5281 | selected the working language. |
5282 | ||
18fae2a8 | 5283 | If you allow @value{GDBN} to set the language automatically, it sets the |
5a2c1d85 RP |
5284 | working language to C or C++ on entering code compiled from a source file |
5285 | whose name ends with @file{.c}, @file{.C}, or @file{.cc}. | |
18fae2a8 | 5286 | @xref{Automatically, ,Having @value{GDBN} infer the source language}, for |
c2bbbb22 RP |
5287 | further details. |
5288 | ||
4eb4cf57 | 5289 | @node C Checks |
93928b60 | 5290 | @subsubsection C and C++ type and range checks |
c2bbbb22 RP |
5291 | @cindex C and C++ checks |
5292 | ||
18fae2a8 RP |
5293 | By default, when @value{GDBN} parses C or C++ expressions, type checking |
5294 | is not used. However, if you turn type checking on, @value{GDBN} will | |
c2bbbb22 RP |
5295 | consider two variables type equivalent if: |
5296 | ||
5297 | @itemize @bullet | |
5298 | @item | |
5299 | The two variables are structured and have the same structure, union, or | |
5300 | enumerated tag. | |
5301 | ||
e251e767 | 5302 | @item |
c2bbbb22 RP |
5303 | Two two variables have the same type name, or types that have been |
5304 | declared equivalent through @code{typedef}. | |
5305 | ||
5306 | @ignore | |
5307 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
5308 | @c FIXME--beers? | |
5309 | @item | |
5310 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
5311 | declared in the same declaration. (Note: this may not be true for all C | |
5312 | compilers.) | |
5313 | @end ignore | |
c2bbbb22 RP |
5314 | @end itemize |
5315 | ||
5316 | Range checking, if turned on, is done on mathematical operations. Array | |
5317 | indices are not checked, since they are often used to index a pointer | |
5318 | that is not itself an array. | |
18fae2a8 | 5319 | @end ifclear |
c2bbbb22 | 5320 | |
18fae2a8 | 5321 | @ifclear CONLY |
4eb4cf57 | 5322 | @node Debugging C |
18fae2a8 RP |
5323 | @subsubsection @value{GDBN} and C |
5324 | @end ifclear | |
5325 | @ifset CONLY | |
5326 | @node Debugging C | |
5327 | @section @value{GDBN} and C | |
5328 | @end ifset | |
c2bbbb22 RP |
5329 | |
5330 | The @code{set print union} and @code{show print union} commands apply to | |
5331 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
1d7c3357 RP |
5332 | inside a @code{struct} |
5333 | @ifclear CONLY | |
5334 | or @code{class} | |
5335 | @end ifclear | |
5336 | will also be printed. | |
c2bbbb22 RP |
5337 | Otherwise, it will appear as @samp{@{...@}}. |
5338 | ||
5339 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
ed447b95 RP |
5340 | with pointers and a memory allocation function. @xref{Expressions, |
5341 | ,Expressions}. | |
c2bbbb22 | 5342 | |
18fae2a8 | 5343 | @ifclear CONLY |
4eb4cf57 | 5344 | @node Debugging C plus plus |
93928b60 | 5345 | @subsubsection @value{GDBN} features for C++ |
b80282d5 RP |
5346 | |
5347 | @cindex commands for C++ | |
18fae2a8 | 5348 | Some @value{GDBN} commands are particularly useful with C++, and some are |
b80282d5 RP |
5349 | designed specifically for use with C++. Here is a summary: |
5350 | ||
5351 | @table @code | |
5352 | @cindex break in overloaded functions | |
5353 | @item @r{breakpoint menus} | |
5354 | When you want a breakpoint in a function whose name is overloaded, | |
93918348 | 5355 | @value{GDBN} breakpoint menus help you specify which function definition |
93928b60 | 5356 | you want. @xref{Breakpoint Menus,,Breakpoint menus}. |
b80282d5 RP |
5357 | |
5358 | @cindex overloading in C++ | |
5359 | @item rbreak @var{regex} | |
5360 | Setting breakpoints using regular expressions is helpful for setting | |
5361 | breakpoints on overloaded functions that are not members of any special | |
e251e767 | 5362 | classes. |
93928b60 | 5363 | @xref{Set Breaks, ,Setting breakpoints}. |
b80282d5 RP |
5364 | |
5365 | @cindex C++ exception handling | |
5366 | @item catch @var{exceptions} | |
5367 | @itemx info catch | |
29a2b744 | 5368 | Debug C++ exception handling using these commands. @xref{Exception |
93928b60 | 5369 | Handling, ,Breakpoints and exceptions}. |
b80282d5 | 5370 | |
e251e767 | 5371 | @cindex inheritance |
b80282d5 RP |
5372 | @item ptype @var{typename} |
5373 | Print inheritance relationships as well as other information for type | |
e251e767 | 5374 | @var{typename}. |
1041a570 | 5375 | @xref{Symbols, ,Examining the Symbol Table}. |
b80282d5 RP |
5376 | |
5377 | @cindex C++ symbol display | |
5378 | @item set print demangle | |
5379 | @itemx show print demangle | |
5380 | @itemx set print asm-demangle | |
5381 | @itemx show print asm-demangle | |
5382 | Control whether C++ symbols display in their source form, both when | |
5383 | displaying code as C++ source and when displaying disassemblies. | |
93928b60 | 5384 | @xref{Print Settings, ,Print settings}. |
b80282d5 RP |
5385 | |
5386 | @item set print object | |
5387 | @itemx show print object | |
e251e767 | 5388 | Choose whether to print derived (actual) or declared types of objects. |
93928b60 | 5389 | @xref{Print Settings, ,Print settings}. |
b80282d5 RP |
5390 | |
5391 | @item set print vtbl | |
5392 | @itemx show print vtbl | |
5393 | Control the format for printing virtual function tables. | |
93928b60 | 5394 | @xref{Print Settings, ,Print settings}. |
6f3ec223 RP |
5395 | |
5396 | @item @r{Overloaded symbol names} | |
5397 | You can specify a particular definition of an overloaded symbol, using | |
93918348 | 5398 | the same notation that is used to declare such symbols in C++: type |
6f3ec223 | 5399 | @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can |
93918348 | 5400 | also use the @value{GDBN} command-line word completion facilities to list the |
6f3ec223 | 5401 | available choices, or to finish the type list for you. |
93928b60 | 5402 | @xref{Completion,, Command completion}, for details on how to do this. |
b80282d5 RP |
5403 | @end table |
5404 | ||
4eb4cf57 | 5405 | @node Modula-2 |
c2bbbb22 RP |
5406 | @subsection Modula-2 |
5407 | @cindex Modula-2 | |
5408 | ||
ed447b95 RP |
5409 | The extensions made to @value{GDBN} to support Modula-2 only support |
5410 | output from the GNU Modula-2 compiler (which is currently being | |
5411 | developed). Other Modula-2 compilers are not currently supported, and | |
5412 | attempting to debug executables produced by them will most likely | |
5413 | result in an error as @value{GDBN} reads in the executable's symbol | |
5414 | table. | |
c2bbbb22 RP |
5415 | |
5416 | @cindex expressions in Modula-2 | |
5417 | @menu | |
5418 | * M2 Operators:: Built-in operators | |
ed447b95 RP |
5419 | * Built-In Func/Proc:: Built-in functions and procedures |
5420 | * M2 Constants:: Modula-2 constants | |
c2bbbb22 RP |
5421 | * M2 Defaults:: Default settings for Modula-2 |
5422 | * Deviations:: Deviations from standard Modula-2 | |
ed447b95 | 5423 | * M2 Checks:: Modula-2 type and range checks |
c2bbbb22 | 5424 | * M2 Scope:: The scope operators @code{::} and @code{.} |
18fae2a8 | 5425 | * GDB/M2:: @value{GDBN} and Modula-2 |
c2bbbb22 RP |
5426 | @end menu |
5427 | ||
4eb4cf57 | 5428 | @node M2 Operators |
c2bbbb22 RP |
5429 | @subsubsection Operators |
5430 | @cindex Modula-2 operators | |
5431 | ||
5432 | Operators must be defined on values of specific types. For instance, | |
5433 | @code{+} is defined on numbers, but not on structures. Operators are | |
5434 | often defined on groups of types. For the purposes of Modula-2, the | |
5435 | following definitions hold: | |
5436 | ||
5437 | @itemize @bullet | |
5438 | ||
5439 | @item | |
5440 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
5441 | their subranges. | |
5442 | ||
5443 | @item | |
5444 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
5445 | ||
5446 | @item | |
5447 | @emph{Floating-point types} consist of @code{REAL}. | |
5448 | ||
5449 | @item | |
5450 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
5451 | @var{type}}. | |
5452 | ||
5453 | @item | |
5454 | @emph{Scalar types} consist of all of the above. | |
5455 | ||
5456 | @item | |
9aa964da | 5457 | @emph{Set types} consist of @code{SET} and @code{BITSET} types. |
c2bbbb22 RP |
5458 | |
5459 | @item | |
5460 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
c2bbbb22 RP |
5461 | @end itemize |
5462 | ||
5463 | @noindent | |
5464 | The following operators are supported, and appear in order of | |
5465 | increasing precedence: | |
5466 | ||
5467 | @table @code | |
c2bbbb22 RP |
5468 | @item , |
5469 | Function argument or array index separator. | |
18fae2a8 | 5470 | |
c2bbbb22 RP |
5471 | @item := |
5472 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
5473 | @var{value}. | |
5474 | ||
5475 | @item <@r{, }> | |
5476 | Less than, greater than on integral, floating-point, or enumerated | |
5477 | types. | |
5478 | ||
5479 | @item <=@r{, }>= | |
5480 | Less than, greater than, less than or equal to, greater than or equal to | |
5481 | on integral, floating-point and enumerated types, or set inclusion on | |
5482 | set types. Same precedence as @code{<}. | |
5483 | ||
5484 | @item =@r{, }<>@r{, }# | |
5485 | Equality and two ways of expressing inequality, valid on scalar types. | |
18fae2a8 | 5486 | Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is |
c2bbbb22 RP |
5487 | available for inequality, since @code{#} conflicts with the script |
5488 | comment character. | |
5489 | ||
5490 | @item IN | |
5491 | Set membership. Defined on set types and the types of their members. | |
5492 | Same precedence as @code{<}. | |
5493 | ||
5494 | @item OR | |
5495 | Boolean disjunction. Defined on boolean types. | |
5496 | ||
5497 | @item AND@r{, }& | |
5498 | Boolean conjuction. Defined on boolean types. | |
5499 | ||
5500 | @item @@ | |
18fae2a8 | 5501 | The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}). |
c2bbbb22 RP |
5502 | |
5503 | @item +@r{, }- | |
5504 | Addition and subtraction on integral and floating-point types, or union | |
5505 | and difference on set types. | |
5506 | ||
5507 | @item * | |
5508 | Multiplication on integral and floating-point types, or set intersection | |
5509 | on set types. | |
5510 | ||
5511 | @item / | |
5512 | Division on floating-point types, or symmetric set difference on set | |
5513 | types. Same precedence as @code{*}. | |
5514 | ||
5515 | @item DIV@r{, }MOD | |
5516 | Integer division and remainder. Defined on integral types. Same | |
5517 | precedence as @code{*}. | |
5518 | ||
5519 | @item - | |
9aa964da | 5520 | Negative. Defined on @code{INTEGER} and @code{REAL} data. |
c2bbbb22 RP |
5521 | |
5522 | @item ^ | |
e251e767 | 5523 | Pointer dereferencing. Defined on pointer types. |
c2bbbb22 RP |
5524 | |
5525 | @item NOT | |
5526 | Boolean negation. Defined on boolean types. Same precedence as | |
5527 | @code{^}. | |
5528 | ||
5529 | @item . | |
9aa964da | 5530 | @code{RECORD} field selector. Defined on @code{RECORD} data. Same |
c2bbbb22 RP |
5531 | precedence as @code{^}. |
5532 | ||
5533 | @item [] | |
9aa964da | 5534 | Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}. |
c2bbbb22 RP |
5535 | |
5536 | @item () | |
9aa964da | 5537 | Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence |
c2bbbb22 RP |
5538 | as @code{^}. |
5539 | ||
5540 | @item ::@r{, }. | |
18fae2a8 | 5541 | @value{GDBN} and Modula-2 scope operators. |
c2bbbb22 RP |
5542 | @end table |
5543 | ||
5544 | @quotation | |
18fae2a8 | 5545 | @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN} |
c2bbbb22 RP |
5546 | will treat the use of the operator @code{IN}, or the use of operators |
5547 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
5548 | @code{<=}, and @code{>=} on sets as an error. | |
5549 | @end quotation | |
18fae2a8 | 5550 | |
29a2b744 | 5551 | @cindex Modula-2 built-ins |
4eb4cf57 | 5552 | @node Built-In Func/Proc |
93928b60 | 5553 | @subsubsection Built-in functions and procedures |
c2bbbb22 RP |
5554 | |
5555 | Modula-2 also makes available several built-in procedures and functions. | |
5556 | In describing these, the following metavariables are used: | |
5557 | ||
5558 | @table @var | |
5559 | ||
5560 | @item a | |
5561 | represents an @code{ARRAY} variable. | |
5562 | ||
5563 | @item c | |
5564 | represents a @code{CHAR} constant or variable. | |
5565 | ||
5566 | @item i | |
5567 | represents a variable or constant of integral type. | |
5568 | ||
5569 | @item m | |
5570 | represents an identifier that belongs to a set. Generally used in the | |
5571 | same function with the metavariable @var{s}. The type of @var{s} should | |
5572 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
5573 | ||
5574 | @item n | |
5575 | represents a variable or constant of integral or floating-point type. | |
5576 | ||
5577 | @item r | |
5578 | represents a variable or constant of floating-point type. | |
5579 | ||
5580 | @item t | |
5581 | represents a type. | |
5582 | ||
5583 | @item v | |
5584 | represents a variable. | |
5585 | ||
5586 | @item x | |
5587 | represents a variable or constant of one of many types. See the | |
5588 | explanation of the function for details. | |
c2bbbb22 RP |
5589 | @end table |
5590 | ||
5591 | All Modula-2 built-in procedures also return a result, described below. | |
5592 | ||
5593 | @table @code | |
5594 | @item ABS(@var{n}) | |
5595 | Returns the absolute value of @var{n}. | |
5596 | ||
5597 | @item CAP(@var{c}) | |
5598 | If @var{c} is a lower case letter, it returns its upper case | |
5599 | equivalent, otherwise it returns its argument | |
5600 | ||
5601 | @item CHR(@var{i}) | |
5602 | Returns the character whose ordinal value is @var{i}. | |
5603 | ||
5604 | @item DEC(@var{v}) | |
5605 | Decrements the value in the variable @var{v}. Returns the new value. | |
5606 | ||
5607 | @item DEC(@var{v},@var{i}) | |
5608 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5609 | new value. | |
5610 | ||
5611 | @item EXCL(@var{m},@var{s}) | |
5612 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5613 | set. | |
5614 | ||
5615 | @item FLOAT(@var{i}) | |
5616 | Returns the floating point equivalent of the integer @var{i}. | |
5617 | ||
5618 | @item HIGH(@var{a}) | |
5619 | Returns the index of the last member of @var{a}. | |
5620 | ||
5621 | @item INC(@var{v}) | |
5622 | Increments the value in the variable @var{v}. Returns the new value. | |
5623 | ||
5624 | @item INC(@var{v},@var{i}) | |
5625 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5626 | new value. | |
5627 | ||
5628 | @item INCL(@var{m},@var{s}) | |
5629 | Adds the element @var{m} to the set @var{s} if it is not already | |
5630 | there. Returns the new set. | |
5631 | ||
5632 | @item MAX(@var{t}) | |
5633 | Returns the maximum value of the type @var{t}. | |
5634 | ||
5635 | @item MIN(@var{t}) | |
5636 | Returns the minimum value of the type @var{t}. | |
5637 | ||
5638 | @item ODD(@var{i}) | |
5639 | Returns boolean TRUE if @var{i} is an odd number. | |
5640 | ||
5641 | @item ORD(@var{x}) | |
5642 | Returns the ordinal value of its argument. For example, the ordinal | |
5643 | value of a character is its ASCII value (on machines supporting the | |
5644 | ASCII character set). @var{x} must be of an ordered type, which include | |
5645 | integral, character and enumerated types. | |
5646 | ||
5647 | @item SIZE(@var{x}) | |
5648 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5649 | ||
5650 | @item TRUNC(@var{r}) | |
5651 | Returns the integral part of @var{r}. | |
5652 | ||
5653 | @item VAL(@var{t},@var{i}) | |
5654 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5655 | @end table | |
5656 | ||
5657 | @quotation | |
5658 | @emph{Warning:} Sets and their operations are not yet supported, so | |
18fae2a8 | 5659 | @value{GDBN} will treat the use of procedures @code{INCL} and @code{EXCL} as |
c2bbbb22 RP |
5660 | an error. |
5661 | @end quotation | |
5662 | ||
5663 | @cindex Modula-2 constants | |
4eb4cf57 | 5664 | @node M2 Constants |
c2bbbb22 RP |
5665 | @subsubsection Constants |
5666 | ||
18fae2a8 | 5667 | @value{GDBN} allows you to express the constants of Modula-2 in the following |
c2bbbb22 RP |
5668 | ways: |
5669 | ||
5670 | @itemize @bullet | |
5671 | ||
5672 | @item | |
5673 | Integer constants are simply a sequence of digits. When used in an | |
5674 | expression, a constant is interpreted to be type-compatible with the | |
5675 | rest of the expression. Hexadecimal integers are specified by a | |
5676 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5677 | ||
5678 | @item | |
5679 | Floating point constants appear as a sequence of digits, followed by a | |
5680 | decimal point and another sequence of digits. An optional exponent can | |
5681 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5682 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5683 | digits of the floating point constant must be valid decimal (base 10) | |
5684 | digits. | |
5685 | ||
5686 | @item | |
5687 | Character constants consist of a single character enclosed by a pair of | |
5688 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5689 | also be expressed by their ordinal value (their ASCII value, usually) | |
5690 | followed by a @samp{C}. | |
5691 | ||
5692 | @item | |
1041a570 RP |
5693 | String constants consist of a sequence of characters enclosed by a |
5694 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5695 | Escape sequences in the style of C are also allowed. @xref{C | |
93928b60 | 5696 | Constants, ,C and C++ constants}, for a brief explanation of escape |
1041a570 | 5697 | sequences. |
c2bbbb22 RP |
5698 | |
5699 | @item | |
5700 | Enumerated constants consist of an enumerated identifier. | |
5701 | ||
5702 | @item | |
5703 | Boolean constants consist of the identifiers @code{TRUE} and | |
5704 | @code{FALSE}. | |
5705 | ||
5706 | @item | |
5707 | Pointer constants consist of integral values only. | |
5708 | ||
5709 | @item | |
5710 | Set constants are not yet supported. | |
c2bbbb22 RP |
5711 | @end itemize |
5712 | ||
4eb4cf57 | 5713 | @node M2 Defaults |
93928b60 | 5714 | @subsubsection Modula-2 defaults |
c2bbbb22 RP |
5715 | @cindex Modula-2 defaults |
5716 | ||
18fae2a8 | 5717 | If type and range checking are set automatically by @value{GDBN}, they |
e251e767 | 5718 | both default to @code{on} whenever the working language changes to |
18fae2a8 | 5719 | Modula-2. This happens regardless of whether you, or @value{GDBN}, |
c2bbbb22 RP |
5720 | selected the working language. |
5721 | ||
18fae2a8 | 5722 | If you allow @value{GDBN} to set the language automatically, then entering |
c2bbbb22 | 5723 | code compiled from a file whose name ends with @file{.mod} will set the |
18fae2a8 | 5724 | working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set |
c2bbbb22 RP |
5725 | the language automatically}, for further details. |
5726 | ||
4eb4cf57 | 5727 | @node Deviations |
93928b60 | 5728 | @subsubsection Deviations from standard Modula-2 |
c2bbbb22 RP |
5729 | @cindex Modula-2, deviations from |
5730 | ||
5731 | A few changes have been made to make Modula-2 programs easier to debug. | |
5732 | This is done primarily via loosening its type strictness: | |
5733 | ||
5734 | @itemize @bullet | |
e251e767 | 5735 | @item |
c2bbbb22 RP |
5736 | Unlike in standard Modula-2, pointer constants can be formed by |
5737 | integers. This allows you to modify pointer variables during | |
5738 | debugging. (In standard Modula-2, the actual address contained in a | |
5739 | pointer variable is hidden from you; it can only be modified | |
5740 | through direct assignment to another pointer variable or expression that | |
5741 | returned a pointer.) | |
5742 | ||
e251e767 | 5743 | @item |
c2bbbb22 | 5744 | C escape sequences can be used in strings and characters to represent |
18fae2a8 | 5745 | non-printable characters. @value{GDBN} will print out strings with these |
c2bbbb22 RP |
5746 | escape sequences embedded. Single non-printable characters are |
5747 | printed using the @samp{CHR(@var{nnn})} format. | |
5748 | ||
5749 | @item | |
5750 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5751 | argument. | |
5752 | ||
5753 | @item | |
29a2b744 | 5754 | All built-in procedures both modify @emph{and} return their argument. |
e251e767 | 5755 | @end itemize |
c2bbbb22 | 5756 | |
4eb4cf57 | 5757 | @node M2 Checks |
93928b60 | 5758 | @subsubsection Modula-2 type and range checks |
c2bbbb22 RP |
5759 | @cindex Modula-2 checks |
5760 | ||
5761 | @quotation | |
18fae2a8 | 5762 | @emph{Warning:} in this release, @value{GDBN} does not yet perform type or |
c2bbbb22 RP |
5763 | range checking. |
5764 | @end quotation | |
5765 | @c FIXME remove warning when type/range checks added | |
5766 | ||
18fae2a8 | 5767 | @value{GDBN} considers two Modula-2 variables type equivalent if: |
c2bbbb22 RP |
5768 | |
5769 | @itemize @bullet | |
5770 | @item | |
5771 | They are of types that have been declared equivalent via a @code{TYPE | |
5772 | @var{t1} = @var{t2}} statement | |
5773 | ||
5774 | @item | |
5775 | They have been declared on the same line. (Note: This is true of the | |
5776 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
c2bbbb22 RP |
5777 | @end itemize |
5778 | ||
5779 | As long as type checking is enabled, any attempt to combine variables | |
5780 | whose types are not equivalent is an error. | |
5781 | ||
5782 | Range checking is done on all mathematical operations, assignment, array | |
29a2b744 | 5783 | index bounds, and all built-in functions and procedures. |
c2bbbb22 | 5784 | |
4eb4cf57 | 5785 | @node M2 Scope |
c2bbbb22 RP |
5786 | @subsubsection The scope operators @code{::} and @code{.} |
5787 | @cindex scope | |
5788 | @kindex . | |
e94b4a2b | 5789 | @cindex colon, doubled as scope operator |
1041a570 RP |
5790 | @ifinfo |
5791 | @kindex colon-colon | |
ed447b95 | 5792 | @c Info cannot handle :: but TeX can. |
1041a570 RP |
5793 | @end ifinfo |
5794 | @iftex | |
c2bbbb22 | 5795 | @kindex :: |
1041a570 | 5796 | @end iftex |
c2bbbb22 RP |
5797 | |
5798 | There are a few subtle differences between the Modula-2 scope operator | |
18fae2a8 | 5799 | (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have |
c2bbbb22 RP |
5800 | similar syntax: |
5801 | ||
5802 | @example | |
5803 | ||
5804 | @var{module} . @var{id} | |
5805 | @var{scope} :: @var{id} | |
c2bbbb22 RP |
5806 | @end example |
5807 | ||
5808 | @noindent | |
5809 | where @var{scope} is the name of a module or a procedure, | |
29a2b744 RP |
5810 | @var{module} the name of a module, and @var{id} is any declared |
5811 | identifier within your program, except another module. | |
c2bbbb22 | 5812 | |
18fae2a8 | 5813 | Using the @code{::} operator makes @value{GDBN} search the scope |
c2bbbb22 | 5814 | specified by @var{scope} for the identifier @var{id}. If it is not |
18fae2a8 | 5815 | found in the specified scope, then @value{GDBN} will search all scopes |
c2bbbb22 RP |
5816 | enclosing the one specified by @var{scope}. |
5817 | ||
18fae2a8 | 5818 | Using the @code{.} operator makes @value{GDBN} search the current scope for |
c2bbbb22 RP |
5819 | the identifier specified by @var{id} that was imported from the |
5820 | definition module specified by @var{module}. With this operator, it is | |
5821 | an error if the identifier @var{id} was not imported from definition | |
5822 | module @var{module}, or if @var{id} is not an identifier in | |
5823 | @var{module}. | |
5824 | ||
4eb4cf57 | 5825 | @node GDB/M2 |
18fae2a8 | 5826 | @subsubsection @value{GDBN} and Modula-2 |
c2bbbb22 | 5827 | |
18fae2a8 | 5828 | Some @value{GDBN} commands have little use when debugging Modula-2 programs. |
c2bbbb22 RP |
5829 | Five subcommands of @code{set print} and @code{show print} apply |
5830 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5831 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
93918348 | 5832 | apply to C++, and the last to the C @code{union} type, which has no direct |
c2bbbb22 RP |
5833 | analogue in Modula-2. |
5834 | ||
1041a570 | 5835 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available |
c2bbbb22 RP |
5836 | while using any language, is not useful with Modula-2. Its |
5837 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5838 | created in Modula-2 as they can in C or C++. However, because an | |
5839 | address can be specified by an integral constant, the construct | |
1041a570 | 5840 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) |
18fae2a8 | 5841 | |
c2bbbb22 | 5842 | @cindex @code{#} in Modula-2 |
18fae2a8 | 5843 | In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is |
c2bbbb22 | 5844 | interpreted as the beginning of a comment. Use @code{<>} instead. |
18fae2a8 RP |
5845 | |
5846 | @end ifclear | |
4eb4cf57 RP |
5847 | |
5848 | @node Symbols | |
70b88761 RP |
5849 | @chapter Examining the Symbol Table |
5850 | ||
5851 | The commands described in this section allow you to inquire about the | |
5852 | symbols (names of variables, functions and types) defined in your | |
5853 | program. This information is inherent in the text of your program and | |
18fae2a8 RP |
5854 | does not change as your program executes. @value{GDBN} finds it in your |
5855 | program's symbol table, in the file indicated when you started @value{GDBN} | |
93928b60 RP |
5856 | (@pxref{File Options, ,Choosing files}), or by one of the |
5857 | file-management commands (@pxref{Files, ,Commands to specify files}). | |
70b88761 | 5858 | |
6c380b13 RP |
5859 | @c FIXME! This might be intentionally specific to C and C++; if so, move |
5860 | @c to someplace in C section of lang chapter. | |
5861 | @cindex symbol names | |
5862 | @cindex names of symbols | |
5863 | @cindex quoting names | |
5864 | Occasionally, you may need to refer to symbols that contain unusual | |
18fae2a8 | 5865 | characters, which @value{GDBN} ordinarily treats as word delimiters. The |
6c380b13 | 5866 | most frequent case is in referring to static variables in other |
93928b60 | 5867 | source files (@pxref{Variables,,Program variables}). File names |
18fae2a8 | 5868 | are recorded in object files as debugging symbols, but @value{GDBN} would |
6c380b13 | 5869 | ordinarily parse a typical file name, like @file{foo.c}, as the three words |
18fae2a8 | 5870 | @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize |
6c380b13 RP |
5871 | @samp{foo.c} as a single symbol, enclose it in single quotes; for example, |
5872 | ||
5873 | @example | |
5874 | p 'foo.c'::x | |
5875 | @end example | |
5876 | ||
5877 | @noindent | |
5878 | looks up the value of @code{x} in the scope of the file @file{foo.c}. | |
5879 | ||
70b88761 RP |
5880 | @table @code |
5881 | @item info address @var{symbol} | |
5882 | @kindex info address | |
5883 | Describe where the data for @var{symbol} is stored. For a register | |
5884 | variable, this says which register it is kept in. For a non-register | |
5885 | local variable, this prints the stack-frame offset at which the variable | |
5886 | is always stored. | |
5887 | ||
5888 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5889 | at all for a register variables, and for a stack local variable prints | |
5890 | the exact address of the current instantiation of the variable. | |
5891 | ||
5892 | @item whatis @var{exp} | |
5893 | @kindex whatis | |
5894 | Print the data type of expression @var{exp}. @var{exp} is not | |
5895 | actually evaluated, and any side-effecting operations (such as | |
5896 | assignments or function calls) inside it do not take place. | |
1041a570 | 5897 | @xref{Expressions, ,Expressions}. |
70b88761 RP |
5898 | |
5899 | @item whatis | |
5900 | Print the data type of @code{$}, the last value in the value history. | |
5901 | ||
5902 | @item ptype @var{typename} | |
5903 | @kindex ptype | |
5904 | Print a description of data type @var{typename}. @var{typename} may be | |
5905 | the name of a type, or for C code it may have the form | |
5906 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
1041a570 | 5907 | @samp{enum @var{enum-tag}}. |
70b88761 RP |
5908 | |
5909 | @item ptype @var{exp} | |
e0dacfd1 | 5910 | @itemx ptype |
70b88761 | 5911 | Print a description of the type of expression @var{exp}. @code{ptype} |
1041a570 | 5912 | differs from @code{whatis} by printing a detailed description, instead |
ed447b95 RP |
5913 | of just the name of the type. |
5914 | ||
5915 | For example, for this variable declaration: | |
1041a570 | 5916 | |
70b88761 RP |
5917 | @example |
5918 | struct complex @{double real; double imag;@} v; | |
5919 | @end example | |
1041a570 | 5920 | |
70b88761 | 5921 | @noindent |
ed447b95 | 5922 | the two commands give this output: |
1041a570 | 5923 | |
70b88761 | 5924 | @example |
1041a570 | 5925 | @group |
18fae2a8 | 5926 | (@value{GDBP}) whatis v |
70b88761 | 5927 | type = struct complex |
18fae2a8 | 5928 | (@value{GDBP}) ptype v |
70b88761 RP |
5929 | type = struct complex @{ |
5930 | double real; | |
5931 | double imag; | |
5932 | @} | |
1041a570 | 5933 | @end group |
70b88761 | 5934 | @end example |
1041a570 | 5935 | |
e0dacfd1 RP |
5936 | @noindent |
5937 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5938 | the type of @code{$}, the last value in the value history. | |
70b88761 RP |
5939 | |
5940 | @item info types @var{regexp} | |
5941 | @itemx info types | |
e251e767 | 5942 | @kindex info types |
70b88761 RP |
5943 | Print a brief description of all types whose name matches @var{regexp} |
5944 | (or all types in your program, if you supply no argument). Each | |
5945 | complete typename is matched as though it were a complete line; thus, | |
5946 | @samp{i type value} gives information on all types in your program whose | |
5947 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5948 | information only on types whose complete name is @code{value}. | |
5949 | ||
5950 | This command differs from @code{ptype} in two ways: first, like | |
5951 | @code{whatis}, it does not print a detailed description; second, it | |
5952 | lists all source files where a type is defined. | |
5953 | ||
5954 | @item info source | |
5955 | @kindex info source | |
5956 | Show the name of the current source file---that is, the source file for | |
c2bbbb22 RP |
5957 | the function containing the current point of execution---and the language |
5958 | it was written in. | |
70b88761 RP |
5959 | |
5960 | @item info sources | |
5961 | @kindex info sources | |
29a2b744 | 5962 | Print the names of all source files in your program for which there is |
b80282d5 RP |
5963 | debugging information, organized into two lists: files whose symbols |
5964 | have already been read, and files whose symbols will be read when needed. | |
70b88761 RP |
5965 | |
5966 | @item info functions | |
5967 | @kindex info functions | |
5968 | Print the names and data types of all defined functions. | |
5969 | ||
5970 | @item info functions @var{regexp} | |
5971 | Print the names and data types of all defined functions | |
5972 | whose names contain a match for regular expression @var{regexp}. | |
5973 | Thus, @samp{info fun step} finds all functions whose names | |
5974 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5975 | start with @code{step}. | |
5976 | ||
5977 | @item info variables | |
5978 | @kindex info variables | |
5979 | Print the names and data types of all variables that are declared | |
5980 | outside of functions (i.e., excluding local variables). | |
5981 | ||
5982 | @item info variables @var{regexp} | |
5983 | Print the names and data types of all variables (except for local | |
5984 | variables) whose names contain a match for regular expression | |
5985 | @var{regexp}. | |
5986 | ||
70b88761 RP |
5987 | @ignore |
5988 | This was never implemented. | |
5989 | @item info methods | |
5990 | @itemx info methods @var{regexp} | |
5991 | @kindex info methods | |
5992 | The @code{info methods} command permits the user to examine all defined | |
5993 | methods within C++ program, or (with the @var{regexp} argument) a | |
5994 | specific set of methods found in the various C++ classes. Many | |
5995 | C++ classes provide a large number of methods. Thus, the output | |
5996 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5997 | @code{info-methods} command filters the methods, printing only those | |
5998 | which match the regular-expression @var{regexp}. | |
5999 | @end ignore | |
6000 | ||
d48da190 RP |
6001 | @item maint print symbols @var{filename} |
6002 | @itemx maint print psymbols @var{filename} | |
6003 | @itemx maint print msymbols @var{filename} | |
6004 | @kindex maint print symbols | |
440d9834 | 6005 | @cindex symbol dump |
d48da190 | 6006 | @kindex maint print psymbols |
440d9834 RP |
6007 | @cindex partial symbol dump |
6008 | Write a dump of debugging symbol data into the file @var{filename}. | |
18fae2a8 | 6009 | These commands are used to debug the @value{GDBN} symbol-reading code. Only |
d48da190 | 6010 | symbols with debugging data are included. If you use @samp{maint print |
18fae2a8 | 6011 | symbols}, @value{GDBN} includes all the symbols for which it has already |
d48da190 | 6012 | collected full details: that is, @var{filename} reflects symbols for |
18fae2a8 | 6013 | only those files whose symbols @value{GDBN} has read. You can use the |
d48da190 RP |
6014 | command @code{info sources} to find out which files these are. If you |
6015 | use @samp{maint print psymbols} instead, the dump shows information about | |
18fae2a8 RP |
6016 | symbols that @value{GDBN} only knows partially---that is, symbols defined in |
6017 | files that @value{GDBN} has skimmed, but not yet read completely. Finally, | |
d48da190 | 6018 | @samp{maint print msymbols} dumps just the minimal symbol information |
18fae2a8 RP |
6019 | required for each object file from which @value{GDBN} has read some symbols. |
6020 | The description of @code{symbol-file} explains how @value{GDBN} reads | |
d48da190 | 6021 | symbols; both @code{info source} and @code{symbol-file} are described in |
93928b60 | 6022 | @ref{Files, ,Commands to specify files}. |
70b88761 RP |
6023 | @end table |
6024 | ||
4eb4cf57 | 6025 | @node Altering |
70b88761 RP |
6026 | @chapter Altering Execution |
6027 | ||
29a2b744 | 6028 | Once you think you have found an error in your program, you might want to |
70b88761 RP |
6029 | find out for certain whether correcting the apparent error would lead to |
6030 | correct results in the rest of the run. You can find the answer by | |
18fae2a8 | 6031 | experiment, using the @value{GDBN} features for altering execution of the |
70b88761 RP |
6032 | program. |
6033 | ||
6034 | For example, you can store new values into variables or memory | |
1d7c3357 | 6035 | locations, |
18fae2a8 | 6036 | @ifclear BARETARGET |
1d7c3357 | 6037 | give your program a signal, restart it |
18fae2a8 | 6038 | @end ifclear |
1d7c3357 RP |
6039 | @ifset BARETARGET |
6040 | restart your program | |
6041 | @end ifset | |
6042 | at a different address, or even return prematurely from a function to | |
6043 | its caller. | |
18fae2a8 | 6044 | |
18fae2a8 | 6045 | @menu |
ed447b95 RP |
6046 | * Assignment:: Assignment to variables |
6047 | * Jumping:: Continuing at a different address | |
1d7c3357 | 6048 | @ifclear BARETARGET |
ed447b95 | 6049 | * Signaling:: Giving your program a signal |
18fae2a8 | 6050 | @end ifclear |
b0157555 | 6051 | |
ed447b95 RP |
6052 | * Returning:: Returning from a function |
6053 | * Calling:: Calling your program's functions | |
6054 | * Patching:: Patching your program | |
18fae2a8 | 6055 | @end menu |
70b88761 | 6056 | |
4eb4cf57 | 6057 | @node Assignment |
93928b60 | 6058 | @section Assignment to variables |
70b88761 RP |
6059 | |
6060 | @cindex assignment | |
6061 | @cindex setting variables | |
6062 | To alter the value of a variable, evaluate an assignment expression. | |
1041a570 | 6063 | @xref{Expressions, ,Expressions}. For example, |
70b88761 RP |
6064 | |
6065 | @example | |
6066 | print x=4 | |
6067 | @end example | |
6068 | ||
6069 | @noindent | |
1041a570 | 6070 | stores the value 4 into the variable @code{x}, and then prints the |
4eb4cf57 | 6071 | value of the assignment expression (which is 4). |
18fae2a8 RP |
6072 | @ifclear CONLY |
6073 | @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more | |
4eb4cf57 | 6074 | information on operators in supported languages. |
18fae2a8 | 6075 | @end ifclear |
70b88761 | 6076 | |
70b88761 RP |
6077 | @kindex set variable |
6078 | @cindex variables, setting | |
6079 | If you are not interested in seeing the value of the assignment, use the | |
6080 | @code{set} command instead of the @code{print} command. @code{set} is | |
93928b60 RP |
6081 | really the same as @code{print} except that the expression's value is |
6082 | not printed and is not put in the value history (@pxref{Value History, | |
6083 | ,Value history}). The expression is evaluated only for its effects. | |
70b88761 RP |
6084 | |
6085 | If the beginning of the argument string of the @code{set} command | |
6086 | appears identical to a @code{set} subcommand, use the @code{set | |
6087 | variable} command instead of just @code{set}. This command is identical | |
ed447b95 RP |
6088 | to @code{set} except for its lack of subcommands. For example, if |
6089 | your program has a variable @code{width}, you get | |
6090 | an error if you try to set a new value with just @samp{set width=13}, | |
6091 | because @value{GDBN} has the command @code{set width}: | |
1041a570 | 6092 | |
70b88761 | 6093 | @example |
18fae2a8 | 6094 | (@value{GDBP}) whatis width |
70b88761 | 6095 | type = double |
18fae2a8 | 6096 | (@value{GDBP}) p width |
70b88761 | 6097 | $4 = 13 |
18fae2a8 | 6098 | (@value{GDBP}) set width=47 |
70b88761 RP |
6099 | Invalid syntax in expression. |
6100 | @end example | |
1041a570 | 6101 | |
70b88761 | 6102 | @noindent |
ed447b95 RP |
6103 | The invalid expression, of course, is @samp{=47}. In |
6104 | order to actually set the program's variable @code{width}, use | |
1041a570 | 6105 | |
70b88761 | 6106 | @example |
18fae2a8 | 6107 | (@value{GDBP}) set var width=47 |
70b88761 RP |
6108 | @end example |
6109 | ||
18fae2a8 | 6110 | @value{GDBN} allows more implicit conversions in assignments than C; you can |
1041a570 | 6111 | freely store an integer value into a pointer variable or vice versa, |
ed447b95 | 6112 | and you can convert any structure to any other structure that is the |
1041a570 | 6113 | same length or shorter. |
e251e767 | 6114 | @comment FIXME: how do structs align/pad in these conversions? |
70b88761 RP |
6115 | @comment /[email protected] 18dec1990 |
6116 | ||
6117 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
6118 | construct to generate a value of specified type at a specified address | |
1041a570 | 6119 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers |
70b88761 RP |
6120 | to memory location @code{0x83040} as an integer (which implies a certain size |
6121 | and representation in memory), and | |
6122 | ||
6123 | @example | |
6124 | set @{int@}0x83040 = 4 | |
6125 | @end example | |
6126 | ||
6127 | @noindent | |
6128 | stores the value 4 into that memory location. | |
6129 | ||
4eb4cf57 | 6130 | @node Jumping |
93928b60 | 6131 | @section Continuing at a different address |
70b88761 | 6132 | |
29a2b744 | 6133 | Ordinarily, when you continue your program, you do so at the place where |
70b88761 RP |
6134 | it stopped, with the @code{continue} command. You can instead continue at |
6135 | an address of your own choosing, with the following commands: | |
6136 | ||
6137 | @table @code | |
6138 | @item jump @var{linespec} | |
6139 | @kindex jump | |
6140 | Resume execution at line @var{linespec}. Execution will stop | |
29a2b744 | 6141 | immediately if there is a breakpoint there. @xref{List, ,Printing |
93928b60 | 6142 | source lines}, for a description of the different forms of |
29a2b744 | 6143 | @var{linespec}. |
70b88761 RP |
6144 | |
6145 | The @code{jump} command does not change the current stack frame, or | |
6146 | the stack pointer, or the contents of any memory location or any | |
6147 | register other than the program counter. If line @var{linespec} is in | |
6148 | a different function from the one currently executing, the results may | |
6149 | be bizarre if the two functions expect different patterns of arguments or | |
6150 | of local variables. For this reason, the @code{jump} command requests | |
6151 | confirmation if the specified line is not in the function currently | |
6152 | executing. However, even bizarre results are predictable if you are | |
29a2b744 | 6153 | well acquainted with the machine-language code of your program. |
70b88761 RP |
6154 | |
6155 | @item jump *@var{address} | |
6156 | Resume execution at the instruction at address @var{address}. | |
6157 | @end table | |
6158 | ||
6159 | You can get much the same effect as the @code{jump} command by storing a | |
6160 | new value into the register @code{$pc}. The difference is that this | |
29a2b744 | 6161 | does not start your program running; it only changes the address where it |
70b88761 RP |
6162 | @emph{will} run when it is continued. For example, |
6163 | ||
6164 | @example | |
6165 | set $pc = 0x485 | |
6166 | @end example | |
6167 | ||
6168 | @noindent | |
6169 | causes the next @code{continue} command or stepping command to execute at | |
1041a570 | 6170 | address @code{0x485}, rather than at the address where your program stopped. |
93928b60 | 6171 | @xref{Continuing and Stepping, ,Continuing and stepping}. |
70b88761 RP |
6172 | |
6173 | The most common occasion to use the @code{jump} command is to back up, | |
6174 | perhaps with more breakpoints set, over a portion of a program that has | |
6175 | already executed, in order to examine its execution in more detail. | |
6176 | ||
18fae2a8 | 6177 | @ifclear BARETARGET |
70b88761 | 6178 | @c @group |
ed447b95 RP |
6179 | @node Signaling |
6180 | @section Giving your program a signal | |
70b88761 RP |
6181 | |
6182 | @table @code | |
6183 | @item signal @var{signalnum} | |
6184 | @kindex signal | |
29a2b744 | 6185 | Resume execution where your program stopped, but give it immediately the |
70b88761 RP |
6186 | signal number @var{signalnum}. |
6187 | ||
6188 | Alternatively, if @var{signalnum} is zero, continue execution without | |
29a2b744 | 6189 | giving a signal. This is useful when your program stopped on account of |
70b88761 RP |
6190 | a signal and would ordinary see the signal when resumed with the |
6191 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
6192 | signal. | |
6193 | ||
6194 | @code{signal} does not repeat when you press @key{RET} a second time | |
6195 | after executing the command. | |
6196 | @end table | |
6197 | @c @end group | |
18fae2a8 | 6198 | @end ifclear |
70b88761 | 6199 | |
4eb4cf57 | 6200 | @node Returning |
93928b60 | 6201 | @section Returning from a function |
70b88761 RP |
6202 | |
6203 | @table @code | |
6204 | @item return | |
6205 | @itemx return @var{expression} | |
6206 | @cindex returning from a function | |
6207 | @kindex return | |
6208 | You can cancel execution of a function call with the @code{return} | |
6209 | command. If you give an | |
6210 | @var{expression} argument, its value is used as the function's return | |
e251e767 | 6211 | value. |
70b88761 RP |
6212 | @end table |
6213 | ||
18fae2a8 | 6214 | When you use @code{return}, @value{GDBN} discards the selected stack frame |
70b88761 RP |
6215 | (and all frames within it). You can think of this as making the |
6216 | discarded frame return prematurely. If you wish to specify a value to | |
6217 | be returned, give that value as the argument to @code{return}. | |
6218 | ||
29a2b744 | 6219 | This pops the selected stack frame (@pxref{Selection, ,Selecting a |
93928b60 | 6220 | frame}), and any other frames inside of it, leaving its caller as the |
29a2b744 RP |
6221 | innermost remaining frame. That frame becomes selected. The |
6222 | specified value is stored in the registers used for returning values | |
6223 | of functions. | |
70b88761 RP |
6224 | |
6225 | The @code{return} command does not resume execution; it leaves the | |
6226 | program stopped in the state that would exist if the function had just | |
1041a570 | 6227 | returned. In contrast, the @code{finish} command (@pxref{Continuing |
93928b60 | 6228 | and Stepping, ,Continuing and stepping}) resumes execution until the |
1041a570 | 6229 | selected stack frame returns naturally. |
70b88761 | 6230 | |
4eb4cf57 | 6231 | @node Calling |
ed447b95 | 6232 | @section Calling program functions |
70b88761 RP |
6233 | |
6234 | @cindex calling functions | |
6235 | @kindex call | |
6236 | @table @code | |
6237 | @item call @var{expr} | |
6238 | Evaluate the expression @var{expr} without displaying @code{void} | |
6239 | returned values. | |
6240 | @end table | |
6241 | ||
6242 | You can use this variant of the @code{print} command if you want to | |
6243 | execute a function from your program, but without cluttering the output | |
6244 | with @code{void} returned values. The result is printed and saved in | |
6245 | the value history, if it is not void. | |
6246 | ||
4eb4cf57 | 6247 | @node Patching |
ed447b95 | 6248 | @section Patching programs |
c338a2fd RP |
6249 | @cindex patching binaries |
6250 | @cindex writing into executables | |
1d7c3357 | 6251 | @ifclear BARETARGET |
c338a2fd | 6252 | @cindex writing into corefiles |
1d7c3357 | 6253 | @end ifclear |
1041a570 | 6254 | |
18fae2a8 | 6255 | By default, @value{GDBN} opens the file containing your program's executable |
1d7c3357 RP |
6256 | code |
6257 | @ifclear BARETARGET | |
6258 | (or the corefile) | |
6259 | @end ifclear | |
6260 | read-only. This prevents accidental alterations | |
c338a2fd RP |
6261 | to machine code; but it also prevents you from intentionally patching |
6262 | your program's binary. | |
6263 | ||
6264 | If you'd like to be able to patch the binary, you can specify that | |
6265 | explicitly with the @code{set write} command. For example, you might | |
6266 | want to turn on internal debugging flags, or even to make emergency | |
e251e767 | 6267 | repairs. |
c338a2fd RP |
6268 | |
6269 | @table @code | |
6270 | @item set write on | |
6271 | @itemx set write off | |
6272 | @kindex set write | |
18fae2a8 RP |
6273 | If you specify @samp{set write on}, @value{GDBN} will open executable |
6274 | @ifclear BARETARGET | |
0f153e74 | 6275 | and core |
18fae2a8 | 6276 | @end ifclear |
0f153e74 | 6277 | files for both reading and writing; if you specify @samp{set write |
18fae2a8 | 6278 | off} (the default), @value{GDBN} will open them read-only. |
c338a2fd | 6279 | |
1d7c3357 RP |
6280 | If you have already loaded a file, you must load it again (using the |
6281 | @code{exec-file} | |
6282 | @ifclear BARETARGET | |
6283 | or @code{core-file} | |
6284 | @end ifclear | |
6285 | command) after changing @code{set write}, for your new setting to take | |
6286 | effect. | |
c338a2fd RP |
6287 | |
6288 | @item show write | |
7d7ff5f6 | 6289 | @kindex show write |
0f153e74 | 6290 | Display whether executable files |
18fae2a8 | 6291 | @ifclear BARETARGET |
0f153e74 | 6292 | and core files |
18fae2a8 | 6293 | @end ifclear |
0f153e74 | 6294 | will be opened for writing as well as reading. |
c338a2fd RP |
6295 | @end table |
6296 | ||
18fae2a8 | 6297 | @node GDB Files |
93918348 | 6298 | @chapter @value{GDBN} Files |
70b88761 | 6299 | |
18fae2a8 | 6300 | @value{GDBN} needs to know the file name of the program to be debugged, both in |
4eb4cf57 | 6301 | order to read its symbol table and in order to start your program. |
18fae2a8 | 6302 | @ifclear BARETARGET |
93918348 RP |
6303 | To debug a core dump of a previous run, you must also tell @value{GDBN} |
6304 | the name of the core dump file. | |
18fae2a8 | 6305 | @end ifclear |
1041a570 | 6306 | |
70b88761 | 6307 | @menu |
ed447b95 RP |
6308 | * Files:: Commands to specify files |
6309 | * Symbol Errors:: Errors reading symbol files | |
70b88761 RP |
6310 | @end menu |
6311 | ||
4eb4cf57 | 6312 | @node Files |
93928b60 | 6313 | @section Commands to specify files |
70b88761 | 6314 | @cindex symbol table |
70b88761 | 6315 | |
18fae2a8 | 6316 | @ifclear BARETARGET |
0f153e74 | 6317 | @cindex core dump file |
1041a570 | 6318 | The usual way to specify executable and core dump file names is with |
ed447b95 | 6319 | the command arguments given when you start @value{GDBN} (@pxref{Invocation, |
18fae2a8 RP |
6320 | ,Getting In and Out of @value{GDBN}}. |
6321 | @end ifclear | |
6322 | @ifset BARETARGET | |
4eb4cf57 | 6323 | The usual way to specify an executable file name is with |
18fae2a8 RP |
6324 | the command argument given when you start @value{GDBN}, (@pxref{Invocation, |
6325 | ,Getting In and Out of @value{GDBN}}. | |
6326 | @end ifset | |
70b88761 RP |
6327 | |
6328 | Occasionally it is necessary to change to a different file during a | |
93918348 RP |
6329 | @value{GDBN} session. Or you may run @value{GDBN} and forget to specify |
6330 | a file you want to use. In these situations the @value{GDBN} commands | |
6331 | to specify new files are useful. | |
70b88761 RP |
6332 | |
6333 | @table @code | |
6334 | @item file @var{filename} | |
6335 | @cindex executable file | |
6336 | @kindex file | |
6337 | Use @var{filename} as the program to be debugged. It is read for its | |
6338 | symbols and for the contents of pure memory. It is also the program | |
6339 | executed when you use the @code{run} command. If you do not specify a | |
93918348 | 6340 | directory and the file is not found in the @value{GDBN} working directory, @value{GDBN} |
1041a570 RP |
6341 | uses the environment variable @code{PATH} as a list of directories to |
6342 | search, just as the shell does when looking for a program to run. You | |
18fae2a8 | 6343 | can change the value of this variable, for both @value{GDBN} and your program, |
1041a570 | 6344 | using the @code{path} command. |
70b88761 | 6345 | |
14d01801 RP |
6346 | On systems with memory-mapped files, an auxiliary symbol table file |
6347 | @file{@var{filename}.syms} may be available for @var{filename}. If it | |
18fae2a8 | 6348 | is, @value{GDBN} will map in the symbol table from |
14d01801 | 6349 | @file{@var{filename}.syms}, starting up more quickly. See the |
95d5ceb9 | 6350 | descriptions of the options @samp{-mapped} and @samp{-readnow} (available |
77b46d13 JG |
6351 | on the command line, and with the commands @code{file}, @code{symbol-file}, |
6352 | or @code{add-symbol-file}), for more information. | |
14d01801 | 6353 | |
e0dacfd1 | 6354 | @item file |
18fae2a8 | 6355 | @code{file} with no argument makes @value{GDBN} discard any information it |
70b88761 RP |
6356 | has on both executable file and the symbol table. |
6357 | ||
e0dacfd1 | 6358 | @item exec-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6359 | @kindex exec-file |
6360 | Specify that the program to be run (but not the symbol table) is found | |
18fae2a8 | 6361 | in @var{filename}. @value{GDBN} will search the environment variable @code{PATH} |
29a2b744 | 6362 | if necessary to locate your program. Omitting @var{filename} means to |
e0dacfd1 | 6363 | discard information on the executable file. |
70b88761 | 6364 | |
e0dacfd1 | 6365 | @item symbol-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6366 | @kindex symbol-file |
6367 | Read symbol table information from file @var{filename}. @code{PATH} is | |
6368 | searched when necessary. Use the @code{file} command to get both symbol | |
6369 | table and program to run from the same file. | |
6370 | ||
93918348 | 6371 | @code{symbol-file} with no argument clears out @value{GDBN} information on your |
70b88761 RP |
6372 | program's symbol table. |
6373 | ||
18fae2a8 | 6374 | The @code{symbol-file} command causes @value{GDBN} to forget the contents of its |
70b88761 RP |
6375 | convenience variables, the value history, and all breakpoints and |
6376 | auto-display expressions. This is because they may contain pointers to | |
6377 | the internal data recording symbols and data types, which are part of | |
18fae2a8 | 6378 | the old symbol table data being discarded inside @value{GDBN}. |
70b88761 RP |
6379 | |
6380 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
6381 | executing it once. | |
6382 | ||
18fae2a8 | 6383 | When @value{GDBN} is configured for a particular environment, it will |
14d01801 RP |
6384 | understand debugging information in whatever format is the standard |
6385 | generated for that environment; you may use either a GNU compiler, or | |
6386 | other compilers that adhere to the local conventions. Best results are | |
18fae2a8 | 6387 | usually obtained from GNU compilers; for example, using @code{@value{GCC}} |
14d01801 RP |
6388 | you can generate debugging information for optimized code. |
6389 | ||
70b88761 | 6390 | On some kinds of object files, the @code{symbol-file} command does not |
14d01801 | 6391 | normally read the symbol table in full right away. Instead, it scans |
70b88761 RP |
6392 | the symbol table quickly to find which source files and which symbols |
6393 | are present. The details are read later, one source file at a time, | |
1041a570 | 6394 | as they are needed. |
70b88761 | 6395 | |
18fae2a8 | 6396 | The purpose of this two-stage reading strategy is to make @value{GDBN} start up |
1041a570 RP |
6397 | faster. For the most part, it is invisible except for occasional |
6398 | pauses while the symbol table details for a particular source file are | |
6399 | being read. (The @code{set verbose} command can turn these pauses | |
93928b60 RP |
6400 | into messages if desired. @xref{Messages/Warnings, ,Optional warnings |
6401 | and messages}.) | |
70b88761 | 6402 | |
8c69096b RP |
6403 | We have not implemented the two-stage strategy for COFF yet. When the |
6404 | symbol table is stored in COFF format, @code{symbol-file} reads the | |
6405 | symbol table data in full right away. | |
70b88761 | 6406 | |
95d5ceb9 RP |
6407 | @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
6408 | @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]} | |
14d01801 RP |
6409 | @kindex readnow |
6410 | @cindex reading symbols immediately | |
6411 | @cindex symbols, reading immediately | |
6412 | @kindex mapped | |
6413 | @cindex memory-mapped symbol file | |
38962738 | 6414 | @cindex saving symbol table |
18fae2a8 | 6415 | You can override the @value{GDBN} two-stage strategy for reading symbol |
95d5ceb9 | 6416 | tables by using the @samp{-readnow} option with any of the commands that |
18fae2a8 | 6417 | load symbol table information, if you want to be sure @value{GDBN} has the |
14d01801 RP |
6418 | entire symbol table available. |
6419 | ||
18fae2a8 | 6420 | @ifclear BARETARGET |
14d01801 | 6421 | If memory-mapped files are available on your system through the |
95d5ceb9 | 6422 | @code{mmap} system call, you can use another option, @samp{-mapped}, to |
18fae2a8 RP |
6423 | cause @value{GDBN} to write the symbols for your program into a reusable |
6424 | file. Future @value{GDBN} debugging sessions will map in symbol information | |
93918348 | 6425 | from this auxiliary symbol file (if the program has not changed), rather |
77b46d13 JG |
6426 | than spending time reading the symbol table from the executable |
6427 | program. Using the @samp{-mapped} option has the same effect as | |
18fae2a8 | 6428 | starting @value{GDBN} with the @samp{-mapped} command-line option. |
14d01801 | 6429 | |
95d5ceb9 | 6430 | You can use both options together, to make sure the auxiliary symbol |
14d01801 RP |
6431 | file has all the symbol information for your program. |
6432 | ||
6433 | The auxiliary symbol file for a program called @var{myprog} is called | |
6434 | @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer | |
18fae2a8 | 6435 | than the corresponding executable), @value{GDBN} will always attempt to use |
14d01801 RP |
6436 | it when you debug @var{myprog}; no special options or commands are |
6437 | needed. | |
93918348 RP |
6438 | |
6439 | The @file{.syms} file is specific to the host machine where you run | |
6440 | @value{GDBN}. It holds an exact image of the internal @value{GDB} | |
6441 | symbol table. It cannot be shared across multiple host platforms. | |
6442 | ||
14d01801 RP |
6443 | @c FIXME: for now no mention of directories, since this seems to be in |
6444 | @c flux. 13mar1992 status is that in theory GDB would look either in | |
6445 | @c current dir or in same dir as myprog; but issues like competing | |
6446 | @c GDB's, or clutter in system dirs, mean that in practice right now | |
6447 | @c only current dir is used. FFish says maybe a special GDB hierarchy | |
6448 | @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol | |
6449 | @c files. | |
70b88761 | 6450 | |
e0dacfd1 | 6451 | @item core-file @r{[} @var{filename} @r{]} |
70b88761 RP |
6452 | @kindex core |
6453 | @kindex core-file | |
6454 | Specify the whereabouts of a core dump file to be used as the ``contents | |
6455 | of memory''. Traditionally, core files contain only some parts of the | |
18fae2a8 | 6456 | address space of the process that generated them; @value{GDBN} can access the |
70b88761 RP |
6457 | executable file itself for other parts. |
6458 | ||
6459 | @code{core-file} with no argument specifies that no core file is | |
6460 | to be used. | |
6461 | ||
6462 | Note that the core file is ignored when your program is actually running | |
18fae2a8 | 6463 | under @value{GDBN}. So, if you have been running your program and you wish to |
70b88761 RP |
6464 | debug a core file instead, you must kill the subprocess in which the |
6465 | program is running. To do this, use the @code{kill} command | |
93928b60 | 6466 | (@pxref{Kill Process, ,Killing the child process}). |
18fae2a8 | 6467 | @end ifclear |
70b88761 RP |
6468 | |
6469 | @item load @var{filename} | |
6470 | @kindex load | |
18fae2a8 | 6471 | @ifset GENERIC |
70b88761 | 6472 | Depending on what remote debugging facilities are configured into |
18fae2a8 | 6473 | @value{GDBN}, the @code{load} command may be available. Where it exists, it |
70b88761 RP |
6474 | is meant to make @var{filename} (an executable) available for debugging |
6475 | on the remote system---by downloading, or dynamic linking, for example. | |
93918348 | 6476 | @code{load} also records the @var{filename} symbol table in @value{GDBN}, like |
70b88761 RP |
6477 | the @code{add-symbol-file} command. |
6478 | ||
ed447b95 RP |
6479 | If your @value{GDBN} does not have a @code{load} command, attempting to |
6480 | execute it gets the error message ``@code{You can't do that when your | |
6481 | target is @dots{}}'' | |
18fae2a8 | 6482 | @end ifset |
70b88761 | 6483 | |
18fae2a8 | 6484 | @ifset VXWORKS |
70b88761 | 6485 | On VxWorks, @code{load} will dynamically link @var{filename} on the |
18fae2a8 RP |
6486 | current target system as well as adding its symbols in @value{GDBN}. |
6487 | @end ifset | |
70b88761 | 6488 | |
a64a6c2b | 6489 | @ifset I960 |
70b88761 RP |
6490 | @cindex download to Nindy-960 |
6491 | With the Nindy interface to an Intel 960 board, @code{load} will | |
6492 | download @var{filename} to the 960 as well as adding its symbols in | |
18fae2a8 RP |
6493 | @value{GDBN}. |
6494 | @end ifset | |
70b88761 | 6495 | |
a64a6c2b | 6496 | @ifset H8 |
1d7c3357 RP |
6497 | @cindex download to H8/300 or H8/500 |
6498 | @cindex H8/300 or H8/500 download | |
a64a6c2b RP |
6499 | @c start-sanitize-Hitachi-SH |
6500 | @cindex download to Hitachi SH | |
6501 | @cindex Hitachi SH download | |
6502 | @c end-sanitize-Hitachi-SH | |
6503 | When you select remote debugging to a Hitachi | |
6504 | @c start-sanitize-Hitachi-SH | |
6505 | SH, | |
6506 | @c end-sanitize-Hitachi-SH | |
6507 | H8/300, or H8/500 board | |
6508 | (@pxref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}), | |
1d7c3357 RP |
6509 | the @code{load} command downloads your program to the Hitachi board and also |
6510 | opens it as the current executable target for @value{GDBN} on your host | |
6511 | (like the @code{file} command). | |
18fae2a8 | 6512 | @end ifset |
c7cb8acb | 6513 | |
70b88761 RP |
6514 | @code{load} will not repeat if you press @key{RET} again after using it. |
6515 | ||
18fae2a8 | 6516 | @ifclear BARETARGET |
70b88761 | 6517 | @item add-symbol-file @var{filename} @var{address} |
95d5ceb9 | 6518 | @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]} |
70b88761 RP |
6519 | @kindex add-symbol-file |
6520 | @cindex dynamic linking | |
6521 | The @code{add-symbol-file} command reads additional symbol table information | |
b80282d5 | 6522 | from the file @var{filename}. You would use this command when @var{filename} |
70b88761 RP |
6523 | has been dynamically loaded (by some other means) into the program that |
6524 | is running. @var{address} should be the memory address at which the | |
18fae2a8 | 6525 | file has been loaded; @value{GDBN} cannot figure this out for itself. |
70b88761 RP |
6526 | |
6527 | The symbol table of the file @var{filename} is added to the symbol table | |
6528 | originally read with the @code{symbol-file} command. You can use the | |
6529 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
6530 | read keeps adding to the old. To discard all old symbol data instead, | |
e251e767 | 6531 | use the @code{symbol-file} command. |
70b88761 RP |
6532 | |
6533 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
6534 | ||
95d5ceb9 | 6535 | You can use the @samp{-mapped} and @samp{-readnow} options just as with |
18fae2a8 | 6536 | the @code{symbol-file} command, to change how @value{GDBN} manages the symbol |
0f153e74 | 6537 | table information for @var{filename}. |
18fae2a8 | 6538 | @end ifclear |
95d5ceb9 | 6539 | |
70b88761 RP |
6540 | @item info files |
6541 | @itemx info target | |
6542 | @kindex info files | |
6543 | @kindex info target | |
1041a570 | 6544 | @code{info files} and @code{info target} are synonymous; both print |
1d7c3357 RP |
6545 | the current target (@pxref{Targets, ,Specifying a Debugging Target}), |
6546 | including the | |
6547 | @ifclear BARETARGET | |
6548 | names of the executable and core dump files | |
6549 | @end ifclear | |
6550 | @ifset BARETARGET | |
6551 | name of the executable file | |
6552 | @end ifset | |
6553 | currently in use by @value{GDBN}, and the files from which symbols were | |
6554 | loaded. The command @code{help targets} lists all possible targets | |
6555 | rather than current ones. | |
70b88761 RP |
6556 | @end table |
6557 | ||
6558 | All file-specifying commands allow both absolute and relative file names | |
18fae2a8 | 6559 | as arguments. @value{GDBN} always converts the file name to an absolute path |
70b88761 RP |
6560 | name and remembers it that way. |
6561 | ||
18fae2a8 | 6562 | @ifclear BARETARGET |
70b88761 | 6563 | @cindex shared libraries |
18fae2a8 RP |
6564 | @value{GDBN} supports SunOS, SVR4, and IBM RS/6000 shared libraries. |
6565 | @value{GDBN} automatically loads symbol definitions from shared libraries | |
77b46d13 | 6566 | when you use the @code{run} command, or when you examine a core file. |
18fae2a8 | 6567 | (Before you issue the @code{run} command, @value{GDBN} will not understand |
77b46d13 JG |
6568 | references to a function in a shared library, however---unless you are |
6569 | debugging a core file). | |
18fae2a8 | 6570 | @c FIXME: next @value{GDBN} release should permit some refs to undef |
1041a570 | 6571 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib |
70b88761 RP |
6572 | |
6573 | @table @code | |
70b88761 RP |
6574 | @item info share |
6575 | @itemx info sharedlibrary | |
6576 | @kindex info sharedlibrary | |
6577 | @kindex info share | |
c338a2fd | 6578 | Print the names of the shared libraries which are currently loaded. |
70b88761 | 6579 | |
c338a2fd RP |
6580 | @item sharedlibrary @var{regex} |
6581 | @itemx share @var{regex} | |
6582 | @kindex sharedlibrary | |
6583 | @kindex share | |
6584 | This is an obsolescent command; you can use it to explicitly | |
6585 | load shared object library symbols for files matching a UNIX regular | |
6586 | expression, but as with files loaded automatically, it will only load | |
6587 | shared libraries required by your program for a core file or after | |
6588 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
6589 | required by your program are loaded. | |
6590 | @end table | |
18fae2a8 | 6591 | @end ifclear |
70b88761 | 6592 | |
4eb4cf57 | 6593 | @node Symbol Errors |
93928b60 | 6594 | @section Errors reading symbol files |
1041a570 | 6595 | |
18fae2a8 | 6596 | While reading a symbol file, @value{GDBN} will occasionally encounter problems, |
1041a570 | 6597 | such as symbol types it does not recognize, or known bugs in compiler |
18fae2a8 | 6598 | output. By default, @value{GDBN} does not notify you of such problems, since |
1041a570 RP |
6599 | they are relatively common and primarily of interest to people |
6600 | debugging compilers. If you are interested in seeing information | |
18fae2a8 | 6601 | about ill-constructed symbol tables, you can either ask @value{GDBN} to print |
b80282d5 | 6602 | only one message about each such type of problem, no matter how many |
18fae2a8 | 6603 | times the problem occurs; or you can ask @value{GDBN} to print more messages, |
1041a570 | 6604 | to see how many times the problems occur, with the @code{set |
93928b60 RP |
6605 | complaints} command (@pxref{Messages/Warnings, ,Optional warnings and |
6606 | messages}). | |
70b88761 RP |
6607 | |
6608 | The messages currently printed, and their meanings, are: | |
6609 | ||
6610 | @table @code | |
6611 | @item inner block not inside outer block in @var{symbol} | |
6612 | ||
6613 | The symbol information shows where symbol scopes begin and end | |
6614 | (such as at the start of a function or a block of statements). This | |
6615 | error indicates that an inner scope block is not fully contained | |
e251e767 | 6616 | in its outer scope blocks. |
70b88761 | 6617 | |
18fae2a8 | 6618 | @value{GDBN} circumvents the problem by treating the inner block as if it had |
70b88761 RP |
6619 | the same scope as the outer block. In the error message, @var{symbol} |
6620 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
6621 | function. | |
6622 | ||
6623 | @item block at @var{address} out of order | |
6624 | ||
e251e767 | 6625 | The symbol information for symbol scope blocks should occur in |
70b88761 | 6626 | order of increasing addresses. This error indicates that it does not |
e251e767 | 6627 | do so. |
70b88761 | 6628 | |
ed447b95 RP |
6629 | @value{GDBN} does not circumvent this problem, and will have trouble |
6630 | locating symbols in the source file whose symbols it is reading. (You | |
6631 | can often determine what source file is affected by specifying | |
93928b60 RP |
6632 | @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and |
6633 | messages}.) | |
70b88761 RP |
6634 | |
6635 | @item bad block start address patched | |
6636 | ||
6637 | The symbol information for a symbol scope block has a start address | |
6638 | smaller than the address of the preceding source line. This is known | |
e251e767 | 6639 | to occur in the SunOS 4.1.1 (and earlier) C compiler. |
70b88761 | 6640 | |
18fae2a8 | 6641 | @value{GDBN} circumvents the problem by treating the symbol scope block as |
70b88761 RP |
6642 | starting on the previous source line. |
6643 | ||
70b88761 RP |
6644 | @item bad string table offset in symbol @var{n} |
6645 | ||
6646 | @cindex foo | |
6647 | Symbol number @var{n} contains a pointer into the string table which is | |
e251e767 | 6648 | larger than the size of the string table. |
70b88761 | 6649 | |
18fae2a8 | 6650 | @value{GDBN} circumvents the problem by considering the symbol to have the |
70b88761 RP |
6651 | name @code{foo}, which may cause other problems if many symbols end up |
6652 | with this name. | |
6653 | ||
6654 | @item unknown symbol type @code{0x@var{nn}} | |
6655 | ||
18fae2a8 | 6656 | The symbol information contains new data types that @value{GDBN} does not yet |
70b88761 | 6657 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood |
e251e767 | 6658 | information, in hexadecimal. |
70b88761 | 6659 | |
18fae2a8 | 6660 | @value{GDBN} circumvents the error by ignoring this symbol information. This |
29a2b744 | 6661 | will usually allow your program to be debugged, though certain symbols |
70b88761 | 6662 | will not be accessible. If you encounter such a problem and feel like |
18fae2a8 | 6663 | debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint on |
70b88761 RP |
6664 | @code{complain}, then go up to the function @code{read_dbx_symtab} and |
6665 | examine @code{*bufp} to see the symbol. | |
6666 | ||
6667 | @item stub type has NULL name | |
1d7c3357 RP |
6668 | @value{GDBN} could not find the full definition for |
6669 | @ifclear CONLY | |
6670 | a struct or class. | |
6671 | @end ifclear | |
6672 | @ifset CONLY | |
6673 | a struct. | |
6674 | @end ifset | |
70b88761 | 6675 | |
1d7c3357 | 6676 | @ifclear CONLY |
440d9834 | 6677 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} |
70b88761 RP |
6678 | |
6679 | The symbol information for a C++ member function is missing some | |
440d9834 RP |
6680 | information that recent versions of the compiler should have output |
6681 | for it. | |
1d7c3357 | 6682 | @end ifclear |
70b88761 | 6683 | |
440d9834 | 6684 | @item info mismatch between compiler and debugger |
70b88761 | 6685 | |
18fae2a8 | 6686 | @value{GDBN} could not parse a type specification output by the compiler. |
70b88761 RP |
6687 | @end table |
6688 | ||
4eb4cf57 | 6689 | @node Targets |
e251e767 | 6690 | @chapter Specifying a Debugging Target |
70b88761 RP |
6691 | @cindex debugging target |
6692 | @kindex target | |
1041a570 | 6693 | |
cedaf8bc | 6694 | A @dfn{target} is the execution environment occupied by your program. |
18fae2a8 RP |
6695 | @ifclear BARETARGET |
6696 | Often, @value{GDBN} runs in the same host environment as your program; in | |
1041a570 RP |
6697 | that case, the debugging target is specified as a side effect when you |
6698 | use the @code{file} or @code{core} commands. When you need more | |
18fae2a8 | 6699 | flexibility---for example, running @value{GDBN} on a physically separate |
1041a570 | 6700 | host, or controlling a standalone system over a serial port or a |
0f153e74 | 6701 | realtime system over a TCP/IP connection---you |
18fae2a8 RP |
6702 | @end ifclear |
6703 | @ifset BARETARGET | |
0f153e74 | 6704 | You |
18fae2a8 | 6705 | @end ifset |
0f153e74 | 6706 | can use the @code{target} command to specify one of the target types |
93928b60 RP |
6707 | configured for @value{GDBN} (@pxref{Target Commands, ,Commands for managing |
6708 | targets}). | |
70b88761 RP |
6709 | |
6710 | @menu | |
ed447b95 RP |
6711 | * Active Targets:: Active targets |
6712 | * Target Commands:: Commands for managing targets | |
6713 | * Remote:: Remote debugging | |
70b88761 RP |
6714 | @end menu |
6715 | ||
4eb4cf57 | 6716 | @node Active Targets |
93928b60 | 6717 | @section Active targets |
70b88761 RP |
6718 | @cindex stacking targets |
6719 | @cindex active targets | |
6720 | @cindex multiple targets | |
6721 | ||
18fae2a8 | 6722 | @ifclear BARETARGET |
cedaf8bc | 6723 | There are three classes of targets: processes, core files, and |
18fae2a8 | 6724 | executable files. @value{GDBN} can work concurrently on up to three active |
cedaf8bc RP |
6725 | targets, one in each class. This allows you to (for example) start a |
6726 | process and inspect its activity without abandoning your work on a core | |
6727 | file. | |
70b88761 | 6728 | |
ed447b95 | 6729 | For example, if you execute @samp{gdb a.out}, then the executable file |
cedaf8bc RP |
6730 | @code{a.out} is the only active target. If you designate a core file as |
6731 | well---presumably from a prior run that crashed and coredumped---then | |
18fae2a8 | 6732 | @value{GDBN} has two active targets and will use them in tandem, looking |
cedaf8bc RP |
6733 | first in the corefile target, then in the executable file, to satisfy |
6734 | requests for memory addresses. (Typically, these two classes of target | |
29a2b744 | 6735 | are complementary, since core files contain only a program's |
cedaf8bc RP |
6736 | read-write memory---variables and so on---plus machine status, while |
6737 | executable files contain only the program text and initialized data.) | |
18fae2a8 | 6738 | @end ifclear |
cedaf8bc RP |
6739 | |
6740 | When you type @code{run}, your executable file becomes an active process | |
18fae2a8 | 6741 | target as well. When a process target is active, all @value{GDBN} commands |
0f153e74 | 6742 | requesting memory addresses refer to that target; addresses in an |
18fae2a8 | 6743 | @ifclear BARETARGET |
0f153e74 | 6744 | active core file or |
18fae2a8 | 6745 | @end ifclear |
0f153e74 | 6746 | executable file target are obscured while the process |
cedaf8bc RP |
6747 | target is active. |
6748 | ||
18fae2a8 | 6749 | @ifset BARETARGET |
4eb4cf57 | 6750 | Use the @code{exec-file} command to select a |
93928b60 RP |
6751 | new executable target (@pxref{Files, ,Commands to specify |
6752 | files}). | |
18fae2a8 RP |
6753 | @end ifset |
6754 | @ifclear BARETARGET | |
1041a570 | 6755 | Use the @code{core-file} and @code{exec-file} commands to select a |
93928b60 RP |
6756 | new core file or executable target (@pxref{Files, ,Commands to specify |
6757 | files}). To specify as a target a process that is already running, use | |
1041a570 | 6758 | the @code{attach} command (@pxref{Attach, ,Debugging an |
93928b60 | 6759 | already-running process}). |
18fae2a8 | 6760 | @end ifclear |
70b88761 | 6761 | |
4eb4cf57 | 6762 | @node Target Commands |
93928b60 | 6763 | @section Commands for managing targets |
70b88761 RP |
6764 | |
6765 | @table @code | |
6766 | @item target @var{type} @var{parameters} | |
1d7c3357 RP |
6767 | Connects the @value{GDBN} host environment to a target |
6768 | @ifset BARETARGET | |
6769 | machine. | |
6770 | @end ifset | |
6771 | @ifclear BARETARGET | |
6772 | machine or process. A target is typically a protocol for talking to | |
6773 | debugging facilities. You use the argument @var{type} to specify the | |
6774 | type or protocol of the target machine. | |
70b88761 RP |
6775 | |
6776 | Further @var{parameters} are interpreted by the target protocol, but | |
6777 | typically include things like device names or host names to connect | |
e251e767 | 6778 | with, process numbers, and baud rates. |
1d7c3357 | 6779 | @end ifclear |
70b88761 RP |
6780 | |
6781 | The @code{target} command will not repeat if you press @key{RET} again | |
6782 | after executing the command. | |
6783 | ||
6784 | @item help target | |
6785 | @kindex help target | |
6786 | Displays the names of all targets available. To display targets | |
6787 | currently selected, use either @code{info target} or @code{info files} | |
93928b60 | 6788 | (@pxref{Files, ,Commands to specify files}). |
70b88761 RP |
6789 | |
6790 | @item help target @var{name} | |
6791 | Describe a particular target, including any parameters necessary to | |
6792 | select it. | |
6793 | @end table | |
6794 | ||
c7cb8acb | 6795 | Here are some common targets (available, or not, depending on the GDB |
70b88761 RP |
6796 | configuration): |
6797 | ||
6798 | @table @code | |
fe715d06 | 6799 | @item target exec @var{program} |
70b88761 | 6800 | @kindex target exec |
fe715d06 RP |
6801 | An executable file. @samp{target exec @var{program}} is the same as |
6802 | @samp{exec-file @var{program}}. | |
70b88761 | 6803 | |
1d7c3357 | 6804 | @ifclear BARETARGET |
70b88761 RP |
6805 | @item target core @var{filename} |
6806 | @kindex target core | |
6807 | A core dump file. @samp{target core @var{filename}} is the same as | |
6808 | @samp{core-file @var{filename}}. | |
1d7c3357 | 6809 | @end ifclear |
70b88761 | 6810 | |
18fae2a8 | 6811 | @ifset REMOTESTUB |
70b88761 RP |
6812 | @item target remote @var{dev} |
6813 | @kindex target remote | |
c7cb8acb | 6814 | Remote serial target in GDB-specific protocol. The argument @var{dev} |
70b88761 | 6815 | specifies what serial device to use for the connection (e.g. |
93928b60 | 6816 | @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. |
18fae2a8 | 6817 | @end ifset |
70b88761 | 6818 | |
fe715d06 RP |
6819 | @ifset SIMS |
6820 | @item target sim | |
6821 | @kindex target sim | |
6822 | CPU simulator. @xref{Simulator,,Simulated CPU Target}. | |
6823 | @end ifset | |
6824 | ||
a64a6c2b | 6825 | @ifset AMD29K |
fe715d06 RP |
6826 | @item target udi @var{keyword} |
6827 | @kindex target udi | |
6828 | Remote AMD29K target, using the AMD UDI protocol. The @var{keyword} | |
6829 | argument specifies which 29K board or simulator to use. @xref{UDI29K | |
6830 | Remote,,@value{GDBN} and the UDI protocol for AMD29K}. | |
6831 | ||
70b88761 RP |
6832 | @item target amd-eb @var{dev} @var{speed} @var{PROG} |
6833 | @kindex target amd-eb | |
6834 | @cindex AMD EB29K | |
6835 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6836 | @var{dev} is the serial device, as for @code{target remote}; | |
6837 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6838 | name of the program to be debugged, as it appears to DOS on the PC. | |
ed447b95 | 6839 | @xref{EB29K Remote, ,@value{GDBN} with a remote EB29K}. |
77fe5411 | 6840 | |
18fae2a8 | 6841 | @end ifset |
a64a6c2b | 6842 | @ifset H8 |
c7cb8acb RP |
6843 | @item target hms |
6844 | @kindex target hms | |
a64a6c2b RP |
6845 | A Hitachi |
6846 | @c start-sanitize-Hitachi-SH | |
6847 | SH, | |
6848 | @c end-sanitize-Hitachi-SH | |
6849 | H8/300, or H8/500 board, attached via serial line to your host. | |
6850 | @ifclear H8EXCLUSIVE | |
6851 | @c Unix only, not currently of interest for H8-only manual | |
6852 | Use special commands @code{device} and @code{speed} to control the serial | |
6853 | line and the communications speed used. | |
6854 | @end ifclear | |
6855 | @xref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}. | |
c7cb8acb | 6856 | |
18fae2a8 | 6857 | @end ifset |
a64a6c2b | 6858 | @ifset I960 |
70b88761 RP |
6859 | @item target nindy @var{devicename} |
6860 | @kindex target nindy | |
6861 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6862 | the name of the serial device to use for the connection, e.g. | |
ed447b95 | 6863 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}. |
70b88761 | 6864 | |
18fae2a8 | 6865 | @end ifset |
a64a6c2b | 6866 | @ifset ST2000 |
77fe5411 RP |
6867 | @item target st2000 @var{dev} @var{speed} |
6868 | @kindex target st2000 | |
6869 | A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev} | |
6870 | is the name of the device attached to the ST2000 serial line; | |
6871 | @var{speed} is the communication line speed. The arguments are not used | |
18fae2a8 RP |
6872 | if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet. |
6873 | @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}. | |
77fe5411 | 6874 | |
18fae2a8 RP |
6875 | @end ifset |
6876 | @ifset VXWORKS | |
70b88761 RP |
6877 | @item target vxworks @var{machinename} |
6878 | @kindex target vxworks | |
6879 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6880 | is the target system's machine name or IP address. | |
18fae2a8 RP |
6881 | @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}. |
6882 | @end ifset | |
70b88761 RP |
6883 | @end table |
6884 | ||
18fae2a8 RP |
6885 | @ifset GENERIC |
6886 | Different targets are available on different configurations of @value{GDBN}; your | |
70b88761 | 6887 | configuration may have more or fewer targets. |
18fae2a8 | 6888 | @end ifset |
70b88761 | 6889 | |
4eb4cf57 | 6890 | @node Remote |
93928b60 | 6891 | @section Remote debugging |
70b88761 RP |
6892 | @cindex remote debugging |
6893 | ||
29a2b744 | 6894 | If you are trying to debug a program running on a machine that cannot run |
c7cb8acb | 6895 | GDB in the usual way, it is often useful to use remote debugging. For |
70b88761 RP |
6896 | example, you might use remote debugging on an operating system kernel, or on |
6897 | a small system which does not have a general purpose operating system | |
e251e767 | 6898 | powerful enough to run a full-featured debugger. |
70b88761 | 6899 | |
c7cb8acb | 6900 | Some configurations of GDB have special serial or TCP/IP interfaces |
70b88761 | 6901 | to make this work with particular debugging targets. In addition, |
c7cb8acb | 6902 | GDB comes with a generic serial protocol (specific to GDB, but |
70b88761 RP |
6903 | not specific to any particular target system) which you can use if you |
6904 | write the remote stubs---the code that will run on the remote system to | |
c7cb8acb | 6905 | communicate with GDB. |
70b88761 | 6906 | |
70b88761 | 6907 | Other remote targets may be available in your |
c7cb8acb | 6908 | configuration of GDB; use @code{help targets} to list them. |
70b88761 | 6909 | |
18fae2a8 RP |
6910 | @ifset GENERIC |
6911 | @c Text on starting up GDB in various specific cases; it goes up front | |
6912 | @c in manuals configured for any of those particular situations, here | |
6913 | @c otherwise. | |
18fae2a8 RP |
6914 | @menu |
6915 | @ifset REMOTESTUB | |
6916 | * Remote Serial:: @value{GDBN} remote serial protocol | |
6917 | @end ifset | |
a64a6c2b | 6918 | @ifset I960 |
18fae2a8 RP |
6919 | * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy) |
6920 | @end ifset | |
a64a6c2b | 6921 | @ifset AMD29K |
fe715d06 | 6922 | * UDI29K Remote:: @value{GDBN} and the UDI protocol for AMD29K |
18fae2a8 RP |
6923 | * EB29K Remote:: @value{GDBN} with a remote EB29K |
6924 | @end ifset | |
6925 | @ifset VXWORKS | |
6926 | * VxWorks Remote:: @value{GDBN} and VxWorks | |
6927 | @end ifset | |
a64a6c2b | 6928 | @ifset ST2000 |
18fae2a8 RP |
6929 | * ST2000 Remote:: @value{GDBN} with a Tandem ST2000 |
6930 | @end ifset | |
a64a6c2b RP |
6931 | @ifset H8 |
6932 | * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors | |
18fae2a8 | 6933 | @end ifset |
fe715d06 RP |
6934 | @ifset SIMS |
6935 | * Simulator:: Simulated CPU target | |
18fae2a8 RP |
6936 | @end ifset |
6937 | @end menu | |
70b88761 | 6938 | |
18fae2a8 RP |
6939 | @include gdbinv-s.texi |
6940 | @end ifset | |
6941 | ||
6942 | @node Controlling GDB | |
6943 | @chapter Controlling @value{GDBN} | |
70b88761 | 6944 | |
93918348 | 6945 | You can alter the way @value{GDBN} interacts with you by using |
18fae2a8 | 6946 | the @code{set} command. For commands controlling how @value{GDBN} displays |
93928b60 | 6947 | data, @pxref{Print Settings, ,Print settings}; other settings are described here. |
70b88761 RP |
6948 | |
6949 | @menu | |
b80282d5 | 6950 | * Prompt:: Prompt |
ed447b95 RP |
6951 | * Editing:: Command editing |
6952 | * History:: Command history | |
6953 | * Screen Size:: Screen size | |
b80282d5 | 6954 | * Numbers:: Numbers |
ed447b95 | 6955 | * Messages/Warnings:: Optional warnings and messages |
70b88761 RP |
6956 | @end menu |
6957 | ||
4eb4cf57 | 6958 | @node Prompt |
70b88761 RP |
6959 | @section Prompt |
6960 | @cindex prompt | |
1041a570 | 6961 | |
18fae2a8 RP |
6962 | @value{GDBN} indicates its readiness to read a command by printing a string |
6963 | called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You | |
70b88761 | 6964 | can change the prompt string with the @code{set prompt} command. For |
18fae2a8 | 6965 | instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change |
9aa964da | 6966 | the prompt in one of the @value{GDBN} sessions so that you can always tell which |
70b88761 RP |
6967 | one you are talking to. |
6968 | ||
6969 | @table @code | |
6970 | @item set prompt @var{newprompt} | |
6971 | @kindex set prompt | |
18fae2a8 | 6972 | Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth. |
70b88761 RP |
6973 | @kindex show prompt |
6974 | @item show prompt | |
6975 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6976 | @end table | |
6977 | ||
4eb4cf57 | 6978 | @node Editing |
93928b60 | 6979 | @section Command editing |
70b88761 RP |
6980 | @cindex readline |
6981 | @cindex command line editing | |
1041a570 | 6982 | |
18fae2a8 | 6983 | @value{GDBN} reads its input commands via the @dfn{readline} interface. This |
70b88761 RP |
6984 | GNU library provides consistent behavior for programs which provide a |
6985 | command line interface to the user. Advantages are @code{emacs}-style | |
6986 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6987 | substitution, and a storage and recall of command history across | |
6988 | debugging sessions. | |
6989 | ||
18fae2a8 | 6990 | You may control the behavior of command line editing in @value{GDBN} with the |
e251e767 | 6991 | command @code{set}. |
70b88761 RP |
6992 | |
6993 | @table @code | |
6994 | @kindex set editing | |
6995 | @cindex editing | |
6996 | @item set editing | |
6997 | @itemx set editing on | |
6998 | Enable command line editing (enabled by default). | |
6999 | ||
7000 | @item set editing off | |
7001 | Disable command line editing. | |
7002 | ||
7003 | @kindex show editing | |
7004 | @item show editing | |
7005 | Show whether command line editing is enabled. | |
7006 | @end table | |
7007 | ||
4eb4cf57 | 7008 | @node History |
ed447b95 RP |
7009 | @section Command history |
7010 | ||
7011 | @value{GDBN} can keep track of the commands you type during your | |
7012 | debugging sessions, so that you can be certain of precisely what | |
7013 | happened. Use these commands to manage the @value{GDBN} command | |
7014 | history facility. | |
1041a570 | 7015 | |
70b88761 RP |
7016 | @table @code |
7017 | @cindex history substitution | |
7018 | @cindex history file | |
7019 | @kindex set history filename | |
7020 | @item set history filename @var{fname} | |
18fae2a8 RP |
7021 | Set the name of the @value{GDBN} command history file to @var{fname}. This is |
7022 | the file from which @value{GDBN} will read an initial command history | |
70b88761 RP |
7023 | list or to which it will write this list when it exits. This list is |
7024 | accessed through history expansion or through the history | |
7025 | command editing characters listed below. This file defaults to the | |
7026 | value of the environment variable @code{GDBHISTFILE}, or to | |
7027 | @file{./.gdb_history} if this variable is not set. | |
7028 | ||
7029 | @cindex history save | |
7030 | @kindex set history save | |
7031 | @item set history save | |
7032 | @itemx set history save on | |
7033 | Record command history in a file, whose name may be specified with the | |
7034 | @code{set history filename} command. By default, this option is disabled. | |
7035 | ||
7036 | @item set history save off | |
7037 | Stop recording command history in a file. | |
7038 | ||
7039 | @cindex history size | |
7040 | @kindex set history size | |
7041 | @item set history size @var{size} | |
18fae2a8 | 7042 | Set the number of commands which @value{GDBN} will keep in its history list. |
70b88761 RP |
7043 | This defaults to the value of the environment variable |
7044 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
7045 | @end table | |
7046 | ||
7047 | @cindex history expansion | |
7048 | History expansion assigns special meaning to the character @kbd{!}. | |
ed447b95 | 7049 | @ifset have-readline-appendices |
1041a570 | 7050 | @xref{Event Designators}. |
ed447b95 RP |
7051 | @end ifset |
7052 | ||
70b88761 RP |
7053 | Since @kbd{!} is also the logical not operator in C, history expansion |
7054 | is off by default. If you decide to enable history expansion with the | |
7055 | @code{set history expansion on} command, you may sometimes need to | |
7056 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
7057 | a space or a tab to prevent it from being expanded. The readline | |
7058 | history facilities will not attempt substitution on the strings | |
7059 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
7060 | ||
7061 | The commands to control history expansion are: | |
7062 | ||
7063 | @table @code | |
7064 | ||
7065 | @kindex set history expansion | |
7066 | @item set history expansion on | |
7067 | @itemx set history expansion | |
7068 | Enable history expansion. History expansion is off by default. | |
7069 | ||
7070 | @item set history expansion off | |
7071 | Disable history expansion. | |
7072 | ||
7073 | The readline code comes with more complete documentation of | |
7074 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
e251e767 | 7075 | or @code{vi} may wish to read it. |
ed447b95 | 7076 | @ifset have-readline-appendices |
70b88761 | 7077 | @xref{Command Line Editing}. |
ed447b95 | 7078 | @end ifset |
70b88761 RP |
7079 | |
7080 | @c @group | |
7081 | @kindex show history | |
7082 | @item show history | |
7083 | @itemx show history filename | |
7084 | @itemx show history save | |
7085 | @itemx show history size | |
7086 | @itemx show history expansion | |
18fae2a8 | 7087 | These commands display the state of the @value{GDBN} history parameters. |
70b88761 RP |
7088 | @code{show history} by itself displays all four states. |
7089 | @c @end group | |
70b88761 RP |
7090 | @end table |
7091 | ||
7092 | @table @code | |
7093 | @kindex show commands | |
7094 | @item show commands | |
7095 | Display the last ten commands in the command history. | |
7096 | ||
7097 | @item show commands @var{n} | |
7098 | Print ten commands centered on command number @var{n}. | |
7099 | ||
7100 | @item show commands + | |
7101 | Print ten commands just after the commands last printed. | |
70b88761 RP |
7102 | @end table |
7103 | ||
4eb4cf57 | 7104 | @node Screen Size |
93928b60 | 7105 | @section Screen size |
70b88761 RP |
7106 | @cindex size of screen |
7107 | @cindex pauses in output | |
1041a570 | 7108 | |
a1eff6c2 RP |
7109 | Certain commands to @value{GDBN} may produce large amounts of |
7110 | information output to the screen. To help you read all of it, | |
7111 | @value{GDBN} pauses and asks you for input at the end of each page of | |
7112 | output. Type @key{RET} when you want to continue the output, or @kbd{q} | |
7113 | to discard the remaining output. @value{GDBN} also uses the screen | |
70b88761 RP |
7114 | width setting to determine when to wrap lines of output. Depending on |
7115 | what is being printed, it tries to break the line at a readable place, | |
7116 | rather than simply letting it overflow onto the following line. | |
7117 | ||
18fae2a8 | 7118 | Normally @value{GDBN} knows the size of the screen from the termcap data base |
70b88761 RP |
7119 | together with the value of the @code{TERM} environment variable and the |
7120 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
7121 | you can override it with the @code{set height} and @code{set | |
7122 | width} commands: | |
7123 | ||
7124 | @table @code | |
7125 | @item set height @var{lpp} | |
7126 | @itemx show height | |
7127 | @itemx set width @var{cpl} | |
7128 | @itemx show width | |
7129 | @kindex set height | |
7130 | @kindex set width | |
7131 | @kindex show width | |
7132 | @kindex show height | |
7133 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
7134 | a screen width of @var{cpl} characters. The associated @code{show} | |
7135 | commands display the current settings. | |
7136 | ||
18fae2a8 | 7137 | If you specify a height of zero lines, @value{GDBN} will not pause during output |
70b88761 RP |
7138 | no matter how long the output is. This is useful if output is to a file |
7139 | or to an editor buffer. | |
7140 | @end table | |
7141 | ||
4eb4cf57 | 7142 | @node Numbers |
70b88761 RP |
7143 | @section Numbers |
7144 | @cindex number representation | |
7145 | @cindex entering numbers | |
1041a570 | 7146 | |
18fae2a8 | 7147 | You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by |
70b88761 RP |
7148 | the usual conventions: octal numbers begin with @samp{0}, decimal |
7149 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
7150 | Numbers that begin with none of these are, by default, entered in base | |
7151 | 10; likewise, the default display for numbers---when no particular | |
7152 | format is specified---is base 10. You can change the default base for | |
7153 | both input and output with the @code{set radix} command. | |
7154 | ||
7155 | @table @code | |
7156 | @kindex set radix | |
7157 | @item set radix @var{base} | |
7158 | Set the default base for numeric input and display. Supported choices | |
c2bbbb22 | 7159 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be |
70b88761 RP |
7160 | specified either unambiguously or using the current default radix; for |
7161 | example, any of | |
7162 | ||
7163 | @example | |
c2bbbb22 | 7164 | set radix 1010 |
70b88761 RP |
7165 | set radix 012 |
7166 | set radix 10. | |
7167 | set radix 0xa | |
7168 | @end example | |
7169 | ||
7170 | @noindent | |
7171 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
7172 | will leave the radix unchanged no matter what it was. | |
7173 | ||
7174 | @kindex show radix | |
7175 | @item show radix | |
7176 | Display the current default base for numeric input and display. | |
70b88761 RP |
7177 | @end table |
7178 | ||
4eb4cf57 | 7179 | @node Messages/Warnings |
93928b60 | 7180 | @section Optional warnings and messages |
1041a570 | 7181 | |
18fae2a8 | 7182 | By default, @value{GDBN} is silent about its inner workings. If you are running |
70b88761 | 7183 | on a slow machine, you may want to use the @code{set verbose} command. |
18fae2a8 | 7184 | It will make @value{GDBN} tell you when it does a lengthy internal operation, so |
1041a570 | 7185 | you will not think it has crashed. |
70b88761 | 7186 | |
1041a570 | 7187 | Currently, the messages controlled by @code{set verbose} are those |
d48da190 | 7188 | which announce that the symbol table for a source file is being read; |
93928b60 | 7189 | see @code{symbol-file} in @ref{Files, ,Commands to specify files}. |
70b88761 RP |
7190 | |
7191 | @table @code | |
7192 | @kindex set verbose | |
7193 | @item set verbose on | |
93918348 | 7194 | Enables @value{GDBN} output of certain informational messages. |
70b88761 RP |
7195 | |
7196 | @item set verbose off | |
93918348 | 7197 | Disables @value{GDBN} output of certain informational messages. |
70b88761 RP |
7198 | |
7199 | @kindex show verbose | |
7200 | @item show verbose | |
7201 | Displays whether @code{set verbose} is on or off. | |
7202 | @end table | |
7203 | ||
18fae2a8 | 7204 | By default, if @value{GDBN} encounters bugs in the symbol table of an object |
b80282d5 | 7205 | file, it is silent; but if you are debugging a compiler, you may find |
93928b60 | 7206 | this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}). |
70b88761 RP |
7207 | |
7208 | @table @code | |
7209 | @kindex set complaints | |
7210 | @item set complaints @var{limit} | |
18fae2a8 | 7211 | Permits @value{GDBN} to output @var{limit} complaints about each type of unusual |
70b88761 RP |
7212 | symbols before becoming silent about the problem. Set @var{limit} to |
7213 | zero to suppress all complaints; set it to a large number to prevent | |
7214 | complaints from being suppressed. | |
7215 | ||
7216 | @kindex show complaints | |
7217 | @item show complaints | |
18fae2a8 | 7218 | Displays how many symbol complaints @value{GDBN} is permitted to produce. |
70b88761 RP |
7219 | @end table |
7220 | ||
18fae2a8 | 7221 | By default, @value{GDBN} is cautious, and asks what sometimes seems to be a |
70b88761 RP |
7222 | lot of stupid questions to confirm certain commands. For example, if |
7223 | you try to run a program which is already running: | |
1041a570 | 7224 | |
70b88761 | 7225 | @example |
18fae2a8 | 7226 | (@value{GDBP}) run |
70b88761 | 7227 | The program being debugged has been started already. |
e251e767 | 7228 | Start it from the beginning? (y or n) |
70b88761 RP |
7229 | @end example |
7230 | ||
29a2b744 | 7231 | If you are willing to unflinchingly face the consequences of your own |
70b88761 RP |
7232 | commands, you can disable this ``feature'': |
7233 | ||
7234 | @table @code | |
7235 | @kindex set confirm | |
7236 | @cindex flinching | |
7237 | @cindex confirmation | |
7238 | @cindex stupid questions | |
7239 | @item set confirm off | |
7240 | Disables confirmation requests. | |
7241 | ||
7242 | @item set confirm on | |
7243 | Enables confirmation requests (the default). | |
7244 | ||
7245 | @item show confirm | |
7246 | @kindex show confirm | |
7247 | Displays state of confirmation requests. | |
7248 | @end table | |
7249 | ||
29a2b744 | 7250 | @c FIXME this does not really belong here. But where *does* it belong? |
b80282d5 RP |
7251 | @cindex reloading symbols |
7252 | Some systems allow individual object files that make up your program to | |
7253 | be replaced without stopping and restarting your program. | |
18fae2a8 | 7254 | @ifset VXWORKS |
b80282d5 RP |
7255 | For example, in VxWorks you can simply recompile a defective object file |
7256 | and keep on running. | |
18fae2a8 RP |
7257 | @end ifset |
7258 | If you are running on one of these systems, you can allow @value{GDBN} to | |
1041a570 RP |
7259 | reload the symbols for automatically relinked modules: |
7260 | ||
b80282d5 RP |
7261 | @table @code |
7262 | @kindex set symbol-reloading | |
7263 | @item set symbol-reloading on | |
7264 | Replace symbol definitions for the corresponding source file when an | |
7265 | object file with a particular name is seen again. | |
7266 | ||
7267 | @item set symbol-reloading off | |
1041a570 | 7268 | Do not replace symbol definitions when re-encountering object files of |
29a2b744 | 7269 | the same name. This is the default state; if you are not running on a |
b80282d5 | 7270 | system that permits automatically relinking modules, you should leave |
18fae2a8 | 7271 | @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols |
b80282d5 RP |
7272 | when linking large programs, that may contain several modules (from |
7273 | different directories or libraries) with the same name. | |
7274 | ||
7275 | @item show symbol-reloading | |
7276 | Show the current @code{on} or @code{off} setting. | |
7277 | @end table | |
7278 | ||
4eb4cf57 | 7279 | @node Sequences |
70b88761 RP |
7280 | @chapter Canned Sequences of Commands |
7281 | ||
29a2b744 | 7282 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint |
93928b60 | 7283 | command lists}), @value{GDBN} provides two ways to store sequences of commands |
1041a570 | 7284 | for execution as a unit: user-defined commands and command files. |
70b88761 RP |
7285 | |
7286 | @menu | |
ed447b95 RP |
7287 | * Define:: User-defined commands |
7288 | * Hooks:: User-defined command hooks | |
7289 | * Command Files:: Command files | |
7290 | * Output:: Commands for controlled output | |
70b88761 RP |
7291 | @end menu |
7292 | ||
4eb4cf57 | 7293 | @node Define |
ed447b95 | 7294 | @section User-defined commands |
70b88761 RP |
7295 | |
7296 | @cindex user-defined command | |
18fae2a8 | 7297 | A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which you |
70b88761 RP |
7298 | assign a new name as a command. This is done with the @code{define} |
7299 | command. | |
7300 | ||
7301 | @table @code | |
7302 | @item define @var{commandname} | |
7303 | @kindex define | |
7304 | Define a command named @var{commandname}. If there is already a command | |
7305 | by that name, you are asked to confirm that you want to redefine it. | |
7306 | ||
18fae2a8 | 7307 | The definition of the command is made up of other @value{GDBN} command lines, |
70b88761 RP |
7308 | which are given following the @code{define} command. The end of these |
7309 | commands is marked by a line containing @code{end}. | |
7310 | ||
7311 | @item document @var{commandname} | |
7312 | @kindex document | |
7313 | Give documentation to the user-defined command @var{commandname}. The | |
7314 | command @var{commandname} must already be defined. This command reads | |
7315 | lines of documentation just as @code{define} reads the lines of the | |
7316 | command definition, ending with @code{end}. After the @code{document} | |
7317 | command is finished, @code{help} on command @var{commandname} will print | |
7318 | the documentation you have specified. | |
7319 | ||
7320 | You may use the @code{document} command again to change the | |
7321 | documentation of a command. Redefining the command with @code{define} | |
7322 | does not change the documentation. | |
7323 | ||
7324 | @item help user-defined | |
7325 | @kindex help user-defined | |
7326 | List all user-defined commands, with the first line of the documentation | |
7327 | (if any) for each. | |
7328 | ||
4768ba62 JG |
7329 | @item show user |
7330 | @itemx show user @var{commandname} | |
7331 | @kindex show user | |
18fae2a8 | 7332 | Display the @value{GDBN} commands used to define @var{commandname} (but not its |
70b88761 RP |
7333 | documentation). If no @var{commandname} is given, display the |
7334 | definitions for all user-defined commands. | |
7335 | @end table | |
7336 | ||
7337 | User-defined commands do not take arguments. When they are executed, the | |
7338 | commands of the definition are not printed. An error in any command | |
7339 | stops execution of the user-defined command. | |
7340 | ||
7341 | Commands that would ask for confirmation if used interactively proceed | |
18fae2a8 | 7342 | without asking when used inside a user-defined command. Many @value{GDBN} commands |
70b88761 RP |
7343 | that normally print messages to say what they are doing omit the messages |
7344 | when used in a user-defined command. | |
7345 | ||
35a15d60 | 7346 | @node Hooks |
93928b60 | 7347 | @section User-defined command hooks |
35a15d60 JG |
7348 | @cindex command files |
7349 | ||
7350 | You may define @emph{hooks}, which are a special kind of user-defined | |
7351 | command. Whenever you run the command @samp{foo}, if the user-defined | |
7352 | command @samp{hook-foo} exists, it is executed (with no arguments) | |
7353 | before that command. | |
7354 | ||
1d7c3357 RP |
7355 | In addition, a pseudo-command, @samp{stop} exists. Defining |
7356 | (@samp{hook-stop}) makes the associated commands execute every time | |
7357 | execution stops in your program: before breakpoint commands are run, | |
7358 | displays are printed, or the stack frame is printed. | |
35a15d60 | 7359 | |
1d7c3357 RP |
7360 | @ifclear BARETARGET |
7361 | For example, to ignore @code{SIGALRM} signals while | |
7362 | single-stepping, but treat them normally during normal execution, | |
7363 | you could define: | |
35a15d60 JG |
7364 | |
7365 | @example | |
7366 | define hook-stop | |
7367 | handle SIGALRM nopass | |
7368 | end | |
7369 | ||
7370 | define hook-run | |
7371 | handle SIGALRM pass | |
7372 | end | |
7373 | ||
7374 | define hook-continue | |
7375 | handle SIGLARM pass | |
7376 | end | |
7377 | @end example | |
1d7c3357 | 7378 | @end ifclear |
35a15d60 | 7379 | |
1d7c3357 RP |
7380 | You can define a hook for any single-word command in @value{GDBN}, but |
7381 | not for command aliases; you should define a hook for the basic command | |
7382 | name, e.g. @code{backtrace} rather than @code{bt}. | |
7383 | @c FIXME! So how does Joe User discover whether a command is an alias | |
7384 | @c or not? | |
7385 | If an error occurs during the execution of your hook, execution of | |
7386 | @value{GDBN} commands stops and @value{GDBN} issues a prompt | |
7387 | (before the command that you actually typed had a chance to run). | |
35a15d60 | 7388 | |
93918348 | 7389 | If you try to define a hook which does not match any known command, you |
35a15d60 JG |
7390 | will get a warning from the @code{define} command. |
7391 | ||
4eb4cf57 | 7392 | @node Command Files |
93928b60 | 7393 | @section Command files |
70b88761 RP |
7394 | |
7395 | @cindex command files | |
18fae2a8 | 7396 | A command file for @value{GDBN} is a file of lines that are @value{GDBN} commands. Comments |
70b88761 RP |
7397 | (lines starting with @kbd{#}) may also be included. An empty line in a |
7398 | command file does nothing; it does not mean to repeat the last command, as | |
7399 | it would from the terminal. | |
7400 | ||
7401 | @cindex init file | |
18fae2a8 RP |
7402 | @cindex @file{@value{GDBINIT}} |
7403 | When you start @value{GDBN}, it automatically executes commands from its | |
7404 | @dfn{init files}. These are files named @file{@value{GDBINIT}}. @value{GDBN} reads | |
1041a570 RP |
7405 | the init file (if any) in your home directory and then the init file |
7406 | (if any) in the current working directory. (The init files are not | |
7407 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
51b65b74 RP |
7408 | ,Choosing modes}.) |
7409 | ||
7410 | @ifset GENERIC | |
7411 | @cindex init file name | |
7412 | On some configurations of @value{GDBN}, the init file is known by a | |
7413 | different name (these are typically environments where a specialized | |
7414 | form of GDB may need to coexist with other forms, hence a different name | |
7415 | for the specialized version's init file). These are the environments | |
7416 | with special init file names: | |
7417 | ||
7418 | @itemize @bullet | |
7419 | @kindex .vxgdbinit | |
7420 | @item | |
7421 | VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit} | |
7422 | ||
7423 | @kindex .os68gdbinit | |
7424 | @item | |
7425 | OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit} | |
7426 | ||
7427 | @kindex .esgdbinit | |
7428 | @item | |
7429 | ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit} | |
7430 | @end itemize | |
7431 | @end ifset | |
7432 | ||
7433 | You can also request the execution of a command file with the | |
7434 | @code{source} command: | |
70b88761 RP |
7435 | |
7436 | @table @code | |
7437 | @item source @var{filename} | |
7438 | @kindex source | |
7439 | Execute the command file @var{filename}. | |
7440 | @end table | |
7441 | ||
7442 | The lines in a command file are executed sequentially. They are not | |
7443 | printed as they are executed. An error in any command terminates execution | |
7444 | of the command file. | |
7445 | ||
7446 | Commands that would ask for confirmation if used interactively proceed | |
18fae2a8 | 7447 | without asking when used in a command file. Many @value{GDBN} commands that |
70b88761 RP |
7448 | normally print messages to say what they are doing omit the messages |
7449 | when called from command files. | |
7450 | ||
4eb4cf57 | 7451 | @node Output |
93928b60 | 7452 | @section Commands for controlled output |
70b88761 RP |
7453 | |
7454 | During the execution of a command file or a user-defined command, normal | |
18fae2a8 | 7455 | @value{GDBN} output is suppressed; the only output that appears is what is |
70b88761 RP |
7456 | explicitly printed by the commands in the definition. This section |
7457 | describes three commands useful for generating exactly the output you | |
7458 | want. | |
7459 | ||
7460 | @table @code | |
7461 | @item echo @var{text} | |
7462 | @kindex echo | |
29a2b744 RP |
7463 | @c I do not consider backslash-space a standard C escape sequence |
7464 | @c because it is not in ANSI. | |
1041a570 RP |
7465 | Print @var{text}. Nonprinting characters can be included in |
7466 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
7467 | newline. @strong{No newline will be printed unless you specify one.} | |
7468 | In addition to the standard C escape sequences, a backslash followed | |
ed447b95 | 7469 | by a space stands for a space. This is useful for displaying a |
1041a570 RP |
7470 | string with spaces at the beginning or the end, since leading and |
7471 | trailing spaces are otherwise trimmed from all arguments. | |
7472 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
7473 | @samp{echo \@w{ }and foo = \@w{ }}. | |
70b88761 RP |
7474 | |
7475 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7476 | the command onto subsequent lines. For example, | |
7477 | ||
7478 | @example | |
7479 | echo This is some text\n\ | |
7480 | which is continued\n\ | |
7481 | onto several lines.\n | |
7482 | @end example | |
7483 | ||
7484 | produces the same output as | |
7485 | ||
7486 | @example | |
7487 | echo This is some text\n | |
7488 | echo which is continued\n | |
7489 | echo onto several lines.\n | |
7490 | @end example | |
7491 | ||
7492 | @item output @var{expression} | |
7493 | @kindex output | |
7494 | Print the value of @var{expression} and nothing but that value: no | |
7495 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
1041a570 | 7496 | value history either. @xref{Expressions, ,Expressions}, for more information on |
e251e767 | 7497 | expressions. |
70b88761 RP |
7498 | |
7499 | @item output/@var{fmt} @var{expression} | |
7500 | Print the value of @var{expression} in format @var{fmt}. You can use | |
ed447b95 RP |
7501 | the same formats as for @code{print}. @xref{Output Formats,,Output |
7502 | formats}, for more information. | |
70b88761 RP |
7503 | |
7504 | @item printf @var{string}, @var{expressions}@dots{} | |
7505 | @kindex printf | |
7506 | Print the values of the @var{expressions} under the control of | |
7507 | @var{string}. The @var{expressions} are separated by commas and may | |
7508 | be either numbers or pointers. Their values are printed as specified | |
29a2b744 | 7509 | by @var{string}, exactly as if your program were to execute |
70b88761 RP |
7510 | |
7511 | @example | |
7512 | printf (@var{string}, @var{expressions}@dots{}); | |
7513 | @end example | |
7514 | ||
7515 | For example, you can print two values in hex like this: | |
7516 | ||
0fd24984 | 7517 | @smallexample |
70b88761 | 7518 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo |
0fd24984 | 7519 | @end smallexample |
70b88761 RP |
7520 | |
7521 | The only backslash-escape sequences that you can use in the format | |
7522 | string are the simple ones that consist of backslash followed by a | |
7523 | letter. | |
7524 | @end table | |
7525 | ||
18fae2a8 | 7526 | @ifclear DOSHOST |
4eb4cf57 | 7527 | @node Emacs |
18fae2a8 | 7528 | @chapter Using @value{GDBN} under GNU Emacs |
70b88761 RP |
7529 | |
7530 | @cindex emacs | |
7531 | A special interface allows you to use GNU Emacs to view (and | |
7532 | edit) the source files for the program you are debugging with | |
18fae2a8 | 7533 | @value{GDBN}. |
70b88761 RP |
7534 | |
7535 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
7536 | executable file you want to debug as an argument. This command starts | |
18fae2a8 | 7537 | @value{GDBN} as a subprocess of Emacs, with input and output through a newly |
70b88761 RP |
7538 | created Emacs buffer. |
7539 | ||
18fae2a8 | 7540 | Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two |
70b88761 RP |
7541 | things: |
7542 | ||
7543 | @itemize @bullet | |
7544 | @item | |
e251e767 | 7545 | All ``terminal'' input and output goes through the Emacs buffer. |
70b88761 RP |
7546 | @end itemize |
7547 | ||
18fae2a8 | 7548 | This applies both to @value{GDBN} commands and their output, and to the input |
70b88761 RP |
7549 | and output done by the program you are debugging. |
7550 | ||
7551 | This is useful because it means that you can copy the text of previous | |
7552 | commands and input them again; you can even use parts of the output | |
7553 | in this way. | |
7554 | ||
3d3ab540 RP |
7555 | All the facilities of Emacs' Shell mode are available for interacting |
7556 | with your program. In particular, you can send signals the usual | |
7557 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
7558 | stop. | |
70b88761 RP |
7559 | |
7560 | @itemize @bullet | |
7561 | @item | |
18fae2a8 | 7562 | @value{GDBN} displays source code through Emacs. |
70b88761 RP |
7563 | @end itemize |
7564 | ||
18fae2a8 RP |
7565 | Each time @value{GDBN} displays a stack frame, Emacs automatically finds the |
7566 | source file for that frame and puts an arrow (@samp{=>}) at the | |
70b88761 | 7567 | left margin of the current line. Emacs uses a separate buffer for |
fe715d06 | 7568 | source display, and splits the screen to show both your @value{GDBN} session |
70b88761 RP |
7569 | and the source. |
7570 | ||
18fae2a8 | 7571 | Explicit @value{GDBN} @code{list} or search commands still produce output as |
70b88761 RP |
7572 | usual, but you probably will have no reason to use them. |
7573 | ||
7574 | @quotation | |
7575 | @emph{Warning:} If the directory where your program resides is not your | |
7576 | current directory, it can be easy to confuse Emacs about the location of | |
7577 | the source files, in which case the auxiliary display buffer will not | |
18fae2a8 RP |
7578 | appear to show your source. @value{GDBN} can find programs by searching your |
7579 | environment's @code{PATH} variable, so the @value{GDBN} input and output | |
29a2b744 | 7580 | session will proceed normally; but Emacs does not get enough information |
18fae2a8 RP |
7581 | back from @value{GDBN} to locate the source files in this situation. To |
7582 | avoid this problem, either start @value{GDBN} mode from the directory where | |
70b88761 RP |
7583 | your program resides, or specify a full path name when prompted for the |
7584 | @kbd{M-x gdb} argument. | |
7585 | ||
18fae2a8 | 7586 | A similar confusion can result if you use the @value{GDBN} @code{file} command to |
70b88761 | 7587 | switch to debugging a program in some other location, from an existing |
18fae2a8 | 7588 | @value{GDBN} buffer in Emacs. |
70b88761 RP |
7589 | @end quotation |
7590 | ||
7591 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
18fae2a8 | 7592 | you need to call @value{GDBN} by a different name (for example, if you keep |
70b88761 RP |
7593 | several configurations around, with different names) you can set the |
7594 | Emacs variable @code{gdb-command-name}; for example, | |
1041a570 | 7595 | |
70b88761 RP |
7596 | @example |
7597 | (setq gdb-command-name "mygdb") | |
7598 | @end example | |
1041a570 | 7599 | |
70b88761 RP |
7600 | @noindent |
7601 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
7602 | in your @file{.emacs} file) will make Emacs call the program named | |
7603 | ``@code{mygdb}'' instead. | |
7604 | ||
18fae2a8 | 7605 | In the @value{GDBN} I/O buffer, you can use these special Emacs commands in |
70b88761 RP |
7606 | addition to the standard Shell mode commands: |
7607 | ||
7608 | @table @kbd | |
7609 | @item C-h m | |
18fae2a8 | 7610 | Describe the features of Emacs' @value{GDBN} Mode. |
70b88761 RP |
7611 | |
7612 | @item M-s | |
18fae2a8 | 7613 | Execute to another source line, like the @value{GDBN} @code{step} command; also |
70b88761 RP |
7614 | update the display window to show the current file and location. |
7615 | ||
7616 | @item M-n | |
7617 | Execute to next source line in this function, skipping all function | |
18fae2a8 | 7618 | calls, like the @value{GDBN} @code{next} command. Then update the display window |
70b88761 RP |
7619 | to show the current file and location. |
7620 | ||
7621 | @item M-i | |
18fae2a8 | 7622 | Execute one instruction, like the @value{GDBN} @code{stepi} command; update |
70b88761 RP |
7623 | display window accordingly. |
7624 | ||
7625 | @item M-x gdb-nexti | |
18fae2a8 | 7626 | Execute to next instruction, using the @value{GDBN} @code{nexti} command; update |
70b88761 RP |
7627 | display window accordingly. |
7628 | ||
7629 | @item C-c C-f | |
18fae2a8 | 7630 | Execute until exit from the selected stack frame, like the @value{GDBN} |
70b88761 RP |
7631 | @code{finish} command. |
7632 | ||
7633 | @item M-c | |
18fae2a8 | 7634 | Continue execution of your program, like the @value{GDBN} @code{continue} |
1041a570 | 7635 | command. |
203eea5d RP |
7636 | |
7637 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
70b88761 RP |
7638 | |
7639 | @item M-u | |
7640 | Go up the number of frames indicated by the numeric argument | |
7641 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
18fae2a8 | 7642 | like the @value{GDBN} @code{up} command. |
203eea5d | 7643 | |
1041a570 | 7644 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. |
70b88761 RP |
7645 | |
7646 | @item M-d | |
7647 | Go down the number of frames indicated by the numeric argument, like the | |
18fae2a8 | 7648 | @value{GDBN} @code{down} command. |
203eea5d RP |
7649 | |
7650 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
70b88761 RP |
7651 | |
7652 | @item C-x & | |
7653 | Read the number where the cursor is positioned, and insert it at the end | |
18fae2a8 | 7654 | of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code |
70b88761 RP |
7655 | around an address that was displayed earlier, type @kbd{disassemble}; |
7656 | then move the cursor to the address display, and pick up the | |
e251e767 | 7657 | argument for @code{disassemble} by typing @kbd{C-x &}. |
70b88761 | 7658 | |
ed447b95 | 7659 | You can customize this further by defining elements of the list |
70b88761 RP |
7660 | @code{gdb-print-command}; once it is defined, you can format or |
7661 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
c2bbbb22 | 7662 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you |
70b88761 RP |
7663 | wish special formatting, and act as an index to pick an element of the |
7664 | list. If the list element is a string, the number to be inserted is | |
7665 | formatted using the Emacs function @code{format}; otherwise the number | |
7666 | is passed as an argument to the corresponding list element. | |
70b88761 RP |
7667 | @end table |
7668 | ||
7669 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
18fae2a8 | 7670 | tells @value{GDBN} to set a breakpoint on the source line point is on. |
70b88761 RP |
7671 | |
7672 | If you accidentally delete the source-display buffer, an easy way to get | |
18fae2a8 | 7673 | it back is to type the command @code{f} in the @value{GDBN} buffer, to |
70b88761 RP |
7674 | request a frame display; when you run under Emacs, this will recreate |
7675 | the source buffer if necessary to show you the context of the current | |
7676 | frame. | |
7677 | ||
7678 | The source files displayed in Emacs are in ordinary Emacs buffers | |
7679 | which are visiting the source files in the usual way. You can edit | |
18fae2a8 | 7680 | the files with these buffers if you wish; but keep in mind that @value{GDBN} |
70b88761 | 7681 | communicates with Emacs in terms of line numbers. If you add or |
18fae2a8 | 7682 | delete lines from the text, the line numbers that @value{GDBN} knows will cease |
ed447b95 | 7683 | to correspond properly with the code. |
70b88761 RP |
7684 | |
7685 | @c The following dropped because Epoch is nonstandard. Reactivate | |
7686 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
7687 | @ignore | |
e251e767 | 7688 | @kindex emacs epoch environment |
70b88761 RP |
7689 | @kindex epoch |
7690 | @kindex inspect | |
7691 | ||
7692 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
7693 | environment. Users of this environment can use a new command, | |
7694 | @code{inspect} which performs identically to @code{print} except that | |
7695 | each value is printed in its own window. | |
7696 | @end ignore | |
18fae2a8 | 7697 | @end ifclear |
70b88761 | 7698 | |
18fae2a8 | 7699 | @ifset LUCID |
4eb4cf57 | 7700 | @node Energize |
18fae2a8 | 7701 | @chapter Using @value{GDBN} with Energize |
6ca72cc6 RP |
7702 | |
7703 | @cindex Energize | |
7704 | The Energize Programming System is an integrated development environment | |
7705 | that includes a point-and-click interface to many programming tools. | |
18fae2a8 RP |
7706 | When you use @value{GDBN} in this environment, you can use the standard |
7707 | Energize graphical interface to drive @value{GDBN}; you can also, if you | |
7708 | choose, type @value{GDBN} commands as usual in a debugging window. Even if | |
6ca72cc6 | 7709 | you use the graphical interface, the debugging window (which uses Emacs, |
18fae2a8 | 7710 | and resembles the standard Emacs interface to @value{GDBN}) displays the |
6ca72cc6 RP |
7711 | equivalent commands, so that the history of your debugging session is |
7712 | properly reflected. | |
7713 | ||
18fae2a8 | 7714 | When Energize starts up a @value{GDBN} session, it uses one of the |
6ca72cc6 RP |
7715 | command-line options @samp{-energize} or @samp{-cadillac} (``cadillac'' |
7716 | is the name of the communications protocol used by the Energize system). | |
18fae2a8 | 7717 | This option makes @value{GDBN} run as one of the tools in the Energize Tool |
6ca72cc6 RP |
7718 | Set: it sends all output to the Energize kernel, and accept input from |
7719 | it as well. | |
7720 | ||
7721 | See the user manual for the Energize Programming System for | |
7722 | information on how to use the Energize graphical interface and the other | |
18fae2a8 | 7723 | development tools that Energize integrates with @value{GDBN}. |
6ca72cc6 | 7724 | |
18fae2a8 | 7725 | @end ifset |
4eb4cf57 | 7726 | |
18fae2a8 RP |
7727 | @node GDB Bugs |
7728 | @chapter Reporting Bugs in @value{GDBN} | |
ed447b95 RP |
7729 | @cindex bugs in @value{GDBN} |
7730 | @cindex reporting bugs in @value{GDBN} | |
70b88761 | 7731 | |
18fae2a8 | 7732 | Your bug reports play an essential role in making @value{GDBN} reliable. |
70b88761 RP |
7733 | |
7734 | Reporting a bug may help you by bringing a solution to your problem, or it | |
7735 | may not. But in any case the principal function of a bug report is to help | |
18fae2a8 RP |
7736 | the entire community by making the next version of @value{GDBN} work better. Bug |
7737 | reports are your contribution to the maintenance of @value{GDBN}. | |
70b88761 RP |
7738 | |
7739 | In order for a bug report to serve its purpose, you must include the | |
7740 | information that enables us to fix the bug. | |
7741 | ||
7742 | @menu | |
ed447b95 RP |
7743 | * Bug Criteria:: Have you found a bug? |
7744 | * Bug Reporting:: How to report bugs | |
70b88761 RP |
7745 | @end menu |
7746 | ||
4eb4cf57 | 7747 | @node Bug Criteria |
93928b60 | 7748 | @section Have you found a bug? |
ed447b95 | 7749 | @cindex bug criteria |
70b88761 RP |
7750 | |
7751 | If you are not sure whether you have found a bug, here are some guidelines: | |
7752 | ||
7753 | @itemize @bullet | |
7754 | @item | |
0f153e74 | 7755 | @cindex fatal signal |
1d7c3357 RP |
7756 | @cindex debugger crash |
7757 | @cindex crash of debugger | |
70b88761 | 7758 | If the debugger gets a fatal signal, for any input whatever, that is a |
18fae2a8 | 7759 | @value{GDBN} bug. Reliable debuggers never crash. |
70b88761 RP |
7760 | |
7761 | @item | |
0f153e74 | 7762 | @cindex error on valid input |
18fae2a8 | 7763 | If @value{GDBN} produces an error message for valid input, that is a bug. |
70b88761 RP |
7764 | |
7765 | @item | |
ed447b95 | 7766 | @cindex invalid input |
18fae2a8 | 7767 | If @value{GDBN} does not produce an error message for invalid input, |
70b88761 RP |
7768 | that is a bug. However, you should note that your idea of |
7769 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
7770 | for traditional practice''. | |
7771 | ||
7772 | @item | |
7773 | If you are an experienced user of debugging tools, your suggestions | |
18fae2a8 | 7774 | for improvement of @value{GDBN} are welcome in any case. |
70b88761 RP |
7775 | @end itemize |
7776 | ||
4eb4cf57 | 7777 | @node Bug Reporting |
93928b60 | 7778 | @section How to report bugs |
0f153e74 | 7779 | @cindex bug reports |
18fae2a8 | 7780 | @cindex @value{GDBN} bugs, reporting |
70b88761 RP |
7781 | |
7782 | A number of companies and individuals offer support for GNU products. | |
18fae2a8 | 7783 | If you obtained @value{GDBN} from a support organization, we recommend you |
e251e767 | 7784 | contact that organization first. |
70b88761 | 7785 | |
ed447b95 RP |
7786 | You can find contact information for many support companies and |
7787 | individuals in the file @file{etc/SERVICE} in the GNU Emacs | |
7788 | distribution. | |
70b88761 | 7789 | |
18fae2a8 | 7790 | In any event, we also recommend that you send bug reports for @value{GDBN} to one |
70b88761 RP |
7791 | of these addresses: |
7792 | ||
7793 | @example | |
7794 | bug-gdb@@prep.ai.mit.edu | |
7795 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
7796 | @end example | |
7797 | ||
7798 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
18fae2a8 | 7799 | @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do not want to |
70b88761 RP |
7800 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. |
7801 | ||
3d3ab540 RP |
7802 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which |
7803 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
7804 | the same messages. Often people think of posting bug reports to the | |
7805 | newsgroup instead of mailing them. This appears to work, but it has one | |
7806 | problem which can be crucial: a newsgroup posting often lacks a mail | |
7807 | path back to the sender. Thus, if we need to ask for more information, | |
7808 | we may be unable to reach you. For this reason, it is better to send | |
7809 | bug reports to the mailing list. | |
70b88761 RP |
7810 | |
7811 | As a last resort, send bug reports on paper to: | |
7812 | ||
7813 | @example | |
7814 | GNU Debugger Bugs | |
3d3ab540 | 7815 | Free Software Foundation |
70b88761 RP |
7816 | 545 Tech Square |
7817 | Cambridge, MA 02139 | |
7818 | @end example | |
7819 | ||
7820 | The fundamental principle of reporting bugs usefully is this: | |
7821 | @strong{report all the facts}. If you are not sure whether to state a | |
7822 | fact or leave it out, state it! | |
7823 | ||
7824 | Often people omit facts because they think they know what causes the | |
29a2b744 | 7825 | problem and assume that some details do not matter. Thus, you might |
70b88761 | 7826 | assume that the name of the variable you use in an example does not matter. |
29a2b744 | 7827 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a |
70b88761 RP |
7828 | stray memory reference which happens to fetch from the location where that |
7829 | name is stored in memory; perhaps, if the name were different, the contents | |
7830 | of that location would fool the debugger into doing the right thing despite | |
7831 | the bug. Play it safe and give a specific, complete example. That is the | |
7832 | easiest thing for you to do, and the most helpful. | |
7833 | ||
7834 | Keep in mind that the purpose of a bug report is to enable us to fix | |
1041a570 | 7835 | the bug if it is new to us. It is not as important as what happens if |
70b88761 RP |
7836 | the bug is already known. Therefore, always write your bug reports on |
7837 | the assumption that the bug has not been reported previously. | |
7838 | ||
7839 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
7840 | bell?'' Those bug reports are useless, and we urge everyone to | |
7841 | @emph{refuse to respond to them} except to chide the sender to report | |
7842 | bugs properly. | |
7843 | ||
7844 | To enable us to fix the bug, you should include all these things: | |
7845 | ||
7846 | @itemize @bullet | |
7847 | @item | |
18fae2a8 | 7848 | The version of @value{GDBN}. @value{GDBN} announces it if you start with no |
70b88761 RP |
7849 | arguments; you can also print it at any time using @code{show version}. |
7850 | ||
1041a570 | 7851 | Without this, we will not know whether there is any point in looking for |
18fae2a8 | 7852 | the bug in the current version of @value{GDBN}. |
70b88761 RP |
7853 | |
7854 | @item | |
ddf21240 JG |
7855 | The type of machine you are using, and the operating system name and |
7856 | version number. | |
70b88761 RP |
7857 | |
7858 | @item | |
18fae2a8 RP |
7859 | What compiler (and its version) was used to compile @value{GDBN}---e.g. |
7860 | ``@value{GCC}--2.0''. | |
70b88761 | 7861 | |
ddf21240 JG |
7862 | @item |
7863 | What compiler (and its version) was used to compile the program you | |
18fae2a8 | 7864 | are debugging---e.g. ``@value{GCC}--2.0''. |
ddf21240 | 7865 | |
70b88761 RP |
7866 | @item |
7867 | The command arguments you gave the compiler to compile your example and | |
7868 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
1041a570 | 7869 | you will not omit something important, list them all. A copy of the |
ddf21240 | 7870 | Makefile (or the output from make) is sufficient. |
70b88761 RP |
7871 | |
7872 | If we were to try to guess the arguments, we would probably guess wrong | |
7873 | and then we might not encounter the bug. | |
7874 | ||
7875 | @item | |
ddf21240 JG |
7876 | A complete input script, and all necessary source files, that will |
7877 | reproduce the bug. | |
70b88761 RP |
7878 | |
7879 | @item | |
7880 | A description of what behavior you observe that you believe is | |
7881 | incorrect. For example, ``It gets a fatal signal.'' | |
7882 | ||
18fae2a8 | 7883 | Of course, if the bug is that @value{GDBN} gets a fatal signal, then we will |
70b88761 RP |
7884 | certainly notice it. But if the bug is incorrect output, we might not |
7885 | notice unless it is glaringly wrong. We are human, after all. You | |
7886 | might as well not give us a chance to make a mistake. | |
7887 | ||
7888 | Even if the problem you experience is a fatal signal, you should still | |
7889 | say so explicitly. Suppose something strange is going on, such as, | |
18fae2a8 | 7890 | your copy of @value{GDBN} is out of synch, or you have encountered a |
70b88761 RP |
7891 | bug in the C library on your system. (This has happened!) Your copy |
7892 | might crash and ours would not. If you told us to expect a crash, | |
7893 | then when ours fails to crash, we would know that the bug was not | |
7894 | happening for us. If you had not told us to expect a crash, then we | |
7895 | would not be able to draw any conclusion from our observations. | |
7896 | ||
7897 | @item | |
18fae2a8 RP |
7898 | If you wish to suggest changes to the @value{GDBN} source, send us context |
7899 | diffs. If you even discuss something in the @value{GDBN} source, refer to | |
70b88761 RP |
7900 | it by context, not by line number. |
7901 | ||
1041a570 | 7902 | The line numbers in our development sources will not match those in your |
70b88761 | 7903 | sources. Your line numbers would convey no useful information to us. |
70b88761 RP |
7904 | @end itemize |
7905 | ||
7906 | Here are some things that are not necessary: | |
7907 | ||
7908 | @itemize @bullet | |
7909 | @item | |
7910 | A description of the envelope of the bug. | |
7911 | ||
7912 | Often people who encounter a bug spend a lot of time investigating | |
7913 | which changes to the input file will make the bug go away and which | |
7914 | changes will not affect it. | |
7915 | ||
7916 | This is often time consuming and not very useful, because the way we | |
7917 | will find the bug is by running a single example under the debugger | |
7918 | with breakpoints, not by pure deduction from a series of examples. | |
7919 | We recommend that you save your time for something else. | |
7920 | ||
7921 | Of course, if you can find a simpler example to report @emph{instead} | |
7922 | of the original one, that is a convenience for us. Errors in the | |
7923 | output will be easier to spot, running under the debugger will take | |
e251e767 | 7924 | less time, etc. |
70b88761 | 7925 | |
29a2b744 | 7926 | However, simplification is not vital; if you do not want to do this, |
70b88761 RP |
7927 | report the bug anyway and send us the entire test case you used. |
7928 | ||
7929 | @item | |
7930 | A patch for the bug. | |
7931 | ||
29a2b744 | 7932 | A patch for the bug does help us if it is a good one. But do not omit |
70b88761 RP |
7933 | the necessary information, such as the test case, on the assumption that |
7934 | a patch is all we need. We might see problems with your patch and decide | |
7935 | to fix the problem another way, or we might not understand it at all. | |
7936 | ||
18fae2a8 | 7937 | Sometimes with a program as complicated as @value{GDBN} it is very hard to |
70b88761 | 7938 | construct an example that will make the program follow a certain path |
1041a570 RP |
7939 | through the code. If you do not send us the example, we will not be able |
7940 | to construct one, so we will not be able to verify that the bug is fixed. | |
70b88761 | 7941 | |
29a2b744 | 7942 | And if we cannot understand what bug you are trying to fix, or why your |
1041a570 | 7943 | patch should be an improvement, we will not install it. A test case will |
70b88761 RP |
7944 | help us to understand. |
7945 | ||
7946 | @item | |
7947 | A guess about what the bug is or what it depends on. | |
7948 | ||
29a2b744 | 7949 | Such guesses are usually wrong. Even we cannot guess right about such |
70b88761 RP |
7950 | things without first using the debugger to find the facts. |
7951 | @end itemize | |
7952 | ||
ed447b95 | 7953 | @ifset have-readline-appendices |
cacf5942 RP |
7954 | @include rluser.texinfo |
7955 | @include inc-hist.texi | |
ed447b95 | 7956 | @end ifset |
70b88761 | 7957 | |
18fae2a8 | 7958 | @ifset NOVEL |
4eb4cf57 | 7959 | @node Renamed Commands |
70b88761 RP |
7960 | @appendix Renamed Commands |
7961 | ||
c7cb8acb | 7962 | The following commands were renamed in GDB 4, in order to make the |
70b88761 RP |
7963 | command set as a whole more consistent and easier to use and remember: |
7964 | ||
e251e767 RP |
7965 | @kindex add-syms |
7966 | @kindex delete environment | |
7967 | @kindex info copying | |
7968 | @kindex info convenience | |
7969 | @kindex info directories | |
7970 | @kindex info editing | |
7971 | @kindex info history | |
7972 | @kindex info targets | |
7973 | @kindex info values | |
7974 | @kindex info version | |
7975 | @kindex info warranty | |
7976 | @kindex set addressprint | |
7977 | @kindex set arrayprint | |
7978 | @kindex set prettyprint | |
7979 | @kindex set screen-height | |
7980 | @kindex set screen-width | |
7981 | @kindex set unionprint | |
7982 | @kindex set vtblprint | |
7983 | @kindex set demangle | |
7984 | @kindex set asm-demangle | |
7985 | @kindex set sevenbit-strings | |
7986 | @kindex set array-max | |
7987 | @kindex set caution | |
7988 | @kindex set history write | |
7989 | @kindex show addressprint | |
7990 | @kindex show arrayprint | |
7991 | @kindex show prettyprint | |
7992 | @kindex show screen-height | |
7993 | @kindex show screen-width | |
7994 | @kindex show unionprint | |
7995 | @kindex show vtblprint | |
7996 | @kindex show demangle | |
7997 | @kindex show asm-demangle | |
7998 | @kindex show sevenbit-strings | |
7999 | @kindex show array-max | |
8000 | @kindex show caution | |
8001 | @kindex show history write | |
8002 | @kindex unset | |
70b88761 | 8003 | |
92b73793 | 8004 | @c TEXI2ROFF-KILL |
70b88761 | 8005 | @ifinfo |
92b73793 | 8006 | @c END TEXI2ROFF-KILL |
cf496415 RP |
8007 | @example |
8008 | OLD COMMAND NEW COMMAND | |
92b73793 | 8009 | @c TEXI2ROFF-KILL |
cf496415 | 8010 | --------------- ------------------------------- |
92b73793 | 8011 | @c END TEXI2ROFF-KILL |
cf496415 RP |
8012 | add-syms add-symbol-file |
8013 | delete environment unset environment | |
8014 | info convenience show convenience | |
8015 | info copying show copying | |
e251e767 | 8016 | info directories show directories |
cf496415 RP |
8017 | info editing show commands |
8018 | info history show values | |
8019 | info targets help target | |
8020 | info values show values | |
8021 | info version show version | |
8022 | info warranty show warranty | |
8023 | set/show addressprint set/show print address | |
8024 | set/show array-max set/show print elements | |
8025 | set/show arrayprint set/show print array | |
8026 | set/show asm-demangle set/show print asm-demangle | |
8027 | set/show caution set/show confirm | |
8028 | set/show demangle set/show print demangle | |
8029 | set/show history write set/show history save | |
8030 | set/show prettyprint set/show print pretty | |
8031 | set/show screen-height set/show height | |
8032 | set/show screen-width set/show width | |
8033 | set/show sevenbit-strings set/show print sevenbit-strings | |
8034 | set/show unionprint set/show print union | |
8035 | set/show vtblprint set/show print vtbl | |
8036 | ||
8037 | unset [No longer an alias for delete] | |
8038 | @end example | |
92b73793 | 8039 | @c TEXI2ROFF-KILL |
70b88761 RP |
8040 | @end ifinfo |
8041 | ||
8042 | @tex | |
8043 | \vskip \parskip\vskip \baselineskip | |
8044 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
8045 | {\bf Old Command} &&{\bf New Command}\cr | |
8046 | add-syms &&add-symbol-file\cr | |
8047 | delete environment &&unset environment\cr | |
8048 | info convenience &&show convenience\cr | |
8049 | info copying &&show copying\cr | |
8050 | info directories &&show directories \cr | |
8051 | info editing &&show commands\cr | |
8052 | info history &&show values\cr | |
8053 | info targets &&help target\cr | |
8054 | info values &&show values\cr | |
8055 | info version &&show version\cr | |
8056 | info warranty &&show warranty\cr | |
8057 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
8058 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
8059 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
8060 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
8061 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
8062 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
8063 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
8064 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
8065 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
8066 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
8067 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
8068 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
8069 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
8070 | \cr | |
8071 | unset &&\rm(No longer an alias for delete)\cr | |
8072 | } | |
8073 | @end tex | |
92b73793 | 8074 | @c END TEXI2ROFF-KILL |
18fae2a8 | 8075 | @end ifset |
70b88761 | 8076 | |
18fae2a8 | 8077 | @ifclear PRECONFIGURED |
4eb4cf57 | 8078 | @node Formatting Documentation |
fe715d06 | 8079 | @appendix Formatting Documentation |
77b46d13 JG |
8080 | |
8081 | @cindex GDB reference card | |
8082 | @cindex reference card | |
8083 | The GDB 4 release includes an already-formatted reference card, ready | |
b1385986 | 8084 | for printing with PostScript or GhostScript, in the @file{gdb} |
ed447b95 RP |
8085 | subdirectory of the main source directory@footnote{In |
8086 | @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN} | |
8087 | release.}. If you can use PostScript or GhostScript with your printer, | |
8088 | you can print the reference card immediately with @file{refcard.ps}. | |
77b46d13 JG |
8089 | |
8090 | The release also includes the source for the reference card. You | |
8091 | can format it, using @TeX{}, by typing: | |
8092 | ||
8093 | @example | |
8094 | make refcard.dvi | |
8095 | @end example | |
8096 | ||
8097 | The GDB reference card is designed to print in landscape mode on US | |
8098 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
8099 | high. You will need to specify this form of printing as an option to | |
8100 | your @sc{dvi} output program. | |
8101 | ||
8102 | @cindex documentation | |
8103 | ||
8104 | All the documentation for GDB comes as part of the machine-readable | |
8105 | distribution. The documentation is written in Texinfo format, which is | |
8106 | a documentation system that uses a single source file to produce both | |
8107 | on-line information and a printed manual. You can use one of the Info | |
8108 | formatting commands to create the on-line version of the documentation | |
8109 | and @TeX{} (or @code{texi2roff}) to typeset the printed version. | |
8110 | ||
8111 | GDB includes an already formatted copy of the on-line Info version of | |
8112 | this manual in the @file{gdb} subdirectory. The main Info file is | |
8113 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
a89f94c2 RP |
8114 | subordinate files matching @samp{gdb.info*} in the same directory. If |
8115 | necessary, you can print out these files, or read them with any editor; | |
8116 | but they are easier to read using the @code{info} subsystem in GNU Emacs | |
8117 | or the standalone @code{info} program, available as part of the GNU | |
8118 | Texinfo distribution. | |
77b46d13 JG |
8119 | |
8120 | If you want to format these Info files yourself, you need one of the | |
8121 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
8122 | @code{makeinfo}. | |
8123 | ||
8124 | If you have @code{makeinfo} installed, and are in the top level GDB | |
18fae2a8 | 8125 | source directory (@file{gdb-@value{GDBVN}}, in the case of version @value{GDBVN}), you can |
77b46d13 JG |
8126 | make the Info file by typing: |
8127 | ||
8128 | @example | |
8129 | cd gdb | |
8130 | make gdb.info | |
8131 | @end example | |
8132 | ||
fe715d06 RP |
8133 | If you want to typeset and print copies of this manual, you need @TeX{}, |
8134 | a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the | |
8135 | Texinfo definitions file. | |
77b46d13 | 8136 | |
83bfcbae | 8137 | @TeX{} is a typesetting program; it does not print files directly, but |
77b46d13 JG |
8138 | produces output files called @sc{dvi} files. To print a typeset |
8139 | document, you need a program to print @sc{dvi} files. If your system | |
8140 | has @TeX{} installed, chances are it has such a program. The precise | |
8141 | command to use depends on your system; @kbd{lpr -d} is common; another | |
fe715d06 RP |
8142 | (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may |
8143 | require a file name without any extension or a @samp{.dvi} extension. | |
77b46d13 JG |
8144 | |
8145 | @TeX{} also requires a macro definitions file called | |
8146 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
8147 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
8148 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
8149 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
8150 | directory. | |
8151 | ||
8152 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
8153 | typeset and print this manual. First switch to the the @file{gdb} | |
8154 | subdirectory of the main source directory (for example, to | |
18fae2a8 | 8155 | @file{gdb-@value{GDBVN}/gdb}) and then type: |
77b46d13 JG |
8156 | |
8157 | @example | |
8158 | make gdb.dvi | |
8159 | @end example | |
8160 | ||
4eb4cf57 | 8161 | @node Installing GDB |
c7cb8acb RP |
8162 | @appendix Installing GDB |
8163 | @cindex configuring GDB | |
70b88761 RP |
8164 | @cindex installation |
8165 | ||
ed447b95 RP |
8166 | GDB comes with a @code{configure} script that automates the process |
8167 | of preparing GDB for installation; you can then use @code{make} to | |
8168 | build the @code{gdb} program. | |
f672bb7f RP |
8169 | @iftex |
8170 | @c irrelevant in info file; it's as current as the code it lives with. | |
ed447b95 RP |
8171 | @footnote{If you have a more recent version of GDB than @value{GDBVN}, |
8172 | look at the @file{README} file in the sources; we may have improved the | |
8173 | installation procedures since publishing this manual.} | |
f672bb7f RP |
8174 | @end iftex |
8175 | ||
c7cb8acb | 8176 | The GDB distribution includes all the source code you need for GDB in |
1041a570 RP |
8177 | a single directory, whose name is usually composed by appending the |
8178 | version number to @samp{gdb}. | |
8179 | ||
ed447b95 RP |
8180 | For example, the GDB version @value{GDBVN} distribution is in the |
8181 | @file{gdb-@value{GDBVN}} directory. That directory contains: | |
b80282d5 | 8182 | |
3d3ab540 | 8183 | @table @code |
18fae2a8 | 8184 | @item gdb-@value{GDBVN}/configure @r{(and supporting files)} |
c7cb8acb | 8185 | script for configuring GDB and all its supporting libraries. |
b80282d5 | 8186 | |
18fae2a8 | 8187 | @item gdb-@value{GDBVN}/gdb |
c7cb8acb | 8188 | the source specific to GDB itself |
3d3ab540 | 8189 | |
18fae2a8 | 8190 | @item gdb-@value{GDBVN}/bfd |
77b46d13 | 8191 | source for the Binary File Descriptor library |
3d3ab540 | 8192 | |
18fae2a8 | 8193 | @item gdb-@value{GDBVN}/include |
b80282d5 | 8194 | GNU include files |
3d3ab540 | 8195 | |
18fae2a8 | 8196 | @item gdb-@value{GDBVN}/libiberty |
3d3ab540 RP |
8197 | source for the @samp{-liberty} free software library |
8198 | ||
18fae2a8 | 8199 | @item gdb-@value{GDBVN}/opcodes |
3214c51c JG |
8200 | source for the library of opcode tables and disassemblers |
8201 | ||
18fae2a8 | 8202 | @item gdb-@value{GDBVN}/readline |
b80282d5 | 8203 | source for the GNU command-line interface |
77b46d13 | 8204 | |
18fae2a8 | 8205 | @item gdb-@value{GDBVN}/glob |
77b46d13 JG |
8206 | source for the GNU filename pattern-matching subroutine |
8207 | ||
18fae2a8 | 8208 | @item gdb-@value{GDBVN}/mmalloc |
77b46d13 | 8209 | source for the GNU memory-mapped malloc package |
3d3ab540 | 8210 | @end table |
1041a570 | 8211 | |
c7cb8acb | 8212 | The simplest way to configure and build GDB is to run @code{configure} |
1041a570 | 8213 | from the @file{gdb-@var{version-number}} source directory, which in |
18fae2a8 | 8214 | this example is the @file{gdb-@value{GDBVN}} directory. |
1041a570 RP |
8215 | |
8216 | First switch to the @file{gdb-@var{version-number}} source directory | |
8217 | if you are not already in it; then run @code{configure}. Pass the | |
c7cb8acb | 8218 | identifier for the platform on which GDB will run as an |
1041a570 RP |
8219 | argument. |
8220 | ||
8221 | For example: | |
8222 | ||
7463aadd | 8223 | @example |
18fae2a8 | 8224 | cd gdb-@value{GDBVN} |
3d3ab540 | 8225 | ./configure @var{host} |
7463aadd RP |
8226 | make |
8227 | @end example | |
1041a570 | 8228 | |
7463aadd | 8229 | @noindent |
1041a570 | 8230 | where @var{host} is an identifier such as @samp{sun4} or |
c7cb8acb | 8231 | @samp{decstation}, that identifies the platform where GDB will run. |
1041a570 | 8232 | |
8c69096b | 8233 | Running @samp{configure @var{host}} and then running @code{make} builds the |
38962738 RP |
8234 | @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty} |
8235 | libraries, then @code{gdb} itself. The configured source files, and the | |
8236 | binaries, are left in the corresponding source directories. | |
3d3ab540 | 8237 | |
e251e767 | 8238 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your |
29a2b744 | 8239 | system does not recognize this automatically when you run a different |
1041a570 RP |
8240 | shell, you may need to run @code{sh} on it explicitly: |
8241 | ||
8242 | @example | |
8243 | sh configure @var{host} | |
8244 | @end example | |
e251e767 | 8245 | |
f672bb7f RP |
8246 | If you run @code{configure} from a directory that contains source |
8247 | directories for multiple libraries or programs, such as the | |
18fae2a8 | 8248 | @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure} |
f672bb7f | 8249 | creates configuration files for every directory level underneath (unless |
98349959 | 8250 | you tell it not to, with the @samp{--norecursion} option). |
f672bb7f RP |
8251 | |
8252 | You can run the @code{configure} script from any of the | |
c7cb8acb | 8253 | subordinate directories in the GDB distribution, if you only want to |
1041a570 RP |
8254 | configure that subdirectory; but be sure to specify a path to it. |
8255 | ||
18fae2a8 | 8256 | For example, with version @value{GDBVN}, type the following to configure only |
1041a570 RP |
8257 | the @code{bfd} subdirectory: |
8258 | ||
e251e767 | 8259 | @example |
203eea5d | 8260 | @group |
18fae2a8 | 8261 | cd gdb-@value{GDBVN}/bfd |
e251e767 | 8262 | ../configure @var{host} |
203eea5d | 8263 | @end group |
e251e767 RP |
8264 | @end example |
8265 | ||
18fae2a8 | 8266 | You can install @code{@value{GDBP}} anywhere; it has no hardwired paths. |
1041a570 RP |
8267 | However, you should make sure that the shell on your path (named by |
8268 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
c7cb8acb RP |
8269 | that GDB uses the shell to start your program---some systems refuse to |
8270 | let GDB debug child processes whose programs are not readable. | |
3d3ab540 RP |
8271 | |
8272 | @menu | |
c7cb8acb | 8273 | * Separate Objdir:: Compiling GDB in another directory |
b80282d5 RP |
8274 | * Config Names:: Specifying names for hosts and targets |
8275 | * configure Options:: Summary of options for configure | |
3d3ab540 RP |
8276 | @end menu |
8277 | ||
4eb4cf57 | 8278 | @node Separate Objdir |
93928b60 | 8279 | @section Compiling GDB in another directory |
1041a570 | 8280 | |
c7cb8acb | 8281 | If you want to run GDB versions for several host or target machines, |
ed447b95 | 8282 | you need a different @code{gdb} compiled for each combination of |
1041a570 | 8283 | host and target. @code{configure} is designed to make this easy by |
f672bb7f RP |
8284 | allowing you to generate each configuration in a separate subdirectory, |
8285 | rather than in the source directory. If your @code{make} program | |
8286 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
ed447b95 | 8287 | @code{make} in each of these directories builds the @code{gdb} |
f672bb7f | 8288 | program specified there. |
b80282d5 | 8289 | |
c7cb8acb | 8290 | To build @code{gdb} in a separate directory, run @code{configure} |
f672bb7f | 8291 | with the @samp{--srcdir} option to specify where to find the source. |
93918348 | 8292 | (You also need to specify a path to find @code{configure} |
77b46d13 JG |
8293 | itself from your working directory. If the path to @code{configure} |
8294 | would be the same as the argument to @samp{--srcdir}, you can leave out | |
8295 | the @samp{--srcdir} option; it will be assumed.) | |
1041a570 | 8296 | |
18fae2a8 | 8297 | For example, with version @value{GDBVN}, you can build GDB in a separate |
f672bb7f | 8298 | directory for a Sun 4 like this: |
70b88761 RP |
8299 | |
8300 | @example | |
3d3ab540 | 8301 | @group |
18fae2a8 | 8302 | cd gdb-@value{GDBVN} |
f672bb7f RP |
8303 | mkdir ../gdb-sun4 |
8304 | cd ../gdb-sun4 | |
18fae2a8 | 8305 | ../gdb-@value{GDBVN}/configure sun4 |
70b88761 | 8306 | make |
3d3ab540 | 8307 | @end group |
70b88761 RP |
8308 | @end example |
8309 | ||
f672bb7f RP |
8310 | When @code{configure} builds a configuration using a remote source |
8311 | directory, it creates a tree for the binaries with the same structure | |
8312 | (and using the same names) as the tree under the source directory. In | |
8313 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
c7cb8acb | 8314 | directory @file{gdb-sun4/libiberty}, and GDB itself in |
f672bb7f | 8315 | @file{gdb-sun4/gdb}. |
1041a570 | 8316 | |
38962738 | 8317 | One popular reason to build several GDB configurations in separate |
c7cb8acb | 8318 | directories is to configure GDB for cross-compiling (where GDB |
f672bb7f RP |
8319 | runs on one machine---the host---while debugging programs that run on |
8320 | another machine---the target). You specify a cross-debugging target by | |
8321 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
c7637ea6 | 8322 | |
1041a570 | 8323 | When you run @code{make} to build a program or library, you must run |
f672bb7f RP |
8324 | it in a configured directory---whatever directory you were in when you |
8325 | called @code{configure} (or one of its subdirectories). | |
c7637ea6 | 8326 | |
fe715d06 | 8327 | The @code{Makefile} that @code{configure} generates in each source |
f672bb7f | 8328 | directory also runs recursively. If you type @code{make} in a source |
18fae2a8 RP |
8329 | directory such as @file{gdb-@value{GDBVN}} (or in a separate configured |
8330 | directory configured with @samp{--srcdir=@var{path}/gdb-@value{GDBVN}}), you | |
ed447b95 | 8331 | will build all the required libraries, and then build GDB. |
3d3ab540 | 8332 | |
f672bb7f RP |
8333 | When you have multiple hosts or targets configured in separate |
8334 | directories, you can run @code{make} on them in parallel (for example, | |
8335 | if they are NFS-mounted on each of the hosts); they will not interfere | |
8336 | with each other. | |
3d3ab540 | 8337 | |
4eb4cf57 | 8338 | @node Config Names |
93928b60 | 8339 | @section Specifying names for hosts and targets |
b80282d5 RP |
8340 | |
8341 | The specifications used for hosts and targets in the @code{configure} | |
8342 | script are based on a three-part naming scheme, but some short predefined | |
8343 | aliases are also supported. The full naming scheme encodes three pieces | |
e251e767 | 8344 | of information in the following pattern: |
1041a570 | 8345 | |
b80282d5 RP |
8346 | @example |
8347 | @var{architecture}-@var{vendor}-@var{os} | |
8348 | @end example | |
8349 | ||
8c69096b RP |
8350 | For example, you can use the alias @code{sun4} as a @var{host} argument, |
8351 | or as the value for @var{target} in a @code{--target=@var{target}} | |
8352 | option. The equivalent full name is @samp{sparc-sun-sunos4}. | |
b80282d5 | 8353 | |
c7cb8acb | 8354 | The @code{configure} script accompanying GDB does not provide |
b80282d5 RP |
8355 | any query facility to list all supported host and target names or |
8356 | aliases. @code{configure} calls the Bourne shell script | |
8357 | @code{config.sub} to map abbreviations to full names; you can read the | |
8358 | script, if you wish, or you can use it to test your guesses on | |
8359 | abbreviations---for example: | |
1041a570 | 8360 | |
b1385986 | 8361 | @smallexample |
b80282d5 | 8362 | % sh config.sub sun4 |
6a8cb0e7 | 8363 | sparc-sun-sunos411 |
b80282d5 | 8364 | % sh config.sub sun3 |
6a8cb0e7 | 8365 | m68k-sun-sunos411 |
b80282d5 | 8366 | % sh config.sub decstation |
6a8cb0e7 | 8367 | mips-dec-ultrix42 |
b80282d5 RP |
8368 | % sh config.sub hp300bsd |
8369 | m68k-hp-bsd | |
8370 | % sh config.sub i386v | |
6a8cb0e7 | 8371 | i386-unknown-sysv |
e94b4a2b | 8372 | % sh config.sub i786v |
6a8cb0e7 | 8373 | Invalid configuration `i786v': machine `i786v' not recognized |
b1385986 | 8374 | @end smallexample |
1041a570 | 8375 | |
c7637ea6 | 8376 | @noindent |
1041a570 | 8377 | @code{config.sub} is also distributed in the GDB source |
18fae2a8 | 8378 | directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}). |
b80282d5 | 8379 | |
4eb4cf57 | 8380 | @node configure Options |
93928b60 | 8381 | @section @code{configure} options |
7463aadd | 8382 | |
d48da190 | 8383 | Here is a summary of the @code{configure} options and arguments that |
18fae2a8 | 8384 | are most often useful for building @value{GDBN}. @code{configure} also has |
d48da190 RP |
8385 | several other options not listed here. @inforef{What Configure |
8386 | Does,,configure.info}, for a full explanation of @code{configure}. | |
8387 | @c FIXME: Would this be more, or less, useful as an xref (ref to printed | |
8388 | @c manual in the printed manual, ref to info file only from the info file)? | |
7463aadd RP |
8389 | |
8390 | @example | |
d48da190 RP |
8391 | configure @r{[}--help@r{]} |
8392 | @r{[}--prefix=@var{dir}@r{]} | |
8393 | @r{[}--srcdir=@var{path}@r{]} | |
f672bb7f RP |
8394 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} |
8395 | @r{[}--target=@var{target}@r{]} @var{host} | |
7463aadd | 8396 | @end example |
1041a570 | 8397 | |
3d3ab540 | 8398 | @noindent |
f672bb7f RP |
8399 | You may introduce options with a single @samp{-} rather than |
8400 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
8401 | @samp{--}. | |
70b88761 RP |
8402 | |
8403 | @table @code | |
d48da190 RP |
8404 | @item --help |
8405 | Display a quick summary of how to invoke @code{configure}. | |
8406 | ||
8407 | @item -prefix=@var{dir} | |
8408 | Configure the source to install programs and files under directory | |
8409 | @file{@var{dir}}. | |
8410 | ||
f672bb7f | 8411 | @item --srcdir=@var{path} |
6ca72cc6 RP |
8412 | @strong{Warning: using this option requires GNU @code{make}, or another |
8413 | @code{make} that implements the @code{VPATH} feature.}@* | |
f672bb7f | 8414 | Use this option to make configurations in directories separate from the |
c7cb8acb | 8415 | GDB source directories. Among other things, you can use this to |
f672bb7f RP |
8416 | build (or maintain) several configurations simultaneously, in separate |
8417 | directories. @code{configure} writes configuration specific files in | |
8418 | the current directory, but arranges for them to use the source in the | |
8419 | directory @var{path}. @code{configure} will create directories under | |
8420 | the working directory in parallel to the source directories below | |
8421 | @var{path}. | |
8422 | ||
8423 | @item --norecursion | |
8424 | Configure only the directory level where @code{configure} is executed; do not | |
7463aadd RP |
8425 | propagate configuration to subdirectories. |
8426 | ||
f672bb7f | 8427 | @item --rm |
b80282d5 | 8428 | Remove the configuration that the other arguments specify. |
7463aadd | 8429 | |
29a2b744 | 8430 | @c This does not work (yet if ever). FIXME. |
f672bb7f | 8431 | @c @item --parse=@var{lang} @dots{} |
c7cb8acb RP |
8432 | @c Configure the GDB expression parser to parse the listed languages. |
8433 | @c @samp{all} configures GDB for all supported languages. To get a | |
d7b569d5 | 8434 | @c list of all supported languages, omit the argument. Without this |
c7cb8acb | 8435 | @c option, GDB is configured to parse all supported languages. |
c2bbbb22 | 8436 | |
f672bb7f | 8437 | @item --target=@var{target} |
c7cb8acb RP |
8438 | Configure GDB for cross-debugging programs running on the specified |
8439 | @var{target}. Without this option, GDB is configured to debug | |
8440 | programs that run on the same machine (@var{host}) as GDB itself. | |
b80282d5 RP |
8441 | |
8442 | There is no convenient way to generate a list of all available targets. | |
7463aadd RP |
8443 | |
8444 | @item @var{host} @dots{} | |
c7cb8acb | 8445 | Configure GDB to run on the specified @var{host}. |
b80282d5 RP |
8446 | |
8447 | There is no convenient way to generate a list of all available hosts. | |
70b88761 RP |
8448 | @end table |
8449 | ||
3d3ab540 RP |
8450 | @noindent |
8451 | @code{configure} accepts other options, for compatibility with | |
b80282d5 | 8452 | configuring other GNU tools recursively; but these are the only |
c7cb8acb | 8453 | options that affect GDB or its supporting libraries. |
18fae2a8 | 8454 | @end ifclear |
3d3ab540 | 8455 | |
18fae2a8 | 8456 | @ifclear AGGLOMERATION |
4eb4cf57 | 8457 | @node Copying |
70b88761 | 8458 | @unnumbered GNU GENERAL PUBLIC LICENSE |
7463aadd | 8459 | @center Version 2, June 1991 |
70b88761 RP |
8460 | |
8461 | @display | |
7463aadd | 8462 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. |
70b88761 RP |
8463 | 675 Mass Ave, Cambridge, MA 02139, USA |
8464 | ||
8465 | Everyone is permitted to copy and distribute verbatim copies | |
8466 | of this license document, but changing it is not allowed. | |
8467 | @end display | |
8468 | ||
8469 | @unnumberedsec Preamble | |
8470 | ||
7463aadd RP |
8471 | The licenses for most software are designed to take away your |
8472 | freedom to share and change it. By contrast, the GNU General Public | |
70b88761 | 8473 | License is intended to guarantee your freedom to share and change free |
7463aadd RP |
8474 | software---to make sure the software is free for all its users. This |
8475 | General Public License applies to most of the Free Software | |
8476 | Foundation's software and to any other program whose authors commit to | |
8477 | using it. (Some other Free Software Foundation software is covered by | |
8478 | the GNU Library General Public License instead.) You can apply it to | |
8479 | your programs, too. | |
70b88761 RP |
8480 | |
8481 | When we speak of free software, we are referring to freedom, not | |
7463aadd RP |
8482 | price. Our General Public Licenses are designed to make sure that you |
8483 | have the freedom to distribute copies of free software (and charge for | |
8484 | this service if you wish), that you receive source code or can get it | |
8485 | if you want it, that you can change the software or use pieces of it | |
8486 | in new free programs; and that you know you can do these things. | |
70b88761 RP |
8487 | |
8488 | To protect your rights, we need to make restrictions that forbid | |
8489 | anyone to deny you these rights or to ask you to surrender the rights. | |
8490 | These restrictions translate to certain responsibilities for you if you | |
8491 | distribute copies of the software, or if you modify it. | |
8492 | ||
7463aadd | 8493 | For example, if you distribute copies of such a program, whether |
70b88761 RP |
8494 | gratis or for a fee, you must give the recipients all the rights that |
8495 | you have. You must make sure that they, too, receive or can get the | |
7463aadd RP |
8496 | source code. And you must show them these terms so they know their |
8497 | rights. | |
70b88761 RP |
8498 | |
8499 | We protect your rights with two steps: (1) copyright the software, and | |
8500 | (2) offer you this license which gives you legal permission to copy, | |
8501 | distribute and/or modify the software. | |
8502 | ||
8503 | Also, for each author's protection and ours, we want to make certain | |
8504 | that everyone understands that there is no warranty for this free | |
8505 | software. If the software is modified by someone else and passed on, we | |
8506 | want its recipients to know that what they have is not the original, so | |
8507 | that any problems introduced by others will not reflect on the original | |
8508 | authors' reputations. | |
8509 | ||
7463aadd RP |
8510 | Finally, any free program is threatened constantly by software |
8511 | patents. We wish to avoid the danger that redistributors of a free | |
8512 | program will individually obtain patent licenses, in effect making the | |
8513 | program proprietary. To prevent this, we have made it clear that any | |
8514 | patent must be licensed for everyone's free use or not licensed at all. | |
8515 | ||
70b88761 RP |
8516 | The precise terms and conditions for copying, distribution and |
8517 | modification follow. | |
8518 | ||
8519 | @iftex | |
7463aadd | 8520 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8521 | @end iftex |
8522 | @ifinfo | |
7463aadd | 8523 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
70b88761 RP |
8524 | @end ifinfo |
8525 | ||
8526 | @enumerate | |
8527 | @item | |
7463aadd RP |
8528 | This License applies to any program or other work which contains |
8529 | a notice placed by the copyright holder saying it may be distributed | |
8530 | under the terms of this General Public License. The ``Program'', below, | |
8531 | refers to any such program or work, and a ``work based on the Program'' | |
8532 | means either the Program or any derivative work under copyright law: | |
8533 | that is to say, a work containing the Program or a portion of it, | |
8534 | either verbatim or with modifications and/or translated into another | |
8535 | language. (Hereinafter, translation is included without limitation in | |
8536 | the term ``modification''.) Each licensee is addressed as ``you''. | |
8537 | ||
8538 | Activities other than copying, distribution and modification are not | |
8539 | covered by this License; they are outside its scope. The act of | |
8540 | running the Program is not restricted, and the output from the Program | |
8541 | is covered only if its contents constitute a work based on the | |
8542 | Program (independent of having been made by running the Program). | |
8543 | Whether that is true depends on what the Program does. | |
70b88761 RP |
8544 | |
8545 | @item | |
7463aadd RP |
8546 | You may copy and distribute verbatim copies of the Program's |
8547 | source code as you receive it, in any medium, provided that you | |
8548 | conspicuously and appropriately publish on each copy an appropriate | |
8549 | copyright notice and disclaimer of warranty; keep intact all the | |
8550 | notices that refer to this License and to the absence of any warranty; | |
8551 | and give any other recipients of the Program a copy of this License | |
8552 | along with the Program. | |
70b88761 | 8553 | |
7463aadd RP |
8554 | You may charge a fee for the physical act of transferring a copy, and |
8555 | you may at your option offer warranty protection in exchange for a fee. | |
70b88761 | 8556 | |
70b88761 | 8557 | @item |
7463aadd RP |
8558 | You may modify your copy or copies of the Program or any portion |
8559 | of it, thus forming a work based on the Program, and copy and | |
8560 | distribute such modifications or work under the terms of Section 1 | |
8561 | above, provided that you also meet all of these conditions: | |
70b88761 | 8562 | |
1041a570 | 8563 | @enumerate a |
70b88761 | 8564 | @item |
7463aadd RP |
8565 | You must cause the modified files to carry prominent notices |
8566 | stating that you changed the files and the date of any change. | |
70b88761 RP |
8567 | |
8568 | @item | |
7463aadd RP |
8569 | You must cause any work that you distribute or publish, that in |
8570 | whole or in part contains or is derived from the Program or any | |
8571 | part thereof, to be licensed as a whole at no charge to all third | |
8572 | parties under the terms of this License. | |
70b88761 RP |
8573 | |
8574 | @item | |
7463aadd RP |
8575 | If the modified program normally reads commands interactively |
8576 | when run, you must cause it, when started running for such | |
8577 | interactive use in the most ordinary way, to print or display an | |
8578 | announcement including an appropriate copyright notice and a | |
8579 | notice that there is no warranty (or else, saying that you provide | |
8580 | a warranty) and that users may redistribute the program under | |
8581 | these conditions, and telling the user how to view a copy of this | |
8582 | License. (Exception: if the Program itself is interactive but | |
8583 | does not normally print such an announcement, your work based on | |
8584 | the Program is not required to print an announcement.) | |
1041a570 | 8585 | @end enumerate |
7463aadd RP |
8586 | |
8587 | These requirements apply to the modified work as a whole. If | |
8588 | identifiable sections of that work are not derived from the Program, | |
8589 | and can be reasonably considered independent and separate works in | |
8590 | themselves, then this License, and its terms, do not apply to those | |
8591 | sections when you distribute them as separate works. But when you | |
8592 | distribute the same sections as part of a whole which is a work based | |
8593 | on the Program, the distribution of the whole must be on the terms of | |
8594 | this License, whose permissions for other licensees extend to the | |
8595 | entire whole, and thus to each and every part regardless of who wrote it. | |
8596 | ||
8597 | Thus, it is not the intent of this section to claim rights or contest | |
8598 | your rights to work written entirely by you; rather, the intent is to | |
8599 | exercise the right to control the distribution of derivative or | |
8600 | collective works based on the Program. | |
8601 | ||
8602 | In addition, mere aggregation of another work not based on the Program | |
8603 | with the Program (or with a work based on the Program) on a volume of | |
8604 | a storage or distribution medium does not bring the other work under | |
8605 | the scope of this License. | |
70b88761 RP |
8606 | |
8607 | @item | |
7463aadd RP |
8608 | You may copy and distribute the Program (or a work based on it, |
8609 | under Section 2) in object code or executable form under the terms of | |
8610 | Sections 1 and 2 above provided that you also do one of the following: | |
70b88761 | 8611 | |
1041a570 | 8612 | @enumerate a |
70b88761 | 8613 | @item |
7463aadd RP |
8614 | Accompany it with the complete corresponding machine-readable |
8615 | source code, which must be distributed under the terms of Sections | |
8616 | 1 and 2 above on a medium customarily used for software interchange; or, | |
70b88761 RP |
8617 | |
8618 | @item | |
7463aadd RP |
8619 | Accompany it with a written offer, valid for at least three |
8620 | years, to give any third party, for a charge no more than your | |
8621 | cost of physically performing source distribution, a complete | |
8622 | machine-readable copy of the corresponding source code, to be | |
8623 | distributed under the terms of Sections 1 and 2 above on a medium | |
8624 | customarily used for software interchange; or, | |
70b88761 RP |
8625 | |
8626 | @item | |
7463aadd RP |
8627 | Accompany it with the information you received as to the offer |
8628 | to distribute corresponding source code. (This alternative is | |
70b88761 | 8629 | allowed only for noncommercial distribution and only if you |
7463aadd RP |
8630 | received the program in object code or executable form with such |
8631 | an offer, in accord with Subsection b above.) | |
1041a570 | 8632 | @end enumerate |
7463aadd RP |
8633 | |
8634 | The source code for a work means the preferred form of the work for | |
8635 | making modifications to it. For an executable work, complete source | |
8636 | code means all the source code for all modules it contains, plus any | |
8637 | associated interface definition files, plus the scripts used to | |
8638 | control compilation and installation of the executable. However, as a | |
8639 | special exception, the source code distributed need not include | |
8640 | anything that is normally distributed (in either source or binary | |
8641 | form) with the major components (compiler, kernel, and so on) of the | |
8642 | operating system on which the executable runs, unless that component | |
8643 | itself accompanies the executable. | |
8644 | ||
8645 | If distribution of executable or object code is made by offering | |
8646 | access to copy from a designated place, then offering equivalent | |
8647 | access to copy the source code from the same place counts as | |
8648 | distribution of the source code, even though third parties are not | |
8649 | compelled to copy the source along with the object code. | |
70b88761 RP |
8650 | |
8651 | @item | |
7463aadd RP |
8652 | You may not copy, modify, sublicense, or distribute the Program |
8653 | except as expressly provided under this License. Any attempt | |
8654 | otherwise to copy, modify, sublicense or distribute the Program is | |
8655 | void, and will automatically terminate your rights under this License. | |
8656 | However, parties who have received copies, or rights, from you under | |
8657 | this License will not have their licenses terminated so long as such | |
8658 | parties remain in full compliance. | |
70b88761 RP |
8659 | |
8660 | @item | |
7463aadd RP |
8661 | You are not required to accept this License, since you have not |
8662 | signed it. However, nothing else grants you permission to modify or | |
8663 | distribute the Program or its derivative works. These actions are | |
8664 | prohibited by law if you do not accept this License. Therefore, by | |
8665 | modifying or distributing the Program (or any work based on the | |
8666 | Program), you indicate your acceptance of this License to do so, and | |
8667 | all its terms and conditions for copying, distributing or modifying | |
8668 | the Program or works based on it. | |
70b88761 RP |
8669 | |
8670 | @item | |
8671 | Each time you redistribute the Program (or any work based on the | |
7463aadd RP |
8672 | Program), the recipient automatically receives a license from the |
8673 | original licensor to copy, distribute or modify the Program subject to | |
8674 | these terms and conditions. You may not impose any further | |
8675 | restrictions on the recipients' exercise of the rights granted herein. | |
8676 | You are not responsible for enforcing compliance by third parties to | |
8677 | this License. | |
8678 | ||
8679 | @item | |
8680 | If, as a consequence of a court judgment or allegation of patent | |
8681 | infringement or for any other reason (not limited to patent issues), | |
8682 | conditions are imposed on you (whether by court order, agreement or | |
8683 | otherwise) that contradict the conditions of this License, they do not | |
8684 | excuse you from the conditions of this License. If you cannot | |
8685 | distribute so as to satisfy simultaneously your obligations under this | |
8686 | License and any other pertinent obligations, then as a consequence you | |
8687 | may not distribute the Program at all. For example, if a patent | |
8688 | license would not permit royalty-free redistribution of the Program by | |
8689 | all those who receive copies directly or indirectly through you, then | |
8690 | the only way you could satisfy both it and this License would be to | |
8691 | refrain entirely from distribution of the Program. | |
8692 | ||
8693 | If any portion of this section is held invalid or unenforceable under | |
8694 | any particular circumstance, the balance of the section is intended to | |
8695 | apply and the section as a whole is intended to apply in other | |
8696 | circumstances. | |
8697 | ||
8698 | It is not the purpose of this section to induce you to infringe any | |
8699 | patents or other property right claims or to contest validity of any | |
8700 | such claims; this section has the sole purpose of protecting the | |
8701 | integrity of the free software distribution system, which is | |
8702 | implemented by public license practices. Many people have made | |
8703 | generous contributions to the wide range of software distributed | |
8704 | through that system in reliance on consistent application of that | |
8705 | system; it is up to the author/donor to decide if he or she is willing | |
8706 | to distribute software through any other system and a licensee cannot | |
8707 | impose that choice. | |
8708 | ||
8709 | This section is intended to make thoroughly clear what is believed to | |
8710 | be a consequence of the rest of this License. | |
8711 | ||
8712 | @item | |
8713 | If the distribution and/or use of the Program is restricted in | |
8714 | certain countries either by patents or by copyrighted interfaces, the | |
8715 | original copyright holder who places the Program under this License | |
8716 | may add an explicit geographical distribution limitation excluding | |
8717 | those countries, so that distribution is permitted only in or among | |
8718 | countries not thus excluded. In such case, this License incorporates | |
8719 | the limitation as if written in the body of this License. | |
70b88761 RP |
8720 | |
8721 | @item | |
8722 | The Free Software Foundation may publish revised and/or new versions | |
8723 | of the General Public License from time to time. Such new versions will | |
8724 | be similar in spirit to the present version, but may differ in detail to | |
8725 | address new problems or concerns. | |
8726 | ||
8727 | Each version is given a distinguishing version number. If the Program | |
7463aadd | 8728 | specifies a version number of this License which applies to it and ``any |
70b88761 RP |
8729 | later version'', you have the option of following the terms and conditions |
8730 | either of that version or of any later version published by the Free | |
8731 | Software Foundation. If the Program does not specify a version number of | |
7463aadd | 8732 | this License, you may choose any version ever published by the Free Software |
70b88761 RP |
8733 | Foundation. |
8734 | ||
8735 | @item | |
8736 | If you wish to incorporate parts of the Program into other free | |
8737 | programs whose distribution conditions are different, write to the author | |
8738 | to ask for permission. For software which is copyrighted by the Free | |
8739 | Software Foundation, write to the Free Software Foundation; we sometimes | |
8740 | make exceptions for this. Our decision will be guided by the two goals | |
8741 | of preserving the free status of all derivatives of our free software and | |
8742 | of promoting the sharing and reuse of software generally. | |
8743 | ||
8744 | @iftex | |
8745 | @heading NO WARRANTY | |
8746 | @end iftex | |
8747 | @ifinfo | |
8748 | @center NO WARRANTY | |
8749 | @end ifinfo | |
8750 | ||
8751 | @item | |
8752 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
8753 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
8754 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
8755 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
8756 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
8757 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
8758 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
8759 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
8760 | REPAIR OR CORRECTION. | |
8761 | ||
8762 | @item | |
7463aadd RP |
8763 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
8764 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
70b88761 | 8765 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
7463aadd RP |
8766 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
8767 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
8768 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
8769 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
8770 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
8771 | POSSIBILITY OF SUCH DAMAGES. | |
70b88761 RP |
8772 | @end enumerate |
8773 | ||
8774 | @iftex | |
8775 | @heading END OF TERMS AND CONDITIONS | |
8776 | @end iftex | |
8777 | @ifinfo | |
8778 | @center END OF TERMS AND CONDITIONS | |
8779 | @end ifinfo | |
8780 | ||
8781 | @page | |
54e6b3c3 | 8782 | @unnumberedsec Applying These Terms to Your New Programs |
70b88761 RP |
8783 | |
8784 | If you develop a new program, and you want it to be of the greatest | |
7463aadd RP |
8785 | possible use to the public, the best way to achieve this is to make it |
8786 | free software which everyone can redistribute and change under these terms. | |
70b88761 | 8787 | |
7463aadd RP |
8788 | To do so, attach the following notices to the program. It is safest |
8789 | to attach them to the start of each source file to most effectively | |
8790 | convey the exclusion of warranty; and each file should have at least | |
8791 | the ``copyright'' line and a pointer to where the full notice is found. | |
70b88761 RP |
8792 | |
8793 | @smallexample | |
203eea5d | 8794 | @var{one line to give the program's name and an idea of what it does.} |
70b88761 RP |
8795 | Copyright (C) 19@var{yy} @var{name of author} |
8796 | ||
203eea5d RP |
8797 | This program is free software; you can redistribute it and/or |
8798 | modify it under the terms of the GNU General Public License | |
8799 | as published by the Free Software Foundation; either version 2 | |
8800 | of the License, or (at your option) any later version. | |
70b88761 RP |
8801 | |
8802 | This program is distributed in the hope that it will be useful, | |
8803 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8804 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8805 | GNU General Public License for more details. | |
8806 | ||
8807 | You should have received a copy of the GNU General Public License | |
203eea5d RP |
8808 | along with this program; if not, write to the |
8809 | Free Software Foundation, Inc., 675 Mass Ave, | |
8810 | Cambridge, MA 02139, USA. | |
70b88761 RP |
8811 | @end smallexample |
8812 | ||
8813 | Also add information on how to contact you by electronic and paper mail. | |
8814 | ||
8815 | If the program is interactive, make it output a short notice like this | |
8816 | when it starts in an interactive mode: | |
8817 | ||
8818 | @smallexample | |
8819 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
203eea5d RP |
8820 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details |
8821 | type `show w'. This is free software, and you are welcome | |
8822 | to redistribute it under certain conditions; type `show c' | |
8823 | for details. | |
70b88761 RP |
8824 | @end smallexample |
8825 | ||
7463aadd RP |
8826 | The hypothetical commands @samp{show w} and @samp{show c} should show |
8827 | the appropriate parts of the General Public License. Of course, the | |
8828 | commands you use may be called something other than @samp{show w} and | |
8829 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8830 | suits your program. | |
70b88761 RP |
8831 | |
8832 | You should also get your employer (if you work as a programmer) or your | |
8833 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8834 | necessary. Here is a sample; alter the names: | |
8835 | ||
1041a570 RP |
8836 | @example |
8837 | Yoyodyne, Inc., hereby disclaims all copyright | |
8838 | interest in the program `Gnomovision' | |
8839 | (which makes passes at compilers) written | |
8840 | by James Hacker. | |
70b88761 RP |
8841 | |
8842 | @var{signature of Ty Coon}, 1 April 1989 | |
8843 | Ty Coon, President of Vice | |
1041a570 | 8844 | @end example |
7463aadd RP |
8845 | |
8846 | This General Public License does not permit incorporating your program into | |
8847 | proprietary programs. If your program is a subroutine library, you may | |
8848 | consider it more useful to permit linking proprietary applications with the | |
8849 | library. If this is what you want to do, use the GNU Library General | |
8850 | Public License instead of this License. | |
18fae2a8 | 8851 | @end ifclear |
70b88761 | 8852 | |
4eb4cf57 | 8853 | @node Index |
d2e08421 | 8854 | @unnumbered Index |
e91b87a3 | 8855 | |
8856 | @printindex cp | |
8857 | ||
fe3f5fc8 RP |
8858 | @tex |
8859 | % I think something like @colophon should be in texinfo. In the | |
8860 | % meantime: | |
8861 | \long\def\colophon{\hbox to0pt{}\vfill | |
8862 | \centerline{The body of this manual is set in} | |
8863 | \centerline{\fontname\tenrm,} | |
8864 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8865 | \centerline{and examples in {\tt\fontname\tentt}.} | |
a6d0b6d3 RP |
8866 | \centerline{{\it\fontname\tenit\/},} |
8867 | \centerline{{\bf\fontname\tenbf}, and} | |
fe3f5fc8 RP |
8868 | \centerline{{\sl\fontname\tensl\/}} |
8869 | \centerline{are used for emphasis.}\vfill} | |
8870 | \page\colophon | |
a6d0b6d3 | 8871 | % Blame: [email protected], 1991. |
fe3f5fc8 RP |
8872 | @end tex |
8873 | ||
e91b87a3 | 8874 | @contents |
8875 | @bye |