]>
Commit | Line | Data |
---|---|---|
7e54e97f RP |
1 | |
2 | \input texinfo @c -*-texinfo-*- | |
3 | @c Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc. | |
4 | @c %**start of header | |
5 | @setfilename gdb.info | |
6 | @settitle Using GDB (v4) | |
7 | @setchapternewpage odd | |
73e44aaf RP |
8 | @c @smallbook |
9 | @c @cropmarks | |
7e54e97f RP |
10 | @c %**end of header |
11 | ||
12 | @finalout | |
13 | @syncodeindex ky cp | |
14 | ||
15 | @c ===> NOTE! <== | |
16 | @c Determine the edition number in *three* places by hand: | |
17 | @c 1. First ifinfo section 2. title page 3. top node | |
18 | @c To find the locations, search for !!set | |
19 | ||
20 | @c The following is for Pesch for his RCS system. | |
21 | @c This revision number *not* the same as the Edition number. | |
22 | @tex | |
23 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
24 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
25 | @end tex | |
26 | ||
27 | @c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN: | |
28 | @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com) | |
29 | @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint) | |
30 | ||
31 | @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly. | |
32 | ||
33 | @ifinfo | |
34 | @format | |
35 | START-INFO-DIR-ENTRY | |
36 | * Gdb: (gdb). The GNU debugger. | |
37 | END-INFO-DIR-ENTRY | |
38 | @end format | |
39 | @end ifinfo | |
40 | @c | |
41 | @ifinfo | |
42 | This file documents the GNU debugger GDB. | |
43 | ||
44 | @c !!set edition, date, version | |
45 | This is Edition 4.01, January 1992, | |
46 | of @cite{Using GDB: A Guide to the GNU Source-Level Debugger} | |
47 | for GDB Version 4.4.4. | |
48 | ||
49 | Copyright (C) 1988, 1989, 1990, 1991 1992 Free Software Foundation, Inc. | |
50 | ||
51 | Permission is granted to make and distribute verbatim copies of | |
52 | this manual provided the copyright notice and this permission notice | |
53 | are preserved on all copies. | |
54 | ||
55 | @ignore | |
56 | Permission is granted to process this file through TeX and print the | |
57 | results, provided the printed document carries copying permission | |
58 | notice identical to this one except for the removal of this paragraph | |
59 | (this paragraph not being relevant to the printed manual). | |
60 | ||
61 | @end ignore | |
62 | Permission is granted to copy and distribute modified versions of this | |
63 | manual under the conditions for verbatim copying, provided also that the | |
64 | section entitled ``GNU General Public License'' is included exactly as | |
65 | in the original, and provided that the entire resulting derived work is | |
66 | distributed under the terms of a permission notice identical to this | |
67 | one. | |
68 | ||
69 | Permission is granted to copy and distribute translations of this manual | |
70 | into another language, under the above conditions for modified versions, | |
71 | except that the section entitled ``GNU General Public License'' may be | |
72 | included in a translation approved by the Free Software Foundation | |
73 | instead of in the original English. | |
74 | @end ifinfo | |
75 | ||
76 | @titlepage | |
77 | @title Using GDB | |
78 | @subtitle A Guide to the GNU Source-Level Debugger | |
79 | @sp 1 | |
80 | @c !!set edition, date, version | |
81 | @subtitle Edition 4.01, for GDB version 4.4.4 | |
82 | @subtitle January 1992 | |
83 | @author by Richard M. Stallman and Roland H. Pesch | |
84 | @page | |
85 | @tex | |
86 | {\parskip=0pt | |
87 | \hfill rms\@ai.mit.edu, pesch\@cygnus.com\par | |
88 | \hfill {\it Using GDB}, \manvers\par | |
89 | \hfill \TeX{}info \texinfoversion\par | |
90 | } | |
91 | @end tex | |
92 | ||
93 | @vskip 0pt plus 1filll | |
94 | Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. | |
95 | ||
96 | Permission is granted to make and distribute verbatim copies of | |
97 | this manual provided the copyright notice and this permission notice | |
98 | are preserved on all copies. | |
99 | ||
100 | Permission is granted to copy and distribute modified versions of this | |
101 | manual under the conditions for verbatim copying, provided also that the | |
102 | section entitled ``GNU General Public License'' is included exactly as | |
103 | in the original, and provided that the entire resulting derived work is | |
104 | distributed under the terms of a permission notice identical to this | |
105 | one. | |
106 | ||
107 | Permission is granted to copy and distribute translations of this manual | |
108 | into another language, under the above conditions for modified versions, | |
109 | except that the section entitled ``GNU General Public License'' may be | |
110 | included in a translation approved by the Free Software Foundation | |
111 | instead of in the original English. | |
112 | @end titlepage | |
113 | @page | |
114 | ||
115 | @ifinfo | |
116 | @node Top, Summary, (dir), (dir) | |
117 | @top GDB, the GNU symbolic debugger | |
118 | ||
119 | This file describes GDB, the GNU symbolic debugger. | |
120 | ||
121 | @c !!set edition, date, version | |
122 | This is Edition 4.01, January 1992, for GDB Version 4.4.4. | |
123 | @end ifinfo | |
124 | ||
125 | @menu | |
126 | * Summary:: Summary of GDB | |
127 | * New Features:: New features since GDB version 3.5 | |
128 | * Sample Session:: A Sample GDB session | |
129 | * Invocation:: Getting in and out of GDB | |
130 | * Commands:: GDB commands | |
131 | * Running:: Running programs under GDB | |
132 | * Stopping:: Stopping and continuing | |
133 | * Stack:: Examining the stack | |
134 | * Source:: Examining source files | |
135 | * Data:: Examining data | |
136 | * Languages:: Using GDB with different languages | |
137 | * Symbols:: Examining the symbol table | |
138 | * Altering:: Altering execution | |
139 | * GDB Files:: GDB's files | |
140 | * Targets:: Specifying a debugging target | |
141 | * Controlling GDB:: Controlling GDB | |
142 | * Sequences:: Canned sequences of commands | |
143 | * Emacs:: Using GDB under GNU Emacs | |
144 | * GDB Bugs:: Reporting bugs in GDB | |
145 | * Renamed Commands:: | |
146 | * Installing GDB:: Installing GDB | |
147 | * Copying:: GNU GENERAL PUBLIC LICENSE | |
148 | * Index:: Index | |
149 | ||
150 | --- The Detailed Node Listing --- | |
151 | ||
152 | Summary of GDB | |
153 | ||
154 | * Free Software:: Free Software | |
155 | * Contributors:: Contributors to GDB | |
156 | ||
157 | Getting In and Out of GDB | |
158 | ||
159 | * Invoking GDB:: Starting GDB | |
160 | * Leaving GDB:: Leaving GDB | |
161 | * Shell Commands:: Shell Commands | |
162 | ||
163 | Starting GDB | |
164 | ||
165 | * File Options:: Choosing Files | |
166 | * Mode Options:: Choosing Modes | |
167 | ||
168 | GDB Commands | |
169 | ||
170 | * Command Syntax:: Command Syntax | |
171 | * Help:: Getting Help | |
172 | ||
173 | Running Programs Under GDB | |
174 | ||
175 | * Compilation:: Compiling for Debugging | |
176 | * Starting:: Starting your Program | |
177 | * Arguments:: Your Program's Arguments | |
178 | * Environment:: Your Program's Environment | |
179 | * Working Directory:: Your Program's Working Directory | |
180 | * Input/Output:: Your Program's Input and Output | |
181 | * Attach:: Debugging an Already-Running Process | |
182 | * Kill Process:: Killing the Child Process | |
183 | ||
184 | Stopping and Continuing | |
185 | ||
186 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions | |
187 | * Continuing and Stepping:: Resuming Execution | |
188 | * Signals:: Signals | |
189 | ||
190 | Breakpoints, Watchpoints, and Exceptions | |
191 | ||
192 | * Set Breaks:: Setting Breakpoints | |
193 | * Set Watchpoints:: Setting Watchpoints | |
194 | * Exception Handling:: Breakpoints and Exceptions | |
195 | * Delete Breaks:: Deleting Breakpoints | |
196 | * Disabling:: Disabling Breakpoints | |
197 | * Conditions:: Break Conditions | |
198 | * Break Commands:: Breakpoint Command Lists | |
199 | * Breakpoint Menus:: Breakpoint Menus | |
200 | * Error in Breakpoints:: ``Cannot insert breakpoints'' | |
201 | ||
202 | Examining the Stack | |
203 | ||
204 | * Frames:: Stack Frames | |
205 | * Backtrace:: Backtraces | |
206 | * Selection:: Selecting a Frame | |
207 | * Frame Info:: Information on a Frame | |
208 | ||
209 | Examining Source Files | |
210 | ||
211 | * List:: Printing Source Lines | |
212 | * Search:: Searching Source Files | |
213 | * Source Path:: Specifying Source Directories | |
214 | * Machine Code:: Source and Machine Code | |
215 | ||
216 | Examining Data | |
217 | ||
218 | * Expressions:: Expressions | |
219 | * Variables:: Program Variables | |
220 | * Arrays:: Artificial Arrays | |
221 | * Output formats:: Output formats | |
222 | * Memory:: Examining Memory | |
223 | * Auto Display:: Automatic Display | |
224 | * Print Settings:: Print Settings | |
225 | * Value History:: Value History | |
226 | * Convenience Vars:: Convenience Variables | |
227 | * Registers:: Registers | |
228 | * Floating Point Hardware:: Floating Point Hardware | |
229 | ||
230 | Using GDB with Different Languages | |
231 | ||
232 | * Setting:: Switching between source languages | |
233 | * Show:: Displaying the language | |
234 | * Checks:: Type and Range checks | |
235 | * Support:: Supported languages | |
236 | ||
237 | Switching between source languages | |
238 | ||
239 | * Manually:: Setting the working language manually | |
240 | * Automatically:: Having GDB infer the source language | |
241 | ||
242 | Type and range Checking | |
243 | ||
244 | * Type Checking:: An overview of type checking | |
245 | * Range Checking:: An overview of range checking | |
246 | ||
247 | Supported Languages | |
248 | ||
249 | * C:: C and C++ | |
250 | * Modula-2:: Modula-2 | |
251 | ||
252 | C and C++ | |
253 | ||
254 | * C Operators:: C and C++ Operators | |
255 | * C Constants:: C and C++ Constants | |
256 | * Cplusplus expressions:: C++ Expressions | |
257 | * C Defaults:: Default settings for C and C++ | |
258 | * C Checks:: C and C++ Type and Range Checks | |
259 | * Debugging C:: GDB and C | |
260 | * Debugging C plus plus:: Special features for C++ | |
261 | ||
262 | Modula-2 | |
263 | ||
264 | * M2 Operators:: Built-in operators | |
265 | * Built-In Func/Proc:: Built-in Functions and Procedures | |
266 | * M2 Constants:: Modula-2 Constants | |
267 | * M2 Defaults:: Default settings for Modula-2 | |
268 | * Deviations:: Deviations from standard Modula-2 | |
269 | * M2 Checks:: Modula-2 Type and Range Checks | |
270 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
271 | * GDB/M2:: GDB and Modula-2 | |
272 | ||
273 | Altering Execution | |
274 | ||
275 | * Assignment:: Assignment to Variables | |
276 | * Jumping:: Continuing at a Different Address | |
277 | * Signaling:: Giving your program a Signal | |
278 | * Returning:: Returning from a Function | |
279 | * Calling:: Calling your Program's Functions | |
280 | * Patching:: Patching your Program | |
281 | ||
282 | GDB's Files | |
283 | ||
284 | * Files:: Commands to Specify Files | |
285 | * Symbol Errors:: Errors Reading Symbol Files | |
286 | ||
287 | Specifying a Debugging Target | |
288 | ||
289 | * Active Targets:: Active Targets | |
290 | * Target Commands:: Commands for Managing Targets | |
291 | * Remote:: Remote Debugging | |
292 | ||
293 | Remote Debugging | |
294 | ||
295 | * i960-Nindy Remote:: GDB with a Remote i960 (Nindy) | |
296 | * EB29K Remote:: GDB with a Remote EB29K | |
297 | * VxWorks Remote:: GDB and VxWorks | |
298 | ||
299 | GDB with a Remote i960 (Nindy) | |
300 | ||
301 | * Nindy Startup:: Startup with Nindy | |
302 | * Nindy Options:: Options for Nindy | |
303 | * Nindy reset:: Nindy Reset Command | |
304 | ||
305 | GDB with a Remote EB29K | |
306 | ||
307 | * Comms (EB29K):: Communications Setup | |
308 | * gdb-EB29K:: EB29K cross-debugging | |
309 | * Remote Log:: Remote Log | |
310 | ||
311 | GDB and VxWorks | |
312 | ||
313 | * VxWorks connection:: Connecting to VxWorks | |
314 | * VxWorks download:: VxWorks Download | |
315 | * VxWorks attach:: Running Tasks | |
316 | ||
317 | Controlling GDB | |
318 | ||
319 | * Prompt:: Prompt | |
320 | * Editing:: Command Editing | |
321 | * History:: Command History | |
322 | * Screen Size:: Screen Size | |
323 | * Numbers:: Numbers | |
324 | * Messages/Warnings:: Optional Warnings and Messages | |
325 | ||
326 | Canned Sequences of Commands | |
327 | ||
328 | * Define:: User-Defined Commands | |
329 | * Command Files:: Command Files | |
330 | * Output:: Commands for Controlled Output | |
331 | ||
332 | Reporting Bugs in GDB | |
333 | ||
334 | * Bug Criteria:: Have You Found a Bug? | |
335 | * Bug Reporting:: How to Report Bugs | |
336 | ||
337 | Installing GDB | |
338 | ||
339 | * Separate Objdir:: Compiling GDB in another directory | |
340 | * Config Names:: Specifying names for hosts and targets | |
341 | * configure Options:: Summary of options for configure | |
342 | * Formatting Documentation:: How to format and print GDB documentation | |
343 | @end menu | |
344 | ||
345 | @node Summary, New Features, Top, Top | |
346 | @unnumbered Summary of GDB | |
347 | ||
348 | The purpose of a debugger such as GDB is to allow you to see what is | |
349 | going on ``inside'' another program while it executes---or what another | |
350 | program was doing at the moment it crashed. | |
351 | ||
352 | GDB can do four main kinds of things (plus other things in support of | |
353 | these) to help you catch bugs in the act: | |
354 | ||
355 | @itemize @bullet | |
356 | @item | |
357 | Start your program, specifying anything that might affect its behavior. | |
358 | ||
359 | @item | |
360 | Make your program stop on specified conditions. | |
361 | ||
362 | @item | |
363 | Examine what has happened, when your program has stopped. | |
364 | ||
365 | @item | |
366 | Change things in your program, so you can experiment with correcting the | |
367 | effects of one bug and go on to learn about another. | |
368 | @end itemize | |
369 | ||
370 | You can use GDB to debug programs written in C, C++, and Modula-2. | |
371 | Fortran support will be added when a GNU Fortran compiler is ready. | |
372 | ||
373 | @menu | |
374 | * Free Software:: Free Software | |
375 | * Contributors:: Contributors to GDB | |
376 | @end menu | |
377 | ||
378 | @node Free Software, Contributors, Summary, Summary | |
379 | @unnumberedsec Free Software | |
380 | ||
381 | GDB is @dfn{free software}, protected by the GNU General Public License | |
382 | (GPL). The GPL gives you the freedom to copy or adapt a licensed | |
383 | program---but every person getting a copy also gets with it the | |
384 | freedom to modify that copy (which means that they must get access to | |
385 | the source code), and the freedom to distribute further copies. | |
386 | Typical software companies use copyrights to limit your freedoms; the | |
387 | Free Software Foundation uses the GPL to preserve these freedoms. | |
388 | ||
389 | Fundamentally, the General Public License is a license which says that | |
390 | you have these freedoms and that you cannot take these freedoms away | |
391 | from anyone else. | |
392 | ||
393 | For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}. | |
394 | ||
395 | @node Contributors, , Free Software, Summary | |
396 | @unnumberedsec Contributors to GDB | |
397 | ||
398 | Richard Stallman was the original author of GDB, and of many other GNU | |
399 | programs. Many others have contributed to its development. This | |
400 | section attempts to credit major contributors. One of the virtues of | |
401 | free software is that everyone is free to contribute to it; with | |
402 | regret, we cannot actually acknowledge everyone here. The file | |
403 | @file{ChangeLog} in the GDB distribution approximates a blow-by-blow | |
404 | account. | |
405 | ||
406 | Changes much prior to version 2.0 are lost in the mists of time. | |
407 | ||
408 | @quotation | |
409 | @emph{Plea:} Additions to this section are particularly welcome. If you | |
410 | or your friends (or enemies; let's be evenhanded) have been unfairly | |
411 | omitted from this list, we would like to add your names! | |
412 | @end quotation | |
413 | ||
414 | So that they may not regard their long labor as thankless, we | |
415 | particularly thank those who shepherded GDB through major releases: Stu | |
416 | Grossman and John Gilmore (release 4.4), John Gilmore (releases 4.3, 4.2, | |
417 | 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy | |
418 | Smith (releases 3.2, 3.1, 3.0). As major maintainer of GDB for some | |
419 | period, each contributed significantly to the structure, stability, and | |
420 | capabilities of the entire debugger. | |
421 | ||
422 | Richard Stallman, assisted at various times by Pete TerMaat, Chris | |
423 | Hanson, and Richard Mlynarik, handled releases through 2.8. | |
424 | ||
425 | Michael Tiemann is the author of most of the GNU C++ support in GDB, | |
426 | with significant additional contributions from Per Bothner. James | |
427 | Clark wrote the GNU C++ demangler. Early work on C++ was by Peter | |
428 | TerMaat (who also did much general update work leading to release 3.0). | |
429 | ||
430 | GDB 4 uses the BFD subroutine library to examine multiple | |
431 | object-file formats; BFD was a joint project of David V. | |
432 | Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. | |
433 | ||
434 | David Johnson wrote the original COFF support; Pace Willison did | |
435 | the original support for encapsulated COFF. | |
436 | ||
437 | Adam de Boor and Bradley Davis contributed the ISI Optimum V support. | |
438 | Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS | |
439 | support. Jean-Daniel Fekete contributed Sun 386i support. Chris | |
440 | Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki | |
441 | Hasei contributed Sony/News OS 3 support. David Johnson contributed | |
442 | Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. | |
443 | Keith Packard contributed NS32K support. Doug Rabson contributed | |
444 | Acorn Risc Machine support. Chris Smith contributed Convex support | |
445 | (and Fortran debugging). Jonathan Stone contributed Pyramid support. | |
446 | Michael Tiemann contributed SPARC support. Tim Tucker contributed | |
447 | support for the Gould NP1 and Gould Powernode. Pace Willison | |
448 | contributed Intel 386 support. Jay Vosburgh contributed Symmetry | |
449 | support. | |
450 | ||
451 | Rich Schaefer and Peter Schauer helped with support of SunOS shared | |
452 | libraries. | |
453 | ||
454 | Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about | |
455 | several machine instruction sets. | |
456 | ||
457 | Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped | |
458 | develop remote debugging. Intel Corporation and Wind River Systems | |
459 | contributed remote debugging modules for their products. | |
460 | ||
461 | Brian Fox is the author of the readline libraries providing | |
462 | command-line editing and command history. | |
463 | ||
464 | Andrew Beers of SUNY Buffalo wrote the language-switching code and | |
465 | the Modula-2 support, and contributed the Languages chapter of this | |
466 | manual. | |
467 | ||
468 | @node New Features, Sample Session, Summary, Top | |
469 | @unnumbered New Features since GDB version 3.5 | |
470 | ||
471 | @table @emph | |
472 | @item Targets | |
473 | Using the new command @code{target}, you can select at runtime whether | |
474 | you are debugging local files, local processes, standalone systems over | |
475 | a serial port, realtime systems over a TCP/IP connection, etc. The | |
476 | command @code{load} can download programs into a remote system. Serial | |
477 | stubs are available for Motorola 680x0 and Intel 80386 remote systems; | |
478 | GDB also supports debugging realtime processes running under | |
479 | VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a | |
480 | debugger stub on the target system. Internally, GDB now uses a | |
481 | function vector to mediate access to different targets; if you need to | |
482 | add your own support for a remote protocol, this makes it much easier. | |
483 | ||
484 | @item Watchpoints | |
485 | GDB now sports watchpoints as well as breakpoints. You can use a | |
486 | watchpoint to stop execution whenever the value of an expression | |
487 | changes, without having to predict a particular place in your program | |
488 | where this may happen. | |
489 | ||
490 | @item Wide Output | |
491 | Commands that issue wide output now insert newlines at places designed | |
492 | to make the output more readable. | |
493 | ||
494 | @item Object Code Formats | |
495 | GDB uses a new library called the Binary File Descriptor (BFD) | |
496 | Library to permit it to switch dynamically, without reconfiguration or | |
497 | recompilation, between different object-file formats. Formats currently | |
498 | supported are COFF, a.out, and the Intel 960 b.out; files may be read as | |
499 | .o's, archive libraries, or core dumps. BFD is available as a | |
500 | subroutine library so that other programs may take advantage of it, and | |
501 | the other GNU binary utilities are being converted to use it. | |
502 | ||
503 | @item Configuration and Ports | |
504 | Compile-time configuration (to select a particular architecture and | |
505 | operating system) is much easier. The script @code{configure} now | |
506 | allows you to configure GDB as either a native debugger or a | |
507 | cross-debugger. @xref{Installing GDB}, for details on how to | |
508 | configure and on what architectures are now available. | |
509 | ||
510 | @item Interaction | |
511 | The user interface to GDB's control variables has been simplified | |
512 | and consolidated in two commands, @code{set} and @code{show}. Output | |
513 | lines are now broken at readable places, rather than overflowing onto | |
514 | the next line. You can suppress output of machine-level addresses, | |
515 | displaying only source language information. | |
516 | ||
517 | @item C++ | |
518 | GDB now supports C++ multiple inheritance (if used with a GCC | |
519 | version 2 compiler), and also has limited support for C++ exception | |
520 | handling, with the commands @code{catch} and @code{info catch}: GDB | |
521 | can break when an exception is raised, before the stack is peeled back | |
522 | to the exception handler's context. | |
523 | ||
524 | @item Modula-2 | |
525 | GDB now has preliminary support for the GNU Modula-2 compiler, | |
526 | currently under development at the State University of New York at | |
527 | Buffalo. Coordinated development of both GDB and the GNU Modula-2 | |
528 | compiler will continue into 1992. Other Modula-2 compilers are | |
529 | currently not supported, and attempting to debug programs compiled with | |
530 | them will likely result in an error as the symbol table of the | |
531 | executable is read in. | |
532 | ||
533 | @item Command Rationalization | |
534 | Many GDB commands have been renamed to make them easier to remember | |
535 | and use. In particular, the subcommands of @code{info} and | |
536 | @code{show}/@code{set} are grouped to make the former refer to the state | |
537 | of your program, and the latter refer to the state of GDB itself. | |
538 | @xref{Renamed Commands}, for details on what commands were renamed. | |
539 | ||
540 | @item Shared Libraries | |
541 | GDB 4 can debug programs and core files that use SunOS shared | |
542 | libraries. | |
543 | ||
544 | @item Reference Card | |
545 | GDB 4 has a reference card. @xref{Formatting Documentation} for | |
546 | instructions on printing it. | |
547 | ||
548 | @item Work in Progress | |
549 | Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture | |
550 | support. | |
551 | @end table | |
552 | ||
553 | @node Sample Session, Invocation, New Features, Top | |
554 | @chapter A Sample GDB Session | |
555 | ||
556 | You can use this manual at your leisure to read all about GDB. | |
557 | However, a handful of commands are enough to get started using the | |
558 | debugger. This chapter illustrates these commands. | |
559 | ||
560 | @iftex | |
561 | In this sample session, we emphasize user input like this: @i{input}, | |
562 | to make it easier to pick out from the surrounding output. | |
563 | @end iftex | |
564 | ||
565 | @c FIXME: this example may not be appropriate for some configs, where | |
566 | @c FIXME...primary interest is in remote use. | |
567 | ||
568 | One of the preliminary versions of GNU @code{m4} (a generic macro | |
569 | processor) exhibits the following bug: sometimes, when we change its | |
570 | quote strings from the default, the commands used to capture one macro's | |
571 | definition in another stop working. In the following short @code{m4} | |
572 | session, we define a macro @code{foo} which expands to @code{0000}; we | |
573 | then use the @code{m4} built-in @code{defn} to define @code{bar} as the | |
574 | same thing. However, when we change the open quote string to | |
575 | @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same | |
576 | procedure fails to define a new synonym @code{baz}: | |
577 | ||
578 | @smallexample | |
579 | $ @i{cd gnu/m4} | |
580 | $ @i{./m4} | |
581 | @i{define(foo,0000)} | |
582 | ||
583 | @i{foo} | |
584 | 0000 | |
585 | @i{define(bar,defn(`foo'))} | |
586 | ||
587 | @i{bar} | |
588 | 0000 | |
589 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
590 | ||
591 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
592 | @i{baz} | |
593 | @i{C-d} | |
594 | m4: End of input: 0: fatal error: EOF in string | |
595 | @end smallexample | |
596 | ||
597 | @noindent | |
598 | Let's use GDB to try to see what's going on. | |
599 | ||
600 | @smallexample | |
601 | $ @i{gdb m4} | |
602 | @c FIXME: this falsifies the exact text played out, to permit smallbook | |
603 | @c FIXME... format to come out better. | |
604 | GDB is free software and you are welcome to distribute copies | |
605 | of it under certain conditions; type "show copying" to see | |
606 | the conditions. | |
607 | There is absolutely no warranty for GDB; type "show warranty" | |
608 | for details. | |
609 | GDB 4.4.4, Copyright 1992 Free Software Foundation, Inc... | |
610 | (gdb) | |
611 | @end smallexample | |
612 | ||
613 | @noindent | |
614 | GDB reads only enough symbol data to know where to find the rest when | |
615 | needed; as a result, the first prompt comes up very quickly. We now | |
616 | tell GDB to use a narrower display width than usual, so that examples | |
617 | will fit in this manual. | |
618 | ||
619 | @smallexample | |
620 | (gdb) @i{set width 70} | |
621 | @end smallexample | |
622 | ||
623 | @noindent | |
624 | Let's see how the @code{m4} built-in @code{changequote} works. | |
625 | Having looked at the source, we know the relevant subroutine is | |
626 | @code{m4_changequote}, so we set a breakpoint there with GDB's | |
627 | @code{break} command. | |
628 | ||
629 | @smallexample | |
630 | (gdb) @i{break m4_changequote} | |
631 | Breakpoint 1 at 0x62f4: file builtin.c, line 879. | |
632 | @end smallexample | |
633 | ||
634 | @noindent | |
635 | Using the @code{run} command, we start @code{m4} running under GDB | |
636 | control; as long as control does not reach the @code{m4_changequote} | |
637 | subroutine, the program runs as usual: | |
638 | ||
639 | @smallexample | |
640 | (gdb) @i{run} | |
641 | Starting program: /work/Editorial/gdb/gnu/m4/m4 | |
642 | @i{define(foo,0000)} | |
643 | ||
644 | @i{foo} | |
645 | 0000 | |
646 | @end smallexample | |
647 | ||
648 | @noindent | |
649 | To trigger the breakpoint, we call @code{changequote}. GDB | |
650 | suspends execution of @code{m4}, displaying information about the | |
651 | context where it stops. | |
652 | ||
653 | @smallexample | |
654 | @i{changequote(<QUOTE>,<UNQUOTE>)} | |
655 | ||
656 | Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) | |
657 | at builtin.c:879 | |
658 | 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3)) | |
659 | @end smallexample | |
660 | ||
661 | @noindent | |
662 | Now we use the command @code{n} (@code{next}) to advance execution to | |
663 | the next line of the current function. | |
664 | ||
665 | @smallexample | |
666 | (gdb) @i{n} | |
667 | 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ | |
668 | : nil, | |
669 | @end smallexample | |
670 | ||
671 | @noindent | |
672 | @code{set_quotes} looks like a promising subroutine. We can go into it | |
673 | by using the command @code{s} (@code{step}) instead of @code{next}. | |
674 | @code{step} goes to the next line to be executed in @emph{any} | |
675 | subroutine, so it steps into @code{set_quotes}. | |
676 | ||
677 | @smallexample | |
678 | (gdb) @i{s} | |
679 | set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
680 | at input.c:530 | |
681 | 530 if (lquote != def_lquote) | |
682 | @end smallexample | |
683 | ||
684 | @noindent | |
685 | The display that shows the subroutine where @code{m4} is now | |
686 | suspended (and its arguments) is called a stack frame display. It | |
687 | shows a summary of the stack. We can use the @code{backtrace} | |
688 | command (which can also be spelled @code{bt}), to see where we are | |
689 | in the stack as a whole: the @code{backtrace} command displays a | |
690 | stack frame for each active subroutine. | |
691 | ||
692 | @smallexample | |
693 | (gdb) @i{bt} | |
694 | #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") | |
695 | at input.c:530 | |
696 | #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) | |
697 | at builtin.c:882 | |
698 | #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 | |
699 | #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) | |
700 | at macro.c:71 | |
701 | #4 0x79dc in expand_input () at macro.c:40 | |
702 | #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 | |
703 | @end smallexample | |
704 | ||
705 | @noindent | |
706 | Let's step through a few more lines to see what happens. The first two | |
707 | times, we can use @samp{s}; the next two times we use @code{n} to avoid | |
708 | falling into the @code{xstrdup} subroutine. | |
709 | ||
710 | @smallexample | |
711 | (gdb) @i{s} | |
712 | 0x3b5c 532 if (rquote != def_rquote) | |
713 | (gdb) @i{s} | |
714 | 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ | |
715 | def_lquote : xstrdup(lq); | |
716 | (gdb) @i{n} | |
717 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
718 | : xstrdup(rq); | |
719 | (gdb) @i{n} | |
720 | 538 len_lquote = strlen(rquote); | |
721 | @end smallexample | |
722 | ||
723 | @noindent | |
724 | The last line displayed looks a little odd; let's examine the variables | |
725 | @code{lquote} and @code{rquote} to see if they are in fact the new left | |
726 | and right quotes we specified. We can use the command @code{p} | |
727 | (@code{print}) to see their values. | |
728 | ||
729 | @smallexample | |
730 | (gdb) @i{p lquote} | |
731 | $1 = 0x35d40 "<QUOTE>" | |
732 | (gdb) @i{p rquote} | |
733 | $2 = 0x35d50 "<UNQUOTE>" | |
734 | @end smallexample | |
735 | ||
736 | @noindent | |
737 | @code{lquote} and @code{rquote} are indeed the new left and right quotes. | |
738 | Let's look at some context; we can display ten lines of source | |
739 | surrounding the current line, with the @code{l} (@code{list}) command. | |
740 | ||
741 | @smallexample | |
742 | (gdb) @i{l} | |
743 | 533 xfree(rquote); | |
744 | 534 | |
745 | 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ | |
746 | : xstrdup (lq); | |
747 | 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ | |
748 | : xstrdup (rq); | |
749 | 537 | |
750 | 538 len_lquote = strlen(rquote); | |
751 | 539 len_rquote = strlen(lquote); | |
752 | 540 @} | |
753 | 541 | |
754 | 542 void | |
755 | @end smallexample | |
756 | ||
757 | @noindent | |
758 | Let's step past the two lines that set @code{len_lquote} and | |
759 | @code{len_rquote}, and then examine the values of those variables. | |
760 | ||
761 | @smallexample | |
762 | (gdb) @i{n} | |
763 | 539 len_rquote = strlen(lquote); | |
764 | (gdb) @i{n} | |
765 | 540 @} | |
766 | (gdb) @i{p len_lquote} | |
767 | $3 = 9 | |
768 | (gdb) @i{p len_rquote} | |
769 | $4 = 7 | |
770 | @end smallexample | |
771 | ||
772 | @noindent | |
773 | That certainly looks wrong, assuming @code{len_lquote} and | |
774 | @code{len_rquote} are meant to be the lengths of @code{lquote} and | |
775 | @code{rquote} respectively. Let's try setting them to better values. | |
776 | We can use the @code{p} command for this, since it'll print the value of | |
777 | any expression---and that expression can include subroutine calls and | |
778 | assignments. | |
779 | ||
780 | @smallexample | |
781 | (gdb) p @i{len_lquote=strlen(lquote)} | |
782 | $5 = 7 | |
783 | (gdb) p @i{len_rquote=strlen(rquote)} | |
784 | $6 = 9 | |
785 | @end smallexample | |
786 | ||
787 | @noindent | |
788 | Let's see if that fixes the problem of using the new quotes with the | |
789 | @code{m4} built-in @code{defn}. We can allow @code{m4} to continue | |
790 | executing with the @code{c} (@code{continue}) command, and then try the | |
791 | example that caused trouble initially: | |
792 | ||
793 | @smallexample | |
794 | (gdb) @i{c} | |
795 | Continuing. | |
796 | ||
797 | @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))} | |
798 | ||
799 | baz | |
800 | 0000 | |
801 | @end smallexample | |
802 | ||
803 | @noindent | |
804 | Success! The new quotes now work just as well as the default ones. The | |
805 | problem seems to have been just the two typos defining the wrong | |
806 | lengths. We'll let @code{m4} exit by giving it an EOF as input. | |
807 | ||
808 | @smallexample | |
809 | @i{C-d} | |
810 | Program exited normally. | |
811 | @end smallexample | |
812 | ||
813 | @noindent | |
814 | The message @samp{Program exited normally.} is from GDB; it | |
815 | indicates @code{m4} has finished executing. We can end our GDB | |
816 | session with the GDB @code{quit} command. | |
817 | ||
818 | @smallexample | |
819 | (gdb) @i{quit} | |
820 | @end smallexample | |
821 | ||
822 | @node Invocation, Commands, Sample Session, Top | |
823 | @chapter Getting In and Out of GDB | |
824 | ||
825 | This chapter discusses how to start GDB, and how to get out of it. | |
826 | (The essentials: type @samp{gdb} to start GDB, and type @kbd{quit} | |
827 | or @kbd{C-d} to exit.) | |
828 | ||
829 | @menu | |
830 | * Invoking GDB:: Starting GDB | |
831 | * Leaving GDB:: Leaving GDB | |
832 | * Shell Commands:: Shell Commands | |
833 | @end menu | |
834 | ||
835 | @node Invoking GDB, Leaving GDB, Invocation, Invocation | |
836 | @section Starting GDB | |
837 | ||
838 | Start GDB with the shell command @code{gdb}. Once it's running, | |
839 | GDB reads commands from the terminal until you tell it to exit. | |
840 | ||
841 | You can also run @code{gdb} with a variety of arguments and options, | |
842 | to specify more of your debugging environment at the outset. | |
843 | ||
844 | The command-line options described here are designed | |
845 | to cover a variety of situations; in some environments, some of these | |
846 | options may effectively be unavailable. | |
847 | ||
848 | ||
849 | The most usual way to start GDB is with one argument or two, | |
850 | specifying an executable program as the argument: | |
851 | ||
852 | @example | |
853 | gdb @var{program} | |
854 | @end example | |
855 | ||
856 | @noindent | |
857 | You can also start with both an executable program and a core file | |
858 | specified: | |
859 | ||
860 | @example | |
861 | gdb @var{program} @var{core} | |
862 | @end example | |
863 | ||
864 | You can, instead, specify a process ID as a second argument, if you want | |
865 | to debug a running process: | |
866 | ||
867 | @example | |
868 | gdb @var{program} 1234 | |
869 | @end example | |
870 | ||
871 | @noindent | |
872 | would attach GDB to process @code{1234} (unless you also have a file | |
873 | named @file{1234}; GDB does check for a core file first). | |
874 | ||
875 | Taking advantage of the second command-line argument requires a fairly | |
876 | complete operating system; when you use GDB as a remote debugger | |
877 | attached to a bare board, there may not be any notion of ``process'', | |
878 | and there is often no way to get a core dump. | |
879 | ||
880 | @noindent | |
881 | You can further control how GDB starts up by using command-line | |
882 | options. GDB itself can remind you of the options available. | |
883 | ||
884 | @noindent | |
885 | Type | |
886 | ||
887 | @example | |
888 | gdb -help | |
889 | @end example | |
890 | ||
891 | @noindent | |
892 | to display all available options and briefly describe their use | |
893 | (@samp{gdb -h} is a shorter equivalent). | |
894 | ||
895 | All options and command line arguments you give are processed | |
896 | in sequential order. The order makes a difference when the | |
897 | @samp{-x} option is used. | |
898 | ||
899 | @menu | |
900 | * File Options:: Choosing Files | |
901 | * Mode Options:: Choosing Modes | |
902 | @end menu | |
903 | ||
904 | @node File Options, Mode Options, Invoking GDB, Invoking GDB | |
905 | @subsection Choosing Files | |
906 | ||
907 | When GDB starts, it reads any arguments other than options as | |
908 | specifying an executable file and core file (or process ID). This is | |
909 | the same as if the arguments were specified by the @samp{-se} and | |
910 | @samp{-c} options respectively. (GDB reads the first argument | |
911 | that does not have an associated option flag as equivalent to the | |
912 | @samp{-se} option followed by that argument; and the second argument | |
913 | that does not have an associated option flag, if any, as equivalent to | |
914 | the @samp{-c} option followed by that argument.) | |
915 | ||
916 | Many options have both long and short forms; both are shown in the | |
917 | following list. GDB also recognizes the long forms if you truncate | |
918 | them, so long as enough of the option is present to be unambiguous. | |
919 | (If you prefer, you can flag option arguments with @samp{--} rather | |
920 | than @samp{-}, though we illustrate the more usual convention.) | |
921 | ||
922 | @table @code | |
923 | @item -symbols=@var{file} | |
924 | @itemx -s @var{file} | |
925 | Read symbol table from file @var{file}. | |
926 | ||
927 | @item -exec=@var{file} | |
928 | @itemx -e @var{file} | |
929 | Use file @var{file} as the executable file to execute when | |
930 | appropriate, and for examining pure data in conjunction with a core | |
931 | dump. | |
932 | ||
933 | @item -se=@var{file} | |
934 | Read symbol table from file @var{file} and use it as the executable | |
935 | file. | |
936 | ||
937 | @item -core=@var{file} | |
938 | @itemx -c @var{file} | |
939 | Use file @var{file} as a core dump to examine. | |
940 | ||
941 | @item -command=@var{file} | |
942 | @itemx -x @var{file} | |
943 | Execute GDB commands from file @var{file}. @xref{Command Files}. | |
944 | ||
945 | @item -directory=@var{directory} | |
946 | @itemx -d @var{directory} | |
947 | Add @var{directory} to the path to search for source files. | |
948 | @end table | |
949 | ||
950 | @node Mode Options, , File Options, Invoking GDB | |
951 | @subsection Choosing Modes | |
952 | ||
953 | You can run GDB in various alternative modes---for example, in | |
954 | batch mode or quiet mode. | |
955 | ||
956 | @table @code | |
957 | @item -nx | |
958 | @itemx -n | |
959 | Do not execute commands from any @file{.gdbinit} initialization files. | |
960 | Normally, the commands in these files are executed after all the | |
961 | command options and arguments have been processed. | |
962 | @xref{Command Files}. | |
963 | ||
964 | @item -quiet | |
965 | @itemx -q | |
966 | ``Quiet''. Do not print the introductory and copyright messages. These | |
967 | messages are also suppressed in batch mode. | |
968 | ||
969 | @item -batch | |
970 | Run in batch mode. Exit with status @code{0} after processing all the command | |
971 | files specified with @samp{-x} (and @file{.gdbinit}, if not inhibited). | |
972 | Exit with nonzero status if an error occurs in executing the GDB | |
973 | commands in the command files. | |
974 | ||
975 | Batch mode may be useful for running GDB as a filter, for example to | |
976 | download and run a program on another computer; in order to make this | |
977 | more useful, the message | |
978 | ||
979 | @example | |
980 | Program exited normally. | |
981 | @end example | |
982 | ||
983 | @noindent | |
984 | (which is ordinarily issued whenever a program running under GDB control | |
985 | terminates) is not issued when running in batch mode. | |
986 | ||
987 | @item -cd=@var{directory} | |
988 | Run GDB using @var{directory} as its working directory, | |
989 | instead of the current directory. | |
990 | ||
991 | @item -fullname | |
992 | @itemx -f | |
993 | Emacs sets this option when it runs GDB as a subprocess. It tells GDB | |
994 | to output the full file name and line number in a standard, | |
995 | recognizable fashion each time a stack frame is displayed (which | |
996 | includes each time your program stops). This recognizable format looks | |
997 | like two @samp{\032} characters, followed by the file name, line number | |
998 | and character position separated by colons, and a newline. The | |
999 | Emacs-to-GDB interface program uses the two @samp{\032} characters as | |
1000 | a signal to display the source code for the frame. | |
1001 | ||
1002 | @item -b @var{bps} | |
1003 | Set the line speed (baud rate or bits per second) of any serial | |
1004 | interface used by GDB for remote debugging. | |
1005 | ||
1006 | @item -tty=@var{device} | |
1007 | Run using @var{device} for your program's standard input and output. | |
1008 | @c FIXME: kingdon thinks there is more to -tty. Investigate. | |
1009 | @end table | |
1010 | ||
1011 | @node Leaving GDB, Shell Commands, Invoking GDB, Invocation | |
1012 | @section Leaving GDB | |
1013 | @cindex exiting GDB | |
1014 | ||
1015 | @table @code | |
1016 | @item quit | |
1017 | @kindex quit | |
1018 | @kindex q | |
1019 | To exit GDB, use the @code{quit} command (abbreviated @code{q}), or type | |
1020 | an end-of-file character (usually @kbd{C-d}). | |
1021 | @end table | |
1022 | ||
1023 | @cindex interrupt | |
1024 | An interrupt (often @kbd{C-c}) will not exit from GDB, but rather | |
1025 | will terminate the action of any GDB command that is in progress and | |
1026 | return to GDB command level. It is safe to type the interrupt | |
1027 | character at any time because GDB does not allow it to take effect | |
1028 | until a time when it is safe. | |
1029 | ||
1030 | If you have been using GDB to control an attached process or device, you | |
1031 | can release it with the @code{detach} command; @pxref{Attach, | |
1032 | ,Debugging an Already-Running Process}.. | |
1033 | ||
1034 | @node Shell Commands, , Leaving GDB, Invocation | |
1035 | @section Shell Commands | |
1036 | ||
1037 | If you need to execute occasional shell commands during your | |
1038 | debugging session, there is no need to leave or suspend GDB; you can | |
1039 | just use the @code{shell} command. | |
1040 | ||
1041 | @table @code | |
1042 | @item shell @var{command string} | |
1043 | @kindex shell | |
1044 | @cindex shell escape | |
1045 | Directs GDB to invoke an inferior shell to execute @var{command | |
1046 | string}. If it exists, the environment variable @code{SHELL} is used | |
1047 | for the name of the shell to run. Otherwise GDB uses | |
1048 | @code{/bin/sh}. | |
1049 | @end table | |
1050 | ||
1051 | The utility @code{make} is often needed in development environments. | |
1052 | You do not have to use the @code{shell} command for this purpose in GDB: | |
1053 | ||
1054 | @table @code | |
1055 | @item make @var{make-args} | |
1056 | @kindex make | |
1057 | @cindex calling make | |
1058 | Causes GDB to execute an inferior @code{make} program with the specified | |
1059 | arguments. This is equivalent to @samp{shell make @var{make-args}}. | |
1060 | @end table | |
1061 | ||
1062 | @node Commands, Running, Invocation, Top | |
1063 | @chapter GDB Commands | |
1064 | ||
1065 | You can abbreviate GDB command if that abbreviation is unambiguous; | |
1066 | and you can repeat certain GDB commands by typing just @key{RET}. | |
1067 | ||
1068 | @menu | |
1069 | * Command Syntax:: Command Syntax | |
1070 | * Help:: Getting Help | |
1071 | @end menu | |
1072 | ||
1073 | @node Command Syntax, Help, Commands, Commands | |
1074 | @section Command Syntax | |
1075 | ||
1076 | A GDB command is a single line of input. There is no limit on how long | |
1077 | it can be. It starts with a command name, which is followed by arguments | |
1078 | whose meaning depends on the command name. For example, the command | |
1079 | @code{step} accepts an argument which is the number of times to step, | |
1080 | as in @samp{step 5}. You can also use the @code{step} command with | |
1081 | no arguments. Some command names do not allow any arguments. | |
1082 | ||
1083 | @cindex abbreviation | |
1084 | GDB command names may always be truncated if that abbreviation is | |
1085 | unambiguous. Other possible command abbreviations are listed in the | |
1086 | documentation for individual commands. In some cases, even ambiguous | |
1087 | abbreviations are allowed; for example, @code{s} is specially defined as | |
1088 | equivalent to @code{step} even though there are other commands whose | |
1089 | names start with @code{s}. You can test abbreviations by using them as | |
1090 | arguments to the @code{help} command. | |
1091 | ||
1092 | @cindex repeating commands | |
1093 | @kindex RET | |
1094 | A blank line as input to GDB (typing just @key{RET}) means to | |
1095 | repeat the previous command. Certain commands (for example, @code{run}) | |
1096 | will not repeat this way; these are commands for which unintentional | |
1097 | repetition might cause trouble and which you are unlikely to want to | |
1098 | repeat. | |
1099 | ||
1100 | The @code{list} and @code{x} commands, when you repeat them with | |
1101 | @key{RET}, construct new arguments rather than repeating | |
1102 | exactly as typed. This permits easy scanning of source or memory. | |
1103 | ||
1104 | GDB can also use @key{RET} in another way: to partition lengthy | |
1105 | output, in a way similar to the common utility @code{more} | |
1106 | (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many | |
1107 | in this situation, GDB disables command repetition after any command | |
1108 | that generates this sort of display. | |
1109 | ||
1110 | @kindex # | |
1111 | @cindex comment | |
1112 | A line of input starting with @kbd{#} is a comment; it does nothing. | |
1113 | This is useful mainly in command files (@pxref{Command Files}). | |
1114 | ||
1115 | @node Help, , Command Syntax, Commands | |
1116 | @section Getting Help | |
1117 | @cindex online documentation | |
1118 | @kindex help | |
1119 | ||
1120 | You can always ask GDB itself for information on its commands, using the | |
1121 | command @code{help}. | |
1122 | ||
1123 | @table @code | |
1124 | @item help | |
1125 | @itemx h | |
1126 | @kindex h | |
1127 | You can use @code{help} (abbreviated @code{h}) with no arguments to | |
1128 | display a short list of named classes of commands: | |
1129 | ||
1130 | @smallexample | |
1131 | (gdb) help | |
1132 | List of classes of commands: | |
1133 | ||
1134 | running -- Running the program | |
1135 | stack -- Examining the stack | |
1136 | data -- Examining data | |
1137 | breakpoints -- Making program stop at certain points | |
1138 | files -- Specifying and examining files | |
1139 | status -- Status inquiries | |
1140 | support -- Support facilities | |
1141 | user-defined -- User-defined commands | |
1142 | aliases -- Aliases of other commands | |
1143 | obscure -- Obscure features | |
1144 | ||
1145 | Type "help" followed by a class name for a list of | |
1146 | commands in that class. | |
1147 | Type "help" followed by command name for full | |
1148 | documentation. | |
1149 | Command name abbreviations are allowed if unambiguous. | |
1150 | (gdb) | |
1151 | @end smallexample | |
1152 | ||
1153 | @item help @var{class} | |
1154 | Using one of the general help classes as an argument, you can get a | |
1155 | list of the individual commands in that class. For example, here is the | |
1156 | help display for the class @code{status}: | |
1157 | ||
1158 | @smallexample | |
1159 | (gdb) help status | |
1160 | Status inquiries. | |
1161 | ||
1162 | List of commands: | |
1163 | ||
1164 | show -- Generic command for showing things set with "set" | |
1165 | info -- Generic command for printing status | |
1166 | ||
1167 | Type "help" followed by command name for full | |
1168 | documentation. | |
1169 | Command name abbreviations are allowed if unambiguous. | |
1170 | (gdb) | |
1171 | @end smallexample | |
1172 | ||
1173 | @item help @var{command} | |
1174 | With a command name as @code{help} argument, GDB will display a | |
1175 | short paragraph on how to use that command. | |
1176 | @end table | |
1177 | ||
1178 | In addition to @code{help}, you can use the GDB commands @code{info} | |
1179 | and @code{show} to inquire about the state of your program, or the state | |
1180 | of GDB itself. Each command supports many topics of inquiry; this | |
1181 | manual introduces each of them in the appropriate context. The listings | |
1182 | under @code{info} and under @code{show} in the Index point to | |
1183 | all the sub-commands. @xref{Index}. | |
1184 | ||
1185 | @c @group | |
1186 | @table @code | |
1187 | @item info | |
1188 | @kindex info | |
1189 | @kindex i | |
1190 | This command (abbreviated @code{i}) is for describing the state of your | |
1191 | program; for example, it can list the arguments given to your program | |
1192 | (@code{info args}), the registers currently in use (@code{info | |
1193 | registers}), or the breakpoints you have set (@code{info breakpoints}). | |
1194 | You can get a complete list of the @code{info} sub-commands with | |
1195 | @w{@code{help info}}. | |
1196 | ||
1197 | @kindex show | |
1198 | @item show | |
1199 | In contrast, @code{show} is for describing the state of GDB itself. | |
1200 | You can change most of the things you can @code{show}, by using the | |
1201 | related command @code{set}; for example, you can control what number | |
1202 | system is used for displays with @code{set radix}, or simply inquire | |
1203 | which is currently in use with @code{show radix}. | |
1204 | ||
1205 | @kindex info set | |
1206 | To display all the settable parameters and their current | |
1207 | values, you can use @code{show} with no arguments; you may also use | |
1208 | @code{info set}. Both commands produce the same display. | |
1209 | @c FIXME: "info set" violates the rule that "info" is for state of | |
1210 | @c FIXME...program. Ck w/ GNU: "info set" to be called something else, | |
1211 | @c FIXME...or change desc of rule---eg "state of prog and debugging session"? | |
1212 | @end table | |
1213 | @c @end group | |
1214 | ||
1215 | Here are three miscellaneous @code{show} subcommands, all of which are | |
1216 | exceptional in lacking corresponding @code{set} commands: | |
1217 | ||
1218 | @table @code | |
1219 | @kindex show version | |
1220 | @cindex version number | |
1221 | @item show version | |
1222 | Show what version of GDB is running. You should include this | |
1223 | information in GDB bug-reports. If multiple versions of GDB are in | |
1224 | use at your site, you may occasionally want to make sure what version | |
1225 | of GDB you are running; as GDB evolves, new commands are introduced, | |
1226 | and old ones may wither away. The version number is also announced | |
1227 | when you start GDB with no arguments. | |
1228 | ||
1229 | @kindex show copying | |
1230 | @item show copying | |
1231 | Display information about permission for copying GDB. | |
1232 | ||
1233 | @kindex show warranty | |
1234 | @item show warranty | |
1235 | Display the GNU ``NO WARRANTY'' statement. | |
1236 | @end table | |
1237 | ||
1238 | @node Running, Stopping, Commands, Top | |
1239 | @chapter Running Programs Under GDB | |
1240 | ||
1241 | To debug a program, you must run it under GDB. | |
1242 | ||
1243 | @menu | |
1244 | * Compilation:: Compiling for Debugging | |
1245 | * Starting:: Starting your Program | |
1246 | * Arguments:: Your Program's Arguments | |
1247 | * Environment:: Your Program's Environment | |
1248 | * Working Directory:: Your Program's Working Directory | |
1249 | * Input/Output:: Your Program's Input and Output | |
1250 | * Attach:: Debugging an Already-Running Process | |
1251 | * Kill Process:: Killing the Child Process | |
1252 | @end menu | |
1253 | ||
1254 | @node Compilation, Starting, Running, Running | |
1255 | @section Compiling for Debugging | |
1256 | ||
1257 | In order to debug a program effectively, you need to generate | |
1258 | debugging information when you compile it. This debugging information | |
1259 | is stored in the object file; it describes the data type of each | |
1260 | variable or function and the correspondence between source line numbers | |
1261 | and addresses in the executable code. | |
1262 | ||
1263 | To request debugging information, specify the @samp{-g} option when you run | |
1264 | the compiler. | |
1265 | ||
1266 | Many C compilers are unable to handle the @samp{-g} and @samp{-O} | |
1267 | options together. Using those compilers, you cannot generate optimized | |
1268 | executables containing debugging information. | |
1269 | ||
1270 | gcc, the GNU C compiler, supports @samp{-g} with or without | |
1271 | @samp{-O}, making it possible to debug optimized code. We recommend | |
1272 | that you @emph{always} use @samp{-g} whenever you compile a program. | |
1273 | You may think your program is correct, but there is no sense in pushing | |
1274 | your luck. | |
1275 | ||
1276 | Some things do not work as well with @samp{-g -O} as with just | |
1277 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1278 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1279 | please report it as a bug (including a test case!). | |
1280 | ||
1281 | Older versions of the GNU C compiler permitted a variant option | |
1282 | @w{@samp{-gg}} for debugging information. GDB no longer supports this | |
1283 | format; if your GNU C compiler has this option, do not use it. | |
1284 | ||
1285 | @ignore | |
1286 | @comment As far as I know, there are no cases in which GDB will | |
1287 | @comment produce strange output in this case. (but no promises). | |
1288 | If your program includes archives made with the @code{ar} program, and | |
1289 | if the object files used as input to @code{ar} were compiled without the | |
1290 | @samp{-g} option and have names longer than 15 characters, GDB will get | |
1291 | confused reading your program's symbol table. No error message will be | |
1292 | given, but GDB may behave strangely. The reason for this problem is a | |
1293 | deficiency in the Unix archive file format, which cannot represent file | |
1294 | names longer than 15 characters. | |
1295 | ||
1296 | To avoid this problem, compile the archive members with the @samp{-g} | |
1297 | option or use shorter file names. Alternatively, use a version of GNU | |
1298 | @code{ar} dated more recently than August 1989. | |
1299 | @end ignore | |
1300 | ||
1301 | @node Starting, Arguments, Compilation, Running | |
1302 | @section Starting your Program | |
1303 | @cindex starting | |
1304 | @cindex running | |
1305 | ||
1306 | @table @code | |
1307 | @item run | |
1308 | @itemx r | |
1309 | @kindex run | |
1310 | Use the @code{run} command to start your program under GDB. You must | |
1311 | first specify the program name | |
1312 | (except on VxWorks) | |
1313 | with an argument to | |
1314 | GDB (@pxref{Invocation, ,Getting In and Out of GDB}), or by using the | |
1315 | @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to | |
1316 | Specify Files}). | |
1317 | ||
1318 | @end table | |
1319 | ||
1320 | If you are running your program in an execution environment that | |
1321 | supports processes, @code{run} creates an inferior process and makes | |
1322 | that process run your program. (In environments without processes, | |
1323 | @code{run} jumps to the start of your program.) | |
1324 | ||
1325 | The execution of a program is affected by certain information it | |
1326 | receives from its superior. GDB provides ways to specify this | |
1327 | information, which you must do @i{before} starting your program. (You | |
1328 | can change it after starting your program, but such changes will only affect | |
1329 | your program the next time you start it.) This information may be | |
1330 | divided into four categories: | |
1331 | ||
1332 | @table @asis | |
1333 | @item The @i{arguments.} | |
1334 | Specify the arguments to give your program as the arguments of the | |
1335 | @code{run} command. If a shell is available on your target, the shell | |
1336 | is used to pass the arguments, so that you may use normal conventions | |
1337 | (such as wildcard expansion or variable substitution) in describing | |
1338 | the arguments. In Unix systems, you can control which shell is used | |
1339 | with the @code{SHELL} environment variable. @xref{Arguments, ,Your | |
1340 | Program's Arguments}. | |
1341 | ||
1342 | @item The @i{environment.} | |
1343 | Your program normally inherits its environment from GDB, but you can | |
1344 | use the GDB commands @code{set environment} and @code{unset | |
1345 | environment} to change parts of the environment that will be given to | |
1346 | your program. @xref{Environment, ,Your Program's Environment}. | |
1347 | ||
1348 | @item The @i{working directory.} | |
1349 | Your program inherits its working directory from GDB. You can set | |
1350 | GDB's working directory with the @code{cd} command in GDB. | |
1351 | @xref{Working Directory, ,Your Program's Working Directory}. | |
1352 | ||
1353 | @item The @i{standard input and output.} | |
1354 | Your program normally uses the same device for standard input and | |
1355 | standard output as GDB is using. You can redirect input and output | |
1356 | in the @code{run} command line, or you can use the @code{tty} command to | |
1357 | set a different device for your program. | |
1358 | @xref{Input/Output, ,Your Program's Input and Output}. | |
1359 | ||
1360 | @cindex pipes | |
1361 | @emph{Warning:} While input and output redirection work, you cannot use | |
1362 | pipes to pass the output of the program you are debugging to another | |
1363 | program; if you attempt this, GDB is likely to wind up debugging the | |
1364 | wrong program. | |
1365 | @end table | |
1366 | ||
1367 | @c FIXME: Rewrite following paragraph, especially its third sentence. | |
1368 | When you issue the @code{run} command, your program begins to execute | |
1369 | immediately. @xref{Stopping, ,Stopping and Continuing}, for | |
1370 | discussion of how to arrange for your program to stop. Once your | |
1371 | program has been started by the @code{run} command (and then stopped), | |
1372 | you may evaluate expressions that involve calls to functions in your | |
1373 | program, using the @code{print} or @code{call} commands. @xref{Data, | |
1374 | ,Examining Data}. | |
1375 | ||
1376 | If the modification time of your symbol file has changed since the | |
1377 | last time GDB read its symbols, GDB will discard its symbol table and | |
1378 | re-read it. When it does this, GDB tries to retain your current | |
1379 | breakpoints. | |
1380 | ||
1381 | @node Arguments, Environment, Starting, Running | |
1382 | @section Your Program's Arguments | |
1383 | ||
1384 | @cindex arguments (to your program) | |
1385 | The arguments to your program can be specified by the arguments of the | |
1386 | @code{run} command. They are passed to a shell, which expands wildcard | |
1387 | characters and performs redirection of I/O, and thence to your program. | |
1388 | GDB uses the shell indicated by your environment variable | |
1389 | @code{SHELL} if it exists; otherwise, GDB uses @code{/bin/sh}. | |
1390 | ||
1391 | @code{run} with no arguments uses the same arguments used by the previous | |
1392 | @code{run}, or those set by the @code{set args} command. | |
1393 | ||
1394 | @kindex set args | |
1395 | @table @code | |
1396 | @item set args | |
1397 | Specify the arguments to be used the next time your program is run. If | |
1398 | @code{set args} has no arguments, @code{run} will execute your program | |
1399 | with no arguments. Once you have run your program with arguments, | |
1400 | using @code{set args} before the next @code{run} is the only way to run | |
1401 | it again without arguments. | |
1402 | ||
1403 | @item show args | |
1404 | @kindex show args | |
1405 | Show the arguments to give your program when it is started. | |
1406 | @end table | |
1407 | ||
1408 | @node Environment, Working Directory, Arguments, Running | |
1409 | @section Your Program's Environment | |
1410 | ||
1411 | @cindex environment (of your program) | |
1412 | The @dfn{environment} consists of a set of environment variables and | |
1413 | their values. Environment variables conventionally record such things as | |
1414 | your user name, your home directory, your terminal type, and your search | |
1415 | path for programs to run. Usually you set up environment variables with | |
1416 | the shell and they are inherited by all the other programs you run. When | |
1417 | debugging, it can be useful to try running your program with a modified | |
1418 | environment without having to start GDB over again. | |
1419 | ||
1420 | @table @code | |
1421 | @item path @var{directory} | |
1422 | @kindex path | |
1423 | Add @var{directory} to the front of the @code{PATH} environment variable | |
1424 | (the search path for executables), for both GDB and your program. | |
1425 | You may specify several directory names, separated by @samp{:} or | |
1426 | whitespace. If @var{directory} is already in the path, it is moved to | |
1427 | the front, so it will be searched sooner. | |
1428 | ||
1429 | You can use the string @samp{$cwd} to refer to whatever is the current | |
1430 | working directory at the time GDB searches the path. If you use | |
1431 | @samp{.} instead, it refers to the directory where you executed the | |
1432 | @code{path} command. GDB fills in the current path where needed in | |
1433 | the @var{directory} argument, before adding it to the search path. | |
1434 | @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to | |
1435 | @c document that, since repeating it would be a no-op. | |
1436 | ||
1437 | @item show paths | |
1438 | @kindex show paths | |
1439 | Display the list of search paths for executables (the @code{PATH} | |
1440 | environment variable). | |
1441 | ||
1442 | @item show environment @r{[}@var{varname}@r{]} | |
1443 | @kindex show environment | |
1444 | Print the value of environment variable @var{varname} to be given to | |
1445 | your program when it starts. If you do not supply @var{varname}, | |
1446 | print the names and values of all environment variables to be given to | |
1447 | your program. You can abbreviate @code{environment} as @code{env}. | |
1448 | ||
1449 | @item set environment @var{varname} @r{[}=@r{]} @var{value} | |
1450 | @kindex set environment | |
1451 | Sets environment variable @var{varname} to @var{value}. The value | |
1452 | changes for your program only, not for GDB itself. @var{value} may | |
1453 | be any string; the values of environment variables are just strings, and | |
1454 | any interpretation is supplied by your program itself. The @var{value} | |
1455 | parameter is optional; if it is eliminated, the variable is set to a | |
1456 | null value. | |
1457 | @c "any string" here does not include leading, trailing | |
1458 | @c blanks. Gnu asks: does anyone care? | |
1459 | ||
1460 | For example, this command: | |
1461 | ||
1462 | @example | |
1463 | set env USER = foo | |
1464 | @end example | |
1465 | ||
1466 | @noindent | |
1467 | tells a Unix program, when subsequently run, that its user is named | |
1468 | @samp{foo}. (The spaces around @samp{=} are used for clarity here; they | |
1469 | are not actually required.) | |
1470 | ||
1471 | @item unset environment @var{varname} | |
1472 | @kindex unset environment | |
1473 | Remove variable @var{varname} from the environment to be passed to your | |
1474 | program. This is different from @samp{set env @var{varname} =}; | |
1475 | @code{unset environment} removes the variable from the environment, | |
1476 | rather than assigning it an empty value. | |
1477 | @end table | |
1478 | ||
1479 | @node Working Directory, Input/Output, Environment, Running | |
1480 | @section Your Program's Working Directory | |
1481 | ||
1482 | @cindex working directory (of your program) | |
1483 | Each time you start your program with @code{run}, it inherits its | |
1484 | working directory from the current working directory of GDB. GDB's | |
1485 | working directory is initially whatever it inherited from its parent | |
1486 | process (typically the shell), but you can specify a new working | |
1487 | directory in GDB with the @code{cd} command. | |
1488 | ||
1489 | The GDB working directory also serves as a default for the commands | |
1490 | that specify files for GDB to operate on. @xref{Files, ,Commands to | |
1491 | Specify Files}. | |
1492 | ||
1493 | @table @code | |
1494 | @item cd @var{directory} | |
1495 | @kindex cd | |
1496 | Set GDB's working directory to @var{directory}. | |
1497 | ||
1498 | @item pwd | |
1499 | @kindex pwd | |
1500 | Print GDB's working directory. | |
1501 | @end table | |
1502 | ||
1503 | @node Input/Output, Attach, Working Directory, Running | |
1504 | @section Your Program's Input and Output | |
1505 | ||
1506 | @cindex redirection | |
1507 | @cindex i/o | |
1508 | @cindex terminal | |
1509 | By default, the program you run under GDB does input and output to | |
1510 | the same terminal that GDB uses. GDB switches the terminal to | |
1511 | its own terminal modes to interact with you, but it records the terminal | |
1512 | modes your program was using and switches back to them when you continue | |
1513 | running your program. | |
1514 | ||
1515 | @table @code | |
1516 | @item info terminal | |
1517 | @kindex info terminal | |
1518 | Displays GDB's recorded information about the terminal modes your | |
1519 | program is using. | |
1520 | @end table | |
1521 | ||
1522 | You can redirect your program's input and/or output using shell | |
1523 | redirection with the @code{run} command. For example, | |
1524 | ||
1525 | @example | |
1526 | run > outfile | |
1527 | @end example | |
1528 | ||
1529 | @noindent | |
1530 | starts your program, diverting its output to the file @file{outfile}. | |
1531 | ||
1532 | @kindex tty | |
1533 | @cindex controlling terminal | |
1534 | Another way to specify where your program should do input and output is | |
1535 | with the @code{tty} command. This command accepts a file name as | |
1536 | argument, and causes this file to be the default for future @code{run} | |
1537 | commands. It also resets the controlling terminal for the child | |
1538 | process, for future @code{run} commands. For example, | |
1539 | ||
1540 | @example | |
1541 | tty /dev/ttyb | |
1542 | @end example | |
1543 | ||
1544 | @noindent | |
1545 | directs that processes started with subsequent @code{run} commands | |
1546 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1547 | that as their controlling terminal. | |
1548 | ||
1549 | An explicit redirection in @code{run} overrides the @code{tty} command's | |
1550 | effect on the input/output device, but not its effect on the controlling | |
1551 | terminal. | |
1552 | ||
1553 | When you use the @code{tty} command or redirect input in the @code{run} | |
1554 | command, only the input @emph{for your program} is affected. The input | |
1555 | for GDB still comes from your terminal. | |
1556 | ||
1557 | @node Attach, Kill Process, Input/Output, Running | |
1558 | @section Debugging an Already-Running Process | |
1559 | @kindex attach | |
1560 | @cindex attach | |
1561 | ||
1562 | @table @code | |
1563 | @item attach @var{process-id} | |
1564 | This command | |
1565 | attaches to a running process---one that was started outside GDB. | |
1566 | (@code{info files} will show your active targets.) The command takes as | |
1567 | argument a process ID. The usual way to find out the process-id of | |
1568 | a Unix process is with the @code{ps} utility, or with the @samp{jobs -l} | |
1569 | shell command. | |
1570 | ||
1571 | @code{attach} will not repeat if you press @key{RET} a second time after | |
1572 | executing the command. | |
1573 | @end table | |
1574 | ||
1575 | To use @code{attach}, you must be debugging in an environment which | |
1576 | supports processes. You must also have permission to send the process a | |
1577 | signal, and it must have the same effective user ID as the GDB | |
1578 | process. | |
1579 | ||
1580 | When using @code{attach}, you should first use the @code{file} command | |
1581 | to specify the program running in the process and load its symbol table. | |
1582 | @xref{Files, ,Commands to Specify Files}. | |
1583 | ||
1584 | The first thing GDB does after arranging to debug the specified | |
1585 | process is to stop it. You can examine and modify an attached process | |
1586 | with all the GDB commands that are ordinarily available when you start | |
1587 | processes with @code{run}. You can insert breakpoints; you can step and | |
1588 | continue; you can modify storage. If you would rather the process | |
1589 | continue running, you may use the @code{continue} command after | |
1590 | attaching GDB to the process. | |
1591 | ||
1592 | @table @code | |
1593 | @item detach | |
1594 | @kindex detach | |
1595 | When you have finished debugging the attached process, you can use the | |
1596 | @code{detach} command to release it from GDB's control. Detaching | |
1597 | the process continues its execution. After the @code{detach} command, | |
1598 | that process and GDB become completely independent once more, and you | |
1599 | are ready to @code{attach} another process or start one with @code{run}. | |
1600 | @code{detach} will not repeat if you press @key{RET} again after | |
1601 | executing the command. | |
1602 | @end table | |
1603 | ||
1604 | If you exit GDB or use the @code{run} command while you have an attached | |
1605 | process, you kill that process. By default, you will be asked for | |
1606 | confirmation if you try to do either of these things; you can control | |
1607 | whether or not you need to confirm by using the @code{set confirm} command | |
1608 | (@pxref{Messages/Warnings, ,Optional Warnings and Messages}). | |
1609 | ||
1610 | @node Kill Process, , Attach, Running | |
1611 | @c @group | |
1612 | @section Killing the Child Process | |
1613 | ||
1614 | @table @code | |
1615 | @item kill | |
1616 | @kindex kill | |
1617 | Kill the child process in which your program is running under GDB. | |
1618 | @end table | |
1619 | ||
1620 | This command is useful if you wish to debug a core dump instead of a | |
1621 | running process. GDB ignores any core dump file while your program | |
1622 | is running. | |
1623 | @c @end group | |
1624 | ||
1625 | On some operating systems, a program cannot be executed outside GDB | |
1626 | while you have breakpoints set on it inside GDB. You can use the | |
1627 | @code{kill} command in this situation to permit running your program | |
1628 | outside the debugger. | |
1629 | ||
1630 | The @code{kill} command is also useful if you wish to recompile and | |
1631 | relink your program, since on many systems it is impossible to modify an | |
1632 | executable file while it is running in a process. In this case, when you | |
1633 | next type @code{run}, GDB will notice that the file has changed, and | |
1634 | will re-read the symbol table (while trying to preserve your current | |
1635 | breakpoint settings). | |
1636 | ||
1637 | @node Stopping, Stack, Running, Top | |
1638 | @chapter Stopping and Continuing | |
1639 | ||
1640 | The principal purpose of using a debugger is so that you can stop your | |
1641 | program before it terminates; or so that, if your program runs into | |
1642 | trouble, you can investigate and find out why. | |
1643 | ||
1644 | Inside GDB, your program may stop for any of several reasons, such | |
1645 | as a signal, a breakpoint, or reaching a new line after a GDB | |
1646 | command such as @code{step}. You may then examine and change | |
1647 | variables, set new breakpoints or remove old ones, and then continue | |
1648 | execution. Usually, the messages shown by GDB provide ample | |
1649 | explanation of the status of your program---but you can also explicitly | |
1650 | request this information at any time. | |
1651 | ||
1652 | @table @code | |
1653 | @item info program | |
1654 | @kindex info program | |
1655 | Display information about the status of your program: whether it is | |
1656 | running or not, what process it is, and why it stopped. | |
1657 | @end table | |
1658 | ||
1659 | @menu | |
1660 | * Breakpoints:: Breakpoints, Watchpoints, and Exceptions | |
1661 | * Continuing and Stepping:: Resuming Execution | |
1662 | * Signals:: Signals | |
1663 | @end menu | |
1664 | ||
1665 | @node Breakpoints, Continuing and Stepping, Stopping, Stopping | |
1666 | @section Breakpoints, Watchpoints, and Exceptions | |
1667 | ||
1668 | @cindex breakpoints | |
1669 | A @dfn{breakpoint} makes your program stop whenever a certain point in | |
1670 | the program is reached. For each breakpoint, you can add various | |
1671 | conditions to control in finer detail whether your program will stop. | |
1672 | You can set breakpoints with the @code{break} command and its variants | |
1673 | (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where | |
1674 | your program should stop by line number, function name or exact address | |
1675 | in the program. In languages with exception handling (such as GNU | |
1676 | C++), you can also set breakpoints where an exception is raised | |
1677 | (@pxref{Exception Handling, ,Breakpoints and Exceptions}). | |
1678 | ||
1679 | @cindex watchpoints | |
1680 | A @dfn{watchpoint} is a special breakpoint that stops your program | |
1681 | when the value of an expression changes. You must use a different | |
1682 | command to set watchpoints (@pxref{Set Watchpoints, ,Setting | |
1683 | Watchpoints}), but aside from that, you can manage a watchpoint like | |
1684 | any other breakpoint: you enable, disable, and delete both breakpoints | |
1685 | and watchpoints using the same commands. | |
1686 | ||
1687 | Each breakpoint or watchpoint is assigned a number when it is created; | |
1688 | these numbers are successive integers starting with one. In many of the | |
1689 | commands for controlling various features of breakpoints you use the | |
1690 | breakpoint number to say which breakpoint you want to change. Each | |
1691 | breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has | |
1692 | no effect on your program until you enable it again. | |
1693 | ||
1694 | @menu | |
1695 | * Set Breaks:: Setting Breakpoints | |
1696 | * Set Watchpoints:: Setting Watchpoints | |
1697 | * Exception Handling:: Breakpoints and Exceptions | |
1698 | * Delete Breaks:: Deleting Breakpoints | |
1699 | * Disabling:: Disabling Breakpoints | |
1700 | * Conditions:: Break Conditions | |
1701 | * Break Commands:: Breakpoint Command Lists | |
1702 | * Breakpoint Menus:: Breakpoint Menus | |
1703 | * Error in Breakpoints:: | |
1704 | @end menu | |
1705 | ||
1706 | @node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints | |
1707 | @subsection Setting Breakpoints | |
1708 | ||
1709 | @c FIXME LMB what does GDB do if no code on line of breakpt? | |
1710 | @c consider in particular declaration with/without initialization. | |
1711 | @c | |
1712 | @c FIXME 2 is there stuff on this already? break at fun start, already init? | |
1713 | ||
1714 | @kindex break | |
1715 | @kindex b | |
1716 | Breakpoints are set with the @code{break} command (abbreviated @code{b}). | |
1717 | ||
1718 | You have several ways to say where the breakpoint should go. | |
1719 | ||
1720 | @table @code | |
1721 | @item break @var{function} | |
1722 | Set a breakpoint at entry to function @var{function}. When using source | |
1723 | languages that permit overloading of symbols, such as C++, | |
1724 | @var{function} may refer to more than one possible place to break. | |
1725 | @xref{Breakpoint Menus}, for a discussion of that situation. | |
1726 | ||
1727 | @item break +@var{offset} | |
1728 | @itemx break -@var{offset} | |
1729 | Set a breakpoint some number of lines forward or back from the position | |
1730 | at which execution stopped in the currently selected frame. | |
1731 | ||
1732 | @item break @var{linenum} | |
1733 | Set a breakpoint at line @var{linenum} in the current source file. | |
1734 | That file is the last file whose source text was printed. This | |
1735 | breakpoint will stop your program just before it executes any of the | |
1736 | code on that line. | |
1737 | ||
1738 | @item break @var{filename}:@var{linenum} | |
1739 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1740 | ||
1741 | @item break @var{filename}:@var{function} | |
1742 | Set a breakpoint at entry to function @var{function} found in file | |
1743 | @var{filename}. Specifying a file name as well as a function name is | |
1744 | superfluous except when multiple files contain similarly named | |
1745 | functions. | |
1746 | ||
1747 | @item break *@var{address} | |
1748 | Set a breakpoint at address @var{address}. You can use this to set | |
1749 | breakpoints in parts of your program which do not have debugging | |
1750 | information or source files. | |
1751 | ||
1752 | @item break | |
1753 | When called without any arguments, @code{break} sets a breakpoint at | |
1754 | the next instruction to be executed in the selected stack frame | |
1755 | (@pxref{Stack, ,Examining the Stack}). In any selected frame but the | |
1756 | innermost, this will cause your program to stop as soon as control | |
1757 | returns to that frame. This is similar to the effect of a | |
1758 | @code{finish} command in the frame inside the selected frame---except | |
1759 | that @code{finish} does not leave an active breakpoint. If you use | |
1760 | @code{break} without an argument in the innermost frame, GDB will stop | |
1761 | the next time it reaches the current location; this may be useful | |
1762 | inside loops. | |
1763 | ||
1764 | GDB normally ignores breakpoints when it resumes execution, until at | |
1765 | least one instruction has been executed. If it did not do this, you | |
1766 | would be unable to proceed past a breakpoint without first disabling the | |
1767 | breakpoint. This rule applies whether or not the breakpoint already | |
1768 | existed when your program stopped. | |
1769 | ||
1770 | @item break @dots{} if @var{cond} | |
1771 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1772 | @var{cond} each time the breakpoint is reached, and stop only if the | |
1773 | value is nonzero---that is, if @var{cond} evaluates as true. | |
1774 | @samp{@dots{}} stands for one of the possible arguments described | |
1775 | above (or no argument) specifying where to break. @xref{Conditions, | |
1776 | ,Break Conditions}, for more information on breakpoint conditions. | |
1777 | ||
1778 | @item tbreak @var{args} | |
1779 | @kindex tbreak | |
1780 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1781 | same as for the @code{break} command, and the breakpoint is set in the same | |
1782 | way, but the breakpoint is automatically disabled after the first time your | |
1783 | program stops there. @xref{Disabling, ,Disabling Breakpoints}. | |
1784 | ||
1785 | @item rbreak @var{regex} | |
1786 | @kindex rbreak | |
1787 | @cindex regular expression | |
1788 | @c FIXME what kind of regexp? | |
1789 | Set breakpoints on all functions matching the regular expression | |
1790 | @var{regex}. This command | |
1791 | sets an unconditional breakpoint on all matches, printing a list of all | |
1792 | breakpoints it set. Once these breakpoints are set, they are treated | |
1793 | just like the breakpoints set with the @code{break} command. They can | |
1794 | be deleted, disabled, made conditional, etc., in the standard ways. | |
1795 | ||
1796 | When debugging C++ programs, @code{rbreak} is useful for setting | |
1797 | breakpoints on overloaded functions that are not members of any special | |
1798 | classes. | |
1799 | ||
1800 | @kindex info breakpoints | |
1801 | @cindex @code{$_} and @code{info breakpoints} | |
1802 | @item info breakpoints @r{[}@var{n}@r{]} | |
1803 | @item info break @r{[}@var{n}@r{]} | |
1804 | Print a list of all breakpoints (but not watchpoints) set and not | |
1805 | deleted, showing their numbers, where in your program they are, and any | |
1806 | special features in use for them. Disabled breakpoints are included in | |
1807 | the list, but marked as disabled. @code{info break} with a breakpoint | |
1808 | number @var{n} as argument lists only that breakpoint. The | |
1809 | convenience variable @code{$_} and the default examining-address for | |
1810 | the @code{x} command are set to the address of the last breakpoint | |
1811 | listed (@pxref{Memory, ,Examining Memory}). The equivalent command | |
1812 | for watchpoints is @code{info watch}. | |
1813 | @end table | |
1814 | ||
1815 | GDB allows you to set any number of breakpoints at the same place in | |
1816 | your program. There is nothing silly or meaningless about this. When | |
1817 | the breakpoints are conditional, this is even useful | |
1818 | (@pxref{Conditions, ,Break Conditions}). | |
1819 | ||
1820 | @node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints | |
1821 | @subsection Setting Watchpoints | |
1822 | @cindex setting watchpoints | |
1823 | ||
1824 | You can use a watchpoint to stop execution whenever the value of an | |
1825 | expression changes, without having to predict a particular place | |
1826 | where this may happen. | |
1827 | ||
1828 | Watchpoints currently execute two orders of magnitude more slowly than | |
1829 | other breakpoints, but this can well be worth it to catch errors where | |
1830 | you have no clue what part of your program is the culprit. Some | |
1831 | processors provide special hardware to support watchpoint evaluation; future | |
1832 | releases of GDB will use such hardware if it is available. | |
1833 | ||
1834 | @table @code | |
1835 | @kindex watch | |
1836 | @item watch @var{expr} | |
1837 | Set a watchpoint for an expression. | |
1838 | ||
1839 | @kindex info watchpoints | |
1840 | @item info watchpoints | |
1841 | This command prints a list of watchpoints; it is otherwise similar to | |
1842 | @code{info break}. | |
1843 | @end table | |
1844 | ||
1845 | @node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints | |
1846 | @subsection Breakpoints and Exceptions | |
1847 | @cindex exception handlers | |
1848 | ||
1849 | Some languages, such as GNU C++, implement exception handling. You can | |
1850 | use GDB to examine what caused your program to raise an exception, | |
1851 | and to list the exceptions your program is prepared to handle at a | |
1852 | given point in time. | |
1853 | ||
1854 | @table @code | |
1855 | @item catch @var{exceptions} | |
1856 | @kindex catch | |
1857 | You can set breakpoints at active exception handlers by using the | |
1858 | @code{catch} command. @var{exceptions} is a list of names of exceptions | |
1859 | to catch. | |
1860 | @end table | |
1861 | ||
1862 | You can use @code{info catch} to list active exception handlers. | |
1863 | @xref{Frame Info, ,Information About a Frame}. | |
1864 | ||
1865 | There are currently some limitations to exception handling in GDB. | |
1866 | These will be corrected in a future release. | |
1867 | ||
1868 | @itemize @bullet | |
1869 | @item | |
1870 | If you call a function interactively, GDB normally returns | |
1871 | control to you when the function has finished executing. If the call | |
1872 | raises an exception, however, the call may bypass the mechanism that | |
1873 | returns control to you and cause your program to simply continue | |
1874 | running until it hits a breakpoint, catches a signal that GDB is | |
1875 | listening for, or exits. | |
1876 | @item | |
1877 | You cannot raise an exception interactively. | |
1878 | @item | |
1879 | You cannot interactively install an exception handler. | |
1880 | @end itemize | |
1881 | ||
1882 | @cindex raise exceptions | |
1883 | Sometimes @code{catch} is not the best way to debug exception handling: | |
1884 | if you need to know exactly where an exception is raised, it is better to | |
1885 | stop @emph{before} the exception handler is called, since that way you | |
1886 | can see the stack before any unwinding takes place. If you set a | |
1887 | breakpoint in an exception handler instead, it may not be easy to find | |
1888 | out where the exception was raised. | |
1889 | ||
1890 | To stop just before an exception handler is called, you need some | |
1891 | knowledge of the implementation. In the case of GNU C++, exceptions are | |
1892 | raised by calling a library function named @code{__raise_exception} | |
1893 | which has the following ANSI C interface: | |
1894 | ||
1895 | @example | |
1896 | /* @var{addr} is where the exception identifier is stored. | |
1897 | ID is the exception identifier. */ | |
1898 | void __raise_exception (void **@var{addr}, void *@var{id}); | |
1899 | @end example | |
1900 | ||
1901 | @noindent | |
1902 | To make the debugger catch all exceptions before any stack | |
1903 | unwinding takes place, set a breakpoint on @code{__raise_exception} | |
1904 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}). | |
1905 | ||
1906 | With a conditional breakpoint (@pxref{Conditions, ,Break Conditions}) | |
1907 | that depends on the value of @var{id}, you can stop your program when | |
1908 | a specific exception is raised. You can use multiple conditional | |
1909 | breakpoints to stop your program when any of a number of exceptions are | |
1910 | raised. | |
1911 | ||
1912 | @node Delete Breaks, Disabling, Exception Handling, Breakpoints | |
1913 | @subsection Deleting Breakpoints | |
1914 | ||
1915 | @cindex clearing breakpoints, watchpoints | |
1916 | @cindex deleting breakpoints, watchpoints | |
1917 | It is often necessary to eliminate a breakpoint or watchpoint once it | |
1918 | has done its job and you no longer want your program to stop there. This | |
1919 | is called @dfn{deleting} the breakpoint. A breakpoint that has been | |
1920 | deleted no longer exists; it is forgotten. | |
1921 | ||
1922 | With the @code{clear} command you can delete breakpoints according to | |
1923 | where they are in your program. With the @code{delete} command you can | |
1924 | delete individual breakpoints or watchpoints by specifying their | |
1925 | breakpoint numbers. | |
1926 | ||
1927 | It is not necessary to delete a breakpoint to proceed past it. GDB | |
1928 | automatically ignores breakpoints on the first instruction to be executed | |
1929 | when you continue execution without changing the execution address. | |
1930 | ||
1931 | @table @code | |
1932 | @item clear | |
1933 | @kindex clear | |
1934 | Delete any breakpoints at the next instruction to be executed in the | |
1935 | selected stack frame (@pxref{Selection, ,Selecting a Frame}). When | |
1936 | the innermost frame is selected, this is a good way to delete a | |
1937 | breakpoint where your program just stopped. | |
1938 | ||
1939 | @item clear @var{function} | |
1940 | @itemx clear @var{filename}:@var{function} | |
1941 | Delete any breakpoints set at entry to the function @var{function}. | |
1942 | ||
1943 | @item clear @var{linenum} | |
1944 | @itemx clear @var{filename}:@var{linenum} | |
1945 | Delete any breakpoints set at or within the code of the specified line. | |
1946 | ||
1947 | @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1948 | @cindex delete breakpoints | |
1949 | @kindex delete | |
1950 | @kindex d | |
1951 | Delete the breakpoints or watchpoints of the numbers specified as | |
1952 | arguments. If no argument is specified, delete all breakpoints (GDB | |
1953 | asks confirmation, unless you have @code{set confirm off}). You | |
1954 | can abbreviate this command as @code{d}. | |
1955 | @end table | |
1956 | ||
1957 | @node Disabling, Conditions, Delete Breaks, Breakpoints | |
1958 | @subsection Disabling Breakpoints | |
1959 | ||
1960 | @cindex disabled breakpoints | |
1961 | @cindex enabled breakpoints | |
1962 | Rather than deleting a breakpoint or watchpoint, you might prefer to | |
1963 | @dfn{disable} it. This makes the breakpoint inoperative as if it had | |
1964 | been deleted, but remembers the information on the breakpoint so that | |
1965 | you can @dfn{enable} it again later. | |
1966 | ||
1967 | You disable and enable breakpoints and watchpoints with the | |
1968 | @code{enable} and @code{disable} commands, optionally specifying one or | |
1969 | more breakpoint numbers as arguments. Use @code{info break} or | |
1970 | @code{info watch} to print a list of breakpoints or watchpoints if you | |
1971 | do not know which numbers to use. | |
1972 | ||
1973 | A breakpoint or watchpoint can have any of four different states of | |
1974 | enablement: | |
1975 | ||
1976 | @itemize @bullet | |
1977 | @item | |
1978 | Enabled. The breakpoint will stop your program. A breakpoint set | |
1979 | with the @code{break} command starts out in this state. | |
1980 | @item | |
1981 | Disabled. The breakpoint has no effect on your program. | |
1982 | @item | |
1983 | Enabled once. The breakpoint will stop your program, but | |
1984 | when it does so it will become disabled. A breakpoint set | |
1985 | with the @code{tbreak} command starts out in this state. | |
1986 | @item | |
1987 | Enabled for deletion. The breakpoint will stop your program, but | |
1988 | immediately after it does so it will be deleted permanently. | |
1989 | @end itemize | |
1990 | ||
1991 | You can use the following commands to enable or disable breakpoints and | |
1992 | watchpoints: | |
1993 | ||
1994 | @table @code | |
1995 | @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
1996 | @kindex disable breakpoints | |
1997 | @kindex disable | |
1998 | @kindex dis | |
1999 | Disable the specified breakpoints---or all breakpoints, if none are | |
2000 | listed. A disabled breakpoint has no effect but is not forgotten. All | |
2001 | options such as ignore-counts, conditions and commands are remembered in | |
2002 | case the breakpoint is enabled again later. You may abbreviate | |
2003 | @code{disable} as @code{dis}. | |
2004 | ||
2005 | @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]} | |
2006 | @kindex enable breakpoints | |
2007 | @kindex enable | |
2008 | Enable the specified breakpoints (or all defined breakpoints). They | |
2009 | become effective once again in stopping your program. | |
2010 | ||
2011 | @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{} | |
2012 | Enable the specified breakpoints temporarily. Each will be disabled | |
2013 | again the next time it stops your program. | |
2014 | ||
2015 | @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{} | |
2016 | Enable the specified breakpoints to work once and then die. Each of | |
2017 | the breakpoints will be deleted the next time it stops your program. | |
2018 | @end table | |
2019 | ||
2020 | Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, | |
2021 | ,Setting Breakpoints}), breakpoints that you set are initially | |
2022 | enabled; subsequently, they become disabled or enabled only when you | |
2023 | use one of the commands above. (The command @code{until} can set and | |
2024 | delete a breakpoint of its own, but it will not change the state of | |
98fe4566 | 2025 | your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.) |
7e54e97f RP |
2026 | |
2027 | @node Conditions, Break Commands, Disabling, Breakpoints | |
2028 | @subsection Break Conditions | |
2029 | @cindex conditional breakpoints | |
2030 | @cindex breakpoint conditions | |
2031 | ||
2032 | @c FIXME what is scope of break condition expr? Context where wanted? | |
2033 | @c in particular for a watchpoint? | |
2034 | The simplest sort of breakpoint breaks every time your program reaches a | |
2035 | specified place. You can also specify a @dfn{condition} for a | |
2036 | breakpoint. A condition is just a Boolean expression in your | |
2037 | programming language (@pxref{Expressions, ,Expressions}). A breakpoint with | |
2038 | a condition evaluates the expression each time your program reaches it, | |
2039 | and your program stops only if the condition is @emph{true}. | |
2040 | ||
2041 | This is the converse of using assertions for program validation; in that | |
2042 | situation, you want to stop when the assertion is violated---that is, | |
2043 | when the condition is false. In C, if you want to test an assertion expressed | |
2044 | by the condition @var{assert}, you should set the condition | |
2045 | @samp{! @var{assert}} on the appropriate breakpoint. | |
2046 | ||
2047 | Conditions are also accepted for watchpoints; you may not need them, | |
2048 | since a watchpoint is inspecting the value of an expression anyhow---but | |
2049 | it might be simpler, say, to just set a watchpoint on a variable name, | |
2050 | and specify a condition that tests whether the new value is an interesting | |
2051 | one. | |
2052 | ||
2053 | Break conditions can have side effects, and may even call functions in | |
2054 | your program. This can be useful, for example, to activate functions | |
2055 | that log program progress, or to use your own print functions to | |
2056 | format special data structures. The effects are completely predictable | |
2057 | unless there is another enabled breakpoint at the same address. (In | |
2058 | that case, GDB might see the other breakpoint first and stop your | |
2059 | program without checking the condition of this one.) Note that | |
2060 | breakpoint commands are usually more convenient and flexible for the | |
2061 | purpose of performing side effects when a breakpoint is reached | |
2062 | (@pxref{Break Commands, ,Breakpoint Command Lists}). | |
2063 | ||
2064 | Break conditions can be specified when a breakpoint is set, by using | |
2065 | @samp{if} in the arguments to the @code{break} command. @xref{Set | |
2066 | Breaks, ,Setting Breakpoints}. They can also be changed at any time | |
2067 | with the @code{condition} command. The @code{watch} command does not | |
2068 | recognize the @code{if} keyword; @code{condition} is the only way to | |
2069 | impose a further condition on a watchpoint. | |
2070 | ||
2071 | @table @code | |
2072 | @item condition @var{bnum} @var{expression} | |
2073 | @kindex condition | |
2074 | Specify @var{expression} as the break condition for breakpoint or | |
2075 | watchpoint number @var{bnum}. From now on, this breakpoint will stop | |
2076 | your program only if the value of @var{expression} is true (nonzero, in | |
2077 | C). When you use @code{condition}, GDB checks @var{expression} | |
2078 | immediately for syntactic correctness, and to determine whether symbols | |
2079 | in it have referents in the context of your breakpoint. | |
2080 | @c FIXME so what does GDB do if there is no referent? Moreover, what | |
2081 | @c about watchpoints? | |
2082 | GDB does | |
2083 | not actually evaluate @var{expression} at the time the @code{condition} | |
2084 | command is given, however. @xref{Expressions, ,Expressions}. | |
2085 | ||
2086 | @item condition @var{bnum} | |
2087 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
2088 | an ordinary unconditional breakpoint. | |
2089 | @end table | |
2090 | ||
2091 | @cindex ignore count (of breakpoint) | |
2092 | A special case of a breakpoint condition is to stop only when the | |
2093 | breakpoint has been reached a certain number of times. This is so | |
2094 | useful that there is a special way to do it, using the @dfn{ignore | |
2095 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
2096 | is an integer. Most of the time, the ignore count is zero, and | |
2097 | therefore has no effect. But if your program reaches a breakpoint whose | |
2098 | ignore count is positive, then instead of stopping, it just decrements | |
2099 | the ignore count by one and continues. As a result, if the ignore count | |
2100 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
2101 | is reached. | |
2102 | ||
2103 | @table @code | |
2104 | @item ignore @var{bnum} @var{count} | |
2105 | @kindex ignore | |
2106 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
2107 | The next @var{count} times the breakpoint is reached, your program's | |
2108 | execution will not stop; other than to decrement the ignore count, GDB | |
2109 | takes no action. | |
2110 | ||
2111 | To make the breakpoint stop the next time it is reached, specify | |
2112 | a count of zero. | |
2113 | ||
2114 | @item continue @var{count} | |
2115 | @itemx c @var{count} | |
2116 | @itemx fg @var{count} | |
2117 | @kindex continue @var{count} | |
2118 | Continue execution of your program, setting the ignore count of the | |
2119 | breakpoint where your program stopped to @var{count} minus one. | |
2120 | Thus, your program will not stop at this breakpoint until the | |
2121 | @var{count}'th time it is reached. | |
2122 | ||
2123 | An argument to this command is meaningful only when your program stopped | |
2124 | due to a breakpoint. At other times, the argument to @code{continue} is | |
2125 | ignored. | |
2126 | ||
2127 | The synonym @code{fg} is provided purely for convenience, and has | |
2128 | exactly the same behavior as other forms of the command. | |
2129 | @end table | |
2130 | ||
2131 | If a breakpoint has a positive ignore count and a condition, the condition | |
2132 | is not checked. Once the ignore count reaches zero, the condition will | |
2133 | be checked. | |
2134 | ||
2135 | You could achieve the effect of the ignore count with a condition such | |
2136 | as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that | |
2137 | is decremented each time. @xref{Convenience Vars, ,Convenience | |
2138 | Variables}. | |
2139 | ||
2140 | @node Break Commands, Breakpoint Menus, Conditions, Breakpoints | |
2141 | @subsection Breakpoint Command Lists | |
2142 | ||
2143 | @cindex breakpoint commands | |
2144 | You can give any breakpoint (or watchpoint) a series of commands to | |
2145 | execute when your program stops due to that breakpoint. For example, you | |
2146 | might want to print the values of certain expressions, or enable other | |
2147 | breakpoints. | |
2148 | ||
2149 | @table @code | |
2150 | @item commands @r{[}@var{bnum}@r{]} | |
2151 | @itemx @dots{} @var{command-list} @dots{} | |
2152 | @itemx end | |
2153 | @kindex commands | |
2154 | @kindex end | |
2155 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
2156 | themselves appear on the following lines. Type a line containing just | |
2157 | @code{end} to terminate the commands. | |
2158 | ||
2159 | To remove all commands from a breakpoint, type @code{commands} and | |
2160 | follow it immediately with @code{end}; that is, give no commands. | |
2161 | ||
2162 | With no @var{bnum} argument, @code{commands} refers to the last | |
2163 | breakpoint or watchpoint set (not to the breakpoint most recently | |
2164 | encountered). | |
2165 | @end table | |
2166 | ||
2167 | Pressing @key{RET} as a means of repeating the last GDB command is | |
2168 | disabled within a @var{command-list}. | |
2169 | ||
2170 | You can use breakpoint commands to start your program up again. Simply | |
2171 | use the @code{continue} command, or @code{step}, or any other command | |
2172 | that resumes execution. Subsequent commands in the command list are | |
2173 | ignored. | |
2174 | ||
2175 | @kindex silent | |
2176 | If the first command specified is @code{silent}, the usual message about | |
2177 | stopping at a breakpoint is not printed. This may be desirable for | |
2178 | breakpoints that are to print a specific message and then continue. | |
2179 | If the remaining commands too print nothing, you will see no sign that | |
2180 | the breakpoint was reached at all. @code{silent} is meaningful only | |
2181 | at the beginning of a breakpoint command list. | |
2182 | ||
2183 | The commands @code{echo} and @code{output} that allow you to print | |
2184 | precisely controlled output are often useful in silent breakpoints. | |
2185 | @xref{Output, ,Commands for Controlled Output}. | |
2186 | ||
2187 | For example, here is how you could use breakpoint commands to print the | |
2188 | value of @code{x} at entry to @code{foo} whenever @code{x} is positive. | |
2189 | ||
2190 | @example | |
2191 | break foo if x>0 | |
2192 | commands | |
2193 | silent | |
2194 | echo x is\040 | |
2195 | output x | |
2196 | echo \n | |
2197 | cont | |
2198 | end | |
2199 | @end example | |
2200 | ||
2201 | One application for breakpoint commands is to compensate for one bug so | |
2202 | you can test for another. Put a breakpoint just after the erroneous line | |
2203 | of code, give it a condition to detect the case in which something | |
2204 | erroneous has been done, and give it commands to assign correct values | |
2205 | to any variables that need them. End with the @code{continue} command | |
2206 | so that your program does not stop, and start with the @code{silent} | |
2207 | command so that no output is produced. Here is an example: | |
2208 | ||
2209 | @example | |
2210 | break 403 | |
2211 | commands | |
2212 | silent | |
2213 | set x = y + 4 | |
2214 | cont | |
2215 | end | |
2216 | @end example | |
2217 | ||
2218 | @cindex lost output | |
2219 | One deficiency in the operation of automatically continuing breakpoints | |
2220 | under Unix appears when your program uses raw mode for the terminal. | |
2221 | GDB switches back to its own terminal modes (not raw) before executing | |
2222 | commands, and then must switch back to raw mode when your program is | |
2223 | continued. This causes any pending terminal input to be lost. | |
2224 | @c FIXME: revisit below when GNU sys avail. | |
2225 | @c In the GNU system, this will be fixed by changing the behavior of | |
2226 | @c terminal modes. | |
2227 | ||
2228 | Under Unix, you can get around this problem by writing actions into | |
2229 | the breakpoint condition rather than in commands. For example | |
2230 | ||
2231 | @example | |
2232 | condition 5 (x = y + 4), 0 | |
2233 | @end example | |
2234 | ||
2235 | @noindent | |
2236 | specifies a condition expression (@pxref{Expressions, ,Expressions}) that will | |
2237 | change @code{x} as needed, then always have the value zero so your | |
2238 | program will not stop. No input is lost here, because GDB evaluates | |
2239 | break conditions without changing the terminal modes. When you want | |
2240 | to have nontrivial conditions for performing the side effects, the | |
2241 | operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
2242 | ||
2243 | @node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints | |
2244 | @subsection Breakpoint Menus | |
2245 | @cindex overloading | |
2246 | @cindex symbol overloading | |
2247 | ||
2248 | Some programming languages (notably C++) permit a single function name | |
2249 | to be defined several times, for application in different contexts. | |
2250 | This is called @dfn{overloading}. When a function name is overloaded, | |
2251 | @samp{break @var{function}} is not enough to tell GDB where you | |
2252 | want a breakpoint. GDB offers you a menu of numbered choices for | |
2253 | different possible breakpoints, and waits for your selection with the | |
2254 | prompt @samp{>}. The first two options are always @samp{[0] cancel} | |
2255 | and @samp{[1] all}. Typing @kbd{1} sets a breakpoint at each | |
2256 | definition of @var{function}, and typing @kbd{0} aborts the | |
2257 | @code{break} command without setting any new breakpoints. | |
2258 | ||
2259 | For example, the following session excerpt shows an attempt to set a | |
2260 | breakpoint at the overloaded symbol @code{String::after}. | |
2261 | We choose three particular definitions of that function name: | |
2262 | ||
2263 | @example | |
2264 | (gdb) b String::after | |
2265 | [0] cancel | |
2266 | [1] all | |
2267 | [2] file:String.cc; line number:867 | |
2268 | [3] file:String.cc; line number:860 | |
2269 | [4] file:String.cc; line number:875 | |
2270 | [5] file:String.cc; line number:853 | |
2271 | [6] file:String.cc; line number:846 | |
2272 | [7] file:String.cc; line number:735 | |
2273 | > 2 4 6 | |
2274 | Breakpoint 1 at 0xb26c: file String.cc, line 867. | |
2275 | Breakpoint 2 at 0xb344: file String.cc, line 875. | |
2276 | Breakpoint 3 at 0xafcc: file String.cc, line 846. | |
2277 | Multiple breakpoints were set. | |
2278 | Use the "delete" command to delete unwanted breakpoints. | |
2279 | (gdb) | |
2280 | @end example | |
2281 | ||
2282 | @node Error in Breakpoints, , Breakpoint Menus, Breakpoints | |
2283 | @subsection ``Cannot Insert Breakpoints'' | |
2284 | ||
2285 | @c FIXME: "cannot insert breakpoints" error, v unclear. | |
2286 | @c Q in pending mail to Gilmore. [email protected], 26mar91 | |
2287 | @c some light may be shed by looking at instances of | |
2288 | @c ONE_PROCESS_WRITETEXT. But error seems possible otherwise | |
2289 | @c too. pesch, 20sep91 | |
2290 | Under some operating systems, breakpoints cannot be used in a program if | |
2291 | any other process is running that program. In this situation, | |
2292 | attempting to run or continue a program with a breakpoint causes GDB | |
2293 | to stop the other process. | |
2294 | ||
2295 | When this happens, you have three ways to proceed: | |
2296 | ||
2297 | @enumerate | |
2298 | @item | |
2299 | Remove or disable the breakpoints, then continue. | |
2300 | ||
2301 | @item | |
2302 | Suspend GDB, and copy the file containing your program to a new name. | |
2303 | Resume GDB and use the @code{exec-file} command to specify that GDB | |
2304 | should run your program under that name. Then start your program again. | |
2305 | ||
2306 | @c FIXME: RMS commented here "Show example". Maybe when someone | |
2307 | @c explains the first FIXME: in this section... | |
2308 | ||
2309 | @item | |
2310 | Relink your program so that the text segment is nonsharable, using the | |
2311 | linker option @samp{-N}. The operating system limitation may not apply | |
2312 | to nonsharable executables. | |
2313 | @end enumerate | |
2314 | ||
2315 | @node Continuing and Stepping, Signals, Breakpoints, Stopping | |
2316 | @section Continuing and Stepping | |
2317 | ||
2318 | @cindex stepping | |
2319 | @cindex continuing | |
2320 | @cindex resuming execution | |
2321 | @dfn{Continuing} means resuming program execution until your program | |
2322 | completes normally. In contrast, @dfn{stepping} means executing just | |
2323 | one more ``step'' of your program, where ``step'' may mean either one | |
2324 | line of source code, or one machine instruction (depending on what | |
2325 | particular command you use). Either when continuing | |
2326 | or when stepping, your program may stop even sooner, due to a breakpoint | |
2327 | or to a signal. (If due to a signal, you may want to use @code{handle}, | |
2328 | or use @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.) | |
2329 | ||
2330 | @table @code | |
2331 | @item continue @r{[}@var{ignore-count}@r{]} | |
2332 | @kindex continue | |
2333 | Resume program execution, at the address where your program last stopped; | |
2334 | any breakpoints set at that address are bypassed. The optional argument | |
2335 | @var{ignore-count} allows you to specify a further number of times to | |
2336 | ignore a breakpoint at this location; its effect is like that of | |
2337 | @code{ignore} (@pxref{Conditions, ,Break Conditions}). | |
2338 | ||
2339 | To resume execution at a different place, you can use @code{return} | |
2340 | (@pxref{Returning, ,Returning from a Function}) to go back to the | |
2341 | calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a | |
2342 | Different Address}) to go to an arbitrary location in your program. | |
2343 | @end table | |
2344 | ||
2345 | A typical technique for using stepping is to set a breakpoint | |
2346 | (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the | |
2347 | beginning of the function or the section of your program where a | |
2348 | problem is believed to lie, run your program until it stops at that | |
2349 | breakpoint, and then step through the suspect area, examining the | |
2350 | variables that are interesting, until you see the problem happen. | |
2351 | ||
2352 | @table @code | |
2353 | @item step | |
2354 | @kindex step | |
2355 | @kindex s | |
2356 | Continue running your program until control reaches a different source | |
2357 | line, then stop it and return control to GDB. This command is | |
2358 | abbreviated @code{s}. | |
2359 | ||
2360 | @quotation | |
2361 | @emph{Warning:} If you use the @code{step} command while control is | |
2362 | within a function that was compiled without debugging information, | |
2363 | execution will proceed until control reaches another function. | |
2364 | @end quotation | |
2365 | ||
2366 | @item step @var{count} | |
2367 | Continue running as in @code{step}, but do so @var{count} times. If a | |
2368 | breakpoint is reached or a signal not related to stepping occurs before | |
2369 | @var{count} steps, stepping stops right away. | |
2370 | ||
2371 | @item next @r{[}@var{count}@r{]} | |
2372 | @kindex next | |
2373 | @kindex n | |
2374 | Continue to the next source line in the current (innermost) stack frame. | |
2375 | Similar to @code{step}, but any function calls appearing within the line | |
2376 | of code are executed without stopping. Execution stops when control | |
2377 | reaches a different line of code at the stack level which was executing | |
2378 | when the @code{next} command was given. This command is abbreviated | |
2379 | @code{n}. | |
2380 | ||
2381 | An argument @var{count} is a repeat count, as for @code{step}. | |
2382 | ||
2383 | @code{next} within a function that lacks debugging information acts like | |
2384 | @code{step}, but any function calls appearing within the code of the | |
2385 | function are executed without stopping. | |
2386 | ||
2387 | @item finish | |
2388 | @kindex finish | |
2389 | Continue running until just after function in the selected stack frame | |
2390 | returns. Print the returned value (if any). | |
2391 | ||
2392 | Contrast this with the @code{return} command (@pxref{Returning, | |
2393 | ,Returning from a Function}). | |
2394 | ||
2395 | @item until | |
2396 | @kindex until | |
2397 | @item u | |
2398 | @kindex u | |
2399 | Continue running until a source line past the current line, in the | |
2400 | current stack frame, is reached. This command is used to avoid single | |
2401 | stepping through a loop more than once. It is like the @code{next} | |
2402 | command, except that when @code{until} encounters a jump, it | |
2403 | automatically continues execution until the program counter is greater | |
2404 | than the address of the jump. | |
2405 | ||
2406 | This means that when you reach the end of a loop after single stepping | |
2407 | though it, @code{until} will cause your program to continue execution | |
2408 | until the loop is exited. In contrast, a @code{next} command at the end | |
2409 | of a loop will simply step back to the beginning of the loop, which | |
2410 | would force you to step through the next iteration. | |
2411 | ||
2412 | @code{until} always stops your program if it attempts to exit the current | |
2413 | stack frame. | |
2414 | ||
2415 | @code{until} may produce somewhat counterintuitive results if the order | |
2416 | of machine code does not match the order of the source lines. For | |
2417 | example, in the following excerpt from a debugging session, the @code{f} | |
2418 | (@code{frame}) command shows that execution is stopped at line | |
2419 | @code{206}; yet when we use @code{until}, we get to line @code{195}: | |
2420 | ||
2421 | @example | |
2422 | (gdb) f | |
2423 | #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 | |
2424 | 206 expand_input(); | |
2425 | (gdb) until | |
2426 | 195 for ( ; argc > 0; NEXTARG) @{ | |
2427 | @end example | |
2428 | ||
2429 | This happened because, for execution efficiency, the compiler had | |
2430 | generated code for the loop closure test at the end, rather than the | |
2431 | start, of the loop---even though the test in a C @code{for}-loop is | |
2432 | written before the body of the loop. The @code{until} command appeared | |
2433 | to step back to the beginning of the loop when it advanced to this | |
2434 | expression; however, it has not really gone to an earlier | |
2435 | statement---not in terms of the actual machine code. | |
2436 | ||
2437 | @code{until} with no argument works by means of single | |
2438 | instruction stepping, and hence is slower than @code{until} with an | |
2439 | argument. | |
2440 | ||
2441 | @item until @var{location} | |
2442 | @item u @var{location} | |
2443 | Continue running your program until either the specified location is | |
2444 | reached, or the current stack frame returns. @var{location} is any of | |
2445 | the forms of argument acceptable to @code{break} (@pxref{Set Breaks, | |
2446 | ,Setting Breakpoints}). This form of the command uses breakpoints, | |
2447 | and hence is quicker than @code{until} without an argument. | |
2448 | ||
2449 | @item stepi | |
2450 | @itemx si | |
2451 | @kindex stepi | |
2452 | @kindex si | |
2453 | Execute one machine instruction, then stop and return to the debugger. | |
2454 | ||
2455 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2456 | instructions. This will cause the next instruction to be executed to | |
2457 | be displayed automatically at each stop. @xref{Auto Display, | |
2458 | ,Automatic Display}. | |
2459 | ||
2460 | An argument is a repeat count, as in @code{step}. | |
2461 | ||
2462 | @item nexti | |
2463 | @itemx ni | |
2464 | @kindex nexti | |
2465 | @kindex ni | |
2466 | Execute one machine instruction, but if it is a function call, | |
2467 | proceed until the function returns. | |
2468 | ||
2469 | An argument is a repeat count, as in @code{next}. | |
2470 | @end table | |
2471 | ||
2472 | @node Signals, , Continuing and Stepping, Stopping | |
2473 | @section Signals | |
2474 | @cindex signals | |
2475 | ||
2476 | A signal is an asynchronous event that can happen in a program. The | |
2477 | operating system defines the possible kinds of signals, and gives each | |
2478 | kind a name and a number. For example, in Unix @code{SIGINT} is the | |
2479 | signal a program gets when you type an interrupt (often @kbd{C-c}); | |
2480 | @code{SIGSEGV} is the signal a program gets from referencing a place in | |
2481 | memory far away from all the areas in use; @code{SIGALRM} occurs when | |
2482 | the alarm clock timer goes off (which happens only if your program has | |
2483 | requested an alarm). | |
2484 | ||
2485 | @cindex fatal signals | |
2486 | Some signals, including @code{SIGALRM}, are a normal part of the | |
2487 | functioning of your program. Others, such as @code{SIGSEGV}, indicate | |
2488 | errors; these signals are @dfn{fatal} (kill your program immediately) if the | |
2489 | program has not specified in advance some other way to handle the signal. | |
2490 | @code{SIGINT} does not indicate an error in your program, but it is normally | |
2491 | fatal so it can carry out the purpose of the interrupt: to kill the program. | |
2492 | ||
2493 | GDB has the ability to detect any occurrence of a signal in your | |
2494 | program. You can tell GDB in advance what to do for each kind of | |
2495 | signal. | |
2496 | ||
2497 | @cindex handling signals | |
2498 | Normally, GDB is set up to ignore non-erroneous signals like @code{SIGALRM} | |
2499 | (so as not to interfere with their role in the functioning of your program) | |
2500 | but to stop your program immediately whenever an error signal happens. | |
2501 | You can change these settings with the @code{handle} command. | |
2502 | ||
2503 | @table @code | |
2504 | @item info signals | |
2505 | @kindex info signals | |
2506 | Print a table of all the kinds of signals and how GDB has been told to | |
2507 | handle each one. You can use this to see the signal numbers of all | |
2508 | the defined types of signals. | |
2509 | ||
2510 | @item handle @var{signal} @var{keywords}@dots{} | |
2511 | @kindex handle | |
2512 | Change the way GDB handles signal @var{signal}. @var{signal} can be the | |
2513 | number of a signal or its name (with or without the @samp{SIG} at the | |
2514 | beginning). The @var{keywords} say what change to make. | |
2515 | @end table | |
2516 | ||
2517 | @c @group | |
2518 | The keywords allowed by the @code{handle} command can be abbreviated. | |
2519 | Their full names are: | |
2520 | ||
2521 | @table @code | |
2522 | @item nostop | |
2523 | GDB should not stop your program when this signal happens. It may | |
2524 | still print a message telling you that the signal has come in. | |
2525 | ||
2526 | @item stop | |
2527 | GDB should stop your program when this signal happens. This implies | |
2528 | the @code{print} keyword as well. | |
2529 | ||
2530 | @item print | |
2531 | GDB should print a message when this signal happens. | |
2532 | ||
2533 | @item noprint | |
2534 | GDB should not mention the occurrence of the signal at all. This | |
2535 | implies the @code{nostop} keyword as well. | |
2536 | ||
2537 | @item pass | |
2538 | GDB should allow your program to see this signal; your program will be | |
2539 | able to handle the signal, or may be terminated if the signal is fatal | |
2540 | and not handled. | |
2541 | ||
2542 | @item nopass | |
2543 | GDB should not allow your program to see this signal. | |
2544 | @end table | |
2545 | @c @end group | |
2546 | ||
2547 | When a signal has been set to stop your program, your program cannot see the | |
2548 | signal until you continue. It will see the signal then, if @code{pass} is | |
2549 | in effect for the signal in question @i{at that time}. In other words, | |
2550 | after GDB reports a signal, you can use the @code{handle} command with | |
2551 | @code{pass} or @code{nopass} to control whether that signal will be seen by | |
2552 | your program when you later continue it. | |
2553 | ||
2554 | You can also use the @code{signal} command to prevent your program from | |
2555 | seeing a signal, or cause it to see a signal it normally would not see, | |
2556 | or to give it any signal at any time. For example, if your program stopped | |
2557 | due to some sort of memory reference error, you might store correct | |
2558 | values into the erroneous variables and continue, hoping to see more | |
2559 | execution; but your program would probably terminate immediately as | |
2560 | a result of the fatal signal once it saw the signal. To prevent this, | |
2561 | you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your | |
2562 | Program a Signal}. | |
2563 | ||
2564 | @node Stack, Source, Stopping, Top | |
2565 | @chapter Examining the Stack | |
2566 | ||
2567 | When your program has stopped, the first thing you need to know is where it | |
2568 | stopped and how it got there. | |
2569 | ||
2570 | @cindex call stack | |
2571 | Each time your program performs a function call, the information about | |
2572 | where in your program the call was made from is saved in a block of data | |
2573 | called a @dfn{stack frame}. The frame also contains the arguments of the | |
2574 | call and the local variables of the function that was called. All the | |
2575 | stack frames are allocated in a region of memory called the @dfn{call | |
2576 | stack}. | |
2577 | ||
2578 | When your program stops, the GDB commands for examining the stack allow you | |
2579 | to see all of this information. | |
2580 | ||
2581 | @cindex selected frame | |
2582 | One of the stack frames is @dfn{selected} by GDB and many GDB commands | |
2583 | refer implicitly to the selected frame. In particular, whenever you ask | |
2584 | GDB for the value of a variable in your program, the value is found in the | |
2585 | selected frame. There are special GDB commands to select whichever frame | |
2586 | you are interested in. | |
2587 | ||
2588 | When your program stops, GDB automatically selects the currently executing | |
2589 | frame and describes it briefly as the @code{frame} command does | |
2590 | (@pxref{Frame Info, ,Information About a Frame}). | |
2591 | ||
2592 | @menu | |
2593 | * Frames:: Stack Frames | |
2594 | * Backtrace:: Backtraces | |
2595 | * Selection:: Selecting a Frame | |
2596 | * Frame Info:: Information on a Frame | |
2597 | @end menu | |
2598 | ||
2599 | @node Frames, Backtrace, Stack, Stack | |
2600 | @section Stack Frames | |
2601 | ||
2602 | @cindex frame | |
2603 | @cindex stack frame | |
2604 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2605 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2606 | with one call to one function. The frame contains the arguments given | |
2607 | to the function, the function's local variables, and the address at | |
2608 | which the function is executing. | |
2609 | ||
2610 | @cindex initial frame | |
2611 | @cindex outermost frame | |
2612 | @cindex innermost frame | |
2613 | When your program is started, the stack has only one frame, that of the | |
2614 | function @code{main}. This is called the @dfn{initial} frame or the | |
2615 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2616 | made. Each time a function returns, the frame for that function invocation | |
2617 | is eliminated. If a function is recursive, there can be many frames for | |
2618 | the same function. The frame for the function in which execution is | |
2619 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2620 | recently created of all the stack frames that still exist. | |
2621 | ||
2622 | @cindex frame pointer | |
2623 | Inside your program, stack frames are identified by their addresses. A | |
2624 | stack frame consists of many bytes, each of which has its own address; each | |
2625 | kind of computer has a convention for choosing one of those bytes whose | |
2626 | address serves as the address of the frame. Usually this address is kept | |
2627 | in a register called the @dfn{frame pointer register} while execution is | |
2628 | going on in that frame. | |
2629 | ||
2630 | @cindex frame number | |
2631 | GDB assigns numbers to all existing stack frames, starting with | |
2632 | zero for the innermost frame, one for the frame that called it, | |
2633 | and so on upward. These numbers do not really exist in your program; | |
2634 | they are assigned by GDB to give you a way of designating stack | |
2635 | frames in GDB commands. | |
2636 | ||
2637 | @cindex frameless execution | |
2638 | Some compilers allow functions to be compiled so that they operate | |
2639 | without stack frames. (For example, the @code{gcc} option | |
2640 | @samp{-fomit-frame-pointer} will generate functions without a frame.) | |
2641 | This is occasionally done with heavily used library functions to save | |
2642 | the frame setup time. GDB has limited facilities for dealing with | |
2643 | these function invocations. If the innermost function invocation has no | |
2644 | stack frame, GDB will nevertheless regard it as though it had a | |
2645 | separate frame, which is numbered zero as usual, allowing correct | |
2646 | tracing of the function call chain. However, GDB has no provision | |
2647 | for frameless functions elsewhere in the stack. | |
2648 | ||
2649 | @node Backtrace, Selection, Frames, Stack | |
2650 | @section Backtraces | |
2651 | ||
2652 | A backtrace is a summary of how your program got where it is. It shows one | |
2653 | line per frame, for many frames, starting with the currently executing | |
2654 | frame (frame zero), followed by its caller (frame one), and on up the | |
2655 | stack. | |
2656 | ||
2657 | @table @code | |
2658 | @item backtrace | |
2659 | @itemx bt | |
2660 | @kindex backtrace | |
2661 | @kindex bt | |
2662 | Print a backtrace of the entire stack: one line per frame for all | |
2663 | frames in the stack. | |
2664 | ||
2665 | You can stop the backtrace at any time by typing the system interrupt | |
2666 | character, normally @kbd{C-c}. | |
2667 | ||
2668 | @item backtrace @var{n} | |
2669 | @itemx bt @var{n} | |
2670 | Similar, but print only the innermost @var{n} frames. | |
2671 | ||
2672 | @item backtrace -@var{n} | |
2673 | @itemx bt -@var{n} | |
2674 | Similar, but print only the outermost @var{n} frames. | |
2675 | @end table | |
2676 | ||
2677 | @kindex where | |
2678 | @kindex info stack | |
2679 | @kindex info s | |
2680 | The names @code{where} and @code{info stack} (abbreviated @code{info s}) | |
2681 | are additional aliases for @code{backtrace}. | |
2682 | ||
2683 | Each line in the backtrace shows the frame number and the function name. | |
2684 | The program counter value is also shown---unless you use @code{set | |
2685 | print address off}. The backtrace also shows the source file name and | |
2686 | line number, as well as the arguments to the function. The program | |
2687 | counter value is omitted if it is at the beginning of the code for that | |
2688 | line number. | |
2689 | ||
2690 | Here is an example of a backtrace. It was made with the command | |
2691 | @samp{bt 3}, so it shows the innermost three frames. | |
2692 | ||
2693 | @smallexample | |
2694 | @group | |
2695 | #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) | |
2696 | at builtin.c:993 | |
2697 | #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 | |
2698 | #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) | |
2699 | at macro.c:71 | |
2700 | (More stack frames follow...) | |
2701 | @end group | |
2702 | @end smallexample | |
2703 | ||
2704 | @noindent | |
2705 | The display for frame zero does not begin with a program counter | |
2706 | value, indicating that your program has stopped at the beginning of the | |
2707 | code for line @code{993} of @code{builtin.c}. | |
2708 | ||
2709 | @node Selection, Frame Info, Backtrace, Stack | |
2710 | @section Selecting a Frame | |
2711 | ||
2712 | Most commands for examining the stack and other data in your program work on | |
2713 | whichever stack frame is selected at the moment. Here are the commands for | |
2714 | selecting a stack frame; all of them finish by printing a brief description | |
2715 | of the stack frame just selected. | |
2716 | ||
2717 | @table @code | |
2718 | @item frame @var{n} | |
2719 | @itemx f @var{n} | |
2720 | @kindex frame | |
2721 | @kindex f | |
2722 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2723 | (currently executing) frame, frame one is the frame that called the | |
2724 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2725 | frame. | |
2726 | ||
2727 | @item frame @var{addr} | |
2728 | @itemx f @var{addr} | |
2729 | Select the frame at address @var{addr}. This is useful mainly if the | |
2730 | chaining of stack frames has been damaged by a bug, making it | |
2731 | impossible for GDB to assign numbers properly to all frames. In | |
2732 | addition, this can be useful when your program has multiple stacks and | |
2733 | switches between them. | |
2734 | ||
2735 | On the SPARC architecture, @code{frame} needs two addresses to | |
2736 | select an arbitrary frame: a frame pointer and a stack pointer. | |
2737 | @c note to future updaters: this is conditioned on a flag | |
2738 | @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used | |
2739 | @c by SPARC, hence the specific attribution. Generalize or list all | |
2740 | @c possibilities if more supported machines start doing this. | |
2741 | ||
2742 | @item up @var{n} | |
2743 | @kindex up | |
2744 | Move @var{n} frames up the stack. For positive numbers @var{n}, this | |
2745 | advances toward the outermost frame, to higher frame numbers, to frames | |
2746 | that have existed longer. @var{n} defaults to one. | |
2747 | ||
2748 | @item down @var{n} | |
2749 | @kindex down | |
2750 | @kindex do | |
2751 | Move @var{n} frames down the stack. For positive numbers @var{n}, this | |
2752 | advances toward the innermost frame, to lower frame numbers, to frames | |
2753 | that were created more recently. @var{n} defaults to one. You may | |
2754 | abbreviate @code{down} as @code{do}. | |
2755 | @end table | |
2756 | ||
2757 | All of these commands end by printing two lines of output describing the | |
2758 | frame. The first line shows the frame number, the function name, the | |
2759 | arguments, and the source file and line number of execution in that | |
2760 | frame. The second line shows the text of that source line. For | |
2761 | example: | |
2762 | ||
2763 | @smallexample | |
2764 | @group | |
2765 | (gdb) up | |
2766 | #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) | |
2767 | at env.c:10 | |
2768 | 10 read_input_file (argv[i]); | |
2769 | @end group | |
2770 | @end smallexample | |
2771 | ||
2772 | After such a printout, the @code{list} command with no arguments will | |
2773 | print ten lines centered on the point of execution in the frame. | |
2774 | @xref{List, ,Printing Source Lines}. | |
2775 | ||
2776 | @table @code | |
2777 | @item up-silently @var{n} | |
2778 | @itemx down-silently @var{n} | |
2779 | @kindex down-silently | |
2780 | @kindex up-silently | |
2781 | These two commands are variants of @code{up} and @code{down}, | |
2782 | respectively; they differ in that they do their work silently, without | |
2783 | causing display of the new frame. They are intended primarily for use | |
2784 | in GDB command scripts, where the output might be unnecessary and | |
2785 | distracting. | |
2786 | @end table | |
2787 | ||
2788 | @node Frame Info, , Selection, Stack | |
2789 | @section Information About a Frame | |
2790 | ||
2791 | There are several other commands to print information about the selected | |
2792 | stack frame. | |
2793 | ||
2794 | @table @code | |
2795 | @item frame | |
2796 | @itemx f | |
2797 | When used without any argument, this command does not change which | |
2798 | frame is selected, but prints a brief description of the currently | |
2799 | selected stack frame. It can be abbreviated @code{f}. With an | |
2800 | argument, this command is used to select a stack frame | |
2801 | (@pxref{Selection, ,Selecting a Frame}). | |
2802 | ||
2803 | @item info frame | |
2804 | @itemx info f | |
2805 | @kindex info frame | |
2806 | @kindex info f | |
2807 | This command prints a verbose description of the selected stack frame, | |
2808 | including the address of the frame, the addresses of the next frame down | |
2809 | (called by this frame) and the next frame up (caller of this frame), the | |
2810 | language that the source code corresponding to this frame was written in, | |
2811 | the address of the frame's arguments, the program counter saved in it | |
2812 | (the address of execution in the caller frame), and which registers | |
2813 | were saved in the frame. The verbose description is useful when | |
2814 | something has gone wrong that has made the stack format fail to fit | |
2815 | the usual conventions. | |
2816 | ||
2817 | @item info frame @var{addr} | |
2818 | @itemx info f @var{addr} | |
2819 | Print a verbose description of the frame at address @var{addr}, | |
2820 | without selecting that frame. The selected frame remains unchanged by | |
2821 | this command. | |
2822 | ||
2823 | @item info args | |
2824 | @kindex info args | |
2825 | Print the arguments of the selected frame, each on a separate line. | |
2826 | ||
2827 | @item info locals | |
2828 | @kindex info locals | |
2829 | Print the local variables of the selected frame, each on a separate | |
2830 | line. These are all variables declared static or automatic within all | |
2831 | program blocks that execution in this frame is currently inside of. | |
2832 | ||
2833 | @item info catch | |
2834 | @kindex info catch | |
2835 | @cindex catch exceptions | |
2836 | @cindex exception handlers | |
2837 | Print a list of all the exception handlers that are active in the | |
2838 | current stack frame at the current point of execution. To see other | |
2839 | exception handlers, visit the associated frame (using the @code{up}, | |
2840 | @code{down}, or @code{frame} commands); then type @code{info catch}. | |
2841 | @xref{Exception Handling, ,Breakpoints and Exceptions}. | |
2842 | @end table | |
2843 | ||
2844 | @node Source, Data, Stack, Top | |
2845 | @chapter Examining Source Files | |
2846 | ||
2847 | GDB can print parts of your program's source, since the debugging | |
2848 | information recorded in your program tells GDB what source files were | |
2849 | used to build it. When your program stops, GDB spontaneously prints | |
2850 | the line where it stopped. Likewise, when you select a stack frame | |
2851 | (@pxref{Selection, ,Selecting a Frame}), GDB prints the line where | |
2852 | execution in that frame has stopped. You can print other portions of | |
2853 | source files by explicit command. | |
2854 | ||
2855 | If you use GDB through its GNU Emacs interface, you may prefer to use | |
2856 | Emacs facilities to view source; @pxref{Emacs, ,Using GDB under GNU | |
2857 | Emacs}. | |
2858 | ||
2859 | @menu | |
2860 | * List:: Printing Source Lines | |
2861 | * Search:: Searching Source Files | |
2862 | * Source Path:: Specifying Source Directories | |
2863 | * Machine Code:: Source and Machine Code | |
2864 | @end menu | |
2865 | ||
2866 | @node List, Search, Source, Source | |
2867 | @section Printing Source Lines | |
2868 | ||
2869 | @kindex list | |
2870 | @kindex l | |
2871 | To print lines from a source file, use the @code{list} command | |
2872 | (abbreviated @code{l}). There are several ways to specify what part | |
2873 | of the file you want to print. | |
2874 | ||
2875 | Here are the forms of the @code{list} command most commonly used: | |
2876 | ||
2877 | @table @code | |
2878 | @item list @var{linenum} | |
2879 | Print lines centered around line number @var{linenum} in the | |
2880 | current source file. | |
2881 | ||
2882 | @item list @var{function} | |
2883 | Print lines centered around the beginning of function | |
2884 | @var{function}. | |
2885 | ||
2886 | @item list | |
2887 | Print more lines. If the last lines printed were printed with a | |
2888 | @code{list} command, this prints lines following the last lines | |
2889 | printed; however, if the last line printed was a solitary line printed | |
2890 | as part of displaying a stack frame (@pxref{Stack, ,Examining the | |
2891 | Stack}), this prints lines centered around that line. | |
2892 | ||
2893 | @item list - | |
2894 | Print lines just before the lines last printed. | |
2895 | @end table | |
2896 | ||
2897 | By default, GDB prints ten source lines with any of these forms of | |
2898 | the @code{list} command. You can change this using @code{set listsize}: | |
2899 | ||
2900 | @table @code | |
2901 | @item set listsize @var{count} | |
2902 | @kindex set listsize | |
2903 | Make the @code{list} command display @var{count} source lines (unless | |
2904 | the @code{list} argument explicitly specifies some other number). | |
2905 | ||
2906 | @item show listsize | |
2907 | @kindex show listsize | |
2908 | Display the number of lines that @code{list} will currently display by | |
2909 | default. | |
2910 | @end table | |
2911 | ||
2912 | Repeating a @code{list} command with @key{RET} discards the argument, | |
2913 | so it is equivalent to typing just @code{list}. This is more useful | |
2914 | than listing the same lines again. An exception is made for an | |
2915 | argument of @samp{-}; that argument is preserved in repetition so that | |
2916 | each repetition moves up in the source file. | |
2917 | ||
2918 | @cindex linespec | |
2919 | In general, the @code{list} command expects you to supply zero, one or two | |
2920 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
2921 | of writing them but the effect is always to specify some source line. | |
2922 | Here is a complete description of the possible arguments for @code{list}: | |
2923 | ||
2924 | @table @code | |
2925 | @item list @var{linespec} | |
2926 | Print lines centered around the line specified by @var{linespec}. | |
2927 | ||
2928 | @item list @var{first},@var{last} | |
2929 | Print lines from @var{first} to @var{last}. Both arguments are | |
2930 | linespecs. | |
2931 | ||
2932 | @item list ,@var{last} | |
2933 | Print lines ending with @var{last}. | |
2934 | ||
2935 | @item list @var{first}, | |
2936 | Print lines starting with @var{first}. | |
2937 | ||
2938 | @item list + | |
2939 | Print lines just after the lines last printed. | |
2940 | ||
2941 | @item list - | |
2942 | Print lines just before the lines last printed. | |
2943 | ||
2944 | @item list | |
2945 | As described in the preceding table. | |
2946 | @end table | |
2947 | ||
2948 | Here are the ways of specifying a single source line---all the | |
2949 | kinds of linespec. | |
2950 | ||
2951 | @table @code | |
2952 | @item @var{number} | |
2953 | Specifies line @var{number} of the current source file. | |
2954 | When a @code{list} command has two linespecs, this refers to | |
2955 | the same source file as the first linespec. | |
2956 | ||
2957 | @item +@var{offset} | |
2958 | Specifies the line @var{offset} lines after the last line printed. | |
2959 | When used as the second linespec in a @code{list} command that has | |
2960 | two, this specifies the line @var{offset} lines down from the | |
2961 | first linespec. | |
2962 | ||
2963 | @item -@var{offset} | |
2964 | Specifies the line @var{offset} lines before the last line printed. | |
2965 | ||
2966 | @item @var{filename}:@var{number} | |
2967 | Specifies line @var{number} in the source file @var{filename}. | |
2968 | ||
2969 | @item @var{function} | |
2970 | @c FIXME: "of the open-brace" is C-centric. When we add other langs... | |
2971 | Specifies the line of the open-brace that begins the body of the | |
2972 | function @var{function}. | |
2973 | ||
2974 | @item @var{filename}:@var{function} | |
2975 | Specifies the line of the open-brace that begins the body of the | |
2976 | function @var{function} in the file @var{filename}. You only need the | |
2977 | file name with a function name to avoid ambiguity when there are | |
2978 | identically named functions in different source files. | |
2979 | ||
2980 | @item *@var{address} | |
2981 | Specifies the line containing the program address @var{address}. | |
2982 | @var{address} may be any expression. | |
2983 | @end table | |
2984 | ||
2985 | @node Search, Source Path, List, Source | |
2986 | @section Searching Source Files | |
2987 | @cindex searching | |
2988 | @kindex reverse-search | |
2989 | ||
2990 | There are two commands for searching through the current source file for a | |
2991 | regular expression. | |
2992 | ||
2993 | @table @code | |
2994 | @item forward-search @var{regexp} | |
2995 | @itemx search @var{regexp} | |
2996 | @kindex search | |
2997 | @kindex forward-search | |
2998 | The command @samp{forward-search @var{regexp}} checks each line, | |
2999 | starting with the one following the last line listed, for a match for | |
3000 | @var{regexp}. It lists the line that is found. You can use | |
3001 | synonym @samp{search @var{regexp}} or abbreviate the command name as | |
3002 | @code{fo}. | |
3003 | ||
3004 | @item reverse-search @var{regexp} | |
3005 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
3006 | with the one before the last line listed and going backward, for a match | |
3007 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
3008 | this command as @code{rev}. | |
3009 | @end table | |
3010 | ||
3011 | @node Source Path, Machine Code, Search, Source | |
3012 | @section Specifying Source Directories | |
3013 | ||
3014 | @cindex source path | |
3015 | @cindex directories for source files | |
3016 | Executable programs sometimes do not record the directories of the source | |
3017 | files from which they were compiled, just the names. Even when they do, | |
3018 | the directories could be moved between the compilation and your debugging | |
3019 | session. GDB has a list of directories to search for source files; | |
3020 | this is called the @dfn{source path}. Each time GDB wants a source file, | |
3021 | it tries all the directories in the list, in the order they are present | |
3022 | in the list, until it finds a file with the desired name. Note that | |
3023 | the executable search path is @emph{not} used for this purpose. Neither is | |
3024 | the current working directory, unless it happens to be in the source | |
3025 | path. | |
3026 | ||
3027 | If GDB cannot find a source file in the source path, and the object | |
3028 | program records a directory, GDB tries that directory too. If the | |
3029 | source path is empty, and there is no record of the compilation | |
3030 | directory, GDB will, as a last resort, look in the current | |
3031 | directory. | |
3032 | ||
3033 | Whenever you reset or rearrange the source path, GDB will clear out | |
3034 | any information it has cached about where source files are found, where | |
3035 | each line is in the file, etc. | |
3036 | ||
3037 | @kindex directory | |
3038 | When you start GDB, its source path is empty. | |
3039 | To add other directories, use the @code{directory} command. | |
3040 | ||
3041 | @table @code | |
3042 | @item directory @var{dirname} @dots{} | |
3043 | Add directory @var{dirname} to the front of the source path. Several | |
3044 | directory names may be given to this command, separated by @samp{:} or | |
3045 | whitespace. You may specify a directory that is already in the source | |
3046 | path; this moves it forward, so it will be searched sooner. | |
3047 | ||
3048 | You can use the string @samp{$cdir} to refer to the compilation | |
3049 | directory (if one is recorded), and @samp{$cwd} to refer to the current | |
3050 | working directory. @samp{$cwd} is not the same as @samp{.}---the former | |
3051 | tracks the current working directory as it changes during your GDB | |
3052 | session, while the latter is immediately expanded to the current | |
3053 | directory at the time you add an entry to the source path. | |
3054 | ||
3055 | @item directory | |
3056 | Reset the source path to empty again. This requires confirmation. | |
3057 | ||
3058 | @c RET-repeat for @code{directory} is explicitly disabled, but since | |
3059 | @c repeating it would be a no-op we do not say that. (thanks to RMS) | |
3060 | ||
3061 | @item show directories | |
3062 | @kindex show directories | |
3063 | Print the source path: show which directories it contains. | |
3064 | @end table | |
3065 | ||
3066 | If your source path is cluttered with directories that are no longer of | |
3067 | interest, GDB may sometimes cause confusion by finding the wrong | |
3068 | versions of source. You can correct the situation as follows: | |
3069 | ||
3070 | @enumerate | |
3071 | @item | |
3072 | Use @code{directory} with no argument to reset the source path to empty. | |
3073 | ||
3074 | @item | |
3075 | Use @code{directory} with suitable arguments to reinstall the | |
3076 | directories you want in the source path. You can add all the | |
3077 | directories in one command. | |
3078 | @end enumerate | |
3079 | ||
3080 | @node Machine Code, , Source Path, Source | |
3081 | @section Source and Machine Code | |
3082 | ||
3083 | You can use the command @code{info line} to map source lines to program | |
3084 | addresses (and viceversa), and the command @code{disassemble} to display | |
3085 | a range of addresses as machine instructions. | |
3086 | ||
3087 | @table @code | |
3088 | @item info line @var{linespec} | |
3089 | @kindex info line | |
3090 | Print the starting and ending addresses of the compiled code for | |
3091 | source line @var{linespec}. You can specify source lines in any of | |
3092 | the ways understood by the @code{list} command (@pxref{List, ,Printing | |
3093 | Source Lines}). | |
3094 | @end table | |
3095 | ||
3096 | For example, we can use @code{info line} to discover the location of | |
3097 | the object code for the first line of function | |
3098 | @code{m4_changequote}: | |
3099 | ||
3100 | @smallexample | |
3101 | (gdb) info line m4_changecom | |
3102 | Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. | |
3103 | @end smallexample | |
3104 | ||
3105 | @noindent | |
3106 | We can also inquire (using @code{*@var{addr}} as the form for | |
3107 | @var{linespec}) what source line covers a particular address: | |
3108 | @smallexample | |
3109 | (gdb) info line *0x63ff | |
3110 | Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. | |
3111 | @end smallexample | |
3112 | ||
3113 | @cindex @code{$_} and @code{info line} | |
3114 | After @code{info line}, the default address for the @code{x} command | |
3115 | is changed to the starting address of the line, so that @samp{x/i} is | |
3116 | sufficient to begin examining the machine code (@pxref{Memory, | |
3117 | ,Examining Memory}). Also, this address is saved as the value of the | |
3118 | convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience | |
3119 | Variables}). | |
3120 | ||
3121 | @table @code | |
3122 | @kindex disassemble | |
3123 | @item disassemble | |
3124 | This specialized command dumps a range of memory as machine | |
3125 | instructions. The default memory range is the function surrounding the | |
3126 | program counter of the selected frame. A single argument to this | |
3127 | command is a program counter value; the function surrounding this value | |
3128 | will be dumped. Two arguments specify a range of addresses (first | |
3129 | inclusive, second exclusive) to dump. | |
3130 | @end table | |
3131 | ||
3132 | We can use @code{disassemble} to inspect the object code | |
3133 | range shown in the last @code{info line} example: | |
3134 | ||
3135 | @smallexample | |
3136 | (gdb) disas 0x63e4 0x6404 | |
3137 | Dump of assembler code from 0x63e4 to 0x6404: | |
3138 | 0x63e4 builtin_init+5340: ble 0x63f8 builtin_init+5360 | |
3139 | 0x63e8 builtin_init+5344: sethi %hi(0x4c00), %o0 | |
3140 | 0x63ec builtin_init+5348: ld [%i1+4], %o0 | |
3141 | 0x63f0 builtin_init+5352: b 0x63fc builtin_init+5364 | |
3142 | 0x63f4 builtin_init+5356: ld [%o0+4], %o0 | |
3143 | 0x63f8 builtin_init+5360: or %o0, 0x1a4, %o0 | |
3144 | 0x63fc builtin_init+5364: call 0x9288 path_search | |
3145 | 0x6400 builtin_init+5368: nop | |
3146 | End of assembler dump. | |
3147 | @end smallexample | |
3148 | ||
3149 | @node Data, Languages, Source, Top | |
3150 | @chapter Examining Data | |
3151 | ||
3152 | @cindex printing data | |
3153 | @cindex examining data | |
3154 | @kindex print | |
3155 | @kindex inspect | |
3156 | @c "inspect" is not quite a synonym if you are using Epoch, which we do not | |
3157 | @c document because it is nonstandard... Under Epoch it displays in a | |
3158 | @c different window or something like that. | |
3159 | The usual way to examine data in your program is with the @code{print} | |
3160 | command (abbreviated @code{p}), or its synonym @code{inspect}. It | |
3161 | evaluates and prints the value of an expression of the language your | |
3162 | program is written in (@pxref{Languages, ,Using GDB with Different | |
3163 | Languages}). | |
3164 | ||
3165 | @table @code | |
3166 | @item print @var{exp} | |
3167 | @itemx print /@var{f} @var{exp} | |
3168 | @var{exp} is an expression (in the source language). By default | |
3169 | the value of @var{exp} is printed in a format appropriate to its data | |
3170 | type; you can choose a different format by specifying @samp{/@var{f}}, | |
3171 | where @var{f} is a letter specifying the format; @pxref{Output formats}. | |
3172 | ||
3173 | @item print | |
3174 | @itemx print /@var{f} | |
3175 | If you omit @var{exp}, GDB displays the last value again (from the | |
3176 | @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to | |
3177 | conveniently inspect the same value in an alternative format. | |
3178 | @end table | |
3179 | ||
3180 | A more low-level way of examining data is with the @code{x} command. | |
3181 | It examines data in memory at a specified address and prints it in a | |
3182 | specified format. @xref{Memory, ,Examining Memory}. | |
3183 | ||
3184 | If you are interested in information about types, or about how the fields | |
3185 | of a struct or class are declared, use the @code{ptype @var{exp}} | |
3186 | command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}. | |
3187 | ||
3188 | @menu | |
3189 | * Expressions:: Expressions | |
3190 | * Variables:: Program Variables | |
3191 | * Arrays:: Artificial Arrays | |
3192 | * Output formats:: Output formats | |
3193 | * Memory:: Examining Memory | |
3194 | * Auto Display:: Automatic Display | |
3195 | * Print Settings:: Print Settings | |
3196 | * Value History:: Value History | |
3197 | * Convenience Vars:: Convenience Variables | |
3198 | * Registers:: Registers | |
3199 | * Floating Point Hardware:: Floating Point Hardware | |
3200 | @end menu | |
3201 | ||
3202 | @node Expressions, Variables, Data, Data | |
3203 | @section Expressions | |
3204 | ||
3205 | @cindex expressions | |
3206 | @code{print} and many other GDB commands accept an expression and | |
3207 | compute its value. Any kind of constant, variable or operator defined | |
3208 | by the programming language you are using is legal in an expression in | |
3209 | GDB. This includes conditional expressions, function calls, casts | |
3210 | and string constants. It unfortunately does not include symbols defined | |
3211 | by preprocessor @code{#define} commands. | |
3212 | ||
3213 | Because C is so widespread, most of the expressions shown in examples in | |
3214 | this manual are in C. @xref{Languages, , Using GDB with Different | |
3215 | Languages}, for information on how to use expressions in other | |
3216 | languages. | |
3217 | ||
3218 | In this section, we discuss operators that you can use in GDB | |
3219 | expressions regardless of your programming language. | |
3220 | ||
3221 | Casts are supported in all languages, not just in C, because it is so | |
3222 | useful to cast a number into a pointer so as to examine a structure | |
3223 | at that address in memory. | |
3224 | @c FIXME: casts supported---Mod2 true? | |
3225 | ||
3226 | GDB supports these operators in addition to those of programming | |
3227 | languages: | |
3228 | ||
3229 | @table @code | |
3230 | @item @@ | |
3231 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
3232 | @xref{Arrays, ,Artificial Arrays}, for more information. | |
3233 | ||
3234 | @item :: | |
3235 | @samp{::} allows you to specify a variable in terms of the file or | |
3236 | function where it is defined. @xref{Variables, ,Program Variables}. | |
3237 | ||
3238 | @item @{@var{type}@} @var{addr} | |
3239 | Refers to an object of type @var{type} stored at address @var{addr} in | |
3240 | memory. @var{addr} may be any expression whose value is an integer or | |
3241 | pointer (but parentheses are required around binary operators, just as in | |
3242 | a cast). This construct is allowed regardless of what kind of data is | |
3243 | normally supposed to reside at @var{addr}. | |
3244 | @end table | |
3245 | ||
3246 | @node Variables, Arrays, Expressions, Data | |
3247 | @section Program Variables | |
3248 | ||
3249 | The most common kind of expression to use is the name of a variable | |
3250 | in your program. | |
3251 | ||
3252 | Variables in expressions are understood in the selected stack frame | |
3253 | (@pxref{Selection, ,Selecting a Frame}); they must either be global | |
3254 | (or static) or be visible according to the scope rules of the | |
3255 | programming language from the point of execution in that frame. This | |
3256 | means that in the function | |
3257 | ||
3258 | @example | |
3259 | foo (a) | |
3260 | int a; | |
3261 | @{ | |
3262 | bar (a); | |
3263 | @{ | |
3264 | int b = test (); | |
3265 | bar (b); | |
3266 | @} | |
3267 | @} | |
3268 | @end example | |
3269 | ||
3270 | @noindent | |
3271 | the variable @code{a} is usable whenever your program is executing | |
3272 | within the function @code{foo}, but the variable @code{b} is visible | |
3273 | only while your program is executing inside the block in which @code{b} | |
3274 | is declared. | |
3275 | ||
3276 | @cindex variable name conflict | |
3277 | There is an exception: you can refer to a variable or function whose | |
3278 | scope is a single source file even if the current execution point is not | |
3279 | in this file. But it is possible to have more than one such variable or | |
3280 | function with the same name (in different source files). If that happens, | |
3281 | referring to that name has unpredictable effects. If you wish, you can | |
3282 | specify a variable in a particular file, using the colon-colon notation: | |
3283 | ||
3284 | @cindex colon-colon | |
3285 | @iftex | |
3286 | @c info cannot cope with a :: index entry, but why deprive hard copy readers? | |
3287 | @kindex :: | |
3288 | @end iftex | |
3289 | @example | |
3290 | @var{file}::@var{variable} | |
3291 | @end example | |
3292 | ||
3293 | @noindent | |
3294 | Here @var{file} is the name of the source file whose variable you want. | |
3295 | ||
3296 | @cindex C++ scope resolution | |
3297 | This use of @samp{::} is very rarely in conflict with the very similar | |
3298 | use of the same notation in C++. GDB also supports use of the C++ | |
3299 | scope resolution operator in GDB expressions. | |
3300 | ||
3301 | @cindex wrong values | |
3302 | @cindex variable values, wrong | |
3303 | @quotation | |
3304 | @emph{Warning:} Occasionally, a local variable may appear to have the | |
3305 | wrong value at certain points in a function---just after entry to the | |
3306 | function, and just before exit. You may see this problem when you are | |
3307 | stepping by machine instructions. This is because on most machines, it | |
3308 | takes more than one instruction to set up a stack frame (including local | |
3309 | variable definitions); if you are stepping by machine instructions, | |
3310 | variables may appear to have the wrong values until the stack frame is | |
3311 | completely built. On function exit, it usually also takes more than one | |
3312 | machine instruction to destroy a stack frame; after you begin stepping | |
3313 | through that group of instructions, local variable definitions may be | |
3314 | gone. | |
3315 | @end quotation | |
3316 | ||
3317 | @node Arrays, Output formats, Variables, Data | |
3318 | @section Artificial Arrays | |
3319 | ||
3320 | @cindex artificial array | |
3321 | @kindex @@ | |
3322 | It is often useful to print out several successive objects of the | |
3323 | same type in memory; a section of an array, or an array of | |
3324 | dynamically determined size for which only a pointer exists in the | |
3325 | program. | |
3326 | ||
3327 | This can be done by constructing an @dfn{artificial array} with the | |
3328 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
3329 | the first element of the desired array, as an individual object. | |
3330 | The right operand should be the desired length of the array. The result is | |
3331 | an array value whose elements are all of the type of the left argument. | |
3332 | The first element is actually the left argument; the second element | |
3333 | comes from bytes of memory immediately following those that hold the | |
3334 | first element, and so on. Here is an example. If a program says | |
3335 | ||
3336 | @example | |
3337 | int *array = (int *) malloc (len * sizeof (int)); | |
3338 | @end example | |
3339 | ||
3340 | @noindent | |
3341 | you can print the contents of @code{array} with | |
3342 | ||
3343 | @example | |
3344 | p *array@@len | |
3345 | @end example | |
3346 | ||
3347 | The left operand of @samp{@@} must reside in memory. Array values made | |
3348 | with @samp{@@} in this way behave just like other arrays in terms of | |
3349 | subscripting, and are coerced to pointers when used in expressions. | |
3350 | Artificial arrays most often appear in expressions via the value history | |
3351 | (@pxref{Value History, ,Value History}), after printing one out.) | |
3352 | ||
3353 | Sometimes the artificial array mechanism is not quite enough; in | |
3354 | moderately complex data structures, the elements of interest may not | |
3355 | actually be adjacent---for example, if you are interested in the values | |
3356 | of pointers in an array. One useful work-around in this situation is | |
3357 | to use a convenience variable (@pxref{Convenience Vars, ,Convenience | |
3358 | Variables}) as a counter in an expression that prints the first | |
3359 | interesting value, and then repeat that expression via @key{RET}. For | |
3360 | instance, suppose you have an array @code{dtab} of pointers to | |
3361 | structures, and you are interested in the values of a field @code{fv} | |
3362 | in each structure. Here is an example of what you might type: | |
3363 | ||
3364 | @example | |
3365 | set $i = 0 | |
3366 | p dtab[$i++]->fv | |
3367 | @key{RET} | |
3368 | @key{RET} | |
3369 | @dots{} | |
3370 | @end example | |
3371 | ||
3372 | @node Output formats, Memory, Arrays, Data | |
3373 | @section Output formats | |
3374 | ||
3375 | @cindex formatted output | |
3376 | @cindex output formats | |
3377 | By default, GDB prints a value according to its data type. Sometimes | |
3378 | this is not what you want. For example, you might want to print a number | |
3379 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
3380 | at a certain address as a character string or as an instruction. To do | |
3381 | these things, specify an @dfn{output format} when you print a value. | |
3382 | ||
3383 | The simplest use of output formats is to say how to print a value | |
3384 | already computed. This is done by starting the arguments of the | |
3385 | @code{print} command with a slash and a format letter. The format | |
3386 | letters supported are: | |
3387 | ||
3388 | @table @code | |
3389 | @item x | |
3390 | Regard the bits of the value as an integer, and print the integer in | |
3391 | hexadecimal. | |
3392 | ||
3393 | @item d | |
3394 | Print as integer in signed decimal. | |
3395 | ||
3396 | @item u | |
3397 | Print as integer in unsigned decimal. | |
3398 | ||
3399 | @item o | |
3400 | Print as integer in octal. | |
3401 | ||
3402 | @item t | |
3403 | Print as integer in binary. The letter @samp{t} stands for ``two''. | |
3404 | ||
3405 | @item a | |
3406 | Print as an address, both absolute in hex and as an offset from the | |
3407 | nearest preceding symbol. This format can be used to discover where (in | |
3408 | what function) an unknown address is located: | |
3409 | ||
3410 | @example | |
3411 | (gdb) p/a 0x54320 | |
3412 | $3 = 0x54320 <_initialize_vx+396> | |
3413 | @end example | |
3414 | ||
3415 | @item c | |
3416 | Regard as an integer and print it as a character constant. | |
3417 | ||
3418 | @item f | |
3419 | Regard the bits of the value as a floating point number and print | |
3420 | using typical floating point syntax. | |
3421 | @end table | |
3422 | ||
3423 | For example, to print the program counter in hex (@pxref{Registers}), type | |
3424 | ||
3425 | @example | |
3426 | p/x $pc | |
3427 | @end example | |
3428 | ||
3429 | @noindent | |
3430 | Note that no space is required before the slash; this is because command | |
3431 | names in GDB cannot contain a slash. | |
3432 | ||
3433 | To reprint the last value in the value history with a different format, | |
3434 | you can use the @code{print} command with just a format and no | |
3435 | expression. For example, @samp{p/x} reprints the last value in hex. | |
3436 | ||
3437 | @node Memory, Auto Display, Output formats, Data | |
3438 | @section Examining Memory | |
3439 | ||
3440 | You can use the command @code{x} (for ``examine'') to examine memory in | |
3441 | any of several formats, independently of your program's data types. | |
3442 | ||
3443 | @cindex examining memory | |
3444 | @table @code | |
3445 | @kindex x | |
3446 | @item x/@var{nfu} @var{addr} | |
3447 | @itemx x @var{addr} | |
3448 | @itemx x | |
3449 | Use the command @code{x} to examine memory. | |
3450 | @end table | |
3451 | ||
3452 | @var{n}, @var{f}, and @var{u} are all optional parameters that specify how | |
3453 | much memory to display and how to format it; @var{addr} is an | |
3454 | expression giving the address where you want to start displaying memory. | |
3455 | If you use defaults for @var{nfu}, you need not type the slash @samp{/}. | |
3456 | Several commands set convenient defaults for @var{addr}. | |
3457 | ||
3458 | @table @r | |
3459 | @item @var{n}, the repeat count | |
3460 | The repeat count is a decimal integer; the default is 1. It specifies | |
3461 | how much memory (counting by units @var{u}) to display. | |
3462 | @c This really is **decimal**; unaffected by 'set radix' as of GDB | |
3463 | @c 4.1.2. | |
3464 | ||
3465 | @item @var{f}, the display format | |
3466 | The display format is one of the formats used by @code{print}, | |
3467 | or @samp{s} (null-terminated string) or @samp{i} (machine instruction). | |
3468 | The default is @samp{x} (hexadecimal) initially, or the format from the | |
3469 | last time you used either @code{x} or @code{print}. | |
3470 | ||
3471 | @item @var{u}, the unit size | |
3472 | The unit size is any of | |
3473 | @table @code | |
3474 | @item b | |
3475 | Bytes. | |
3476 | @item h | |
3477 | Halfwords (two bytes). | |
3478 | @item w | |
3479 | Words (four bytes). This is the initial default. | |
3480 | @item g | |
3481 | Giant words (eight bytes). | |
3482 | @end table | |
3483 | ||
3484 | Each time you specify a unit size with @code{x}, that size becomes the | |
3485 | default unit the next time you use @code{x}. (For the @samp{s} and | |
3486 | @samp{i} formats, the unit size is ignored and is normally not written.) | |
3487 | ||
3488 | @item @var{addr}, starting display address | |
3489 | @var{addr} is the address where you want GDB to begin displaying | |
3490 | memory. The expression need not have a pointer value (though it may); | |
3491 | it is always interpreted as an integer address of a byte of memory. | |
3492 | @xref{Expressions, ,Expressions}, for more information on expressions. The default for | |
3493 | @var{addr} is usually just after the last address examined---but several | |
3494 | other commands also set the default address: @code{info breakpoints} (to | |
3495 | the address of the last breakpoint listed), @code{info line} (to the | |
3496 | starting address of a line), and @code{print} (if you use it to display | |
3497 | a value from memory). | |
3498 | @end table | |
3499 | ||
3500 | For example, @samp{x/3uh 0x54320} is a request to display three halfwords | |
3501 | (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}), | |
3502 | starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four | |
3503 | words (@samp{w}) of memory above the stack pointer (here, @samp{$sp}; | |
3504 | @pxref{Registers}) in hexadecimal (@samp{x}). | |
3505 | ||
3506 | Since the letters indicating unit sizes are all distinct from the | |
3507 | letters specifying output formats, you do not have to remember whether | |
3508 | unit size or format comes first; either order will work. The output | |
3509 | specifications @samp{4xw} and @samp{4wx} mean exactly the same thing. | |
3510 | (However, the count @var{n} must come first; @samp{wx4} will not work.) | |
3511 | ||
3512 | Even though the unit size @var{u} is ignored for the formats @samp{s} | |
3513 | and @samp{i}, you might still want to use a count @var{n}; for example, | |
3514 | @samp{3i} specifies that you want to see three machine instructions, | |
3515 | including any operands. The command @code{disassemble} gives an | |
3516 | alternative way of inspecting machine instructions; @pxref{Machine | |
3517 | Code}. | |
3518 | ||
3519 | All the defaults for the arguments to @code{x} are designed to make it | |
3520 | easy to continue scanning memory with minimal specifications each time | |
3521 | you use @code{x}. For example, after you have inspected three machine | |
3522 | instructions with @samp{x/3i @var{addr}}, you can inspect the next seven | |
3523 | with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command, | |
3524 | the repeat count @var{n} is used again; the other arguments default as | |
3525 | for successive uses of @code{x}. | |
3526 | ||
3527 | @cindex @code{$_}, @code{$__}, and value history | |
3528 | The addresses and contents printed by the @code{x} command are not saved | |
3529 | in the value history because there is often too much of them and they | |
3530 | would get in the way. Instead, GDB makes these values available for | |
3531 | subsequent use in expressions as values of the convenience variables | |
3532 | @code{$_} and @code{$__}. After an @code{x} command, the last address | |
3533 | examined is available for use in expressions in the convenience variable | |
3534 | @code{$_}. The contents of that address, as examined, are available in | |
3535 | the convenience variable @code{$__}. | |
3536 | ||
3537 | If the @code{x} command has a repeat count, the address and contents saved | |
3538 | are from the last memory unit printed; this is not the same as the last | |
3539 | address printed if several units were printed on the last line of output. | |
3540 | ||
3541 | @node Auto Display, Print Settings, Memory, Data | |
3542 | @section Automatic Display | |
3543 | @cindex automatic display | |
3544 | @cindex display of expressions | |
3545 | ||
3546 | If you find that you want to print the value of an expression frequently | |
3547 | (to see how it changes), you might want to add it to the @dfn{automatic | |
3548 | display list} so that GDB will print its value each time your program stops. | |
3549 | Each expression added to the list is given a number to identify it; | |
3550 | to remove an expression from the list, you specify that number. | |
3551 | The automatic display looks like this: | |
3552 | ||
3553 | @example | |
3554 | 2: foo = 38 | |
3555 | 3: bar[5] = (struct hack *) 0x3804 | |
3556 | @end example | |
3557 | ||
3558 | @noindent | |
3559 | showing item numbers, expressions and their current values. As with | |
3560 | displays you request manually using @code{x} or @code{print}, you can | |
3561 | specify the output format you prefer; in fact, @code{display} decides | |
3562 | whether to use @code{print} or @code{x} depending on how elaborate your | |
3563 | format specification is---it uses @code{x} if you specify a unit size, | |
3564 | or one of the two formats (@samp{i} and @samp{s}) that are only | |
3565 | supported by @code{x}; otherwise it uses @code{print}. | |
3566 | ||
3567 | @table @code | |
3568 | @item display @var{exp} | |
3569 | @kindex display | |
3570 | Add the expression @var{exp} to the list of expressions to display | |
3571 | each time your program stops. @xref{Expressions, ,Expressions}. | |
3572 | ||
3573 | @code{display} will not repeat if you press @key{RET} again after using it. | |
3574 | ||
3575 | @item display/@var{fmt} @var{exp} | |
3576 | For @var{fmt} specifying only a display format and not a size or | |
3577 | count, add the expression @var{exp} to the auto-display list but | |
3578 | arranges to display it each time in the specified format @var{fmt}. | |
3579 | @xref{Output formats}. | |
3580 | ||
3581 | @item display/@var{fmt} @var{addr} | |
3582 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3583 | number of units, add the expression @var{addr} as a memory address to | |
3584 | be examined each time your program stops. Examining means in effect | |
3585 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}. | |
3586 | @end table | |
3587 | ||
3588 | For example, @samp{display/i $pc} can be helpful, to see the machine | |
3589 | instruction about to be executed each time execution stops (@samp{$pc} | |
3590 | is a common name for the program counter; @pxref{Registers}). | |
3591 | ||
3592 | @table @code | |
3593 | @item undisplay @var{dnums}@dots{} | |
3594 | @itemx delete display @var{dnums}@dots{} | |
3595 | @kindex delete display | |
3596 | @kindex undisplay | |
3597 | Remove item numbers @var{dnums} from the list of expressions to display. | |
3598 | ||
3599 | @code{undisplay} will not repeat if you press @key{RET} after using it. | |
3600 | (Otherwise you would just get the error @samp{No display number @dots{}}.) | |
3601 | ||
3602 | @item disable display @var{dnums}@dots{} | |
3603 | @kindex disable display | |
3604 | Disable the display of item numbers @var{dnums}. A disabled display | |
3605 | item is not printed automatically, but is not forgotten. It may be | |
3606 | enabled again later. | |
3607 | ||
3608 | @item enable display @var{dnums}@dots{} | |
3609 | @kindex enable display | |
3610 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3611 | again in auto display of its expression, until you specify otherwise. | |
3612 | ||
3613 | @item display | |
3614 | Display the current values of the expressions on the list, just as is | |
3615 | done when your program stops. | |
3616 | ||
3617 | @item info display | |
3618 | @kindex info display | |
3619 | Print the list of expressions previously set up to display | |
3620 | automatically, each one with its item number, but without showing the | |
3621 | values. This includes disabled expressions, which are marked as such. | |
3622 | It also includes expressions which would not be displayed right now | |
3623 | because they refer to automatic variables not currently available. | |
3624 | @end table | |
3625 | ||
3626 | If a display expression refers to local variables, then it does not make | |
3627 | sense outside the lexical context for which it was set up. Such an | |
3628 | expression is disabled when execution enters a context where one of its | |
3629 | variables is not defined. For example, if you give the command | |
3630 | @code{display last_char} while inside a function with an argument | |
3631 | @code{last_char}, then this argument will be displayed while your program | |
3632 | continues to stop inside that function. When it stops elsewhere---where | |
3633 | there is no variable @code{last_char}---display is disabled. The next time | |
3634 | your program stops where @code{last_char} is meaningful, you can enable the | |
3635 | display expression once again. | |
3636 | ||
3637 | @node Print Settings, Value History, Auto Display, Data | |
3638 | @section Print Settings | |
3639 | ||
3640 | @cindex format options | |
3641 | @cindex print settings | |
3642 | GDB provides the following ways to control how arrays, structures, | |
3643 | and symbols are printed. | |
3644 | ||
3645 | @noindent | |
3646 | These settings are useful for debugging programs in any language: | |
3647 | ||
3648 | @table @code | |
3649 | @item set print address | |
3650 | @item set print address on | |
3651 | @kindex set print address | |
3652 | GDB will print memory addresses showing the location of stack | |
3653 | traces, structure values, pointer values, breakpoints, and so forth, | |
3654 | even when it also displays the contents of those addresses. The default | |
3655 | is on. For example, this is what a stack frame display looks like, with | |
3656 | @code{set print address on}: | |
3657 | ||
3658 | @smallexample | |
3659 | @group | |
3660 | (gdb) f | |
3661 | #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") | |
3662 | at input.c:530 | |
3663 | 530 if (lquote != def_lquote) | |
3664 | @end group | |
3665 | @end smallexample | |
3666 | ||
3667 | @item set print address off | |
3668 | Do not print addresses when displaying their contents. For example, | |
3669 | this is the same stack frame displayed with @code{set print address off}: | |
3670 | ||
3671 | @example | |
3672 | @group | |
3673 | (gdb) set print addr off | |
3674 | (gdb) f | |
3675 | #0 set_quotes (lq="<<", rq=">>") at input.c:530 | |
3676 | 530 if (lquote != def_lquote) | |
3677 | @end group | |
3678 | @end example | |
3679 | ||
3680 | @item show print address | |
3681 | @kindex show print address | |
3682 | Show whether or not addresses are to be printed. | |
3683 | ||
3684 | @item set print array | |
3685 | @itemx set print array on | |
3686 | @kindex set print array | |
3687 | GDB will pretty print arrays. This format is more convenient to read, | |
3688 | but uses more space. The default is off. | |
3689 | ||
3690 | @item set print array off. | |
3691 | Return to compressed format for arrays. | |
3692 | ||
3693 | @item show print array | |
3694 | @kindex show print array | |
3695 | Show whether compressed or pretty format is selected for displaying | |
3696 | arrays. | |
3697 | ||
3698 | @item set print elements @var{number-of-elements} | |
3699 | @kindex set print elements | |
3700 | If GDB is printing a large array, it will stop printing after it has | |
3701 | printed the number of elements set by the @code{set print elements} command. | |
3702 | This limit also applies to the display of strings. | |
3703 | ||
3704 | @item show print elements | |
3705 | @kindex show print elements | |
3706 | Display the number of elements of a large array that GDB will print | |
3707 | before losing patience. | |
3708 | ||
3709 | @item set print pretty on | |
3710 | @kindex set print pretty | |
3711 | Cause GDB to print structures in an indented format with one member per | |
3712 | line, like this: | |
3713 | ||
3714 | @example | |
3715 | @group | |
3716 | $1 = @{ | |
3717 | next = 0x0, | |
3718 | flags = @{ | |
3719 | sweet = 1, | |
3720 | sour = 1 | |
3721 | @}, | |
3722 | meat = 0x54 "Pork" | |
3723 | @} | |
3724 | @end group | |
3725 | @end example | |
3726 | ||
3727 | @item set print pretty off | |
3728 | Cause GDB to print structures in a compact format, like this: | |
3729 | ||
3730 | @smallexample | |
3731 | @group | |
3732 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \ | |
3733 | = 0x54 "Pork"@} | |
3734 | @end group | |
3735 | @end smallexample | |
3736 | ||
3737 | @noindent | |
3738 | This is the default format. | |
3739 | ||
3740 | @item show print pretty | |
3741 | @kindex show print pretty | |
3742 | Show which format GDB will use to print structures. | |
3743 | ||
3744 | @item set print sevenbit-strings on | |
3745 | @kindex set print sevenbit-strings | |
3746 | Print using only seven-bit characters; if this option is set, | |
3747 | GDB will display any eight-bit characters (in strings or character | |
3748 | values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is | |
3749 | displayed as @code{\341}. | |
3750 | ||
3751 | @item set print sevenbit-strings off | |
3752 | Print using either seven-bit or eight-bit characters, as required. This | |
3753 | is the default. | |
3754 | ||
3755 | @item show print sevenbit-strings | |
3756 | @kindex show print sevenbit-strings | |
3757 | Show whether or not GDB will print only seven-bit characters. | |
3758 | ||
3759 | @item set print union on | |
3760 | @kindex set print union | |
3761 | Tell GDB to print unions which are contained in structures. This is the | |
3762 | default setting. | |
3763 | ||
3764 | @item set print union off | |
3765 | Tell GDB not to print unions which are contained in structures. | |
3766 | ||
3767 | @item show print union | |
3768 | @kindex show print union | |
3769 | Ask GDB whether or not it will print unions which are contained in | |
3770 | structures. | |
3771 | ||
3772 | For example, given the declarations | |
3773 | ||
3774 | @smallexample | |
3775 | typedef enum @{Tree, Bug@} Species; | |
3776 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
3777 | typedef enum @{Caterpillar, Cocoon, Butterfly@} | |
3778 | Bug_forms; | |
3779 | ||
3780 | struct thing @{ | |
3781 | Species it; | |
3782 | union @{ | |
3783 | Tree_forms tree; | |
3784 | Bug_forms bug; | |
3785 | @} form; | |
3786 | @}; | |
3787 | ||
3788 | struct thing foo = @{Tree, @{Acorn@}@}; | |
3789 | @end smallexample | |
3790 | ||
3791 | @noindent | |
3792 | with @code{set print union on} in effect @samp{p foo} would print | |
3793 | ||
3794 | @smallexample | |
3795 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
3796 | @end smallexample | |
3797 | ||
3798 | @noindent | |
3799 | and with @code{set print union off} in effect it would print | |
3800 | ||
3801 | @smallexample | |
3802 | $1 = @{it = Tree, form = @{...@}@} | |
3803 | @end smallexample | |
3804 | @end table | |
3805 | ||
3806 | @noindent | |
3807 | These settings are of interest when debugging C++ programs: | |
3808 | ||
3809 | @table @code | |
3810 | @item set print demangle | |
3811 | @itemx set print demangle on | |
3812 | @kindex set print demangle | |
3813 | Print C++ names in their source form rather than in the mangled form | |
3814 | in which they are passed to the assembler and linker for type-safe linkage. | |
3815 | The default is on. | |
3816 | ||
3817 | @item show print demangle | |
3818 | @kindex show print demangle | |
3819 | Show whether C++ names will be printed in mangled or demangled form. | |
3820 | ||
3821 | @item set print asm-demangle | |
3822 | @itemx set print asm-demangle on | |
3823 | @kindex set print asm-demangle | |
3824 | Print C++ names in their source form rather than their mangled form, even | |
3825 | in assembler code printouts such as instruction disassemblies. | |
3826 | The default is off. | |
3827 | ||
3828 | @item show print asm-demangle | |
3829 | @kindex show print asm-demangle | |
3830 | Show whether C++ names in assembly listings will be printed in mangled | |
3831 | or demangled form. | |
3832 | ||
3833 | @item set print object | |
3834 | @itemx set print object on | |
3835 | @kindex set print object | |
3836 | When displaying a pointer to an object, identify the @emph{actual} | |
3837 | (derived) type of the object rather than the @emph{declared} type, using | |
3838 | the virtual function table. | |
3839 | ||
3840 | @item set print object off | |
3841 | Display only the declared type of objects, without reference to the | |
3842 | virtual function table. This is the default setting. | |
3843 | ||
3844 | @item show print object | |
3845 | @kindex show print object | |
3846 | Show whether actual, or declared, object types will be displayed. | |
3847 | ||
3848 | @item set print vtbl | |
3849 | @itemx set print vtbl on | |
3850 | @kindex set print vtbl | |
3851 | Pretty print C++ virtual function tables. The default is off. | |
3852 | ||
3853 | @item set print vtbl off | |
3854 | Do not pretty print C++ virtual function tables. | |
3855 | ||
3856 | @item show print vtbl | |
3857 | @kindex show print vtbl | |
3858 | Show whether C++ virtual function tables are pretty printed, or not. | |
3859 | @end table | |
3860 | ||
3861 | @node Value History, Convenience Vars, Print Settings, Data | |
3862 | @section Value History | |
3863 | ||
3864 | @cindex value history | |
3865 | Values printed by the @code{print} command are saved in GDB's @dfn{value | |
3866 | history} so that you can refer to them in other expressions. Values are | |
3867 | kept until the symbol table is re-read or discarded (for example with | |
3868 | the @code{file} or @code{symbol-file} commands). When the symbol table | |
3869 | changes, the value history is discarded, since the values may contain | |
3870 | pointers back to the types defined in the symbol table. | |
3871 | ||
3872 | @cindex @code{$} | |
3873 | @cindex @code{$$} | |
3874 | @cindex history number | |
3875 | The values printed are given @dfn{history numbers} for you to refer to them | |
3876 | by. These are successive integers starting with one. @code{print} shows you | |
3877 | the history number assigned to a value by printing @samp{$@var{num} = } | |
3878 | before the value; here @var{num} is the history number. | |
3879 | ||
3880 | To refer to any previous value, use @samp{$} followed by the value's | |
3881 | history number. The way @code{print} labels its output is designed to | |
3882 | remind you of this. Just @code{$} refers to the most recent value in | |
3883 | the history, and @code{$$} refers to the value before that. | |
3884 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
3885 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
3886 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
3887 | ||
3888 | For example, suppose you have just printed a pointer to a structure and | |
3889 | want to see the contents of the structure. It suffices to type | |
3890 | ||
3891 | @example | |
3892 | p *$ | |
3893 | @end example | |
3894 | ||
3895 | If you have a chain of structures where the component @code{next} points | |
3896 | to the next one, you can print the contents of the next one with this: | |
3897 | ||
3898 | @example | |
3899 | p *$.next | |
3900 | @end example | |
3901 | ||
3902 | @noindent | |
3903 | You can print successive links in the chain by repeating this | |
3904 | command---which you can do by just typing @key{RET}. | |
3905 | ||
3906 | Note that the history records values, not expressions. If the value of | |
3907 | @code{x} is 4 and you type these commands: | |
3908 | ||
3909 | @example | |
3910 | print x | |
3911 | set x=5 | |
3912 | @end example | |
3913 | ||
3914 | @noindent | |
3915 | then the value recorded in the value history by the @code{print} command | |
3916 | remains 4 even though the value of @code{x} has changed. | |
3917 | ||
3918 | @table @code | |
3919 | @kindex show values | |
3920 | @item show values | |
3921 | Print the last ten values in the value history, with their item numbers. | |
3922 | This is like @samp{p@ $$9} repeated ten times, except that @code{show | |
3923 | values} does not change the history. | |
3924 | ||
3925 | @item show values @var{n} | |
3926 | Print ten history values centered on history item number @var{n}. | |
3927 | ||
3928 | @item show values + | |
3929 | Print ten history values just after the values last printed. If no more | |
3930 | values are available, produces no display. | |
3931 | @end table | |
3932 | ||
3933 | Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the | |
3934 | same effect as @samp{show values +}. | |
3935 | ||
3936 | @node Convenience Vars, Registers, Value History, Data | |
3937 | @section Convenience Variables | |
3938 | ||
3939 | @cindex convenience variables | |
3940 | GDB provides @dfn{convenience variables} that you can use within | |
3941 | GDB to hold on to a value and refer to it later. These variables | |
3942 | exist entirely within GDB; they are not part of your program, and | |
3943 | setting a convenience variable has no direct effect on further execution | |
3944 | of your program. That is why you can use them freely. | |
3945 | ||
3946 | Convenience variables are prefixed with @samp{$}. Any name preceded by | |
3947 | @samp{$} can be used for a convenience variable, unless it is one of | |
3948 | the predefined machine-specific register names (@pxref{Registers}). | |
3949 | (Value history references, in contrast, are @emph{numbers} preceded | |
3950 | by @samp{$}. @xref{Value History, ,Value History}.) | |
3951 | ||
3952 | You can save a value in a convenience variable with an assignment | |
3953 | expression, just as you would set a variable in your program. Example: | |
3954 | ||
3955 | @example | |
3956 | set $foo = *object_ptr | |
3957 | @end example | |
3958 | ||
3959 | @noindent | |
3960 | would save in @code{$foo} the value contained in the object pointed to by | |
3961 | @code{object_ptr}. | |
3962 | ||
3963 | Using a convenience variable for the first time creates it; but its value | |
3964 | is @code{void} until you assign a new value. You can alter the value with | |
3965 | another assignment at any time. | |
3966 | ||
3967 | Convenience variables have no fixed types. You can assign a convenience | |
3968 | variable any type of value, including structures and arrays, even if | |
3969 | that variable already has a value of a different type. The convenience | |
3970 | variable, when used as an expression, has the type of its current value. | |
3971 | ||
3972 | @table @code | |
3973 | @item show convenience | |
3974 | @kindex show convenience | |
3975 | Print a list of convenience variables used so far, and their values. | |
3976 | Abbreviated @code{show con}. | |
3977 | @end table | |
3978 | ||
3979 | One of the ways to use a convenience variable is as a counter to be | |
3980 | incremented or a pointer to be advanced. For example, to print | |
3981 | a field from successive elements of an array of structures: | |
3982 | ||
3983 | @example | |
3984 | set $i = 0 | |
3985 | print bar[$i++]->contents | |
3986 | @i{@dots{} repeat that command by typing @key{RET}.} | |
3987 | @end example | |
3988 | ||
3989 | Some convenience variables are created automatically by GDB and given | |
3990 | values likely to be useful. | |
3991 | ||
3992 | @table @code | |
3993 | @item $_ | |
3994 | @kindex $_ | |
3995 | The variable @code{$_} is automatically set by the @code{x} command to | |
3996 | the last address examined (@pxref{Memory, ,Examining Memory}). Other | |
3997 | commands which provide a default address for @code{x} to examine also | |
3998 | set @code{$_} to that address; these commands include @code{info line} | |
3999 | and @code{info breakpoint}. The type of @code{$_} is @code{void *} | |
4000 | except when set by the @code{x} command, in which case it is a pointer | |
4001 | to the type of @code{$__}. | |
4002 | ||
4003 | @item $__ | |
4004 | @kindex $__ | |
4005 | The variable @code{$__} is automatically set by the @code{x} command | |
4006 | to the value found in the last address examined. Its type is chosen | |
4007 | to match the format in which the data was printed. | |
4008 | @end table | |
4009 | ||
4010 | @node Registers, Floating Point Hardware, Convenience Vars, Data | |
4011 | @section Registers | |
4012 | ||
4013 | @cindex registers | |
4014 | You can refer to machine register contents, in expressions, as variables | |
4015 | with names starting with @samp{$}. The names of registers are different | |
4016 | for each machine; use @code{info registers} to see the names used on | |
4017 | your machine. | |
4018 | ||
4019 | @table @code | |
4020 | @item info registers | |
4021 | @kindex info registers | |
4022 | Print the names and values of all registers except floating-point | |
4023 | registers (in the selected stack frame). | |
4024 | ||
4025 | @item info all-registers | |
4026 | @kindex info all-registers | |
4027 | @cindex floating point registers | |
4028 | Print the names and values of all registers, including floating-point | |
4029 | registers. | |
4030 | ||
4031 | @item info registers @var{regname} | |
4032 | Print the relativized value of register @var{regname}. @var{regname} | |
4033 | may be any register name valid on the machine you are using, with | |
4034 | or without the initial @samp{$}. | |
4035 | @end table | |
4036 | ||
4037 | GDB has four ``standard'' register names that are available (in | |
4038 | expressions) on most machines---whenever they do not conflict with an | |
4039 | architecture's canonical mnemonics for registers. The register names | |
4040 | @code{$pc} and @code{$sp} are used for the program counter register and | |
4041 | the stack pointer. @code{$fp} is used for a register that contains a | |
4042 | pointer to the current stack frame, and @code{$ps} is used for a | |
4043 | register that contains the processor status. For example, | |
4044 | you could print the program counter in hex with | |
4045 | ||
4046 | @example | |
4047 | p/x $pc | |
4048 | @end example | |
4049 | ||
4050 | @noindent | |
4051 | or print the instruction to be executed next with | |
4052 | ||
4053 | @example | |
4054 | x/i $pc | |
4055 | @end example | |
4056 | ||
4057 | @noindent | |
4058 | or add four to the stack pointer @footnote{This is a way of removing | |
4059 | one word from the stack, on machines where stacks grow downward in | |
4060 | memory (most machines, nowadays). This assumes that the innermost | |
4061 | stack frame is selected; setting @code{$sp} is not allowed when other | |
4062 | stack frames are selected. To pop entire frames off the stack, | |
4063 | regardless of machine architecture, use @code{return}; | |
4064 | @pxref{Returning, ,Returning from a Function}.} with | |
4065 | ||
4066 | @example | |
4067 | set $sp += 4 | |
4068 | @end example | |
4069 | ||
4070 | Whenever possible, these four standard register names are available on | |
4071 | your machine even though the machine has different canonical mnemonics, | |
4072 | so long as there is no conflict. The @code{info registers} command | |
4073 | shows the canonical names. For example, on the SPARC, @code{info | |
4074 | registers} displays the processor status register as @code{$psr} but you | |
4075 | can also refer to it as @code{$ps}. | |
4076 | ||
4077 | GDB always considers the contents of an ordinary register as an | |
4078 | integer when the register is examined in this way. Some machines have | |
4079 | special registers which can hold nothing but floating point; these | |
4080 | registers are considered to have floating point values. There is no way | |
4081 | to refer to the contents of an ordinary register as floating point value | |
4082 | (although you can @emph{print} it as a floating point value with | |
4083 | @samp{print/f $@var{regname}}). | |
4084 | ||
4085 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
4086 | means that the data format in which the register contents are saved by | |
4087 | the operating system is not the same one that your program normally | |
4088 | sees. For example, the registers of the 68881 floating point | |
4089 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
4090 | programs expect to work with ``double'' (virtual) format. In such | |
4091 | cases, GDB normally works with the virtual format only (the format that | |
4092 | makes sense for your program), but the @code{info registers} command | |
4093 | prints the data in both formats. | |
4094 | ||
4095 | Normally, register values are relative to the selected stack frame | |
4096 | (@pxref{Selection, ,Selecting a Frame}). This means that you get the | |
4097 | value that the register would contain if all stack frames farther in | |
4098 | were exited and their saved registers restored. In order to see the | |
4099 | true contents of hardware registers, you must select the innermost | |
4100 | frame (with @samp{frame 0}). | |
4101 | ||
4102 | However, GDB must deduce where registers are saved, from the machine | |
4103 | code generated by your compiler. If some registers are not saved, or if | |
4104 | GDB is unable to locate the saved registers, the selected stack | |
4105 | frame will make no difference. | |
4106 | ||
4107 | @node Floating Point Hardware, , Registers, Data | |
4108 | @section Floating Point Hardware | |
4109 | @cindex floating point | |
4110 | ||
4111 | Depending on the host machine architecture, GDB may be able to give | |
4112 | you more information about the status of the floating point hardware. | |
4113 | ||
4114 | @table @code | |
4115 | @item info float | |
4116 | @kindex info float | |
4117 | If available, provides hardware-dependent information about the floating | |
4118 | point unit. The exact contents and layout vary depending on the | |
4119 | floating point chip. | |
4120 | @end table | |
4121 | @c FIXME: this is a cop-out. Try to get examples, explanations. Only | |
4122 | @c FIXME...supported currently on arm's and 386's. Mark properly with | |
4123 | @c FIXME... m4 macros to isolate general statements from hardware-dep, | |
4124 | @c FIXME... at that point. | |
4125 | ||
4126 | @node Languages, Symbols, Data, Top | |
4127 | @chapter Using GDB with Different Languages | |
4128 | @cindex languages | |
4129 | ||
4130 | Although programming languages generally have common aspects, they are | |
4131 | rarely expressed in the same manner. For instance, in ANSI C, | |
4132 | dereferencing a pointer @code{p} is accomplished by @code{*p}, but in | |
4133 | Modula-2, it is accomplished by @code{p^}. Values can also be | |
4134 | represented (and displayed) differently. Hex numbers in C are written | |
4135 | like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}. | |
4136 | ||
4137 | @cindex working language | |
4138 | Language-specific information is built into GDB for some languages, | |
4139 | allowing you to express operations like the above in your program's | |
4140 | native language, and allowing GDB to output values in a manner | |
4141 | consistent with the syntax of your program's native language. The | |
4142 | language you use to build expressions, called the @dfn{working | |
4143 | language}, can be selected manually, or GDB can set it | |
4144 | automatically. | |
4145 | ||
4146 | @menu | |
4147 | * Setting:: Switching between source languages | |
4148 | * Show:: Displaying the language | |
4149 | * Checks:: Type and Range checks | |
4150 | * Support:: Supported languages | |
4151 | @end menu | |
4152 | ||
4153 | @node Setting, Show, Languages, Languages | |
4154 | @section Switching between source languages | |
4155 | ||
4156 | There are two ways to control the working language---either have GDB | |
4157 | set it automatically, or select it manually yourself. You can use the | |
4158 | @code{set language} command for either purpose. On startup, GDB | |
4159 | defaults to setting the language automatically. | |
4160 | ||
4161 | @menu | |
4162 | * Manually:: Setting the working language manually | |
4163 | * Automatically:: Having GDB infer the source language | |
4164 | @end menu | |
4165 | ||
4166 | @node Manually, Automatically, Setting, Setting | |
4167 | @subsection Setting the working language | |
4168 | ||
4169 | @kindex set language | |
4170 | To set the language, issue the command @samp{set language @var{lang}}, | |
4171 | where @var{lang} is the name of a language: @code{c} or @code{modula-2}. | |
4172 | For a list of the supported languages, type @samp{set language}. | |
4173 | ||
4174 | Setting the language manually prevents GDB from updating the working | |
4175 | language automatically. This can lead to confusion if you try | |
4176 | to debug a program when the working language is not the same as the | |
4177 | source language, when an expression is acceptable to both | |
4178 | languages---but means different things. For instance, if the current | |
4179 | source file were written in C, and GDB was parsing Modula-2, a | |
4180 | command such as: | |
4181 | ||
4182 | @example | |
4183 | print a = b + c | |
4184 | @end example | |
4185 | ||
4186 | @noindent | |
4187 | might not have the effect you intended. In C, this means to add | |
4188 | @code{b} and @code{c} and place the result in @code{a}. The result | |
4189 | printed would be the value of @code{a}. In Modula-2, this means to compare | |
4190 | @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value. | |
4191 | ||
4192 | If you allow GDB to set the language automatically, then | |
4193 | you can count on expressions evaluating the same way in your debugging | |
4194 | session and in your program. | |
4195 | ||
4196 | @node Automatically, , Manually, Setting | |
4197 | @subsection Having GDB infer the source language | |
4198 | ||
4199 | To have GDB set the working language automatically, use @samp{set | |
4200 | language local} or @samp{set language auto}. GDB then infers the | |
4201 | language that a program was written in by looking at the name of its | |
4202 | source files, and examining their extensions: | |
4203 | ||
4204 | @table @file | |
4205 | @item *.mod | |
4206 | Modula-2 source file | |
4207 | ||
4208 | @item *.c | |
4209 | @itemx *.cc | |
4210 | C or C++ source file. | |
4211 | @end table | |
4212 | ||
4213 | This information is recorded for each function or procedure in a source | |
4214 | file. When your program stops in a frame (usually by encountering a | |
4215 | breakpoint), GDB sets the working language to the language recorded | |
4216 | for the function in that frame. If the language for a frame is unknown | |
4217 | (that is, if the function or block corresponding to the frame was | |
4218 | defined in a source file that does not have a recognized extension), the | |
4219 | current working language is not changed, and GDB issues a warning. | |
4220 | ||
4221 | This may not seem necessary for most programs, which are written | |
4222 | entirely in one source language. However, program modules and libraries | |
4223 | written in one source language can be used by a main program written in | |
4224 | a different source language. Using @samp{set language auto} in this | |
4225 | case frees you from having to set the working language manually. | |
4226 | ||
4227 | @node Show, Checks, Setting, Languages | |
4228 | @section Displaying the language | |
4229 | ||
4230 | The following commands will help you find out which language is the | |
4231 | working language, and also what language source files were written in. | |
4232 | ||
4233 | @kindex show language | |
4234 | @kindex info frame | |
4235 | @kindex info source | |
4236 | @table @code | |
4237 | @item show language | |
4238 | Display the current working language. This is the | |
4239 | language you can use with commands such as @code{print} to | |
4240 | build and compute expressions that may involve variables in your program. | |
4241 | ||
4242 | @item info frame | |
4243 | Among the other information listed here (@pxref{Frame Info, ,Information | |
4244 | about a Frame}) is the source language for this frame. This is the | |
4245 | language that will become the working language if you ever use an | |
4246 | identifier that is in this frame. | |
4247 | ||
4248 | @item info source | |
4249 | Among the other information listed here (@pxref{Symbols, ,Examining the | |
4250 | Symbol Table}) is the source language of this source file. | |
4251 | @end table | |
4252 | ||
4253 | @node Checks, Support, Show, Languages | |
4254 | @section Type and range Checking | |
4255 | ||
4256 | @quotation | |
4257 | @emph{Warning:} In this release, the GDB commands for type and range | |
4258 | checking are included, but they do not yet have any effect. This | |
4259 | section documents the intended facilities. | |
4260 | @end quotation | |
4261 | @c FIXME remove warning when type/range code added | |
4262 | ||
4263 | Some languages are designed to guard you against making seemingly common | |
4264 | errors through a series of compile- and run-time checks. These include | |
4265 | checking the type of arguments to functions and operators, and making | |
4266 | sure mathematical overflows are caught at run time. Checks such as | |
4267 | these help to ensure a program's correctness once it has been compiled | |
4268 | by eliminating type mismatches, and providing active checks for range | |
4269 | errors when your program is running. | |
4270 | ||
4271 | GDB can check for conditions like the above if you wish. | |
4272 | Although GDB will not check the statements in your program, it | |
4273 | can check expressions entered directly into GDB for evaluation via | |
4274 | the @code{print} command, for example. As with the working language, | |
4275 | GDB can also decide whether or not to check automatically based on | |
4276 | your program's source language. @xref{Support, ,Supported Languages}, | |
4277 | for the default settings of supported languages. | |
4278 | ||
4279 | @menu | |
4280 | * Type Checking:: An overview of type checking | |
4281 | * Range Checking:: An overview of range checking | |
4282 | @end menu | |
4283 | ||
4284 | @cindex type checking | |
4285 | @cindex checks, type | |
4286 | @node Type Checking, Range Checking, Checks, Checks | |
4287 | @subsection An overview of type checking | |
4288 | ||
4289 | Some languages, such as Modula-2, are strongly typed, meaning that the | |
4290 | arguments to operators and functions have to be of the correct type, | |
4291 | otherwise an error occurs. These checks prevent type mismatch | |
4292 | errors from ever causing any run-time problems. For example, | |
4293 | ||
4294 | @example | |
4295 | 1 + 2 @result{} 3 | |
4296 | @exdent but | |
4297 | @error{} 1 + 2.3 | |
4298 | @end example | |
4299 | ||
4300 | The second example fails because the @code{CARDINAL} 1 is not | |
4301 | type-compatible with the @code{REAL} 2.3. | |
4302 | ||
4303 | For expressions you use in GDB commands, you can tell the GDB | |
4304 | type checker to skip checking; to treat any mismatches as errors and | |
4305 | abandon the expression; or only issue warnings when type mismatches | |
4306 | occur, but evaluate the expression anyway. When you choose the last of | |
4307 | these, GDB evaluates expressions like the second example above, but | |
4308 | also issues a warning. | |
4309 | ||
4310 | Even though you may turn type checking off, other type-based reasons may | |
4311 | prevent GDB from evaluating an expression. For instance, GDB does not | |
4312 | know how to add an @code{int} and a @code{struct foo}. These particular | |
4313 | type errors have nothing to do with the language in use, and usually | |
4314 | arise from expressions, such as the one described above, which make | |
4315 | little sense to evaluate anyway. | |
4316 | ||
4317 | Each language defines to what degree it is strict about type. For | |
4318 | instance, both Modula-2 and C require the arguments to arithmetical | |
4319 | operators to be numbers. In C, enumerated types and pointers can be | |
4320 | represented as numbers, so that they are valid arguments to mathematical | |
4321 | operators. @xref{Support, ,Supported Languages}, for further | |
4322 | details on specific languages. | |
4323 | ||
4324 | GDB provides some additional commands for controlling the type checker: | |
4325 | ||
4326 | @kindex set check | |
4327 | @kindex set check type | |
4328 | @kindex show check type | |
4329 | @table @code | |
4330 | @item set check type auto | |
4331 | Set type checking on or off based on the current working language. | |
4332 | @xref{Support, ,Supported Languages}, for the default settings for | |
4333 | each language. | |
4334 | ||
4335 | @item set check type on | |
4336 | @itemx set check type off | |
4337 | Set type checking on or off, overriding the default setting for the | |
4338 | current working language. Issue a warning if the setting does not | |
4339 | match the language's default. If any type mismatches occur in | |
4340 | evaluating an expression while typechecking is on, GDB prints a | |
4341 | message and aborts evaluation of the expression. | |
4342 | ||
4343 | @item set check type warn | |
4344 | Cause the type checker to issue warnings, but to always attempt to | |
4345 | evaluate the expression. Evaluating the expression may still | |
4346 | be impossible for other reasons. For example, GDB cannot add | |
4347 | numbers and structures. | |
4348 | ||
4349 | @item show type | |
4350 | Show the current setting of the type checker, and whether or not GDB is | |
4351 | setting it automatically. | |
4352 | @end table | |
4353 | ||
4354 | @cindex range checking | |
4355 | @cindex checks, range | |
4356 | @node Range Checking, , Type Checking, Checks | |
4357 | @subsection An overview of Range Checking | |
4358 | ||
4359 | In some languages (such as Modula-2), it is an error to exceed the | |
4360 | bounds of a type; this is enforced with run-time checks. Such range | |
4361 | checking is meant to ensure program correctness by making sure | |
4362 | computations do not overflow, or indices on an array element access do | |
4363 | not exceed the bounds of the array. | |
4364 | ||
4365 | For expressions you use in GDB commands, you can tell GDB to | |
4366 | ignore range errors; to always treat them as errors and abandon the | |
4367 | expression; or to issue warnings when a range error occurs but evaluate | |
4368 | the expression anyway. | |
4369 | ||
4370 | A range error can result from numerical overflow, from exceeding an | |
4371 | array index bound, or when you type in a constant that is not a member | |
4372 | of any type. Some languages, however, do not treat overflows as an | |
4373 | error. In many implementations of C, mathematical overflow causes the | |
4374 | result to ``wrap around'' to lower values---for example, if @var{m} is | |
4375 | the largest integer value, and @var{s} is the smallest, then | |
4376 | ||
4377 | @example | |
4378 | @var{m} + 1 @result{} @var{s} | |
4379 | @end example | |
4380 | ||
4381 | This, too, is specific to individual languages, and in some cases | |
4382 | specific to individual compilers or machines. @xref{Support, , | |
4383 | Supported Languages}, for further details on specific languages. | |
4384 | ||
4385 | GDB provides some additional commands for controlling the range checker: | |
4386 | ||
4387 | @kindex set check | |
4388 | @kindex set check range | |
4389 | @kindex show check range | |
4390 | @table @code | |
4391 | @item set check range auto | |
4392 | Set range checking on or off based on the current working language. | |
4393 | @xref{Support, ,Supported Languages}, for the default settings for | |
4394 | each language. | |
4395 | ||
4396 | @item set check range on | |
4397 | @itemx set check range off | |
4398 | Set range checking on or off, overriding the default setting for the | |
4399 | current working language. A warning is issued if the setting does not | |
4400 | match the language's default. If a range error occurs, then a message | |
4401 | is printed and evaluation of the expression is aborted. | |
4402 | ||
4403 | @item set check range warn | |
4404 | Output messages when the GDB range checker detects a range error, | |
4405 | but attempt to evaluate the expression anyway. Evaluating the | |
4406 | expression may still be impossible for other reasons, such as accessing | |
4407 | memory that the process does not own (a typical example from many UNIX | |
4408 | systems). | |
4409 | ||
4410 | @item show range | |
4411 | Show the current setting of the range checker, and whether or not it is | |
4412 | being set automatically by GDB. | |
4413 | @end table | |
4414 | ||
4415 | @node Support, , Checks, Languages | |
4416 | @section Supported Languages | |
4417 | ||
4418 | GDB 4 supports C, C++, and Modula-2. The syntax for C and C++ is so | |
4419 | closely related that GDB does not distinguish the two. Some GDB | |
4420 | features may be used in expressions regardless of the language you | |
4421 | use: the GDB @code{@@} and @code{::} operators, and the | |
4422 | @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be | |
4423 | used with the constructs of any of the supported languages. | |
4424 | ||
4425 | The following sections detail to what degree each of these | |
4426 | source languages is supported by GDB. These sections are | |
4427 | not meant to be language tutorials or references, but serve only as a | |
4428 | reference guide to what the GDB expression parser will accept, and | |
4429 | what input and output formats should look like for different languages. | |
4430 | There are many good books written on each of these languages; please | |
4431 | look to these for a language reference or tutorial. | |
4432 | ||
4433 | @menu | |
4434 | * C:: C and C++ | |
4435 | * Modula-2:: Modula-2 | |
4436 | @end menu | |
4437 | ||
4438 | @node C, Modula-2, Support, Support | |
4439 | @subsection C and C++ | |
4440 | @cindex C and C++ | |
4441 | ||
4442 | @cindex expressions in C or C++ | |
4443 | Since C and C++ are so closely related, GDB does not distinguish | |
4444 | between them when interpreting the expressions recognized in GDB | |
4445 | commands. | |
4446 | ||
4447 | @cindex C++ | |
4448 | @kindex g++ | |
4449 | @cindex GNU C++ | |
4450 | The C++ debugging facilities are jointly implemented by the GNU C++ | |
4451 | compiler and GDB. Therefore, to debug your C++ code effectively, | |
4452 | you must compile your C++ programs with the GNU C++ compiler, | |
4453 | @code{g++}. | |
4454 | ||
4455 | @menu | |
4456 | * C Operators:: C and C++ Operators | |
4457 | * C Constants:: C and C++ Constants | |
4458 | * Cplusplus expressions:: C++ Expressions | |
4459 | * C Defaults:: Default settings for C and C++ | |
4460 | * C Checks:: C and C++ Type and Range Checks | |
4461 | * Debugging C:: GDB and C | |
4462 | * Debugging C plus plus:: Special features for C++ | |
4463 | @end menu | |
4464 | ||
4465 | @cindex C and C++ operators | |
4466 | @node C Operators, C Constants, C, C | |
4467 | @subsubsection C and C++ Operators | |
4468 | ||
4469 | Operators must be defined on values of specific types. For instance, | |
4470 | @code{+} is defined on numbers, but not on structures. Operators are | |
4471 | often defined on groups of types. For the purposes of C and C++, the | |
4472 | following definitions hold: | |
4473 | ||
4474 | @itemize @bullet | |
4475 | @item | |
4476 | @emph{Integral types} include @code{int} with any of its storage-class | |
4477 | specifiers, @code{char}, and @code{enum}s. | |
4478 | ||
4479 | @item | |
4480 | @emph{Floating-point types} include @code{float} and @code{double}. | |
4481 | ||
4482 | @item | |
4483 | @emph{Pointer types} include all types defined as @code{(@var{type} | |
4484 | *)}. | |
4485 | ||
4486 | @item | |
4487 | @emph{Scalar types} include all of the above. | |
4488 | @end itemize | |
4489 | ||
4490 | @noindent | |
4491 | The following operators are supported. They are listed here | |
4492 | in order of increasing precedence: | |
4493 | ||
4494 | @table @code | |
4495 | @item , | |
4496 | The comma or sequencing operator. Expressions in a comma-separated list | |
4497 | are evaluated from left to right, with the result of the entire | |
4498 | expression being the last expression evaluated. | |
4499 | ||
4500 | @item = | |
4501 | Assignment. The value of an assignment expression is the value | |
4502 | assigned. Defined on scalar types. | |
4503 | ||
4504 | @item @var{op}= | |
4505 | Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}}, | |
4506 | and translated to @w{@code{@var{a} = @var{a op b}}}. | |
4507 | @w{@code{@var{op}=}} and @code{=} have the same precendence. | |
4508 | @var{op} is any one of the operators @code{|}, @code{^}, @code{&}, | |
4509 | @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}. | |
4510 | ||
4511 | @item ?: | |
4512 | The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought | |
4513 | of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an | |
4514 | integral type. | |
4515 | ||
4516 | @item || | |
4517 | Logical @sc{or}. Defined on integral types. | |
4518 | ||
4519 | @item && | |
4520 | Logical @sc{and}. Defined on integral types. | |
4521 | ||
4522 | @item | | |
4523 | Bitwise @sc{or}. Defined on integral types. | |
4524 | ||
4525 | @item ^ | |
4526 | Bitwise exclusive-@sc{or}. Defined on integral types. | |
4527 | ||
4528 | @item & | |
4529 | Bitwise @sc{and}. Defined on integral types. | |
4530 | ||
4531 | @item ==@r{, }!= | |
4532 | Equality and inequality. Defined on scalar types. The value of these | |
4533 | expressions is 0 for false and non-zero for true. | |
4534 | ||
4535 | @item <@r{, }>@r{, }<=@r{, }>= | |
4536 | Less than, greater than, less than or equal, greater than or equal. | |
4537 | Defined on scalar types. The value of these expressions is 0 for false | |
4538 | and non-zero for true. | |
4539 | ||
4540 | @item <<@r{, }>> | |
4541 | left shift, and right shift. Defined on integral types. | |
4542 | ||
4543 | @item @@ | |
4544 | The GDB ``artificial array'' operator (@pxref{Expressions, ,Expressions}). | |
4545 | ||
4546 | @item +@r{, }- | |
4547 | Addition and subtraction. Defined on integral types, floating-point types and | |
4548 | pointer types. | |
4549 | ||
4550 | @item *@r{, }/@r{, }% | |
4551 | Multiplication, division, and modulus. Multiplication and division are | |
4552 | defined on integral and floating-point types. Modulus is defined on | |
4553 | integral types. | |
4554 | ||
4555 | @item ++@r{, }-- | |
4556 | Increment and decrement. When appearing before a variable, the | |
4557 | operation is performed before the variable is used in an expression; | |
4558 | when appearing after it, the variable's value is used before the | |
4559 | operation takes place. | |
4560 | ||
4561 | @item * | |
4562 | Pointer dereferencing. Defined on pointer types. Same precedence as | |
4563 | @code{++}. | |
4564 | ||
4565 | @item & | |
4566 | Address operator. Defined on variables. Same precedence as @code{++}. | |
4567 | ||
4568 | @item - | |
4569 | Negative. Defined on integral and floating-point types. Same | |
4570 | precedence as @code{++}. | |
4571 | ||
4572 | @item ! | |
4573 | Logical negation. Defined on integral types. Same precedence as | |
4574 | @code{++}. | |
4575 | ||
4576 | @item ~ | |
4577 | Bitwise complement operator. Defined on integral types. Same precedence as | |
4578 | @code{++}. | |
4579 | ||
4580 | @item .@r{, }-> | |
4581 | Structure member, and pointer-to-structure member. For convenience, | |
4582 | GDB regards the two as equivalent, choosing whether to dereference a | |
4583 | pointer based on the stored type information. | |
4584 | Defined on @code{struct}s and @code{union}s. | |
4585 | ||
4586 | @item [] | |
4587 | Array indexing. @code{@var{a}[@var{i}]} is defined as | |
4588 | @code{*(@var{a}+@var{i})}. Same precedence as @code{->}. | |
4589 | ||
4590 | @item () | |
4591 | Function parameter list. Same precedence as @code{->}. | |
4592 | ||
4593 | @item :: | |
4594 | C++ scope resolution operator. Defined on | |
4595 | @code{struct}, @code{union}, and @code{class} types. | |
4596 | ||
4597 | @item :: | |
4598 | The GDB scope operator (@pxref{Expressions, ,Expressions}). Same precedence as | |
4599 | @code{::}, above. | |
4600 | @end table | |
4601 | ||
4602 | @cindex C and C++ constants | |
4603 | @node C Constants, Cplusplus expressions, C Operators, C | |
4604 | @subsubsection C and C++ Constants | |
4605 | ||
4606 | GDB allows you to express the constants of C and C++ in the | |
4607 | following ways: | |
4608 | ||
4609 | @itemize @bullet | |
4610 | @item | |
4611 | Integer constants are a sequence of digits. Octal constants are | |
4612 | specified by a leading @samp{0} (ie. zero), and hexadecimal constants by | |
4613 | a leading @samp{0x} or @samp{0X}. Constants may also end with a letter | |
4614 | @samp{l}, specifying that the constant should be treated as a | |
4615 | @code{long} value. | |
4616 | ||
4617 | @item | |
4618 | Floating point constants are a sequence of digits, followed by a decimal | |
4619 | point, followed by a sequence of digits, and optionally followed by an | |
4620 | exponent. An exponent is of the form: | |
4621 | @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another | |
4622 | sequence of digits. The @samp{+} is optional for positive exponents. | |
4623 | ||
4624 | @item | |
4625 | Enumerated constants consist of enumerated identifiers, or their | |
4626 | integral equivalents. | |
4627 | ||
4628 | @item | |
4629 | Character constants are a single character surrounded by single quotes | |
4630 | (@code{'}), or a number---the ordinal value of the corresponding character | |
4631 | (usually its @sc{ASCII} value). Within quotes, the single character may | |
4632 | be represented by a letter or by @dfn{escape sequences}, which are of | |
4633 | the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation | |
4634 | of the character's ordinal value; or of the form @samp{\@var{x}}, where | |
4635 | @samp{@var{x}} is a predefined special character---for example, | |
4636 | @samp{\n} for newline. | |
4637 | ||
4638 | @item | |
4639 | String constants are a sequence of character constants surrounded | |
4640 | by double quotes (@code{"}). | |
4641 | ||
4642 | @item | |
4643 | Pointer constants are an integral value. | |
4644 | @end itemize | |
4645 | ||
4646 | @node Cplusplus expressions, C Defaults, C Constants, C | |
4647 | @subsubsection C++ Expressions | |
4648 | ||
4649 | @cindex expressions in C++ | |
4650 | GDB's expression handling has the following extensions to | |
4651 | interpret a significant subset of C++ expressions: | |
4652 | ||
4653 | @enumerate | |
4654 | ||
4655 | @cindex member functions | |
4656 | @item | |
4657 | Member function calls are allowed; you can use expressions like | |
4658 | ||
4659 | @example | |
4660 | count = aml->GetOriginal(x, y) | |
4661 | @end example | |
4662 | ||
4663 | @kindex this | |
4664 | @cindex namespace in C++ | |
4665 | @item | |
4666 | While a member function is active (in the selected stack frame), your | |
4667 | expressions have the same namespace available as the member function; | |
4668 | that is, GDB allows implicit references to the class instance | |
4669 | pointer @code{this} following the same rules as C++. | |
4670 | ||
4671 | @cindex call overloaded functions | |
4672 | @cindex type conversions in C++ | |
4673 | @item | |
4674 | You can call overloaded functions; GDB will resolve the function | |
4675 | call to the right definition, with one restriction---you must use | |
4676 | arguments of the type required by the function that you want to call. | |
4677 | GDB will not perform conversions requiring constructors or | |
4678 | user-defined type operators. | |
4679 | ||
4680 | @cindex reference declarations | |
4681 | @item | |
4682 | GDB understands variables declared as C++ references; you can use them in | |
4683 | expressions just as you do in C++ source---they are automatically | |
4684 | dereferenced. | |
4685 | ||
4686 | In the parameter list shown when GDB displays a frame, the values of | |
4687 | reference variables are not displayed (unlike other variables); this | |
4688 | avoids clutter, since references are often used for large structures. | |
4689 | The @emph{address} of a reference variable is always shown, unless | |
4690 | you have specified @samp{set print address off}. | |
4691 | ||
4692 | @item | |
4693 | GDB supports the C++ name resolution operator @code{::}---your | |
4694 | expressions can use it just as expressions in your program do. Since | |
4695 | one scope may be defined in another, you can use @code{::} repeatedly if | |
4696 | necessary, for example in an expression like | |
4697 | @samp{@var{scope1}::@var{scope2}::@var{name}}. GDB also allows | |
4698 | resolving name scope by reference to source files, in both C and C++ | |
4699 | debugging (@pxref{Variables, ,Program Variables}). | |
4700 | @end enumerate | |
4701 | ||
4702 | @node C Defaults, C Checks, Cplusplus expressions, C | |
4703 | @subsubsection C and C++ Defaults | |
4704 | @cindex C and C++ defaults | |
4705 | ||
4706 | If you allow GDB to set type and range checking automatically, they | |
4707 | both default to @code{off} whenever the working language changes to | |
4708 | C/C++. This happens regardless of whether you, or GDB, | |
4709 | selected the working language. | |
4710 | ||
4711 | If you allow GDB to set the language automatically, it sets the | |
4712 | working language to C/C++ on entering code compiled from a source file | |
4713 | whose name ends with @file{.c} or @file{.cc}. | |
4714 | @xref{Automatically, ,Having GDB infer the source language}, for | |
4715 | further details. | |
4716 | ||
4717 | @node C Checks, Debugging C, C Defaults, C | |
4718 | @subsubsection C and C++ Type and Range Checks | |
4719 | @cindex C and C++ checks | |
4720 | ||
4721 | @quotation | |
4722 | @emph{Warning:} in this release, GDB does not yet perform type or | |
4723 | range checking. | |
4724 | @end quotation | |
4725 | @c FIXME remove warning when type/range checks added | |
4726 | ||
4727 | By default, when GDB parses C or C++ expressions, type checking | |
4728 | is not used. However, if you turn type checking on, GDB will | |
4729 | consider two variables type equivalent if: | |
4730 | ||
4731 | @itemize @bullet | |
4732 | @item | |
4733 | The two variables are structured and have the same structure, union, or | |
4734 | enumerated tag. | |
4735 | ||
4736 | @item | |
4737 | Two two variables have the same type name, or types that have been | |
4738 | declared equivalent through @code{typedef}. | |
4739 | ||
4740 | @ignore | |
4741 | @c leaving this out because neither J Gilmore nor R Pesch understand it. | |
4742 | @c FIXME--beers? | |
4743 | @item | |
4744 | The two @code{struct}, @code{union}, or @code{enum} variables are | |
4745 | declared in the same declaration. (Note: this may not be true for all C | |
4746 | compilers.) | |
4747 | @end ignore | |
4748 | @end itemize | |
4749 | ||
4750 | Range checking, if turned on, is done on mathematical operations. Array | |
4751 | indices are not checked, since they are often used to index a pointer | |
4752 | that is not itself an array. | |
4753 | ||
4754 | @node Debugging C, Debugging C plus plus, C Checks, C | |
4755 | @subsubsection GDB and C | |
4756 | ||
4757 | The @code{set print union} and @code{show print union} commands apply to | |
4758 | the @code{union} type. When set to @samp{on}, any @code{union} that is | |
4759 | inside a @code{struct} or @code{class} will also be printed. | |
4760 | Otherwise, it will appear as @samp{@{...@}}. | |
4761 | ||
4762 | The @code{@@} operator aids in the debugging of dynamic arrays, formed | |
4763 | with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions}) | |
4764 | ||
4765 | @node Debugging C plus plus, , Debugging C, C | |
4766 | @subsubsection GDB Commands for C++ | |
4767 | ||
4768 | @cindex commands for C++ | |
4769 | Some GDB commands are particularly useful with C++, and some are | |
4770 | designed specifically for use with C++. Here is a summary: | |
4771 | ||
4772 | @table @code | |
4773 | @cindex break in overloaded functions | |
4774 | @item @r{breakpoint menus} | |
4775 | When you want a breakpoint in a function whose name is overloaded, | |
4776 | GDB's breakpoint menus help you specify which function definition | |
4777 | you want. @xref{Breakpoint Menus}. | |
4778 | ||
4779 | @cindex overloading in C++ | |
4780 | @item rbreak @var{regex} | |
4781 | Setting breakpoints using regular expressions is helpful for setting | |
4782 | breakpoints on overloaded functions that are not members of any special | |
4783 | classes. | |
4784 | @xref{Set Breaks, ,Setting Breakpoints}. | |
4785 | ||
4786 | @cindex C++ exception handling | |
4787 | @item catch @var{exceptions} | |
4788 | @itemx info catch | |
4789 | Debug C++ exception handling using these commands. @xref{Exception | |
4790 | Handling, ,Breakpoints and Exceptions}. | |
4791 | ||
4792 | @cindex inheritance | |
4793 | @item ptype @var{typename} | |
4794 | Print inheritance relationships as well as other information for type | |
4795 | @var{typename}. | |
4796 | @xref{Symbols, ,Examining the Symbol Table}. | |
4797 | ||
4798 | @cindex C++ symbol display | |
4799 | @item set print demangle | |
4800 | @itemx show print demangle | |
4801 | @itemx set print asm-demangle | |
4802 | @itemx show print asm-demangle | |
4803 | Control whether C++ symbols display in their source form, both when | |
4804 | displaying code as C++ source and when displaying disassemblies. | |
4805 | @xref{Print Settings, ,Print Settings}. | |
4806 | ||
4807 | @item set print object | |
4808 | @itemx show print object | |
4809 | Choose whether to print derived (actual) or declared types of objects. | |
4810 | @xref{Print Settings, ,Print Settings}. | |
4811 | ||
4812 | @item set print vtbl | |
4813 | @itemx show print vtbl | |
4814 | Control the format for printing virtual function tables. | |
4815 | @xref{Print Settings, ,Print Settings}. | |
4816 | @end table | |
4817 | ||
4818 | @node Modula-2, , C, Support | |
4819 | @subsection Modula-2 | |
4820 | @cindex Modula-2 | |
4821 | ||
4822 | The extensions made to GDB to support Modula-2 support output | |
4823 | from the GNU Modula-2 compiler (which is currently being developed). | |
4824 | Other Modula-2 compilers are not currently supported, and attempting to | |
4825 | debug executables produced by them will most likely result in an error | |
4826 | as GDB reads in the executable's symbol table. | |
4827 | ||
4828 | @cindex expressions in Modula-2 | |
4829 | @menu | |
4830 | * M2 Operators:: Built-in operators | |
4831 | * Built-In Func/Proc:: Built-in Functions and Procedures | |
4832 | * M2 Constants:: Modula-2 Constants | |
4833 | * M2 Defaults:: Default settings for Modula-2 | |
4834 | * Deviations:: Deviations from standard Modula-2 | |
4835 | * M2 Checks:: Modula-2 Type and Range Checks | |
4836 | * M2 Scope:: The scope operators @code{::} and @code{.} | |
4837 | * GDB/M2:: GDB and Modula-2 | |
4838 | @end menu | |
4839 | ||
4840 | @node M2 Operators, Built-In Func/Proc, Modula-2, Modula-2 | |
4841 | @subsubsection Operators | |
4842 | @cindex Modula-2 operators | |
4843 | ||
4844 | Operators must be defined on values of specific types. For instance, | |
4845 | @code{+} is defined on numbers, but not on structures. Operators are | |
4846 | often defined on groups of types. For the purposes of Modula-2, the | |
4847 | following definitions hold: | |
4848 | ||
4849 | @itemize @bullet | |
4850 | ||
4851 | @item | |
4852 | @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and | |
4853 | their subranges. | |
4854 | ||
4855 | @item | |
4856 | @emph{Character types} consist of @code{CHAR} and its subranges. | |
4857 | ||
4858 | @item | |
4859 | @emph{Floating-point types} consist of @code{REAL}. | |
4860 | ||
4861 | @item | |
4862 | @emph{Pointer types} consist of anything declared as @code{POINTER TO | |
4863 | @var{type}}. | |
4864 | ||
4865 | @item | |
4866 | @emph{Scalar types} consist of all of the above. | |
4867 | ||
4868 | @item | |
4869 | @emph{Set types} consist of @code{SET}s and @code{BITSET}s. | |
4870 | ||
4871 | @item | |
4872 | @emph{Boolean types} consist of @code{BOOLEAN}. | |
4873 | @end itemize | |
4874 | ||
4875 | @noindent | |
4876 | The following operators are supported, and appear in order of | |
4877 | increasing precedence: | |
4878 | ||
4879 | @table @code | |
4880 | @item , | |
4881 | Function argument or array index separator. | |
4882 | ||
4883 | @item := | |
4884 | Assignment. The value of @var{var} @code{:=} @var{value} is | |
4885 | @var{value}. | |
4886 | ||
4887 | @item <@r{, }> | |
4888 | Less than, greater than on integral, floating-point, or enumerated | |
4889 | types. | |
4890 | ||
4891 | @item <=@r{, }>= | |
4892 | Less than, greater than, less than or equal to, greater than or equal to | |
4893 | on integral, floating-point and enumerated types, or set inclusion on | |
4894 | set types. Same precedence as @code{<}. | |
4895 | ||
4896 | @item =@r{, }<>@r{, }# | |
4897 | Equality and two ways of expressing inequality, valid on scalar types. | |
4898 | Same precedence as @code{<}. In GDB scripts, only @code{<>} is | |
4899 | available for inequality, since @code{#} conflicts with the script | |
4900 | comment character. | |
4901 | ||
4902 | @item IN | |
4903 | Set membership. Defined on set types and the types of their members. | |
4904 | Same precedence as @code{<}. | |
4905 | ||
4906 | @item OR | |
4907 | Boolean disjunction. Defined on boolean types. | |
4908 | ||
4909 | @item AND@r{, }& | |
4910 | Boolean conjuction. Defined on boolean types. | |
4911 | ||
4912 | @item @@ | |
4913 | The GDB ``artificial array'' operator (@pxref{Expressions, ,Expressions}). | |
4914 | ||
4915 | @item +@r{, }- | |
4916 | Addition and subtraction on integral and floating-point types, or union | |
4917 | and difference on set types. | |
4918 | ||
4919 | @item * | |
4920 | Multiplication on integral and floating-point types, or set intersection | |
4921 | on set types. | |
4922 | ||
4923 | @item / | |
4924 | Division on floating-point types, or symmetric set difference on set | |
4925 | types. Same precedence as @code{*}. | |
4926 | ||
4927 | @item DIV@r{, }MOD | |
4928 | Integer division and remainder. Defined on integral types. Same | |
4929 | precedence as @code{*}. | |
4930 | ||
4931 | @item - | |
4932 | Negative. Defined on @code{INTEGER}s and @code{REAL}s. | |
4933 | ||
4934 | @item ^ | |
4935 | Pointer dereferencing. Defined on pointer types. | |
4936 | ||
4937 | @item NOT | |
4938 | Boolean negation. Defined on boolean types. Same precedence as | |
4939 | @code{^}. | |
4940 | ||
4941 | @item . | |
4942 | @code{RECORD} field selector. Defined on @code{RECORD}s. Same | |
4943 | precedence as @code{^}. | |
4944 | ||
4945 | @item [] | |
4946 | Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}. | |
4947 | ||
4948 | @item () | |
4949 | Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence | |
4950 | as @code{^}. | |
4951 | ||
4952 | @item ::@r{, }. | |
4953 | GDB and Modula-2 scope operators. | |
4954 | @end table | |
4955 | ||
4956 | @quotation | |
4957 | @emph{Warning:} Sets and their operations are not yet supported, so GDB | |
4958 | will treat the use of the operator @code{IN}, or the use of operators | |
4959 | @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#}, | |
4960 | @code{<=}, and @code{>=} on sets as an error. | |
4961 | @end quotation | |
4962 | ||
4963 | @cindex Modula-2 built-ins | |
4964 | @node Built-In Func/Proc, M2 Constants, M2 Operators, Modula-2 | |
4965 | @subsubsection Built-in Functions and Procedures | |
4966 | ||
4967 | Modula-2 also makes available several built-in procedures and functions. | |
4968 | In describing these, the following metavariables are used: | |
4969 | ||
4970 | @table @var | |
4971 | ||
4972 | @item a | |
4973 | represents an @code{ARRAY} variable. | |
4974 | ||
4975 | @item c | |
4976 | represents a @code{CHAR} constant or variable. | |
4977 | ||
4978 | @item i | |
4979 | represents a variable or constant of integral type. | |
4980 | ||
4981 | @item m | |
4982 | represents an identifier that belongs to a set. Generally used in the | |
4983 | same function with the metavariable @var{s}. The type of @var{s} should | |
4984 | be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}. | |
4985 | ||
4986 | @item n | |
4987 | represents a variable or constant of integral or floating-point type. | |
4988 | ||
4989 | @item r | |
4990 | represents a variable or constant of floating-point type. | |
4991 | ||
4992 | @item t | |
4993 | represents a type. | |
4994 | ||
4995 | @item v | |
4996 | represents a variable. | |
4997 | ||
4998 | @item x | |
4999 | represents a variable or constant of one of many types. See the | |
5000 | explanation of the function for details. | |
5001 | @end table | |
5002 | ||
5003 | All Modula-2 built-in procedures also return a result, described below. | |
5004 | ||
5005 | @table @code | |
5006 | @item ABS(@var{n}) | |
5007 | Returns the absolute value of @var{n}. | |
5008 | ||
5009 | @item CAP(@var{c}) | |
5010 | If @var{c} is a lower case letter, it returns its upper case | |
5011 | equivalent, otherwise it returns its argument | |
5012 | ||
5013 | @item CHR(@var{i}) | |
5014 | Returns the character whose ordinal value is @var{i}. | |
5015 | ||
5016 | @item DEC(@var{v}) | |
5017 | Decrements the value in the variable @var{v}. Returns the new value. | |
5018 | ||
5019 | @item DEC(@var{v},@var{i}) | |
5020 | Decrements the value in the variable @var{v} by @var{i}. Returns the | |
5021 | new value. | |
5022 | ||
5023 | @item EXCL(@var{m},@var{s}) | |
5024 | Removes the element @var{m} from the set @var{s}. Returns the new | |
5025 | set. | |
5026 | ||
5027 | @item FLOAT(@var{i}) | |
5028 | Returns the floating point equivalent of the integer @var{i}. | |
5029 | ||
5030 | @item HIGH(@var{a}) | |
5031 | Returns the index of the last member of @var{a}. | |
5032 | ||
5033 | @item INC(@var{v}) | |
5034 | Increments the value in the variable @var{v}. Returns the new value. | |
5035 | ||
5036 | @item INC(@var{v},@var{i}) | |
5037 | Increments the value in the variable @var{v} by @var{i}. Returns the | |
5038 | new value. | |
5039 | ||
5040 | @item INCL(@var{m},@var{s}) | |
5041 | Adds the element @var{m} to the set @var{s} if it is not already | |
5042 | there. Returns the new set. | |
5043 | ||
5044 | @item MAX(@var{t}) | |
5045 | Returns the maximum value of the type @var{t}. | |
5046 | ||
5047 | @item MIN(@var{t}) | |
5048 | Returns the minimum value of the type @var{t}. | |
5049 | ||
5050 | @item ODD(@var{i}) | |
5051 | Returns boolean TRUE if @var{i} is an odd number. | |
5052 | ||
5053 | @item ORD(@var{x}) | |
5054 | Returns the ordinal value of its argument. For example, the ordinal | |
5055 | value of a character is its ASCII value (on machines supporting the | |
5056 | ASCII character set). @var{x} must be of an ordered type, which include | |
5057 | integral, character and enumerated types. | |
5058 | ||
5059 | @item SIZE(@var{x}) | |
5060 | Returns the size of its argument. @var{x} can be a variable or a type. | |
5061 | ||
5062 | @item TRUNC(@var{r}) | |
5063 | Returns the integral part of @var{r}. | |
5064 | ||
5065 | @item VAL(@var{t},@var{i}) | |
5066 | Returns the member of the type @var{t} whose ordinal value is @var{i}. | |
5067 | @end table | |
5068 | ||
5069 | @quotation | |
5070 | @emph{Warning:} Sets and their operations are not yet supported, so | |
5071 | GDB will treat the use of procedures @code{INCL} and @code{EXCL} as | |
5072 | an error. | |
5073 | @end quotation | |
5074 | ||
5075 | @cindex Modula-2 constants | |
5076 | @node M2 Constants, M2 Defaults, Built-In Func/Proc, Modula-2 | |
5077 | @subsubsection Constants | |
5078 | ||
5079 | GDB allows you to express the constants of Modula-2 in the following | |
5080 | ways: | |
5081 | ||
5082 | @itemize @bullet | |
5083 | ||
5084 | @item | |
5085 | Integer constants are simply a sequence of digits. When used in an | |
5086 | expression, a constant is interpreted to be type-compatible with the | |
5087 | rest of the expression. Hexadecimal integers are specified by a | |
5088 | trailing @samp{H}, and octal integers by a trailing @samp{B}. | |
5089 | ||
5090 | @item | |
5091 | Floating point constants appear as a sequence of digits, followed by a | |
5092 | decimal point and another sequence of digits. An optional exponent can | |
5093 | then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where | |
5094 | @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the | |
5095 | digits of the floating point constant must be valid decimal (base 10) | |
5096 | digits. | |
5097 | ||
5098 | @item | |
5099 | Character constants consist of a single character enclosed by a pair of | |
5100 | like quotes, either single (@code{'}) or double (@code{"}). They may | |
5101 | also be expressed by their ordinal value (their ASCII value, usually) | |
5102 | followed by a @samp{C}. | |
5103 | ||
5104 | @item | |
5105 | String constants consist of a sequence of characters enclosed by a | |
5106 | pair of like quotes, either single (@code{'}) or double (@code{"}). | |
5107 | Escape sequences in the style of C are also allowed. @xref{C | |
5108 | Constants, ,C and C++ Constants}, for a brief explanation of escape | |
5109 | sequences. | |
5110 | ||
5111 | @item | |
5112 | Enumerated constants consist of an enumerated identifier. | |
5113 | ||
5114 | @item | |
5115 | Boolean constants consist of the identifiers @code{TRUE} and | |
5116 | @code{FALSE}. | |
5117 | ||
5118 | @item | |
5119 | Pointer constants consist of integral values only. | |
5120 | ||
5121 | @item | |
5122 | Set constants are not yet supported. | |
5123 | @end itemize | |
5124 | ||
5125 | @node M2 Defaults, Deviations, M2 Constants, Modula-2 | |
5126 | @subsubsection Modula-2 Defaults | |
5127 | @cindex Modula-2 defaults | |
5128 | ||
5129 | If type and range checking are set automatically by GDB, they | |
5130 | both default to @code{on} whenever the working language changes to | |
5131 | Modula-2. This happens regardless of whether you, or GDB, | |
5132 | selected the working language. | |
5133 | ||
5134 | If you allow GDB to set the language automatically, then entering | |
5135 | code compiled from a file whose name ends with @file{.mod} will set the | |
5136 | working language to Modula-2. @xref{Automatically, ,Having GDB set | |
5137 | the language automatically}, for further details. | |
5138 | ||
5139 | @node Deviations, M2 Checks, M2 Defaults, Modula-2 | |
5140 | @subsubsection Deviations from Standard Modula-2 | |
5141 | @cindex Modula-2, deviations from | |
5142 | ||
5143 | A few changes have been made to make Modula-2 programs easier to debug. | |
5144 | This is done primarily via loosening its type strictness: | |
5145 | ||
5146 | @itemize @bullet | |
5147 | @item | |
5148 | Unlike in standard Modula-2, pointer constants can be formed by | |
5149 | integers. This allows you to modify pointer variables during | |
5150 | debugging. (In standard Modula-2, the actual address contained in a | |
5151 | pointer variable is hidden from you; it can only be modified | |
5152 | through direct assignment to another pointer variable or expression that | |
5153 | returned a pointer.) | |
5154 | ||
5155 | @item | |
5156 | C escape sequences can be used in strings and characters to represent | |
5157 | non-printable characters. GDB will print out strings with these | |
5158 | escape sequences embedded. Single non-printable characters are | |
5159 | printed using the @samp{CHR(@var{nnn})} format. | |
5160 | ||
5161 | @item | |
5162 | The assignment operator (@code{:=}) returns the value of its right-hand | |
5163 | argument. | |
5164 | ||
5165 | @item | |
5166 | All built-in procedures both modify @emph{and} return their argument. | |
5167 | @end itemize | |
5168 | ||
5169 | @node M2 Checks, M2 Scope, Deviations, Modula-2 | |
5170 | @subsubsection Modula-2 Type and Range Checks | |
5171 | @cindex Modula-2 checks | |
5172 | ||
5173 | @quotation | |
5174 | @emph{Warning:} in this release, GDB does not yet perform type or | |
5175 | range checking. | |
5176 | @end quotation | |
5177 | @c FIXME remove warning when type/range checks added | |
5178 | ||
5179 | GDB considers two Modula-2 variables type equivalent if: | |
5180 | ||
5181 | @itemize @bullet | |
5182 | @item | |
5183 | They are of types that have been declared equivalent via a @code{TYPE | |
5184 | @var{t1} = @var{t2}} statement | |
5185 | ||
5186 | @item | |
5187 | They have been declared on the same line. (Note: This is true of the | |
5188 | GNU Modula-2 compiler, but it may not be true of other compilers.) | |
5189 | @end itemize | |
5190 | ||
5191 | As long as type checking is enabled, any attempt to combine variables | |
5192 | whose types are not equivalent is an error. | |
5193 | ||
5194 | Range checking is done on all mathematical operations, assignment, array | |
5195 | index bounds, and all built-in functions and procedures. | |
5196 | ||
5197 | @node M2 Scope, GDB/M2, M2 Checks, Modula-2 | |
5198 | @subsubsection The scope operators @code{::} and @code{.} | |
5199 | @cindex scope | |
5200 | @kindex . | |
5201 | @cindex colon, doubled as scope operator | |
5202 | @ifinfo | |
5203 | @kindex colon-colon | |
5204 | @c Info cannot handoe :: but TeX can. | |
5205 | @end ifinfo | |
5206 | @iftex | |
5207 | @kindex :: | |
5208 | @end iftex | |
5209 | ||
5210 | There are a few subtle differences between the Modula-2 scope operator | |
5211 | (@code{.}) and the GDB scope operator (@code{::}). The two have | |
5212 | similar syntax: | |
5213 | ||
5214 | @example | |
5215 | ||
5216 | @var{module} . @var{id} | |
5217 | @var{scope} :: @var{id} | |
5218 | @end example | |
5219 | ||
5220 | @noindent | |
5221 | where @var{scope} is the name of a module or a procedure, | |
5222 | @var{module} the name of a module, and @var{id} is any declared | |
5223 | identifier within your program, except another module. | |
5224 | ||
5225 | Using the @code{::} operator makes GDB search the scope | |
5226 | specified by @var{scope} for the identifier @var{id}. If it is not | |
5227 | found in the specified scope, then GDB will search all scopes | |
5228 | enclosing the one specified by @var{scope}. | |
5229 | ||
5230 | Using the @code{.} operator makes GDB search the current scope for | |
5231 | the identifier specified by @var{id} that was imported from the | |
5232 | definition module specified by @var{module}. With this operator, it is | |
5233 | an error if the identifier @var{id} was not imported from definition | |
5234 | module @var{module}, or if @var{id} is not an identifier in | |
5235 | @var{module}. | |
5236 | ||
5237 | @node GDB/M2, , M2 Scope, Modula-2 | |
5238 | @subsubsection GDB and Modula-2 | |
5239 | ||
5240 | Some GDB commands have little use when debugging Modula-2 programs. | |
5241 | Five subcommands of @code{set print} and @code{show print} apply | |
5242 | specifically to C and C++: @samp{vtbl}, @samp{demangle}, | |
5243 | @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four | |
5244 | apply to C++, and the last to C's @code{union} type, which has no direct | |
5245 | analogue in Modula-2. | |
5246 | ||
5247 | The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available | |
5248 | while using any language, is not useful with Modula-2. Its | |
5249 | intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be | |
5250 | created in Modula-2 as they can in C or C++. However, because an | |
5251 | address can be specified by an integral constant, the construct | |
5252 | @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions}) | |
5253 | ||
5254 | @cindex @code{#} in Modula-2 | |
5255 | In GDB scripts, the Modula-2 inequality operator @code{#} is | |
5256 | interpreted as the beginning of a comment. Use @code{<>} instead. | |
5257 | ||
5258 | @node Symbols, Altering, Languages, Top | |
5259 | @chapter Examining the Symbol Table | |
5260 | ||
5261 | The commands described in this section allow you to inquire about the | |
5262 | symbols (names of variables, functions and types) defined in your | |
5263 | program. This information is inherent in the text of your program and | |
5264 | does not change as your program executes. GDB finds it in your | |
5265 | program's symbol table, in the file indicated when you started GDB | |
5266 | (@pxref{File Options, ,Choosing Files}), or by one of the | |
5267 | file-management commands (@pxref{Files, ,Commands to Specify Files}). | |
5268 | ||
5269 | @table @code | |
5270 | @item info address @var{symbol} | |
5271 | @kindex info address | |
5272 | Describe where the data for @var{symbol} is stored. For a register | |
5273 | variable, this says which register it is kept in. For a non-register | |
5274 | local variable, this prints the stack-frame offset at which the variable | |
5275 | is always stored. | |
5276 | ||
5277 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
5278 | at all for a register variables, and for a stack local variable prints | |
5279 | the exact address of the current instantiation of the variable. | |
5280 | ||
5281 | @item whatis @var{exp} | |
5282 | @kindex whatis | |
5283 | Print the data type of expression @var{exp}. @var{exp} is not | |
5284 | actually evaluated, and any side-effecting operations (such as | |
5285 | assignments or function calls) inside it do not take place. | |
5286 | @xref{Expressions, ,Expressions}. | |
5287 | ||
5288 | @item whatis | |
5289 | Print the data type of @code{$}, the last value in the value history. | |
5290 | ||
5291 | @item ptype @var{typename} | |
5292 | @kindex ptype | |
5293 | Print a description of data type @var{typename}. @var{typename} may be | |
5294 | the name of a type, or for C code it may have the form | |
5295 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
5296 | @samp{enum @var{enum-tag}}. | |
5297 | ||
5298 | @item ptype @var{exp} | |
5299 | @itemx ptype | |
5300 | Print a description of the type of expression @var{exp}. @code{ptype} | |
5301 | differs from @code{whatis} by printing a detailed description, instead | |
5302 | of just the name of the type. For example, if your program declares a | |
5303 | variable as | |
5304 | ||
5305 | @example | |
5306 | struct complex @{double real; double imag;@} v; | |
5307 | @end example | |
5308 | ||
5309 | @noindent | |
5310 | compare the output of the two commands: | |
5311 | ||
5312 | @example | |
5313 | @group | |
5314 | (gdb) whatis v | |
5315 | type = struct complex | |
5316 | (gdb) ptype v | |
5317 | type = struct complex @{ | |
5318 | double real; | |
5319 | double imag; | |
5320 | @} | |
5321 | @end group | |
5322 | @end example | |
5323 | ||
5324 | @noindent | |
5325 | As with @code{whatis}, using @code{ptype} without an argument refers to | |
5326 | the type of @code{$}, the last value in the value history. | |
5327 | ||
5328 | @item info types @var{regexp} | |
5329 | @itemx info types | |
5330 | @kindex info types | |
5331 | Print a brief description of all types whose name matches @var{regexp} | |
5332 | (or all types in your program, if you supply no argument). Each | |
5333 | complete typename is matched as though it were a complete line; thus, | |
5334 | @samp{i type value} gives information on all types in your program whose | |
5335 | name includes the string @code{value}, but @samp{i type ^value$} gives | |
5336 | information only on types whose complete name is @code{value}. | |
5337 | ||
5338 | This command differs from @code{ptype} in two ways: first, like | |
5339 | @code{whatis}, it does not print a detailed description; second, it | |
5340 | lists all source files where a type is defined. | |
5341 | ||
5342 | @item info source | |
5343 | @kindex info source | |
5344 | Show the name of the current source file---that is, the source file for | |
5345 | the function containing the current point of execution---and the language | |
5346 | it was written in. | |
5347 | ||
5348 | @item info sources | |
5349 | @kindex info sources | |
5350 | Print the names of all source files in your program for which there is | |
5351 | debugging information, organized into two lists: files whose symbols | |
5352 | have already been read, and files whose symbols will be read when needed. | |
5353 | ||
5354 | @item info functions | |
5355 | @kindex info functions | |
5356 | Print the names and data types of all defined functions. | |
5357 | ||
5358 | @item info functions @var{regexp} | |
5359 | Print the names and data types of all defined functions | |
5360 | whose names contain a match for regular expression @var{regexp}. | |
5361 | Thus, @samp{info fun step} finds all functions whose names | |
5362 | include @code{step}; @samp{info fun ^step} finds those whose names | |
5363 | start with @code{step}. | |
5364 | ||
5365 | @item info variables | |
5366 | @kindex info variables | |
5367 | Print the names and data types of all variables that are declared | |
5368 | outside of functions (i.e., excluding local variables). | |
5369 | ||
5370 | @item info variables @var{regexp} | |
5371 | Print the names and data types of all variables (except for local | |
5372 | variables) whose names contain a match for regular expression | |
5373 | @var{regexp}. | |
5374 | ||
5375 | @ignore | |
5376 | This was never implemented. | |
5377 | @item info methods | |
5378 | @itemx info methods @var{regexp} | |
5379 | @kindex info methods | |
5380 | The @code{info methods} command permits the user to examine all defined | |
5381 | methods within C++ program, or (with the @var{regexp} argument) a | |
5382 | specific set of methods found in the various C++ classes. Many | |
5383 | C++ classes provide a large number of methods. Thus, the output | |
5384 | from the @code{ptype} command can be overwhelming and hard to use. The | |
5385 | @code{info-methods} command filters the methods, printing only those | |
5386 | which match the regular-expression @var{regexp}. | |
5387 | @end ignore | |
5388 | ||
5389 | @item printsyms @var{filename} | |
5390 | @itemx printpsyms @var{filename} | |
5391 | @kindex printsyms | |
5392 | @cindex symbol dump | |
5393 | @kindex printsyms | |
5394 | @cindex partial symbol dump | |
5395 | Write a dump of debugging symbol data into the file @var{filename}. | |
5396 | These commands are used to debug the GDB symbol-reading code. Only | |
5397 | symbols with debugging data are included. If you use @code{printsyms}, | |
5398 | GDB includes all the symbols for which it has already collected full | |
5399 | details: that is, @var{filename} reflects symbols for only those files | |
5400 | whose symbols GDB has read. You can use the command @code{info | |
5401 | sources} to find out which files these are. If you use | |
5402 | @code{printpsyms}, the dump also shows information about symbols that | |
5403 | GDB only knows partially---that is, symbols defined in files that | |
5404 | GDB has skimmed, but not yet read completely. The description of | |
5405 | @code{symbol-file} describes how GDB reads symbols; both commands | |
5406 | are described under @ref{Files, ,Commands to Specify Files}. | |
5407 | @end table | |
5408 | ||
5409 | @node Altering, GDB Files, Symbols, Top | |
5410 | @chapter Altering Execution | |
5411 | ||
5412 | Once you think you have found an error in your program, you might want to | |
5413 | find out for certain whether correcting the apparent error would lead to | |
5414 | correct results in the rest of the run. You can find the answer by | |
5415 | experiment, using the GDB features for altering execution of the | |
5416 | program. | |
5417 | ||
5418 | For example, you can store new values into variables or memory | |
5419 | locations, give your program a signal, restart it at a different address, | |
5420 | or even return prematurely from a function to its caller. | |
5421 | ||
5422 | @menu | |
5423 | * Assignment:: Assignment to Variables | |
5424 | * Jumping:: Continuing at a Different Address | |
5425 | * Signaling:: Giving your program a Signal | |
5426 | * Returning:: Returning from a Function | |
5427 | * Calling:: Calling your Program's Functions | |
5428 | * Patching:: Patching your Program | |
5429 | @end menu | |
5430 | ||
5431 | @node Assignment, Jumping, Altering, Altering | |
5432 | @section Assignment to Variables | |
5433 | ||
5434 | @cindex assignment | |
5435 | @cindex setting variables | |
5436 | To alter the value of a variable, evaluate an assignment expression. | |
5437 | @xref{Expressions, ,Expressions}. For example, | |
5438 | ||
5439 | @example | |
5440 | print x=4 | |
5441 | @end example | |
5442 | ||
5443 | @noindent | |
5444 | stores the value 4 into the variable @code{x}, and then prints the | |
5445 | value of the assignment expression (which is 4). @xref{Languages, | |
5446 | ,Using GDB with Different Languages}, for more information on | |
5447 | operators in supported languages. | |
5448 | ||
5449 | @kindex set variable | |
5450 | @cindex variables, setting | |
5451 | If you are not interested in seeing the value of the assignment, use the | |
5452 | @code{set} command instead of the @code{print} command. @code{set} is | |
5453 | really the same as @code{print} except that the expression's value is not | |
5454 | printed and is not put in the value history (@pxref{Value History, ,Value History}). The | |
5455 | expression is evaluated only for its effects. | |
5456 | ||
5457 | If the beginning of the argument string of the @code{set} command | |
5458 | appears identical to a @code{set} subcommand, use the @code{set | |
5459 | variable} command instead of just @code{set}. This command is identical | |
5460 | to @code{set} except for its lack of subcommands. For example, a | |
5461 | program might well have a variable @code{width}---which leads to | |
5462 | an error if we try to set a new value with just @samp{set width=13}, as | |
5463 | we might if @code{set width} did not happen to be a GDB command: | |
5464 | ||
5465 | @example | |
5466 | (gdb) whatis width | |
5467 | type = double | |
5468 | (gdb) p width | |
5469 | $4 = 13 | |
5470 | (gdb) set width=47 | |
5471 | Invalid syntax in expression. | |
5472 | @end example | |
5473 | ||
5474 | @noindent | |
5475 | The invalid expression, of course, is @samp{=47}. What we can do in | |
5476 | order to actually set our program's variable @code{width} is | |
5477 | ||
5478 | @example | |
5479 | (gdb) set var width=47 | |
5480 | @end example | |
5481 | ||
5482 | GDB allows more implicit conversions in assignments than C; you can | |
5483 | freely store an integer value into a pointer variable or vice versa, | |
5484 | and any structure can be converted to any other structure that is the | |
5485 | same length or shorter. | |
5486 | @comment FIXME: how do structs align/pad in these conversions? | |
5487 | @comment /[email protected] 18dec1990 | |
5488 | ||
5489 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} | |
5490 | construct to generate a value of specified type at a specified address | |
5491 | (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers | |
5492 | to memory location @code{0x83040} as an integer (which implies a certain size | |
5493 | and representation in memory), and | |
5494 | ||
5495 | @example | |
5496 | set @{int@}0x83040 = 4 | |
5497 | @end example | |
5498 | ||
5499 | @noindent | |
5500 | stores the value 4 into that memory location. | |
5501 | ||
5502 | @node Jumping, Signaling, Assignment, Altering | |
5503 | @section Continuing at a Different Address | |
5504 | ||
5505 | Ordinarily, when you continue your program, you do so at the place where | |
5506 | it stopped, with the @code{continue} command. You can instead continue at | |
5507 | an address of your own choosing, with the following commands: | |
5508 | ||
5509 | @table @code | |
5510 | @item jump @var{linespec} | |
5511 | @kindex jump | |
5512 | Resume execution at line @var{linespec}. Execution will stop | |
5513 | immediately if there is a breakpoint there. @xref{List, ,Printing | |
5514 | Source Lines}, for a description of the different forms of | |
5515 | @var{linespec}. | |
5516 | ||
5517 | The @code{jump} command does not change the current stack frame, or | |
5518 | the stack pointer, or the contents of any memory location or any | |
5519 | register other than the program counter. If line @var{linespec} is in | |
5520 | a different function from the one currently executing, the results may | |
5521 | be bizarre if the two functions expect different patterns of arguments or | |
5522 | of local variables. For this reason, the @code{jump} command requests | |
5523 | confirmation if the specified line is not in the function currently | |
5524 | executing. However, even bizarre results are predictable if you are | |
5525 | well acquainted with the machine-language code of your program. | |
5526 | ||
5527 | @item jump *@var{address} | |
5528 | Resume execution at the instruction at address @var{address}. | |
5529 | @end table | |
5530 | ||
5531 | You can get much the same effect as the @code{jump} command by storing a | |
5532 | new value into the register @code{$pc}. The difference is that this | |
5533 | does not start your program running; it only changes the address where it | |
5534 | @emph{will} run when it is continued. For example, | |
5535 | ||
5536 | @example | |
5537 | set $pc = 0x485 | |
5538 | @end example | |
5539 | ||
5540 | @noindent | |
5541 | causes the next @code{continue} command or stepping command to execute at | |
5542 | address @code{0x485}, rather than at the address where your program stopped. | |
5543 | @xref{Continuing and Stepping, ,Continuing and Stepping}. | |
5544 | ||
5545 | The most common occasion to use the @code{jump} command is to back up, | |
5546 | perhaps with more breakpoints set, over a portion of a program that has | |
5547 | already executed, in order to examine its execution in more detail. | |
5548 | ||
5549 | @node Signaling, Returning, Jumping, Altering | |
5550 | @c @group | |
5551 | @section Giving your program a Signal | |
5552 | ||
5553 | @table @code | |
5554 | @item signal @var{signalnum} | |
5555 | @kindex signal | |
5556 | Resume execution where your program stopped, but give it immediately the | |
5557 | signal number @var{signalnum}. | |
5558 | ||
5559 | Alternatively, if @var{signalnum} is zero, continue execution without | |
5560 | giving a signal. This is useful when your program stopped on account of | |
5561 | a signal and would ordinary see the signal when resumed with the | |
5562 | @code{continue} command; @samp{signal 0} causes it to resume without a | |
5563 | signal. | |
5564 | ||
5565 | @code{signal} does not repeat when you press @key{RET} a second time | |
5566 | after executing the command. | |
5567 | @end table | |
5568 | @c @end group | |
5569 | ||
5570 | @node Returning, Calling, Signaling, Altering | |
5571 | @section Returning from a Function | |
5572 | ||
5573 | @table @code | |
5574 | @item return | |
5575 | @itemx return @var{expression} | |
5576 | @cindex returning from a function | |
5577 | @kindex return | |
5578 | You can cancel execution of a function call with the @code{return} | |
5579 | command. If you give an | |
5580 | @var{expression} argument, its value is used as the function's return | |
5581 | value. | |
5582 | @end table | |
5583 | ||
5584 | When you use @code{return}, GDB discards the selected stack frame | |
5585 | (and all frames within it). You can think of this as making the | |
5586 | discarded frame return prematurely. If you wish to specify a value to | |
5587 | be returned, give that value as the argument to @code{return}. | |
5588 | ||
5589 | This pops the selected stack frame (@pxref{Selection, ,Selecting a | |
5590 | Frame}), and any other frames inside of it, leaving its caller as the | |
5591 | innermost remaining frame. That frame becomes selected. The | |
5592 | specified value is stored in the registers used for returning values | |
5593 | of functions. | |
5594 | ||
5595 | The @code{return} command does not resume execution; it leaves the | |
5596 | program stopped in the state that would exist if the function had just | |
5597 | returned. In contrast, the @code{finish} command (@pxref{Continuing | |
5598 | and Stepping, ,Continuing and Stepping}) resumes execution until the | |
5599 | selected stack frame returns naturally. | |
5600 | ||
5601 | @node Calling, Patching, Returning, Altering | |
5602 | @section Calling your Program's Functions | |
5603 | ||
5604 | @cindex calling functions | |
5605 | @kindex call | |
5606 | @table @code | |
5607 | @item call @var{expr} | |
5608 | Evaluate the expression @var{expr} without displaying @code{void} | |
5609 | returned values. | |
5610 | @end table | |
5611 | ||
5612 | You can use this variant of the @code{print} command if you want to | |
5613 | execute a function from your program, but without cluttering the output | |
5614 | with @code{void} returned values. The result is printed and saved in | |
5615 | the value history, if it is not void. | |
5616 | ||
5617 | @node Patching, , Calling, Altering | |
5618 | @section Patching your Program | |
5619 | @cindex patching binaries | |
5620 | @cindex writing into executables | |
5621 | @cindex writing into corefiles | |
5622 | ||
5623 | By default, GDB opens the file containing your program's executable | |
5624 | code (or the corefile) read-only. This prevents accidental alterations | |
5625 | to machine code; but it also prevents you from intentionally patching | |
5626 | your program's binary. | |
5627 | ||
5628 | If you'd like to be able to patch the binary, you can specify that | |
5629 | explicitly with the @code{set write} command. For example, you might | |
5630 | want to turn on internal debugging flags, or even to make emergency | |
5631 | repairs. | |
5632 | ||
5633 | @table @code | |
5634 | @item set write on | |
5635 | @itemx set write off | |
5636 | @kindex set write | |
5637 | If you specify @samp{set write on}, GDB will open executable and | |
5638 | core files for both reading and writing; if you specify @samp{set write | |
5639 | off} (the default), GDB will open them read-only. | |
5640 | ||
5641 | If you have already loaded a file, you must load it | |
5642 | again (using the @code{exec-file} or @code{core-file} command) after | |
5643 | changing @code{set write}, for your new setting to take effect. | |
5644 | ||
5645 | @item show write | |
5646 | @kindex show write | |
5647 | Display whether executable files and core files will be opened for | |
5648 | writing as well as reading. | |
5649 | @end table | |
5650 | ||
5651 | @node GDB Files, Targets, Altering, Top | |
5652 | @chapter GDB's Files | |
5653 | ||
5654 | GDB needs to know the file name of the program to be debugged, both in | |
5655 | order to read its symbol table and in order to start your program. To | |
5656 | debug a core dump of a previous run, GDB must be told the file name of | |
5657 | the core dump. | |
5658 | ||
5659 | @menu | |
5660 | * Files:: Commands to Specify Files | |
5661 | * Symbol Errors:: Errors Reading Symbol Files | |
5662 | @end menu | |
5663 | ||
5664 | @node Files, Symbol Errors, GDB Files, GDB Files | |
5665 | @section Commands to Specify Files | |
5666 | @cindex core dump file | |
5667 | @cindex symbol table | |
5668 | ||
5669 | The usual way to specify executable and core dump file names is with | |
5670 | the command arguments given when you start GDB, (@pxref{Invocation, | |
5671 | ,Getting In and Out of GDB}. | |
5672 | ||
5673 | Occasionally it is necessary to change to a different file during a | |
5674 | GDB session. Or you may run GDB and forget to specify the files you | |
5675 | want to use. In these situations the GDB commands to specify new files | |
5676 | are useful. | |
5677 | ||
5678 | @table @code | |
5679 | @item file @var{filename} | |
5680 | @cindex executable file | |
5681 | @kindex file | |
5682 | Use @var{filename} as the program to be debugged. It is read for its | |
5683 | symbols and for the contents of pure memory. It is also the program | |
5684 | executed when you use the @code{run} command. If you do not specify a | |
5685 | directory and the file is not found in GDB's working directory, GDB | |
5686 | uses the environment variable @code{PATH} as a list of directories to | |
5687 | search, just as the shell does when looking for a program to run. You | |
5688 | can change the value of this variable, for both GDB and your program, | |
5689 | using the @code{path} command. | |
5690 | ||
5691 | @item file | |
5692 | @code{file} with no argument makes GDB discard any information it | |
5693 | has on both executable file and the symbol table. | |
5694 | ||
5695 | @item exec-file @r{[} @var{filename} @r{]} | |
5696 | @kindex exec-file | |
5697 | Specify that the program to be run (but not the symbol table) is found | |
5698 | in @var{filename}. GDB will search the environment variable @code{PATH} | |
5699 | if necessary to locate your program. Omitting @var{filename} means to | |
5700 | discard information on the executable file. | |
5701 | ||
5702 | @item symbol-file @r{[} @var{filename} @r{]} | |
5703 | @kindex symbol-file | |
5704 | Read symbol table information from file @var{filename}. @code{PATH} is | |
5705 | searched when necessary. Use the @code{file} command to get both symbol | |
5706 | table and program to run from the same file. | |
5707 | ||
5708 | @code{symbol-file} with no argument clears out GDB's information on your | |
5709 | program's symbol table. | |
5710 | ||
5711 | The @code{symbol-file} command causes GDB to forget the contents of its | |
5712 | convenience variables, the value history, and all breakpoints and | |
5713 | auto-display expressions. This is because they may contain pointers to | |
5714 | the internal data recording symbols and data types, which are part of | |
5715 | the old symbol table data being discarded inside GDB. | |
5716 | ||
5717 | @code{symbol-file} will not repeat if you press @key{RET} again after | |
5718 | executing it once. | |
5719 | ||
5720 | On some kinds of object files, the @code{symbol-file} command does not | |
5721 | actually read the symbol table in full right away. Instead, it scans | |
5722 | the symbol table quickly to find which source files and which symbols | |
5723 | are present. The details are read later, one source file at a time, | |
5724 | as they are needed. | |
5725 | ||
5726 | The purpose of this two-stage reading strategy is to make GDB start up | |
5727 | faster. For the most part, it is invisible except for occasional | |
5728 | pauses while the symbol table details for a particular source file are | |
5729 | being read. (The @code{set verbose} command can turn these pauses | |
5730 | into messages if desired. @xref{Messages/Warnings, ,Optional Warnings | |
5731 | and Messages}.) | |
5732 | ||
5733 | When the symbol table is stored in COFF format, @code{symbol-file} does | |
5734 | read the symbol table data in full right away. We have not implemented | |
5735 | the two-stage strategy for COFF yet. | |
5736 | ||
5737 | When GDB is configured for a particular environment, it will | |
5738 | understand debugging information in whatever format is the standard | |
5739 | generated for that environment; you may use either a GNU compiler, or | |
5740 | other compilers that adhere to the local conventions. Best results are | |
5741 | usually obtained from GNU compilers; for example, using @code{gcc} | |
5742 | you can generate debugging information for optimized code. | |
5743 | ||
5744 | @item core-file @r{[} @var{filename} @r{]} | |
5745 | @kindex core | |
5746 | @kindex core-file | |
5747 | Specify the whereabouts of a core dump file to be used as the ``contents | |
5748 | of memory''. Traditionally, core files contain only some parts of the | |
5749 | address space of the process that generated them; GDB can access the | |
5750 | executable file itself for other parts. | |
5751 | ||
5752 | @code{core-file} with no argument specifies that no core file is | |
5753 | to be used. | |
5754 | ||
5755 | Note that the core file is ignored when your program is actually running | |
5756 | under GDB. So, if you have been running your program and you wish to | |
5757 | debug a core file instead, you must kill the subprocess in which the | |
5758 | program is running. To do this, use the @code{kill} command | |
5759 | (@pxref{Kill Process, ,Killing the Child Process}). | |
5760 | ||
5761 | @item load @var{filename} | |
5762 | @kindex load | |
5763 | Depending on what remote debugging facilities are configured into | |
5764 | GDB, the @code{load} command may be available. Where it exists, it | |
5765 | is meant to make @var{filename} (an executable) available for debugging | |
5766 | on the remote system---by downloading, or dynamic linking, for example. | |
5767 | @code{load} also records @var{filename}'s symbol table in GDB, like | |
5768 | the @code{add-symbol-file} command. | |
5769 | ||
5770 | If @code{load} is not available on your GDB, attempting to execute | |
5771 | it gets the error message ``@code{You can't do that when your target is | |
5772 | @dots{}}'' | |
5773 | ||
5774 | On VxWorks, @code{load} will dynamically link @var{filename} on the | |
5775 | current target system as well as adding its symbols in GDB. | |
5776 | ||
5777 | @cindex download to Nindy-960 | |
5778 | With the Nindy interface to an Intel 960 board, @code{load} will | |
5779 | download @var{filename} to the 960 as well as adding its symbols in | |
5780 | GDB. | |
5781 | ||
5782 | ||
5783 | @code{load} will not repeat if you press @key{RET} again after using it. | |
5784 | ||
5785 | @item add-symbol-file @var{filename} @var{address} | |
5786 | @kindex add-symbol-file | |
5787 | @cindex dynamic linking | |
5788 | The @code{add-symbol-file} command reads additional symbol table information | |
5789 | from the file @var{filename}. You would use this command when @var{filename} | |
5790 | has been dynamically loaded (by some other means) into the program that | |
5791 | is running. @var{address} should be the memory address at which the | |
5792 | file has been loaded; GDB cannot figure this out for itself. | |
5793 | ||
5794 | The symbol table of the file @var{filename} is added to the symbol table | |
5795 | originally read with the @code{symbol-file} command. You can use the | |
5796 | @code{add-symbol-file} command any number of times; the new symbol data thus | |
5797 | read keeps adding to the old. To discard all old symbol data instead, | |
5798 | use the @code{symbol-file} command. | |
5799 | ||
5800 | @code{add-symbol-file} will not repeat if you press @key{RET} after using it. | |
5801 | ||
5802 | @item info files | |
5803 | @itemx info target | |
5804 | @kindex info files | |
5805 | @kindex info target | |
5806 | @code{info files} and @code{info target} are synonymous; both print | |
5807 | the current targets (@pxref{Targets, ,Specifying a Debugging Target}), | |
5808 | including the names of the executable and core dump files currently in | |
5809 | use by GDB, and the files from which symbols were loaded. The command | |
5810 | @code{help targets} lists all possible targets rather than current | |
5811 | ones. | |
5812 | ||
5813 | @end table | |
5814 | ||
5815 | All file-specifying commands allow both absolute and relative file names | |
5816 | as arguments. GDB always converts the file name to an absolute path | |
5817 | name and remembers it that way. | |
5818 | ||
5819 | @cindex shared libraries | |
5820 | ||
5821 | GDB supports the SunOS shared library format. GDB automatically | |
5822 | loads symbol definitions from shared libraries when you use the | |
5823 | @code{run} command, or when you examine a core file. (Before you issue | |
5824 | the @code{run} command, GDB will not understand references to a | |
5825 | function in a shared library, however---unless you are debugging a core | |
5826 | file). | |
5827 | @c FIXME: next GDB release should permit some refs to undef | |
5828 | @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib | |
5829 | ||
5830 | @table @code | |
5831 | @item info share | |
5832 | @itemx info sharedlibrary | |
5833 | @kindex info sharedlibrary | |
5834 | @kindex info share | |
5835 | Print the names of the shared libraries which are currently loaded. | |
5836 | ||
5837 | @item sharedlibrary @var{regex} | |
5838 | @itemx share @var{regex} | |
5839 | @kindex sharedlibrary | |
5840 | @kindex share | |
5841 | This is an obsolescent command; you can use it to explicitly | |
5842 | load shared object library symbols for files matching a UNIX regular | |
5843 | expression, but as with files loaded automatically, it will only load | |
5844 | shared libraries required by your program for a core file or after | |
5845 | typing @code{run}. If @var{regex} is omitted all shared libraries | |
5846 | required by your program are loaded. | |
5847 | @end table | |
5848 | ||
5849 | @node Symbol Errors, , Files, GDB Files | |
5850 | @section Errors Reading Symbol Files | |
5851 | ||
5852 | While reading a symbol file, GDB will occasionally encounter problems, | |
5853 | such as symbol types it does not recognize, or known bugs in compiler | |
5854 | output. By default, GDB does not notify you of such problems, since | |
5855 | they are relatively common and primarily of interest to people | |
5856 | debugging compilers. If you are interested in seeing information | |
5857 | about ill-constructed symbol tables, you can either ask GDB to print | |
5858 | only one message about each such type of problem, no matter how many | |
5859 | times the problem occurs; or you can ask GDB to print more messages, | |
5860 | to see how many times the problems occur, with the @code{set | |
5861 | complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and | |
5862 | Messages}). | |
5863 | ||
5864 | The messages currently printed, and their meanings, are: | |
5865 | ||
5866 | @table @code | |
5867 | @item inner block not inside outer block in @var{symbol} | |
5868 | ||
5869 | The symbol information shows where symbol scopes begin and end | |
5870 | (such as at the start of a function or a block of statements). This | |
5871 | error indicates that an inner scope block is not fully contained | |
5872 | in its outer scope blocks. | |
5873 | ||
5874 | GDB circumvents the problem by treating the inner block as if it had | |
5875 | the same scope as the outer block. In the error message, @var{symbol} | |
5876 | may be shown as ``@code{(don't know)}'' if the outer block is not a | |
5877 | function. | |
5878 | ||
5879 | @item block at @var{address} out of order | |
5880 | ||
5881 | The symbol information for symbol scope blocks should occur in | |
5882 | order of increasing addresses. This error indicates that it does not | |
5883 | do so. | |
5884 | ||
5885 | GDB does not circumvent this problem, and will have trouble locating | |
5886 | symbols in the source file whose symbols being read. (You can often | |
5887 | determine what source file is affected by specifying @code{set verbose | |
5888 | on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.) | |
5889 | ||
5890 | @item bad block start address patched | |
5891 | ||
5892 | The symbol information for a symbol scope block has a start address | |
5893 | smaller than the address of the preceding source line. This is known | |
5894 | to occur in the SunOS 4.1.1 (and earlier) C compiler. | |
5895 | ||
5896 | GDB circumvents the problem by treating the symbol scope block as | |
5897 | starting on the previous source line. | |
5898 | ||
5899 | @item bad string table offset in symbol @var{n} | |
5900 | ||
5901 | @cindex foo | |
5902 | Symbol number @var{n} contains a pointer into the string table which is | |
5903 | larger than the size of the string table. | |
5904 | ||
5905 | GDB circumvents the problem by considering the symbol to have the | |
5906 | name @code{foo}, which may cause other problems if many symbols end up | |
5907 | with this name. | |
5908 | ||
5909 | @item unknown symbol type @code{0x@var{nn}} | |
5910 | ||
5911 | The symbol information contains new data types that GDB does not yet | |
5912 | know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood | |
5913 | information, in hexadecimal. | |
5914 | ||
5915 | GDB circumvents the error by ignoring this symbol information. This | |
5916 | will usually allow your program to be debugged, though certain symbols | |
5917 | will not be accessible. If you encounter such a problem and feel like | |
5918 | debugging it, you can debug @code{gdb} with itself, breakpoint on | |
5919 | @code{complain}, then go up to the function @code{read_dbx_symtab} and | |
5920 | examine @code{*bufp} to see the symbol. | |
5921 | ||
5922 | @item stub type has NULL name | |
5923 | GDB could not find the full definition for a struct or class. | |
5924 | ||
5925 | @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{} | |
5926 | ||
5927 | The symbol information for a C++ member function is missing some | |
5928 | information that recent versions of the compiler should have output | |
5929 | for it. | |
5930 | ||
5931 | @item info mismatch between compiler and debugger | |
5932 | ||
5933 | GDB could not parse a type specification output by the compiler. | |
5934 | @end table | |
5935 | ||
5936 | @node Targets, Controlling GDB, GDB Files, Top | |
5937 | @chapter Specifying a Debugging Target | |
5938 | @cindex debugging target | |
5939 | @kindex target | |
5940 | ||
5941 | A @dfn{target} is the execution environment occupied by your program. | |
5942 | Often, GDB runs in the same host environment as your program; in | |
5943 | that case, the debugging target is specified as a side effect when you | |
5944 | use the @code{file} or @code{core} commands. When you need more | |
5945 | flexibility---for example, running GDB on a physically separate | |
5946 | host, or controlling a standalone system over a serial port or a | |
5947 | realtime system over a TCP/IP connection---you can use the @code{target} | |
5948 | command to specify one of the target types configured for GDB | |
5949 | (@pxref{Target Commands, ,Commands for Managing Targets}). | |
5950 | ||
5951 | @menu | |
5952 | * Active Targets:: Active Targets | |
5953 | * Target Commands:: Commands for Managing Targets | |
5954 | * Remote:: Remote Debugging | |
5955 | @end menu | |
5956 | ||
5957 | @node Active Targets, Target Commands, Targets, Targets | |
5958 | @section Active Targets | |
5959 | @cindex stacking targets | |
5960 | @cindex active targets | |
5961 | @cindex multiple targets | |
5962 | ||
5963 | There are three classes of targets: processes, core files, and | |
5964 | executable files. GDB can work concurrently on up to three active | |
5965 | targets, one in each class. This allows you to (for example) start a | |
5966 | process and inspect its activity without abandoning your work on a core | |
5967 | file. | |
5968 | ||
5969 | If, for example, you execute @samp{gdb a.out}, then the executable file | |
5970 | @code{a.out} is the only active target. If you designate a core file as | |
5971 | well---presumably from a prior run that crashed and coredumped---then | |
5972 | GDB has two active targets and will use them in tandem, looking | |
5973 | first in the corefile target, then in the executable file, to satisfy | |
5974 | requests for memory addresses. (Typically, these two classes of target | |
5975 | are complementary, since core files contain only a program's | |
5976 | read-write memory---variables and so on---plus machine status, while | |
5977 | executable files contain only the program text and initialized data.) | |
5978 | ||
5979 | When you type @code{run}, your executable file becomes an active process | |
5980 | target as well. When a process target is active, all GDB commands | |
5981 | requesting memory addresses refer to that target; addresses in an active | |
5982 | core file or executable file target are obscured while the process | |
5983 | target is active. | |
5984 | ||
5985 | Use the @code{core-file} and @code{exec-file} commands to select a | |
5986 | new core file or executable target (@pxref{Files, ,Commands to Specify | |
5987 | Files}). To specify as a target a process that is already running, use | |
5988 | the @code{attach} command (@pxref{Attach, ,Debugging an | |
5989 | Already-Running Process}.). | |
5990 | ||
5991 | @node Target Commands, Remote, Active Targets, Targets | |
5992 | @section Commands for Managing Targets | |
5993 | ||
5994 | @table @code | |
5995 | @item target @var{type} @var{parameters} | |
5996 | Connects the GDB host environment to a target machine or process. A | |
5997 | target is typically a protocol for talking to debugging facilities. You | |
5998 | use the argument @var{type} to specify the type or protocol of the | |
5999 | target machine. | |
6000 | ||
6001 | Further @var{parameters} are interpreted by the target protocol, but | |
6002 | typically include things like device names or host names to connect | |
6003 | with, process numbers, and baud rates. | |
6004 | ||
6005 | The @code{target} command will not repeat if you press @key{RET} again | |
6006 | after executing the command. | |
6007 | ||
6008 | @item help target | |
6009 | @kindex help target | |
6010 | Displays the names of all targets available. To display targets | |
6011 | currently selected, use either @code{info target} or @code{info files} | |
6012 | (@pxref{Files, ,Commands to Specify Files}). | |
6013 | ||
6014 | @item help target @var{name} | |
6015 | Describe a particular target, including any parameters necessary to | |
6016 | select it. | |
6017 | @end table | |
6018 | ||
6019 | Here are some common targets (available, or not, depending on the GDB | |
6020 | configuration): | |
6021 | ||
6022 | @table @code | |
6023 | @item target exec @var{prog} | |
6024 | @kindex target exec | |
6025 | An executable file. @samp{target exec @var{prog}} is the same as | |
6026 | @samp{exec-file @var{prog}}. | |
6027 | ||
6028 | @item target core @var{filename} | |
6029 | @kindex target core | |
6030 | A core dump file. @samp{target core @var{filename}} is the same as | |
6031 | @samp{core-file @var{filename}}. | |
6032 | ||
6033 | @item target remote @var{dev} | |
6034 | @kindex target remote | |
6035 | Remote serial target in GDB-specific protocol. The argument @var{dev} | |
6036 | specifies what serial device to use for the connection (e.g. | |
6037 | @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}. | |
6038 | ||
6039 | @item target amd-eb @var{dev} @var{speed} @var{PROG} | |
6040 | @kindex target amd-eb | |
6041 | @cindex AMD EB29K | |
6042 | Remote PC-resident AMD EB29K board, attached over serial lines. | |
6043 | @var{dev} is the serial device, as for @code{target remote}; | |
6044 | @var{speed} allows you to specify the linespeed; and @var{PROG} is the | |
6045 | name of the program to be debugged, as it appears to DOS on the PC. | |
6046 | @xref{EB29K Remote, ,GDB with a Remote EB29K}. | |
6047 | ||
6048 | @item target nindy @var{devicename} | |
6049 | @kindex target nindy | |
6050 | An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is | |
6051 | the name of the serial device to use for the connection, e.g. | |
6052 | @file{/dev/ttya}. @xref{i960-Nindy Remote, ,GDB with a Remote i960 (Nindy)}. | |
6053 | ||
6054 | @item target vxworks @var{machinename} | |
6055 | @kindex target vxworks | |
6056 | A VxWorks system, attached via TCP/IP. The argument @var{machinename} | |
6057 | is the target system's machine name or IP address. | |
6058 | @xref{VxWorks Remote, ,GDB and VxWorks}. | |
6059 | @end table | |
6060 | ||
6061 | Different targets are available on different configurations of GDB; your | |
6062 | configuration may have more or fewer targets. | |
6063 | ||
6064 | @node Remote, , Target Commands, Targets | |
6065 | @section Remote Debugging | |
6066 | @cindex remote debugging | |
6067 | ||
6068 | If you are trying to debug a program running on a machine that cannot run | |
6069 | GDB in the usual way, it is often useful to use remote debugging. For | |
6070 | example, you might use remote debugging on an operating system kernel, or on | |
6071 | a small system which does not have a general purpose operating system | |
6072 | powerful enough to run a full-featured debugger. | |
6073 | ||
6074 | Some configurations of GDB have special serial or TCP/IP interfaces | |
6075 | to make this work with particular debugging targets. In addition, | |
6076 | GDB comes with a generic serial protocol (specific to GDB, but | |
6077 | not specific to any particular target system) which you can use if you | |
6078 | write the remote stubs---the code that will run on the remote system to | |
6079 | communicate with GDB. | |
6080 | ||
6081 | To use the GDB remote serial protocol, the program to be debugged on | |
6082 | the remote machine needs to contain a debugging stub which talks to | |
6083 | GDB over the serial line. Several working remote stubs are | |
6084 | distributed with GDB; see the @file{README} file in the GDB | |
6085 | distribution for more information. | |
6086 | ||
6087 | For details of this communication protocol, see the comments in the | |
6088 | GDB source file @file{remote.c}. | |
6089 | ||
6090 | To start remote debugging, first run GDB and specify as an executable file | |
6091 | the program that is running in the remote machine. This tells GDB how | |
6092 | to find your program's symbols and the contents of its pure text. Then | |
6093 | establish communication using the @code{target remote} command with a device | |
6094 | name as an argument. For example: | |
6095 | ||
6096 | @example | |
6097 | target remote /dev/ttyb | |
6098 | @end example | |
6099 | ||
6100 | @noindent | |
6101 | if the serial line is connected to the device named @file{/dev/ttyb}. This | |
6102 | will stop the remote machine if it is not already stopped. | |
6103 | ||
6104 | Now you can use all the usual commands to examine and change data and to | |
6105 | step and continue the remote program. | |
6106 | ||
6107 | To resume the remote program and stop debugging it, use the @code{detach} | |
6108 | command. | |
6109 | ||
6110 | Other remote targets may be available in your | |
6111 | configuration of GDB; use @code{help targets} to list them. | |
6112 | ||
6113 | @menu | |
6114 | * i960-Nindy Remote:: GDB with a Remote i960 (Nindy) | |
6115 | * EB29K Remote:: GDB with a Remote EB29K | |
6116 | * VxWorks Remote:: GDB and VxWorks | |
6117 | ||
6118 | @end menu | |
6119 | @node i960-Nindy Remote, EB29K Remote, Remote, Remote | |
6120 | @subsection GDB with a Remote i960 (Nindy) | |
6121 | ||
6122 | @cindex Nindy | |
6123 | @cindex i960 | |
6124 | @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When | |
6125 | GDB is configured to control a remote Intel 960 using Nindy, you can | |
6126 | tell GDB how to connect to the 960 in several ways: | |
6127 | ||
6128 | @itemize @bullet | |
6129 | @item | |
6130 | Through command line options specifying serial port, version of the | |
6131 | Nindy protocol, and communications speed; | |
6132 | ||
6133 | @item | |
6134 | By responding to a prompt on startup; | |
6135 | ||
6136 | @item | |
6137 | By using the @code{target} command at any point during your GDB | |
6138 | session. @xref{Target Commands, ,Commands for Managing Targets}. | |
6139 | ||
6140 | @end itemize | |
6141 | ||
6142 | @menu | |
6143 | * Nindy Startup:: Startup with Nindy | |
6144 | * Nindy Options:: Options for Nindy | |
6145 | * Nindy reset:: Nindy Reset Command | |
6146 | @end menu | |
6147 | ||
6148 | @node Nindy Startup, Nindy Options, i960-Nindy Remote, i960-Nindy Remote | |
6149 | @subsubsection Startup with Nindy | |
6150 | ||
6151 | If you simply start @code{gdb} without using any command-line | |
6152 | options, you are prompted for what serial port to use, @emph{before} you | |
6153 | reach the ordinary GDB prompt: | |
6154 | ||
6155 | @example | |
6156 | Attach /dev/ttyNN -- specify NN, or "quit" to quit: | |
6157 | @end example | |
6158 | ||
6159 | @noindent | |
6160 | Respond to the prompt with whatever suffix (after @samp{/dev/tty}) | |
6161 | identifies the serial port you want to use. You can, if you choose, | |
6162 | simply start up with no Nindy connection by responding to the prompt | |
6163 | with an empty line. If you do this, and later wish to attach to Nindy, | |
6164 | use @code{target} (@pxref{Target Commands, ,Commands for Managing Targets}). | |
6165 | ||
6166 | @node Nindy Options, Nindy reset, Nindy Startup, i960-Nindy Remote | |
6167 | @subsubsection Options for Nindy | |
6168 | ||
6169 | These are the startup options for beginning your GDB session with a | |
6170 | Nindy-960 board attached: | |
6171 | ||
6172 | @table @code | |
6173 | @item -r @var{port} | |
6174 | Specify the serial port name of a serial interface to be used to connect | |
6175 | to the target system. This option is only available when GDB is | |
6176 | configured for the Intel 960 target architecture. You may specify | |
6177 | @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a | |
6178 | device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique | |
6179 | suffix for a specific @code{tty} (e.g. @samp{-r a}). | |
6180 | ||
6181 | @item -O | |
6182 | (An uppercase letter ``O'', not a zero.) Specify that GDB should use | |
6183 | the ``old'' Nindy monitor protocol to connect to the target system. | |
6184 | This option is only available when GDB is configured for the Intel 960 | |
6185 | target architecture. | |
6186 | ||
6187 | @quotation | |
6188 | @emph{Warning:} if you specify @samp{-O}, but are actually trying to | |
6189 | connect to a target system that expects the newer protocol, the connection | |
6190 | will fail, appearing to be a speed mismatch. GDB will repeatedly | |
6191 | attempt to reconnect at several different line speeds. You can abort | |
6192 | this process with an interrupt. | |
6193 | @end quotation | |
6194 | ||
6195 | @item -brk | |
6196 | Specify that GDB should first send a @code{BREAK} signal to the target | |
6197 | system, in an attempt to reset it, before connecting to a Nindy target. | |
6198 | ||
6199 | @quotation | |
6200 | @emph{Warning:} Many target systems do not have the hardware that this | |
6201 | requires; it only works with a few boards. | |
6202 | @end quotation | |
6203 | @end table | |
6204 | ||
6205 | The standard @samp{-b} option controls the line speed used on the serial | |
6206 | port. | |
6207 | ||
6208 | @c @group | |
6209 | @node Nindy reset, , Nindy Options, i960-Nindy Remote | |
6210 | @subsubsection Nindy Reset Command | |
6211 | ||
6212 | @table @code | |
6213 | @item reset | |
6214 | @kindex reset | |
6215 | For a Nindy target, this command sends a ``break'' to the remote target | |
6216 | system; this is only useful if the target has been equipped with a | |
6217 | circuit to perform a hard reset (or some other interesting action) when | |
6218 | a break is detected. | |
6219 | @end table | |
6220 | @c @end group | |
6221 | ||
6222 | @node EB29K Remote, VxWorks Remote, i960-Nindy Remote, Remote | |
6223 | @subsection GDB with a Remote EB29K | |
6224 | ||
6225 | @cindex EB29K board | |
6226 | @cindex running 29K programs | |
6227 | ||
6228 | To use GDB from a Unix system to run programs on AMD's EB29K | |
6229 | board in a PC, you must first connect a serial cable between the PC | |
6230 | and a serial port on the Unix system. In the following, we assume | |
6231 | you've hooked the cable between the PC's @file{COM1} port and | |
6232 | @file{/dev/ttya} on the Unix system. | |
6233 | ||
6234 | @menu | |
6235 | * Comms (EB29K):: Communications Setup | |
6236 | * gdb-EB29K:: EB29K cross-debugging | |
6237 | * Remote Log:: Remote Log | |
6238 | @end menu | |
6239 | ||
6240 | @node Comms (EB29K), gdb-EB29K, EB29K Remote, EB29K Remote | |
6241 | @subsubsection Communications Setup | |
6242 | ||
6243 | The next step is to set up the PC's port, by doing something like the | |
6244 | following in DOS on the PC: | |
6245 | ||
6246 | @example | |
6247 | C:\> MODE com1:9600,n,8,1,none | |
6248 | @end example | |
6249 | ||
6250 | @noindent | |
6251 | This example---run on an MS DOS 4.0 system---sets the PC port to 9600 | |
6252 | bps, no parity, eight data bits, one stop bit, and no ``retry'' action; | |
6253 | you must match the communications parameters when establishing the Unix | |
6254 | end of the connection as well. | |
6255 | @c FIXME: Who knows what this "no retry action" crud from the DOS manual may | |
6256 | @c mean? It's optional; leave it out? [email protected], 25feb91 | |
6257 | ||
6258 | To give control of the PC to the Unix side of the serial line, type | |
6259 | the following at the DOS console: | |
6260 | ||
6261 | @example | |
6262 | C:\> CTTY com1 | |
6263 | @end example | |
6264 | ||
6265 | @noindent | |
6266 | (Later, if you wish to return control to the DOS console, you can use | |
6267 | the command @code{CTTY con}---but you must send it over the device that | |
6268 | had control, in our example over the @file{COM1} serial line). | |
6269 | ||
6270 | From the Unix host, use a communications program such as @code{tip} or | |
6271 | @code{cu} to communicate with the PC; for example, | |
6272 | ||
6273 | @example | |
6274 | cu -s 9600 -l /dev/ttya | |
6275 | @end example | |
6276 | ||
6277 | @noindent | |
6278 | The @code{cu} options shown specify, respectively, the linespeed and the | |
6279 | serial port to use. If you use @code{tip} instead, your command line | |
6280 | may look something like the following: | |
6281 | ||
6282 | @example | |
6283 | tip -9600 /dev/ttya | |
6284 | @end example | |
6285 | ||
6286 | @noindent | |
6287 | Your system may define a different name where our example uses | |
6288 | @file{/dev/ttya} as the argument to @code{tip}. The communications | |
6289 | parameters, including which port to use, are associated with the | |
6290 | @code{tip} argument in the ``remote'' descriptions file---normally the | |
6291 | system table @file{/etc/remote}. | |
6292 | @c FIXME: What if anything needs doing to match the "n,8,1,none" part of | |
6293 | @c the DOS side's comms setup? cu can support -o (odd | |
6294 | @c parity), -e (even parity)---apparently no settings for no parity or | |
6295 | @c for character size. Taken from stty maybe...? John points out tip | |
6296 | @c can set these as internal variables, eg ~s parity=none; man stty | |
6297 | @c suggests that it *might* work to stty these options with stdin or | |
6298 | @c stdout redirected... [email protected], 25feb91 | |
6299 | ||
6300 | @kindex EBMON | |
6301 | Using the @code{tip} or @code{cu} connection, change the DOS working | |
6302 | directory to the directory containing a copy of your 29K program, then | |
6303 | start the PC program @code{EBMON} (an EB29K control program supplied | |
6304 | with your board by AMD). You should see an initial display from | |
6305 | @code{EBMON} similar to the one that follows, ending with the | |
6306 | @code{EBMON} prompt @samp{#}--- | |
6307 | ||
6308 | @example | |
6309 | C:\> G: | |
6310 | ||
6311 | G:\> CD \usr\joe\work29k | |
6312 | ||
6313 | G:\USR\JOE\WORK29K> EBMON | |
6314 | Am29000 PC Coprocessor Board Monitor, version 3.0-18 | |
6315 | Copyright 1990 Advanced Micro Devices, Inc. | |
6316 | Written by Gibbons and Associates, Inc. | |
6317 | ||
6318 | Enter '?' or 'H' for help | |
6319 | ||
6320 | PC Coprocessor Type = EB29K | |
6321 | I/O Base = 0x208 | |
6322 | Memory Base = 0xd0000 | |
6323 | ||
6324 | Data Memory Size = 2048KB | |
6325 | Available I-RAM Range = 0x8000 to 0x1fffff | |
6326 | Available D-RAM Range = 0x80002000 to 0x801fffff | |
6327 | ||
6328 | PageSize = 0x400 | |
6329 | Register Stack Size = 0x800 | |
6330 | Memory Stack Size = 0x1800 | |
6331 | ||
6332 | CPU PRL = 0x3 | |
6333 | Am29027 Available = No | |
6334 | Byte Write Available = Yes | |
6335 | ||
6336 | # ~. | |
6337 | @end example | |
6338 | ||
6339 | Then exit the @code{cu} or @code{tip} program (done in the example by | |
6340 | typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} will keep | |
6341 | running, ready for GDB to take over. | |
6342 | ||
6343 | For this example, we've assumed what is probably the most convenient | |
6344 | way to make sure the same 29K program is on both the PC and the Unix | |
6345 | system: a PC/NFS connection that establishes ``drive @code{G:}'' on the | |
6346 | PC as a file system on the Unix host. If you do not have PC/NFS or | |
6347 | something similar connecting the two systems, you must arrange some | |
6348 | other way---perhaps floppy-disk transfer---of getting the 29K program | |
6349 | from the Unix system to the PC; GDB will @emph{not} download it over the | |
6350 | serial line. | |
6351 | ||
6352 | @node gdb-EB29K, Remote Log, Comms (EB29K), EB29K Remote | |
6353 | @subsubsection EB29K cross-debugging | |
6354 | ||
6355 | Finally, @code{cd} to the directory containing an image of your 29K | |
6356 | program on the Unix system, and start GDB---specifying as argument the | |
6357 | name of your 29K program: | |
6358 | ||
6359 | @example | |
6360 | cd /usr/joe/work29k | |
6361 | gdb myfoo | |
6362 | @end example | |
6363 | ||
6364 | Now you can use the @code{target} command: | |
6365 | ||
6366 | @example | |
6367 | target amd-eb /dev/ttya 9600 MYFOO | |
6368 | @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to | |
6369 | @c emphasize that this is the name as seen by DOS (since I think DOS is | |
6370 | @c single-minded about case of letters). [email protected], 25feb91 | |
6371 | @end example | |
6372 | ||
6373 | @noindent | |
6374 | In this example, we've assumed your program is in a file called | |
6375 | @file{myfoo}. Note that the filename given as the last argument to | |
6376 | @code{target amd-eb} should be the name of the program as it appears to DOS. | |
6377 | In our example this is simply @code{MYFOO}, but in general it can include | |
6378 | a DOS path, and depending on your transfer mechanism may not resemble | |
6379 | the name on the Unix side. | |
6380 | ||
6381 | At this point, you can set any breakpoints you wish; when you are ready | |
6382 | to see your program run on the 29K board, use the GDB command | |
6383 | @code{run}. | |
6384 | ||
6385 | To stop debugging the remote program, use the GDB @code{detach} | |
6386 | command. | |
6387 | ||
6388 | To return control of the PC to its console, use @code{tip} or @code{cu} | |
6389 | once again, after your GDB session has concluded, to attach to | |
6390 | @code{EBMON}. You can then type the command @code{q} to shut down | |
6391 | @code{EBMON}, returning control to the DOS command-line interpreter. | |
6392 | Type @code{CTTY con} to return command input to the main DOS console, | |
6393 | and type @kbd{~.} to leave @code{tip} or @code{cu}. | |
6394 | ||
6395 | @node Remote Log, , gdb-EB29K, EB29K Remote | |
6396 | @subsubsection Remote Log | |
6397 | @kindex eb.log | |
6398 | @cindex log file for EB29K | |
6399 | ||
6400 | The @code{target amd-eb} command creates a file @file{eb.log} in the | |
6401 | current working directory, to help debug problems with the connection. | |
6402 | @file{eb.log} records all the output from @code{EBMON}, including echoes | |
6403 | of the commands sent to it. Running @samp{tail -f} on this file in | |
6404 | another window often helps to understand trouble with @code{EBMON}, or | |
6405 | unexpected events on the PC side of the connection. | |
6406 | ||
6407 | @node VxWorks Remote, , EB29K Remote, Remote | |
6408 | @subsection GDB and VxWorks | |
6409 | @cindex VxWorks | |
6410 | ||
6411 | GDB enables developers to spawn and debug tasks running on networked | |
6412 | VxWorks targets from a Unix host. Already-running tasks spawned from | |
6413 | the VxWorks shell can also be debugged. GDB uses code that runs on | |
6414 | both the UNIX host and on the VxWorks target. The program | |
6415 | @code{gdb} is installed and executed on the UNIX host. | |
6416 | ||
6417 | The following information on connecting to VxWorks was current when | |
6418 | this manual was produced; newer releases of VxWorks may use revised | |
6419 | procedures. | |
6420 | ||
6421 | The remote debugging interface (RDB) routines are installed and executed | |
6422 | on the VxWorks target. These routines are included in the VxWorks library | |
6423 | @file{rdb.a} and are incorporated into the system image when source-level | |
6424 | debugging is enabled in the VxWorks configuration. | |
6425 | ||
6426 | @kindex INCLUDE_RDB | |
6427 | If you wish, you can define @code{INCLUDE_RDB} in the VxWorks | |
6428 | configuration file @file{configAll.h} to include the RDB interface | |
6429 | routines and spawn the source debugging task @code{tRdbTask} when | |
6430 | VxWorks is booted. For more information on configuring and remaking | |
6431 | VxWorks, see the manufacturer's manual. | |
6432 | ||
6433 | Once you have included the RDB interface in your VxWorks system image | |
6434 | and set your Unix execution search path to find GDB, you are ready | |
6435 | to run GDB. From your UNIX host, type: | |
6436 | ||
6437 | @smallexample | |
6438 | % gdb | |
6439 | @end smallexample | |
6440 | ||
6441 | GDB will come up showing the prompt: | |
6442 | ||
6443 | @smallexample | |
6444 | (gdb) | |
6445 | @end smallexample | |
6446 | ||
6447 | @menu | |
6448 | * VxWorks connection:: Connecting to VxWorks | |
6449 | * VxWorks download:: VxWorks Download | |
6450 | * VxWorks attach:: Running Tasks | |
6451 | @end menu | |
6452 | ||
6453 | @node VxWorks connection, VxWorks download, VxWorks Remote, VxWorks Remote | |
6454 | @subsubsection Connecting to VxWorks | |
6455 | ||
6456 | The GDB command @code{target} lets you connect to a VxWorks target on the | |
6457 | network. To connect to a target whose host name is ``@code{tt}'', type: | |
6458 | ||
6459 | @smallexample | |
6460 | (gdb) target vxworks tt | |
6461 | @end smallexample | |
6462 | ||
6463 | GDB will display a message similar to the following: | |
6464 | ||
6465 | @smallexample | |
6466 | Attaching remote machine across net... Success! | |
6467 | @end smallexample | |
6468 | ||
6469 | GDB will then attempt to read the symbol tables of any object modules | |
6470 | loaded into the VxWorks target since it was last booted. GDB locates | |
6471 | these files by searching the directories listed in the command search | |
6472 | path (@pxref{Environment, ,Your Program's Environment}); if it fails | |
6473 | to find an object file, it will display a message such as: | |
6474 | ||
6475 | @smallexample | |
6476 | prog.o: No such file or directory. | |
6477 | @end smallexample | |
6478 | ||
6479 | This will cause the @code{target} command to abort. When this happens, | |
6480 | you should add the appropriate directory to the search path, with the | |
6481 | GDB command @code{path}, and execute the @code{target} command | |
6482 | again. | |
6483 | ||
6484 | @node VxWorks download, VxWorks attach, VxWorks connection, VxWorks Remote | |
6485 | @subsubsection VxWorks Download | |
6486 | ||
6487 | @cindex download to VxWorks | |
6488 | If you have connected to the VxWorks target and you want to debug an | |
6489 | object that has not yet been loaded, you can use the GDB @code{load} | |
6490 | command to download a file from UNIX to VxWorks incrementally. The | |
6491 | object file given as an argument to the @code{load} command is actually | |
6492 | opened twice: first by the VxWorks target in order to download the code, | |
6493 | then by GDB in order to read the symbol table. This can lead to | |
6494 | problems if the current working directories on the two systems differ. | |
6495 | It is simplest to set the working directory on both systems to the | |
6496 | directory in which the object file resides, and then to reference the | |
6497 | file by its name, without any path. Thus, to load a program | |
6498 | @file{prog.o}, residing in @file{wherever/vw/demo/rdb}, on VxWorks type: | |
6499 | ||
6500 | @smallexample | |
6501 | -> cd "wherever/vw/demo/rdb" | |
6502 | @end smallexample | |
6503 | ||
6504 | On GDB type: | |
6505 | ||
6506 | @smallexample | |
6507 | (gdb) cd wherever/vw/demo/rdb | |
6508 | (gdb) load prog.o | |
6509 | @end smallexample | |
6510 | ||
6511 | GDB will display a response similar to the following: | |
6512 | ||
6513 | @smallexample | |
6514 | Reading symbol data from wherever/vw/demo/rdb/prog.o... done. | |
6515 | @end smallexample | |
6516 | ||
6517 | You can also use the @code{load} command to reload an object module | |
6518 | after editing and recompiling the corresponding source file. Note that | |
6519 | this will cause GDB to delete all currently-defined breakpoints, | |
6520 | auto-displays, and convenience variables, and to clear the value | |
6521 | history. (This is necessary in order to preserve the integrity of | |
6522 | debugger data structures that reference the target system's symbol | |
6523 | table.) | |
6524 | ||
6525 | @node VxWorks attach, , VxWorks download, VxWorks Remote | |
6526 | @subsubsection Running Tasks | |
6527 | ||
6528 | @cindex running VxWorks tasks | |
6529 | You can also attach to an existing task using the @code{attach} command as | |
6530 | follows: | |
6531 | ||
6532 | @smallexample | |
6533 | (gdb) attach @var{task} | |
6534 | @end smallexample | |
6535 | ||
6536 | @noindent | |
6537 | where @var{task} is the VxWorks hexadecimal task ID. The task can be running | |
6538 | or suspended when you attach to it. If running, it will be suspended at | |
6539 | the time of attachment. | |
6540 | ||
6541 | ||
6542 | @node Controlling GDB, Sequences, Targets, Top | |
6543 | @chapter Controlling GDB | |
6544 | ||
6545 | You can alter many aspects of GDB's interaction with you by using | |
6546 | the @code{set} command. For commands controlling how GDB displays | |
6547 | data, @pxref{Print Settings, ,Print Settings}; other settings are described here. | |
6548 | ||
6549 | @menu | |
6550 | * Prompt:: Prompt | |
6551 | * Editing:: Command Editing | |
6552 | * History:: Command History | |
6553 | * Screen Size:: Screen Size | |
6554 | * Numbers:: Numbers | |
6555 | * Messages/Warnings:: Optional Warnings and Messages | |
6556 | @end menu | |
6557 | ||
6558 | @node Prompt, Editing, Controlling GDB, Controlling GDB | |
6559 | @section Prompt | |
6560 | @cindex prompt | |
6561 | ||
6562 | GDB indicates its readiness to read a command by printing a string | |
6563 | called the @dfn{prompt}. This string is normally @samp{(gdb)}. You | |
6564 | can change the prompt string with the @code{set prompt} command. For | |
6565 | instance, when debugging GDB with GDB, it is useful to change | |
6566 | the prompt in one of the GDBs so that you can always tell which | |
6567 | one you are talking to. | |
6568 | ||
6569 | @table @code | |
6570 | @item set prompt @var{newprompt} | |
6571 | @kindex set prompt | |
6572 | Directs GDB to use @var{newprompt} as its prompt string henceforth. | |
6573 | @kindex show prompt | |
6574 | @item show prompt | |
6575 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} | |
6576 | @end table | |
6577 | ||
6578 | @node Editing, History, Prompt, Controlling GDB | |
6579 | @section Command Editing | |
6580 | @cindex readline | |
6581 | @cindex command line editing | |
6582 | ||
6583 | GDB reads its input commands via the @dfn{readline} interface. This | |
6584 | GNU library provides consistent behavior for programs which provide a | |
6585 | command line interface to the user. Advantages are @code{emacs}-style | |
6586 | or @code{vi}-style inline editing of commands, @code{csh}-like history | |
6587 | substitution, and a storage and recall of command history across | |
6588 | debugging sessions. | |
6589 | ||
6590 | You may control the behavior of command line editing in GDB with the | |
6591 | command @code{set}. | |
6592 | ||
6593 | @table @code | |
6594 | @kindex set editing | |
6595 | @cindex editing | |
6596 | @item set editing | |
6597 | @itemx set editing on | |
6598 | Enable command line editing (enabled by default). | |
6599 | ||
6600 | @item set editing off | |
6601 | Disable command line editing. | |
6602 | ||
6603 | @kindex show editing | |
6604 | @item show editing | |
6605 | Show whether command line editing is enabled. | |
6606 | @end table | |
6607 | ||
6608 | @node History, Screen Size, Editing, Controlling GDB | |
6609 | @section Command History | |
6610 | ||
6611 | @table @code | |
6612 | @cindex history substitution | |
6613 | @cindex history file | |
6614 | @kindex set history filename | |
6615 | @item set history filename @var{fname} | |
6616 | Set the name of the GDB command history file to @var{fname}. This is | |
6617 | the file from which GDB will read an initial command history | |
6618 | list or to which it will write this list when it exits. This list is | |
6619 | accessed through history expansion or through the history | |
6620 | command editing characters listed below. This file defaults to the | |
6621 | value of the environment variable @code{GDBHISTFILE}, or to | |
6622 | @file{./.gdb_history} if this variable is not set. | |
6623 | ||
6624 | @cindex history save | |
6625 | @kindex set history save | |
6626 | @item set history save | |
6627 | @itemx set history save on | |
6628 | Record command history in a file, whose name may be specified with the | |
6629 | @code{set history filename} command. By default, this option is disabled. | |
6630 | ||
6631 | @item set history save off | |
6632 | Stop recording command history in a file. | |
6633 | ||
6634 | @cindex history size | |
6635 | @kindex set history size | |
6636 | @item set history size @var{size} | |
6637 | Set the number of commands which GDB will keep in its history list. | |
6638 | This defaults to the value of the environment variable | |
6639 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6640 | @end table | |
6641 | ||
6642 | @cindex history expansion | |
6643 | History expansion assigns special meaning to the character @kbd{!}. | |
6644 | @iftex | |
6645 | @xref{Event Designators}. | |
6646 | @end iftex | |
6647 | Since @kbd{!} is also the logical not operator in C, history expansion | |
6648 | is off by default. If you decide to enable history expansion with the | |
6649 | @code{set history expansion on} command, you may sometimes need to | |
6650 | follow @kbd{!} (when it is used as logical not, in an expression) with | |
6651 | a space or a tab to prevent it from being expanded. The readline | |
6652 | history facilities will not attempt substitution on the strings | |
6653 | @kbd{!=} and @kbd{!(}, even when history expansion is enabled. | |
6654 | ||
6655 | The commands to control history expansion are: | |
6656 | ||
6657 | @table @code | |
6658 | ||
6659 | @kindex set history expansion | |
6660 | @item set history expansion on | |
6661 | @itemx set history expansion | |
6662 | Enable history expansion. History expansion is off by default. | |
6663 | ||
6664 | @item set history expansion off | |
6665 | Disable history expansion. | |
6666 | ||
6667 | The readline code comes with more complete documentation of | |
6668 | editing and history expansion features. Users unfamiliar with @code{emacs} | |
6669 | or @code{vi} may wish to read it. | |
6670 | @iftex | |
6671 | @xref{Command Line Editing}. | |
6672 | @end iftex | |
6673 | ||
6674 | @c @group | |
6675 | @kindex show history | |
6676 | @item show history | |
6677 | @itemx show history filename | |
6678 | @itemx show history save | |
6679 | @itemx show history size | |
6680 | @itemx show history expansion | |
6681 | These commands display the state of the GDB history parameters. | |
6682 | @code{show history} by itself displays all four states. | |
6683 | @c @end group | |
6684 | @end table | |
6685 | ||
6686 | @table @code | |
6687 | @kindex show commands | |
6688 | @item show commands | |
6689 | Display the last ten commands in the command history. | |
6690 | ||
6691 | @item show commands @var{n} | |
6692 | Print ten commands centered on command number @var{n}. | |
6693 | ||
6694 | @item show commands + | |
6695 | Print ten commands just after the commands last printed. | |
6696 | @end table | |
6697 | ||
6698 | @node Screen Size, Numbers, History, Controlling GDB | |
6699 | @section Screen Size | |
6700 | @cindex size of screen | |
6701 | @cindex pauses in output | |
6702 | ||
6703 | Certain commands to GDB may produce large amounts of information | |
6704 | output to the screen. To help you read all of it, GDB pauses and | |
6705 | asks you for input at the end of each page of output. Type @key{RET} | |
6706 | when you want to continue the output. GDB also uses the screen | |
6707 | width setting to determine when to wrap lines of output. Depending on | |
6708 | what is being printed, it tries to break the line at a readable place, | |
6709 | rather than simply letting it overflow onto the following line. | |
6710 | ||
6711 | Normally GDB knows the size of the screen from the termcap data base | |
6712 | together with the value of the @code{TERM} environment variable and the | |
6713 | @code{stty rows} and @code{stty cols} settings. If this is not correct, | |
6714 | you can override it with the @code{set height} and @code{set | |
6715 | width} commands: | |
6716 | ||
6717 | @table @code | |
6718 | @item set height @var{lpp} | |
6719 | @itemx show height | |
6720 | @itemx set width @var{cpl} | |
6721 | @itemx show width | |
6722 | @kindex set height | |
6723 | @kindex set width | |
6724 | @kindex show width | |
6725 | @kindex show height | |
6726 | These @code{set} commands specify a screen height of @var{lpp} lines and | |
6727 | a screen width of @var{cpl} characters. The associated @code{show} | |
6728 | commands display the current settings. | |
6729 | ||
6730 | If you specify a height of zero lines, GDB will not pause during output | |
6731 | no matter how long the output is. This is useful if output is to a file | |
6732 | or to an editor buffer. | |
6733 | @end table | |
6734 | ||
6735 | @node Numbers, Messages/Warnings, Screen Size, Controlling GDB | |
6736 | @section Numbers | |
6737 | @cindex number representation | |
6738 | @cindex entering numbers | |
6739 | ||
6740 | You can always enter numbers in octal, decimal, or hexadecimal in GDB by | |
6741 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
6742 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
6743 | Numbers that begin with none of these are, by default, entered in base | |
6744 | 10; likewise, the default display for numbers---when no particular | |
6745 | format is specified---is base 10. You can change the default base for | |
6746 | both input and output with the @code{set radix} command. | |
6747 | ||
6748 | @table @code | |
6749 | @kindex set radix | |
6750 | @item set radix @var{base} | |
6751 | Set the default base for numeric input and display. Supported choices | |
6752 | for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be | |
6753 | specified either unambiguously or using the current default radix; for | |
6754 | example, any of | |
6755 | ||
6756 | @example | |
6757 | set radix 1010 | |
6758 | set radix 012 | |
6759 | set radix 10. | |
6760 | set radix 0xa | |
6761 | @end example | |
6762 | ||
6763 | @noindent | |
6764 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
6765 | will leave the radix unchanged no matter what it was. | |
6766 | ||
6767 | @kindex show radix | |
6768 | @item show radix | |
6769 | Display the current default base for numeric input and display. | |
6770 | @end table | |
6771 | ||
6772 | @node Messages/Warnings, , Numbers, Controlling GDB | |
6773 | @section Optional Warnings and Messages | |
6774 | ||
6775 | By default, GDB is silent about its inner workings. If you are running | |
6776 | on a slow machine, you may want to use the @code{set verbose} command. | |
6777 | It will make GDB tell you when it does a lengthy internal operation, so | |
6778 | you will not think it has crashed. | |
6779 | ||
6780 | Currently, the messages controlled by @code{set verbose} are those | |
6781 | which announce that the symbol table for a source file is being read | |
6782 | (@pxref{Files, ,Commands to Specify Files}, in the description of the | |
6783 | command @code{symbol-file}). | |
6784 | @c The following is the right way to do it, but emacs 18.55 does not support | |
6785 | @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo | |
6786 | @c is released. | |
6787 | @ignore | |
6788 | see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}). | |
6789 | @end ignore | |
6790 | ||
6791 | @table @code | |
6792 | @kindex set verbose | |
6793 | @item set verbose on | |
6794 | Enables GDB's output of certain informational messages. | |
6795 | ||
6796 | @item set verbose off | |
6797 | Disables GDB's output of certain informational messages. | |
6798 | ||
6799 | @kindex show verbose | |
6800 | @item show verbose | |
6801 | Displays whether @code{set verbose} is on or off. | |
6802 | @end table | |
6803 | ||
6804 | By default, if GDB encounters bugs in the symbol table of an object | |
6805 | file, it is silent; but if you are debugging a compiler, you may find | |
6806 | this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}). | |
6807 | ||
6808 | @table @code | |
6809 | @kindex set complaints | |
6810 | @item set complaints @var{limit} | |
6811 | Permits GDB to output @var{limit} complaints about each type of unusual | |
6812 | symbols before becoming silent about the problem. Set @var{limit} to | |
6813 | zero to suppress all complaints; set it to a large number to prevent | |
6814 | complaints from being suppressed. | |
6815 | ||
6816 | @kindex show complaints | |
6817 | @item show complaints | |
6818 | Displays how many symbol complaints GDB is permitted to produce. | |
6819 | @end table | |
6820 | ||
6821 | By default, GDB is cautious, and asks what sometimes seem to be a | |
6822 | lot of stupid questions to confirm certain commands. For example, if | |
6823 | you try to run a program which is already running: | |
6824 | ||
6825 | @example | |
6826 | (gdb) run | |
6827 | The program being debugged has been started already. | |
6828 | Start it from the beginning? (y or n) | |
6829 | @end example | |
6830 | ||
6831 | If you are willing to unflinchingly face the consequences of your own | |
6832 | commands, you can disable this ``feature'': | |
6833 | ||
6834 | @table @code | |
6835 | @kindex set confirm | |
6836 | @cindex flinching | |
6837 | @cindex confirmation | |
6838 | @cindex stupid questions | |
6839 | @item set confirm off | |
6840 | Disables confirmation requests. | |
6841 | ||
6842 | @item set confirm on | |
6843 | Enables confirmation requests (the default). | |
6844 | ||
6845 | @item show confirm | |
6846 | @kindex show confirm | |
6847 | Displays state of confirmation requests. | |
6848 | @end table | |
6849 | ||
6850 | @c FIXME this does not really belong here. But where *does* it belong? | |
6851 | @cindex reloading symbols | |
6852 | Some systems allow individual object files that make up your program to | |
6853 | be replaced without stopping and restarting your program. | |
6854 | For example, in VxWorks you can simply recompile a defective object file | |
6855 | and keep on running. | |
6856 | If you are running on one of these systems, you can allow GDB to | |
6857 | reload the symbols for automatically relinked modules: | |
6858 | ||
6859 | @table @code | |
6860 | @kindex set symbol-reloading | |
6861 | @item set symbol-reloading on | |
6862 | Replace symbol definitions for the corresponding source file when an | |
6863 | object file with a particular name is seen again. | |
6864 | ||
6865 | @item set symbol-reloading off | |
6866 | Do not replace symbol definitions when re-encountering object files of | |
6867 | the same name. This is the default state; if you are not running on a | |
6868 | system that permits automatically relinking modules, you should leave | |
6869 | @code{symbol-reloading} off, since otherwise GDB may discard symbols | |
6870 | when linking large programs, that may contain several modules (from | |
6871 | different directories or libraries) with the same name. | |
6872 | ||
6873 | @item show symbol-reloading | |
6874 | Show the current @code{on} or @code{off} setting. | |
6875 | @end table | |
6876 | ||
6877 | @node Sequences, Emacs, Controlling GDB, Top | |
6878 | @chapter Canned Sequences of Commands | |
6879 | ||
6880 | Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint | |
6881 | Command Lists}), GDB provides two ways to store sequences of commands | |
6882 | for execution as a unit: user-defined commands and command files. | |
6883 | ||
6884 | @menu | |
6885 | * Define:: User-Defined Commands | |
6886 | * Command Files:: Command Files | |
6887 | * Output:: Commands for Controlled Output | |
6888 | @end menu | |
6889 | ||
6890 | @node Define, Command Files, Sequences, Sequences | |
6891 | @section User-Defined Commands | |
6892 | ||
6893 | @cindex user-defined command | |
6894 | A @dfn{user-defined command} is a sequence of GDB commands to which you | |
6895 | assign a new name as a command. This is done with the @code{define} | |
6896 | command. | |
6897 | ||
6898 | @table @code | |
6899 | @item define @var{commandname} | |
6900 | @kindex define | |
6901 | Define a command named @var{commandname}. If there is already a command | |
6902 | by that name, you are asked to confirm that you want to redefine it. | |
6903 | ||
6904 | The definition of the command is made up of other GDB command lines, | |
6905 | which are given following the @code{define} command. The end of these | |
6906 | commands is marked by a line containing @code{end}. | |
6907 | ||
6908 | @item document @var{commandname} | |
6909 | @kindex document | |
6910 | Give documentation to the user-defined command @var{commandname}. The | |
6911 | command @var{commandname} must already be defined. This command reads | |
6912 | lines of documentation just as @code{define} reads the lines of the | |
6913 | command definition, ending with @code{end}. After the @code{document} | |
6914 | command is finished, @code{help} on command @var{commandname} will print | |
6915 | the documentation you have specified. | |
6916 | ||
6917 | You may use the @code{document} command again to change the | |
6918 | documentation of a command. Redefining the command with @code{define} | |
6919 | does not change the documentation. | |
6920 | ||
6921 | @item help user-defined | |
6922 | @kindex help user-defined | |
6923 | List all user-defined commands, with the first line of the documentation | |
6924 | (if any) for each. | |
6925 | ||
6926 | @item info user | |
6927 | @itemx info user @var{commandname} | |
6928 | @kindex info user | |
6929 | Display the GDB commands used to define @var{commandname} (but not its | |
6930 | documentation). If no @var{commandname} is given, display the | |
6931 | definitions for all user-defined commands. | |
6932 | @end table | |
6933 | ||
6934 | User-defined commands do not take arguments. When they are executed, the | |
6935 | commands of the definition are not printed. An error in any command | |
6936 | stops execution of the user-defined command. | |
6937 | ||
6938 | Commands that would ask for confirmation if used interactively proceed | |
6939 | without asking when used inside a user-defined command. Many GDB commands | |
6940 | that normally print messages to say what they are doing omit the messages | |
6941 | when used in a user-defined command. | |
6942 | ||
6943 | @node Command Files, Output, Define, Sequences | |
6944 | @section Command Files | |
6945 | ||
6946 | @cindex command files | |
6947 | A command file for GDB is a file of lines that are GDB commands. Comments | |
6948 | (lines starting with @kbd{#}) may also be included. An empty line in a | |
6949 | command file does nothing; it does not mean to repeat the last command, as | |
6950 | it would from the terminal. | |
6951 | ||
6952 | @cindex init file | |
6953 | @cindex @file{.gdbinit} | |
6954 | When you start GDB, it automatically executes commands from its | |
6955 | @dfn{init files}. These are files named @file{.gdbinit}. GDB reads | |
6956 | the init file (if any) in your home directory and then the init file | |
6957 | (if any) in the current working directory. (The init files are not | |
6958 | executed if you use the @samp{-nx} option; @pxref{Mode Options, | |
6959 | ,Choosing Modes}.) You can also request the execution of a command | |
6960 | file with the @code{source} command: | |
6961 | ||
6962 | @table @code | |
6963 | @item source @var{filename} | |
6964 | @kindex source | |
6965 | Execute the command file @var{filename}. | |
6966 | @end table | |
6967 | ||
6968 | The lines in a command file are executed sequentially. They are not | |
6969 | printed as they are executed. An error in any command terminates execution | |
6970 | of the command file. | |
6971 | ||
6972 | Commands that would ask for confirmation if used interactively proceed | |
6973 | without asking when used in a command file. Many GDB commands that | |
6974 | normally print messages to say what they are doing omit the messages | |
6975 | when called from command files. | |
6976 | ||
6977 | @node Output, , Command Files, Sequences | |
6978 | @section Commands for Controlled Output | |
6979 | ||
6980 | During the execution of a command file or a user-defined command, normal | |
6981 | GDB output is suppressed; the only output that appears is what is | |
6982 | explicitly printed by the commands in the definition. This section | |
6983 | describes three commands useful for generating exactly the output you | |
6984 | want. | |
6985 | ||
6986 | @table @code | |
6987 | @item echo @var{text} | |
6988 | @kindex echo | |
6989 | @c I do not consider backslash-space a standard C escape sequence | |
6990 | @c because it is not in ANSI. | |
6991 | Print @var{text}. Nonprinting characters can be included in | |
6992 | @var{text} using C escape sequences, such as @samp{\n} to print a | |
6993 | newline. @strong{No newline will be printed unless you specify one.} | |
6994 | In addition to the standard C escape sequences, a backslash followed | |
6995 | by a space stands for a space. This is useful for outputting a | |
6996 | string with spaces at the beginning or the end, since leading and | |
6997 | trailing spaces are otherwise trimmed from all arguments. | |
6998 | To print @samp{@w{ }and foo =@w{ }}, use the command | |
6999 | @samp{echo \@w{ }and foo = \@w{ }}. | |
7000 | ||
7001 | A backslash at the end of @var{text} can be used, as in C, to continue | |
7002 | the command onto subsequent lines. For example, | |
7003 | ||
7004 | @example | |
7005 | echo This is some text\n\ | |
7006 | which is continued\n\ | |
7007 | onto several lines.\n | |
7008 | @end example | |
7009 | ||
7010 | produces the same output as | |
7011 | ||
7012 | @example | |
7013 | echo This is some text\n | |
7014 | echo which is continued\n | |
7015 | echo onto several lines.\n | |
7016 | @end example | |
7017 | ||
7018 | @item output @var{expression} | |
7019 | @kindex output | |
7020 | Print the value of @var{expression} and nothing but that value: no | |
7021 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
7022 | value history either. @xref{Expressions, ,Expressions}, for more information on | |
7023 | expressions. | |
7024 | ||
7025 | @item output/@var{fmt} @var{expression} | |
7026 | Print the value of @var{expression} in format @var{fmt}. You can use | |
7027 | the same formats as for @code{print}; @pxref{Output formats}, for more | |
7028 | information. | |
7029 | ||
7030 | @item printf @var{string}, @var{expressions}@dots{} | |
7031 | @kindex printf | |
7032 | Print the values of the @var{expressions} under the control of | |
7033 | @var{string}. The @var{expressions} are separated by commas and may | |
7034 | be either numbers or pointers. Their values are printed as specified | |
7035 | by @var{string}, exactly as if your program were to execute | |
7036 | ||
7037 | @example | |
7038 | printf (@var{string}, @var{expressions}@dots{}); | |
7039 | @end example | |
7040 | ||
7041 | For example, you can print two values in hex like this: | |
7042 | ||
7043 | @example | |
7044 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo | |
7045 | @end example | |
7046 | ||
7047 | The only backslash-escape sequences that you can use in the format | |
7048 | string are the simple ones that consist of backslash followed by a | |
7049 | letter. | |
7050 | @end table | |
7051 | ||
7052 | @node Emacs, GDB Bugs, Sequences, Top | |
7053 | @chapter Using GDB under GNU Emacs | |
7054 | ||
7055 | @cindex emacs | |
7056 | A special interface allows you to use GNU Emacs to view (and | |
7057 | edit) the source files for the program you are debugging with | |
7058 | GDB. | |
7059 | ||
7060 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the | |
7061 | executable file you want to debug as an argument. This command starts | |
7062 | GDB as a subprocess of Emacs, with input and output through a newly | |
7063 | created Emacs buffer. | |
7064 | ||
7065 | Using GDB under Emacs is just like using GDB normally except for two | |
7066 | things: | |
7067 | ||
7068 | @itemize @bullet | |
7069 | @item | |
7070 | All ``terminal'' input and output goes through the Emacs buffer. | |
7071 | @end itemize | |
7072 | ||
7073 | This applies both to GDB commands and their output, and to the input | |
7074 | and output done by the program you are debugging. | |
7075 | ||
7076 | This is useful because it means that you can copy the text of previous | |
7077 | commands and input them again; you can even use parts of the output | |
7078 | in this way. | |
7079 | ||
7080 | All the facilities of Emacs' Shell mode are available for interacting | |
7081 | with your program. In particular, you can send signals the usual | |
7082 | way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a | |
7083 | stop. | |
7084 | ||
7085 | @itemize @bullet | |
7086 | @item | |
7087 | GDB displays source code through Emacs. | |
7088 | @end itemize | |
7089 | ||
7090 | Each time GDB displays a stack frame, Emacs automatically finds the | |
7091 | source file for that frame and puts an arrow (@samp{=>}) at the | |
7092 | left margin of the current line. Emacs uses a separate buffer for | |
7093 | source display, and splits the window to show both your GDB session | |
7094 | and the source. | |
7095 | ||
7096 | Explicit GDB @code{list} or search commands still produce output as | |
7097 | usual, but you probably will have no reason to use them. | |
7098 | ||
7099 | @quotation | |
7100 | @emph{Warning:} If the directory where your program resides is not your | |
7101 | current directory, it can be easy to confuse Emacs about the location of | |
7102 | the source files, in which case the auxiliary display buffer will not | |
7103 | appear to show your source. GDB can find programs by searching your | |
7104 | environment's @code{PATH} variable, so the GDB input and output | |
7105 | session will proceed normally; but Emacs does not get enough information | |
7106 | back from GDB to locate the source files in this situation. To | |
7107 | avoid this problem, either start GDB mode from the directory where | |
7108 | your program resides, or specify a full path name when prompted for the | |
7109 | @kbd{M-x gdb} argument. | |
7110 | ||
7111 | A similar confusion can result if you use the GDB @code{file} command to | |
7112 | switch to debugging a program in some other location, from an existing | |
7113 | GDB buffer in Emacs. | |
7114 | @end quotation | |
7115 | ||
7116 | By default, @kbd{M-x gdb} calls the program called @file{gdb}. If | |
7117 | you need to call GDB by a different name (for example, if you keep | |
7118 | several configurations around, with different names) you can set the | |
7119 | Emacs variable @code{gdb-command-name}; for example, | |
7120 | ||
7121 | @example | |
7122 | (setq gdb-command-name "mygdb") | |
7123 | @end example | |
7124 | ||
7125 | @noindent | |
7126 | (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or | |
7127 | in your @file{.emacs} file) will make Emacs call the program named | |
7128 | ``@code{mygdb}'' instead. | |
7129 | ||
7130 | In the GDB I/O buffer, you can use these special Emacs commands in | |
7131 | addition to the standard Shell mode commands: | |
7132 | ||
7133 | @table @kbd | |
7134 | @item C-h m | |
7135 | Describe the features of Emacs' GDB Mode. | |
7136 | ||
7137 | @item M-s | |
7138 | Execute to another source line, like the GDB @code{step} command; also | |
7139 | update the display window to show the current file and location. | |
7140 | ||
7141 | @item M-n | |
7142 | Execute to next source line in this function, skipping all function | |
7143 | calls, like the GDB @code{next} command. Then update the display window | |
7144 | to show the current file and location. | |
7145 | ||
7146 | @item M-i | |
7147 | Execute one instruction, like the GDB @code{stepi} command; update | |
7148 | display window accordingly. | |
7149 | ||
7150 | @item M-x gdb-nexti | |
7151 | Execute to next instruction, using the GDB @code{nexti} command; update | |
7152 | display window accordingly. | |
7153 | ||
7154 | @item C-c C-f | |
7155 | Execute until exit from the selected stack frame, like the GDB | |
7156 | @code{finish} command. | |
7157 | ||
7158 | @item M-c | |
7159 | Continue execution of your program, like the GDB @code{continue} | |
7160 | command. | |
7161 | ||
7162 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}. | |
7163 | ||
7164 | @item M-u | |
7165 | Go up the number of frames indicated by the numeric argument | |
7166 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
7167 | like the GDB @code{up} command. | |
7168 | ||
7169 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}. | |
7170 | ||
7171 | @item M-d | |
7172 | Go down the number of frames indicated by the numeric argument, like the | |
7173 | GDB @code{down} command. | |
7174 | ||
7175 | @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}. | |
7176 | ||
7177 | @item C-x & | |
7178 | Read the number where the cursor is positioned, and insert it at the end | |
7179 | of the GDB I/O buffer. For example, if you wish to disassemble code | |
7180 | around an address that was displayed earlier, type @kbd{disassemble}; | |
7181 | then move the cursor to the address display, and pick up the | |
7182 | argument for @code{disassemble} by typing @kbd{C-x &}. | |
7183 | ||
7184 | You can customize this further on the fly by defining elements of the list | |
7185 | @code{gdb-print-command}; once it is defined, you can format or | |
7186 | otherwise process numbers picked up by @kbd{C-x &} before they are | |
7187 | inserted. A numeric argument to @kbd{C-x &} will both indicate that you | |
7188 | wish special formatting, and act as an index to pick an element of the | |
7189 | list. If the list element is a string, the number to be inserted is | |
7190 | formatted using the Emacs function @code{format}; otherwise the number | |
7191 | is passed as an argument to the corresponding list element. | |
7192 | @end table | |
7193 | ||
7194 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
7195 | tells GDB to set a breakpoint on the source line point is on. | |
7196 | ||
7197 | If you accidentally delete the source-display buffer, an easy way to get | |
7198 | it back is to type the command @code{f} in the GDB buffer, to | |
7199 | request a frame display; when you run under Emacs, this will recreate | |
7200 | the source buffer if necessary to show you the context of the current | |
7201 | frame. | |
7202 | ||
7203 | The source files displayed in Emacs are in ordinary Emacs buffers | |
7204 | which are visiting the source files in the usual way. You can edit | |
7205 | the files with these buffers if you wish; but keep in mind that GDB | |
7206 | communicates with Emacs in terms of line numbers. If you add or | |
7207 | delete lines from the text, the line numbers that GDB knows will cease | |
7208 | to correspond properly to the code. | |
7209 | ||
7210 | @c The following dropped because Epoch is nonstandard. Reactivate | |
7211 | @c if/when v19 does something similar. [email protected] 19dec1990 | |
7212 | @ignore | |
7213 | @kindex emacs epoch environment | |
7214 | @kindex epoch | |
7215 | @kindex inspect | |
7216 | ||
7217 | Version 18 of Emacs has a built-in window system called the @code{epoch} | |
7218 | environment. Users of this environment can use a new command, | |
7219 | @code{inspect} which performs identically to @code{print} except that | |
7220 | each value is printed in its own window. | |
7221 | @end ignore | |
7222 | ||
7223 | @node GDB Bugs, Renamed Commands, Emacs, Top | |
7224 | @chapter Reporting Bugs in GDB | |
7225 | @cindex Bugs in GDB | |
7226 | @cindex Reporting Bugs in GDB | |
7227 | ||
7228 | Your bug reports play an essential role in making GDB reliable. | |
7229 | ||
7230 | Reporting a bug may help you by bringing a solution to your problem, or it | |
7231 | may not. But in any case the principal function of a bug report is to help | |
7232 | the entire community by making the next version of GDB work better. Bug | |
7233 | reports are your contribution to the maintenance of GDB. | |
7234 | ||
7235 | In order for a bug report to serve its purpose, you must include the | |
7236 | information that enables us to fix the bug. | |
7237 | ||
7238 | @menu | |
7239 | * Bug Criteria:: Have You Found a Bug? | |
7240 | * Bug Reporting:: How to Report Bugs | |
7241 | @end menu | |
7242 | ||
7243 | @node Bug Criteria, Bug Reporting, GDB Bugs, GDB Bugs | |
7244 | @section Have You Found a Bug? | |
7245 | @cindex Bug Criteria | |
7246 | ||
7247 | If you are not sure whether you have found a bug, here are some guidelines: | |
7248 | ||
7249 | @itemize @bullet | |
7250 | @item | |
7251 | @cindex Fatal Signal | |
7252 | @cindex Core Dump | |
7253 | If the debugger gets a fatal signal, for any input whatever, that is a | |
7254 | GDB bug. Reliable debuggers never crash. | |
7255 | ||
7256 | @item | |
7257 | @cindex error on Valid Input | |
7258 | If GDB produces an error message for valid input, that is a bug. | |
7259 | ||
7260 | @item | |
7261 | @cindex Invalid Input | |
7262 | If GDB does not produce an error message for invalid input, | |
7263 | that is a bug. However, you should note that your idea of | |
7264 | ``invalid input'' might be our idea of ``an extension'' or ``support | |
7265 | for traditional practice''. | |
7266 | ||
7267 | @item | |
7268 | If you are an experienced user of debugging tools, your suggestions | |
7269 | for improvement of GDB are welcome in any case. | |
7270 | @end itemize | |
7271 | ||
7272 | @node Bug Reporting, , Bug Criteria, GDB Bugs | |
7273 | @section How to Report Bugs | |
7274 | @cindex Bug Reports | |
7275 | @cindex GDB Bugs, Reporting | |
7276 | ||
7277 | A number of companies and individuals offer support for GNU products. | |
7278 | If you obtained GDB from a support organization, we recommend you | |
7279 | contact that organization first. | |
7280 | ||
7281 | Contact information for many support companies and individuals is | |
7282 | available in the file @file{etc/SERVICE} in the GNU Emacs distribution. | |
7283 | ||
7284 | In any event, we also recommend that you send bug reports for GDB to one | |
7285 | of these addresses: | |
7286 | ||
7287 | @example | |
7288 | bug-gdb@@prep.ai.mit.edu | |
7289 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
7290 | @end example | |
7291 | ||
7292 | @strong{Do not send bug reports to @samp{info-gdb}, or to | |
7293 | @samp{help-gdb}, or to any newsgroups.} Most users of GDB do not want to | |
7294 | receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}. | |
7295 | ||
7296 | The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which | |
7297 | serves as a repeater. The mailing list and the newsgroup carry exactly | |
7298 | the same messages. Often people think of posting bug reports to the | |
7299 | newsgroup instead of mailing them. This appears to work, but it has one | |
7300 | problem which can be crucial: a newsgroup posting often lacks a mail | |
7301 | path back to the sender. Thus, if we need to ask for more information, | |
7302 | we may be unable to reach you. For this reason, it is better to send | |
7303 | bug reports to the mailing list. | |
7304 | ||
7305 | As a last resort, send bug reports on paper to: | |
7306 | ||
7307 | @example | |
7308 | GNU Debugger Bugs | |
7309 | Free Software Foundation | |
7310 | 545 Tech Square | |
7311 | Cambridge, MA 02139 | |
7312 | @end example | |
7313 | ||
7314 | The fundamental principle of reporting bugs usefully is this: | |
7315 | @strong{report all the facts}. If you are not sure whether to state a | |
7316 | fact or leave it out, state it! | |
7317 | ||
7318 | Often people omit facts because they think they know what causes the | |
7319 | problem and assume that some details do not matter. Thus, you might | |
7320 | assume that the name of the variable you use in an example does not matter. | |
7321 | Well, probably it does not, but one cannot be sure. Perhaps the bug is a | |
7322 | stray memory reference which happens to fetch from the location where that | |
7323 | name is stored in memory; perhaps, if the name were different, the contents | |
7324 | of that location would fool the debugger into doing the right thing despite | |
7325 | the bug. Play it safe and give a specific, complete example. That is the | |
7326 | easiest thing for you to do, and the most helpful. | |
7327 | ||
7328 | Keep in mind that the purpose of a bug report is to enable us to fix | |
7329 | the bug if it is new to us. It is not as important as what happens if | |
7330 | the bug is already known. Therefore, always write your bug reports on | |
7331 | the assumption that the bug has not been reported previously. | |
7332 | ||
7333 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
7334 | bell?'' Those bug reports are useless, and we urge everyone to | |
7335 | @emph{refuse to respond to them} except to chide the sender to report | |
7336 | bugs properly. | |
7337 | ||
7338 | To enable us to fix the bug, you should include all these things: | |
7339 | ||
7340 | @itemize @bullet | |
7341 | @item | |
7342 | The version of GDB. GDB announces it if you start with no | |
7343 | arguments; you can also print it at any time using @code{show version}. | |
7344 | ||
7345 | Without this, we will not know whether there is any point in looking for | |
7346 | the bug in the current version of GDB. | |
7347 | ||
7348 | @item | |
7349 | The type of machine you are using, and the operating system name and | |
7350 | version number. | |
7351 | ||
7352 | @item | |
7353 | What compiler (and its version) was used to compile GDB---e.g. | |
7354 | ``gcc-2.0''. | |
7355 | ||
7356 | @item | |
7357 | What compiler (and its version) was used to compile the program you | |
7358 | are debugging---e.g. ``gcc-2.0''. | |
7359 | ||
7360 | @item | |
7361 | The command arguments you gave the compiler to compile your example and | |
7362 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
7363 | you will not omit something important, list them all. A copy of the | |
7364 | Makefile (or the output from make) is sufficient. | |
7365 | ||
7366 | If we were to try to guess the arguments, we would probably guess wrong | |
7367 | and then we might not encounter the bug. | |
7368 | ||
7369 | @item | |
7370 | A complete input script, and all necessary source files, that will | |
7371 | reproduce the bug. | |
7372 | ||
7373 | @item | |
7374 | A description of what behavior you observe that you believe is | |
7375 | incorrect. For example, ``It gets a fatal signal.'' | |
7376 | ||
7377 | Of course, if the bug is that GDB gets a fatal signal, then we will | |
7378 | certainly notice it. But if the bug is incorrect output, we might not | |
7379 | notice unless it is glaringly wrong. We are human, after all. You | |
7380 | might as well not give us a chance to make a mistake. | |
7381 | ||
7382 | Even if the problem you experience is a fatal signal, you should still | |
7383 | say so explicitly. Suppose something strange is going on, such as, | |
7384 | your copy of GDB is out of synch, or you have encountered a | |
7385 | bug in the C library on your system. (This has happened!) Your copy | |
7386 | might crash and ours would not. If you told us to expect a crash, | |
7387 | then when ours fails to crash, we would know that the bug was not | |
7388 | happening for us. If you had not told us to expect a crash, then we | |
7389 | would not be able to draw any conclusion from our observations. | |
7390 | ||
7391 | @item | |
7392 | If you wish to suggest changes to the GDB source, send us context | |
7393 | diffs. If you even discuss something in the GDB source, refer to | |
7394 | it by context, not by line number. | |
7395 | ||
7396 | The line numbers in our development sources will not match those in your | |
7397 | sources. Your line numbers would convey no useful information to us. | |
7398 | @end itemize | |
7399 | ||
7400 | Here are some things that are not necessary: | |
7401 | ||
7402 | @itemize @bullet | |
7403 | @item | |
7404 | A description of the envelope of the bug. | |
7405 | ||
7406 | Often people who encounter a bug spend a lot of time investigating | |
7407 | which changes to the input file will make the bug go away and which | |
7408 | changes will not affect it. | |
7409 | ||
7410 | This is often time consuming and not very useful, because the way we | |
7411 | will find the bug is by running a single example under the debugger | |
7412 | with breakpoints, not by pure deduction from a series of examples. | |
7413 | We recommend that you save your time for something else. | |
7414 | ||
7415 | Of course, if you can find a simpler example to report @emph{instead} | |
7416 | of the original one, that is a convenience for us. Errors in the | |
7417 | output will be easier to spot, running under the debugger will take | |
7418 | less time, etc. | |
7419 | ||
7420 | However, simplification is not vital; if you do not want to do this, | |
7421 | report the bug anyway and send us the entire test case you used. | |
7422 | ||
7423 | @item | |
7424 | A patch for the bug. | |
7425 | ||
7426 | A patch for the bug does help us if it is a good one. But do not omit | |
7427 | the necessary information, such as the test case, on the assumption that | |
7428 | a patch is all we need. We might see problems with your patch and decide | |
7429 | to fix the problem another way, or we might not understand it at all. | |
7430 | ||
7431 | Sometimes with a program as complicated as GDB it is very hard to | |
7432 | construct an example that will make the program follow a certain path | |
7433 | through the code. If you do not send us the example, we will not be able | |
7434 | to construct one, so we will not be able to verify that the bug is fixed. | |
7435 | ||
7436 | And if we cannot understand what bug you are trying to fix, or why your | |
7437 | patch should be an improvement, we will not install it. A test case will | |
7438 | help us to understand. | |
7439 | ||
7440 | @item | |
7441 | A guess about what the bug is or what it depends on. | |
7442 | ||
7443 | Such guesses are usually wrong. Even we cannot guess right about such | |
7444 | things without first using the debugger to find the facts. | |
7445 | @end itemize | |
7446 | ||
7447 | @c Note: no need to update nodes for rdl-apps.texi since it appears | |
7448 | @c *only* in the TeX version of the manual. | |
7449 | @c Note: eventually, make a cross reference to the readline Info nodes. | |
7450 | @iftex | |
7451 | @c appendices describing GNU readline. Distributed with readline code. | |
7452 | @include rluser.texinfo | |
7453 | @include inc-hist.texi | |
7454 | @end iftex | |
7455 | ||
7456 | @node Renamed Commands, Installing GDB, GDB Bugs, Top | |
7457 | @appendix Renamed Commands | |
7458 | ||
7459 | The following commands were renamed in GDB 4, in order to make the | |
7460 | command set as a whole more consistent and easier to use and remember: | |
7461 | ||
7462 | @kindex add-syms | |
7463 | @kindex delete environment | |
7464 | @kindex info copying | |
7465 | @kindex info convenience | |
7466 | @kindex info directories | |
7467 | @kindex info editing | |
7468 | @kindex info history | |
7469 | @kindex info targets | |
7470 | @kindex info values | |
7471 | @kindex info version | |
7472 | @kindex info warranty | |
7473 | @kindex set addressprint | |
7474 | @kindex set arrayprint | |
7475 | @kindex set prettyprint | |
7476 | @kindex set screen-height | |
7477 | @kindex set screen-width | |
7478 | @kindex set unionprint | |
7479 | @kindex set vtblprint | |
7480 | @kindex set demangle | |
7481 | @kindex set asm-demangle | |
7482 | @kindex set sevenbit-strings | |
7483 | @kindex set array-max | |
7484 | @kindex set caution | |
7485 | @kindex set history write | |
7486 | @kindex show addressprint | |
7487 | @kindex show arrayprint | |
7488 | @kindex show prettyprint | |
7489 | @kindex show screen-height | |
7490 | @kindex show screen-width | |
7491 | @kindex show unionprint | |
7492 | @kindex show vtblprint | |
7493 | @kindex show demangle | |
7494 | @kindex show asm-demangle | |
7495 | @kindex show sevenbit-strings | |
7496 | @kindex show array-max | |
7497 | @kindex show caution | |
7498 | @kindex show history write | |
7499 | @kindex unset | |
7500 | ||
7501 | @c TEXI2ROFF-KILL | |
7502 | @ifinfo | |
7503 | @c END TEXI2ROFF-KILL | |
7504 | @example | |
7505 | OLD COMMAND NEW COMMAND | |
7506 | @c TEXI2ROFF-KILL | |
7507 | --------------- ------------------------------- | |
7508 | @c END TEXI2ROFF-KILL | |
7509 | add-syms add-symbol-file | |
7510 | delete environment unset environment | |
7511 | info convenience show convenience | |
7512 | info copying show copying | |
7513 | info directories show directories | |
7514 | info editing show commands | |
7515 | info history show values | |
7516 | info targets help target | |
7517 | info values show values | |
7518 | info version show version | |
7519 | info warranty show warranty | |
7520 | set/show addressprint set/show print address | |
7521 | set/show array-max set/show print elements | |
7522 | set/show arrayprint set/show print array | |
7523 | set/show asm-demangle set/show print asm-demangle | |
7524 | set/show caution set/show confirm | |
7525 | set/show demangle set/show print demangle | |
7526 | set/show history write set/show history save | |
7527 | set/show prettyprint set/show print pretty | |
7528 | set/show screen-height set/show height | |
7529 | set/show screen-width set/show width | |
7530 | set/show sevenbit-strings set/show print sevenbit-strings | |
7531 | set/show unionprint set/show print union | |
7532 | set/show vtblprint set/show print vtbl | |
7533 | ||
7534 | unset [No longer an alias for delete] | |
7535 | @end example | |
7536 | @c TEXI2ROFF-KILL | |
7537 | @end ifinfo | |
7538 | ||
7539 | @tex | |
7540 | \vskip \parskip\vskip \baselineskip | |
7541 | \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr | |
7542 | {\bf Old Command} &&{\bf New Command}\cr | |
7543 | add-syms &&add-symbol-file\cr | |
7544 | delete environment &&unset environment\cr | |
7545 | info convenience &&show convenience\cr | |
7546 | info copying &&show copying\cr | |
7547 | info directories &&show directories \cr | |
7548 | info editing &&show commands\cr | |
7549 | info history &&show values\cr | |
7550 | info targets &&help target\cr | |
7551 | info values &&show values\cr | |
7552 | info version &&show version\cr | |
7553 | info warranty &&show warranty\cr | |
7554 | set{\rm / }show addressprint &&set{\rm / }show print address\cr | |
7555 | set{\rm / }show array-max &&set{\rm / }show print elements\cr | |
7556 | set{\rm / }show arrayprint &&set{\rm / }show print array\cr | |
7557 | set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr | |
7558 | set{\rm / }show caution &&set{\rm / }show confirm\cr | |
7559 | set{\rm / }show demangle &&set{\rm / }show print demangle\cr | |
7560 | set{\rm / }show history write &&set{\rm / }show history save\cr | |
7561 | set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr | |
7562 | set{\rm / }show screen-height &&set{\rm / }show height\cr | |
7563 | set{\rm / }show screen-width &&set{\rm / }show width\cr | |
7564 | set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr | |
7565 | set{\rm / }show unionprint &&set{\rm / }show print union\cr | |
7566 | set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr | |
7567 | \cr | |
7568 | unset &&\rm(No longer an alias for delete)\cr | |
7569 | } | |
7570 | @end tex | |
7571 | @c END TEXI2ROFF-KILL | |
7572 | ||
7573 | @node Installing GDB, Copying, Renamed Commands, Top | |
7574 | @appendix Installing GDB | |
7575 | @cindex configuring GDB | |
7576 | @cindex installation | |
7577 | ||
7578 | @iftex | |
7579 | @c irrelevant in info file; it's as current as the code it lives with. | |
7580 | @quotation | |
7581 | @emph{Warning:} These installation instructions are current as of | |
7582 | GDB version 4.4.4. If you're installing a more recent release | |
7583 | of GDB, we may have improved the installation procedures since | |
7584 | printing this manual; see the @file{README} file included in your | |
7585 | release for the most recent instructions. | |
7586 | @end quotation | |
7587 | @end iftex | |
7588 | ||
7589 | GDB comes with a @code{configure} script that automates the process | |
7590 | of preparing GDB for installation; you can then use @code{make} to | |
7591 | build the program. | |
7592 | ||
7593 | The GDB distribution includes all the source code you need for GDB in | |
7594 | a single directory, whose name is usually composed by appending the | |
7595 | version number to @samp{gdb}. | |
7596 | ||
7597 | For example, the GDB version 4.4.4 distribution is in the @file{gdb-4.4.4} | |
7598 | directory. That directory contains: | |
7599 | ||
7600 | @table @code | |
7601 | @item gdb-4.4.4/configure @r{(and supporting files)} | |
7602 | script for configuring GDB and all its supporting libraries. | |
7603 | ||
7604 | @item gdb-4.4.4/gdb | |
7605 | the source specific to GDB itself | |
7606 | ||
7607 | @item gdb-4.4.4/bfd | |
7608 | source for the Binary File Descriptor Library | |
7609 | ||
7610 | @item gdb-4.4.4/include | |
7611 | GNU include files | |
7612 | ||
7613 | @item gdb-4.4.4/libiberty | |
7614 | source for the @samp{-liberty} free software library | |
7615 | ||
7616 | @item gdb-4.4.4/readline | |
7617 | source for the GNU command-line interface | |
7618 | @end table | |
7619 | ||
7620 | The simplest way to configure and build GDB is to run @code{configure} | |
7621 | from the @file{gdb-@var{version-number}} source directory, which in | |
7622 | this example is the @file{gdb-4.4.4} directory. | |
7623 | ||
7624 | First switch to the @file{gdb-@var{version-number}} source directory | |
7625 | if you are not already in it; then run @code{configure}. Pass the | |
7626 | identifier for the platform on which GDB will run as an | |
7627 | argument. | |
7628 | ||
7629 | For example: | |
7630 | ||
7631 | @example | |
7632 | cd gdb-4.4.4 | |
7633 | ./configure @var{host} | |
7634 | make | |
7635 | @end example | |
7636 | ||
7637 | @noindent | |
7638 | where @var{host} is an identifier such as @samp{sun4} or | |
7639 | @samp{decstation}, that identifies the platform where GDB will run. | |
7640 | ||
7641 | These @code{configure} and @code{make} commands build the three libraries @file{bfd}, | |
7642 | @file{readline}, and @file{libiberty}, then @code{gdb} itself. The | |
7643 | configured source files, and the binaries, are left in the | |
7644 | corresponding source directories. | |
7645 | ||
7646 | @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your | |
7647 | system does not recognize this automatically when you run a different | |
7648 | shell, you may need to run @code{sh} on it explicitly: | |
7649 | ||
7650 | @example | |
7651 | sh configure @var{host} | |
7652 | @end example | |
7653 | ||
7654 | If you run @code{configure} from a directory that contains source | |
7655 | directories for multiple libraries or programs, such as the | |
7656 | @file{gdb-4.4.4} source directory for version 4.4.4, @code{configure} | |
7657 | creates configuration files for every directory level underneath (unless | |
7658 | you tell it not to, with the @samp{--norecursion} option). | |
7659 | ||
7660 | You can run the @code{configure} script from any of the | |
7661 | subordinate directories in the GDB distribution, if you only want to | |
7662 | configure that subdirectory; but be sure to specify a path to it. | |
7663 | ||
7664 | For example, with version 4.4.4, type the following to configure only | |
7665 | the @code{bfd} subdirectory: | |
7666 | ||
7667 | @example | |
7668 | @group | |
7669 | cd gdb-4.4.4/bfd | |
7670 | ../configure @var{host} | |
7671 | @end group | |
7672 | @end example | |
7673 | ||
7674 | You can install @code{gdb} anywhere; it has no hardwired paths. | |
7675 | However, you should make sure that the shell on your path (named by | |
7676 | the @samp{SHELL} environment variable) is publicly readable. Remember | |
7677 | that GDB uses the shell to start your program---some systems refuse to | |
7678 | let GDB debug child processes whose programs are not readable. | |
7679 | ||
7680 | @menu | |
7681 | * Separate Objdir:: Compiling GDB in another directory | |
7682 | * Config Names:: Specifying names for hosts and targets | |
7683 | * configure Options:: Summary of options for configure | |
7684 | * Formatting Documentation:: How to format and print GDB documentation | |
7685 | @end menu | |
7686 | ||
7687 | @node Separate Objdir, Config Names, Installing GDB, Installing GDB | |
7688 | @section Compiling GDB in Another Directory | |
7689 | ||
7690 | If you want to run GDB versions for several host or target machines, | |
7691 | you'll need a different @code{gdb} compiled for each combination of | |
7692 | host and target. @code{configure} is designed to make this easy by | |
7693 | allowing you to generate each configuration in a separate subdirectory, | |
7694 | rather than in the source directory. If your @code{make} program | |
7695 | handles the @samp{VPATH} feature (GNU @code{make} does), running | |
7696 | @code{make} in each of these directories then builds the @code{gdb} | |
7697 | program specified there. | |
7698 | ||
7699 | To build @code{gdb} in a separate directory, run @code{configure} | |
7700 | with the @samp{--srcdir} option to specify where to find the source. | |
7701 | (Remember, you'll also need to specify a path to find @code{configure} | |
7702 | itself from your working directory.) | |
7703 | ||
7704 | For example, with version 4.4.4, you can build GDB in a separate | |
7705 | directory for a Sun 4 like this: | |
7706 | ||
7707 | @example | |
7708 | @group | |
7709 | cd gdb-4.4.4 | |
7710 | mkdir ../gdb-sun4 | |
7711 | cd ../gdb-sun4 | |
7712 | ../gdb-4.4.4/configure --srcdir=../gdb-4.4.4 sun4 | |
7713 | make | |
7714 | @end group | |
7715 | @end example | |
7716 | ||
7717 | When @code{configure} builds a configuration using a remote source | |
7718 | directory, it creates a tree for the binaries with the same structure | |
7719 | (and using the same names) as the tree under the source directory. In | |
7720 | the example, you'd find the Sun 4 library @file{libiberty.a} in the | |
7721 | directory @file{gdb-sun4/libiberty}, and GDB itself in | |
7722 | @file{gdb-sun4/gdb}. | |
7723 | ||
7724 | One popular use for building several GDB configurations in separate | |
7725 | directories is to configure GDB for cross-compiling (where GDB | |
7726 | runs on one machine---the host---while debugging programs that run on | |
7727 | another machine---the target). You specify a cross-debugging target by | |
7728 | giving the @samp{--target=@var{target}} option to @code{configure}. | |
7729 | ||
7730 | When you run @code{make} to build a program or library, you must run | |
7731 | it in a configured directory---whatever directory you were in when you | |
7732 | called @code{configure} (or one of its subdirectories). | |
7733 | ||
7734 | The @code{Makefile} generated by @code{configure} for each source | |
7735 | directory also runs recursively. If you type @code{make} in a source | |
7736 | directory such as @file{gdb-4.4.4} (or in a separate configured | |
7737 | directory configured with @samp{--srcdir=@var{path}/gdb-4.4.4}), you | |
7738 | will build all the required libraries, then build GDB. | |
7739 | ||
7740 | When you have multiple hosts or targets configured in separate | |
7741 | directories, you can run @code{make} on them in parallel (for example, | |
7742 | if they are NFS-mounted on each of the hosts); they will not interfere | |
7743 | with each other. | |
7744 | ||
7745 | @node Config Names, configure Options, Separate Objdir, Installing GDB | |
7746 | @section Specifying Names for Hosts and Targets | |
7747 | ||
7748 | The specifications used for hosts and targets in the @code{configure} | |
7749 | script are based on a three-part naming scheme, but some short predefined | |
7750 | aliases are also supported. The full naming scheme encodes three pieces | |
7751 | of information in the following pattern: | |
7752 | ||
7753 | @example | |
7754 | @var{architecture}-@var{vendor}-@var{os} | |
7755 | @end example | |
7756 | ||
7757 | For example, you can use the alias @code{sun4} as a @var{host} argument | |
7758 | or in a @code{--target=@var{target}} option, but the equivalent full name | |
7759 | is @samp{sparc-sun-sunos4}. | |
7760 | ||
7761 | The following table shows all the architectures, hosts, and OS | |
7762 | prefixes that @code{configure} recognizes in GDB version 4.4.4. Entries | |
7763 | in the ``OS prefix'' column ending in a @samp{*} may be followed by a | |
7764 | release number. | |
7765 | ||
7766 | @c FIXME! Update for gdb 4.4 | |
7767 | @c TEXI2ROFF-KILL | |
7768 | @ifinfo | |
7769 | @c END TEXI2ROFF-KILL | |
7770 | @example | |
7771 | ||
7772 | ARCHITECTURE VENDOR OS prefix | |
7773 | @c TEXI2ROFF-KILL | |
7774 | ------------+--------------------------+--------------------------- | |
7775 | @c END TEXI2ROFF-KILL | |
7776 | | | | |
7777 | 580 | altos hp | aix* msdos* | |
7778 | a29k | amd ibm | amigados newsos* | |
7779 | alliant | amdahl intel | aout nindy* | |
7780 | arm | aout isi | bout osf* | |
7781 | c1 | apollo little | bsd* sco* | |
7782 | c2 | att mips | coff sunos* | |
7783 | cray2 | bcs motorola | ctix* svr4 | |
7784 | h8300 | bout ncr | dgux* sym* | |
7785 | i386 | bull next | dynix* sysv* | |
7786 | i860 | cbm nyu | ebmon ultrix* | |
7787 | i960 | coff sco | esix* unicos* | |
7788 | m68000 | convergent sequent | hds unos* | |
7789 | m68k | convex sgi | hpux* uts | |
7790 | m88k | cray sony | irix* v88r* | |
7791 | mips | dec sun | isc* vms* | |
7792 | ns32k | encore unicom | kern vxworks* | |
7793 | pyramid | gould utek | mach* | |
7794 | romp | hitachi wrs | | |
7795 | rs6000 | | | |
7796 | sparc | | | |
7797 | tahoe | | | |
7798 | tron | | | |
7799 | vax | | | |
7800 | xmp | | | |
7801 | ymp | | | |
7802 | @end example | |
7803 | ||
7804 | @c TEXI2ROFF-KILL | |
7805 | @end ifinfo | |
7806 | @tex | |
7807 | %\vskip\parskip | |
7808 | \vskip \baselineskip | |
7809 | \hfil\vbox{\offinterlineskip | |
7810 | \halign{\strut\tt #\hfil\ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil | |
7811 | \ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil \cr | |
7812 | {\bf Architecture} &&{\bf Vendor} &&&{\bf OS prefix}\cr | |
7813 | \multispan7\hrulefill\cr | |
7814 | 580 && altos & hp && aix* & msdos* \cr | |
7815 | a29k && amd & ibm && amigados & newsos* \cr | |
7816 | alliant && amdahl & intel && aout & nindy* \cr | |
7817 | arm && aout & isi && bout & osf* \cr | |
7818 | c1 && apollo & little && bsd* & sco* \cr | |
7819 | c2 && att & mips && coff & sunos* \cr | |
7820 | cray2 && bcs & motorola && ctix* & svr4 \cr | |
7821 | h8300 && bout & ncr && dgux* & sym* \cr | |
7822 | i386 && bull & next && dynix* & sysv* \cr | |
7823 | i860 && cbm & nyu && ebmon & ultrix* \cr | |
7824 | i960 && coff & sco && esix* & unicos* \cr | |
7825 | m68000 && convergent& sequent && hds & unos* \cr | |
7826 | m68k && convex & sgi && hpux* & uts \cr | |
7827 | m88k && cray & sony && irix* & v88r* \cr | |
7828 | mips && dec & sun && isc* & vms* \cr | |
7829 | ns32k && encore & unicom && kern & vxworks* \cr | |
7830 | pyramid && gould & utek && mach* & \cr | |
7831 | romp && hitachi & wrs && & \cr | |
7832 | rs6000 && & && & \cr | |
7833 | sparc && & && & \cr | |
7834 | tahoe && & && & \cr | |
7835 | tron && & && & \cr | |
7836 | vax && & && & \cr | |
7837 | xmp && & && & \cr | |
7838 | ymp && & && & \cr | |
7839 | }\hfil} | |
7840 | @end tex | |
7841 | @c END TEXI2ROFF-KILL | |
7842 | ||
7843 | @quotation | |
7844 | @emph{Warning:} @code{configure} can represent a very large number of | |
7845 | combinations of architecture, vendor, and OS. There is by no means | |
7846 | support available for all possible combinations! | |
7847 | @end quotation | |
7848 | ||
7849 | The @code{configure} script accompanying GDB does not provide | |
7850 | any query facility to list all supported host and target names or | |
7851 | aliases. @code{configure} calls the Bourne shell script | |
7852 | @code{config.sub} to map abbreviations to full names; you can read the | |
7853 | script, if you wish, or you can use it to test your guesses on | |
7854 | abbreviations---for example: | |
7855 | ||
7856 | @example | |
7857 | % sh config.sub sun4 | |
7858 | sparc-sun-sunos4 | |
7859 | % sh config.sub sun3 | |
7860 | m68k-sun-sunos4 | |
7861 | % sh config.sub decstation | |
7862 | mips-dec-ultrix | |
7863 | % sh config.sub hp300bsd | |
7864 | m68k-hp-bsd | |
7865 | % sh config.sub i386v | |
7866 | i386-none-sysv | |
7867 | % sh config.sub i786v | |
7868 | *** Configuration "i786v" not recognized | |
7869 | @end example | |
7870 | ||
7871 | @noindent | |
7872 | @code{config.sub} is also distributed in the GDB source | |
7873 | directory (@file{gdb-4.4.4}, for version 4.4.4). | |
7874 | ||
7875 | @node configure Options, Formatting Documentation, Config Names, Installing GDB | |
7876 | @section @code{configure} Options | |
7877 | ||
7878 | Here is a summary of all the @code{configure} options and arguments that | |
7879 | you might use for building GDB: | |
7880 | ||
7881 | @example | |
7882 | configure @r{[}--destdir=@var{dir}@r{]} @r{[}--srcdir=@var{path}@r{]} | |
7883 | @r{[}--norecursion@r{]} @r{[}--rm@r{]} | |
7884 | @r{[}--target=@var{target}@r{]} @var{host} | |
7885 | @end example | |
7886 | ||
7887 | @noindent | |
7888 | You may introduce options with a single @samp{-} rather than | |
7889 | @samp{--} if you prefer; but you may abbreviate option names if you use | |
7890 | @samp{--}. | |
7891 | ||
7892 | @table @code | |
7893 | @item --destdir=@var{dir} | |
7894 | @var{dir} is an installation directory @emph{path prefix}. After you | |
7895 | configure with this option, @code{make install} will install GDB as | |
7896 | @file{@var{dir}/bin/gdb}, and the libraries in @file{@var{dir}/lib}. | |
7897 | If you specify @samp{--destdir=/usr/local}, for example, @code{make | |
7898 | install} creates @file{/usr/local/bin/gdb}. | |
7899 | ||
7900 | @item --srcdir=@var{path} | |
7901 | Use this option to make configurations in directories separate from the | |
7902 | GDB source directories. Among other things, you can use this to | |
7903 | build (or maintain) several configurations simultaneously, in separate | |
7904 | directories. @code{configure} writes configuration specific files in | |
7905 | the current directory, but arranges for them to use the source in the | |
7906 | directory @var{path}. @code{configure} will create directories under | |
7907 | the working directory in parallel to the source directories below | |
7908 | @var{path}. | |
7909 | ||
7910 | @item --norecursion | |
7911 | Configure only the directory level where @code{configure} is executed; do not | |
7912 | propagate configuration to subdirectories. | |
7913 | ||
7914 | @item --rm | |
7915 | Remove the configuration that the other arguments specify. | |
7916 | ||
7917 | @c This does not work (yet if ever). FIXME. | |
7918 | @c @item --parse=@var{lang} @dots{} | |
7919 | @c Configure the GDB expression parser to parse the listed languages. | |
7920 | @c @samp{all} configures GDB for all supported languages. To get a | |
7921 | @c list of all supported languages, omit the argument. Without this | |
7922 | @c option, GDB is configured to parse all supported languages. | |
7923 | ||
7924 | @item --target=@var{target} | |
7925 | Configure GDB for cross-debugging programs running on the specified | |
7926 | @var{target}. Without this option, GDB is configured to debug | |
7927 | programs that run on the same machine (@var{host}) as GDB itself. | |
7928 | ||
7929 | There is no convenient way to generate a list of all available targets. | |
7930 | ||
7931 | @item @var{host} @dots{} | |
7932 | Configure GDB to run on the specified @var{host}. | |
7933 | ||
7934 | There is no convenient way to generate a list of all available hosts. | |
7935 | @end table | |
7936 | ||
7937 | @noindent | |
7938 | @code{configure} accepts other options, for compatibility with | |
7939 | configuring other GNU tools recursively; but these are the only | |
7940 | options that affect GDB or its supporting libraries. | |
7941 | ||
7942 | @node Formatting Documentation, , configure Options, Installing GDB | |
7943 | @section Formatting the Documentation | |
7944 | ||
7945 | All the documentation for GDB, including this manual, comes as part of | |
7946 | the distribution. The documentation is written in Texinfo format, | |
7947 | which is a documentation system that uses a single source file to | |
7948 | produce both on-line information and a printed manual. You can use | |
7949 | one of the Info formatting commands to create the on-line version of | |
7950 | the documentation and @TeX{} (or @code{texi2roff}) to typeset the | |
7951 | printed version. | |
7952 | ||
7953 | GDB includes an already formatted copy of the on-line Info version of | |
7954 | this manual in the @file{gdb} subdirectory. The main Info file is | |
7955 | @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to | |
7956 | subordinate files matching @samp{gdb.info*} in the same directory. | |
7957 | ||
7958 | If you want to format these Info files yourself, you need one of the | |
7959 | Info formatting programs, such as @code{texinfo-format-buffer} or | |
7960 | @code{makeinfo}. | |
7961 | ||
7962 | If you have @code{makeinfo} installed, and are in the top level GDB | |
7963 | source directory (@file{gdb-4.4.4}, in the case of version 4.4.4), you can | |
7964 | make the Info file by typing: | |
7965 | ||
7966 | @example | |
7967 | cd gdb | |
7968 | make gdb.info | |
7969 | @end example | |
7970 | ||
7971 | If you want to typeset and print copies of this manual, you need | |
7972 | @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex}, | |
7973 | the Texinfo definitions file. | |
7974 | ||
7975 | @TeX{} is typesetting program; it does not print files directly, but | |
7976 | produces output files called @sc{dvi} files. To print a typeset | |
7977 | document, you need a program to print @sc{dvi} files. If your system | |
7978 | has @TeX{} installed, chances are it has such a program. The precise | |
7979 | command to use depends on your system; @kbd{lpr -d} is common; another | |
7980 | is @kbd{dvips}. The @sc{dvi} print command may require a file name | |
7981 | without any extension or a @samp{.dvi} extension. | |
7982 | ||
7983 | @TeX{} also requires a macro definitions file called | |
7984 | @file{texinfo.tex}. This file tells @TeX{} how to typeset a document | |
7985 | written in Texinfo format. On its own, @TeX{} cannot read, much less | |
7986 | typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB | |
7987 | and is located in the @file{gdb-@var{version-number}/texinfo} | |
7988 | directory. | |
7989 | ||
7990 | If you have @TeX{} and a @sc{dvi} printer program installed, you can | |
7991 | typeset and print this manual. First switch to the the @file{gdb} | |
7992 | subdirectory of the main source directory (for example, to | |
7993 | @file{gdb-4.4.4/gdb}) and then type: | |
7994 | ||
7995 | @example | |
7996 | make gdb.dvi | |
7997 | @end example | |
7998 | ||
7999 | @cindex GDB reference card | |
8000 | @cindex reference card | |
8001 | In addition to the manual, the GDB 4 release includes a three-column | |
8002 | reference card. Format the GDB reference card by typing: | |
8003 | ||
8004 | @example | |
8005 | make refcard.dvi | |
8006 | @end example | |
8007 | ||
8008 | The GDB reference card is designed to print in landscape mode on US | |
8009 | ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches | |
8010 | high. You will need to specify this form of printing as an option to | |
8011 | your @sc{dvi} output program. | |
8012 | ||
8013 | The GDB 4 release includes an already-formatted reference card, ready | |
8014 | for printing on a PostScript or GhostScript printer, in the @file{gdb} | |
8015 | subdirectory of the main source directory---in | |
8016 | @file{gdb-4.2/gdb/refcard.ps} of the version 4.2 release. If you have | |
8017 | a PostScript or GhostScript printer, you can print the reference card | |
8018 | by just sending @file{refcard.ps} to the printer. | |
8019 | ||
8020 | @node Copying, Index, Installing GDB, Top | |
8021 | @unnumbered GNU GENERAL PUBLIC LICENSE | |
8022 | @center Version 2, June 1991 | |
8023 | ||
8024 | @display | |
8025 | Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. | |
8026 | 675 Mass Ave, Cambridge, MA 02139, USA | |
8027 | ||
8028 | Everyone is permitted to copy and distribute verbatim copies | |
8029 | of this license document, but changing it is not allowed. | |
8030 | @end display | |
8031 | ||
8032 | @unnumberedsec Preamble | |
8033 | ||
8034 | The licenses for most software are designed to take away your | |
8035 | freedom to share and change it. By contrast, the GNU General Public | |
8036 | License is intended to guarantee your freedom to share and change free | |
8037 | software---to make sure the software is free for all its users. This | |
8038 | General Public License applies to most of the Free Software | |
8039 | Foundation's software and to any other program whose authors commit to | |
8040 | using it. (Some other Free Software Foundation software is covered by | |
8041 | the GNU Library General Public License instead.) You can apply it to | |
8042 | your programs, too. | |
8043 | ||
8044 | When we speak of free software, we are referring to freedom, not | |
8045 | price. Our General Public Licenses are designed to make sure that you | |
8046 | have the freedom to distribute copies of free software (and charge for | |
8047 | this service if you wish), that you receive source code or can get it | |
8048 | if you want it, that you can change the software or use pieces of it | |
8049 | in new free programs; and that you know you can do these things. | |
8050 | ||
8051 | To protect your rights, we need to make restrictions that forbid | |
8052 | anyone to deny you these rights or to ask you to surrender the rights. | |
8053 | These restrictions translate to certain responsibilities for you if you | |
8054 | distribute copies of the software, or if you modify it. | |
8055 | ||
8056 | For example, if you distribute copies of such a program, whether | |
8057 | gratis or for a fee, you must give the recipients all the rights that | |
8058 | you have. You must make sure that they, too, receive or can get the | |
8059 | source code. And you must show them these terms so they know their | |
8060 | rights. | |
8061 | ||
8062 | We protect your rights with two steps: (1) copyright the software, and | |
8063 | (2) offer you this license which gives you legal permission to copy, | |
8064 | distribute and/or modify the software. | |
8065 | ||
8066 | Also, for each author's protection and ours, we want to make certain | |
8067 | that everyone understands that there is no warranty for this free | |
8068 | software. If the software is modified by someone else and passed on, we | |
8069 | want its recipients to know that what they have is not the original, so | |
8070 | that any problems introduced by others will not reflect on the original | |
8071 | authors' reputations. | |
8072 | ||
8073 | Finally, any free program is threatened constantly by software | |
8074 | patents. We wish to avoid the danger that redistributors of a free | |
8075 | program will individually obtain patent licenses, in effect making the | |
8076 | program proprietary. To prevent this, we have made it clear that any | |
8077 | patent must be licensed for everyone's free use or not licensed at all. | |
8078 | ||
8079 | The precise terms and conditions for copying, distribution and | |
8080 | modification follow. | |
8081 | ||
8082 | @iftex | |
8083 | @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
8084 | @end iftex | |
8085 | @ifinfo | |
8086 | @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
8087 | @end ifinfo | |
8088 | ||
8089 | @enumerate | |
8090 | @item | |
8091 | This License applies to any program or other work which contains | |
8092 | a notice placed by the copyright holder saying it may be distributed | |
8093 | under the terms of this General Public License. The ``Program'', below, | |
8094 | refers to any such program or work, and a ``work based on the Program'' | |
8095 | means either the Program or any derivative work under copyright law: | |
8096 | that is to say, a work containing the Program or a portion of it, | |
8097 | either verbatim or with modifications and/or translated into another | |
8098 | language. (Hereinafter, translation is included without limitation in | |
8099 | the term ``modification''.) Each licensee is addressed as ``you''. | |
8100 | ||
8101 | Activities other than copying, distribution and modification are not | |
8102 | covered by this License; they are outside its scope. The act of | |
8103 | running the Program is not restricted, and the output from the Program | |
8104 | is covered only if its contents constitute a work based on the | |
8105 | Program (independent of having been made by running the Program). | |
8106 | Whether that is true depends on what the Program does. | |
8107 | ||
8108 | @item | |
8109 | You may copy and distribute verbatim copies of the Program's | |
8110 | source code as you receive it, in any medium, provided that you | |
8111 | conspicuously and appropriately publish on each copy an appropriate | |
8112 | copyright notice and disclaimer of warranty; keep intact all the | |
8113 | notices that refer to this License and to the absence of any warranty; | |
8114 | and give any other recipients of the Program a copy of this License | |
8115 | along with the Program. | |
8116 | ||
8117 | You may charge a fee for the physical act of transferring a copy, and | |
8118 | you may at your option offer warranty protection in exchange for a fee. | |
8119 | ||
8120 | @item | |
8121 | You may modify your copy or copies of the Program or any portion | |
8122 | of it, thus forming a work based on the Program, and copy and | |
8123 | distribute such modifications or work under the terms of Section 1 | |
8124 | above, provided that you also meet all of these conditions: | |
8125 | ||
8126 | @enumerate a | |
8127 | @item | |
8128 | You must cause the modified files to carry prominent notices | |
8129 | stating that you changed the files and the date of any change. | |
8130 | ||
8131 | @item | |
8132 | You must cause any work that you distribute or publish, that in | |
8133 | whole or in part contains or is derived from the Program or any | |
8134 | part thereof, to be licensed as a whole at no charge to all third | |
8135 | parties under the terms of this License. | |
8136 | ||
8137 | @item | |
8138 | If the modified program normally reads commands interactively | |
8139 | when run, you must cause it, when started running for such | |
8140 | interactive use in the most ordinary way, to print or display an | |
8141 | announcement including an appropriate copyright notice and a | |
8142 | notice that there is no warranty (or else, saying that you provide | |
8143 | a warranty) and that users may redistribute the program under | |
8144 | these conditions, and telling the user how to view a copy of this | |
8145 | License. (Exception: if the Program itself is interactive but | |
8146 | does not normally print such an announcement, your work based on | |
8147 | the Program is not required to print an announcement.) | |
8148 | @end enumerate | |
8149 | ||
8150 | These requirements apply to the modified work as a whole. If | |
8151 | identifiable sections of that work are not derived from the Program, | |
8152 | and can be reasonably considered independent and separate works in | |
8153 | themselves, then this License, and its terms, do not apply to those | |
8154 | sections when you distribute them as separate works. But when you | |
8155 | distribute the same sections as part of a whole which is a work based | |
8156 | on the Program, the distribution of the whole must be on the terms of | |
8157 | this License, whose permissions for other licensees extend to the | |
8158 | entire whole, and thus to each and every part regardless of who wrote it. | |
8159 | ||
8160 | Thus, it is not the intent of this section to claim rights or contest | |
8161 | your rights to work written entirely by you; rather, the intent is to | |
8162 | exercise the right to control the distribution of derivative or | |
8163 | collective works based on the Program. | |
8164 | ||
8165 | In addition, mere aggregation of another work not based on the Program | |
8166 | with the Program (or with a work based on the Program) on a volume of | |
8167 | a storage or distribution medium does not bring the other work under | |
8168 | the scope of this License. | |
8169 | ||
8170 | @item | |
8171 | You may copy and distribute the Program (or a work based on it, | |
8172 | under Section 2) in object code or executable form under the terms of | |
8173 | Sections 1 and 2 above provided that you also do one of the following: | |
8174 | ||
8175 | @enumerate a | |
8176 | @item | |
8177 | Accompany it with the complete corresponding machine-readable | |
8178 | source code, which must be distributed under the terms of Sections | |
8179 | 1 and 2 above on a medium customarily used for software interchange; or, | |
8180 | ||
8181 | @item | |
8182 | Accompany it with a written offer, valid for at least three | |
8183 | years, to give any third party, for a charge no more than your | |
8184 | cost of physically performing source distribution, a complete | |
8185 | machine-readable copy of the corresponding source code, to be | |
8186 | distributed under the terms of Sections 1 and 2 above on a medium | |
8187 | customarily used for software interchange; or, | |
8188 | ||
8189 | @item | |
8190 | Accompany it with the information you received as to the offer | |
8191 | to distribute corresponding source code. (This alternative is | |
8192 | allowed only for noncommercial distribution and only if you | |
8193 | received the program in object code or executable form with such | |
8194 | an offer, in accord with Subsection b above.) | |
8195 | @end enumerate | |
8196 | ||
8197 | The source code for a work means the preferred form of the work for | |
8198 | making modifications to it. For an executable work, complete source | |
8199 | code means all the source code for all modules it contains, plus any | |
8200 | associated interface definition files, plus the scripts used to | |
8201 | control compilation and installation of the executable. However, as a | |
8202 | special exception, the source code distributed need not include | |
8203 | anything that is normally distributed (in either source or binary | |
8204 | form) with the major components (compiler, kernel, and so on) of the | |
8205 | operating system on which the executable runs, unless that component | |
8206 | itself accompanies the executable. | |
8207 | ||
8208 | If distribution of executable or object code is made by offering | |
8209 | access to copy from a designated place, then offering equivalent | |
8210 | access to copy the source code from the same place counts as | |
8211 | distribution of the source code, even though third parties are not | |
8212 | compelled to copy the source along with the object code. | |
8213 | ||
8214 | @item | |
8215 | You may not copy, modify, sublicense, or distribute the Program | |
8216 | except as expressly provided under this License. Any attempt | |
8217 | otherwise to copy, modify, sublicense or distribute the Program is | |
8218 | void, and will automatically terminate your rights under this License. | |
8219 | However, parties who have received copies, or rights, from you under | |
8220 | this License will not have their licenses terminated so long as such | |
8221 | parties remain in full compliance. | |
8222 | ||
8223 | @item | |
8224 | You are not required to accept this License, since you have not | |
8225 | signed it. However, nothing else grants you permission to modify or | |
8226 | distribute the Program or its derivative works. These actions are | |
8227 | prohibited by law if you do not accept this License. Therefore, by | |
8228 | modifying or distributing the Program (or any work based on the | |
8229 | Program), you indicate your acceptance of this License to do so, and | |
8230 | all its terms and conditions for copying, distributing or modifying | |
8231 | the Program or works based on it. | |
8232 | ||
8233 | @item | |
8234 | Each time you redistribute the Program (or any work based on the | |
8235 | Program), the recipient automatically receives a license from the | |
8236 | original licensor to copy, distribute or modify the Program subject to | |
8237 | these terms and conditions. You may not impose any further | |
8238 | restrictions on the recipients' exercise of the rights granted herein. | |
8239 | You are not responsible for enforcing compliance by third parties to | |
8240 | this License. | |
8241 | ||
8242 | @item | |
8243 | If, as a consequence of a court judgment or allegation of patent | |
8244 | infringement or for any other reason (not limited to patent issues), | |
8245 | conditions are imposed on you (whether by court order, agreement or | |
8246 | otherwise) that contradict the conditions of this License, they do not | |
8247 | excuse you from the conditions of this License. If you cannot | |
8248 | distribute so as to satisfy simultaneously your obligations under this | |
8249 | License and any other pertinent obligations, then as a consequence you | |
8250 | may not distribute the Program at all. For example, if a patent | |
8251 | license would not permit royalty-free redistribution of the Program by | |
8252 | all those who receive copies directly or indirectly through you, then | |
8253 | the only way you could satisfy both it and this License would be to | |
8254 | refrain entirely from distribution of the Program. | |
8255 | ||
8256 | If any portion of this section is held invalid or unenforceable under | |
8257 | any particular circumstance, the balance of the section is intended to | |
8258 | apply and the section as a whole is intended to apply in other | |
8259 | circumstances. | |
8260 | ||
8261 | It is not the purpose of this section to induce you to infringe any | |
8262 | patents or other property right claims or to contest validity of any | |
8263 | such claims; this section has the sole purpose of protecting the | |
8264 | integrity of the free software distribution system, which is | |
8265 | implemented by public license practices. Many people have made | |
8266 | generous contributions to the wide range of software distributed | |
8267 | through that system in reliance on consistent application of that | |
8268 | system; it is up to the author/donor to decide if he or she is willing | |
8269 | to distribute software through any other system and a licensee cannot | |
8270 | impose that choice. | |
8271 | ||
8272 | This section is intended to make thoroughly clear what is believed to | |
8273 | be a consequence of the rest of this License. | |
8274 | ||
8275 | @item | |
8276 | If the distribution and/or use of the Program is restricted in | |
8277 | certain countries either by patents or by copyrighted interfaces, the | |
8278 | original copyright holder who places the Program under this License | |
8279 | may add an explicit geographical distribution limitation excluding | |
8280 | those countries, so that distribution is permitted only in or among | |
8281 | countries not thus excluded. In such case, this License incorporates | |
8282 | the limitation as if written in the body of this License. | |
8283 | ||
8284 | @item | |
8285 | The Free Software Foundation may publish revised and/or new versions | |
8286 | of the General Public License from time to time. Such new versions will | |
8287 | be similar in spirit to the present version, but may differ in detail to | |
8288 | address new problems or concerns. | |
8289 | ||
8290 | Each version is given a distinguishing version number. If the Program | |
8291 | specifies a version number of this License which applies to it and ``any | |
8292 | later version'', you have the option of following the terms and conditions | |
8293 | either of that version or of any later version published by the Free | |
8294 | Software Foundation. If the Program does not specify a version number of | |
8295 | this License, you may choose any version ever published by the Free Software | |
8296 | Foundation. | |
8297 | ||
8298 | @item | |
8299 | If you wish to incorporate parts of the Program into other free | |
8300 | programs whose distribution conditions are different, write to the author | |
8301 | to ask for permission. For software which is copyrighted by the Free | |
8302 | Software Foundation, write to the Free Software Foundation; we sometimes | |
8303 | make exceptions for this. Our decision will be guided by the two goals | |
8304 | of preserving the free status of all derivatives of our free software and | |
8305 | of promoting the sharing and reuse of software generally. | |
8306 | ||
8307 | @iftex | |
8308 | @heading NO WARRANTY | |
8309 | @end iftex | |
8310 | @ifinfo | |
8311 | @center NO WARRANTY | |
8312 | @end ifinfo | |
8313 | ||
8314 | @item | |
8315 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
8316 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
8317 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
8318 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
8319 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
8320 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
8321 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
8322 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
8323 | REPAIR OR CORRECTION. | |
8324 | ||
8325 | @item | |
8326 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | |
8327 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
8328 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | |
8329 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | |
8330 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
8331 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
8332 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
8333 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
8334 | POSSIBILITY OF SUCH DAMAGES. | |
8335 | @end enumerate | |
8336 | ||
8337 | @iftex | |
8338 | @heading END OF TERMS AND CONDITIONS | |
8339 | @end iftex | |
8340 | @ifinfo | |
8341 | @center END OF TERMS AND CONDITIONS | |
8342 | @end ifinfo | |
8343 | ||
8344 | @page | |
8345 | @unnumberedsec Applying These Terms to Your New Programs | |
8346 | ||
8347 | If you develop a new program, and you want it to be of the greatest | |
8348 | possible use to the public, the best way to achieve this is to make it | |
8349 | free software which everyone can redistribute and change under these terms. | |
8350 | ||
8351 | To do so, attach the following notices to the program. It is safest | |
8352 | to attach them to the start of each source file to most effectively | |
8353 | convey the exclusion of warranty; and each file should have at least | |
8354 | the ``copyright'' line and a pointer to where the full notice is found. | |
8355 | ||
8356 | @smallexample | |
8357 | @var{one line to give the program's name and an idea of what it does.} | |
8358 | Copyright (C) 19@var{yy} @var{name of author} | |
8359 | ||
8360 | This program is free software; you can redistribute it and/or | |
8361 | modify it under the terms of the GNU General Public License | |
8362 | as published by the Free Software Foundation; either version 2 | |
8363 | of the License, or (at your option) any later version. | |
8364 | ||
8365 | This program is distributed in the hope that it will be useful, | |
8366 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8367 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8368 | GNU General Public License for more details. | |
8369 | ||
8370 | You should have received a copy of the GNU General Public License | |
8371 | along with this program; if not, write to the | |
8372 | Free Software Foundation, Inc., 675 Mass Ave, | |
8373 | Cambridge, MA 02139, USA. | |
8374 | @end smallexample | |
8375 | ||
8376 | Also add information on how to contact you by electronic and paper mail. | |
8377 | ||
8378 | If the program is interactive, make it output a short notice like this | |
8379 | when it starts in an interactive mode: | |
8380 | ||
8381 | @smallexample | |
8382 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
8383 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details | |
8384 | type `show w'. This is free software, and you are welcome | |
8385 | to redistribute it under certain conditions; type `show c' | |
8386 | for details. | |
8387 | @end smallexample | |
8388 | ||
8389 | The hypothetical commands @samp{show w} and @samp{show c} should show | |
8390 | the appropriate parts of the General Public License. Of course, the | |
8391 | commands you use may be called something other than @samp{show w} and | |
8392 | @samp{show c}; they could even be mouse-clicks or menu items---whatever | |
8393 | suits your program. | |
8394 | ||
8395 | You should also get your employer (if you work as a programmer) or your | |
8396 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
8397 | necessary. Here is a sample; alter the names: | |
8398 | ||
8399 | @example | |
8400 | Yoyodyne, Inc., hereby disclaims all copyright | |
8401 | interest in the program `Gnomovision' | |
8402 | (which makes passes at compilers) written | |
8403 | by James Hacker. | |
8404 | ||
8405 | @var{signature of Ty Coon}, 1 April 1989 | |
8406 | Ty Coon, President of Vice | |
8407 | @end example | |
8408 | ||
8409 | This General Public License does not permit incorporating your program into | |
8410 | proprietary programs. If your program is a subroutine library, you may | |
8411 | consider it more useful to permit linking proprietary applications with the | |
8412 | library. If this is what you want to do, use the GNU Library General | |
8413 | Public License instead of this License. | |
8414 | ||
8415 | @node Index, , Copying, Top | |
8416 | @unnumbered Index | |
8417 | ||
8418 | @printindex cp | |
8419 | ||
8420 | @tex | |
8421 | % I think something like @colophon should be in texinfo. In the | |
8422 | % meantime: | |
8423 | \long\def\colophon{\hbox to0pt{}\vfill | |
8424 | \centerline{The body of this manual is set in} | |
8425 | \centerline{\fontname\tenrm,} | |
8426 | \centerline{with headings in {\bf\fontname\tenbf}} | |
8427 | \centerline{and examples in {\tt\fontname\tentt}.} | |
8428 | \centerline{{\it\fontname\tenit\/},} | |
8429 | \centerline{{\bf\fontname\tenbf}, and} | |
8430 | \centerline{{\sl\fontname\tensl\/}} | |
8431 | \centerline{are used for emphasis.}\vfill} | |
8432 | \page\colophon | |
8433 | % Blame: [email protected], 1991. | |
8434 | @end tex | |
8435 | ||
8436 | @contents | |
8437 | @bye |