]>
Commit | Line | Data |
---|---|---|
e91b87a3 | 1 | \input texinfo |
4187119d | 2 | @setfilename gdb.info |
e91b87a3 | 3 | @settitle GDB, The GNU Debugger |
4187119d | 4 | @synindex ky cp |
e91b87a3 | 5 | @ifinfo |
6 | This file documents the GNU debugger GDB. | |
7 | ||
4187119d | 8 | Copyright (C) 1988, 1989 Free Software Foundation, Inc. |
e91b87a3 | 9 | |
10 | Permission is granted to make and distribute verbatim copies of | |
11 | this manual provided the copyright notice and this permission notice | |
12 | are preserved on all copies. | |
13 | ||
14 | @ignore | |
15 | Permission is granted to process this file through Tex and print the | |
16 | results, provided the printed document carries copying permission | |
17 | notice identical to this one except for the removal of this paragraph | |
18 | (this paragraph not being relevant to the printed manual). | |
19 | ||
20 | @end ignore | |
21 | Permission is granted to copy and distribute modified versions of this | |
22 | manual under the conditions for verbatim copying, provided also that the | |
4187119d | 23 | section entitled ``GNU General Public License'' is included exactly as |
24 | in the original, and provided that the entire resulting derived work is | |
25 | distributed under the terms of a permission notice identical to this | |
26 | one. | |
e91b87a3 | 27 | |
28 | Permission is granted to copy and distribute translations of this manual | |
29 | into another language, under the above conditions for modified versions, | |
4187119d | 30 | except that the section entitled ``GNU General Public License'' may be |
31 | included in a translation approved by the author instead of in the | |
32 | original English. | |
e91b87a3 | 33 | @end ifinfo |
34 | ||
35 | @setchapternewpage odd | |
36 | @settitle GDB Manual | |
37 | @titlepage | |
38 | @sp 6 | |
6ad6aa52 | 39 | @center @titlefont{GDB} |
e91b87a3 | 40 | @sp 1 |
41 | @center The GNU Source-Level Debugger | |
42 | @sp 4 | |
96a816c5 | 43 | @center Third Edition, GDB version 4.0 |
e91b87a3 | 44 | @sp 1 |
6ad6aa52 | 45 | @center December 1990 |
e91b87a3 | 46 | @sp 5 |
47 | @center Richard M. Stallman | |
6ad6aa52 | 48 | @center (Revised by Cygnus Support) |
e91b87a3 | 49 | @page |
9c91ee3e RP |
50 | @hfill Cygnus Support |
51 | @par@hskip -@parfillskip@hfill $Revision$ | |
52 | @par@hskip -@parfillskip@hfill @TeX{}info @texinfoversion | |
e91b87a3 | 53 | @vskip 0pt plus 1filll |
6ad6aa52 | 54 | Copyright @copyright{} 1988, 1989, 1990 Free Software Foundation, Inc. |
e91b87a3 | 55 | |
56 | Permission is granted to make and distribute verbatim copies of | |
57 | this manual provided the copyright notice and this permission notice | |
58 | are preserved on all copies. | |
59 | ||
60 | Permission is granted to copy and distribute modified versions of this | |
61 | manual under the conditions for verbatim copying, provided also that the | |
4187119d | 62 | section entitled ``GNU General Public License'' is included exactly as |
63 | in the original, and provided that the entire resulting derived work is | |
64 | distributed under the terms of a permission notice identical to this | |
65 | one. | |
e91b87a3 | 66 | |
67 | Permission is granted to copy and distribute translations of this manual | |
68 | into another language, under the above conditions for modified versions, | |
4187119d | 69 | except that the section entitled ``GNU General Public License'' may be |
70 | included in a translation approved by the author instead of in the | |
71 | original English. | |
e91b87a3 | 72 | @end titlepage |
73 | @page | |
74 | ||
4187119d | 75 | @node Top, Top, Top, (DIR) |
e91b87a3 | 76 | @unnumbered Summary of GDB |
77 | ||
9da601bf RP |
78 | The purpose of a debugger such as GDB is to allow you to see what is |
79 | going on ``inside'' another program while it executes---or what another | |
80 | program was doing at the moment it crashed. We call the other program | |
81 | ``your program'' or ``the program being debugged''. | |
e91b87a3 | 82 | |
9da601bf RP |
83 | GDB can do four main kinds of things (plus other things in support of |
84 | these) to help you catch bugs in the act: | |
e91b87a3 | 85 | |
86 | @enumerate | |
87 | @item | |
9da601bf | 88 | Start your program, specifying anything that might affect its behavior. |
e91b87a3 | 89 | |
90 | @item | |
9da601bf | 91 | Make your program stop on specified conditions. |
e91b87a3 | 92 | |
93 | @item | |
9da601bf | 94 | Examine what has happened, when your program has stopped. |
e91b87a3 | 95 | |
96 | @item | |
9da601bf RP |
97 | Change things in your program, so you can experiment with correcting the |
98 | effects of one bug and go on to learn about another. | |
e91b87a3 | 99 | @end enumerate |
100 | ||
101 | GDB can be used to debug programs written in C and C++. Pascal support | |
102 | is being implemented, and Fortran support will be added when a GNU | |
103 | Fortran compiler is written. | |
104 | ||
105 | @menu | |
9da601bf | 106 | * New Features:: What's new in GDB 4.0 |
4187119d | 107 | * License:: The GNU General Public License gives you permission |
e91b87a3 | 108 | to redistribute GDB on certain terms; and also |
109 | explains that there is no warranty. | |
4187119d | 110 | * User Interface:: GDB command syntax and input and output conventions. |
e91b87a3 | 111 | * Files:: Specifying files for GDB to operate on. |
112 | * Options:: GDB arguments and options. | |
113 | * Compilation::Compiling your program so you can debug it. | |
114 | * Running:: Running your program under GDB. | |
115 | * Stopping:: Making your program stop. Why it may stop. What to do then. | |
116 | * Stack:: Examining your program's stack. | |
117 | * Source:: Examining your program's source files. | |
118 | * Data:: Examining data in your program. | |
119 | * Symbols:: Examining the debugger's symbol table. | |
120 | * Altering:: Altering things in your program. | |
121 | * Sequences:: Canned command sequences for repeated use. | |
122 | * Emacs:: Using GDB through GNU Emacs. | |
123 | * Remote:: Remote kernel debugging across a serial line. | |
9c91ee3e | 124 | * GDB Bugs:: How to report bugs (if you want to get them fixed). |
e91b87a3 | 125 | * Commands:: Index of GDB commands. |
126 | * Concepts:: Index of GDB concepts. | |
127 | @end menu | |
128 | ||
9da601bf RP |
129 | @node New Features, License, Top, Top |
130 | @unnumbered New Features in GDB version 4.0 | |
131 | ||
132 | @itemize @bullet | |
133 | @item | |
134 | TARGETS: Using the new command @samp{target}, you can select at runtime | |
135 | whether you are debugging local files, local processes, standalone | |
136 | systems over the serial port, realtime systems over a TCP/IP | |
137 | connection, etc. Gdb now uses a function vector to mediate access to | |
138 | all the different possible targets, making it much easier to add | |
139 | support for new remote protocols. | |
140 | ||
141 | @item | |
142 | WATCHPOINTS: GDB now sports watchpoints as well as breakpoints. You can | |
143 | use a watchpoint to stop execution whenever the value of an expression | |
144 | changes, without having to predict a particular place in the inferior | |
145 | process where this may happen. | |
146 | ||
147 | @item | |
148 | OBJECT CODE FORMATS: GDB uses a new scheme called Binary File | |
149 | Descriptors (BFD) to permit it to switch dynamically, without | |
150 | reconfiguration or recompilation, between different object-file | |
151 | formats. Formats currently supported are COFF, a.out, and the new | |
152 | Intel 960 b.out; files may be read as .o's, archive libraries, or core | |
153 | dumps. BFD is available as a subroutine library so that other | |
154 | programs may take advantage of it, and the other GNU binary utilities | |
155 | are being converted to use it. | |
156 | ||
157 | @item | |
158 | CONFIGURATION: You must still choose a particular machine architecture | |
159 | and operating system for GDB's host and target systems when GDB is built. | |
160 | The script @samp{config.gdb} now handles specification of separate host | |
161 | and target configurations. | |
162 | ||
163 | @item | |
164 | INTERACTION: GDB now uses the GNU @code{readline} interface to read its | |
165 | input; this provides inline editing of commands, using the familiar | |
166 | Emacs or VI keymaps, and command-history support. The user interface | |
167 | to GDB's control variables has been simplified and consolidated in two | |
168 | commands, @samp{set} and @samp{show}. | |
169 | ||
170 | @item | |
171 | SOURCE LANGUAGE: GDB now understands C++ source as well as C. Multiple | |
172 | inheritance is supported when used with G++ 2.0. There is also limited | |
173 | support for C++ exception handling: GDB can break on the raising of an | |
174 | exception, before the stack is peeled back to the exception handler's | |
175 | context. | |
176 | ||
177 | @item | |
178 | PORTS: GDB has been ported to the following new architectures: | |
179 | AT&T 3b1, Acorn RISC machine, HP300 running HPUX, big- and little- | |
180 | endian MIPS machines, Motorola 88k, Sun 386i, and Sun 3 running SunOS | |
181 | 4. In addition, the following are supported as targets only: AMD | |
182 | 29k, Intel 960, and Wind River's VxWorks. | |
183 | ||
184 | @item | |
185 | SHARED LIBRARIES: GDB 4.0 supports SunOS shared libraries. | |
186 | ||
187 | @item | |
188 | WORK IN PROGRESS: kernel debugging for BSD and Mach systems; Tahoe and | |
189 | HPPA architecture support. | |
190 | ||
191 | @end itemize | |
192 | ||
193 | ||
194 | ||
195 | @node License, User Interface, New Features, Top | |
4187119d | 196 | @unnumbered GNU GENERAL PUBLIC LICENSE |
197 | @center Version 1, February 1989 | |
198 | ||
199 | @display | |
200 | Copyright @copyright{} 1989 Free Software Foundation, Inc. | |
201 | 675 Mass Ave, Cambridge, MA 02139, USA | |
202 | ||
203 | Everyone is permitted to copy and distribute verbatim copies | |
204 | of this license document, but changing it is not allowed. | |
205 | @end display | |
206 | ||
207 | @unnumberedsec Preamble | |
208 | ||
209 | The license agreements of most software companies try to keep users | |
210 | at the mercy of those companies. By contrast, our General Public | |
211 | License is intended to guarantee your freedom to share and change free | |
212 | software---to make sure the software is free for all its users. The | |
213 | General Public License applies to the Free Software Foundation's | |
214 | software and to any other program whose authors commit to using it. | |
215 | You can use it for your programs, too. | |
216 | ||
217 | When we speak of free software, we are referring to freedom, not | |
218 | price. Specifically, the General Public License is designed to make | |
219 | sure that you have the freedom to give away or sell copies of free | |
220 | software, that you receive source code or can get it if you want it, | |
221 | that you can change the software or use pieces of it in new free | |
222 | programs; and that you know you can do these things. | |
223 | ||
224 | To protect your rights, we need to make restrictions that forbid | |
225 | anyone to deny you these rights or to ask you to surrender the rights. | |
226 | These restrictions translate to certain responsibilities for you if you | |
227 | distribute copies of the software, or if you modify it. | |
228 | ||
229 | For example, if you distribute copies of a such a program, whether | |
230 | gratis or for a fee, you must give the recipients all the rights that | |
231 | you have. You must make sure that they, too, receive or can get the | |
232 | source code. And you must tell them their rights. | |
233 | ||
234 | We protect your rights with two steps: (1) copyright the software, and | |
235 | (2) offer you this license which gives you legal permission to copy, | |
236 | distribute and/or modify the software. | |
237 | ||
238 | Also, for each author's protection and ours, we want to make certain | |
239 | that everyone understands that there is no warranty for this free | |
240 | software. If the software is modified by someone else and passed on, we | |
241 | want its recipients to know that what they have is not the original, so | |
242 | that any problems introduced by others will not reflect on the original | |
243 | authors' reputations. | |
244 | ||
245 | The precise terms and conditions for copying, distribution and | |
246 | modification follow. | |
e91b87a3 | 247 | |
4187119d | 248 | @iftex |
249 | @unnumberedsec TERMS AND CONDITIONS | |
250 | @end iftex | |
251 | @ifinfo | |
252 | @center TERMS AND CONDITIONS | |
253 | @end ifinfo | |
e91b87a3 | 254 | |
255 | @enumerate | |
256 | @item | |
4187119d | 257 | This License Agreement applies to any program or other work which |
258 | contains a notice placed by the copyright holder saying it may be | |
259 | distributed under the terms of this General Public License. The | |
260 | ``Program'', below, refers to any such program or work, and a ``work based | |
261 | on the Program'' means either the Program or any work containing the | |
262 | Program or a portion of it, either verbatim or with modifications. Each | |
263 | licensee is addressed as ``you''. | |
264 | ||
265 | @item | |
266 | You may copy and distribute verbatim copies of the Program's source | |
267 | code as you receive it, in any medium, provided that you conspicuously and | |
268 | appropriately publish on each copy an appropriate copyright notice and | |
269 | disclaimer of warranty; keep intact all the notices that refer to this | |
270 | General Public License and to the absence of any warranty; and give any | |
271 | other recipients of the Program a copy of this General Public License | |
272 | along with the Program. You may charge a fee for the physical act of | |
273 | transferring a copy. | |
e91b87a3 | 274 | |
275 | @item | |
4187119d | 276 | You may modify your copy or copies of the Program or any portion of |
277 | it, and copy and distribute such modifications under the terms of Paragraph | |
278 | 1 above, provided that you also do the following: | |
e91b87a3 | 279 | |
280 | @itemize @bullet | |
281 | @item | |
4187119d | 282 | cause the modified files to carry prominent notices stating that |
283 | you changed the files and the date of any change; and | |
e91b87a3 | 284 | |
285 | @item | |
286 | cause the whole of any work that you distribute or publish, that | |
4187119d | 287 | in whole or in part contains the Program or any part thereof, either |
288 | with or without modifications, to be licensed at no charge to all | |
289 | third parties under the terms of this General Public License (except | |
290 | that you may choose to grant warranty protection to some or all | |
291 | third parties, at your option). | |
e91b87a3 | 292 | |
293 | @item | |
4187119d | 294 | If the modified program normally reads commands interactively when |
295 | run, you must cause it, when started running for such interactive use | |
296 | in the simplest and most usual way, to print or display an | |
297 | announcement including an appropriate copyright notice and a notice | |
298 | that there is no warranty (or else, saying that you provide a | |
299 | warranty) and that users may redistribute the program under these | |
300 | conditions, and telling the user how to view a copy of this General | |
301 | Public License. | |
e91b87a3 | 302 | |
303 | @item | |
4187119d | 304 | You may charge a fee for the physical act of transferring a |
305 | copy, and you may at your option offer warranty protection in | |
306 | exchange for a fee. | |
e91b87a3 | 307 | @end itemize |
308 | ||
4187119d | 309 | Mere aggregation of another independent work with the Program (or its |
e91b87a3 | 310 | derivative) on a volume of a storage or distribution medium does not bring |
4187119d | 311 | the other work under the scope of these terms. |
e91b87a3 | 312 | |
313 | @item | |
4187119d | 314 | You may copy and distribute the Program (or a portion or derivative of |
315 | it, under Paragraph 2) in object code or executable form under the terms of | |
316 | Paragraphs 1 and 2 above provided that you also do one of the following: | |
e91b87a3 | 317 | |
318 | @itemize @bullet | |
319 | @item | |
320 | accompany it with the complete corresponding machine-readable | |
321 | source code, which must be distributed under the terms of | |
322 | Paragraphs 1 and 2 above; or, | |
323 | ||
324 | @item | |
325 | accompany it with a written offer, valid for at least three | |
4187119d | 326 | years, to give any third party free (except for a nominal charge |
327 | for the cost of distribution) a complete machine-readable copy of the | |
e91b87a3 | 328 | corresponding source code, to be distributed under the terms of |
329 | Paragraphs 1 and 2 above; or, | |
330 | ||
331 | @item | |
332 | accompany it with the information you received as to where the | |
333 | corresponding source code may be obtained. (This alternative is | |
334 | allowed only for noncommercial distribution and only if you | |
335 | received the program in object code or executable form alone.) | |
336 | @end itemize | |
337 | ||
4187119d | 338 | Source code for a work means the preferred form of the work for making |
339 | modifications to it. For an executable file, complete source code means | |
340 | all the source code for all modules it contains; but, as a special | |
341 | exception, it need not include source code for modules which are standard | |
342 | libraries that accompany the operating system on which the executable | |
343 | file runs, or for standard header files or definitions files that | |
344 | accompany that operating system. | |
e91b87a3 | 345 | |
346 | @item | |
4187119d | 347 | You may not copy, modify, sublicense, distribute or transfer the |
348 | Program except as expressly provided under this General Public License. | |
349 | Any attempt otherwise to copy, modify, sublicense, distribute or transfer | |
350 | the Program is void, and will automatically terminate your rights to use | |
351 | the Program under this License. However, parties who have received | |
352 | copies, or rights to use copies, from you under this General Public | |
353 | License will not have their licenses terminated so long as such parties | |
354 | remain in full compliance. | |
e91b87a3 | 355 | |
356 | @item | |
4187119d | 357 | By copying, distributing or modifying the Program (or any work based |
358 | on the Program) you indicate your acceptance of this license to do so, | |
359 | and all its terms and conditions. | |
360 | ||
361 | @item | |
362 | Each time you redistribute the Program (or any work based on the | |
363 | Program), the recipient automatically receives a license from the original | |
364 | licensor to copy, distribute or modify the Program subject to these | |
365 | terms and conditions. You may not impose any further restrictions on the | |
366 | recipients' exercise of the rights granted herein. | |
367 | ||
368 | @item | |
369 | The Free Software Foundation may publish revised and/or new versions | |
370 | of the General Public License from time to time. Such new versions will | |
371 | be similar in spirit to the present version, but may differ in detail to | |
372 | address new problems or concerns. | |
373 | ||
374 | Each version is given a distinguishing version number. If the Program | |
375 | specifies a version number of the license which applies to it and ``any | |
376 | later version'', you have the option of following the terms and conditions | |
377 | either of that version or of any later version published by the Free | |
378 | Software Foundation. If the Program does not specify a version number of | |
379 | the license, you may choose any version ever published by the Free Software | |
380 | Foundation. | |
381 | ||
382 | @item | |
383 | If you wish to incorporate parts of the Program into other free | |
384 | programs whose distribution conditions are different, write to the author | |
385 | to ask for permission. For software which is copyrighted by the Free | |
386 | Software Foundation, write to the Free Software Foundation; we sometimes | |
387 | make exceptions for this. Our decision will be guided by the two goals | |
388 | of preserving the free status of all derivatives of our free software and | |
389 | of promoting the sharing and reuse of software generally. | |
390 | ||
391 | @iftex | |
392 | @heading NO WARRANTY | |
393 | @end iftex | |
394 | @ifinfo | |
395 | @center NO WARRANTY | |
396 | @end ifinfo | |
397 | ||
398 | @item | |
399 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
400 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
401 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
402 | PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
403 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
404 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
405 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
406 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
407 | REPAIR OR CORRECTION. | |
408 | ||
409 | @item | |
410 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL | |
411 | ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
412 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | |
413 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES | |
414 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT | |
415 | LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES | |
416 | SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE | |
417 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN | |
418 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
e91b87a3 | 419 | @end enumerate |
420 | ||
421 | @iftex | |
4187119d | 422 | @heading END OF TERMS AND CONDITIONS |
e91b87a3 | 423 | @end iftex |
4187119d | 424 | @ifinfo |
425 | @center END OF TERMS AND CONDITIONS | |
426 | @end ifinfo | |
427 | ||
428 | @page | |
429 | @unnumberedsec Appendix: How to Apply These Terms to Your New Programs | |
430 | ||
431 | If you develop a new program, and you want it to be of the greatest | |
432 | possible use to humanity, the best way to achieve this is to make it | |
433 | free software which everyone can redistribute and change under these | |
434 | terms. | |
435 | ||
436 | To do so, attach the following notices to the program. It is safest to | |
437 | attach them to the start of each source file to most effectively convey | |
438 | the exclusion of warranty; and each file should have at least the | |
439 | ``copyright'' line and a pointer to where the full notice is found. | |
440 | ||
441 | @smallexample | |
442 | @var{one line to give the program's name and a brief idea of what it does.} | |
443 | Copyright (C) 19@var{yy} @var{name of author} | |
444 | ||
445 | This program is free software; you can redistribute it and/or modify | |
446 | it under the terms of the GNU General Public License as published by | |
447 | the Free Software Foundation; either version 1, or (at your option) | |
448 | any later version. | |
449 | ||
450 | This program is distributed in the hope that it will be useful, | |
451 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
452 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
453 | GNU General Public License for more details. | |
454 | ||
455 | You should have received a copy of the GNU General Public License | |
456 | along with this program; if not, write to the Free Software | |
457 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
458 | @end smallexample | |
459 | ||
460 | Also add information on how to contact you by electronic and paper mail. | |
461 | ||
462 | If the program is interactive, make it output a short notice like this | |
463 | when it starts in an interactive mode: | |
464 | ||
465 | @smallexample | |
466 | Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} | |
467 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
468 | This is free software, and you are welcome to redistribute it | |
469 | under certain conditions; type `show c' for details. | |
470 | @end smallexample | |
471 | ||
472 | The hypothetical commands `show w' and `show c' should show the | |
473 | appropriate parts of the General Public License. Of course, the | |
474 | commands you use may be called something other than `show w' and `show | |
475 | c'; they could even be mouse-clicks or menu items---whatever suits your | |
476 | program. | |
477 | ||
478 | You should also get your employer (if you work as a programmer) or your | |
479 | school, if any, to sign a ``copyright disclaimer'' for the program, if | |
480 | necessary. Here a sample; alter the names: | |
481 | ||
482 | @example | |
483 | Yoyodyne, Inc., hereby disclaims all copyright interest in the | |
484 | program `Gnomovision' (a program to direct compilers to make passes | |
485 | at assemblers) written by James Hacker. | |
486 | ||
487 | @var{signature of Ty Coon}, 1 April 1989 | |
488 | Ty Coon, President of Vice | |
489 | @end example | |
490 | ||
491 | That's all there is to it! | |
492 | ||
493 | @node User Interface, Files, License, Top | |
494 | @chapter GDB Input and Output Conventions | |
e91b87a3 | 495 | |
496 | GDB is invoked with the shell command @samp{gdb}. Once started, it reads | |
497 | commands from the terminal until you tell it to exit. | |
498 | ||
499 | A GDB command is a single line of input. There is no limit on how long | |
500 | it can be. It starts with a command name, which is followed by arguments | |
4187119d | 501 | whose meaning depends on the command name. For example, the command |
502 | @samp{step} accepts an argument which is the number of times to step, | |
503 | as in @samp{step 5}. You can also use the @samp{step} command with | |
504 | no arguments. Some command names do not allow any arguments. | |
e91b87a3 | 505 | |
4187119d | 506 | @cindex abbreviation |
9da601bf RP |
507 | GDB command names may always be truncated if that abbreviation is |
508 | unambiguous. Other possible command abbreviations are listed in the | |
509 | documentation of the individual commands. Sometimes even ambiguous | |
510 | abbreviations are allowed; for example, @samp{s} is specially defined as | |
511 | equivalent to @samp{step} even though there are other commands whose | |
512 | names start with @samp{s}. | |
e91b87a3 | 513 | |
4187119d | 514 | @cindex repeating commands |
9da601bf RP |
515 | A blank line as input to GDB means to repeat the previous command. |
516 | Certain commands will not repeat this way; these are commands for which | |
517 | unintentional repetition might cause trouble and which you are unlikely | |
518 | to want to repeat. Certain others (@samp{list} and @samp{x}) act | |
519 | differently when repeated because that is more useful. | |
e91b87a3 | 520 | |
521 | A line of input starting with @samp{#} is a comment; it does nothing. | |
522 | This is useful mainly in command files (@xref{Command Files}). | |
523 | ||
9da601bf RP |
524 | @cindex online documentation |
525 | @kindex help | |
526 | @table @code | |
527 | @item help | |
528 | @itemx help @var{category} | |
529 | @itemx help @var{command} | |
530 | You can always ask GDB itself for information on its commands, using the | |
531 | command @samp{help}. With a command name as argument, it will display a | |
532 | paragraph on how to use the command. Used with no arguments, | |
533 | @samp{help} displays a short list of named categories of commands; you | |
534 | can then use @samp{help @var{category}} to list the individual commands | |
535 | in a category. | |
536 | @end table | |
537 | ||
4187119d | 538 | @cindex prompt |
539 | GDB indicates its readiness to read a command by printing a string | |
540 | called the @dfn{prompt}. This string is normally @samp{(gdb)}. You can | |
541 | change the prompt string with the @samp{set prompt} command. For | |
542 | instance, when debugging GDB with GDB, it is useful to change the prompt | |
543 | in one of the GDBs so that you tell which one you are talking to. | |
e91b87a3 | 544 | |
545 | @table @code | |
9c91ee3e | 546 | @item set prompt @var{newprompt} |
e91b87a3 | 547 | @kindex set prompt |
9da601bf | 548 | Directs GDB to use @var{newprompt} as its prompt string henceforth. |
96a816c5 JG |
549 | @kindex show prompt |
550 | @item show prompt | |
9da601bf | 551 | Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}} |
e91b87a3 | 552 | @end table |
553 | ||
554 | @cindex exiting GDB | |
555 | @kindex quit | |
9c91ee3e RP |
556 | To exit GDB, use the @samp{quit} command (abbreviated @samp{q}), or type |
557 | an end-of-file character (usually @ctrl{d}). An interrupt (often | |
558 | @ctrl{c}) will not exit from GDB, but rather will terminate the action | |
e91b87a3 | 559 | of any GDB command that is in progress and return to GDB command level. |
9c91ee3e RP |
560 | It is safe to type the interrupt character at any time because GDB does |
561 | not allow it to take effect until a time when it is safe. | |
e91b87a3 | 562 | |
96a816c5 JG |
563 | @cindex readline |
564 | @cindex command line editing | |
565 | @cindex history substitution | |
566 | GDB now reads its input commands via the @code{readline} interface. | |
9c91ee3e RP |
567 | This GNU library provides consistant behaviour for programs which |
568 | provide a command line interface to the user. From the point | |
569 | of view of the user, the advantages are @samp{emacs}-style or @samp{vi}-style | |
96a816c5 JG |
570 | inline editing of commands, @samp{csh}-like history substitution, |
571 | and a storage and recall of command history across debugging sessions. | |
572 | ||
573 | You may control the behavior of command line editing in GDB with the | |
9da601bf RP |
574 | command @samp{set}. You may check the status of any of these settings |
575 | with the command @samp{show}. | |
96a816c5 JG |
576 | |
577 | @table @code | |
578 | @kindex set editing | |
9da601bf | 579 | @cindex editing |
96a816c5 JG |
580 | @item set editing |
581 | @itemx set editing on | |
582 | Enable command line editing (enabled by default). | |
583 | ||
584 | @item set editing off | |
585 | Disable command line editing. | |
586 | ||
9da601bf RP |
587 | @kindex show editing |
588 | @item show editing | |
589 | Show whether command line editing is enabled. | |
96a816c5 | 590 | |
9da601bf | 591 | @cindex history file |
96a816c5 | 592 | @kindex set history file |
9c91ee3e | 593 | @item set history file @var{filename} |
96a816c5 JG |
594 | Set the name of the GDB command history file to @samp{filename}. This is |
595 | the file from which GDB will read an initial command history | |
596 | list or to which it will write this list when it exits. This list is | |
597 | accessed through history expansion or through the history | |
598 | command editing characters listed below. This file defaults to the | |
599 | value of the environmental variable @code{GDBHISTFILE}, or to | |
600 | @code{./.gdb_history} if this variable is not set. | |
601 | ||
9da601bf | 602 | @cindex history write |
96a816c5 JG |
603 | @kindex set history write |
604 | @item set history write | |
605 | @itemx set history write on | |
9c91ee3e RP |
606 | Make GDB record command history in a file, whose name may be specified with the |
607 | @samp{set history file} command. By default, this option is disabled. | |
96a816c5 JG |
608 | |
609 | @item set history write off | |
9c91ee3e | 610 | Make GDB stop recording command history in a file. |
96a816c5 | 611 | |
9da601bf | 612 | @cindex history size |
96a816c5 JG |
613 | @kindex set history size |
614 | @item set history size @var{size} | |
615 | Set the number of commands which GDB will keep in its history list. | |
616 | This defaults to the value of the environmental variable | |
617 | @code{HISTSIZE}, or to 256 if this variable is not set. | |
6ad6aa52 | 618 | @end table |
96a816c5 JG |
619 | |
620 | @cindex history expansion | |
9da601bf RP |
621 | History expansion is off by default, because of the additional meaning |
622 | of `@code{!}' to GDB (as the logical not operator in C). If you decide | |
623 | to enable history expansion with the @samp{set history expansion on} | |
624 | command, you may sometimes need to follow @samp{!} (when it is used as | |
625 | logical not, in an expression) with a space or a tab to prevent it from | |
626 | being expanded. The @samp{readline} history facilities will not attempt | |
627 | substitution on the strings @samp{!=} and @samp{!(}, even when history | |
628 | expansion is enabled. @xref{Event Designators}. | |
96a816c5 | 629 | |
96a816c5 JG |
630 | The commands to control history expansion are: |
631 | ||
632 | @table @code | |
633 | ||
634 | @kindex set history expansion | |
635 | @item set history expansion on | |
636 | @itemx set history expansion | |
9c91ee3e | 637 | Enable history expansion. History expansion is off by default. |
96a816c5 JG |
638 | |
639 | @item set history expansion off | |
9c91ee3e | 640 | Disable history expansion. |
96a816c5 | 641 | |
9da601bf RP |
642 | The @code{readline} code comes with more complete documentation of |
643 | editing and history expansion features. Users unfamiliar with @samp{emacs} | |
644 | or @samp{vi} may wish to read it. @xref{Command Line Editing}. | |
645 | ||
646 | @kindex show history | |
647 | @item show history | |
648 | @itemx show history file | |
649 | @itemx show history write | |
650 | @itemx show history size | |
651 | @itemx show history expansion | |
652 | These commands display the state of the GDB history parameters. | |
653 | @samp{show history} by itself displays all four states. | |
654 | ||
96a816c5 JG |
655 | @end table |
656 | ||
9da601bf RP |
657 | @table @code |
658 | @kindex info editing | |
659 | @item info editing | |
660 | Display the last ten commands in the command history. | |
9c91ee3e | 661 | |
9da601bf RP |
662 | @item info editing @var{n} |
663 | Print ten commands centered on command number @var{n}. | |
9c91ee3e | 664 | |
9da601bf RP |
665 | @item info editing + |
666 | Print ten commands just after the commands last printed. | |
667 | ||
668 | @end table | |
96a816c5 JG |
669 | |
670 | Occasionally it is useful to execute a shell command from within GDB. | |
671 | This can be done with the @samp{shell} command. | |
672 | ||
673 | @table @code | |
9c91ee3e | 674 | @item shell @var{command string} |
96a816c5 JG |
675 | @kindex shell |
676 | @cindex shell escape | |
9c91ee3e | 677 | Directs GDB to invoke an inferior shell to execute @var{command string}. |
96a816c5 JG |
678 | The environment variable @code{SHELL} is used if it exists, otherwise GDB |
679 | uses @samp{/bin/sh}. | |
680 | ||
9c91ee3e RP |
681 | @item make @var{target} |
682 | @kindex make | |
683 | @cindex calling make | |
684 | Causes GDB to execute an inferior @code{make} program with the specified | |
685 | arguments. This is equivalent to @samp{shell make @var{target}}. | |
686 | @end table | |
687 | ||
4187119d | 688 | @cindex screen size |
689 | @cindex pauses in output | |
690 | Certain commands to GDB may produce large amounts of information output | |
691 | to the screen. To help you read all of it, GDB pauses and asks you for | |
692 | input at the end of each page of output. Type @key{RET} when you want | |
693 | to continue the output. Normally GDB knows the size of the screen from | |
9c91ee3e RP |
694 | the termcap data base together with the value of the @code{TERM} |
695 | environment variable and the @code{stty rows} and @code{stty cols} | |
696 | settings. If this is not correct, you can override it with | |
96a816c5 | 697 | the @samp{set screen-height} and @samp{set screen-width} commands: |
4187119d | 698 | |
699 | @table @code | |
96a816c5 | 700 | @item set screen-height @var{lpp} |
9da601bf RP |
701 | @itemx show screen-height |
702 | @itemx set screen-width @var{cpl} | |
703 | @itemx show screen-width | |
96a816c5 JG |
704 | @kindex set screen-height |
705 | @kindex set screen-width | |
9da601bf RP |
706 | @kindex show screen-width |
707 | @kindex show screen-height | |
708 | These @samp{set} commands specify a screen height of @var{lpp} lines and | |
709 | a screen width of @var{cpl} characters. The associated @samp{show} | |
710 | commands display the current settings. | |
4187119d | 711 | |
712 | If you specify a height of zero lines, GDB will not pause during output | |
713 | no matter how long the output is. This is useful if output is to a file | |
714 | or to an editor buffer. | |
715 | @end table | |
716 | ||
9da601bf RP |
717 | @cindex number representation |
718 | @cindex entering numbers | |
719 | You can always enter numbers in octal, decimal, or hexadecimal in GDB by | |
720 | the usual conventions: octal numbers begin with @samp{0}, decimal | |
721 | numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}. | |
722 | Numbers that begin with none of these are, by default, entered in base | |
723 | 10; likewise, the default display for numbers---when no particular | |
724 | format is specified---is base 10. You can change the default base for | |
725 | both input and output with the @samp{set radix} command. | |
726 | ||
727 | @table @code | |
728 | @kindex set radix | |
729 | @item set radix @var{base} | |
730 | Set the default base for numeric input and display. Supported choices | |
731 | for @var{base} are decimal 8, 10, 16. @var{base} must itself be | |
732 | specified either unambiguously or using the current default radix; for | |
733 | example, any of | |
734 | ||
735 | @example | |
736 | set radix 012 | |
737 | set radix 10. | |
738 | set radix 0xa | |
739 | @end example | |
740 | ||
741 | @noindent | |
742 | will set the base to decimal. On the other hand, @samp{set radix 10} | |
743 | will leave the radix unchanged no matter what it was. | |
744 | ||
745 | @kindex show radix | |
746 | @item show radix | |
747 | Display the current default base for numeric input and display. | |
748 | ||
749 | @end table | |
750 | ||
9c91ee3e RP |
751 | By default, GDB is silent about its inner workings. If you are running |
752 | on a slow machine, you may want to use the @samp{set verbose} command. | |
753 | It will make GDB tell you when it does a lengthy internal operation, so | |
754 | you won't think it has crashed. | |
4187119d | 755 | |
756 | Currently, the messages controlled by @samp{set verbose} are those which | |
757 | announce that the symbol table for a source file is being read | |
758 | (@pxref{File Commands}, in the description of the command | |
759 | @samp{symbol-file}). | |
760 | @c The following is the right way to do it, but emacs 18.55 doesn't support | |
761 | @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo | |
762 | @c is released. | |
763 | @ignore | |
764 | see @samp{symbol-file} in @ref{File Commands}). | |
765 | @end ignore | |
766 | ||
9c91ee3e RP |
767 | @table @code |
768 | @kindex set verbose | |
769 | @item set verbose on | |
770 | Enables GDB's output of certain informational messages. | |
771 | ||
772 | @item set verbose off | |
773 | Disables GDB's output of certain informational messages. | |
774 | ||
9da601bf RP |
775 | @kindex show verbose |
776 | @item show verbose | |
777 | Displays whether @samp{set verbose} is on or off. | |
9c91ee3e RP |
778 | @end table |
779 | ||
780 | By default, GDB asks what sometimes seem to be a lot of stupid | |
781 | questions. For example, if you try to run a program which is already | |
782 | running: | |
783 | @example | |
784 | ||
785 | (gdb) run | |
786 | The program being debugged has been started already. | |
787 | Start it from the beginning? (y or n) | |
788 | @end example | |
789 | ||
790 | If you're willing to unflinchingly face the consequences of your own | |
791 | commands, you can disable this ``feature'': | |
792 | ||
793 | @table @code | |
794 | @kindex set stupidity | |
795 | @cindex flinching | |
4afc6002 | 796 | @cindex stupid questions |
9c91ee3e RP |
797 | @item set stupidity off |
798 | Disables stupid questions. | |
799 | ||
800 | @item set stupidity on | |
801 | Enables stupid questions (the default). | |
9da601bf RP |
802 | |
803 | @item show stupidity | |
804 | @kindex show stupidity | |
805 | Displays state of stupid questions. | |
4afc6002 | 806 | @end table |
9c91ee3e | 807 | |
4187119d | 808 | @node Files, Compilation, User Interface, Top |
e91b87a3 | 809 | @chapter Specifying GDB's Files |
810 | ||
811 | @cindex core dump file | |
812 | @cindex executable file | |
813 | @cindex symbol table | |
4187119d | 814 | GDB needs to know the file name of the program to be debugged, both in |
815 | order to read its symbol table and in order to start the program. To | |
816 | debug a core dump of a previous run, GDB must be told the file name of | |
817 | the core dump. | |
e91b87a3 | 818 | |
819 | @menu | |
820 | * Arguments: File Arguments. Specifying files with arguments | |
821 | (when you start GDB). | |
822 | * Commands: File Commands. Specifying files with GDB commands. | |
823 | @end menu | |
824 | ||
825 | @node File Arguments, File Commands, Files, Files | |
826 | @section Specifying Files with Arguments | |
827 | ||
828 | The usual way to specify the executable and core dump file names is with | |
829 | two command arguments given when you start GDB. The first argument is used | |
830 | as the file for execution and symbols, and the second argument (if any) is | |
831 | used as the core dump file name. Thus, | |
832 | ||
833 | @example | |
834 | gdb progm core | |
835 | @end example | |
836 | ||
837 | @noindent | |
838 | specifies @file{progm} as the executable program and @file{core} as a core | |
839 | dump file to examine. (You do not need to have a core dump file if what | |
840 | you plan to do is debug the program interactively.) | |
841 | ||
4187119d | 842 | @xref{Options}, for full information on options and arguments for |
843 | invoking GDB. | |
e91b87a3 | 844 | |
845 | @node File Commands,, File Arguments, Files | |
846 | @section Specifying Files with Commands | |
847 | ||
848 | Usually you specify the files for GDB to work with by giving arguments when | |
849 | you invoke GDB. But occasionally it is necessary to change to a different | |
850 | file during a GDB session. Or you may run GDB and forget to specify the | |
851 | files you want to use. In these situations the GDB commands to specify new | |
852 | files are useful. | |
853 | ||
854 | @table @code | |
9c91ee3e RP |
855 | @item file @var{filename} |
856 | @kindex file | |
857 | Use @var{file} as the program to be debugged. It is read for its | |
858 | symbols, for getting the contents of pure memory, and it is the program | |
859 | executed when you use the @samp{run} command. If you do not specify a | |
860 | directory and the file is not found in GDB's working directory, GDB will | |
861 | use the environment variable @code{PATH} as a list of directories to | |
862 | search, just as the shell does when looking for a program to run. | |
863 | ||
864 | @samp{file} with no argument makes both executable file and symbol | |
865 | table become unspecified. | |
866 | ||
e91b87a3 | 867 | @item exec-file @var{filename} |
868 | @kindex exec-file | |
9c91ee3e RP |
869 | Specify that the program to be run (but not the symbol table) is found |
870 | in @var{filename}. GDB will search the environment variable @code{PATH} | |
871 | if necessary to locate the program. | |
e91b87a3 | 872 | |
873 | @item symbol-file @var{filename} | |
874 | @kindex symbol-file | |
9c91ee3e RP |
875 | Read symbol table information from file @var{filename}. @code{PATH} is |
876 | searched when necessary. Use the @samp{file} command to get both symbol | |
877 | table and program to run from the same file. | |
e91b87a3 | 878 | |
879 | @samp{symbol-file} with no argument clears out GDB's symbol table. | |
880 | ||
9da601bf RP |
881 | The @samp{symbol-file} command causes GDB to forget the contents of its |
882 | convenience variables, the value history, and all breakpoints and | |
883 | auto-display expressions. This is because they may contain pointers to the | |
884 | internal data recording symbols and data types, which are part of the old | |
885 | symbol table data being discarded inside GDB. | |
886 | ||
9c91ee3e RP |
887 | On some systems, the @samp{symbol-file} command does not actually read |
888 | the symbol table in full right away. Instead, it scans the symbol table | |
889 | quickly to find which source files and which symbols are present. The | |
890 | details are read later, one source file at a time, when they are needed. | |
4187119d | 891 | |
892 | The purpose of this two-stage reading strategy is to make GDB start up | |
9c91ee3e RP |
893 | faster. For the most part, it is invisible except for occasional pauses |
894 | while the symbol table details for a particular source file are being | |
895 | read. (The @samp{set verbose} command can turn these pauses into | |
896 | messages if desired. @xref{User Interface}). | |
4187119d | 897 | |
898 | When the symbol table is stored in COFF format, @samp{symbol-file} does | |
9da601bf RP |
899 | read the symbol table data in full right away. We haven't implemented |
900 | the two-stage strategy for COFF yet. | |
4187119d | 901 | |
9da601bf | 902 | @item core-file @var{filename} |
9c91ee3e | 903 | @kindex core |
9da601bf RP |
904 | @itemx core @var{filename} |
905 | @kindex core-file | |
e91b87a3 | 906 | Specify the whereabouts of a core dump file to be used as the |
907 | ``contents of memory''. Note that the core dump contains only the | |
908 | writable parts of memory; the read-only parts must come from the | |
909 | executable file. | |
910 | ||
911 | @samp{core-file} with no argument specifies that no core file is | |
912 | to be used. | |
913 | ||
4187119d | 914 | Note that the core file is ignored when your program is actually running |
915 | under GDB. So, if you have been running the program and you wish to | |
916 | debug a core file instead, you must kill the subprocess in which the | |
917 | program is running. To do this, use the @samp{kill} command | |
918 | (@pxref{Kill Process}). | |
919 | ||
e91b87a3 | 920 | @item add-file @var{filename} @var{address} |
9c91ee3e | 921 | @itemx load @var{filename} @var{address} |
e91b87a3 | 922 | @kindex add-file |
9c91ee3e | 923 | @kindex load |
4187119d | 924 | @cindex dynamic linking |
925 | The @samp{add-file} command reads additional symbol table information | |
9da601bf RP |
926 | from the file @var{filename}. You would use this command when that file |
927 | has been dynamically loaded into the program that is running. | |
928 | @var{address} should be the memory address at which the file has been | |
929 | loaded; GDB cannot figure this out for itself. | |
4187119d | 930 | |
9c91ee3e RP |
931 | When debugging with some targets (@pxref{Targets}), this command will |
932 | also cause the file to be dynamically loaded into the target system. | |
933 | @comment FIXME: "some" is obnoxious. Currently this is only VxWorks. | |
934 | @comment ---pesch 18dec1990 | |
935 | ||
4187119d | 936 | The symbol table of the file @var{filename} is added to the symbol table |
937 | originally read with the @samp{symbol-file} command. You can use the | |
938 | @samp{add-file} command any number of times; the new symbol data thus | |
939 | read keeps adding to the old. The @samp{symbol-file} command forgets | |
9c91ee3e | 940 | all the symbol data GDB has read. |
e91b87a3 | 941 | |
942 | @item info files | |
943 | @kindex info files | |
944 | Print the names of the executable and core dump files currently in | |
9da601bf | 945 | use by GDB, and the files from which symbols were loaded, as well as the |
9c91ee3e RP |
946 | stack of current targets (@pxref{Targets}). |
947 | ||
948 | @end table | |
e91b87a3 | 949 | |
950 | While all three file-specifying commands allow both absolute and relative | |
951 | file names as arguments, GDB always converts the file name to an absolute | |
952 | one and remembers it that way. | |
953 | ||
9da601bf | 954 | @kindex sharedlibrary |
96a816c5 JG |
955 | @kindex share |
956 | @cindex shared libraries | |
957 | ||
9c91ee3e | 958 | GDB supports the SunOS shared library format. Symbols from a shared |
96a816c5 JG |
959 | library cannot be referenced before the shared library has been linked |
960 | with the program. (That is to say, after one types @samp{run} and | |
9c91ee3e RP |
961 | the function @code{main()} has been entered; or when examining core |
962 | files.) Once the shared library has been linked in, you can use the | |
963 | following commands: | |
96a816c5 | 964 | |
9c91ee3e RP |
965 | @table @code |
966 | @item sharedlibrary @var{regex} | |
967 | @itemx share @var{regex} | |
96a816c5 JG |
968 | Load shared object library symbols for files matching a UNIX regular |
969 | expresssion. | |
970 | ||
9c91ee3e RP |
971 | @item share |
972 | @itemx sharedlibrary | |
96a816c5 JG |
973 | Load symbols for all shared libraries. |
974 | ||
9c91ee3e RP |
975 | @item info share |
976 | @itemx info sharedlibrary | |
96a816c5 | 977 | @kindex info sharedlibrary |
9c91ee3e | 978 | @kindex info share |
96a816c5 | 979 | Print the names of the shared libraries which are currently loaded. |
6ad6aa52 | 980 | @end table |
96a816c5 JG |
981 | |
982 | ||
9c91ee3e | 983 | @node Compilation, Targets, Files, Top |
e91b87a3 | 984 | @chapter Compiling Your Program for Debugging |
985 | ||
986 | In order to debug a program effectively, you need to ask for debugging | |
9da601bf RP |
987 | information when you compile it. This debugging information is stored |
988 | in the object file; it describes the data type of each variable or | |
989 | function and the correspondence between source line numbers and | |
990 | addresses in the executable code. | |
e91b87a3 | 991 | |
992 | To request debugging information, specify the @samp{-g} option when you run | |
993 | the compiler. | |
994 | ||
995 | The Unix C compiler is unable to handle the @samp{-g} and @samp{-O} options | |
996 | together. This means that you cannot ask for optimization if you ask for | |
997 | debugger information. | |
998 | ||
999 | The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it | |
1000 | possible to debug optimized code. We recommend that you @emph{always} use | |
1001 | @samp{-g} whenever you compile a program. You may think the program is | |
1002 | correct, but there's no sense in pushing your luck. | |
1003 | ||
9c91ee3e RP |
1004 | Some things do not work as well with @samp{-g -O} as with just |
1005 | @samp{-g}, particularly on machines with instruction scheduling. If in | |
1006 | doubt, recompile with @samp{-g} alone, and if this fixes the problem, | |
1007 | please report it as a bug (including a test case---@pxref{GDB Bugs}). | |
1008 | ||
1009 | Older versions of the GNU C compiler, GCC, permitted a variant option | |
1010 | @samp{-gg} for debugging information. GDB no longer supports this format; | |
1011 | if your GNU C compiler has this option, do not use it. | |
e91b87a3 | 1012 | |
1c997a4a | 1013 | @ignore |
1014 | @comment As far as I know, there are no cases in which GDB will | |
1015 | @comment produce strange output in this case. (but no promises). | |
4187119d | 1016 | If your program includes archives made with the @code{ar} program, and |
1017 | if the object files used as input to @code{ar} were compiled without the | |
1018 | @samp{-g} option and have names longer than 15 characters, GDB will get | |
1019 | confused reading the program's symbol table. No error message will be | |
1020 | given, but GDB may behave strangely. The reason for this problem is a | |
1021 | deficiency in the Unix archive file format, which cannot represent file | |
1022 | names longer than 15 characters. | |
e91b87a3 | 1023 | |
4187119d | 1024 | To avoid this problem, compile the archive members with the @samp{-g} |
1025 | option or use shorter file names. Alternatively, use a version of GNU | |
1026 | @code{ar} dated more recently than August 1989. | |
1c997a4a | 1027 | @end ignore |
e91b87a3 | 1028 | |
9c91ee3e RP |
1029 | @node Targets, Running, Compilation, Top |
1030 | @chapter Specifying a Debugging Target | |
1031 | @cindex debugging target | |
1032 | @kindex target | |
1033 | Often, you will be able to run GDB in the same host environment as the | |
1034 | program you are debugging; in that case, the debugging target is | |
1035 | specified as a side effect of the @samp{file} or @samp{core} commands. | |
1036 | When you need more flexibility---for example, running GDB on a | |
1037 | physically separate host, controlling standalone systems over a | |
1038 | serial port, or realtime systems over a TCP/IP connection---you can use | |
1039 | the @samp{target} command. | |
1040 | ||
1041 | @table @code | |
1042 | @item target @var{type} @var{parameters} | |
1043 | Connects the GDB host environment to a target machine or process. A | |
1044 | target is typically a protocol for talking to debugging facilities. You | |
1045 | use the argument @var{type} to specify the type or protocol of the | |
1046 | target machine; for example, @samp{target child} for Unix child processes, or | |
1047 | @samp{target vxworks} for a TCP/IP link to a VxWorks system. | |
1048 | ||
1049 | Further @var{parameters} are interpreted by the target protocol, but | |
1050 | typically include things like device names or host names to connect | |
1051 | with, process numbers, and baud rates. Executing | |
1052 | @example | |
1053 | target @var{type} | |
1054 | @end example | |
1055 | ||
1056 | @noindent{}(without any parameters) will issue a message about what | |
1057 | parameters are required for that target type. | |
1058 | ||
1059 | @end table | |
1060 | ||
1061 | Targets are managed as a stack, so that you may (for example) specify | |
1062 | a core file as a target without abandoning a running program; when | |
1063 | you're done with the core file, you can return to the previous target | |
1064 | using @samp{detach}. The related command @samp{attach} provides you | |
1065 | with an alternative way of stacking a new target. @xref{Attach}. | |
1066 | ||
1067 | @table @code | |
1068 | @item info targets | |
1069 | Displays the names of all targets available. | |
1070 | @end table | |
1071 | ||
1072 | To display the targets currently stacked, use the @samp{info files} | |
1073 | command (@pxref{File Commands}). | |
1074 | ||
1075 | @node Running, Stopping, Targets, Top | |
e91b87a3 | 1076 | @chapter Running Your Program Under GDB |
1077 | ||
1078 | @cindex running | |
1079 | @kindex run | |
9c91ee3e RP |
1080 | To start your program under GDB, use the @samp{run} command. Except on |
1081 | VxWorks, the program must already have been specified using the | |
1082 | @samp{file} or @samp{exec-file} command, or with an argument to GDB | |
1083 | (@pxref{Files}); what @samp{run} does is create an inferior process, | |
9da601bf | 1084 | load the program into it, and allow it to execute. |
e91b87a3 | 1085 | |
4187119d | 1086 | The execution of a program is affected by certain information it |
1087 | receives from its superior. GDB provides ways to specify this | |
1088 | information, which you must do @i{before} starting the program. (You | |
1089 | can change it after starting the program, but such changes do not affect | |
1090 | the program unless you start it over again.) This information may be | |
1091 | divided into three categories: | |
e91b87a3 | 1092 | |
1093 | @table @asis | |
1094 | @item The @i{arguments.} | |
1095 | You specify the arguments to give the program as the arguments of the | |
4187119d | 1096 | @samp{run} command. |
e91b87a3 | 1097 | |
1098 | @item The @i{environment.} | |
1099 | The program normally inherits its environment from GDB, but you can | |
1100 | use the GDB commands @samp{set environment} and | |
1101 | @samp{unset environment} to change parts of the environment that will | |
1102 | be given to the program.@refill | |
1103 | ||
1104 | @item The @i{working directory.} | |
1105 | The program inherits its working directory from GDB. You can set GDB's | |
1106 | working directory with the @samp{cd} command in GDB. | |
1107 | @end table | |
1108 | ||
9c91ee3e RP |
1109 | When you issue the @samp{run} command, your program begins to execute |
1110 | immediately. @xref{Stopping}, for discussion of how to arrange for your | |
1111 | program to stop. | |
e91b87a3 | 1112 | |
1113 | Note that once your program has been started by the @samp{run} command, | |
1114 | you may evaluate expressions that involve calls to functions in the | |
9c91ee3e RP |
1115 | inferior, using the @samp{print} or @samp{call} commands. @xref{Data}. |
1116 | ||
1117 | If your program's timestamp has changed since the last time GDB read its | |
1118 | symbols, GDB will discard its symbol table and re-read it from your | |
1119 | program. In this process, it tries to retain your current breakpoints. | |
e91b87a3 | 1120 | |
1121 | @menu | |
1122 | * Arguments:: Specifying the arguments for your program. | |
1123 | * Environment:: Specifying the environment for your program. | |
1124 | * Working Directory:: Specifying the working directory for giving | |
1125 | to your program when it is run. | |
1126 | * Input/Output:: Specifying the program's standard input and output. | |
1127 | * Attach:: Debugging a process started outside GDB. | |
4187119d | 1128 | * Kill Process:: Getting rid of the child process running your program. |
e91b87a3 | 1129 | @end menu |
1130 | ||
1131 | @node Arguments, Environment, Running, Running | |
1132 | @section Your Program's Arguments | |
1133 | ||
1134 | @cindex arguments (to your program) | |
4187119d | 1135 | The arguments to your program are specified by the arguments of the |
e91b87a3 | 1136 | @samp{run} command. They are passed to a shell, which expands wildcard |
1137 | characters and performs redirection of I/O, and thence to the program. | |
1138 | ||
1139 | @samp{run} with no arguments uses the same arguments used by the previous | |
1140 | @samp{run}. | |
1141 | ||
1142 | @kindex set args | |
9da601bf RP |
1143 | @table @code |
1144 | @item set args | |
e91b87a3 | 1145 | The command @samp{set args} can be used to specify the arguments to be used |
1146 | the next time the program is run. If @samp{set args} has no arguments, it | |
1147 | means to use no arguments the next time the program is run. If you have | |
1148 | run your program with arguments and want to run it again with no arguments, | |
1149 | this is the only way to do so. | |
1150 | ||
9da601bf RP |
1151 | @item show args |
1152 | @kindex show args | |
1153 | Show the arguments to give your program when it is started. | |
1154 | @end table | |
1155 | ||
e91b87a3 | 1156 | @node Environment, Working Directory, Arguments, Running |
1157 | @section Your Program's Environment | |
1158 | ||
1159 | @cindex environment (of your program) | |
1160 | The @dfn{environment} consists of a set of @dfn{environment variables} and | |
1161 | their values. Environment variables conventionally record such things as | |
1162 | your user name, your home directory, your terminal type, and your search | |
1163 | path for programs to run. Usually you set up environment variables with | |
1164 | the shell and they are inherited by all the other programs you run. When | |
1165 | debugging, it can be useful to try running the program with different | |
1166 | environments without having to start the debugger over again. | |
1167 | ||
1168 | @table @code | |
1169 | @item info environment @var{varname} | |
1170 | @kindex info environment | |
1171 | Print the value of environment variable @var{varname} to be given to | |
1172 | your program when it is started. This command can be abbreviated | |
1173 | @samp{i env @var{varname}}. | |
1174 | ||
1175 | @item info environment | |
1176 | Print the names and values of all environment variables to be given to | |
1177 | your program when it is started. This command can be abbreviated | |
1178 | @samp{i env}. | |
1179 | ||
1180 | @item set environment @var{varname} @var{value} | |
4187119d | 1181 | @itemx set environment @var{varname} = @var{value} |
e91b87a3 | 1182 | @kindex set environment |
1183 | Sets environment variable @var{varname} to @var{value}, for your program | |
1184 | only, not for GDB itself. @var{value} may be any string; the values of | |
1185 | environment variables are just strings, and any interpretation is | |
1186 | supplied by your program itself. The @var{value} parameter is optional; | |
1187 | if it is eliminated, the variable is set to a null value. This command | |
9c91ee3e | 1188 | can be abbreviated as @samp{set e}. |
e91b87a3 | 1189 | |
4187119d | 1190 | For example, this command: |
1191 | ||
1192 | @example | |
1193 | set env USER = foo | |
1194 | @end example | |
1195 | ||
1196 | @noindent | |
1197 | tells the program, when subsequently run, to assume it is being run | |
1198 | on behalf of the user named @samp{foo}. | |
1199 | ||
e91b87a3 | 1200 | @item delete environment @var{varname} |
4187119d | 1201 | @itemx unset environment @var{varname} |
e91b87a3 | 1202 | @kindex delete environment |
e91b87a3 | 1203 | @kindex unset environment |
4187119d | 1204 | Remove variable @var{varname} from the environment to be passed to your |
9da601bf RP |
1205 | program. This is different from @samp{set env @var{varname}@ =}; |
1206 | @samp{delete environment} removes the variable from the environment, | |
1207 | rather than assigning it an empty value. This command can be | |
1208 | abbreviated @samp{d e}. | |
e91b87a3 | 1209 | @end table |
1210 | ||
1211 | @node Working Directory, Input/Output, Environment, Running | |
1212 | @section Your Program's Working Directory | |
1213 | ||
1214 | @cindex working directory (of your program) | |
4187119d | 1215 | Each time you start your program with @samp{run}, it inherits its |
1216 | working directory from the current working directory of GDB. GDB's | |
1217 | working directory is initially whatever it inherited from its parent | |
1218 | process (typically the shell), but you can specify a new working | |
1219 | directory in GDB with the @samp{cd} command. | |
e91b87a3 | 1220 | |
1221 | The GDB working directory also serves as a default for the commands | |
1222 | that specify files for GDB to operate on. @xref{Files}. | |
1223 | ||
1224 | @table @code | |
1225 | @item cd @var{directory} | |
1226 | @kindex cd | |
1227 | Set GDB's working directory to @var{directory}. | |
1228 | ||
1229 | @item pwd | |
1230 | @kindex pwd | |
1231 | Print GDB's working directory. | |
1232 | @end table | |
1233 | ||
1234 | @node Input/Output, Attach, Working Directory, Running | |
1235 | @section Your Program's Input and Output | |
1236 | ||
1237 | @cindex redirection | |
1238 | @cindex controlling terminal | |
1239 | By default, the program you run under GDB does input and output to the same | |
1240 | terminal that GDB uses. | |
1241 | ||
1242 | You can redirect the program's input and/or output using @samp{sh}-style | |
1243 | redirection commands in the @samp{run} command. For example, | |
1244 | ||
1245 | @example | |
1246 | run > outfile | |
1247 | @end example | |
1248 | ||
1249 | @noindent | |
1250 | starts the program, diverting its output to the file @file{outfile}. | |
1251 | ||
1252 | @kindex tty | |
4187119d | 1253 | Another way to specify where the program should do input and output is |
1254 | with the @samp{tty} command. This command accepts a file name as | |
1255 | argument, and causes this file to be the default for future @samp{run} | |
1256 | commands. It also resets the controlling terminal for the child | |
1257 | process, for future @samp{run} commands. For example, | |
e91b87a3 | 1258 | |
1259 | @example | |
1260 | tty /dev/ttyb | |
1261 | @end example | |
1262 | ||
1263 | @noindent | |
4187119d | 1264 | directs that processes started with subsequent @samp{run} commands |
1265 | default to do input and output on the terminal @file{/dev/ttyb} and have | |
1266 | that as their controlling terminal. | |
1267 | ||
1268 | An explicit redirection in @samp{run} overrides the @samp{tty} command's | |
1269 | effect on input/output redirection, but not its effect on the | |
1270 | controlling terminal. | |
e91b87a3 | 1271 | |
1272 | When you use the @samp{tty} command or redirect input in the @samp{run} | |
4187119d | 1273 | command, only the @emph{input for your program} is affected. The input |
1274 | for GDB still comes from your terminal. | |
e91b87a3 | 1275 | |
4187119d | 1276 | @node Attach, Kill Process, Input/Output, Running |
e91b87a3 | 1277 | @section Debugging an Already-Running Process |
1278 | @kindex detach | |
1279 | @kindex attach | |
1280 | @cindex attach | |
1281 | ||
9c91ee3e RP |
1282 | @table @code |
1283 | @item attach @var{process--id} | |
1284 | @itemx attach @var{device} | |
1285 | This command attaches to another target, of the same type as your last | |
1286 | @samp{target} command (@samp{info files} will show your target stack). | |
1287 | The command may take as argument a process ID or a device file. | |
1288 | ||
1289 | You specify a process ID to debug an already-running process that was | |
1290 | started outside of GDB. (The usual way to find out the process-id of | |
1291 | the process is with the @code{ps} utility, or with the @code{jobs -l} | |
1292 | shell command.) In this case, you must have permission to send the | |
1293 | process a signal, and it must have the same effective user ID as the | |
1294 | debugger. | |
1295 | @end table | |
e91b87a3 | 1296 | |
9c91ee3e RP |
1297 | When using @samp{attach}, you should first use the @samp{file} command |
1298 | to specify the program running in the process and load its symbol table. | |
e91b87a3 | 1299 | |
1300 | The first thing GDB does after arranging to debug the process is to stop | |
1301 | it. You can examine and modify an attached process with all the GDB | |
1302 | commands that ordinarily available when you start processes with | |
1303 | @samp{run}. You can insert breakpoints; you can step and continue; you | |
1304 | can modify storage. If you would rather the process continue running, | |
4187119d | 1305 | you may use the @samp{continue} command after attaching GDB to the |
1306 | process. | |
e91b87a3 | 1307 | |
4187119d | 1308 | When you have finished debugging the attached process, you can use the |
e91b87a3 | 1309 | @samp{detach} command to release it from GDB's control. Detaching |
1310 | the process continues its execution. After the @samp{detach} command, | |
1311 | that process and GDB become completely independent once more, and you | |
1312 | are ready to @samp{attach} another process or start one with @samp{run}. | |
1313 | ||
1314 | If you exit GDB or use the @samp{run} command while you have an attached | |
9c91ee3e RP |
1315 | process, you kill that process. By default, you will be asked for |
1316 | confirmation if you try to do either of these things; you can control | |
1317 | whether or not this happens by using the @samp{set stupidity} command | |
1318 | (@pxref{User Interface}). | |
e91b87a3 | 1319 | |
4187119d | 1320 | The @samp{attach} command is also used to debug a remote machine via a |
831c8511 | 1321 | serial connection. @xref{Remote}, for more info. |
4187119d | 1322 | |
1323 | @node Kill Process,, Attach, Running | |
1324 | @section Killing the Child Process | |
1325 | ||
1326 | @table @code | |
1327 | @item kill | |
1328 | @kindex kill | |
9da601bf | 1329 | Kill the child process in which your program is running under GDB. |
9c91ee3e | 1330 | @end table |
4187119d | 1331 | |
1332 | This command is useful if you wish to debug a core dump instead. GDB | |
9da601bf | 1333 | ignores any core dump file if it is actually running the program. |
4187119d | 1334 | |
9c91ee3e | 1335 | On some operating systems, you can't execute your program in another |
9da601bf RP |
1336 | process while breakpoints are active inside GDB. The @samp{kill} |
1337 | command is also useful in this situation, if you wish to run the program | |
1338 | outside the debugger. | |
4187119d | 1339 | |
1340 | The @samp{kill} command is also useful if you wish to recompile and | |
1341 | relink the program, since on many systems it is impossible to modify an | |
9c91ee3e RP |
1342 | executable file which is running in a process. In this case, when you |
1343 | next type @samp{run}, GDB will notice that the file has changed, and | |
1344 | will re-read the symbol table (while trying to preserve your current | |
1345 | breakpoint settings). | |
4187119d | 1346 | |
e91b87a3 | 1347 | @node Stopping, Stack, Running, Top |
1348 | @chapter Stopping and Continuing | |
1349 | ||
4187119d | 1350 | When you run a program normally, it runs until it terminates. The |
1351 | principal purpose of using a debugger is so that you can stop it before | |
1352 | that point; or so that if the program runs into trouble you can | |
1353 | investigate and find out why. | |
e91b87a3 | 1354 | |
1355 | @menu | |
1356 | * Signals:: Fatal signals in your program just stop it; | |
1357 | then you can use GDB to see what is going on. | |
1358 | * Breakpoints:: Breakpoints let you stop your program when it | |
1359 | reaches a specified point in the code. | |
96a816c5 | 1360 | an expression changes. |
e91b87a3 | 1361 | * Continuing:: Resuming execution until the next signal or breakpoint. |
1362 | * Stepping:: Stepping runs the program a short distance and | |
1363 | then stops it wherever it has come to. | |
1364 | @end menu | |
1365 | ||
1366 | @node Signals, Breakpoints, Stopping, Stopping | |
1367 | @section Signals | |
4187119d | 1368 | @cindex signals |
e91b87a3 | 1369 | |
1370 | A signal is an asynchronous event that can happen in a program. The | |
1371 | operating system defines the possible kinds of signals, and gives each kind | |
1372 | a name and a number. For example, @code{SIGINT} is the signal a program | |
1373 | gets when you type @kbd{Ctrl-c}; @code{SIGSEGV} is the signal a program | |
1374 | gets from referencing a place in memory far away from all the areas in use; | |
1375 | @code{SIGALRM} occurs when the alarm clock timer goes off (which happens | |
1376 | only if the program has requested an alarm). | |
1377 | ||
4187119d | 1378 | @cindex fatal signals |
e91b87a3 | 1379 | Some signals, including @code{SIGALRM}, are a normal part of the |
1380 | functioning of the program. Others, such as @code{SIGSEGV}, indicate | |
1381 | errors; these signals are @dfn{fatal} (kill the program immediately) if the | |
1382 | program has not specified in advance some other way to handle the signal. | |
1383 | @code{SIGINT} does not indicate an error in the program, but it is normally | |
1384 | fatal so it can carry out the purpose of @kbd{Ctrl-c}: to kill the program. | |
1385 | ||
1386 | GDB has the ability to detect any occurrence of a signal in the program | |
1387 | running under GDB's control. You can tell GDB in advance what to do for | |
1388 | each kind of signal. | |
1389 | ||
4187119d | 1390 | @cindex handling signals |
e91b87a3 | 1391 | Normally, GDB is set up to ignore non-erroneous signals like @code{SIGALRM} |
1392 | (so as not to interfere with their role in the functioning of the program) | |
1393 | but to stop the program immediately whenever an error signal happens. | |
831c8511 | 1394 | You can change these settings with the @samp{handle} command. |
e91b87a3 | 1395 | |
1396 | @table @code | |
1397 | @item info signal | |
1398 | @kindex info signal | |
1399 | Print a table of all the kinds of signals and how GDB has been told to | |
1400 | handle each one. You can use this to see the signal numbers of all | |
1401 | the defined types of signals. | |
1402 | ||
831c8511 | 1403 | @item handle @var{signal} @var{keywords}@dots{} |
e91b87a3 | 1404 | @kindex handle |
831c8511 JG |
1405 | Change the way GDB handles signal @var{signal}. @var{signal} can be the |
1406 | number of a signal or its name (with or without the @samp{SIG} at the | |
1407 | beginning). The @var{keywords} say what change to make. | |
e91b87a3 | 1408 | @end table |
1409 | ||
9da601bf RP |
1410 | The keywords allowed by the @samp{handle} command can be abbreviated. |
1411 | Their full names are | |
e91b87a3 | 1412 | |
1413 | @table @code | |
9da601bf RP |
1414 | @item nostop |
1415 | GDB should not stop the program when this signal happens. It may | |
1416 | still print a message telling you that the signal has come in. | |
1417 | ||
e91b87a3 | 1418 | @item stop |
1419 | GDB should stop the program when this signal happens. This implies | |
1420 | the @samp{print} keyword as well. | |
1421 | ||
1422 | @item print | |
1423 | GDB should print a message when this signal happens. | |
1424 | ||
e91b87a3 | 1425 | @item noprint |
1426 | GDB should not mention the occurrence of the signal at all. This | |
1427 | implies the @samp{nostop} keyword as well. | |
1428 | ||
1429 | @item pass | |
1430 | GDB should allow the program to see this signal; the program will be | |
1431 | able to handle the signal, or may be terminated if the signal is fatal | |
1432 | and not handled. | |
1433 | ||
1434 | @item nopass | |
1435 | GDB should not allow the program to see this signal. | |
1436 | @end table | |
1437 | ||
1438 | When a signal has been set to stop the program, the program cannot see the | |
1439 | signal until you continue. It will see the signal then, if @samp{pass} is | |
1440 | in effect for the signal in question @i{at that time}. In other words, | |
1441 | after GDB reports a signal, you can use the @samp{handle} command with | |
1442 | @samp{pass} or @samp{nopass} to control whether that signal will be seen by | |
1443 | the program when you later continue it. | |
1444 | ||
1445 | You can also use the @samp{signal} command to prevent the program from | |
1446 | seeing a signal, or cause it to see a signal it normally would not see, | |
1447 | or to give it any signal at any time. @xref{Signaling}. | |
1448 | ||
96a816c5 | 1449 | @node Breakpoints, Watchpoints Continuing, Signals, Stopping |
e91b87a3 | 1450 | @section Breakpoints |
1451 | ||
1452 | @cindex breakpoints | |
1453 | A @dfn{breakpoint} makes your program stop whenever a certain point in the | |
1454 | program is reached. You set breakpoints explicitly with GDB commands, | |
1455 | specifying the place where the program should stop by line number, function | |
1456 | name or exact address in the program. You can add various other conditions | |
1457 | to control whether the program will stop. | |
1458 | ||
1459 | Each breakpoint is assigned a number when it is created; these numbers are | |
1460 | successive integers starting with 1. In many of the commands for controlling | |
1461 | various features of breakpoints you use the breakpoint number to say which | |
1462 | breakpoint you want to change. Each breakpoint may be @dfn{enabled} or | |
1463 | @dfn{disabled}; if disabled, it has no effect on the program until you | |
1464 | enable it again. | |
1465 | ||
9c91ee3e | 1466 | @table @code |
e91b87a3 | 1467 | @kindex info break |
1468 | @kindex $_ | |
9c91ee3e | 1469 | @item info break |
e91b87a3 | 1470 | The command @samp{info break} prints a list of all breakpoints set and not |
4187119d | 1471 | deleted, showing their numbers, where in the program they are, and any |
e91b87a3 | 1472 | special features in use for them. Disabled breakpoints are included in the |
1473 | list, but marked as disabled. @samp{info break} with a breakpoint number | |
4187119d | 1474 | as argument lists only that breakpoint. The convenience variable @code{$_} |
e91b87a3 | 1475 | and the default examining-address for the @samp{x} command are set to the |
1476 | address of the last breakpoint listed (@pxref{Memory}). | |
1477 | ||
96a816c5 JG |
1478 | @kindex info watch |
1479 | @item info watch | |
1480 | This command prints a list of watchpoints. | |
9c91ee3e RP |
1481 | |
1482 | @cindex watchpoints | |
1483 | A @dfn{watchpoint} is a special breakpoint that stops your program when | |
1484 | the value of an expression changes. You can use a watchpoint to stop | |
1485 | execution whenever the value of an expression changes, without having to | |
1486 | predict a particular place in the inferior process where this may | |
1487 | happen. Aside from the different syntax in setting a watchpoint, it is | |
1488 | managed exactly like any other breakpoint and is enabled, disabled, and | |
9da601bf | 1489 | deleted using exactly the same commands. |
9c91ee3e | 1490 | |
9da601bf RP |
1491 | Watchpoints currently execute two orders of magnitude more slowly than |
1492 | other breakpoints, but this can well be worth it to catch errors where | |
1493 | you have no clue what part of your program is the culprit. Some | |
1494 | processors provide special hardware to implement this feature; future | |
1495 | releases of GDB will use such hardware if it is available. | |
9c91ee3e | 1496 | |
6ad6aa52 | 1497 | @end table |
96a816c5 | 1498 | |
e91b87a3 | 1499 | @menu |
1500 | * Set Breaks:: How to establish breakpoints. | |
4187119d | 1501 | * Delete Breaks:: How to remove breakpoints no longer needed. |
e91b87a3 | 1502 | * Disabling:: How to disable breakpoints (turn them off temporarily). |
1503 | * Conditions:: Making extra conditions on whether to stop. | |
1504 | * Break Commands:: Commands to be executed at a breakpoint. | |
1505 | * Error in Breakpoints:: "Cannot insert breakpoints" error--why, what to do. | |
1506 | @end menu | |
1507 | ||
4187119d | 1508 | @node Set Breaks, Delete Breaks, Breakpoints, Breakpoints |
e91b87a3 | 1509 | @subsection Setting Breakpoints |
1510 | ||
1511 | @kindex break | |
96a816c5 | 1512 | @kindex watch |
e91b87a3 | 1513 | Breakpoints are set with the @samp{break} command (abbreviated @samp{b}). |
96a816c5 JG |
1514 | Watchpoints are set with the @samp{watch} command. |
1515 | ||
e91b87a3 | 1516 | You have several ways to say where the breakpoint should go. |
1517 | ||
1518 | @table @code | |
1519 | @item break @var{function} | |
1520 | Set a breakpoint at entry to function @var{function}. | |
1521 | ||
4187119d | 1522 | @item break @var{+offset} |
1523 | @itemx break @var{-offset} | |
1524 | Set a breakpoint some number of lines forward or back from the position | |
1525 | at which execution stopped in the currently selected frame. | |
1526 | ||
e91b87a3 | 1527 | @item break @var{linenum} |
1528 | Set a breakpoint at line @var{linenum} in the current source file. | |
1529 | That file is the last file whose source text was printed. This | |
1530 | breakpoint will stop the program just before it executes any of the | |
1531 | code on that line. | |
1532 | ||
1533 | @item break @var{filename}:@var{linenum} | |
1534 | Set a breakpoint at line @var{linenum} in source file @var{filename}. | |
1535 | ||
1536 | @item break @var{filename}:@var{function} | |
1537 | Set a breakpoint at entry to function @var{function} found in file | |
4187119d | 1538 | @var{filename}. Specifying a file name as well as a function name is |
e91b87a3 | 1539 | superfluous except when multiple files contain similarly named |
1540 | functions. | |
1541 | ||
1542 | @item break *@var{address} | |
1543 | Set a breakpoint at address @var{address}. You can use this to set | |
1544 | breakpoints in parts of the program which do not have debugging | |
1545 | information or source files. | |
1546 | ||
1547 | @item break | |
1548 | Set a breakpoint at the next instruction to be executed in the selected | |
1549 | stack frame (@pxref{Stack}). In any selected frame but the innermost, | |
1550 | this will cause the program to stop as soon as control returns to that | |
1551 | frame. This is equivalent to a @samp{finish} command in the frame | |
4187119d | 1552 | inside the selected frame. If this is done in the innermost frame, GDB |
e91b87a3 | 1553 | will stop the next time it reaches the current location; this may be |
4187119d | 1554 | useful inside of loops. |
1555 | ||
1556 | GDB normally ignores breakpoints when it resumes execution, until at | |
1557 | least one instruction has been executed. If it did not do this, you | |
1558 | would be unable to proceed past a breakpoint without first disabling the | |
1559 | breakpoint. This rule applies whether or not the breakpoint already | |
1560 | existed when the program stopped. | |
e91b87a3 | 1561 | |
1562 | @item break @dots{} if @var{cond} | |
1563 | Set a breakpoint with condition @var{cond}; evaluate the expression | |
1564 | @var{cond} each time the breakpoint is reached, and stop only if the | |
1565 | value is nonzero. @samp{@dots{}} stands for one of the possible | |
1566 | arguments described above (or no argument) specifying where to break. | |
1567 | @xref{Conditions}, for more information on breakpoint conditions. | |
1568 | ||
1569 | @item tbreak @var{args} | |
1570 | @kindex tbreak | |
1571 | Set a breakpoint enabled only for one stop. @var{args} are the | |
1572 | same as in the @samp{break} command, and the breakpoint is set in the same | |
4187119d | 1573 | way, but the breakpoint is automatically disabled the first time it |
1574 | is hit. @xref{Disabling}. | |
96a816c5 | 1575 | |
6ad6aa52 RP |
1576 | @item rbreak @var{regex} |
1577 | @kindex rbreak | |
1578 | Set a breakpoint on all functions matching @var{regex}. This is | |
1579 | useful for setting breakpoints on overloaded functions that are not | |
1580 | members of any special classes. This command sets an unconditional | |
1581 | breakpoint on all matches, printing a list of all breakpoints it set. | |
1582 | Once these breakpoints are set, they are treated just like the | |
1583 | breakpoints set with the @samp{break} command. They can be deleted, | |
1584 | disabled, made conditional, etc., in the standard ways. | |
1585 | ||
96a816c5 | 1586 | @kindex watch |
9c91ee3e | 1587 | @item watch @var{expr} |
96a816c5 | 1588 | Set a watchpoint for an expression. |
e91b87a3 | 1589 | @end table |
1590 | ||
1591 | GDB allows you to set any number of breakpoints at the same place in the | |
1592 | program. There is nothing silly or meaningless about this. When the | |
1593 | breakpoints are conditional, this is even useful (@pxref{Conditions}). | |
1594 | ||
4187119d | 1595 | @node Delete Breaks, Disabling, Set Breaks, Breakpoints |
1596 | @subsection Deleting Breakpoints | |
e91b87a3 | 1597 | |
96a816c5 JG |
1598 | @cindex clearing breakpoints and watchpoints |
1599 | @cindex deleting breakpoints and watchpoints | |
e91b87a3 | 1600 | It is often necessary to eliminate a breakpoint once it has done its job |
1601 | and you no longer want the program to stop there. This is called | |
4187119d | 1602 | @dfn{deleting} the breakpoint. A breakpoint that has been deleted no |
1603 | longer exists in any sense; it is forgotten. | |
e91b87a3 | 1604 | |
4187119d | 1605 | With the @samp{clear} command you can delete breakpoints according to where |
1606 | they are in the program. With the @samp{delete} command you can delete | |
e91b87a3 | 1607 | individual breakpoints by specifying their breakpoint numbers. |
1608 | ||
9da601bf RP |
1609 | It is not necessary to delete a breakpoint to proceed past it. GDB |
1610 | automatically ignores breakpoints on the first instruction to be executed | |
4187119d | 1611 | when you continue execution without changing the execution address. |
e91b87a3 | 1612 | |
1613 | @table @code | |
1614 | @item clear | |
1615 | @kindex clear | |
4187119d | 1616 | Delete any breakpoints at the next instruction to be executed in the |
e91b87a3 | 1617 | selected stack frame (@pxref{Selection}). When the innermost frame |
4187119d | 1618 | is selected, this is a good way to delete a breakpoint that the program |
e91b87a3 | 1619 | just stopped at. |
1620 | ||
1621 | @item clear @var{function} | |
1622 | @itemx clear @var{filename}:@var{function} | |
4187119d | 1623 | Delete any breakpoints set at entry to the function @var{function}. |
e91b87a3 | 1624 | |
1625 | @item clear @var{linenum} | |
4187119d | 1626 | @itemx clear @var{filename}:@var{linenum} |
1627 | Delete any breakpoints set at or within the code of the specified line. | |
e91b87a3 | 1628 | |
9da601bf RP |
1629 | @item delete breakpoints @var{bnums}@dots{} |
1630 | @kindex delete breakpoints | |
1631 | @itemx delete @var{bnums}@dots{} | |
e91b87a3 | 1632 | @kindex delete |
1633 | Delete the breakpoints of the numbers specified as arguments. | |
e91b87a3 | 1634 | @end table |
1635 | ||
4187119d | 1636 | @node Disabling, Conditions, Delete Breaks, Breakpoints |
e91b87a3 | 1637 | @subsection Disabling Breakpoints |
1638 | ||
1639 | @cindex disabled breakpoints | |
1640 | @cindex enabled breakpoints | |
4187119d | 1641 | Rather than deleting a breakpoint, you might prefer to @dfn{disable} it. |
1642 | This makes the breakpoint inoperative as if it had been deleted, but | |
e91b87a3 | 1643 | remembers the information on the breakpoint so that you can @dfn{enable} |
1644 | it again later. | |
1645 | ||
1646 | You disable and enable breakpoints with the @samp{enable} and | |
1647 | @samp{disable} commands, specifying one or more breakpoint numbers as | |
1648 | arguments. Use @samp{info break} to print a list of breakpoints if you | |
1649 | don't know which breakpoint numbers to use. | |
1650 | ||
1651 | A breakpoint can have any of four different states of enablement: | |
1652 | ||
1653 | @itemize @bullet | |
1654 | @item | |
1655 | Enabled. The breakpoint will stop the program. A breakpoint made | |
1656 | with the @samp{break} command starts out in this state. | |
1657 | @item | |
1658 | Disabled. The breakpoint has no effect on the program. | |
1659 | @item | |
1660 | Enabled once. The breakpoint will stop the program, but | |
1661 | when it does so it will become disabled. A breakpoint made | |
1662 | with the @samp{tbreak} command starts out in this state. | |
1663 | @item | |
1664 | Enabled for deletion. The breakpoint will stop the program, but | |
1665 | immediately after it does so it will be deleted permanently. | |
1666 | @end itemize | |
1667 | ||
9c91ee3e | 1668 | You can use the following commands to enable or disable a breakpoint: |
e91b87a3 | 1669 | |
1670 | @table @code | |
1671 | @item disable breakpoints @var{bnums}@dots{} | |
4187119d | 1672 | @itemx disable @var{bnums}@dots{} |
e91b87a3 | 1673 | @kindex disable breakpoints |
e91b87a3 | 1674 | @kindex disable |
1675 | Disable the specified breakpoints. A disabled breakpoint has no | |
1676 | effect but is not forgotten. All options such as ignore-counts, | |
1677 | conditions and commands are remembered in case the breakpoint is | |
1678 | enabled again later. | |
1679 | ||
1680 | @item enable breakpoints @var{bnums}@dots{} | |
4187119d | 1681 | @itemx enable @var{bnums}@dots{} |
e91b87a3 | 1682 | @kindex enable breakpoints |
e91b87a3 | 1683 | @kindex enable |
1684 | Enable the specified breakpoints. They become effective once again in | |
1685 | stopping the program, until you specify otherwise. | |
1686 | ||
1687 | @item enable breakpoints once @var{bnums}@dots{} | |
4187119d | 1688 | @itemx enable once @var{bnums}@dots{} |
e91b87a3 | 1689 | Enable the specified breakpoints temporarily. Each will be disabled |
1690 | again the next time it stops the program (unless you have used one of | |
1691 | these commands to specify a different state before that time comes). | |
1692 | ||
1693 | @item enable breakpoints delete @var{bnums}@dots{} | |
4187119d | 1694 | @itemx enable delete @var{bnums}@dots{} |
e91b87a3 | 1695 | Enable the specified breakpoints to work once and then die. Each of |
1696 | the breakpoints will be deleted the next time it stops the program | |
1697 | (unless you have used one of these commands to specify a different | |
1698 | state before that time comes). | |
1699 | @end table | |
1700 | ||
9c91ee3e RP |
1701 | Save for a breakpoint set with @samp{tbreak} (@pxref{Set Breaks}, |
1702 | breakpoints that you set are enabled or disabled only when you use one | |
1703 | of the commands above. (The command @samp{until} can set and delete a | |
1704 | breakpoint on its own, but it will not change the state of your | |
1705 | breakpoints). | |
e91b87a3 | 1706 | |
1707 | @node Conditions, Break Commands, Disabling, Breakpoints | |
1708 | @subsection Break Conditions | |
4187119d | 1709 | @cindex conditional breakpoints |
1710 | @cindex breakpoint conditions | |
e91b87a3 | 1711 | |
e91b87a3 | 1712 | The simplest sort of breakpoint breaks every time the program reaches a |
4187119d | 1713 | specified place. You can also specify a @dfn{condition} for a |
1714 | breakpoint. A condition is just a boolean expression in your | |
1715 | programming language. (@xref{Expressions}). A breakpoint with a | |
1716 | condition evaluates the expression each time the program reaches it, and | |
1717 | the program stops only if the condition is true. | |
e91b87a3 | 1718 | |
1719 | Break conditions may have side effects, and may even call functions in your | |
1720 | program. These may sound like strange things to do, but their effects are | |
1721 | completely predictable unless there is another enabled breakpoint at the | |
1722 | same address. (In that case, GDB might see the other breakpoint first and | |
1723 | stop the program without checking the condition of this one.) Note that | |
1724 | breakpoint commands are usually more convenient and flexible for the | |
1725 | purpose of performing side effects when a breakpoint is reached | |
1726 | (@pxref{Break Commands}). | |
1727 | ||
1728 | Break conditions can be specified when a breakpoint is set, by using | |
1729 | @samp{if} in the arguments to the @samp{break} command. @xref{Set Breaks}. | |
1730 | They can also be changed at any time with the @samp{condition} command: | |
1731 | ||
1732 | @table @code | |
1733 | @item condition @var{bnum} @var{expression} | |
1734 | @kindex condition | |
1735 | Specify @var{expression} as the break condition for breakpoint number | |
1736 | @var{bnum}. From now on, this breakpoint will stop the program only if | |
1737 | the value of @var{expression} is true (nonzero, in C). @var{expression} | |
1738 | is not evaluated at the time the @samp{condition} command is given. | |
9da601bf RP |
1739 | When you call @samp{condition}, the expression you specify is checked |
1740 | immediately for syntactic correctness, and to determine whether symbols | |
1741 | in it have referents in the context of your breakpoint. | |
e91b87a3 | 1742 | @xref{Expressions}. |
1743 | ||
1744 | @item condition @var{bnum} | |
1745 | Remove the condition from breakpoint number @var{bnum}. It becomes | |
1746 | an ordinary unconditional breakpoint. | |
1747 | @end table | |
1748 | ||
1749 | @cindex ignore count (of breakpoint) | |
4187119d | 1750 | A special case of a breakpoint condition is to stop only when the |
1751 | breakpoint has been reached a certain number of times. This is so | |
1752 | useful that there is a special way to do it, using the @dfn{ignore | |
1753 | count} of the breakpoint. Every breakpoint has an ignore count, which | |
1754 | is an integer. Most of the time, the ignore count is zero, and | |
1755 | therefore has no effect. But if the program reaches a breakpoint whose | |
1756 | ignore count is positive, then instead of stopping, it just decrements | |
1757 | the ignore count by one and continues. As a result, if the ignore count | |
1758 | value is @var{n}, the breakpoint will not stop the next @var{n} times it | |
1759 | is reached. | |
e91b87a3 | 1760 | |
1761 | @table @code | |
1762 | @item ignore @var{bnum} @var{count} | |
1763 | @kindex ignore | |
1764 | Set the ignore count of breakpoint number @var{bnum} to @var{count}. | |
9c91ee3e RP |
1765 | The next @var{count} times the breakpoint is reached, your program's |
1766 | execution will not stop; other than to decrement the ignore count, GDB | |
1767 | takes no action. | |
e91b87a3 | 1768 | |
1769 | To make the breakpoint stop the next time it is reached, specify | |
1770 | a count of zero. | |
1771 | ||
9da601bf RP |
1772 | @item continue @var{count} |
1773 | @itemx cont @var{count} | |
1774 | @kindex cont @var{count} | |
1775 | @kindex continue @var{count} | |
e91b87a3 | 1776 | Continue execution of the program, setting the ignore count of the |
1777 | breakpoint that the program stopped at to @var{count} minus one. | |
4187119d | 1778 | Thus, the program will not stop at this breakpoint until the |
1779 | @var{count}'th time it is reached. | |
e91b87a3 | 1780 | |
1781 | This command is allowed only when the program stopped due to a | |
1782 | breakpoint. At other times, the argument to @samp{cont} is ignored. | |
1783 | @end table | |
1784 | ||
1785 | If a breakpoint has a positive ignore count and a condition, the condition | |
1786 | is not checked. Once the ignore count reaches zero, the condition will | |
9da601bf | 1787 | be checked. |
e91b87a3 | 1788 | |
4187119d | 1789 | Note that you could achieve the effect of the ignore count with a |
1790 | condition such as @w{@samp{$foo-- <= 0}} using a debugger convenience | |
1791 | variable that is decremented each time. @xref{Convenience Vars}. | |
e91b87a3 | 1792 | |
1793 | @node Break Commands, Error in Breakpoints, Conditions, Breakpoints | |
1794 | @subsection Commands Executed on Breaking | |
1795 | ||
1796 | @cindex breakpoint commands | |
1797 | You can give any breakpoint a series of commands to execute when the | |
1798 | program stops due to that breakpoint. For example, you might want to | |
1799 | print the values of certain expressions, or enable other breakpoints. | |
1800 | ||
1801 | @table @code | |
1802 | @item commands @var{bnum} | |
9da601bf RP |
1803 | @kindex commands |
1804 | Specify a list of commands for breakpoint number @var{bnum}. The commands | |
e91b87a3 | 1805 | themselves appear on the following lines. Type a line containing just |
1806 | @samp{end} to terminate the commands. | |
1807 | ||
1808 | To remove all commands from a breakpoint, use the command | |
1809 | @samp{commands} and follow it immediately by @samp{end}; that is, give | |
1810 | no commands. | |
1811 | ||
9da601bf RP |
1812 | With no arguments, @samp{commands} refers to the last breakpoint set |
1813 | (not to the breakpoint most recently encountered). | |
e91b87a3 | 1814 | @end table |
1815 | ||
9da601bf RP |
1816 | You can use breakpoint commands to start the program up again. Simply |
1817 | use the @samp{cont} command, or @samp{step}, or any other command to | |
1818 | resume execution. However, if you do this, any further commands in the | |
1819 | same breakpoint's command list are ignored. When the program stops | |
1820 | again, GDB will act according to the cause of that stop. | |
e91b87a3 | 1821 | |
1822 | @kindex silent | |
1823 | If the first command specified is @samp{silent}, the usual message about | |
1824 | stopping at a breakpoint is not printed. This may be desirable for | |
1825 | breakpoints that are to print a specific message and then continue. | |
1826 | If the remaining commands too print nothing, you will see no sign that | |
1827 | the breakpoint was reached at all. @samp{silent} is not really a command; | |
1828 | it is meaningful only at the beginning of the commands for a breakpoint. | |
1829 | ||
1830 | The commands @samp{echo} and @samp{output} that allow you to print precisely | |
1831 | controlled output are often useful in silent breakpoints. @xref{Output}. | |
1832 | ||
1833 | For example, here is how you could use breakpoint commands to print the | |
4187119d | 1834 | value of @code{x} at entry to @code{foo} whenever it is positive. |
e91b87a3 | 1835 | |
1836 | @example | |
1837 | break foo if x>0 | |
4187119d | 1838 | commands |
e91b87a3 | 1839 | silent |
1840 | echo x is\040 | |
1841 | output x | |
1842 | echo \n | |
1843 | cont | |
1844 | end | |
1845 | @end example | |
1846 | ||
1847 | One application for breakpoint commands is to correct one bug so you can | |
1848 | test another. Put a breakpoint just after the erroneous line of code, give | |
1849 | it a condition to detect the case in which something erroneous has been | |
1850 | done, and give it commands to assign correct values to any variables that | |
1851 | need them. End with the @samp{cont} command so that the program does not | |
1852 | stop, and start with the @samp{silent} command so that no output is | |
1853 | produced. Here is an example: | |
1854 | ||
1855 | @example | |
1856 | break 403 | |
4187119d | 1857 | commands |
e91b87a3 | 1858 | silent |
1859 | set x = y + 4 | |
1860 | cont | |
1861 | end | |
1862 | @end example | |
1863 | ||
1864 | One deficiency in the operation of automatically continuing breakpoints | |
1865 | under Unix appears when your program uses raw mode for the terminal. | |
1866 | GDB switches back to its own terminal modes (not raw) before executing | |
1867 | commands, and then must switch back to raw mode when your program is | |
9da601bf | 1868 | continued. This causes any pending terminal input to be lost. |
e91b87a3 | 1869 | In the GNU system, this will be fixed by changing the behavior of |
1870 | terminal modes. | |
1871 | ||
1872 | Under Unix, when you have this problem, you might be able to get around | |
1873 | it by putting your actions into the breakpoint condition instead of | |
1874 | commands. For example | |
1875 | ||
1876 | @example | |
1877 | condition 5 (x = y + 4), 0 | |
1878 | @end example | |
1879 | ||
1880 | @noindent | |
4187119d | 1881 | specifies a condition expression (@xref{Expressions}) that will change |
1882 | @code{x} as needed, then always have the value 0 so the program will not | |
1883 | stop. Loss of input is avoided here because break conditions are | |
1884 | evaluated without changing the terminal modes. When you want to have | |
1885 | nontrivial conditions for performing the side effects, the operators | |
1886 | @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful. | |
e91b87a3 | 1887 | |
1888 | @node Error in Breakpoints,, Break Commands, Breakpoints | |
1889 | @subsection ``Cannot Insert Breakpoints'' Error | |
1890 | ||
4187119d | 1891 | Under some operating systems, breakpoints cannot be used in a program if |
9da601bf RP |
1892 | any other process is running that program. In this situation, |
1893 | attempting to run or continue a program with a breakpoint will cause GDB | |
1894 | to stop the other process. | |
e91b87a3 | 1895 | |
1896 | When this happens, you have three ways to proceed: | |
1897 | ||
1898 | @enumerate | |
1899 | @item | |
1900 | Remove or disable the breakpoints, then continue. | |
1901 | ||
1902 | @item | |
1903 | Suspend GDB, and copy the file containing the program to a new name. | |
1904 | Resume GDB and use the @samp{exec-file} command to specify that GDB | |
1905 | should run the program under that name. Then start the program again. | |
1906 | ||
1907 | @item | |
4187119d | 1908 | Relink the program so that the text segment is nonsharable, using the |
1909 | linker option @samp{-N}. The operating system limitation may not apply | |
1910 | to nonsharable executables. | |
e91b87a3 | 1911 | @end enumerate |
1912 | ||
1913 | @node Continuing, Stepping, Breakpoints, Stopping | |
1914 | @section Continuing | |
1915 | ||
1916 | After your program stops, most likely you will want it to run some more if | |
1917 | the bug you are looking for has not happened yet. | |
1918 | ||
1919 | @table @code | |
9da601bf | 1920 | @item continue |
e91b87a3 | 1921 | @item cont |
1922 | @kindex cont | |
9da601bf | 1923 | @kindex continue |
e91b87a3 | 1924 | Continue running the program at the place where it stopped. |
1925 | @end table | |
1926 | ||
1927 | If the program stopped at a breakpoint, the place to continue running | |
1928 | is the address of the breakpoint. You might expect that continuing would | |
1929 | just stop at the same breakpoint immediately. In fact, @samp{cont} | |
1930 | takes special care to prevent that from happening. You do not need | |
4187119d | 1931 | to delete the breakpoint to proceed through it after stopping at it. |
e91b87a3 | 1932 | |
1933 | You can, however, specify an ignore-count for the breakpoint that the | |
1934 | program stopped at, by means of an argument to the @samp{cont} command. | |
1935 | @xref{Conditions}. | |
1936 | ||
1937 | If the program stopped because of a signal other than @code{SIGINT} or | |
1938 | @code{SIGTRAP}, continuing will cause the program to see that signal. | |
1939 | You may not want this to happen. For example, if the program stopped | |
1940 | due to some sort of memory reference error, you might store correct | |
1941 | values into the erroneous variables and continue, hoping to see more | |
1942 | execution; but the program would probably terminate immediately as | |
1943 | a result of the fatal signal once it sees the signal. To prevent this, | |
1944 | you can continue with @samp{signal 0}. @xref{Signaling}. You can | |
1945 | also act in advance to prevent the program from seeing certain kinds | |
1946 | of signals, using the @samp{handle} command (@pxref{Signals}). | |
1947 | ||
1948 | @node Stepping,, Continuing, Stopping | |
1949 | @section Stepping | |
1950 | ||
1951 | @cindex stepping | |
1952 | @dfn{Stepping} means setting your program in motion for a limited time, so | |
1953 | that control will return automatically to the debugger after one line of | |
1954 | code or one machine instruction. Breakpoints are active during stepping | |
1955 | and the program will stop for them even if it has not gone as far as the | |
1956 | stepping command specifies. | |
1957 | ||
1958 | @table @code | |
1959 | @item step | |
1960 | @kindex step | |
4187119d | 1961 | Continue running the program until control reaches a different line, |
1962 | then stop it and return control to the debugger. This command is | |
1963 | abbreviated @samp{s}. | |
e91b87a3 | 1964 | |
4187119d | 1965 | This command may be given when control is within a function for which |
e91b87a3 | 1966 | there is no debugging information. In that case, execution will proceed |
4187119d | 1967 | until control reaches a different function, or is about to return from |
1968 | this function. An argument repeats this action. | |
1969 | ||
1970 | @item step @var{count} | |
1971 | Continue running as in @samp{step}, but do so @var{count} times. If a | |
1972 | breakpoint is reached or a signal not related to stepping occurs before | |
1973 | @var{count} steps, stepping stops right away. | |
e91b87a3 | 1974 | |
1975 | @item next | |
1976 | @kindex next | |
1977 | Similar to @samp{step}, but any function calls appearing within the line of | |
1978 | code are executed without stopping. Execution stops when control reaches a | |
1979 | different line of code at the stack level which was executing when the | |
1980 | @samp{next} command was given. This command is abbreviated @samp{n}. | |
1981 | ||
1982 | An argument is a repeat count, as in @samp{step}. | |
1983 | ||
4187119d | 1984 | @samp{next} within a function without debugging information acts as does |
e91b87a3 | 1985 | @samp{step}, but any function calls appearing within the code of the |
4187119d | 1986 | function are executed without stopping. |
e91b87a3 | 1987 | |
1988 | @item finish | |
1989 | @kindex finish | |
4187119d | 1990 | Continue running until just after the selected stack frame returns (or |
1991 | until there is some other reason to stop, such as a fatal signal or a | |
1992 | breakpoint). Print value returned by the selected stack frame (if any). | |
e91b87a3 | 1993 | |
1994 | Contrast this with the @samp{return} command (@pxref{Returning}). | |
1995 | ||
1996 | @item until | |
1997 | @kindex until | |
4187119d | 1998 | This command is used to avoid single stepping through a loop more than |
1999 | once. It is like the @samp{next} command, except that when @samp{until} | |
2000 | encounters a jump, it automatically continues execution until the | |
2001 | program counter is greater than the address of the jump. | |
2002 | ||
2003 | This means that when you reach the end of a loop after single stepping | |
2004 | though it, @samp{until} will cause the program to continue execution | |
2005 | until the loop is exited. In contrast, a @samp{next} command at the end | |
2006 | of a loop will simply step back to the beginning of the loop, which | |
2007 | would force you to step through the next iteration. | |
2008 | ||
2009 | @samp{until} always stops the program if it attempts to exit the current | |
2010 | stack frame. | |
2011 | ||
2012 | @samp{until} may produce somewhat counterintuitive results if the order | |
2013 | of the source lines does not match the actual order of execution. For | |
2014 | example, in a typical C @code{for}-loop, the third expression in the | |
2015 | @code{for}-statement (the loop-step expression) is executed after the | |
2016 | statements in the body of the loop, but is written before them. | |
2017 | Therefore, the @samp{until} command would appear to step back to the | |
2018 | beginning of the loop when it advances to this expression. However, it | |
2019 | has not really done so, not in terms of the actual machine code. | |
2020 | ||
2021 | Note that @samp{until} with no argument works by means of single | |
2022 | instruction stepping, and hence is slower than @samp{until} with an | |
2023 | argument. | |
e91b87a3 | 2024 | |
2025 | @item until @var{location} | |
4187119d | 2026 | Continue running the program until either the specified location is |
9c91ee3e RP |
2027 | reached, or the current (innermost) stack frame returns. @var{location} |
2028 | is any of the forms of argument acceptable to @samp{break} (@pxref{Set | |
2029 | Breaks}). This form of the command uses breakpoints, and hence is | |
2030 | quicker than @samp{until} without an argument. | |
e91b87a3 | 2031 | |
2032 | @item stepi | |
2033 | @itemx si | |
2034 | @kindex stepi | |
2035 | @kindex si | |
4187119d | 2036 | Execute one machine instruction, then stop and return to the debugger. |
e91b87a3 | 2037 | |
2038 | It is often useful to do @samp{display/i $pc} when stepping by machine | |
2039 | instructions. This will cause the next instruction to be executed to | |
2040 | be displayed automatically at each stop. @xref{Auto Display}. | |
2041 | ||
2042 | An argument is a repeat count, as in @samp{step}. | |
2043 | ||
2044 | @item nexti | |
2045 | @itemx ni | |
2046 | @kindex nexti | |
2047 | @kindex ni | |
4187119d | 2048 | Execute one machine instruction, but if it is a subroutine call, |
e91b87a3 | 2049 | proceed until the subroutine returns. |
2050 | ||
2051 | An argument is a repeat count, as in @samp{next}. | |
2052 | @end table | |
2053 | ||
2054 | A typical technique for using stepping is to put a breakpoint | |
2055 | (@pxref{Breakpoints}) at the beginning of the function or the section of | |
2056 | the program in which a problem is believed to lie, and then step through | |
2057 | the suspect area, examining the variables that are interesting, until the | |
2058 | problem happens. | |
2059 | ||
2060 | The @samp{cont} command can be used after stepping to resume execution | |
2061 | until the next breakpoint or signal. | |
2062 | ||
2063 | @node Stack, Source, Stopping, Top | |
2064 | @chapter Examining the Stack | |
2065 | ||
2066 | When your program has stopped, the first thing you need to know is where it | |
2067 | stopped and how it got there. | |
2068 | ||
2069 | @cindex call stack | |
2070 | Each time your program performs a function call, the information about | |
2071 | where in the program the call was made from is saved in a block of data | |
2072 | called a @dfn{stack frame}. The frame also contains the arguments of the | |
2073 | call and the local variables of the function that was called. All the | |
2074 | stack frames are allocated in a region of memory called the @dfn{call | |
2075 | stack}. | |
2076 | ||
2077 | When your program stops, the GDB commands for examining the stack allow you | |
2078 | to see all of this information. | |
2079 | ||
2080 | One of the stack frames is @dfn{selected} by GDB and many GDB commands | |
2081 | refer implicitly to the selected frame. In particular, whenever you ask | |
2082 | GDB for the value of a variable in the program, the value is found in the | |
2083 | selected frame. There are special GDB commands to select whichever frame | |
2084 | you are interested in. | |
2085 | ||
2086 | When the program stops, GDB automatically selects the currently executing | |
2087 | frame and describes it briefly as the @samp{frame} command does | |
2088 | (@pxref{Frame Info, Info}). | |
2089 | ||
2090 | @menu | |
2091 | * Frames:: Explanation of stack frames and terminology. | |
2092 | * Backtrace:: Summarizing many frames at once. | |
2093 | * Selection:: How to select a stack frame. | |
2094 | * Info: Frame Info, Commands to print information on stack frames. | |
6ad6aa52 | 2095 | * Exception Handling: How GDB supports exception handling for C++. |
e91b87a3 | 2096 | @end menu |
2097 | ||
2098 | @node Frames, Backtrace, Stack, Stack | |
2099 | @section Stack Frames | |
2100 | ||
2101 | @cindex frame | |
4187119d | 2102 | @cindex stack frame |
2103 | The call stack is divided up into contiguous pieces called @dfn{stack | |
2104 | frames}, or @dfn{frames} for short; each frame is the data associated | |
2105 | with one call to one function. The frame contains the arguments given | |
2106 | to the function, the function's local variables, and the address at | |
2107 | which the function is executing. | |
e91b87a3 | 2108 | |
2109 | @cindex initial frame | |
2110 | @cindex outermost frame | |
2111 | @cindex innermost frame | |
2112 | When your program is started, the stack has only one frame, that of the | |
2113 | function @code{main}. This is called the @dfn{initial} frame or the | |
2114 | @dfn{outermost} frame. Each time a function is called, a new frame is | |
2115 | made. Each time a function returns, the frame for that function invocation | |
2116 | is eliminated. If a function is recursive, there can be many frames for | |
2117 | the same function. The frame for the function in which execution is | |
2118 | actually occurring is called the @dfn{innermost} frame. This is the most | |
2119 | recently created of all the stack frames that still exist. | |
2120 | ||
2121 | @cindex frame pointer | |
2122 | Inside your program, stack frames are identified by their addresses. A | |
2123 | stack frame consists of many bytes, each of which has its own address; each | |
2124 | kind of computer has a convention for choosing one of those bytes whose | |
2125 | address serves as the address of the frame. Usually this address is kept | |
2126 | in a register called the @dfn{frame pointer register} while execution is | |
2127 | going on in that frame. | |
2128 | ||
2129 | @cindex frame number | |
2130 | GDB assigns numbers to all existing stack frames, starting with zero for | |
2131 | the innermost frame, one for the frame that called it, and so on upward. | |
2132 | These numbers do not really exist in your program; they are to give you a | |
2133 | way of talking about stack frames in GDB commands. | |
2134 | ||
2135 | @cindex selected frame | |
2136 | Many GDB commands refer implicitly to one stack frame. GDB records a stack | |
2137 | frame that is called the @dfn{selected} stack frame; you can select any | |
2138 | frame using one set of GDB commands, and then other commands will operate | |
2139 | on that frame. When your program stops, GDB automatically selects the | |
2140 | innermost frame. | |
2141 | ||
4187119d | 2142 | @cindex frameless execution |
2143 | Some functions can be compiled to run without a frame reserved for them | |
2144 | on the stack. This is occasionally done with heavily used library | |
2145 | functions to save the frame setup time. GDB has limited facilities for | |
2146 | dealing with these function invocations; if the innermost function | |
2147 | invocation has no stack frame, GDB will give it a virtual stack frame of | |
2148 | 0 and correctly allow tracing of the function call chain. Results are | |
2149 | undefined if a function invocation besides the innermost one is | |
2150 | frameless. | |
2151 | ||
e91b87a3 | 2152 | @node Backtrace, Selection, Frames, Stack |
2153 | @section Backtraces | |
2154 | ||
2155 | A backtrace is a summary of how the program got where it is. It shows one | |
2156 | line per frame, for many frames, starting with the currently executing | |
2157 | frame (frame zero), followed by its caller (frame one), and on up the | |
2158 | stack. | |
2159 | ||
2160 | @table @code | |
2161 | @item backtrace | |
2162 | @itemx bt | |
4187119d | 2163 | @kindex backtrace |
2164 | @kindex bt | |
e91b87a3 | 2165 | Print a backtrace of the entire stack: one line per frame for all |
2166 | frames in the stack. | |
2167 | ||
2168 | You can stop the backtrace at any time by typing the system interrupt | |
2169 | character, normally @kbd{Control-C}. | |
2170 | ||
2171 | @item backtrace @var{n} | |
2172 | @itemx bt @var{n} | |
4187119d | 2173 | Similar, but print only the innermost @var{n} frames. |
e91b87a3 | 2174 | |
2175 | @item backtrace @var{-n} | |
2176 | @itemx bt @var{-n} | |
4187119d | 2177 | Similar, but print only the outermost @var{n} frames. |
e91b87a3 | 2178 | @end table |
2179 | ||
4187119d | 2180 | @kindex where |
2181 | @kindex info stack | |
2182 | The names @samp{where} and @samp{info stack} are additional aliases | |
2183 | for @samp{backtrace}. | |
2184 | ||
2185 | Every line in the backtrace shows the frame number, the function name | |
2186 | and the program counter value. | |
2187 | ||
2188 | If the function is in a source file whose symbol table data has been | |
2189 | fully read, the backtrace shows the source file name and line number, as | |
2190 | well as the arguments to the function. (The program counter value is | |
2191 | omitted if it is at the beginning of the code for that line number.) | |
2192 | ||
4187119d | 2193 | Here is an example of a backtrace. It was made with the command |
2194 | @samp{bt 3}, so it shows the innermost three frames. | |
2195 | ||
2196 | @example | |
9c91ee3e RP |
2197 | #0 rtx_equal_p (x=(rtx) 0x8e58c, y=(rtx) 0x1086c4) \ |
2198 | (/gp/rms/cc/rtlanal.c line 337) | |
4187119d | 2199 | #1 0x246b0 in expand_call (...) (...) |
2200 | #2 0x21cfc in expand_expr (...) (...) | |
2201 | (More stack frames follow...) | |
2202 | @end example | |
2203 | ||
2204 | @noindent | |
2205 | The functions @code{expand_call} and @code{expand_expr} are in a file | |
2206 | whose symbol details have not been fully read. Full detail is available | |
2207 | for the function @code{rtx_equal_p}, which is in the file | |
2208 | @file{rtlanal.c}. Its arguments, named @code{x} and @code{y}, are shown | |
2209 | with their typed values. | |
e91b87a3 | 2210 | |
2211 | @node Selection, Frame Info, Backtrace, Stack | |
2212 | @section Selecting a Frame | |
2213 | ||
2214 | Most commands for examining the stack and other data in the program work on | |
2215 | whichever stack frame is selected at the moment. Here are the commands for | |
2216 | selecting a stack frame; all of them finish by printing a brief description | |
2217 | of the stack frame just selected. | |
2218 | ||
2219 | @table @code | |
2220 | @item frame @var{n} | |
2221 | @kindex frame | |
2222 | Select frame number @var{n}. Recall that frame zero is the innermost | |
2223 | (currently executing) frame, frame one is the frame that called the | |
2224 | innermost one, and so on. The highest-numbered frame is @code{main}'s | |
2225 | frame. | |
2226 | ||
2227 | @item frame @var{addr} | |
2228 | Select the frame at address @var{addr}. This is useful mainly if the | |
2229 | chaining of stack frames has been damaged by a bug, making it | |
2230 | impossible for GDB to assign numbers properly to all frames. In | |
2231 | addition, this can be useful when the program has multiple stacks and | |
2232 | switches between them. | |
2233 | ||
2234 | @item up @var{n} | |
2235 | @kindex up | |
2236 | Select the frame @var{n} frames up from the frame previously selected. | |
2237 | For positive numbers @var{n}, this advances toward the outermost | |
2238 | frame, to higher frame numbers, to frames that have existed longer. | |
2239 | @var{n} defaults to one. | |
2240 | ||
2241 | @item down @var{n} | |
2242 | @kindex down | |
2243 | Select the frame @var{n} frames down from the frame previously | |
2244 | selected. For positive numbers @var{n}, this advances toward the | |
2245 | innermost frame, to lower frame numbers, to frames that were created | |
2246 | more recently. @var{n} defaults to one. | |
2247 | @end table | |
2248 | ||
2249 | All of these commands end by printing some information on the frame that | |
2250 | has been selected: the frame number, the function name, the arguments, the | |
2251 | source file and line number of execution in that frame, and the text of | |
2252 | that source line. For example: | |
2253 | ||
2254 | @example | |
2255 | #3 main (argc=3, argv=??, env=??) at main.c, line 67 | |
2256 | 67 read_input_file (argv[i]); | |
2257 | @end example | |
2258 | ||
2259 | After such a printout, the @samp{list} command with no arguments will print | |
2260 | ten lines centered on the point of execution in the frame. @xref{List}. | |
2261 | ||
6ad6aa52 | 2262 | @node Frame Info, Exception Handling, Selection, Stack |
e91b87a3 | 2263 | @section Information on a Frame |
2264 | ||
2265 | There are several other commands to print information about the selected | |
2266 | stack frame. | |
2267 | ||
2268 | @table @code | |
2269 | @item frame | |
9da601bf RP |
2270 | When used without any argument, this command does not change which frame |
2271 | is selected, but still prints a brief description of the currently | |
2272 | selected stack frame. It can be abbreviated @samp{f}. With an | |
2273 | argument, this command is used to select a stack frame; with no | |
2274 | argument, it does not change which frame is selected, but still prints | |
2275 | the same kind of information. | |
e91b87a3 | 2276 | |
2277 | @item info frame | |
2278 | @kindex info frame | |
2279 | This command prints a verbose description of the selected stack frame, | |
2280 | including the address of the frame, the addresses of the next frame in | |
2281 | (called by this frame) and the next frame out (caller of this frame), | |
2282 | the address of the frame's arguments, the program counter saved in it | |
2283 | (the address of execution in the caller frame), and which registers | |
2284 | were saved in the frame. The verbose description is useful when | |
2285 | something has gone wrong that has made the stack format fail to fit | |
2286 | the usual conventions. | |
2287 | ||
2288 | @item info frame @var{addr} | |
2289 | Print a verbose description of the frame at address @var{addr}, | |
2290 | without selecting that frame. The selected frame remains unchanged by | |
2291 | this command. | |
2292 | ||
2293 | @item info args | |
2294 | @kindex info args | |
2295 | Print the arguments of the selected frame, each on a separate line. | |
2296 | ||
2297 | @item info locals | |
2298 | @kindex info locals | |
2299 | Print the local variables of the selected frame, each on a separate | |
2300 | line. These are all variables declared static or automatic within all | |
2301 | program blocks that execution in this frame is currently inside of. | |
e91b87a3 | 2302 | |
6ad6aa52 RP |
2303 | @item info catch |
2304 | @kindex info catch | |
9da601bf | 2305 | @cindex catch exceptions |
6ad6aa52 | 2306 | Print a list of all the exception handlers that are active in the |
9da601bf RP |
2307 | current stack frame given the current value of @code{pc}. To see other |
2308 | exception handlers, visit the associated frame (using the @samp{up}, | |
2309 | @samp{down}, or @samp{frame} commands) and type @samp{info catch}. | |
6ad6aa52 RP |
2310 | @end table |
2311 | ||
2312 | @node Exception Handling,, Frame Info, Stack | |
2313 | ||
2314 | Some languages, such as GNU C++, implement exception handling. GDB | |
2315 | can be used to examine what caused the program to raise an exception | |
2316 | and to list the exceptions the program is prepared to handle at a | |
2317 | given point in time. | |
2318 | ||
2319 | @cindex raise exceptions | |
2320 | GNU C++ raises an exception by calling a library function named | |
2321 | @code{__raise_exception} which has the following ANSI C interface: | |
2322 | ||
2323 | @example | |
2324 | /* ADDR is where the exception identifier is stored. | |
2325 | ID is the exception identifier. */ | |
2326 | void __raise_exception (void **addr, void *id); | |
2327 | @end example | |
2328 | ||
2329 | @noindent | |
4afc6002 RP |
2330 | You can make the debugger catch all exceptions @emph{before} any stack |
2331 | unwinding takes place: set a breakpoint on @code{__raise_exception} | |
2332 | (@pxref{Breakpoints}). If you set a breakpoint in an exception handler | |
2333 | instead, it may not be easy to find out where the exception was raised. | |
6ad6aa52 | 2334 | |
9c91ee3e | 2335 | By using a conditional breakpoint (@xref{Conditions}), you can cause |
6ad6aa52 RP |
2336 | the debugger to stop only when a specific exception is raised. |
2337 | Multiple conditional breakpoints can be used to stop the program when | |
2338 | any of a number of exceptions are raised. | |
2339 | ||
9da601bf RP |
2340 | @table @code |
2341 | @item catch @var{exceptions} | |
2342 | @kindex catch | |
6ad6aa52 RP |
2343 | |
2344 | Breakpoints can be set at active exception handlers by using the | |
9da601bf RP |
2345 | @samp{catch} command. @var{exceptions} is a list of names of exceptions |
2346 | to catch. | |
2347 | @end table | |
6ad6aa52 RP |
2348 | |
2349 | There are currently some limitations to exception handling in GDB. | |
2350 | These will be corrected in a future release. | |
2351 | ||
2352 | @itemize @bullet | |
9da601bf RP |
2353 | @item |
2354 | If you call a function interactively it will normally return | |
6ad6aa52 | 2355 | control to the user when it has finished executing. If the call |
9da601bf | 2356 | raises an exception, however, the call may bypass the mechanism that |
6ad6aa52 RP |
2357 | returns control to the user and cause the program to simply continue |
2358 | running until it hits a breakpoint, catches a signal that GDB is | |
2359 | listening for, or exits. | |
9da601bf RP |
2360 | @item |
2361 | You cannot raise an exception interactively. | |
2362 | @item | |
2363 | You cannot interactively install an exception handler. | |
6ad6aa52 RP |
2364 | @end itemize |
2365 | ||
e91b87a3 | 2366 | @node Source, Data, Stack, Top |
2367 | @chapter Examining Source Files | |
2368 | ||
2369 | GDB knows which source files your program was compiled from, and | |
2370 | can print parts of their text. When your program stops, GDB | |
2371 | spontaneously prints the line it stopped in. Likewise, when you | |
2372 | select a stack frame (@pxref{Selection}), GDB prints the line | |
2373 | which execution in that frame has stopped in. You can also | |
2374 | print parts of source files by explicit command. | |
2375 | ||
2376 | @menu | |
2377 | * List:: Using the @samp{list} command to print source files. | |
2378 | * Search:: Commands for searching source files. | |
2379 | * Source Path:: Specifying the directories to search for source files. | |
2380 | @end menu | |
2381 | ||
2382 | @node List, Search, Source, Source | |
2383 | @section Printing Source Lines | |
2384 | ||
2385 | @kindex list | |
9da601bf | 2386 | @kindex l |
e91b87a3 | 2387 | To print lines from a source file, use the @samp{list} command |
2388 | (abbreviated @samp{l}). There are several ways to specify what part | |
2389 | of the file you want to print. | |
2390 | ||
2391 | Here are the forms of the @samp{list} command most commonly used: | |
2392 | ||
2393 | @table @code | |
2394 | @item list @var{linenum} | |
2395 | Print ten lines centered around line number @var{linenum} in the | |
2396 | current source file. | |
2397 | ||
2398 | @item list @var{function} | |
2399 | Print ten lines centered around the beginning of function | |
2400 | @var{function}. | |
2401 | ||
2402 | @item list | |
2403 | Print ten more lines. If the last lines printed were printed with a | |
2404 | @samp{list} command, this prints ten lines following the last lines | |
2405 | printed; however, if the last line printed was a solitary line printed | |
2406 | as part of displaying a stack frame (@pxref{Stack}), this prints ten | |
2407 | lines centered around that line. | |
2408 | ||
4187119d | 2409 | @item list - |
e91b87a3 | 2410 | Print ten lines just before the lines last printed. |
2411 | @end table | |
2412 | ||
2413 | Repeating a @samp{list} command with @key{RET} discards the argument, | |
2414 | so it is equivalent to typing just @samp{list}. This is more useful | |
2415 | than listing the same lines again. An exception is made for an | |
2416 | argument of @samp{-}; that argument is preserved in repetition so that | |
2417 | each repetition moves up in the file. | |
2418 | ||
4187119d | 2419 | @cindex linespec |
e91b87a3 | 2420 | In general, the @samp{list} command expects you to supply zero, one or two |
2421 | @dfn{linespecs}. Linespecs specify source lines; there are several ways | |
2422 | of writing them but the effect is always to specify some source line. | |
2423 | Here is a complete description of the possible arguments for @samp{list}: | |
2424 | ||
2425 | @table @code | |
2426 | @item list @var{linespec} | |
2427 | Print ten lines centered around the line specified by @var{linespec}. | |
2428 | ||
2429 | @item list @var{first},@var{last} | |
2430 | Print lines from @var{first} to @var{last}. Both arguments are | |
2431 | linespecs. | |
2432 | ||
2433 | @item list ,@var{last} | |
2434 | Print ten lines ending with @var{last}. | |
2435 | ||
2436 | @item list @var{first}, | |
2437 | Print ten lines starting with @var{first}. | |
2438 | ||
2439 | @item list + | |
2440 | Print ten lines just after the lines last printed. | |
2441 | ||
4187119d | 2442 | @item list - |
e91b87a3 | 2443 | Print ten lines just before the lines last printed. |
2444 | ||
2445 | @item list | |
2446 | As described in the preceding table. | |
2447 | @end table | |
2448 | ||
2449 | Here are the ways of specifying a single source line---all the | |
2450 | kinds of linespec. | |
2451 | ||
4187119d | 2452 | @table @code |
e91b87a3 | 2453 | @item @var{linenum} |
2454 | Specifies line @var{linenum} of the current source file. | |
2455 | When a @samp{list} command has two linespecs, this refers to | |
2456 | the same source file as the first linespec. | |
2457 | ||
2458 | @item +@var{offset} | |
2459 | Specifies the line @var{offset} lines after the last line printed. | |
2460 | When used as the second linespec in a @samp{list} command that has | |
2461 | two, this specifies the line @var{offset} lines down from the | |
2462 | first linespec. | |
2463 | ||
4187119d | 2464 | @item -@var{offset} |
e91b87a3 | 2465 | Specifies the line @var{offset} lines before the last line printed. |
2466 | ||
2467 | @item @var{filename}:@var{linenum} | |
2468 | Specifies line @var{linenum} in the source file @var{filename}. | |
2469 | ||
2470 | @item @var{function} | |
2471 | Specifies the line of the open-brace that begins the body of the | |
2472 | function @var{function}. | |
2473 | ||
2474 | @item @var{filename}:@var{function} | |
2475 | Specifies the line of the open-brace that begins the body of the | |
2476 | function @var{function} in the file @var{filename}. The file name is | |
2477 | needed with a function name only for disambiguation of identically | |
2478 | named functions in different source files. | |
2479 | ||
2480 | @item *@var{address} | |
2481 | Specifies the line containing the program address @var{address}. | |
2482 | @var{address} may be any expression. | |
2483 | @end table | |
2484 | ||
2485 | One other command is used to map source lines to program addresses. | |
2486 | ||
2487 | @table @code | |
2488 | @item info line @var{linenum} | |
2489 | @kindex info line | |
2490 | Print the starting and ending addresses of the compiled code for | |
2491 | source line @var{linenum}. | |
2492 | ||
2493 | @kindex $_ | |
2494 | The default examine address for the @samp{x} command is changed to the | |
2495 | starting address of the line, so that @samp{x/i} is sufficient to | |
2496 | begin examining the machine code (@pxref{Memory}). Also, this address | |
4187119d | 2497 | is saved as the value of the convenience variable @code{$_} |
e91b87a3 | 2498 | (@pxref{Convenience Vars}). |
2499 | @end table | |
2500 | ||
2501 | @node Search, Source Path, List, Source | |
2502 | @section Searching Source Files | |
2503 | @cindex searching | |
9da601bf | 2504 | @kindex search |
e91b87a3 | 2505 | @kindex forward-search |
2506 | @kindex reverse-search | |
2507 | ||
2508 | There are two commands for searching through the current source file for a | |
2509 | regular expression. | |
2510 | ||
2511 | The command @samp{forward-search @var{regexp}} checks each line, starting | |
2512 | with the one following the last line listed, for a match for @var{regexp}. | |
2513 | It lists the line that is found. You can abbreviate the command name | |
9da601bf | 2514 | as @samp{fo}. The synonym @samp{search @var{regexp}} is also supported. |
e91b87a3 | 2515 | |
2516 | The command @samp{reverse-search @var{regexp}} checks each line, starting | |
2517 | with the one before the last line listed and going backward, for a match | |
2518 | for @var{regexp}. It lists the line that is found. You can abbreviate | |
2519 | this command with as little as @samp{rev}. | |
2520 | ||
2521 | @node Source Path,, Search, Source | |
2522 | @section Specifying Source Directories | |
2523 | ||
2524 | @cindex source path | |
2525 | @cindex directories for source files | |
6ad6aa52 RP |
2526 | Executable programs sometimes do not record the directories of the source |
2527 | files from which they were compiled, just the names. Even when they do, | |
2528 | the directories could be moved between the compilation and your debugging | |
2529 | session. GDB remembers a list of directories to search for source files; | |
2530 | this is called the @dfn{source path}. Each time GDB wants a source file, | |
2531 | it tries all the directories in the list, in the order they are present | |
9da601bf RP |
2532 | in the list, until it finds a file with the desired name. Note that |
2533 | the executable search path is @emph{not} used for this purpose. Neither is | |
6ad6aa52 | 2534 | the current working directory, unless it happens to be in the source |
9da601bf | 2535 | path. |
0bed9994 JG |
2536 | |
2537 | If it can't find a source file in the source path, and the object program | |
2538 | records what directory it was compiled in, GDB tries that directory too. | |
2539 | If the source path is empty, and there is no record of the compilation | |
2540 | directory, GDB will, as a last resort, look in the current directory. | |
2541 | ||
2542 | Whenever you reset or rearrange the source path, GDB will clear out | |
2543 | any information it has cached about where source files are found, where | |
2544 | each line is in the file, etc. | |
e91b87a3 | 2545 | |
2546 | @kindex directory | |
0bed9994 JG |
2547 | When you start GDB, its source path is empty. |
2548 | To add other directories, use the @samp{directory} command. | |
e91b87a3 | 2549 | |
2550 | @table @code | |
4187119d | 2551 | @item directory @var{dirnames...} |
0bed9994 | 2552 | Add directory @var{dirname} to the front of the source path. Several |
4187119d | 2553 | directory names may be given to this command, separated by whitespace or |
0bed9994 JG |
2554 | @samp{:}. If a name is already in the source path, it is moved to the |
2555 | front of the path, so it will be searched sooner. | |
e91b87a3 | 2556 | |
2557 | @item directory | |
0bed9994 | 2558 | Reset the source path to empty again. This requires confirmation. |
e91b87a3 | 2559 | |
2560 | @item info directories | |
2561 | @kindex info directories | |
2562 | Print the source path: show which directories it contains. | |
2563 | @end table | |
2564 | ||
9c91ee3e RP |
2565 | Because the @samp{directory} command, when used with arguments, adds to |
2566 | the front of the source path, it can affect files that GDB has already | |
2567 | found. If the source path contains directories that you do not want, | |
2568 | and these directories contain misleading files with names matching your | |
2569 | source files, the way to correct the situation is as follows: | |
e91b87a3 | 2570 | |
2571 | @enumerate | |
2572 | @item | |
0bed9994 | 2573 | Use @samp{directory} with no argument to reset the source path to empty. |
e91b87a3 | 2574 | |
2575 | @item | |
2576 | Use @samp{directory} with suitable arguments to add any other | |
0bed9994 JG |
2577 | directories you want in the source path. You can add all the directories |
2578 | in one command. | |
e91b87a3 | 2579 | @end enumerate |
2580 | ||
2581 | @node Data, Symbols, Source, Top | |
2582 | @chapter Examining Data | |
2583 | ||
2584 | @cindex printing data | |
2585 | @cindex examining data | |
2586 | @kindex print | |
9da601bf | 2587 | @kindex inspect |
4187119d | 2588 | The usual way to examine data in your program is with the @samp{print} |
9da601bf RP |
2589 | command (abbreviated @samp{p}), or its synonym @samp{inspect}. It |
2590 | evaluates and prints the value of any valid expression of the language | |
2591 | the program is written in (for now, C or C++). You type | |
e91b87a3 | 2592 | |
2593 | @example | |
2594 | print @var{exp} | |
2595 | @end example | |
2596 | ||
2597 | @noindent | |
9c91ee3e RP |
2598 | where @var{exp} is any valid expression (in the source language), and |
2599 | the value of @var{exp} is printed in a format appropriate to its data | |
2600 | type. | |
e91b87a3 | 2601 | |
2602 | A more low-level way of examining data is with the @samp{x} command. | |
2603 | It examines data in memory at a specified address and prints it in a | |
2604 | specified format. | |
2605 | ||
e91b87a3 | 2606 | @menu |
2607 | * Expressions:: Expressions that can be computed and printed. | |
2608 | * Variables:: Using your program's variables in expressions. | |
2609 | * Assignment:: Setting your program's variables. | |
2610 | * Arrays:: Examining part of memory as an array. | |
4187119d | 2611 | * Format Options:: Controlling how structures and arrays are printed. |
2612 | * Output formats:: Specifying formats for printing values. | |
e91b87a3 | 2613 | * Memory:: Examining memory explicitly. |
2614 | * Auto Display:: Printing certain expressions whenever program stops. | |
2615 | * Value History:: Referring to values previously printed. | |
2616 | * Convenience Vars:: Giving names to values for future reference. | |
2617 | * Registers:: Referring to and storing in machine registers. | |
2618 | @end menu | |
2619 | ||
2620 | @node Expressions, Variables, Data, Data | |
2621 | @section Expressions | |
2622 | ||
2623 | @cindex expressions | |
2624 | Many different GDB commands accept an expression and compute its value. | |
2625 | Any kind of constant, variable or operator defined by the programming | |
2626 | language you are using is legal in an expression in GDB. This includes | |
2627 | conditional expressions, function calls, casts and string constants. | |
2628 | It unfortunately does not include symbols defined by preprocessor | |
4187119d | 2629 | @code{#define} commands. |
e91b87a3 | 2630 | |
2631 | Casts are supported in all languages, not just in C, because it is so | |
2632 | useful to cast a number into a pointer so as to examine a structure | |
2633 | at that address in memory. | |
2634 | ||
2635 | GDB supports three kinds of operator in addition to those of programming | |
2636 | languages: | |
2637 | ||
2638 | @table @code | |
2639 | @item @@ | |
2640 | @samp{@@} is a binary operator for treating parts of memory as arrays. | |
2641 | @xref{Arrays}, for more information. | |
2642 | ||
2643 | @item :: | |
2644 | @samp{::} allows you to specify a variable in terms of the file or | |
2645 | function it is defined in. @xref{Variables}. | |
2646 | ||
2647 | @item @{@var{type}@} @var{addr} | |
2648 | Refers to an object of type @var{type} stored at address @var{addr} in | |
2649 | memory. @var{addr} may be any expression whose value is an integer or | |
2650 | pointer (but parentheses are required around nonunary operators, just as in | |
2651 | a cast). This construct is allowed regardless of what kind of data is | |
2652 | officially supposed to reside at @var{addr}.@refill | |
2653 | @end table | |
2654 | ||
2655 | @node Variables, Arrays, Expressions, Data | |
2656 | @section Program Variables | |
2657 | ||
2658 | The most common kind of expression to use is the name of a variable | |
2659 | in your program. | |
2660 | ||
2661 | Variables in expressions are understood in the selected stack frame | |
2662 | (@pxref{Selection}); they must either be global (or static) or be visible | |
2663 | according to the scope rules of the programming language from the point of | |
2664 | execution in that frame. This means that in the function | |
2665 | ||
2666 | @example | |
2667 | foo (a) | |
2668 | int a; | |
2669 | @{ | |
2670 | bar (a); | |
2671 | @{ | |
2672 | int b = test (); | |
2673 | bar (b); | |
2674 | @} | |
2675 | @} | |
2676 | @end example | |
2677 | ||
2678 | @noindent | |
2679 | the variable @code{a} is usable whenever the program is executing | |
2680 | within the function @code{foo}, but the variable @code{b} is visible | |
2681 | only while the program is executing inside the block in which @code{b} | |
2682 | is declared. | |
2683 | ||
2684 | As a special exception, you can refer to a variable or function whose | |
2685 | scope is a single source file even if the current execution point is not | |
2686 | in this file. But it is possible to have more than one such variable | |
2687 | or function with the same name (if they are in different source files). | |
2688 | In such a case, it is not defined which one you will get. If you wish, | |
2689 | you can specify any one of them using the colon-colon construct: | |
2690 | ||
2691 | @example | |
2692 | @var{block}::@var{variable} | |
2693 | @end example | |
2694 | ||
2695 | @noindent | |
2696 | Here @var{block} is the name of the source file whose variable you want. | |
2697 | ||
4187119d | 2698 | @node Arrays, Format options, Variables, Data |
e91b87a3 | 2699 | @section Artificial Arrays |
2700 | ||
2701 | @cindex artificial array | |
2702 | It is often useful to print out several successive objects of the | |
2703 | same type in memory; a section of an array, or an array of | |
2704 | dynamically determined size for which only a pointer exists in the | |
2705 | program. | |
2706 | ||
2707 | This can be done by constructing an @dfn{artificial array} with the | |
2708 | binary operator @samp{@@}. The left operand of @samp{@@} should be | |
2709 | the first element of the desired array, as an individual object. | |
2710 | The right operand should be the length of the array. The result is | |
2711 | an array value whose elements are all of the type of the left argument. | |
2712 | The first element is actually the left argument; the second element | |
2713 | comes from bytes of memory immediately following those that hold the | |
2714 | first element, and so on. Here is an example. If a program says | |
2715 | ||
2716 | @example | |
2717 | int *array = (int *) malloc (len * sizeof (int)); | |
2718 | @end example | |
2719 | ||
2720 | @noindent | |
2721 | you can print the contents of @code{array} with | |
2722 | ||
2723 | @example | |
2724 | p *array@@len | |
2725 | @end example | |
2726 | ||
2727 | The left operand of @samp{@@} must reside in memory. Array values made | |
2728 | with @samp{@@} in this way behave just like other arrays in terms of | |
2729 | subscripting, and are coerced to pointers when used in expressions. | |
2730 | (It would probably appear in an expression via the value history, | |
2731 | after you had printed it out.) | |
2732 | ||
4187119d | 2733 | @node Format options, Output formats, Arrays, Data |
2734 | @section Format options | |
2735 | ||
2736 | @cindex format options | |
2737 | GDB provides a few ways to control how arrays and structures are | |
2738 | printed. | |
2739 | ||
2740 | @table @code | |
2741 | @item info format | |
2742 | @kindex info format | |
2743 | Display the current settings for the format options. | |
2744 | ||
2745 | @item set array-max @var{number-of-elements} | |
2746 | @kindex set array-max | |
2747 | If GDB is printing a large array, it will stop printing after it has | |
2748 | printed the number of elements set by the @samp{set array-max} command. | |
2749 | This limit also applies to the display of strings. | |
2750 | ||
9da601bf RP |
2751 | @item show array-max |
2752 | @kindex show array-max | |
2753 | Display the number of elements of a large array that GDB will print | |
2754 | before losing patience. | |
2755 | ||
96a816c5 JG |
2756 | @item set arrayprint |
2757 | @itemx set arrayprint on | |
2758 | @kindex set arrayprint | |
2759 | GDB will pretty print arrays. This format is more convenient to read, | |
2760 | but uses more space. The default is off. | |
2761 | ||
2762 | @item set arrayprint off. | |
2763 | Return to compressed format for arrays. | |
2764 | ||
9da601bf RP |
2765 | @item show arrayprint |
2766 | @kindex show arrayprint | |
2767 | Show whether compressed or pretty format is selected for displaying | |
2768 | arrays. | |
2769 | ||
96a816c5 JG |
2770 | @item set vtblprint |
2771 | @itemx set vtblprint on | |
9c91ee3e | 2772 | @kindex set vtblprint |
96a816c5 JG |
2773 | Pretty print C++ virtual function tables. The default is off. |
2774 | ||
2775 | @item set vtblprint off | |
2776 | Do not pretty print C++ virtual arrays. | |
2777 | ||
9da601bf RP |
2778 | @item show vtblprint |
2779 | @kindex show vtblprint | |
2780 | Show whether C++ virtual function tables are pretty printed, or not. | |
2781 | ||
96a816c5 JG |
2782 | @item set addressprint |
2783 | @item set adressprint on | |
2784 | @kindex set addressprint | |
2785 | GDB will print memory addresses in stack traces and structure values. | |
2786 | The default is on. | |
2787 | ||
2788 | @item set addressprint off | |
2789 | Do not print addresses. | |
2790 | ||
9da601bf RP |
2791 | @item show addressprint |
2792 | @kindex show addressprint | |
2793 | Show whether or not addresses are to be printed. | |
96a816c5 | 2794 | |
4187119d | 2795 | @item set prettyprint on |
2796 | @kindex set prettyprint | |
2797 | Cause GDB to print structures in an indented format with one member per | |
2798 | line, like this: | |
2799 | ||
2800 | @example | |
2801 | $1 = @{ | |
2802 | next = 0x0, | |
2803 | flags = @{ | |
2804 | sweet = 1, | |
2805 | sour = 1 | |
2806 | @}, | |
2807 | meat = 0x54 "Pork" | |
2808 | @} | |
2809 | @end example | |
2810 | ||
2811 | @item set prettyprint off | |
2812 | Cause GDB to print structures in a compact format, like this: | |
2813 | ||
2814 | @example | |
4afc6002 RP |
2815 | $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \ |
2816 | = 0x54 "Pork"@} | |
4187119d | 2817 | @end example |
2818 | ||
4afc6002 | 2819 | @noindent |
4187119d | 2820 | This is the default format. |
2821 | ||
9da601bf RP |
2822 | @item show prettyprint |
2823 | @kindex show prettyprint | |
2824 | Show which format GDB will use to print structures. | |
2825 | ||
4187119d | 2826 | @item set unionprint on |
2827 | @kindex set unionprint | |
2828 | Tell GDB to print unions which are contained in structures. This is the | |
2829 | default setting. | |
9da601bf | 2830 | |
4187119d | 2831 | @item set unionprint off |
2832 | Tell GDB not to print unions which are contained in structures. | |
2833 | ||
9da601bf RP |
2834 | @item show unionprint |
2835 | @kindex show unionprint | |
2836 | Ask GDB whether or not it will print unions which are contained in | |
2837 | structures. | |
2838 | ||
4187119d | 2839 | For example, given the declarations |
2840 | ||
2841 | @example | |
2842 | typedef enum @{Tree, Bug@} Species; | |
2843 | typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms; | |
9c91ee3e | 2844 | typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms; |
4187119d | 2845 | |
2846 | struct thing @{ | |
2847 | Species it; | |
2848 | union @{ | |
2849 | Tree_forms tree; | |
2850 | Bug_forms bug; | |
2851 | @} form; | |
2852 | @}; | |
2853 | ||
2854 | struct thing foo = @{Tree, @{Acorn@}@}; | |
2855 | @end example | |
2856 | ||
2857 | @noindent | |
2858 | with @samp{set unionprint on} in effect @samp{p foo} would print | |
2859 | ||
2860 | @example | |
2861 | $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@} | |
2862 | @end example | |
2863 | ||
2864 | @noindent | |
2865 | and with @samp{set unionprint off} in effect it would print | |
2866 | ||
2867 | @example | |
2868 | $1 = @{it = Tree, form = @{...@}@} | |
2869 | @end example | |
2870 | @end table | |
2871 | ||
2872 | @node Output formats, Memory, Format options, Data | |
2873 | @section Output formats | |
e91b87a3 | 2874 | |
2875 | @cindex formatted output | |
2876 | @cindex output formats | |
2877 | GDB normally prints all values according to their data types. Sometimes | |
2878 | this is not what you want. For example, you might want to print a number | |
2879 | in hex, or a pointer in decimal. Or you might want to view data in memory | |
2880 | at a certain address as a character string or an instruction. These things | |
2881 | can be done with @dfn{output formats}. | |
2882 | ||
2883 | The simplest use of output formats is to say how to print a value | |
2884 | already computed. This is done by starting the arguments of the | |
2885 | @samp{print} command with a slash and a format letter. The format | |
2886 | letters supported are: | |
2887 | ||
2888 | @table @samp | |
2889 | @item x | |
2890 | Regard the bits of the value as an integer, and print the integer in | |
2891 | hexadecimal. | |
2892 | ||
2893 | @item d | |
2894 | Print as integer in signed decimal. | |
2895 | ||
2896 | @item u | |
2897 | Print as integer in unsigned decimal. | |
2898 | ||
2899 | @item o | |
2900 | Print as integer in octal. | |
2901 | ||
2902 | @item a | |
9c91ee3e | 2903 | Print as an address, both absolute in hex and as an offset from the |
9da601bf RP |
2904 | nearest preceding symbol. This format can be used to discover where (in |
2905 | what function) an unknown address is located: | |
2906 | @example | |
2907 | (gdb) p/a 0x54320 | |
2908 | $3 = 0x54320 <_initialize_vx+396> | |
2909 | @end example | |
2910 | ||
e91b87a3 | 2911 | |
2912 | @item c | |
2913 | Regard as an integer and print it as a character constant. | |
2914 | ||
2915 | @item f | |
2916 | Regard the bits of the value as a floating point number and print | |
2917 | using typical floating point syntax. | |
2918 | @end table | |
2919 | ||
2920 | For example, to print the program counter in hex (@pxref{Registers}), type | |
2921 | ||
2922 | @example | |
2923 | p/x $pc | |
2924 | @end example | |
2925 | ||
2926 | @noindent | |
2927 | Note that no space is required before the slash; this is because command | |
2928 | names in GDB cannot contain a slash. | |
2929 | ||
2930 | To reprint the last value in the value history with a different format, | |
2931 | you can use the @samp{print} command with just a format and no | |
2932 | expression. For example, @samp{p/x} reprints the last value in hex. | |
2933 | ||
4187119d | 2934 | @node Memory, Auto Display, Output formats, Data |
e91b87a3 | 2935 | @subsection Examining Memory |
2936 | ||
2937 | @cindex examining memory | |
9da601bf RP |
2938 | @table @code |
2939 | @kindex disassemble | |
2940 | @item disassemble | |
2941 | This specialized command is provided to dump a range of memory as | |
2942 | machine instructions. The default memory range is the function | |
2943 | surrounding the program counter of the selected frame. A single | |
2944 | argument to this command is a program counter value; the function | |
2945 | surrounding this value will be dumped. Two arguments (separated by one | |
2946 | or more spaces) specify a range of addresss (first inclusive, second | |
2947 | exclusive) to be dumped. | |
2948 | ||
e91b87a3 | 2949 | @kindex x |
9da601bf | 2950 | @item x |
4187119d | 2951 | The command @samp{x} (for `examine') can be used to examine memory |
2952 | without reference to the program's data types. The format in which you | |
2953 | wish to examine memory is instead explicitly specified. The allowable | |
2954 | formats are a superset of the formats described in the previous section. | |
9da601bf | 2955 | @end table |
e91b87a3 | 2956 | |
2957 | @samp{x} is followed by a slash and an output format specification, | |
2958 | followed by an expression for an address. The expression need not have | |
2959 | a pointer value (though it may); it is used as an integer, as the | |
4187119d | 2960 | address of a byte of memory. @xref{Expressions} for more information on |
2961 | expressions. For example, @samp{x/4xw $sp} prints the four words of | |
2962 | memory above the stack pointer in hexadecimal. | |
e91b87a3 | 2963 | |
2964 | The output format in this case specifies both how big a unit of memory | |
2965 | to examine and how to print the contents of that unit. It is done | |
2966 | with one or two of the following letters: | |
2967 | ||
2968 | These letters specify just the size of unit to examine: | |
2969 | ||
2970 | @table @samp | |
2971 | @item b | |
2972 | Examine individual bytes. | |
2973 | ||
2974 | @item h | |
2975 | Examine halfwords (two bytes each). | |
2976 | ||
2977 | @item w | |
2978 | Examine words (four bytes each). | |
2979 | ||
2980 | @cindex word | |
2981 | Many assemblers and cpu designers still use `word' for a 16-bit quantity, | |
2982 | as a holdover from specific predecessor machines of the 1970's that really | |
2983 | did use two-byte words. But more generally the term `word' has always | |
2984 | referred to the size of quantity that a machine normally operates on and | |
4187119d | 2985 | stores in its registers. This is 32 bits for all the machines that GDB |
e91b87a3 | 2986 | runs on. |
2987 | ||
2988 | @item g | |
2989 | Examine giant words (8 bytes). | |
2990 | @end table | |
2991 | ||
2992 | These letters specify just the way to print the contents: | |
2993 | ||
2994 | @table @samp | |
2995 | @item x | |
2996 | Print as integers in unsigned hexadecimal. | |
2997 | ||
2998 | @item d | |
2999 | Print as integers in signed decimal. | |
3000 | ||
3001 | @item u | |
3002 | Print as integers in unsigned decimal. | |
3003 | ||
3004 | @item o | |
3005 | Print as integers in unsigned octal. | |
3006 | ||
3007 | @item a | |
3008 | Print as an address, both absolute in hex and then relative | |
3009 | to a symbol defined as an address below it. | |
3010 | ||
3011 | @item c | |
3012 | Print as character constants. | |
3013 | ||
3014 | @item f | |
3015 | Print as floating point. This works only with sizes @samp{w} and | |
3016 | @samp{g}. | |
3017 | ||
3018 | @item s | |
3019 | Print a null-terminated string of characters. The specified unit size | |
3020 | is ignored; instead, the unit is however many bytes it takes to reach | |
3021 | a null character (including the null character). | |
3022 | ||
3023 | @item i | |
3024 | Print a machine instruction in assembler syntax (or nearly). The | |
3025 | specified unit size is ignored; the number of bytes in an instruction | |
3026 | varies depending on the type of machine, the opcode and the addressing | |
9da601bf RP |
3027 | modes used. The command @samp{disassemble} gives an alternative way of |
3028 | inspecting machine instructions. | |
e91b87a3 | 3029 | @end table |
3030 | ||
3031 | If either the manner of printing or the size of unit fails to be specified, | |
3032 | the default is to use the same one that was used last. If you don't want | |
3033 | to use any letters after the slash, you can omit the slash as well. | |
3034 | ||
3035 | You can also omit the address to examine. Then the address used is | |
3036 | just after the last unit examined. This is why string and instruction | |
3037 | formats actually compute a unit-size based on the data: so that the | |
3038 | next string or instruction examined will start in the right place. | |
3039 | The @samp{print} command sometimes sets the default address for | |
3040 | the @samp{x} command; when the value printed resides in memory, the | |
3041 | default is set to examine the same location. @samp{info line} also | |
3042 | sets the default for @samp{x}, to the address of the start of the | |
3043 | machine code for the specified line and @samp{info breakpoints} sets | |
3044 | it to the address of the last breakpoint listed. | |
3045 | ||
3046 | When you use @key{RET} to repeat an @samp{x} command, it does not repeat | |
3047 | exactly the same: the address specified previously (if any) is ignored, so | |
3048 | that the repeated command examines the successive locations in memory | |
3049 | rather than the same ones. | |
3050 | ||
3051 | You can examine several consecutive units of memory with one command by | |
3052 | writing a repeat-count after the slash (before the format letters, if any). | |
3053 | The repeat count must be a decimal integer. It has the same effect as | |
3054 | repeating the @samp{x} command that many times except that the output may | |
4187119d | 3055 | be more compact with several units per line. For example, |
e91b87a3 | 3056 | |
3057 | @example | |
3058 | x/10i $pc | |
3059 | @end example | |
3060 | ||
3061 | @noindent | |
4187119d | 3062 | prints ten instructions starting with the one to be executed next in the |
9da601bf | 3063 | selected frame. After doing this, you could print another seven following |
e91b87a3 | 3064 | instructions with |
3065 | ||
3066 | @example | |
9da601bf | 3067 | x/7 |
e91b87a3 | 3068 | @end example |
3069 | ||
3070 | @noindent | |
3071 | in which the format and address are allowed to default. | |
3072 | ||
3073 | @kindex $_ | |
3074 | @kindex $__ | |
3075 | The addresses and contents printed by the @samp{x} command are not put in | |
3076 | the value history because there is often too much of them and they would | |
3077 | get in the way. Instead, GDB makes these values available for subsequent | |
4187119d | 3078 | use in expressions as values of the convenience variables @code{$_} and |
3079 | @code{$__}. | |
e91b87a3 | 3080 | |
3081 | After an @samp{x} command, the last address examined is available for use | |
4187119d | 3082 | in expressions in the convenience variable @code{$_}. The contents of that |
3083 | address, as examined, are available in the convenience variable @code{$__}. | |
e91b87a3 | 3084 | |
3085 | If the @samp{x} command has a repeat count, the address and contents saved | |
3086 | are from the last memory unit printed; this is not the same as the last | |
3087 | address printed if several units were printed on the last line of output. | |
3088 | ||
3089 | @node Auto Display, Value History, Memory, Data | |
3090 | @section Automatic Display | |
4187119d | 3091 | @cindex automatic display |
3092 | @cindex display of expressions | |
e91b87a3 | 3093 | |
3094 | If you find that you want to print the value of an expression frequently | |
3095 | (to see how it changes), you might want to add it to the @dfn{automatic | |
3096 | display list} so that GDB will print its value each time the program stops. | |
3097 | Each expression added to the list is given a number to identify it; | |
3098 | to remove an expression from the list, you specify that number. | |
3099 | The automatic display looks like this: | |
3100 | ||
3101 | @example | |
3102 | 2: foo = 38 | |
3103 | 3: bar[5] = (struct hack *) 0x3804 | |
3104 | @end example | |
3105 | ||
3106 | @noindent | |
3107 | showing item numbers, expressions and their current values. | |
3108 | ||
4187119d | 3109 | If the expression refers to local variables, then it does not make sense |
3110 | outside the lexical context for which it was set up. Such an expression | |
9c91ee3e RP |
3111 | is disabled when execution enters a context where one of its variables |
3112 | is not defined. For example, if you give the command | |
3113 | @samp{display name} while inside a function with an argument | |
3114 | @code{name}, then this argument will be displayed while the program | |
3115 | continues to stop inside that function. When it stops elsewhere---where | |
3116 | there is no variable @samp{name}---display is disabled. The next time | |
3117 | your program stops where @samp{name} is meaningful, you can enable the | |
3118 | display expression once again. | |
4187119d | 3119 | |
e91b87a3 | 3120 | @table @code |
3121 | @item display @var{exp} | |
3122 | @kindex display | |
3123 | Add the expression @var{exp} to the list of expressions to display | |
3124 | each time the program stops. @xref{Expressions}. | |
3125 | ||
3126 | @item display/@var{fmt} @var{exp} | |
3127 | For @var{fmt} specifying only a display format and not a size or | |
3128 | count, add the expression @var{exp} to the auto-display list but | |
3129 | arranges to display it each time in the specified format @var{fmt}. | |
3130 | ||
3131 | @item display/@var{fmt} @var{addr} | |
3132 | For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a | |
3133 | number of units, add the expression @var{addr} as a memory address to | |
3134 | be examined each time the program stops. Examining means in effect | |
3135 | doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}. | |
3136 | ||
3137 | @item undisplay @var{dnums}@dots{} | |
4187119d | 3138 | @itemx delete display @var{dnums}@dots{} |
e91b87a3 | 3139 | @kindex delete display |
4187119d | 3140 | @kindex undisplay |
e91b87a3 | 3141 | Remove item numbers @var{dnums} from the list of expressions to display. |
3142 | ||
3143 | @item disable display @var{dnums}@dots{} | |
3144 | @kindex disable display | |
4187119d | 3145 | Disable the display of item numbers @var{dnums}. A disabled display |
3146 | item is not printed automatically, but is not forgotten. It may be | |
3147 | reenabled later. | |
e91b87a3 | 3148 | |
3149 | @item enable display @var{dnums}@dots{} | |
3150 | @kindex enable display | |
3151 | Enable display of item numbers @var{dnums}. It becomes effective once | |
3152 | again in auto display of its expression, until you specify otherwise. | |
3153 | ||
3154 | @item display | |
3155 | Display the current values of the expressions on the list, just as is | |
3156 | done when the program stops. | |
3157 | ||
3158 | @item info display | |
3159 | @kindex info display | |
4187119d | 3160 | Print the list of expressions previously set up to display |
3161 | automatically, each one with its item number, but without showing the | |
3162 | values. This includes disabled expressions, which are marked as such. | |
3163 | It also includes expressions which would not be displayed right now | |
3164 | because they refer to automatic variables not currently available. | |
e91b87a3 | 3165 | @end table |
3166 | ||
3167 | @node Value History, Convenience Vars, Auto Display, Data | |
3168 | @section Value History | |
3169 | ||
3170 | @cindex value history | |
3171 | Every value printed by the @samp{print} command is saved for the entire | |
3172 | session in GDB's @dfn{value history} so that you can refer to it in | |
3173 | other expressions. | |
3174 | ||
4187119d | 3175 | @cindex @code{$} |
3176 | @cindex @code{$$} | |
3177 | @cindex history number | |
e91b87a3 | 3178 | The values printed are given @dfn{history numbers} for you to refer to them |
3179 | by. These are successive integers starting with 1. @samp{print} shows you | |
4187119d | 3180 | the history number assigned to a value by printing @samp{$@var{num} = } |
3181 | before the value; here @var{num} is the history number. | |
e91b87a3 | 3182 | |
3183 | To refer to any previous value, use @samp{$} followed by the value's | |
9da601bf RP |
3184 | history number. The output printed by @samp{print} is designed to |
3185 | remind you of this. Just @code{$} refers to the most recent value in | |
3186 | the history, and @code{$$} refers to the value before that. | |
3187 | @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2} | |
3188 | is the value just prior to @code{$$}, @code{$$1} is equivalent to | |
3189 | @code{$$}, and @code{$$0} is equivalent to @code{$}. | |
e91b87a3 | 3190 | |
3191 | For example, suppose you have just printed a pointer to a structure and | |
3192 | want to see the contents of the structure. It suffices to type | |
3193 | ||
3194 | @example | |
3195 | p *$ | |
3196 | @end example | |
3197 | ||
3198 | If you have a chain of structures where the component @samp{next} points | |
4187119d | 3199 | to the next one, you can print the contents of the next one with this: |
e91b87a3 | 3200 | |
3201 | @example | |
3202 | p *$.next | |
3203 | @end example | |
3204 | ||
4187119d | 3205 | @noindent |
e91b87a3 | 3206 | It might be useful to repeat this command many times by typing @key{RET}. |
3207 | ||
3208 | Note that the history records values, not expressions. If the value of | |
4187119d | 3209 | @code{x} is 4 and you type this command: |
e91b87a3 | 3210 | |
3211 | @example | |
3212 | print x | |
3213 | set x=5 | |
3214 | @end example | |
3215 | ||
3216 | @noindent | |
3217 | then the value recorded in the value history by the @samp{print} command | |
4187119d | 3218 | remains 4 even though the value of @code{x} has changed. |
e91b87a3 | 3219 | |
3220 | @table @code | |
4187119d | 3221 | @item info values |
3222 | @kindex info values | |
9da601bf RP |
3223 | @itemx info history |
3224 | @kindex info history | |
3225 | These two commands are synonymous. Either form will print the last ten | |
3226 | values in the value history, with their item numbers. This is like | |
3227 | @samp{p@ $$9} repeated ten times, except that @samp{info values} does | |
3228 | not change the history. | |
e91b87a3 | 3229 | |
4187119d | 3230 | @item info values @var{n} |
e91b87a3 | 3231 | Print ten history values centered on history item number @var{n}. |
4187119d | 3232 | |
3233 | @item info values + | |
3234 | Print ten history values just after the values last printed. | |
e91b87a3 | 3235 | @end table |
3236 | ||
3237 | @node Convenience Vars, Registers, Value History, Data | |
3238 | @section Convenience Variables | |
3239 | ||
3240 | @cindex convenience variables | |
3241 | GDB provides @dfn{convenience variables} that you can use within GDB to | |
3242 | hold on to a value and refer to it later. These variables exist entirely | |
3243 | within GDB; they are not part of your program, and setting a convenience | |
3244 | variable has no effect on further execution of your program. That's why | |
3245 | you can use them freely. | |
3246 | ||
3247 | Convenience variables have names starting with @samp{$}. Any name starting | |
3248 | with @samp{$} can be used for a convenience variable, unless it is one of | |
3249 | the predefined set of register names (@pxref{Registers}). | |
3250 | ||
3251 | You can save a value in a convenience variable with an assignment | |
3252 | expression, just as you would set a variable in your program. Example: | |
3253 | ||
3254 | @example | |
3255 | set $foo = *object_ptr | |
3256 | @end example | |
3257 | ||
3258 | @noindent | |
4187119d | 3259 | would save in @code{$foo} the value contained in the object pointed to by |
e91b87a3 | 3260 | @code{object_ptr}. |
3261 | ||
3262 | Using a convenience variable for the first time creates it; but its value | |
3263 | is @code{void} until you assign a new value. You can alter the value with | |
3264 | another assignment at any time. | |
3265 | ||
3266 | Convenience variables have no fixed types. You can assign a convenience | |
3267 | variable any type of value, even if it already has a value of a different | |
3268 | type. The convenience variable as an expression has whatever type its | |
3269 | current value has. | |
3270 | ||
3271 | @table @code | |
3272 | @item info convenience | |
3273 | @kindex info convenience | |
3274 | Print a list of convenience variables used so far, and their values. | |
3275 | Abbreviated @samp{i con}. | |
3276 | @end table | |
3277 | ||
3278 | One of the ways to use a convenience variable is as a counter to be | |
3279 | incremented or a pointer to be advanced. For example: | |
3280 | ||
3281 | @example | |
3282 | set $i = 0 | |
3283 | print bar[$i++]->contents | |
3284 | @i{@dots{}repeat that command by typing @key{RET}.} | |
3285 | @end example | |
3286 | ||
3287 | Some convenience variables are created automatically by GDB and given | |
3288 | values likely to be useful. | |
3289 | ||
4187119d | 3290 | @table @code |
e91b87a3 | 3291 | @item $_ |
4187119d | 3292 | The variable @code{$_} is automatically set by the @samp{x} command to |
e91b87a3 | 3293 | the last address examined (@pxref{Memory}). Other commands which |
4187119d | 3294 | provide a default address for @samp{x} to examine also set @code{$_} |
e91b87a3 | 3295 | to that address; these commands include @samp{info line} and @samp{info |
3296 | breakpoint}. | |
3297 | ||
3298 | @item $__ | |
4187119d | 3299 | The variable @code{$__} is automatically set by the @samp{x} command |
e91b87a3 | 3300 | to the value found in the last address examined. |
3301 | @end table | |
3302 | ||
3303 | @node Registers,, Convenience Vars, Data | |
3304 | @section Registers | |
3305 | ||
3306 | @cindex registers | |
3307 | Machine register contents can be referred to in expressions as variables | |
3308 | with names starting with @samp{$}. The names of registers are different | |
3309 | for each machine; use @samp{info registers} to see the names used on your | |
4187119d | 3310 | machine. The names @code{$pc} and @code{$sp} are used on all machines for |
3311 | the program counter register and the stack pointer. Often @code{$fp} is | |
3312 | used for a register that contains a pointer to the current stack frame, | |
3313 | and @code{$ps} is used for a register that contains the processor | |
3314 | status. These standard register names may be available on your machine | |
3315 | even though the @code{info registers} command displays them with a | |
3316 | different name. For example, on the SPARC, @code{info registers} | |
3317 | displays the processor status register as @code{$psr} but you can also | |
3318 | refer to it as @code{$ps}. | |
e91b87a3 | 3319 | |
3320 | GDB always considers the contents of an ordinary register as an integer | |
3321 | when the register is examined in this way. Some machines have special | |
3322 | registers which can hold nothing but floating point; these registers are | |
3323 | considered floating point. There is no way to refer to the contents of an | |
3324 | ordinary register as floating point value (although you can @emph{print} | |
3325 | it as a floating point value with @samp{print/f $@var{regname}}). | |
3326 | ||
3327 | Some registers have distinct ``raw'' and ``virtual'' data formats. This | |
9da601bf RP |
3328 | means that the data format in which the register contents are saved by |
3329 | the operating system is not the same one that your program normally | |
3330 | sees. For example, the registers of the 68881 floating point | |
3331 | coprocessor are always saved in ``extended'' (raw) format, but all C | |
3332 | programs expect to work with ``double'' (virtual) format. In such | |
3333 | cases, GDB normally works with the virtual format only (the format that | |
3334 | makes sense for your program), but the @samp{info registers} command | |
3335 | prints the data in both formats. | |
e91b87a3 | 3336 | |
3337 | Register values are relative to the selected stack frame | |
3338 | (@pxref{Selection}). This means that you get the value that the register | |
3339 | would contain if all stack frames farther in were exited and their saved | |
3340 | registers restored. In order to see the real contents of all registers, | |
3341 | you must select the innermost frame (with @samp{frame 0}). | |
3342 | ||
3343 | Some registers are never saved (typically those numbered zero or one) | |
3344 | because they are used for returning function values; for these registers, | |
3345 | relativization makes no difference. | |
3346 | ||
3347 | @table @code | |
3348 | @item info registers | |
3349 | @kindex info registers | |
3350 | Print the names and relativized values of all registers. | |
3351 | ||
3352 | @item info registers @var{regname} | |
3353 | Print the relativized value of register @var{regname}. @var{regname} | |
3354 | may be any register name valid on the machine you are using, with | |
3355 | or without the initial @samp{$}. | |
3356 | @end table | |
3357 | ||
3358 | @subsection Examples | |
3359 | ||
3360 | You could print the program counter in hex with | |
3361 | ||
3362 | @example | |
3363 | p/x $pc | |
3364 | @end example | |
3365 | ||
3366 | @noindent | |
3367 | or print the instruction to be executed next with | |
3368 | ||
3369 | @example | |
3370 | x/i $pc | |
3371 | @end example | |
3372 | ||
3373 | @noindent | |
3374 | or add four to the stack pointer with | |
3375 | ||
3376 | @example | |
3377 | set $sp += 4 | |
3378 | @end example | |
3379 | ||
3380 | @noindent | |
3381 | The last is a way of removing one word from the stack, on machines where | |
3382 | stacks grow downward in memory (most machines, nowadays). This assumes | |
4187119d | 3383 | that the innermost stack frame is selected. Setting @code{$sp} is |
e91b87a3 | 3384 | not allowed when other stack frames are selected. |
3385 | ||
3386 | @node Symbols, Altering, Data, Top | |
3387 | @chapter Examining the Symbol Table | |
3388 | ||
9c91ee3e RP |
3389 | The commands described in this section allow you to inquire about the |
3390 | symbols (names of variables, functions and types) defined in your | |
3391 | program. This information is found by GDB in the symbol table loaded by | |
3392 | the @samp{symbol-file} command; it is inherent in the text of your | |
3393 | program and does not change as the program executes. | |
e91b87a3 | 3394 | |
3395 | @table @code | |
e91b87a3 | 3396 | @item info address @var{symbol} |
3397 | @kindex info address | |
4187119d | 3398 | Describe where the data for @var{symbol} is stored. For a register |
3399 | variable, this says which register it is kept in. For a non-register | |
3400 | local variable, this prints the stack-frame offset at which the variable | |
3401 | is always stored. | |
3402 | ||
3403 | Note the contrast with @samp{print &@var{symbol}}, which does not work | |
3404 | at all for a register variables, and for a stack local variable prints | |
3405 | the exact address of the current instantiation of the variable. | |
e91b87a3 | 3406 | |
831c8511 JG |
3407 | @item whatis @var{exp} |
3408 | @kindex whatis | |
3409 | Print the data type of expression @var{exp}. @var{exp} is not | |
3410 | actually evaluated, and any side-effecting operations (such as | |
3411 | assignments or function calls) inside it do not take place. | |
3412 | @xref{Expressions}. | |
3413 | ||
3414 | @item whatis | |
3415 | Print the data type of @code{$}, the last value in the value history. | |
3416 | ||
e91b87a3 | 3417 | @item ptype @var{typename} |
3418 | @kindex ptype | |
3419 | Print a description of data type @var{typename}. @var{typename} may be | |
3420 | the name of a type, or for C code it may have the form | |
3421 | @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or | |
3422 | @samp{enum @var{enum-tag}}.@refill | |
3423 | ||
831c8511 JG |
3424 | @item ptype @var{exp} |
3425 | Print a description of the type of expression @var{exp}. This is like | |
3426 | @samp{whatis} except it prints a detailed description, instead of just | |
3427 | the name of the type. For example, if the type of a variable is | |
3428 | @samp{struct complex @{double real; double imag;@}}, @samp{whatis} will | |
3429 | print @samp{struct complex} and @samp{ptype} will print @samp{struct | |
3430 | complex @{double real; double imag;@}} | |
3431 | ||
e91b87a3 | 3432 | @item info sources |
3433 | @kindex info sources | |
3434 | Print the names of all source files in the program for which there | |
3435 | is debugging information. | |
3436 | ||
3437 | @item info functions | |
3438 | @kindex info functions | |
3439 | Print the names and data types of all defined functions. | |
3440 | ||
3441 | @item info functions @var{regexp} | |
3442 | Print the names and data types of all defined functions | |
3443 | whose names contain a match for regular expression @var{regexp}. | |
3444 | Thus, @samp{info fun step} finds all functions whose names | |
3445 | include @samp{step}; @samp{info fun ^step} finds those whose names | |
3446 | start with @samp{step}. | |
3447 | ||
3448 | @item info variables | |
3449 | @kindex info variables | |
3450 | Print the names and data types of all variables that are declared | |
4187119d | 3451 | outside of functions (i.e., except for local variables). |
e91b87a3 | 3452 | |
3453 | @item info variables @var{regexp} | |
4187119d | 3454 | Print the names and data types of all variables (except for local |
3455 | variables) whose names contain a match for regular expression | |
e91b87a3 | 3456 | @var{regexp}. |
3457 | ||
e91b87a3 | 3458 | |
7a67dd45 | 3459 | @ignore |
3460 | This was never implemented. | |
e91b87a3 | 3461 | @item info methods |
4187119d | 3462 | @itemx info methods @var{regexp} |
e91b87a3 | 3463 | @kindex info methods |
3464 | The @samp{info-methods} command permits the user to examine all defined | |
4187119d | 3465 | methods within C++ program, or (with the @var{regexp} argument) a |
3466 | specific set of methods found in the various C++ classes. Many | |
3467 | C++ classes provide a large number of methods. Thus, the output | |
3468 | from the @samp{ptype} command can be overwhelming and hard to use. The | |
3469 | @samp{info-methods} command filters the methods, printing only those | |
3470 | which match the regular-expression @var{regexp}. | |
7a67dd45 | 3471 | @end ignore |
e91b87a3 | 3472 | |
3473 | @item printsyms @var{filename} | |
3474 | @kindex printsyms | |
3475 | Write a complete dump of the debugger's symbol data into the | |
3476 | file @var{filename}. | |
3477 | @end table | |
3478 | ||
3479 | @node Altering, Sequences, Symbols, Top | |
3480 | @chapter Altering Execution | |
3481 | ||
9c91ee3e | 3482 | Once you think you have found an error in the program, you might want to |
4187119d | 3483 | find out for certain whether correcting the apparent error would lead to |
3484 | correct results in the rest of the run. You can find the answer by | |
3485 | experiment, using the GDB features for altering execution of the | |
3486 | program. | |
3487 | ||
3488 | For example, you can store new values into variables or memory | |
3489 | locations, give the program a signal, restart it at a different address, | |
3490 | or even return prematurely from a function to its caller. | |
e91b87a3 | 3491 | |
3492 | @menu | |
3493 | * Assignment:: Altering variable values or memory contents. | |
3494 | * Jumping:: Altering control flow. | |
3495 | * Signaling:: Making signals happen in the program. | |
3496 | * Returning:: Making a function return prematurely. | |
9da601bf | 3497 | * Calling:: Calling functions from your program |
e91b87a3 | 3498 | @end menu |
3499 | ||
3500 | @node Assignment, Jumping, Altering, Altering | |
3501 | @section Assignment to Variables | |
3502 | ||
3503 | @cindex assignment | |
3504 | @cindex setting variables | |
3505 | To alter the value of a variable, evaluate an assignment expression. | |
3506 | @xref{Expressions}. For example, | |
3507 | ||
3508 | @example | |
3509 | print x=4 | |
3510 | @end example | |
3511 | ||
3512 | @noindent | |
3513 | would store the value 4 into the variable @code{x}, and then print | |
3514 | the value of the assignment expression (which is 4). | |
3515 | ||
4187119d | 3516 | All the assignment operators of C are supported, including the |
3517 | incrementation operators @samp{++} and @samp{--}, and combining | |
3518 | assignments such as @samp{+=} and @samp{<<=}. | |
3519 | ||
e91b87a3 | 3520 | @kindex set |
3521 | @kindex set variable | |
3522 | If you are not interested in seeing the value of the assignment, use the | |
3523 | @samp{set} command instead of the @samp{print} command. @samp{set} is | |
3524 | really the same as @samp{print} except that the expression's value is not | |
3525 | printed and is not put in the value history (@pxref{Value History}). The | |
3526 | expression is evaluated only for side effects. | |
3527 | ||
3528 | Note that if the beginning of the argument string of the @samp{set} command | |
3529 | appears identical to a @samp{set} subcommand, it may be necessary to use | |
3530 | the @samp{set variable} command. This command is identical to @samp{set} | |
3531 | except for its lack of subcommands. | |
3532 | ||
3533 | GDB allows more implicit conversions in assignments than C does; you can | |
3534 | freely store an integer value into a pointer variable or vice versa, and | |
3535 | any structure can be converted to any other structure that is the same | |
3536 | length or shorter. | |
9c91ee3e RP |
3537 | @comment FIXME: how do structs align/pad in these conversions? |
3538 | @comment /[email protected] 18dec1990 | |
e91b87a3 | 3539 | |
4187119d | 3540 | To store values into arbitrary places in memory, use the @samp{@{@dots{}@}} |
e91b87a3 | 3541 | construct to generate a value of specified type at a specified address |
4187119d | 3542 | (@pxref{Expressions}). For example, @code{@{int@}0x83040} would refer |
3543 | to memory location 0x83040 as an integer (which implies a certain size | |
3544 | and representation in memory), and | |
e91b87a3 | 3545 | |
3546 | @example | |
3547 | set @{int@}0x83040 = 4 | |
3548 | @end example | |
3549 | ||
4187119d | 3550 | would store the value 4 into that memory location. |
3551 | ||
e91b87a3 | 3552 | @node Jumping, Signaling, Assignment, Altering |
3553 | @section Continuing at a Different Address | |
3554 | ||
4187119d | 3555 | Ordinarily, when you continue the program, you do so at the place where |
3556 | it stopped, with the @samp{cont} command. You can instead continue at | |
3557 | an address of your own choosing, with the following commands: | |
3558 | ||
e91b87a3 | 3559 | @table @code |
3560 | @item jump @var{linenum} | |
3561 | @kindex jump | |
3562 | Resume execution at line number @var{linenum}. Execution may stop | |
3563 | immediately if there is a breakpoint there. | |
3564 | ||
3565 | The @samp{jump} command does not change the current stack frame, or | |
3566 | the stack pointer, or the contents of any memory location or any | |
3567 | register other than the program counter. If line @var{linenum} is in | |
3568 | a different function from the one currently executing, the results may | |
4187119d | 3569 | be bizarre if the two functions expect different patterns of arguments or |
e91b87a3 | 3570 | of local variables. For this reason, the @samp{jump} command requests |
3571 | confirmation if the specified line is not in the function currently | |
4187119d | 3572 | executing. However, even bizarre results are predictable based on |
3573 | careful study of the machine-language code of the program. | |
e91b87a3 | 3574 | |
3575 | @item jump *@var{address} | |
3576 | Resume execution at the instruction at address @var{address}. | |
3577 | @end table | |
3578 | ||
4187119d | 3579 | You can get much the same effect as the @code{jump} command by storing a |
3580 | new value into the register @code{$pc}. The difference is that this | |
3581 | does not start the program running; it only changes the address where it | |
3582 | @emph{will} run when it is continued. For example, | |
e91b87a3 | 3583 | |
3584 | @example | |
3585 | set $pc = 0x485 | |
3586 | @end example | |
3587 | ||
3588 | @noindent | |
4187119d | 3589 | causes the next @samp{cont} command or stepping command to execute at |
3590 | address 0x485, rather than at the address where the program stopped. | |
3591 | @xref{Stepping}. | |
3592 | ||
9da601bf RP |
3593 | The most common occasion to use the @samp{jump} command is to back up, |
3594 | perhaps with more breakpoints set, over a portion of a program that has | |
3595 | already executed. | |
e91b87a3 | 3596 | |
3597 | @node Signaling, Returning, Jumping, Altering | |
3598 | @section Giving the Program a Signal | |
3599 | ||
3600 | @table @code | |
3601 | @item signal @var{signalnum} | |
3602 | @kindex signal | |
4187119d | 3603 | Resume execution where the program stopped, but give it immediately the |
3604 | signal number @var{signalnum}. | |
3605 | ||
3606 | Alternatively, if @var{signalnum} is zero, continue execution without | |
3607 | giving a signal. This is useful when the program stopped on account of | |
3608 | a signal and would ordinary see the signal when resumed with the | |
3609 | @samp{cont} command; @samp{signal 0} causes it to resume without a | |
3610 | signal. | |
e91b87a3 | 3611 | @end table |
3612 | ||
9da601bf | 3613 | @node Returning, Calling, Signaling, Altering |
e91b87a3 | 3614 | @section Returning from a Function |
3615 | ||
3616 | @cindex returning from a function | |
3617 | @kindex return | |
4187119d | 3618 | You can cancel execution of a function call with the @samp{return} |
3619 | command. This command has the effect of discarding the selected stack | |
3620 | frame (and all frames within it), so that control moves to the caller of | |
3621 | that function. You can think of this as making the discarded frame | |
3622 | return prematurely. | |
e91b87a3 | 3623 | |
3624 | First select the stack frame that you wish to return from | |
4187119d | 3625 | (@pxref{Selection}). Then type the @samp{return} command. If you wish |
3626 | to specify the value to be returned, give that as an argument. | |
e91b87a3 | 3627 | |
3628 | This pops the selected stack frame (and any other frames inside of it), | |
3629 | leaving its caller as the innermost remaining frame. That frame becomes | |
3630 | selected. The specified value is stored in the registers used for | |
3631 | returning values of functions. | |
3632 | ||
4187119d | 3633 | The @samp{return} command does not resume execution; it leaves the |
3634 | program stopped in the state that would exist if the function had just | |
3635 | returned. Contrast this with the @samp{finish} command | |
3636 | (@pxref{Stepping}), which resumes execution until the selected stack | |
3637 | frame returns @emph{naturally}. | |
e91b87a3 | 3638 | |
9da601bf RP |
3639 | @node Calling, , , Returning, Altering |
3640 | @comment node-name, next, previous, up | |
3641 | @section Calling Functions from your Program | |
3642 | ||
3643 | @cindex calling functions | |
3644 | @kindex call | |
3645 | @table @code | |
3646 | @item call @var{function}(@var{args}) | |
3647 | @end table | |
3648 | You can call functions in the inferior process directly from GDB with | |
3649 | this command. The argument is the function name and arguments, in | |
3650 | standard C notation. The result is printed and saved in the value | |
3651 | history, if it is not void. | |
3652 | ||
4187119d | 3653 | @node Sequences, Options, Altering, Top |
e91b87a3 | 3654 | @chapter Canned Sequences of Commands |
3655 | ||
3656 | GDB provides two ways to store sequences of commands for execution as a | |
3657 | unit: user-defined commands and command files. | |
3658 | ||
3659 | @menu | |
3660 | * Define:: User-defined commands. | |
3661 | * Command Files:: Command files. | |
3662 | * Output:: Controlled output commands useful in | |
3663 | user-defined commands and command files. | |
3664 | @end menu | |
3665 | ||
3666 | @node Define, Command Files, Sequences, Sequences | |
3667 | @section User-Defined Commands | |
3668 | ||
4187119d | 3669 | @cindex user-defined command |
e91b87a3 | 3670 | A @dfn{user-defined command} is a sequence of GDB commands to which you |
3671 | assign a new name as a command. This is done with the @samp{define} | |
3672 | command. | |
3673 | ||
3674 | @table @code | |
3675 | @item define @var{commandname} | |
3676 | @kindex define | |
3677 | Define a command named @var{commandname}. If there is already a command | |
3678 | by that name, you are asked to confirm that you want to redefine it. | |
3679 | ||
3680 | The definition of the command is made up of other GDB command lines, | |
3681 | which are given following the @samp{define} command. The end of these | |
3682 | commands is marked by a line containing @samp{end}. | |
3683 | ||
3684 | @item document @var{commandname} | |
3685 | @kindex document | |
3686 | Give documentation to the user-defined command @var{commandname}. The | |
3687 | command @var{commandname} must already be defined. This command reads | |
3688 | lines of documentation just as @samp{define} reads the lines of the | |
4187119d | 3689 | command definition, ending with @samp{end}. After the @samp{document} |
3690 | command is finished, @samp{help} on command @var{commandname} will print | |
3691 | the documentation you have specified. | |
e91b87a3 | 3692 | |
3693 | You may use the @samp{document} command again to change the | |
3694 | documentation of a command. Redefining the command with @samp{define} | |
3695 | does not change the documentation. | |
3696 | @end table | |
3697 | ||
3698 | User-defined commands do not take arguments. When they are executed, the | |
3699 | commands of the definition are not printed. An error in any command | |
3700 | stops execution of the user-defined command. | |
3701 | ||
3702 | Commands that would ask for confirmation if used interactively proceed | |
3703 | without asking when used inside a user-defined command. Many GDB commands | |
3704 | that normally print messages to say what they are doing omit the messages | |
3705 | when used in user-defined command. | |
3706 | ||
3707 | @node Command Files, Output, Define, Sequences | |
3708 | @section Command Files | |
3709 | ||
3710 | @cindex command files | |
3711 | A command file for GDB is a file of lines that are GDB commands. Comments | |
3712 | (lines starting with @samp{#}) may also be included. An empty line in a | |
3713 | command file does nothing; it does not mean to repeat the last command, as | |
3714 | it would from the terminal. | |
3715 | ||
3716 | @cindex init file | |
4187119d | 3717 | @cindex @file{.gdbinit} |
9da601bf | 3718 | When you start GDB, it first executes commands from its @dfn{init files}. |
4afc6002 RP |
3719 | These are files named @file{.gdbinit}. GDB reads the init file (if any) |
3720 | in your home directory and then the init file (if any) in the current | |
3721 | working directory. (The init files are not executed if the @samp{-nx} | |
3722 | option is given.) You can also request the execution of a command file | |
3723 | with the @samp{source} command: | |
e91b87a3 | 3724 | |
3725 | @table @code | |
3726 | @item source @var{filename} | |
3727 | @kindex source | |
3728 | Execute the command file @var{filename}. | |
3729 | @end table | |
3730 | ||
3731 | The lines in a command file are executed sequentially. They are not | |
3732 | printed as they are executed. An error in any command terminates execution | |
3733 | of the command file. | |
3734 | ||
3735 | Commands that would ask for confirmation if used interactively proceed | |
3736 | without asking when used in a command file. Many GDB commands that | |
3737 | normally print messages to say what they are doing omit the messages | |
3738 | when used in a command file. | |
3739 | ||
3740 | @node Output,, Command Files, Sequences | |
3741 | @section Commands for Controlled Output | |
3742 | ||
3743 | During the execution of a command file or a user-defined command, the only | |
3744 | output that appears is what is explicitly printed by the commands of the | |
3745 | definition. This section describes three commands useful for generating | |
3746 | exactly the output you want. | |
3747 | ||
3748 | @table @code | |
3749 | @item echo @var{text} | |
3750 | @kindex echo | |
4187119d | 3751 | @comment I don't consider backslash-space a standard C escape sequence |
3752 | @comment because it's not in ANSI. | |
3753 | Print @var{text}. Nonprinting characters can be included in @var{text} | |
3754 | using C escape sequences, such as @samp{\n} to print a newline. @b{No | |
3755 | newline will be printed unless you specify one.} In addition to the | |
3756 | standard C escape sequences a backslash followed by a space stands for a | |
3757 | space. This is useful for outputting a string with spaces at the | |
9c91ee3e RP |
3758 | beginning or the end, since leading and trailing spaces are otherwise |
3759 | trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the | |
3760 | command @samp{echo \@ and foo = \@ }. | |
3761 | @comment FIXME: verify hard copy actually issues enspaces for '@ '! Will this | |
3762 | @comment confuse texinfo? | |
4187119d | 3763 | |
3764 | A backslash at the end of @var{text} can be used, as in C, to continue | |
3765 | the command onto subsequent lines. For example, | |
e91b87a3 | 3766 | |
4187119d | 3767 | @example |
3768 | echo This is some text\n\ | |
3769 | which is continued\n\ | |
3770 | onto several lines.\n | |
3771 | @end example | |
3772 | ||
3773 | produces the same output as | |
e91b87a3 | 3774 | |
3775 | @example | |
4187119d | 3776 | echo This is some text\n |
3777 | echo which is continued\n | |
3778 | echo onto several lines.\n | |
e91b87a3 | 3779 | @end example |
3780 | ||
3781 | @item output @var{expression} | |
3782 | @kindex output | |
3783 | Print the value of @var{expression} and nothing but that value: no | |
3784 | newlines, no @samp{$@var{nn} = }. The value is not entered in the | |
4187119d | 3785 | value history either. @xref{Expressions} for more information on |
3786 | expressions. | |
e91b87a3 | 3787 | |
3788 | @item output/@var{fmt} @var{expression} | |
3789 | Print the value of @var{expression} in format @var{fmt}. | |
4187119d | 3790 | @xref{Output formats}, for more information. |
e91b87a3 | 3791 | |
3792 | @item printf @var{string}, @var{expressions}@dots{} | |
3793 | @kindex printf | |
3794 | Print the values of the @var{expressions} under the control of | |
3795 | @var{string}. The @var{expressions} are separated by commas and may | |
3796 | be either numbers or pointers. Their values are printed as specified | |
3797 | by @var{string}, exactly as if the program were to execute | |
3798 | ||
3799 | @example | |
3800 | printf (@var{string}, @var{expressions}@dots{}); | |
3801 | @end example | |
3802 | ||
3803 | For example, you can print two values in hex like this: | |
3804 | ||
3805 | @example | |
3806 | printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo | |
3807 | @end example | |
3808 | ||
9da601bf RP |
3809 | The only backslash-escape sequences that you can use in the format |
3810 | string are the simple ones that consist of backslash followed by a | |
3811 | letter. | |
e91b87a3 | 3812 | @end table |
3813 | ||
4187119d | 3814 | @node Options, Emacs, Sequences, Top |
3815 | @chapter Options and Arguments for GDB | |
3816 | ||
3817 | When you invoke GDB, you can specify arguments telling it what files to | |
3818 | operate on and what other things to do. | |
3819 | ||
3820 | @menu | |
3821 | * Mode Options:: Options controlling modes of operation. | |
3822 | * File Options:: Options to specify files (executable, coredump, commands) | |
3823 | * Other Arguments:: Any other arguments without options | |
3824 | also specify files. | |
3825 | @end menu | |
3826 | ||
3827 | @node Mode Options, File Options, Options, Options | |
3828 | @section Mode Options | |
3829 | ||
3830 | @table @samp | |
3831 | @item -nx | |
3832 | Do not execute commands from the init files @file{.gdbinit}. | |
3833 | Normally, the commands in these files are executed after all the | |
3834 | command options and arguments have been processed. @xref{Command | |
3835 | Files}. | |
3836 | ||
3837 | @item -q | |
3838 | ``Quiet''. Do not print the usual introductory messages. | |
3839 | ||
3840 | @item -batch | |
3841 | Run in batch mode. Exit with code 0 after processing all the command | |
3842 | files specified with @samp{-x} (and @file{.gdbinit}, if not inhibited). | |
3843 | Exit with nonzero status if an error occurs in executing the GDB | |
3844 | commands in the command files. | |
3845 | ||
3846 | @item -fullname | |
3847 | This option is used when Emacs runs GDB as a subprocess. It tells GDB | |
3848 | to output the full file name and line number in a standard, | |
3849 | recognizable fashion each time a stack frame is displayed (which | |
3850 | includes each time the program stops). This recognizable format looks | |
3851 | like two @samp{\032} characters, followed by the file name, line number | |
3852 | and character position separated by colons, and a newline. The | |
3853 | Emacs-to-GDB interface program uses the two @samp{\032} characters as | |
3854 | a signal to display the source code for the frame. | |
3855 | @end table | |
3856 | ||
3857 | @node File Options, Other Arguments, Mode Options, Options | |
3858 | @section File-specifying Options | |
3859 | ||
3860 | All the options and command line arguments given are processed | |
3861 | in sequential order. The order makes a difference when the | |
3862 | @samp{-x} option is used. | |
3863 | ||
3864 | @table @samp | |
3865 | @item -s @var{file} | |
3866 | Read symbol table from file @var{file}. | |
3867 | ||
3868 | @item -e @var{file} | |
3869 | Use file @var{file} as the executable file to execute when | |
3870 | appropriate, and for examining pure data in conjunction with a core | |
3871 | dump. | |
3872 | ||
3873 | @item -se @var{file} | |
3874 | Read symbol table from file @var{file} and use it as the executable | |
3875 | file. | |
3876 | ||
3877 | @item -c @var{file} | |
3878 | Use file @var{file} as a core dump to examine. | |
3879 | ||
3880 | @item -x @var{file} | |
3881 | Execute GDB commands from file @var{file}. | |
3882 | ||
3883 | @item -d @var{directory} | |
3884 | Add @var{directory} to the path to search for source files. | |
3885 | @end table | |
3886 | ||
3887 | @node Other Arguments,, File Options, Options | |
3888 | @section Other Arguments | |
3889 | ||
3890 | If there are arguments to GDB that are not options or associated with | |
3891 | options, the first one specifies the symbol table and executable file name | |
3892 | (as if it were preceded by @samp{-se}) and the second one specifies a core | |
3893 | dump file name (as if it were preceded by @samp{-c}). | |
3894 | ||
3895 | @node Emacs, Remote, Options, Top | |
e91b87a3 | 3896 | @chapter Using GDB under GNU Emacs |
3897 | ||
45007746 | 3898 | @cindex emacs |
e91b87a3 | 3899 | A special interface allows you to use GNU Emacs to view (and |
3900 | edit) the source files for the program you are debugging with | |
3901 | GDB. | |
3902 | ||
4187119d | 3903 | To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the |
3904 | executable file you want to debug as an argument. This command starts | |
3905 | GDB as a subprocess of Emacs, with input and output through a newly | |
3906 | created Emacs buffer. | |
e91b87a3 | 3907 | |
4187119d | 3908 | Using GDB under Emacs is just like using GDB normally except for two |
3909 | things: | |
e91b87a3 | 3910 | |
3911 | @itemize @bullet | |
3912 | @item | |
3913 | All ``terminal'' input and output goes through the Emacs buffer. This | |
3914 | applies both to GDB commands and their output, and to the input and | |
3915 | output done by the program you are debugging. | |
3916 | ||
3917 | This is useful because it means that you can copy the text of previous | |
3918 | commands and input them again; you can even use parts of the output | |
3919 | in this way. | |
3920 | ||
3921 | All the facilities of Emacs's Shell mode are available for this purpose. | |
3922 | ||
3923 | @item | |
3924 | GDB displays source code through Emacs. Each time GDB displays a | |
3925 | stack frame, Emacs automatically finds the source file for that frame | |
3926 | and puts an arrow (@samp{=>}) at the left margin of the current line. | |
9c91ee3e RP |
3927 | Emacs uses a separate buffer for source display, and splits the window |
3928 | to show both your GDB session and the source. | |
e91b87a3 | 3929 | |
3930 | Explicit GDB @samp{list} or search commands still produce output as | |
3931 | usual, but you probably will have no reason to use them. | |
3932 | @end itemize | |
3933 | ||
3934 | In the GDB I/O buffer, you can use these special Emacs commands: | |
3935 | ||
3936 | @table @kbd | |
3937 | @item M-s | |
3938 | Execute to another source line, like the GDB @samp{step} command. | |
3939 | ||
3940 | @item M-n | |
3941 | Execute to next source line in this function, skipping all function | |
3942 | calls, like the GDB @samp{next} command. | |
3943 | ||
3944 | @item M-i | |
3945 | Execute one instruction, like the GDB @samp{stepi} command. | |
3946 | ||
e91b87a3 | 3947 | @item C-c C-f |
3948 | Execute until exit from the selected stack frame, like the GDB | |
3949 | @samp{finish} command. | |
4187119d | 3950 | |
7a67dd45 | 3951 | @item M-c |
3952 | @comment C-c C-p in emacs 19 | |
4187119d | 3953 | Continue execution of the program, like the GDB @samp{cont} command. |
7a67dd45 | 3954 | |
3955 | @item M-u | |
3956 | @comment C-c C-u in emacs 19 | |
3957 | Go up the number of frames indicated by the numeric argument | |
3958 | (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}), | |
3959 | like the GDB @samp{up} command.@refill | |
3960 | ||
3961 | @item M-d | |
3962 | @comment C-c C-d in emacs 19 | |
3963 | Go down the number of frames indicated by the numeric argument, like the | |
3964 | GDB @samp{down} command. | |
e91b87a3 | 3965 | @end table |
3966 | ||
3967 | In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break}) | |
3968 | tells GDB to set a breakpoint on the source line point is on. | |
3969 | ||
3970 | The source files displayed in Emacs are in ordinary Emacs buffers | |
3971 | which are visiting the source files in the usual way. You can edit | |
3972 | the files with these buffers if you wish; but keep in mind that GDB | |
3973 | communicates with Emacs in terms of line numbers. If you add or | |
3974 | delete lines from the text, the line numbers that GDB knows will cease | |
3975 | to correspond properly to the code. | |
3976 | ||
4afc6002 RP |
3977 | @comment The following dropped because Epoch is nonstandard. Reactivate |
3978 | @comment if/when v19 does something similar. [email protected] 19dec1990 | |
3979 | @ignore | |
96a816c5 JG |
3980 | @kindex emacs epoch environment |
3981 | @kindex epoch | |
3982 | @kindex inspect | |
3983 | ||
3984 | Version 18 of Emacs has a built-in window system called the @samp{epoch} | |
3985 | environment. Users of this environment can use a new command, | |
3986 | @samp{inspect} which performs identically to @samp{print} except that | |
3987 | each value is printed in its own window. | |
4afc6002 | 3988 | @end ignore |
96a816c5 | 3989 | |
e91b87a3 | 3990 | @node Remote, Commands, Emacs, Top |
9da601bf | 3991 | @chapter Remote Debugging |
e91b87a3 | 3992 | |
1c997a4a | 3993 | If you are trying to debug a program running on a machine that can't run |
3994 | GDB in the usual way, it is often useful to use remote debugging. For | |
3995 | example, you might be debugging an operating system kernel, or debugging | |
3996 | a small system which does not have a general purpose operating system | |
3997 | powerful enough to run a full-featured debugger. Currently GDB supports | |
3998 | remote debugging over a serial connection. | |
e91b87a3 | 3999 | |
4000 | The program to be debugged on the remote machine needs to contain a | |
9da601bf RP |
4001 | debugging device driver which talks to GDB over the serial line. The |
4002 | same version of GDB that is used ordinarily can be used for this. | |
4003 | Several sample remote debugging drivers are distributed with GDB; see | |
4004 | the @file{README} file in the GDB distribution for more information. | |
e91b87a3 | 4005 | |
4006 | @menu | |
4007 | * Remote Commands:: Commands used to start and finish remote debugging. | |
4008 | @end menu | |
4009 | ||
4010 | For details of the communication protocol, see the comments in the GDB | |
4011 | source file @file{remote.c}. | |
4012 | ||
9c91ee3e | 4013 | @node Remote Commands, GDB Bugs, Remote, Remote |
e91b87a3 | 4014 | @section Commands for Remote Debugging |
4015 | ||
4016 | To start remote debugging, first run GDB and specify as an executable file | |
4017 | the program that is running in the remote machine. This tells GDB how | |
4018 | to find the program's symbols and the contents of its pure text. Then | |
9da601bf RP |
4019 | establish communication using the @samp{target remote} command with a device |
4020 | name as an argument. For example: | |
e91b87a3 | 4021 | |
4022 | @example | |
9da601bf | 4023 | target remote /dev/ttyd |
e91b87a3 | 4024 | @end example |
4025 | ||
4026 | @noindent | |
4027 | if the serial line is connected to the device named @file{/dev/ttyd}. This | |
4028 | will stop the remote machine if it is not already stopped. | |
4029 | ||
4030 | Now you can use all the usual commands to examine and change data and to | |
4031 | step and continue the remote program. | |
4032 | ||
4033 | To resume the remote program and stop debugging it, use the @samp{detach} | |
4034 | command. | |
4035 | ||
9da601bf RP |
4036 | @table @code |
4037 | @item reset | |
4038 | @kindex reset | |
4039 | For a target attached through a serial line, this command sends a | |
4040 | ``break'' to the remote target system; this is only useful if the target | |
4041 | has been equipped with a circuit to perform a hard reset (or some other | |
4042 | interesting action) when a break is detected. | |
4043 | @end table | |
4044 | ||
9c91ee3e RP |
4045 | @node GDB Bugs, , Remote Commands, Top |
4046 | @comment node-name, next, previous, up | |
4047 | @chapter Reporting Bugs in GDB | |
4048 | @cindex Bugs in GDB | |
4049 | @cindex Reporting Bugs in GDB | |
4050 | ||
4051 | Your bug reports play an essential role in making GDB reliable. | |
4052 | ||
4053 | Reporting a bug may help you by bringing a solution to your problem, or it | |
4054 | may not. But in any case the important function of a bug report is to help | |
4055 | the entire community by making the next version of GDB work better. Bug | |
4056 | reports are your contribution to the maintenance of GDB. | |
4057 | ||
4058 | In order for a bug report to serve its purpose, you must include the | |
4059 | information that makes for fixing the bug. | |
4060 | ||
4061 | @menu | |
4062 | * Criteria: Bug Criteria. Have you really found a bug? | |
4063 | * Reporting: Bug Reporting. How to report a bug effectively. | |
4064 | * Known: Trouble. Known problems. | |
4065 | * Help: Service. Where to ask for help. | |
4066 | @end menu | |
4067 | ||
4068 | @node Bug Criteria, Bug Reporting, Bugs, Bugs | |
4069 | @section Have You Found a Bug? | |
4070 | @cindex Bug Criteria | |
4071 | ||
4072 | If you are not sure whether you have found a bug, here are some guidelines: | |
4073 | ||
4074 | @itemize @bullet | |
4075 | @item | |
4076 | @cindex Fatal Signal | |
4077 | @cindex Core Dump | |
4078 | If the debugger gets a fatal signal, for any input whatever, that is a | |
4079 | GDB bug. Reliable debuggers never crash. | |
4080 | ||
4081 | @item | |
4082 | @cindex error on Valid Input | |
4083 | If GDB produces an error message for valid input, that is a bug. | |
4084 | ||
4085 | @item | |
4086 | @cindex Invalid Input | |
4087 | If GDB does not produce an error message for invalid input, | |
4088 | that is a bug. However, you should note that your idea of | |
4089 | ``invalid input'' might be my idea of ``an extension'' or ``support | |
4090 | for traditional practice''. | |
4091 | ||
4092 | @item | |
4093 | If you are an experienced user of debugging tools, your suggestions | |
4094 | for improvement of GDB are welcome in any case. | |
4095 | @end itemize | |
4096 | ||
4097 | @node Bug Reporting,, Bug Criteria, Bugs | |
4098 | @section How to Report Bugs | |
4099 | @cindex Bug Reports | |
4100 | @cindex Compiler Bugs, Reporting | |
4101 | ||
4102 | Send bug reports for GDB to one of these addresses: | |
4103 | ||
4104 | @example | |
4105 | bug-gdb@@prep.ai.mit.edu | |
4106 | @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb | |
4107 | @end example | |
4108 | ||
4109 | @strong{Do not send bug reports to @samp{info-gdb}, or to any | |
4110 | newsgroups.} Most users of GDB do not want to receive bug reports. | |
4111 | Those that do, have asked to be on @samp{bug-gcc}. | |
4112 | ||
4113 | The mailing list @samp{bug-gcc} has a newsgroup which serves as a | |
4114 | repeater. The mailing list and the newsgroup carry exactly the same | |
4115 | messages. Often people think of posting bug reports to the newsgroup | |
4116 | instead of mailing them. This appears to work, but it has one problem | |
4117 | which can be crucial: a newsgroup posting does not contain a mail path | |
4118 | back to the sender. Thus, if I need to ask for more information, I | |
4119 | may be unable to reach you. For this reason, it is better to send bug | |
4120 | reports to the mailing list. | |
4121 | ||
4122 | As a last resort, send bug reports on paper to: | |
4123 | ||
4124 | @example | |
4125 | GNU Debugger Bugs | |
4126 | 545 Tech Sq | |
4127 | Cambridge, MA 02139 | |
4128 | @end example | |
4129 | ||
4130 | The fundamental principle of reporting bugs usefully is this: | |
4131 | @strong{report all the facts}. If you are not sure whether to state a | |
4132 | fact or leave it out, state it! | |
4133 | ||
4134 | Often people omit facts because they think they know what causes the | |
4135 | problem and they conclude that some details don't matter. Thus, you might | |
4136 | assume that the name of the variable you use in an example does not matter. | |
4137 | Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a | |
4138 | stray memory reference which happens to fetch from the location where that | |
4139 | name is stored in memory; perhaps, if the name were different, the contents | |
4140 | of that location would fool the debugger into doing the right thing despite | |
4141 | the bug. Play it safe and give a specific, complete example. That is the | |
4142 | easiest thing for you to do, and the most helpful. | |
4143 | ||
4144 | Keep in mind that the purpose of a bug report is to enable me to fix | |
4145 | the bug if it is not known. It isn't very important what happens if | |
4146 | the bug is already known. Therefore, always write your bug reports on | |
4147 | the assumption that the bug is not known. | |
4148 | ||
4149 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
4150 | bell?'' Those bug reports are useless, and I urge everyone to | |
4151 | @emph{refuse to respond to them} except to chide the sender to report | |
4152 | bugs properly. | |
4153 | ||
4154 | To enable me to fix the bug, you should include all these things: | |
4155 | ||
4156 | @itemize @bullet | |
4157 | @item | |
4158 | The version of GDB. GDB announces it on startup. | |
4159 | ||
4160 | Without this, I won't know whether there is any point in looking for | |
4161 | the bug in the current version of GDB. | |
4162 | ||
4163 | @item | |
4164 | ||
4165 | A complete input file, and all necessary source files, that will | |
4166 | reproduce the bug. Run your source files through the C | |
4167 | preprocessor by doing @samp{gcc -E @var{sourcefile} > @var{outfile}}, | |
4168 | then include the contents of @var{outfile} in the bug report. (Any | |
4169 | @samp{-I}, @samp{-D} or @samp{-U} options that you used in actual | |
4170 | compilation should also be used when doing this.) | |
4171 | ||
4172 | A single statement is not enough of an example. In order to compile | |
4173 | it, it must be embedded in a function definition; and the bug might | |
4174 | depend on the details of how this is done. | |
4175 | ||
4176 | Without a real example I can compile, all I can do about your bug | |
4177 | report is wish you luck. It would be futile to try to guess how to | |
4178 | provoke the bug. | |
4179 | ||
4180 | @item | |
4181 | The command arguments you gave GCC or G++ to compile that example and | |
4182 | observe the bug. For example, did you use @samp{-O}? To guarantee | |
4183 | you won't omit something important, list them all. | |
4184 | ||
4185 | If I were to try to guess the arguments, I would probably guess wrong | |
4186 | and then I would not encounter the bug. | |
4187 | ||
4188 | @item | |
4189 | The type of machine you are using, and the operating system name and | |
4190 | version number. | |
4191 | ||
4192 | @item | |
4193 | A description of what behavior you observe that you believe is | |
4194 | incorrect. For example, ``It gets a fatal signal,'' or, ``There is an | |
4195 | incorrect assembler instruction in the output.'' | |
4196 | ||
4197 | Of course, if the bug is that GDB gets a fatal signal, then I | |
4198 | will certainly notice it. But if the bug is incorrect output, I might | |
4199 | not notice unless it is glaringly wrong. | |
4200 | ||
4201 | Even if the problem you experience is a fatal signal, you should still | |
4202 | say so explicitly. Suppose something strange is going on, such as, | |
4203 | your copy of GDB is out of synch, or you have encountered a | |
4204 | bug in the C library on your system. (This has happened!) Your copy | |
4205 | might crash and mine would not. If you @i{told} me to expect a crash, | |
4206 | then when mine fails to crash, I would know that the bug was not | |
4207 | happening for me. If you had not told me to expect a crash, then I | |
4208 | would not be able to draw any conclusion from my observations. | |
4209 | ||
4210 | @item | |
4211 | If you wish to suggest changes to the GDB source, send me context | |
4212 | diffs. If you even discuss something in the GDB source, refer to | |
4213 | it by context, not by line number. | |
4214 | ||
4215 | The line numbers in my development sources don't match those in your | |
4216 | sources. Your line numbers would convey no useful information to me. | |
4217 | ||
4218 | @end itemize | |
4219 | ||
4220 | Here are some things that are not necessary: | |
4221 | ||
4222 | @itemize @bullet | |
4223 | @item | |
4224 | A description of the envelope of the bug. | |
4225 | ||
4226 | Often people who encounter a bug spend a lot of time investigating | |
4227 | which changes to the input file will make the bug go away and which | |
4228 | changes will not affect it. | |
4229 | ||
4230 | This is often time consuming and not very useful, because the way I | |
4231 | will find the bug is by running a single example under the debugger | |
4232 | with breakpoints, not by pure deduction from a series of examples. | |
4233 | I recommend that you save your time for something else. | |
4234 | ||
4235 | Of course, if you can find a simpler example to report @emph{instead} | |
4236 | of the original one, that is a convenience for me. Errors in the | |
4237 | output will be easier to spot, running under the debugger will take | |
4238 | less time, etc. | |
4239 | ||
4240 | However, simplification is not vital; if you don't want to do this, | |
4241 | report the bug anyway and send me the entire test case you used. | |
4242 | ||
4243 | @item | |
4244 | A patch for the bug. | |
4245 | ||
4246 | A patch for the bug does help me if it is a good one. But don't omit | |
4247 | the necessary information, such as the test case, on the assumption that | |
4248 | a patch is all I need. I might see problems with your patch and decide | |
4249 | to fix the problem another way, or I might not understand it at all. | |
4250 | ||
4251 | Sometimes with a program as complicated as GDB it is very hard to | |
4252 | construct an example that will make the program follow a certain path | |
4253 | through the code. If you don't send me the example, I won't be able | |
4254 | to construct one, so I won't be able to verify that the bug is fixed. | |
4255 | ||
4256 | And if I can't understand what bug you are trying to fix, or why your | |
4257 | patch should be an improvement, I won't install it. A test case will | |
4258 | help me to understand. | |
4259 | ||
4260 | @item | |
4261 | A guess about what the bug is or what it depends on. | |
4262 | ||
4263 | Such guesses are usually wrong. Even I can't guess right about such | |
4264 | things without first using the debugger to find the facts. | |
4265 | @end itemize | |
4266 | ||
6ad6aa52 RP |
4267 | @include readline/inc-readline.texinfo |
4268 | @include readline/inc-history.texinfo | |
4187119d | 4269 | |
e91b87a3 | 4270 | @node Commands, Concepts, Remote, Top |
4271 | @unnumbered Command Index | |
4272 | ||
4273 | @printindex ky | |
4274 | ||
4187119d | 4275 | @node Concepts, , Commands, Top |
e91b87a3 | 4276 | @unnumbered Concept Index |
4277 | ||
4278 | @printindex cp | |
4279 | ||
4280 | @contents | |
4281 | @bye |