1 |
342 |
jeremybenn |
This is gdb.info, produced by makeinfo version 4.13 from ./gdb.texinfo.
|
2 |
330 |
jeremybenn |
|
3 |
|
|
INFO-DIR-SECTION Software development
|
4 |
|
|
START-INFO-DIR-ENTRY
|
5 |
|
|
* Gdb: (gdb). The GNU debugger.
|
6 |
|
|
END-INFO-DIR-ENTRY
|
7 |
|
|
|
8 |
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
|
9 |
|
|
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
10 |
|
|
2010 Free Software Foundation, Inc.
|
11 |
|
|
|
12 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
13 |
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
14 |
|
|
any later version published by the Free Software Foundation; with the
|
15 |
|
|
Invariant Sections being "Free Software" and "Free Software Needs Free
|
16 |
|
|
Documentation", with the Front-Cover Texts being "A GNU Manual," and
|
17 |
|
|
with the Back-Cover Texts as in (a) below.
|
18 |
|
|
|
19 |
|
|
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
|
20 |
|
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
21 |
|
|
developing GNU and promoting software freedom."
|
22 |
|
|
|
23 |
|
|
This file documents the GNU debugger GDB.
|
24 |
|
|
|
25 |
|
|
This is the Ninth Edition, of `Debugging with GDB: the GNU
|
26 |
342 |
jeremybenn |
Source-Level Debugger' for GDB (GDB) Version 7.2-or32-1.0rc1.
|
27 |
330 |
jeremybenn |
|
28 |
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
|
29 |
|
|
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
30 |
|
|
2010 Free Software Foundation, Inc.
|
31 |
|
|
|
32 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
33 |
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
34 |
|
|
any later version published by the Free Software Foundation; with the
|
35 |
|
|
Invariant Sections being "Free Software" and "Free Software Needs Free
|
36 |
|
|
Documentation", with the Front-Cover Texts being "A GNU Manual," and
|
37 |
|
|
with the Back-Cover Texts as in (a) below.
|
38 |
|
|
|
39 |
|
|
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
|
40 |
|
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
41 |
|
|
developing GNU and promoting software freedom."
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
File: gdb.info, Node: Top, Next: Summary, Prev: (dir), Up: (dir)
|
45 |
|
|
|
46 |
|
|
Debugging with GDB
|
47 |
|
|
******************
|
48 |
|
|
|
49 |
|
|
This file describes GDB, the GNU symbolic debugger.
|
50 |
|
|
|
51 |
342 |
jeremybenn |
This is the Ninth Edition, for GDB (GDB) Version 7.2-or32-1.0rc1.
|
52 |
330 |
jeremybenn |
|
53 |
|
|
Copyright (C) 1988-2010 Free Software Foundation, Inc.
|
54 |
|
|
|
55 |
|
|
This edition of the GDB manual is dedicated to the memory of Fred
|
56 |
|
|
Fish. Fred was a long-standing contributor to GDB and to Free software
|
57 |
|
|
in general. We will miss him.
|
58 |
|
|
|
59 |
|
|
* Menu:
|
60 |
|
|
|
61 |
|
|
* Summary:: Summary of GDB
|
62 |
|
|
* Sample Session:: A sample GDB session
|
63 |
|
|
|
64 |
|
|
* Invocation:: Getting in and out of GDB
|
65 |
|
|
* Commands:: GDB commands
|
66 |
|
|
* Running:: Running programs under GDB
|
67 |
|
|
* Stopping:: Stopping and continuing
|
68 |
|
|
* Reverse Execution:: Running programs backward
|
69 |
|
|
* Process Record and Replay:: Recording inferior's execution and replaying it
|
70 |
|
|
* Stack:: Examining the stack
|
71 |
|
|
* Source:: Examining source files
|
72 |
|
|
* Data:: Examining data
|
73 |
|
|
* Optimized Code:: Debugging optimized code
|
74 |
|
|
* Macros:: Preprocessor Macros
|
75 |
|
|
* Tracepoints:: Debugging remote targets non-intrusively
|
76 |
|
|
* Overlays:: Debugging programs that use overlays
|
77 |
|
|
|
78 |
|
|
* Languages:: Using GDB with different languages
|
79 |
|
|
|
80 |
|
|
* Symbols:: Examining the symbol table
|
81 |
|
|
* Altering:: Altering execution
|
82 |
|
|
* GDB Files:: GDB files
|
83 |
|
|
* Targets:: Specifying a debugging target
|
84 |
|
|
* Remote Debugging:: Debugging remote programs
|
85 |
|
|
* Configurations:: Configuration-specific information
|
86 |
|
|
* Controlling GDB:: Controlling GDB
|
87 |
|
|
* Extending GDB:: Extending GDB
|
88 |
|
|
* Interpreters:: Command Interpreters
|
89 |
|
|
* TUI:: GDB Text User Interface
|
90 |
|
|
* Emacs:: Using GDB under GNU Emacs
|
91 |
|
|
* GDB/MI:: GDB's Machine Interface.
|
92 |
|
|
* Annotations:: GDB's annotation interface.
|
93 |
|
|
* JIT Interface:: Using the JIT debugging interface.
|
94 |
|
|
|
95 |
|
|
* GDB Bugs:: Reporting bugs in GDB
|
96 |
|
|
|
97 |
|
|
* Command Line Editing:: Command Line Editing
|
98 |
|
|
* Using History Interactively:: Using History Interactively
|
99 |
|
|
* Formatting Documentation:: How to format and print GDB documentation
|
100 |
|
|
* Installing GDB:: Installing GDB
|
101 |
|
|
* Maintenance Commands:: Maintenance Commands
|
102 |
|
|
* Remote Protocol:: GDB Remote Serial Protocol
|
103 |
|
|
* Agent Expressions:: The GDB Agent Expression Mechanism
|
104 |
|
|
* Target Descriptions:: How targets can describe themselves to
|
105 |
|
|
GDB
|
106 |
|
|
* Operating System Information:: Getting additional information from
|
107 |
|
|
the operating system
|
108 |
|
|
* Trace File Format:: GDB trace file format
|
109 |
|
|
* Copying:: GNU General Public License says
|
110 |
|
|
how you can copy and share GDB
|
111 |
|
|
* GNU Free Documentation License:: The license for this documentation
|
112 |
|
|
* Index:: Index
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
File: gdb.info, Node: Summary, Next: Sample Session, Prev: Top, Up: Top
|
116 |
|
|
|
117 |
|
|
Summary of GDB
|
118 |
|
|
**************
|
119 |
|
|
|
120 |
|
|
The purpose of a debugger such as GDB is to allow you to see what is
|
121 |
|
|
going on "inside" another program while it executes--or what another
|
122 |
|
|
program was doing at the moment it crashed.
|
123 |
|
|
|
124 |
|
|
GDB can do four main kinds of things (plus other things in support of
|
125 |
|
|
these) to help you catch bugs in the act:
|
126 |
|
|
|
127 |
|
|
* Start your program, specifying anything that might affect its
|
128 |
|
|
behavior.
|
129 |
|
|
|
130 |
|
|
* Make your program stop on specified conditions.
|
131 |
|
|
|
132 |
|
|
* Examine what has happened, when your program has stopped.
|
133 |
|
|
|
134 |
|
|
* Change things in your program, so you can experiment with
|
135 |
|
|
correcting the effects of one bug and go on to learn about another.
|
136 |
|
|
|
137 |
|
|
You can use GDB to debug programs written in C and C++. For more
|
138 |
342 |
jeremybenn |
information, see *note Supported Languages: Supported Languages. For
|
139 |
|
|
more information, see *note C and C++: C.
|
140 |
330 |
jeremybenn |
|
141 |
342 |
jeremybenn |
Support for D is partial. For information on D, see *note D: D.
|
142 |
330 |
jeremybenn |
|
143 |
|
|
Support for Modula-2 is partial. For information on Modula-2, see
|
144 |
342 |
jeremybenn |
*note Modula-2: Modula-2.
|
145 |
330 |
jeremybenn |
|
146 |
|
|
Debugging Pascal programs which use sets, subranges, file variables,
|
147 |
|
|
or nested functions does not currently work. GDB does not support
|
148 |
|
|
entering expressions, printing values, or similar features using Pascal
|
149 |
|
|
syntax.
|
150 |
|
|
|
151 |
|
|
GDB can be used to debug programs written in Fortran, although it
|
152 |
|
|
may be necessary to refer to some variables with a trailing underscore.
|
153 |
|
|
|
154 |
|
|
GDB can be used to debug programs written in Objective-C, using
|
155 |
|
|
either the Apple/NeXT or the GNU Objective-C runtime.
|
156 |
|
|
|
157 |
|
|
* Menu:
|
158 |
|
|
|
159 |
|
|
* Free Software:: Freely redistributable software
|
160 |
|
|
* Contributors:: Contributors to GDB
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
File: gdb.info, Node: Free Software, Next: Contributors, Up: Summary
|
164 |
|
|
|
165 |
|
|
Free Software
|
166 |
|
|
=============
|
167 |
|
|
|
168 |
|
|
GDB is "free software", protected by the GNU General Public License
|
169 |
|
|
(GPL). The GPL gives you the freedom to copy or adapt a licensed
|
170 |
|
|
program--but every person getting a copy also gets with it the freedom
|
171 |
|
|
to modify that copy (which means that they must get access to the
|
172 |
|
|
source code), and the freedom to distribute further copies. Typical
|
173 |
|
|
software companies use copyrights to limit your freedoms; the Free
|
174 |
|
|
Software Foundation uses the GPL to preserve these freedoms.
|
175 |
|
|
|
176 |
|
|
Fundamentally, the General Public License is a license which says
|
177 |
|
|
that you have these freedoms and that you cannot take these freedoms
|
178 |
|
|
away from anyone else.
|
179 |
|
|
|
180 |
|
|
Free Software Needs Free Documentation
|
181 |
|
|
======================================
|
182 |
|
|
|
183 |
|
|
The biggest deficiency in the free software community today is not in
|
184 |
|
|
the software--it is the lack of good free documentation that we can
|
185 |
|
|
include with the free software. Many of our most important programs do
|
186 |
|
|
not come with free reference manuals and free introductory texts.
|
187 |
|
|
Documentation is an essential part of any software package; when an
|
188 |
|
|
important free software package does not come with a free manual and a
|
189 |
|
|
free tutorial, that is a major gap. We have many such gaps today.
|
190 |
|
|
|
191 |
|
|
Consider Perl, for instance. The tutorial manuals that people
|
192 |
|
|
normally use are non-free. How did this come about? Because the
|
193 |
|
|
authors of those manuals published them with restrictive terms--no
|
194 |
|
|
copying, no modification, source files not available--which exclude
|
195 |
|
|
them from the free software world.
|
196 |
|
|
|
197 |
|
|
That wasn't the first time this sort of thing happened, and it was
|
198 |
|
|
far from the last. Many times we have heard a GNU user eagerly
|
199 |
|
|
describe a manual that he is writing, his intended contribution to the
|
200 |
|
|
community, only to learn that he had ruined everything by signing a
|
201 |
|
|
publication contract to make it non-free.
|
202 |
|
|
|
203 |
|
|
Free documentation, like free software, is a matter of freedom, not
|
204 |
|
|
price. The problem with the non-free manual is not that publishers
|
205 |
|
|
charge a price for printed copies--that in itself is fine. (The Free
|
206 |
|
|
Software Foundation sells printed copies of manuals, too.) The problem
|
207 |
|
|
is the restrictions on the use of the manual. Free manuals are
|
208 |
|
|
available in source code form, and give you permission to copy and
|
209 |
|
|
modify. Non-free manuals do not allow this.
|
210 |
|
|
|
211 |
|
|
The criteria of freedom for a free manual are roughly the same as for
|
212 |
|
|
free software. Redistribution (including the normal kinds of
|
213 |
|
|
commercial redistribution) must be permitted, so that the manual can
|
214 |
|
|
accompany every copy of the program, both on-line and on paper.
|
215 |
|
|
|
216 |
|
|
Permission for modification of the technical content is crucial too.
|
217 |
|
|
When people modify the software, adding or changing features, if they
|
218 |
|
|
are conscientious they will change the manual too--so they can provide
|
219 |
|
|
accurate and clear documentation for the modified program. A manual
|
220 |
|
|
that leaves you no choice but to write a new manual to document a
|
221 |
|
|
changed version of the program is not really available to our community.
|
222 |
|
|
|
223 |
|
|
Some kinds of limits on the way modification is handled are
|
224 |
|
|
acceptable. For example, requirements to preserve the original
|
225 |
|
|
author's copyright notice, the distribution terms, or the list of
|
226 |
|
|
authors, are ok. It is also no problem to require modified versions to
|
227 |
|
|
include notice that they were modified. Even entire sections that may
|
228 |
|
|
not be deleted or changed are acceptable, as long as they deal with
|
229 |
|
|
nontechnical topics (like this one). These kinds of restrictions are
|
230 |
|
|
acceptable because they don't obstruct the community's normal use of
|
231 |
|
|
the manual.
|
232 |
|
|
|
233 |
|
|
However, it must be possible to modify all the _technical_ content
|
234 |
|
|
of the manual, and then distribute the result in all the usual media,
|
235 |
|
|
through all the usual channels. Otherwise, the restrictions obstruct
|
236 |
|
|
the use of the manual, it is not free, and we need another manual to
|
237 |
|
|
replace it.
|
238 |
|
|
|
239 |
|
|
Please spread the word about this issue. Our community continues to
|
240 |
|
|
lose manuals to proprietary publishing. If we spread the word that
|
241 |
|
|
free software needs free reference manuals and free tutorials, perhaps
|
242 |
|
|
the next person who wants to contribute by writing documentation will
|
243 |
|
|
realize, before it is too late, that only free manuals contribute to
|
244 |
|
|
the free software community.
|
245 |
|
|
|
246 |
|
|
If you are writing documentation, please insist on publishing it
|
247 |
|
|
under the GNU Free Documentation License or another free documentation
|
248 |
|
|
license. Remember that this decision requires your approval--you don't
|
249 |
|
|
have to let the publisher decide. Some commercial publishers will use
|
250 |
|
|
a free license if you insist, but they will not propose the option; it
|
251 |
|
|
is up to you to raise the issue and say firmly that this is what you
|
252 |
|
|
want. If the publisher you are dealing with refuses, please try other
|
253 |
|
|
publishers. If you're not sure whether a proposed license is free,
|
254 |
|
|
write to .
|
255 |
|
|
|
256 |
|
|
You can encourage commercial publishers to sell more free, copylefted
|
257 |
|
|
manuals and tutorials by buying them, and particularly by buying copies
|
258 |
|
|
from the publishers that paid for their writing or for major
|
259 |
|
|
improvements. Meanwhile, try to avoid buying non-free documentation at
|
260 |
|
|
all. Check the distribution terms of a manual before you buy it, and
|
261 |
|
|
insist that whoever seeks your business must respect your freedom.
|
262 |
|
|
Check the history of the book, and try to reward the publishers that
|
263 |
|
|
have paid or pay the authors to work on it.
|
264 |
|
|
|
265 |
|
|
The Free Software Foundation maintains a list of free documentation
|
266 |
|
|
published by other publishers, at
|
267 |
|
|
`http://www.fsf.org/doc/other-free-books.html'.
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
File: gdb.info, Node: Contributors, Prev: Free Software, Up: Summary
|
271 |
|
|
|
272 |
|
|
Contributors to GDB
|
273 |
|
|
===================
|
274 |
|
|
|
275 |
|
|
Richard Stallman was the original author of GDB, and of many other GNU
|
276 |
|
|
programs. Many others have contributed to its development. This
|
277 |
|
|
section attempts to credit major contributors. One of the virtues of
|
278 |
|
|
free software is that everyone is free to contribute to it; with
|
279 |
|
|
regret, we cannot actually acknowledge everyone here. The file
|
280 |
|
|
`ChangeLog' in the GDB distribution approximates a blow-by-blow account.
|
281 |
|
|
|
282 |
|
|
Changes much prior to version 2.0 are lost in the mists of time.
|
283 |
|
|
|
284 |
|
|
_Plea:_ Additions to this section are particularly welcome. If you
|
285 |
|
|
or your friends (or enemies, to be evenhanded) have been unfairly
|
286 |
|
|
omitted from this list, we would like to add your names!
|
287 |
|
|
|
288 |
|
|
So that they may not regard their many labors as thankless, we
|
289 |
|
|
particularly thank those who shepherded GDB through major releases:
|
290 |
|
|
Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim
|
291 |
|
|
Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs
|
292 |
|
|
(release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10,
|
293 |
|
|
and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5,
|
294 |
|
|
and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim
|
295 |
|
|
Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2,
|
296 |
|
|
3.1, and 3.0).
|
297 |
|
|
|
298 |
|
|
Richard Stallman, assisted at various times by Peter TerMaat, Chris
|
299 |
|
|
Hanson, and Richard Mlynarik, handled releases through 2.8.
|
300 |
|
|
|
301 |
|
|
Michael Tiemann is the author of most of the GNU C++ support in GDB,
|
302 |
|
|
with significant additional contributions from Per Bothner and Daniel
|
303 |
|
|
Berlin. James Clark wrote the GNU C++ demangler. Early work on C++
|
304 |
|
|
was by Peter TerMaat (who also did much general update work leading to
|
305 |
|
|
release 3.0).
|
306 |
|
|
|
307 |
|
|
GDB uses the BFD subroutine library to examine multiple object-file
|
308 |
|
|
formats; BFD was a joint project of David V. Henkel-Wallace, Rich
|
309 |
|
|
Pixley, Steve Chamberlain, and John Gilmore.
|
310 |
|
|
|
311 |
|
|
David Johnson wrote the original COFF support; Pace Willison did the
|
312 |
|
|
original support for encapsulated COFF.
|
313 |
|
|
|
314 |
|
|
Brent Benson of Harris Computer Systems contributed DWARF 2 support.
|
315 |
|
|
|
316 |
|
|
Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
|
317 |
|
|
Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
|
318 |
|
|
support. Jean-Daniel Fekete contributed Sun 386i support. Chris
|
319 |
|
|
Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
|
320 |
|
|
Hasei contributed Sony/News OS 3 support. David Johnson contributed
|
321 |
|
|
Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
|
322 |
|
|
Jeff Law contributed HP PA and SOM support. Keith Packard contributed
|
323 |
|
|
NS32K support. Doug Rabson contributed Acorn Risc Machine support.
|
324 |
|
|
Bob Rusk contributed Harris Nighthawk CX-UX support. Chris Smith
|
325 |
|
|
contributed Convex support (and Fortran debugging). Jonathan Stone
|
326 |
|
|
contributed Pyramid support. Michael Tiemann contributed SPARC support.
|
327 |
|
|
Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
|
328 |
|
|
Pace Willison contributed Intel 386 support. Jay Vosburgh contributed
|
329 |
|
|
Symmetry support. Marko Mlinar contributed OpenRISC 1000 support.
|
330 |
|
|
|
331 |
|
|
Andreas Schwab contributed M68K GNU/Linux support.
|
332 |
|
|
|
333 |
|
|
Rich Schaefer and Peter Schauer helped with support of SunOS shared
|
334 |
|
|
libraries.
|
335 |
|
|
|
336 |
|
|
Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
|
337 |
|
|
several machine instruction sets.
|
338 |
|
|
|
339 |
|
|
Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
|
340 |
|
|
develop remote debugging. Intel Corporation, Wind River Systems, AMD,
|
341 |
|
|
and ARM contributed remote debugging modules for the i960, VxWorks,
|
342 |
|
|
A29K UDI, and RDI targets, respectively.
|
343 |
|
|
|
344 |
|
|
Brian Fox is the author of the readline libraries providing
|
345 |
|
|
command-line editing and command history.
|
346 |
|
|
|
347 |
|
|
Andrew Beers of SUNY Buffalo wrote the language-switching code, the
|
348 |
|
|
Modula-2 support, and contributed the Languages chapter of this manual.
|
349 |
|
|
|
350 |
|
|
Fred Fish wrote most of the support for Unix System Vr4. He also
|
351 |
|
|
enhanced the command-completion support to cover C++ overloaded symbols.
|
352 |
|
|
|
353 |
|
|
Hitachi America (now Renesas America), Ltd. sponsored the support for
|
354 |
|
|
H8/300, H8/500, and Super-H processors.
|
355 |
|
|
|
356 |
|
|
NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
|
357 |
|
|
processors.
|
358 |
|
|
|
359 |
|
|
Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
|
360 |
|
|
M32R/D processors.
|
361 |
|
|
|
362 |
|
|
Toshiba sponsored the support for the TX39 Mips processor.
|
363 |
|
|
|
364 |
|
|
Matsushita sponsored the support for the MN10200 and MN10300
|
365 |
|
|
processors.
|
366 |
|
|
|
367 |
|
|
Fujitsu sponsored the support for SPARClite and FR30 processors.
|
368 |
|
|
|
369 |
|
|
Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
|
370 |
|
|
watchpoints.
|
371 |
|
|
|
372 |
|
|
Michael Snyder added support for tracepoints.
|
373 |
|
|
|
374 |
|
|
Stu Grossman wrote gdbserver.
|
375 |
|
|
|
376 |
|
|
Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
|
377 |
|
|
innumerable bug fixes and cleanups throughout GDB.
|
378 |
|
|
|
379 |
|
|
The following people at the Hewlett-Packard Company contributed
|
380 |
|
|
support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
|
381 |
|
|
(narrow mode), HP's implementation of kernel threads, HP's aC++
|
382 |
|
|
compiler, and the Text User Interface (nee Terminal User Interface):
|
383 |
|
|
Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
|
384 |
|
|
Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
|
385 |
|
|
provided HP-specific information in this manual.
|
386 |
|
|
|
387 |
|
|
DJ Delorie ported GDB to MS-DOS, for the DJGPP project. Robert
|
388 |
|
|
Hoehne made significant contributions to the DJGPP port.
|
389 |
|
|
|
390 |
|
|
Cygnus Solutions has sponsored GDB maintenance and much of its
|
391 |
|
|
development since 1991. Cygnus engineers who have worked on GDB
|
392 |
|
|
fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
|
393 |
|
|
Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
|
394 |
|
|
Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
|
395 |
|
|
Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
|
396 |
|
|
Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
|
397 |
|
|
addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
|
398 |
|
|
JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
|
399 |
|
|
Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
|
400 |
|
|
Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
|
401 |
|
|
Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
|
402 |
|
|
Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
|
403 |
|
|
Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
|
404 |
|
|
Zuhn have made contributions both large and small.
|
405 |
|
|
|
406 |
|
|
Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
|
407 |
|
|
Cygnus Solutions, implemented the original GDB/MI interface.
|
408 |
|
|
|
409 |
|
|
Jim Blandy added support for preprocessor macros, while working for
|
410 |
|
|
Red Hat.
|
411 |
|
|
|
412 |
|
|
Andrew Cagney designed GDB's architecture vector. Many people
|
413 |
|
|
including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek,
|
414 |
|
|
Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei Sakamoto,
|
415 |
|
|
Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna
|
416 |
|
|
Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration
|
417 |
|
|
of old architectures to this new framework.
|
418 |
|
|
|
419 |
|
|
Andrew Cagney completely re-designed and re-implemented GDB's
|
420 |
|
|
unwinder framework, this consisting of a fresh new design featuring
|
421 |
|
|
frame IDs, independent frame sniffers, and the sentinel frame. Mark
|
422 |
|
|
Kettenis implemented the DWARF 2 unwinder, Jeff Johnston the libunwind
|
423 |
|
|
unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad
|
424 |
|
|
unwinders. The architecture-specific changes, each involving a
|
425 |
|
|
complete rewrite of the architecture's frame code, were carried out by
|
426 |
|
|
Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
|
427 |
|
|
Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
|
428 |
|
|
Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
|
429 |
|
|
Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
|
430 |
|
|
Weigand.
|
431 |
|
|
|
432 |
|
|
Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
|
433 |
|
|
Tensilica, Inc. contributed support for Xtensa processors. Others who
|
434 |
|
|
have worked on the Xtensa port of GDB in the past include Steve Tjiang,
|
435 |
|
|
John Newlin, and Scott Foehner.
|
436 |
|
|
|
437 |
|
|
Michael Eager and staff of Xilinx, Inc., contributed support for the
|
438 |
|
|
Xilinx MicroBlaze architecture.
|
439 |
|
|
|
440 |
342 |
jeremybenn |
The original port to the OpenRISC 1000 is believed to be due to
|
441 |
|
|
Alessandro Forin and Per Bothner. More recent ports have been the work
|
442 |
|
|
of Jeremy Bennett.
|
443 |
|
|
|
444 |
330 |
jeremybenn |
|
445 |
|
|
File: gdb.info, Node: Sample Session, Next: Invocation, Prev: Summary, Up: Top
|
446 |
|
|
|
447 |
|
|
1 A Sample GDB Session
|
448 |
|
|
**********************
|
449 |
|
|
|
450 |
|
|
You can use this manual at your leisure to read all about GDB.
|
451 |
|
|
However, a handful of commands are enough to get started using the
|
452 |
|
|
debugger. This chapter illustrates those commands.
|
453 |
|
|
|
454 |
|
|
One of the preliminary versions of GNU `m4' (a generic macro
|
455 |
|
|
processor) exhibits the following bug: sometimes, when we change its
|
456 |
|
|
quote strings from the default, the commands used to capture one macro
|
457 |
|
|
definition within another stop working. In the following short `m4'
|
458 |
|
|
session, we define a macro `foo' which expands to `0000'; we then use
|
459 |
|
|
the `m4' built-in `defn' to define `bar' as the same thing. However,
|
460 |
|
|
when we change the open quote string to `' and the close quote
|
461 |
|
|
string to `', the same procedure fails to define a new synonym
|
462 |
|
|
`baz':
|
463 |
|
|
|
464 |
|
|
$ cd gnu/m4
|
465 |
|
|
$ ./m4
|
466 |
|
|
define(foo,0000)
|
467 |
|
|
|
468 |
|
|
foo
|
469 |
|
|
0000
|
470 |
|
|
define(bar,defn(`foo'))
|
471 |
|
|
|
472 |
|
|
bar
|
473 |
|
|
0000
|
474 |
|
|
changequote(,)
|
475 |
|
|
|
476 |
|
|
define(baz,defn(foo))
|
477 |
|
|
baz
|
478 |
|
|
Ctrl-d
|
479 |
|
|
m4: End of input: 0: fatal error: EOF in string
|
480 |
|
|
|
481 |
|
|
Let us use GDB to try to see what is going on.
|
482 |
|
|
|
483 |
|
|
$ gdb m4
|
484 |
|
|
GDB is free software and you are welcome to distribute copies
|
485 |
|
|
of it under certain conditions; type "show copying" to see
|
486 |
|
|
the conditions.
|
487 |
|
|
There is absolutely no warranty for GDB; type "show warranty"
|
488 |
|
|
for details.
|
489 |
|
|
|
490 |
342 |
jeremybenn |
GDB 7.2-or32-1.0rc1, Copyright 1999 Free Software Foundation, Inc...
|
491 |
330 |
jeremybenn |
(gdb)
|
492 |
|
|
|
493 |
|
|
GDB reads only enough symbol data to know where to find the rest when
|
494 |
|
|
needed; as a result, the first prompt comes up very quickly. We now
|
495 |
|
|
tell GDB to use a narrower display width than usual, so that examples
|
496 |
|
|
fit in this manual.
|
497 |
|
|
|
498 |
|
|
(gdb) set width 70
|
499 |
|
|
|
500 |
|
|
We need to see how the `m4' built-in `changequote' works. Having
|
501 |
|
|
looked at the source, we know the relevant subroutine is
|
502 |
|
|
`m4_changequote', so we set a breakpoint there with the GDB `break'
|
503 |
|
|
command.
|
504 |
|
|
|
505 |
|
|
(gdb) break m4_changequote
|
506 |
|
|
Breakpoint 1 at 0x62f4: file builtin.c, line 879.
|
507 |
|
|
|
508 |
|
|
Using the `run' command, we start `m4' running under GDB control; as
|
509 |
|
|
long as control does not reach the `m4_changequote' subroutine, the
|
510 |
|
|
program runs as usual:
|
511 |
|
|
|
512 |
|
|
(gdb) run
|
513 |
|
|
Starting program: /work/Editorial/gdb/gnu/m4/m4
|
514 |
|
|
define(foo,0000)
|
515 |
|
|
|
516 |
|
|
foo
|
517 |
|
|
0000
|
518 |
|
|
|
519 |
|
|
To trigger the breakpoint, we call `changequote'. GDB suspends
|
520 |
|
|
execution of `m4', displaying information about the context where it
|
521 |
|
|
stops.
|
522 |
|
|
|
523 |
|
|
changequote(,)
|
524 |
|
|
|
525 |
|
|
Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
|
526 |
|
|
at builtin.c:879
|
527 |
|
|
879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
|
528 |
|
|
|
529 |
|
|
Now we use the command `n' (`next') to advance execution to the next
|
530 |
|
|
line of the current function.
|
531 |
|
|
|
532 |
|
|
(gdb) n
|
533 |
|
|
882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
|
534 |
|
|
: nil,
|
535 |
|
|
|
536 |
|
|
`set_quotes' looks like a promising subroutine. We can go into it by
|
537 |
|
|
using the command `s' (`step') instead of `next'. `step' goes to the
|
538 |
|
|
next line to be executed in _any_ subroutine, so it steps into
|
539 |
|
|
`set_quotes'.
|
540 |
|
|
|
541 |
|
|
(gdb) s
|
542 |
|
|
set_quotes (lq=0x34c78 "", rq=0x34c88 "")
|
543 |
|
|
at input.c:530
|
544 |
|
|
530 if (lquote != def_lquote)
|
545 |
|
|
|
546 |
|
|
The display that shows the subroutine where `m4' is now suspended (and
|
547 |
|
|
its arguments) is called a stack frame display. It shows a summary of
|
548 |
|
|
the stack. We can use the `backtrace' command (which can also be
|
549 |
|
|
spelled `bt'), to see where we are in the stack as a whole: the
|
550 |
|
|
`backtrace' command displays a stack frame for each active subroutine.
|
551 |
|
|
|
552 |
|
|
(gdb) bt
|
553 |
|
|
#0 set_quotes (lq=0x34c78 "", rq=0x34c88 "")
|
554 |
|
|
at input.c:530
|
555 |
|
|
#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
|
556 |
|
|
at builtin.c:882
|
557 |
|
|
#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
|
558 |
|
|
#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
|
559 |
|
|
at macro.c:71
|
560 |
|
|
#4 0x79dc in expand_input () at macro.c:40
|
561 |
|
|
#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
|
562 |
|
|
|
563 |
|
|
We step through a few more lines to see what happens. The first two
|
564 |
|
|
times, we can use `s'; the next two times we use `n' to avoid falling
|
565 |
|
|
into the `xstrdup' subroutine.
|
566 |
|
|
|
567 |
|
|
(gdb) s
|
568 |
|
|
0x3b5c 532 if (rquote != def_rquote)
|
569 |
|
|
(gdb) s
|
570 |
|
|
0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
|
571 |
|
|
def_lquote : xstrdup(lq);
|
572 |
|
|
(gdb) n
|
573 |
|
|
536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
|
574 |
|
|
: xstrdup(rq);
|
575 |
|
|
(gdb) n
|
576 |
|
|
538 len_lquote = strlen(rquote);
|
577 |
|
|
|
578 |
|
|
The last line displayed looks a little odd; we can examine the variables
|
579 |
|
|
`lquote' and `rquote' to see if they are in fact the new left and right
|
580 |
|
|
quotes we specified. We use the command `p' (`print') to see their
|
581 |
|
|
values.
|
582 |
|
|
|
583 |
|
|
(gdb) p lquote
|
584 |
|
|
$1 = 0x35d40 ""
|
585 |
|
|
(gdb) p rquote
|
586 |
|
|
$2 = 0x35d50 ""
|
587 |
|
|
|
588 |
|
|
`lquote' and `rquote' are indeed the new left and right quotes. To
|
589 |
|
|
look at some context, we can display ten lines of source surrounding
|
590 |
|
|
the current line with the `l' (`list') command.
|
591 |
|
|
|
592 |
|
|
(gdb) l
|
593 |
|
|
533 xfree(rquote);
|
594 |
|
|
534
|
595 |
|
|
535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
|
596 |
|
|
: xstrdup (lq);
|
597 |
|
|
536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
|
598 |
|
|
: xstrdup (rq);
|
599 |
|
|
537
|
600 |
|
|
538 len_lquote = strlen(rquote);
|
601 |
|
|
539 len_rquote = strlen(lquote);
|
602 |
|
|
540 }
|
603 |
|
|
541
|
604 |
|
|
542 void
|
605 |
|
|
|
606 |
|
|
Let us step past the two lines that set `len_lquote' and `len_rquote',
|
607 |
|
|
and then examine the values of those variables.
|
608 |
|
|
|
609 |
|
|
(gdb) n
|
610 |
|
|
539 len_rquote = strlen(lquote);
|
611 |
|
|
(gdb) n
|
612 |
|
|
540 }
|
613 |
|
|
(gdb) p len_lquote
|
614 |
|
|
$3 = 9
|
615 |
|
|
(gdb) p len_rquote
|
616 |
|
|
$4 = 7
|
617 |
|
|
|
618 |
|
|
That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
|
619 |
|
|
meant to be the lengths of `lquote' and `rquote' respectively. We can
|
620 |
|
|
set them to better values using the `p' command, since it can print the
|
621 |
|
|
value of any expression--and that expression can include subroutine
|
622 |
|
|
calls and assignments.
|
623 |
|
|
|
624 |
|
|
(gdb) p len_lquote=strlen(lquote)
|
625 |
|
|
$5 = 7
|
626 |
|
|
(gdb) p len_rquote=strlen(rquote)
|
627 |
|
|
$6 = 9
|
628 |
|
|
|
629 |
|
|
Is that enough to fix the problem of using the new quotes with the `m4'
|
630 |
|
|
built-in `defn'? We can allow `m4' to continue executing with the `c'
|
631 |
|
|
(`continue') command, and then try the example that caused trouble
|
632 |
|
|
initially:
|
633 |
|
|
|
634 |
|
|
(gdb) c
|
635 |
|
|
Continuing.
|
636 |
|
|
|
637 |
|
|
define(baz,defn(foo))
|
638 |
|
|
|
639 |
|
|
baz
|
640 |
|
|
0000
|
641 |
|
|
|
642 |
|
|
Success! The new quotes now work just as well as the default ones. The
|
643 |
|
|
problem seems to have been just the two typos defining the wrong
|
644 |
|
|
lengths. We allow `m4' exit by giving it an EOF as input:
|
645 |
|
|
|
646 |
|
|
Ctrl-d
|
647 |
|
|
Program exited normally.
|
648 |
|
|
|
649 |
|
|
The message `Program exited normally.' is from GDB; it indicates `m4'
|
650 |
|
|
has finished executing. We can end our GDB session with the GDB `quit'
|
651 |
|
|
command.
|
652 |
|
|
|
653 |
|
|
(gdb) quit
|
654 |
|
|
|
655 |
|
|
|
656 |
|
|
File: gdb.info, Node: Invocation, Next: Commands, Prev: Sample Session, Up: Top
|
657 |
|
|
|
658 |
|
|
2 Getting In and Out of GDB
|
659 |
|
|
***************************
|
660 |
|
|
|
661 |
|
|
This chapter discusses how to start GDB, and how to get out of it. The
|
662 |
|
|
essentials are:
|
663 |
|
|
* type `gdb' to start GDB.
|
664 |
|
|
|
665 |
|
|
* type `quit' or `Ctrl-d' to exit.
|
666 |
|
|
|
667 |
|
|
* Menu:
|
668 |
|
|
|
669 |
|
|
* Invoking GDB:: How to start GDB
|
670 |
|
|
* Quitting GDB:: How to quit GDB
|
671 |
|
|
* Shell Commands:: How to use shell commands inside GDB
|
672 |
|
|
* Logging Output:: How to log GDB's output to a file
|
673 |
|
|
|
674 |
|
|
|
675 |
|
|
File: gdb.info, Node: Invoking GDB, Next: Quitting GDB, Up: Invocation
|
676 |
|
|
|
677 |
|
|
2.1 Invoking GDB
|
678 |
|
|
================
|
679 |
|
|
|
680 |
|
|
Invoke GDB by running the program `gdb'. Once started, GDB reads
|
681 |
|
|
commands from the terminal until you tell it to exit.
|
682 |
|
|
|
683 |
|
|
You can also run `gdb' with a variety of arguments and options, to
|
684 |
|
|
specify more of your debugging environment at the outset.
|
685 |
|
|
|
686 |
|
|
The command-line options described here are designed to cover a
|
687 |
|
|
variety of situations; in some environments, some of these options may
|
688 |
|
|
effectively be unavailable.
|
689 |
|
|
|
690 |
|
|
The most usual way to start GDB is with one argument, specifying an
|
691 |
|
|
executable program:
|
692 |
|
|
|
693 |
|
|
gdb PROGRAM
|
694 |
|
|
|
695 |
|
|
You can also start with both an executable program and a core file
|
696 |
|
|
specified:
|
697 |
|
|
|
698 |
|
|
gdb PROGRAM CORE
|
699 |
|
|
|
700 |
|
|
You can, instead, specify a process ID as a second argument, if you
|
701 |
|
|
want to debug a running process:
|
702 |
|
|
|
703 |
|
|
gdb PROGRAM 1234
|
704 |
|
|
|
705 |
|
|
would attach GDB to process `1234' (unless you also have a file named
|
706 |
|
|
`1234'; GDB does check for a core file first).
|
707 |
|
|
|
708 |
|
|
Taking advantage of the second command-line argument requires a
|
709 |
|
|
fairly complete operating system; when you use GDB as a remote debugger
|
710 |
|
|
attached to a bare board, there may not be any notion of "process", and
|
711 |
|
|
there is often no way to get a core dump. GDB will warn you if it is
|
712 |
|
|
unable to attach or to read core dumps.
|
713 |
|
|
|
714 |
|
|
You can optionally have `gdb' pass any arguments after the
|
715 |
|
|
executable file to the inferior using `--args'. This option stops
|
716 |
|
|
option processing.
|
717 |
|
|
gdb --args gcc -O2 -c foo.c
|
718 |
|
|
This will cause `gdb' to debug `gcc', and to set `gcc''s
|
719 |
|
|
command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
|
720 |
|
|
|
721 |
|
|
You can run `gdb' without printing the front material, which
|
722 |
|
|
describes GDB's non-warranty, by specifying `-silent':
|
723 |
|
|
|
724 |
|
|
gdb -silent
|
725 |
|
|
|
726 |
|
|
You can further control how GDB starts up by using command-line
|
727 |
|
|
options. GDB itself can remind you of the options available.
|
728 |
|
|
|
729 |
|
|
Type
|
730 |
|
|
|
731 |
|
|
gdb -help
|
732 |
|
|
|
733 |
|
|
to display all available options and briefly describe their use (`gdb
|
734 |
|
|
-h' is a shorter equivalent).
|
735 |
|
|
|
736 |
|
|
All options and command line arguments you give are processed in
|
737 |
|
|
sequential order. The order makes a difference when the `-x' option is
|
738 |
|
|
used.
|
739 |
|
|
|
740 |
|
|
* Menu:
|
741 |
|
|
|
742 |
|
|
* File Options:: Choosing files
|
743 |
|
|
* Mode Options:: Choosing modes
|
744 |
|
|
* Startup:: What GDB does during startup
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
File: gdb.info, Node: File Options, Next: Mode Options, Up: Invoking GDB
|
748 |
|
|
|
749 |
|
|
2.1.1 Choosing Files
|
750 |
|
|
--------------------
|
751 |
|
|
|
752 |
|
|
When GDB starts, it reads any arguments other than options as
|
753 |
|
|
specifying an executable file and core file (or process ID). This is
|
754 |
|
|
the same as if the arguments were specified by the `-se' and `-c' (or
|
755 |
|
|
`-p') options respectively. (GDB reads the first argument that does
|
756 |
|
|
not have an associated option flag as equivalent to the `-se' option
|
757 |
|
|
followed by that argument; and the second argument that does not have
|
758 |
|
|
an associated option flag, if any, as equivalent to the `-c'/`-p'
|
759 |
|
|
option followed by that argument.) If the second argument begins with
|
760 |
|
|
a decimal digit, GDB will first attempt to attach to it as a process,
|
761 |
|
|
and if that fails, attempt to open it as a corefile. If you have a
|
762 |
|
|
corefile whose name begins with a digit, you can prevent GDB from
|
763 |
|
|
treating it as a pid by prefixing it with `./', e.g. `./12345'.
|
764 |
|
|
|
765 |
|
|
If GDB has not been configured to included core file support, such
|
766 |
|
|
as for most embedded targets, then it will complain about a second
|
767 |
|
|
argument and ignore it.
|
768 |
|
|
|
769 |
|
|
Many options have both long and short forms; both are shown in the
|
770 |
|
|
following list. GDB also recognizes the long forms if you truncate
|
771 |
|
|
them, so long as enough of the option is present to be unambiguous.
|
772 |
|
|
(If you prefer, you can flag option arguments with `--' rather than
|
773 |
|
|
`-', though we illustrate the more usual convention.)
|
774 |
|
|
|
775 |
|
|
`-symbols FILE'
|
776 |
|
|
`-s FILE'
|
777 |
|
|
Read symbol table from file FILE.
|
778 |
|
|
|
779 |
|
|
`-exec FILE'
|
780 |
|
|
`-e FILE'
|
781 |
|
|
Use file FILE as the executable file to execute when appropriate,
|
782 |
|
|
and for examining pure data in conjunction with a core dump.
|
783 |
|
|
|
784 |
|
|
`-se FILE'
|
785 |
|
|
Read symbol table from file FILE and use it as the executable file.
|
786 |
|
|
|
787 |
|
|
`-core FILE'
|
788 |
|
|
`-c FILE'
|
789 |
|
|
Use file FILE as a core dump to examine.
|
790 |
|
|
|
791 |
|
|
`-pid NUMBER'
|
792 |
|
|
`-p NUMBER'
|
793 |
|
|
Connect to process ID NUMBER, as with the `attach' command.
|
794 |
|
|
|
795 |
|
|
`-command FILE'
|
796 |
|
|
`-x FILE'
|
797 |
|
|
Execute commands from file FILE. The contents of this file is
|
798 |
|
|
evaluated exactly as the `source' command would. *Note Command
|
799 |
|
|
files: Command Files.
|
800 |
|
|
|
801 |
|
|
`-eval-command COMMAND'
|
802 |
|
|
`-ex COMMAND'
|
803 |
|
|
Execute a single GDB command.
|
804 |
|
|
|
805 |
|
|
This option may be used multiple times to call multiple commands.
|
806 |
|
|
It may also be interleaved with `-command' as required.
|
807 |
|
|
|
808 |
|
|
gdb -ex 'target sim' -ex 'load' \
|
809 |
|
|
-x setbreakpoints -ex 'run' a.out
|
810 |
|
|
|
811 |
|
|
`-directory DIRECTORY'
|
812 |
|
|
`-d DIRECTORY'
|
813 |
|
|
Add DIRECTORY to the path to search for source and script files.
|
814 |
|
|
|
815 |
|
|
`-r'
|
816 |
|
|
`-readnow'
|
817 |
|
|
Read each symbol file's entire symbol table immediately, rather
|
818 |
|
|
than the default, which is to read it incrementally as it is
|
819 |
|
|
needed. This makes startup slower, but makes future operations
|
820 |
|
|
faster.
|
821 |
|
|
|
822 |
|
|
|
823 |
|
|
|
824 |
|
|
File: gdb.info, Node: Mode Options, Next: Startup, Prev: File Options, Up: Invoking GDB
|
825 |
|
|
|
826 |
|
|
2.1.2 Choosing Modes
|
827 |
|
|
--------------------
|
828 |
|
|
|
829 |
|
|
You can run GDB in various alternative modes--for example, in batch
|
830 |
|
|
mode or quiet mode.
|
831 |
|
|
|
832 |
|
|
`-nx'
|
833 |
|
|
`-n'
|
834 |
|
|
Do not execute commands found in any initialization files.
|
835 |
|
|
Normally, GDB executes the commands in these files after all the
|
836 |
|
|
command options and arguments have been processed. *Note Command
|
837 |
|
|
Files: Command Files.
|
838 |
|
|
|
839 |
|
|
`-quiet'
|
840 |
|
|
`-silent'
|
841 |
|
|
`-q'
|
842 |
|
|
"Quiet". Do not print the introductory and copyright messages.
|
843 |
|
|
These messages are also suppressed in batch mode.
|
844 |
|
|
|
845 |
|
|
`-batch'
|
846 |
|
|
Run in batch mode. Exit with status `0' after processing all the
|
847 |
|
|
command files specified with `-x' (and all commands from
|
848 |
|
|
initialization files, if not inhibited with `-n'). Exit with
|
849 |
|
|
nonzero status if an error occurs in executing the GDB commands in
|
850 |
|
|
the command files. Batch mode also disables pagination, sets
|
851 |
|
|
unlimited terminal width and height *note Screen Size::, and acts
|
852 |
|
|
as if `set confirm off' were in effect (*note Messages/Warnings::).
|
853 |
|
|
|
854 |
|
|
Batch mode may be useful for running GDB as a filter, for example
|
855 |
|
|
to download and run a program on another computer; in order to
|
856 |
|
|
make this more useful, the message
|
857 |
|
|
|
858 |
|
|
Program exited normally.
|
859 |
|
|
|
860 |
|
|
(which is ordinarily issued whenever a program running under GDB
|
861 |
|
|
control terminates) is not issued when running in batch mode.
|
862 |
|
|
|
863 |
|
|
`-batch-silent'
|
864 |
|
|
Run in batch mode exactly like `-batch', but totally silently. All
|
865 |
|
|
GDB output to `stdout' is prevented (`stderr' is unaffected).
|
866 |
|
|
This is much quieter than `-silent' and would be useless for an
|
867 |
|
|
interactive session.
|
868 |
|
|
|
869 |
|
|
This is particularly useful when using targets that give `Loading
|
870 |
|
|
section' messages, for example.
|
871 |
|
|
|
872 |
|
|
Note that targets that give their output via GDB, as opposed to
|
873 |
|
|
writing directly to `stdout', will also be made silent.
|
874 |
|
|
|
875 |
|
|
`-return-child-result'
|
876 |
|
|
The return code from GDB will be the return code from the child
|
877 |
|
|
process (the process being debugged), with the following
|
878 |
|
|
exceptions:
|
879 |
|
|
|
880 |
|
|
* GDB exits abnormally. E.g., due to an incorrect argument or
|
881 |
|
|
an internal error. In this case the exit code is the same as
|
882 |
|
|
it would have been without `-return-child-result'.
|
883 |
|
|
|
884 |
|
|
* The user quits with an explicit value. E.g., `quit 1'.
|
885 |
|
|
|
886 |
|
|
* The child process never runs, or is not allowed to terminate,
|
887 |
|
|
in which case the exit code will be -1.
|
888 |
|
|
|
889 |
|
|
This option is useful in conjunction with `-batch' or
|
890 |
|
|
`-batch-silent', when GDB is being used as a remote program loader
|
891 |
|
|
or simulator interface.
|
892 |
|
|
|
893 |
|
|
`-nowindows'
|
894 |
|
|
`-nw'
|
895 |
|
|
"No windows". If GDB comes with a graphical user interface (GUI)
|
896 |
|
|
built in, then this option tells GDB to only use the command-line
|
897 |
|
|
interface. If no GUI is available, this option has no effect.
|
898 |
|
|
|
899 |
|
|
`-windows'
|
900 |
|
|
`-w'
|
901 |
|
|
If GDB includes a GUI, then this option requires it to be used if
|
902 |
|
|
possible.
|
903 |
|
|
|
904 |
|
|
`-cd DIRECTORY'
|
905 |
|
|
Run GDB using DIRECTORY as its working directory, instead of the
|
906 |
|
|
current directory.
|
907 |
|
|
|
908 |
|
|
`-fullname'
|
909 |
|
|
`-f'
|
910 |
|
|
GNU Emacs sets this option when it runs GDB as a subprocess. It
|
911 |
|
|
tells GDB to output the full file name and line number in a
|
912 |
|
|
standard, recognizable fashion each time a stack frame is
|
913 |
|
|
displayed (which includes each time your program stops). This
|
914 |
|
|
recognizable format looks like two `\032' characters, followed by
|
915 |
|
|
the file name, line number and character position separated by
|
916 |
|
|
colons, and a newline. The Emacs-to-GDB interface program uses
|
917 |
|
|
the two `\032' characters as a signal to display the source code
|
918 |
|
|
for the frame.
|
919 |
|
|
|
920 |
|
|
`-epoch'
|
921 |
|
|
The Epoch Emacs-GDB interface sets this option when it runs GDB as
|
922 |
|
|
a subprocess. It tells GDB to modify its print routines so as to
|
923 |
|
|
allow Epoch to display values of expressions in a separate window.
|
924 |
|
|
|
925 |
|
|
`-annotate LEVEL'
|
926 |
|
|
This option sets the "annotation level" inside GDB. Its effect is
|
927 |
|
|
identical to using `set annotate LEVEL' (*note Annotations::).
|
928 |
|
|
The annotation LEVEL controls how much information GDB prints
|
929 |
|
|
together with its prompt, values of expressions, source lines, and
|
930 |
|
|
other types of output. Level 0 is the normal, level 1 is for use
|
931 |
|
|
when GDB is run as a subprocess of GNU Emacs, level 3 is the
|
932 |
|
|
maximum annotation suitable for programs that control GDB, and
|
933 |
|
|
level 2 has been deprecated.
|
934 |
|
|
|
935 |
|
|
The annotation mechanism has largely been superseded by GDB/MI
|
936 |
|
|
(*note GDB/MI::).
|
937 |
|
|
|
938 |
|
|
`--args'
|
939 |
|
|
Change interpretation of command line so that arguments following
|
940 |
|
|
the executable file are passed as command line arguments to the
|
941 |
|
|
inferior. This option stops option processing.
|
942 |
|
|
|
943 |
|
|
`-baud BPS'
|
944 |
|
|
`-b BPS'
|
945 |
|
|
Set the line speed (baud rate or bits per second) of any serial
|
946 |
|
|
interface used by GDB for remote debugging.
|
947 |
|
|
|
948 |
|
|
`-l TIMEOUT'
|
949 |
|
|
Set the timeout (in seconds) of any communication used by GDB for
|
950 |
|
|
remote debugging.
|
951 |
|
|
|
952 |
|
|
`-tty DEVICE'
|
953 |
|
|
`-t DEVICE'
|
954 |
|
|
Run using DEVICE for your program's standard input and output.
|
955 |
|
|
|
956 |
|
|
`-tui'
|
957 |
|
|
Activate the "Text User Interface" when starting. The Text User
|
958 |
|
|
Interface manages several text windows on the terminal, showing
|
959 |
|
|
source, assembly, registers and GDB command outputs (*note GDB
|
960 |
|
|
Text User Interface: TUI.). Alternatively, the Text User
|
961 |
|
|
Interface can be enabled by invoking the program `gdbtui'. Do not
|
962 |
|
|
use this option if you run GDB from Emacs (*note Using GDB under
|
963 |
|
|
GNU Emacs: Emacs.).
|
964 |
|
|
|
965 |
|
|
`-interpreter INTERP'
|
966 |
|
|
Use the interpreter INTERP for interface with the controlling
|
967 |
|
|
program or device. This option is meant to be set by programs
|
968 |
|
|
which communicate with GDB using it as a back end. *Note Command
|
969 |
|
|
Interpreters: Interpreters.
|
970 |
|
|
|
971 |
|
|
`--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
|
972 |
|
|
"GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
|
973 |
|
|
since GDB version 6.0. The previous GDB/MI interface, included in
|
974 |
|
|
GDB version 5.3 and selected with `--interpreter=mi1', is
|
975 |
|
|
deprecated. Earlier GDB/MI interfaces are no longer supported.
|
976 |
|
|
|
977 |
|
|
`-write'
|
978 |
|
|
Open the executable and core files for both reading and writing.
|
979 |
|
|
This is equivalent to the `set write on' command inside GDB (*note
|
980 |
|
|
Patching::).
|
981 |
|
|
|
982 |
|
|
`-statistics'
|
983 |
|
|
This option causes GDB to print statistics about time and memory
|
984 |
|
|
usage after it completes each command and returns to the prompt.
|
985 |
|
|
|
986 |
|
|
`-version'
|
987 |
|
|
This option causes GDB to print its version number and no-warranty
|
988 |
|
|
blurb, and exit.
|
989 |
|
|
|
990 |
|
|
|
991 |
|
|
|
992 |
|
|
File: gdb.info, Node: Startup, Prev: Mode Options, Up: Invoking GDB
|
993 |
|
|
|
994 |
|
|
2.1.3 What GDB Does During Startup
|
995 |
|
|
----------------------------------
|
996 |
|
|
|
997 |
|
|
Here's the description of what GDB does during session startup:
|
998 |
|
|
|
999 |
|
|
1. Sets up the command interpreter as specified by the command line
|
1000 |
|
|
(*note interpreter: Mode Options.).
|
1001 |
|
|
|
1002 |
|
|
2. Reads the system-wide "init file" (if `--with-system-gdbinit' was
|
1003 |
|
|
used when building GDB; *note System-wide configuration and
|
1004 |
|
|
settings: System-wide configuration.) and executes all the
|
1005 |
|
|
commands in that file.
|
1006 |
|
|
|
1007 |
|
|
3. Reads the init file (if any) in your home directory(1) and
|
1008 |
|
|
executes all the commands in that file.
|
1009 |
|
|
|
1010 |
|
|
4. Processes command line options and operands.
|
1011 |
|
|
|
1012 |
|
|
5. Reads and executes the commands from init file (if any) in the
|
1013 |
|
|
current working directory. This is only done if the current
|
1014 |
|
|
directory is different from your home directory. Thus, you can
|
1015 |
|
|
have more than one init file, one generic in your home directory,
|
1016 |
|
|
and another, specific to the program you are debugging, in the
|
1017 |
|
|
directory where you invoke GDB.
|
1018 |
|
|
|
1019 |
|
|
6. Reads command files specified by the `-x' option. *Note Command
|
1020 |
|
|
Files::, for more details about GDB command files.
|
1021 |
|
|
|
1022 |
|
|
7. Reads the command history recorded in the "history file". *Note
|
1023 |
|
|
Command History::, for more details about the command history and
|
1024 |
|
|
the files where GDB records it.
|
1025 |
|
|
|
1026 |
|
|
Init files use the same syntax as "command files" (*note Command
|
1027 |
|
|
Files::) and are processed by GDB in the same way. The init file in
|
1028 |
|
|
your home directory can set options (such as `set complaints') that
|
1029 |
|
|
affect subsequent processing of command line options and operands.
|
1030 |
|
|
Init files are not executed if you use the `-nx' option (*note Choosing
|
1031 |
|
|
Modes: Mode Options.).
|
1032 |
|
|
|
1033 |
|
|
To display the list of init files loaded by gdb at startup, you can
|
1034 |
|
|
use `gdb --help'.
|
1035 |
|
|
|
1036 |
|
|
The GDB init files are normally called `.gdbinit'. The DJGPP port
|
1037 |
|
|
of GDB uses the name `gdb.ini', due to the limitations of file names
|
1038 |
|
|
imposed by DOS filesystems. The Windows ports of GDB use the standard
|
1039 |
|
|
name, but if they find a `gdb.ini' file, they warn you about that and
|
1040 |
|
|
suggest to rename the file to the standard name.
|
1041 |
|
|
|
1042 |
|
|
---------- Footnotes ----------
|
1043 |
|
|
|
1044 |
|
|
(1) On DOS/Windows systems, the home directory is the one pointed to
|
1045 |
|
|
by the `HOME' environment variable.
|
1046 |
|
|
|
1047 |
|
|
|
1048 |
|
|
File: gdb.info, Node: Quitting GDB, Next: Shell Commands, Prev: Invoking GDB, Up: Invocation
|
1049 |
|
|
|
1050 |
|
|
2.2 Quitting GDB
|
1051 |
|
|
================
|
1052 |
|
|
|
1053 |
|
|
`quit [EXPRESSION]'
|
1054 |
|
|
`q'
|
1055 |
|
|
To exit GDB, use the `quit' command (abbreviated `q'), or type an
|
1056 |
|
|
end-of-file character (usually `Ctrl-d'). If you do not supply
|
1057 |
|
|
EXPRESSION, GDB will terminate normally; otherwise it will
|
1058 |
|
|
terminate using the result of EXPRESSION as the error code.
|
1059 |
|
|
|
1060 |
|
|
An interrupt (often `Ctrl-c') does not exit from GDB, but rather
|
1061 |
|
|
terminates the action of any GDB command that is in progress and
|
1062 |
|
|
returns to GDB command level. It is safe to type the interrupt
|
1063 |
|
|
character at any time because GDB does not allow it to take effect
|
1064 |
|
|
until a time when it is safe.
|
1065 |
|
|
|
1066 |
|
|
If you have been using GDB to control an attached process or device,
|
1067 |
|
|
you can release it with the `detach' command (*note Debugging an
|
1068 |
|
|
Already-running Process: Attach.).
|
1069 |
|
|
|
1070 |
|
|
|
1071 |
|
|
File: gdb.info, Node: Shell Commands, Next: Logging Output, Prev: Quitting GDB, Up: Invocation
|
1072 |
|
|
|
1073 |
|
|
2.3 Shell Commands
|
1074 |
|
|
==================
|
1075 |
|
|
|
1076 |
|
|
If you need to execute occasional shell commands during your debugging
|
1077 |
|
|
session, there is no need to leave or suspend GDB; you can just use the
|
1078 |
|
|
`shell' command.
|
1079 |
|
|
|
1080 |
|
|
`shell COMMAND STRING'
|
1081 |
|
|
Invoke a standard shell to execute COMMAND STRING. If it exists,
|
1082 |
|
|
the environment variable `SHELL' determines which shell to run.
|
1083 |
|
|
Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
|
1084 |
|
|
`COMMAND.COM' on MS-DOS, etc.).
|
1085 |
|
|
|
1086 |
|
|
The utility `make' is often needed in development environments. You
|
1087 |
|
|
do not have to use the `shell' command for this purpose in GDB:
|
1088 |
|
|
|
1089 |
|
|
`make MAKE-ARGS'
|
1090 |
|
|
Execute the `make' program with the specified arguments. This is
|
1091 |
|
|
equivalent to `shell make MAKE-ARGS'.
|
1092 |
|
|
|
1093 |
|
|
|
1094 |
|
|
File: gdb.info, Node: Logging Output, Prev: Shell Commands, Up: Invocation
|
1095 |
|
|
|
1096 |
|
|
2.4 Logging Output
|
1097 |
|
|
==================
|
1098 |
|
|
|
1099 |
|
|
You may want to save the output of GDB commands to a file. There are
|
1100 |
|
|
several commands to control GDB's logging.
|
1101 |
|
|
|
1102 |
|
|
`set logging on'
|
1103 |
|
|
Enable logging.
|
1104 |
|
|
|
1105 |
|
|
`set logging off'
|
1106 |
|
|
Disable logging.
|
1107 |
|
|
|
1108 |
|
|
`set logging file FILE'
|
1109 |
|
|
Change the name of the current logfile. The default logfile is
|
1110 |
|
|
`gdb.txt'.
|
1111 |
|
|
|
1112 |
|
|
`set logging overwrite [on|off]'
|
1113 |
|
|
By default, GDB will append to the logfile. Set `overwrite' if
|
1114 |
|
|
you want `set logging on' to overwrite the logfile instead.
|
1115 |
|
|
|
1116 |
|
|
`set logging redirect [on|off]'
|
1117 |
|
|
By default, GDB output will go to both the terminal and the
|
1118 |
|
|
logfile. Set `redirect' if you want output to go only to the log
|
1119 |
|
|
file.
|
1120 |
|
|
|
1121 |
|
|
`show logging'
|
1122 |
|
|
Show the current values of the logging settings.
|
1123 |
|
|
|
1124 |
|
|
|
1125 |
|
|
File: gdb.info, Node: Commands, Next: Running, Prev: Invocation, Up: Top
|
1126 |
|
|
|
1127 |
|
|
3 GDB Commands
|
1128 |
|
|
**************
|
1129 |
|
|
|
1130 |
|
|
You can abbreviate a GDB command to the first few letters of the command
|
1131 |
|
|
name, if that abbreviation is unambiguous; and you can repeat certain
|
1132 |
|
|
GDB commands by typing just . You can also use the key to
|
1133 |
|
|
get GDB to fill out the rest of a word in a command (or to show you the
|
1134 |
|
|
alternatives available, if there is more than one possibility).
|
1135 |
|
|
|
1136 |
|
|
* Menu:
|
1137 |
|
|
|
1138 |
|
|
* Command Syntax:: How to give commands to GDB
|
1139 |
|
|
* Completion:: Command completion
|
1140 |
|
|
* Help:: How to ask GDB for help
|
1141 |
|
|
|
1142 |
|
|
|
1143 |
|
|
File: gdb.info, Node: Command Syntax, Next: Completion, Up: Commands
|
1144 |
|
|
|
1145 |
|
|
3.1 Command Syntax
|
1146 |
|
|
==================
|
1147 |
|
|
|
1148 |
|
|
A GDB command is a single line of input. There is no limit on how long
|
1149 |
|
|
it can be. It starts with a command name, which is followed by
|
1150 |
|
|
arguments whose meaning depends on the command name. For example, the
|
1151 |
|
|
command `step' accepts an argument which is the number of times to
|
1152 |
|
|
step, as in `step 5'. You can also use the `step' command with no
|
1153 |
|
|
arguments. Some commands do not allow any arguments.
|
1154 |
|
|
|
1155 |
|
|
GDB command names may always be truncated if that abbreviation is
|
1156 |
|
|
unambiguous. Other possible command abbreviations are listed in the
|
1157 |
|
|
documentation for individual commands. In some cases, even ambiguous
|
1158 |
|
|
abbreviations are allowed; for example, `s' is specially defined as
|
1159 |
|
|
equivalent to `step' even though there are other commands whose names
|
1160 |
|
|
start with `s'. You can test abbreviations by using them as arguments
|
1161 |
|
|
to the `help' command.
|
1162 |
|
|
|
1163 |
|
|
A blank line as input to GDB (typing just ) means to repeat the
|
1164 |
|
|
previous command. Certain commands (for example, `run') will not
|
1165 |
|
|
repeat this way; these are commands whose unintentional repetition
|
1166 |
|
|
might cause trouble and which you are unlikely to want to repeat.
|
1167 |
342 |
jeremybenn |
User-defined commands can disable this feature; see *note dont-repeat:
|
1168 |
330 |
jeremybenn |
Define.
|
1169 |
|
|
|
1170 |
|
|
The `list' and `x' commands, when you repeat them with ,
|
1171 |
|
|
construct new arguments rather than repeating exactly as typed. This
|
1172 |
|
|
permits easy scanning of source or memory.
|
1173 |
|
|
|
1174 |
|
|
GDB can also use in another way: to partition lengthy output,
|
1175 |
|
|
in a way similar to the common utility `more' (*note Screen Size:
|
1176 |
|
|
Screen Size.). Since it is easy to press one too many in this
|
1177 |
|
|
situation, GDB disables command repetition after any command that
|
1178 |
|
|
generates this sort of display.
|
1179 |
|
|
|
1180 |
|
|
Any text from a `#' to the end of the line is a comment; it does
|
1181 |
|
|
nothing. This is useful mainly in command files (*note Command Files:
|
1182 |
|
|
Command Files.).
|
1183 |
|
|
|
1184 |
|
|
The `Ctrl-o' binding is useful for repeating a complex sequence of
|
1185 |
|
|
commands. This command accepts the current line, like , and then
|
1186 |
|
|
fetches the next line relative to the current line from the history for
|
1187 |
|
|
editing.
|
1188 |
|
|
|
1189 |
|
|
|
1190 |
|
|
File: gdb.info, Node: Completion, Next: Help, Prev: Command Syntax, Up: Commands
|
1191 |
|
|
|
1192 |
|
|
3.2 Command Completion
|
1193 |
|
|
======================
|
1194 |
|
|
|
1195 |
|
|
GDB can fill in the rest of a word in a command for you, if there is
|
1196 |
|
|
only one possibility; it can also show you what the valid possibilities
|
1197 |
|
|
are for the next word in a command, at any time. This works for GDB
|
1198 |
|
|
commands, GDB subcommands, and the names of symbols in your program.
|
1199 |
|
|
|
1200 |
|
|
Press the key whenever you want GDB to fill out the rest of a
|
1201 |
|
|
word. If there is only one possibility, GDB fills in the word, and
|
1202 |
|
|
waits for you to finish the command (or press to enter it). For
|
1203 |
|
|
example, if you type
|
1204 |
|
|
|
1205 |
|
|
(gdb) info bre
|
1206 |
|
|
|
1207 |
|
|
GDB fills in the rest of the word `breakpoints', since that is the only
|
1208 |
|
|
`info' subcommand beginning with `bre':
|
1209 |
|
|
|
1210 |
|
|
(gdb) info breakpoints
|
1211 |
|
|
|
1212 |
|
|
You can either press at this point, to run the `info breakpoints'
|
1213 |
|
|
command, or backspace and enter something else, if `breakpoints' does
|
1214 |
|
|
not look like the command you expected. (If you were sure you wanted
|
1215 |
|
|
`info breakpoints' in the first place, you might as well just type
|
1216 |
|
|
immediately after `info bre', to exploit command abbreviations
|
1217 |
|
|
rather than command completion).
|
1218 |
|
|
|
1219 |
|
|
If there is more than one possibility for the next word when you
|
1220 |
|
|
press , GDB sounds a bell. You can either supply more characters
|
1221 |
|
|
and try again, or just press a second time; GDB displays all the
|
1222 |
|
|
possible completions for that word. For example, you might want to set
|
1223 |
|
|
a breakpoint on a subroutine whose name begins with `make_', but when
|
1224 |
|
|
you type `b make_' GDB just sounds the bell. Typing again
|
1225 |
|
|
displays all the function names in your program that begin with those
|
1226 |
|
|
characters, for example:
|
1227 |
|
|
|
1228 |
|
|
(gdb) b make_
|
1229 |
|
|
GDB sounds bell; press again, to see:
|
1230 |
|
|
make_a_section_from_file make_environ
|
1231 |
|
|
make_abs_section make_function_type
|
1232 |
|
|
make_blockvector make_pointer_type
|
1233 |
|
|
make_cleanup make_reference_type
|
1234 |
|
|
make_command make_symbol_completion_list
|
1235 |
|
|
(gdb) b make_
|
1236 |
|
|
|
1237 |
|
|
After displaying the available possibilities, GDB copies your partial
|
1238 |
|
|
input (`b make_' in the example) so you can finish the command.
|
1239 |
|
|
|
1240 |
|
|
If you just want to see the list of alternatives in the first place,
|
1241 |
|
|
you can press `M-?' rather than pressing twice. `M-?' means
|
1242 |
|
|
` ?'. You can type this either by holding down a key designated
|
1243 |
|
|
as the shift on your keyboard (if there is one) while typing
|
1244 |
|
|
`?', or as followed by `?'.
|
1245 |
|
|
|
1246 |
|
|
Sometimes the string you need, while logically a "word", may contain
|
1247 |
|
|
parentheses or other characters that GDB normally excludes from its
|
1248 |
|
|
notion of a word. To permit word completion to work in this situation,
|
1249 |
|
|
you may enclose words in `'' (single quote marks) in GDB commands.
|
1250 |
|
|
|
1251 |
|
|
The most likely situation where you might need this is in typing the
|
1252 |
|
|
name of a C++ function. This is because C++ allows function
|
1253 |
|
|
overloading (multiple definitions of the same function, distinguished
|
1254 |
|
|
by argument type). For example, when you want to set a breakpoint you
|
1255 |
|
|
may need to distinguish whether you mean the version of `name' that
|
1256 |
|
|
takes an `int' parameter, `name(int)', or the version that takes a
|
1257 |
|
|
`float' parameter, `name(float)'. To use the word-completion
|
1258 |
|
|
facilities in this situation, type a single quote `'' at the beginning
|
1259 |
|
|
of the function name. This alerts GDB that it may need to consider
|
1260 |
|
|
more information than usual when you press or `M-?' to request
|
1261 |
|
|
word completion:
|
1262 |
|
|
|
1263 |
|
|
(gdb) b 'bubble( M-?
|
1264 |
|
|
bubble(double,double) bubble(int,int)
|
1265 |
|
|
(gdb) b 'bubble(
|
1266 |
|
|
|
1267 |
|
|
In some cases, GDB can tell that completing a name requires using
|
1268 |
|
|
quotes. When this happens, GDB inserts the quote for you (while
|
1269 |
|
|
completing as much as it can) if you do not type the quote in the first
|
1270 |
|
|
place:
|
1271 |
|
|
|
1272 |
|
|
(gdb) b bub
|
1273 |
|
|
GDB alters your input line to the following, and rings a bell:
|
1274 |
|
|
(gdb) b 'bubble(
|
1275 |
|
|
|
1276 |
|
|
In general, GDB can tell that a quote is needed (and inserts it) if you
|
1277 |
|
|
have not yet started typing the argument list when you ask for
|
1278 |
|
|
completion on an overloaded symbol.
|
1279 |
|
|
|
1280 |
342 |
jeremybenn |
For more information about overloaded functions, see *note C++
|
1281 |
330 |
jeremybenn |
Expressions: C Plus Plus Expressions. You can use the command `set
|
1282 |
342 |
jeremybenn |
overload-resolution off' to disable overload resolution; see *note GDB
|
1283 |
330 |
jeremybenn |
Features for C++: Debugging C Plus Plus.
|
1284 |
|
|
|
1285 |
|
|
When completing in an expression which looks up a field in a
|
1286 |
|
|
structure, GDB also tries(1) to limit completions to the field names
|
1287 |
|
|
available in the type of the left-hand-side:
|
1288 |
|
|
|
1289 |
|
|
(gdb) p gdb_stdout.M-?
|
1290 |
|
|
magic to_delete to_fputs to_put to_rewind
|
1291 |
|
|
to_data to_flush to_isatty to_read to_write
|
1292 |
|
|
|
1293 |
|
|
This is because the `gdb_stdout' is a variable of the type `struct
|
1294 |
|
|
ui_file' that is defined in GDB sources as follows:
|
1295 |
|
|
|
1296 |
|
|
struct ui_file
|
1297 |
|
|
{
|
1298 |
|
|
int *magic;
|
1299 |
|
|
ui_file_flush_ftype *to_flush;
|
1300 |
|
|
ui_file_write_ftype *to_write;
|
1301 |
|
|
ui_file_fputs_ftype *to_fputs;
|
1302 |
|
|
ui_file_read_ftype *to_read;
|
1303 |
|
|
ui_file_delete_ftype *to_delete;
|
1304 |
|
|
ui_file_isatty_ftype *to_isatty;
|
1305 |
|
|
ui_file_rewind_ftype *to_rewind;
|
1306 |
|
|
ui_file_put_ftype *to_put;
|
1307 |
|
|
void *to_data;
|
1308 |
|
|
}
|
1309 |
|
|
|
1310 |
|
|
---------- Footnotes ----------
|
1311 |
|
|
|
1312 |
|
|
(1) The completer can be confused by certain kinds of invalid
|
1313 |
|
|
expressions. Also, it only examines the static type of the expression,
|
1314 |
|
|
not the dynamic type.
|
1315 |
|
|
|
1316 |
|
|
|
1317 |
|
|
File: gdb.info, Node: Help, Prev: Completion, Up: Commands
|
1318 |
|
|
|
1319 |
|
|
3.3 Getting Help
|
1320 |
|
|
================
|
1321 |
|
|
|
1322 |
|
|
You can always ask GDB itself for information on its commands, using
|
1323 |
|
|
the command `help'.
|
1324 |
|
|
|
1325 |
|
|
`help'
|
1326 |
|
|
`h'
|
1327 |
|
|
You can use `help' (abbreviated `h') with no arguments to display
|
1328 |
|
|
a short list of named classes of commands:
|
1329 |
|
|
|
1330 |
|
|
(gdb) help
|
1331 |
|
|
List of classes of commands:
|
1332 |
|
|
|
1333 |
|
|
aliases -- Aliases of other commands
|
1334 |
|
|
breakpoints -- Making program stop at certain points
|
1335 |
|
|
data -- Examining data
|
1336 |
|
|
files -- Specifying and examining files
|
1337 |
|
|
internals -- Maintenance commands
|
1338 |
|
|
obscure -- Obscure features
|
1339 |
|
|
running -- Running the program
|
1340 |
|
|
stack -- Examining the stack
|
1341 |
|
|
status -- Status inquiries
|
1342 |
|
|
support -- Support facilities
|
1343 |
|
|
tracepoints -- Tracing of program execution without
|
1344 |
|
|
stopping the program
|
1345 |
|
|
user-defined -- User-defined commands
|
1346 |
|
|
|
1347 |
|
|
Type "help" followed by a class name for a list of
|
1348 |
|
|
commands in that class.
|
1349 |
|
|
Type "help" followed by command name for full
|
1350 |
|
|
documentation.
|
1351 |
|
|
Command name abbreviations are allowed if unambiguous.
|
1352 |
|
|
(gdb)
|
1353 |
|
|
|
1354 |
|
|
`help CLASS'
|
1355 |
|
|
Using one of the general help classes as an argument, you can get a
|
1356 |
|
|
list of the individual commands in that class. For example, here
|
1357 |
|
|
is the help display for the class `status':
|
1358 |
|
|
|
1359 |
|
|
(gdb) help status
|
1360 |
|
|
Status inquiries.
|
1361 |
|
|
|
1362 |
|
|
List of commands:
|
1363 |
|
|
|
1364 |
|
|
info -- Generic command for showing things
|
1365 |
|
|
about the program being debugged
|
1366 |
|
|
show -- Generic command for showing things
|
1367 |
|
|
about the debugger
|
1368 |
|
|
|
1369 |
|
|
Type "help" followed by command name for full
|
1370 |
|
|
documentation.
|
1371 |
|
|
Command name abbreviations are allowed if unambiguous.
|
1372 |
|
|
(gdb)
|
1373 |
|
|
|
1374 |
|
|
`help COMMAND'
|
1375 |
|
|
With a command name as `help' argument, GDB displays a short
|
1376 |
|
|
paragraph on how to use that command.
|
1377 |
|
|
|
1378 |
|
|
`apropos ARGS'
|
1379 |
|
|
The `apropos' command searches through all of the GDB commands,
|
1380 |
|
|
and their documentation, for the regular expression specified in
|
1381 |
|
|
ARGS. It prints out all matches found. For example:
|
1382 |
|
|
|
1383 |
|
|
apropos reload
|
1384 |
|
|
|
1385 |
|
|
results in:
|
1386 |
|
|
|
1387 |
|
|
set symbol-reloading -- Set dynamic symbol table reloading
|
1388 |
|
|
multiple times in one run
|
1389 |
|
|
show symbol-reloading -- Show dynamic symbol table reloading
|
1390 |
|
|
multiple times in one run
|
1391 |
|
|
|
1392 |
|
|
`complete ARGS'
|
1393 |
|
|
The `complete ARGS' command lists all the possible completions for
|
1394 |
|
|
the beginning of a command. Use ARGS to specify the beginning of
|
1395 |
|
|
the command you want completed. For example:
|
1396 |
|
|
|
1397 |
|
|
complete i
|
1398 |
|
|
|
1399 |
|
|
results in:
|
1400 |
|
|
|
1401 |
|
|
if
|
1402 |
|
|
ignore
|
1403 |
|
|
info
|
1404 |
|
|
inspect
|
1405 |
|
|
|
1406 |
|
|
This is intended for use by GNU Emacs.
|
1407 |
|
|
|
1408 |
|
|
In addition to `help', you can use the GDB commands `info' and
|
1409 |
|
|
`show' to inquire about the state of your program, or the state of GDB
|
1410 |
|
|
itself. Each command supports many topics of inquiry; this manual
|
1411 |
|
|
introduces each of them in the appropriate context. The listings under
|
1412 |
|
|
`info' and under `show' in the Index point to all the sub-commands.
|
1413 |
|
|
*Note Index::.
|
1414 |
|
|
|
1415 |
|
|
`info'
|
1416 |
|
|
This command (abbreviated `i') is for describing the state of your
|
1417 |
|
|
program. For example, you can show the arguments passed to a
|
1418 |
|
|
function with `info args', list the registers currently in use
|
1419 |
|
|
with `info registers', or list the breakpoints you have set with
|
1420 |
|
|
`info breakpoints'. You can get a complete list of the `info'
|
1421 |
|
|
sub-commands with `help info'.
|
1422 |
|
|
|
1423 |
|
|
`set'
|
1424 |
|
|
You can assign the result of an expression to an environment
|
1425 |
|
|
variable with `set'. For example, you can set the GDB prompt to a
|
1426 |
|
|
$-sign with `set prompt $'.
|
1427 |
|
|
|
1428 |
|
|
`show'
|
1429 |
|
|
In contrast to `info', `show' is for describing the state of GDB
|
1430 |
|
|
itself. You can change most of the things you can `show', by
|
1431 |
|
|
using the related command `set'; for example, you can control what
|
1432 |
|
|
number system is used for displays with `set radix', or simply
|
1433 |
|
|
inquire which is currently in use with `show radix'.
|
1434 |
|
|
|
1435 |
|
|
To display all the settable parameters and their current values,
|
1436 |
|
|
you can use `show' with no arguments; you may also use `info set'.
|
1437 |
|
|
Both commands produce the same display.
|
1438 |
|
|
|
1439 |
|
|
Here are three miscellaneous `show' subcommands, all of which are
|
1440 |
|
|
exceptional in lacking corresponding `set' commands:
|
1441 |
|
|
|
1442 |
|
|
`show version'
|
1443 |
|
|
Show what version of GDB is running. You should include this
|
1444 |
|
|
information in GDB bug-reports. If multiple versions of GDB are
|
1445 |
|
|
in use at your site, you may need to determine which version of
|
1446 |
|
|
GDB you are running; as GDB evolves, new commands are introduced,
|
1447 |
|
|
and old ones may wither away. Also, many system vendors ship
|
1448 |
|
|
variant versions of GDB, and there are variant versions of GDB in
|
1449 |
|
|
GNU/Linux distributions as well. The version number is the same
|
1450 |
|
|
as the one announced when you start GDB.
|
1451 |
|
|
|
1452 |
|
|
`show copying'
|
1453 |
|
|
`info copying'
|
1454 |
|
|
Display information about permission for copying GDB.
|
1455 |
|
|
|
1456 |
|
|
`show warranty'
|
1457 |
|
|
`info warranty'
|
1458 |
|
|
Display the GNU "NO WARRANTY" statement, or a warranty, if your
|
1459 |
|
|
version of GDB comes with one.
|
1460 |
|
|
|
1461 |
|
|
|
1462 |
|
|
|
1463 |
|
|
File: gdb.info, Node: Running, Next: Stopping, Prev: Commands, Up: Top
|
1464 |
|
|
|
1465 |
|
|
4 Running Programs Under GDB
|
1466 |
|
|
****************************
|
1467 |
|
|
|
1468 |
|
|
When you run a program under GDB, you must first generate debugging
|
1469 |
|
|
information when you compile it.
|
1470 |
|
|
|
1471 |
|
|
You may start GDB with its arguments, if any, in an environment of
|
1472 |
|
|
your choice. If you are doing native debugging, you may redirect your
|
1473 |
|
|
program's input and output, debug an already running process, or kill a
|
1474 |
|
|
child process.
|
1475 |
|
|
|
1476 |
|
|
* Menu:
|
1477 |
|
|
|
1478 |
|
|
* Compilation:: Compiling for debugging
|
1479 |
|
|
* Starting:: Starting your program
|
1480 |
|
|
* Arguments:: Your program's arguments
|
1481 |
|
|
* Environment:: Your program's environment
|
1482 |
|
|
|
1483 |
|
|
* Working Directory:: Your program's working directory
|
1484 |
|
|
* Input/Output:: Your program's input and output
|
1485 |
|
|
* Attach:: Debugging an already-running process
|
1486 |
|
|
* Kill Process:: Killing the child process
|
1487 |
|
|
|
1488 |
|
|
* Inferiors and Programs:: Debugging multiple inferiors and programs
|
1489 |
|
|
* Threads:: Debugging programs with multiple threads
|
1490 |
|
|
* Forks:: Debugging forks
|
1491 |
|
|
* Checkpoint/Restart:: Setting a _bookmark_ to return to later
|
1492 |
|
|
|
1493 |
|
|
|
1494 |
|
|
File: gdb.info, Node: Compilation, Next: Starting, Up: Running
|
1495 |
|
|
|
1496 |
|
|
4.1 Compiling for Debugging
|
1497 |
|
|
===========================
|
1498 |
|
|
|
1499 |
|
|
In order to debug a program effectively, you need to generate debugging
|
1500 |
|
|
information when you compile it. This debugging information is stored
|
1501 |
|
|
in the object file; it describes the data type of each variable or
|
1502 |
|
|
function and the correspondence between source line numbers and
|
1503 |
|
|
addresses in the executable code.
|
1504 |
|
|
|
1505 |
|
|
To request debugging information, specify the `-g' option when you
|
1506 |
|
|
run the compiler.
|
1507 |
|
|
|
1508 |
|
|
Programs that are to be shipped to your customers are compiled with
|
1509 |
|
|
optimizations, using the `-O' compiler option. However, some compilers
|
1510 |
|
|
are unable to handle the `-g' and `-O' options together. Using those
|
1511 |
|
|
compilers, you cannot generate optimized executables containing
|
1512 |
|
|
debugging information.
|
1513 |
|
|
|
1514 |
|
|
GCC, the GNU C/C++ compiler, supports `-g' with or without `-O',
|
1515 |
|
|
making it possible to debug optimized code. We recommend that you
|
1516 |
|
|
_always_ use `-g' whenever you compile a program. You may think your
|
1517 |
|
|
program is correct, but there is no sense in pushing your luck. For
|
1518 |
342 |
jeremybenn |
more information, see *note Optimized Code::.
|
1519 |
330 |
jeremybenn |
|
1520 |
|
|
Older versions of the GNU C compiler permitted a variant option
|
1521 |
|
|
`-gg' for debugging information. GDB no longer supports this format;
|
1522 |
|
|
if your GNU C compiler has this option, do not use it.
|
1523 |
|
|
|
1524 |
|
|
GDB knows about preprocessor macros and can show you their expansion
|
1525 |
|
|
(*note Macros::). Most compilers do not include information about
|
1526 |
|
|
preprocessor macros in the debugging information if you specify the
|
1527 |
|
|
`-g' flag alone, because this information is rather large. Version 3.1
|
1528 |
|
|
and later of GCC, the GNU C compiler, provides macro information if you
|
1529 |
|
|
specify the options `-gdwarf-2' and `-g3'; the former option requests
|
1530 |
|
|
debugging information in the Dwarf 2 format, and the latter requests
|
1531 |
|
|
"extra information". In the future, we hope to find more compact ways
|
1532 |
|
|
to represent macro information, so that it can be included with `-g'
|
1533 |
|
|
alone.
|
1534 |
|
|
|
1535 |
|
|
|
1536 |
|
|
File: gdb.info, Node: Starting, Next: Arguments, Prev: Compilation, Up: Running
|
1537 |
|
|
|
1538 |
|
|
4.2 Starting your Program
|
1539 |
|
|
=========================
|
1540 |
|
|
|
1541 |
|
|
`run'
|
1542 |
|
|
`r'
|
1543 |
|
|
Use the `run' command to start your program under GDB. You must
|
1544 |
|
|
first specify the program name (except on VxWorks) with an
|
1545 |
|
|
argument to GDB (*note Getting In and Out of GDB: Invocation.), or
|
1546 |
|
|
by using the `file' or `exec-file' command (*note Commands to
|
1547 |
|
|
Specify Files: Files.).
|
1548 |
|
|
|
1549 |
|
|
|
1550 |
|
|
If you are running your program in an execution environment that
|
1551 |
|
|
supports processes, `run' creates an inferior process and makes that
|
1552 |
|
|
process run your program. In some environments without processes,
|
1553 |
|
|
`run' jumps to the start of your program. Other targets, like
|
1554 |
|
|
`remote', are always running. If you get an error message like this
|
1555 |
|
|
one:
|
1556 |
|
|
|
1557 |
|
|
The "remote" target does not support "run".
|
1558 |
|
|
Try "help target" or "continue".
|
1559 |
|
|
|
1560 |
|
|
then use `continue' to run your program. You may need `load' first
|
1561 |
|
|
(*note load::).
|
1562 |
|
|
|
1563 |
|
|
The execution of a program is affected by certain information it
|
1564 |
|
|
receives from its superior. GDB provides ways to specify this
|
1565 |
|
|
information, which you must do _before_ starting your program. (You
|
1566 |
|
|
can change it after starting your program, but such changes only affect
|
1567 |
|
|
your program the next time you start it.) This information may be
|
1568 |
|
|
divided into four categories:
|
1569 |
|
|
|
1570 |
|
|
The _arguments._
|
1571 |
|
|
Specify the arguments to give your program as the arguments of the
|
1572 |
|
|
`run' command. If a shell is available on your target, the shell
|
1573 |
|
|
is used to pass the arguments, so that you may use normal
|
1574 |
|
|
conventions (such as wildcard expansion or variable substitution)
|
1575 |
|
|
in describing the arguments. In Unix systems, you can control
|
1576 |
|
|
which shell is used with the `SHELL' environment variable. *Note
|
1577 |
|
|
Your Program's Arguments: Arguments.
|
1578 |
|
|
|
1579 |
|
|
The _environment._
|
1580 |
|
|
Your program normally inherits its environment from GDB, but you
|
1581 |
|
|
can use the GDB commands `set environment' and `unset environment'
|
1582 |
|
|
to change parts of the environment that affect your program.
|
1583 |
|
|
*Note Your Program's Environment: Environment.
|
1584 |
|
|
|
1585 |
|
|
The _working directory._
|
1586 |
|
|
Your program inherits its working directory from GDB. You can set
|
1587 |
|
|
the GDB working directory with the `cd' command in GDB. *Note
|
1588 |
|
|
Your Program's Working Directory: Working Directory.
|
1589 |
|
|
|
1590 |
|
|
The _standard input and output._
|
1591 |
|
|
Your program normally uses the same device for standard input and
|
1592 |
|
|
standard output as GDB is using. You can redirect input and output
|
1593 |
|
|
in the `run' command line, or you can use the `tty' command to set
|
1594 |
|
|
a different device for your program. *Note Your Program's Input
|
1595 |
|
|
and Output: Input/Output.
|
1596 |
|
|
|
1597 |
|
|
_Warning:_ While input and output redirection work, you cannot use
|
1598 |
|
|
pipes to pass the output of the program you are debugging to
|
1599 |
|
|
another program; if you attempt this, GDB is likely to wind up
|
1600 |
|
|
debugging the wrong program.
|
1601 |
|
|
|
1602 |
|
|
When you issue the `run' command, your program begins to execute
|
1603 |
|
|
immediately. *Note Stopping and Continuing: Stopping, for discussion
|
1604 |
|
|
of how to arrange for your program to stop. Once your program has
|
1605 |
|
|
stopped, you may call functions in your program, using the `print' or
|
1606 |
|
|
`call' commands. *Note Examining Data: Data.
|
1607 |
|
|
|
1608 |
|
|
If the modification time of your symbol file has changed since the
|
1609 |
|
|
last time GDB read its symbols, GDB discards its symbol table, and
|
1610 |
|
|
reads it again. When it does this, GDB tries to retain your current
|
1611 |
|
|
breakpoints.
|
1612 |
|
|
|
1613 |
|
|
`start'
|
1614 |
|
|
The name of the main procedure can vary from language to language.
|
1615 |
|
|
With C or C++, the main procedure name is always `main', but other
|
1616 |
|
|
languages such as Ada do not require a specific name for their
|
1617 |
|
|
main procedure. The debugger provides a convenient way to start
|
1618 |
|
|
the execution of the program and to stop at the beginning of the
|
1619 |
|
|
main procedure, depending on the language used.
|
1620 |
|
|
|
1621 |
|
|
The `start' command does the equivalent of setting a temporary
|
1622 |
|
|
breakpoint at the beginning of the main procedure and then invoking
|
1623 |
|
|
the `run' command.
|
1624 |
|
|
|
1625 |
|
|
Some programs contain an "elaboration" phase where some startup
|
1626 |
|
|
code is executed before the main procedure is called. This
|
1627 |
|
|
depends on the languages used to write your program. In C++, for
|
1628 |
|
|
instance, constructors for static and global objects are executed
|
1629 |
|
|
before `main' is called. It is therefore possible that the
|
1630 |
|
|
debugger stops before reaching the main procedure. However, the
|
1631 |
|
|
temporary breakpoint will remain to halt execution.
|
1632 |
|
|
|
1633 |
|
|
Specify the arguments to give to your program as arguments to the
|
1634 |
|
|
`start' command. These arguments will be given verbatim to the
|
1635 |
|
|
underlying `run' command. Note that the same arguments will be
|
1636 |
|
|
reused if no argument is provided during subsequent calls to
|
1637 |
|
|
`start' or `run'.
|
1638 |
|
|
|
1639 |
|
|
It is sometimes necessary to debug the program during elaboration.
|
1640 |
342 |
jeremybenn |
In these cases, using the `start' command would stop the execution
|
1641 |
|
|
of your program too late, as the program would have already
|
1642 |
|
|
completed the elaboration phase. Under these circumstances,
|
1643 |
|
|
insert breakpoints in your elaboration code before running your
|
1644 |
|
|
program.
|
1645 |
330 |
jeremybenn |
|
1646 |
|
|
`set exec-wrapper WRAPPER'
|
1647 |
|
|
`show exec-wrapper'
|
1648 |
|
|
`unset exec-wrapper'
|
1649 |
|
|
When `exec-wrapper' is set, the specified wrapper is used to
|
1650 |
|
|
launch programs for debugging. GDB starts your program with a
|
1651 |
|
|
shell command of the form `exec WRAPPER PROGRAM'. Quoting is
|
1652 |
|
|
added to PROGRAM and its arguments, but not to WRAPPER, so you
|
1653 |
|
|
should add quotes if appropriate for your shell. The wrapper runs
|
1654 |
|
|
until it executes your program, and then GDB takes control.
|
1655 |
|
|
|
1656 |
|
|
You can use any program that eventually calls `execve' with its
|
1657 |
|
|
arguments as a wrapper. Several standard Unix utilities do this,
|
1658 |
|
|
e.g. `env' and `nohup'. Any Unix shell script ending with `exec
|
1659 |
|
|
"$@"' will also work.
|
1660 |
|
|
|
1661 |
|
|
For example, you can use `env' to pass an environment variable to
|
1662 |
|
|
the debugged program, without setting the variable in your shell's
|
1663 |
|
|
environment:
|
1664 |
|
|
|
1665 |
|
|
(gdb) set exec-wrapper env 'LD_PRELOAD=libtest.so'
|
1666 |
|
|
(gdb) run
|
1667 |
|
|
|
1668 |
|
|
This command is available when debugging locally on most targets,
|
1669 |
|
|
excluding DJGPP, Cygwin, MS Windows, and QNX Neutrino.
|
1670 |
|
|
|
1671 |
|
|
`set disable-randomization'
|
1672 |
|
|
`set disable-randomization on'
|
1673 |
|
|
This option (enabled by default in GDB) will turn off the native
|
1674 |
|
|
randomization of the virtual address space of the started program.
|
1675 |
|
|
This option is useful for multiple debugging sessions to make the
|
1676 |
|
|
execution better reproducible and memory addresses reusable across
|
1677 |
|
|
debugging sessions.
|
1678 |
|
|
|
1679 |
|
|
This feature is implemented only on GNU/Linux. You can get the
|
1680 |
|
|
same behavior using
|
1681 |
|
|
|
1682 |
|
|
(gdb) set exec-wrapper setarch `uname -m` -R
|
1683 |
|
|
|
1684 |
|
|
`set disable-randomization off'
|
1685 |
|
|
Leave the behavior of the started executable unchanged. Some bugs
|
1686 |
|
|
rear their ugly heads only when the program is loaded at certain
|
1687 |
|
|
addresses. If your bug disappears when you run the program under
|
1688 |
|
|
GDB, that might be because GDB by default disables the address
|
1689 |
|
|
randomization on platforms, such as GNU/Linux, which do that for
|
1690 |
|
|
stand-alone programs. Use `set disable-randomization off' to try
|
1691 |
|
|
to reproduce such elusive bugs.
|
1692 |
|
|
|
1693 |
|
|
The virtual address space randomization is implemented only on
|
1694 |
|
|
GNU/Linux. It protects the programs against some kinds of
|
1695 |
|
|
security attacks. In these cases the attacker needs to know the
|
1696 |
|
|
exact location of a concrete executable code. Randomizing its
|
1697 |
|
|
location makes it impossible to inject jumps misusing a code at
|
1698 |
|
|
its expected addresses.
|
1699 |
|
|
|
1700 |
|
|
Prelinking shared libraries provides a startup performance
|
1701 |
|
|
advantage but it makes addresses in these libraries predictable
|
1702 |
|
|
for privileged processes by having just unprivileged access at the
|
1703 |
|
|
target system. Reading the shared library binary gives enough
|
1704 |
|
|
information for assembling the malicious code misusing it. Still
|
1705 |
|
|
even a prelinked shared library can get loaded at a new random
|
1706 |
|
|
address just requiring the regular relocation process during the
|
1707 |
|
|
startup. Shared libraries not already prelinked are always loaded
|
1708 |
|
|
at a randomly chosen address.
|
1709 |
|
|
|
1710 |
|
|
Position independent executables (PIE) contain position
|
1711 |
|
|
independent code similar to the shared libraries and therefore
|
1712 |
|
|
such executables get loaded at a randomly chosen address upon
|
1713 |
|
|
startup. PIE executables always load even already prelinked
|
1714 |
|
|
shared libraries at a random address. You can build such
|
1715 |
|
|
executable using `gcc -fPIE -pie'.
|
1716 |
|
|
|
1717 |
|
|
Heap (malloc storage), stack and custom mmap areas are always
|
1718 |
|
|
placed randomly (as long as the randomization is enabled).
|
1719 |
|
|
|
1720 |
|
|
`show disable-randomization'
|
1721 |
|
|
Show the current setting of the explicit disable of the native
|
1722 |
|
|
randomization of the virtual address space of the started program.
|
1723 |
|
|
|
1724 |
|
|
|
1725 |
|
|
|
1726 |
|
|
File: gdb.info, Node: Arguments, Next: Environment, Prev: Starting, Up: Running
|
1727 |
|
|
|
1728 |
|
|
4.3 Your Program's Arguments
|
1729 |
|
|
============================
|
1730 |
|
|
|
1731 |
|
|
The arguments to your program can be specified by the arguments of the
|
1732 |
|
|
`run' command. They are passed to a shell, which expands wildcard
|
1733 |
|
|
characters and performs redirection of I/O, and thence to your program.
|
1734 |
|
|
Your `SHELL' environment variable (if it exists) specifies what shell
|
1735 |
|
|
GDB uses. If you do not define `SHELL', GDB uses the default shell
|
1736 |
|
|
(`/bin/sh' on Unix).
|
1737 |
|
|
|
1738 |
|
|
On non-Unix systems, the program is usually invoked directly by GDB,
|
1739 |
|
|
which emulates I/O redirection via the appropriate system calls, and
|
1740 |
|
|
the wildcard characters are expanded by the startup code of the
|
1741 |
|
|
program, not by the shell.
|
1742 |
|
|
|
1743 |
|
|
`run' with no arguments uses the same arguments used by the previous
|
1744 |
|
|
`run', or those set by the `set args' command.
|
1745 |
|
|
|
1746 |
|
|
`set args'
|
1747 |
|
|
Specify the arguments to be used the next time your program is
|
1748 |
|
|
run. If `set args' has no arguments, `run' executes your program
|
1749 |
|
|
with no arguments. Once you have run your program with arguments,
|
1750 |
|
|
using `set args' before the next `run' is the only way to run it
|
1751 |
|
|
again without arguments.
|
1752 |
|
|
|
1753 |
|
|
`show args'
|
1754 |
|
|
Show the arguments to give your program when it is started.
|
1755 |
|
|
|
1756 |
|
|
|
1757 |
|
|
File: gdb.info, Node: Environment, Next: Working Directory, Prev: Arguments, Up: Running
|
1758 |
|
|
|
1759 |
|
|
4.4 Your Program's Environment
|
1760 |
|
|
==============================
|
1761 |
|
|
|
1762 |
|
|
The "environment" consists of a set of environment variables and their
|
1763 |
|
|
values. Environment variables conventionally record such things as
|
1764 |
|
|
your user name, your home directory, your terminal type, and your search
|
1765 |
|
|
path for programs to run. Usually you set up environment variables with
|
1766 |
|
|
the shell and they are inherited by all the other programs you run.
|
1767 |
|
|
When debugging, it can be useful to try running your program with a
|
1768 |
|
|
modified environment without having to start GDB over again.
|
1769 |
|
|
|
1770 |
|
|
`path DIRECTORY'
|
1771 |
|
|
Add DIRECTORY to the front of the `PATH' environment variable (the
|
1772 |
|
|
search path for executables) that will be passed to your program.
|
1773 |
|
|
The value of `PATH' used by GDB does not change. You may specify
|
1774 |
|
|
several directory names, separated by whitespace or by a
|
1775 |
|
|
system-dependent separator character (`:' on Unix, `;' on MS-DOS
|
1776 |
|
|
and MS-Windows). If DIRECTORY is already in the path, it is moved
|
1777 |
|
|
to the front, so it is searched sooner.
|
1778 |
|
|
|
1779 |
|
|
You can use the string `$cwd' to refer to whatever is the current
|
1780 |
|
|
working directory at the time GDB searches the path. If you use
|
1781 |
|
|
`.' instead, it refers to the directory where you executed the
|
1782 |
|
|
`path' command. GDB replaces `.' in the DIRECTORY argument (with
|
1783 |
|
|
the current path) before adding DIRECTORY to the search path.
|
1784 |
|
|
|
1785 |
|
|
`show paths'
|
1786 |
|
|
Display the list of search paths for executables (the `PATH'
|
1787 |
|
|
environment variable).
|
1788 |
|
|
|
1789 |
|
|
`show environment [VARNAME]'
|
1790 |
|
|
Print the value of environment variable VARNAME to be given to
|
1791 |
|
|
your program when it starts. If you do not supply VARNAME, print
|
1792 |
|
|
the names and values of all environment variables to be given to
|
1793 |
|
|
your program. You can abbreviate `environment' as `env'.
|
1794 |
|
|
|
1795 |
|
|
`set environment VARNAME [=VALUE]'
|
1796 |
|
|
Set environment variable VARNAME to VALUE. The value changes for
|
1797 |
|
|
your program only, not for GDB itself. VALUE may be any string;
|
1798 |
|
|
the values of environment variables are just strings, and any
|
1799 |
|
|
interpretation is supplied by your program itself. The VALUE
|
1800 |
|
|
parameter is optional; if it is eliminated, the variable is set to
|
1801 |
|
|
a null value.
|
1802 |
|
|
|
1803 |
|
|
For example, this command:
|
1804 |
|
|
|
1805 |
|
|
set env USER = foo
|
1806 |
|
|
|
1807 |
|
|
tells the debugged program, when subsequently run, that its user
|
1808 |
|
|
is named `foo'. (The spaces around `=' are used for clarity here;
|
1809 |
|
|
they are not actually required.)
|
1810 |
|
|
|
1811 |
|
|
`unset environment VARNAME'
|
1812 |
|
|
Remove variable VARNAME from the environment to be passed to your
|
1813 |
|
|
program. This is different from `set env VARNAME ='; `unset
|
1814 |
|
|
environment' removes the variable from the environment, rather
|
1815 |
|
|
than assigning it an empty value.
|
1816 |
|
|
|
1817 |
|
|
_Warning:_ On Unix systems, GDB runs your program using the shell
|
1818 |
|
|
indicated by your `SHELL' environment variable if it exists (or
|
1819 |
|
|
`/bin/sh' if not). If your `SHELL' variable names a shell that runs an
|
1820 |
|
|
initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
|
1821 |
|
|
BASH--any variables you set in that file affect your program. You may
|
1822 |
|
|
wish to move setting of environment variables to files that are only
|
1823 |
|
|
run when you sign on, such as `.login' or `.profile'.
|
1824 |
|
|
|
1825 |
|
|
|
1826 |
|
|
File: gdb.info, Node: Working Directory, Next: Input/Output, Prev: Environment, Up: Running
|
1827 |
|
|
|
1828 |
|
|
4.5 Your Program's Working Directory
|
1829 |
|
|
====================================
|
1830 |
|
|
|
1831 |
|
|
Each time you start your program with `run', it inherits its working
|
1832 |
|
|
directory from the current working directory of GDB. The GDB working
|
1833 |
|
|
directory is initially whatever it inherited from its parent process
|
1834 |
|
|
(typically the shell), but you can specify a new working directory in
|
1835 |
|
|
GDB with the `cd' command.
|
1836 |
|
|
|
1837 |
|
|
The GDB working directory also serves as a default for the commands
|
1838 |
|
|
that specify files for GDB to operate on. *Note Commands to Specify
|
1839 |
|
|
Files: Files.
|
1840 |
|
|
|
1841 |
|
|
`cd DIRECTORY'
|
1842 |
|
|
Set the GDB working directory to DIRECTORY.
|
1843 |
|
|
|
1844 |
|
|
`pwd'
|
1845 |
|
|
Print the GDB working directory.
|
1846 |
|
|
|
1847 |
|
|
It is generally impossible to find the current working directory of
|
1848 |
|
|
the process being debugged (since a program can change its directory
|
1849 |
|
|
during its run). If you work on a system where GDB is configured with
|
1850 |
|
|
the `/proc' support, you can use the `info proc' command (*note SVR4
|
1851 |
|
|
Process Information::) to find out the current working directory of the
|
1852 |
|
|
debuggee.
|
1853 |
|
|
|
1854 |
|
|
|
1855 |
|
|
File: gdb.info, Node: Input/Output, Next: Attach, Prev: Working Directory, Up: Running
|
1856 |
|
|
|
1857 |
|
|
4.6 Your Program's Input and Output
|
1858 |
|
|
===================================
|
1859 |
|
|
|
1860 |
|
|
By default, the program you run under GDB does input and output to the
|
1861 |
|
|
same terminal that GDB uses. GDB switches the terminal to its own
|
1862 |
|
|
terminal modes to interact with you, but it records the terminal modes
|
1863 |
|
|
your program was using and switches back to them when you continue
|
1864 |
|
|
running your program.
|
1865 |
|
|
|
1866 |
|
|
`info terminal'
|
1867 |
|
|
Displays information recorded by GDB about the terminal modes your
|
1868 |
|
|
program is using.
|
1869 |
|
|
|
1870 |
|
|
You can redirect your program's input and/or output using shell
|
1871 |
|
|
redirection with the `run' command. For example,
|
1872 |
|
|
|
1873 |
|
|
run > outfile
|
1874 |
|
|
|
1875 |
|
|
starts your program, diverting its output to the file `outfile'.
|
1876 |
|
|
|
1877 |
|
|
Another way to specify where your program should do input and output
|
1878 |
|
|
is with the `tty' command. This command accepts a file name as
|
1879 |
|
|
argument, and causes this file to be the default for future `run'
|
1880 |
|
|
commands. It also resets the controlling terminal for the child
|
1881 |
|
|
process, for future `run' commands. For example,
|
1882 |
|
|
|
1883 |
|
|
tty /dev/ttyb
|
1884 |
|
|
|
1885 |
|
|
directs that processes started with subsequent `run' commands default
|
1886 |
|
|
to do input and output on the terminal `/dev/ttyb' and have that as
|
1887 |
|
|
their controlling terminal.
|
1888 |
|
|
|
1889 |
|
|
An explicit redirection in `run' overrides the `tty' command's
|
1890 |
|
|
effect on the input/output device, but not its effect on the controlling
|
1891 |
|
|
terminal.
|
1892 |
|
|
|
1893 |
|
|
When you use the `tty' command or redirect input in the `run'
|
1894 |
|
|
command, only the input _for your program_ is affected. The input for
|
1895 |
|
|
GDB still comes from your terminal. `tty' is an alias for `set
|
1896 |
|
|
inferior-tty'.
|
1897 |
|
|
|
1898 |
|
|
You can use the `show inferior-tty' command to tell GDB to display
|
1899 |
|
|
the name of the terminal that will be used for future runs of your
|
1900 |
|
|
program.
|
1901 |
|
|
|
1902 |
|
|
`set inferior-tty /dev/ttyb'
|
1903 |
|
|
Set the tty for the program being debugged to /dev/ttyb.
|
1904 |
|
|
|
1905 |
|
|
`show inferior-tty'
|
1906 |
|
|
Show the current tty for the program being debugged.
|
1907 |
|
|
|
1908 |
|
|
|
1909 |
|
|
File: gdb.info, Node: Attach, Next: Kill Process, Prev: Input/Output, Up: Running
|
1910 |
|
|
|
1911 |
|
|
4.7 Debugging an Already-running Process
|
1912 |
|
|
========================================
|
1913 |
|
|
|
1914 |
|
|
`attach PROCESS-ID'
|
1915 |
|
|
This command attaches to a running process--one that was started
|
1916 |
|
|
outside GDB. (`info files' shows your active targets.) The
|
1917 |
|
|
command takes as argument a process ID. The usual way to find out
|
1918 |
|
|
the PROCESS-ID of a Unix process is with the `ps' utility, or with
|
1919 |
|
|
the `jobs -l' shell command.
|
1920 |
|
|
|
1921 |
|
|
`attach' does not repeat if you press a second time after
|
1922 |
|
|
executing the command.
|
1923 |
|
|
|
1924 |
|
|
To use `attach', your program must be running in an environment
|
1925 |
|
|
which supports processes; for example, `attach' does not work for
|
1926 |
|
|
programs on bare-board targets that lack an operating system. You must
|
1927 |
|
|
also have permission to send the process a signal.
|
1928 |
|
|
|
1929 |
|
|
When you use `attach', the debugger finds the program running in the
|
1930 |
|
|
process first by looking in the current working directory, then (if the
|
1931 |
|
|
program is not found) by using the source file search path (*note
|
1932 |
|
|
Specifying Source Directories: Source Path.). You can also use the
|
1933 |
|
|
`file' command to load the program. *Note Commands to Specify Files:
|
1934 |
|
|
Files.
|
1935 |
|
|
|
1936 |
|
|
The first thing GDB does after arranging to debug the specified
|
1937 |
|
|
process is to stop it. You can examine and modify an attached process
|
1938 |
|
|
with all the GDB commands that are ordinarily available when you start
|
1939 |
|
|
processes with `run'. You can insert breakpoints; you can step and
|
1940 |
|
|
continue; you can modify storage. If you would rather the process
|
1941 |
|
|
continue running, you may use the `continue' command after attaching
|
1942 |
|
|
GDB to the process.
|
1943 |
|
|
|
1944 |
|
|
`detach'
|
1945 |
|
|
When you have finished debugging the attached process, you can use
|
1946 |
|
|
the `detach' command to release it from GDB control. Detaching
|
1947 |
|
|
the process continues its execution. After the `detach' command,
|
1948 |
|
|
that process and GDB become completely independent once more, and
|
1949 |
|
|
you are ready to `attach' another process or start one with `run'.
|
1950 |
|
|
`detach' does not repeat if you press again after executing
|
1951 |
|
|
the command.
|
1952 |
|
|
|
1953 |
|
|
If you exit GDB while you have an attached process, you detach that
|
1954 |
|
|
process. If you use the `run' command, you kill that process. By
|
1955 |
|
|
default, GDB asks for confirmation if you try to do either of these
|
1956 |
|
|
things; you can control whether or not you need to confirm by using the
|
1957 |
|
|
`set confirm' command (*note Optional Warnings and Messages:
|
1958 |
|
|
Messages/Warnings.).
|
1959 |
|
|
|
1960 |
|
|
|
1961 |
|
|
File: gdb.info, Node: Kill Process, Next: Inferiors and Programs, Prev: Attach, Up: Running
|
1962 |
|
|
|
1963 |
|
|
4.8 Killing the Child Process
|
1964 |
|
|
=============================
|
1965 |
|
|
|
1966 |
|
|
`kill'
|
1967 |
|
|
Kill the child process in which your program is running under GDB.
|
1968 |
|
|
|
1969 |
|
|
This command is useful if you wish to debug a core dump instead of a
|
1970 |
|
|
running process. GDB ignores any core dump file while your program is
|
1971 |
|
|
running.
|
1972 |
|
|
|
1973 |
|
|
On some operating systems, a program cannot be executed outside GDB
|
1974 |
|
|
while you have breakpoints set on it inside GDB. You can use the
|
1975 |
|
|
`kill' command in this situation to permit running your program outside
|
1976 |
|
|
the debugger.
|
1977 |
|
|
|
1978 |
|
|
The `kill' command is also useful if you wish to recompile and
|
1979 |
|
|
relink your program, since on many systems it is impossible to modify an
|
1980 |
|
|
executable file while it is running in a process. In this case, when
|
1981 |
|
|
you next type `run', GDB notices that the file has changed, and reads
|
1982 |
|
|
the symbol table again (while trying to preserve your current
|
1983 |
|
|
breakpoint settings).
|
1984 |
|
|
|
1985 |
|
|
|
1986 |
|
|
File: gdb.info, Node: Inferiors and Programs, Next: Threads, Prev: Kill Process, Up: Running
|
1987 |
|
|
|
1988 |
|
|
4.9 Debugging Multiple Inferiors and Programs
|
1989 |
|
|
=============================================
|
1990 |
|
|
|
1991 |
|
|
GDB lets you run and debug multiple programs in a single session. In
|
1992 |
|
|
addition, GDB on some systems may let you run several programs
|
1993 |
|
|
simultaneously (otherwise you have to exit from one before starting
|
1994 |
|
|
another). In the most general case, you can have multiple threads of
|
1995 |
|
|
execution in each of multiple processes, launched from multiple
|
1996 |
|
|
executables.
|
1997 |
|
|
|
1998 |
|
|
GDB represents the state of each program execution with an object
|
1999 |
|
|
called an "inferior". An inferior typically corresponds to a process,
|
2000 |
|
|
but is more general and applies also to targets that do not have
|
2001 |
|
|
processes. Inferiors may be created before a process runs, and may be
|
2002 |
|
|
retained after a process exits. Inferiors have unique identifiers that
|
2003 |
|
|
are different from process ids. Usually each inferior will also have
|
2004 |
|
|
its own distinct address space, although some embedded targets may have
|
2005 |
|
|
several inferiors running in different parts of a single address space.
|
2006 |
|
|
Each inferior may in turn have multiple threads running in it.
|
2007 |
|
|
|
2008 |
|
|
To find out what inferiors exist at any moment, use `info inferiors':
|
2009 |
|
|
|
2010 |
|
|
`info inferiors'
|
2011 |
|
|
Print a list of all inferiors currently being managed by GDB.
|
2012 |
|
|
|
2013 |
|
|
GDB displays for each inferior (in this order):
|
2014 |
|
|
|
2015 |
|
|
1. the inferior number assigned by GDB
|
2016 |
|
|
|
2017 |
|
|
2. the target system's inferior identifier
|
2018 |
|
|
|
2019 |
|
|
3. the name of the executable the inferior is running.
|
2020 |
|
|
|
2021 |
|
|
|
2022 |
|
|
An asterisk `*' preceding the GDB inferior number indicates the
|
2023 |
|
|
current inferior.
|
2024 |
|
|
|
2025 |
|
|
For example,
|
2026 |
|
|
|
2027 |
|
|
(gdb) info inferiors
|
2028 |
|
|
Num Description Executable
|
2029 |
|
|
2 process 2307 hello
|
2030 |
|
|
* 1 process 3401 goodbye
|
2031 |
|
|
|
2032 |
|
|
To switch focus between inferiors, use the `inferior' command:
|
2033 |
|
|
|
2034 |
|
|
`inferior INFNO'
|
2035 |
|
|
Make inferior number INFNO the current inferior. The argument
|
2036 |
|
|
INFNO is the inferior number assigned by GDB, as shown in the
|
2037 |
|
|
first field of the `info inferiors' display.
|
2038 |
|
|
|
2039 |
|
|
You can get multiple executables into a debugging session via the
|
2040 |
|
|
`add-inferior' and `clone-inferior' commands. On some systems GDB can
|
2041 |
|
|
add inferiors to the debug session automatically by following calls to
|
2042 |
|
|
`fork' and `exec'. To remove inferiors from the debugging session use
|
2043 |
|
|
the `remove-inferior' command.
|
2044 |
|
|
|
2045 |
|
|
`add-inferior [ -copies N ] [ -exec EXECUTABLE ]'
|
2046 |
|
|
Adds N inferiors to be run using EXECUTABLE as the executable. N
|
2047 |
|
|
defaults to 1. If no executable is specified, the inferiors
|
2048 |
|
|
begins empty, with no program. You can still assign or change the
|
2049 |
|
|
program assigned to the inferior at any time by using the `file'
|
2050 |
|
|
command with the executable name as its argument.
|
2051 |
|
|
|
2052 |
|
|
`clone-inferior [ -copies N ] [ INFNO ]'
|
2053 |
|
|
Adds N inferiors ready to execute the same program as inferior
|
2054 |
|
|
INFNO. N defaults to 1. INFNO defaults to the number of the
|
2055 |
|
|
current inferior. This is a convenient command when you want to
|
2056 |
|
|
run another instance of the inferior you are debugging.
|
2057 |
|
|
|
2058 |
|
|
(gdb) info inferiors
|
2059 |
|
|
Num Description Executable
|
2060 |
|
|
* 1 process 29964 helloworld
|
2061 |
|
|
(gdb) clone-inferior
|
2062 |
|
|
Added inferior 2.
|
2063 |
|
|
1 inferiors added.
|
2064 |
|
|
(gdb) info inferiors
|
2065 |
|
|
Num Description Executable
|
2066 |
|
|
2 helloworld
|
2067 |
|
|
* 1 process 29964 helloworld
|
2068 |
|
|
|
2069 |
|
|
You can now simply switch focus to inferior 2 and run it.
|
2070 |
|
|
|
2071 |
|
|
`remove-inferior INFNO'
|
2072 |
|
|
Removes the inferior INFNO. It is not possible to remove an
|
2073 |
|
|
inferior that is running with this command. For those, use the
|
2074 |
|
|
`kill' or `detach' command first.
|
2075 |
|
|
|
2076 |
|
|
|
2077 |
|
|
To quit debugging one of the running inferiors that is not the
|
2078 |
|
|
current inferior, you can either detach from it by using the
|
2079 |
|
|
`detach inferior' command (allowing it to run independently), or kill it
|
2080 |
|
|
using the `kill inferior' command:
|
2081 |
|
|
|
2082 |
|
|
`detach inferior INFNO'
|
2083 |
|
|
Detach from the inferior identified by GDB inferior number INFNO.
|
2084 |
|
|
Note that the inferior's entry still stays on the list of
|
2085 |
|
|
inferiors shown by `info inferiors', but its Description will show
|
2086 |
|
|
`'.
|
2087 |
|
|
|
2088 |
|
|
`kill inferior INFNO'
|
2089 |
|
|
Kill the inferior identified by GDB inferior number INFNO. Note
|
2090 |
|
|
that the inferior's entry still stays on the list of inferiors
|
2091 |
|
|
shown by `info inferiors', but its Description will show `'.
|
2092 |
|
|
|
2093 |
|
|
After the successful completion of a command such as `detach',
|
2094 |
|
|
`detach inferior', `kill' or `kill inferior', or after a normal process
|
2095 |
|
|
exit, the inferior is still valid and listed with `info inferiors',
|
2096 |
|
|
ready to be restarted.
|
2097 |
|
|
|
2098 |
|
|
To be notified when inferiors are started or exit under GDB's
|
2099 |
|
|
control use `set print inferior-events':
|
2100 |
|
|
|
2101 |
|
|
`set print inferior-events'
|
2102 |
|
|
`set print inferior-events on'
|
2103 |
|
|
`set print inferior-events off'
|
2104 |
|
|
The `set print inferior-events' command allows you to enable or
|
2105 |
|
|
disable printing of messages when GDB notices that new inferiors
|
2106 |
|
|
have started or that inferiors have exited or have been detached.
|
2107 |
|
|
By default, these messages will not be printed.
|
2108 |
|
|
|
2109 |
|
|
`show print inferior-events'
|
2110 |
|
|
Show whether messages will be printed when GDB detects that
|
2111 |
|
|
inferiors have started, exited or have been detached.
|
2112 |
|
|
|
2113 |
|
|
Many commands will work the same with multiple programs as with a
|
2114 |
|
|
single program: e.g., `print myglobal' will simply display the value of
|
2115 |
|
|
`myglobal' in the current inferior.
|
2116 |
|
|
|
2117 |
|
|
Occasionaly, when debugging GDB itself, it may be useful to get more
|
2118 |
|
|
info about the relationship of inferiors, programs, address spaces in a
|
2119 |
|
|
debug session. You can do that with the `maint info program-spaces'
|
2120 |
|
|
command.
|
2121 |
|
|
|
2122 |
|
|
`maint info program-spaces'
|
2123 |
|
|
Print a list of all program spaces currently being managed by GDB.
|
2124 |
|
|
|
2125 |
|
|
GDB displays for each program space (in this order):
|
2126 |
|
|
|
2127 |
|
|
1. the program space number assigned by GDB
|
2128 |
|
|
|
2129 |
|
|
2. the name of the executable loaded into the program space,
|
2130 |
|
|
with e.g., the `file' command.
|
2131 |
|
|
|
2132 |
|
|
|
2133 |
|
|
An asterisk `*' preceding the GDB program space number indicates
|
2134 |
|
|
the current program space.
|
2135 |
|
|
|
2136 |
|
|
In addition, below each program space line, GDB prints extra
|
2137 |
|
|
information that isn't suitable to display in tabular form. For
|
2138 |
|
|
example, the list of inferiors bound to the program space.
|
2139 |
|
|
|
2140 |
|
|
(gdb) maint info program-spaces
|
2141 |
|
|
Id Executable
|
2142 |
|
|
2 goodbye
|
2143 |
|
|
Bound inferiors: ID 1 (process 21561)
|
2144 |
|
|
* 1 hello
|
2145 |
|
|
|
2146 |
|
|
Here we can see that no inferior is running the program `hello',
|
2147 |
|
|
while `process 21561' is running the program `goodbye'. On some
|
2148 |
|
|
targets, it is possible that multiple inferiors are bound to the
|
2149 |
|
|
same program space. The most common example is that of debugging
|
2150 |
|
|
both the parent and child processes of a `vfork' call. For
|
2151 |
|
|
example,
|
2152 |
|
|
|
2153 |
|
|
(gdb) maint info program-spaces
|
2154 |
|
|
Id Executable
|
2155 |
|
|
* 1 vfork-test
|
2156 |
|
|
Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
|
2157 |
|
|
|
2158 |
|
|
Here, both inferior 2 and inferior 1 are running in the same
|
2159 |
|
|
program space as a result of inferior 1 having executed a `vfork'
|
2160 |
|
|
call.
|
2161 |
|
|
|
2162 |
|
|
|
2163 |
|
|
File: gdb.info, Node: Threads, Next: Forks, Prev: Inferiors and Programs, Up: Running
|
2164 |
|
|
|
2165 |
|
|
4.10 Debugging Programs with Multiple Threads
|
2166 |
|
|
=============================================
|
2167 |
|
|
|
2168 |
|
|
In some operating systems, such as HP-UX and Solaris, a single program
|
2169 |
|
|
may have more than one "thread" of execution. The precise semantics of
|
2170 |
|
|
threads differ from one operating system to another, but in general the
|
2171 |
|
|
threads of a single program are akin to multiple processes--except that
|
2172 |
|
|
they share one address space (that is, they can all examine and modify
|
2173 |
|
|
the same variables). On the other hand, each thread has its own
|
2174 |
|
|
registers and execution stack, and perhaps private memory.
|
2175 |
|
|
|
2176 |
|
|
GDB provides these facilities for debugging multi-thread programs:
|
2177 |
|
|
|
2178 |
|
|
* automatic notification of new threads
|
2179 |
|
|
|
2180 |
|
|
* `thread THREADNO', a command to switch among threads
|
2181 |
|
|
|
2182 |
|
|
* `info threads', a command to inquire about existing threads
|
2183 |
|
|
|
2184 |
|
|
* `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
|
2185 |
|
|
to a list of threads
|
2186 |
|
|
|
2187 |
|
|
* thread-specific breakpoints
|
2188 |
|
|
|
2189 |
|
|
* `set print thread-events', which controls printing of messages on
|
2190 |
|
|
thread start and exit.
|
2191 |
|
|
|
2192 |
|
|
* `set libthread-db-search-path PATH', which lets the user specify
|
2193 |
|
|
which `libthread_db' to use if the default choice isn't compatible
|
2194 |
|
|
with the program.
|
2195 |
|
|
|
2196 |
|
|
_Warning:_ These facilities are not yet available on every GDB
|
2197 |
|
|
configuration where the operating system supports threads. If
|
2198 |
|
|
your GDB does not support threads, these commands have no effect.
|
2199 |
|
|
For example, a system without thread support shows no output from
|
2200 |
|
|
`info threads', and always rejects the `thread' command, like this:
|
2201 |
|
|
|
2202 |
|
|
(gdb) info threads
|
2203 |
|
|
(gdb) thread 1
|
2204 |
|
|
Thread ID 1 not known. Use the "info threads" command to
|
2205 |
|
|
see the IDs of currently known threads.
|
2206 |
|
|
|
2207 |
|
|
The GDB thread debugging facility allows you to observe all threads
|
2208 |
|
|
while your program runs--but whenever GDB takes control, one thread in
|
2209 |
|
|
particular is always the focus of debugging. This thread is called the
|
2210 |
|
|
"current thread". Debugging commands show program information from the
|
2211 |
|
|
perspective of the current thread.
|
2212 |
|
|
|
2213 |
|
|
Whenever GDB detects a new thread in your program, it displays the
|
2214 |
|
|
target system's identification for the thread with a message in the
|
2215 |
|
|
form `[New SYSTAG]'. SYSTAG is a thread identifier whose form varies
|
2216 |
|
|
depending on the particular system. For example, on GNU/Linux, you
|
2217 |
|
|
might see
|
2218 |
|
|
|
2219 |
|
|
[New Thread 46912507313328 (LWP 25582)]
|
2220 |
|
|
|
2221 |
|
|
when GDB notices a new thread. In contrast, on an SGI system, the
|
2222 |
|
|
SYSTAG is simply something like `process 368', with no further
|
2223 |
|
|
qualifier.
|
2224 |
|
|
|
2225 |
|
|
For debugging purposes, GDB associates its own thread number--always
|
2226 |
|
|
a single integer--with each thread in your program.
|
2227 |
|
|
|
2228 |
|
|
`info threads'
|
2229 |
|
|
Display a summary of all threads currently in your program. GDB
|
2230 |
|
|
displays for each thread (in this order):
|
2231 |
|
|
|
2232 |
|
|
1. the thread number assigned by GDB
|
2233 |
|
|
|
2234 |
|
|
2. the target system's thread identifier (SYSTAG)
|
2235 |
|
|
|
2236 |
|
|
3. the current stack frame summary for that thread
|
2237 |
|
|
|
2238 |
|
|
An asterisk `*' to the left of the GDB thread number indicates the
|
2239 |
|
|
current thread.
|
2240 |
|
|
|
2241 |
|
|
For example,
|
2242 |
|
|
|
2243 |
|
|
(gdb) info threads
|
2244 |
|
|
3 process 35 thread 27 0x34e5 in sigpause ()
|
2245 |
|
|
2 process 35 thread 23 0x34e5 in sigpause ()
|
2246 |
|
|
* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
|
2247 |
|
|
at threadtest.c:68
|
2248 |
|
|
|
2249 |
|
|
On HP-UX systems:
|
2250 |
|
|
|
2251 |
|
|
For debugging purposes, GDB associates its own thread number--a
|
2252 |
|
|
small integer assigned in thread-creation order--with each thread in
|
2253 |
|
|
your program.
|
2254 |
|
|
|
2255 |
|
|
Whenever GDB detects a new thread in your program, it displays both
|
2256 |
|
|
GDB's thread number and the target system's identification for the
|
2257 |
|
|
thread with a message in the form `[New SYSTAG]'. SYSTAG is a thread
|
2258 |
|
|
identifier whose form varies depending on the particular system. For
|
2259 |
|
|
example, on HP-UX, you see
|
2260 |
|
|
|
2261 |
|
|
[New thread 2 (system thread 26594)]
|
2262 |
|
|
|
2263 |
|
|
when GDB notices a new thread.
|
2264 |
|
|
|
2265 |
|
|
`info threads'
|
2266 |
|
|
Display a summary of all threads currently in your program. GDB
|
2267 |
|
|
displays for each thread (in this order):
|
2268 |
|
|
|
2269 |
|
|
1. the thread number assigned by GDB
|
2270 |
|
|
|
2271 |
|
|
2. the target system's thread identifier (SYSTAG)
|
2272 |
|
|
|
2273 |
|
|
3. the current stack frame summary for that thread
|
2274 |
|
|
|
2275 |
|
|
An asterisk `*' to the left of the GDB thread number indicates the
|
2276 |
|
|
current thread.
|
2277 |
|
|
|
2278 |
|
|
For example,
|
2279 |
|
|
|
2280 |
|
|
(gdb) info threads
|
2281 |
|
|
* 3 system thread 26607 worker (wptr=0x7b09c318 "@") \
|
2282 |
|
|
|
2283 |
|
|
at quicksort.c:137
|
2284 |
|
|
2 system thread 26606 0x7b0030d8 in __ksleep () \
|
2285 |
|
|
|
2286 |
|
|
from /usr/lib/libc.2
|
2287 |
|
|
1 system thread 27905 0x7b003498 in _brk () \
|
2288 |
|
|
|
2289 |
|
|
from /usr/lib/libc.2
|
2290 |
|
|
|
2291 |
|
|
On Solaris, you can display more information about user threads with
|
2292 |
|
|
a Solaris-specific command:
|
2293 |
|
|
|
2294 |
|
|
`maint info sol-threads'
|
2295 |
|
|
Display info on Solaris user threads.
|
2296 |
|
|
|
2297 |
|
|
`thread THREADNO'
|
2298 |
|
|
Make thread number THREADNO the current thread. The command
|
2299 |
|
|
argument THREADNO is the internal GDB thread number, as shown in
|
2300 |
|
|
the first field of the `info threads' display. GDB responds by
|
2301 |
|
|
displaying the system identifier of the thread you selected, and
|
2302 |
|
|
its current stack frame summary:
|
2303 |
|
|
|
2304 |
|
|
(gdb) thread 2
|
2305 |
|
|
[Switching to process 35 thread 23]
|
2306 |
|
|
0x34e5 in sigpause ()
|
2307 |
|
|
|
2308 |
|
|
As with the `[New ...]' message, the form of the text after
|
2309 |
|
|
`Switching to' depends on your system's conventions for identifying
|
2310 |
|
|
threads.
|
2311 |
|
|
|
2312 |
|
|
The debugger convenience variable `$_thread' contains the number
|
2313 |
|
|
of the current thread. You may find this useful in writing
|
2314 |
|
|
breakpoint conditional expressions, command scripts, and so forth.
|
2315 |
|
|
See *Note Convenience Variables: Convenience Vars, for general
|
2316 |
|
|
information on convenience variables.
|
2317 |
|
|
|
2318 |
|
|
`thread apply [THREADNO] [ALL] COMMAND'
|
2319 |
|
|
The `thread apply' command allows you to apply the named COMMAND
|
2320 |
|
|
to one or more threads. Specify the numbers of the threads that
|
2321 |
|
|
you want affected with the command argument THREADNO. It can be a
|
2322 |
|
|
single thread number, one of the numbers shown in the first field
|
2323 |
|
|
of the `info threads' display; or it could be a range of thread
|
2324 |
|
|
numbers, as in `2-4'. To apply a command to all threads, type
|
2325 |
|
|
`thread apply all COMMAND'.
|
2326 |
|
|
|
2327 |
|
|
`set print thread-events'
|
2328 |
|
|
`set print thread-events on'
|
2329 |
|
|
`set print thread-events off'
|
2330 |
|
|
The `set print thread-events' command allows you to enable or
|
2331 |
|
|
disable printing of messages when GDB notices that new threads have
|
2332 |
|
|
started or that threads have exited. By default, these messages
|
2333 |
|
|
will be printed if detection of these events is supported by the
|
2334 |
|
|
target. Note that these messages cannot be disabled on all
|
2335 |
|
|
targets.
|
2336 |
|
|
|
2337 |
|
|
`show print thread-events'
|
2338 |
|
|
Show whether messages will be printed when GDB detects that threads
|
2339 |
|
|
have started and exited.
|
2340 |
|
|
|
2341 |
|
|
*Note Stopping and Starting Multi-thread Programs: Thread Stops, for
|
2342 |
|
|
more information about how GDB behaves when you stop and start programs
|
2343 |
|
|
with multiple threads.
|
2344 |
|
|
|
2345 |
|
|
*Note Setting Watchpoints: Set Watchpoints, for information about
|
2346 |
|
|
watchpoints in programs with multiple threads.
|
2347 |
|
|
|
2348 |
|
|
`set libthread-db-search-path [PATH]'
|
2349 |
|
|
If this variable is set, PATH is a colon-separated list of
|
2350 |
|
|
directories GDB will use to search for `libthread_db'. If you
|
2351 |
|
|
omit PATH, `libthread-db-search-path' will be reset to an empty
|
2352 |
|
|
list.
|
2353 |
|
|
|
2354 |
|
|
On GNU/Linux and Solaris systems, GDB uses a "helper"
|
2355 |
|
|
`libthread_db' library to obtain information about threads in the
|
2356 |
|
|
inferior process. GDB will use `libthread-db-search-path' to find
|
2357 |
|
|
`libthread_db'. If that fails, GDB will continue with default
|
2358 |
|
|
system shared library directories, and finally the directory from
|
2359 |
|
|
which `libpthread' was loaded in the inferior process.
|
2360 |
|
|
|
2361 |
|
|
For any `libthread_db' library GDB finds in above directories, GDB
|
2362 |
|
|
attempts to initialize it with the current inferior process. If
|
2363 |
|
|
this initialization fails (which could happen because of a version
|
2364 |
|
|
mismatch between `libthread_db' and `libpthread'), GDB will unload
|
2365 |
|
|
`libthread_db', and continue with the next directory. If none of
|
2366 |
|
|
`libthread_db' libraries initialize successfully, GDB will issue a
|
2367 |
|
|
warning and thread debugging will be disabled.
|
2368 |
|
|
|
2369 |
|
|
Setting `libthread-db-search-path' is currently implemented only
|
2370 |
|
|
on some platforms.
|
2371 |
|
|
|
2372 |
|
|
`show libthread-db-search-path'
|
2373 |
|
|
Display current libthread_db search path.
|
2374 |
|
|
|
2375 |
|
|
|
2376 |
|
|
File: gdb.info, Node: Forks, Next: Checkpoint/Restart, Prev: Threads, Up: Running
|
2377 |
|
|
|
2378 |
|
|
4.11 Debugging Forks
|
2379 |
|
|
====================
|
2380 |
|
|
|
2381 |
|
|
On most systems, GDB has no special support for debugging programs
|
2382 |
|
|
which create additional processes using the `fork' function. When a
|
2383 |
|
|
program forks, GDB will continue to debug the parent process and the
|
2384 |
|
|
child process will run unimpeded. If you have set a breakpoint in any
|
2385 |
|
|
code which the child then executes, the child will get a `SIGTRAP'
|
2386 |
|
|
signal which (unless it catches the signal) will cause it to terminate.
|
2387 |
|
|
|
2388 |
|
|
However, if you want to debug the child process there is a workaround
|
2389 |
|
|
which isn't too painful. Put a call to `sleep' in the code which the
|
2390 |
|
|
child process executes after the fork. It may be useful to sleep only
|
2391 |
|
|
if a certain environment variable is set, or a certain file exists, so
|
2392 |
|
|
that the delay need not occur when you don't want to run GDB on the
|
2393 |
|
|
child. While the child is sleeping, use the `ps' program to get its
|
2394 |
|
|
process ID. Then tell GDB (a new invocation of GDB if you are also
|
2395 |
|
|
debugging the parent process) to attach to the child process (*note
|
2396 |
|
|
Attach::). From that point on you can debug the child process just
|
2397 |
|
|
like any other process which you attached to.
|
2398 |
|
|
|
2399 |
|
|
On some systems, GDB provides support for debugging programs that
|
2400 |
|
|
create additional processes using the `fork' or `vfork' functions.
|
2401 |
|
|
Currently, the only platforms with this feature are HP-UX (11.x and
|
2402 |
|
|
later only?) and GNU/Linux (kernel version 2.5.60 and later).
|
2403 |
|
|
|
2404 |
|
|
By default, when a program forks, GDB will continue to debug the
|
2405 |
|
|
parent process and the child process will run unimpeded.
|
2406 |
|
|
|
2407 |
|
|
If you want to follow the child process instead of the parent
|
2408 |
|
|
process, use the command `set follow-fork-mode'.
|
2409 |
|
|
|
2410 |
|
|
`set follow-fork-mode MODE'
|
2411 |
|
|
Set the debugger response to a program call of `fork' or `vfork'.
|
2412 |
|
|
A call to `fork' or `vfork' creates a new process. The MODE
|
2413 |
|
|
argument can be:
|
2414 |
|
|
|
2415 |
|
|
`parent'
|
2416 |
|
|
The original process is debugged after a fork. The child
|
2417 |
|
|
process runs unimpeded. This is the default.
|
2418 |
|
|
|
2419 |
|
|
`child'
|
2420 |
|
|
The new process is debugged after a fork. The parent process
|
2421 |
|
|
runs unimpeded.
|
2422 |
|
|
|
2423 |
|
|
|
2424 |
|
|
`show follow-fork-mode'
|
2425 |
|
|
Display the current debugger response to a `fork' or `vfork' call.
|
2426 |
|
|
|
2427 |
|
|
On Linux, if you want to debug both the parent and child processes,
|
2428 |
|
|
use the command `set detach-on-fork'.
|
2429 |
|
|
|
2430 |
|
|
`set detach-on-fork MODE'
|
2431 |
|
|
Tells gdb whether to detach one of the processes after a fork, or
|
2432 |
|
|
retain debugger control over them both.
|
2433 |
|
|
|
2434 |
|
|
`on'
|
2435 |
|
|
The child process (or parent process, depending on the value
|
2436 |
|
|
of `follow-fork-mode') will be detached and allowed to run
|
2437 |
|
|
independently. This is the default.
|
2438 |
|
|
|
2439 |
|
|
`off'
|
2440 |
|
|
Both processes will be held under the control of GDB. One
|
2441 |
|
|
process (child or parent, depending on the value of
|
2442 |
|
|
`follow-fork-mode') is debugged as usual, while the other is
|
2443 |
|
|
held suspended.
|
2444 |
|
|
|
2445 |
|
|
|
2446 |
|
|
`show detach-on-fork'
|
2447 |
|
|
Show whether detach-on-fork mode is on/off.
|
2448 |
|
|
|
2449 |
|
|
If you choose to set `detach-on-fork' mode off, then GDB will retain
|
2450 |
|
|
control of all forked processes (including nested forks). You can list
|
2451 |
|
|
the forked processes under the control of GDB by using the
|
2452 |
|
|
`info inferiors' command, and switch from one fork to another by using
|
2453 |
|
|
the `inferior' command (*note Debugging Multiple Inferiors and
|
2454 |
|
|
Programs: Inferiors and Programs.).
|
2455 |
|
|
|
2456 |
|
|
To quit debugging one of the forked processes, you can either detach
|
2457 |
|
|
from it by using the `detach inferior' command (allowing it to run
|
2458 |
|
|
independently), or kill it using the `kill inferior' command. *Note
|
2459 |
|
|
Debugging Multiple Inferiors and Programs: Inferiors and Programs.
|
2460 |
|
|
|
2461 |
|
|
If you ask to debug a child process and a `vfork' is followed by an
|
2462 |
|
|
`exec', GDB executes the new target up to the first breakpoint in the
|
2463 |
|
|
new target. If you have a breakpoint set on `main' in your original
|
2464 |
|
|
program, the breakpoint will also be set on the child process's `main'.
|
2465 |
|
|
|
2466 |
|
|
On some systems, when a child process is spawned by `vfork', you
|
2467 |
|
|
cannot debug the child or parent until an `exec' call completes.
|
2468 |
|
|
|
2469 |
|
|
If you issue a `run' command to GDB after an `exec' call executes,
|
2470 |
|
|
the new target restarts. To restart the parent process, use the `file'
|
2471 |
|
|
command with the parent executable name as its argument. By default,
|
2472 |
|
|
after an `exec' call executes, GDB discards the symbols of the previous
|
2473 |
|
|
executable image. You can change this behaviour with the
|
2474 |
|
|
`set follow-exec-mode' command.
|
2475 |
|
|
|
2476 |
|
|
`set follow-exec-mode MODE'
|
2477 |
|
|
Set debugger response to a program call of `exec'. An `exec' call
|
2478 |
|
|
replaces the program image of a process.
|
2479 |
|
|
|
2480 |
|
|
`follow-exec-mode' can be:
|
2481 |
|
|
|
2482 |
|
|
`new'
|
2483 |
|
|
GDB creates a new inferior and rebinds the process to this
|
2484 |
|
|
new inferior. The program the process was running before the
|
2485 |
|
|
`exec' call can be restarted afterwards by restarting the
|
2486 |
|
|
original inferior.
|
2487 |
|
|
|
2488 |
|
|
For example:
|
2489 |
|
|
|
2490 |
|
|
(gdb) info inferiors
|
2491 |
|
|
(gdb) info inferior
|
2492 |
|
|
Id Description Executable
|
2493 |
|
|
* 1 prog1
|
2494 |
|
|
(gdb) run
|
2495 |
|
|
process 12020 is executing new program: prog2
|
2496 |
|
|
Program exited normally.
|
2497 |
|
|
(gdb) info inferiors
|
2498 |
|
|
Id Description Executable
|
2499 |
|
|
* 2 prog2
|
2500 |
|
|
1 prog1
|
2501 |
|
|
|
2502 |
|
|
`same'
|
2503 |
|
|
GDB keeps the process bound to the same inferior. The new
|
2504 |
|
|
executable image replaces the previous executable loaded in
|
2505 |
|
|
the inferior. Restarting the inferior after the `exec' call,
|
2506 |
|
|
with e.g., the `run' command, restarts the executable the
|
2507 |
|
|
process was running after the `exec' call. This is the
|
2508 |
|
|
default mode.
|
2509 |
|
|
|
2510 |
|
|
For example:
|
2511 |
|
|
|
2512 |
|
|
(gdb) info inferiors
|
2513 |
|
|
Id Description Executable
|
2514 |
|
|
* 1 prog1
|
2515 |
|
|
(gdb) run
|
2516 |
|
|
process 12020 is executing new program: prog2
|
2517 |
|
|
Program exited normally.
|
2518 |
|
|
(gdb) info inferiors
|
2519 |
|
|
Id Description Executable
|
2520 |
|
|
* 1 prog2
|
2521 |
|
|
|
2522 |
|
|
|
2523 |
|
|
You can use the `catch' command to make GDB stop whenever a `fork',
|
2524 |
|
|
`vfork', or `exec' call is made. *Note Setting Catchpoints: Set
|
2525 |
|
|
Catchpoints.
|
2526 |
|
|
|
2527 |
|
|
|
2528 |
|
|
File: gdb.info, Node: Checkpoint/Restart, Prev: Forks, Up: Running
|
2529 |
|
|
|
2530 |
|
|
4.12 Setting a _Bookmark_ to Return to Later
|
2531 |
|
|
============================================
|
2532 |
|
|
|
2533 |
|
|
On certain operating systems(1), GDB is able to save a "snapshot" of a
|
2534 |
|
|
program's state, called a "checkpoint", and come back to it later.
|
2535 |
|
|
|
2536 |
|
|
Returning to a checkpoint effectively undoes everything that has
|
2537 |
|
|
happened in the program since the `checkpoint' was saved. This
|
2538 |
|
|
includes changes in memory, registers, and even (within some limits)
|
2539 |
|
|
system state. Effectively, it is like going back in time to the moment
|
2540 |
|
|
when the checkpoint was saved.
|
2541 |
|
|
|
2542 |
|
|
Thus, if you're stepping thru a program and you think you're getting
|
2543 |
|
|
close to the point where things go wrong, you can save a checkpoint.
|
2544 |
|
|
Then, if you accidentally go too far and miss the critical statement,
|
2545 |
|
|
instead of having to restart your program from the beginning, you can
|
2546 |
|
|
just go back to the checkpoint and start again from there.
|
2547 |
|
|
|
2548 |
|
|
This can be especially useful if it takes a lot of time or steps to
|
2549 |
|
|
reach the point where you think the bug occurs.
|
2550 |
|
|
|
2551 |
|
|
To use the `checkpoint'/`restart' method of debugging:
|
2552 |
|
|
|
2553 |
|
|
`checkpoint'
|
2554 |
|
|
Save a snapshot of the debugged program's current execution state.
|
2555 |
|
|
The `checkpoint' command takes no arguments, but each checkpoint
|
2556 |
|
|
is assigned a small integer id, similar to a breakpoint id.
|
2557 |
|
|
|
2558 |
|
|
`info checkpoints'
|
2559 |
|
|
List the checkpoints that have been saved in the current debugging
|
2560 |
|
|
session. For each checkpoint, the following information will be
|
2561 |
|
|
listed:
|
2562 |
|
|
|
2563 |
|
|
`Checkpoint ID'
|
2564 |
|
|
|
2565 |
|
|
`Process ID'
|
2566 |
|
|
|
2567 |
|
|
`Code Address'
|
2568 |
|
|
|
2569 |
|
|
`Source line, or label'
|
2570 |
|
|
|
2571 |
|
|
`restart CHECKPOINT-ID'
|
2572 |
|
|
Restore the program state that was saved as checkpoint number
|
2573 |
|
|
CHECKPOINT-ID. All program variables, registers, stack frames
|
2574 |
|
|
etc. will be returned to the values that they had when the
|
2575 |
|
|
checkpoint was saved. In essence, gdb will "wind back the clock"
|
2576 |
|
|
to the point in time when the checkpoint was saved.
|
2577 |
|
|
|
2578 |
|
|
Note that breakpoints, GDB variables, command history etc. are
|
2579 |
|
|
not affected by restoring a checkpoint. In general, a checkpoint
|
2580 |
|
|
only restores things that reside in the program being debugged,
|
2581 |
|
|
not in the debugger.
|
2582 |
|
|
|
2583 |
|
|
`delete checkpoint CHECKPOINT-ID'
|
2584 |
|
|
Delete the previously-saved checkpoint identified by CHECKPOINT-ID.
|
2585 |
|
|
|
2586 |
|
|
|
2587 |
|
|
Returning to a previously saved checkpoint will restore the user
|
2588 |
|
|
state of the program being debugged, plus a significant subset of the
|
2589 |
|
|
system (OS) state, including file pointers. It won't "un-write" data
|
2590 |
|
|
from a file, but it will rewind the file pointer to the previous
|
2591 |
|
|
location, so that the previously written data can be overwritten. For
|
2592 |
|
|
files opened in read mode, the pointer will also be restored so that the
|
2593 |
|
|
previously read data can be read again.
|
2594 |
|
|
|
2595 |
|
|
Of course, characters that have been sent to a printer (or other
|
2596 |
|
|
external device) cannot be "snatched back", and characters received
|
2597 |
|
|
from eg. a serial device can be removed from internal program buffers,
|
2598 |
|
|
but they cannot be "pushed back" into the serial pipeline, ready to be
|
2599 |
|
|
received again. Similarly, the actual contents of files that have been
|
2600 |
|
|
changed cannot be restored (at this time).
|
2601 |
|
|
|
2602 |
|
|
However, within those constraints, you actually can "rewind" your
|
2603 |
|
|
program to a previously saved point in time, and begin debugging it
|
2604 |
|
|
again -- and you can change the course of events so as to debug a
|
2605 |
|
|
different execution path this time.
|
2606 |
|
|
|
2607 |
|
|
Finally, there is one bit of internal program state that will be
|
2608 |
|
|
different when you return to a checkpoint -- the program's process id.
|
2609 |
|
|
Each checkpoint will have a unique process id (or PID), and each will
|
2610 |
|
|
be different from the program's original PID. If your program has
|
2611 |
|
|
saved a local copy of its process id, this could potentially pose a
|
2612 |
|
|
problem.
|
2613 |
|
|
|
2614 |
|
|
4.12.1 A Non-obvious Benefit of Using Checkpoints
|
2615 |
|
|
-------------------------------------------------
|
2616 |
|
|
|
2617 |
|
|
On some systems such as GNU/Linux, address space randomization is
|
2618 |
|
|
performed on new processes for security reasons. This makes it
|
2619 |
|
|
difficult or impossible to set a breakpoint, or watchpoint, on an
|
2620 |
|
|
absolute address if you have to restart the program, since the absolute
|
2621 |
|
|
location of a symbol will change from one execution to the next.
|
2622 |
|
|
|
2623 |
|
|
A checkpoint, however, is an _identical_ copy of a process.
|
2624 |
|
|
Therefore if you create a checkpoint at (eg.) the start of main, and
|
2625 |
|
|
simply return to that checkpoint instead of restarting the process, you
|
2626 |
|
|
can avoid the effects of address randomization and your symbols will
|
2627 |
|
|
all stay in the same place.
|
2628 |
|
|
|
2629 |
|
|
---------- Footnotes ----------
|
2630 |
|
|
|
2631 |
|
|
(1) Currently, only GNU/Linux.
|
2632 |
|
|
|
2633 |
|
|
|
2634 |
|
|
File: gdb.info, Node: Stopping, Next: Reverse Execution, Prev: Running, Up: Top
|
2635 |
|
|
|
2636 |
|
|
5 Stopping and Continuing
|
2637 |
|
|
*************************
|
2638 |
|
|
|
2639 |
|
|
The principal purposes of using a debugger are so that you can stop your
|
2640 |
|
|
program before it terminates; or so that, if your program runs into
|
2641 |
|
|
trouble, you can investigate and find out why.
|
2642 |
|
|
|
2643 |
|
|
Inside GDB, your program may stop for any of several reasons, such
|
2644 |
|
|
as a signal, a breakpoint, or reaching a new line after a GDB command
|
2645 |
|
|
such as `step'. You may then examine and change variables, set new
|
2646 |
|
|
breakpoints or remove old ones, and then continue execution. Usually,
|
2647 |
|
|
the messages shown by GDB provide ample explanation of the status of
|
2648 |
|
|
your program--but you can also explicitly request this information at
|
2649 |
|
|
any time.
|
2650 |
|
|
|
2651 |
|
|
`info program'
|
2652 |
|
|
Display information about the status of your program: whether it is
|
2653 |
|
|
running or not, what process it is, and why it stopped.
|
2654 |
|
|
|
2655 |
|
|
* Menu:
|
2656 |
|
|
|
2657 |
|
|
* Breakpoints:: Breakpoints, watchpoints, and catchpoints
|
2658 |
|
|
* Continuing and Stepping:: Resuming execution
|
2659 |
|
|
* Signals:: Signals
|
2660 |
|
|
* Thread Stops:: Stopping and starting multi-thread programs
|
2661 |
|
|
|
2662 |
|
|
|
2663 |
|
|
File: gdb.info, Node: Breakpoints, Next: Continuing and Stepping, Up: Stopping
|
2664 |
|
|
|
2665 |
|
|
5.1 Breakpoints, Watchpoints, and Catchpoints
|
2666 |
|
|
=============================================
|
2667 |
|
|
|
2668 |
|
|
A "breakpoint" makes your program stop whenever a certain point in the
|
2669 |
|
|
program is reached. For each breakpoint, you can add conditions to
|
2670 |
|
|
control in finer detail whether your program stops. You can set
|
2671 |
|
|
breakpoints with the `break' command and its variants (*note Setting
|
2672 |
|
|
Breakpoints: Set Breaks.), to specify the place where your program
|
2673 |
|
|
should stop by line number, function name or exact address in the
|
2674 |
|
|
program.
|
2675 |
|
|
|
2676 |
|
|
On some systems, you can set breakpoints in shared libraries before
|
2677 |
|
|
the executable is run. There is a minor limitation on HP-UX systems:
|
2678 |
|
|
you must wait until the executable is run in order to set breakpoints
|
2679 |
|
|
in shared library routines that are not called directly by the program
|
2680 |
|
|
(for example, routines that are arguments in a `pthread_create' call).
|
2681 |
|
|
|
2682 |
|
|
A "watchpoint" is a special breakpoint that stops your program when
|
2683 |
|
|
the value of an expression changes. The expression may be a value of a
|
2684 |
|
|
variable, or it could involve values of one or more variables combined
|
2685 |
|
|
by operators, such as `a + b'. This is sometimes called "data
|
2686 |
|
|
breakpoints". You must use a different command to set watchpoints
|
2687 |
|
|
(*note Setting Watchpoints: Set Watchpoints.), but aside from that, you
|
2688 |
|
|
can manage a watchpoint like any other breakpoint: you enable, disable,
|
2689 |
|
|
and delete both breakpoints and watchpoints using the same commands.
|
2690 |
|
|
|
2691 |
|
|
You can arrange to have values from your program displayed
|
2692 |
|
|
automatically whenever GDB stops at a breakpoint. *Note Automatic
|
2693 |
|
|
Display: Auto Display.
|
2694 |
|
|
|
2695 |
|
|
A "catchpoint" is another special breakpoint that stops your program
|
2696 |
|
|
when a certain kind of event occurs, such as the throwing of a C++
|
2697 |
|
|
exception or the loading of a library. As with watchpoints, you use a
|
2698 |
|
|
different command to set a catchpoint (*note Setting Catchpoints: Set
|
2699 |
|
|
Catchpoints.), but aside from that, you can manage a catchpoint like any
|
2700 |
|
|
other breakpoint. (To stop when your program receives a signal, use the
|
2701 |
342 |
jeremybenn |
`handle' command; see *note Signals: Signals.)
|
2702 |
330 |
jeremybenn |
|
2703 |
|
|
GDB assigns a number to each breakpoint, watchpoint, or catchpoint
|
2704 |
|
|
when you create it; these numbers are successive integers starting with
|
2705 |
|
|
one. In many of the commands for controlling various features of
|
2706 |
|
|
breakpoints you use the breakpoint number to say which breakpoint you
|
2707 |
|
|
want to change. Each breakpoint may be "enabled" or "disabled"; if
|
2708 |
|
|
disabled, it has no effect on your program until you enable it again.
|
2709 |
|
|
|
2710 |
|
|
Some GDB commands accept a range of breakpoints on which to operate.
|
2711 |
|
|
A breakpoint range is either a single breakpoint number, like `5', or
|
2712 |
|
|
two such numbers, in increasing order, separated by a hyphen, like
|
2713 |
|
|
`5-7'. When a breakpoint range is given to a command, all breakpoints
|
2714 |
|
|
in that range are operated on.
|
2715 |
|
|
|
2716 |
|
|
* Menu:
|
2717 |
|
|
|
2718 |
|
|
* Set Breaks:: Setting breakpoints
|
2719 |
|
|
* Set Watchpoints:: Setting watchpoints
|
2720 |
|
|
* Set Catchpoints:: Setting catchpoints
|
2721 |
|
|
* Delete Breaks:: Deleting breakpoints
|
2722 |
|
|
* Disabling:: Disabling breakpoints
|
2723 |
|
|
* Conditions:: Break conditions
|
2724 |
|
|
* Break Commands:: Breakpoint command lists
|
2725 |
|
|
* Save Breakpoints:: How to save breakpoints in a file
|
2726 |
|
|
* Error in Breakpoints:: ``Cannot insert breakpoints''
|
2727 |
|
|
* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
|
2728 |
|
|
|
2729 |
|
|
|
2730 |
|
|
File: gdb.info, Node: Set Breaks, Next: Set Watchpoints, Up: Breakpoints
|
2731 |
|
|
|
2732 |
|
|
5.1.1 Setting Breakpoints
|
2733 |
|
|
-------------------------
|
2734 |
|
|
|
2735 |
|
|
Breakpoints are set with the `break' command (abbreviated `b'). The
|
2736 |
|
|
debugger convenience variable `$bpnum' records the number of the
|
2737 |
342 |
jeremybenn |
breakpoint you've set most recently; see *note Convenience Variables:
|
2738 |
330 |
jeremybenn |
Convenience Vars, for a discussion of what you can do with convenience
|
2739 |
|
|
variables.
|
2740 |
|
|
|
2741 |
|
|
`break LOCATION'
|
2742 |
|
|
Set a breakpoint at the given LOCATION, which can specify a
|
2743 |
|
|
function name, a line number, or an address of an instruction.
|
2744 |
|
|
(*Note Specify Location::, for a list of all the possible ways to
|
2745 |
|
|
specify a LOCATION.) The breakpoint will stop your program just
|
2746 |
|
|
before it executes any of the code in the specified LOCATION.
|
2747 |
|
|
|
2748 |
|
|
When using source languages that permit overloading of symbols,
|
2749 |
|
|
such as C++, a function name may refer to more than one possible
|
2750 |
|
|
place to break. *Note Ambiguous Expressions: Ambiguous
|
2751 |
|
|
Expressions, for a discussion of that situation.
|
2752 |
|
|
|
2753 |
|
|
It is also possible to insert a breakpoint that will stop the
|
2754 |
|
|
program only if a specific thread (*note Thread-Specific
|
2755 |
|
|
Breakpoints::) or a specific task (*note Ada Tasks::) hits that
|
2756 |
|
|
breakpoint.
|
2757 |
|
|
|
2758 |
|
|
`break'
|
2759 |
|
|
When called without any arguments, `break' sets a breakpoint at
|
2760 |
|
|
the next instruction to be executed in the selected stack frame
|
2761 |
|
|
(*note Examining the Stack: Stack.). In any selected frame but the
|
2762 |
|
|
innermost, this makes your program stop as soon as control returns
|
2763 |
|
|
to that frame. This is similar to the effect of a `finish'
|
2764 |
|
|
command in the frame inside the selected frame--except that
|
2765 |
|
|
`finish' does not leave an active breakpoint. If you use `break'
|
2766 |
|
|
without an argument in the innermost frame, GDB stops the next
|
2767 |
|
|
time it reaches the current location; this may be useful inside
|
2768 |
|
|
loops.
|
2769 |
|
|
|
2770 |
|
|
GDB normally ignores breakpoints when it resumes execution, until
|
2771 |
|
|
at least one instruction has been executed. If it did not do
|
2772 |
|
|
this, you would be unable to proceed past a breakpoint without
|
2773 |
|
|
first disabling the breakpoint. This rule applies whether or not
|
2774 |
|
|
the breakpoint already existed when your program stopped.
|
2775 |
|
|
|
2776 |
|
|
`break ... if COND'
|
2777 |
|
|
Set a breakpoint with condition COND; evaluate the expression COND
|
2778 |
|
|
each time the breakpoint is reached, and stop only if the value is
|
2779 |
|
|
nonzero--that is, if COND evaluates as true. `...' stands for one
|
2780 |
|
|
of the possible arguments described above (or no argument)
|
2781 |
|
|
specifying where to break. *Note Break Conditions: Conditions,
|
2782 |
|
|
for more information on breakpoint conditions.
|
2783 |
|
|
|
2784 |
|
|
`tbreak ARGS'
|
2785 |
|
|
Set a breakpoint enabled only for one stop. ARGS are the same as
|
2786 |
|
|
for the `break' command, and the breakpoint is set in the same
|
2787 |
|
|
way, but the breakpoint is automatically deleted after the first
|
2788 |
|
|
time your program stops there. *Note Disabling Breakpoints:
|
2789 |
|
|
Disabling.
|
2790 |
|
|
|
2791 |
|
|
`hbreak ARGS'
|
2792 |
|
|
Set a hardware-assisted breakpoint. ARGS are the same as for the
|
2793 |
|
|
`break' command and the breakpoint is set in the same way, but the
|
2794 |
|
|
breakpoint requires hardware support and some target hardware may
|
2795 |
|
|
not have this support. The main purpose of this is EPROM/ROM code
|
2796 |
|
|
debugging, so you can set a breakpoint at an instruction without
|
2797 |
|
|
changing the instruction. This can be used with the new
|
2798 |
|
|
trap-generation provided by SPARClite DSU and most x86-based
|
2799 |
|
|
targets. These targets will generate traps when a program
|
2800 |
|
|
accesses some data or instruction address that is assigned to the
|
2801 |
|
|
debug registers. However the hardware breakpoint registers can
|
2802 |
|
|
take a limited number of breakpoints. For example, on the DSU,
|
2803 |
|
|
only two data breakpoints can be set at a time, and GDB will
|
2804 |
|
|
reject this command if more than two are used. Delete or disable
|
2805 |
|
|
unused hardware breakpoints before setting new ones (*note
|
2806 |
|
|
Disabling Breakpoints: Disabling.). *Note Break Conditions:
|
2807 |
|
|
Conditions. For remote targets, you can restrict the number of
|
2808 |
342 |
jeremybenn |
hardware breakpoints GDB will use, see *note set remote
|
2809 |
330 |
jeremybenn |
hardware-breakpoint-limit::.
|
2810 |
|
|
|
2811 |
|
|
`thbreak ARGS'
|
2812 |
|
|
Set a hardware-assisted breakpoint enabled only for one stop. ARGS
|
2813 |
|
|
are the same as for the `hbreak' command and the breakpoint is set
|
2814 |
|
|
in the same way. However, like the `tbreak' command, the
|
2815 |
|
|
breakpoint is automatically deleted after the first time your
|
2816 |
|
|
program stops there. Also, like the `hbreak' command, the
|
2817 |
|
|
breakpoint requires hardware support and some target hardware may
|
2818 |
|
|
not have this support. *Note Disabling Breakpoints: Disabling.
|
2819 |
342 |
jeremybenn |
See also *note Break Conditions: Conditions.
|
2820 |
330 |
jeremybenn |
|
2821 |
|
|
`rbreak REGEX'
|
2822 |
|
|
Set breakpoints on all functions matching the regular expression
|
2823 |
|
|
REGEX. This command sets an unconditional breakpoint on all
|
2824 |
|
|
matches, printing a list of all breakpoints it set. Once these
|
2825 |
|
|
breakpoints are set, they are treated just like the breakpoints
|
2826 |
|
|
set with the `break' command. You can delete them, disable them,
|
2827 |
|
|
or make them conditional the same way as any other breakpoint.
|
2828 |
|
|
|
2829 |
|
|
The syntax of the regular expression is the standard one used with
|
2830 |
|
|
tools like `grep'. Note that this is different from the syntax
|
2831 |
|
|
used by shells, so for instance `foo*' matches all functions that
|
2832 |
|
|
include an `fo' followed by zero or more `o's. There is an
|
2833 |
|
|
implicit `.*' leading and trailing the regular expression you
|
2834 |
|
|
supply, so to match only functions that begin with `foo', use
|
2835 |
|
|
`^foo'.
|
2836 |
|
|
|
2837 |
|
|
When debugging C++ programs, `rbreak' is useful for setting
|
2838 |
|
|
breakpoints on overloaded functions that are not members of any
|
2839 |
|
|
special classes.
|
2840 |
|
|
|
2841 |
|
|
The `rbreak' command can be used to set breakpoints in *all* the
|
2842 |
|
|
functions in a program, like this:
|
2843 |
|
|
|
2844 |
|
|
(gdb) rbreak .
|
2845 |
|
|
|
2846 |
|
|
`rbreak FILE:REGEX'
|
2847 |
|
|
If `rbreak' is called with a filename qualification, it limits the
|
2848 |
|
|
search for functions matching the given regular expression to the
|
2849 |
|
|
specified FILE. This can be used, for example, to set breakpoints
|
2850 |
|
|
on every function in a given file:
|
2851 |
|
|
|
2852 |
|
|
(gdb) rbreak file.c:.
|
2853 |
|
|
|
2854 |
|
|
The colon separating the filename qualifier from the regex may
|
2855 |
|
|
optionally be surrounded by spaces.
|
2856 |
|
|
|
2857 |
|
|
`info breakpoints [N]'
|
2858 |
|
|
`info break [N]'
|
2859 |
|
|
Print a table of all breakpoints, watchpoints, and catchpoints set
|
2860 |
|
|
and not deleted. Optional argument N means print information only
|
2861 |
|
|
about the specified breakpoint (or watchpoint or catchpoint). For
|
2862 |
|
|
each breakpoint, following columns are printed:
|
2863 |
|
|
|
2864 |
|
|
_Breakpoint Numbers_
|
2865 |
|
|
|
2866 |
|
|
_Type_
|
2867 |
|
|
Breakpoint, watchpoint, or catchpoint.
|
2868 |
|
|
|
2869 |
|
|
_Disposition_
|
2870 |
|
|
Whether the breakpoint is marked to be disabled or deleted
|
2871 |
|
|
when hit.
|
2872 |
|
|
|
2873 |
|
|
_Enabled or Disabled_
|
2874 |
|
|
Enabled breakpoints are marked with `y'. `n' marks
|
2875 |
|
|
breakpoints that are not enabled.
|
2876 |
|
|
|
2877 |
|
|
_Address_
|
2878 |
|
|
Where the breakpoint is in your program, as a memory address.
|
2879 |
342 |
jeremybenn |
For a pending breakpoint whose address is not yet known, this
|
2880 |
|
|
field will contain `'. Such breakpoint won't fire
|
2881 |
|
|
until a shared library that has the symbol or line referred
|
2882 |
|
|
by breakpoint is loaded. See below for details. A
|
2883 |
330 |
jeremybenn |
breakpoint with several locations will have `' in
|
2884 |
|
|
this field--see below for details.
|
2885 |
|
|
|
2886 |
|
|
_What_
|
2887 |
|
|
Where the breakpoint is in the source for your program, as a
|
2888 |
|
|
file and line number. For a pending breakpoint, the original
|
2889 |
|
|
string passed to the breakpoint command will be listed as it
|
2890 |
|
|
cannot be resolved until the appropriate shared library is
|
2891 |
|
|
loaded in the future.
|
2892 |
|
|
|
2893 |
|
|
If a breakpoint is conditional, `info break' shows the condition on
|
2894 |
|
|
the line following the affected breakpoint; breakpoint commands,
|
2895 |
|
|
if any, are listed after that. A pending breakpoint is allowed to
|
2896 |
|
|
have a condition specified for it. The condition is not parsed
|
2897 |
|
|
for validity until a shared library is loaded that allows the
|
2898 |
|
|
pending breakpoint to resolve to a valid location.
|
2899 |
|
|
|
2900 |
|
|
`info break' with a breakpoint number N as argument lists only
|
2901 |
|
|
that breakpoint. The convenience variable `$_' and the default
|
2902 |
|
|
examining-address for the `x' command are set to the address of
|
2903 |
|
|
the last breakpoint listed (*note Examining Memory: Memory.).
|
2904 |
|
|
|
2905 |
|
|
`info break' displays a count of the number of times the breakpoint
|
2906 |
|
|
has been hit. This is especially useful in conjunction with the
|
2907 |
|
|
`ignore' command. You can ignore a large number of breakpoint
|
2908 |
|
|
hits, look at the breakpoint info to see how many times the
|
2909 |
|
|
breakpoint was hit, and then run again, ignoring one less than
|
2910 |
|
|
that number. This will get you quickly to the last hit of that
|
2911 |
|
|
breakpoint.
|
2912 |
|
|
|
2913 |
|
|
GDB allows you to set any number of breakpoints at the same place in
|
2914 |
|
|
your program. There is nothing silly or meaningless about this. When
|
2915 |
|
|
the breakpoints are conditional, this is even useful (*note Break
|
2916 |
|
|
Conditions: Conditions.).
|
2917 |
|
|
|
2918 |
|
|
It is possible that a breakpoint corresponds to several locations in
|
2919 |
|
|
your program. Examples of this situation are:
|
2920 |
|
|
|
2921 |
|
|
* For a C++ constructor, the GCC compiler generates several
|
2922 |
|
|
instances of the function body, used in different cases.
|
2923 |
|
|
|
2924 |
|
|
* For a C++ template function, a given line in the function can
|
2925 |
|
|
correspond to any number of instantiations.
|
2926 |
|
|
|
2927 |
|
|
* For an inlined function, a given source line can correspond to
|
2928 |
|
|
several places where that function is inlined.
|
2929 |
|
|
|
2930 |
|
|
In all those cases, GDB will insert a breakpoint at all the relevant
|
2931 |
|
|
locations(1).
|
2932 |
|
|
|
2933 |
|
|
A breakpoint with multiple locations is displayed in the breakpoint
|
2934 |
|
|
table using several rows--one header row, followed by one row for each
|
2935 |
|
|
breakpoint location. The header row has `' in the address
|
2936 |
|
|
column. The rows for individual locations contain the actual addresses
|
2937 |
|
|
for locations, and show the functions to which those locations belong.
|
2938 |
|
|
The number column for a location is of the form
|
2939 |
|
|
BREAKPOINT-NUMBER.LOCATION-NUMBER.
|
2940 |
|
|
|
2941 |
|
|
For example:
|
2942 |
|
|
|
2943 |
|
|
Num Type Disp Enb Address What
|
2944 |
|
|
1 breakpoint keep y
|
2945 |
|
|
stop only if i==1
|
2946 |
|
|
breakpoint already hit 1 time
|
2947 |
|
|
1.1 y 0x080486a2 in void foo() at t.cc:8
|
2948 |
|
|
1.2 y 0x080486ca in void foo() at t.cc:8
|
2949 |
|
|
|
2950 |
|
|
Each location can be individually enabled or disabled by passing
|
2951 |
|
|
BREAKPOINT-NUMBER.LOCATION-NUMBER as argument to the `enable' and
|
2952 |
|
|
`disable' commands. Note that you cannot delete the individual
|
2953 |
|
|
locations from the list, you can only delete the entire list of
|
2954 |
|
|
locations that belong to their parent breakpoint (with the `delete NUM'
|
2955 |
|
|
command, where NUM is the number of the parent breakpoint, 1 in the
|
2956 |
|
|
above example). Disabling or enabling the parent breakpoint (*note
|
2957 |
|
|
Disabling::) affects all of the locations that belong to that
|
2958 |
|
|
breakpoint.
|
2959 |
|
|
|
2960 |
|
|
It's quite common to have a breakpoint inside a shared library.
|
2961 |
|
|
Shared libraries can be loaded and unloaded explicitly, and possibly
|
2962 |
|
|
repeatedly, as the program is executed. To support this use case, GDB
|
2963 |
|
|
updates breakpoint locations whenever any shared library is loaded or
|
2964 |
|
|
unloaded. Typically, you would set a breakpoint in a shared library at
|
2965 |
|
|
the beginning of your debugging session, when the library is not
|
2966 |
|
|
loaded, and when the symbols from the library are not available. When
|
2967 |
|
|
you try to set breakpoint, GDB will ask you if you want to set a so
|
2968 |
|
|
called "pending breakpoint"--breakpoint whose address is not yet
|
2969 |
|
|
resolved.
|
2970 |
|
|
|
2971 |
|
|
After the program is run, whenever a new shared library is loaded,
|
2972 |
|
|
GDB reevaluates all the breakpoints. When a newly loaded shared
|
2973 |
|
|
library contains the symbol or line referred to by some pending
|
2974 |
|
|
breakpoint, that breakpoint is resolved and becomes an ordinary
|
2975 |
|
|
breakpoint. When a library is unloaded, all breakpoints that refer to
|
2976 |
|
|
its symbols or source lines become pending again.
|
2977 |
|
|
|
2978 |
|
|
This logic works for breakpoints with multiple locations, too. For
|
2979 |
|
|
example, if you have a breakpoint in a C++ template function, and a
|
2980 |
|
|
newly loaded shared library has an instantiation of that template, a
|
2981 |
|
|
new location is added to the list of locations for the breakpoint.
|
2982 |
|
|
|
2983 |
|
|
Except for having unresolved address, pending breakpoints do not
|
2984 |
|
|
differ from regular breakpoints. You can set conditions or commands,
|
2985 |
|
|
enable and disable them and perform other breakpoint operations.
|
2986 |
|
|
|
2987 |
|
|
GDB provides some additional commands for controlling what happens
|
2988 |
|
|
when the `break' command cannot resolve breakpoint address
|
2989 |
|
|
specification to an address:
|
2990 |
|
|
|
2991 |
|
|
`set breakpoint pending auto'
|
2992 |
|
|
This is the default behavior. When GDB cannot find the breakpoint
|
2993 |
|
|
location, it queries you whether a pending breakpoint should be
|
2994 |
|
|
created.
|
2995 |
|
|
|
2996 |
|
|
`set breakpoint pending on'
|
2997 |
|
|
This indicates that an unrecognized breakpoint location should
|
2998 |
|
|
automatically result in a pending breakpoint being created.
|
2999 |
|
|
|
3000 |
|
|
`set breakpoint pending off'
|
3001 |
|
|
This indicates that pending breakpoints are not to be created. Any
|
3002 |
|
|
unrecognized breakpoint location results in an error. This
|
3003 |
|
|
setting does not affect any pending breakpoints previously created.
|
3004 |
|
|
|
3005 |
|
|
`show breakpoint pending'
|
3006 |
|
|
Show the current behavior setting for creating pending breakpoints.
|
3007 |
|
|
|
3008 |
|
|
The settings above only affect the `break' command and its variants.
|
3009 |
|
|
Once breakpoint is set, it will be automatically updated as shared
|
3010 |
|
|
libraries are loaded and unloaded.
|
3011 |
|
|
|
3012 |
|
|
For some targets, GDB can automatically decide if hardware or
|
3013 |
|
|
software breakpoints should be used, depending on whether the
|
3014 |
|
|
breakpoint address is read-only or read-write. This applies to
|
3015 |
|
|
breakpoints set with the `break' command as well as to internal
|
3016 |
|
|
breakpoints set by commands like `next' and `finish'. For breakpoints
|
3017 |
|
|
set with `hbreak', GDB will always use hardware breakpoints.
|
3018 |
|
|
|
3019 |
|
|
You can control this automatic behaviour with the following
|
3020 |
|
|
commands::
|
3021 |
|
|
|
3022 |
|
|
`set breakpoint auto-hw on'
|
3023 |
|
|
This is the default behavior. When GDB sets a breakpoint, it will
|
3024 |
|
|
try to use the target memory map to decide if software or hardware
|
3025 |
|
|
breakpoint must be used.
|
3026 |
|
|
|
3027 |
|
|
`set breakpoint auto-hw off'
|
3028 |
|
|
This indicates GDB should not automatically select breakpoint
|
3029 |
|
|
type. If the target provides a memory map, GDB will warn when
|
3030 |
|
|
trying to set software breakpoint at a read-only address.
|
3031 |
|
|
|
3032 |
|
|
GDB normally implements breakpoints by replacing the program code at
|
3033 |
|
|
the breakpoint address with a special instruction, which, when
|
3034 |
|
|
executed, given control to the debugger. By default, the program code
|
3035 |
|
|
is so modified only when the program is resumed. As soon as the
|
3036 |
|
|
program stops, GDB restores the original instructions. This behaviour
|
3037 |
|
|
guards against leaving breakpoints inserted in the target should gdb
|
3038 |
|
|
abrubptly disconnect. However, with slow remote targets, inserting and
|
3039 |
|
|
removing breakpoint can reduce the performance. This behavior can be
|
3040 |
|
|
controlled with the following commands::
|
3041 |
|
|
|
3042 |
|
|
`set breakpoint always-inserted off'
|
3043 |
|
|
All breakpoints, including newly added by the user, are inserted in
|
3044 |
|
|
the target only when the target is resumed. All breakpoints are
|
3045 |
|
|
removed from the target when it stops.
|
3046 |
|
|
|
3047 |
|
|
`set breakpoint always-inserted on'
|
3048 |
|
|
Causes all breakpoints to be inserted in the target at all times.
|
3049 |
|
|
If the user adds a new breakpoint, or changes an existing
|
3050 |
|
|
breakpoint, the breakpoints in the target are updated immediately.
|
3051 |
|
|
A breakpoint is removed from the target only when breakpoint
|
3052 |
|
|
itself is removed.
|
3053 |
|
|
|
3054 |
|
|
`set breakpoint always-inserted auto'
|
3055 |
|
|
This is the default mode. If GDB is controlling the inferior in
|
3056 |
|
|
non-stop mode (*note Non-Stop Mode::), gdb behaves as if
|
3057 |
|
|
`breakpoint always-inserted' mode is on. If GDB is controlling
|
3058 |
|
|
the inferior in all-stop mode, GDB behaves as if `breakpoint
|
3059 |
|
|
always-inserted' mode is off.
|
3060 |
|
|
|
3061 |
|
|
GDB itself sometimes sets breakpoints in your program for special
|
3062 |
|
|
purposes, such as proper handling of `longjmp' (in C programs). These
|
3063 |
|
|
internal breakpoints are assigned negative numbers, starting with `-1';
|
3064 |
|
|
`info breakpoints' does not display them. You can see these
|
3065 |
|
|
breakpoints with the GDB maintenance command `maint info breakpoints'
|
3066 |
|
|
(*note maint info breakpoints::).
|
3067 |
|
|
|
3068 |
|
|
---------- Footnotes ----------
|
3069 |
|
|
|
3070 |
|
|
(1) As of this writing, multiple-location breakpoints work only if
|
3071 |
|
|
there's line number information for all the locations. This means that
|
3072 |
|
|
they will generally not work in system libraries, unless you have debug
|
3073 |
|
|
info with line numbers for them.
|
3074 |
|
|
|
3075 |
|
|
|
3076 |
|
|
File: gdb.info, Node: Set Watchpoints, Next: Set Catchpoints, Prev: Set Breaks, Up: Breakpoints
|
3077 |
|
|
|
3078 |
|
|
5.1.2 Setting Watchpoints
|
3079 |
|
|
-------------------------
|
3080 |
|
|
|
3081 |
|
|
You can use a watchpoint to stop execution whenever the value of an
|
3082 |
|
|
expression changes, without having to predict a particular place where
|
3083 |
|
|
this may happen. (This is sometimes called a "data breakpoint".) The
|
3084 |
|
|
expression may be as simple as the value of a single variable, or as
|
3085 |
|
|
complex as many variables combined by operators. Examples include:
|
3086 |
|
|
|
3087 |
|
|
* A reference to the value of a single variable.
|
3088 |
|
|
|
3089 |
|
|
* An address cast to an appropriate data type. For example, `*(int
|
3090 |
|
|
*)0x12345678' will watch a 4-byte region at the specified address
|
3091 |
|
|
(assuming an `int' occupies 4 bytes).
|
3092 |
|
|
|
3093 |
|
|
* An arbitrarily complex expression, such as `a*b + c/d'. The
|
3094 |
|
|
expression can use any operators valid in the program's native
|
3095 |
|
|
language (*note Languages::).
|
3096 |
|
|
|
3097 |
|
|
You can set a watchpoint on an expression even if the expression can
|
3098 |
|
|
not be evaluated yet. For instance, you can set a watchpoint on
|
3099 |
|
|
`*global_ptr' before `global_ptr' is initialized. GDB will stop when
|
3100 |
|
|
your program sets `global_ptr' and the expression produces a valid
|
3101 |
|
|
value. If the expression becomes valid in some other way than changing
|
3102 |
|
|
a variable (e.g. if the memory pointed to by `*global_ptr' becomes
|
3103 |
|
|
readable as the result of a `malloc' call), GDB may not stop until the
|
3104 |
|
|
next time the expression changes.
|
3105 |
|
|
|
3106 |
|
|
Depending on your system, watchpoints may be implemented in software
|
3107 |
|
|
or hardware. GDB does software watchpointing by single-stepping your
|
3108 |
|
|
program and testing the variable's value each time, which is hundreds of
|
3109 |
|
|
times slower than normal execution. (But this may still be worth it, to
|
3110 |
|
|
catch errors where you have no clue what part of your program is the
|
3111 |
|
|
culprit.)
|
3112 |
|
|
|
3113 |
|
|
On some systems, such as HP-UX, PowerPC, GNU/Linux and most other
|
3114 |
|
|
x86-based targets, GDB includes support for hardware watchpoints, which
|
3115 |
|
|
do not slow down the running of your program.
|
3116 |
|
|
|
3117 |
|
|
`watch EXPR [thread THREADNUM]'
|
3118 |
|
|
Set a watchpoint for an expression. GDB will break when the
|
3119 |
|
|
expression EXPR is written into by the program and its value
|
3120 |
|
|
changes. The simplest (and the most popular) use of this command
|
3121 |
|
|
is to watch the value of a single variable:
|
3122 |
|
|
|
3123 |
|
|
(gdb) watch foo
|
3124 |
|
|
|
3125 |
|
|
If the command includes a `[thread THREADNUM]' clause, GDB breaks
|
3126 |
|
|
only when the thread identified by THREADNUM changes the value of
|
3127 |
|
|
EXPR. If any other threads change the value of EXPR, GDB will not
|
3128 |
|
|
break. Note that watchpoints restricted to a single thread in
|
3129 |
|
|
this way only work with Hardware Watchpoints.
|
3130 |
|
|
|
3131 |
|
|
`rwatch EXPR [thread THREADNUM]'
|
3132 |
|
|
Set a watchpoint that will break when the value of EXPR is read by
|
3133 |
|
|
the program.
|
3134 |
|
|
|
3135 |
|
|
`awatch EXPR [thread THREADNUM]'
|
3136 |
|
|
Set a watchpoint that will break when EXPR is either read from or
|
3137 |
|
|
written into by the program.
|
3138 |
|
|
|
3139 |
|
|
`info watchpoints'
|
3140 |
|
|
This command prints a list of watchpoints, using the same format as
|
3141 |
|
|
`info break' (*note Set Breaks::).
|
3142 |
|
|
|
3143 |
|
|
If you watch for a change in a numerically entered address you need
|
3144 |
|
|
to dereference it, as the address itself is just a constant number
|
3145 |
|
|
which will never change. GDB refuses to create a watchpoint that
|
3146 |
|
|
watches a never-changing value:
|
3147 |
|
|
|
3148 |
|
|
(gdb) watch 0x600850
|
3149 |
|
|
Cannot watch constant value 0x600850.
|
3150 |
|
|
(gdb) watch *(int *) 0x600850
|
3151 |
|
|
Watchpoint 1: *(int *) 6293584
|
3152 |
|
|
|
3153 |
|
|
GDB sets a "hardware watchpoint" if possible. Hardware watchpoints
|
3154 |
|
|
execute very quickly, and the debugger reports a change in value at the
|
3155 |
|
|
exact instruction where the change occurs. If GDB cannot set a
|
3156 |
|
|
hardware watchpoint, it sets a software watchpoint, which executes more
|
3157 |
|
|
slowly and reports the change in value at the next _statement_, not the
|
3158 |
|
|
instruction, after the change occurs.
|
3159 |
|
|
|
3160 |
|
|
You can force GDB to use only software watchpoints with the `set
|
3161 |
|
|
can-use-hw-watchpoints 0' command. With this variable set to zero, GDB
|
3162 |
|
|
will never try to use hardware watchpoints, even if the underlying
|
3163 |
|
|
system supports them. (Note that hardware-assisted watchpoints that
|
3164 |
|
|
were set _before_ setting `can-use-hw-watchpoints' to zero will still
|
3165 |
|
|
use the hardware mechanism of watching expression values.)
|
3166 |
|
|
|
3167 |
|
|
`set can-use-hw-watchpoints'
|
3168 |
|
|
Set whether or not to use hardware watchpoints.
|
3169 |
|
|
|
3170 |
|
|
`show can-use-hw-watchpoints'
|
3171 |
|
|
Show the current mode of using hardware watchpoints.
|
3172 |
|
|
|
3173 |
|
|
For remote targets, you can restrict the number of hardware
|
3174 |
342 |
jeremybenn |
watchpoints GDB will use, see *note set remote
|
3175 |
330 |
jeremybenn |
hardware-breakpoint-limit::.
|
3176 |
|
|
|
3177 |
|
|
When you issue the `watch' command, GDB reports
|
3178 |
|
|
|
3179 |
|
|
Hardware watchpoint NUM: EXPR
|
3180 |
|
|
|
3181 |
|
|
if it was able to set a hardware watchpoint.
|
3182 |
|
|
|
3183 |
|
|
Currently, the `awatch' and `rwatch' commands can only set hardware
|
3184 |
|
|
watchpoints, because accesses to data that don't change the value of
|
3185 |
|
|
the watched expression cannot be detected without examining every
|
3186 |
|
|
instruction as it is being executed, and GDB does not do that
|
3187 |
|
|
currently. If GDB finds that it is unable to set a hardware breakpoint
|
3188 |
|
|
with the `awatch' or `rwatch' command, it will print a message like
|
3189 |
|
|
this:
|
3190 |
|
|
|
3191 |
|
|
Expression cannot be implemented with read/access watchpoint.
|
3192 |
|
|
|
3193 |
|
|
Sometimes, GDB cannot set a hardware watchpoint because the data
|
3194 |
|
|
type of the watched expression is wider than what a hardware watchpoint
|
3195 |
|
|
on the target machine can handle. For example, some systems can only
|
3196 |
|
|
watch regions that are up to 4 bytes wide; on such systems you cannot
|
3197 |
|
|
set hardware watchpoints for an expression that yields a
|
3198 |
|
|
double-precision floating-point number (which is typically 8 bytes
|
3199 |
|
|
wide). As a work-around, it might be possible to break the large region
|
3200 |
|
|
into a series of smaller ones and watch them with separate watchpoints.
|
3201 |
|
|
|
3202 |
|
|
If you set too many hardware watchpoints, GDB might be unable to
|
3203 |
|
|
insert all of them when you resume the execution of your program.
|
3204 |
|
|
Since the precise number of active watchpoints is unknown until such
|
3205 |
|
|
time as the program is about to be resumed, GDB might not be able to
|
3206 |
|
|
warn you about this when you set the watchpoints, and the warning will
|
3207 |
|
|
be printed only when the program is resumed:
|
3208 |
|
|
|
3209 |
|
|
Hardware watchpoint NUM: Could not insert watchpoint
|
3210 |
|
|
|
3211 |
|
|
If this happens, delete or disable some of the watchpoints.
|
3212 |
|
|
|
3213 |
|
|
Watching complex expressions that reference many variables can also
|
3214 |
|
|
exhaust the resources available for hardware-assisted watchpoints.
|
3215 |
|
|
That's because GDB needs to watch every variable in the expression with
|
3216 |
|
|
separately allocated resources.
|
3217 |
|
|
|
3218 |
|
|
If you call a function interactively using `print' or `call', any
|
3219 |
|
|
watchpoints you have set will be inactive until GDB reaches another
|
3220 |
|
|
kind of breakpoint or the call completes.
|
3221 |
|
|
|
3222 |
|
|
GDB automatically deletes watchpoints that watch local (automatic)
|
3223 |
|
|
variables, or expressions that involve such variables, when they go out
|
3224 |
|
|
of scope, that is, when the execution leaves the block in which these
|
3225 |
|
|
variables were defined. In particular, when the program being debugged
|
3226 |
|
|
terminates, _all_ local variables go out of scope, and so only
|
3227 |
|
|
watchpoints that watch global variables remain set. If you rerun the
|
3228 |
|
|
program, you will need to set all such watchpoints again. One way of
|
3229 |
|
|
doing that would be to set a code breakpoint at the entry to the `main'
|
3230 |
|
|
function and when it breaks, set all the watchpoints.
|
3231 |
|
|
|
3232 |
|
|
In multi-threaded programs, watchpoints will detect changes to the
|
3233 |
|
|
watched expression from every thread.
|
3234 |
|
|
|
3235 |
|
|
_Warning:_ In multi-threaded programs, software watchpoints have
|
3236 |
|
|
only limited usefulness. If GDB creates a software watchpoint, it
|
3237 |
|
|
can only watch the value of an expression _in a single thread_.
|
3238 |
|
|
If you are confident that the expression can only change due to
|
3239 |
|
|
the current thread's activity (and if you are also confident that
|
3240 |
|
|
no other thread can become current), then you can use software
|
3241 |
|
|
watchpoints as usual. However, GDB may not notice when a
|
3242 |
|
|
non-current thread's activity changes the expression. (Hardware
|
3243 |
|
|
watchpoints, in contrast, watch an expression in all threads.)
|
3244 |
|
|
|
3245 |
|
|
*Note set remote hardware-watchpoint-limit::.
|
3246 |
|
|
|
3247 |
|
|
|
3248 |
|
|
File: gdb.info, Node: Set Catchpoints, Next: Delete Breaks, Prev: Set Watchpoints, Up: Breakpoints
|
3249 |
|
|
|
3250 |
|
|
5.1.3 Setting Catchpoints
|
3251 |
|
|
-------------------------
|
3252 |
|
|
|
3253 |
|
|
You can use "catchpoints" to cause the debugger to stop for certain
|
3254 |
|
|
kinds of program events, such as C++ exceptions or the loading of a
|
3255 |
|
|
shared library. Use the `catch' command to set a catchpoint.
|
3256 |
|
|
|
3257 |
|
|
`catch EVENT'
|
3258 |
|
|
Stop when EVENT occurs. EVENT can be any of the following:
|
3259 |
|
|
`throw'
|
3260 |
|
|
The throwing of a C++ exception.
|
3261 |
|
|
|
3262 |
|
|
`catch'
|
3263 |
|
|
The catching of a C++ exception.
|
3264 |
|
|
|
3265 |
|
|
`exception'
|
3266 |
|
|
An Ada exception being raised. If an exception name is
|
3267 |
|
|
specified at the end of the command (eg `catch exception
|
3268 |
|
|
Program_Error'), the debugger will stop only when this
|
3269 |
|
|
specific exception is raised. Otherwise, the debugger stops
|
3270 |
|
|
execution when any Ada exception is raised.
|
3271 |
|
|
|
3272 |
|
|
When inserting an exception catchpoint on a user-defined
|
3273 |
|
|
exception whose name is identical to one of the exceptions
|
3274 |
|
|
defined by the language, the fully qualified name must be
|
3275 |
|
|
used as the exception name. Otherwise, GDB will assume that
|
3276 |
|
|
it should stop on the pre-defined exception rather than the
|
3277 |
|
|
user-defined one. For instance, assuming an exception called
|
3278 |
|
|
`Constraint_Error' is defined in package `Pck', then the
|
3279 |
|
|
command to use to catch such exceptions is `catch exception
|
3280 |
|
|
Pck.Constraint_Error'.
|
3281 |
|
|
|
3282 |
|
|
`exception unhandled'
|
3283 |
|
|
An exception that was raised but is not handled by the
|
3284 |
|
|
program.
|
3285 |
|
|
|
3286 |
|
|
`assert'
|
3287 |
|
|
A failed Ada assertion.
|
3288 |
|
|
|
3289 |
|
|
`exec'
|
3290 |
|
|
A call to `exec'. This is currently only available for HP-UX
|
3291 |
|
|
and GNU/Linux.
|
3292 |
|
|
|
3293 |
|
|
`syscall'
|
3294 |
|
|
`syscall [NAME | NUMBER] ...'
|
3295 |
|
|
A call to or return from a system call, a.k.a. "syscall". A
|
3296 |
|
|
syscall is a mechanism for application programs to request a
|
3297 |
|
|
service from the operating system (OS) or one of the OS
|
3298 |
|
|
system services. GDB can catch some or all of the syscalls
|
3299 |
|
|
issued by the debuggee, and show the related information for
|
3300 |
|
|
each syscall. If no argument is specified, calls to and
|
3301 |
|
|
returns from all system calls will be caught.
|
3302 |
|
|
|
3303 |
|
|
NAME can be any system call name that is valid for the
|
3304 |
|
|
underlying OS. Just what syscalls are valid depends on the
|
3305 |
|
|
OS. On GNU and Unix systems, you can find the full list of
|
3306 |
|
|
valid syscall names on `/usr/include/asm/unistd.h'.
|
3307 |
|
|
|
3308 |
|
|
Normally, GDB knows in advance which syscalls are valid for
|
3309 |
|
|
each OS, so you can use the GDB command-line completion
|
3310 |
|
|
facilities (*note command completion: Completion.) to list the
|
3311 |
|
|
available choices.
|
3312 |
|
|
|
3313 |
|
|
You may also specify the system call numerically. A syscall's
|
3314 |
|
|
number is the value passed to the OS's syscall dispatcher to
|
3315 |
|
|
identify the requested service. When you specify the syscall
|
3316 |
|
|
by its name, GDB uses its database of syscalls to convert the
|
3317 |
|
|
name into the corresponding numeric code, but using the
|
3318 |
|
|
number directly may be useful if GDB's database does not have
|
3319 |
|
|
the complete list of syscalls on your system (e.g., because
|
3320 |
|
|
GDB lags behind the OS upgrades).
|
3321 |
|
|
|
3322 |
|
|
The example below illustrates how this command works if you
|
3323 |
|
|
don't provide arguments to it:
|
3324 |
|
|
|
3325 |
|
|
(gdb) catch syscall
|
3326 |
|
|
Catchpoint 1 (syscall)
|
3327 |
|
|
(gdb) r
|
3328 |
|
|
Starting program: /tmp/catch-syscall
|
3329 |
|
|
|
3330 |
|
|
Catchpoint 1 (call to syscall 'close'), \
|
3331 |
|
|
0xffffe424 in __kernel_vsyscall ()
|
3332 |
|
|
(gdb) c
|
3333 |
|
|
Continuing.
|
3334 |
|
|
|
3335 |
|
|
Catchpoint 1 (returned from syscall 'close'), \
|
3336 |
|
|
0xffffe424 in __kernel_vsyscall ()
|
3337 |
|
|
(gdb)
|
3338 |
|
|
|
3339 |
|
|
Here is an example of catching a system call by name:
|
3340 |
|
|
|
3341 |
|
|
(gdb) catch syscall chroot
|
3342 |
|
|
Catchpoint 1 (syscall 'chroot' [61])
|
3343 |
|
|
(gdb) r
|
3344 |
|
|
Starting program: /tmp/catch-syscall
|
3345 |
|
|
|
3346 |
|
|
Catchpoint 1 (call to syscall 'chroot'), \
|
3347 |
|
|
0xffffe424 in __kernel_vsyscall ()
|
3348 |
|
|
(gdb) c
|
3349 |
|
|
Continuing.
|
3350 |
|
|
|
3351 |
|
|
Catchpoint 1 (returned from syscall 'chroot'), \
|
3352 |
|
|
0xffffe424 in __kernel_vsyscall ()
|
3353 |
|
|
(gdb)
|
3354 |
|
|
|
3355 |
|
|
An example of specifying a system call numerically. In the
|
3356 |
|
|
case below, the syscall number has a corresponding entry in
|
3357 |
|
|
the XML file, so GDB finds its name and prints it:
|
3358 |
|
|
|
3359 |
|
|
(gdb) catch syscall 252
|
3360 |
|
|
Catchpoint 1 (syscall(s) 'exit_group')
|
3361 |
|
|
(gdb) r
|
3362 |
|
|
Starting program: /tmp/catch-syscall
|
3363 |
|
|
|
3364 |
|
|
Catchpoint 1 (call to syscall 'exit_group'), \
|
3365 |
|
|
0xffffe424 in __kernel_vsyscall ()
|
3366 |
|
|
(gdb) c
|
3367 |
|
|
Continuing.
|
3368 |
|
|
|
3369 |
|
|
Program exited normally.
|
3370 |
|
|
(gdb)
|
3371 |
|
|
|
3372 |
|
|
However, there can be situations when there is no
|
3373 |
|
|
corresponding name in XML file for that syscall number. In
|
3374 |
|
|
this case, GDB prints a warning message saying that it was
|
3375 |
|
|
not able to find the syscall name, but the catchpoint will be
|
3376 |
|
|
set anyway. See the example below:
|
3377 |
|
|
|
3378 |
|
|
(gdb) catch syscall 764
|
3379 |
|
|
warning: The number '764' does not represent a known syscall.
|
3380 |
|
|
Catchpoint 2 (syscall 764)
|
3381 |
|
|
(gdb)
|
3382 |
|
|
|
3383 |
|
|
If you configure GDB using the `--without-expat' option, it
|
3384 |
|
|
will not be able to display syscall names. Also, if your
|
3385 |
|
|
architecture does not have an XML file describing its system
|
3386 |
|
|
calls, you will not be able to see the syscall names. It is
|
3387 |
|
|
important to notice that these two features are used for
|
3388 |
|
|
accessing the syscall name database. In either case, you
|
3389 |
|
|
will see a warning like this:
|
3390 |
|
|
|
3391 |
|
|
(gdb) catch syscall
|
3392 |
|
|
warning: Could not open "syscalls/i386-linux.xml"
|
3393 |
|
|
warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
|
3394 |
|
|
GDB will not be able to display syscall names.
|
3395 |
|
|
Catchpoint 1 (syscall)
|
3396 |
|
|
(gdb)
|
3397 |
|
|
|
3398 |
|
|
Of course, the file name will change depending on your
|
3399 |
|
|
architecture and system.
|
3400 |
|
|
|
3401 |
|
|
Still using the example above, you can also try to catch a
|
3402 |
|
|
syscall by its number. In this case, you would see something
|
3403 |
|
|
like:
|
3404 |
|
|
|
3405 |
|
|
(gdb) catch syscall 252
|
3406 |
|
|
Catchpoint 1 (syscall(s) 252)
|
3407 |
|
|
|
3408 |
|
|
Again, in this case GDB would not be able to display
|
3409 |
|
|
syscall's names.
|
3410 |
|
|
|
3411 |
|
|
`fork'
|
3412 |
|
|
A call to `fork'. This is currently only available for HP-UX
|
3413 |
|
|
and GNU/Linux.
|
3414 |
|
|
|
3415 |
|
|
`vfork'
|
3416 |
|
|
A call to `vfork'. This is currently only available for HP-UX
|
3417 |
|
|
and GNU/Linux.
|
3418 |
|
|
|
3419 |
|
|
|
3420 |
|
|
`tcatch EVENT'
|
3421 |
|
|
Set a catchpoint that is enabled only for one stop. The
|
3422 |
|
|
catchpoint is automatically deleted after the first time the event
|
3423 |
|
|
is caught.
|
3424 |
|
|
|
3425 |
|
|
|
3426 |
|
|
Use the `info break' command to list the current catchpoints.
|
3427 |
|
|
|
3428 |
|
|
There are currently some limitations to C++ exception handling
|
3429 |
|
|
(`catch throw' and `catch catch') in GDB:
|
3430 |
|
|
|
3431 |
|
|
* If you call a function interactively, GDB normally returns control
|
3432 |
|
|
to you when the function has finished executing. If the call
|
3433 |
|
|
raises an exception, however, the call may bypass the mechanism
|
3434 |
|
|
that returns control to you and cause your program either to abort
|
3435 |
|
|
or to simply continue running until it hits a breakpoint, catches
|
3436 |
|
|
a signal that GDB is listening for, or exits. This is the case
|
3437 |
|
|
even if you set a catchpoint for the exception; catchpoints on
|
3438 |
|
|
exceptions are disabled within interactive calls.
|
3439 |
|
|
|
3440 |
|
|
* You cannot raise an exception interactively.
|
3441 |
|
|
|
3442 |
|
|
* You cannot install an exception handler interactively.
|
3443 |
|
|
|
3444 |
|
|
Sometimes `catch' is not the best way to debug exception handling:
|
3445 |
|
|
if you need to know exactly where an exception is raised, it is better
|
3446 |
|
|
to stop _before_ the exception handler is called, since that way you
|
3447 |
|
|
can see the stack before any unwinding takes place. If you set a
|
3448 |
|
|
breakpoint in an exception handler instead, it may not be easy to find
|
3449 |
|
|
out where the exception was raised.
|
3450 |
|
|
|
3451 |
|
|
To stop just before an exception handler is called, you need some
|
3452 |
|
|
knowledge of the implementation. In the case of GNU C++, exceptions are
|
3453 |
|
|
raised by calling a library function named `__raise_exception' which
|
3454 |
|
|
has the following ANSI C interface:
|
3455 |
|
|
|
3456 |
|
|
/* ADDR is where the exception identifier is stored.
|
3457 |
|
|
ID is the exception identifier. */
|
3458 |
|
|
void __raise_exception (void **addr, void *id);
|
3459 |
|
|
|
3460 |
|
|
To make the debugger catch all exceptions before any stack unwinding
|
3461 |
|
|
takes place, set a breakpoint on `__raise_exception' (*note
|
3462 |
|
|
Breakpoints; Watchpoints; and Exceptions: Breakpoints.).
|
3463 |
|
|
|
3464 |
|
|
With a conditional breakpoint (*note Break Conditions: Conditions.)
|
3465 |
|
|
that depends on the value of ID, you can stop your program when a
|
3466 |
|
|
specific exception is raised. You can use multiple conditional
|
3467 |
|
|
breakpoints to stop your program when any of a number of exceptions are
|
3468 |
|
|
raised.
|
3469 |
|
|
|
3470 |
|
|
|
3471 |
|
|
File: gdb.info, Node: Delete Breaks, Next: Disabling, Prev: Set Catchpoints, Up: Breakpoints
|
3472 |
|
|
|
3473 |
|
|
5.1.4 Deleting Breakpoints
|
3474 |
|
|
--------------------------
|
3475 |
|
|
|
3476 |
|
|
It is often necessary to eliminate a breakpoint, watchpoint, or
|
3477 |
|
|
catchpoint once it has done its job and you no longer want your program
|
3478 |
|
|
to stop there. This is called "deleting" the breakpoint. A breakpoint
|
3479 |
|
|
that has been deleted no longer exists; it is forgotten.
|
3480 |
|
|
|
3481 |
|
|
With the `clear' command you can delete breakpoints according to
|
3482 |
|
|
where they are in your program. With the `delete' command you can
|
3483 |
|
|
delete individual breakpoints, watchpoints, or catchpoints by specifying
|
3484 |
|
|
their breakpoint numbers.
|
3485 |
|
|
|
3486 |
|
|
It is not necessary to delete a breakpoint to proceed past it. GDB
|
3487 |
|
|
automatically ignores breakpoints on the first instruction to be
|
3488 |
|
|
executed when you continue execution without changing the execution
|
3489 |
|
|
address.
|
3490 |
|
|
|
3491 |
|
|
`clear'
|
3492 |
|
|
Delete any breakpoints at the next instruction to be executed in
|
3493 |
|
|
the selected stack frame (*note Selecting a Frame: Selection.).
|
3494 |
|
|
When the innermost frame is selected, this is a good way to delete
|
3495 |
|
|
a breakpoint where your program just stopped.
|
3496 |
|
|
|
3497 |
|
|
`clear LOCATION'
|
3498 |
|
|
Delete any breakpoints set at the specified LOCATION. *Note
|
3499 |
|
|
Specify Location::, for the various forms of LOCATION; the most
|
3500 |
|
|
useful ones are listed below:
|
3501 |
|
|
|
3502 |
|
|
`clear FUNCTION'
|
3503 |
|
|
`clear FILENAME:FUNCTION'
|
3504 |
|
|
Delete any breakpoints set at entry to the named FUNCTION.
|
3505 |
|
|
|
3506 |
|
|
`clear LINENUM'
|
3507 |
|
|
`clear FILENAME:LINENUM'
|
3508 |
|
|
Delete any breakpoints set at or within the code of the
|
3509 |
|
|
specified LINENUM of the specified FILENAME.
|
3510 |
|
|
|
3511 |
|
|
`delete [breakpoints] [RANGE...]'
|
3512 |
|
|
Delete the breakpoints, watchpoints, or catchpoints of the
|
3513 |
|
|
breakpoint ranges specified as arguments. If no argument is
|
3514 |
|
|
specified, delete all breakpoints (GDB asks confirmation, unless
|
3515 |
|
|
you have `set confirm off'). You can abbreviate this command as
|
3516 |
|
|
`d'.
|
3517 |
|
|
|
3518 |
|
|
|
3519 |
|
|
File: gdb.info, Node: Disabling, Next: Conditions, Prev: Delete Breaks, Up: Breakpoints
|
3520 |
|
|
|
3521 |
|
|
5.1.5 Disabling Breakpoints
|
3522 |
|
|
---------------------------
|
3523 |
|
|
|
3524 |
|
|
Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
|
3525 |
|
|
prefer to "disable" it. This makes the breakpoint inoperative as if it
|
3526 |
|
|
had been deleted, but remembers the information on the breakpoint so
|
3527 |
|
|
that you can "enable" it again later.
|
3528 |
|
|
|
3529 |
|
|
You disable and enable breakpoints, watchpoints, and catchpoints with
|
3530 |
|
|
the `enable' and `disable' commands, optionally specifying one or more
|
3531 |
|
|
breakpoint numbers as arguments. Use `info break' to print a list of
|
3532 |
|
|
all breakpoints, watchpoints, and catchpoints if you do not know which
|
3533 |
|
|
numbers to use.
|
3534 |
|
|
|
3535 |
|
|
Disabling and enabling a breakpoint that has multiple locations
|
3536 |
|
|
affects all of its locations.
|
3537 |
|
|
|
3538 |
|
|
A breakpoint, watchpoint, or catchpoint can have any of four
|
3539 |
|
|
different states of enablement:
|
3540 |
|
|
|
3541 |
|
|
* Enabled. The breakpoint stops your program. A breakpoint set
|
3542 |
|
|
with the `break' command starts out in this state.
|
3543 |
|
|
|
3544 |
|
|
* Disabled. The breakpoint has no effect on your program.
|
3545 |
|
|
|
3546 |
|
|
* Enabled once. The breakpoint stops your program, but then becomes
|
3547 |
|
|
disabled.
|
3548 |
|
|
|
3549 |
|
|
* Enabled for deletion. The breakpoint stops your program, but
|
3550 |
|
|
immediately after it does so it is deleted permanently. A
|
3551 |
|
|
breakpoint set with the `tbreak' command starts out in this state.
|
3552 |
|
|
|
3553 |
|
|
You can use the following commands to enable or disable breakpoints,
|
3554 |
|
|
watchpoints, and catchpoints:
|
3555 |
|
|
|
3556 |
|
|
`disable [breakpoints] [RANGE...]'
|
3557 |
|
|
Disable the specified breakpoints--or all breakpoints, if none are
|
3558 |
|
|
listed. A disabled breakpoint has no effect but is not forgotten.
|
3559 |
|
|
All options such as ignore-counts, conditions and commands are
|
3560 |
|
|
remembered in case the breakpoint is enabled again later. You may
|
3561 |
|
|
abbreviate `disable' as `dis'.
|
3562 |
|
|
|
3563 |
|
|
`enable [breakpoints] [RANGE...]'
|
3564 |
|
|
Enable the specified breakpoints (or all defined breakpoints).
|
3565 |
|
|
They become effective once again in stopping your program.
|
3566 |
|
|
|
3567 |
|
|
`enable [breakpoints] once RANGE...'
|
3568 |
|
|
Enable the specified breakpoints temporarily. GDB disables any of
|
3569 |
|
|
these breakpoints immediately after stopping your program.
|
3570 |
|
|
|
3571 |
|
|
`enable [breakpoints] delete RANGE...'
|
3572 |
|
|
Enable the specified breakpoints to work once, then die. GDB
|
3573 |
|
|
deletes any of these breakpoints as soon as your program stops
|
3574 |
|
|
there. Breakpoints set by the `tbreak' command start out in this
|
3575 |
|
|
state.
|
3576 |
|
|
|
3577 |
|
|
Except for a breakpoint set with `tbreak' (*note Setting
|
3578 |
|
|
Breakpoints: Set Breaks.), breakpoints that you set are initially
|
3579 |
|
|
enabled; subsequently, they become disabled or enabled only when you
|
3580 |
|
|
use one of the commands above. (The command `until' can set and delete
|
3581 |
|
|
a breakpoint of its own, but it does not change the state of your other
|
3582 |
342 |
jeremybenn |
breakpoints; see *note Continuing and Stepping: Continuing and
|
3583 |
330 |
jeremybenn |
Stepping.)
|
3584 |
|
|
|
3585 |
|
|
|
3586 |
|
|
File: gdb.info, Node: Conditions, Next: Break Commands, Prev: Disabling, Up: Breakpoints
|
3587 |
|
|
|
3588 |
|
|
5.1.6 Break Conditions
|
3589 |
|
|
----------------------
|
3590 |
|
|
|
3591 |
|
|
The simplest sort of breakpoint breaks every time your program reaches a
|
3592 |
|
|
specified place. You can also specify a "condition" for a breakpoint.
|
3593 |
|
|
A condition is just a Boolean expression in your programming language
|
3594 |
|
|
(*note Expressions: Expressions.). A breakpoint with a condition
|
3595 |
|
|
evaluates the expression each time your program reaches it, and your
|
3596 |
|
|
program stops only if the condition is _true_.
|
3597 |
|
|
|
3598 |
|
|
This is the converse of using assertions for program validation; in
|
3599 |
|
|
that situation, you want to stop when the assertion is violated--that
|
3600 |
|
|
is, when the condition is false. In C, if you want to test an
|
3601 |
|
|
assertion expressed by the condition ASSERT, you should set the
|
3602 |
|
|
condition `! ASSERT' on the appropriate breakpoint.
|
3603 |
|
|
|
3604 |
|
|
Conditions are also accepted for watchpoints; you may not need them,
|
3605 |
|
|
since a watchpoint is inspecting the value of an expression anyhow--but
|
3606 |
|
|
it might be simpler, say, to just set a watchpoint on a variable name,
|
3607 |
|
|
and specify a condition that tests whether the new value is an
|
3608 |
|
|
interesting one.
|
3609 |
|
|
|
3610 |
|
|
Break conditions can have side effects, and may even call functions
|
3611 |
|
|
in your program. This can be useful, for example, to activate functions
|
3612 |
|
|
that log program progress, or to use your own print functions to format
|
3613 |
|
|
special data structures. The effects are completely predictable unless
|
3614 |
|
|
there is another enabled breakpoint at the same address. (In that
|
3615 |
|
|
case, GDB might see the other breakpoint first and stop your program
|
3616 |
|
|
without checking the condition of this one.) Note that breakpoint
|
3617 |
|
|
commands are usually more convenient and flexible than break conditions
|
3618 |
|
|
for the purpose of performing side effects when a breakpoint is reached
|
3619 |
|
|
(*note Breakpoint Command Lists: Break Commands.).
|
3620 |
|
|
|
3621 |
|
|
Break conditions can be specified when a breakpoint is set, by using
|
3622 |
|
|
`if' in the arguments to the `break' command. *Note Setting
|
3623 |
|
|
Breakpoints: Set Breaks. They can also be changed at any time with the
|
3624 |
|
|
`condition' command.
|
3625 |
|
|
|
3626 |
|
|
You can also use the `if' keyword with the `watch' command. The
|
3627 |
|
|
`catch' command does not recognize the `if' keyword; `condition' is the
|
3628 |
|
|
only way to impose a further condition on a catchpoint.
|
3629 |
|
|
|
3630 |
|
|
`condition BNUM EXPRESSION'
|
3631 |
|
|
Specify EXPRESSION as the break condition for breakpoint,
|
3632 |
|
|
watchpoint, or catchpoint number BNUM. After you set a condition,
|
3633 |
|
|
breakpoint BNUM stops your program only if the value of EXPRESSION
|
3634 |
|
|
is true (nonzero, in C). When you use `condition', GDB checks
|
3635 |
|
|
EXPRESSION immediately for syntactic correctness, and to determine
|
3636 |
|
|
whether symbols in it have referents in the context of your
|
3637 |
|
|
breakpoint. If EXPRESSION uses symbols not referenced in the
|
3638 |
|
|
context of the breakpoint, GDB prints an error message:
|
3639 |
|
|
|
3640 |
|
|
No symbol "foo" in current context.
|
3641 |
|
|
|
3642 |
|
|
GDB does not actually evaluate EXPRESSION at the time the
|
3643 |
|
|
`condition' command (or a command that sets a breakpoint with a
|
3644 |
|
|
condition, like `break if ...') is given, however. *Note
|
3645 |
|
|
Expressions: Expressions.
|
3646 |
|
|
|
3647 |
|
|
`condition BNUM'
|
3648 |
|
|
Remove the condition from breakpoint number BNUM. It becomes an
|
3649 |
|
|
ordinary unconditional breakpoint.
|
3650 |
|
|
|
3651 |
|
|
A special case of a breakpoint condition is to stop only when the
|
3652 |
|
|
breakpoint has been reached a certain number of times. This is so
|
3653 |
|
|
useful that there is a special way to do it, using the "ignore count"
|
3654 |
|
|
of the breakpoint. Every breakpoint has an ignore count, which is an
|
3655 |
|
|
integer. Most of the time, the ignore count is zero, and therefore has
|
3656 |
|
|
no effect. But if your program reaches a breakpoint whose ignore count
|
3657 |
|
|
is positive, then instead of stopping, it just decrements the ignore
|
3658 |
|
|
count by one and continues. As a result, if the ignore count value is
|
3659 |
|
|
N, the breakpoint does not stop the next N times your program reaches
|
3660 |
|
|
it.
|
3661 |
|
|
|
3662 |
|
|
`ignore BNUM COUNT'
|
3663 |
|
|
Set the ignore count of breakpoint number BNUM to COUNT. The next
|
3664 |
|
|
COUNT times the breakpoint is reached, your program's execution
|
3665 |
|
|
does not stop; other than to decrement the ignore count, GDB takes
|
3666 |
|
|
no action.
|
3667 |
|
|
|
3668 |
|
|
To make the breakpoint stop the next time it is reached, specify a
|
3669 |
|
|
count of zero.
|
3670 |
|
|
|
3671 |
|
|
When you use `continue' to resume execution of your program from a
|
3672 |
|
|
breakpoint, you can specify an ignore count directly as an
|
3673 |
|
|
argument to `continue', rather than using `ignore'. *Note
|
3674 |
|
|
Continuing and Stepping: Continuing and Stepping.
|
3675 |
|
|
|
3676 |
|
|
If a breakpoint has a positive ignore count and a condition, the
|
3677 |
|
|
condition is not checked. Once the ignore count reaches zero, GDB
|
3678 |
|
|
resumes checking the condition.
|
3679 |
|
|
|
3680 |
|
|
You could achieve the effect of the ignore count with a condition
|
3681 |
|
|
such as `$foo-- <= 0' using a debugger convenience variable that
|
3682 |
|
|
is decremented each time. *Note Convenience Variables:
|
3683 |
|
|
Convenience Vars.
|
3684 |
|
|
|
3685 |
|
|
Ignore counts apply to breakpoints, watchpoints, and catchpoints.
|
3686 |
|
|
|
3687 |
|
|
|
3688 |
|
|
File: gdb.info, Node: Break Commands, Next: Save Breakpoints, Prev: Conditions, Up: Breakpoints
|
3689 |
|
|
|
3690 |
|
|
5.1.7 Breakpoint Command Lists
|
3691 |
|
|
------------------------------
|
3692 |
|
|
|
3693 |
|
|
You can give any breakpoint (or watchpoint or catchpoint) a series of
|
3694 |
|
|
commands to execute when your program stops due to that breakpoint. For
|
3695 |
|
|
example, you might want to print the values of certain expressions, or
|
3696 |
|
|
enable other breakpoints.
|
3697 |
|
|
|
3698 |
|
|
`commands [RANGE...]'
|
3699 |
|
|
`... COMMAND-LIST ...'
|
3700 |
|
|
`end'
|
3701 |
|
|
Specify a list of commands for the given breakpoints. The commands
|
3702 |
|
|
themselves appear on the following lines. Type a line containing
|
3703 |
|
|
just `end' to terminate the commands.
|
3704 |
|
|
|
3705 |
|
|
To remove all commands from a breakpoint, type `commands' and
|
3706 |
|
|
follow it immediately with `end'; that is, give no commands.
|
3707 |
|
|
|
3708 |
|
|
With no argument, `commands' refers to the last breakpoint,
|
3709 |
|
|
watchpoint, or catchpoint set (not to the breakpoint most recently
|
3710 |
|
|
encountered). If the most recent breakpoints were set with a
|
3711 |
|
|
single command, then the `commands' will apply to all the
|
3712 |
|
|
breakpoints set by that command. This applies to breakpoints set
|
3713 |
|
|
by `rbreak', and also applies when a single `break' command
|
3714 |
|
|
creates multiple breakpoints (*note Ambiguous Expressions:
|
3715 |
|
|
Ambiguous Expressions.).
|
3716 |
|
|
|
3717 |
|
|
Pressing as a means of repeating the last GDB command is
|
3718 |
|
|
disabled within a COMMAND-LIST.
|
3719 |
|
|
|
3720 |
|
|
You can use breakpoint commands to start your program up again.
|
3721 |
|
|
Simply use the `continue' command, or `step', or any other command that
|
3722 |
|
|
resumes execution.
|
3723 |
|
|
|
3724 |
|
|
Any other commands in the command list, after a command that resumes
|
3725 |
|
|
execution, are ignored. This is because any time you resume execution
|
3726 |
|
|
(even with a simple `next' or `step'), you may encounter another
|
3727 |
|
|
breakpoint--which could have its own command list, leading to
|
3728 |
|
|
ambiguities about which list to execute.
|
3729 |
|
|
|
3730 |
|
|
If the first command you specify in a command list is `silent', the
|
3731 |
|
|
usual message about stopping at a breakpoint is not printed. This may
|
3732 |
|
|
be desirable for breakpoints that are to print a specific message and
|
3733 |
|
|
then continue. If none of the remaining commands print anything, you
|
3734 |
|
|
see no sign that the breakpoint was reached. `silent' is meaningful
|
3735 |
|
|
only at the beginning of a breakpoint command list.
|
3736 |
|
|
|
3737 |
|
|
The commands `echo', `output', and `printf' allow you to print
|
3738 |
|
|
precisely controlled output, and are often useful in silent
|
3739 |
|
|
breakpoints. *Note Commands for Controlled Output: Output.
|
3740 |
|
|
|
3741 |
|
|
For example, here is how you could use breakpoint commands to print
|
3742 |
|
|
the value of `x' at entry to `foo' whenever `x' is positive.
|
3743 |
|
|
|
3744 |
|
|
break foo if x>0
|
3745 |
|
|
commands
|
3746 |
|
|
silent
|
3747 |
|
|
printf "x is %d\n",x
|
3748 |
|
|
cont
|
3749 |
|
|
end
|
3750 |
|
|
|
3751 |
|
|
One application for breakpoint commands is to compensate for one bug
|
3752 |
|
|
so you can test for another. Put a breakpoint just after the erroneous
|
3753 |
|
|
line of code, give it a condition to detect the case in which something
|
3754 |
|
|
erroneous has been done, and give it commands to assign correct values
|
3755 |
|
|
to any variables that need them. End with the `continue' command so
|
3756 |
|
|
that your program does not stop, and start with the `silent' command so
|
3757 |
|
|
that no output is produced. Here is an example:
|
3758 |
|
|
|
3759 |
|
|
break 403
|
3760 |
|
|
commands
|
3761 |
|
|
silent
|
3762 |
|
|
set x = y + 4
|
3763 |
|
|
cont
|
3764 |
|
|
end
|
3765 |
|
|
|
3766 |
|
|
|
3767 |
|
|
File: gdb.info, Node: Save Breakpoints, Next: Error in Breakpoints, Prev: Break Commands, Up: Breakpoints
|
3768 |
|
|
|
3769 |
|
|
5.1.8 How to save breakpoints to a file
|
3770 |
|
|
---------------------------------------
|
3771 |
|
|
|
3772 |
|
|
To save breakpoint definitions to a file use the `save breakpoints'
|
3773 |
|
|
command.
|
3774 |
|
|
|
3775 |
|
|
`save breakpoints [FILENAME]'
|
3776 |
|
|
This command saves all current breakpoint definitions together with
|
3777 |
|
|
their commands and ignore counts, into a file `FILENAME' suitable
|
3778 |
|
|
for use in a later debugging session. This includes all types of
|
3779 |
|
|
breakpoints (breakpoints, watchpoints, catchpoints, tracepoints).
|
3780 |
|
|
To read the saved breakpoint definitions, use the `source' command
|
3781 |
|
|
(*note Command Files::). Note that watchpoints with expressions
|
3782 |
|
|
involving local variables may fail to be recreated because it may
|
3783 |
|
|
not be possible to access the context where the watchpoint is
|
3784 |
|
|
valid anymore. Because the saved breakpoint definitions are
|
3785 |
|
|
simply a sequence of GDB commands that recreate the breakpoints,
|
3786 |
|
|
you can edit the file in your favorite editing program, and remove
|
3787 |
|
|
the breakpoint definitions you're not interested in, or that can
|
3788 |
|
|
no longer be recreated.
|
3789 |
|
|
|
3790 |
|
|
|
3791 |
|
|
File: gdb.info, Node: Error in Breakpoints, Next: Breakpoint-related Warnings, Prev: Save Breakpoints, Up: Breakpoints
|
3792 |
|
|
|
3793 |
|
|
5.1.9 "Cannot insert breakpoints"
|
3794 |
|
|
---------------------------------
|
3795 |
|
|
|
3796 |
|
|
If you request too many active hardware-assisted breakpoints and
|
3797 |
|
|
watchpoints, you will see this error message:
|
3798 |
|
|
|
3799 |
|
|
Stopped; cannot insert breakpoints.
|
3800 |
|
|
You may have requested too many hardware breakpoints and watchpoints.
|
3801 |
|
|
|
3802 |
|
|
This message is printed when you attempt to resume the program, since
|
3803 |
|
|
only then GDB knows exactly how many hardware breakpoints and
|
3804 |
|
|
watchpoints it needs to insert.
|
3805 |
|
|
|
3806 |
|
|
When this message is printed, you need to disable or remove some of
|
3807 |
|
|
the hardware-assisted breakpoints and watchpoints, and then continue.
|
3808 |
|
|
|
3809 |
|
|
|
3810 |
|
|
File: gdb.info, Node: Breakpoint-related Warnings, Prev: Error in Breakpoints, Up: Breakpoints
|
3811 |
|
|
|
3812 |
|
|
5.1.10 "Breakpoint address adjusted..."
|
3813 |
|
|
---------------------------------------
|
3814 |
|
|
|
3815 |
|
|
Some processor architectures place constraints on the addresses at
|
3816 |
|
|
which breakpoints may be placed. For architectures thus constrained,
|
3817 |
|
|
GDB will attempt to adjust the breakpoint's address to comply with the
|
3818 |
|
|
constraints dictated by the architecture.
|
3819 |
|
|
|
3820 |
|
|
One example of such an architecture is the Fujitsu FR-V. The FR-V is
|
3821 |
|
|
a VLIW architecture in which a number of RISC-like instructions may be
|
3822 |
|
|
bundled together for parallel execution. The FR-V architecture
|
3823 |
|
|
constrains the location of a breakpoint instruction within such a
|
3824 |
|
|
bundle to the instruction with the lowest address. GDB honors this
|
3825 |
|
|
constraint by adjusting a breakpoint's address to the first in the
|
3826 |
|
|
bundle.
|
3827 |
|
|
|
3828 |
|
|
It is not uncommon for optimized code to have bundles which contain
|
3829 |
|
|
instructions from different source statements, thus it may happen that
|
3830 |
|
|
a breakpoint's address will be adjusted from one source statement to
|
3831 |
|
|
another. Since this adjustment may significantly alter GDB's
|
3832 |
|
|
breakpoint related behavior from what the user expects, a warning is
|
3833 |
|
|
printed when the breakpoint is first set and also when the breakpoint
|
3834 |
|
|
is hit.
|
3835 |
|
|
|
3836 |
|
|
A warning like the one below is printed when setting a breakpoint
|
3837 |
|
|
that's been subject to address adjustment:
|
3838 |
|
|
|
3839 |
|
|
warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
|
3840 |
|
|
|
3841 |
|
|
Such warnings are printed both for user settable and GDB's internal
|
3842 |
|
|
breakpoints. If you see one of these warnings, you should verify that
|
3843 |
|
|
a breakpoint set at the adjusted address will have the desired affect.
|
3844 |
|
|
If not, the breakpoint in question may be removed and other breakpoints
|
3845 |
|
|
may be set which will have the desired behavior. E.g., it may be
|
3846 |
|
|
sufficient to place the breakpoint at a later instruction. A
|
3847 |
|
|
conditional breakpoint may also be useful in some cases to prevent the
|
3848 |
|
|
breakpoint from triggering too often.
|
3849 |
|
|
|
3850 |
|
|
GDB will also issue a warning when stopping at one of these adjusted
|
3851 |
|
|
breakpoints:
|
3852 |
|
|
|
3853 |
|
|
warning: Breakpoint 1 address previously adjusted from 0x00010414
|
3854 |
|
|
to 0x00010410.
|
3855 |
|
|
|
3856 |
|
|
When this warning is encountered, it may be too late to take remedial
|
3857 |
|
|
action except in cases where the breakpoint is hit earlier or more
|
3858 |
|
|
frequently than expected.
|
3859 |
|
|
|
3860 |
|
|
|
3861 |
|
|
File: gdb.info, Node: Continuing and Stepping, Next: Signals, Prev: Breakpoints, Up: Stopping
|
3862 |
|
|
|
3863 |
|
|
5.2 Continuing and Stepping
|
3864 |
|
|
===========================
|
3865 |
|
|
|
3866 |
|
|
"Continuing" means resuming program execution until your program
|
3867 |
|
|
completes normally. In contrast, "stepping" means executing just one
|
3868 |
|
|
more "step" of your program, where "step" may mean either one line of
|
3869 |
|
|
source code, or one machine instruction (depending on what particular
|
3870 |
|
|
command you use). Either when continuing or when stepping, your
|
3871 |
|
|
program may stop even sooner, due to a breakpoint or a signal. (If it
|
3872 |
|
|
stops due to a signal, you may want to use `handle', or use `signal 0'
|
3873 |
|
|
to resume execution. *Note Signals: Signals.)
|
3874 |
|
|
|
3875 |
|
|
`continue [IGNORE-COUNT]'
|
3876 |
|
|
`c [IGNORE-COUNT]'
|
3877 |
|
|
`fg [IGNORE-COUNT]'
|
3878 |
|
|
Resume program execution, at the address where your program last
|
3879 |
|
|
stopped; any breakpoints set at that address are bypassed. The
|
3880 |
|
|
optional argument IGNORE-COUNT allows you to specify a further
|
3881 |
|
|
number of times to ignore a breakpoint at this location; its
|
3882 |
|
|
effect is like that of `ignore' (*note Break Conditions:
|
3883 |
|
|
Conditions.).
|
3884 |
|
|
|
3885 |
|
|
The argument IGNORE-COUNT is meaningful only when your program
|
3886 |
|
|
stopped due to a breakpoint. At other times, the argument to
|
3887 |
|
|
`continue' is ignored.
|
3888 |
|
|
|
3889 |
|
|
The synonyms `c' and `fg' (for "foreground", as the debugged
|
3890 |
|
|
program is deemed to be the foreground program) are provided
|
3891 |
|
|
purely for convenience, and have exactly the same behavior as
|
3892 |
|
|
`continue'.
|
3893 |
|
|
|
3894 |
|
|
To resume execution at a different place, you can use `return'
|
3895 |
|
|
(*note Returning from a Function: Returning.) to go back to the calling
|
3896 |
|
|
function; or `jump' (*note Continuing at a Different Address: Jumping.)
|
3897 |
|
|
to go to an arbitrary location in your program.
|
3898 |
|
|
|
3899 |
|
|
A typical technique for using stepping is to set a breakpoint (*note
|
3900 |
|
|
Breakpoints; Watchpoints; and Catchpoints: Breakpoints.) at the
|
3901 |
|
|
beginning of the function or the section of your program where a problem
|
3902 |
|
|
is believed to lie, run your program until it stops at that breakpoint,
|
3903 |
|
|
and then step through the suspect area, examining the variables that are
|
3904 |
|
|
interesting, until you see the problem happen.
|
3905 |
|
|
|
3906 |
|
|
`step'
|
3907 |
|
|
Continue running your program until control reaches a different
|
3908 |
|
|
source line, then stop it and return control to GDB. This command
|
3909 |
|
|
is abbreviated `s'.
|
3910 |
|
|
|
3911 |
|
|
_Warning:_ If you use the `step' command while control is
|
3912 |
|
|
within a function that was compiled without debugging
|
3913 |
|
|
information, execution proceeds until control reaches a
|
3914 |
|
|
function that does have debugging information. Likewise, it
|
3915 |
|
|
will not step into a function which is compiled without
|
3916 |
|
|
debugging information. To step through functions without
|
3917 |
|
|
debugging information, use the `stepi' command, described
|
3918 |
|
|
below.
|
3919 |
|
|
|
3920 |
|
|
The `step' command only stops at the first instruction of a source
|
3921 |
|
|
line. This prevents the multiple stops that could otherwise occur
|
3922 |
|
|
in `switch' statements, `for' loops, etc. `step' continues to
|
3923 |
|
|
stop if a function that has debugging information is called within
|
3924 |
|
|
the line. In other words, `step' _steps inside_ any functions
|
3925 |
|
|
called within the line.
|
3926 |
|
|
|
3927 |
|
|
Also, the `step' command only enters a function if there is line
|
3928 |
|
|
number information for the function. Otherwise it acts like the
|
3929 |
|
|
`next' command. This avoids problems when using `cc -gl' on MIPS
|
3930 |
|
|
machines. Previously, `step' entered subroutines if there was any
|
3931 |
|
|
debugging information about the routine.
|
3932 |
|
|
|
3933 |
|
|
`step COUNT'
|
3934 |
|
|
Continue running as in `step', but do so COUNT times. If a
|
3935 |
|
|
breakpoint is reached, or a signal not related to stepping occurs
|
3936 |
|
|
before COUNT steps, stepping stops right away.
|
3937 |
|
|
|
3938 |
|
|
`next [COUNT]'
|
3939 |
|
|
Continue to the next source line in the current (innermost) stack
|
3940 |
|
|
frame. This is similar to `step', but function calls that appear
|
3941 |
|
|
within the line of code are executed without stopping. Execution
|
3942 |
|
|
stops when control reaches a different line of code at the
|
3943 |
|
|
original stack level that was executing when you gave the `next'
|
3944 |
|
|
command. This command is abbreviated `n'.
|
3945 |
|
|
|
3946 |
|
|
An argument COUNT is a repeat count, as for `step'.
|
3947 |
|
|
|
3948 |
|
|
The `next' command only stops at the first instruction of a source
|
3949 |
|
|
line. This prevents multiple stops that could otherwise occur in
|
3950 |
|
|
`switch' statements, `for' loops, etc.
|
3951 |
|
|
|
3952 |
|
|
`set step-mode'
|
3953 |
|
|
`set step-mode on'
|
3954 |
|
|
The `set step-mode on' command causes the `step' command to stop
|
3955 |
|
|
at the first instruction of a function which contains no debug line
|
3956 |
|
|
information rather than stepping over it.
|
3957 |
|
|
|
3958 |
|
|
This is useful in cases where you may be interested in inspecting
|
3959 |
|
|
the machine instructions of a function which has no symbolic info
|
3960 |
|
|
and do not want GDB to automatically skip over this function.
|
3961 |
|
|
|
3962 |
|
|
`set step-mode off'
|
3963 |
|
|
Causes the `step' command to step over any functions which
|
3964 |
|
|
contains no debug information. This is the default.
|
3965 |
|
|
|
3966 |
|
|
`show step-mode'
|
3967 |
|
|
Show whether GDB will stop in or step over functions without
|
3968 |
|
|
source line debug information.
|
3969 |
|
|
|
3970 |
|
|
`finish'
|
3971 |
|
|
Continue running until just after function in the selected stack
|
3972 |
|
|
frame returns. Print the returned value (if any). This command
|
3973 |
|
|
can be abbreviated as `fin'.
|
3974 |
|
|
|
3975 |
|
|
Contrast this with the `return' command (*note Returning from a
|
3976 |
|
|
Function: Returning.).
|
3977 |
|
|
|
3978 |
|
|
`until'
|
3979 |
|
|
`u'
|
3980 |
|
|
Continue running until a source line past the current line, in the
|
3981 |
|
|
current stack frame, is reached. This command is used to avoid
|
3982 |
|
|
single stepping through a loop more than once. It is like the
|
3983 |
|
|
`next' command, except that when `until' encounters a jump, it
|
3984 |
|
|
automatically continues execution until the program counter is
|
3985 |
|
|
greater than the address of the jump.
|
3986 |
|
|
|
3987 |
|
|
This means that when you reach the end of a loop after single
|
3988 |
|
|
stepping though it, `until' makes your program continue execution
|
3989 |
|
|
until it exits the loop. In contrast, a `next' command at the end
|
3990 |
|
|
of a loop simply steps back to the beginning of the loop, which
|
3991 |
|
|
forces you to step through the next iteration.
|
3992 |
|
|
|
3993 |
|
|
`until' always stops your program if it attempts to exit the
|
3994 |
|
|
current stack frame.
|
3995 |
|
|
|
3996 |
|
|
`until' may produce somewhat counterintuitive results if the order
|
3997 |
|
|
of machine code does not match the order of the source lines. For
|
3998 |
|
|
example, in the following excerpt from a debugging session, the `f'
|
3999 |
|
|
(`frame') command shows that execution is stopped at line `206';
|
4000 |
|
|
yet when we use `until', we get to line `195':
|
4001 |
|
|
|
4002 |
|
|
(gdb) f
|
4003 |
|
|
#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
|
4004 |
|
|
206 expand_input();
|
4005 |
|
|
(gdb) until
|
4006 |
|
|
195 for ( ; argc > 0; NEXTARG) {
|
4007 |
|
|
|
4008 |
|
|
This happened because, for execution efficiency, the compiler had
|
4009 |
|
|
generated code for the loop closure test at the end, rather than
|
4010 |
|
|
the start, of the loop--even though the test in a C `for'-loop is
|
4011 |
|
|
written before the body of the loop. The `until' command appeared
|
4012 |
|
|
to step back to the beginning of the loop when it advanced to this
|
4013 |
|
|
expression; however, it has not really gone to an earlier
|
4014 |
|
|
statement--not in terms of the actual machine code.
|
4015 |
|
|
|
4016 |
|
|
`until' with no argument works by means of single instruction
|
4017 |
|
|
stepping, and hence is slower than `until' with an argument.
|
4018 |
|
|
|
4019 |
|
|
`until LOCATION'
|
4020 |
|
|
`u LOCATION'
|
4021 |
|
|
Continue running your program until either the specified location
|
4022 |
|
|
is reached, or the current stack frame returns. LOCATION is any of
|
4023 |
342 |
jeremybenn |
the forms described in *note Specify Location::. This form of the
|
4024 |
330 |
jeremybenn |
command uses temporary breakpoints, and hence is quicker than
|
4025 |
|
|
`until' without an argument. The specified location is actually
|
4026 |
|
|
reached only if it is in the current frame. This implies that
|
4027 |
|
|
`until' can be used to skip over recursive function invocations.
|
4028 |
|
|
For instance in the code below, if the current location is line
|
4029 |
|
|
`96', issuing `until 99' will execute the program up to line `99'
|
4030 |
|
|
in the same invocation of factorial, i.e., after the inner
|
4031 |
|
|
invocations have returned.
|
4032 |
|
|
|
4033 |
|
|
94 int factorial (int value)
|
4034 |
|
|
95 {
|
4035 |
|
|
96 if (value > 1) {
|
4036 |
|
|
97 value *= factorial (value - 1);
|
4037 |
|
|
98 }
|
4038 |
|
|
99 return (value);
|
4039 |
|
|
100 }
|
4040 |
|
|
|
4041 |
|
|
`advance LOCATION'
|
4042 |
|
|
Continue running the program up to the given LOCATION. An
|
4043 |
|
|
argument is required, which should be of one of the forms
|
4044 |
342 |
jeremybenn |
described in *note Specify Location::. Execution will also stop
|
4045 |
330 |
jeremybenn |
upon exit from the current stack frame. This command is similar
|
4046 |
|
|
to `until', but `advance' will not skip over recursive function
|
4047 |
|
|
calls, and the target location doesn't have to be in the same
|
4048 |
|
|
frame as the current one.
|
4049 |
|
|
|
4050 |
|
|
`stepi'
|
4051 |
|
|
`stepi ARG'
|
4052 |
|
|
`si'
|
4053 |
|
|
Execute one machine instruction, then stop and return to the
|
4054 |
|
|
debugger.
|
4055 |
|
|
|
4056 |
|
|
It is often useful to do `display/i $pc' when stepping by machine
|
4057 |
|
|
instructions. This makes GDB automatically display the next
|
4058 |
|
|
instruction to be executed, each time your program stops. *Note
|
4059 |
|
|
Automatic Display: Auto Display.
|
4060 |
|
|
|
4061 |
|
|
An argument is a repeat count, as in `step'.
|
4062 |
|
|
|
4063 |
|
|
`nexti'
|
4064 |
|
|
`nexti ARG'
|
4065 |
|
|
`ni'
|
4066 |
|
|
Execute one machine instruction, but if it is a function call,
|
4067 |
|
|
proceed until the function returns.
|
4068 |
|
|
|
4069 |
|
|
An argument is a repeat count, as in `next'.
|
4070 |
|
|
|
4071 |
|
|
|
4072 |
|
|
File: gdb.info, Node: Signals, Next: Thread Stops, Prev: Continuing and Stepping, Up: Stopping
|
4073 |
|
|
|
4074 |
|
|
5.3 Signals
|
4075 |
|
|
===========
|
4076 |
|
|
|
4077 |
|
|
A signal is an asynchronous event that can happen in a program. The
|
4078 |
|
|
operating system defines the possible kinds of signals, and gives each
|
4079 |
|
|
kind a name and a number. For example, in Unix `SIGINT' is the signal
|
4080 |
|
|
a program gets when you type an interrupt character (often `Ctrl-c');
|
4081 |
|
|
`SIGSEGV' is the signal a program gets from referencing a place in
|
4082 |
|
|
memory far away from all the areas in use; `SIGALRM' occurs when the
|
4083 |
|
|
alarm clock timer goes off (which happens only if your program has
|
4084 |
|
|
requested an alarm).
|
4085 |
|
|
|
4086 |
|
|
Some signals, including `SIGALRM', are a normal part of the
|
4087 |
|
|
functioning of your program. Others, such as `SIGSEGV', indicate
|
4088 |
|
|
errors; these signals are "fatal" (they kill your program immediately)
|
4089 |
|
|
if the program has not specified in advance some other way to handle
|
4090 |
|
|
the signal. `SIGINT' does not indicate an error in your program, but
|
4091 |
|
|
it is normally fatal so it can carry out the purpose of the interrupt:
|
4092 |
|
|
to kill the program.
|
4093 |
|
|
|
4094 |
|
|
GDB has the ability to detect any occurrence of a signal in your
|
4095 |
|
|
program. You can tell GDB in advance what to do for each kind of
|
4096 |
|
|
signal.
|
4097 |
|
|
|
4098 |
|
|
Normally, GDB is set up to let the non-erroneous signals like
|
4099 |
|
|
`SIGALRM' be silently passed to your program (so as not to interfere
|
4100 |
|
|
with their role in the program's functioning) but to stop your program
|
4101 |
|
|
immediately whenever an error signal happens. You can change these
|
4102 |
|
|
settings with the `handle' command.
|
4103 |
|
|
|
4104 |
|
|
`info signals'
|
4105 |
|
|
`info handle'
|
4106 |
|
|
Print a table of all the kinds of signals and how GDB has been
|
4107 |
|
|
told to handle each one. You can use this to see the signal
|
4108 |
|
|
numbers of all the defined types of signals.
|
4109 |
|
|
|
4110 |
|
|
`info signals SIG'
|
4111 |
|
|
Similar, but print information only about the specified signal
|
4112 |
|
|
number.
|
4113 |
|
|
|
4114 |
|
|
`info handle' is an alias for `info signals'.
|
4115 |
|
|
|
4116 |
|
|
`handle SIGNAL [KEYWORDS...]'
|
4117 |
|
|
Change the way GDB handles signal SIGNAL. SIGNAL can be the
|
4118 |
|
|
number of a signal or its name (with or without the `SIG' at the
|
4119 |
|
|
beginning); a list of signal numbers of the form `LOW-HIGH'; or
|
4120 |
|
|
the word `all', meaning all the known signals. Optional arguments
|
4121 |
|
|
KEYWORDS, described below, say what change to make.
|
4122 |
|
|
|
4123 |
|
|
The keywords allowed by the `handle' command can be abbreviated.
|
4124 |
|
|
Their full names are:
|
4125 |
|
|
|
4126 |
|
|
`nostop'
|
4127 |
|
|
GDB should not stop your program when this signal happens. It may
|
4128 |
|
|
still print a message telling you that the signal has come in.
|
4129 |
|
|
|
4130 |
|
|
`stop'
|
4131 |
|
|
GDB should stop your program when this signal happens. This
|
4132 |
|
|
implies the `print' keyword as well.
|
4133 |
|
|
|
4134 |
|
|
`print'
|
4135 |
|
|
GDB should print a message when this signal happens.
|
4136 |
|
|
|
4137 |
|
|
`noprint'
|
4138 |
|
|
GDB should not mention the occurrence of the signal at all. This
|
4139 |
|
|
implies the `nostop' keyword as well.
|
4140 |
|
|
|
4141 |
|
|
`pass'
|
4142 |
|
|
`noignore'
|
4143 |
|
|
GDB should allow your program to see this signal; your program can
|
4144 |
|
|
handle the signal, or else it may terminate if the signal is fatal
|
4145 |
|
|
and not handled. `pass' and `noignore' are synonyms.
|
4146 |
|
|
|
4147 |
|
|
`nopass'
|
4148 |
|
|
`ignore'
|
4149 |
|
|
GDB should not allow your program to see this signal. `nopass'
|
4150 |
|
|
and `ignore' are synonyms.
|
4151 |
|
|
|
4152 |
|
|
When a signal stops your program, the signal is not visible to the
|
4153 |
|
|
program until you continue. Your program sees the signal then, if
|
4154 |
|
|
`pass' is in effect for the signal in question _at that time_. In
|
4155 |
|
|
other words, after GDB reports a signal, you can use the `handle'
|
4156 |
|
|
command with `pass' or `nopass' to control whether your program sees
|
4157 |
|
|
that signal when you continue.
|
4158 |
|
|
|
4159 |
|
|
The default is set to `nostop', `noprint', `pass' for non-erroneous
|
4160 |
|
|
signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
|
4161 |
|
|
`print', `pass' for the erroneous signals.
|
4162 |
|
|
|
4163 |
|
|
You can also use the `signal' command to prevent your program from
|
4164 |
|
|
seeing a signal, or cause it to see a signal it normally would not see,
|
4165 |
|
|
or to give it any signal at any time. For example, if your program
|
4166 |
|
|
stopped due to some sort of memory reference error, you might store
|
4167 |
|
|
correct values into the erroneous variables and continue, hoping to see
|
4168 |
|
|
more execution; but your program would probably terminate immediately as
|
4169 |
|
|
a result of the fatal signal once it saw the signal. To prevent this,
|
4170 |
|
|
you can continue with `signal 0'. *Note Giving your Program a Signal:
|
4171 |
|
|
Signaling.
|
4172 |
|
|
|
4173 |
|
|
On some targets, GDB can inspect extra signal information associated
|
4174 |
|
|
with the intercepted signal, before it is actually delivered to the
|
4175 |
|
|
program being debugged. This information is exported by the
|
4176 |
|
|
convenience variable `$_siginfo', and consists of data that is passed
|
4177 |
|
|
by the kernel to the signal handler at the time of the receipt of a
|
4178 |
|
|
signal. The data type of the information itself is target dependent.
|
4179 |
|
|
You can see the data type using the `ptype $_siginfo' command. On Unix
|
4180 |
|
|
systems, it typically corresponds to the standard `siginfo_t' type, as
|
4181 |
|
|
defined in the `signal.h' system header.
|
4182 |
|
|
|
4183 |
|
|
Here's an example, on a GNU/Linux system, printing the stray
|
4184 |
|
|
referenced address that raised a segmentation fault.
|
4185 |
|
|
|
4186 |
|
|
(gdb) continue
|
4187 |
|
|
Program received signal SIGSEGV, Segmentation fault.
|
4188 |
|
|
0x0000000000400766 in main ()
|
4189 |
|
|
69 *(int *)p = 0;
|
4190 |
|
|
(gdb) ptype $_siginfo
|
4191 |
|
|
type = struct {
|
4192 |
|
|
int si_signo;
|
4193 |
|
|
int si_errno;
|
4194 |
|
|
int si_code;
|
4195 |
|
|
union {
|
4196 |
|
|
int _pad[28];
|
4197 |
|
|
struct {...} _kill;
|
4198 |
|
|
struct {...} _timer;
|
4199 |
|
|
struct {...} _rt;
|
4200 |
|
|
struct {...} _sigchld;
|
4201 |
|
|
struct {...} _sigfault;
|
4202 |
|
|
struct {...} _sigpoll;
|
4203 |
|
|
} _sifields;
|
4204 |
|
|
}
|
4205 |
|
|
(gdb) ptype $_siginfo._sifields._sigfault
|
4206 |
|
|
type = struct {
|
4207 |
|
|
void *si_addr;
|
4208 |
|
|
}
|
4209 |
|
|
(gdb) p $_siginfo._sifields._sigfault.si_addr
|
4210 |
|
|
$1 = (void *) 0x7ffff7ff7000
|
4211 |
|
|
|
4212 |
|
|
Depending on target support, `$_siginfo' may also be writable.
|
4213 |
|
|
|
4214 |
|
|
|
4215 |
|
|
File: gdb.info, Node: Thread Stops, Prev: Signals, Up: Stopping
|
4216 |
|
|
|
4217 |
|
|
5.4 Stopping and Starting Multi-thread Programs
|
4218 |
|
|
===============================================
|
4219 |
|
|
|
4220 |
|
|
GDB supports debugging programs with multiple threads (*note Debugging
|
4221 |
|
|
Programs with Multiple Threads: Threads.). There are two modes of
|
4222 |
|
|
controlling execution of your program within the debugger. In the
|
4223 |
|
|
default mode, referred to as "all-stop mode", when any thread in your
|
4224 |
|
|
program stops (for example, at a breakpoint or while being stepped),
|
4225 |
|
|
all other threads in the program are also stopped by GDB. On some
|
4226 |
|
|
targets, GDB also supports "non-stop mode", in which other threads can
|
4227 |
|
|
continue to run freely while you examine the stopped thread in the
|
4228 |
|
|
debugger.
|
4229 |
|
|
|
4230 |
|
|
* Menu:
|
4231 |
|
|
|
4232 |
|
|
* All-Stop Mode:: All threads stop when GDB takes control
|
4233 |
|
|
* Non-Stop Mode:: Other threads continue to execute
|
4234 |
|
|
* Background Execution:: Running your program asynchronously
|
4235 |
|
|
* Thread-Specific Breakpoints:: Controlling breakpoints
|
4236 |
|
|
* Interrupted System Calls:: GDB may interfere with system calls
|
4237 |
|
|
* Observer Mode:: GDB does not alter program behavior
|
4238 |
|
|
|
4239 |
|
|
|
4240 |
|
|
File: gdb.info, Node: All-Stop Mode, Next: Non-Stop Mode, Up: Thread Stops
|
4241 |
|
|
|
4242 |
|
|
5.4.1 All-Stop Mode
|
4243 |
|
|
-------------------
|
4244 |
|
|
|
4245 |
|
|
In all-stop mode, whenever your program stops under GDB for any reason,
|
4246 |
|
|
_all_ threads of execution stop, not just the current thread. This
|
4247 |
|
|
allows you to examine the overall state of the program, including
|
4248 |
|
|
switching between threads, without worrying that things may change
|
4249 |
|
|
underfoot.
|
4250 |
|
|
|
4251 |
|
|
Conversely, whenever you restart the program, _all_ threads start
|
4252 |
|
|
executing. _This is true even when single-stepping_ with commands like
|
4253 |
|
|
`step' or `next'.
|
4254 |
|
|
|
4255 |
|
|
In particular, GDB cannot single-step all threads in lockstep.
|
4256 |
|
|
Since thread scheduling is up to your debugging target's operating
|
4257 |
|
|
system (not controlled by GDB), other threads may execute more than one
|
4258 |
|
|
statement while the current thread completes a single step. Moreover,
|
4259 |
|
|
in general other threads stop in the middle of a statement, rather than
|
4260 |
|
|
at a clean statement boundary, when the program stops.
|
4261 |
|
|
|
4262 |
|
|
You might even find your program stopped in another thread after
|
4263 |
|
|
continuing or even single-stepping. This happens whenever some other
|
4264 |
|
|
thread runs into a breakpoint, a signal, or an exception before the
|
4265 |
|
|
first thread completes whatever you requested.
|
4266 |
|
|
|
4267 |
|
|
Whenever GDB stops your program, due to a breakpoint or a signal, it
|
4268 |
|
|
automatically selects the thread where that breakpoint or signal
|
4269 |
|
|
happened. GDB alerts you to the context switch with a message such as
|
4270 |
|
|
`[Switching to Thread N]' to identify the thread.
|
4271 |
|
|
|
4272 |
|
|
On some OSes, you can modify GDB's default behavior by locking the
|
4273 |
|
|
OS scheduler to allow only a single thread to run.
|
4274 |
|
|
|
4275 |
|
|
`set scheduler-locking MODE'
|
4276 |
|
|
Set the scheduler locking mode. If it is `off', then there is no
|
4277 |
|
|
locking and any thread may run at any time. If `on', then only the
|
4278 |
|
|
current thread may run when the inferior is resumed. The `step'
|
4279 |
|
|
mode optimizes for single-stepping; it prevents other threads from
|
4280 |
|
|
preempting the current thread while you are stepping, so that the
|
4281 |
|
|
focus of debugging does not change unexpectedly. Other threads
|
4282 |
|
|
only rarely (or never) get a chance to run when you step. They
|
4283 |
|
|
are more likely to run when you `next' over a function call, and
|
4284 |
|
|
they are completely free to run when you use commands like
|
4285 |
|
|
`continue', `until', or `finish'. However, unless another thread
|
4286 |
|
|
hits a breakpoint during its timeslice, GDB does not change the
|
4287 |
|
|
current thread away from the thread that you are debugging.
|
4288 |
|
|
|
4289 |
|
|
`show scheduler-locking'
|
4290 |
|
|
Display the current scheduler locking mode.
|
4291 |
|
|
|
4292 |
|
|
By default, when you issue one of the execution commands such as
|
4293 |
|
|
`continue', `next' or `step', GDB allows only threads of the current
|
4294 |
|
|
inferior to run. For example, if GDB is attached to two inferiors,
|
4295 |
|
|
each with two threads, the `continue' command resumes only the two
|
4296 |
|
|
threads of the current inferior. This is useful, for example, when you
|
4297 |
|
|
debug a program that forks and you want to hold the parent stopped (so
|
4298 |
|
|
that, for instance, it doesn't run to exit), while you debug the child.
|
4299 |
|
|
In other situations, you may not be interested in inspecting the
|
4300 |
|
|
current state of any of the processes GDB is attached to, and you may
|
4301 |
|
|
want to resume them all until some breakpoint is hit. In the latter
|
4302 |
|
|
case, you can instruct GDB to allow all threads of all the inferiors to
|
4303 |
|
|
run with the `set schedule-multiple' command.
|
4304 |
|
|
|
4305 |
|
|
`set schedule-multiple'
|
4306 |
|
|
Set the mode for allowing threads of multiple processes to be
|
4307 |
|
|
resumed when an execution command is issued. When `on', all
|
4308 |
|
|
threads of all processes are allowed to run. When `off', only the
|
4309 |
|
|
threads of the current process are resumed. The default is `off'.
|
4310 |
342 |
jeremybenn |
The `scheduler-locking' mode takes precedence when set to `on', or
|
4311 |
|
|
while you are stepping and set to `step'.
|
4312 |
330 |
jeremybenn |
|
4313 |
|
|
`show schedule-multiple'
|
4314 |
|
|
Display the current mode for resuming the execution of threads of
|
4315 |
|
|
multiple processes.
|
4316 |
|
|
|
4317 |
|
|
|
4318 |
|
|
File: gdb.info, Node: Non-Stop Mode, Next: Background Execution, Prev: All-Stop Mode, Up: Thread Stops
|
4319 |
|
|
|
4320 |
|
|
5.4.2 Non-Stop Mode
|
4321 |
|
|
-------------------
|
4322 |
|
|
|
4323 |
|
|
For some multi-threaded targets, GDB supports an optional mode of
|
4324 |
|
|
operation in which you can examine stopped program threads in the
|
4325 |
|
|
debugger while other threads continue to execute freely. This
|
4326 |
|
|
minimizes intrusion when debugging live systems, such as programs where
|
4327 |
|
|
some threads have real-time constraints or must continue to respond to
|
4328 |
|
|
external events. This is referred to as "non-stop" mode.
|
4329 |
|
|
|
4330 |
|
|
In non-stop mode, when a thread stops to report a debugging event,
|
4331 |
|
|
_only_ that thread is stopped; GDB does not stop other threads as well,
|
4332 |
|
|
in contrast to the all-stop mode behavior. Additionally, execution
|
4333 |
|
|
commands such as `continue' and `step' apply by default only to the
|
4334 |
|
|
current thread in non-stop mode, rather than all threads as in all-stop
|
4335 |
|
|
mode. This allows you to control threads explicitly in ways that are
|
4336 |
|
|
not possible in all-stop mode -- for example, stepping one thread while
|
4337 |
|
|
allowing others to run freely, stepping one thread while holding all
|
4338 |
|
|
others stopped, or stepping several threads independently and
|
4339 |
|
|
simultaneously.
|
4340 |
|
|
|
4341 |
|
|
To enter non-stop mode, use this sequence of commands before you run
|
4342 |
|
|
or attach to your program:
|
4343 |
|
|
|
4344 |
|
|
# Enable the async interface.
|
4345 |
|
|
set target-async 1
|
4346 |
|
|
|
4347 |
|
|
# If using the CLI, pagination breaks non-stop.
|
4348 |
|
|
set pagination off
|
4349 |
|
|
|
4350 |
|
|
# Finally, turn it on!
|
4351 |
|
|
set non-stop on
|
4352 |
|
|
|
4353 |
|
|
You can use these commands to manipulate the non-stop mode setting:
|
4354 |
|
|
|
4355 |
|
|
`set non-stop on'
|
4356 |
|
|
Enable selection of non-stop mode.
|
4357 |
|
|
|
4358 |
|
|
`set non-stop off'
|
4359 |
|
|
Disable selection of non-stop mode.
|
4360 |
|
|
|
4361 |
|
|
`show non-stop'
|
4362 |
|
|
Show the current non-stop enablement setting.
|
4363 |
|
|
|
4364 |
|
|
Note these commands only reflect whether non-stop mode is enabled,
|
4365 |
|
|
not whether the currently-executing program is being run in non-stop
|
4366 |
|
|
mode. In particular, the `set non-stop' preference is only consulted
|
4367 |
|
|
when GDB starts or connects to the target program, and it is generally
|
4368 |
|
|
not possible to switch modes once debugging has started. Furthermore,
|
4369 |
|
|
since not all targets support non-stop mode, even when you have enabled
|
4370 |
|
|
non-stop mode, GDB may still fall back to all-stop operation by default.
|
4371 |
|
|
|
4372 |
|
|
In non-stop mode, all execution commands apply only to the current
|
4373 |
|
|
thread by default. That is, `continue' only continues one thread. To
|
4374 |
|
|
continue all threads, issue `continue -a' or `c -a'.
|
4375 |
|
|
|
4376 |
|
|
You can use GDB's background execution commands (*note Background
|
4377 |
|
|
Execution::) to run some threads in the background while you continue
|
4378 |
|
|
to examine or step others from GDB. The MI execution commands (*note
|
4379 |
|
|
GDB/MI Program Execution::) are always executed asynchronously in
|
4380 |
|
|
non-stop mode.
|
4381 |
|
|
|
4382 |
|
|
Suspending execution is done with the `interrupt' command when
|
4383 |
|
|
running in the background, or `Ctrl-c' during foreground execution. In
|
4384 |
|
|
all-stop mode, this stops the whole process; but in non-stop mode the
|
4385 |
|
|
interrupt applies only to the current thread. To stop the whole
|
4386 |
|
|
program, use `interrupt -a'.
|
4387 |
|
|
|
4388 |
|
|
Other execution commands do not currently support the `-a' option.
|
4389 |
|
|
|
4390 |
|
|
In non-stop mode, when a thread stops, GDB doesn't automatically make
|
4391 |
|
|
that thread current, as it does in all-stop mode. This is because the
|
4392 |
|
|
thread stop notifications are asynchronous with respect to GDB's
|
4393 |
|
|
command interpreter, and it would be confusing if GDB unexpectedly
|
4394 |
|
|
changed to a different thread just as you entered a command to operate
|
4395 |
|
|
on the previously current thread.
|
4396 |
|
|
|
4397 |
|
|
|
4398 |
|
|
File: gdb.info, Node: Background Execution, Next: Thread-Specific Breakpoints, Prev: Non-Stop Mode, Up: Thread Stops
|
4399 |
|
|
|
4400 |
|
|
5.4.3 Background Execution
|
4401 |
|
|
--------------------------
|
4402 |
|
|
|
4403 |
|
|
GDB's execution commands have two variants: the normal foreground
|
4404 |
|
|
(synchronous) behavior, and a background (asynchronous) behavior. In
|
4405 |
|
|
foreground execution, GDB waits for the program to report that some
|
4406 |
|
|
thread has stopped before prompting for another command. In background
|
4407 |
|
|
execution, GDB immediately gives a command prompt so that you can issue
|
4408 |
|
|
other commands while your program runs.
|
4409 |
|
|
|
4410 |
|
|
You need to explicitly enable asynchronous mode before you can use
|
4411 |
|
|
background execution commands. You can use these commands to
|
4412 |
|
|
manipulate the asynchronous mode setting:
|
4413 |
|
|
|
4414 |
|
|
`set target-async on'
|
4415 |
|
|
Enable asynchronous mode.
|
4416 |
|
|
|
4417 |
|
|
`set target-async off'
|
4418 |
|
|
Disable asynchronous mode.
|
4419 |
|
|
|
4420 |
|
|
`show target-async'
|
4421 |
|
|
Show the current target-async setting.
|
4422 |
|
|
|
4423 |
|
|
If the target doesn't support async mode, GDB issues an error
|
4424 |
|
|
message if you attempt to use the background execution commands.
|
4425 |
|
|
|
4426 |
|
|
To specify background execution, add a `&' to the command. For
|
4427 |
|
|
example, the background form of the `continue' command is `continue&',
|
4428 |
|
|
or just `c&'. The execution commands that accept background execution
|
4429 |
|
|
are:
|
4430 |
|
|
|
4431 |
|
|
`run'
|
4432 |
|
|
*Note Starting your Program: Starting.
|
4433 |
|
|
|
4434 |
|
|
`attach'
|
4435 |
|
|
*Note Debugging an Already-running Process: Attach.
|
4436 |
|
|
|
4437 |
|
|
`step'
|
4438 |
|
|
*Note step: Continuing and Stepping.
|
4439 |
|
|
|
4440 |
|
|
`stepi'
|
4441 |
|
|
*Note stepi: Continuing and Stepping.
|
4442 |
|
|
|
4443 |
|
|
`next'
|
4444 |
|
|
*Note next: Continuing and Stepping.
|
4445 |
|
|
|
4446 |
|
|
`nexti'
|
4447 |
|
|
*Note nexti: Continuing and Stepping.
|
4448 |
|
|
|
4449 |
|
|
`continue'
|
4450 |
|
|
*Note continue: Continuing and Stepping.
|
4451 |
|
|
|
4452 |
|
|
`finish'
|
4453 |
|
|
*Note finish: Continuing and Stepping.
|
4454 |
|
|
|
4455 |
|
|
`until'
|
4456 |
|
|
*Note until: Continuing and Stepping.
|
4457 |
|
|
|
4458 |
|
|
|
4459 |
|
|
Background execution is especially useful in conjunction with
|
4460 |
342 |
jeremybenn |
non-stop mode for debugging programs with multiple threads; see *note
|
4461 |
330 |
jeremybenn |
Non-Stop Mode::. However, you can also use these commands in the
|
4462 |
|
|
normal all-stop mode with the restriction that you cannot issue another
|
4463 |
|
|
execution command until the previous one finishes. Examples of
|
4464 |
|
|
commands that are valid in all-stop mode while the program is running
|
4465 |
|
|
include `help' and `info break'.
|
4466 |
|
|
|
4467 |
|
|
You can interrupt your program while it is running in the background
|
4468 |
|
|
by using the `interrupt' command.
|
4469 |
|
|
|
4470 |
|
|
`interrupt'
|
4471 |
|
|
`interrupt -a'
|
4472 |
|
|
Suspend execution of the running program. In all-stop mode,
|
4473 |
|
|
`interrupt' stops the whole process, but in non-stop mode, it stops
|
4474 |
|
|
only the current thread. To stop the whole program in non-stop
|
4475 |
|
|
mode, use `interrupt -a'.
|
4476 |
|
|
|
4477 |
|
|
|
4478 |
|
|
File: gdb.info, Node: Thread-Specific Breakpoints, Next: Interrupted System Calls, Prev: Background Execution, Up: Thread Stops
|
4479 |
|
|
|
4480 |
|
|
5.4.4 Thread-Specific Breakpoints
|
4481 |
|
|
---------------------------------
|
4482 |
|
|
|
4483 |
|
|
When your program has multiple threads (*note Debugging Programs with
|
4484 |
|
|
Multiple Threads: Threads.), you can choose whether to set breakpoints
|
4485 |
|
|
on all threads, or on a particular thread.
|
4486 |
|
|
|
4487 |
|
|
`break LINESPEC thread THREADNO'
|
4488 |
|
|
`break LINESPEC thread THREADNO if ...'
|
4489 |
|
|
LINESPEC specifies source lines; there are several ways of writing
|
4490 |
|
|
them (*note Specify Location::), but the effect is always to
|
4491 |
|
|
specify some source line.
|
4492 |
|
|
|
4493 |
|
|
Use the qualifier `thread THREADNO' with a breakpoint command to
|
4494 |
|
|
specify that you only want GDB to stop the program when a
|
4495 |
|
|
particular thread reaches this breakpoint. THREADNO is one of the
|
4496 |
|
|
numeric thread identifiers assigned by GDB, shown in the first
|
4497 |
|
|
column of the `info threads' display.
|
4498 |
|
|
|
4499 |
|
|
If you do not specify `thread THREADNO' when you set a breakpoint,
|
4500 |
|
|
the breakpoint applies to _all_ threads of your program.
|
4501 |
|
|
|
4502 |
|
|
You can use the `thread' qualifier on conditional breakpoints as
|
4503 |
|
|
well; in this case, place `thread THREADNO' before or after the
|
4504 |
|
|
breakpoint condition, like this:
|
4505 |
|
|
|
4506 |
|
|
(gdb) break frik.c:13 thread 28 if bartab > lim
|
4507 |
|
|
|
4508 |
|
|
|
4509 |
|
|
|
4510 |
|
|
File: gdb.info, Node: Interrupted System Calls, Next: Observer Mode, Prev: Thread-Specific Breakpoints, Up: Thread Stops
|
4511 |
|
|
|
4512 |
|
|
5.4.5 Interrupted System Calls
|
4513 |
|
|
------------------------------
|
4514 |
|
|
|
4515 |
|
|
There is an unfortunate side effect when using GDB to debug
|
4516 |
|
|
multi-threaded programs. If one thread stops for a breakpoint, or for
|
4517 |
|
|
some other reason, and another thread is blocked in a system call, then
|
4518 |
|
|
the system call may return prematurely. This is a consequence of the
|
4519 |
|
|
interaction between multiple threads and the signals that GDB uses to
|
4520 |
|
|
implement breakpoints and other events that stop execution.
|
4521 |
|
|
|
4522 |
|
|
To handle this problem, your program should check the return value of
|
4523 |
|
|
each system call and react appropriately. This is good programming
|
4524 |
|
|
style anyways.
|
4525 |
|
|
|
4526 |
|
|
For example, do not write code like this:
|
4527 |
|
|
|
4528 |
|
|
sleep (10);
|
4529 |
|
|
|
4530 |
|
|
The call to `sleep' will return early if a different thread stops at
|
4531 |
|
|
a breakpoint or for some other reason.
|
4532 |
|
|
|
4533 |
|
|
Instead, write this:
|
4534 |
|
|
|
4535 |
|
|
int unslept = 10;
|
4536 |
|
|
while (unslept > 0)
|
4537 |
|
|
unslept = sleep (unslept);
|
4538 |
|
|
|
4539 |
|
|
A system call is allowed to return early, so the system is still
|
4540 |
|
|
conforming to its specification. But GDB does cause your
|
4541 |
|
|
multi-threaded program to behave differently than it would without GDB.
|
4542 |
|
|
|
4543 |
|
|
Also, GDB uses internal breakpoints in the thread library to monitor
|
4544 |
|
|
certain events such as thread creation and thread destruction. When
|
4545 |
|
|
such an event happens, a system call in another thread may return
|
4546 |
|
|
prematurely, even though your program does not appear to stop.
|
4547 |
|
|
|
4548 |
|
|
|
4549 |
|
|
File: gdb.info, Node: Observer Mode, Prev: Interrupted System Calls, Up: Thread Stops
|
4550 |
|
|
|
4551 |
|
|
5.4.6 Observer Mode
|
4552 |
|
|
-------------------
|
4553 |
|
|
|
4554 |
|
|
If you want to build on non-stop mode and observe program behavior
|
4555 |
|
|
without any chance of disruption by GDB, you can set variables to
|
4556 |
|
|
disable all of the debugger's attempts to modify state, whether by
|
4557 |
|
|
writing memory, inserting breakpoints, etc. These operate at a low
|
4558 |
|
|
level, intercepting operations from all commands.
|
4559 |
|
|
|
4560 |
|
|
When all of these are set to `off', then GDB is said to be "observer
|
4561 |
|
|
mode". As a convenience, the variable `observer' can be set to disable
|
4562 |
|
|
these, plus enable non-stop mode.
|
4563 |
|
|
|
4564 |
|
|
Note that GDB will not prevent you from making nonsensical
|
4565 |
|
|
combinations of these settings. For instance, if you have enabled
|
4566 |
|
|
`may-insert-breakpoints' but disabled `may-write-memory', then
|
4567 |
|
|
breakpoints that work by writing trap instructions into the code stream
|
4568 |
|
|
will still not be able to be placed.
|
4569 |
|
|
|
4570 |
|
|
`set observer on'
|
4571 |
|
|
`set observer off'
|
4572 |
|
|
When set to `on', this disables all the permission variables below
|
4573 |
|
|
(except for `insert-fast-tracepoints'), plus enables non-stop
|
4574 |
|
|
debugging. Setting this to `off' switches back to normal
|
4575 |
|
|
debugging, though remaining in non-stop mode.
|
4576 |
|
|
|
4577 |
|
|
`show observer'
|
4578 |
|
|
Show whether observer mode is on or off.
|
4579 |
|
|
|
4580 |
|
|
`set may-write-registers on'
|
4581 |
|
|
`set may-write-registers off'
|
4582 |
|
|
This controls whether GDB will attempt to alter the values of
|
4583 |
|
|
registers, such as with assignment expressions in `print', or the
|
4584 |
|
|
`jump' command. It defaults to `on'.
|
4585 |
|
|
|
4586 |
|
|
`show may-write-registers'
|
4587 |
|
|
Show the current permission to write registers.
|
4588 |
|
|
|
4589 |
|
|
`set may-write-memory on'
|
4590 |
|
|
`set may-write-memory off'
|
4591 |
|
|
This controls whether GDB will attempt to alter the contents of
|
4592 |
|
|
memory, such as with assignment expressions in `print'. It
|
4593 |
|
|
defaults to `on'.
|
4594 |
|
|
|
4595 |
|
|
`show may-write-memory'
|
4596 |
|
|
Show the current permission to write memory.
|
4597 |
|
|
|
4598 |
|
|
`set may-insert-breakpoints on'
|
4599 |
|
|
`set may-insert-breakpoints off'
|
4600 |
|
|
This controls whether GDB will attempt to insert breakpoints.
|
4601 |
|
|
This affects all breakpoints, including internal breakpoints
|
4602 |
|
|
defined by GDB. It defaults to `on'.
|
4603 |
|
|
|
4604 |
|
|
`show may-insert-breakpoints'
|
4605 |
|
|
Show the current permission to insert breakpoints.
|
4606 |
|
|
|
4607 |
|
|
`set may-insert-tracepoints on'
|
4608 |
|
|
`set may-insert-tracepoints off'
|
4609 |
|
|
This controls whether GDB will attempt to insert (regular)
|
4610 |
|
|
tracepoints at the beginning of a tracing experiment. It affects
|
4611 |
|
|
only non-fast tracepoints, fast tracepoints being under the
|
4612 |
|
|
control of `may-insert-fast-tracepoints'. It defaults to `on'.
|
4613 |
|
|
|
4614 |
|
|
`show may-insert-tracepoints'
|
4615 |
|
|
Show the current permission to insert tracepoints.
|
4616 |
|
|
|
4617 |
|
|
`set may-insert-fast-tracepoints on'
|
4618 |
|
|
`set may-insert-fast-tracepoints off'
|
4619 |
|
|
This controls whether GDB will attempt to insert fast tracepoints
|
4620 |
|
|
at the beginning of a tracing experiment. It affects only fast
|
4621 |
|
|
tracepoints, regular (non-fast) tracepoints being under the
|
4622 |
|
|
control of `may-insert-tracepoints'. It defaults to `on'.
|
4623 |
|
|
|
4624 |
|
|
`show may-insert-fast-tracepoints'
|
4625 |
|
|
Show the current permission to insert fast tracepoints.
|
4626 |
|
|
|
4627 |
|
|
`set may-interrupt on'
|
4628 |
|
|
`set may-interrupt off'
|
4629 |
|
|
This controls whether GDB will attempt to interrupt or stop
|
4630 |
|
|
program execution. When this variable is `off', the `interrupt'
|
4631 |
|
|
command will have no effect, nor will `Ctrl-c'. It defaults to
|
4632 |
|
|
`on'.
|
4633 |
|
|
|
4634 |
|
|
`show may-interrupt'
|
4635 |
|
|
Show the current permission to interrupt or stop the program.
|
4636 |
|
|
|
4637 |
|
|
|
4638 |
|
|
|
4639 |
|
|
File: gdb.info, Node: Reverse Execution, Next: Process Record and Replay, Prev: Stopping, Up: Top
|
4640 |
|
|
|
4641 |
|
|
6 Running programs backward
|
4642 |
|
|
***************************
|
4643 |
|
|
|
4644 |
|
|
When you are debugging a program, it is not unusual to realize that you
|
4645 |
|
|
have gone too far, and some event of interest has already happened. If
|
4646 |
|
|
the target environment supports it, GDB can allow you to "rewind" the
|
4647 |
|
|
program by running it backward.
|
4648 |
|
|
|
4649 |
|
|
A target environment that supports reverse execution should be able
|
4650 |
|
|
to "undo" the changes in machine state that have taken place as the
|
4651 |
|
|
program was executing normally. Variables, registers etc. should
|
4652 |
|
|
revert to their previous values. Obviously this requires a great deal
|
4653 |
|
|
of sophistication on the part of the target environment; not all target
|
4654 |
|
|
environments can support reverse execution.
|
4655 |
|
|
|
4656 |
|
|
When a program is executed in reverse, the instructions that have
|
4657 |
|
|
most recently been executed are "un-executed", in reverse order. The
|
4658 |
|
|
program counter runs backward, following the previous thread of
|
4659 |
|
|
execution in reverse. As each instruction is "un-executed", the values
|
4660 |
|
|
of memory and/or registers that were changed by that instruction are
|
4661 |
|
|
reverted to their previous states. After executing a piece of source
|
4662 |
|
|
code in reverse, all side effects of that code should be "undone", and
|
4663 |
|
|
all variables should be returned to their prior values(1).
|
4664 |
|
|
|
4665 |
|
|
If you are debugging in a target environment that supports reverse
|
4666 |
|
|
execution, GDB provides the following commands.
|
4667 |
|
|
|
4668 |
|
|
`reverse-continue [IGNORE-COUNT]'
|
4669 |
|
|
`rc [IGNORE-COUNT]'
|
4670 |
|
|
Beginning at the point where your program last stopped, start
|
4671 |
|
|
executing in reverse. Reverse execution will stop for breakpoints
|
4672 |
|
|
and synchronous exceptions (signals), just like normal execution.
|
4673 |
|
|
Behavior of asynchronous signals depends on the target environment.
|
4674 |
|
|
|
4675 |
|
|
`reverse-step [COUNT]'
|
4676 |
|
|
Run the program backward until control reaches the start of a
|
4677 |
|
|
different source line; then stop it, and return control to GDB.
|
4678 |
|
|
|
4679 |
|
|
Like the `step' command, `reverse-step' will only stop at the
|
4680 |
|
|
beginning of a source line. It "un-executes" the previously
|
4681 |
|
|
executed source line. If the previous source line included calls
|
4682 |
|
|
to debuggable functions, `reverse-step' will step (backward) into
|
4683 |
|
|
the called function, stopping at the beginning of the _last_
|
4684 |
|
|
statement in the called function (typically a return statement).
|
4685 |
|
|
|
4686 |
|
|
Also, as with the `step' command, if non-debuggable functions are
|
4687 |
|
|
called, `reverse-step' will run thru them backward without
|
4688 |
|
|
stopping.
|
4689 |
|
|
|
4690 |
|
|
`reverse-stepi [COUNT]'
|
4691 |
|
|
Reverse-execute one machine instruction. Note that the instruction
|
4692 |
|
|
to be reverse-executed is _not_ the one pointed to by the program
|
4693 |
|
|
counter, but the instruction executed prior to that one. For
|
4694 |
|
|
instance, if the last instruction was a jump, `reverse-stepi' will
|
4695 |
|
|
take you back from the destination of the jump to the jump
|
4696 |
|
|
instruction itself.
|
4697 |
|
|
|
4698 |
|
|
`reverse-next [COUNT]'
|
4699 |
|
|
Run backward to the beginning of the previous line executed in the
|
4700 |
|
|
current (innermost) stack frame. If the line contains function
|
4701 |
|
|
calls, they will be "un-executed" without stopping. Starting from
|
4702 |
|
|
the first line of a function, `reverse-next' will take you back to
|
4703 |
|
|
the caller of that function, _before_ the function was called,
|
4704 |
|
|
just as the normal `next' command would take you from the last
|
4705 |
|
|
line of a function back to its return to its caller (2).
|
4706 |
|
|
|
4707 |
|
|
`reverse-nexti [COUNT]'
|
4708 |
|
|
Like `nexti', `reverse-nexti' executes a single instruction in
|
4709 |
|
|
reverse, except that called functions are "un-executed" atomically.
|
4710 |
|
|
That is, if the previously executed instruction was a return from
|
4711 |
|
|
another function, `reverse-nexti' will continue to execute in
|
4712 |
|
|
reverse until the call to that function (from the current stack
|
4713 |
|
|
frame) is reached.
|
4714 |
|
|
|
4715 |
|
|
`reverse-finish'
|
4716 |
|
|
Just as the `finish' command takes you to the point where the
|
4717 |
|
|
current function returns, `reverse-finish' takes you to the point
|
4718 |
|
|
where it was called. Instead of ending up at the end of the
|
4719 |
|
|
current function invocation, you end up at the beginning.
|
4720 |
|
|
|
4721 |
|
|
`set exec-direction'
|
4722 |
|
|
Set the direction of target execution.
|
4723 |
|
|
|
4724 |
|
|
`set exec-direction reverse'
|
4725 |
|
|
GDB will perform all execution commands in reverse, until the
|
4726 |
|
|
exec-direction mode is changed to "forward". Affected commands
|
4727 |
|
|
include `step, stepi, next, nexti, continue, and finish'. The
|
4728 |
|
|
`return' command cannot be used in reverse mode.
|
4729 |
|
|
|
4730 |
|
|
`set exec-direction forward'
|
4731 |
|
|
GDB will perform all execution commands in the normal fashion.
|
4732 |
|
|
This is the default.
|
4733 |
|
|
|
4734 |
|
|
---------- Footnotes ----------
|
4735 |
|
|
|
4736 |
|
|
(1) Note that some side effects are easier to undo than others. For
|
4737 |
|
|
instance, memory and registers are relatively easy, but device I/O is
|
4738 |
|
|
hard. Some targets may be able undo things like device I/O, and some
|
4739 |
|
|
may not.
|
4740 |
|
|
|
4741 |
|
|
The contract between GDB and the reverse executing target requires
|
4742 |
|
|
only that the target do something reasonable when GDB tells it to
|
4743 |
|
|
execute backwards, and then report the results back to GDB. Whatever
|
4744 |
|
|
the target reports back to GDB, GDB will report back to the user. GDB
|
4745 |
|
|
assumes that the memory and registers that the target reports are in a
|
4746 |
|
|
consistant state, but GDB accepts whatever it is given.
|
4747 |
|
|
|
4748 |
|
|
(2) Unless the code is too heavily optimized.
|
4749 |
|
|
|
4750 |
|
|
|
4751 |
|
|
File: gdb.info, Node: Process Record and Replay, Next: Stack, Prev: Reverse Execution, Up: Top
|
4752 |
|
|
|
4753 |
|
|
7 Recording Inferior's Execution and Replaying It
|
4754 |
|
|
*************************************************
|
4755 |
|
|
|
4756 |
|
|
On some platforms, GDB provides a special "process record and replay"
|
4757 |
|
|
target that can record a log of the process execution, and replay it
|
4758 |
|
|
later with both forward and reverse execution commands.
|
4759 |
|
|
|
4760 |
|
|
When this target is in use, if the execution log includes the record
|
4761 |
|
|
for the next instruction, GDB will debug in "replay mode". In the
|
4762 |
|
|
replay mode, the inferior does not really execute code instructions.
|
4763 |
|
|
Instead, all the events that normally happen during code execution are
|
4764 |
|
|
taken from the execution log. While code is not really executed in
|
4765 |
|
|
replay mode, the values of registers (including the program counter
|
4766 |
|
|
register) and the memory of the inferior are still changed as they
|
4767 |
|
|
normally would. Their contents are taken from the execution log.
|
4768 |
|
|
|
4769 |
|
|
If the record for the next instruction is not in the execution log,
|
4770 |
|
|
GDB will debug in "record mode". In this mode, the inferior executes
|
4771 |
|
|
normally, and GDB records the execution log for future replay.
|
4772 |
|
|
|
4773 |
|
|
The process record and replay target supports reverse execution
|
4774 |
|
|
(*note Reverse Execution::), even if the platform on which the inferior
|
4775 |
|
|
runs does not. However, the reverse execution is limited in this case
|
4776 |
|
|
by the range of the instructions recorded in the execution log. In
|
4777 |
|
|
other words, reverse execution on platforms that don't support it
|
4778 |
|
|
directly can only be done in the replay mode.
|
4779 |
|
|
|
4780 |
|
|
When debugging in the reverse direction, GDB will work in replay
|
4781 |
|
|
mode as long as the execution log includes the record for the previous
|
4782 |
|
|
instruction; otherwise, it will work in record mode, if the platform
|
4783 |
|
|
supports reverse execution, or stop if not.
|
4784 |
|
|
|
4785 |
|
|
For architecture environments that support process record and replay,
|
4786 |
|
|
GDB provides the following commands:
|
4787 |
|
|
|
4788 |
|
|
`target record'
|
4789 |
|
|
This command starts the process record and replay target. The
|
4790 |
|
|
process record and replay target can only debug a process that is
|
4791 |
|
|
already running. Therefore, you need first to start the process
|
4792 |
|
|
with the `run' or `start' commands, and then start the recording
|
4793 |
|
|
with the `target record' command.
|
4794 |
|
|
|
4795 |
|
|
Both `record' and `rec' are aliases of `target record'.
|
4796 |
|
|
|
4797 |
|
|
Displaced stepping (*note displaced stepping: Maintenance
|
4798 |
|
|
Commands.) will be automatically disabled when process record and
|
4799 |
|
|
replay target is started. That's because the process record and
|
4800 |
|
|
replay target doesn't support displaced stepping.
|
4801 |
|
|
|
4802 |
|
|
If the inferior is in the non-stop mode (*note Non-Stop Mode::) or
|
4803 |
|
|
in the asynchronous execution mode (*note Background Execution::),
|
4804 |
|
|
the process record and replay target cannot be started because it
|
4805 |
|
|
doesn't support these two modes.
|
4806 |
|
|
|
4807 |
|
|
`record stop'
|
4808 |
|
|
Stop the process record and replay target. When process record and
|
4809 |
|
|
replay target stops, the entire execution log will be deleted and
|
4810 |
|
|
the inferior will either be terminated, or will remain in its
|
4811 |
|
|
final state.
|
4812 |
|
|
|
4813 |
|
|
When you stop the process record and replay target in record mode
|
4814 |
|
|
(at the end of the execution log), the inferior will be stopped at
|
4815 |
|
|
the next instruction that would have been recorded. In other
|
4816 |
|
|
words, if you record for a while and then stop recording, the
|
4817 |
|
|
inferior process will be left in the same state as if the
|
4818 |
|
|
recording never happened.
|
4819 |
|
|
|
4820 |
|
|
On the other hand, if the process record and replay target is
|
4821 |
|
|
stopped while in replay mode (that is, not at the end of the
|
4822 |
|
|
execution log, but at some earlier point), the inferior process
|
4823 |
|
|
will become "live" at that earlier state, and it will then be
|
4824 |
|
|
possible to continue the usual "live" debugging of the process
|
4825 |
|
|
from that state.
|
4826 |
|
|
|
4827 |
|
|
When the inferior process exits, or GDB detaches from it, process
|
4828 |
|
|
record and replay target will automatically stop itself.
|
4829 |
|
|
|
4830 |
|
|
`record save FILENAME'
|
4831 |
|
|
Save the execution log to a file `FILENAME'. Default filename is
|
4832 |
|
|
`gdb_record.PROCESS_ID', where PROCESS_ID is the process ID of the
|
4833 |
|
|
inferior.
|
4834 |
|
|
|
4835 |
|
|
`record restore FILENAME'
|
4836 |
|
|
Restore the execution log from a file `FILENAME'. File must have
|
4837 |
|
|
been created with `record save'.
|
4838 |
|
|
|
4839 |
|
|
`set record insn-number-max LIMIT'
|
4840 |
|
|
Set the limit of instructions to be recorded. Default value is
|
4841 |
|
|
200000.
|
4842 |
|
|
|
4843 |
|
|
If LIMIT is a positive number, then GDB will start deleting
|
4844 |
|
|
instructions from the log once the number of the record
|
4845 |
|
|
instructions becomes greater than LIMIT. For every new recorded
|
4846 |
|
|
instruction, GDB will delete the earliest recorded instruction to
|
4847 |
|
|
keep the number of recorded instructions at the limit. (Since
|
4848 |
|
|
deleting recorded instructions loses information, GDB lets you
|
4849 |
|
|
control what happens when the limit is reached, by means of the
|
4850 |
|
|
`stop-at-limit' option, described below.)
|
4851 |
|
|
|
4852 |
|
|
If LIMIT is zero, GDB will never delete recorded instructions from
|
4853 |
|
|
the execution log. The number of recorded instructions is
|
4854 |
|
|
unlimited in this case.
|
4855 |
|
|
|
4856 |
|
|
`show record insn-number-max'
|
4857 |
|
|
Show the limit of instructions to be recorded.
|
4858 |
|
|
|
4859 |
|
|
`set record stop-at-limit'
|
4860 |
|
|
Control the behavior when the number of recorded instructions
|
4861 |
|
|
reaches the limit. If ON (the default), GDB will stop when the
|
4862 |
|
|
limit is reached for the first time and ask you whether you want
|
4863 |
|
|
to stop the inferior or continue running it and recording the
|
4864 |
|
|
execution log. If you decide to continue recording, each new
|
4865 |
|
|
recorded instruction will cause the oldest one to be deleted.
|
4866 |
|
|
|
4867 |
|
|
If this option is OFF, GDB will automatically delete the oldest
|
4868 |
|
|
record to make room for each new one, without asking.
|
4869 |
|
|
|
4870 |
|
|
`show record stop-at-limit'
|
4871 |
|
|
Show the current setting of `stop-at-limit'.
|
4872 |
|
|
|
4873 |
|
|
`set record memory-query'
|
4874 |
|
|
Control the behavior when GDB is unable to record memory changes
|
4875 |
|
|
caused by an instruction. If ON, GDB will query whether to stop
|
4876 |
|
|
the inferior in that case.
|
4877 |
|
|
|
4878 |
|
|
If this option is OFF (the default), GDB will automatically ignore
|
4879 |
|
|
the effect of such instructions on memory. Later, when GDB
|
4880 |
|
|
replays this execution log, it will mark the log of this
|
4881 |
|
|
instruction as not accessible, and it will not affect the replay
|
4882 |
|
|
results.
|
4883 |
|
|
|
4884 |
|
|
`show record memory-query'
|
4885 |
|
|
Show the current setting of `memory-query'.
|
4886 |
|
|
|
4887 |
|
|
`info record'
|
4888 |
|
|
Show various statistics about the state of process record and its
|
4889 |
|
|
in-memory execution log buffer, including:
|
4890 |
|
|
|
4891 |
|
|
* Whether in record mode or replay mode.
|
4892 |
|
|
|
4893 |
|
|
* Lowest recorded instruction number (counting from when the
|
4894 |
|
|
current execution log started recording instructions).
|
4895 |
|
|
|
4896 |
|
|
* Highest recorded instruction number.
|
4897 |
|
|
|
4898 |
|
|
* Current instruction about to be replayed (if in replay mode).
|
4899 |
|
|
|
4900 |
|
|
* Number of instructions contained in the execution log.
|
4901 |
|
|
|
4902 |
|
|
* Maximum number of instructions that may be contained in the
|
4903 |
|
|
execution log.
|
4904 |
|
|
|
4905 |
|
|
`record delete'
|
4906 |
|
|
When record target runs in replay mode ("in the past"), delete the
|
4907 |
|
|
subsequent execution log and begin to record a new execution log
|
4908 |
|
|
starting from the current address. This means you will abandon
|
4909 |
|
|
the previously recorded "future" and begin recording a new
|
4910 |
|
|
"future".
|
4911 |
|
|
|
4912 |
|
|
|
4913 |
|
|
File: gdb.info, Node: Stack, Next: Source, Prev: Process Record and Replay, Up: Top
|
4914 |
|
|
|
4915 |
|
|
8 Examining the Stack
|
4916 |
|
|
*********************
|
4917 |
|
|
|
4918 |
|
|
When your program has stopped, the first thing you need to know is
|
4919 |
|
|
where it stopped and how it got there.
|
4920 |
|
|
|
4921 |
|
|
Each time your program performs a function call, information about
|
4922 |
|
|
the call is generated. That information includes the location of the
|
4923 |
|
|
call in your program, the arguments of the call, and the local
|
4924 |
|
|
variables of the function being called. The information is saved in a
|
4925 |
|
|
block of data called a "stack frame". The stack frames are allocated
|
4926 |
|
|
in a region of memory called the "call stack".
|
4927 |
|
|
|
4928 |
|
|
When your program stops, the GDB commands for examining the stack
|
4929 |
|
|
allow you to see all of this information.
|
4930 |
|
|
|
4931 |
|
|
One of the stack frames is "selected" by GDB and many GDB commands
|
4932 |
|
|
refer implicitly to the selected frame. In particular, whenever you
|
4933 |
|
|
ask GDB for the value of a variable in your program, the value is found
|
4934 |
|
|
in the selected frame. There are special GDB commands to select
|
4935 |
|
|
whichever frame you are interested in. *Note Selecting a Frame:
|
4936 |
|
|
Selection.
|
4937 |
|
|
|
4938 |
|
|
When your program stops, GDB automatically selects the currently
|
4939 |
|
|
executing frame and describes it briefly, similar to the `frame'
|
4940 |
|
|
command (*note Information about a Frame: Frame Info.).
|
4941 |
|
|
|
4942 |
|
|
* Menu:
|
4943 |
|
|
|
4944 |
|
|
* Frames:: Stack frames
|
4945 |
|
|
* Backtrace:: Backtraces
|
4946 |
|
|
* Selection:: Selecting a frame
|
4947 |
|
|
* Frame Info:: Information on a frame
|
4948 |
|
|
|
4949 |
|
|
|
4950 |
|
|
File: gdb.info, Node: Frames, Next: Backtrace, Up: Stack
|
4951 |
|
|
|
4952 |
|
|
8.1 Stack Frames
|
4953 |
|
|
================
|
4954 |
|
|
|
4955 |
|
|
The call stack is divided up into contiguous pieces called "stack
|
4956 |
|
|
frames", or "frames" for short; each frame is the data associated with
|
4957 |
|
|
one call to one function. The frame contains the arguments given to
|
4958 |
|
|
the function, the function's local variables, and the address at which
|
4959 |
|
|
the function is executing.
|
4960 |
|
|
|
4961 |
|
|
When your program is started, the stack has only one frame, that of
|
4962 |
|
|
the function `main'. This is called the "initial" frame or the
|
4963 |
|
|
"outermost" frame. Each time a function is called, a new frame is
|
4964 |
|
|
made. Each time a function returns, the frame for that function
|
4965 |
|
|
invocation is eliminated. If a function is recursive, there can be
|
4966 |
|
|
many frames for the same function. The frame for the function in which
|
4967 |
|
|
execution is actually occurring is called the "innermost" frame. This
|
4968 |
|
|
is the most recently created of all the stack frames that still exist.
|
4969 |
|
|
|
4970 |
|
|
Inside your program, stack frames are identified by their addresses.
|
4971 |
|
|
A stack frame consists of many bytes, each of which has its own
|
4972 |
|
|
address; each kind of computer has a convention for choosing one byte
|
4973 |
|
|
whose address serves as the address of the frame. Usually this address
|
4974 |
|
|
is kept in a register called the "frame pointer register" (*note $fp:
|
4975 |
|
|
Registers.) while execution is going on in that frame.
|
4976 |
|
|
|
4977 |
|
|
GDB assigns numbers to all existing stack frames, starting with zero
|
4978 |
|
|
for the innermost frame, one for the frame that called it, and so on
|
4979 |
|
|
upward. These numbers do not really exist in your program; they are
|
4980 |
|
|
assigned by GDB to give you a way of designating stack frames in GDB
|
4981 |
|
|
commands.
|
4982 |
|
|
|
4983 |
|
|
Some compilers provide a way to compile functions so that they
|
4984 |
|
|
operate without stack frames. (For example, the GCC option
|
4985 |
|
|
`-fomit-frame-pointer'
|
4986 |
|
|
generates functions without a frame.) This is occasionally done
|
4987 |
|
|
with heavily used library functions to save the frame setup time. GDB
|
4988 |
|
|
has limited facilities for dealing with these function invocations. If
|
4989 |
|
|
the innermost function invocation has no stack frame, GDB nevertheless
|
4990 |
|
|
regards it as though it had a separate frame, which is numbered zero as
|
4991 |
|
|
usual, allowing correct tracing of the function call chain. However,
|
4992 |
|
|
GDB has no provision for frameless functions elsewhere in the stack.
|
4993 |
|
|
|
4994 |
|
|
`frame ARGS'
|
4995 |
|
|
The `frame' command allows you to move from one stack frame to
|
4996 |
|
|
another, and to print the stack frame you select. ARGS may be
|
4997 |
|
|
either the address of the frame or the stack frame number.
|
4998 |
|
|
Without an argument, `frame' prints the current stack frame.
|
4999 |
|
|
|
5000 |
|
|
`select-frame'
|
5001 |
|
|
The `select-frame' command allows you to move from one stack frame
|
5002 |
|
|
to another without printing the frame. This is the silent version
|
5003 |
|
|
of `frame'.
|
5004 |
|
|
|
5005 |
|
|
|
5006 |
|
|
File: gdb.info, Node: Backtrace, Next: Selection, Prev: Frames, Up: Stack
|
5007 |
|
|
|
5008 |
|
|
8.2 Backtraces
|
5009 |
|
|
==============
|
5010 |
|
|
|
5011 |
|
|
A backtrace is a summary of how your program got where it is. It shows
|
5012 |
|
|
one line per frame, for many frames, starting with the currently
|
5013 |
|
|
executing frame (frame zero), followed by its caller (frame one), and
|
5014 |
|
|
on up the stack.
|
5015 |
|
|
|
5016 |
|
|
`backtrace'
|
5017 |
|
|
`bt'
|
5018 |
|
|
Print a backtrace of the entire stack: one line per frame for all
|
5019 |
|
|
frames in the stack.
|
5020 |
|
|
|
5021 |
|
|
You can stop the backtrace at any time by typing the system
|
5022 |
|
|
interrupt character, normally `Ctrl-c'.
|
5023 |
|
|
|
5024 |
|
|
`backtrace N'
|
5025 |
|
|
`bt N'
|
5026 |
|
|
Similar, but print only the innermost N frames.
|
5027 |
|
|
|
5028 |
|
|
`backtrace -N'
|
5029 |
|
|
`bt -N'
|
5030 |
|
|
Similar, but print only the outermost N frames.
|
5031 |
|
|
|
5032 |
|
|
`backtrace full'
|
5033 |
|
|
`bt full'
|
5034 |
|
|
`bt full N'
|
5035 |
|
|
`bt full -N'
|
5036 |
|
|
Print the values of the local variables also. N specifies the
|
5037 |
|
|
number of frames to print, as described above.
|
5038 |
|
|
|
5039 |
|
|
The names `where' and `info stack' (abbreviated `info s') are
|
5040 |
|
|
additional aliases for `backtrace'.
|
5041 |
|
|
|
5042 |
|
|
In a multi-threaded program, GDB by default shows the backtrace only
|
5043 |
|
|
for the current thread. To display the backtrace for several or all of
|
5044 |
|
|
the threads, use the command `thread apply' (*note thread apply:
|
5045 |
|
|
Threads.). For example, if you type `thread apply all backtrace', GDB
|
5046 |
|
|
will display the backtrace for all the threads; this is handy when you
|
5047 |
|
|
debug a core dump of a multi-threaded program.
|
5048 |
|
|
|
5049 |
|
|
Each line in the backtrace shows the frame number and the function
|
5050 |
|
|
name. The program counter value is also shown--unless you use `set
|
5051 |
|
|
print address off'. The backtrace also shows the source file name and
|
5052 |
|
|
line number, as well as the arguments to the function. The program
|
5053 |
|
|
counter value is omitted if it is at the beginning of the code for that
|
5054 |
|
|
line number.
|
5055 |
|
|
|
5056 |
|
|
Here is an example of a backtrace. It was made with the command `bt
|
5057 |
|
|
3', so it shows the innermost three frames.
|
5058 |
|
|
|
5059 |
|
|
#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
|
5060 |
|
|
at builtin.c:993
|
5061 |
|
|
#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
|
5062 |
|
|
#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
|
5063 |
|
|
at macro.c:71
|
5064 |
|
|
(More stack frames follow...)
|
5065 |
|
|
|
5066 |
|
|
The display for frame zero does not begin with a program counter value,
|
5067 |
|
|
indicating that your program has stopped at the beginning of the code
|
5068 |
|
|
for line `993' of `builtin.c'.
|
5069 |
|
|
|
5070 |
|
|
The value of parameter `data' in frame 1 has been replaced by `...'.
|
5071 |
|
|
By default, GDB prints the value of a parameter only if it is a scalar
|
5072 |
|
|
(integer, pointer, enumeration, etc). See command `set print
|
5073 |
342 |
jeremybenn |
frame-arguments' in *note Print Settings:: for more details on how to
|
5074 |
330 |
jeremybenn |
configure the way function parameter values are printed.
|
5075 |
|
|
|
5076 |
|
|
If your program was compiled with optimizations, some compilers will
|
5077 |
|
|
optimize away arguments passed to functions if those arguments are
|
5078 |
|
|
never used after the call. Such optimizations generate code that
|
5079 |
|
|
passes arguments through registers, but doesn't store those arguments
|
5080 |
|
|
in the stack frame. GDB has no way of displaying such arguments in
|
5081 |
|
|
stack frames other than the innermost one. Here's what such a
|
5082 |
|
|
backtrace might look like:
|
5083 |
|
|
|
5084 |
|
|
#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
|
5085 |
|
|
at builtin.c:993
|
5086 |
|
|
#1 0x6e38 in expand_macro (sym=) at macro.c:242
|
5087 |
|
|
#2 0x6840 in expand_token (obs=0x0, t=, td=0xf7fffb08)
|
5088 |
|
|
at macro.c:71
|
5089 |
|
|
(More stack frames follow...)
|
5090 |
|
|
|
5091 |
|
|
The values of arguments that were not saved in their stack frames are
|
5092 |
|
|
shown as `'.
|
5093 |
|
|
|
5094 |
|
|
If you need to display the values of such optimized-out arguments,
|
5095 |
|
|
either deduce that from other variables whose values depend on the one
|
5096 |
|
|
you are interested in, or recompile without optimizations.
|
5097 |
|
|
|
5098 |
|
|
Most programs have a standard user entry point--a place where system
|
5099 |
|
|
libraries and startup code transition into user code. For C this is
|
5100 |
|
|
`main'(1). When GDB finds the entry function in a backtrace it will
|
5101 |
|
|
terminate the backtrace, to avoid tracing into highly system-specific
|
5102 |
|
|
(and generally uninteresting) code.
|
5103 |
|
|
|
5104 |
|
|
If you need to examine the startup code, or limit the number of
|
5105 |
|
|
levels in a backtrace, you can change this behavior:
|
5106 |
|
|
|
5107 |
|
|
`set backtrace past-main'
|
5108 |
|
|
`set backtrace past-main on'
|
5109 |
|
|
Backtraces will continue past the user entry point.
|
5110 |
|
|
|
5111 |
|
|
`set backtrace past-main off'
|
5112 |
|
|
Backtraces will stop when they encounter the user entry point.
|
5113 |
|
|
This is the default.
|
5114 |
|
|
|
5115 |
|
|
`show backtrace past-main'
|
5116 |
|
|
Display the current user entry point backtrace policy.
|
5117 |
|
|
|
5118 |
|
|
`set backtrace past-entry'
|
5119 |
|
|
`set backtrace past-entry on'
|
5120 |
|
|
Backtraces will continue past the internal entry point of an
|
5121 |
|
|
application. This entry point is encoded by the linker when the
|
5122 |
|
|
application is built, and is likely before the user entry point
|
5123 |
|
|
`main' (or equivalent) is called.
|
5124 |
|
|
|
5125 |
|
|
`set backtrace past-entry off'
|
5126 |
|
|
Backtraces will stop when they encounter the internal entry point
|
5127 |
|
|
of an application. This is the default.
|
5128 |
|
|
|
5129 |
|
|
`show backtrace past-entry'
|
5130 |
|
|
Display the current internal entry point backtrace policy.
|
5131 |
|
|
|
5132 |
|
|
`set backtrace limit N'
|
5133 |
|
|
`set backtrace limit 0'
|
5134 |
|
|
Limit the backtrace to N levels. A value of zero means unlimited.
|
5135 |
|
|
|
5136 |
|
|
`show backtrace limit'
|
5137 |
|
|
Display the current limit on backtrace levels.
|
5138 |
|
|
|
5139 |
|
|
---------- Footnotes ----------
|
5140 |
|
|
|
5141 |
|
|
(1) Note that embedded programs (the so-called "free-standing"
|
5142 |
|
|
environment) are not required to have a `main' function as the entry
|
5143 |
|
|
point. They could even have multiple entry points.
|
5144 |
|
|
|
5145 |
|
|
|
5146 |
|
|
File: gdb.info, Node: Selection, Next: Frame Info, Prev: Backtrace, Up: Stack
|
5147 |
|
|
|
5148 |
|
|
8.3 Selecting a Frame
|
5149 |
|
|
=====================
|
5150 |
|
|
|
5151 |
|
|
Most commands for examining the stack and other data in your program
|
5152 |
|
|
work on whichever stack frame is selected at the moment. Here are the
|
5153 |
|
|
commands for selecting a stack frame; all of them finish by printing a
|
5154 |
|
|
brief description of the stack frame just selected.
|
5155 |
|
|
|
5156 |
|
|
`frame N'
|
5157 |
|
|
`f N'
|
5158 |
|
|
Select frame number N. Recall that frame zero is the innermost
|
5159 |
|
|
(currently executing) frame, frame one is the frame that called the
|
5160 |
|
|
innermost one, and so on. The highest-numbered frame is the one
|
5161 |
|
|
for `main'.
|
5162 |
|
|
|
5163 |
|
|
`frame ADDR'
|
5164 |
|
|
`f ADDR'
|
5165 |
|
|
Select the frame at address ADDR. This is useful mainly if the
|
5166 |
|
|
chaining of stack frames has been damaged by a bug, making it
|
5167 |
|
|
impossible for GDB to assign numbers properly to all frames. In
|
5168 |
|
|
addition, this can be useful when your program has multiple stacks
|
5169 |
|
|
and switches between them.
|
5170 |
|
|
|
5171 |
|
|
On the SPARC architecture, `frame' needs two addresses to select
|
5172 |
|
|
an arbitrary frame: a frame pointer and a stack pointer.
|
5173 |
|
|
|
5174 |
|
|
On the MIPS and Alpha architecture, it needs two addresses: a stack
|
5175 |
|
|
pointer and a program counter.
|
5176 |
|
|
|
5177 |
|
|
On the 29k architecture, it needs three addresses: a register stack
|
5178 |
|
|
pointer, a program counter, and a memory stack pointer.
|
5179 |
|
|
|
5180 |
|
|
`up N'
|
5181 |
|
|
Move N frames up the stack. For positive numbers N, this advances
|
5182 |
|
|
toward the outermost frame, to higher frame numbers, to frames
|
5183 |
|
|
that have existed longer. N defaults to one.
|
5184 |
|
|
|
5185 |
|
|
`down N'
|
5186 |
|
|
Move N frames down the stack. For positive numbers N, this
|
5187 |
|
|
advances toward the innermost frame, to lower frame numbers, to
|
5188 |
|
|
frames that were created more recently. N defaults to one. You
|
5189 |
|
|
may abbreviate `down' as `do'.
|
5190 |
|
|
|
5191 |
|
|
All of these commands end by printing two lines of output describing
|
5192 |
|
|
the frame. The first line shows the frame number, the function name,
|
5193 |
|
|
the arguments, and the source file and line number of execution in that
|
5194 |
|
|
frame. The second line shows the text of that source line.
|
5195 |
|
|
|
5196 |
|
|
For example:
|
5197 |
|
|
|
5198 |
|
|
(gdb) up
|
5199 |
|
|
#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
|
5200 |
|
|
at env.c:10
|
5201 |
|
|
10 read_input_file (argv[i]);
|
5202 |
|
|
|
5203 |
|
|
After such a printout, the `list' command with no arguments prints
|
5204 |
|
|
ten lines centered on the point of execution in the frame. You can
|
5205 |
|
|
also edit the program at the point of execution with your favorite
|
5206 |
|
|
editing program by typing `edit'. *Note Printing Source Lines: List,
|
5207 |
|
|
for details.
|
5208 |
|
|
|
5209 |
|
|
`up-silently N'
|
5210 |
|
|
`down-silently N'
|
5211 |
|
|
These two commands are variants of `up' and `down', respectively;
|
5212 |
|
|
they differ in that they do their work silently, without causing
|
5213 |
|
|
display of the new frame. They are intended primarily for use in
|
5214 |
|
|
GDB command scripts, where the output might be unnecessary and
|
5215 |
|
|
distracting.
|
5216 |
|
|
|
5217 |
|
|
|
5218 |
|
|
File: gdb.info, Node: Frame Info, Prev: Selection, Up: Stack
|
5219 |
|
|
|
5220 |
|
|
8.4 Information About a Frame
|
5221 |
|
|
=============================
|
5222 |
|
|
|
5223 |
|
|
There are several other commands to print information about the selected
|
5224 |
|
|
stack frame.
|
5225 |
|
|
|
5226 |
|
|
`frame'
|
5227 |
|
|
`f'
|
5228 |
|
|
When used without any argument, this command does not change which
|
5229 |
|
|
frame is selected, but prints a brief description of the currently
|
5230 |
|
|
selected stack frame. It can be abbreviated `f'. With an
|
5231 |
|
|
argument, this command is used to select a stack frame. *Note
|
5232 |
|
|
Selecting a Frame: Selection.
|
5233 |
|
|
|
5234 |
|
|
`info frame'
|
5235 |
|
|
`info f'
|
5236 |
|
|
This command prints a verbose description of the selected stack
|
5237 |
|
|
frame, including:
|
5238 |
|
|
|
5239 |
|
|
* the address of the frame
|
5240 |
|
|
|
5241 |
|
|
* the address of the next frame down (called by this frame)
|
5242 |
|
|
|
5243 |
|
|
* the address of the next frame up (caller of this frame)
|
5244 |
|
|
|
5245 |
|
|
* the language in which the source code corresponding to this
|
5246 |
|
|
frame is written
|
5247 |
|
|
|
5248 |
|
|
* the address of the frame's arguments
|
5249 |
|
|
|
5250 |
|
|
* the address of the frame's local variables
|
5251 |
|
|
|
5252 |
|
|
* the program counter saved in it (the address of execution in
|
5253 |
|
|
the caller frame)
|
5254 |
|
|
|
5255 |
|
|
* which registers were saved in the frame
|
5256 |
|
|
|
5257 |
|
|
The verbose description is useful when something has gone wrong
|
5258 |
|
|
that has made the stack format fail to fit the usual conventions.
|
5259 |
|
|
|
5260 |
|
|
`info frame ADDR'
|
5261 |
|
|
`info f ADDR'
|
5262 |
|
|
Print a verbose description of the frame at address ADDR, without
|
5263 |
|
|
selecting that frame. The selected frame remains unchanged by this
|
5264 |
|
|
command. This requires the same kind of address (more than one
|
5265 |
|
|
for some architectures) that you specify in the `frame' command.
|
5266 |
|
|
*Note Selecting a Frame: Selection.
|
5267 |
|
|
|
5268 |
|
|
`info args'
|
5269 |
|
|
Print the arguments of the selected frame, each on a separate line.
|
5270 |
|
|
|
5271 |
|
|
`info locals'
|
5272 |
|
|
Print the local variables of the selected frame, each on a separate
|
5273 |
|
|
line. These are all variables (declared either static or
|
5274 |
|
|
automatic) accessible at the point of execution of the selected
|
5275 |
|
|
frame.
|
5276 |
|
|
|
5277 |
|
|
`info catch'
|
5278 |
|
|
Print a list of all the exception handlers that are active in the
|
5279 |
|
|
current stack frame at the current point of execution. To see
|
5280 |
|
|
other exception handlers, visit the associated frame (using the
|
5281 |
|
|
`up', `down', or `frame' commands); then type `info catch'. *Note
|
5282 |
|
|
Setting Catchpoints: Set Catchpoints.
|
5283 |
|
|
|
5284 |
|
|
|
5285 |
|
|
|
5286 |
|
|
File: gdb.info, Node: Source, Next: Data, Prev: Stack, Up: Top
|
5287 |
|
|
|
5288 |
|
|
9 Examining Source Files
|
5289 |
|
|
************************
|
5290 |
|
|
|
5291 |
|
|
GDB can print parts of your program's source, since the debugging
|
5292 |
|
|
information recorded in the program tells GDB what source files were
|
5293 |
|
|
used to build it. When your program stops, GDB spontaneously prints
|
5294 |
|
|
the line where it stopped. Likewise, when you select a stack frame
|
5295 |
|
|
(*note Selecting a Frame: Selection.), GDB prints the line where
|
5296 |
|
|
execution in that frame has stopped. You can print other portions of
|
5297 |
|
|
source files by explicit command.
|
5298 |
|
|
|
5299 |
|
|
If you use GDB through its GNU Emacs interface, you may prefer to
|
5300 |
342 |
jeremybenn |
use Emacs facilities to view source; see *note Using GDB under GNU
|
5301 |
330 |
jeremybenn |
Emacs: Emacs.
|
5302 |
|
|
|
5303 |
|
|
* Menu:
|
5304 |
|
|
|
5305 |
|
|
* List:: Printing source lines
|
5306 |
|
|
* Specify Location:: How to specify code locations
|
5307 |
|
|
* Edit:: Editing source files
|
5308 |
|
|
* Search:: Searching source files
|
5309 |
|
|
* Source Path:: Specifying source directories
|
5310 |
|
|
* Machine Code:: Source and machine code
|
5311 |
|
|
|
5312 |
|
|
|
5313 |
|
|
File: gdb.info, Node: List, Next: Specify Location, Up: Source
|
5314 |
|
|
|
5315 |
|
|
9.1 Printing Source Lines
|
5316 |
|
|
=========================
|
5317 |
|
|
|
5318 |
|
|
To print lines from a source file, use the `list' command (abbreviated
|
5319 |
|
|
`l'). By default, ten lines are printed. There are several ways to
|
5320 |
342 |
jeremybenn |
specify what part of the file you want to print; see *note Specify
|
5321 |
330 |
jeremybenn |
Location::, for the full list.
|
5322 |
|
|
|
5323 |
|
|
Here are the forms of the `list' command most commonly used:
|
5324 |
|
|
|
5325 |
|
|
`list LINENUM'
|
5326 |
|
|
Print lines centered around line number LINENUM in the current
|
5327 |
|
|
source file.
|
5328 |
|
|
|
5329 |
|
|
`list FUNCTION'
|
5330 |
|
|
Print lines centered around the beginning of function FUNCTION.
|
5331 |
|
|
|
5332 |
|
|
`list'
|
5333 |
|
|
Print more lines. If the last lines printed were printed with a
|
5334 |
|
|
`list' command, this prints lines following the last lines
|
5335 |
|
|
printed; however, if the last line printed was a solitary line
|
5336 |
|
|
printed as part of displaying a stack frame (*note Examining the
|
5337 |
|
|
Stack: Stack.), this prints lines centered around that line.
|
5338 |
|
|
|
5339 |
|
|
`list -'
|
5340 |
|
|
Print lines just before the lines last printed.
|
5341 |
|
|
|
5342 |
|
|
By default, GDB prints ten source lines with any of these forms of
|
5343 |
|
|
the `list' command. You can change this using `set listsize':
|
5344 |
|
|
|
5345 |
|
|
`set listsize COUNT'
|
5346 |
|
|
Make the `list' command display COUNT source lines (unless the
|
5347 |
|
|
`list' argument explicitly specifies some other number).
|
5348 |
|
|
|
5349 |
|
|
`show listsize'
|
5350 |
|
|
Display the number of lines that `list' prints.
|
5351 |
|
|
|
5352 |
|
|
Repeating a `list' command with discards the argument, so it
|
5353 |
|
|
is equivalent to typing just `list'. This is more useful than listing
|
5354 |
|
|
the same lines again. An exception is made for an argument of `-';
|
5355 |
|
|
that argument is preserved in repetition so that each repetition moves
|
5356 |
|
|
up in the source file.
|
5357 |
|
|
|
5358 |
|
|
In general, the `list' command expects you to supply zero, one or two
|
5359 |
|
|
"linespecs". Linespecs specify source lines; there are several ways of
|
5360 |
|
|
writing them (*note Specify Location::), but the effect is always to
|
5361 |
|
|
specify some source line.
|
5362 |
|
|
|
5363 |
|
|
Here is a complete description of the possible arguments for `list':
|
5364 |
|
|
|
5365 |
|
|
`list LINESPEC'
|
5366 |
|
|
Print lines centered around the line specified by LINESPEC.
|
5367 |
|
|
|
5368 |
|
|
`list FIRST,LAST'
|
5369 |
|
|
Print lines from FIRST to LAST. Both arguments are linespecs.
|
5370 |
|
|
When a `list' command has two linespecs, and the source file of
|
5371 |
|
|
the second linespec is omitted, this refers to the same source
|
5372 |
|
|
file as the first linespec.
|
5373 |
|
|
|
5374 |
|
|
`list ,LAST'
|
5375 |
|
|
Print lines ending with LAST.
|
5376 |
|
|
|
5377 |
|
|
`list FIRST,'
|
5378 |
|
|
Print lines starting with FIRST.
|
5379 |
|
|
|
5380 |
|
|
`list +'
|
5381 |
|
|
Print lines just after the lines last printed.
|
5382 |
|
|
|
5383 |
|
|
`list -'
|
5384 |
|
|
Print lines just before the lines last printed.
|
5385 |
|
|
|
5386 |
|
|
`list'
|
5387 |
|
|
As described in the preceding table.
|
5388 |
|
|
|
5389 |
|
|
|
5390 |
|
|
File: gdb.info, Node: Specify Location, Next: Edit, Prev: List, Up: Source
|
5391 |
|
|
|
5392 |
|
|
9.2 Specifying a Location
|
5393 |
|
|
=========================
|
5394 |
|
|
|
5395 |
|
|
Several GDB commands accept arguments that specify a location of your
|
5396 |
|
|
program's code. Since GDB is a source-level debugger, a location
|
5397 |
|
|
usually specifies some line in the source code; for that reason,
|
5398 |
|
|
locations are also known as "linespecs".
|
5399 |
|
|
|
5400 |
|
|
Here are all the different ways of specifying a code location that
|
5401 |
|
|
GDB understands:
|
5402 |
|
|
|
5403 |
|
|
`LINENUM'
|
5404 |
|
|
Specifies the line number LINENUM of the current source file.
|
5405 |
|
|
|
5406 |
|
|
`-OFFSET'
|
5407 |
|
|
`+OFFSET'
|
5408 |
|
|
Specifies the line OFFSET lines before or after the "current
|
5409 |
|
|
line". For the `list' command, the current line is the last one
|
5410 |
|
|
printed; for the breakpoint commands, this is the line at which
|
5411 |
|
|
execution stopped in the currently selected "stack frame" (*note
|
5412 |
|
|
Frames: Frames, for a description of stack frames.) When used as
|
5413 |
|
|
the second of the two linespecs in a `list' command, this
|
5414 |
|
|
specifies the line OFFSET lines up or down from the first linespec.
|
5415 |
|
|
|
5416 |
|
|
`FILENAME:LINENUM'
|
5417 |
|
|
Specifies the line LINENUM in the source file FILENAME.
|
5418 |
|
|
|
5419 |
|
|
`FUNCTION'
|
5420 |
|
|
Specifies the line that begins the body of the function FUNCTION.
|
5421 |
|
|
For example, in C, this is the line with the open brace.
|
5422 |
|
|
|
5423 |
|
|
`FILENAME:FUNCTION'
|
5424 |
|
|
Specifies the line that begins the body of the function FUNCTION
|
5425 |
|
|
in the file FILENAME. You only need the file name with a function
|
5426 |
|
|
name to avoid ambiguity when there are identically named functions
|
5427 |
|
|
in different source files.
|
5428 |
|
|
|
5429 |
|
|
`*ADDRESS'
|
5430 |
|
|
Specifies the program address ADDRESS. For line-oriented
|
5431 |
|
|
commands, such as `list' and `edit', this specifies a source line
|
5432 |
|
|
that contains ADDRESS. For `break' and other breakpoint oriented
|
5433 |
|
|
commands, this can be used to set breakpoints in parts of your
|
5434 |
|
|
program which do not have debugging information or source files.
|
5435 |
|
|
|
5436 |
|
|
Here ADDRESS may be any expression valid in the current working
|
5437 |
|
|
language (*note working language: Languages.) that specifies a code
|
5438 |
|
|
address. In addition, as a convenience, GDB extends the semantics
|
5439 |
|
|
of expressions used in locations to cover the situations that
|
5440 |
|
|
frequently happen during debugging. Here are the various forms of
|
5441 |
|
|
ADDRESS:
|
5442 |
|
|
|
5443 |
|
|
`EXPRESSION'
|
5444 |
|
|
Any expression valid in the current working language.
|
5445 |
|
|
|
5446 |
|
|
`FUNCADDR'
|
5447 |
|
|
An address of a function or procedure derived from its name.
|
5448 |
|
|
In C, C++, Java, Objective-C, Fortran, minimal, and assembly,
|
5449 |
|
|
this is simply the function's name FUNCTION (and actually a
|
5450 |
|
|
special case of a valid expression). In Pascal and Modula-2,
|
5451 |
|
|
this is `&FUNCTION'. In Ada, this is `FUNCTION'Address'
|
5452 |
|
|
(although the Pascal form also works).
|
5453 |
|
|
|
5454 |
|
|
This form specifies the address of the function's first
|
5455 |
|
|
instruction, before the stack frame and arguments have been
|
5456 |
|
|
set up.
|
5457 |
|
|
|
5458 |
|
|
`'FILENAME'::FUNCADDR'
|
5459 |
|
|
Like FUNCADDR above, but also specifies the name of the source
|
5460 |
|
|
file explicitly. This is useful if the name of the function
|
5461 |
|
|
does not specify the function unambiguously, e.g., if there
|
5462 |
|
|
are several functions with identical names in different
|
5463 |
|
|
source files.
|
5464 |
|
|
|
5465 |
|
|
|
5466 |
|
|
|
5467 |
|
|
File: gdb.info, Node: Edit, Next: Search, Prev: Specify Location, Up: Source
|
5468 |
|
|
|
5469 |
|
|
9.3 Editing Source Files
|
5470 |
|
|
========================
|
5471 |
|
|
|
5472 |
|
|
To edit the lines in a source file, use the `edit' command. The
|
5473 |
|
|
editing program of your choice is invoked with the current line set to
|
5474 |
|
|
the active line in the program. Alternatively, there are several ways
|
5475 |
|
|
to specify what part of the file you want to print if you want to see
|
5476 |
|
|
other parts of the program:
|
5477 |
|
|
|
5478 |
|
|
`edit LOCATION'
|
5479 |
|
|
Edit the source file specified by `location'. Editing starts at
|
5480 |
|
|
that LOCATION, e.g., at the specified source line of the specified
|
5481 |
|
|
file. *Note Specify Location::, for all the possible forms of the
|
5482 |
|
|
LOCATION argument; here are the forms of the `edit' command most
|
5483 |
|
|
commonly used:
|
5484 |
|
|
|
5485 |
|
|
`edit NUMBER'
|
5486 |
|
|
Edit the current source file with NUMBER as the active line
|
5487 |
|
|
number.
|
5488 |
|
|
|
5489 |
|
|
`edit FUNCTION'
|
5490 |
|
|
Edit the file containing FUNCTION at the beginning of its
|
5491 |
|
|
definition.
|
5492 |
|
|
|
5493 |
|
|
|
5494 |
|
|
9.3.1 Choosing your Editor
|
5495 |
|
|
--------------------------
|
5496 |
|
|
|
5497 |
|
|
You can customize GDB to use any editor you want (1). By default, it
|
5498 |
|
|
is `/bin/ex', but you can change this by setting the environment
|
5499 |
|
|
variable `EDITOR' before using GDB. For example, to configure GDB to
|
5500 |
|
|
use the `vi' editor, you could use these commands with the `sh' shell:
|
5501 |
|
|
EDITOR=/usr/bin/vi
|
5502 |
|
|
export EDITOR
|
5503 |
|
|
gdb ...
|
5504 |
|
|
or in the `csh' shell,
|
5505 |
|
|
setenv EDITOR /usr/bin/vi
|
5506 |
|
|
gdb ...
|
5507 |
|
|
|
5508 |
|
|
---------- Footnotes ----------
|
5509 |
|
|
|
5510 |
|
|
(1) The only restriction is that your editor (say `ex'), recognizes
|
5511 |
|
|
the following command-line syntax:
|
5512 |
|
|
ex +NUMBER file
|
5513 |
|
|
The optional numeric value +NUMBER specifies the number of the line
|
5514 |
|
|
in the file where to start editing.
|
5515 |
|
|
|
5516 |
|
|
|
5517 |
|
|
File: gdb.info, Node: Search, Next: Source Path, Prev: Edit, Up: Source
|
5518 |
|
|
|
5519 |
|
|
9.4 Searching Source Files
|
5520 |
|
|
==========================
|
5521 |
|
|
|
5522 |
|
|
There are two commands for searching through the current source file
|
5523 |
|
|
for a regular expression.
|
5524 |
|
|
|
5525 |
|
|
`forward-search REGEXP'
|
5526 |
|
|
`search REGEXP'
|
5527 |
|
|
The command `forward-search REGEXP' checks each line, starting
|
5528 |
|
|
with the one following the last line listed, for a match for
|
5529 |
|
|
REGEXP. It lists the line that is found. You can use the synonym
|
5530 |
|
|
`search REGEXP' or abbreviate the command name as `fo'.
|
5531 |
|
|
|
5532 |
|
|
`reverse-search REGEXP'
|
5533 |
|
|
The command `reverse-search REGEXP' checks each line, starting
|
5534 |
|
|
with the one before the last line listed and going backward, for a
|
5535 |
|
|
match for REGEXP. It lists the line that is found. You can
|
5536 |
|
|
abbreviate this command as `rev'.
|
5537 |
|
|
|
5538 |
|
|
|
5539 |
|
|
File: gdb.info, Node: Source Path, Next: Machine Code, Prev: Search, Up: Source
|
5540 |
|
|
|
5541 |
|
|
9.5 Specifying Source Directories
|
5542 |
|
|
=================================
|
5543 |
|
|
|
5544 |
|
|
Executable programs sometimes do not record the directories of the
|
5545 |
|
|
source files from which they were compiled, just the names. Even when
|
5546 |
|
|
they do, the directories could be moved between the compilation and
|
5547 |
|
|
your debugging session. GDB has a list of directories to search for
|
5548 |
|
|
source files; this is called the "source path". Each time GDB wants a
|
5549 |
|
|
source file, it tries all the directories in the list, in the order
|
5550 |
|
|
they are present in the list, until it finds a file with the desired
|
5551 |
|
|
name.
|
5552 |
|
|
|
5553 |
|
|
For example, suppose an executable references the file
|
5554 |
|
|
`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'. The
|
5555 |
|
|
file is first looked up literally; if this fails,
|
5556 |
|
|
`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
|
5557 |
|
|
`/mnt/cross/foo.c' is opened; if this fails, an error message is
|
5558 |
|
|
printed. GDB does not look up the parts of the source file name, such
|
5559 |
|
|
as `/mnt/cross/src/foo-1.0/lib/foo.c'. Likewise, the subdirectories of
|
5560 |
|
|
the source path are not searched: if the source path is `/mnt/cross',
|
5561 |
|
|
and the binary refers to `foo.c', GDB would not find it under
|
5562 |
|
|
`/mnt/cross/usr/src/foo-1.0/lib'.
|
5563 |
|
|
|
5564 |
|
|
Plain file names, relative file names with leading directories, file
|
5565 |
|
|
names containing dots, etc. are all treated as described above; for
|
5566 |
|
|
instance, if the source path is `/mnt/cross', and the source file is
|
5567 |
|
|
recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
|
5568 |
|
|
`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
|
5569 |
|
|
|
5570 |
|
|
Note that the executable search path is _not_ used to locate the
|
5571 |
|
|
source files.
|
5572 |
|
|
|
5573 |
|
|
Whenever you reset or rearrange the source path, GDB clears out any
|
5574 |
|
|
information it has cached about where source files are found and where
|
5575 |
|
|
each line is in the file.
|
5576 |
|
|
|
5577 |
|
|
When you start GDB, its source path includes only `cdir' and `cwd',
|
5578 |
|
|
in that order. To add other directories, use the `directory' command.
|
5579 |
|
|
|
5580 |
|
|
The search path is used to find both program source files and GDB
|
5581 |
|
|
script files (read using the `-command' option and `source' command).
|
5582 |
|
|
|
5583 |
|
|
In addition to the source path, GDB provides a set of commands that
|
5584 |
|
|
manage a list of source path substitution rules. A "substitution rule"
|
5585 |
|
|
specifies how to rewrite source directories stored in the program's
|
5586 |
|
|
debug information in case the sources were moved to a different
|
5587 |
|
|
directory between compilation and debugging. A rule is made of two
|
5588 |
|
|
strings, the first specifying what needs to be rewritten in the path,
|
5589 |
342 |
jeremybenn |
and the second specifying how it should be rewritten. In *note set
|
5590 |
330 |
jeremybenn |
substitute-path::, we name these two parts FROM and TO respectively.
|
5591 |
|
|
GDB does a simple string replacement of FROM with TO at the start of
|
5592 |
|
|
the directory part of the source file name, and uses that result
|
5593 |
|
|
instead of the original file name to look up the sources.
|
5594 |
|
|
|
5595 |
|
|
Using the previous example, suppose the `foo-1.0' tree has been
|
5596 |
|
|
moved from `/usr/src' to `/mnt/cross', then you can tell GDB to replace
|
5597 |
|
|
`/usr/src' in all source path names with `/mnt/cross'. The first
|
5598 |
|
|
lookup will then be `/mnt/cross/foo-1.0/lib/foo.c' in place of the
|
5599 |
|
|
original location of `/usr/src/foo-1.0/lib/foo.c'. To define a source
|
5600 |
|
|
path substitution rule, use the `set substitute-path' command (*note
|
5601 |
|
|
set substitute-path::).
|
5602 |
|
|
|
5603 |
|
|
To avoid unexpected substitution results, a rule is applied only if
|
5604 |
|
|
the FROM part of the directory name ends at a directory separator. For
|
5605 |
|
|
instance, a rule substituting `/usr/source' into `/mnt/cross' will be
|
5606 |
|
|
applied to `/usr/source/foo-1.0' but not to `/usr/sourceware/foo-2.0'.
|
5607 |
|
|
And because the substitution is applied only at the beginning of the
|
5608 |
|
|
directory name, this rule will not be applied to
|
5609 |
|
|
`/root/usr/source/baz.c' either.
|
5610 |
|
|
|
5611 |
|
|
In many cases, you can achieve the same result using the `directory'
|
5612 |
|
|
command. However, `set substitute-path' can be more efficient in the
|
5613 |
|
|
case where the sources are organized in a complex tree with multiple
|
5614 |
|
|
subdirectories. With the `directory' command, you need to add each
|
5615 |
|
|
subdirectory of your project. If you moved the entire tree while
|
5616 |
|
|
preserving its internal organization, then `set substitute-path' allows
|
5617 |
|
|
you to direct the debugger to all the sources with one single command.
|
5618 |
|
|
|
5619 |
|
|
`set substitute-path' is also more than just a shortcut command.
|
5620 |
|
|
The source path is only used if the file at the original location no
|
5621 |
|
|
longer exists. On the other hand, `set substitute-path' modifies the
|
5622 |
|
|
debugger behavior to look at the rewritten location instead. So, if
|
5623 |
|
|
for any reason a source file that is not relevant to your executable is
|
5624 |
|
|
located at the original location, a substitution rule is the only
|
5625 |
|
|
method available to point GDB at the new location.
|
5626 |
|
|
|
5627 |
|
|
You can configure a default source path substitution rule by
|
5628 |
|
|
configuring GDB with the `--with-relocated-sources=DIR' option. The DIR
|
5629 |
|
|
should be the name of a directory under GDB's configured prefix (set
|
5630 |
|
|
with `--prefix' or `--exec-prefix'), and directory names in debug
|
5631 |
|
|
information under DIR will be adjusted automatically if the installed
|
5632 |
|
|
GDB is moved to a new location. This is useful if GDB, libraries or
|
5633 |
|
|
executables with debug information and corresponding source code are
|
5634 |
|
|
being moved together.
|
5635 |
|
|
|
5636 |
|
|
`directory DIRNAME ...'
|
5637 |
|
|
|
5638 |
|
|
`dir DIRNAME ...'
|
5639 |
|
|
Add directory DIRNAME to the front of the source path. Several
|
5640 |
|
|
directory names may be given to this command, separated by `:'
|
5641 |
|
|
(`;' on MS-DOS and MS-Windows, where `:' usually appears as part
|
5642 |
|
|
of absolute file names) or whitespace. You may specify a
|
5643 |
|
|
directory that is already in the source path; this moves it
|
5644 |
|
|
forward, so GDB searches it sooner.
|
5645 |
|
|
|
5646 |
|
|
You can use the string `$cdir' to refer to the compilation
|
5647 |
|
|
directory (if one is recorded), and `$cwd' to refer to the current
|
5648 |
|
|
working directory. `$cwd' is not the same as `.'--the former
|
5649 |
|
|
tracks the current working directory as it changes during your GDB
|
5650 |
|
|
session, while the latter is immediately expanded to the current
|
5651 |
|
|
directory at the time you add an entry to the source path.
|
5652 |
|
|
|
5653 |
|
|
`directory'
|
5654 |
|
|
Reset the source path to its default value (`$cdir:$cwd' on Unix
|
5655 |
|
|
systems). This requires confirmation.
|
5656 |
|
|
|
5657 |
|
|
`show directories'
|
5658 |
|
|
Print the source path: show which directories it contains.
|
5659 |
|
|
|
5660 |
|
|
`set substitute-path FROM TO'
|
5661 |
|
|
Define a source path substitution rule, and add it at the end of
|
5662 |
|
|
the current list of existing substitution rules. If a rule with
|
5663 |
|
|
the same FROM was already defined, then the old rule is also
|
5664 |
|
|
deleted.
|
5665 |
|
|
|
5666 |
|
|
For example, if the file `/foo/bar/baz.c' was moved to
|
5667 |
|
|
`/mnt/cross/baz.c', then the command
|
5668 |
|
|
|
5669 |
|
|
(gdb) set substitute-path /usr/src /mnt/cross
|
5670 |
|
|
|
5671 |
|
|
will tell GDB to replace `/usr/src' with `/mnt/cross', which will
|
5672 |
|
|
allow GDB to find the file `baz.c' even though it was moved.
|
5673 |
|
|
|
5674 |
|
|
In the case when more than one substitution rule have been defined,
|
5675 |
|
|
the rules are evaluated one by one in the order where they have
|
5676 |
|
|
been defined. The first one matching, if any, is selected to
|
5677 |
|
|
perform the substitution.
|
5678 |
|
|
|
5679 |
|
|
For instance, if we had entered the following commands:
|
5680 |
|
|
|
5681 |
|
|
(gdb) set substitute-path /usr/src/include /mnt/include
|
5682 |
|
|
(gdb) set substitute-path /usr/src /mnt/src
|
5683 |
|
|
|
5684 |
|
|
GDB would then rewrite `/usr/src/include/defs.h' into
|
5685 |
|
|
`/mnt/include/defs.h' by using the first rule. However, it would
|
5686 |
|
|
use the second rule to rewrite `/usr/src/lib/foo.c' into
|
5687 |
|
|
`/mnt/src/lib/foo.c'.
|
5688 |
|
|
|
5689 |
|
|
`unset substitute-path [path]'
|
5690 |
|
|
If a path is specified, search the current list of substitution
|
5691 |
|
|
rules for a rule that would rewrite that path. Delete that rule
|
5692 |
|
|
if found. A warning is emitted by the debugger if no rule could
|
5693 |
|
|
be found.
|
5694 |
|
|
|
5695 |
|
|
If no path is specified, then all substitution rules are deleted.
|
5696 |
|
|
|
5697 |
|
|
`show substitute-path [path]'
|
5698 |
|
|
If a path is specified, then print the source path substitution
|
5699 |
|
|
rule which would rewrite that path, if any.
|
5700 |
|
|
|
5701 |
|
|
If no path is specified, then print all existing source path
|
5702 |
|
|
substitution rules.
|
5703 |
|
|
|
5704 |
|
|
|
5705 |
|
|
If your source path is cluttered with directories that are no longer
|
5706 |
|
|
of interest, GDB may sometimes cause confusion by finding the wrong
|
5707 |
|
|
versions of source. You can correct the situation as follows:
|
5708 |
|
|
|
5709 |
|
|
1. Use `directory' with no argument to reset the source path to its
|
5710 |
|
|
default value.
|
5711 |
|
|
|
5712 |
|
|
2. Use `directory' with suitable arguments to reinstall the
|
5713 |
|
|
directories you want in the source path. You can add all the
|
5714 |
|
|
directories in one command.
|
5715 |
|
|
|
5716 |
|
|
|
5717 |
|
|
File: gdb.info, Node: Machine Code, Prev: Source Path, Up: Source
|
5718 |
|
|
|
5719 |
|
|
9.6 Source and Machine Code
|
5720 |
|
|
===========================
|
5721 |
|
|
|
5722 |
|
|
You can use the command `info line' to map source lines to program
|
5723 |
|
|
addresses (and vice versa), and the command `disassemble' to display a
|
5724 |
|
|
range of addresses as machine instructions. You can use the command
|
5725 |
|
|
`set disassemble-next-line' to set whether to disassemble next source
|
5726 |
|
|
line when execution stops. When run under GNU Emacs mode, the `info
|
5727 |
|
|
line' command causes the arrow to point to the line specified. Also,
|
5728 |
|
|
`info line' prints addresses in symbolic form as well as hex.
|
5729 |
|
|
|
5730 |
|
|
`info line LINESPEC'
|
5731 |
|
|
Print the starting and ending addresses of the compiled code for
|
5732 |
|
|
source line LINESPEC. You can specify source lines in any of the
|
5733 |
342 |
jeremybenn |
ways documented in *note Specify Location::.
|
5734 |
330 |
jeremybenn |
|
5735 |
|
|
For example, we can use `info line' to discover the location of the
|
5736 |
|
|
object code for the first line of function `m4_changequote':
|
5737 |
|
|
|
5738 |
|
|
(gdb) info line m4_changequote
|
5739 |
|
|
Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
|
5740 |
|
|
|
5741 |
|
|
We can also inquire (using `*ADDR' as the form for LINESPEC) what
|
5742 |
|
|
source line covers a particular address:
|
5743 |
|
|
(gdb) info line *0x63ff
|
5744 |
|
|
Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
|
5745 |
|
|
|
5746 |
|
|
After `info line', the default address for the `x' command is
|
5747 |
|
|
changed to the starting address of the line, so that `x/i' is
|
5748 |
|
|
sufficient to begin examining the machine code (*note Examining Memory:
|
5749 |
|
|
Memory.). Also, this address is saved as the value of the convenience
|
5750 |
|
|
variable `$_' (*note Convenience Variables: Convenience Vars.).
|
5751 |
|
|
|
5752 |
|
|
`disassemble'
|
5753 |
|
|
`disassemble /m'
|
5754 |
|
|
`disassemble /r'
|
5755 |
|
|
This specialized command dumps a range of memory as machine
|
5756 |
|
|
instructions. It can also print mixed source+disassembly by
|
5757 |
|
|
specifying the `/m' modifier and print the raw instructions in hex
|
5758 |
|
|
as well as in symbolic form by specifying the `/r'. The default
|
5759 |
|
|
memory range is the function surrounding the program counter of
|
5760 |
|
|
the selected frame. A single argument to this command is a
|
5761 |
|
|
program counter value; GDB dumps the function surrounding this
|
5762 |
|
|
value. When two arguments are given, they should be separated by
|
5763 |
|
|
a comma, possibly surrounded by whitespace. The arguments specify
|
5764 |
|
|
a range of addresses to dump, in one of two forms:
|
5765 |
|
|
|
5766 |
|
|
`START,END'
|
5767 |
|
|
the addresses from START (inclusive) to END (exclusive)
|
5768 |
|
|
|
5769 |
|
|
`START,+LENGTH'
|
5770 |
|
|
the addresses from START (inclusive) to `START+LENGTH'
|
5771 |
|
|
(exclusive).
|
5772 |
|
|
|
5773 |
|
|
When 2 arguments are specified, the name of the function is also
|
5774 |
|
|
printed (since there could be several functions in the given
|
5775 |
|
|
range).
|
5776 |
|
|
|
5777 |
|
|
The argument(s) can be any expression yielding a numeric value,
|
5778 |
|
|
such as `0x32c4', `&main+10' or `$pc - 8'.
|
5779 |
|
|
|
5780 |
|
|
If the range of memory being disassembled contains current program
|
5781 |
|
|
counter, the instruction at that location is shown with a `=>'
|
5782 |
|
|
marker.
|
5783 |
|
|
|
5784 |
|
|
The following example shows the disassembly of a range of addresses
|
5785 |
|
|
of HP PA-RISC 2.0 code:
|
5786 |
|
|
|
5787 |
|
|
(gdb) disas 0x32c4, 0x32e4
|
5788 |
|
|
Dump of assembler code from 0x32c4 to 0x32e4:
|
5789 |
|
|
0x32c4 : addil 0,dp
|
5790 |
|
|
0x32c8 : ldw 0x22c(sr0,r1),r26
|
5791 |
|
|
0x32cc : ldil 0x3000,r31
|
5792 |
|
|
0x32d0 : ble 0x3f8(sr4,r31)
|
5793 |
|
|
0x32d4 : ldo 0(r31),rp
|
5794 |
|
|
0x32d8 : addil -0x800,dp
|
5795 |
|
|
0x32dc : ldo 0x588(r1),r26
|
5796 |
|
|
0x32e0 : ldil 0x3000,r31
|
5797 |
|
|
End of assembler dump.
|
5798 |
|
|
|
5799 |
|
|
Here is an example showing mixed source+assembly for Intel x86, when
|
5800 |
|
|
the program is stopped just after function prologue:
|
5801 |
|
|
|
5802 |
|
|
(gdb) disas /m main
|
5803 |
|
|
Dump of assembler code for function main:
|
5804 |
|
|
5 {
|
5805 |
|
|
0x08048330 <+0>: push %ebp
|
5806 |
|
|
0x08048331 <+1>: mov %esp,%ebp
|
5807 |
|
|
0x08048333 <+3>: sub $0x8,%esp
|
5808 |
|
|
0x08048336 <+6>: and $0xfffffff0,%esp
|
5809 |
|
|
0x08048339 <+9>: sub $0x10,%esp
|
5810 |
|
|
|
5811 |
|
|
6 printf ("Hello.\n");
|
5812 |
|
|
=> 0x0804833c <+12>: movl $0x8048440,(%esp)
|
5813 |
|
|
0x08048343 <+19>: call 0x8048284
|
5814 |
|
|
|
5815 |
|
|
7 return 0;
|
5816 |
|
|
8 }
|
5817 |
|
|
0x08048348 <+24>: mov $0x0,%eax
|
5818 |
|
|
0x0804834d <+29>: leave
|
5819 |
|
|
0x0804834e <+30>: ret
|
5820 |
|
|
|
5821 |
|
|
End of assembler dump.
|
5822 |
|
|
|
5823 |
|
|
Here is another example showing raw instructions in hex for AMD
|
5824 |
|
|
x86-64,
|
5825 |
|
|
|
5826 |
|
|
(gdb) disas /r 0x400281,+10
|
5827 |
|
|
Dump of assembler code from 0x400281 to 0x40028b:
|
5828 |
|
|
0x0000000000400281: 38 36 cmp %dh,(%rsi)
|
5829 |
|
|
0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
|
5830 |
|
|
0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
|
5831 |
|
|
0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
|
5832 |
|
|
End of assembler dump.
|
5833 |
|
|
|
5834 |
|
|
Some architectures have more than one commonly-used set of
|
5835 |
|
|
instruction mnemonics or other syntax.
|
5836 |
|
|
|
5837 |
|
|
For programs that were dynamically linked and use shared libraries,
|
5838 |
|
|
instructions that call functions or branch to locations in the shared
|
5839 |
|
|
libraries might show a seemingly bogus location--it's actually a
|
5840 |
|
|
location of the relocation table. On some architectures, GDB might be
|
5841 |
|
|
able to resolve these to actual function names.
|
5842 |
|
|
|
5843 |
|
|
`set disassembly-flavor INSTRUCTION-SET'
|
5844 |
|
|
Select the instruction set to use when disassembling the program
|
5845 |
|
|
via the `disassemble' or `x/i' commands.
|
5846 |
|
|
|
5847 |
|
|
Currently this command is only defined for the Intel x86 family.
|
5848 |
|
|
You can set INSTRUCTION-SET to either `intel' or `att'. The
|
5849 |
|
|
default is `att', the AT&T flavor used by default by Unix
|
5850 |
|
|
assemblers for x86-based targets.
|
5851 |
|
|
|
5852 |
|
|
`show disassembly-flavor'
|
5853 |
|
|
Show the current setting of the disassembly flavor.
|
5854 |
|
|
|
5855 |
|
|
`set disassemble-next-line'
|
5856 |
|
|
`show disassemble-next-line'
|
5857 |
|
|
Control whether or not GDB will disassemble the next source line
|
5858 |
|
|
or instruction when execution stops. If ON, GDB will display
|
5859 |
|
|
disassembly of the next source line when execution of the program
|
5860 |
|
|
being debugged stops. This is _in addition_ to displaying the
|
5861 |
|
|
source line itself, which GDB always does if possible. If the
|
5862 |
|
|
next source line cannot be displayed for some reason (e.g., if GDB
|
5863 |
|
|
cannot find the source file, or there's no line info in the debug
|
5864 |
|
|
info), GDB will display disassembly of the next _instruction_
|
5865 |
|
|
instead of showing the next source line. If AUTO, GDB will
|
5866 |
|
|
display disassembly of next instruction only if the source line
|
5867 |
|
|
cannot be displayed. This setting causes GDB to display some
|
5868 |
|
|
feedback when you step through a function with no line info or
|
5869 |
|
|
whose source file is unavailable. The default is OFF, which means
|
5870 |
|
|
never display the disassembly of the next line or instruction.
|
5871 |
|
|
|
5872 |
|
|
|
5873 |
|
|
File: gdb.info, Node: Data, Next: Optimized Code, Prev: Source, Up: Top
|
5874 |
|
|
|
5875 |
|
|
10 Examining Data
|
5876 |
|
|
*****************
|
5877 |
|
|
|
5878 |
|
|
The usual way to examine data in your program is with the `print'
|
5879 |
|
|
command (abbreviated `p'), or its synonym `inspect'. It evaluates and
|
5880 |
|
|
prints the value of an expression of the language your program is
|
5881 |
|
|
written in (*note Using GDB with Different Languages: Languages.). It
|
5882 |
|
|
may also print the expression using a Python-based pretty-printer
|
5883 |
|
|
(*note Pretty Printing::).
|
5884 |
|
|
|
5885 |
|
|
`print EXPR'
|
5886 |
|
|
`print /F EXPR'
|
5887 |
|
|
EXPR is an expression (in the source language). By default the
|
5888 |
|
|
value of EXPR is printed in a format appropriate to its data type;
|
5889 |
|
|
you can choose a different format by specifying `/F', where F is a
|
5890 |
342 |
jeremybenn |
letter specifying the format; see *note Output Formats: Output
|
5891 |
330 |
jeremybenn |
Formats.
|
5892 |
|
|
|
5893 |
|
|
`print'
|
5894 |
|
|
`print /F'
|
5895 |
|
|
If you omit EXPR, GDB displays the last value again (from the
|
5896 |
|
|
"value history"; *note Value History: Value History.). This
|
5897 |
|
|
allows you to conveniently inspect the same value in an
|
5898 |
|
|
alternative format.
|
5899 |
|
|
|
5900 |
|
|
A more low-level way of examining data is with the `x' command. It
|
5901 |
|
|
examines data in memory at a specified address and prints it in a
|
5902 |
|
|
specified format. *Note Examining Memory: Memory.
|
5903 |
|
|
|
5904 |
|
|
If you are interested in information about types, or about how the
|
5905 |
|
|
fields of a struct or a class are declared, use the `ptype EXP' command
|
5906 |
|
|
rather than `print'. *Note Examining the Symbol Table: Symbols.
|
5907 |
|
|
|
5908 |
|
|
* Menu:
|
5909 |
|
|
|
5910 |
|
|
* Expressions:: Expressions
|
5911 |
|
|
* Ambiguous Expressions:: Ambiguous Expressions
|
5912 |
|
|
* Variables:: Program variables
|
5913 |
|
|
* Arrays:: Artificial arrays
|
5914 |
|
|
* Output Formats:: Output formats
|
5915 |
|
|
* Memory:: Examining memory
|
5916 |
|
|
* Auto Display:: Automatic display
|
5917 |
|
|
* Print Settings:: Print settings
|
5918 |
|
|
* Pretty Printing:: Python pretty printing
|
5919 |
|
|
* Value History:: Value history
|
5920 |
|
|
* Convenience Vars:: Convenience variables
|
5921 |
|
|
* Registers:: Registers
|
5922 |
|
|
* Floating Point Hardware:: Floating point hardware
|
5923 |
|
|
* Vector Unit:: Vector Unit
|
5924 |
|
|
* OS Information:: Auxiliary data provided by operating system
|
5925 |
|
|
* Memory Region Attributes:: Memory region attributes
|
5926 |
|
|
* Dump/Restore Files:: Copy between memory and a file
|
5927 |
|
|
* Core File Generation:: Cause a program dump its core
|
5928 |
|
|
* Character Sets:: Debugging programs that use a different
|
5929 |
|
|
character set than GDB does
|
5930 |
|
|
* Caching Remote Data:: Data caching for remote targets
|
5931 |
|
|
* Searching Memory:: Searching memory for a sequence of bytes
|
5932 |
|
|
|
5933 |
|
|
|
5934 |
|
|
File: gdb.info, Node: Expressions, Next: Ambiguous Expressions, Up: Data
|
5935 |
|
|
|
5936 |
|
|
10.1 Expressions
|
5937 |
|
|
================
|
5938 |
|
|
|
5939 |
|
|
`print' and many other GDB commands accept an expression and compute
|
5940 |
|
|
its value. Any kind of constant, variable or operator defined by the
|
5941 |
|
|
programming language you are using is valid in an expression in GDB.
|
5942 |
|
|
This includes conditional expressions, function calls, casts, and
|
5943 |
|
|
string constants. It also includes preprocessor macros, if you
|
5944 |
342 |
jeremybenn |
compiled your program to include this information; see *note
|
5945 |
330 |
jeremybenn |
Compilation::.
|
5946 |
|
|
|
5947 |
|
|
GDB supports array constants in expressions input by the user. The
|
5948 |
|
|
syntax is {ELEMENT, ELEMENT...}. For example, you can use the command
|
5949 |
|
|
`print {1, 2, 3}' to create an array of three integers. If you pass an
|
5950 |
|
|
array to a function or assign it to a program variable, GDB copies the
|
5951 |
|
|
array to memory that is `malloc'ed in the target program.
|
5952 |
|
|
|
5953 |
|
|
Because C is so widespread, most of the expressions shown in
|
5954 |
|
|
examples in this manual are in C. *Note Using GDB with Different
|
5955 |
|
|
Languages: Languages, for information on how to use expressions in other
|
5956 |
|
|
languages.
|
5957 |
|
|
|
5958 |
|
|
In this section, we discuss operators that you can use in GDB
|
5959 |
|
|
expressions regardless of your programming language.
|
5960 |
|
|
|
5961 |
|
|
Casts are supported in all languages, not just in C, because it is so
|
5962 |
|
|
useful to cast a number into a pointer in order to examine a structure
|
5963 |
|
|
at that address in memory.
|
5964 |
|
|
|
5965 |
|
|
GDB supports these operators, in addition to those common to
|
5966 |
|
|
programming languages:
|
5967 |
|
|
|
5968 |
|
|
`@'
|
5969 |
|
|
`@' is a binary operator for treating parts of memory as arrays.
|
5970 |
|
|
*Note Artificial Arrays: Arrays, for more information.
|
5971 |
|
|
|
5972 |
|
|
`::'
|
5973 |
|
|
`::' allows you to specify a variable in terms of the file or
|
5974 |
|
|
function where it is defined. *Note Program Variables: Variables.
|
5975 |
|
|
|
5976 |
|
|
`{TYPE} ADDR'
|
5977 |
|
|
Refers to an object of type TYPE stored at address ADDR in memory.
|
5978 |
|
|
ADDR may be any expression whose value is an integer or pointer
|
5979 |
|
|
(but parentheses are required around binary operators, just as in
|
5980 |
|
|
a cast). This construct is allowed regardless of what kind of
|
5981 |
|
|
data is normally supposed to reside at ADDR.
|
5982 |
|
|
|
5983 |
|
|
|
5984 |
|
|
File: gdb.info, Node: Ambiguous Expressions, Next: Variables, Prev: Expressions, Up: Data
|
5985 |
|
|
|
5986 |
|
|
10.2 Ambiguous Expressions
|
5987 |
|
|
==========================
|
5988 |
|
|
|
5989 |
|
|
Expressions can sometimes contain some ambiguous elements. For
|
5990 |
|
|
instance, some programming languages (notably Ada, C++ and Objective-C)
|
5991 |
|
|
permit a single function name to be defined several times, for
|
5992 |
|
|
application in different contexts. This is called "overloading".
|
5993 |
|
|
Another example involving Ada is generics. A "generic package" is
|
5994 |
|
|
similar to C++ templates and is typically instantiated several times,
|
5995 |
|
|
resulting in the same function name being defined in different contexts.
|
5996 |
|
|
|
5997 |
|
|
In some cases and depending on the language, it is possible to adjust
|
5998 |
|
|
the expression to remove the ambiguity. For instance in C++, you can
|
5999 |
|
|
specify the signature of the function you want to break on, as in
|
6000 |
|
|
`break FUNCTION(TYPES)'. In Ada, using the fully qualified name of
|
6001 |
|
|
your function often makes the expression unambiguous as well.
|
6002 |
|
|
|
6003 |
|
|
When an ambiguity that needs to be resolved is detected, the debugger
|
6004 |
|
|
has the capability to display a menu of numbered choices for each
|
6005 |
|
|
possibility, and then waits for the selection with the prompt `>'. The
|
6006 |
|
|
first option is always `[0] cancel', and typing `0 ' aborts the
|
6007 |
|
|
current command. If the command in which the expression was used
|
6008 |
|
|
allows more than one choice to be selected, the next option in the menu
|
6009 |
|
|
is `[1] all', and typing `1 ' selects all possible choices.
|
6010 |
|
|
|
6011 |
|
|
For example, the following session excerpt shows an attempt to set a
|
6012 |
|
|
breakpoint at the overloaded symbol `String::after'. We choose three
|
6013 |
|
|
particular definitions of that function name:
|
6014 |
|
|
|
6015 |
|
|
(gdb) b String::after
|
6016 |
|
|
[0] cancel
|
6017 |
|
|
[1] all
|
6018 |
|
|
[2] file:String.cc; line number:867
|
6019 |
|
|
[3] file:String.cc; line number:860
|
6020 |
|
|
[4] file:String.cc; line number:875
|
6021 |
|
|
[5] file:String.cc; line number:853
|
6022 |
|
|
[6] file:String.cc; line number:846
|
6023 |
|
|
[7] file:String.cc; line number:735
|
6024 |
|
|
> 2 4 6
|
6025 |
|
|
Breakpoint 1 at 0xb26c: file String.cc, line 867.
|
6026 |
|
|
Breakpoint 2 at 0xb344: file String.cc, line 875.
|
6027 |
|
|
Breakpoint 3 at 0xafcc: file String.cc, line 846.
|
6028 |
|
|
Multiple breakpoints were set.
|
6029 |
|
|
Use the "delete" command to delete unwanted
|
6030 |
|
|
breakpoints.
|
6031 |
|
|
(gdb)
|
6032 |
|
|
|
6033 |
|
|
`set multiple-symbols MODE'
|
6034 |
|
|
This option allows you to adjust the debugger behavior when an
|
6035 |
|
|
expression is ambiguous.
|
6036 |
|
|
|
6037 |
|
|
By default, MODE is set to `all'. If the command with which the
|
6038 |
|
|
expression is used allows more than one choice, then GDB
|
6039 |
|
|
automatically selects all possible choices. For instance,
|
6040 |
|
|
inserting a breakpoint on a function using an ambiguous name
|
6041 |
|
|
results in a breakpoint inserted on each possible match. However,
|
6042 |
|
|
if a unique choice must be made, then GDB uses the menu to help
|
6043 |
|
|
you disambiguate the expression. For instance, printing the
|
6044 |
|
|
address of an overloaded function will result in the use of the
|
6045 |
|
|
menu.
|
6046 |
|
|
|
6047 |
|
|
When MODE is set to `ask', the debugger always uses the menu when
|
6048 |
|
|
an ambiguity is detected.
|
6049 |
|
|
|
6050 |
|
|
Finally, when MODE is set to `cancel', the debugger reports an
|
6051 |
|
|
error due to the ambiguity and the command is aborted.
|
6052 |
|
|
|
6053 |
|
|
`show multiple-symbols'
|
6054 |
|
|
Show the current value of the `multiple-symbols' setting.
|
6055 |
|
|
|
6056 |
|
|
|
6057 |
|
|
File: gdb.info, Node: Variables, Next: Arrays, Prev: Ambiguous Expressions, Up: Data
|
6058 |
|
|
|
6059 |
|
|
10.3 Program Variables
|
6060 |
|
|
======================
|
6061 |
|
|
|
6062 |
|
|
The most common kind of expression to use is the name of a variable in
|
6063 |
|
|
your program.
|
6064 |
|
|
|
6065 |
|
|
Variables in expressions are understood in the selected stack frame
|
6066 |
|
|
(*note Selecting a Frame: Selection.); they must be either:
|
6067 |
|
|
|
6068 |
|
|
* global (or file-static)
|
6069 |
|
|
|
6070 |
|
|
or
|
6071 |
|
|
|
6072 |
|
|
* visible according to the scope rules of the programming language
|
6073 |
|
|
from the point of execution in that frame
|
6074 |
|
|
|
6075 |
|
|
This means that in the function
|
6076 |
|
|
|
6077 |
|
|
foo (a)
|
6078 |
|
|
int a;
|
6079 |
|
|
{
|
6080 |
|
|
bar (a);
|
6081 |
|
|
{
|
6082 |
|
|
int b = test ();
|
6083 |
|
|
bar (b);
|
6084 |
|
|
}
|
6085 |
|
|
}
|
6086 |
|
|
|
6087 |
|
|
you can examine and use the variable `a' whenever your program is
|
6088 |
|
|
executing within the function `foo', but you can only use or examine
|
6089 |
|
|
the variable `b' while your program is executing inside the block where
|
6090 |
|
|
`b' is declared.
|
6091 |
|
|
|
6092 |
|
|
There is an exception: you can refer to a variable or function whose
|
6093 |
|
|
scope is a single source file even if the current execution point is not
|
6094 |
|
|
in this file. But it is possible to have more than one such variable or
|
6095 |
|
|
function with the same name (in different source files). If that
|
6096 |
|
|
happens, referring to that name has unpredictable effects. If you wish,
|
6097 |
|
|
you can specify a static variable in a particular function or file,
|
6098 |
|
|
using the colon-colon (`::') notation:
|
6099 |
|
|
|
6100 |
|
|
FILE::VARIABLE
|
6101 |
|
|
FUNCTION::VARIABLE
|
6102 |
|
|
|
6103 |
|
|
Here FILE or FUNCTION is the name of the context for the static
|
6104 |
|
|
VARIABLE. In the case of file names, you can use quotes to make sure
|
6105 |
|
|
GDB parses the file name as a single word--for example, to print a
|
6106 |
|
|
global value of `x' defined in `f2.c':
|
6107 |
|
|
|
6108 |
|
|
(gdb) p 'f2.c'::x
|
6109 |
|
|
|
6110 |
|
|
This use of `::' is very rarely in conflict with the very similar
|
6111 |
|
|
use of the same notation in C++. GDB also supports use of the C++
|
6112 |
|
|
scope resolution operator in GDB expressions.
|
6113 |
|
|
|
6114 |
|
|
_Warning:_ Occasionally, a local variable may appear to have the
|
6115 |
|
|
wrong value at certain points in a function--just after entry to a
|
6116 |
|
|
new scope, and just before exit.
|
6117 |
|
|
You may see this problem when you are stepping by machine
|
6118 |
|
|
instructions. This is because, on most machines, it takes more than
|
6119 |
|
|
one instruction to set up a stack frame (including local variable
|
6120 |
|
|
definitions); if you are stepping by machine instructions, variables
|
6121 |
|
|
may appear to have the wrong values until the stack frame is completely
|
6122 |
|
|
built. On exit, it usually also takes more than one machine
|
6123 |
|
|
instruction to destroy a stack frame; after you begin stepping through
|
6124 |
|
|
that group of instructions, local variable definitions may be gone.
|
6125 |
|
|
|
6126 |
|
|
This may also happen when the compiler does significant
|
6127 |
|
|
optimizations. To be sure of always seeing accurate values, turn off
|
6128 |
|
|
all optimization when compiling.
|
6129 |
|
|
|
6130 |
|
|
Another possible effect of compiler optimizations is to optimize
|
6131 |
|
|
unused variables out of existence, or assign variables to registers (as
|
6132 |
|
|
opposed to memory addresses). Depending on the support for such cases
|
6133 |
|
|
offered by the debug info format used by the compiler, GDB might not be
|
6134 |
|
|
able to display values for such local variables. If that happens, GDB
|
6135 |
|
|
will print a message like this:
|
6136 |
|
|
|
6137 |
|
|
No symbol "foo" in current context.
|
6138 |
|
|
|
6139 |
|
|
To solve such problems, either recompile without optimizations, or
|
6140 |
|
|
use a different debug info format, if the compiler supports several such
|
6141 |
|
|
formats. For example, GCC, the GNU C/C++ compiler, usually supports
|
6142 |
|
|
the `-gstabs+' option. `-gstabs+' produces debug info in a format that
|
6143 |
|
|
is superior to formats such as COFF. You may be able to use DWARF 2
|
6144 |
|
|
(`-gdwarf-2'), which is also an effective form for debug info. *Note
|
6145 |
|
|
Options for Debugging Your Program or GCC: (gcc.info)Debugging Options.
|
6146 |
|
|
*Note C and C++: C, for more information about debug info formats that
|
6147 |
|
|
are best suited to C++ programs.
|
6148 |
|
|
|
6149 |
|
|
If you ask to print an object whose contents are unknown to GDB,
|
6150 |
|
|
e.g., because its data type is not completely specified by the debug
|
6151 |
|
|
information, GDB will say `'. *Note incomplete type:
|
6152 |
|
|
Symbols, for more about this.
|
6153 |
|
|
|
6154 |
|
|
Strings are identified as arrays of `char' values without specified
|
6155 |
|
|
signedness. Arrays of either `signed char' or `unsigned char' get
|
6156 |
|
|
printed as arrays of 1 byte sized integers. `-fsigned-char' or
|
6157 |
|
|
`-funsigned-char' GCC options have no effect as GDB defines literal
|
6158 |
|
|
string type `"char"' as `char' without a sign. For program code
|
6159 |
|
|
|
6160 |
|
|
char var0[] = "A";
|
6161 |
|
|
signed char var1[] = "A";
|
6162 |
|
|
|
6163 |
|
|
You get during debugging
|
6164 |
|
|
(gdb) print var0
|
6165 |
|
|
$1 = "A"
|
6166 |
|
|
(gdb) print var1
|
6167 |
|
|
$2 = {65 'A', 0 '\0'}
|
6168 |
|
|
|
6169 |
|
|
|
6170 |
|
|
File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: Data
|
6171 |
|
|
|
6172 |
|
|
10.4 Artificial Arrays
|
6173 |
|
|
======================
|
6174 |
|
|
|
6175 |
|
|
It is often useful to print out several successive objects of the same
|
6176 |
|
|
type in memory; a section of an array, or an array of dynamically
|
6177 |
|
|
determined size for which only a pointer exists in the program.
|
6178 |
|
|
|
6179 |
|
|
You can do this by referring to a contiguous span of memory as an
|
6180 |
|
|
"artificial array", using the binary operator `@'. The left operand of
|
6181 |
|
|
`@' should be the first element of the desired array and be an
|
6182 |
|
|
individual object. The right operand should be the desired length of
|
6183 |
|
|
the array. The result is an array value whose elements are all of the
|
6184 |
|
|
type of the left argument. The first element is actually the left
|
6185 |
|
|
argument; the second element comes from bytes of memory immediately
|
6186 |
|
|
following those that hold the first element, and so on. Here is an
|
6187 |
|
|
example. If a program says
|
6188 |
|
|
|
6189 |
|
|
int *array = (int *) malloc (len * sizeof (int));
|
6190 |
|
|
|
6191 |
|
|
you can print the contents of `array' with
|
6192 |
|
|
|
6193 |
|
|
p *array@len
|
6194 |
|
|
|
6195 |
|
|
The left operand of `@' must reside in memory. Array values made
|
6196 |
|
|
with `@' in this way behave just like other arrays in terms of
|
6197 |
|
|
subscripting, and are coerced to pointers when used in expressions.
|
6198 |
|
|
Artificial arrays most often appear in expressions via the value history
|
6199 |
|
|
(*note Value History: Value History.), after printing one out.
|
6200 |
|
|
|
6201 |
|
|
Another way to create an artificial array is to use a cast. This
|
6202 |
|
|
re-interprets a value as if it were an array. The value need not be in
|
6203 |
|
|
memory:
|
6204 |
|
|
(gdb) p/x (short[2])0x12345678
|
6205 |
|
|
$1 = {0x1234, 0x5678}
|
6206 |
|
|
|
6207 |
|
|
As a convenience, if you leave the array length out (as in
|
6208 |
|
|
`(TYPE[])VALUE') GDB calculates the size to fill the value (as
|
6209 |
|
|
`sizeof(VALUE)/sizeof(TYPE)':
|
6210 |
|
|
(gdb) p/x (short[])0x12345678
|
6211 |
|
|
$2 = {0x1234, 0x5678}
|
6212 |
|
|
|
6213 |
|
|
Sometimes the artificial array mechanism is not quite enough; in
|
6214 |
|
|
moderately complex data structures, the elements of interest may not
|
6215 |
|
|
actually be adjacent--for example, if you are interested in the values
|
6216 |
|
|
of pointers in an array. One useful work-around in this situation is
|
6217 |
|
|
to use a convenience variable (*note Convenience Variables: Convenience
|
6218 |
|
|
Vars.) as a counter in an expression that prints the first interesting
|
6219 |
|
|
value, and then repeat that expression via . For instance,
|
6220 |
|
|
suppose you have an array `dtab' of pointers to structures, and you are
|
6221 |
|
|
interested in the values of a field `fv' in each structure. Here is an
|
6222 |
|
|
example of what you might type:
|
6223 |
|
|
|
6224 |
|
|
set $i = 0
|
6225 |
|
|
p dtab[$i++]->fv
|
6226 |
|
|
|
6227 |
|
|
|
6228 |
|
|
...
|
6229 |
|
|
|
6230 |
|
|
|
6231 |
|
|
File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: Data
|
6232 |
|
|
|
6233 |
|
|
10.5 Output Formats
|
6234 |
|
|
===================
|
6235 |
|
|
|
6236 |
|
|
By default, GDB prints a value according to its data type. Sometimes
|
6237 |
|
|
this is not what you want. For example, you might want to print a
|
6238 |
|
|
number in hex, or a pointer in decimal. Or you might want to view data
|
6239 |
|
|
in memory at a certain address as a character string or as an
|
6240 |
|
|
instruction. To do these things, specify an "output format" when you
|
6241 |
|
|
print a value.
|
6242 |
|
|
|
6243 |
|
|
The simplest use of output formats is to say how to print a value
|
6244 |
|
|
already computed. This is done by starting the arguments of the
|
6245 |
|
|
`print' command with a slash and a format letter. The format letters
|
6246 |
|
|
supported are:
|
6247 |
|
|
|
6248 |
|
|
`x'
|
6249 |
|
|
Regard the bits of the value as an integer, and print the integer
|
6250 |
|
|
in hexadecimal.
|
6251 |
|
|
|
6252 |
|
|
`d'
|
6253 |
|
|
Print as integer in signed decimal.
|
6254 |
|
|
|
6255 |
|
|
`u'
|
6256 |
|
|
Print as integer in unsigned decimal.
|
6257 |
|
|
|
6258 |
|
|
`o'
|
6259 |
|
|
Print as integer in octal.
|
6260 |
|
|
|
6261 |
|
|
`t'
|
6262 |
|
|
Print as integer in binary. The letter `t' stands for "two". (1)
|
6263 |
|
|
|
6264 |
|
|
`a'
|
6265 |
|
|
Print as an address, both absolute in hexadecimal and as an offset
|
6266 |
|
|
from the nearest preceding symbol. You can use this format used
|
6267 |
|
|
to discover where (in what function) an unknown address is located:
|
6268 |
|
|
|
6269 |
|
|
(gdb) p/a 0x54320
|
6270 |
|
|
$3 = 0x54320 <_initialize_vx+396>
|
6271 |
|
|
|
6272 |
|
|
The command `info symbol 0x54320' yields similar results. *Note
|
6273 |
|
|
info symbol: Symbols.
|
6274 |
|
|
|
6275 |
|
|
`c'
|
6276 |
|
|
Regard as an integer and print it as a character constant. This
|
6277 |
|
|
prints both the numerical value and its character representation.
|
6278 |
|
|
The character representation is replaced with the octal escape
|
6279 |
|
|
`\nnn' for characters outside the 7-bit ASCII range.
|
6280 |
|
|
|
6281 |
|
|
Without this format, GDB displays `char', `unsigned char', and
|
6282 |
|
|
`signed char' data as character constants. Single-byte members of
|
6283 |
|
|
vectors are displayed as integer data.
|
6284 |
|
|
|
6285 |
|
|
`f'
|
6286 |
|
|
Regard the bits of the value as a floating point number and print
|
6287 |
|
|
using typical floating point syntax.
|
6288 |
|
|
|
6289 |
|
|
`s'
|
6290 |
|
|
Regard as a string, if possible. With this format, pointers to
|
6291 |
|
|
single-byte data are displayed as null-terminated strings and
|
6292 |
|
|
arrays of single-byte data are displayed as fixed-length strings.
|
6293 |
|
|
Other values are displayed in their natural types.
|
6294 |
|
|
|
6295 |
|
|
Without this format, GDB displays pointers to and arrays of
|
6296 |
|
|
`char', `unsigned char', and `signed char' as strings.
|
6297 |
|
|
Single-byte members of a vector are displayed as an integer array.
|
6298 |
|
|
|
6299 |
|
|
`r'
|
6300 |
|
|
Print using the `raw' formatting. By default, GDB will use a
|
6301 |
|
|
Python-based pretty-printer, if one is available (*note Pretty
|
6302 |
|
|
Printing::). This typically results in a higher-level display of
|
6303 |
|
|
the value's contents. The `r' format bypasses any Python
|
6304 |
|
|
pretty-printer which might exist.
|
6305 |
|
|
|
6306 |
|
|
For example, to print the program counter in hex (*note
|
6307 |
|
|
Registers::), type
|
6308 |
|
|
|
6309 |
|
|
p/x $pc
|
6310 |
|
|
|
6311 |
|
|
Note that no space is required before the slash; this is because command
|
6312 |
|
|
names in GDB cannot contain a slash.
|
6313 |
|
|
|
6314 |
|
|
To reprint the last value in the value history with a different
|
6315 |
|
|
format, you can use the `print' command with just a format and no
|
6316 |
|
|
expression. For example, `p/x' reprints the last value in hex.
|
6317 |
|
|
|
6318 |
|
|
---------- Footnotes ----------
|
6319 |
|
|
|
6320 |
|
|
(1) `b' cannot be used because these format letters are also used
|
6321 |
342 |
jeremybenn |
with the `x' command, where `b' stands for "byte"; see *note Examining
|
6322 |
330 |
jeremybenn |
Memory: Memory.
|
6323 |
|
|
|
6324 |
|
|
|
6325 |
|
|
File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: Data
|
6326 |
|
|
|
6327 |
|
|
10.6 Examining Memory
|
6328 |
|
|
=====================
|
6329 |
|
|
|
6330 |
|
|
You can use the command `x' (for "examine") to examine memory in any of
|
6331 |
|
|
several formats, independently of your program's data types.
|
6332 |
|
|
|
6333 |
|
|
`x/NFU ADDR'
|
6334 |
|
|
`x ADDR'
|
6335 |
|
|
`x'
|
6336 |
|
|
Use the `x' command to examine memory.
|
6337 |
|
|
|
6338 |
|
|
N, F, and U are all optional parameters that specify how much memory
|
6339 |
|
|
to display and how to format it; ADDR is an expression giving the
|
6340 |
|
|
address where you want to start displaying memory. If you use defaults
|
6341 |
|
|
for NFU, you need not type the slash `/'. Several commands set
|
6342 |
|
|
convenient defaults for ADDR.
|
6343 |
|
|
|
6344 |
|
|
N, the repeat count
|
6345 |
|
|
The repeat count is a decimal integer; the default is 1. It
|
6346 |
|
|
specifies how much memory (counting by units U) to display.
|
6347 |
|
|
|
6348 |
|
|
F, the display format
|
6349 |
|
|
The display format is one of the formats used by `print' (`x',
|
6350 |
|
|
`d', `u', `o', `t', `a', `c', `f', `s'), and in addition `i' (for
|
6351 |
|
|
machine instructions). The default is `x' (hexadecimal)
|
6352 |
|
|
initially. The default changes each time you use either `x' or
|
6353 |
|
|
`print'.
|
6354 |
|
|
|
6355 |
|
|
U, the unit size
|
6356 |
|
|
The unit size is any of
|
6357 |
|
|
|
6358 |
|
|
`b'
|
6359 |
|
|
Bytes.
|
6360 |
|
|
|
6361 |
|
|
`h'
|
6362 |
|
|
Halfwords (two bytes).
|
6363 |
|
|
|
6364 |
|
|
`w'
|
6365 |
|
|
Words (four bytes). This is the initial default.
|
6366 |
|
|
|
6367 |
|
|
`g'
|
6368 |
|
|
Giant words (eight bytes).
|
6369 |
|
|
|
6370 |
|
|
Each time you specify a unit size with `x', that size becomes the
|
6371 |
|
|
default unit the next time you use `x'. For the `i' format, the
|
6372 |
|
|
unit size is ignored and is normally not written. For the `s'
|
6373 |
|
|
format, the unit size defaults to `b', unless it is explicitly
|
6374 |
|
|
given. Use `x /hs' to display 16-bit char strings and `x /ws' to
|
6375 |
|
|
display 32-bit strings. The next use of `x /s' will again display
|
6376 |
|
|
8-bit strings. Note that the results depend on the programming
|
6377 |
|
|
language of the current compilation unit. If the language is C,
|
6378 |
|
|
the `s' modifier will use the UTF-16 encoding while `w' will use
|
6379 |
|
|
UTF-32. The encoding is set by the programming language and cannot
|
6380 |
|
|
be altered.
|
6381 |
|
|
|
6382 |
|
|
ADDR, starting display address
|
6383 |
|
|
ADDR is the address where you want GDB to begin displaying memory.
|
6384 |
|
|
The expression need not have a pointer value (though it may); it
|
6385 |
|
|
is always interpreted as an integer address of a byte of memory.
|
6386 |
|
|
*Note Expressions: Expressions, for more information on
|
6387 |
|
|
expressions. The default for ADDR is usually just after the last
|
6388 |
|
|
address examined--but several other commands also set the default
|
6389 |
|
|
address: `info breakpoints' (to the address of the last breakpoint
|
6390 |
|
|
listed), `info line' (to the starting address of a line), and
|
6391 |
|
|
`print' (if you use it to display a value from memory).
|
6392 |
|
|
|
6393 |
|
|
For example, `x/3uh 0x54320' is a request to display three halfwords
|
6394 |
|
|
(`h') of memory, formatted as unsigned decimal integers (`u'), starting
|
6395 |
|
|
at address `0x54320'. `x/4xw $sp' prints the four words (`w') of
|
6396 |
|
|
memory above the stack pointer (here, `$sp'; *note Registers:
|
6397 |
|
|
Registers.) in hexadecimal (`x').
|
6398 |
|
|
|
6399 |
|
|
Since the letters indicating unit sizes are all distinct from the
|
6400 |
|
|
letters specifying output formats, you do not have to remember whether
|
6401 |
|
|
unit size or format comes first; either order works. The output
|
6402 |
|
|
specifications `4xw' and `4wx' mean exactly the same thing. (However,
|
6403 |
|
|
the count N must come first; `wx4' does not work.)
|
6404 |
|
|
|
6405 |
|
|
Even though the unit size U is ignored for the formats `s' and `i',
|
6406 |
|
|
you might still want to use a count N; for example, `3i' specifies that
|
6407 |
|
|
you want to see three machine instructions, including any operands.
|
6408 |
|
|
For convenience, especially when used with the `display' command, the
|
6409 |
|
|
`i' format also prints branch delay slot instructions, if any, beyond
|
6410 |
|
|
the count specified, which immediately follow the last instruction that
|
6411 |
|
|
is within the count. The command `disassemble' gives an alternative
|
6412 |
342 |
jeremybenn |
way of inspecting machine instructions; see *note Source and Machine
|
6413 |
330 |
jeremybenn |
Code: Machine Code.
|
6414 |
|
|
|
6415 |
|
|
All the defaults for the arguments to `x' are designed to make it
|
6416 |
|
|
easy to continue scanning memory with minimal specifications each time
|
6417 |
|
|
you use `x'. For example, after you have inspected three machine
|
6418 |
|
|
instructions with `x/3i ADDR', you can inspect the next seven with just
|
6419 |
|
|
`x/7'. If you use to repeat the `x' command, the repeat count N
|
6420 |
|
|
is used again; the other arguments default as for successive uses of
|
6421 |
|
|
`x'.
|
6422 |
|
|
|
6423 |
|
|
When examining machine instructions, the instruction at current
|
6424 |
|
|
program counter is shown with a `=>' marker. For example:
|
6425 |
|
|
|
6426 |
|
|
(gdb) x/5i $pc-6
|
6427 |
|
|
0x804837f : mov %esp,%ebp
|
6428 |
|
|
0x8048381 : push %ecx
|
6429 |
|
|
0x8048382 : sub $0x4,%esp
|
6430 |
|
|
=> 0x8048385 : movl $0x8048460,(%esp)
|
6431 |
|
|
0x804838c : call 0x80482d4
|
6432 |
|
|
|
6433 |
|
|
The addresses and contents printed by the `x' command are not saved
|
6434 |
|
|
in the value history because there is often too much of them and they
|
6435 |
|
|
would get in the way. Instead, GDB makes these values available for
|
6436 |
|
|
subsequent use in expressions as values of the convenience variables
|
6437 |
|
|
`$_' and `$__'. After an `x' command, the last address examined is
|
6438 |
|
|
available for use in expressions in the convenience variable `$_'. The
|
6439 |
|
|
contents of that address, as examined, are available in the convenience
|
6440 |
|
|
variable `$__'.
|
6441 |
|
|
|
6442 |
|
|
If the `x' command has a repeat count, the address and contents saved
|
6443 |
|
|
are from the last memory unit printed; this is not the same as the last
|
6444 |
|
|
address printed if several units were printed on the last line of
|
6445 |
|
|
output.
|
6446 |
|
|
|
6447 |
|
|
When you are debugging a program running on a remote target machine
|
6448 |
|
|
(*note Remote Debugging::), you may wish to verify the program's image
|
6449 |
|
|
in the remote machine's memory against the executable file you
|
6450 |
|
|
downloaded to the target. The `compare-sections' command is provided
|
6451 |
|
|
for such situations.
|
6452 |
|
|
|
6453 |
|
|
`compare-sections [SECTION-NAME]'
|
6454 |
|
|
Compare the data of a loadable section SECTION-NAME in the
|
6455 |
|
|
executable file of the program being debugged with the same
|
6456 |
|
|
section in the remote machine's memory, and report any mismatches.
|
6457 |
|
|
With no arguments, compares all loadable sections. This command's
|
6458 |
|
|
availability depends on the target's support for the `"qCRC"'
|
6459 |
|
|
remote request.
|
6460 |
|
|
|
6461 |
|
|
|
6462 |
|
|
File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: Data
|
6463 |
|
|
|
6464 |
|
|
10.7 Automatic Display
|
6465 |
|
|
======================
|
6466 |
|
|
|
6467 |
|
|
If you find that you want to print the value of an expression frequently
|
6468 |
|
|
(to see how it changes), you might want to add it to the "automatic
|
6469 |
|
|
display list" so that GDB prints its value each time your program stops.
|
6470 |
|
|
Each expression added to the list is given a number to identify it; to
|
6471 |
|
|
remove an expression from the list, you specify that number. The
|
6472 |
|
|
automatic display looks like this:
|
6473 |
|
|
|
6474 |
|
|
2: foo = 38
|
6475 |
|
|
3: bar[5] = (struct hack *) 0x3804
|
6476 |
|
|
|
6477 |
|
|
This display shows item numbers, expressions and their current values.
|
6478 |
|
|
As with displays you request manually using `x' or `print', you can
|
6479 |
|
|
specify the output format you prefer; in fact, `display' decides
|
6480 |
|
|
whether to use `print' or `x' depending your format specification--it
|
6481 |
|
|
uses `x' if you specify either the `i' or `s' format, or a unit size;
|
6482 |
|
|
otherwise it uses `print'.
|
6483 |
|
|
|
6484 |
|
|
`display EXPR'
|
6485 |
|
|
Add the expression EXPR to the list of expressions to display each
|
6486 |
|
|
time your program stops. *Note Expressions: Expressions.
|
6487 |
|
|
|
6488 |
|
|
`display' does not repeat if you press again after using it.
|
6489 |
|
|
|
6490 |
|
|
`display/FMT EXPR'
|
6491 |
|
|
For FMT specifying only a display format and not a size or count,
|
6492 |
|
|
add the expression EXPR to the auto-display list but arrange to
|
6493 |
|
|
display it each time in the specified format FMT. *Note Output
|
6494 |
|
|
Formats: Output Formats.
|
6495 |
|
|
|
6496 |
|
|
`display/FMT ADDR'
|
6497 |
|
|
For FMT `i' or `s', or including a unit-size or a number of units,
|
6498 |
|
|
add the expression ADDR as a memory address to be examined each
|
6499 |
|
|
time your program stops. Examining means in effect doing `x/FMT
|
6500 |
|
|
ADDR'. *Note Examining Memory: Memory.
|
6501 |
|
|
|
6502 |
|
|
For example, `display/i $pc' can be helpful, to see the machine
|
6503 |
|
|
instruction about to be executed each time execution stops (`$pc' is a
|
6504 |
|
|
common name for the program counter; *note Registers: Registers.).
|
6505 |
|
|
|
6506 |
|
|
`undisplay DNUMS...'
|
6507 |
|
|
`delete display DNUMS...'
|
6508 |
|
|
Remove item numbers DNUMS from the list of expressions to display.
|
6509 |
|
|
|
6510 |
|
|
`undisplay' does not repeat if you press after using it.
|
6511 |
|
|
(Otherwise you would just get the error `No display number ...'.)
|
6512 |
|
|
|
6513 |
|
|
`disable display DNUMS...'
|
6514 |
|
|
Disable the display of item numbers DNUMS. A disabled display
|
6515 |
|
|
item is not printed automatically, but is not forgotten. It may be
|
6516 |
|
|
enabled again later.
|
6517 |
|
|
|
6518 |
|
|
`enable display DNUMS...'
|
6519 |
|
|
Enable display of item numbers DNUMS. It becomes effective once
|
6520 |
|
|
again in auto display of its expression, until you specify
|
6521 |
|
|
otherwise.
|
6522 |
|
|
|
6523 |
|
|
`display'
|
6524 |
|
|
Display the current values of the expressions on the list, just as
|
6525 |
|
|
is done when your program stops.
|
6526 |
|
|
|
6527 |
|
|
`info display'
|
6528 |
|
|
Print the list of expressions previously set up to display
|
6529 |
|
|
automatically, each one with its item number, but without showing
|
6530 |
|
|
the values. This includes disabled expressions, which are marked
|
6531 |
|
|
as such. It also includes expressions which would not be
|
6532 |
|
|
displayed right now because they refer to automatic variables not
|
6533 |
|
|
currently available.
|
6534 |
|
|
|
6535 |
|
|
If a display expression refers to local variables, then it does not
|
6536 |
|
|
make sense outside the lexical context for which it was set up. Such an
|
6537 |
|
|
expression is disabled when execution enters a context where one of its
|
6538 |
|
|
variables is not defined. For example, if you give the command
|
6539 |
|
|
`display last_char' while inside a function with an argument
|
6540 |
|
|
`last_char', GDB displays this argument while your program continues to
|
6541 |
|
|
stop inside that function. When it stops elsewhere--where there is no
|
6542 |
|
|
variable `last_char'--the display is disabled automatically. The next
|
6543 |
|
|
time your program stops where `last_char' is meaningful, you can enable
|
6544 |
|
|
the display expression once again.
|
6545 |
|
|
|
6546 |
|
|
|
6547 |
|
|
File: gdb.info, Node: Print Settings, Next: Pretty Printing, Prev: Auto Display, Up: Data
|
6548 |
|
|
|
6549 |
|
|
10.8 Print Settings
|
6550 |
|
|
===================
|
6551 |
|
|
|
6552 |
|
|
GDB provides the following ways to control how arrays, structures, and
|
6553 |
|
|
symbols are printed.
|
6554 |
|
|
|
6555 |
|
|
These settings are useful for debugging programs in any language:
|
6556 |
|
|
|
6557 |
|
|
`set print address'
|
6558 |
|
|
`set print address on'
|
6559 |
|
|
GDB prints memory addresses showing the location of stack traces,
|
6560 |
|
|
structure values, pointer values, breakpoints, and so forth, even
|
6561 |
|
|
when it also displays the contents of those addresses. The default
|
6562 |
|
|
is `on'. For example, this is what a stack frame display looks
|
6563 |
|
|
like with `set print address on':
|
6564 |
|
|
|
6565 |
|
|
(gdb) f
|
6566 |
|
|
#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
|
6567 |
|
|
at input.c:530
|
6568 |
|
|
530 if (lquote != def_lquote)
|
6569 |
|
|
|
6570 |
|
|
`set print address off'
|
6571 |
|
|
Do not print addresses when displaying their contents. For
|
6572 |
|
|
example, this is the same stack frame displayed with `set print
|
6573 |
|
|
address off':
|
6574 |
|
|
|
6575 |
|
|
(gdb) set print addr off
|
6576 |
|
|
(gdb) f
|
6577 |
|
|
#0 set_quotes (lq="<<", rq=">>") at input.c:530
|
6578 |
|
|
530 if (lquote != def_lquote)
|
6579 |
|
|
|
6580 |
|
|
You can use `set print address off' to eliminate all machine
|
6581 |
|
|
dependent displays from the GDB interface. For example, with
|
6582 |
|
|
`print address off', you should get the same text for backtraces on
|
6583 |
|
|
all machines--whether or not they involve pointer arguments.
|
6584 |
|
|
|
6585 |
|
|
`show print address'
|
6586 |
|
|
Show whether or not addresses are to be printed.
|
6587 |
|
|
|
6588 |
|
|
When GDB prints a symbolic address, it normally prints the closest
|
6589 |
|
|
earlier symbol plus an offset. If that symbol does not uniquely
|
6590 |
|
|
identify the address (for example, it is a name whose scope is a single
|
6591 |
|
|
source file), you may need to clarify. One way to do this is with
|
6592 |
|
|
`info line', for example `info line *0x4537'. Alternately, you can set
|
6593 |
|
|
GDB to print the source file and line number when it prints a symbolic
|
6594 |
|
|
address:
|
6595 |
|
|
|
6596 |
|
|
`set print symbol-filename on'
|
6597 |
|
|
Tell GDB to print the source file name and line number of a symbol
|
6598 |
|
|
in the symbolic form of an address.
|
6599 |
|
|
|
6600 |
|
|
`set print symbol-filename off'
|
6601 |
|
|
Do not print source file name and line number of a symbol. This
|
6602 |
|
|
is the default.
|
6603 |
|
|
|
6604 |
|
|
`show print symbol-filename'
|
6605 |
|
|
Show whether or not GDB will print the source file name and line
|
6606 |
|
|
number of a symbol in the symbolic form of an address.
|
6607 |
|
|
|
6608 |
|
|
Another situation where it is helpful to show symbol filenames and
|
6609 |
|
|
line numbers is when disassembling code; GDB shows you the line number
|
6610 |
|
|
and source file that corresponds to each instruction.
|
6611 |
|
|
|
6612 |
|
|
Also, you may wish to see the symbolic form only if the address being
|
6613 |
|
|
printed is reasonably close to the closest earlier symbol:
|
6614 |
|
|
|
6615 |
|
|
`set print max-symbolic-offset MAX-OFFSET'
|
6616 |
|
|
Tell GDB to only display the symbolic form of an address if the
|
6617 |
|
|
offset between the closest earlier symbol and the address is less
|
6618 |
|
|
than MAX-OFFSET. The default is 0, which tells GDB to always
|
6619 |
|
|
print the symbolic form of an address if any symbol precedes it.
|
6620 |
|
|
|
6621 |
|
|
`show print max-symbolic-offset'
|
6622 |
|
|
Ask how large the maximum offset is that GDB prints in a symbolic
|
6623 |
|
|
address.
|
6624 |
|
|
|
6625 |
|
|
If you have a pointer and you are not sure where it points, try `set
|
6626 |
|
|
print symbol-filename on'. Then you can determine the name and source
|
6627 |
|
|
file location of the variable where it points, using `p/a POINTER'.
|
6628 |
|
|
This interprets the address in symbolic form. For example, here GDB
|
6629 |
|
|
shows that a variable `ptt' points at another variable `t', defined in
|
6630 |
|
|
`hi2.c':
|
6631 |
|
|
|
6632 |
|
|
(gdb) set print symbol-filename on
|
6633 |
|
|
(gdb) p/a ptt
|
6634 |
|
|
$4 = 0xe008
|
6635 |
|
|
|
6636 |
|
|
_Warning:_ For pointers that point to a local variable, `p/a' does
|
6637 |
|
|
not show the symbol name and filename of the referent, even with
|
6638 |
|
|
the appropriate `set print' options turned on.
|
6639 |
|
|
|
6640 |
|
|
Other settings control how different kinds of objects are printed:
|
6641 |
|
|
|
6642 |
|
|
`set print array'
|
6643 |
|
|
`set print array on'
|
6644 |
|
|
Pretty print arrays. This format is more convenient to read, but
|
6645 |
|
|
uses more space. The default is off.
|
6646 |
|
|
|
6647 |
|
|
`set print array off'
|
6648 |
|
|
Return to compressed format for arrays.
|
6649 |
|
|
|
6650 |
|
|
`show print array'
|
6651 |
|
|
Show whether compressed or pretty format is selected for displaying
|
6652 |
|
|
arrays.
|
6653 |
|
|
|
6654 |
|
|
`set print array-indexes'
|
6655 |
|
|
`set print array-indexes on'
|
6656 |
|
|
Print the index of each element when displaying arrays. May be
|
6657 |
|
|
more convenient to locate a given element in the array or quickly
|
6658 |
|
|
find the index of a given element in that printed array. The
|
6659 |
|
|
default is off.
|
6660 |
|
|
|
6661 |
|
|
`set print array-indexes off'
|
6662 |
|
|
Stop printing element indexes when displaying arrays.
|
6663 |
|
|
|
6664 |
|
|
`show print array-indexes'
|
6665 |
|
|
Show whether the index of each element is printed when displaying
|
6666 |
|
|
arrays.
|
6667 |
|
|
|
6668 |
|
|
`set print elements NUMBER-OF-ELEMENTS'
|
6669 |
|
|
Set a limit on how many elements of an array GDB will print. If
|
6670 |
|
|
GDB is printing a large array, it stops printing after it has
|
6671 |
|
|
printed the number of elements set by the `set print elements'
|
6672 |
|
|
command. This limit also applies to the display of strings. When
|
6673 |
|
|
GDB starts, this limit is set to 200. Setting NUMBER-OF-ELEMENTS
|
6674 |
|
|
to zero means that the printing is unlimited.
|
6675 |
|
|
|
6676 |
|
|
`show print elements'
|
6677 |
|
|
Display the number of elements of a large array that GDB will
|
6678 |
|
|
print. If the number is 0, then the printing is unlimited.
|
6679 |
|
|
|
6680 |
|
|
`set print frame-arguments VALUE'
|
6681 |
|
|
This command allows to control how the values of arguments are
|
6682 |
|
|
printed when the debugger prints a frame (*note Frames::). The
|
6683 |
|
|
possible values are:
|
6684 |
|
|
|
6685 |
|
|
`all'
|
6686 |
|
|
The values of all arguments are printed.
|
6687 |
|
|
|
6688 |
|
|
`scalars'
|
6689 |
|
|
Print the value of an argument only if it is a scalar. The
|
6690 |
|
|
value of more complex arguments such as arrays, structures,
|
6691 |
|
|
unions, etc, is replaced by `...'. This is the default.
|
6692 |
|
|
Here is an example where only scalar arguments are shown:
|
6693 |
|
|
|
6694 |
|
|
#1 0x08048361 in call_me (i=3, s=..., ss=0xbf8d508c, u=..., e=green)
|
6695 |
|
|
at frame-args.c:23
|
6696 |
|
|
|
6697 |
|
|
`none'
|
6698 |
|
|
None of the argument values are printed. Instead, the value
|
6699 |
|
|
of each argument is replaced by `...'. In this case, the
|
6700 |
|
|
example above now becomes:
|
6701 |
|
|
|
6702 |
|
|
#1 0x08048361 in call_me (i=..., s=..., ss=..., u=..., e=...)
|
6703 |
|
|
at frame-args.c:23
|
6704 |
|
|
|
6705 |
|
|
By default, only scalar arguments are printed. This command can
|
6706 |
|
|
be used to configure the debugger to print the value of all
|
6707 |
|
|
arguments, regardless of their type. However, it is often
|
6708 |
|
|
advantageous to not print the value of more complex parameters.
|
6709 |
|
|
For instance, it reduces the amount of information printed in each
|
6710 |
|
|
frame, making the backtrace more readable. Also, it improves
|
6711 |
|
|
performance when displaying Ada frames, because the computation of
|
6712 |
|
|
large arguments can sometimes be CPU-intensive, especially in
|
6713 |
|
|
large applications. Setting `print frame-arguments' to `scalars'
|
6714 |
|
|
(the default) or `none' avoids this computation, thus speeding up
|
6715 |
|
|
the display of each Ada frame.
|
6716 |
|
|
|
6717 |
|
|
`show print frame-arguments'
|
6718 |
|
|
Show how the value of arguments should be displayed when printing
|
6719 |
|
|
a frame.
|
6720 |
|
|
|
6721 |
|
|
`set print repeats'
|
6722 |
|
|
Set the threshold for suppressing display of repeated array
|
6723 |
|
|
elements. When the number of consecutive identical elements of an
|
6724 |
|
|
array exceeds the threshold, GDB prints the string `"
|
6725 |
|
|
times>"', where N is the number of identical repetitions, instead
|
6726 |
|
|
of displaying the identical elements themselves. Setting the
|
6727 |
|
|
threshold to zero will cause all elements to be individually
|
6728 |
|
|
printed. The default threshold is 10.
|
6729 |
|
|
|
6730 |
|
|
`show print repeats'
|
6731 |
|
|
Display the current threshold for printing repeated identical
|
6732 |
|
|
elements.
|
6733 |
|
|
|
6734 |
|
|
`set print null-stop'
|
6735 |
|
|
Cause GDB to stop printing the characters of an array when the
|
6736 |
|
|
first NULL is encountered. This is useful when large arrays
|
6737 |
|
|
actually contain only short strings. The default is off.
|
6738 |
|
|
|
6739 |
|
|
`show print null-stop'
|
6740 |
|
|
Show whether GDB stops printing an array on the first NULL
|
6741 |
|
|
character.
|
6742 |
|
|
|
6743 |
|
|
`set print pretty on'
|
6744 |
|
|
Cause GDB to print structures in an indented format with one member
|
6745 |
|
|
per line, like this:
|
6746 |
|
|
|
6747 |
|
|
$1 = {
|
6748 |
|
|
next = 0x0,
|
6749 |
|
|
flags = {
|
6750 |
|
|
sweet = 1,
|
6751 |
|
|
sour = 1
|
6752 |
|
|
},
|
6753 |
|
|
meat = 0x54 "Pork"
|
6754 |
|
|
}
|
6755 |
|
|
|
6756 |
|
|
`set print pretty off'
|
6757 |
|
|
Cause GDB to print structures in a compact format, like this:
|
6758 |
|
|
|
6759 |
|
|
$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
|
6760 |
|
|
meat = 0x54 "Pork"}
|
6761 |
|
|
|
6762 |
|
|
This is the default format.
|
6763 |
|
|
|
6764 |
|
|
`show print pretty'
|
6765 |
|
|
Show which format GDB is using to print structures.
|
6766 |
|
|
|
6767 |
|
|
`set print sevenbit-strings on'
|
6768 |
|
|
Print using only seven-bit characters; if this option is set, GDB
|
6769 |
|
|
displays any eight-bit characters (in strings or character values)
|
6770 |
|
|
using the notation `\'NNN. This setting is best if you are
|
6771 |
|
|
working in English (ASCII) and you use the high-order bit of
|
6772 |
|
|
characters as a marker or "meta" bit.
|
6773 |
|
|
|
6774 |
|
|
`set print sevenbit-strings off'
|
6775 |
|
|
Print full eight-bit characters. This allows the use of more
|
6776 |
|
|
international character sets, and is the default.
|
6777 |
|
|
|
6778 |
|
|
`show print sevenbit-strings'
|
6779 |
|
|
Show whether or not GDB is printing only seven-bit characters.
|
6780 |
|
|
|
6781 |
|
|
`set print union on'
|
6782 |
|
|
Tell GDB to print unions which are contained in structures and
|
6783 |
|
|
other unions. This is the default setting.
|
6784 |
|
|
|
6785 |
|
|
`set print union off'
|
6786 |
|
|
Tell GDB not to print unions which are contained in structures and
|
6787 |
|
|
other unions. GDB will print `"{...}"' instead.
|
6788 |
|
|
|
6789 |
|
|
`show print union'
|
6790 |
|
|
Ask GDB whether or not it will print unions which are contained in
|
6791 |
|
|
structures and other unions.
|
6792 |
|
|
|
6793 |
|
|
For example, given the declarations
|
6794 |
|
|
|
6795 |
|
|
typedef enum {Tree, Bug} Species;
|
6796 |
|
|
typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
|
6797 |
|
|
typedef enum {Caterpillar, Cocoon, Butterfly}
|
6798 |
|
|
Bug_forms;
|
6799 |
|
|
|
6800 |
|
|
struct thing {
|
6801 |
|
|
Species it;
|
6802 |
|
|
union {
|
6803 |
|
|
Tree_forms tree;
|
6804 |
|
|
Bug_forms bug;
|
6805 |
|
|
} form;
|
6806 |
|
|
};
|
6807 |
|
|
|
6808 |
|
|
struct thing foo = {Tree, {Acorn}};
|
6809 |
|
|
|
6810 |
|
|
with `set print union on' in effect `p foo' would print
|
6811 |
|
|
|
6812 |
|
|
$1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
|
6813 |
|
|
|
6814 |
|
|
and with `set print union off' in effect it would print
|
6815 |
|
|
|
6816 |
|
|
$1 = {it = Tree, form = {...}}
|
6817 |
|
|
|
6818 |
|
|
`set print union' affects programs written in C-like languages and
|
6819 |
|
|
in Pascal.
|
6820 |
|
|
|
6821 |
|
|
These settings are of interest when debugging C++ programs:
|
6822 |
|
|
|
6823 |
|
|
`set print demangle'
|
6824 |
|
|
`set print demangle on'
|
6825 |
|
|
Print C++ names in their source form rather than in the encoded
|
6826 |
|
|
("mangled") form passed to the assembler and linker for type-safe
|
6827 |
|
|
linkage. The default is on.
|
6828 |
|
|
|
6829 |
|
|
`show print demangle'
|
6830 |
|
|
Show whether C++ names are printed in mangled or demangled form.
|
6831 |
|
|
|
6832 |
|
|
`set print asm-demangle'
|
6833 |
|
|
`set print asm-demangle on'
|
6834 |
|
|
Print C++ names in their source form rather than their mangled
|
6835 |
|
|
form, even in assembler code printouts such as instruction
|
6836 |
|
|
disassemblies. The default is off.
|
6837 |
|
|
|
6838 |
|
|
`show print asm-demangle'
|
6839 |
|
|
Show whether C++ names in assembly listings are printed in mangled
|
6840 |
|
|
or demangled form.
|
6841 |
|
|
|
6842 |
|
|
`set demangle-style STYLE'
|
6843 |
|
|
Choose among several encoding schemes used by different compilers
|
6844 |
|
|
to represent C++ names. The choices for STYLE are currently:
|
6845 |
|
|
|
6846 |
|
|
`auto'
|
6847 |
|
|
Allow GDB to choose a decoding style by inspecting your
|
6848 |
|
|
program.
|
6849 |
|
|
|
6850 |
|
|
`gnu'
|
6851 |
|
|
Decode based on the GNU C++ compiler (`g++') encoding
|
6852 |
|
|
algorithm. This is the default.
|
6853 |
|
|
|
6854 |
|
|
`hp'
|
6855 |
|
|
Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
|
6856 |
|
|
|
6857 |
|
|
`lucid'
|
6858 |
|
|
Decode based on the Lucid C++ compiler (`lcc') encoding
|
6859 |
|
|
algorithm.
|
6860 |
|
|
|
6861 |
|
|
`arm'
|
6862 |
|
|
Decode using the algorithm in the `C++ Annotated Reference
|
6863 |
|
|
Manual'. *Warning:* this setting alone is not sufficient to
|
6864 |
|
|
allow debugging `cfront'-generated executables. GDB would
|
6865 |
|
|
require further enhancement to permit that.
|
6866 |
|
|
|
6867 |
|
|
If you omit STYLE, you will see a list of possible formats.
|
6868 |
|
|
|
6869 |
|
|
`show demangle-style'
|
6870 |
|
|
Display the encoding style currently in use for decoding C++
|
6871 |
|
|
symbols.
|
6872 |
|
|
|
6873 |
|
|
`set print object'
|
6874 |
|
|
`set print object on'
|
6875 |
|
|
When displaying a pointer to an object, identify the _actual_
|
6876 |
|
|
(derived) type of the object rather than the _declared_ type, using
|
6877 |
|
|
the virtual function table.
|
6878 |
|
|
|
6879 |
|
|
`set print object off'
|
6880 |
|
|
Display only the declared type of objects, without reference to the
|
6881 |
|
|
virtual function table. This is the default setting.
|
6882 |
|
|
|
6883 |
|
|
`show print object'
|
6884 |
|
|
Show whether actual, or declared, object types are displayed.
|
6885 |
|
|
|
6886 |
|
|
`set print static-members'
|
6887 |
|
|
`set print static-members on'
|
6888 |
|
|
Print static members when displaying a C++ object. The default is
|
6889 |
|
|
on.
|
6890 |
|
|
|
6891 |
|
|
`set print static-members off'
|
6892 |
|
|
Do not print static members when displaying a C++ object.
|
6893 |
|
|
|
6894 |
|
|
`show print static-members'
|
6895 |
|
|
Show whether C++ static members are printed or not.
|
6896 |
|
|
|
6897 |
|
|
`set print pascal_static-members'
|
6898 |
|
|
`set print pascal_static-members on'
|
6899 |
|
|
Print static members when displaying a Pascal object. The default
|
6900 |
|
|
is on.
|
6901 |
|
|
|
6902 |
|
|
`set print pascal_static-members off'
|
6903 |
|
|
Do not print static members when displaying a Pascal object.
|
6904 |
|
|
|
6905 |
|
|
`show print pascal_static-members'
|
6906 |
|
|
Show whether Pascal static members are printed or not.
|
6907 |
|
|
|
6908 |
|
|
`set print vtbl'
|
6909 |
|
|
`set print vtbl on'
|
6910 |
|
|
Pretty print C++ virtual function tables. The default is off.
|
6911 |
|
|
(The `vtbl' commands do not work on programs compiled with the HP
|
6912 |
|
|
ANSI C++ compiler (`aCC').)
|
6913 |
|
|
|
6914 |
|
|
`set print vtbl off'
|
6915 |
|
|
Do not pretty print C++ virtual function tables.
|
6916 |
|
|
|
6917 |
|
|
`show print vtbl'
|
6918 |
|
|
Show whether C++ virtual function tables are pretty printed, or
|
6919 |
|
|
not.
|
6920 |
|
|
|
6921 |
|
|
|
6922 |
|
|
File: gdb.info, Node: Pretty Printing, Next: Value History, Prev: Print Settings, Up: Data
|
6923 |
|
|
|
6924 |
|
|
10.9 Pretty Printing
|
6925 |
|
|
====================
|
6926 |
|
|
|
6927 |
|
|
GDB provides a mechanism to allow pretty-printing of values using
|
6928 |
|
|
Python code. It greatly simplifies the display of complex objects.
|
6929 |
|
|
This mechanism works for both MI and the CLI.
|
6930 |
|
|
|
6931 |
|
|
For example, here is how a C++ `std::string' looks without a
|
6932 |
|
|
pretty-printer:
|
6933 |
|
|
|
6934 |
|
|
(gdb) print s
|
6935 |
|
|
$1 = {
|
6936 |
|
|
static npos = 4294967295,
|
6937 |
|
|
_M_dataplus = {
|
6938 |
|
|
> = {
|
6939 |
|
|
<__gnu_cxx::new_allocator> = {
|
6940 |
|
|
},
|
6941 |
|
|
},
|
6942 |
|
|
members of std::basic_string,
|
6943 |
|
|
std::allocator >::_Alloc_hider:
|
6944 |
|
|
_M_p = 0x804a014 "abcd"
|
6945 |
|
|
}
|
6946 |
|
|
}
|
6947 |
|
|
|
6948 |
|
|
With a pretty-printer for `std::string' only the contents are
|
6949 |
|
|
printed:
|
6950 |
|
|
|
6951 |
|
|
(gdb) print s
|
6952 |
|
|
$2 = "abcd"
|
6953 |
|
|
|
6954 |
|
|
For implementing pretty printers for new types you should read the
|
6955 |
|
|
Python API details (*note Pretty Printing API::).
|
6956 |
|
|
|
6957 |
|
|
|
6958 |
|
|
File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Pretty Printing, Up: Data
|
6959 |
|
|
|
6960 |
|
|
10.10 Value History
|
6961 |
|
|
===================
|
6962 |
|
|
|
6963 |
|
|
Values printed by the `print' command are saved in the GDB "value
|
6964 |
|
|
history". This allows you to refer to them in other expressions.
|
6965 |
|
|
Values are kept until the symbol table is re-read or discarded (for
|
6966 |
|
|
example with the `file' or `symbol-file' commands). When the symbol
|
6967 |
|
|
table changes, the value history is discarded, since the values may
|
6968 |
|
|
contain pointers back to the types defined in the symbol table.
|
6969 |
|
|
|
6970 |
|
|
The values printed are given "history numbers" by which you can
|
6971 |
|
|
refer to them. These are successive integers starting with one.
|
6972 |
|
|
`print' shows you the history number assigned to a value by printing
|
6973 |
|
|
`$NUM = ' before the value; here NUM is the history number.
|
6974 |
|
|
|
6975 |
|
|
To refer to any previous value, use `$' followed by the value's
|
6976 |
|
|
history number. The way `print' labels its output is designed to
|
6977 |
|
|
remind you of this. Just `$' refers to the most recent value in the
|
6978 |
|
|
history, and `$$' refers to the value before that. `$$N' refers to the
|
6979 |
|
|
Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
|
6980 |
|
|
equivalent to `$$', and `$$0' is equivalent to `$'.
|
6981 |
|
|
|
6982 |
|
|
For example, suppose you have just printed a pointer to a structure
|
6983 |
|
|
and want to see the contents of the structure. It suffices to type
|
6984 |
|
|
|
6985 |
|
|
p *$
|
6986 |
|
|
|
6987 |
|
|
If you have a chain of structures where the component `next' points
|
6988 |
|
|
to the next one, you can print the contents of the next one with this:
|
6989 |
|
|
|
6990 |
|
|
p *$.next
|
6991 |
|
|
|
6992 |
|
|
You can print successive links in the chain by repeating this
|
6993 |
|
|
command--which you can do by just typing .
|
6994 |
|
|
|
6995 |
|
|
Note that the history records values, not expressions. If the value
|
6996 |
|
|
of `x' is 4 and you type these commands:
|
6997 |
|
|
|
6998 |
|
|
print x
|
6999 |
|
|
set x=5
|
7000 |
|
|
|
7001 |
|
|
then the value recorded in the value history by the `print' command
|
7002 |
|
|
remains 4 even though the value of `x' has changed.
|
7003 |
|
|
|
7004 |
|
|
`show values'
|
7005 |
|
|
Print the last ten values in the value history, with their item
|
7006 |
|
|
numbers. This is like `p $$9' repeated ten times, except that
|
7007 |
|
|
`show values' does not change the history.
|
7008 |
|
|
|
7009 |
|
|
`show values N'
|
7010 |
|
|
Print ten history values centered on history item number N.
|
7011 |
|
|
|
7012 |
|
|
`show values +'
|
7013 |
|
|
Print ten history values just after the values last printed. If
|
7014 |
|
|
no more values are available, `show values +' produces no display.
|
7015 |
|
|
|
7016 |
|
|
Pressing to repeat `show values N' has exactly the same effect
|
7017 |
|
|
as `show values +'.
|
7018 |
|
|
|
7019 |
|
|
|
7020 |
|
|
File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: Data
|
7021 |
|
|
|
7022 |
|
|
10.11 Convenience Variables
|
7023 |
|
|
===========================
|
7024 |
|
|
|
7025 |
|
|
GDB provides "convenience variables" that you can use within GDB to
|
7026 |
|
|
hold on to a value and refer to it later. These variables exist
|
7027 |
|
|
entirely within GDB; they are not part of your program, and setting a
|
7028 |
|
|
convenience variable has no direct effect on further execution of your
|
7029 |
|
|
program. That is why you can use them freely.
|
7030 |
|
|
|
7031 |
|
|
Convenience variables are prefixed with `$'. Any name preceded by
|
7032 |
|
|
`$' can be used for a convenience variable, unless it is one of the
|
7033 |
|
|
predefined machine-specific register names (*note Registers:
|
7034 |
|
|
Registers.). (Value history references, in contrast, are _numbers_
|
7035 |
|
|
preceded by `$'. *Note Value History: Value History.)
|
7036 |
|
|
|
7037 |
|
|
You can save a value in a convenience variable with an assignment
|
7038 |
|
|
expression, just as you would set a variable in your program. For
|
7039 |
|
|
example:
|
7040 |
|
|
|
7041 |
|
|
set $foo = *object_ptr
|
7042 |
|
|
|
7043 |
|
|
would save in `$foo' the value contained in the object pointed to by
|
7044 |
|
|
`object_ptr'.
|
7045 |
|
|
|
7046 |
|
|
Using a convenience variable for the first time creates it, but its
|
7047 |
|
|
value is `void' until you assign a new value. You can alter the value
|
7048 |
|
|
with another assignment at any time.
|
7049 |
|
|
|
7050 |
|
|
Convenience variables have no fixed types. You can assign a
|
7051 |
|
|
convenience variable any type of value, including structures and
|
7052 |
|
|
arrays, even if that variable already has a value of a different type.
|
7053 |
|
|
The convenience variable, when used as an expression, has the type of
|
7054 |
|
|
its current value.
|
7055 |
|
|
|
7056 |
|
|
`show convenience'
|
7057 |
|
|
Print a list of convenience variables used so far, and their
|
7058 |
|
|
values. Abbreviated `show conv'.
|
7059 |
|
|
|
7060 |
|
|
`init-if-undefined $VARIABLE = EXPRESSION'
|
7061 |
|
|
Set a convenience variable if it has not already been set. This
|
7062 |
|
|
is useful for user-defined commands that keep some state. It is
|
7063 |
|
|
similar, in concept, to using local static variables with
|
7064 |
|
|
initializers in C (except that convenience variables are global).
|
7065 |
|
|
It can also be used to allow users to override default values used
|
7066 |
|
|
in a command script.
|
7067 |
|
|
|
7068 |
|
|
If the variable is already defined then the expression is not
|
7069 |
|
|
evaluated so any side-effects do not occur.
|
7070 |
|
|
|
7071 |
|
|
One of the ways to use a convenience variable is as a counter to be
|
7072 |
|
|
incremented or a pointer to be advanced. For example, to print a field
|
7073 |
|
|
from successive elements of an array of structures:
|
7074 |
|
|
|
7075 |
|
|
set $i = 0
|
7076 |
|
|
print bar[$i++]->contents
|
7077 |
|
|
|
7078 |
|
|
Repeat that command by typing .
|
7079 |
|
|
|
7080 |
|
|
Some convenience variables are created automatically by GDB and given
|
7081 |
|
|
values likely to be useful.
|
7082 |
|
|
|
7083 |
|
|
`$_'
|
7084 |
|
|
The variable `$_' is automatically set by the `x' command to the
|
7085 |
|
|
last address examined (*note Examining Memory: Memory.). Other
|
7086 |
|
|
commands which provide a default address for `x' to examine also
|
7087 |
|
|
set `$_' to that address; these commands include `info line' and
|
7088 |
|
|
`info breakpoint'. The type of `$_' is `void *' except when set
|
7089 |
|
|
by the `x' command, in which case it is a pointer to the type of
|
7090 |
|
|
`$__'.
|
7091 |
|
|
|
7092 |
|
|
`$__'
|
7093 |
|
|
The variable `$__' is automatically set by the `x' command to the
|
7094 |
|
|
value found in the last address examined. Its type is chosen to
|
7095 |
|
|
match the format in which the data was printed.
|
7096 |
|
|
|
7097 |
|
|
`$_exitcode'
|
7098 |
|
|
The variable `$_exitcode' is automatically set to the exit code
|
7099 |
|
|
when the program being debugged terminates.
|
7100 |
|
|
|
7101 |
|
|
`$_sdata'
|
7102 |
|
|
The variable `$_sdata' contains extra collected static tracepoint
|
7103 |
|
|
data. *Note Tracepoint Action Lists: Tracepoint Actions. Note
|
7104 |
|
|
that `$_sdata' could be empty, if not inspecting a trace buffer, or
|
7105 |
|
|
if extra static tracepoint data has not been collected.
|
7106 |
|
|
|
7107 |
|
|
`$_siginfo'
|
7108 |
|
|
The variable `$_siginfo' contains extra signal information (*note
|
7109 |
|
|
extra signal information::). Note that `$_siginfo' could be
|
7110 |
|
|
empty, if the application has not yet received any signals. For
|
7111 |
|
|
example, it will be empty before you execute the `run' command.
|
7112 |
|
|
|
7113 |
|
|
`$_tlb'
|
7114 |
|
|
The variable `$_tlb' is automatically set when debugging
|
7115 |
|
|
applications running on MS-Windows in native mode or connected to
|
7116 |
|
|
gdbserver that supports the `qGetTIBAddr' request. *Note General
|
7117 |
|
|
Query Packets::. This variable contains the address of the thread
|
7118 |
|
|
information block.
|
7119 |
|
|
|
7120 |
|
|
|
7121 |
|
|
On HP-UX systems, if you refer to a function or variable name that
|
7122 |
|
|
begins with a dollar sign, GDB searches for a user or system name
|
7123 |
|
|
first, before it searches for a convenience variable.
|
7124 |
|
|
|
7125 |
|
|
GDB also supplies some "convenience functions". These have a syntax
|
7126 |
|
|
similar to convenience variables. A convenience function can be used
|
7127 |
|
|
in an expression just like an ordinary function; however, a convenience
|
7128 |
|
|
function is implemented internally to GDB.
|
7129 |
|
|
|
7130 |
|
|
`help function'
|
7131 |
|
|
Print a list of all convenience functions.
|
7132 |
|
|
|