OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [doc/] [gdb.info-1] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
This is gdb.info, produced by makeinfo version 4.8 from
2
../.././gdb/doc/gdb.texinfo.
3
 
4
INFO-DIR-SECTION Software development
5
START-INFO-DIR-ENTRY
6
* Gdb: (gdb).                     The GNU debugger.
7
END-INFO-DIR-ENTRY
8
 
9
   This file documents the GNU debugger GDB.
10
 
11
   This is the Ninth Edition, of `Debugging with GDB: the GNU
12
Source-Level Debugger' for GDB Version 6.8.
13
 
14
   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
15
1998,
16
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
17
Free Software Foundation, Inc.
18
 
19
   Permission is granted to copy, distribute and/or modify this document
20
under the terms of the GNU Free Documentation License, Version 1.1 or
21
any later version published by the Free Software Foundation; with the
22
Invariant Sections being "Free Software" and "Free Software Needs Free
23
Documentation", with the Front-Cover Texts being "A GNU Manual," and
24
with the Back-Cover Texts as in (a) below.
25
 
26
   (a) The FSF's Back-Cover Text is: "You are free to copy and modify
27
this GNU Manual.  Buying copies from GNU Press supports the FSF in
28
developing GNU and promoting software freedom."
29
 
30

31
File: gdb.info,  Node: Top,  Next: Summary,  Prev: (dir),  Up: (dir)
32
 
33
Debugging with GDB
34
******************
35
 
36
This file describes GDB, the GNU symbolic debugger.
37
 
38
   This is the Ninth Edition, for GDB Version 6.8.
39
 
40
   Copyright (C) 1988-2006 Free Software Foundation, Inc.
41
 
42
   This edition of the GDB manual is dedicated to the memory of Fred
43
Fish.  Fred was a long-standing contributor to GDB and to Free software
44
in general.  We will miss him.
45
 
46
* Menu:
47
 
48
* Summary::                     Summary of GDB
49
* Sample Session::              A sample GDB session
50
 
51
* Invocation::                  Getting in and out of GDB
52
* Commands::                    GDB commands
53
* Running::                     Running programs under GDB
54
* Stopping::                    Stopping and continuing
55
* Stack::                       Examining the stack
56
* Source::                      Examining source files
57
* Data::                        Examining data
58
* Macros::                      Preprocessor Macros
59
* Tracepoints::                 Debugging remote targets non-intrusively
60
* Overlays::                    Debugging programs that use overlays
61
 
62
* Languages::                   Using GDB with different languages
63
 
64
* Symbols::                     Examining the symbol table
65
* Altering::                    Altering execution
66
* GDB Files::                   GDB files
67
* Targets::                     Specifying a debugging target
68
* Remote Debugging::            Debugging remote programs
69
* Configurations::              Configuration-specific information
70
* Controlling GDB::             Controlling GDB
71
* Sequences::                   Canned sequences of commands
72
* Interpreters::                Command Interpreters
73
* TUI::                         GDB Text User Interface
74
* Emacs::                       Using GDB under GNU Emacs
75
* GDB/MI::                      GDB's Machine Interface.
76
* Annotations::                 GDB's annotation interface.
77
 
78
* GDB Bugs::                    Reporting bugs in GDB
79
 
80
* Command Line Editing::        Command Line Editing
81
* Using History Interactively:: Using History Interactively
82
* Formatting Documentation::    How to format and print GDB documentation
83
* Installing GDB::              Installing GDB
84
* Maintenance Commands::        Maintenance Commands
85
* Remote Protocol::             GDB Remote Serial Protocol
86
* Agent Expressions::           The GDB Agent Expression Mechanism
87
* Target Descriptions::         How targets can describe themselves to
88
                                GDB
89
* Copying::                     GNU General Public License says
90
                                how you can copy and share GDB
91
* GNU Free Documentation License::  The license for this documentation
92
* Index::                       Index
93
 
94

95
File: gdb.info,  Node: Summary,  Next: Sample Session,  Prev: Top,  Up: Top
96
 
97
Summary of GDB
98
**************
99
 
100
The purpose of a debugger such as GDB is to allow you to see what is
101
going on "inside" another program while it executes--or what another
102
program was doing at the moment it crashed.
103
 
104
   GDB can do four main kinds of things (plus other things in support of
105
these) to help you catch bugs in the act:
106
 
107
   * Start your program, specifying anything that might affect its
108
     behavior.
109
 
110
   * Make your program stop on specified conditions.
111
 
112
   * Examine what has happened, when your program has stopped.
113
 
114
   * Change things in your program, so you can experiment with
115
     correcting the effects of one bug and go on to learn about another.
116
 
117
   You can use GDB to debug programs written in C and C++.  For more
118
information, see *Note Supported Languages: Supported Languages.  For
119
more information, see *Note C and C++: C.
120
 
121
   Support for Modula-2 is partial.  For information on Modula-2, see
122
*Note Modula-2: Modula-2.
123
 
124
   Debugging Pascal programs which use sets, subranges, file variables,
125
or nested functions does not currently work.  GDB does not support
126
entering expressions, printing values, or similar features using Pascal
127
syntax.
128
 
129
   GDB can be used to debug programs written in Fortran, although it
130
may be necessary to refer to some variables with a trailing underscore.
131
 
132
   GDB can be used to debug programs written in Objective-C, using
133
either the Apple/NeXT or the GNU Objective-C runtime.
134
 
135
* Menu:
136
 
137
* Free Software::               Freely redistributable software
138
* Contributors::                Contributors to GDB
139
 
140

141
File: gdb.info,  Node: Free Software,  Next: Contributors,  Up: Summary
142
 
143
Free Software
144
=============
145
 
146
GDB is "free software", protected by the GNU General Public License
147
(GPL).  The GPL gives you the freedom to copy or adapt a licensed
148
program--but every person getting a copy also gets with it the freedom
149
to modify that copy (which means that they must get access to the
150
source code), and the freedom to distribute further copies.  Typical
151
software companies use copyrights to limit your freedoms; the Free
152
Software Foundation uses the GPL to preserve these freedoms.
153
 
154
   Fundamentally, the General Public License is a license which says
155
that you have these freedoms and that you cannot take these freedoms
156
away from anyone else.
157
 
158
Free Software Needs Free Documentation
159
======================================
160
 
161
The biggest deficiency in the free software community today is not in
162
the software--it is the lack of good free documentation that we can
163
include with the free software.  Many of our most important programs do
164
not come with free reference manuals and free introductory texts.
165
Documentation is an essential part of any software package; when an
166
important free software package does not come with a free manual and a
167
free tutorial, that is a major gap.  We have many such gaps today.
168
 
169
   Consider Perl, for instance.  The tutorial manuals that people
170
normally use are non-free.  How did this come about?  Because the
171
authors of those manuals published them with restrictive terms--no
172
copying, no modification, source files not available--which exclude
173
them from the free software world.
174
 
175
   That wasn't the first time this sort of thing happened, and it was
176
far from the last.  Many times we have heard a GNU user eagerly
177
describe a manual that he is writing, his intended contribution to the
178
community, only to learn that he had ruined everything by signing a
179
publication contract to make it non-free.
180
 
181
   Free documentation, like free software, is a matter of freedom, not
182
price.  The problem with the non-free manual is not that publishers
183
charge a price for printed copies--that in itself is fine.  (The Free
184
Software Foundation sells printed copies of manuals, too.)  The problem
185
is the restrictions on the use of the manual.  Free manuals are
186
available in source code form, and give you permission to copy and
187
modify.  Non-free manuals do not allow this.
188
 
189
   The criteria of freedom for a free manual are roughly the same as for
190
free software.  Redistribution (including the normal kinds of
191
commercial redistribution) must be permitted, so that the manual can
192
accompany every copy of the program, both on-line and on paper.
193
 
194
   Permission for modification of the technical content is crucial too.
195
When people modify the software, adding or changing features, if they
196
are conscientious they will change the manual too--so they can provide
197
accurate and clear documentation for the modified program.  A manual
198
that leaves you no choice but to write a new manual to document a
199
changed version of the program is not really available to our community.
200
 
201
   Some kinds of limits on the way modification is handled are
202
acceptable.  For example, requirements to preserve the original
203
author's copyright notice, the distribution terms, or the list of
204
authors, are ok.  It is also no problem to require modified versions to
205
include notice that they were modified.  Even entire sections that may
206
not be deleted or changed are acceptable, as long as they deal with
207
nontechnical topics (like this one).  These kinds of restrictions are
208
acceptable because they don't obstruct the community's normal use of
209
the manual.
210
 
211
   However, it must be possible to modify all the _technical_ content
212
of the manual, and then distribute the result in all the usual media,
213
through all the usual channels.  Otherwise, the restrictions obstruct
214
the use of the manual, it is not free, and we need another manual to
215
replace it.
216
 
217
   Please spread the word about this issue.  Our community continues to
218
lose manuals to proprietary publishing.  If we spread the word that
219
free software needs free reference manuals and free tutorials, perhaps
220
the next person who wants to contribute by writing documentation will
221
realize, before it is too late, that only free manuals contribute to
222
the free software community.
223
 
224
   If you are writing documentation, please insist on publishing it
225
under the GNU Free Documentation License or another free documentation
226
license.  Remember that this decision requires your approval--you don't
227
have to let the publisher decide.  Some commercial publishers will use
228
a free license if you insist, but they will not propose the option; it
229
is up to you to raise the issue and say firmly that this is what you
230
want.  If the publisher you are dealing with refuses, please try other
231
publishers.  If you're not sure whether a proposed license is free,
232
write to .
233
 
234
   You can encourage commercial publishers to sell more free, copylefted
235
manuals and tutorials by buying them, and particularly by buying copies
236
from the publishers that paid for their writing or for major
237
improvements.  Meanwhile, try to avoid buying non-free documentation at
238
all.  Check the distribution terms of a manual before you buy it, and
239
insist that whoever seeks your business must respect your freedom.
240
Check the history of the book, and try to reward the publishers that
241
have paid or pay the authors to work on it.
242
 
243
   The Free Software Foundation maintains a list of free documentation
244
published by other publishers, at
245
`http://www.fsf.org/doc/other-free-books.html'.
246
 
247

248
File: gdb.info,  Node: Contributors,  Prev: Free Software,  Up: Summary
249
 
250
Contributors to GDB
251
===================
252
 
253
Richard Stallman was the original author of GDB, and of many other GNU
254
programs.  Many others have contributed to its development.  This
255
section attempts to credit major contributors.  One of the virtues of
256
free software is that everyone is free to contribute to it; with
257
regret, we cannot actually acknowledge everyone here.  The file
258
`ChangeLog' in the GDB distribution approximates a blow-by-blow account.
259
 
260
   Changes much prior to version 2.0 are lost in the mists of time.
261
 
262
     _Plea:_ Additions to this section are particularly welcome.  If you
263
     or your friends (or enemies, to be evenhanded) have been unfairly
264
     omitted from this list, we would like to add your names!
265
 
266
   So that they may not regard their many labors as thankless, we
267
particularly thank those who shepherded GDB through major releases:
268
Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim
269
Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs
270
(release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10,
271
and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5,
272
and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim
273
Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2,
274
3.1, and 3.0).
275
 
276
   Richard Stallman, assisted at various times by Peter TerMaat, Chris
277
Hanson, and Richard Mlynarik, handled releases through 2.8.
278
 
279
   Michael Tiemann is the author of most of the GNU C++ support in GDB,
280
with significant additional contributions from Per Bothner and Daniel
281
Berlin.  James Clark wrote the GNU C++ demangler.  Early work on C++
282
was by Peter TerMaat (who also did much general update work leading to
283
release 3.0).
284
 
285
   GDB uses the BFD subroutine library to examine multiple object-file
286
formats; BFD was a joint project of David V.  Henkel-Wallace, Rich
287
Pixley, Steve Chamberlain, and John Gilmore.
288
 
289
   David Johnson wrote the original COFF support; Pace Willison did the
290
original support for encapsulated COFF.
291
 
292
   Brent Benson of Harris Computer Systems contributed DWARF 2 support.
293
 
294
   Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
295
Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
296
support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
297
Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
298
Hasei contributed Sony/News OS 3 support.  David Johnson contributed
299
Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
300
Jeff Law contributed HP PA and SOM support.  Keith Packard contributed
301
NS32K support.  Doug Rabson contributed Acorn Risc Machine support.
302
Bob Rusk contributed Harris Nighthawk CX-UX support.  Chris Smith
303
contributed Convex support (and Fortran debugging).  Jonathan Stone
304
contributed Pyramid support.  Michael Tiemann contributed SPARC support.
305
Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
306
Pace Willison contributed Intel 386 support.  Jay Vosburgh contributed
307
Symmetry support.  Marko Mlinar contributed OpenRISC 1000 support.
308
 
309
   Andreas Schwab contributed M68K GNU/Linux support.
310
 
311
   Rich Schaefer and Peter Schauer helped with support of SunOS shared
312
libraries.
313
 
314
   Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
315
several machine instruction sets.
316
 
317
   Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
318
develop remote debugging.  Intel Corporation, Wind River Systems, AMD,
319
and ARM contributed remote debugging modules for the i960, VxWorks,
320
A29K UDI, and RDI targets, respectively.
321
 
322
   Brian Fox is the author of the readline libraries providing
323
command-line editing and command history.
324
 
325
   Andrew Beers of SUNY Buffalo wrote the language-switching code, the
326
Modula-2 support, and contributed the Languages chapter of this manual.
327
 
328
   Fred Fish wrote most of the support for Unix System Vr4.  He also
329
enhanced the command-completion support to cover C++ overloaded symbols.
330
 
331
   Hitachi America (now Renesas America), Ltd. sponsored the support for
332
H8/300, H8/500, and Super-H processors.
333
 
334
   NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
335
processors.
336
 
337
   Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
338
M32R/D processors.
339
 
340
   Toshiba sponsored the support for the TX39 Mips processor.
341
 
342
   Matsushita sponsored the support for the MN10200 and MN10300
343
processors.
344
 
345
   Fujitsu sponsored the support for SPARClite and FR30 processors.
346
 
347
   Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
348
watchpoints.
349
 
350
   Michael Snyder added support for tracepoints.
351
 
352
   Stu Grossman wrote gdbserver.
353
 
354
   Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
355
innumerable bug fixes and cleanups throughout GDB.
356
 
357
   The following people at the Hewlett-Packard Company contributed
358
support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
359
(narrow mode), HP's implementation of kernel threads, HP's aC++
360
compiler, and the Text User Interface (nee Terminal User Interface):
361
Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
362
Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
363
provided HP-specific information in this manual.
364
 
365
   DJ Delorie ported GDB to MS-DOS, for the DJGPP project.  Robert
366
Hoehne made significant contributions to the DJGPP port.
367
 
368
   Cygnus Solutions has sponsored GDB maintenance and much of its
369
development since 1991.  Cygnus engineers who have worked on GDB
370
fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
371
Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
372
Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
373
Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
374
Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
375
addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
376
JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
377
Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
378
Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
379
Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
380
Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
381
Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
382
Zuhn have made contributions both large and small.
383
 
384
   Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
385
Cygnus Solutions, implemented the original GDB/MI interface.
386
 
387
   Jim Blandy added support for preprocessor macros, while working for
388
Red Hat.
389
 
390
   Andrew Cagney designed GDB's architecture vector.  Many people
391
including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek,
392
Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei Sakamoto,
393
Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna
394
Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration
395
of old architectures to this new framework.
396
 
397
   Andrew Cagney completely re-designed and re-implemented GDB's
398
unwinder framework, this consisting of a fresh new design featuring
399
frame IDs, independent frame sniffers, and the sentinel frame.  Mark
400
Kettenis implemented the DWARF 2 unwinder, Jeff Johnston the libunwind
401
unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad
402
unwinders.  The architecture-specific changes, each involving a
403
complete rewrite of the architecture's frame code, were carried out by
404
Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
405
Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
406
Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
407
Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
408
Weigand.
409
 
410
   Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
411
Tensilica, Inc. contributed support for Xtensa processors.  Others who
412
have worked on the Xtensa port of GDB in the past include Steve Tjiang,
413
John Newlin, and Scott Foehner.
414
 
415

416
File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: Summary,  Up: Top
417
 
418
1 A Sample GDB Session
419
**********************
420
 
421
You can use this manual at your leisure to read all about GDB.
422
However, a handful of commands are enough to get started using the
423
debugger.  This chapter illustrates those commands.
424
 
425
   One of the preliminary versions of GNU `m4' (a generic macro
426
processor) exhibits the following bug: sometimes, when we change its
427
quote strings from the default, the commands used to capture one macro
428
definition within another stop working.  In the following short `m4'
429
session, we define a macro `foo' which expands to `0000'; we then use
430
the `m4' built-in `defn' to define `bar' as the same thing.  However,
431
when we change the open quote string to `' and the close quote
432
string to `', the same procedure fails to define a new synonym
433
`baz':
434
 
435
     $ cd gnu/m4
436
     $ ./m4
437
     define(foo,0000)
438
 
439
     foo
440
     0000
441
     define(bar,defn(`foo'))
442
 
443
     bar
444
     0000
445
     changequote(,)
446
 
447
     define(baz,defn(foo))
448
     baz
449
     Ctrl-d
450
     m4: End of input: 0: fatal error: EOF in string
451
 
452
Let us use GDB to try to see what is going on.
453
 
454
     $ gdb m4
455
     GDB is free software and you are welcome to distribute copies
456
      of it under certain conditions; type "show copying" to see
457
      the conditions.
458
     There is absolutely no warranty for GDB; type "show warranty"
459
      for details.
460
 
461
     GDB 6.8, Copyright 1999 Free Software Foundation, Inc...
462
     (gdb)
463
 
464
GDB reads only enough symbol data to know where to find the rest when
465
needed; as a result, the first prompt comes up very quickly.  We now
466
tell GDB to use a narrower display width than usual, so that examples
467
fit in this manual.
468
 
469
     (gdb) set width 70
470
 
471
We need to see how the `m4' built-in `changequote' works.  Having
472
looked at the source, we know the relevant subroutine is
473
`m4_changequote', so we set a breakpoint there with the GDB `break'
474
command.
475
 
476
     (gdb) break m4_changequote
477
     Breakpoint 1 at 0x62f4: file builtin.c, line 879.
478
 
479
Using the `run' command, we start `m4' running under GDB control; as
480
long as control does not reach the `m4_changequote' subroutine, the
481
program runs as usual:
482
 
483
     (gdb) run
484
     Starting program: /work/Editorial/gdb/gnu/m4/m4
485
     define(foo,0000)
486
 
487
     foo
488
     0000
489
 
490
To trigger the breakpoint, we call `changequote'.  GDB suspends
491
execution of `m4', displaying information about the context where it
492
stops.
493
 
494
     changequote(,)
495
 
496
     Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
497
         at builtin.c:879
498
     879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
499
 
500
Now we use the command `n' (`next') to advance execution to the next
501
line of the current function.
502
 
503
     (gdb) n
504
     882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
505
      : nil,
506
 
507
`set_quotes' looks like a promising subroutine.  We can go into it by
508
using the command `s' (`step') instead of `next'.  `step' goes to the
509
next line to be executed in _any_ subroutine, so it steps into
510
`set_quotes'.
511
 
512
     (gdb) s
513
     set_quotes (lq=0x34c78 "", rq=0x34c88 "")
514
         at input.c:530
515
     530         if (lquote != def_lquote)
516
 
517
The display that shows the subroutine where `m4' is now suspended (and
518
its arguments) is called a stack frame display.  It shows a summary of
519
the stack.  We can use the `backtrace' command (which can also be
520
spelled `bt'), to see where we are in the stack as a whole: the
521
`backtrace' command displays a stack frame for each active subroutine.
522
 
523
     (gdb) bt
524
     #0  set_quotes (lq=0x34c78 "", rq=0x34c88 "")
525
         at input.c:530
526
     #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
527
         at builtin.c:882
528
     #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
529
     #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
530
         at macro.c:71
531
     #4  0x79dc in expand_input () at macro.c:40
532
     #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
533
 
534
We step through a few more lines to see what happens.  The first two
535
times, we can use `s'; the next two times we use `n' to avoid falling
536
into the `xstrdup' subroutine.
537
 
538
     (gdb) s
539
     0x3b5c  532         if (rquote != def_rquote)
540
     (gdb) s
541
     0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
542
     def_lquote : xstrdup(lq);
543
     (gdb) n
544
     536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
545
      : xstrdup(rq);
546
     (gdb) n
547
     538         len_lquote = strlen(rquote);
548
 
549
The last line displayed looks a little odd; we can examine the variables
550
`lquote' and `rquote' to see if they are in fact the new left and right
551
quotes we specified.  We use the command `p' (`print') to see their
552
values.
553
 
554
     (gdb) p lquote
555
     $1 = 0x35d40 ""
556
     (gdb) p rquote
557
     $2 = 0x35d50 ""
558
 
559
`lquote' and `rquote' are indeed the new left and right quotes.  To
560
look at some context, we can display ten lines of source surrounding
561
the current line with the `l' (`list') command.
562
 
563
     (gdb) l
564
     533             xfree(rquote);
565
     534
566
     535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
567
      : xstrdup (lq);
568
     536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
569
      : xstrdup (rq);
570
     537
571
     538         len_lquote = strlen(rquote);
572
     539         len_rquote = strlen(lquote);
573
     540     }
574
     541
575
     542     void
576
 
577
Let us step past the two lines that set `len_lquote' and `len_rquote',
578
and then examine the values of those variables.
579
 
580
     (gdb) n
581
     539         len_rquote = strlen(lquote);
582
     (gdb) n
583
     540     }
584
     (gdb) p len_lquote
585
     $3 = 9
586
     (gdb) p len_rquote
587
     $4 = 7
588
 
589
That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
590
meant to be the lengths of `lquote' and `rquote' respectively.  We can
591
set them to better values using the `p' command, since it can print the
592
value of any expression--and that expression can include subroutine
593
calls and assignments.
594
 
595
     (gdb) p len_lquote=strlen(lquote)
596
     $5 = 7
597
     (gdb) p len_rquote=strlen(rquote)
598
     $6 = 9
599
 
600
Is that enough to fix the problem of using the new quotes with the `m4'
601
built-in `defn'?  We can allow `m4' to continue executing with the `c'
602
(`continue') command, and then try the example that caused trouble
603
initially:
604
 
605
     (gdb) c
606
     Continuing.
607
 
608
     define(baz,defn(foo))
609
 
610
     baz
611
     0000
612
 
613
Success!  The new quotes now work just as well as the default ones.  The
614
problem seems to have been just the two typos defining the wrong
615
lengths.  We allow `m4' exit by giving it an EOF as input:
616
 
617
     Ctrl-d
618
     Program exited normally.
619
 
620
The message `Program exited normally.' is from GDB; it indicates `m4'
621
has finished executing.  We can end our GDB session with the GDB `quit'
622
command.
623
 
624
     (gdb) quit
625
 
626

627
File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
628
 
629
2 Getting In and Out of GDB
630
***************************
631
 
632
This chapter discusses how to start GDB, and how to get out of it.  The
633
essentials are:
634
   * type `gdb' to start GDB.
635
 
636
   * type `quit' or `Ctrl-d' to exit.
637
 
638
* Menu:
639
 
640
* Invoking GDB::                How to start GDB
641
* Quitting GDB::                How to quit GDB
642
* Shell Commands::              How to use shell commands inside GDB
643
* Logging Output::              How to log GDB's output to a file
644
 
645

646
File: gdb.info,  Node: Invoking GDB,  Next: Quitting GDB,  Up: Invocation
647
 
648
2.1 Invoking GDB
649
================
650
 
651
Invoke GDB by running the program `gdb'.  Once started, GDB reads
652
commands from the terminal until you tell it to exit.
653
 
654
   You can also run `gdb' with a variety of arguments and options, to
655
specify more of your debugging environment at the outset.
656
 
657
   The command-line options described here are designed to cover a
658
variety of situations; in some environments, some of these options may
659
effectively be unavailable.
660
 
661
   The most usual way to start GDB is with one argument, specifying an
662
executable program:
663
 
664
     gdb PROGRAM
665
 
666
You can also start with both an executable program and a core file
667
specified:
668
 
669
     gdb PROGRAM CORE
670
 
671
   You can, instead, specify a process ID as a second argument, if you
672
want to debug a running process:
673
 
674
     gdb PROGRAM 1234
675
 
676
would attach GDB to process `1234' (unless you also have a file named
677
`1234'; GDB does check for a core file first).
678
 
679
   Taking advantage of the second command-line argument requires a
680
fairly complete operating system; when you use GDB as a remote debugger
681
attached to a bare board, there may not be any notion of "process", and
682
there is often no way to get a core dump.  GDB will warn you if it is
683
unable to attach or to read core dumps.
684
 
685
   You can optionally have `gdb' pass any arguments after the
686
executable file to the inferior using `--args'.  This option stops
687
option processing.
688
     gdb --args gcc -O2 -c foo.c
689
   This will cause `gdb' to debug `gcc', and to set `gcc''s
690
command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
691
 
692
   You can run `gdb' without printing the front material, which
693
describes GDB's non-warranty, by specifying `-silent':
694
 
695
     gdb -silent
696
 
697
You can further control how GDB starts up by using command-line
698
options.  GDB itself can remind you of the options available.
699
 
700
Type
701
 
702
     gdb -help
703
 
704
to display all available options and briefly describe their use (`gdb
705
-h' is a shorter equivalent).
706
 
707
   All options and command line arguments you give are processed in
708
sequential order.  The order makes a difference when the `-x' option is
709
used.
710
 
711
* Menu:
712
 
713
* File Options::                Choosing files
714
* Mode Options::                Choosing modes
715
* Startup::                     What GDB does during startup
716
 
717

718
File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
719
 
720
2.1.1 Choosing Files
721
--------------------
722
 
723
When GDB starts, it reads any arguments other than options as
724
specifying an executable file and core file (or process ID).  This is
725
the same as if the arguments were specified by the `-se' and `-c' (or
726
`-p') options respectively.  (GDB reads the first argument that does
727
not have an associated option flag as equivalent to the `-se' option
728
followed by that argument; and the second argument that does not have
729
an associated option flag, if any, as equivalent to the `-c'/`-p'
730
option followed by that argument.)  If the second argument begins with
731
a decimal digit, GDB will first attempt to attach to it as a process,
732
and if that fails, attempt to open it as a corefile.  If you have a
733
corefile whose name begins with a digit, you can prevent GDB from
734
treating it as a pid by prefixing it with `./', e.g. `./12345'.
735
 
736
   If GDB has not been configured to included core file support, such
737
as for most embedded targets, then it will complain about a second
738
argument and ignore it.
739
 
740
   Many options have both long and short forms; both are shown in the
741
following list.  GDB also recognizes the long forms if you truncate
742
them, so long as enough of the option is present to be unambiguous.
743
(If you prefer, you can flag option arguments with `--' rather than
744
`-', though we illustrate the more usual convention.)
745
 
746
`-symbols FILE'
747
`-s FILE'
748
     Read symbol table from file FILE.
749
 
750
`-exec FILE'
751
`-e FILE'
752
     Use file FILE as the executable file to execute when appropriate,
753
     and for examining pure data in conjunction with a core dump.
754
 
755
`-se FILE'
756
     Read symbol table from file FILE and use it as the executable file.
757
 
758
`-core FILE'
759
`-c FILE'
760
     Use file FILE as a core dump to examine.
761
 
762
`-pid NUMBER'
763
`-p NUMBER'
764
     Connect to process ID NUMBER, as with the `attach' command.
765
 
766
`-command FILE'
767
`-x FILE'
768
     Execute GDB commands from file FILE.  *Note Command files: Command
769
     Files.
770
 
771
`-eval-command COMMAND'
772
`-ex COMMAND'
773
     Execute a single GDB command.
774
 
775
     This option may be used multiple times to call multiple commands.
776
     It may also be interleaved with `-command' as required.
777
 
778
          gdb -ex 'target sim' -ex 'load' \
779
             -x setbreakpoints -ex 'run' a.out
780
 
781
`-directory DIRECTORY'
782
`-d DIRECTORY'
783
     Add DIRECTORY to the path to search for source and script files.
784
 
785
`-r'
786
`-readnow'
787
     Read each symbol file's entire symbol table immediately, rather
788
     than the default, which is to read it incrementally as it is
789
     needed.  This makes startup slower, but makes future operations
790
     faster.
791
 
792
 
793

794
File: gdb.info,  Node: Mode Options,  Next: Startup,  Prev: File Options,  Up: Invoking GDB
795
 
796
2.1.2 Choosing Modes
797
--------------------
798
 
799
You can run GDB in various alternative modes--for example, in batch
800
mode or quiet mode.
801
 
802
`-nx'
803
`-n'
804
     Do not execute commands found in any initialization files.
805
     Normally, GDB executes the commands in these files after all the
806
     command options and arguments have been processed.  *Note Command
807
     Files: Command Files.
808
 
809
`-quiet'
810
`-silent'
811
`-q'
812
     "Quiet".  Do not print the introductory and copyright messages.
813
     These messages are also suppressed in batch mode.
814
 
815
`-batch'
816
     Run in batch mode.  Exit with status `0' after processing all the
817
     command files specified with `-x' (and all commands from
818
     initialization files, if not inhibited with `-n').  Exit with
819
     nonzero status if an error occurs in executing the GDB commands in
820
     the command files.
821
 
822
     Batch mode may be useful for running GDB as a filter, for example
823
     to download and run a program on another computer; in order to
824
     make this more useful, the message
825
 
826
          Program exited normally.
827
 
828
     (which is ordinarily issued whenever a program running under GDB
829
     control terminates) is not issued when running in batch mode.
830
 
831
`-batch-silent'
832
     Run in batch mode exactly like `-batch', but totally silently.  All
833
     GDB output to `stdout' is prevented (`stderr' is unaffected).
834
     This is much quieter than `-silent' and would be useless for an
835
     interactive session.
836
 
837
     This is particularly useful when using targets that give `Loading
838
     section' messages, for example.
839
 
840
     Note that targets that give their output via GDB, as opposed to
841
     writing directly to `stdout', will also be made silent.
842
 
843
`-return-child-result'
844
     The return code from GDB will be the return code from the child
845
     process (the process being debugged), with the following
846
     exceptions:
847
 
848
        * GDB exits abnormally.  E.g., due to an incorrect argument or
849
          an internal error.  In this case the exit code is the same as
850
          it would have been without `-return-child-result'.
851
 
852
        * The user quits with an explicit value.  E.g., `quit 1'.
853
 
854
        * The child process never runs, or is not allowed to terminate,
855
          in which case the exit code will be -1.
856
 
857
     This option is useful in conjunction with `-batch' or
858
     `-batch-silent', when GDB is being used as a remote program loader
859
     or simulator interface.
860
 
861
`-nowindows'
862
`-nw'
863
     "No windows".  If GDB comes with a graphical user interface (GUI)
864
     built in, then this option tells GDB to only use the command-line
865
     interface.  If no GUI is available, this option has no effect.
866
 
867
`-windows'
868
`-w'
869
     If GDB includes a GUI, then this option requires it to be used if
870
     possible.
871
 
872
`-cd DIRECTORY'
873
     Run GDB using DIRECTORY as its working directory, instead of the
874
     current directory.
875
 
876
`-fullname'
877
`-f'
878
     GNU Emacs sets this option when it runs GDB as a subprocess.  It
879
     tells GDB to output the full file name and line number in a
880
     standard, recognizable fashion each time a stack frame is
881
     displayed (which includes each time your program stops).  This
882
     recognizable format looks like two `\032' characters, followed by
883
     the file name, line number and character position separated by
884
     colons, and a newline.  The Emacs-to-GDB interface program uses
885
     the two `\032' characters as a signal to display the source code
886
     for the frame.
887
 
888
`-epoch'
889
     The Epoch Emacs-GDB interface sets this option when it runs GDB as
890
     a subprocess.  It tells GDB to modify its print routines so as to
891
     allow Epoch to display values of expressions in a separate window.
892
 
893
`-annotate LEVEL'
894
     This option sets the "annotation level" inside GDB.  Its effect is
895
     identical to using `set annotate LEVEL' (*note Annotations::).
896
     The annotation LEVEL controls how much information GDB prints
897
     together with its prompt, values of expressions, source lines, and
898
     other types of output.  Level 0 is the normal, level 1 is for use
899
     when GDB is run as a subprocess of GNU Emacs, level 3 is the
900
     maximum annotation suitable for programs that control GDB, and
901
     level 2 has been deprecated.
902
 
903
     The annotation mechanism has largely been superseded by GDB/MI
904
     (*note GDB/MI::).
905
 
906
`--args'
907
     Change interpretation of command line so that arguments following
908
     the executable file are passed as command line arguments to the
909
     inferior.  This option stops option processing.
910
 
911
`-baud BPS'
912
`-b BPS'
913
     Set the line speed (baud rate or bits per second) of any serial
914
     interface used by GDB for remote debugging.
915
 
916
`-l TIMEOUT'
917
     Set the timeout (in seconds) of any communication used by GDB for
918
     remote debugging.
919
 
920
`-tty DEVICE'
921
`-t DEVICE'
922
     Run using DEVICE for your program's standard input and output.
923
 
924
`-tui'
925
     Activate the "Text User Interface" when starting.  The Text User
926
     Interface manages several text windows on the terminal, showing
927
     source, assembly, registers and GDB command outputs (*note GDB
928
     Text User Interface: TUI.).  Alternatively, the Text User
929
     Interface can be enabled by invoking the program `gdbtui'.  Do not
930
     use this option if you run GDB from Emacs (*note Using GDB under
931
     GNU Emacs: Emacs.).
932
 
933
`-interpreter INTERP'
934
     Use the interpreter INTERP for interface with the controlling
935
     program or device.  This option is meant to be set by programs
936
     which communicate with GDB using it as a back end.  *Note Command
937
     Interpreters: Interpreters.
938
 
939
     `--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
940
     "GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
941
     since GDB version 6.0.  The previous GDB/MI interface, included in
942
     GDB version 5.3 and selected with `--interpreter=mi1', is
943
     deprecated.  Earlier GDB/MI interfaces are no longer supported.
944
 
945
`-write'
946
     Open the executable and core files for both reading and writing.
947
     This is equivalent to the `set write on' command inside GDB (*note
948
     Patching::).
949
 
950
`-statistics'
951
     This option causes GDB to print statistics about time and memory
952
     usage after it completes each command and returns to the prompt.
953
 
954
`-version'
955
     This option causes GDB to print its version number and no-warranty
956
     blurb, and exit.
957
 
958
 
959

960
File: gdb.info,  Node: Startup,  Prev: Mode Options,  Up: Invoking GDB
961
 
962
2.1.3 What GDB Does During Startup
963
----------------------------------
964
 
965
Here's the description of what GDB does during session startup:
966
 
967
  1. Sets up the command interpreter as specified by the command line
968
     (*note interpreter: Mode Options.).
969
 
970
  2. Reads the "init file" (if any) in your home directory(1) and
971
     executes all the commands in that file.
972
 
973
  3. Processes command line options and operands.
974
 
975
  4. Reads and executes the commands from init file (if any) in the
976
     current working directory.  This is only done if the current
977
     directory is different from your home directory.  Thus, you can
978
     have more than one init file, one generic in your home directory,
979
     and another, specific to the program you are debugging, in the
980
     directory where you invoke GDB.
981
 
982
  5. Reads command files specified by the `-x' option.  *Note Command
983
     Files::, for more details about GDB command files.
984
 
985
  6. Reads the command history recorded in the "history file".  *Note
986
     Command History::, for more details about the command history and
987
     the files where GDB records it.
988
 
989
   Init files use the same syntax as "command files" (*note Command
990
Files::) and are processed by GDB in the same way.  The init file in
991
your home directory can set options (such as `set complaints') that
992
affect subsequent processing of command line options and operands.
993
Init files are not executed if you use the `-nx' option (*note Choosing
994
Modes: Mode Options.).
995
 
996
   The GDB init files are normally called `.gdbinit'.  The DJGPP port
997
of GDB uses the name `gdb.ini', due to the limitations of file names
998
imposed by DOS filesystems.  The Windows ports of GDB use the standard
999
name, but if they find a `gdb.ini' file, they warn you about that and
1000
suggest to rename the file to the standard name.
1001
 
1002
   ---------- Footnotes ----------
1003
 
1004
   (1) On DOS/Windows systems, the home directory is the one pointed to
1005
by the `HOME' environment variable.
1006
 
1007

1008
File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
1009
 
1010
2.2 Quitting GDB
1011
================
1012
 
1013
`quit [EXPRESSION]'
1014
`q'
1015
     To exit GDB, use the `quit' command (abbreviated `q'), or type an
1016
     end-of-file character (usually `Ctrl-d').  If you do not supply
1017
     EXPRESSION, GDB will terminate normally; otherwise it will
1018
     terminate using the result of EXPRESSION as the error code.
1019
 
1020
   An interrupt (often `Ctrl-c') does not exit from GDB, but rather
1021
terminates the action of any GDB command that is in progress and
1022
returns to GDB command level.  It is safe to type the interrupt
1023
character at any time because GDB does not allow it to take effect
1024
until a time when it is safe.
1025
 
1026
   If you have been using GDB to control an attached process or device,
1027
you can release it with the `detach' command (*note Debugging an
1028
Already-running Process: Attach.).
1029
 
1030

1031
File: gdb.info,  Node: Shell Commands,  Next: Logging Output,  Prev: Quitting GDB,  Up: Invocation
1032
 
1033
2.3 Shell Commands
1034
==================
1035
 
1036
If you need to execute occasional shell commands during your debugging
1037
session, there is no need to leave or suspend GDB; you can just use the
1038
`shell' command.
1039
 
1040
`shell COMMAND STRING'
1041
     Invoke a standard shell to execute COMMAND STRING.  If it exists,
1042
     the environment variable `SHELL' determines which shell to run.
1043
     Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
1044
     `COMMAND.COM' on MS-DOS, etc.).
1045
 
1046
   The utility `make' is often needed in development environments.  You
1047
do not have to use the `shell' command for this purpose in GDB:
1048
 
1049
`make MAKE-ARGS'
1050
     Execute the `make' program with the specified arguments.  This is
1051
     equivalent to `shell make MAKE-ARGS'.
1052
 
1053

1054
File: gdb.info,  Node: Logging Output,  Prev: Shell Commands,  Up: Invocation
1055
 
1056
2.4 Logging Output
1057
==================
1058
 
1059
You may want to save the output of GDB commands to a file.  There are
1060
several commands to control GDB's logging.
1061
 
1062
`set logging on'
1063
     Enable logging.
1064
 
1065
`set logging off'
1066
     Disable logging.
1067
 
1068
`set logging file FILE'
1069
     Change the name of the current logfile.  The default logfile is
1070
     `gdb.txt'.
1071
 
1072
`set logging overwrite [on|off]'
1073
     By default, GDB will append to the logfile.  Set `overwrite' if
1074
     you want `set logging on' to overwrite the logfile instead.
1075
 
1076
`set logging redirect [on|off]'
1077
     By default, GDB output will go to both the terminal and the
1078
     logfile.  Set `redirect' if you want output to go only to the log
1079
     file.
1080
 
1081
`show logging'
1082
     Show the current values of the logging settings.
1083
 
1084

1085
File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
1086
 
1087
3 GDB Commands
1088
**************
1089
 
1090
You can abbreviate a GDB command to the first few letters of the command
1091
name, if that abbreviation is unambiguous; and you can repeat certain
1092
GDB commands by typing just .  You can also use the  key to
1093
get GDB to fill out the rest of a word in a command (or to show you the
1094
alternatives available, if there is more than one possibility).
1095
 
1096
* Menu:
1097
 
1098
* Command Syntax::              How to give commands to GDB
1099
* Completion::                  Command completion
1100
* Help::                        How to ask GDB for help
1101
 
1102

1103
File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
1104
 
1105
3.1 Command Syntax
1106
==================
1107
 
1108
A GDB command is a single line of input.  There is no limit on how long
1109
it can be.  It starts with a command name, which is followed by
1110
arguments whose meaning depends on the command name.  For example, the
1111
command `step' accepts an argument which is the number of times to
1112
step, as in `step 5'.  You can also use the `step' command with no
1113
arguments.  Some commands do not allow any arguments.
1114
 
1115
   GDB command names may always be truncated if that abbreviation is
1116
unambiguous.  Other possible command abbreviations are listed in the
1117
documentation for individual commands.  In some cases, even ambiguous
1118
abbreviations are allowed; for example, `s' is specially defined as
1119
equivalent to `step' even though there are other commands whose names
1120
start with `s'.  You can test abbreviations by using them as arguments
1121
to the `help' command.
1122
 
1123
   A blank line as input to GDB (typing just ) means to repeat the
1124
previous command.  Certain commands (for example, `run') will not
1125
repeat this way; these are commands whose unintentional repetition
1126
might cause trouble and which you are unlikely to want to repeat.
1127
User-defined commands can disable this feature; see *Note dont-repeat:
1128
Define.
1129
 
1130
   The `list' and `x' commands, when you repeat them with ,
1131
construct new arguments rather than repeating exactly as typed.  This
1132
permits easy scanning of source or memory.
1133
 
1134
   GDB can also use  in another way: to partition lengthy output,
1135
in a way similar to the common utility `more' (*note Screen Size:
1136
Screen Size.).  Since it is easy to press one  too many in this
1137
situation, GDB disables command repetition after any command that
1138
generates this sort of display.
1139
 
1140
   Any text from a `#' to the end of the line is a comment; it does
1141
nothing.  This is useful mainly in command files (*note Command Files:
1142
Command Files.).
1143
 
1144
   The `Ctrl-o' binding is useful for repeating a complex sequence of
1145
commands.  This command accepts the current line, like , and then
1146
fetches the next line relative to the current line from the history for
1147
editing.
1148
 
1149

1150
File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
1151
 
1152
3.2 Command Completion
1153
======================
1154
 
1155
GDB can fill in the rest of a word in a command for you, if there is
1156
only one possibility; it can also show you what the valid possibilities
1157
are for the next word in a command, at any time.  This works for GDB
1158
commands, GDB subcommands, and the names of symbols in your program.
1159
 
1160
   Press the  key whenever you want GDB to fill out the rest of a
1161
word.  If there is only one possibility, GDB fills in the word, and
1162
waits for you to finish the command (or press  to enter it).  For
1163
example, if you type
1164
 
1165
     (gdb) info bre 
1166
 
1167
GDB fills in the rest of the word `breakpoints', since that is the only
1168
`info' subcommand beginning with `bre':
1169
 
1170
     (gdb) info breakpoints
1171
 
1172
You can either press  at this point, to run the `info breakpoints'
1173
command, or backspace and enter something else, if `breakpoints' does
1174
not look like the command you expected.  (If you were sure you wanted
1175
`info breakpoints' in the first place, you might as well just type
1176
 immediately after `info bre', to exploit command abbreviations
1177
rather than command completion).
1178
 
1179
   If there is more than one possibility for the next word when you
1180
press , GDB sounds a bell.  You can either supply more characters
1181
and try again, or just press  a second time; GDB displays all the
1182
possible completions for that word.  For example, you might want to set
1183
a breakpoint on a subroutine whose name begins with `make_', but when
1184
you type `b make_' GDB just sounds the bell.  Typing  again
1185
displays all the function names in your program that begin with those
1186
characters, for example:
1187
 
1188
     (gdb) b make_ 
1189
GDB sounds bell; press  again, to see:
1190
     make_a_section_from_file     make_environ
1191
     make_abs_section             make_function_type
1192
     make_blockvector             make_pointer_type
1193
     make_cleanup                 make_reference_type
1194
     make_command                 make_symbol_completion_list
1195
     (gdb) b make_
1196
 
1197
After displaying the available possibilities, GDB copies your partial
1198
input (`b make_' in the example) so you can finish the command.
1199
 
1200
   If you just want to see the list of alternatives in the first place,
1201
you can press `M-?' rather than pressing  twice.  `M-?' means
1202
` ?'.  You can type this either by holding down a key designated
1203
as the  shift on your keyboard (if there is one) while typing
1204
`?', or as  followed by `?'.
1205
 
1206
   Sometimes the string you need, while logically a "word", may contain
1207
parentheses or other characters that GDB normally excludes from its
1208
notion of a word.  To permit word completion to work in this situation,
1209
you may enclose words in `'' (single quote marks) in GDB commands.
1210
 
1211
   The most likely situation where you might need this is in typing the
1212
name of a C++ function.  This is because C++ allows function
1213
overloading (multiple definitions of the same function, distinguished
1214
by argument type).  For example, when you want to set a breakpoint you
1215
may need to distinguish whether you mean the version of `name' that
1216
takes an `int' parameter, `name(int)', or the version that takes a
1217
`float' parameter, `name(float)'.  To use the word-completion
1218
facilities in this situation, type a single quote `'' at the beginning
1219
of the function name.  This alerts GDB that it may need to consider
1220
more information than usual when you press  or `M-?' to request
1221
word completion:
1222
 
1223
     (gdb) b 'bubble( M-?
1224
     bubble(double,double)    bubble(int,int)
1225
     (gdb) b 'bubble(
1226
 
1227
   In some cases, GDB can tell that completing a name requires using
1228
quotes.  When this happens, GDB inserts the quote for you (while
1229
completing as much as it can) if you do not type the quote in the first
1230
place:
1231
 
1232
     (gdb) b bub 
1233
GDB alters your input line to the following, and rings a bell:
1234
     (gdb) b 'bubble(
1235
 
1236
In general, GDB can tell that a quote is needed (and inserts it) if you
1237
have not yet started typing the argument list when you ask for
1238
completion on an overloaded symbol.
1239
 
1240
   For more information about overloaded functions, see *Note C++
1241
Expressions: C Plus Plus Expressions.  You can use the command `set
1242
overload-resolution off' to disable overload resolution; see *Note GDB
1243
Features for C++: Debugging C Plus Plus.
1244
 
1245

1246
File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
1247
 
1248
3.3 Getting Help
1249
================
1250
 
1251
You can always ask GDB itself for information on its commands, using
1252
the command `help'.
1253
 
1254
`help'
1255
`h'
1256
     You can use `help' (abbreviated `h') with no arguments to display
1257
     a short list of named classes of commands:
1258
 
1259
          (gdb) help
1260
          List of classes of commands:
1261
 
1262
          aliases -- Aliases of other commands
1263
          breakpoints -- Making program stop at certain points
1264
          data -- Examining data
1265
          files -- Specifying and examining files
1266
          internals -- Maintenance commands
1267
          obscure -- Obscure features
1268
          running -- Running the program
1269
          stack -- Examining the stack
1270
          status -- Status inquiries
1271
          support -- Support facilities
1272
          tracepoints -- Tracing of program execution without
1273
                         stopping the program
1274
          user-defined -- User-defined commands
1275
 
1276
          Type "help" followed by a class name for a list of
1277
          commands in that class.
1278
          Type "help" followed by command name for full
1279
          documentation.
1280
          Command name abbreviations are allowed if unambiguous.
1281
          (gdb)
1282
 
1283
`help CLASS'
1284
     Using one of the general help classes as an argument, you can get a
1285
     list of the individual commands in that class.  For example, here
1286
     is the help display for the class `status':
1287
 
1288
          (gdb) help status
1289
          Status inquiries.
1290
 
1291
          List of commands:
1292
 
1293
          info -- Generic command for showing things
1294
                  about the program being debugged
1295
          show -- Generic command for showing things
1296
                  about the debugger
1297
 
1298
          Type "help" followed by command name for full
1299
          documentation.
1300
          Command name abbreviations are allowed if unambiguous.
1301
          (gdb)
1302
 
1303
`help COMMAND'
1304
     With a command name as `help' argument, GDB displays a short
1305
     paragraph on how to use that command.
1306
 
1307
`apropos ARGS'
1308
     The `apropos' command searches through all of the GDB commands,
1309
     and their documentation, for the regular expression specified in
1310
     ARGS. It prints out all matches found. For example:
1311
 
1312
          apropos reload
1313
 
1314
     results in:
1315
 
1316
          set symbol-reloading -- Set dynamic symbol table reloading
1317
                                  multiple times in one run
1318
          show symbol-reloading -- Show dynamic symbol table reloading
1319
                                  multiple times in one run
1320
 
1321
`complete ARGS'
1322
     The `complete ARGS' command lists all the possible completions for
1323
     the beginning of a command.  Use ARGS to specify the beginning of
1324
     the command you want completed.  For example:
1325
 
1326
          complete i
1327
 
1328
     results in:
1329
 
1330
          if
1331
          ignore
1332
          info
1333
          inspect
1334
 
1335
     This is intended for use by GNU Emacs.
1336
 
1337
   In addition to `help', you can use the GDB commands `info' and
1338
`show' to inquire about the state of your program, or the state of GDB
1339
itself.  Each command supports many topics of inquiry; this manual
1340
introduces each of them in the appropriate context.  The listings under
1341
`info' and under `show' in the Index point to all the sub-commands.
1342
*Note Index::.
1343
 
1344
`info'
1345
     This command (abbreviated `i') is for describing the state of your
1346
     program.  For example, you can show the arguments passed to a
1347
     function with `info args', list the registers currently in use
1348
     with `info registers', or list the breakpoints you have set with
1349
     `info breakpoints'.  You can get a complete list of the `info'
1350
     sub-commands with `help info'.
1351
 
1352
`set'
1353
     You can assign the result of an expression to an environment
1354
     variable with `set'.  For example, you can set the GDB prompt to a
1355
     $-sign with `set prompt $'.
1356
 
1357
`show'
1358
     In contrast to `info', `show' is for describing the state of GDB
1359
     itself.  You can change most of the things you can `show', by
1360
     using the related command `set'; for example, you can control what
1361
     number system is used for displays with `set radix', or simply
1362
     inquire which is currently in use with `show radix'.
1363
 
1364
     To display all the settable parameters and their current values,
1365
     you can use `show' with no arguments; you may also use `info set'.
1366
     Both commands produce the same display.
1367
 
1368
   Here are three miscellaneous `show' subcommands, all of which are
1369
exceptional in lacking corresponding `set' commands:
1370
 
1371
`show version'
1372
     Show what version of GDB is running.  You should include this
1373
     information in GDB bug-reports.  If multiple versions of GDB are
1374
     in use at your site, you may need to determine which version of
1375
     GDB you are running; as GDB evolves, new commands are introduced,
1376
     and old ones may wither away.  Also, many system vendors ship
1377
     variant versions of GDB, and there are variant versions of GDB in
1378
     GNU/Linux distributions as well.  The version number is the same
1379
     as the one announced when you start GDB.
1380
 
1381
`show copying'
1382
`info copying'
1383
     Display information about permission for copying GDB.
1384
 
1385
`show warranty'
1386
`info warranty'
1387
     Display the GNU "NO WARRANTY" statement, or a warranty, if your
1388
     version of GDB comes with one.
1389
 
1390
 
1391

1392
File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
1393
 
1394
4 Running Programs Under GDB
1395
****************************
1396
 
1397
When you run a program under GDB, you must first generate debugging
1398
information when you compile it.
1399
 
1400
   You may start GDB with its arguments, if any, in an environment of
1401
your choice.  If you are doing native debugging, you may redirect your
1402
program's input and output, debug an already running process, or kill a
1403
child process.
1404
 
1405
* Menu:
1406
 
1407
* Compilation::                 Compiling for debugging
1408
* Starting::                    Starting your program
1409
* Arguments::                   Your program's arguments
1410
* Environment::                 Your program's environment
1411
 
1412
* Working Directory::           Your program's working directory
1413
* Input/Output::                Your program's input and output
1414
* Attach::                      Debugging an already-running process
1415
* Kill Process::                Killing the child process
1416
 
1417
* Threads::                     Debugging programs with multiple threads
1418
* Processes::                   Debugging programs with multiple processes
1419
* Checkpoint/Restart::          Setting a _bookmark_ to return to later
1420
 
1421

1422
File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
1423
 
1424
4.1 Compiling for Debugging
1425
===========================
1426
 
1427
In order to debug a program effectively, you need to generate debugging
1428
information when you compile it.  This debugging information is stored
1429
in the object file; it describes the data type of each variable or
1430
function and the correspondence between source line numbers and
1431
addresses in the executable code.
1432
 
1433
   To request debugging information, specify the `-g' option when you
1434
run the compiler.
1435
 
1436
   Programs that are to be shipped to your customers are compiled with
1437
optimizations, using the `-O' compiler option.  However, many compilers
1438
are unable to handle the `-g' and `-O' options together.  Using those
1439
compilers, you cannot generate optimized executables containing
1440
debugging information.
1441
 
1442
   GCC, the GNU C/C++ compiler, supports `-g' with or without `-O',
1443
making it possible to debug optimized code.  We recommend that you
1444
_always_ use `-g' whenever you compile a program.  You may think your
1445
program is correct, but there is no sense in pushing your luck.
1446
 
1447
   When you debug a program compiled with `-g -O', remember that the
1448
optimizer is rearranging your code; the debugger shows you what is
1449
really there.  Do not be too surprised when the execution path does not
1450
exactly match your source file!  An extreme example: if you define a
1451
variable, but never use it, GDB never sees that variable--because the
1452
compiler optimizes it out of existence.
1453
 
1454
   Some things do not work as well with `-g -O' as with just `-g',
1455
particularly on machines with instruction scheduling.  If in doubt,
1456
recompile with `-g' alone, and if this fixes the problem, please report
1457
it to us as a bug (including a test case!).  *Note Variables::, for
1458
more information about debugging optimized code.
1459
 
1460
   Older versions of the GNU C compiler permitted a variant option
1461
`-gg' for debugging information.  GDB no longer supports this format;
1462
if your GNU C compiler has this option, do not use it.
1463
 
1464
   GDB knows about preprocessor macros and can show you their expansion
1465
(*note Macros::).  Most compilers do not include information about
1466
preprocessor macros in the debugging information if you specify the
1467
`-g' flag alone, because this information is rather large.  Version 3.1
1468
and later of GCC, the GNU C compiler, provides macro information if you
1469
specify the options `-gdwarf-2' and `-g3'; the former option requests
1470
debugging information in the Dwarf 2 format, and the latter requests
1471
"extra information".  In the future, we hope to find more compact ways
1472
to represent macro information, so that it can be included with `-g'
1473
alone.
1474
 
1475

1476
File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
1477
 
1478
4.2 Starting your Program
1479
=========================
1480
 
1481
`run'
1482
`r'
1483
     Use the `run' command to start your program under GDB.  You must
1484
     first specify the program name (except on VxWorks) with an
1485
     argument to GDB (*note Getting In and Out of GDB: Invocation.), or
1486
     by using the `file' or `exec-file' command (*note Commands to
1487
     Specify Files: Files.).
1488
 
1489
 
1490
   If you are running your program in an execution environment that
1491
supports processes, `run' creates an inferior process and makes that
1492
process run your program.  (In environments without processes, `run'
1493
jumps to the start of your program.)
1494
 
1495
   The execution of a program is affected by certain information it
1496
receives from its superior.  GDB provides ways to specify this
1497
information, which you must do _before_ starting your program.  (You
1498
can change it after starting your program, but such changes only affect
1499
your program the next time you start it.)  This information may be
1500
divided into four categories:
1501
 
1502
The _arguments._
1503
     Specify the arguments to give your program as the arguments of the
1504
     `run' command.  If a shell is available on your target, the shell
1505
     is used to pass the arguments, so that you may use normal
1506
     conventions (such as wildcard expansion or variable substitution)
1507
     in describing the arguments.  In Unix systems, you can control
1508
     which shell is used with the `SHELL' environment variable.  *Note
1509
     Your Program's Arguments: Arguments.
1510
 
1511
The _environment._
1512
     Your program normally inherits its environment from GDB, but you
1513
     can use the GDB commands `set environment' and `unset environment'
1514
     to change parts of the environment that affect your program.
1515
     *Note Your Program's Environment: Environment.
1516
 
1517
The _working directory._
1518
     Your program inherits its working directory from GDB.  You can set
1519
     the GDB working directory with the `cd' command in GDB.  *Note
1520
     Your Program's Working Directory: Working Directory.
1521
 
1522
The _standard input and output._
1523
     Your program normally uses the same device for standard input and
1524
     standard output as GDB is using.  You can redirect input and output
1525
     in the `run' command line, or you can use the `tty' command to set
1526
     a different device for your program.  *Note Your Program's Input
1527
     and Output: Input/Output.
1528
 
1529
     _Warning:_ While input and output redirection work, you cannot use
1530
     pipes to pass the output of the program you are debugging to
1531
     another program; if you attempt this, GDB is likely to wind up
1532
     debugging the wrong program.
1533
 
1534
   When you issue the `run' command, your program begins to execute
1535
immediately.  *Note Stopping and Continuing: Stopping, for discussion
1536
of how to arrange for your program to stop.  Once your program has
1537
stopped, you may call functions in your program, using the `print' or
1538
`call' commands.  *Note Examining Data: Data.
1539
 
1540
   If the modification time of your symbol file has changed since the
1541
last time GDB read its symbols, GDB discards its symbol table, and
1542
reads it again.  When it does this, GDB tries to retain your current
1543
breakpoints.
1544
 
1545
`start'
1546
     The name of the main procedure can vary from language to language.
1547
     With C or C++, the main procedure name is always `main', but other
1548
     languages such as Ada do not require a specific name for their
1549
     main procedure.  The debugger provides a convenient way to start
1550
     the execution of the program and to stop at the beginning of the
1551
     main procedure, depending on the language used.
1552
 
1553
     The `start' command does the equivalent of setting a temporary
1554
     breakpoint at the beginning of the main procedure and then invoking
1555
     the `run' command.
1556
 
1557
     Some programs contain an "elaboration" phase where some startup
1558
     code is executed before the main procedure is called.  This
1559
     depends on the languages used to write your program.  In C++, for
1560
     instance, constructors for static and global objects are executed
1561
     before `main' is called.  It is therefore possible that the
1562
     debugger stops before reaching the main procedure.  However, the
1563
     temporary breakpoint will remain to halt execution.
1564
 
1565
     Specify the arguments to give to your program as arguments to the
1566
     `start' command.  These arguments will be given verbatim to the
1567
     underlying `run' command.  Note that the same arguments will be
1568
     reused if no argument is provided during subsequent calls to
1569
     `start' or `run'.
1570
 
1571
     It is sometimes necessary to debug the program during elaboration.
1572
     In these cases, using the `start' command would stop the
1573
     execution of your program too late, as the program would have
1574
     already completed the elaboration phase.  Under these
1575
     circumstances, insert breakpoints in your elaboration code before
1576
     running your program.
1577
 
1578

1579
File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
1580
 
1581
4.3 Your Program's Arguments
1582
============================
1583
 
1584
The arguments to your program can be specified by the arguments of the
1585
`run' command.  They are passed to a shell, which expands wildcard
1586
characters and performs redirection of I/O, and thence to your program.
1587
Your `SHELL' environment variable (if it exists) specifies what shell
1588
GDB uses.  If you do not define `SHELL', GDB uses the default shell
1589
(`/bin/sh' on Unix).
1590
 
1591
   On non-Unix systems, the program is usually invoked directly by GDB,
1592
which emulates I/O redirection via the appropriate system calls, and
1593
the wildcard characters are expanded by the startup code of the
1594
program, not by the shell.
1595
 
1596
   `run' with no arguments uses the same arguments used by the previous
1597
`run', or those set by the `set args' command.
1598
 
1599
`set args'
1600
     Specify the arguments to be used the next time your program is
1601
     run.  If `set args' has no arguments, `run' executes your program
1602
     with no arguments.  Once you have run your program with arguments,
1603
     using `set args' before the next `run' is the only way to run it
1604
     again without arguments.
1605
 
1606
`show args'
1607
     Show the arguments to give your program when it is started.
1608
 
1609

1610
File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
1611
 
1612
4.4 Your Program's Environment
1613
==============================
1614
 
1615
The "environment" consists of a set of environment variables and their
1616
values.  Environment variables conventionally record such things as
1617
your user name, your home directory, your terminal type, and your search
1618
path for programs to run.  Usually you set up environment variables with
1619
the shell and they are inherited by all the other programs you run.
1620
When debugging, it can be useful to try running your program with a
1621
modified environment without having to start GDB over again.
1622
 
1623
`path DIRECTORY'
1624
     Add DIRECTORY to the front of the `PATH' environment variable (the
1625
     search path for executables) that will be passed to your program.
1626
     The value of `PATH' used by GDB does not change.  You may specify
1627
     several directory names, separated by whitespace or by a
1628
     system-dependent separator character (`:' on Unix, `;' on MS-DOS
1629
     and MS-Windows).  If DIRECTORY is already in the path, it is moved
1630
     to the front, so it is searched sooner.
1631
 
1632
     You can use the string `$cwd' to refer to whatever is the current
1633
     working directory at the time GDB searches the path.  If you use
1634
     `.' instead, it refers to the directory where you executed the
1635
     `path' command.  GDB replaces `.' in the DIRECTORY argument (with
1636
     the current path) before adding DIRECTORY to the search path.
1637
 
1638
`show paths'
1639
     Display the list of search paths for executables (the `PATH'
1640
     environment variable).
1641
 
1642
`show environment [VARNAME]'
1643
     Print the value of environment variable VARNAME to be given to
1644
     your program when it starts.  If you do not supply VARNAME, print
1645
     the names and values of all environment variables to be given to
1646
     your program.  You can abbreviate `environment' as `env'.
1647
 
1648
`set environment VARNAME [=VALUE]'
1649
     Set environment variable VARNAME to VALUE.  The value changes for
1650
     your program only, not for GDB itself.  VALUE may be any string;
1651
     the values of environment variables are just strings, and any
1652
     interpretation is supplied by your program itself.  The VALUE
1653
     parameter is optional; if it is eliminated, the variable is set to
1654
     a null value.
1655
 
1656
     For example, this command:
1657
 
1658
          set env USER = foo
1659
 
1660
     tells the debugged program, when subsequently run, that its user
1661
     is named `foo'.  (The spaces around `=' are used for clarity here;
1662
     they are not actually required.)
1663
 
1664
`unset environment VARNAME'
1665
     Remove variable VARNAME from the environment to be passed to your
1666
     program.  This is different from `set env VARNAME ='; `unset
1667
     environment' removes the variable from the environment, rather
1668
     than assigning it an empty value.
1669
 
1670
   _Warning:_ On Unix systems, GDB runs your program using the shell
1671
indicated by your `SHELL' environment variable if it exists (or
1672
`/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
1673
initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
1674
BASH--any variables you set in that file affect your program.  You may
1675
wish to move setting of environment variables to files that are only
1676
run when you sign on, such as `.login' or `.profile'.
1677
 
1678

1679
File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
1680
 
1681
4.5 Your Program's Working Directory
1682
====================================
1683
 
1684
Each time you start your program with `run', it inherits its working
1685
directory from the current working directory of GDB.  The GDB working
1686
directory is initially whatever it inherited from its parent process
1687
(typically the shell), but you can specify a new working directory in
1688
GDB with the `cd' command.
1689
 
1690
   The GDB working directory also serves as a default for the commands
1691
that specify files for GDB to operate on.  *Note Commands to Specify
1692
Files: Files.
1693
 
1694
`cd DIRECTORY'
1695
     Set the GDB working directory to DIRECTORY.
1696
 
1697
`pwd'
1698
     Print the GDB working directory.
1699
 
1700
   It is generally impossible to find the current working directory of
1701
the process being debugged (since a program can change its directory
1702
during its run).  If you work on a system where GDB is configured with
1703
the `/proc' support, you can use the `info proc' command (*note SVR4
1704
Process Information::) to find out the current working directory of the
1705
debuggee.
1706
 
1707

1708
File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
1709
 
1710
4.6 Your Program's Input and Output
1711
===================================
1712
 
1713
By default, the program you run under GDB does input and output to the
1714
same terminal that GDB uses.  GDB switches the terminal to its own
1715
terminal modes to interact with you, but it records the terminal modes
1716
your program was using and switches back to them when you continue
1717
running your program.
1718
 
1719
`info terminal'
1720
     Displays information recorded by GDB about the terminal modes your
1721
     program is using.
1722
 
1723
   You can redirect your program's input and/or output using shell
1724
redirection with the `run' command.  For example,
1725
 
1726
     run > outfile
1727
 
1728
starts your program, diverting its output to the file `outfile'.
1729
 
1730
   Another way to specify where your program should do input and output
1731
is with the `tty' command.  This command accepts a file name as
1732
argument, and causes this file to be the default for future `run'
1733
commands.  It also resets the controlling terminal for the child
1734
process, for future `run' commands.  For example,
1735
 
1736
     tty /dev/ttyb
1737
 
1738
directs that processes started with subsequent `run' commands default
1739
to do input and output on the terminal `/dev/ttyb' and have that as
1740
their controlling terminal.
1741
 
1742
   An explicit redirection in `run' overrides the `tty' command's
1743
effect on the input/output device, but not its effect on the controlling
1744
terminal.
1745
 
1746
   When you use the `tty' command or redirect input in the `run'
1747
command, only the input _for your program_ is affected.  The input for
1748
GDB still comes from your terminal.  `tty' is an alias for `set
1749
inferior-tty'.
1750
 
1751
   You can use the `show inferior-tty' command to tell GDB to display
1752
the name of the terminal that will be used for future runs of your
1753
program.
1754
 
1755
`set inferior-tty /dev/ttyb'
1756
     Set the tty for the program being debugged to /dev/ttyb.
1757
 
1758
`show inferior-tty'
1759
     Show the current tty for the program being debugged.
1760
 
1761

1762
File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
1763
 
1764
4.7 Debugging an Already-running Process
1765
========================================
1766
 
1767
`attach PROCESS-ID'
1768
     This command attaches to a running process--one that was started
1769
     outside GDB.  (`info files' shows your active targets.)  The
1770
     command takes as argument a process ID.  The usual way to find out
1771
     the PROCESS-ID of a Unix process is with the `ps' utility, or with
1772
     the `jobs -l' shell command.
1773
 
1774
     `attach' does not repeat if you press  a second time after
1775
     executing the command.
1776
 
1777
   To use `attach', your program must be running in an environment
1778
which supports processes; for example, `attach' does not work for
1779
programs on bare-board targets that lack an operating system.  You must
1780
also have permission to send the process a signal.
1781
 
1782
   When you use `attach', the debugger finds the program running in the
1783
process first by looking in the current working directory, then (if the
1784
program is not found) by using the source file search path (*note
1785
Specifying Source Directories: Source Path.).  You can also use the
1786
`file' command to load the program.  *Note Commands to Specify Files:
1787
Files.
1788
 
1789
   The first thing GDB does after arranging to debug the specified
1790
process is to stop it.  You can examine and modify an attached process
1791
with all the GDB commands that are ordinarily available when you start
1792
processes with `run'.  You can insert breakpoints; you can step and
1793
continue; you can modify storage.  If you would rather the process
1794
continue running, you may use the `continue' command after attaching
1795
GDB to the process.
1796
 
1797
`detach'
1798
     When you have finished debugging the attached process, you can use
1799
     the `detach' command to release it from GDB control.  Detaching
1800
     the process continues its execution.  After the `detach' command,
1801
     that process and GDB become completely independent once more, and
1802
     you are ready to `attach' another process or start one with `run'.
1803
     `detach' does not repeat if you press  again after executing
1804
     the command.
1805
 
1806
   If you exit GDB while you have an attached process, you detach that
1807
process.  If you use the `run' command, you kill that process.  By
1808
default, GDB asks for confirmation if you try to do either of these
1809
things; you can control whether or not you need to confirm by using the
1810
`set confirm' command (*note Optional Warnings and Messages:
1811
Messages/Warnings.).
1812
 
1813

1814
File: gdb.info,  Node: Kill Process,  Next: Threads,  Prev: Attach,  Up: Running
1815
 
1816
4.8 Killing the Child Process
1817
=============================
1818
 
1819
`kill'
1820
     Kill the child process in which your program is running under GDB.
1821
 
1822
   This command is useful if you wish to debug a core dump instead of a
1823
running process.  GDB ignores any core dump file while your program is
1824
running.
1825
 
1826
   On some operating systems, a program cannot be executed outside GDB
1827
while you have breakpoints set on it inside GDB.  You can use the
1828
`kill' command in this situation to permit running your program outside
1829
the debugger.
1830
 
1831
   The `kill' command is also useful if you wish to recompile and
1832
relink your program, since on many systems it is impossible to modify an
1833
executable file while it is running in a process.  In this case, when
1834
you next type `run', GDB notices that the file has changed, and reads
1835
the symbol table again (while trying to preserve your current
1836
breakpoint settings).
1837
 
1838

1839
File: gdb.info,  Node: Threads,  Next: Processes,  Prev: Kill Process,  Up: Running
1840
 
1841
4.9 Debugging Programs with Multiple Threads
1842
============================================
1843
 
1844
In some operating systems, such as HP-UX and Solaris, a single program
1845
may have more than one "thread" of execution.  The precise semantics of
1846
threads differ from one operating system to another, but in general the
1847
threads of a single program are akin to multiple processes--except that
1848
they share one address space (that is, they can all examine and modify
1849
the same variables).  On the other hand, each thread has its own
1850
registers and execution stack, and perhaps private memory.
1851
 
1852
   GDB provides these facilities for debugging multi-thread programs:
1853
 
1854
   * automatic notification of new threads
1855
 
1856
   * `thread THREADNO', a command to switch among threads
1857
 
1858
   * `info threads', a command to inquire about existing threads
1859
 
1860
   * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
1861
     to a list of threads
1862
 
1863
   * thread-specific breakpoints
1864
 
1865
   * `set print thread-events', which controls printing of messages on
1866
     thread start and exit.
1867
 
1868
     _Warning:_ These facilities are not yet available on every GDB
1869
     configuration where the operating system supports threads.  If
1870
     your GDB does not support threads, these commands have no effect.
1871
     For example, a system without thread support shows no output from
1872
     `info threads', and always rejects the `thread' command, like this:
1873
 
1874
          (gdb) info threads
1875
          (gdb) thread 1
1876
          Thread ID 1 not known.  Use the "info threads" command to
1877
          see the IDs of currently known threads.
1878
 
1879
   The GDB thread debugging facility allows you to observe all threads
1880
while your program runs--but whenever GDB takes control, one thread in
1881
particular is always the focus of debugging.  This thread is called the
1882
"current thread".  Debugging commands show program information from the
1883
perspective of the current thread.
1884
 
1885
   Whenever GDB detects a new thread in your program, it displays the
1886
target system's identification for the thread with a message in the
1887
form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
1888
depending on the particular system.  For example, on GNU/Linux, you
1889
might see
1890
 
1891
     [New Thread 46912507313328 (LWP 25582)]
1892
 
1893
when GDB notices a new thread.  In contrast, on an SGI system, the
1894
SYSTAG is simply something like `process 368', with no further
1895
qualifier.
1896
 
1897
   For debugging purposes, GDB associates its own thread number--always
1898
a single integer--with each thread in your program.
1899
 
1900
`info threads'
1901
     Display a summary of all threads currently in your program.  GDB
1902
     displays for each thread (in this order):
1903
 
1904
       1. the thread number assigned by GDB
1905
 
1906
       2. the target system's thread identifier (SYSTAG)
1907
 
1908
       3. the current stack frame summary for that thread
1909
 
1910
     An asterisk `*' to the left of the GDB thread number indicates the
1911
     current thread.
1912
 
1913
     For example,
1914
 
1915
     (gdb) info threads
1916
       3 process 35 thread 27  0x34e5 in sigpause ()
1917
       2 process 35 thread 23  0x34e5 in sigpause ()
1918
     * 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
1919
         at threadtest.c:68
1920
 
1921
   On HP-UX systems:
1922
 
1923
   For debugging purposes, GDB associates its own thread number--a
1924
small integer assigned in thread-creation order--with each thread in
1925
your program.
1926
 
1927
   Whenever GDB detects a new thread in your program, it displays both
1928
GDB's thread number and the target system's identification for the
1929
thread with a message in the form `[New SYSTAG]'.  SYSTAG is a thread
1930
identifier whose form varies depending on the particular system.  For
1931
example, on HP-UX, you see
1932
 
1933
     [New thread 2 (system thread 26594)]
1934
 
1935
when GDB notices a new thread.
1936
 
1937
`info threads'
1938
     Display a summary of all threads currently in your program.  GDB
1939
     displays for each thread (in this order):
1940
 
1941
       1. the thread number assigned by GDB
1942
 
1943
       2. the target system's thread identifier (SYSTAG)
1944
 
1945
       3. the current stack frame summary for that thread
1946
 
1947
     An asterisk `*' to the left of the GDB thread number indicates the
1948
     current thread.
1949
 
1950
     For example,
1951
 
1952
     (gdb) info threads
1953
         * 3 system thread 26607  worker (wptr=0x7b09c318 "@") \
1954
 
1955
     at quicksort.c:137
1956
           2 system thread 26606  0x7b0030d8 in __ksleep () \
1957
 
1958
     from /usr/lib/libc.2
1959
           1 system thread 27905  0x7b003498 in _brk () \
1960
 
1961
     from /usr/lib/libc.2
1962
 
1963
   On Solaris, you can display more information about user threads with
1964
a Solaris-specific command:
1965
 
1966
`maint info sol-threads'
1967
     Display info on Solaris user threads.
1968
 
1969
`thread THREADNO'
1970
     Make thread number THREADNO the current thread.  The command
1971
     argument THREADNO is the internal GDB thread number, as shown in
1972
     the first field of the `info threads' display.  GDB responds by
1973
     displaying the system identifier of the thread you selected, and
1974
     its current stack frame summary:
1975
 
1976
          (gdb) thread 2
1977
          [Switching to process 35 thread 23]
1978
          0x34e5 in sigpause ()
1979
 
1980
     As with the `[New ...]' message, the form of the text after
1981
     `Switching to' depends on your system's conventions for identifying
1982
     threads.
1983
 
1984
`thread apply [THREADNO] [ALL] COMMAND'
1985
     The `thread apply' command allows you to apply the named COMMAND
1986
     to one or more threads.  Specify the numbers of the threads that
1987
     you want affected with the command argument THREADNO.  It can be a
1988
     single thread number, one of the numbers shown in the first field
1989
     of the `info threads' display; or it could be a range of thread
1990
     numbers, as in `2-4'.  To apply a command to all threads, type
1991
     `thread apply all COMMAND'.
1992
 
1993
`set print thread-events'
1994
`set print thread-events on'
1995
`set print thread-events off'
1996
     The `set print thread-events' command allows you to enable or
1997
     disable printing of messages when GDB notices that new threads have
1998
     started or that threads have exited.  By default, these messages
1999
     will be printed if detection of these events is supported by the
2000
     target.  Note that these messages cannot be disabled on all
2001
     targets.
2002
 
2003
`show print thread-events'
2004
     Show whether messages will be printed when GDB detects that threads
2005
     have started and exited.
2006
 
2007
   Whenever GDB stops your program, due to a breakpoint or a signal, it
2008
automatically selects the thread where that breakpoint or signal
2009
happened.  GDB alerts you to the context switch with a message of the
2010
form `[Switching to SYSTAG]' to identify the thread.
2011
 
2012
   *Note Stopping and Starting Multi-thread Programs: Thread Stops, for
2013
more information about how GDB behaves when you stop and start programs
2014
with multiple threads.
2015
 
2016
   *Note Setting Watchpoints: Set Watchpoints, for information about
2017
watchpoints in programs with multiple threads.
2018
 
2019

2020
File: gdb.info,  Node: Processes,  Next: Checkpoint/Restart,  Prev: Threads,  Up: Running
2021
 
2022
4.10 Debugging Programs with Multiple Processes
2023
===============================================
2024
 
2025
On most systems, GDB has no special support for debugging programs
2026
which create additional processes using the `fork' function.  When a
2027
program forks, GDB will continue to debug the parent process and the
2028
child process will run unimpeded.  If you have set a breakpoint in any
2029
code which the child then executes, the child will get a `SIGTRAP'
2030
signal which (unless it catches the signal) will cause it to terminate.
2031
 
2032
   However, if you want to debug the child process there is a workaround
2033
which isn't too painful.  Put a call to `sleep' in the code which the
2034
child process executes after the fork.  It may be useful to sleep only
2035
if a certain environment variable is set, or a certain file exists, so
2036
that the delay need not occur when you don't want to run GDB on the
2037
child.  While the child is sleeping, use the `ps' program to get its
2038
process ID.  Then tell GDB (a new invocation of GDB if you are also
2039
debugging the parent process) to attach to the child process (*note
2040
Attach::).  From that point on you can debug the child process just
2041
like any other process which you attached to.
2042
 
2043
   On some systems, GDB provides support for debugging programs that
2044
create additional processes using the `fork' or `vfork' functions.
2045
Currently, the only platforms with this feature are HP-UX (11.x and
2046
later only?) and GNU/Linux (kernel version 2.5.60 and later).
2047
 
2048
   By default, when a program forks, GDB will continue to debug the
2049
parent process and the child process will run unimpeded.
2050
 
2051
   If you want to follow the child process instead of the parent
2052
process, use the command `set follow-fork-mode'.
2053
 
2054
`set follow-fork-mode MODE'
2055
     Set the debugger response to a program call of `fork' or `vfork'.
2056
     A call to `fork' or `vfork' creates a new process.  The MODE
2057
     argument can be:
2058
 
2059
    `parent'
2060
          The original process is debugged after a fork.  The child
2061
          process runs unimpeded.  This is the default.
2062
 
2063
    `child'
2064
          The new process is debugged after a fork.  The parent process
2065
          runs unimpeded.
2066
 
2067
 
2068
`show follow-fork-mode'
2069
     Display the current debugger response to a `fork' or `vfork' call.
2070
 
2071
   On Linux, if you want to debug both the parent and child processes,
2072
use the command `set detach-on-fork'.
2073
 
2074
`set detach-on-fork MODE'
2075
     Tells gdb whether to detach one of the processes after a fork, or
2076
     retain debugger control over them both.
2077
 
2078
    `on'
2079
          The child process (or parent process, depending on the value
2080
          of `follow-fork-mode') will be detached and allowed to run
2081
          independently.  This is the default.
2082
 
2083
    `off'
2084
          Both processes will be held under the control of GDB.  One
2085
          process (child or parent, depending on the value of
2086
          `follow-fork-mode') is debugged as usual, while the other is
2087
          held suspended.
2088
 
2089
 
2090
`show detach-on-fork'
2091
     Show whether detach-on-fork mode is on/off.
2092
 
2093
   If you choose to set `detach-on-fork' mode off, then GDB will retain
2094
control of all forked processes (including nested forks).  You can list
2095
the forked processes under the control of GDB by using the `info forks'
2096
command, and switch from one fork to another by using the `fork'
2097
command.
2098
 
2099
`info forks'
2100
     Print a list of all forked processes under the control of GDB.
2101
     The listing will include a fork id, a process id, and the current
2102
     position (program counter) of the process.
2103
 
2104
`fork FORK-ID'
2105
     Make fork number FORK-ID the current process.  The argument
2106
     FORK-ID is the internal fork number assigned by GDB, as shown in
2107
     the first field of the `info forks' display.
2108
 
2109
`process PROCESS-ID'
2110
     Make process number PROCESS-ID the current process.  The argument
2111
     PROCESS-ID must be one that is listed in the output of `info
2112
     forks'.
2113
 
2114
 
2115
   To quit debugging one of the forked processes, you can either detach
2116
from it by using the `detach fork' command (allowing it to run
2117
independently), or delete (and kill) it using the `delete fork' command.
2118
 
2119
`detach fork FORK-ID'
2120
     Detach from the process identified by GDB fork number FORK-ID, and
2121
     remove it from the fork list.  The process will be allowed to run
2122
     independently.
2123
 
2124
`delete fork FORK-ID'
2125
     Kill the process identified by GDB fork number FORK-ID, and remove
2126
     it from the fork list.
2127
 
2128
 
2129
   If you ask to debug a child process and a `vfork' is followed by an
2130
`exec', GDB executes the new target up to the first breakpoint in the
2131
new target.  If you have a breakpoint set on `main' in your original
2132
program, the breakpoint will also be set on the child process's `main'.
2133
 
2134
   When a child process is spawned by `vfork', you cannot debug the
2135
child or parent until an `exec' call completes.
2136
 
2137
   If you issue a `run' command to GDB after an `exec' call executes,
2138
the new target restarts.  To restart the parent process, use the `file'
2139
command with the parent executable name as its argument.
2140
 
2141
   You can use the `catch' command to make GDB stop whenever a `fork',
2142
`vfork', or `exec' call is made.  *Note Setting Catchpoints: Set
2143
Catchpoints.
2144
 
2145

2146
File: gdb.info,  Node: Checkpoint/Restart,  Prev: Processes,  Up: Running
2147
 
2148
4.11 Setting a _Bookmark_ to Return to Later
2149
============================================
2150
 
2151
On certain operating systems(1), GDB is able to save a "snapshot" of a
2152
program's state, called a "checkpoint", and come back to it later.
2153
 
2154
   Returning to a checkpoint effectively undoes everything that has
2155
happened in the program since the `checkpoint' was saved.  This
2156
includes changes in memory, registers, and even (within some limits)
2157
system state.  Effectively, it is like going back in time to the moment
2158
when the checkpoint was saved.
2159
 
2160
   Thus, if you're stepping thru a program and you think you're getting
2161
close to the point where things go wrong, you can save a checkpoint.
2162
Then, if you accidentally go too far and miss the critical statement,
2163
instead of having to restart your program from the beginning, you can
2164
just go back to the checkpoint and start again from there.
2165
 
2166
   This can be especially useful if it takes a lot of time or steps to
2167
reach the point where you think the bug occurs.
2168
 
2169
   To use the `checkpoint'/`restart' method of debugging:
2170
 
2171
`checkpoint'
2172
     Save a snapshot of the debugged program's current execution state.
2173
     The `checkpoint' command takes no arguments, but each checkpoint
2174
     is assigned a small integer id, similar to a breakpoint id.
2175
 
2176
`info checkpoints'
2177
     List the checkpoints that have been saved in the current debugging
2178
     session.  For each checkpoint, the following information will be
2179
     listed:
2180
 
2181
    `Checkpoint ID'
2182
 
2183
    `Process ID'
2184
 
2185
    `Code Address'
2186
 
2187
    `Source line, or label'
2188
 
2189
`restart CHECKPOINT-ID'
2190
     Restore the program state that was saved as checkpoint number
2191
     CHECKPOINT-ID.  All program variables, registers, stack frames
2192
     etc.  will be returned to the values that they had when the
2193
     checkpoint was saved.  In essence, gdb will "wind back the clock"
2194
     to the point in time when the checkpoint was saved.
2195
 
2196
     Note that breakpoints, GDB variables, command history etc.  are
2197
     not affected by restoring a checkpoint.  In general, a checkpoint
2198
     only restores things that reside in the program being debugged,
2199
     not in the debugger.
2200
 
2201
`delete checkpoint CHECKPOINT-ID'
2202
     Delete the previously-saved checkpoint identified by CHECKPOINT-ID.
2203
 
2204
 
2205
   Returning to a previously saved checkpoint will restore the user
2206
state of the program being debugged, plus a significant subset of the
2207
system (OS) state, including file pointers.  It won't "un-write" data
2208
from a file, but it will rewind the file pointer to the previous
2209
location, so that the previously written data can be overwritten.  For
2210
files opened in read mode, the pointer will also be restored so that the
2211
previously read data can be read again.
2212
 
2213
   Of course, characters that have been sent to a printer (or other
2214
external device) cannot be "snatched back", and characters received
2215
from eg. a serial device can be removed from internal program buffers,
2216
but they cannot be "pushed back" into the serial pipeline, ready to be
2217
received again.  Similarly, the actual contents of files that have been
2218
changed cannot be restored (at this time).
2219
 
2220
   However, within those constraints, you actually can "rewind" your
2221
program to a previously saved point in time, and begin debugging it
2222
again -- and you can change the course of events so as to debug a
2223
different execution path this time.
2224
 
2225
   Finally, there is one bit of internal program state that will be
2226
different when you return to a checkpoint -- the program's process id.
2227
Each checkpoint will have a unique process id (or PID), and each will
2228
be different from the program's original PID.  If your program has
2229
saved a local copy of its process id, this could potentially pose a
2230
problem.
2231
 
2232
4.11.1 A Non-obvious Benefit of Using Checkpoints
2233
-------------------------------------------------
2234
 
2235
On some systems such as GNU/Linux, address space randomization is
2236
performed on new processes for security reasons.  This makes it
2237
difficult or impossible to set a breakpoint, or watchpoint, on an
2238
absolute address if you have to restart the program, since the absolute
2239
location of a symbol will change from one execution to the next.
2240
 
2241
   A checkpoint, however, is an _identical_ copy of a process.
2242
Therefore if you create a checkpoint at (eg.) the start of main, and
2243
simply return to that checkpoint instead of restarting the process, you
2244
can avoid the effects of address randomization and your symbols will
2245
all stay in the same place.
2246
 
2247
   ---------- Footnotes ----------
2248
 
2249
   (1) Currently, only GNU/Linux.
2250
 
2251

2252
File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
2253
 
2254
5 Stopping and Continuing
2255
*************************
2256
 
2257
The principal purposes of using a debugger are so that you can stop your
2258
program before it terminates; or so that, if your program runs into
2259
trouble, you can investigate and find out why.
2260
 
2261
   Inside GDB, your program may stop for any of several reasons, such
2262
as a signal, a breakpoint, or reaching a new line after a GDB command
2263
such as `step'.  You may then examine and change variables, set new
2264
breakpoints or remove old ones, and then continue execution.  Usually,
2265
the messages shown by GDB provide ample explanation of the status of
2266
your program--but you can also explicitly request this information at
2267
any time.
2268
 
2269
`info program'
2270
     Display information about the status of your program: whether it is
2271
     running or not, what process it is, and why it stopped.
2272
 
2273
* Menu:
2274
 
2275
* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
2276
* Continuing and Stepping::     Resuming execution
2277
* Signals::                     Signals
2278
* Thread Stops::                Stopping and starting multi-thread programs
2279
 
2280

2281
File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
2282
 
2283
5.1 Breakpoints, Watchpoints, and Catchpoints
2284
=============================================
2285
 
2286
A "breakpoint" makes your program stop whenever a certain point in the
2287
program is reached.  For each breakpoint, you can add conditions to
2288
control in finer detail whether your program stops.  You can set
2289
breakpoints with the `break' command and its variants (*note Setting
2290
Breakpoints: Set Breaks.), to specify the place where your program
2291
should stop by line number, function name or exact address in the
2292
program.
2293
 
2294
   On some systems, you can set breakpoints in shared libraries before
2295
the executable is run.  There is a minor limitation on HP-UX systems:
2296
you must wait until the executable is run in order to set breakpoints
2297
in shared library routines that are not called directly by the program
2298
(for example, routines that are arguments in a `pthread_create' call).
2299
 
2300
   A "watchpoint" is a special breakpoint that stops your program when
2301
the value of an expression changes.  The expression may be a value of a
2302
variable, or it could involve values of one or more variables combined
2303
by operators, such as `a + b'.  This is sometimes called "data
2304
breakpoints".  You must use a different command to set watchpoints
2305
(*note Setting Watchpoints: Set Watchpoints.), but aside from that, you
2306
can manage a watchpoint like any other breakpoint: you enable, disable,
2307
and delete both breakpoints and watchpoints using the same commands.
2308
 
2309
   You can arrange to have values from your program displayed
2310
automatically whenever GDB stops at a breakpoint.  *Note Automatic
2311
Display: Auto Display.
2312
 
2313
   A "catchpoint" is another special breakpoint that stops your program
2314
when a certain kind of event occurs, such as the throwing of a C++
2315
exception or the loading of a library.  As with watchpoints, you use a
2316
different command to set a catchpoint (*note Setting Catchpoints: Set
2317
Catchpoints.), but aside from that, you can manage a catchpoint like any
2318
other breakpoint.  (To stop when your program receives a signal, use the
2319
`handle' command; see *Note Signals: Signals.)
2320
 
2321
   GDB assigns a number to each breakpoint, watchpoint, or catchpoint
2322
when you create it; these numbers are successive integers starting with
2323
one.  In many of the commands for controlling various features of
2324
breakpoints you use the breakpoint number to say which breakpoint you
2325
want to change.  Each breakpoint may be "enabled" or "disabled"; if
2326
disabled, it has no effect on your program until you enable it again.
2327
 
2328
   Some GDB commands accept a range of breakpoints on which to operate.
2329
A breakpoint range is either a single breakpoint number, like `5', or
2330
two such numbers, in increasing order, separated by a hyphen, like
2331
`5-7'.  When a breakpoint range is given to a command, all breakpoints
2332
in that range are operated on.
2333
 
2334
* Menu:
2335
 
2336
* Set Breaks::                  Setting breakpoints
2337
* Set Watchpoints::             Setting watchpoints
2338
* Set Catchpoints::             Setting catchpoints
2339
* Delete Breaks::               Deleting breakpoints
2340
* Disabling::                   Disabling breakpoints
2341
* Conditions::                  Break conditions
2342
* Break Commands::              Breakpoint command lists
2343
* Breakpoint Menus::            Breakpoint menus
2344
* Error in Breakpoints::        ``Cannot insert breakpoints''
2345
* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
2346
 
2347

2348
File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
2349
 
2350
5.1.1 Setting Breakpoints
2351
-------------------------
2352
 
2353
Breakpoints are set with the `break' command (abbreviated `b').  The
2354
debugger convenience variable `$bpnum' records the number of the
2355
breakpoint you've set most recently; see *Note Convenience Variables:
2356
Convenience Vars, for a discussion of what you can do with convenience
2357
variables.
2358
 
2359
`break LOCATION'
2360
     Set a breakpoint at the given LOCATION, which can specify a
2361
     function name, a line number, or an address of an instruction.
2362
     (*Note Specify Location::, for a list of all the possible ways to
2363
     specify a LOCATION.)  The breakpoint will stop your program just
2364
     before it executes any of the code in the specified LOCATION.
2365
 
2366
     When using source languages that permit overloading of symbols,
2367
     such as C++, a function name may refer to more than one possible
2368
     place to break.  *Note Breakpoint Menus: Breakpoint Menus, for a
2369
     discussion of that situation.
2370
 
2371
`break'
2372
     When called without any arguments, `break' sets a breakpoint at
2373
     the next instruction to be executed in the selected stack frame
2374
     (*note Examining the Stack: Stack.).  In any selected frame but the
2375
     innermost, this makes your program stop as soon as control returns
2376
     to that frame.  This is similar to the effect of a `finish'
2377
     command in the frame inside the selected frame--except that
2378
     `finish' does not leave an active breakpoint.  If you use `break'
2379
     without an argument in the innermost frame, GDB stops the next
2380
     time it reaches the current location; this may be useful inside
2381
     loops.
2382
 
2383
     GDB normally ignores breakpoints when it resumes execution, until
2384
     at least one instruction has been executed.  If it did not do
2385
     this, you would be unable to proceed past a breakpoint without
2386
     first disabling the breakpoint.  This rule applies whether or not
2387
     the breakpoint already existed when your program stopped.
2388
 
2389
`break ... if COND'
2390
     Set a breakpoint with condition COND; evaluate the expression COND
2391
     each time the breakpoint is reached, and stop only if the value is
2392
     nonzero--that is, if COND evaluates as true.  `...' stands for one
2393
     of the possible arguments described above (or no argument)
2394
     specifying where to break.  *Note Break Conditions: Conditions,
2395
     for more information on breakpoint conditions.
2396
 
2397
`tbreak ARGS'
2398
     Set a breakpoint enabled only for one stop.  ARGS are the same as
2399
     for the `break' command, and the breakpoint is set in the same
2400
     way, but the breakpoint is automatically deleted after the first
2401
     time your program stops there.  *Note Disabling Breakpoints:
2402
     Disabling.
2403
 
2404
`hbreak ARGS'
2405
     Set a hardware-assisted breakpoint.  ARGS are the same as for the
2406
     `break' command and the breakpoint is set in the same way, but the
2407
     breakpoint requires hardware support and some target hardware may
2408
     not have this support.  The main purpose of this is EPROM/ROM code
2409
     debugging, so you can set a breakpoint at an instruction without
2410
     changing the instruction.  This can be used with the new
2411
     trap-generation provided by SPARClite DSU and most x86-based
2412
     targets.  These targets will generate traps when a program
2413
     accesses some data or instruction address that is assigned to the
2414
     debug registers.  However the hardware breakpoint registers can
2415
     take a limited number of breakpoints.  For example, on the DSU,
2416
     only two data breakpoints can be set at a time, and GDB will
2417
     reject this command if more than two are used.  Delete or disable
2418
     unused hardware breakpoints before setting new ones (*note
2419
     Disabling Breakpoints: Disabling.).  *Note Break Conditions:
2420
     Conditions.  For remote targets, you can restrict the number of
2421
     hardware breakpoints GDB will use, see *Note set remote
2422
     hardware-breakpoint-limit::.
2423
 
2424
`thbreak ARGS'
2425
     Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
2426
     are the same as for the `hbreak' command and the breakpoint is set
2427
     in the same way.  However, like the `tbreak' command, the
2428
     breakpoint is automatically deleted after the first time your
2429
     program stops there.  Also, like the `hbreak' command, the
2430
     breakpoint requires hardware support and some target hardware may
2431
     not have this support.  *Note Disabling Breakpoints: Disabling.
2432
     See also *Note Break Conditions: Conditions.
2433
 
2434
`rbreak REGEX'
2435
     Set breakpoints on all functions matching the regular expression
2436
     REGEX.  This command sets an unconditional breakpoint on all
2437
     matches, printing a list of all breakpoints it set.  Once these
2438
     breakpoints are set, they are treated just like the breakpoints
2439
     set with the `break' command.  You can delete them, disable them,
2440
     or make them conditional the same way as any other breakpoint.
2441
 
2442
     The syntax of the regular expression is the standard one used with
2443
     tools like `grep'.  Note that this is different from the syntax
2444
     used by shells, so for instance `foo*' matches all functions that
2445
     include an `fo' followed by zero or more `o's.  There is an
2446
     implicit `.*' leading and trailing the regular expression you
2447
     supply, so to match only functions that begin with `foo', use
2448
     `^foo'.
2449
 
2450
     When debugging C++ programs, `rbreak' is useful for setting
2451
     breakpoints on overloaded functions that are not members of any
2452
     special classes.
2453
 
2454
     The `rbreak' command can be used to set breakpoints in *all* the
2455
     functions in a program, like this:
2456
 
2457
          (gdb) rbreak .
2458
 
2459
`info breakpoints [N]'
2460
`info break [N]'
2461
`info watchpoints [N]'
2462
     Print a table of all breakpoints, watchpoints, and catchpoints set
2463
     and not deleted.  Optional argument N means print information only
2464
     about the specified breakpoint (or watchpoint or catchpoint).  For
2465
     each breakpoint, following columns are printed:
2466
 
2467
    _Breakpoint Numbers_
2468
 
2469
    _Type_
2470
          Breakpoint, watchpoint, or catchpoint.
2471
 
2472
    _Disposition_
2473
          Whether the breakpoint is marked to be disabled or deleted
2474
          when hit.
2475
 
2476
    _Enabled or Disabled_
2477
          Enabled breakpoints are marked with `y'.  `n' marks
2478
          breakpoints that are not enabled.
2479
 
2480
    _Address_
2481
          Where the breakpoint is in your program, as a memory address.
2482
          For a pending breakpoint whose address is not yet known,
2483
          this field will contain `'.  Such breakpoint won't
2484
          fire until a shared library that has the symbol or line
2485
          referred by breakpoint is loaded.  See below for details.  A
2486
          breakpoint with several locations will have `' in
2487
          this field--see below for details.
2488
 
2489
    _What_
2490
          Where the breakpoint is in the source for your program, as a
2491
          file and line number.  For a pending breakpoint, the original
2492
          string passed to the breakpoint command will be listed as it
2493
          cannot be resolved until the appropriate shared library is
2494
          loaded in the future.
2495
 
2496
     If a breakpoint is conditional, `info break' shows the condition on
2497
     the line following the affected breakpoint; breakpoint commands,
2498
     if any, are listed after that.  A pending breakpoint is allowed to
2499
     have a condition specified for it.  The condition is not parsed
2500
     for validity until a shared library is loaded that allows the
2501
     pending breakpoint to resolve to a valid location.
2502
 
2503
     `info break' with a breakpoint number N as argument lists only
2504
     that breakpoint.  The convenience variable `$_' and the default
2505
     examining-address for the `x' command are set to the address of
2506
     the last breakpoint listed (*note Examining Memory: Memory.).
2507
 
2508
     `info break' displays a count of the number of times the breakpoint
2509
     has been hit.  This is especially useful in conjunction with the
2510
     `ignore' command.  You can ignore a large number of breakpoint
2511
     hits, look at the breakpoint info to see how many times the
2512
     breakpoint was hit, and then run again, ignoring one less than
2513
     that number.  This will get you quickly to the last hit of that
2514
     breakpoint.
2515
 
2516
   GDB allows you to set any number of breakpoints at the same place in
2517
your program.  There is nothing silly or meaningless about this.  When
2518
the breakpoints are conditional, this is even useful (*note Break
2519
Conditions: Conditions.).
2520
 
2521
   It is possible that a breakpoint corresponds to several locations in
2522
your program.  Examples of this situation are:
2523
 
2524
   * For a C++ constructor, the GCC compiler generates several
2525
     instances of the function body, used in different cases.
2526
 
2527
   * For a C++ template function, a given line in the function can
2528
     correspond to any number of instantiations.
2529
 
2530
   * For an inlined function, a given source line can correspond to
2531
     several places where that function is inlined.
2532
 
2533
 
2534
   In all those cases, GDB will insert a breakpoint at all the relevant
2535
locations.
2536
 
2537
   A breakpoint with multiple locations is displayed in the breakpoint
2538
table using several rows--one header row, followed by one row for each
2539
breakpoint location.  The header row has `' in the address
2540
column.  The rows for individual locations contain the actual addresses
2541
for locations, and show the functions to which those locations belong.
2542
The number column for a location is of the form
2543
BREAKPOINT-NUMBER.LOCATION-NUMBER.
2544
 
2545
   For example:
2546
 
2547
     Num     Type           Disp Enb  Address    What
2548
     1       breakpoint     keep y    
2549
             stop only if i==1
2550
             breakpoint already hit 1 time
2551
     1.1                         y    0x080486a2 in void foo() at t.cc:8
2552
     1.2                         y    0x080486ca in void foo() at t.cc:8
2553
 
2554
   Each location can be individually enabled or disabled by passing
2555
BREAKPOINT-NUMBER.LOCATION-NUMBER as argument to the `enable' and
2556
`disable' commands.  Note that you cannot delete the individual
2557
locations from the list, you can only delete the entire list of
2558
locations that belong to their parent breakpoint (with the `delete NUM'
2559
command, where NUM is the number of the parent breakpoint, 1 in the
2560
above example).  Disabling or enabling the parent breakpoint (*note
2561
Disabling::) affects all of the locations that belong to that
2562
breakpoint.
2563
 
2564
   It's quite common to have a breakpoint inside a shared library.
2565
Shared libraries can be loaded and unloaded explicitly, and possibly
2566
repeatedly, as the program is executed.  To support this use case, GDB
2567
updates breakpoint locations whenever any shared library is loaded or
2568
unloaded.  Typically, you would set a breakpoint in a shared library at
2569
the beginning of your debugging session, when the library is not
2570
loaded, and when the symbols from the library are not available.  When
2571
you try to set breakpoint, GDB will ask you if you want to set a so
2572
called "pending breakpoint"--breakpoint whose address is not yet
2573
resolved.
2574
 
2575
   After the program is run, whenever a new shared library is loaded,
2576
GDB reevaluates all the breakpoints.  When a newly loaded shared
2577
library contains the symbol or line referred to by some pending
2578
breakpoint, that breakpoint is resolved and becomes an ordinary
2579
breakpoint.  When a library is unloaded, all breakpoints that refer to
2580
its symbols or source lines become pending again.
2581
 
2582
   This logic works for breakpoints with multiple locations, too.  For
2583
example, if you have a breakpoint in a C++ template function, and a
2584
newly loaded shared library has an instantiation of that template, a
2585
new location is added to the list of locations for the breakpoint.
2586
 
2587
   Except for having unresolved address, pending breakpoints do not
2588
differ from regular breakpoints.  You can set conditions or commands,
2589
enable and disable them and perform other breakpoint operations.
2590
 
2591
   GDB provides some additional commands for controlling what happens
2592
when the `break' command cannot resolve breakpoint address
2593
specification to an address:
2594
 
2595
`set breakpoint pending auto'
2596
     This is the default behavior.  When GDB cannot find the breakpoint
2597
     location, it queries you whether a pending breakpoint should be
2598
     created.
2599
 
2600
`set breakpoint pending on'
2601
     This indicates that an unrecognized breakpoint location should
2602
     automatically result in a pending breakpoint being created.
2603
 
2604
`set breakpoint pending off'
2605
     This indicates that pending breakpoints are not to be created.  Any
2606
     unrecognized breakpoint location results in an error.  This
2607
     setting does not affect any pending breakpoints previously created.
2608
 
2609
`show breakpoint pending'
2610
     Show the current behavior setting for creating pending breakpoints.
2611
 
2612
   The settings above only affect the `break' command and its variants.
2613
Once breakpoint is set, it will be automatically updated as shared
2614
libraries are loaded and unloaded.
2615
 
2616
   For some targets, GDB can automatically decide if hardware or
2617
software breakpoints should be used, depending on whether the
2618
breakpoint address is read-only or read-write.  This applies to
2619
breakpoints set with the `break' command as well as to internal
2620
breakpoints set by commands like `next' and `finish'.  For breakpoints
2621
set with `hbreak', GDB will always use hardware breakpoints.
2622
 
2623
   You can control this automatic behaviour with the following
2624
commands::
2625
 
2626
`set breakpoint auto-hw on'
2627
     This is the default behavior.  When GDB sets a breakpoint, it will
2628
     try to use the target memory map to decide if software or hardware
2629
     breakpoint must be used.
2630
 
2631
`set breakpoint auto-hw off'
2632
     This indicates GDB should not automatically select breakpoint
2633
     type.  If the target provides a memory map, GDB will warn when
2634
     trying to set software breakpoint at a read-only address.
2635
 
2636
   GDB itself sometimes sets breakpoints in your program for special
2637
purposes, such as proper handling of `longjmp' (in C programs).  These
2638
internal breakpoints are assigned negative numbers, starting with `-1';
2639
`info breakpoints' does not display them.  You can see these
2640
breakpoints with the GDB maintenance command `maint info breakpoints'
2641
(*note maint info breakpoints::).
2642
 
2643

2644
File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
2645
 
2646
5.1.2 Setting Watchpoints
2647
-------------------------
2648
 
2649
You can use a watchpoint to stop execution whenever the value of an
2650
expression changes, without having to predict a particular place where
2651
this may happen.  (This is sometimes called a "data breakpoint".)  The
2652
expression may be as simple as the value of a single variable, or as
2653
complex as many variables combined by operators.  Examples include:
2654
 
2655
   * A reference to the value of a single variable.
2656
 
2657
   * An address cast to an appropriate data type.  For example, `*(int
2658
     *)0x12345678' will watch a 4-byte region at the specified address
2659
     (assuming an `int' occupies 4 bytes).
2660
 
2661
   * An arbitrarily complex expression, such as `a*b + c/d'.  The
2662
     expression can use any operators valid in the program's native
2663
     language (*note Languages::).
2664
 
2665
   Depending on your system, watchpoints may be implemented in software
2666
or hardware.  GDB does software watchpointing by single-stepping your
2667
program and testing the variable's value each time, which is hundreds of
2668
times slower than normal execution.  (But this may still be worth it, to
2669
catch errors where you have no clue what part of your program is the
2670
culprit.)
2671
 
2672
   On some systems, such as HP-UX, PowerPC, GNU/Linux and most other
2673
x86-based targets, GDB includes support for hardware watchpoints, which
2674
do not slow down the running of your program.
2675
 
2676
`watch EXPR [thread THREADNUM]'
2677
     Set a watchpoint for an expression.  GDB will break when the
2678
     expression EXPR is written into by the program and its value
2679
     changes.  The simplest (and the most popular) use of this command
2680
     is to watch the value of a single variable:
2681
 
2682
          (gdb) watch foo
2683
 
2684
     If the command includes a `[thread THREADNUM]' clause, GDB breaks
2685
     only when the thread identified by THREADNUM changes the value of
2686
     EXPR.  If any other threads change the value of EXPR, GDB will not
2687
     break.  Note that watchpoints restricted to a single thread in
2688
     this way only work with Hardware Watchpoints.
2689
 
2690
`rwatch EXPR [thread THREADNUM]'
2691
     Set a watchpoint that will break when the value of EXPR is read by
2692
     the program.
2693
 
2694
`awatch EXPR [thread THREADNUM]'
2695
     Set a watchpoint that will break when EXPR is either read from or
2696
     written into by the program.
2697
 
2698
`info watchpoints'
2699
     This command prints a list of watchpoints, breakpoints, and
2700
     catchpoints; it is the same as `info break' (*note Set Breaks::).
2701
 
2702
   GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
2703
execute very quickly, and the debugger reports a change in value at the
2704
exact instruction where the change occurs.  If GDB cannot set a
2705
hardware watchpoint, it sets a software watchpoint, which executes more
2706
slowly and reports the change in value at the next _statement_, not the
2707
instruction, after the change occurs.
2708
 
2709
   You can force GDB to use only software watchpoints with the `set
2710
can-use-hw-watchpoints 0' command.  With this variable set to zero, GDB
2711
will never try to use hardware watchpoints, even if the underlying
2712
system supports them.  (Note that hardware-assisted watchpoints that
2713
were set _before_ setting `can-use-hw-watchpoints' to zero will still
2714
use the hardware mechanism of watching expression values.)
2715
 
2716
`set can-use-hw-watchpoints'
2717
     Set whether or not to use hardware watchpoints.
2718
 
2719
`show can-use-hw-watchpoints'
2720
     Show the current mode of using hardware watchpoints.
2721
 
2722
   For remote targets, you can restrict the number of hardware
2723
watchpoints GDB will use, see *Note set remote
2724
hardware-breakpoint-limit::.
2725
 
2726
   When you issue the `watch' command, GDB reports
2727
 
2728
     Hardware watchpoint NUM: EXPR
2729
 
2730
if it was able to set a hardware watchpoint.
2731
 
2732
   Currently, the `awatch' and `rwatch' commands can only set hardware
2733
watchpoints, because accesses to data that don't change the value of
2734
the watched expression cannot be detected without examining every
2735
instruction as it is being executed, and GDB does not do that
2736
currently.  If GDB finds that it is unable to set a hardware breakpoint
2737
with the `awatch' or `rwatch' command, it will print a message like
2738
this:
2739
 
2740
     Expression cannot be implemented with read/access watchpoint.
2741
 
2742
   Sometimes, GDB cannot set a hardware watchpoint because the data
2743
type of the watched expression is wider than what a hardware watchpoint
2744
on the target machine can handle.  For example, some systems can only
2745
watch regions that are up to 4 bytes wide; on such systems you cannot
2746
set hardware watchpoints for an expression that yields a
2747
double-precision floating-point number (which is typically 8 bytes
2748
wide).  As a work-around, it might be possible to break the large region
2749
into a series of smaller ones and watch them with separate watchpoints.
2750
 
2751
   If you set too many hardware watchpoints, GDB might be unable to
2752
insert all of them when you resume the execution of your program.
2753
Since the precise number of active watchpoints is unknown until such
2754
time as the program is about to be resumed, GDB might not be able to
2755
warn you about this when you set the watchpoints, and the warning will
2756
be printed only when the program is resumed:
2757
 
2758
     Hardware watchpoint NUM: Could not insert watchpoint
2759
 
2760
If this happens, delete or disable some of the watchpoints.
2761
 
2762
   Watching complex expressions that reference many variables can also
2763
exhaust the resources available for hardware-assisted watchpoints.
2764
That's because GDB needs to watch every variable in the expression with
2765
separately allocated resources.
2766
 
2767
   The SPARClite DSU will generate traps when a program accesses some
2768
data or instruction address that is assigned to the debug registers.
2769
For the data addresses, DSU facilitates the `watch' command.  However
2770
the hardware breakpoint registers can only take two data watchpoints,
2771
and both watchpoints must be the same kind.  For example, you can set
2772
two watchpoints with `watch' commands, two with `rwatch' commands, *or*
2773
two with `awatch' commands, but you cannot set one watchpoint with one
2774
command and the other with a different command.  GDB will reject the
2775
command if you try to mix watchpoints.  Delete or disable unused
2776
watchpoint commands before setting new ones.
2777
 
2778
   If you call a function interactively using `print' or `call', any
2779
watchpoints you have set will be inactive until GDB reaches another
2780
kind of breakpoint or the call completes.
2781
 
2782
   GDB automatically deletes watchpoints that watch local (automatic)
2783
variables, or expressions that involve such variables, when they go out
2784
of scope, that is, when the execution leaves the block in which these
2785
variables were defined.  In particular, when the program being debugged
2786
terminates, _all_ local variables go out of scope, and so only
2787
watchpoints that watch global variables remain set.  If you rerun the
2788
program, you will need to set all such watchpoints again.  One way of
2789
doing that would be to set a code breakpoint at the entry to the `main'
2790
function and when it breaks, set all the watchpoints.
2791
 
2792
   In multi-threaded programs, watchpoints will detect changes to the
2793
watched expression from every thread.
2794
 
2795
     _Warning:_ In multi-threaded programs, software watchpoints have
2796
     only limited usefulness.  If GDB creates a software watchpoint, it
2797
     can only watch the value of an expression _in a single thread_.
2798
     If you are confident that the expression can only change due to
2799
     the current thread's activity (and if you are also confident that
2800
     no other thread can become current), then you can use software
2801
     watchpoints as usual.  However, GDB may not notice when a
2802
     non-current thread's activity changes the expression.  (Hardware
2803
     watchpoints, in contrast, watch an expression in all threads.)
2804
 
2805
   *Note set remote hardware-watchpoint-limit::.
2806
 
2807

2808
File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
2809
 
2810
5.1.3 Setting Catchpoints
2811
-------------------------
2812
 
2813
You can use "catchpoints" to cause the debugger to stop for certain
2814
kinds of program events, such as C++ exceptions or the loading of a
2815
shared library.  Use the `catch' command to set a catchpoint.
2816
 
2817
`catch EVENT'
2818
     Stop when EVENT occurs.  EVENT can be any of the following:
2819
    `throw'
2820
          The throwing of a C++ exception.
2821
 
2822
    `catch'
2823
          The catching of a C++ exception.
2824
 
2825
    `exception'
2826
          An Ada exception being raised.  If an exception name is
2827
          specified at the end of the command (eg `catch exception
2828
          Program_Error'), the debugger will stop only when this
2829
          specific exception is raised.  Otherwise, the debugger stops
2830
          execution when any Ada exception is raised.
2831
 
2832
    `exception unhandled'
2833
          An exception that was raised but is not handled by the
2834
          program.
2835
 
2836
    `assert'
2837
          A failed Ada assertion.
2838
 
2839
    `exec'
2840
          A call to `exec'.  This is currently only available for HP-UX
2841
          and GNU/Linux.
2842
 
2843
    `fork'
2844
          A call to `fork'.  This is currently only available for HP-UX
2845
          and GNU/Linux.
2846
 
2847
    `vfork'
2848
          A call to `vfork'.  This is currently only available for HP-UX
2849
          and GNU/Linux.
2850
 
2851
    `load'
2852
    `load LIBNAME'
2853
          The dynamic loading of any shared library, or the loading of
2854
          the library LIBNAME.  This is currently only available for
2855
          HP-UX.
2856
 
2857
    `unload'
2858
    `unload LIBNAME'
2859
          The unloading of any dynamically loaded shared library, or
2860
          the unloading of the library LIBNAME.  This is currently only
2861
          available for HP-UX.
2862
 
2863
`tcatch EVENT'
2864
     Set a catchpoint that is enabled only for one stop.  The
2865
     catchpoint is automatically deleted after the first time the event
2866
     is caught.
2867
 
2868
 
2869
   Use the `info break' command to list the current catchpoints.
2870
 
2871
   There are currently some limitations to C++ exception handling
2872
(`catch throw' and `catch catch') in GDB:
2873
 
2874
   * If you call a function interactively, GDB normally returns control
2875
     to you when the function has finished executing.  If the call
2876
     raises an exception, however, the call may bypass the mechanism
2877
     that returns control to you and cause your program either to abort
2878
     or to simply continue running until it hits a breakpoint, catches
2879
     a signal that GDB is listening for, or exits.  This is the case
2880
     even if you set a catchpoint for the exception; catchpoints on
2881
     exceptions are disabled within interactive calls.
2882
 
2883
   * You cannot raise an exception interactively.
2884
 
2885
   * You cannot install an exception handler interactively.
2886
 
2887
   Sometimes `catch' is not the best way to debug exception handling:
2888
if you need to know exactly where an exception is raised, it is better
2889
to stop _before_ the exception handler is called, since that way you
2890
can see the stack before any unwinding takes place.  If you set a
2891
breakpoint in an exception handler instead, it may not be easy to find
2892
out where the exception was raised.
2893
 
2894
   To stop just before an exception handler is called, you need some
2895
knowledge of the implementation.  In the case of GNU C++, exceptions are
2896
raised by calling a library function named `__raise_exception' which
2897
has the following ANSI C interface:
2898
 
2899
         /* ADDR is where the exception identifier is stored.
2900
            ID is the exception identifier.  */
2901
         void __raise_exception (void **addr, void *id);
2902
 
2903
To make the debugger catch all exceptions before any stack unwinding
2904
takes place, set a breakpoint on `__raise_exception' (*note
2905
Breakpoints; Watchpoints; and Exceptions: Breakpoints.).
2906
 
2907
   With a conditional breakpoint (*note Break Conditions: Conditions.)
2908
that depends on the value of ID, you can stop your program when a
2909
specific exception is raised.  You can use multiple conditional
2910
breakpoints to stop your program when any of a number of exceptions are
2911
raised.
2912
 
2913

2914
File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
2915
 
2916
5.1.4 Deleting Breakpoints
2917
--------------------------
2918
 
2919
It is often necessary to eliminate a breakpoint, watchpoint, or
2920
catchpoint once it has done its job and you no longer want your program
2921
to stop there.  This is called "deleting" the breakpoint.  A breakpoint
2922
that has been deleted no longer exists; it is forgotten.
2923
 
2924
   With the `clear' command you can delete breakpoints according to
2925
where they are in your program.  With the `delete' command you can
2926
delete individual breakpoints, watchpoints, or catchpoints by specifying
2927
their breakpoint numbers.
2928
 
2929
   It is not necessary to delete a breakpoint to proceed past it.  GDB
2930
automatically ignores breakpoints on the first instruction to be
2931
executed when you continue execution without changing the execution
2932
address.
2933
 
2934
`clear'
2935
     Delete any breakpoints at the next instruction to be executed in
2936
     the selected stack frame (*note Selecting a Frame: Selection.).
2937
     When the innermost frame is selected, this is a good way to delete
2938
     a breakpoint where your program just stopped.
2939
 
2940
`clear LOCATION'
2941
     Delete any breakpoints set at the specified LOCATION.  *Note
2942
     Specify Location::, for the various forms of LOCATION; the most
2943
     useful ones are listed below:
2944
 
2945
    `clear FUNCTION'
2946
    `clear FILENAME:FUNCTION'
2947
          Delete any breakpoints set at entry to the named FUNCTION.
2948
 
2949
    `clear LINENUM'
2950
    `clear FILENAME:LINENUM'
2951
          Delete any breakpoints set at or within the code of the
2952
          specified LINENUM of the specified FILENAME.
2953
 
2954
`delete [breakpoints] [RANGE...]'
2955
     Delete the breakpoints, watchpoints, or catchpoints of the
2956
     breakpoint ranges specified as arguments.  If no argument is
2957
     specified, delete all breakpoints (GDB asks confirmation, unless
2958
     you have `set confirm off').  You can abbreviate this command as
2959
     `d'.
2960
 
2961

2962
File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
2963
 
2964
5.1.5 Disabling Breakpoints
2965
---------------------------
2966
 
2967
Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2968
prefer to "disable" it.  This makes the breakpoint inoperative as if it
2969
had been deleted, but remembers the information on the breakpoint so
2970
that you can "enable" it again later.
2971
 
2972
   You disable and enable breakpoints, watchpoints, and catchpoints with
2973
the `enable' and `disable' commands, optionally specifying one or more
2974
breakpoint numbers as arguments.  Use `info break' or `info watch' to
2975
print a list of breakpoints, watchpoints, and catchpoints if you do not
2976
know which numbers to use.
2977
 
2978
   Disabling and enabling a breakpoint that has multiple locations
2979
affects all of its locations.
2980
 
2981
   A breakpoint, watchpoint, or catchpoint can have any of four
2982
different states of enablement:
2983
 
2984
   * Enabled.  The breakpoint stops your program.  A breakpoint set
2985
     with the `break' command starts out in this state.
2986
 
2987
   * Disabled.  The breakpoint has no effect on your program.
2988
 
2989
   * Enabled once.  The breakpoint stops your program, but then becomes
2990
     disabled.
2991
 
2992
   * Enabled for deletion.  The breakpoint stops your program, but
2993
     immediately after it does so it is deleted permanently.  A
2994
     breakpoint set with the `tbreak' command starts out in this state.
2995
 
2996
   You can use the following commands to enable or disable breakpoints,
2997
watchpoints, and catchpoints:
2998
 
2999
`disable [breakpoints] [RANGE...]'
3000
     Disable the specified breakpoints--or all breakpoints, if none are
3001
     listed.  A disabled breakpoint has no effect but is not forgotten.
3002
     All options such as ignore-counts, conditions and commands are
3003
     remembered in case the breakpoint is enabled again later.  You may
3004
     abbreviate `disable' as `dis'.
3005
 
3006
`enable [breakpoints] [RANGE...]'
3007
     Enable the specified breakpoints (or all defined breakpoints).
3008
     They become effective once again in stopping your program.
3009
 
3010
`enable [breakpoints] once RANGE...'
3011
     Enable the specified breakpoints temporarily.  GDB disables any of
3012
     these breakpoints immediately after stopping your program.
3013
 
3014
`enable [breakpoints] delete RANGE...'
3015
     Enable the specified breakpoints to work once, then die.  GDB
3016
     deletes any of these breakpoints as soon as your program stops
3017
     there.  Breakpoints set by the `tbreak' command start out in this
3018
     state.
3019
 
3020
   Except for a breakpoint set with `tbreak' (*note Setting
3021
Breakpoints: Set Breaks.), breakpoints that you set are initially
3022
enabled; subsequently, they become disabled or enabled only when you
3023
use one of the commands above.  (The command `until' can set and delete
3024
a breakpoint of its own, but it does not change the state of your other
3025
breakpoints; see *Note Continuing and Stepping: Continuing and
3026
Stepping.)
3027
 
3028

3029
File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
3030
 
3031
5.1.6 Break Conditions
3032
----------------------
3033
 
3034
The simplest sort of breakpoint breaks every time your program reaches a
3035
specified place.  You can also specify a "condition" for a breakpoint.
3036
A condition is just a Boolean expression in your programming language
3037
(*note Expressions: Expressions.).  A breakpoint with a condition
3038
evaluates the expression each time your program reaches it, and your
3039
program stops only if the condition is _true_.
3040
 
3041
   This is the converse of using assertions for program validation; in
3042
that situation, you want to stop when the assertion is violated--that
3043
is, when the condition is false.  In C, if you want to test an
3044
assertion expressed by the condition ASSERT, you should set the
3045
condition `! ASSERT' on the appropriate breakpoint.
3046
 
3047
   Conditions are also accepted for watchpoints; you may not need them,
3048
since a watchpoint is inspecting the value of an expression anyhow--but
3049
it might be simpler, say, to just set a watchpoint on a variable name,
3050
and specify a condition that tests whether the new value is an
3051
interesting one.
3052
 
3053
   Break conditions can have side effects, and may even call functions
3054
in your program.  This can be useful, for example, to activate functions
3055
that log program progress, or to use your own print functions to format
3056
special data structures. The effects are completely predictable unless
3057
there is another enabled breakpoint at the same address.  (In that
3058
case, GDB might see the other breakpoint first and stop your program
3059
without checking the condition of this one.)  Note that breakpoint
3060
commands are usually more convenient and flexible than break conditions
3061
for the purpose of performing side effects when a breakpoint is reached
3062
(*note Breakpoint Command Lists: Break Commands.).
3063
 
3064
   Break conditions can be specified when a breakpoint is set, by using
3065
`if' in the arguments to the `break' command.  *Note Setting
3066
Breakpoints: Set Breaks.  They can also be changed at any time with the
3067
`condition' command.
3068
 
3069
   You can also use the `if' keyword with the `watch' command.  The
3070
`catch' command does not recognize the `if' keyword; `condition' is the
3071
only way to impose a further condition on a catchpoint.
3072
 
3073
`condition BNUM EXPRESSION'
3074
     Specify EXPRESSION as the break condition for breakpoint,
3075
     watchpoint, or catchpoint number BNUM.  After you set a condition,
3076
     breakpoint BNUM stops your program only if the value of EXPRESSION
3077
     is true (nonzero, in C).  When you use `condition', GDB checks
3078
     EXPRESSION immediately for syntactic correctness, and to determine
3079
     whether symbols in it have referents in the context of your
3080
     breakpoint.  If EXPRESSION uses symbols not referenced in the
3081
     context of the breakpoint, GDB prints an error message:
3082
 
3083
          No symbol "foo" in current context.
3084
 
3085
     GDB does not actually evaluate EXPRESSION at the time the
3086
     `condition' command (or a command that sets a breakpoint with a
3087
     condition, like `break if ...') is given, however.  *Note
3088
     Expressions: Expressions.
3089
 
3090
`condition BNUM'
3091
     Remove the condition from breakpoint number BNUM.  It becomes an
3092
     ordinary unconditional breakpoint.
3093
 
3094
   A special case of a breakpoint condition is to stop only when the
3095
breakpoint has been reached a certain number of times.  This is so
3096
useful that there is a special way to do it, using the "ignore count"
3097
of the breakpoint.  Every breakpoint has an ignore count, which is an
3098
integer.  Most of the time, the ignore count is zero, and therefore has
3099
no effect.  But if your program reaches a breakpoint whose ignore count
3100
is positive, then instead of stopping, it just decrements the ignore
3101
count by one and continues.  As a result, if the ignore count value is
3102
N, the breakpoint does not stop the next N times your program reaches
3103
it.
3104
 
3105
`ignore BNUM COUNT'
3106
     Set the ignore count of breakpoint number BNUM to COUNT.  The next
3107
     COUNT times the breakpoint is reached, your program's execution
3108
     does not stop; other than to decrement the ignore count, GDB takes
3109
     no action.
3110
 
3111
     To make the breakpoint stop the next time it is reached, specify a
3112
     count of zero.
3113
 
3114
     When you use `continue' to resume execution of your program from a
3115
     breakpoint, you can specify an ignore count directly as an
3116
     argument to `continue', rather than using `ignore'.  *Note
3117
     Continuing and Stepping: Continuing and Stepping.
3118
 
3119
     If a breakpoint has a positive ignore count and a condition, the
3120
     condition is not checked.  Once the ignore count reaches zero, GDB
3121
     resumes checking the condition.
3122
 
3123
     You could achieve the effect of the ignore count with a condition
3124
     such as `$foo-- <= 0' using a debugger convenience variable that
3125
     is decremented each time.  *Note Convenience Variables:
3126
     Convenience Vars.
3127
 
3128
   Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3129
 
3130

3131
File: gdb.info,  Node: Break Commands,  Next: Breakpoint Menus,  Prev: Conditions,  Up: Breakpoints
3132
 
3133
5.1.7 Breakpoint Command Lists
3134
------------------------------
3135
 
3136
You can give any breakpoint (or watchpoint or catchpoint) a series of
3137
commands to execute when your program stops due to that breakpoint.  For
3138
example, you might want to print the values of certain expressions, or
3139
enable other breakpoints.
3140
 
3141
`commands [BNUM]'
3142
`... COMMAND-LIST ...'
3143
`end'
3144
     Specify a list of commands for breakpoint number BNUM.  The
3145
     commands themselves appear on the following lines.  Type a line
3146
     containing just `end' to terminate the commands.
3147
 
3148
     To remove all commands from a breakpoint, type `commands' and
3149
     follow it immediately with `end'; that is, give no commands.
3150
 
3151
     With no BNUM argument, `commands' refers to the last breakpoint,
3152
     watchpoint, or catchpoint set (not to the breakpoint most recently
3153
     encountered).
3154
 
3155
   Pressing  as a means of repeating the last GDB command is
3156
disabled within a COMMAND-LIST.
3157
 
3158
   You can use breakpoint commands to start your program up again.
3159
Simply use the `continue' command, or `step', or any other command that
3160
resumes execution.
3161
 
3162
   Any other commands in the command list, after a command that resumes
3163
execution, are ignored.  This is because any time you resume execution
3164
(even with a simple `next' or `step'), you may encounter another
3165
breakpoint--which could have its own command list, leading to
3166
ambiguities about which list to execute.
3167
 
3168
   If the first command you specify in a command list is `silent', the
3169
usual message about stopping at a breakpoint is not printed.  This may
3170
be desirable for breakpoints that are to print a specific message and
3171
then continue.  If none of the remaining commands print anything, you
3172
see no sign that the breakpoint was reached.  `silent' is meaningful
3173
only at the beginning of a breakpoint command list.
3174
 
3175
   The commands `echo', `output', and `printf' allow you to print
3176
precisely controlled output, and are often useful in silent
3177
breakpoints.  *Note Commands for Controlled Output: Output.
3178
 
3179
   For example, here is how you could use breakpoint commands to print
3180
the value of `x' at entry to `foo' whenever `x' is positive.
3181
 
3182
     break foo if x>0
3183
     commands
3184
     silent
3185
     printf "x is %d\n",x
3186
     cont
3187
     end
3188
 
3189
   One application for breakpoint commands is to compensate for one bug
3190
so you can test for another.  Put a breakpoint just after the erroneous
3191
line of code, give it a condition to detect the case in which something
3192
erroneous has been done, and give it commands to assign correct values
3193
to any variables that need them.  End with the `continue' command so
3194
that your program does not stop, and start with the `silent' command so
3195
that no output is produced.  Here is an example:
3196
 
3197
     break 403
3198
     commands
3199
     silent
3200
     set x = y + 4
3201
     cont
3202
     end
3203
 
3204

3205
File: gdb.info,  Node: Breakpoint Menus,  Next: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
3206
 
3207
5.1.8 Breakpoint Menus
3208
----------------------
3209
 
3210
Some programming languages (notably C++ and Objective-C) permit a
3211
single function name to be defined several times, for application in
3212
different contexts.  This is called "overloading".  When a function
3213
name is overloaded, `break FUNCTION' is not enough to tell GDB where
3214
you want a breakpoint.  You can use explicit signature of the function,
3215
as in `break FUNCTION(TYPES)', to specify which particular version of
3216
the function you want.  Otherwise, GDB offers you a menu of numbered
3217
choices for different possible breakpoints, and waits for your
3218
selection with the prompt `>'.  The first two options are always `[0]
3219
cancel' and `[1] all'.  Typing `1' sets a breakpoint at each definition
3220
of FUNCTION, and typing `0' aborts the `break' command without setting
3221
any new breakpoints.
3222
 
3223
   For example, the following session excerpt shows an attempt to set a
3224
breakpoint at the overloaded symbol `String::after'.  We choose three
3225
particular definitions of that function name:
3226
 
3227
     (gdb) b String::after
3228
     [0] cancel
3229
     [1] all
3230
     [2] file:String.cc; line number:867
3231
     [3] file:String.cc; line number:860
3232
     [4] file:String.cc; line number:875
3233
     [5] file:String.cc; line number:853
3234
     [6] file:String.cc; line number:846
3235
     [7] file:String.cc; line number:735
3236
     > 2 4 6
3237
     Breakpoint 1 at 0xb26c: file String.cc, line 867.
3238
     Breakpoint 2 at 0xb344: file String.cc, line 875.
3239
     Breakpoint 3 at 0xafcc: file String.cc, line 846.
3240
     Multiple breakpoints were set.
3241
     Use the "delete" command to delete unwanted
3242
      breakpoints.
3243
     (gdb)
3244
 
3245

3246
File: gdb.info,  Node: Error in Breakpoints,  Next: Breakpoint-related Warnings,  Prev: Breakpoint Menus,  Up: Breakpoints
3247
 
3248
5.1.9 "Cannot insert breakpoints"
3249
---------------------------------
3250
 
3251
Under some operating systems, breakpoints cannot be used in a program if
3252
any other process is running that program.  In this situation,
3253
attempting to run or continue a program with a breakpoint causes GDB to
3254
print an error message:
3255
 
3256
     Cannot insert breakpoints.
3257
     The same program may be running in another process.
3258
 
3259
   When this happens, you have three ways to proceed:
3260
 
3261
  1. Remove or disable the breakpoints, then continue.
3262
 
3263
  2. Suspend GDB, and copy the file containing your program to a new
3264
     name.  Resume GDB and use the `exec-file' command to specify that
3265
     GDB should run your program under that name.  Then start your
3266
     program again.
3267
 
3268
  3. Relink your program so that the text segment is nonsharable, using
3269
     the linker option `-N'.  The operating system limitation may not
3270
     apply to nonsharable executables.
3271
 
3272
   A similar message can be printed if you request too many active
3273
hardware-assisted breakpoints and watchpoints:
3274
 
3275
     Stopped; cannot insert breakpoints.
3276
     You may have requested too many hardware breakpoints and watchpoints.
3277
 
3278
This message is printed when you attempt to resume the program, since
3279
only then GDB knows exactly how many hardware breakpoints and
3280
watchpoints it needs to insert.
3281
 
3282
   When this message is printed, you need to disable or remove some of
3283
the hardware-assisted breakpoints and watchpoints, and then continue.
3284
 
3285

3286
File: gdb.info,  Node: Breakpoint-related Warnings,  Prev: Error in Breakpoints,  Up: Breakpoints
3287
 
3288
5.1.10 "Breakpoint address adjusted..."
3289
---------------------------------------
3290
 
3291
Some processor architectures place constraints on the addresses at
3292
which breakpoints may be placed.  For architectures thus constrained,
3293
GDB will attempt to adjust the breakpoint's address to comply with the
3294
constraints dictated by the architecture.
3295
 
3296
   One example of such an architecture is the Fujitsu FR-V.  The FR-V is
3297
a VLIW architecture in which a number of RISC-like instructions may be
3298
bundled together for parallel execution.  The FR-V architecture
3299
constrains the location of a breakpoint instruction within such a
3300
bundle to the instruction with the lowest address.  GDB honors this
3301
constraint by adjusting a breakpoint's address to the first in the
3302
bundle.
3303
 
3304
   It is not uncommon for optimized code to have bundles which contain
3305
instructions from different source statements, thus it may happen that
3306
a breakpoint's address will be adjusted from one source statement to
3307
another.  Since this adjustment may significantly alter GDB's
3308
breakpoint related behavior from what the user expects, a warning is
3309
printed when the breakpoint is first set and also when the breakpoint
3310
is hit.
3311
 
3312
   A warning like the one below is printed when setting a breakpoint
3313
that's been subject to address adjustment:
3314
 
3315
     warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3316
 
3317
   Such warnings are printed both for user settable and GDB's internal
3318
breakpoints.  If you see one of these warnings, you should verify that
3319
a breakpoint set at the adjusted address will have the desired affect.
3320
If not, the breakpoint in question may be removed and other breakpoints
3321
may be set which will have the desired behavior.  E.g., it may be
3322
sufficient to place the breakpoint at a later instruction.  A
3323
conditional breakpoint may also be useful in some cases to prevent the
3324
breakpoint from triggering too often.
3325
 
3326
   GDB will also issue a warning when stopping at one of these adjusted
3327
breakpoints:
3328
 
3329
     warning: Breakpoint 1 address previously adjusted from 0x00010414
3330
     to 0x00010410.
3331
 
3332
   When this warning is encountered, it may be too late to take remedial
3333
action except in cases where the breakpoint is hit earlier or more
3334
frequently than expected.
3335
 
3336

3337
File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
3338
 
3339
5.2 Continuing and Stepping
3340
===========================
3341
 
3342
"Continuing" means resuming program execution until your program
3343
completes normally.  In contrast, "stepping" means executing just one
3344
more "step" of your program, where "step" may mean either one line of
3345
source code, or one machine instruction (depending on what particular
3346
command you use).  Either when continuing or when stepping, your
3347
program may stop even sooner, due to a breakpoint or a signal.  (If it
3348
stops due to a signal, you may want to use `handle', or use `signal 0'
3349
to resume execution.  *Note Signals: Signals.)
3350
 
3351
`continue [IGNORE-COUNT]'
3352
`c [IGNORE-COUNT]'
3353
`fg [IGNORE-COUNT]'
3354
     Resume program execution, at the address where your program last
3355
     stopped; any breakpoints set at that address are bypassed.  The
3356
     optional argument IGNORE-COUNT allows you to specify a further
3357
     number of times to ignore a breakpoint at this location; its
3358
     effect is like that of `ignore' (*note Break Conditions:
3359
     Conditions.).
3360
 
3361
     The argument IGNORE-COUNT is meaningful only when your program
3362
     stopped due to a breakpoint.  At other times, the argument to
3363
     `continue' is ignored.
3364
 
3365
     The synonyms `c' and `fg' (for "foreground", as the debugged
3366
     program is deemed to be the foreground program) are provided
3367
     purely for convenience, and have exactly the same behavior as
3368
     `continue'.
3369
 
3370
   To resume execution at a different place, you can use `return'
3371
(*note Returning from a Function: Returning.) to go back to the calling
3372
function; or `jump' (*note Continuing at a Different Address: Jumping.)
3373
to go to an arbitrary location in your program.
3374
 
3375
   A typical technique for using stepping is to set a breakpoint (*note
3376
Breakpoints; Watchpoints; and Catchpoints: Breakpoints.) at the
3377
beginning of the function or the section of your program where a problem
3378
is believed to lie, run your program until it stops at that breakpoint,
3379
and then step through the suspect area, examining the variables that are
3380
interesting, until you see the problem happen.
3381
 
3382
`step'
3383
     Continue running your program until control reaches a different
3384
     source line, then stop it and return control to GDB.  This command
3385
     is abbreviated `s'.
3386
 
3387
          _Warning:_ If you use the `step' command while control is
3388
          within a function that was compiled without debugging
3389
          information, execution proceeds until control reaches a
3390
          function that does have debugging information.  Likewise, it
3391
          will not step into a function which is compiled without
3392
          debugging information.  To step through functions without
3393
          debugging information, use the `stepi' command, described
3394
          below.
3395
 
3396
     The `step' command only stops at the first instruction of a source
3397
     line.  This prevents the multiple stops that could otherwise occur
3398
     in `switch' statements, `for' loops, etc.  `step' continues to
3399
     stop if a function that has debugging information is called within
3400
     the line.  In other words, `step' _steps inside_ any functions
3401
     called within the line.
3402
 
3403
     Also, the `step' command only enters a function if there is line
3404
     number information for the function.  Otherwise it acts like the
3405
     `next' command.  This avoids problems when using `cc -gl' on MIPS
3406
     machines.  Previously, `step' entered subroutines if there was any
3407
     debugging information about the routine.
3408
 
3409
`step COUNT'
3410
     Continue running as in `step', but do so COUNT times.  If a
3411
     breakpoint is reached, or a signal not related to stepping occurs
3412
     before COUNT steps, stepping stops right away.
3413
 
3414
`next [COUNT]'
3415
     Continue to the next source line in the current (innermost) stack
3416
     frame.  This is similar to `step', but function calls that appear
3417
     within the line of code are executed without stopping.  Execution
3418
     stops when control reaches a different line of code at the
3419
     original stack level that was executing when you gave the `next'
3420
     command.  This command is abbreviated `n'.
3421
 
3422
     An argument COUNT is a repeat count, as for `step'.
3423
 
3424
     The `next' command only stops at the first instruction of a source
3425
     line.  This prevents multiple stops that could otherwise occur in
3426
     `switch' statements, `for' loops, etc.
3427
 
3428
`set step-mode'
3429
`set step-mode on'
3430
     The `set step-mode on' command causes the `step' command to stop
3431
     at the first instruction of a function which contains no debug line
3432
     information rather than stepping over it.
3433
 
3434
     This is useful in cases where you may be interested in inspecting
3435
     the machine instructions of a function which has no symbolic info
3436
     and do not want GDB to automatically skip over this function.
3437
 
3438
`set step-mode off'
3439
     Causes the `step' command to step over any functions which
3440
     contains no debug information.  This is the default.
3441
 
3442
`show step-mode'
3443
     Show whether GDB will stop in or step over functions without
3444
     source line debug information.
3445
 
3446
`finish'
3447
     Continue running until just after function in the selected stack
3448
     frame returns.  Print the returned value (if any).
3449
 
3450
     Contrast this with the `return' command (*note Returning from a
3451
     Function: Returning.).
3452
 
3453
`until'
3454
`u'
3455
     Continue running until a source line past the current line, in the
3456
     current stack frame, is reached.  This command is used to avoid
3457
     single stepping through a loop more than once.  It is like the
3458
     `next' command, except that when `until' encounters a jump, it
3459
     automatically continues execution until the program counter is
3460
     greater than the address of the jump.
3461
 
3462
     This means that when you reach the end of a loop after single
3463
     stepping though it, `until' makes your program continue execution
3464
     until it exits the loop.  In contrast, a `next' command at the end
3465
     of a loop simply steps back to the beginning of the loop, which
3466
     forces you to step through the next iteration.
3467
 
3468
     `until' always stops your program if it attempts to exit the
3469
     current stack frame.
3470
 
3471
     `until' may produce somewhat counterintuitive results if the order
3472
     of machine code does not match the order of the source lines.  For
3473
     example, in the following excerpt from a debugging session, the `f'
3474
     (`frame') command shows that execution is stopped at line `206';
3475
     yet when we use `until', we get to line `195':
3476
 
3477
          (gdb) f
3478
          #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
3479
          206                 expand_input();
3480
          (gdb) until
3481
          195             for ( ; argc > 0; NEXTARG) {
3482
 
3483
     This happened because, for execution efficiency, the compiler had
3484
     generated code for the loop closure test at the end, rather than
3485
     the start, of the loop--even though the test in a C `for'-loop is
3486
     written before the body of the loop.  The `until' command appeared
3487
     to step back to the beginning of the loop when it advanced to this
3488
     expression; however, it has not really gone to an earlier
3489
     statement--not in terms of the actual machine code.
3490
 
3491
     `until' with no argument works by means of single instruction
3492
     stepping, and hence is slower than `until' with an argument.
3493
 
3494
`until LOCATION'
3495
`u LOCATION'
3496
     Continue running your program until either the specified location
3497
     is reached, or the current stack frame returns.  LOCATION is any of
3498
     the forms described in *Note Specify Location::.  This form of the
3499
     command uses temporary breakpoints, and hence is quicker than
3500
     `until' without an argument.  The specified location is actually
3501
     reached only if it is in the current frame.  This implies that
3502
     `until' can be used to skip over recursive function invocations.
3503
     For instance in the code below, if the current location is line
3504
     `96', issuing `until 99' will execute the program up to line `99'
3505
     in the same invocation of factorial, i.e., after the inner
3506
     invocations have returned.
3507
 
3508
          94    int factorial (int value)
3509
          95    {
3510
          96        if (value > 1) {
3511
          97            value *= factorial (value - 1);
3512
          98        }
3513
          99        return (value);
3514
          100     }
3515
 
3516
`advance LOCATION'
3517
     Continue running the program up to the given LOCATION.  An
3518
     argument is required, which should be of one of the forms
3519
     described in *Note Specify Location::.  Execution will also stop
3520
     upon exit from the current stack frame.  This command is similar
3521
     to `until', but `advance' will not skip over recursive function
3522
     calls, and the target location doesn't have to be in the same
3523
     frame as the current one.
3524
 
3525
`stepi'
3526
`stepi ARG'
3527
`si'
3528
     Execute one machine instruction, then stop and return to the
3529
     debugger.
3530
 
3531
     It is often useful to do `display/i $pc' when stepping by machine
3532
     instructions.  This makes GDB automatically display the next
3533
     instruction to be executed, each time your program stops.  *Note
3534
     Automatic Display: Auto Display.
3535
 
3536
     An argument is a repeat count, as in `step'.
3537
 
3538
`nexti'
3539
`nexti ARG'
3540
`ni'
3541
     Execute one machine instruction, but if it is a function call,
3542
     proceed until the function returns.
3543
 
3544
     An argument is a repeat count, as in `next'.
3545
 
3546

3547
File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Continuing and Stepping,  Up: Stopping
3548
 
3549
5.3 Signals
3550
===========
3551
 
3552
A signal is an asynchronous event that can happen in a program.  The
3553
operating system defines the possible kinds of signals, and gives each
3554
kind a name and a number.  For example, in Unix `SIGINT' is the signal
3555
a program gets when you type an interrupt character (often `Ctrl-c');
3556
`SIGSEGV' is the signal a program gets from referencing a place in
3557
memory far away from all the areas in use; `SIGALRM' occurs when the
3558
alarm clock timer goes off (which happens only if your program has
3559
requested an alarm).
3560
 
3561
   Some signals, including `SIGALRM', are a normal part of the
3562
functioning of your program.  Others, such as `SIGSEGV', indicate
3563
errors; these signals are "fatal" (they kill your program immediately)
3564
if the program has not specified in advance some other way to handle
3565
the signal.  `SIGINT' does not indicate an error in your program, but
3566
it is normally fatal so it can carry out the purpose of the interrupt:
3567
to kill the program.
3568
 
3569
   GDB has the ability to detect any occurrence of a signal in your
3570
program.  You can tell GDB in advance what to do for each kind of
3571
signal.
3572
 
3573
   Normally, GDB is set up to let the non-erroneous signals like
3574
`SIGALRM' be silently passed to your program (so as not to interfere
3575
with their role in the program's functioning) but to stop your program
3576
immediately whenever an error signal happens.  You can change these
3577
settings with the `handle' command.
3578
 
3579
`info signals'
3580
`info handle'
3581
     Print a table of all the kinds of signals and how GDB has been
3582
     told to handle each one.  You can use this to see the signal
3583
     numbers of all the defined types of signals.
3584
 
3585
`info signals SIG'
3586
     Similar, but print information only about the specified signal
3587
     number.
3588
 
3589
     `info handle' is an alias for `info signals'.
3590
 
3591
`handle SIGNAL [KEYWORDS...]'
3592
     Change the way GDB handles signal SIGNAL.  SIGNAL can be the
3593
     number of a signal or its name (with or without the `SIG' at the
3594
     beginning); a list of signal numbers of the form `LOW-HIGH'; or
3595
     the word `all', meaning all the known signals.  Optional arguments
3596
     KEYWORDS, described below, say what change to make.
3597
 
3598
   The keywords allowed by the `handle' command can be abbreviated.
3599
Their full names are:
3600
 
3601
`nostop'
3602
     GDB should not stop your program when this signal happens.  It may
3603
     still print a message telling you that the signal has come in.
3604
 
3605
`stop'
3606
     GDB should stop your program when this signal happens.  This
3607
     implies the `print' keyword as well.
3608
 
3609
`print'
3610
     GDB should print a message when this signal happens.
3611
 
3612
`noprint'
3613
     GDB should not mention the occurrence of the signal at all.  This
3614
     implies the `nostop' keyword as well.
3615
 
3616
`pass'
3617
`noignore'
3618
     GDB should allow your program to see this signal; your program can
3619
     handle the signal, or else it may terminate if the signal is fatal
3620
     and not handled.  `pass' and `noignore' are synonyms.
3621
 
3622
`nopass'
3623
`ignore'
3624
     GDB should not allow your program to see this signal.  `nopass'
3625
     and `ignore' are synonyms.
3626
 
3627
   When a signal stops your program, the signal is not visible to the
3628
program until you continue.  Your program sees the signal then, if
3629
`pass' is in effect for the signal in question _at that time_.  In
3630
other words, after GDB reports a signal, you can use the `handle'
3631
command with `pass' or `nopass' to control whether your program sees
3632
that signal when you continue.
3633
 
3634
   The default is set to `nostop', `noprint', `pass' for non-erroneous
3635
signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
3636
`print', `pass' for the erroneous signals.
3637
 
3638
   You can also use the `signal' command to prevent your program from
3639
seeing a signal, or cause it to see a signal it normally would not see,
3640
or to give it any signal at any time.  For example, if your program
3641
stopped due to some sort of memory reference error, you might store
3642
correct values into the erroneous variables and continue, hoping to see
3643
more execution; but your program would probably terminate immediately as
3644
a result of the fatal signal once it saw the signal.  To prevent this,
3645
you can continue with `signal 0'.  *Note Giving your Program a Signal:
3646
Signaling.
3647
 
3648

3649
File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
3650
 
3651
5.4 Stopping and Starting Multi-thread Programs
3652
===============================================
3653
 
3654
When your program has multiple threads (*note Debugging Programs with
3655
Multiple Threads: Threads.), you can choose whether to set breakpoints
3656
on all threads, or on a particular thread.
3657
 
3658
`break LINESPEC thread THREADNO'
3659
`break LINESPEC thread THREADNO if ...'
3660
     LINESPEC specifies source lines; there are several ways of writing
3661
     them (*note Specify Location::), but the effect is always to
3662
     specify some source line.
3663
 
3664
     Use the qualifier `thread THREADNO' with a breakpoint command to
3665
     specify that you only want GDB to stop the program when a
3666
     particular thread reaches this breakpoint.  THREADNO is one of the
3667
     numeric thread identifiers assigned by GDB, shown in the first
3668
     column of the `info threads' display.
3669
 
3670
     If you do not specify `thread THREADNO' when you set a breakpoint,
3671
     the breakpoint applies to _all_ threads of your program.
3672
 
3673
     You can use the `thread' qualifier on conditional breakpoints as
3674
     well; in this case, place `thread THREADNO' before the breakpoint
3675
     condition, like this:
3676
 
3677
          (gdb) break frik.c:13 thread 28 if bartab > lim
3678
 
3679
 
3680
   Whenever your program stops under GDB for any reason, _all_ threads
3681
of execution stop, not just the current thread.  This allows you to
3682
examine the overall state of the program, including switching between
3683
threads, without worrying that things may change underfoot.
3684
 
3685
   There is an unfortunate side effect.  If one thread stops for a
3686
breakpoint, or for some other reason, and another thread is blocked in a
3687
system call, then the system call may return prematurely.  This is a
3688
consequence of the interaction between multiple threads and the signals
3689
that GDB uses to implement breakpoints and other events that stop
3690
execution.
3691
 
3692
   To handle this problem, your program should check the return value of
3693
each system call and react appropriately.  This is good programming
3694
style anyways.
3695
 
3696
   For example, do not write code like this:
3697
 
3698
       sleep (10);
3699
 
3700
   The call to `sleep' will return early if a different thread stops at
3701
a breakpoint or for some other reason.
3702
 
3703
   Instead, write this:
3704
 
3705
       int unslept = 10;
3706
       while (unslept > 0)
3707
         unslept = sleep (unslept);
3708
 
3709
   A system call is allowed to return early, so the system is still
3710
conforming to its specification.  But GDB does cause your
3711
multi-threaded program to behave differently than it would without GDB.
3712
 
3713
   Also, GDB uses internal breakpoints in the thread library to monitor
3714
certain events such as thread creation and thread destruction.  When
3715
such an event happens, a system call in another thread may return
3716
prematurely, even though your program does not appear to stop.
3717
 
3718
   Conversely, whenever you restart the program, _all_ threads start
3719
executing.  _This is true even when single-stepping_ with commands like
3720
`step' or `next'.
3721
 
3722
   In particular, GDB cannot single-step all threads in lockstep.
3723
Since thread scheduling is up to your debugging target's operating
3724
system (not controlled by GDB), other threads may execute more than one
3725
statement while the current thread completes a single step.  Moreover,
3726
in general other threads stop in the middle of a statement, rather than
3727
at a clean statement boundary, when the program stops.
3728
 
3729
   You might even find your program stopped in another thread after
3730
continuing or even single-stepping.  This happens whenever some other
3731
thread runs into a breakpoint, a signal, or an exception before the
3732
first thread completes whatever you requested.
3733
 
3734
   On some OSes, you can lock the OS scheduler and thus allow only a
3735
single thread to run.
3736
 
3737
`set scheduler-locking MODE'
3738
     Set the scheduler locking mode.  If it is `off', then there is no
3739
     locking and any thread may run at any time.  If `on', then only the
3740
     current thread may run when the inferior is resumed.  The `step'
3741
     mode optimizes for single-stepping.  It stops other threads from
3742
     "seizing the prompt" by preempting the current thread while you are
3743
     stepping.  Other threads will only rarely (or never) get a chance
3744
     to run when you step.  They are more likely to run when you `next'
3745
     over a function call, and they are completely free to run when you
3746
     use commands like `continue', `until', or `finish'.  However,
3747
     unless another thread hits a breakpoint during its timeslice, they
3748
     will never steal the GDB prompt away from the thread that you are
3749
     debugging.
3750
 
3751
`show scheduler-locking'
3752
     Display the current scheduler locking mode.
3753
 
3754

3755
File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
3756
 
3757
6 Examining the Stack
3758
*********************
3759
 
3760
When your program has stopped, the first thing you need to know is
3761
where it stopped and how it got there.
3762
 
3763
   Each time your program performs a function call, information about
3764
the call is generated.  That information includes the location of the
3765
call in your program, the arguments of the call, and the local
3766
variables of the function being called.  The information is saved in a
3767
block of data called a "stack frame".  The stack frames are allocated
3768
in a region of memory called the "call stack".
3769
 
3770
   When your program stops, the GDB commands for examining the stack
3771
allow you to see all of this information.
3772
 
3773
   One of the stack frames is "selected" by GDB and many GDB commands
3774
refer implicitly to the selected frame.  In particular, whenever you
3775
ask GDB for the value of a variable in your program, the value is found
3776
in the selected frame.  There are special GDB commands to select
3777
whichever frame you are interested in.  *Note Selecting a Frame:
3778
Selection.
3779
 
3780
   When your program stops, GDB automatically selects the currently
3781
executing frame and describes it briefly, similar to the `frame'
3782
command (*note Information about a Frame: Frame Info.).
3783
 
3784
* Menu:
3785
 
3786
* Frames::                      Stack frames
3787
* Backtrace::                   Backtraces
3788
* Selection::                   Selecting a frame
3789
* Frame Info::                  Information on a frame
3790
 
3791

3792
File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
3793
 
3794
6.1 Stack Frames
3795
================
3796
 
3797
The call stack is divided up into contiguous pieces called "stack
3798
frames", or "frames" for short; each frame is the data associated with
3799
one call to one function.  The frame contains the arguments given to
3800
the function, the function's local variables, and the address at which
3801
the function is executing.
3802
 
3803
   When your program is started, the stack has only one frame, that of
3804
the function `main'.  This is called the "initial" frame or the
3805
"outermost" frame.  Each time a function is called, a new frame is
3806
made.  Each time a function returns, the frame for that function
3807
invocation is eliminated.  If a function is recursive, there can be
3808
many frames for the same function.  The frame for the function in which
3809
execution is actually occurring is called the "innermost" frame.  This
3810
is the most recently created of all the stack frames that still exist.
3811
 
3812
   Inside your program, stack frames are identified by their addresses.
3813
A stack frame consists of many bytes, each of which has its own
3814
address; each kind of computer has a convention for choosing one byte
3815
whose address serves as the address of the frame.  Usually this address
3816
is kept in a register called the "frame pointer register" (*note $fp:
3817
Registers.) while execution is going on in that frame.
3818
 
3819
   GDB assigns numbers to all existing stack frames, starting with zero
3820
for the innermost frame, one for the frame that called it, and so on
3821
upward.  These numbers do not really exist in your program; they are
3822
assigned by GDB to give you a way of designating stack frames in GDB
3823
commands.
3824
 
3825
   Some compilers provide a way to compile functions so that they
3826
operate without stack frames.  (For example, the GCC option
3827
     `-fomit-frame-pointer'
3828
   generates functions without a frame.)  This is occasionally done
3829
with heavily used library functions to save the frame setup time.  GDB
3830
has limited facilities for dealing with these function invocations.  If
3831
the innermost function invocation has no stack frame, GDB nevertheless
3832
regards it as though it had a separate frame, which is numbered zero as
3833
usual, allowing correct tracing of the function call chain.  However,
3834
GDB has no provision for frameless functions elsewhere in the stack.
3835
 
3836
`frame ARGS'
3837
     The `frame' command allows you to move from one stack frame to
3838
     another, and to print the stack frame you select.  ARGS may be
3839
     either the address of the frame or the stack frame number.
3840
     Without an argument, `frame' prints the current stack frame.
3841
 
3842
`select-frame'
3843
     The `select-frame' command allows you to move from one stack frame
3844
     to another without printing the frame.  This is the silent version
3845
     of `frame'.
3846
 
3847

3848
File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
3849
 
3850
6.2 Backtraces
3851
==============
3852
 
3853
A backtrace is a summary of how your program got where it is.  It shows
3854
one line per frame, for many frames, starting with the currently
3855
executing frame (frame zero), followed by its caller (frame one), and
3856
on up the stack.
3857
 
3858
`backtrace'
3859
`bt'
3860
     Print a backtrace of the entire stack: one line per frame for all
3861
     frames in the stack.
3862
 
3863
     You can stop the backtrace at any time by typing the system
3864
     interrupt character, normally `Ctrl-c'.
3865
 
3866
`backtrace N'
3867
`bt N'
3868
     Similar, but print only the innermost N frames.
3869
 
3870
`backtrace -N'
3871
`bt -N'
3872
     Similar, but print only the outermost N frames.
3873
 
3874
`backtrace full'
3875
`bt full'
3876
`bt full N'
3877
`bt full -N'
3878
     Print the values of the local variables also.  N specifies the
3879
     number of frames to print, as described above.
3880
 
3881
   The names `where' and `info stack' (abbreviated `info s') are
3882
additional aliases for `backtrace'.
3883
 
3884
   In a multi-threaded program, GDB by default shows the backtrace only
3885
for the current thread.  To display the backtrace for several or all of
3886
the threads, use the command `thread apply' (*note thread apply:
3887
Threads.).  For example, if you type `thread apply all backtrace', GDB
3888
will display the backtrace for all the threads; this is handy when you
3889
debug a core dump of a multi-threaded program.
3890
 
3891
   Each line in the backtrace shows the frame number and the function
3892
name.  The program counter value is also shown--unless you use `set
3893
print address off'.  The backtrace also shows the source file name and
3894
line number, as well as the arguments to the function.  The program
3895
counter value is omitted if it is at the beginning of the code for that
3896
line number.
3897
 
3898
   Here is an example of a backtrace.  It was made with the command `bt
3899
3', so it shows the innermost three frames.
3900
 
3901
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3902
         at builtin.c:993
3903
     #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3904
     #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3905
         at macro.c:71
3906
     (More stack frames follow...)
3907
 
3908
The display for frame zero does not begin with a program counter value,
3909
indicating that your program has stopped at the beginning of the code
3910
for line `993' of `builtin.c'.
3911
 
3912
   If your program was compiled with optimizations, some compilers will
3913
optimize away arguments passed to functions if those arguments are
3914
never used after the call.  Such optimizations generate code that
3915
passes arguments through registers, but doesn't store those arguments
3916
in the stack frame.  GDB has no way of displaying such arguments in
3917
stack frames other than the innermost one.  Here's what such a
3918
backtrace might look like:
3919
 
3920
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3921
         at builtin.c:993
3922
     #1  0x6e38 in expand_macro (sym=) at macro.c:242
3923
     #2  0x6840 in expand_token (obs=0x0, t=, td=0xf7fffb08)
3924
         at macro.c:71
3925
     (More stack frames follow...)
3926
 
3927
The values of arguments that were not saved in their stack frames are
3928
shown as `'.
3929
 
3930
   If you need to display the values of such optimized-out arguments,
3931
either deduce that from other variables whose values depend on the one
3932
you are interested in, or recompile without optimizations.
3933
 
3934
   Most programs have a standard user entry point--a place where system
3935
libraries and startup code transition into user code.  For C this is
3936
`main'(1).  When GDB finds the entry function in a backtrace it will
3937
terminate the backtrace, to avoid tracing into highly system-specific
3938
(and generally uninteresting) code.
3939
 
3940
   If you need to examine the startup code, or limit the number of
3941
levels in a backtrace, you can change this behavior:
3942
 
3943
`set backtrace past-main'
3944
`set backtrace past-main on'
3945
     Backtraces will continue past the user entry point.
3946
 
3947
`set backtrace past-main off'
3948
     Backtraces will stop when they encounter the user entry point.
3949
     This is the default.
3950
 
3951
`show backtrace past-main'
3952
     Display the current user entry point backtrace policy.
3953
 
3954
`set backtrace past-entry'
3955
`set backtrace past-entry on'
3956
     Backtraces will continue past the internal entry point of an
3957
     application.  This entry point is encoded by the linker when the
3958
     application is built, and is likely before the user entry point
3959
     `main' (or equivalent) is called.
3960
 
3961
`set backtrace past-entry off'
3962
     Backtraces will stop when they encounter the internal entry point
3963
     of an application.  This is the default.
3964
 
3965
`show backtrace past-entry'
3966
     Display the current internal entry point backtrace policy.
3967
 
3968
`set backtrace limit N'
3969
`set backtrace limit 0'
3970
     Limit the backtrace to N levels.  A value of zero means unlimited.
3971
 
3972
`show backtrace limit'
3973
     Display the current limit on backtrace levels.
3974
 
3975
   ---------- Footnotes ----------
3976
 
3977
   (1) Note that embedded programs (the so-called "free-standing"
3978
environment) are not required to have a `main' function as the entry
3979
point.  They could even have multiple entry points.
3980
 
3981

3982
File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
3983
 
3984
6.3 Selecting a Frame
3985
=====================
3986
 
3987
Most commands for examining the stack and other data in your program
3988
work on whichever stack frame is selected at the moment.  Here are the
3989
commands for selecting a stack frame; all of them finish by printing a
3990
brief description of the stack frame just selected.
3991
 
3992
`frame N'
3993
`f N'
3994
     Select frame number N.  Recall that frame zero is the innermost
3995
     (currently executing) frame, frame one is the frame that called the
3996
     innermost one, and so on.  The highest-numbered frame is the one
3997
     for `main'.
3998
 
3999
`frame ADDR'
4000
`f ADDR'
4001
     Select the frame at address ADDR.  This is useful mainly if the
4002
     chaining of stack frames has been damaged by a bug, making it
4003
     impossible for GDB to assign numbers properly to all frames.  In
4004
     addition, this can be useful when your program has multiple stacks
4005
     and switches between them.
4006
 
4007
     On the SPARC architecture, `frame' needs two addresses to select
4008
     an arbitrary frame: a frame pointer and a stack pointer.
4009
 
4010
     On the MIPS and Alpha architecture, it needs two addresses: a stack
4011
     pointer and a program counter.
4012
 
4013
     On the 29k architecture, it needs three addresses: a register stack
4014
     pointer, a program counter, and a memory stack pointer.
4015
 
4016
`up N'
4017
     Move N frames up the stack.  For positive numbers N, this advances
4018
     toward the outermost frame, to higher frame numbers, to frames
4019
     that have existed longer.  N defaults to one.
4020
 
4021
`down N'
4022
     Move N frames down the stack.  For positive numbers N, this
4023
     advances toward the innermost frame, to lower frame numbers, to
4024
     frames that were created more recently.  N defaults to one.  You
4025
     may abbreviate `down' as `do'.
4026
 
4027
   All of these commands end by printing two lines of output describing
4028
the frame.  The first line shows the frame number, the function name,
4029
the arguments, and the source file and line number of execution in that
4030
frame.  The second line shows the text of that source line.
4031
 
4032
   For example:
4033
 
4034
     (gdb) up
4035
     #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4036
         at env.c:10
4037
     10              read_input_file (argv[i]);
4038
 
4039
   After such a printout, the `list' command with no arguments prints
4040
ten lines centered on the point of execution in the frame.  You can
4041
also edit the program at the point of execution with your favorite
4042
editing program by typing `edit'.  *Note Printing Source Lines: List,
4043
for details.
4044
 
4045
`up-silently N'
4046
`down-silently N'
4047
     These two commands are variants of `up' and `down', respectively;
4048
     they differ in that they do their work silently, without causing
4049
     display of the new frame.  They are intended primarily for use in
4050
     GDB command scripts, where the output might be unnecessary and
4051
     distracting.
4052
 
4053

4054
File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
4055
 
4056
6.4 Information About a Frame
4057
=============================
4058
 
4059
There are several other commands to print information about the selected
4060
stack frame.
4061
 
4062
`frame'
4063
`f'
4064
     When used without any argument, this command does not change which
4065
     frame is selected, but prints a brief description of the currently
4066
     selected stack frame.  It can be abbreviated `f'.  With an
4067
     argument, this command is used to select a stack frame.  *Note
4068
     Selecting a Frame: Selection.
4069
 
4070
`info frame'
4071
`info f'
4072
     This command prints a verbose description of the selected stack
4073
     frame, including:
4074
 
4075
        * the address of the frame
4076
 
4077
        * the address of the next frame down (called by this frame)
4078
 
4079
        * the address of the next frame up (caller of this frame)
4080
 
4081
        * the language in which the source code corresponding to this
4082
          frame is written
4083
 
4084
        * the address of the frame's arguments
4085
 
4086
        * the address of the frame's local variables
4087
 
4088
        * the program counter saved in it (the address of execution in
4089
          the caller frame)
4090
 
4091
        * which registers were saved in the frame
4092
 
4093
     The verbose description is useful when something has gone wrong
4094
     that has made the stack format fail to fit the usual conventions.
4095
 
4096
`info frame ADDR'
4097
`info f ADDR'
4098
     Print a verbose description of the frame at address ADDR, without
4099
     selecting that frame.  The selected frame remains unchanged by this
4100
     command.  This requires the same kind of address (more than one
4101
     for some architectures) that you specify in the `frame' command.
4102
     *Note Selecting a Frame: Selection.
4103
 
4104
`info args'
4105
     Print the arguments of the selected frame, each on a separate line.
4106
 
4107
`info locals'
4108
     Print the local variables of the selected frame, each on a separate
4109
     line.  These are all variables (declared either static or
4110
     automatic) accessible at the point of execution of the selected
4111
     frame.
4112
 
4113
`info catch'
4114
     Print a list of all the exception handlers that are active in the
4115
     current stack frame at the current point of execution.  To see
4116
     other exception handlers, visit the associated frame (using the
4117
     `up', `down', or `frame' commands); then type `info catch'.  *Note
4118
     Setting Catchpoints: Set Catchpoints.
4119
 
4120
 
4121

4122
File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
4123
 
4124
7 Examining Source Files
4125
************************
4126
 
4127
GDB can print parts of your program's source, since the debugging
4128
information recorded in the program tells GDB what source files were
4129
used to build it.  When your program stops, GDB spontaneously prints
4130
the line where it stopped.  Likewise, when you select a stack frame
4131
(*note Selecting a Frame: Selection.), GDB prints the line where
4132
execution in that frame has stopped.  You can print other portions of
4133
source files by explicit command.
4134
 
4135
   If you use GDB through its GNU Emacs interface, you may prefer to
4136
use Emacs facilities to view source; see *Note Using GDB under GNU
4137
Emacs: Emacs.
4138
 
4139
* Menu:
4140
 
4141
* List::                        Printing source lines
4142
* Specify Location::            How to specify code locations
4143
* Edit::                        Editing source files
4144
* Search::                      Searching source files
4145
* Source Path::                 Specifying source directories
4146
* Machine Code::                Source and machine code
4147
 
4148

4149
File: gdb.info,  Node: List,  Next: Specify Location,  Up: Source
4150
 
4151
7.1 Printing Source Lines
4152
=========================
4153
 
4154
To print lines from a source file, use the `list' command (abbreviated
4155
`l').  By default, ten lines are printed.  There are several ways to
4156
specify what part of the file you want to print; see *Note Specify
4157
Location::, for the full list.
4158
 
4159
   Here are the forms of the `list' command most commonly used:
4160
 
4161
`list LINENUM'
4162
     Print lines centered around line number LINENUM in the current
4163
     source file.
4164
 
4165
`list FUNCTION'
4166
     Print lines centered around the beginning of function FUNCTION.
4167
 
4168
`list'
4169
     Print more lines.  If the last lines printed were printed with a
4170
     `list' command, this prints lines following the last lines
4171
     printed; however, if the last line printed was a solitary line
4172
     printed as part of displaying a stack frame (*note Examining the
4173
     Stack: Stack.), this prints lines centered around that line.
4174
 
4175
`list -'
4176
     Print lines just before the lines last printed.
4177
 
4178
   By default, GDB prints ten source lines with any of these forms of
4179
the `list' command.  You can change this using `set listsize':
4180
 
4181
`set listsize COUNT'
4182
     Make the `list' command display COUNT source lines (unless the
4183
     `list' argument explicitly specifies some other number).
4184
 
4185
`show listsize'
4186
     Display the number of lines that `list' prints.
4187
 
4188
   Repeating a `list' command with  discards the argument, so it
4189
is equivalent to typing just `list'.  This is more useful than listing
4190
the same lines again.  An exception is made for an argument of `-';
4191
that argument is preserved in repetition so that each repetition moves
4192
up in the source file.
4193
 
4194
   In general, the `list' command expects you to supply zero, one or two
4195
"linespecs".  Linespecs specify source lines; there are several ways of
4196
writing them (*note Specify Location::), but the effect is always to
4197
specify some source line.
4198
 
4199
   Here is a complete description of the possible arguments for `list':
4200
 
4201
`list LINESPEC'
4202
     Print lines centered around the line specified by LINESPEC.
4203
 
4204
`list FIRST,LAST'
4205
     Print lines from FIRST to LAST.  Both arguments are linespecs.
4206
     When a `list' command has two linespecs, and the source file of
4207
     the second linespec is omitted, this refers to the same source
4208
     file as the first linespec.
4209
 
4210
`list ,LAST'
4211
     Print lines ending with LAST.
4212
 
4213
`list FIRST,'
4214
     Print lines starting with FIRST.
4215
 
4216
`list +'
4217
     Print lines just after the lines last printed.
4218
 
4219
`list -'
4220
     Print lines just before the lines last printed.
4221
 
4222
`list'
4223
     As described in the preceding table.
4224
 
4225

4226
File: gdb.info,  Node: Specify Location,  Next: Edit,  Prev: List,  Up: Source
4227
 
4228
7.2 Specifying a Location
4229
=========================
4230
 
4231
Several GDB commands accept arguments that specify a location of your
4232
program's code.  Since GDB is a source-level debugger, a location
4233
usually specifies some line in the source code; for that reason,
4234
locations are also known as "linespecs".
4235
 
4236
   Here are all the different ways of specifying a code location that
4237
GDB understands:
4238
 
4239
`LINENUM'
4240
     Specifies the line number LINENUM of the current source file.
4241
 
4242
`-OFFSET'
4243
`+OFFSET'
4244
     Specifies the line OFFSET lines before or after the "current
4245
     line".  For the `list' command, the current line is the last one
4246
     printed; for the breakpoint commands, this is the line at which
4247
     execution stopped in the currently selected "stack frame" (*note
4248
     Frames: Frames, for a description of stack frames.)  When used as
4249
     the second of the two linespecs in a `list' command, this
4250
     specifies the line OFFSET lines up or down from the first linespec.
4251
 
4252
`FILENAME:LINENUM'
4253
     Specifies the line LINENUM in the source file FILENAME.
4254
 
4255
`FUNCTION'
4256
     Specifies the line that begins the body of the function FUNCTION.
4257
     For example, in C, this is the line with the open brace.
4258
 
4259
`FILENAME:FUNCTION'
4260
     Specifies the line that begins the body of the function FUNCTION
4261
     in the file FILENAME.  You only need the file name with a function
4262
     name to avoid ambiguity when there are identically named functions
4263
     in different source files.
4264
 
4265
`*ADDRESS'
4266
     Specifies the program address ADDRESS.  For line-oriented
4267
     commands, such as `list' and `edit', this specifies a source line
4268
     that contains ADDRESS.  For `break' and other breakpoint oriented
4269
     commands, this can be used to set breakpoints in parts of your
4270
     program which do not have debugging information or source files.
4271
 
4272
     Here ADDRESS may be any expression valid in the current working
4273
     language (*note working language: Languages.) that specifies a code
4274
     address.  In addition, as a convenience, GDB extends the semantics
4275
     of expressions used in locations to cover the situations that
4276
     frequently happen during debugging.  Here are the various forms of
4277
     ADDRESS:
4278
 
4279
    `EXPRESSION'
4280
          Any expression valid in the current working language.
4281
 
4282
    `FUNCADDR'
4283
          An address of a function or procedure derived from its name.
4284
          In C, C++, Java, Objective-C, Fortran, minimal, and assembly,
4285
          this is simply the function's name FUNCTION (and actually a
4286
          special case of a valid expression).  In Pascal and Modula-2,
4287
          this is `&FUNCTION'.  In Ada, this is `FUNCTION'Address'
4288
          (although the Pascal form also works).
4289
 
4290
          This form specifies the address of the function's first
4291
          instruction, before the stack frame and arguments have been
4292
          set up.
4293
 
4294
    `'FILENAME'::FUNCADDR'
4295
          Like FUNCADDR above, but also specifies the name of the source
4296
          file explicitly.  This is useful if the name of the function
4297
          does not specify the function unambiguously, e.g., if there
4298
          are several functions with identical names in different
4299
          source files.
4300
 
4301
 
4302

4303
File: gdb.info,  Node: Edit,  Next: Search,  Prev: Specify Location,  Up: Source
4304
 
4305
7.3 Editing Source Files
4306
========================
4307
 
4308
To edit the lines in a source file, use the `edit' command.  The
4309
editing program of your choice is invoked with the current line set to
4310
the active line in the program.  Alternatively, there are several ways
4311
to specify what part of the file you want to print if you want to see
4312
other parts of the program:
4313
 
4314
`edit LOCATION'
4315
     Edit the source file specified by `location'.  Editing starts at
4316
     that LOCATION, e.g., at the specified source line of the specified
4317
     file.  *Note Specify Location::, for all the possible forms of the
4318
     LOCATION argument; here are the forms of the `edit' command most
4319
     commonly used:
4320
 
4321
    `edit NUMBER'
4322
          Edit the current source file with NUMBER as the active line
4323
          number.
4324
 
4325
    `edit FUNCTION'
4326
          Edit the file containing FUNCTION at the beginning of its
4327
          definition.
4328
 
4329
 
4330
7.3.1 Choosing your Editor
4331
--------------------------
4332
 
4333
You can customize GDB to use any editor you want (1).  By default, it
4334
is `/bin/ex', but you can change this by setting the environment
4335
variable `EDITOR' before using GDB.  For example, to configure GDB to
4336
use the `vi' editor, you could use these commands with the `sh' shell:
4337
     EDITOR=/usr/bin/vi
4338
     export EDITOR
4339
     gdb ...
4340
   or in the `csh' shell,
4341
     setenv EDITOR /usr/bin/vi
4342
     gdb ...
4343
 
4344
   ---------- Footnotes ----------
4345
 
4346
   (1) The only restriction is that your editor (say `ex'), recognizes
4347
the following command-line syntax:
4348
     ex +NUMBER file
4349
   The optional numeric value +NUMBER specifies the number of the line
4350
in the file where to start editing.
4351
 
4352

4353
File: gdb.info,  Node: Search,  Next: Source Path,  Prev: Edit,  Up: Source
4354
 
4355
7.4 Searching Source Files
4356
==========================
4357
 
4358
There are two commands for searching through the current source file
4359
for a regular expression.
4360
 
4361
`forward-search REGEXP'
4362
`search REGEXP'
4363
     The command `forward-search REGEXP' checks each line, starting
4364
     with the one following the last line listed, for a match for
4365
     REGEXP.  It lists the line that is found.  You can use the synonym
4366
     `search REGEXP' or abbreviate the command name as `fo'.
4367
 
4368
`reverse-search REGEXP'
4369
     The command `reverse-search REGEXP' checks each line, starting
4370
     with the one before the last line listed and going backward, for a
4371
     match for REGEXP.  It lists the line that is found.  You can
4372
     abbreviate this command as `rev'.
4373
 
4374

4375
File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
4376
 
4377
7.5 Specifying Source Directories
4378
=================================
4379
 
4380
Executable programs sometimes do not record the directories of the
4381
source files from which they were compiled, just the names.  Even when
4382
they do, the directories could be moved between the compilation and
4383
your debugging session.  GDB has a list of directories to search for
4384
source files; this is called the "source path".  Each time GDB wants a
4385
source file, it tries all the directories in the list, in the order
4386
they are present in the list, until it finds a file with the desired
4387
name.
4388
 
4389
   For example, suppose an executable references the file
4390
`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
4391
file is first looked up literally; if this fails,
4392
`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
4393
`/mnt/cross/foo.c' is opened; if this fails, an error message is
4394
printed.  GDB does not look up the parts of the source file name, such
4395
as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
4396
the source path are not searched: if the source path is `/mnt/cross',
4397
and the binary refers to `foo.c', GDB would not find it under
4398
`/mnt/cross/usr/src/foo-1.0/lib'.
4399
 
4400
   Plain file names, relative file names with leading directories, file
4401
names containing dots, etc. are all treated as described above; for
4402
instance, if the source path is `/mnt/cross', and the source file is
4403
recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
4404
`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
4405
 
4406
   Note that the executable search path is _not_ used to locate the
4407
source files.
4408
 
4409
   Whenever you reset or rearrange the source path, GDB clears out any
4410
information it has cached about where source files are found and where
4411
each line is in the file.
4412
 
4413
   When you start GDB, its source path includes only `cdir' and `cwd',
4414
in that order.  To add other directories, use the `directory' command.
4415
 
4416
   The search path is used to find both program source files and GDB
4417
script files (read using the `-command' option and `source' command).
4418
 
4419
   In addition to the source path, GDB provides a set of commands that
4420
manage a list of source path substitution rules.  A "substitution rule"
4421
specifies how to rewrite source directories stored in the program's
4422
debug information in case the sources were moved to a different
4423
directory between compilation and debugging.  A rule is made of two
4424
strings, the first specifying what needs to be rewritten in the path,
4425
and the second specifying how it should be rewritten.  In *Note set
4426
substitute-path::, we name these two parts FROM and TO respectively.
4427
GDB does a simple string replacement of FROM with TO at the start of
4428
the directory part of the source file name, and uses that result
4429
instead of the original file name to look up the sources.
4430
 
4431
   Using the previous example, suppose the `foo-1.0' tree has been
4432
moved from `/usr/src' to `/mnt/cross', then you can tell GDB to replace
4433
`/usr/src' in all source path names with `/mnt/cross'.  The first
4434
lookup will then be `/mnt/cross/foo-1.0/lib/foo.c' in place of the
4435
original location of `/usr/src/foo-1.0/lib/foo.c'.  To define a source
4436
path substitution rule, use the `set substitute-path' command (*note
4437
set substitute-path::).
4438
 
4439
   To avoid unexpected substitution results, a rule is applied only if
4440
the FROM part of the directory name ends at a directory separator.  For
4441
instance, a rule substituting  `/usr/source' into `/mnt/cross' will be
4442
applied to `/usr/source/foo-1.0' but not to `/usr/sourceware/foo-2.0'.
4443
And because the substitution is applied only at the beginning of the
4444
directory name, this rule will not be applied to
4445
`/root/usr/source/baz.c' either.
4446
 
4447
   In many cases, you can achieve the same result using the `directory'
4448
command.  However, `set substitute-path' can be more efficient in the
4449
case where the sources are organized in a complex tree with multiple
4450
subdirectories.  With the `directory' command, you need to add each
4451
subdirectory of your project.  If you moved the entire tree while
4452
preserving its internal organization, then `set substitute-path' allows
4453
you to direct the debugger to all the sources with one single command.
4454
 
4455
   `set substitute-path' is also more than just a shortcut command.
4456
The source path is only used if the file at the original location no
4457
longer exists.  On the other hand, `set substitute-path' modifies the
4458
debugger behavior to look at the rewritten location instead.  So, if
4459
for any reason a source file that is not relevant to your executable is
4460
located at the original location, a substitution rule is the only
4461
method available to point GDB at the new location.
4462
 
4463
`directory DIRNAME ...'
4464
 
4465
`dir DIRNAME ...'
4466
     Add directory DIRNAME to the front of the source path.  Several
4467
     directory names may be given to this command, separated by `:'
4468
     (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
4469
     of absolute file names) or whitespace.  You may specify a
4470
     directory that is already in the source path; this moves it
4471
     forward, so GDB searches it sooner.
4472
 
4473
     You can use the string `$cdir' to refer to the compilation
4474
     directory (if one is recorded), and `$cwd' to refer to the current
4475
     working directory.  `$cwd' is not the same as `.'--the former
4476
     tracks the current working directory as it changes during your GDB
4477
     session, while the latter is immediately expanded to the current
4478
     directory at the time you add an entry to the source path.
4479
 
4480
`directory'
4481
     Reset the source path to its default value (`$cdir:$cwd' on Unix
4482
     systems).  This requires confirmation.
4483
 
4484
`show directories'
4485
     Print the source path: show which directories it contains.
4486
 
4487
`set substitute-path FROM TO'
4488
     Define a source path substitution rule, and add it at the end of
4489
     the current list of existing substitution rules.  If a rule with
4490
     the same FROM was already defined, then the old rule is also
4491
     deleted.
4492
 
4493
     For example, if the file `/foo/bar/baz.c' was moved to
4494
     `/mnt/cross/baz.c', then the command
4495
 
4496
          (gdb) set substitute-path /usr/src /mnt/cross
4497
 
4498
     will tell GDB to replace `/usr/src' with `/mnt/cross', which will
4499
     allow GDB to find the file `baz.c' even though it was moved.
4500
 
4501
     In the case when more than one substitution rule have been defined,
4502
     the rules are evaluated one by one in the order where they have
4503
     been defined.  The first one matching, if any, is selected to
4504
     perform the substitution.
4505
 
4506
     For instance, if we had entered the following commands:
4507
 
4508
          (gdb) set substitute-path /usr/src/include /mnt/include
4509
          (gdb) set substitute-path /usr/src /mnt/src
4510
 
4511
     GDB would then rewrite `/usr/src/include/defs.h' into
4512
     `/mnt/include/defs.h' by using the first rule.  However, it would
4513
     use the second rule to rewrite `/usr/src/lib/foo.c' into
4514
     `/mnt/src/lib/foo.c'.
4515
 
4516
`unset substitute-path [path]'
4517
     If a path is specified, search the current list of substitution
4518
     rules for a rule that would rewrite that path.  Delete that rule
4519
     if found.  A warning is emitted by the debugger if no rule could
4520
     be found.
4521
 
4522
     If no path is specified, then all substitution rules are deleted.
4523
 
4524
`show substitute-path [path]'
4525
     If a path is specified, then print the source path substitution
4526
     rule which would rewrite that path, if any.
4527
 
4528
     If no path is specified, then print all existing source path
4529
     substitution rules.
4530
 
4531
 
4532
   If your source path is cluttered with directories that are no longer
4533
of interest, GDB may sometimes cause confusion by finding the wrong
4534
versions of source.  You can correct the situation as follows:
4535
 
4536
  1. Use `directory' with no argument to reset the source path to its
4537
     default value.
4538
 
4539
  2. Use `directory' with suitable arguments to reinstall the
4540
     directories you want in the source path.  You can add all the
4541
     directories in one command.
4542
 
4543

4544
File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
4545
 
4546
7.6 Source and Machine Code
4547
===========================
4548
 
4549
You can use the command `info line' to map source lines to program
4550
addresses (and vice versa), and the command `disassemble' to display a
4551
range of addresses as machine instructions.  When run under GNU Emacs
4552
mode, the `info line' command causes the arrow to point to the line
4553
specified.  Also, `info line' prints addresses in symbolic form as well
4554
as hex.
4555
 
4556
`info line LINESPEC'
4557
     Print the starting and ending addresses of the compiled code for
4558
     source line LINESPEC.  You can specify source lines in any of the
4559
     ways documented in *Note Specify Location::.
4560
 
4561
   For example, we can use `info line' to discover the location of the
4562
object code for the first line of function `m4_changequote':
4563
 
4564
     (gdb) info line m4_changequote
4565
     Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4566
 
4567
We can also inquire (using `*ADDR' as the form for LINESPEC) what
4568
source line covers a particular address:
4569
     (gdb) info line *0x63ff
4570
     Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4571
 
4572
   After `info line', the default address for the `x' command is
4573
changed to the starting address of the line, so that `x/i' is
4574
sufficient to begin examining the machine code (*note Examining Memory:
4575
Memory.).  Also, this address is saved as the value of the convenience
4576
variable `$_' (*note Convenience Variables: Convenience Vars.).
4577
 
4578
`disassemble'
4579
     This specialized command dumps a range of memory as machine
4580
     instructions.  The default memory range is the function
4581
     surrounding the program counter of the selected frame.  A single
4582
     argument to this command is a program counter value; GDB dumps the
4583
     function surrounding this value.  Two arguments specify a range of
4584
     addresses (first inclusive, second exclusive) to dump.
4585
 
4586
   The following example shows the disassembly of a range of addresses
4587
of HP PA-RISC 2.0 code:
4588
 
4589
     (gdb) disas 0x32c4 0x32e4
4590
     Dump of assembler code from 0x32c4 to 0x32e4:
4591
     0x32c4 :      addil 0,dp
4592
     0x32c8 :      ldw 0x22c(sr0,r1),r26
4593
     0x32cc :      ldil 0x3000,r31
4594
     0x32d0 :      ble 0x3f8(sr4,r31)
4595
     0x32d4 :      ldo 0(r31),rp
4596
     0x32d8 :      addil -0x800,dp
4597
     0x32dc :      ldo 0x588(r1),r26
4598
     0x32e0 :      ldil 0x3000,r31
4599
     End of assembler dump.
4600
 
4601
   Some architectures have more than one commonly-used set of
4602
instruction mnemonics or other syntax.
4603
 
4604
   For programs that were dynamically linked and use shared libraries,
4605
instructions that call functions or branch to locations in the shared
4606
libraries might show a seemingly bogus location--it's actually a
4607
location of the relocation table.  On some architectures, GDB might be
4608
able to resolve these to actual function names.
4609
 
4610
`set disassembly-flavor INSTRUCTION-SET'
4611
     Select the instruction set to use when disassembling the program
4612
     via the `disassemble' or `x/i' commands.
4613
 
4614
     Currently this command is only defined for the Intel x86 family.
4615
     You can set INSTRUCTION-SET to either `intel' or `att'.  The
4616
     default is `att', the AT&T flavor used by default by Unix
4617
     assemblers for x86-based targets.
4618
 
4619
`show disassembly-flavor'
4620
     Show the current setting of the disassembly flavor.
4621
 
4622

4623
File: gdb.info,  Node: Data,  Next: Macros,  Prev: Source,  Up: Top
4624
 
4625
8 Examining Data
4626
****************
4627
 
4628
The usual way to examine data in your program is with the `print'
4629
command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
4630
prints the value of an expression of the language your program is
4631
written in (*note Using GDB with Different Languages: Languages.).
4632
 
4633
`print EXPR'
4634
`print /F EXPR'
4635
     EXPR is an expression (in the source language).  By default the
4636
     value of EXPR is printed in a format appropriate to its data type;
4637
     you can choose a different format by specifying `/F', where F is a
4638
     letter specifying the format; see *Note Output Formats: Output
4639
     Formats.
4640
 
4641
`print'
4642
`print /F'
4643
     If you omit EXPR, GDB displays the last value again (from the
4644
     "value history"; *note Value History: Value History.).  This
4645
     allows you to conveniently inspect the same value in an
4646
     alternative format.
4647
 
4648
   A more low-level way of examining data is with the `x' command.  It
4649
examines data in memory at a specified address and prints it in a
4650
specified format.  *Note Examining Memory: Memory.
4651
 
4652
   If you are interested in information about types, or about how the
4653
fields of a struct or a class are declared, use the `ptype EXP' command
4654
rather than `print'.  *Note Examining the Symbol Table: Symbols.
4655
 
4656
* Menu:
4657
 
4658
* Expressions::                 Expressions
4659
* Variables::                   Program variables
4660
* Arrays::                      Artificial arrays
4661
* Output Formats::              Output formats
4662
* Memory::                      Examining memory
4663
* Auto Display::                Automatic display
4664
* Print Settings::              Print settings
4665
* Value History::               Value history
4666
* Convenience Vars::            Convenience variables
4667
* Registers::                   Registers
4668
* Floating Point Hardware::     Floating point hardware
4669
* Vector Unit::                 Vector Unit
4670
* OS Information::              Auxiliary data provided by operating system
4671
* Memory Region Attributes::    Memory region attributes
4672
* Dump/Restore Files::          Copy between memory and a file
4673
* Core File Generation::        Cause a program dump its core
4674
* Character Sets::              Debugging programs that use a different
4675
                                character set than GDB does
4676
* Caching Remote Data::         Data caching for remote targets
4677
 
4678

4679
File: gdb.info,  Node: Expressions,  Next: Variables,  Up: Data
4680
 
4681
8.1 Expressions
4682
===============
4683
 
4684
`print' and many other GDB commands accept an expression and compute
4685
its value.  Any kind of constant, variable or operator defined by the
4686
programming language you are using is valid in an expression in GDB.
4687
This includes conditional expressions, function calls, casts, and
4688
string constants.  It also includes preprocessor macros, if you
4689
compiled your program to include this information; see *Note
4690
Compilation::.
4691
 
4692
   GDB supports array constants in expressions input by the user.  The
4693
syntax is {ELEMENT, ELEMENT...}.  For example, you can use the command
4694
`print {1, 2, 3}' to build up an array in memory that is `malloc'ed in
4695
the target program.
4696
 
4697
   Because C is so widespread, most of the expressions shown in
4698
examples in this manual are in C.  *Note Using GDB with Different
4699
Languages: Languages, for information on how to use expressions in other
4700
languages.
4701
 
4702
   In this section, we discuss operators that you can use in GDB
4703
expressions regardless of your programming language.
4704
 
4705
   Casts are supported in all languages, not just in C, because it is so
4706
useful to cast a number into a pointer in order to examine a structure
4707
at that address in memory.
4708
 
4709
   GDB supports these operators, in addition to those common to
4710
programming languages:
4711
 
4712
`@'
4713
     `@' is a binary operator for treating parts of memory as arrays.
4714
     *Note Artificial Arrays: Arrays, for more information.
4715
 
4716
`::'
4717
     `::' allows you to specify a variable in terms of the file or
4718
     function where it is defined.  *Note Program Variables: Variables.
4719
 
4720
`{TYPE} ADDR'
4721
     Refers to an object of type TYPE stored at address ADDR in memory.
4722
     ADDR may be any expression whose value is an integer or pointer
4723
     (but parentheses are required around binary operators, just as in
4724
     a cast).  This construct is allowed regardless of what kind of
4725
     data is normally supposed to reside at ADDR.
4726
 
4727

4728
File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
4729
 
4730
8.2 Program Variables
4731
=====================
4732
 
4733
The most common kind of expression to use is the name of a variable in
4734
your program.
4735
 
4736
   Variables in expressions are understood in the selected stack frame
4737
(*note Selecting a Frame: Selection.); they must be either:
4738
 
4739
   * global (or file-static)
4740
 
4741
or
4742
 
4743
   * visible according to the scope rules of the programming language
4744
     from the point of execution in that frame
4745
 
4746
This means that in the function
4747
 
4748
     foo (a)
4749
          int a;
4750
     {
4751
       bar (a);
4752
       {
4753
         int b = test ();
4754
         bar (b);
4755
       }
4756
     }
4757
 
4758
you can examine and use the variable `a' whenever your program is
4759
executing within the function `foo', but you can only use or examine
4760
the variable `b' while your program is executing inside the block where
4761
`b' is declared.
4762
 
4763
   There is an exception: you can refer to a variable or function whose
4764
scope is a single source file even if the current execution point is not
4765
in this file.  But it is possible to have more than one such variable or
4766
function with the same name (in different source files).  If that
4767
happens, referring to that name has unpredictable effects.  If you wish,
4768
you can specify a static variable in a particular function or file,
4769
using the colon-colon (`::') notation:
4770
 
4771
     FILE::VARIABLE
4772
     FUNCTION::VARIABLE
4773
 
4774
Here FILE or FUNCTION is the name of the context for the static
4775
VARIABLE.  In the case of file names, you can use quotes to make sure
4776
GDB parses the file name as a single word--for example, to print a
4777
global value of `x' defined in `f2.c':
4778
 
4779
     (gdb) p 'f2.c'::x
4780
 
4781
   This use of `::' is very rarely in conflict with the very similar
4782
use of the same notation in C++.  GDB also supports use of the C++
4783
scope resolution operator in GDB expressions.
4784
 
4785
     _Warning:_ Occasionally, a local variable may appear to have the
4786
     wrong value at certain points in a function--just after entry to a
4787
     new scope, and just before exit.
4788
   You may see this problem when you are stepping by machine
4789
instructions.  This is because, on most machines, it takes more than
4790
one instruction to set up a stack frame (including local variable
4791
definitions); if you are stepping by machine instructions, variables
4792
may appear to have the wrong values until the stack frame is completely
4793
built.  On exit, it usually also takes more than one machine
4794
instruction to destroy a stack frame; after you begin stepping through
4795
that group of instructions, local variable definitions may be gone.
4796
 
4797
   This may also happen when the compiler does significant
4798
optimizations.  To be sure of always seeing accurate values, turn off
4799
all optimization when compiling.
4800
 
4801
   Another possible effect of compiler optimizations is to optimize
4802
unused variables out of existence, or assign variables to registers (as
4803
opposed to memory addresses).  Depending on the support for such cases
4804
offered by the debug info format used by the compiler, GDB might not be
4805
able to display values for such local variables.  If that happens, GDB
4806
will print a message like this:
4807
 
4808
     No symbol "foo" in current context.
4809
 
4810
   To solve such problems, either recompile without optimizations, or
4811
use a different debug info format, if the compiler supports several such
4812
formats.  For example, GCC, the GNU C/C++ compiler, usually supports
4813
the `-gstabs+' option.  `-gstabs+' produces debug info in a format that
4814
is superior to formats such as COFF.  You may be able to use DWARF 2
4815
(`-gdwarf-2'), which is also an effective form for debug info.  *Note
4816
Options for Debugging Your Program or GCC: (gcc.info)Debugging Options.
4817
*Note C and C++: C, for more information about debug info formats that
4818
are best suited to C++ programs.
4819
 
4820
   If you ask to print an object whose contents are unknown to GDB,
4821
e.g., because its data type is not completely specified by the debug
4822
information, GDB will say `'.  *Note incomplete type:
4823
Symbols, for more about this.
4824
 
4825
   Strings are identified as arrays of `char' values without specified
4826
signedness.  Arrays of either `signed char' or `unsigned char' get
4827
printed as arrays of 1 byte sized integers.  `-fsigned-char' or
4828
`-funsigned-char' GCC options have no effect as GDB defines literal
4829
string type `"char"' as `char' without a sign.  For program code
4830
 
4831
     char var0[] = "A";
4832
     signed char var1[] = "A";
4833
 
4834
   You get during debugging
4835
     (gdb) print var0
4836
     $1 = "A"
4837
     (gdb) print var1
4838
     $2 = {65 'A', 0 '\0'}
4839
 
4840

4841
File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
4842
 
4843
8.3 Artificial Arrays
4844
=====================
4845
 
4846
It is often useful to print out several successive objects of the same
4847
type in memory; a section of an array, or an array of dynamically
4848
determined size for which only a pointer exists in the program.
4849
 
4850
   You can do this by referring to a contiguous span of memory as an
4851
"artificial array", using the binary operator `@'.  The left operand of
4852
`@' should be the first element of the desired array and be an
4853
individual object.  The right operand should be the desired length of
4854
the array.  The result is an array value whose elements are all of the
4855
type of the left argument.  The first element is actually the left
4856
argument; the second element comes from bytes of memory immediately
4857
following those that hold the first element, and so on.  Here is an
4858
example.  If a program says
4859
 
4860
     int *array = (int *) malloc (len * sizeof (int));
4861
 
4862
you can print the contents of `array' with
4863
 
4864
     p *array@len
4865
 
4866
   The left operand of `@' must reside in memory.  Array values made
4867
with `@' in this way behave just like other arrays in terms of
4868
subscripting, and are coerced to pointers when used in expressions.
4869
Artificial arrays most often appear in expressions via the value history
4870
(*note Value History: Value History.), after printing one out.
4871
 
4872
   Another way to create an artificial array is to use a cast.  This
4873
re-interprets a value as if it were an array.  The value need not be in
4874
memory:
4875
     (gdb) p/x (short[2])0x12345678
4876
     $1 = {0x1234, 0x5678}
4877
 
4878
   As a convenience, if you leave the array length out (as in
4879
`(TYPE[])VALUE') GDB calculates the size to fill the value (as
4880
`sizeof(VALUE)/sizeof(TYPE)':
4881
     (gdb) p/x (short[])0x12345678
4882
     $2 = {0x1234, 0x5678}
4883
 
4884
   Sometimes the artificial array mechanism is not quite enough; in
4885
moderately complex data structures, the elements of interest may not
4886
actually be adjacent--for example, if you are interested in the values
4887
of pointers in an array.  One useful work-around in this situation is
4888
to use a convenience variable (*note Convenience Variables: Convenience
4889
Vars.) as a counter in an expression that prints the first interesting
4890
value, and then repeat that expression via .  For instance,
4891
suppose you have an array `dtab' of pointers to structures, and you are
4892
interested in the values of a field `fv' in each structure.  Here is an
4893
example of what you might type:
4894
 
4895
     set $i = 0
4896
     p dtab[$i++]->fv
4897
     
4898
     
4899
     ...
4900
 
4901

4902
File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
4903
 
4904
8.4 Output Formats
4905
==================
4906
 
4907
By default, GDB prints a value according to its data type.  Sometimes
4908
this is not what you want.  For example, you might want to print a
4909
number in hex, or a pointer in decimal.  Or you might want to view data
4910
in memory at a certain address as a character string or as an
4911
instruction.  To do these things, specify an "output format" when you
4912
print a value.
4913
 
4914
   The simplest use of output formats is to say how to print a value
4915
already computed.  This is done by starting the arguments of the
4916
`print' command with a slash and a format letter.  The format letters
4917
supported are:
4918
 
4919
`x'
4920
     Regard the bits of the value as an integer, and print the integer
4921
     in hexadecimal.
4922
 
4923
`d'
4924
     Print as integer in signed decimal.
4925
 
4926
`u'
4927
     Print as integer in unsigned decimal.
4928
 
4929
`o'
4930
     Print as integer in octal.
4931
 
4932
`t'
4933
     Print as integer in binary.  The letter `t' stands for "two".  (1)
4934
 
4935
`a'
4936
     Print as an address, both absolute in hexadecimal and as an offset
4937
     from the nearest preceding symbol.  You can use this format used
4938
     to discover where (in what function) an unknown address is located:
4939
 
4940
          (gdb) p/a 0x54320
4941
          $3 = 0x54320 <_initialize_vx+396>
4942
 
4943
     The command `info symbol 0x54320' yields similar results.  *Note
4944
     info symbol: Symbols.
4945
 
4946
`c'
4947
     Regard as an integer and print it as a character constant.  This
4948
     prints both the numerical value and its character representation.
4949
     The character representation is replaced with the octal escape
4950
     `\nnn' for characters outside the 7-bit ASCII range.
4951
 
4952
     Without this format, GDB displays `char', `unsigned char', and
4953
     `signed char' data as character constants.  Single-byte members of
4954
     vectors are displayed as integer data.
4955
 
4956
`f'
4957
     Regard the bits of the value as a floating point number and print
4958
     using typical floating point syntax.
4959
 
4960
`s'
4961
     Regard as a string, if possible.  With this format, pointers to
4962
     single-byte data are displayed as null-terminated strings and
4963
     arrays of single-byte data are displayed as fixed-length strings.
4964
     Other values are displayed in their natural types.
4965
 
4966
     Without this format, GDB displays pointers to and arrays of
4967
     `char', `unsigned char', and `signed char' as strings.
4968
     Single-byte members of a vector are displayed as an integer array.
4969
 
4970
   For example, to print the program counter in hex (*note
4971
Registers::), type
4972
 
4973
     p/x $pc
4974
 
4975
Note that no space is required before the slash; this is because command
4976
names in GDB cannot contain a slash.
4977
 
4978
   To reprint the last value in the value history with a different
4979
format, you can use the `print' command with just a format and no
4980
expression.  For example, `p/x' reprints the last value in hex.
4981
 
4982
   ---------- Footnotes ----------
4983
 
4984
   (1) `b' cannot be used because these format letters are also used
4985
with the `x' command, where `b' stands for "byte"; see *Note Examining
4986
Memory: Memory.
4987
 
4988

4989
File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
4990
 
4991
8.5 Examining Memory
4992
====================
4993
 
4994
You can use the command `x' (for "examine") to examine memory in any of
4995
several formats, independently of your program's data types.
4996
 
4997
`x/NFU ADDR'
4998
`x ADDR'
4999
`x'
5000
     Use the `x' command to examine memory.
5001
 
5002
   N, F, and U are all optional parameters that specify how much memory
5003
to display and how to format it; ADDR is an expression giving the
5004
address where you want to start displaying memory.  If you use defaults
5005
for NFU, you need not type the slash `/'.  Several commands set
5006
convenient defaults for ADDR.
5007
 
5008
N, the repeat count
5009
     The repeat count is a decimal integer; the default is 1.  It
5010
     specifies how much memory (counting by units U) to display.
5011
 
5012
F, the display format
5013
     The display format is one of the formats used by `print' (`x',
5014
     `d', `u', `o', `t', `a', `c', `f', `s'), and in addition `i' (for
5015
     machine instructions).  The default is `x' (hexadecimal)
5016
     initially.  The default changes each time you use either `x' or
5017
     `print'.
5018
 
5019
U, the unit size
5020
     The unit size is any of
5021
 
5022
    `b'
5023
          Bytes.
5024
 
5025
    `h'
5026
          Halfwords (two bytes).
5027
 
5028
    `w'
5029
          Words (four bytes).  This is the initial default.
5030
 
5031
    `g'
5032
          Giant words (eight bytes).
5033
 
5034
     Each time you specify a unit size with `x', that size becomes the
5035
     default unit the next time you use `x'.  (For the `s' and `i'
5036
     formats, the unit size is ignored and is normally not written.)
5037
 
5038
ADDR, starting display address
5039
     ADDR is the address where you want GDB to begin displaying memory.
5040
     The expression need not have a pointer value (though it may); it
5041
     is always interpreted as an integer address of a byte of memory.
5042
     *Note Expressions: Expressions, for more information on
5043
     expressions.  The default for ADDR is usually just after the last
5044
     address examined--but several other commands also set the default
5045
     address: `info breakpoints' (to the address of the last breakpoint
5046
     listed), `info line' (to the starting address of a line), and
5047
     `print' (if you use it to display a value from memory).
5048
 
5049
   For example, `x/3uh 0x54320' is a request to display three halfwords
5050
(`h') of memory, formatted as unsigned decimal integers (`u'), starting
5051
at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
5052
memory above the stack pointer (here, `$sp'; *note Registers:
5053
Registers.) in hexadecimal (`x').
5054
 
5055
   Since the letters indicating unit sizes are all distinct from the
5056
letters specifying output formats, you do not have to remember whether
5057
unit size or format comes first; either order works.  The output
5058
specifications `4xw' and `4wx' mean exactly the same thing.  (However,
5059
the count N must come first; `wx4' does not work.)
5060
 
5061
   Even though the unit size U is ignored for the formats `s' and `i',
5062
you might still want to use a count N; for example, `3i' specifies that
5063
you want to see three machine instructions, including any operands.
5064
For convenience, especially when used with the `display' command, the
5065
`i' format also prints branch delay slot instructions, if any, beyond
5066
the count specified, which immediately follow the last instruction that
5067
is within the count.  The command `disassemble' gives an alternative
5068
way of inspecting machine instructions; see *Note Source and Machine
5069
Code: Machine Code.
5070
 
5071
   All the defaults for the arguments to `x' are designed to make it
5072
easy to continue scanning memory with minimal specifications each time
5073
you use `x'.  For example, after you have inspected three machine
5074
instructions with `x/3i ADDR', you can inspect the next seven with just
5075
`x/7'.  If you use  to repeat the `x' command, the repeat count N
5076
is used again; the other arguments default as for successive uses of
5077
`x'.
5078
 
5079
   The addresses and contents printed by the `x' command are not saved
5080
in the value history because there is often too much of them and they
5081
would get in the way.  Instead, GDB makes these values available for
5082
subsequent use in expressions as values of the convenience variables
5083
`$_' and `$__'.  After an `x' command, the last address examined is
5084
available for use in expressions in the convenience variable `$_'.  The
5085
contents of that address, as examined, are available in the convenience
5086
variable `$__'.
5087
 
5088
   If the `x' command has a repeat count, the address and contents saved
5089
are from the last memory unit printed; this is not the same as the last
5090
address printed if several units were printed on the last line of
5091
output.
5092
 
5093
   When you are debugging a program running on a remote target machine
5094
(*note Remote Debugging::), you may wish to verify the program's image
5095
in the remote machine's memory against the executable file you
5096
downloaded to the target.  The `compare-sections' command is provided
5097
for such situations.
5098
 
5099
`compare-sections [SECTION-NAME]'
5100
     Compare the data of a loadable section SECTION-NAME in the
5101
     executable file of the program being debugged with the same
5102
     section in the remote machine's memory, and report any mismatches.
5103
     With no arguments, compares all loadable sections.  This command's
5104
     availability depends on the target's support for the `"qCRC"'
5105
     remote request.
5106
 
5107

5108
File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
5109
 
5110
8.6 Automatic Display
5111
=====================
5112
 
5113
If you find that you want to print the value of an expression frequently
5114
(to see how it changes), you might want to add it to the "automatic
5115
display list" so that GDB prints its value each time your program stops.
5116
Each expression added to the list is given a number to identify it; to
5117
remove an expression from the list, you specify that number.  The
5118
automatic display looks like this:
5119
 
5120
     2: foo = 38
5121
     3: bar[5] = (struct hack *) 0x3804
5122
 
5123
This display shows item numbers, expressions and their current values.
5124
As with displays you request manually using `x' or `print', you can
5125
specify the output format you prefer; in fact, `display' decides
5126
whether to use `print' or `x' depending your format specification--it
5127
uses `x' if you specify either the `i' or `s' format, or a unit size;
5128
otherwise it uses `print'.
5129
 
5130
`display EXPR'
5131
     Add the expression EXPR to the list of expressions to display each
5132
     time your program stops.  *Note Expressions: Expressions.
5133
 
5134
     `display' does not repeat if you press  again after using it.
5135
 
5136
`display/FMT EXPR'
5137
     For FMT specifying only a display format and not a size or count,
5138
     add the expression EXPR to the auto-display list but arrange to
5139
     display it each time in the specified format FMT.  *Note Output
5140
     Formats: Output Formats.
5141
 
5142
`display/FMT ADDR'
5143
     For FMT `i' or `s', or including a unit-size or a number of units,
5144
     add the expression ADDR as a memory address to be examined each
5145
     time your program stops.  Examining means in effect doing `x/FMT
5146
     ADDR'.  *Note Examining Memory: Memory.
5147
 
5148
   For example, `display/i $pc' can be helpful, to see the machine
5149
instruction about to be executed each time execution stops (`$pc' is a
5150
common name for the program counter; *note Registers: Registers.).
5151
 
5152
`undisplay DNUMS...'
5153
`delete display DNUMS...'
5154
     Remove item numbers DNUMS from the list of expressions to display.
5155
 
5156
     `undisplay' does not repeat if you press  after using it.
5157
     (Otherwise you would just get the error `No display number ...'.)
5158
 
5159
`disable display DNUMS...'
5160
     Disable the display of item numbers DNUMS.  A disabled display
5161
     item is not printed automatically, but is not forgotten.  It may be
5162
     enabled again later.
5163
 
5164
`enable display DNUMS...'
5165
     Enable display of item numbers DNUMS.  It becomes effective once
5166
     again in auto display of its expression, until you specify
5167
     otherwise.
5168
 
5169
`display'
5170
     Display the current values of the expressions on the list, just as
5171
     is done when your program stops.
5172
 
5173
`info display'
5174
     Print the list of expressions previously set up to display
5175
     automatically, each one with its item number, but without showing
5176
     the values.  This includes disabled expressions, which are marked
5177
     as such.  It also includes expressions which would not be
5178
     displayed right now because they refer to automatic variables not
5179
     currently available.
5180
 
5181
   If a display expression refers to local variables, then it does not
5182
make sense outside the lexical context for which it was set up.  Such an
5183
expression is disabled when execution enters a context where one of its
5184
variables is not defined.  For example, if you give the command
5185
`display last_char' while inside a function with an argument
5186
`last_char', GDB displays this argument while your program continues to
5187
stop inside that function.  When it stops elsewhere--where there is no
5188
variable `last_char'--the display is disabled automatically.  The next
5189
time your program stops where `last_char' is meaningful, you can enable
5190
the display expression once again.
5191
 
5192

5193
File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
5194
 
5195
8.7 Print Settings
5196
==================
5197
 
5198
GDB provides the following ways to control how arrays, structures, and
5199
symbols are printed.
5200
 
5201
These settings are useful for debugging programs in any language:
5202
 
5203
`set print address'
5204
`set print address on'
5205
     GDB prints memory addresses showing the location of stack traces,
5206
     structure values, pointer values, breakpoints, and so forth, even
5207
     when it also displays the contents of those addresses.  The default
5208
     is `on'.  For example, this is what a stack frame display looks
5209
     like with `set print address on':
5210
 
5211
          (gdb) f
5212
          #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5213
              at input.c:530
5214
          530         if (lquote != def_lquote)
5215
 
5216
`set print address off'
5217
     Do not print addresses when displaying their contents.  For
5218
     example, this is the same stack frame displayed with `set print
5219
     address off':
5220
 
5221
          (gdb) set print addr off
5222
          (gdb) f
5223
          #0  set_quotes (lq="<<", rq=">>") at input.c:530
5224
          530         if (lquote != def_lquote)
5225
 
5226
     You can use `set print address off' to eliminate all machine
5227
     dependent displays from the GDB interface.  For example, with
5228
     `print address off', you should get the same text for backtraces on
5229
     all machines--whether or not they involve pointer arguments.
5230
 
5231
`show print address'
5232
     Show whether or not addresses are to be printed.
5233
 
5234
   When GDB prints a symbolic address, it normally prints the closest
5235
earlier symbol plus an offset.  If that symbol does not uniquely
5236
identify the address (for example, it is a name whose scope is a single
5237
source file), you may need to clarify.  One way to do this is with
5238
`info line', for example `info line *0x4537'.  Alternately, you can set
5239
GDB to print the source file and line number when it prints a symbolic
5240
address:
5241
 
5242
`set print symbol-filename on'
5243
     Tell GDB to print the source file name and line number of a symbol
5244
     in the symbolic form of an address.
5245
 
5246
`set print symbol-filename off'
5247
     Do not print source file name and line number of a symbol.  This
5248
     is the default.
5249
 
5250
`show print symbol-filename'
5251
     Show whether or not GDB will print the source file name and line
5252
     number of a symbol in the symbolic form of an address.
5253
 
5254
   Another situation where it is helpful to show symbol filenames and
5255
line numbers is when disassembling code; GDB shows you the line number
5256
and source file that corresponds to each instruction.
5257
 
5258
   Also, you may wish to see the symbolic form only if the address being
5259
printed is reasonably close to the closest earlier symbol:
5260
 
5261
`set print max-symbolic-offset MAX-OFFSET'
5262
     Tell GDB to only display the symbolic form of an address if the
5263
     offset between the closest earlier symbol and the address is less
5264
     than MAX-OFFSET.  The default is 0, which tells GDB to always
5265
     print the symbolic form of an address if any symbol precedes it.
5266
 
5267
`show print max-symbolic-offset'
5268
     Ask how large the maximum offset is that GDB prints in a symbolic
5269
     address.
5270
 
5271
   If you have a pointer and you are not sure where it points, try `set
5272
print symbol-filename on'.  Then you can determine the name and source
5273
file location of the variable where it points, using `p/a POINTER'.
5274
This interprets the address in symbolic form.  For example, here GDB
5275
shows that a variable `ptt' points at another variable `t', defined in
5276
`hi2.c':
5277
 
5278
     (gdb) set print symbol-filename on
5279
     (gdb) p/a ptt
5280
     $4 = 0xe008 
5281
 
5282
     _Warning:_ For pointers that point to a local variable, `p/a' does
5283
     not show the symbol name and filename of the referent, even with
5284
     the appropriate `set print' options turned on.
5285
 
5286
   Other settings control how different kinds of objects are printed:
5287
 
5288
`set print array'
5289
`set print array on'
5290
     Pretty print arrays.  This format is more convenient to read, but
5291
     uses more space.  The default is off.
5292
 
5293
`set print array off'
5294
     Return to compressed format for arrays.
5295
 
5296
`show print array'
5297
     Show whether compressed or pretty format is selected for displaying
5298
     arrays.
5299
 
5300
`set print array-indexes'
5301
`set print array-indexes on'
5302
     Print the index of each element when displaying arrays.  May be
5303
     more convenient to locate a given element in the array or quickly
5304
     find the index of a given element in that printed array.  The
5305
     default is off.
5306
 
5307
`set print array-indexes off'
5308
     Stop printing element indexes when displaying arrays.
5309
 
5310
`show print array-indexes'
5311
     Show whether the index of each element is printed when displaying
5312
     arrays.
5313
 
5314
`set print elements NUMBER-OF-ELEMENTS'
5315
     Set a limit on how many elements of an array GDB will print.  If
5316
     GDB is printing a large array, it stops printing after it has
5317
     printed the number of elements set by the `set print elements'
5318
     command.  This limit also applies to the display of strings.  When
5319
     GDB starts, this limit is set to 200.  Setting  NUMBER-OF-ELEMENTS
5320
     to zero means that the printing is unlimited.
5321
 
5322
`show print elements'
5323
     Display the number of elements of a large array that GDB will
5324
     print.  If the number is 0, then the printing is unlimited.
5325
 
5326
`set print frame-arguments VALUE'
5327
     This command allows to control how the values of arguments are
5328
     printed when the debugger prints a frame (*note Frames::).  The
5329
     possible values are:
5330
 
5331
    `all'
5332
          The values of all arguments are printed.  This is the default.
5333
 
5334
    `scalars'
5335
          Print the value of an argument only if it is a scalar.  The
5336
          value of more complex arguments such as arrays, structures,
5337
          unions, etc, is replaced by `...'.  Here is an example where
5338
          only scalar arguments are shown:
5339
 
5340
               #1  0x08048361 in call_me (i=3, s=..., ss=0xbf8d508c, u=..., e=green)
5341
                 at frame-args.c:23
5342
 
5343
    `none'
5344
          None of the argument values are printed.  Instead, the value
5345
          of each argument is replaced by `...'.  In this case, the
5346
          example above now becomes:
5347
 
5348
               #1  0x08048361 in call_me (i=..., s=..., ss=..., u=..., e=...)
5349
                 at frame-args.c:23
5350
 
5351
     By default, all argument values are always printed.  But this
5352
     command can be useful in several cases.  For instance, it can be
5353
     used to reduce the amount of information printed in each frame,
5354
     making the backtrace more readable.  Also, this command can be
5355
     used to improve performance when displaying Ada frames, because
5356
     the computation of large arguments can sometimes be CPU-intensive,
5357
     especiallly in large applications.  Setting `print
5358
     frame-arguments' to `scalars' or `none' avoids this computation,
5359
     thus speeding up the display of each Ada frame.
5360
 
5361
`show print frame-arguments'
5362
     Show how the value of arguments should be displayed when printing
5363
     a frame.
5364
 
5365
`set print repeats'
5366
     Set the threshold for suppressing display of repeated array
5367
     elements.  When the number of consecutive identical elements of an
5368
     array exceeds the threshold, GDB prints the string `"
5369
     times>"', where N is the number of identical repetitions, instead
5370
     of displaying the identical elements themselves.  Setting the
5371
     threshold to zero will cause all elements to be individually
5372
     printed.  The default threshold is 10.
5373
 
5374
`show print repeats'
5375
     Display the current threshold for printing repeated identical
5376
     elements.
5377
 
5378
`set print null-stop'
5379
     Cause GDB to stop printing the characters of an array when the
5380
     first NULL is encountered.  This is useful when large arrays
5381
     actually contain only short strings.  The default is off.
5382
 
5383
`show print null-stop'
5384
     Show whether GDB stops printing an array on the first NULL
5385
     character.
5386
 
5387
`set print pretty on'
5388
     Cause GDB to print structures in an indented format with one member
5389
     per line, like this:
5390
 
5391
          $1 = {
5392
            next = 0x0,
5393
            flags = {
5394
              sweet = 1,
5395
              sour = 1
5396
            },
5397
            meat = 0x54 "Pork"
5398
          }
5399
 
5400
`set print pretty off'
5401
     Cause GDB to print structures in a compact format, like this:
5402
 
5403
          $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
5404
          meat = 0x54 "Pork"}
5405
 
5406
     This is the default format.
5407
 
5408
`show print pretty'
5409
     Show which format GDB is using to print structures.
5410
 
5411
`set print sevenbit-strings on'
5412
     Print using only seven-bit characters; if this option is set, GDB
5413
     displays any eight-bit characters (in strings or character values)
5414
     using the notation `\'NNN.  This setting is best if you are
5415
     working in English (ASCII) and you use the high-order bit of
5416
     characters as a marker or "meta" bit.
5417
 
5418
`set print sevenbit-strings off'
5419
     Print full eight-bit characters.  This allows the use of more
5420
     international character sets, and is the default.
5421
 
5422
`show print sevenbit-strings'
5423
     Show whether or not GDB is printing only seven-bit characters.
5424
 
5425
`set print union on'
5426
     Tell GDB to print unions which are contained in structures and
5427
     other unions.  This is the default setting.
5428
 
5429
`set print union off'
5430
     Tell GDB not to print unions which are contained in structures and
5431
     other unions.  GDB will print `"{...}"' instead.
5432
 
5433
`show print union'
5434
     Ask GDB whether or not it will print unions which are contained in
5435
     structures and other unions.
5436
 
5437
     For example, given the declarations
5438
 
5439
          typedef enum {Tree, Bug} Species;
5440
          typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
5441
          typedef enum {Caterpillar, Cocoon, Butterfly}
5442
                        Bug_forms;
5443
 
5444
          struct thing {
5445
            Species it;
5446
            union {
5447
              Tree_forms tree;
5448
              Bug_forms bug;
5449
            } form;
5450
          };
5451
 
5452
          struct thing foo = {Tree, {Acorn}};
5453
 
5454
     with `set print union on' in effect `p foo' would print
5455
 
5456
          $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
5457
 
5458
     and with `set print union off' in effect it would print
5459
 
5460
          $1 = {it = Tree, form = {...}}
5461
 
5462
     `set print union' affects programs written in C-like languages and
5463
     in Pascal.
5464
 
5465
These settings are of interest when debugging C++ programs:
5466
 
5467
`set print demangle'
5468
`set print demangle on'
5469
     Print C++ names in their source form rather than in the encoded
5470
     ("mangled") form passed to the assembler and linker for type-safe
5471
     linkage.  The default is on.
5472
 
5473
`show print demangle'
5474
     Show whether C++ names are printed in mangled or demangled form.
5475
 
5476
`set print asm-demangle'
5477
`set print asm-demangle on'
5478
     Print C++ names in their source form rather than their mangled
5479
     form, even in assembler code printouts such as instruction
5480
     disassemblies.  The default is off.
5481
 
5482
`show print asm-demangle'
5483
     Show whether C++ names in assembly listings are printed in mangled
5484
     or demangled form.
5485
 
5486
`set demangle-style STYLE'
5487
     Choose among several encoding schemes used by different compilers
5488
     to represent C++ names.  The choices for STYLE are currently:
5489
 
5490
    `auto'
5491
          Allow GDB to choose a decoding style by inspecting your
5492
          program.
5493
 
5494
    `gnu'
5495
          Decode based on the GNU C++ compiler (`g++') encoding
5496
          algorithm.  This is the default.
5497
 
5498
    `hp'
5499
          Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
5500
 
5501
    `lucid'
5502
          Decode based on the Lucid C++ compiler (`lcc') encoding
5503
          algorithm.
5504
 
5505
    `arm'
5506
          Decode using the algorithm in the `C++ Annotated Reference
5507
          Manual'.  *Warning:* this setting alone is not sufficient to
5508
          allow debugging `cfront'-generated executables.  GDB would
5509
          require further enhancement to permit that.
5510
 
5511
     If you omit STYLE, you will see a list of possible formats.
5512
 
5513
`show demangle-style'
5514
     Display the encoding style currently in use for decoding C++
5515
     symbols.
5516
 
5517
`set print object'
5518
`set print object on'
5519
     When displaying a pointer to an object, identify the _actual_
5520
     (derived) type of the object rather than the _declared_ type, using
5521
     the virtual function table.
5522
 
5523
`set print object off'
5524
     Display only the declared type of objects, without reference to the
5525
     virtual function table.  This is the default setting.
5526
 
5527
`show print object'
5528
     Show whether actual, or declared, object types are displayed.
5529
 
5530
`set print static-members'
5531
`set print static-members on'
5532
     Print static members when displaying a C++ object.  The default is
5533
     on.
5534
 
5535
`set print static-members off'
5536
     Do not print static members when displaying a C++ object.
5537
 
5538
`show print static-members'
5539
     Show whether C++ static members are printed or not.
5540
 
5541
`set print pascal_static-members'
5542
`set print pascal_static-members on'
5543
     Print static members when displaying a Pascal object.  The default
5544
     is on.
5545
 
5546
`set print pascal_static-members off'
5547
     Do not print static members when displaying a Pascal object.
5548
 
5549
`show print pascal_static-members'
5550
     Show whether Pascal static members are printed or not.
5551
 
5552
`set print vtbl'
5553
`set print vtbl on'
5554
     Pretty print C++ virtual function tables.  The default is off.
5555
     (The `vtbl' commands do not work on programs compiled with the HP
5556
     ANSI C++ compiler (`aCC').)
5557
 
5558
`set print vtbl off'
5559
     Do not pretty print C++ virtual function tables.
5560
 
5561
`show print vtbl'
5562
     Show whether C++ virtual function tables are pretty printed, or
5563
     not.
5564
 
5565

5566
File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
5567
 
5568
8.8 Value History
5569
=================
5570
 
5571
Values printed by the `print' command are saved in the GDB "value
5572
history".  This allows you to refer to them in other expressions.
5573
Values are kept until the symbol table is re-read or discarded (for
5574
example with the `file' or `symbol-file' commands).  When the symbol
5575
table changes, the value history is discarded, since the values may
5576
contain pointers back to the types defined in the symbol table.
5577
 
5578
   The values printed are given "history numbers" by which you can
5579
refer to them.  These are successive integers starting with one.
5580
`print' shows you the history number assigned to a value by printing
5581
`$NUM = ' before the value; here NUM is the history number.
5582
 
5583
   To refer to any previous value, use `$' followed by the value's
5584
history number.  The way `print' labels its output is designed to
5585
remind you of this.  Just `$' refers to the most recent value in the
5586
history, and `$$' refers to the value before that.  `$$N' refers to the
5587
Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
5588
equivalent to `$$', and `$$0' is equivalent to `$'.
5589
 
5590
   For example, suppose you have just printed a pointer to a structure
5591
and want to see the contents of the structure.  It suffices to type
5592
 
5593
     p *$
5594
 
5595
   If you have a chain of structures where the component `next' points
5596
to the next one, you can print the contents of the next one with this:
5597
 
5598
     p *$.next
5599
 
5600
You can print successive links in the chain by repeating this
5601
command--which you can do by just typing .
5602
 
5603
   Note that the history records values, not expressions.  If the value
5604
of `x' is 4 and you type these commands:
5605
 
5606
     print x
5607
     set x=5
5608
 
5609
then the value recorded in the value history by the `print' command
5610
remains 4 even though the value of `x' has changed.
5611
 
5612
`show values'
5613
     Print the last ten values in the value history, with their item
5614
     numbers.  This is like `p $$9' repeated ten times, except that
5615
     `show values' does not change the history.
5616
 
5617
`show values N'
5618
     Print ten history values centered on history item number N.
5619
 
5620
`show values +'
5621
     Print ten history values just after the values last printed.  If
5622
     no more values are available, `show values +' produces no display.
5623
 
5624
   Pressing  to repeat `show values N' has exactly the same effect
5625
as `show values +'.
5626
 
5627

5628
File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
5629
 
5630
8.9 Convenience Variables
5631
=========================
5632
 
5633
GDB provides "convenience variables" that you can use within GDB to
5634
hold on to a value and refer to it later.  These variables exist
5635
entirely within GDB; they are not part of your program, and setting a
5636
convenience variable has no direct effect on further execution of your
5637
program.  That is why you can use them freely.
5638
 
5639
   Convenience variables are prefixed with `$'.  Any name preceded by
5640
`$' can be used for a convenience variable, unless it is one of the
5641
predefined machine-specific register names (*note Registers:
5642
Registers.).  (Value history references, in contrast, are _numbers_
5643
preceded by `$'.  *Note Value History: Value History.)
5644
 
5645
   You can save a value in a convenience variable with an assignment
5646
expression, just as you would set a variable in your program.  For
5647
example:
5648
 
5649
     set $foo = *object_ptr
5650
 
5651
would save in `$foo' the value contained in the object pointed to by
5652
`object_ptr'.
5653
 
5654
   Using a convenience variable for the first time creates it, but its
5655
value is `void' until you assign a new value.  You can alter the value
5656
with another assignment at any time.
5657
 
5658
   Convenience variables have no fixed types.  You can assign a
5659
convenience variable any type of value, including structures and
5660
arrays, even if that variable already has a value of a different type.
5661
The convenience variable, when used as an expression, has the type of
5662
its current value.
5663
 
5664
`show convenience'
5665
     Print a list of convenience variables used so far, and their
5666
     values.  Abbreviated `show conv'.
5667
 
5668
`init-if-undefined $VARIABLE = EXPRESSION'
5669
     Set a convenience variable if it has not already been set.  This
5670
     is useful for user-defined commands that keep some state.  It is
5671
     similar, in concept, to using local static variables with
5672
     initializers in C (except that convenience variables are global).
5673
     It can also be used to allow users to override default values used
5674
     in a command script.
5675
 
5676
     If the variable is already defined then the expression is not
5677
     evaluated so any side-effects do not occur.
5678
 
5679
   One of the ways to use a convenience variable is as a counter to be
5680
incremented or a pointer to be advanced.  For example, to print a field
5681
from successive elements of an array of structures:
5682
 
5683
     set $i = 0
5684
     print bar[$i++]->contents
5685
 
5686
Repeat that command by typing .
5687
 
5688
   Some convenience variables are created automatically by GDB and given
5689
values likely to be useful.
5690
 
5691
`$_'
5692
     The variable `$_' is automatically set by the `x' command to the
5693
     last address examined (*note Examining Memory: Memory.).  Other
5694
     commands which provide a default address for `x' to examine also
5695
     set `$_' to that address; these commands include `info line' and
5696
     `info breakpoint'.  The type of `$_' is `void *' except when set
5697
     by the `x' command, in which case it is a pointer to the type of
5698
     `$__'.
5699
 
5700
`$__'
5701
     The variable `$__' is automatically set by the `x' command to the
5702
     value found in the last address examined.  Its type is chosen to
5703
     match the format in which the data was printed.
5704
 
5705
`$_exitcode'
5706
     The variable `$_exitcode' is automatically set to the exit code
5707
     when the program being debugged terminates.
5708
 
5709
   On HP-UX systems, if you refer to a function or variable name that
5710
begins with a dollar sign, GDB searches for a user or system name
5711
first, before it searches for a convenience variable.
5712
 
5713

5714
File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
5715
 
5716
8.10 Registers
5717
==============
5718
 
5719
You can refer to machine register contents, in expressions, as variables
5720
with names starting with `$'.  The names of registers are different for
5721
each machine; use `info registers' to see the names used on your
5722
machine.
5723
 
5724
`info registers'
5725
     Print the names and values of all registers except floating-point
5726
     and vector registers (in the selected stack frame).
5727
 
5728
`info all-registers'
5729
     Print the names and values of all registers, including
5730
     floating-point and vector registers (in the selected stack frame).
5731
 
5732
`info registers REGNAME ...'
5733
     Print the "relativized" value of each specified register REGNAME.
5734
     As discussed in detail below, register values are normally
5735
     relative to the selected stack frame.  REGNAME may be any register
5736
     name valid on the machine you are using, with or without the
5737
     initial `$'.
5738
 
5739
   GDB has four "standard" register names that are available (in
5740
expressions) on most machines--whenever they do not conflict with an
5741
architecture's canonical mnemonics for registers.  The register names
5742
`$pc' and `$sp' are used for the program counter register and the stack
5743
pointer.  `$fp' is used for a register that contains a pointer to the
5744
current stack frame, and `$ps' is used for a register that contains the
5745
processor status.  For example, you could print the program counter in
5746
hex with
5747
 
5748
     p/x $pc
5749
 
5750
or print the instruction to be executed next with
5751
 
5752
     x/i $pc
5753
 
5754
or add four to the stack pointer(1) with
5755
 
5756
     set $sp += 4
5757
 
5758
   Whenever possible, these four standard register names are available
5759
on your machine even though the machine has different canonical
5760
mnemonics, so long as there is no conflict.  The `info registers'
5761
command shows the canonical names.  For example, on the SPARC, `info
5762
registers' displays the processor status register as `$psr' but you can
5763
also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
5764
for the EFLAGS register.
5765
 
5766
   GDB always considers the contents of an ordinary register as an
5767
integer when the register is examined in this way.  Some machines have
5768
special registers which can hold nothing but floating point; these
5769
registers are considered to have floating point values.  There is no way
5770
to refer to the contents of an ordinary register as floating point value
5771
(although you can _print_ it as a floating point value with `print/f
5772
$REGNAME').
5773
 
5774
   Some registers have distinct "raw" and "virtual" data formats.  This
5775
means that the data format in which the register contents are saved by
5776
the operating system is not the same one that your program normally
5777
sees.  For example, the registers of the 68881 floating point
5778
coprocessor are always saved in "extended" (raw) format, but all C
5779
programs expect to work with "double" (virtual) format.  In such cases,
5780
GDB normally works with the virtual format only (the format that makes
5781
sense for your program), but the `info registers' command prints the
5782
data in both formats.
5783
 
5784
   Some machines have special registers whose contents can be
5785
interpreted in several different ways.  For example, modern x86-based
5786
machines have SSE and MMX registers that can hold several values packed
5787
together in several different formats.  GDB refers to such registers in
5788
`struct' notation:
5789
 
5790
     (gdb) print $xmm1
5791
     $1 = {
5792
       v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044},
5793
       v2_double = {9.92129282474342e-303, 2.7585945287983262e-313},
5794
       v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
5795
       v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0},
5796
       v4_int32 = {0, 20657912, 11, 13},
5797
       v2_int64 = {88725056443645952, 55834574859},
5798
       uint128 = 0x0000000d0000000b013b36f800000000
5799
     }
5800
 
5801
To set values of such registers, you need to tell GDB which view of the
5802
register you wish to change, as if you were assigning value to a
5803
`struct' member:
5804
 
5805
      (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
5806
 
5807
   Normally, register values are relative to the selected stack frame
5808
(*note Selecting a Frame: Selection.).  This means that you get the
5809
value that the register would contain if all stack frames farther in
5810
were exited and their saved registers restored.  In order to see the
5811
true contents of hardware registers, you must select the innermost
5812
frame (with `frame 0').
5813
 
5814
   However, GDB must deduce where registers are saved, from the machine
5815
code generated by your compiler.  If some registers are not saved, or if
5816
GDB is unable to locate the saved registers, the selected stack frame
5817
makes no difference.
5818
 
5819
   ---------- Footnotes ----------
5820
 
5821
   (1) This is a way of removing one word from the stack, on machines
5822
where stacks grow downward in memory (most machines, nowadays).  This
5823
assumes that the innermost stack frame is selected; setting `$sp' is
5824
not allowed when other stack frames are selected.  To pop entire frames
5825
off the stack, regardless of machine architecture, use `return'; see
5826
*Note Returning from a Function: Returning.
5827
 
5828

5829
File: gdb.info,  Node: Floating Point Hardware,  Next: Vector Unit,  Prev: Registers,  Up: Data
5830
 
5831
8.11 Floating Point Hardware
5832
============================
5833
 
5834
Depending on the configuration, GDB may be able to give you more
5835
information about the status of the floating point hardware.
5836
 
5837
`info float'
5838
     Display hardware-dependent information about the floating point
5839
     unit.  The exact contents and layout vary depending on the
5840
     floating point chip.  Currently, `info float' is supported on the
5841
     ARM and x86 machines.
5842
 
5843

5844
File: gdb.info,  Node: Vector Unit,  Next: OS Information,  Prev: Floating Point Hardware,  Up: Data
5845
 
5846
8.12 Vector Unit
5847
================
5848
 
5849
Depending on the configuration, GDB may be able to give you more
5850
information about the status of the vector unit.
5851
 
5852
`info vector'
5853
     Display information about the vector unit.  The exact contents and
5854
     layout vary depending on the hardware.
5855
 
5856

5857
File: gdb.info,  Node: OS Information,  Next: Memory Region Attributes,  Prev: Vector Unit,  Up: Data
5858
 
5859
8.13 Operating System Auxiliary Information
5860
===========================================
5861
 
5862
GDB provides interfaces to useful OS facilities that can help you debug
5863
your program.
5864
 
5865
   When GDB runs on a "Posix system" (such as GNU or Unix machines), it
5866
interfaces with the inferior via the `ptrace' system call.  The
5867
operating system creates a special sata structure, called `struct
5868
user', for this interface.  You can use the command `info udot' to
5869
display the contents of this data structure.
5870
 
5871
`info udot'
5872
     Display the contents of the `struct user' maintained by the OS
5873
     kernel for the program being debugged.  GDB displays the contents
5874
     of `struct user' as a list of hex numbers, similar to the
5875
     `examine' command.
5876
 
5877
   Some operating systems supply an "auxiliary vector" to programs at
5878
startup.  This is akin to the arguments and environment that you
5879
specify for a program, but contains a system-dependent variety of
5880
binary values that tell system libraries important details about the
5881
hardware, operating system, and process.  Each value's purpose is
5882
identified by an integer tag; the meanings are well-known but
5883
system-specific.  Depending on the configuration and operating system
5884
facilities, GDB may be able to show you this information.  For remote
5885
targets, this functionality may further depend on the remote stub's
5886
support of the `qXfer:auxv:read' packet, see *Note qXfer auxiliary
5887
vector read::.
5888
 
5889
`info auxv'
5890
     Display the auxiliary vector of the inferior, which can be either a
5891
     live process or a core dump file.  GDB prints each tag value
5892
     numerically, and also shows names and text descriptions for
5893
     recognized tags.  Some values in the vector are numbers, some bit
5894
     masks, and some pointers to strings or other data.  GDB displays
5895
     each value in the most appropriate form for a recognized tag, and
5896
     in hexadecimal for an unrecognized tag.
5897
 
5898

5899
File: gdb.info,  Node: Memory Region Attributes,  Next: Dump/Restore Files,  Prev: OS Information,  Up: Data
5900
 
5901
8.14 Memory Region Attributes
5902
=============================
5903
 
5904
"Memory region attributes" allow you to describe special handling
5905
required by regions of your target's memory.  GDB uses attributes to
5906
determine whether to allow certain types of memory accesses; whether to
5907
use specific width accesses; and whether to cache target memory.  By
5908
default the description of memory regions is fetched from the target
5909
(if the current target supports this), but the user can override the
5910
fetched regions.
5911
 
5912
   Defined memory regions can be individually enabled and disabled.
5913
When a memory region is disabled, GDB uses the default attributes when
5914
accessing memory in that region.  Similarly, if no memory regions have
5915
been defined, GDB uses the default attributes when accessing all memory.
5916
 
5917
   When a memory region is defined, it is given a number to identify it;
5918
to enable, disable, or remove a memory region, you specify that number.
5919
 
5920
`mem LOWER UPPER ATTRIBUTES...'
5921
     Define a memory region bounded by LOWER and UPPER with attributes
5922
     ATTRIBUTES..., and add it to the list of regions monitored by GDB.
5923
     Note that UPPER == 0 is a special case: it is treated as the
5924
     target's maximum memory address.  (0xffff on 16 bit targets,
5925
     0xffffffff on 32 bit targets, etc.)
5926
 
5927
`mem auto'
5928
     Discard any user changes to the memory regions and use
5929
     target-supplied regions, if available, or no regions if the target
5930
     does not support.
5931
 
5932
`delete mem NUMS...'
5933
     Remove memory regions NUMS... from the list of regions monitored
5934
     by GDB.
5935
 
5936
`disable mem NUMS...'
5937
     Disable monitoring of memory regions NUMS....  A disabled memory
5938
     region is not forgotten.  It may be enabled again later.
5939
 
5940
`enable mem NUMS...'
5941
     Enable monitoring of memory regions NUMS....
5942
 
5943
`info mem'
5944
     Print a table of all defined memory regions, with the following
5945
     columns for each region:
5946
 
5947
    _Memory Region Number_
5948
 
5949
    _Enabled or Disabled._
5950
          Enabled memory regions are marked with `y'.  Disabled memory
5951
          regions are marked with `n'.
5952
 
5953
    _Lo Address_
5954
          The address defining the inclusive lower bound of the memory
5955
          region.
5956
 
5957
    _Hi Address_
5958
          The address defining the exclusive upper bound of the memory
5959
          region.
5960
 
5961
    _Attributes_
5962
          The list of attributes set for this memory region.
5963
 
5964
8.14.1 Attributes
5965
-----------------
5966
 
5967
8.14.1.1 Memory Access Mode
5968
...........................
5969
 
5970
The access mode attributes set whether GDB may make read or write
5971
accesses to a memory region.
5972
 
5973
   While these attributes prevent GDB from performing invalid memory
5974
accesses, they do nothing to prevent the target system, I/O DMA, etc.
5975
from accessing memory.
5976
 
5977
`ro'
5978
     Memory is read only.
5979
 
5980
`wo'
5981
     Memory is write only.
5982
 
5983
`rw'
5984
     Memory is read/write.  This is the default.
5985
 
5986
8.14.1.2 Memory Access Size
5987
...........................
5988
 
5989
The access size attribute tells GDB to use specific sized accesses in
5990
the memory region.  Often memory mapped device registers require
5991
specific sized accesses.  If no access size attribute is specified, GDB
5992
may use accesses of any size.
5993
 
5994
`8'
5995
     Use 8 bit memory accesses.
5996
 
5997
`16'
5998
     Use 16 bit memory accesses.
5999
 
6000
`32'
6001
     Use 32 bit memory accesses.
6002
 
6003
`64'
6004
     Use 64 bit memory accesses.
6005
 
6006
8.14.1.3 Data Cache
6007
...................
6008
 
6009
The data cache attributes set whether GDB will cache target memory.
6010
While this generally improves performance by reducing debug protocol
6011
overhead, it can lead to incorrect results because GDB does not know
6012
about volatile variables or memory mapped device registers.
6013
 
6014
`cache'
6015
     Enable GDB to cache target memory.
6016
 
6017
`nocache'
6018
     Disable GDB from caching target memory.  This is the default.
6019
 
6020
8.14.2 Memory Access Checking
6021
-----------------------------
6022
 
6023
GDB can be instructed to refuse accesses to memory that is not
6024
explicitly described.  This can be useful if accessing such regions has
6025
undesired effects for a specific target, or to provide better error
6026
checking.  The following commands control this behaviour.
6027
 
6028
`set mem inaccessible-by-default [on|off]'
6029
     If `on' is specified, make  GDB treat memory not explicitly
6030
     described by the memory ranges as non-existent and refuse accesses
6031
     to such memory.  The checks are only performed if there's at least
6032
     one memory range defined.  If `off' is specified, make GDB treat
6033
     the memory not explicitly described by the memory ranges as RAM.
6034
     The default value is `on'.
6035
 
6036
`show mem inaccessible-by-default'
6037
     Show the current handling of accesses to unknown memory.
6038
 
6039

6040
File: gdb.info,  Node: Dump/Restore Files,  Next: Core File Generation,  Prev: Memory Region Attributes,  Up: Data
6041
 
6042
8.15 Copy Between Memory and a File
6043
===================================
6044
 
6045
You can use the commands `dump', `append', and `restore' to copy data
6046
between target memory and a file.  The `dump' and `append' commands
6047
write data to a file, and the `restore' command reads data from a file
6048
back into the inferior's memory.  Files may be in binary, Motorola
6049
S-record, Intel hex, or Tektronix Hex format; however, GDB can only
6050
append to binary files.
6051
 
6052
`dump [FORMAT] memory FILENAME START_ADDR END_ADDR'
6053
`dump [FORMAT] value FILENAME EXPR'
6054
     Dump the contents of memory from START_ADDR to END_ADDR, or the
6055
     value of EXPR, to FILENAME in the given format.
6056
 
6057
     The FORMAT parameter may be any one of:
6058
    `binary'
6059
          Raw binary form.
6060
 
6061
    `ihex'
6062
          Intel hex format.
6063
 
6064
    `srec'
6065
          Motorola S-record format.
6066
 
6067
    `tekhex'
6068
          Tektronix Hex format.
6069
 
6070
     GDB uses the same definitions of these formats as the GNU binary
6071
     utilities, like `objdump' and `objcopy'.  If FORMAT is omitted,
6072
     GDB dumps the data in raw binary form.
6073
 
6074
`append [binary] memory FILENAME START_ADDR END_ADDR'
6075
`append [binary] value FILENAME EXPR'
6076
     Append the contents of memory from START_ADDR to END_ADDR, or the
6077
     value of EXPR, to the file FILENAME, in raw binary form.  (GDB can
6078
     only append data to files in raw binary form.)
6079
 
6080
`restore FILENAME [binary] BIAS START END'
6081
     Restore the contents of file FILENAME into memory.  The `restore'
6082
     command can automatically recognize any known BFD file format,
6083
     except for raw binary.  To restore a raw binary file you must
6084
     specify the optional keyword `binary' after the filename.
6085
 
6086
     If BIAS is non-zero, its value will be added to the addresses
6087
     contained in the file.  Binary files always start at address zero,
6088
     so they will be restored at address BIAS.  Other bfd files have a
6089
     built-in location; they will be restored at offset BIAS from that
6090
     location.
6091
 
6092
     If START and/or END are non-zero, then only data between file
6093
     offset START and file offset END will be restored.  These offsets
6094
     are relative to the addresses in the file, before the BIAS
6095
     argument is applied.
6096
 
6097
 
6098

6099
File: gdb.info,  Node: Core File Generation,  Next: Character Sets,  Prev: Dump/Restore Files,  Up: Data
6100
 
6101
8.16 How to Produce a Core File from Your Program
6102
=================================================
6103
 
6104
A "core file" or "core dump" is a file that records the memory image of
6105
a running process and its process status (register values etc.).  Its
6106
primary use is post-mortem debugging of a program that crashed while it
6107
ran outside a debugger.  A program that crashes automatically produces
6108
a core file, unless this feature is disabled by the user.  *Note
6109
Files::, for information on invoking GDB in the post-mortem debugging
6110
mode.
6111
 
6112
   Occasionally, you may wish to produce a core file of the program you
6113
are debugging in order to preserve a snapshot of its state.  GDB has a
6114
special command for that.
6115
 
6116
`generate-core-file [FILE]'
6117
`gcore [FILE]'
6118
     Produce a core dump of the inferior process.  The optional argument
6119
     FILE specifies the file name where to put the core dump.  If not
6120
     specified, the file name defaults to `core.PID', where PID is the
6121
     inferior process ID.
6122
 
6123
     Note that this command is implemented only for some systems (as of
6124
     this writing, GNU/Linux, FreeBSD, Solaris, Unixware, and S390).
6125
 
6126

6127
File: gdb.info,  Node: Character Sets,  Next: Caching Remote Data,  Prev: Core File Generation,  Up: Data
6128
 
6129
8.17 Character Sets
6130
===================
6131
 
6132
If the program you are debugging uses a different character set to
6133
represent characters and strings than the one GDB uses itself, GDB can
6134
automatically translate between the character sets for you.  The
6135
character set GDB uses we call the "host character set"; the one the
6136
inferior program uses we call the "target character set".
6137
 
6138
   For example, if you are running GDB on a GNU/Linux system, which
6139
uses the ISO Latin 1 character set, but you are using GDB's remote
6140
protocol (*note Remote Debugging::) to debug a program running on an
6141
IBM mainframe, which uses the EBCDIC character set, then the host
6142
character set is Latin-1, and the target character set is EBCDIC.  If
6143
you give GDB the command `set target-charset EBCDIC-US', then GDB
6144
translates between EBCDIC and Latin 1 as you print character or string
6145
values, or use character and string literals in expressions.
6146
 
6147
   GDB has no way to automatically recognize which character set the
6148
inferior program uses; you must tell it, using the `set target-charset'
6149
command, described below.
6150
 
6151
   Here are the commands for controlling GDB's character set support:
6152
 
6153
`set target-charset CHARSET'
6154
     Set the current target character set to CHARSET.  We list the
6155
     character set names GDB recognizes below, but if you type `set
6156
     target-charset' followed by , GDB will list the target
6157
     character sets it supports.
6158
 
6159
`set host-charset CHARSET'
6160
     Set the current host character set to CHARSET.
6161
 
6162
     By default, GDB uses a host character set appropriate to the
6163
     system it is running on; you can override that default using the
6164
     `set host-charset' command.
6165
 
6166
     GDB can only use certain character sets as its host character set.
6167
     We list the character set names GDB recognizes below, and
6168
     indicate which can be host character sets, but if you type `set
6169
     target-charset' followed by , GDB will list the host
6170
     character sets it supports.
6171
 
6172
`set charset CHARSET'
6173
     Set the current host and target character sets to CHARSET.  As
6174
     above, if you type `set charset' followed by , GDB will
6175
     list the name of the character sets that can be used for both host
6176
     and target.
6177
 
6178
`show charset'
6179
     Show the names of the current host and target charsets.
6180
 
6181
`show host-charset'
6182
     Show the name of the current host charset.
6183
 
6184
`show target-charset'
6185
     Show the name of the current target charset.
6186
 
6187
 
6188
   GDB currently includes support for the following character sets:
6189
 
6190
`ASCII'
6191
     Seven-bit U.S. ASCII.  GDB can use this as its host character set.
6192
 
6193
`ISO-8859-1'
6194
     The ISO Latin 1 character set.  This extends ASCII with accented
6195
     characters needed for French, German, and Spanish.  GDB can use
6196
     this as its host character set.
6197
 
6198
`EBCDIC-US'
6199
`IBM1047'
6200
     Variants of the EBCDIC character set, used on some of IBM's
6201
     mainframe operating systems.  (GNU/Linux on the S/390 uses U.S.
6202
     ASCII.)  GDB cannot use these as its host character set.
6203
 
6204
 
6205
   Note that these are all single-byte character sets.  More work inside
6206
GDB is needed to support multi-byte or variable-width character
6207
encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6208
 
6209
   Here is an example of GDB's character set support in action.  Assume
6210
that the following source code has been placed in the file
6211
`charset-test.c':
6212
 
6213
     #include 
6214
 
6215
     char ascii_hello[]
6216
       = {72, 101, 108, 108, 111, 44, 32, 119,
6217
          111, 114, 108, 100, 33, 10, 0};
6218
     char ibm1047_hello[]
6219
       = {200, 133, 147, 147, 150, 107, 64, 166,
6220
          150, 153, 147, 132, 90, 37, 0};
6221
 
6222
     main ()
6223
     {
6224
       printf ("Hello, world!\n");
6225
     }
6226
 
6227
   In this program, `ascii_hello' and `ibm1047_hello' are arrays
6228
containing the string `Hello, world!' followed by a newline, encoded in
6229
the ASCII and IBM1047 character sets.
6230
 
6231
   We compile the program, and invoke the debugger on it:
6232
 
6233
     $ gcc -g charset-test.c -o charset-test
6234
     $ gdb -nw charset-test
6235
     GNU gdb 2001-12-19-cvs
6236
     Copyright 2001 Free Software Foundation, Inc.
6237
     ...
6238
     (gdb)
6239
 
6240
   We can use the `show charset' command to see what character sets GDB
6241
is currently using to interpret and display characters and strings:
6242
 
6243
     (gdb) show charset
6244
     The current host and target character set is `ISO-8859-1'.
6245
     (gdb)
6246
 
6247
   For the sake of printing this manual, let's use ASCII as our initial
6248
character set:
6249
     (gdb) set charset ASCII
6250
     (gdb) show charset
6251
     The current host and target character set is `ASCII'.
6252
     (gdb)
6253
 
6254
   Let's assume that ASCII is indeed the correct character set for our
6255
host system -- in other words, let's assume that if GDB prints
6256
characters using the ASCII character set, our terminal will display
6257
them properly.  Since our current target character set is also ASCII,
6258
the contents of `ascii_hello' print legibly:
6259
 
6260
     (gdb) print ascii_hello
6261
     $1 = 0x401698 "Hello, world!\n"
6262
     (gdb) print ascii_hello[0]
6263
     $2 = 72 'H'
6264
     (gdb)
6265
 
6266
   GDB uses the target character set for character and string literals
6267
you use in expressions:
6268
 
6269
     (gdb) print '+'
6270
     $3 = 43 '+'
6271
     (gdb)
6272
 
6273
   The ASCII character set uses the number 43 to encode the `+'
6274
character.
6275
 
6276
   GDB relies on the user to tell it which character set the target
6277
program uses.  If we print `ibm1047_hello' while our target character
6278
set is still ASCII, we get jibberish:
6279
 
6280
     (gdb) print ibm1047_hello
6281
     $4 = 0x4016a8 "\310\205\223\223\226k@\246\226\231\223\204Z%"
6282
     (gdb) print ibm1047_hello[0]
6283
     $5 = 200 '\310'
6284
     (gdb)
6285
 
6286
   If we invoke the `set target-charset' followed by , GDB
6287
tells us the character sets it supports:
6288
 
6289
     (gdb) set target-charset
6290
     ASCII       EBCDIC-US   IBM1047     ISO-8859-1
6291
     (gdb) set target-charset
6292
 
6293
   We can select IBM1047 as our target character set, and examine the
6294
program's strings again.  Now the ASCII string is wrong, but GDB
6295
translates the contents of `ibm1047_hello' from the target character
6296
set, IBM1047, to the host character set, ASCII, and they display
6297
correctly:
6298
 
6299
     (gdb) set target-charset IBM1047
6300
     (gdb) show charset
6301
     The current host character set is `ASCII'.
6302
     The current target character set is `IBM1047'.
6303
     (gdb) print ascii_hello
6304
     $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6305
     (gdb) print ascii_hello[0]
6306
     $7 = 72 '\110'
6307
     (gdb) print ibm1047_hello
6308
     $8 = 0x4016a8 "Hello, world!\n"
6309
     (gdb) print ibm1047_hello[0]
6310
     $9 = 200 'H'
6311
     (gdb)
6312
 
6313
   As above, GDB uses the target character set for character and string
6314
literals you use in expressions:
6315
 
6316
     (gdb) print '+'
6317
     $10 = 78 '+'
6318
     (gdb)
6319
 
6320
   The IBM1047 character set uses the number 78 to encode the `+'
6321
character.
6322
 
6323

6324
File: gdb.info,  Node: Caching Remote Data,  Prev: Character Sets,  Up: Data
6325
 
6326
8.18 Caching Data of Remote Targets
6327
===================================
6328
 
6329
GDB can cache data exchanged between the debugger and a remote target
6330
(*note Remote Debugging::).  Such caching generally improves
6331
performance, because it reduces the overhead of the remote protocol by
6332
bundling memory reads and writes into large chunks.  Unfortunately, GDB
6333
does not currently know anything about volatile registers, and thus
6334
data caching will produce incorrect results when volatile registers are
6335
in use.
6336
 
6337
`set remotecache on'
6338
`set remotecache off'
6339
     Set caching state for remote targets.  When `ON', use data
6340
     caching.  By default, this option is `OFF'.
6341
 
6342
`show remotecache'
6343
     Show the current state of data caching for remote targets.
6344
 
6345
`info dcache'
6346
     Print the information about the data cache performance.  The
6347
     information displayed includes: the dcache width and depth; and for
6348
     each cache line, how many times it was referenced, and its data and
6349
     state (dirty, bad, ok, etc.).  This command is useful for debugging
6350
     the data cache operation.
6351
 
6352

6353
File: gdb.info,  Node: Macros,  Next: Tracepoints,  Prev: Data,  Up: Top
6354
 
6355
9 C Preprocessor Macros
6356
***********************
6357
 
6358
Some languages, such as C and C++, provide a way to define and invoke
6359
"preprocessor macros" which expand into strings of tokens.  GDB can
6360
evaluate expressions containing macro invocations, show the result of
6361
macro expansion, and show a macro's definition, including where it was
6362
defined.
6363
 
6364
   You may need to compile your program specially to provide GDB with
6365
information about preprocessor macros.  Most compilers do not include
6366
macros in their debugging information, even when you compile with the
6367
`-g' flag.  *Note Compilation::.
6368
 
6369
   A program may define a macro at one point, remove that definition
6370
later, and then provide a different definition after that.  Thus, at
6371
different points in the program, a macro may have different
6372
definitions, or have no definition at all.  If there is a current stack
6373
frame, GDB uses the macros in scope at that frame's source code line.
6374
Otherwise, GDB uses the macros in scope at the current listing location;
6375
see *Note List::.
6376
 
6377
   At the moment, GDB does not support the `##' token-splicing
6378
operator, the `#' stringification operator, or variable-arity macros.
6379
 
6380
   Whenever GDB evaluates an expression, it always expands any macro
6381
invocations present in the expression.  GDB also provides the following
6382
commands for working with macros explicitly.
6383
 
6384
`macro expand EXPRESSION'
6385
`macro exp EXPRESSION'
6386
     Show the results of expanding all preprocessor macro invocations in
6387
     EXPRESSION.  Since GDB simply expands macros, but does not parse
6388
     the result, EXPRESSION need not be a valid expression; it can be
6389
     any string of tokens.
6390
 
6391
`macro expand-once EXPRESSION'
6392
`macro exp1 EXPRESSION'
6393
     (This command is not yet implemented.)  Show the results of
6394
     expanding those preprocessor macro invocations that appear
6395
     explicitly in EXPRESSION.  Macro invocations appearing in that
6396
     expansion are left unchanged.  This command allows you to see the
6397
     effect of a particular macro more clearly, without being confused
6398
     by further expansions.  Since GDB simply expands macros, but does
6399
     not parse the result, EXPRESSION need not be a valid expression; it
6400
     can be any string of tokens.
6401
 
6402
`info macro MACRO'
6403
     Show the definition of the macro named MACRO, and describe the
6404
     source location where that definition was established.
6405
 
6406
`macro define MACRO REPLACEMENT-LIST'
6407
`macro define MACRO(ARGLIST) REPLACEMENT-LIST'
6408
     (This command is not yet implemented.)  Introduce a definition for
6409
     a preprocessor macro named MACRO, invocations of which are replaced
6410
     by the tokens given in REPLACEMENT-LIST.  The first form of this
6411
     command defines an "object-like" macro, which takes no arguments;
6412
     the second form defines a "function-like" macro, which takes the
6413
     arguments given in ARGLIST.
6414
 
6415
     A definition introduced by this command is in scope in every
6416
     expression evaluated in GDB, until it is removed with the `macro
6417
     undef' command, described below.  The definition overrides all
6418
     definitions for MACRO present in the program being debugged, as
6419
     well as any previous user-supplied definition.
6420
 
6421
`macro undef MACRO'
6422
     (This command is not yet implemented.)  Remove any user-supplied
6423
     definition for the macro named MACRO.  This command only affects
6424
     definitions provided with the `macro define' command, described
6425
     above; it cannot remove definitions present in the program being
6426
     debugged.
6427
 
6428
`macro list'
6429
     (This command is not yet implemented.)  List all the macros
6430
     defined using the `macro define' command.
6431
 
6432
   Here is a transcript showing the above commands in action.  First, we
6433
show our source files:
6434
 
6435
     $ cat sample.c
6436
     #include 
6437
     #include "sample.h"
6438
 
6439
     #define M 42
6440
     #define ADD(x) (M + x)
6441
 
6442
     main ()
6443
     {
6444
     #define N 28
6445
       printf ("Hello, world!\n");
6446
     #undef N
6447
       printf ("We're so creative.\n");
6448
     #define N 1729
6449
       printf ("Goodbye, world!\n");
6450
     }
6451
     $ cat sample.h
6452
     #define Q <
6453
     $
6454
 
6455
   Now, we compile the program using the GNU C compiler, GCC.  We pass
6456
the `-gdwarf-2' and `-g3' flags to ensure the compiler includes
6457
information about preprocessor macros in the debugging information.
6458
 
6459
     $ gcc -gdwarf-2 -g3 sample.c -o sample
6460
     $
6461
 
6462
   Now, we start GDB on our sample program:
6463
 
6464
     $ gdb -nw sample
6465
     GNU gdb 2002-05-06-cvs
6466
     Copyright 2002 Free Software Foundation, Inc.
6467
     GDB is free software, ...
6468
     (gdb)
6469
 
6470
   We can expand macros and examine their definitions, even when the
6471
program is not running.  GDB uses the current listing position to
6472
decide which macro definitions are in scope:
6473
 
6474
     (gdb) list main
6475
     3
6476
     4       #define M 42
6477
     5       #define ADD(x) (M + x)
6478
     6
6479
     7       main ()
6480
     8       {
6481
     9       #define N 28
6482
     10        printf ("Hello, world!\n");
6483
     11      #undef N
6484
     12        printf ("We're so creative.\n");
6485
     (gdb) info macro ADD
6486
     Defined at /home/jimb/gdb/macros/play/sample.c:5
6487
     #define ADD(x) (M + x)
6488
     (gdb) info macro Q
6489
     Defined at /home/jimb/gdb/macros/play/sample.h:1
6490
       included at /home/jimb/gdb/macros/play/sample.c:2
6491
     #define Q <
6492
     (gdb) macro expand ADD(1)
6493
     expands to: (42 + 1)
6494
     (gdb) macro expand-once ADD(1)
6495
     expands to: once (M + 1)
6496
     (gdb)
6497
 
6498
   In the example above, note that `macro expand-once' expands only the
6499
macro invocation explicit in the original text -- the invocation of
6500
`ADD' -- but does not expand the invocation of the macro `M', which was
6501
introduced by `ADD'.
6502
 
6503
   Once the program is running, GDB uses the macro definitions in force
6504
at the source line of the current stack frame:
6505
 
6506
     (gdb) break main
6507
     Breakpoint 1 at 0x8048370: file sample.c, line 10.
6508
     (gdb) run
6509
     Starting program: /home/jimb/gdb/macros/play/sample
6510
 
6511
     Breakpoint 1, main () at sample.c:10
6512
     10        printf ("Hello, world!\n");
6513
     (gdb)
6514
 
6515
   At line 10, the definition of the macro `N' at line 9 is in force:
6516
 
6517
     (gdb) info macro N
6518
     Defined at /home/jimb/gdb/macros/play/sample.c:9
6519
     #define N 28
6520
     (gdb) macro expand N Q M
6521
     expands to: 28 < 42
6522
     (gdb) print N Q M
6523
     $1 = 1
6524
     (gdb)
6525
 
6526
   As we step over directives that remove `N''s definition, and then
6527
give it a new definition, GDB finds the definition (or lack thereof) in
6528
force at each point:
6529
 
6530
     (gdb) next
6531
     Hello, world!
6532
     12        printf ("We're so creative.\n");
6533
     (gdb) info macro N
6534
     The symbol `N' has no definition as a C/C++ preprocessor macro
6535
     at /home/jimb/gdb/macros/play/sample.c:12
6536
     (gdb) next
6537
     We're so creative.
6538
     14        printf ("Goodbye, world!\n");
6539
     (gdb) info macro N
6540
     Defined at /home/jimb/gdb/macros/play/sample.c:13
6541
     #define N 1729
6542
     (gdb) macro expand N Q M
6543
     expands to: 1729 < 42
6544
     (gdb) print N Q M
6545
     $2 = 0
6546
     (gdb)
6547
 
6548

6549
File: gdb.info,  Node: Tracepoints,  Next: Overlays,  Prev: Macros,  Up: Top
6550
 
6551
10 Tracepoints
6552
**************
6553
 
6554
In some applications, it is not feasible for the debugger to interrupt
6555
the program's execution long enough for the developer to learn anything
6556
helpful about its behavior.  If the program's correctness depends on
6557
its real-time behavior, delays introduced by a debugger might cause the
6558
program to change its behavior drastically, or perhaps fail, even when
6559
the code itself is correct.  It is useful to be able to observe the
6560
program's behavior without interrupting it.
6561
 
6562
   Using GDB's `trace' and `collect' commands, you can specify
6563
locations in the program, called "tracepoints", and arbitrary
6564
expressions to evaluate when those tracepoints are reached.  Later,
6565
using the `tfind' command, you can examine the values those expressions
6566
had when the program hit the tracepoints.  The expressions may also
6567
denote objects in memory--structures or arrays, for example--whose
6568
values GDB should record; while visiting a particular tracepoint, you
6569
may inspect those objects as if they were in memory at that moment.
6570
However, because GDB records these values without interacting with you,
6571
it can do so quickly and unobtrusively, hopefully not disturbing the
6572
program's behavior.
6573
 
6574
   The tracepoint facility is currently available only for remote
6575
targets.  *Note Targets::.  In addition, your remote target must know
6576
how to collect trace data.  This functionality is implemented in the
6577
remote stub; however, none of the stubs distributed with GDB support
6578
tracepoints as of this writing.  The format of the remote packets used
6579
to implement tracepoints are described in *Note Tracepoint Packets::.
6580
 
6581
   This chapter describes the tracepoint commands and features.
6582
 
6583
* Menu:
6584
 
6585
* Set Tracepoints::
6586
* Analyze Collected Data::
6587
* Tracepoint Variables::
6588
 
6589

6590
File: gdb.info,  Node: Set Tracepoints,  Next: Analyze Collected Data,  Up: Tracepoints
6591
 
6592
10.1 Commands to Set Tracepoints
6593
================================
6594
 
6595
Before running such a "trace experiment", an arbitrary number of
6596
tracepoints can be set.  Like a breakpoint (*note Set Breaks::), a
6597
tracepoint has a number assigned to it by GDB.  Like with breakpoints,
6598
tracepoint numbers are successive integers starting from one.  Many of
6599
the commands associated with tracepoints take the tracepoint number as
6600
their argument, to identify which tracepoint to work on.
6601
 
6602
   For each tracepoint, you can specify, in advance, some arbitrary set
6603
of data that you want the target to collect in the trace buffer when it
6604
hits that tracepoint.  The collected data can include registers, local
6605
variables, or global data.  Later, you can use GDB commands to examine
6606
the values these data had at the time the tracepoint was hit.
6607
 
6608
   This section describes commands to set tracepoints and associated
6609
conditions and actions.
6610
 
6611
* Menu:
6612
 
6613
* Create and Delete Tracepoints::
6614
* Enable and Disable Tracepoints::
6615
* Tracepoint Passcounts::
6616
* Tracepoint Actions::
6617
* Listing Tracepoints::
6618
* Starting and Stopping Trace Experiments::
6619
 
6620

6621
File: gdb.info,  Node: Create and Delete Tracepoints,  Next: Enable and Disable Tracepoints,  Up: Set Tracepoints
6622
 
6623
10.1.1 Create and Delete Tracepoints
6624
------------------------------------
6625
 
6626
`trace'
6627
     The `trace' command is very similar to the `break' command.  Its
6628
     argument can be a source line, a function name, or an address in
6629
     the target program.  *Note Set Breaks::.  The `trace' command
6630
     defines a tracepoint, which is a point in the target program where
6631
     the debugger will briefly stop, collect some data, and then allow
6632
     the program to continue.  Setting a tracepoint or changing its
6633
     commands doesn't take effect until the next `tstart' command;
6634
     thus, you cannot change the tracepoint attributes once a trace
6635
     experiment is running.
6636
 
6637
     Here are some examples of using the `trace' command:
6638
 
6639
          (gdb) trace foo.c:121    // a source file and line number
6640
 
6641
          (gdb) trace +2           // 2 lines forward
6642
 
6643
          (gdb) trace my_function  // first source line of function
6644
 
6645
          (gdb) trace *my_function // EXACT start address of function
6646
 
6647
          (gdb) trace *0x2117c4    // an address
6648
 
6649
     You can abbreviate `trace' as `tr'.
6650
 
6651
     The convenience variable `$tpnum' records the tracepoint number of
6652
     the most recently set tracepoint.
6653
 
6654
`delete tracepoint [NUM]'
6655
     Permanently delete one or more tracepoints.  With no argument, the
6656
     default is to delete all tracepoints.
6657
 
6658
     Examples:
6659
 
6660
          (gdb) delete trace 1 2 3 // remove three tracepoints
6661
 
6662
          (gdb) delete trace       // remove all tracepoints
6663
 
6664
     You can abbreviate this command as `del tr'.
6665
 
6666

6667
File: gdb.info,  Node: Enable and Disable Tracepoints,  Next: Tracepoint Passcounts,  Prev: Create and Delete Tracepoints,  Up: Set Tracepoints
6668
 
6669
10.1.2 Enable and Disable Tracepoints
6670
-------------------------------------
6671
 
6672
`disable tracepoint [NUM]'
6673
     Disable tracepoint NUM, or all tracepoints if no argument NUM is
6674
     given.  A disabled tracepoint will have no effect during the next
6675
     trace experiment, but it is not forgotten.  You can re-enable a
6676
     disabled tracepoint using the `enable tracepoint' command.
6677
 
6678
`enable tracepoint [NUM]'
6679
     Enable tracepoint NUM, or all tracepoints.  The enabled
6680
     tracepoints will become effective the next time a trace experiment
6681
     is run.
6682
 
6683

6684
File: gdb.info,  Node: Tracepoint Passcounts,  Next: Tracepoint Actions,  Prev: Enable and Disable Tracepoints,  Up: Set Tracepoints
6685
 
6686
10.1.3 Tracepoint Passcounts
6687
----------------------------
6688
 
6689
`passcount [N [NUM]]'
6690
     Set the "passcount" of a tracepoint.  The passcount is a way to
6691
     automatically stop a trace experiment.  If a tracepoint's
6692
     passcount is N, then the trace experiment will be automatically
6693
     stopped on the N'th time that tracepoint is hit.  If the
6694
     tracepoint number NUM is not specified, the `passcount' command
6695
     sets the passcount of the most recently defined tracepoint.  If no
6696
     passcount is given, the trace experiment will run until stopped
6697
     explicitly by the user.
6698
 
6699
     Examples:
6700
 
6701
          (gdb) passcount 5 2 // Stop on the 5th execution of
6702
                                        `// tracepoint 2'
6703
 
6704
          (gdb) passcount 12  // Stop on the 12th execution of the
6705
                                        `// most recently defined tracepoint.'
6706
          (gdb) trace foo
6707
          (gdb) pass 3
6708
          (gdb) trace bar
6709
          (gdb) pass 2
6710
          (gdb) trace baz
6711
          (gdb) pass 1        // Stop tracing when foo has been
6712
                                         `// executed 3 times OR when bar has'
6713
                                         `// been executed 2 times'
6714
                                         `// OR when baz has been executed 1 time.'
6715
 
6716
 
6717

6718
File: gdb.info,  Node: Tracepoint Actions,  Next: Listing Tracepoints,  Prev: Tracepoint Passcounts,  Up: Set Tracepoints
6719
 
6720
10.1.4 Tracepoint Action Lists
6721
------------------------------
6722
 
6723
`actions [NUM]'
6724
     This command will prompt for a list of actions to be taken when the
6725
     tracepoint is hit.  If the tracepoint number NUM is not specified,
6726
     this command sets the actions for the one that was most recently
6727
     defined (so that you can define a tracepoint and then say
6728
     `actions' without bothering about its number).  You specify the
6729
     actions themselves on the following lines, one action at a time,
6730
     and terminate the actions list with a line containing just `end'.
6731
     So far, the only defined actions are `collect' and
6732
     `while-stepping'.
6733
 
6734
     To remove all actions from a tracepoint, type `actions NUM' and
6735
     follow it immediately with `end'.
6736
 
6737
          (gdb) collect DATA // collect some data
6738
 
6739
          (gdb) while-stepping 5 // single-step 5 times, collect data
6740
 
6741
          (gdb) end              // signals the end of actions.
6742
 
6743
     In the following example, the action list begins with `collect'
6744
     commands indicating the things to be collected when the tracepoint
6745
     is hit.  Then, in order to single-step and collect additional data
6746
     following the tracepoint, a `while-stepping' command is used,
6747
     followed by the list of things to be collected while stepping.  The
6748
     `while-stepping' command is terminated by its own separate `end'
6749
     command.  Lastly, the action list is terminated by an `end'
6750
     command.
6751
 
6752
          (gdb) trace foo
6753
          (gdb) actions
6754
          Enter actions for tracepoint 1, one per line:
6755
          > collect bar,baz
6756
          > collect $regs
6757
          > while-stepping 12
6758
            > collect $fp, $sp
6759
            > end
6760
          end
6761
 
6762
`collect EXPR1, EXPR2, ...'
6763
     Collect values of the given expressions when the tracepoint is hit.
6764
     This command accepts a comma-separated list of any valid
6765
     expressions.  In addition to global, static, or local variables,
6766
     the following special arguments are supported:
6767
 
6768
    `$regs'
6769
          collect all registers
6770
 
6771
    `$args'
6772
          collect all function arguments
6773
 
6774
    `$locals'
6775
          collect all local variables.
6776
 
6777
     You can give several consecutive `collect' commands, each one with
6778
     a single argument, or one `collect' command with several arguments
6779
     separated by commas: the effect is the same.
6780
 
6781
     The command `info scope' (*note info scope: Symbols.) is
6782
     particularly useful for figuring out what data to collect.
6783
 
6784
`while-stepping N'
6785
     Perform N single-step traces after the tracepoint, collecting new
6786
     data at each step.  The `while-stepping' command is followed by
6787
     the list of what to collect while stepping (followed by its own
6788
     `end' command):
6789
 
6790
          > while-stepping 12
6791
            > collect $regs, myglobal
6792
            > end
6793
          >
6794
 
6795
     You may abbreviate `while-stepping' as `ws' or `stepping'.
6796
 
6797

6798
File: gdb.info,  Node: Listing Tracepoints,  Next: Starting and Stopping Trace Experiments,  Prev: Tracepoint Actions,  Up: Set Tracepoints
6799
 
6800
10.1.5 Listing Tracepoints
6801
--------------------------
6802
 
6803
`info tracepoints [NUM]'
6804
     Display information about the tracepoint NUM.  If you don't specify
6805
     a tracepoint number, displays information about all the tracepoints
6806
     defined so far.  For each tracepoint, the following information is
6807
     shown:
6808
 
6809
        * its number
6810
 
6811
        * whether it is enabled or disabled
6812
 
6813
        * its address
6814
 
6815
        * its passcount as given by the `passcount N' command
6816
 
6817
        * its step count as given by the `while-stepping N' command
6818
 
6819
        * where in the source files is the tracepoint set
6820
 
6821
        * its action list as given by the `actions' command
6822
 
6823
          (gdb) info trace
6824
          Num Enb Address    PassC StepC What
6825
          1   y   0x002117c4 0     0     
6826
          2   y   0x0020dc64 0     0     in g_test at g_test.c:1375
6827
          3   y   0x0020b1f4 0     0     in get_data at ../foo.c:41
6828
          (gdb)
6829
 
6830
     This command can be abbreviated `info tp'.
6831
 
6832

6833
File: gdb.info,  Node: Starting and Stopping Trace Experiments,  Prev: Listing Tracepoints,  Up: Set Tracepoints
6834
 
6835
10.1.6 Starting and Stopping Trace Experiments
6836
----------------------------------------------
6837
 
6838
`tstart'
6839
     This command takes no arguments.  It starts the trace experiment,
6840
     and begins collecting data.  This has the side effect of
6841
     discarding all the data collected in the trace buffer during the
6842
     previous trace experiment.
6843
 
6844
`tstop'
6845
     This command takes no arguments.  It ends the trace experiment, and
6846
     stops collecting data.
6847
 
6848
     *Note*: a trace experiment and data collection may stop
6849
     automatically if any tracepoint's passcount is reached (*note
6850
     Tracepoint Passcounts::), or if the trace buffer becomes full.
6851
 
6852
`tstatus'
6853
     This command displays the status of the current trace data
6854
     collection.
6855
 
6856
   Here is an example of the commands we described so far:
6857
 
6858
     (gdb) trace gdb_c_test
6859
     (gdb) actions
6860
     Enter actions for tracepoint #1, one per line.
6861
     > collect $regs,$locals,$args
6862
     > while-stepping 11
6863
       > collect $regs
6864
       > end
6865
     > end
6866
     (gdb) tstart
6867
        [time passes ...]
6868
     (gdb) tstop
6869
 
6870

6871
File: gdb.info,  Node: Analyze Collected Data,  Next: Tracepoint Variables,  Prev: Set Tracepoints,  Up: Tracepoints
6872
 
6873
10.2 Using the Collected Data
6874
=============================
6875
 
6876
After the tracepoint experiment ends, you use GDB commands for
6877
examining the trace data.  The basic idea is that each tracepoint
6878
collects a trace "snapshot" every time it is hit and another snapshot
6879
every time it single-steps.  All these snapshots are consecutively
6880
numbered from zero and go into a buffer, and you can examine them
6881
later.  The way you examine them is to "focus" on a specific trace
6882
snapshot.  When the remote stub is focused on a trace snapshot, it will
6883
respond to all GDB requests for memory and registers by reading from
6884
the buffer which belongs to that snapshot, rather than from _real_
6885
memory or registers of the program being debugged.  This means that
6886
*all* GDB commands (`print', `info registers', `backtrace', etc.) will
6887
behave as if we were currently debugging the program state as it was
6888
when the tracepoint occurred.  Any requests for data that are not in
6889
the buffer will fail.
6890
 
6891
* Menu:
6892
 
6893
* tfind::                       How to select a trace snapshot
6894
* tdump::                       How to display all data for a snapshot
6895
* save-tracepoints::            How to save tracepoints for a future run
6896
 
6897

6898
File: gdb.info,  Node: tfind,  Next: tdump,  Up: Analyze Collected Data
6899
 
6900
10.2.1 `tfind N'
6901
----------------
6902
 
6903
The basic command for selecting a trace snapshot from the buffer is
6904
`tfind N', which finds trace snapshot number N, counting from zero.  If
6905
no argument N is given, the next snapshot is selected.
6906
 
6907
   Here are the various forms of using the `tfind' command.
6908
 
6909
`tfind start'
6910
     Find the first snapshot in the buffer.  This is a synonym for
6911
     `tfind 0' (since 0 is the number of the first snapshot).
6912
 
6913
`tfind none'
6914
     Stop debugging trace snapshots, resume _live_ debugging.
6915
 
6916
`tfind end'
6917
     Same as `tfind none'.
6918
 
6919
`tfind'
6920
     No argument means find the next trace snapshot.
6921
 
6922
`tfind -'
6923
     Find the previous trace snapshot before the current one.  This
6924
     permits retracing earlier steps.
6925
 
6926
`tfind tracepoint NUM'
6927
     Find the next snapshot associated with tracepoint NUM.  Search
6928
     proceeds forward from the last examined trace snapshot.  If no
6929
     argument NUM is given, it means find the next snapshot collected
6930
     for the same tracepoint as the current snapshot.
6931
 
6932
`tfind pc ADDR'
6933
     Find the next snapshot associated with the value ADDR of the
6934
     program counter.  Search proceeds forward from the last examined
6935
     trace snapshot.  If no argument ADDR is given, it means find the
6936
     next snapshot with the same value of PC as the current snapshot.
6937
 
6938
`tfind outside ADDR1, ADDR2'
6939
     Find the next snapshot whose PC is outside the given range of
6940
     addresses.
6941
 
6942
`tfind range ADDR1, ADDR2'
6943
     Find the next snapshot whose PC is between ADDR1 and ADDR2.
6944
 
6945
`tfind line [FILE:]N'
6946
     Find the next snapshot associated with the source line N.  If the
6947
     optional argument FILE is given, refer to line N in that source
6948
     file.  Search proceeds forward from the last examined trace
6949
     snapshot.  If no argument N is given, it means find the next line
6950
     other than the one currently being examined; thus saying `tfind
6951
     line' repeatedly can appear to have the same effect as stepping
6952
     from line to line in a _live_ debugging session.
6953
 
6954
   The default arguments for the `tfind' commands are specifically
6955
designed to make it easy to scan through the trace buffer.  For
6956
instance, `tfind' with no argument selects the next trace snapshot, and
6957
`tfind -' with no argument selects the previous trace snapshot.  So, by
6958
giving one `tfind' command, and then simply hitting  repeatedly
6959
you can examine all the trace snapshots in order.  Or, by saying `tfind
6960
-' and then hitting  repeatedly you can examine the snapshots in
6961
reverse order.  The `tfind line' command with no argument selects the
6962
snapshot for the next source line executed.  The `tfind pc' command with
6963
no argument selects the next snapshot with the same program counter
6964
(PC) as the current frame.  The `tfind tracepoint' command with no
6965
argument selects the next trace snapshot collected by the same
6966
tracepoint as the current one.
6967
 
6968
   In addition to letting you scan through the trace buffer manually,
6969
these commands make it easy to construct GDB scripts that scan through
6970
the trace buffer and print out whatever collected data you are
6971
interested in.  Thus, if we want to examine the PC, FP, and SP
6972
registers from each trace frame in the buffer, we can say this:
6973
 
6974
     (gdb) tfind start
6975
     (gdb) while ($trace_frame != -1)
6976
     > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6977
               $trace_frame, $pc, $sp, $fp
6978
     > tfind
6979
     > end
6980
 
6981
     Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6982
     Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6983
     Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6984
     Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6985
     Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6986
     Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6987
     Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6988
     Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6989
     Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6990
     Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6991
     Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6992
 
6993
   Or, if we want to examine the variable `X' at each source line in
6994
the buffer:
6995
 
6996
     (gdb) tfind start
6997
     (gdb) while ($trace_frame != -1)
6998
     > printf "Frame %d, X == %d\n", $trace_frame, X
6999
     > tfind line
7000
     > end
7001
 
7002
     Frame 0, X = 1
7003
     Frame 7, X = 2
7004
     Frame 13, X = 255
7005
 
7006

7007
File: gdb.info,  Node: tdump,  Next: save-tracepoints,  Prev: tfind,  Up: Analyze Collected Data
7008
 
7009
10.2.2 `tdump'
7010
--------------
7011
 
7012
This command takes no arguments.  It prints all the data collected at
7013
the current trace snapshot.
7014
 
7015
     (gdb) trace 444
7016
     (gdb) actions
7017
     Enter actions for tracepoint #2, one per line:
7018
     > collect $regs, $locals, $args, gdb_long_test
7019
     > end
7020
 
7021
     (gdb) tstart
7022
 
7023
     (gdb) tfind line 444
7024
     #0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7025
     at gdb_test.c:444
7026
     444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7027
 
7028
     (gdb) tdump
7029
     Data collected at tracepoint 2, trace frame 1:
7030
     d0             0xc4aa0085       -995491707
7031
     d1             0x18     24
7032
     d2             0x80     128
7033
     d3             0x33     51
7034
     d4             0x71aea3d        119204413
7035
     d5             0x22     34
7036
     d6             0xe0     224
7037
     d7             0x380035 3670069
7038
     a0             0x19e24a 1696330
7039
     a1             0x3000668        50333288
7040
     a2             0x100    256
7041
     a3             0x322000 3284992
7042
     a4             0x3000698        50333336
7043
     a5             0x1ad3cc 1758156
7044
     fp             0x30bf3c 0x30bf3c
7045
     sp             0x30bf34 0x30bf34
7046
     ps             0x0      0
7047
     pc             0x20b2c8 0x20b2c8
7048
     fpcontrol      0x0      0
7049
     fpstatus       0x0      0
7050
     fpiaddr        0x0      0
7051
     p = 0x20e5b4 "gdb-test"
7052
     p1 = (void *) 0x11
7053
     p2 = (void *) 0x22
7054
     p3 = (void *) 0x33
7055
     p4 = (void *) 0x44
7056
     p5 = (void *) 0x55
7057
     p6 = (void *) 0x66
7058
     gdb_long_test = 17 '\021'
7059
 
7060
     (gdb)
7061
 
7062

7063
File: gdb.info,  Node: save-tracepoints,  Prev: tdump,  Up: Analyze Collected Data
7064
 
7065
10.2.3 `save-tracepoints FILENAME'
7066
----------------------------------
7067
 
7068
This command saves all current tracepoint definitions together with
7069
their actions and passcounts, into a file `FILENAME' suitable for use
7070
in a later debugging session.  To read the saved tracepoint
7071
definitions, use the `source' command (*note Command Files::).
7072
 
7073

7074
File: gdb.info,  Node: Tracepoint Variables,  Prev: Analyze Collected Data,  Up: Tracepoints
7075
 
7076
10.3 Convenience Variables for Tracepoints
7077
==========================================
7078
 
7079
`(int) $trace_frame'
7080
     The current trace snapshot (a.k.a. "frame") number, or -1 if no
7081
     snapshot is selected.
7082
 
7083
`(int) $tracepoint'
7084
     The tracepoint for the current trace snapshot.
7085
 
7086
`(int) $trace_line'
7087
     The line number for the current trace snapshot.
7088
 
7089
`(char []) $trace_file'
7090
     The source file for the current trace snapshot.
7091
 
7092
`(char []) $trace_func'
7093
     The name of the function containing `$tracepoint'.
7094
 
7095
   Note: `$trace_file' is not suitable for use in `printf', use
7096
`output' instead.
7097
 
7098
   Here's a simple example of using these convenience variables for
7099
stepping through all the trace snapshots and printing some of their
7100
data.
7101
 
7102
     (gdb) tfind start
7103
 
7104
     (gdb) while $trace_frame != -1
7105
     > output $trace_file
7106
     > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7107
     > tfind
7108
     > end
7109
 
7110

7111
File: gdb.info,  Node: Overlays,  Next: Languages,  Prev: Tracepoints,  Up: Top
7112
 
7113
11 Debugging Programs That Use Overlays
7114
***************************************
7115
 
7116
If your program is too large to fit completely in your target system's
7117
memory, you can sometimes use "overlays" to work around this problem.
7118
GDB provides some support for debugging programs that use overlays.
7119
 
7120
* Menu:
7121
 
7122
* How Overlays Work::              A general explanation of overlays.
7123
* Overlay Commands::               Managing overlays in GDB.
7124
* Automatic Overlay Debugging::    GDB can find out which overlays are
7125
                                   mapped by asking the inferior.
7126
* Overlay Sample Program::         A sample program using overlays.
7127
 
7128

7129
File: gdb.info,  Node: How Overlays Work,  Next: Overlay Commands,  Up: Overlays
7130
 
7131
11.1 How Overlays Work
7132
======================
7133
 
7134
Suppose you have a computer whose instruction address space is only 64
7135
kilobytes long, but which has much more memory which can be accessed by
7136
other means: special instructions, segment registers, or memory
7137
management hardware, for example.  Suppose further that you want to
7138
adapt a program which is larger than 64 kilobytes to run on this system.
7139
 
7140
   One solution is to identify modules of your program which are
7141
relatively independent, and need not call each other directly; call
7142
these modules "overlays".  Separate the overlays from the main program,
7143
and place their machine code in the larger memory.  Place your main
7144
program in instruction memory, but leave at least enough space there to
7145
hold the largest overlay as well.
7146
 
7147
   Now, to call a function located in an overlay, you must first copy
7148
that overlay's machine code from the large memory into the space set
7149
aside for it in the instruction memory, and then jump to its entry point
7150
there.
7151
 
7152
         Data             Instruction            Larger
7153
     Address Space       Address Space        Address Space
7154
     +-----------+       +-----------+        +-----------+
7155
     |           |       |           |        |           |
7156
     +-----------+       +-----------+        +-----------+<-- overlay 1
7157
     | program   |       |   main    |   .----| overlay 1 | load address
7158
     | variables |       |  program  |   |    +-----------+
7159
     | and heap  |       |           |   |    |           |
7160
     +-----------+       |           |   |    +-----------+<-- overlay 2
7161
     |           |       +-----------+   |    |           | load address
7162
     +-----------+       |           |   |  .-| overlay 2 |
7163
                         |           |   |  | |           |
7164
              mapped --->+-----------+   |  | +-----------+
7165
              address    |           |   |  | |           |
7166
                         |  overlay  | <-'  | |           |
7167
                         |   area    |  <---' +-----------+<-- overlay 3
7168
                         |           | <---.  |           | load address
7169
                         +-----------+     `--| overlay 3 |
7170
                         |           |        |           |
7171
                         +-----------+        |           |
7172
                                              +-----------+
7173
                                              |           |
7174
                                              +-----------+
7175
 
7176
                         A code overlay
7177
 
7178
   The diagram (*note A code overlay::) shows a system with separate
7179
data and instruction address spaces.  To map an overlay, the program
7180
copies its code from the larger address space to the instruction
7181
address space.  Since the overlays shown here all use the same mapped
7182
address, only one may be mapped at a time.  For a system with a single
7183
address space for data and instructions, the diagram would be similar,
7184
except that the program variables and heap would share an address space
7185
with the main program and the overlay area.
7186
 
7187
   An overlay loaded into instruction memory and ready for use is
7188
called a "mapped" overlay; its "mapped address" is its address in the
7189
instruction memory.  An overlay not present (or only partially present)
7190
in instruction memory is called "unmapped"; its "load address" is its
7191
address in the larger memory.  The mapped address is also called the
7192
"virtual memory address", or "VMA"; the load address is also called the
7193
"load memory address", or "LMA".
7194
 
7195
   Unfortunately, overlays are not a completely transparent way to
7196
adapt a program to limited instruction memory.  They introduce a new
7197
set of global constraints you must keep in mind as you design your
7198
program:
7199
 
7200
   * Before calling or returning to a function in an overlay, your
7201
     program must make sure that overlay is actually mapped.
7202
     Otherwise, the call or return will transfer control to the right
7203
     address, but in the wrong overlay, and your program will probably
7204
     crash.
7205
 
7206
   * If the process of mapping an overlay is expensive on your system,
7207
     you will need to choose your overlays carefully to minimize their
7208
     effect on your program's performance.
7209
 
7210
   * The executable file you load onto your system must contain each
7211
     overlay's instructions, appearing at the overlay's load address,
7212
     not its mapped address.  However, each overlay's instructions must
7213
     be relocated and its symbols defined as if the overlay were at its
7214
     mapped address.  You can use GNU linker scripts to specify
7215
     different load and relocation addresses for pieces of your
7216
     program; see *Note Overlay Description: (ld.info)Overlay
7217
     Description.
7218
 
7219
   * The procedure for loading executable files onto your system must
7220
     be able to load their contents into the larger address space as
7221
     well as the instruction and data spaces.
7222
 
7223
 
7224
   The overlay system described above is rather simple, and could be
7225
improved in many ways:
7226
 
7227
   * If your system has suitable bank switch registers or memory
7228
     management hardware, you could use those facilities to make an
7229
     overlay's load area contents simply appear at their mapped address
7230
     in instruction space.  This would probably be faster than copying
7231
     the overlay to its mapped area in the usual way.
7232
 
7233
   * If your overlays are small enough, you could set aside more than
7234
     one overlay area, and have more than one overlay mapped at a time.
7235
 
7236
   * You can use overlays to manage data, as well as instructions.  In
7237
     general, data overlays are even less transparent to your design
7238
     than code overlays: whereas code overlays only require care when
7239
     you call or return to functions, data overlays require care every
7240
     time you access the data.  Also, if you change the contents of a
7241
     data overlay, you must copy its contents back out to its load
7242
     address before you can copy a different data overlay into the same
7243
     mapped area.
7244
 
7245
 
7246

7247
File: gdb.info,  Node: Overlay Commands,  Next: Automatic Overlay Debugging,  Prev: How Overlays Work,  Up: Overlays
7248
 
7249
11.2 Overlay Commands
7250
=====================
7251
 
7252
To use GDB's overlay support, each overlay in your program must
7253
correspond to a separate section of the executable file.  The section's
7254
virtual memory address and load memory address must be the overlay's
7255
mapped and load addresses.  Identifying overlays with sections allows
7256
GDB to determine the appropriate address of a function or variable,
7257
depending on whether the overlay is mapped or not.
7258
 
7259
   GDB's overlay commands all start with the word `overlay'; you can
7260
abbreviate this as `ov' or `ovly'.  The commands are:
7261
 
7262
`overlay off'
7263
     Disable GDB's overlay support.  When overlay support is disabled,
7264
     GDB assumes that all functions and variables are always present at
7265
     their mapped addresses.  By default, GDB's overlay support is
7266
     disabled.
7267
 
7268
`overlay manual'
7269
     Enable "manual" overlay debugging.  In this mode, GDB relies on
7270
     you to tell it which overlays are mapped, and which are not, using
7271
     the `overlay map-overlay' and `overlay unmap-overlay' commands
7272
     described below.
7273
 
7274
`overlay map-overlay OVERLAY'
7275
`overlay map OVERLAY'
7276
     Tell GDB that OVERLAY is now mapped; OVERLAY must be the name of
7277
     the object file section containing the overlay.  When an overlay
7278
     is mapped, GDB assumes it can find the overlay's functions and
7279
     variables at their mapped addresses.  GDB assumes that any other
7280
     overlays whose mapped ranges overlap that of OVERLAY are now
7281
     unmapped.
7282
 
7283
`overlay unmap-overlay OVERLAY'
7284
`overlay unmap OVERLAY'
7285
     Tell GDB that OVERLAY is no longer mapped; OVERLAY must be the
7286
     name of the object file section containing the overlay.  When an
7287
     overlay is unmapped, GDB assumes it can find the overlay's
7288
     functions and variables at their load addresses.
7289
 
7290
`overlay auto'
7291
     Enable "automatic" overlay debugging.  In this mode, GDB consults
7292
     a data structure the overlay manager maintains in the inferior to
7293
     see which overlays are mapped.  For details, see *Note Automatic
7294
     Overlay Debugging::.
7295
 
7296
`overlay load-target'
7297
`overlay load'
7298
     Re-read the overlay table from the inferior.  Normally, GDB
7299
     re-reads the table GDB automatically each time the inferior stops,
7300
     so this command should only be necessary if you have changed the
7301
     overlay mapping yourself using GDB.  This command is only useful
7302
     when using automatic overlay debugging.
7303
 
7304
`overlay list-overlays'
7305
`overlay list'
7306
     Display a list of the overlays currently mapped, along with their
7307
     mapped addresses, load addresses, and sizes.
7308
 
7309
 
7310
   Normally, when GDB prints a code address, it includes the name of
7311
the function the address falls in:
7312
 
7313
     (gdb) print main
7314
     $3 = {int ()} 0x11a0 
7315
   When overlay debugging is enabled, GDB recognizes code in unmapped
7316
overlays, and prints the names of unmapped functions with asterisks
7317
around them.  For example, if `foo' is a function in an unmapped
7318
overlay, GDB prints it this way:
7319
 
7320
     (gdb) overlay list
7321
     No sections are mapped.
7322
     (gdb) print foo
7323
     $5 = {int (int)} 0x100000 <*foo*>
7324
   When `foo''s overlay is mapped, GDB prints the function's name
7325
normally:
7326
 
7327
     (gdb) overlay list
7328
     Section .ov.foo.text, loaded at 0x100000 - 0x100034,
7329
             mapped at 0x1016 - 0x104a
7330
     (gdb) print foo
7331
     $6 = {int (int)} 0x1016 
7332
 
7333
   When overlay debugging is enabled, GDB can find the correct address
7334
for functions and variables in an overlay, whether or not the overlay
7335
is mapped.  This allows most GDB commands, like `break' and
7336
`disassemble', to work normally, even on unmapped code.  However, GDB's
7337
breakpoint support has some limitations:
7338
 
7339
   * You can set breakpoints in functions in unmapped overlays, as long
7340
     as GDB can write to the overlay at its load address.
7341
 
7342
   * GDB can not set hardware or simulator-based breakpoints in
7343
     unmapped overlays.  However, if you set a breakpoint at the end of
7344
     your overlay manager (and tell GDB which overlays are now mapped,
7345
     if you are using manual overlay management), GDB will re-set its
7346
     breakpoints properly.
7347
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.